Skia's HelloWorld example does not draw text

605 views
Skip to first unread message

Данил Буланов

unread,
Oct 24, 2023, 8:49:42 AM10/24/23
to skia-discuss
Hello, I am exploring skia, and I managed to download deps and compile skia. And now I am trying to run HelloWorld example. But there is a problem -- the text is not drawn. The circle and rect are drawn as expected, but there is no text. I am running it on linux, there is a screenshot of what I got when launch this example

photo_2023-10-24_12-42-07.jpg
Is there any clue to why there is no text?

jlav...@google.com

unread,
Oct 24, 2023, 9:31:38 AM10/24/23
to skia-discuss
Usually it's one of the two reasons: 
1. The text is drawn as white on white, missed text style  setForegroundColor(SkPaint) or setColor(SkColor). Default text color is white...
2. Font is not found and there is no fallback font
If it's not one of these two, send the code, please

Данил Буланов

unread,
Oct 24, 2023, 10:25:02 AM10/24/23
to skia-discuss
Great, now it works, I just added this lines to the example
auto tf = SkTypeface::MakeFromFile("example/Inter-Regular.ttf");
and
font.setTypeface(tf);

But I suspect that developers expect it to work even without pointing the typeface? So I guess in my case there is no fallback font available? Can you elaborate on this fallback font resolution, where does it come from?
вторник, 24 октября 2023 г. в 16:31:38 UTC+3, skia-discuss:

Jim Van Verth

unread,
Oct 24, 2023, 10:31:09 AM10/24/23
to skia-d...@googlegroups.com
This is the code to set up the font in HelloWorld.cpp:

    // Draw a message with a nice black paint

    SkFont font;

    font.setSubpixel(true);

    font.setSize(20);

    paint.setColor(SK_ColorBLACK);

Julia, is there some modification we should do to this to ensure a default font is available?

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/1395de90-6a89-4d47-bb68-908a07794b0en%40googlegroups.com.


--

Jim Van Verth |
 Software Engineer | Google.com

jlav...@google.com

unread,
Oct 24, 2023, 10:56:12 AM10/24/23
to skia-discuss
Font fallback depends on a platform and a system configuration and cannot be used reliably.
Some clients may have certain fonts, some may not and in the end you simply don't know what your text will look like (in bad cases it may not show up at all).
So be careful with this feature.
Font fallback resolution works well when there are fonts available. It would work on Linux, for instance (where we use a list of system fonts) but it would not work in CanvasKit (where you have to load all fonts yourself).
You can take a look at https://skia.googlesource.com/skia/+/refs/heads/main/modules/skparagraph/slides/ParagraphSlide.cpp, there are many examples of font fallback usage.
All it takes (provided, default font manager has a list of fonts loaded from somewhere):
        auto fontCollection = sk_make_sp<FontCollection>();
        fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
        fontCollection->enableFontFallback();
And now you do not have to set font family in text style at all unless you need a certain order. If there are fonts that can show the text SkParagraph will pick the first available and will use it.
It's very convenient and even more unpredictable (it depends even on the order in which system fonts are loaded).

jlav...@google.com

unread,
Oct 24, 2023, 10:57:58 AM10/24/23
to skia-discuss
We never promise default font available and we always work with what we have (or rather what a user have).
It depends on a user's system configuration. 

On Tuesday, October 24, 2023 at 10:31:09 AM UTC-4 Jim Van Verth wrote:

Greg Daniel

unread,
Oct 24, 2023, 10:59:33 AM10/24/23
to skia-d...@googlegroups.com
Don't we have some sort of very simple font that we use on a lot of test GMs so that they look the same across platforms? Can we use/setup that font for this example as well?

jlav...@google.com

unread,
Oct 24, 2023, 11:05:36 AM10/24/23
to skia-discuss
A user can do it himself. We do not provide any font, we only use what is available. For instance, in CanvasKit not fonts available by default so it's a user responsibility to load whatever he needs.

Greg Daniel

unread,
Oct 24, 2023, 11:10:31 AM10/24/23
to skia-d...@googlegroups.com
Sure but this is our sample HelloWorld example that we are shipping with Skia. We are the "client" writing a think against Skia here.

jlav...@google.com

unread,
Oct 24, 2023, 11:17:43 AM10/24/23
to skia-discuss
Yes, you are right. I didn't realize where the example came from. I will fix it once I figure out how.

aiz berg

unread,
Oct 26, 2023, 8:43:40 AM10/26/23
to skia-discuss
But in canvaskit this code seems to work (without any fonts):

const font = new CanvasKit.Font(null, 25);
canvas.drawText(`Some text`, 5, 25, fontPaint, font);


вторник, 24 октября 2023 г. в 18:05:36 UTC+3, jlav...@google.com:
Reply all
Reply to author
Forward
0 new messages