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


C++ AttributedString类代码示例

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


在下文中一共展示了AttributedString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: paintListBoxItem

    void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected) override
    {
        if (rowIsSelected)
            g.fillAll (Colours::deepskyblue);

        if (JuceDemoTypeBase* type = JuceDemoTypeBase::getDemoTypeList() [rowNumber])
        {
            String name (type->name.trimCharactersAtStart ("0123456789").trimStart());

            AttributedString a;
            a.setJustification (Justification::centredLeft);

            String category;

            if (name.containsChar (':'))
            {
                category = name.upToFirstOccurrenceOf (":", true, false);
                name = name.fromFirstOccurrenceOf (":", false, false).trim();

                if (height > 20)
                    category << "\n";
                else
                    category << " ";
            }

            if (category.isNotEmpty())
                a.append (category, Font (10.0f), Colour::greyLevel (0.5f));

            a.append (name, Font (13.0f), Colours::white.withAlpha (0.9f));

            a.draw (g, Rectangle<int> (width + 10, height).reduced (6, 0).toFloat());
        }
    }
开发者ID:topilski,项目名称:JUCE,代码行数:33,代码来源:MainWindow.cpp

示例3: text

void NodeComponent::bubbleMessage(String msg)
{
  AttributedString text (msg);
  text.setJustification (Justification::centred);
  bbl.setAlwaysOnTop (true);
  bbl.addToDesktop (0);
  
  bbl.showAt(this, text, 5000., true, false);
}
开发者ID:olilarkin,项目名称:pMix2,代码行数:9,代码来源:pMixGraphEditorParts.cpp

示例4: updateLayout

    void updateLayout (const int width)
    {
        AttributedString s;
        s.setJustification (Justification::topLeft);
        s.append (getText(), getFont());

        TextLayout text;
        text.createLayoutWithBalancedLineLengths (s, width - 8.0f);
        setSize (width, jmin (width, (int) (text.getHeight() + getFont().getHeight())));
    }
开发者ID:Amcut,项目名称:pizmidi,代码行数:10,代码来源:juce_AlertWindow.cpp

示例5: BubbleMessageComponent

void FilterComponent::bubbleMessage(String msg)
{
  BubbleMessageComponent* bbl = new BubbleMessageComponent();
  AttributedString text (msg);
  text.setJustification (Justification::centred);
  bbl->setAlwaysOnTop (true);
  bbl->addToDesktop (0);
  
  bbl->showAt(this, text, 2000., true, true);
}
开发者ID:eriser,项目名称:pMix2,代码行数:10,代码来源:pMixGraphEditorParts.cpp

