当前位置: 首页>>代码示例>>C++>>正文


C++ Paragraph::Hyphenate方法代码示例

本文整理汇总了C++中Paragraph::Hyphenate方法的典型用法代码示例。如果您正苦于以下问题:C++ Paragraph::Hyphenate方法的具体用法?C++ Paragraph::Hyphenate怎么用?C++ Paragraph::Hyphenate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Paragraph的用法示例。


在下文中一共展示了Paragraph::Hyphenate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WrapLine

// the formatter's core, wraps the line and justifies it if needed
int TextFormatter::WrapLine(CFDC& dc, Paragraph& pp,
    FilePos& pos, LineArray& la,
    int top, int maxh)
{
    if (maxh <= 0)
        return 0;
    // process images separately
    if (pp.flags&Paragraph::image)
        return WrapImage(dc, pp, pos, la, top, maxh);
    if (pp.len == 0 || (pp.len == 1 && pp.str[0] == L' '))
    {
        dc.SelectFont(0, 0);
        int fh, fa;
        dc.GetFontSize(fh, fa);
        if (fh > maxh)
            return -1;
        Line l;
        l.pos = pos;
        l.flags = Line::first | Line::last | Line::defstyle;
        l.height = fh;
        l.base = fa;
        la.Add(l);
        pos.off = pp.len;
        return l.height;
    }
    if (m_hyphenate)
        pp.Hyphenate();
    const wchar_t *str = pp.str;
    int len = pp.len;
    Buffer<int> dx(len + 1);
    int toth = 0;
    while (toth < maxh && pos.off < len)
    {
        // 1. get text size
        int nch = len;
        int curwidth = m_width;
        int ispace = 0;
        if (pos.off == 0 && (pp.flags&(Paragraph::center | Paragraph::right)) == 0)
            AdjustIndent(curwidth, ispace, pp.lindent, pp.rindent, pp.findent, dc.GetLPX());
        else
            AdjustIndent(curwidth, ispace, pp.lindent, pp.rindent, 0, dc.GetLPX());
        dx[0] = 0;
        int lh = 1, lbase = 1;
        GetTextExtent(dc, pp, pos.off, curwidth, nch, dx + 1, lh, lbase);
        if (toth + lh > maxh)
            return -1;
        if (nch == 0)
            nch = 1;
        // 2. do word wrap
        bool addhyp = false;
        if (nch + pos.off < pp.str.size())
        {
            int i;
            for (i = nch; i > 0 && str[pos.off + i] != L' '; --i)
            {
                // wrap at existing dashes
                if (i < nch && (str[pos.off + i] == L'-' || str[pos.off + i] == 0x2013 ||
                    str[pos.off + i] == 0x2014) && i < len - 1 && (str[pos.off + i + 1] == L' ' ||
                    iswalpha(str[pos.off + i + 1])))
                {
                    ++i;
                    break;
                }
                // or at possible hyphenation points
                if (m_hyphenate && pp.cflags[pos.off + i].hyphen &&
                    dx[i] + dc.GetHypWidth() <= curwidth)
                {
                    addhyp = true;
                    break;
                }
            }
            if (i > 0)
                nch = i;
            else
                addhyp = false;
        }
        // insert it into line list
        if (pos.off == 0 && nch == pp.str.size())
        {
            // got full line
            Line l(str, len, false);
            l.pos = pos;
            l.flags = Line::first | Line::last;
            l.ispace = ispace;
            l.height = lh;
            l.base = lbase;
            if (dx[nch] < curwidth)
            {
                if (pp.flags&Paragraph::center)
                    l.ispace += (curwidth - dx[nch]) / 2;
                else if (pp.flags&Paragraph::right)
                    l.ispace += curwidth - dx[nch];
            }
            CopyAttr(l.attr, pp.cflags, len);
            for (int j = 0; j < len; ++j)
                l.dx[j] = dx[j + 1] - dx[j];
            la.Add(l);
            pos.off = len;
        }
//.........这里部分代码省略.........
开发者ID:MakiseKurisu,项目名称:TextViewNG,代码行数:101,代码来源:TextFormatter.cpp


注:本文中的Paragraph::Hyphenate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。