Text is not rendering when using SkParagraph. skia version m128

49 views
Skip to first unread message

Surya B

unread,
May 15, 2025, 8:52:09 AM5/15/25
to skia-discuss
sk_sp<FontCollection> fontCollection = sk_make_sp<FontCollection>();
            sk_sp<SkFontMgr> fontMgr = SkFontMgr::RefEmpty();
            SkFontStyle fontStyle = SkFontStyle(SkFontStyle::kNormal_Weight,
                                               SkFontStyle::kNormal_Width,
                                               SkFontStyle::kUpright_Slant);

            sk_sp<SkTypeface> typeface = fontMgr->legacyMakeTypeface("Arial", fontStyle);
            fontCollection->setDefaultFontManager(fontMgr);
            ParagraphStyle paragraphStyle;
            paragraphStyle.setTextAlign(TextAlign::kLeft);
            paragraphStyle.setMaxLines(10);
            paragraphStyle.setEllipsis(SkString("..."));
            TextStyle textStyle;
            textStyle.setColor(SK_ColorBLACK);
            textStyle.setFontSize(32.0);
            SkString familyName;
            if (typeface) {
                typeface->getFamilyName(&familyName);
                textStyle.setFontFamilies({familyName});
            } else {
                textStyle.setFontFamilies({SkString("Arial")});
            }
            std::unique_ptr<ParagraphBuilder> builder =
                ParagraphBuilder::make(paragraphStyle, fontCollection);
            builder->pushStyle(textStyle);
            builder->addText("Hello, Text Rendering Test");
            std::unique_ptr<Paragraph> paragraph = builder->Build();
            paragraph->layout(300);
            paragraph->paint(canvas, 50, 50);

jlav...@google.com

unread,
May 15, 2025, 10:24:36 AM5/15/25
to skia-discuss
You need to use another font manager, not the empty one.
For instance:
sk_sp<SkFontMgr> fontMgr = ToolUtils::TestFontMgr();
It works.

Reply all
Reply to author
Forward
0 new messages