Strike/Line Through position in SkParagraph

39 views
Skip to first unread message

Hemanth

unread,
Jun 18, 2025, 8:43:10 AM6/18/25
to skia-discuss
Hi team,

I'm trying to render Strike through for text using SkParagraph
But it seems it is not drawing exactly at center like Notes in mac
I checked for different fonts but still it is not drawing center for most of them.
Is it default behaviour of Skia or can we change it?

I checked for "Roboto", "Droid Sans", "Open Sans", "Archivo" and "DejaVu Sans" fonts
Screenshot 2025-06-18 at 5.51.17 PM.png
as you can see Strike Though position is not exactly at center


I have tried like
TextStyle textStyle;
textStyle.setFontSize(10);
textStyle.setFontFamily({SkString("Roboto")}); 
textStyle.setTextDecoration(TextDecoration::kLineThrough);

ParagraphStyle paraStyle;
paraStyle.setTextAlign(TextAlign::kLeft);
paraStyle.setMaxLines(1);

sk_sp<FontCollection> fontCollection = sk_make_sp<FontCollection>();
fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());

auto builder = ParagraphBuilder::make(paraStyle, fontCollection);
builder->pushStyle(textStyle);
builder->addText("Some Strike through text");
builder->pop();

std::shared_ptr<Paragraph> paragraph = builder->Build();
paragraph->layout(1000);
paragraph.get()->paint(canvas, contentRect.left(), contentRect.top());

Is there any better way to draw strike through using SkParagraph?

Thank you,
Hemanth.


Reply all
Reply to author
Forward
0 new messages