示例6: setupLayout

    bool setupLayout (const AttributedString& text, const float maxWidth, const float maxHeight,
                      ID2D1RenderTarget& renderTarget, IDWriteFactory& directWriteFactory,
                      IDWriteFontCollection& fontCollection, ComSmartPtr<IDWriteTextLayout>& textLayout)
    {
        // To add color to text, we need to create a D2D render target
        // Since we are not actually rendering to a D2D context we create a temporary GDI render target

        Font defaultFont;
        BOOL fontFound = false;
        uint32 fontIndex;
        fontCollection.FindFamilyName (defaultFont.getTypeface()->getName().toWideCharPointer(), &fontIndex, &fontFound);

        if (! fontFound)
            fontIndex = 0;

        ComSmartPtr<IDWriteFontFamily> dwFontFamily;
        HRESULT hr = fontCollection.GetFontFamily (fontIndex, dwFontFamily.resetAndGetPointerAddress());

        ComSmartPtr<IDWriteFont> dwFont;
        hr = dwFontFamily->GetFirstMatchingFont (DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STYLE_NORMAL,
                                                 dwFont.resetAndGetPointerAddress());
        jassert (dwFont != nullptr);

        const float defaultFontHeightToEmSizeFactor = getFontHeightToEmSizeFactor (*dwFont);

        ComSmartPtr<IDWriteTextFormat> dwTextFormat;
        hr = directWriteFactory.CreateTextFormat (defaultFont.getTypefaceName().toWideCharPointer(), &fontCollection,
                                                  DWRITE_FONT_WEIGHT_REGULAR, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
                                                  defaultFont.getHeight() * defaultFontHeightToEmSizeFactor,
                                                  L"en-us", dwTextFormat.resetAndGetPointerAddress());

        setTextFormatProperties (text, *dwTextFormat);

        {
            DWRITE_TRIMMING trimming = { DWRITE_TRIMMING_GRANULARITY_CHARACTER, 0, 0 };
            ComSmartPtr<IDWriteInlineObject> trimmingSign;
            hr = directWriteFactory.CreateEllipsisTrimmingSign (dwTextFormat, trimmingSign.resetAndGetPointerAddress());
            hr = dwTextFormat->SetTrimming (&trimming, trimmingSign);
        }

        const int textLen = text.getText().length();

        hr = directWriteFactory.CreateTextLayout (text.getText().toWideCharPointer(), textLen, dwTextFormat,
                                                  maxWidth, maxHeight, textLayout.resetAndGetPointerAddress());

        if (FAILED (hr) || textLayout == nullptr)
            return false;

        const int numAttributes = text.getNumAttributes();

        for (int i = 0; i < numAttributes; ++i)
            addAttributedRange (*text.getAttribute (i), *textLayout, textLen, renderTarget, fontCollection);

        return true;
    }
开发者ID:Flowersoft,项目名称:MIDI2LR,代码行数:55,代码来源:juce_win32_DirectWriteTypeLayout.cpp

示例7: font

void CtrlrLuaMethodEditorTabsLF::createTabTextLayout (const TabBarButton& button, float length, float depth, Colour colour, TextLayout& textLayout)
{
    Font font (12.0f);
    font.setUnderline (button.hasKeyboardFocus (false));

    AttributedString s;
    s.setJustification (Justification::centred);
    s.append (button.getButtonText().trim(), font, colour);

    textLayout.createLayout (s, length);
}
开发者ID:Srikrishna31,项目名称:ctrlr,代码行数:11,代码来源:CtrlrLuaMethodEditorTabs.cpp

示例8: BubbleMessageComponent

void TracktionMarketplaceUnlockForm::showBubbleMessage (const String& text, Component& target)
{
    bubble = new BubbleMessageComponent (500);
    addChildComponent (bubble);

    AttributedString attString;
    attString.append (text, Font (15.0f));

    bubble->showAt (getLocalArea (&target, target.getLocalBounds()),
                    attString, 500,  // numMillisecondsBeforeRemoving
                    true,  // removeWhenMouseClicked
                    false); // deleteSelfAfterUse
}
开发者ID:BrainDamage,项目名称:ambix,代码行数:13,代码来源:juce_TracktionMarketplaceUnlockForm.cpp

示例9: layoutTooltipText

    static TextLayout layoutTooltipText (const String& text, const Colour& colour) noexcept
    {
        const float tooltipFontSize = 13.0f;
        const int maxToolTipWidth = 400;

        AttributedString s;
        s.setJustification (Justification::centred);
        s.append (text, Font (tooltipFontSize, Font::bold), colour);

        TextLayout tl;
        tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth);
        return tl;
    }
开发者ID:Amcut,项目名称:pizmidi,代码行数:13,代码来源:LookAndFeel.cpp

示例10: BubbleMessageComponent

void MainAppWindow::showMessageBubble (const String& text)
{
    currentBubbleMessage = new BubbleMessageComponent (500);
    getContentComponent()->addChildComponent (currentBubbleMessage);

    AttributedString attString;
    attString.append (text, Font (15.0f));

    currentBubbleMessage->showAt (Rectangle<int> (getLocalBounds().getCentreX(), 10, 1, 1),
                                  attString,
                                  500,  // numMillisecondsBeforeRemoving
                                  true,  // removeWhenMouseClicked
                                  false); // deleteSelfAfterUse
}
开发者ID:topilski,项目名称:JUCE,代码行数:14,代码来源:MainWindow.cpp

