Search code examples
c++macosskia

SkParagraph not shaping or rendering text


I compiled skia for macosx using cmake. Everything works except SkParagraph. Can render using canvas->drawString. Compiles and runs fine but does not wrap or show any text. Am I missing something while compiling skia?

This is what I tried,

 ParagraphStyle paraStyle;
 paraStyle.setTextAlign(skia::textlayout::TextAlign::kLeft);
 auto builder =
 ParagraphBuilderImpl::make(paraStyle, sk_make_sp<FontCollection>());

 builder->pushStyle(style);
 std::string text = "Hello";
 builder->addText(text.c_str(), text.length());
 builder->pop();

 // canvas->drawString("Hello", 20, 20, SkFont(), SkPaint());

 auto para = builder->Build();
 para.get()->layout(27);
 para.get()->paint(canvas, 300, 300);

Solution

  • As suggested here, try setting default font manager:

    fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
    

    Also check if you have set:

    • Color
    • Font style.setFontFamilies({SkString("Roboto")});
    • Width is enough