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


C++ AttributedString::getJustification方法代码示例

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


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

示例1: setTextFormatProperties

    void setTextFormatProperties (const AttributedString& text, IDWriteTextFormat* const format)
    {
        DWRITE_TEXT_ALIGNMENT alignment = DWRITE_TEXT_ALIGNMENT_LEADING;
        DWRITE_WORD_WRAPPING wrapType = DWRITE_WORD_WRAPPING_WRAP;

        switch (text.getJustification().getOnlyHorizontalFlags())
        {
            case Justification::left:                   break;
            case Justification::right:                  alignment = DWRITE_TEXT_ALIGNMENT_TRAILING; break;
            case Justification::horizontallyCentred:    alignment = DWRITE_TEXT_ALIGNMENT_CENTER; break;
            case Justification::horizontallyJustified:  break; // DirectWrite cannot justify text, default to left alignment
            default:                                    jassertfalse; break; // Illegal justification flags
        }

        switch (text.getWordWrap())
        {
            case AttributedString::none:      wrapType = DWRITE_WORD_WRAPPING_NO_WRAP; break;
            case AttributedString::byWord:    break;
            case AttributedString::byChar:    break; // DirectWrite doesn't support wrapping by character, default to word-wrap
            default:                          jassertfalse; break; // Illegal flags!
        }

        format->SetTextAlignment (alignment);
        format->SetWordWrapping (wrapType);

        // DirectWrite does not automatically set reading direction
        // This must be set correctly and manually when using RTL Scripts (Hebrew, Arabic)
        if (text.getReadingDirection() == AttributedString::rightToLeft)
            format->SetReadingDirection (DWRITE_READING_DIRECTION_RIGHT_TO_LEFT);
    }
开发者ID:sonic59,项目名称:JuceFontLegacyS1,代码行数:30,代码来源:juce_win32_DirectWriteTypeLayout.cpp

示例2: createLayout

void TextLayout::createLayout (const AttributedString& text, float maxWidth)
{
    lines.clear();
    width = maxWidth;
    justification = text.getJustification();

    if (! createNativeLayout (text))
        createStandardLayout (text);

    recalculateWidth (text);
}
开发者ID:Theadd,项目名称:MultipurposeButton,代码行数:11,代码来源:juce_TextLayout.cpp

示例3: createLayout

        void createLayout (const AttributedString& text, TextLayout& layout)
        {
            tokens.ensureStorageAllocated (64);
            layout.ensureStorageAllocated (totalLines);

            addTextRuns (text);

            layoutRuns ((int) layout.getWidth());

            int charPosition = 0;
            int lineStartPosition = 0;
            int runStartPosition = 0;

            TextLayout::Line* glyphLine = new TextLayout::Line();
            TextLayout::Run*  glyphRun  = new TextLayout::Run();

            for (int i = 0; i < tokens.size(); ++i)
            {
                const Token* const t = tokens.getUnchecked (i);
                const Point<float> tokenPos (t->area.getPosition().toFloat());

                Array <int> newGlyphs;
                Array <float> xOffsets;
                t->font.getGlyphPositions (t->text.trimEnd(), newGlyphs, xOffsets);

                glyphRun->glyphs.ensureStorageAllocated (glyphRun->glyphs.size() + newGlyphs.size());

                for (int j = 0; j < newGlyphs.size(); ++j)
                {
                    if (charPosition == lineStartPosition)
                        glyphLine->lineOrigin = tokenPos.translated (0, t->font.getAscent());

                    const float x = xOffsets.getUnchecked (j);
                    glyphRun->glyphs.add (TextLayout::Glyph (newGlyphs.getUnchecked(j),
                                                             Point<float> (tokenPos.getX() + x, 0),
                                                             xOffsets.getUnchecked (j + 1) - x));
                    ++charPosition;
                }

                if (t->isWhitespace || t->isNewLine)
                    ++charPosition;

                const Token* const nextToken = tokens [i + 1];

                if (nextToken == nullptr) // this is the last token
                {
                    addRun (glyphLine, glyphRun, t, runStartPosition, charPosition);
                    glyphLine->stringRange = Range<int> (lineStartPosition, charPosition);
                    layout.addLine (glyphLine);
                }
                else
                {
                    if (t->font != nextToken->font || t->colour != nextToken->colour)
                    {
                        addRun (glyphLine, glyphRun, t, runStartPosition, charPosition);
                        runStartPosition = charPosition;
                        glyphRun = new TextLayout::Run();
                    }

                    if (t->line != nextToken->line)
                    {
                        addRun (glyphLine, glyphRun, t, runStartPosition, charPosition);
                        glyphLine->stringRange = Range<int> (lineStartPosition, charPosition);
                        layout.addLine (glyphLine);

                        runStartPosition = charPosition;
                        lineStartPosition = charPosition;
                        glyphLine = new TextLayout::Line();
                        glyphRun  = new TextLayout::Run();
                    }
                }
            }

            if ((text.getJustification().getFlags() & (Justification::right | Justification::horizontallyCentred)) != 0)
            {
                const int totalW = (int) layout.getWidth();

                for (int i = 0; i < totalLines; ++i)
                {
                    const int lineW = getLineWidth (i);
                    float dx = 0;

                    if ((text.getJustification().getFlags() & Justification::right) != 0)
                        dx = (float) (totalW - lineW);
                    else
                        dx = (totalW - lineW) / 2.0f;

                    TextLayout::Line& glyphLine = layout.getLine (i);
                    glyphLine.lineOrigin.x += dx;
                }
            }
        }
开发者ID:sonic59,项目名称:JuceS2Text,代码行数:92,代码来源:juce_TextLayout.cpp


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