示例11: drawSelectionRectangle

void CtrlrValueTreeEditorItem::paintItem (Graphics &g, int width, int height)
{
	Image icon = provider.getIconForItem (treeToEdit);
	if (isSelected())
	{
		drawSelectionRectangle (g,width,height);
	}

	g.setColour (Colours::black);

	AttributedString as = provider.getDisplayString(treeToEdit);
	as.setJustification (Justification (Justification::centredLeft));
	as.draw (g, Rectangle <float> (24.0, 0.0, width - 24.0, height));
	g.drawImageWithin (icon, 4, 0, 16, height, RectanglePlacement (RectanglePlacement::centred));
}
开发者ID:noscript,项目名称:ctrlr,代码行数:15,代码来源:CtrlrValueTreeEditor.cpp

示例12: addTextRuns

        void addTextRuns (const AttributedString& text)
        {
            Font defaultFont;
            Array<RunAttribute> runAttributes;

            {
                const int stringLength = text.getText().length();
                int rangeStart = 0;
                FontAndColour lastFontAndColour;

                // Iterate through every character in the string
                for (int i = 0; i < stringLength; ++i)
                {
                    FontAndColour newFontAndColour;
                    newFontAndColour.font = &defaultFont;

                    const int numCharacterAttributes = text.getNumAttributes();

                    for (int j = 0; j < numCharacterAttributes; ++j)
                    {
                        const AttributedString::Attribute* const attr = text.getAttribute (j);

                        // Check if the current character falls within the range of a font attribute
                        if (attr->getFont() != nullptr && (i >= attr->range.getStart()) && (i < attr->range.getEnd()))
                            newFontAndColour.font = attr->getFont();

                        // Check if the current character falls within the range of a foreground colour attribute
                        if (attr->getColour() != nullptr && (i >= attr->range.getStart()) && (i < attr->range.getEnd()))
                            newFontAndColour.colour = *attr->getColour();
                    }

                    if (i > 0 && (newFontAndColour != lastFontAndColour || i == stringLength - 1))
                    {
                        runAttributes.add (RunAttribute (lastFontAndColour,
                                                         Range<int> (rangeStart, (i < stringLength - 1) ? i : (i + 1))));
                        rangeStart = i;
                    }

                    lastFontAndColour = newFontAndColour;
                }
            }

            for (int i = 0; i < runAttributes.size(); ++i)
            {
                const RunAttribute& r = runAttributes.getReference(i);
                appendText (text, r.range, *(r.fontAndColour.font), r.fontAndColour.colour);
            }
        }
开发者ID:sonic59,项目名称:JulesText,代码行数:48,代码来源:juce_GlyphLayout.cpp

示例13: getDisplayString

const AttributedString CtrlrLuaMethodEditor::getDisplayString(const ValueTree &item)	const
{
	AttributedString str;

	if (item.getType () == Ids::luaMethod)
	{
		Colour text;

		if ((bool)item.getProperty(Ids::luaMethodValid) == false)
			text = Colours::red;
		else
			text = Colours::black;

		str.append (item.getProperty(Ids::luaMethodName).toString()+"\n", Font(12.0f, Font::plain), text);

		if ((int)item.getProperty(Ids::luaMethodSource) == CtrlrLuaMethod::codeInFile)
		{
			str.append (File::descriptionOfSizeInBytes (File(item.getProperty(Ids::luaMethodSourcePath).toString()).getSize()), Font(10.0f, Font::italic), text.brighter(0.2f));
		}
		else
		{
			str.append (File::descriptionOfSizeInBytes (item.getProperty(Ids::luaMethodCode).toString().length()), Font(10.0f, Font::italic), text.brighter(0.2f));
		}

		str.setJustification (Justification::left);
	}

	if (item.getType() == Ids::luaMethodGroup)
	{
		str.append (item.getProperty(Ids::name), Font(14.0f, Font::plain), Colours::black);
		str.append (" ["+String(item.getNumChildren())+"]", Font(10.0f, Font::italic), Colours::darkgrey);

		str.setJustification (Justification::left);
	}

	if (item.getType() == Ids::luaManagerMethods)
	{
		str.append ("LUA", Font(14.0f, Font::bold), Colours::black);

		str.setJustification (Justification::left);
	}

	return (str);
}
开发者ID:grimtraveller,项目名称:ctrlr,代码行数:44,代码来源:CtrlrLuaMethodEditor.cpp

示例14: setupLayout

    void setupLayout (const AttributedString& text, const float& maxWidth, const float& maxHeight,
                      ID2D1RenderTarget* const renderTarget, IDWriteFactory* const directWriteFactory,
                      IDWriteFontCollection* const fontCollection, IDWriteTextLayout** dwTextLayout)
    {
        // To add color to text, we need to create a D2D render target
        // Since we are not actually rendering to a D2D context we create a temporary GDI render target

        Font defaultFont;
        BOOL fontFound = false;
        uint32 fontIndex;
        fontCollection->FindFamilyName (defaultFont.getTypeface()->getName().toWideCharPointer(), &fontIndex, &fontFound);

        if (! fontFound)
            fontIndex = 0;

        ComSmartPtr<IDWriteFontFamily> dwFontFamily;
        HRESULT hr = fontCollection->GetFontFamily (fontIndex, dwFontFamily.resetAndGetPointerAddress());

        ComSmartPtr<IDWriteFont> dwFont;
        hr = dwFontFamily->GetFirstMatchingFont (DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STRETCH_NORMAL, DWRITE_FONT_STYLE_NORMAL,
                                                 dwFont.resetAndGetPointerAddress());

        const float defaultFontHeightToEmSizeFactor = getFontHeightToEmSizeFactor (dwFont);

        jassert (directWriteFactory != nullptr);

        ComSmartPtr<IDWriteTextFormat> dwTextFormat;
        hr = directWriteFactory->CreateTextFormat (defaultFont.getTypefaceName().toWideCharPointer(), fontCollection,
                                                   DWRITE_FONT_WEIGHT_REGULAR, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL,
                                                   defaultFont.getHeight() * defaultFontHeightToEmSizeFactor,
                                                   L"en-us", dwTextFormat.resetAndGetPointerAddress());

        setTextFormatProperties (text, dwTextFormat);

        const int textLen = text.getText().length();

        hr = directWriteFactory->CreateTextLayout (text.getText().toWideCharPointer(), textLen,
                                                   dwTextFormat, maxWidth, maxHeight, dwTextLayout);

        const int numAttributes = text.getNumAttributes();

        for (int i = 0; i < numAttributes; ++i)
            addAttributedRange (*text.getAttribute (i), *dwTextLayout, textLen, renderTarget, fontCollection);
    }
开发者ID:Emisense,项目名称:S3Test,代码行数:44,代码来源:juce_win32_DirectWriteTypeLayout.cpp

示例15: newMessage

//==============================================================================
void AlertWindow::setMessage (const String& message)
{
    const String newMessage (message.substring (0, 2048));

    if (text != newMessage)
    {
        text = newMessage;

        font = getLookAndFeel().getAlertWindowMessageFont();

        AttributedString newText;
        newText.append (getName() + "\n\n", Font (font.getHeight() * 1.1f, Font::bold));
        newText.append (text, font);
        attributedText = newText;

        updateLayout (true);
        repaint();
    }
}
开发者ID:sonic59,项目名称:JuceS2Text,代码行数:20,代码来源:juce_AlertWindow.cpp


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