How to write Arabic strings in the right direction right to left.

256 views
Skip to first unread message

Heidi Kurz

unread,
Apr 12, 2021, 8:17:25 AM4/12/21
to skia-discuss
Hi Together,

we use the method 
SkTextUtils::DrawString(...)
to draw our strings.  
Unfortunately when we try to write our arabic strings it`s written from left to right and not from right to left. 
What I have to do to write this in correct direction?

Thanks for help, 
 

Ben Wagner

unread,
Apr 12, 2021, 9:42:50 AM4/12/21
to skia-d...@googlegroups.com
As Skia is used more externally and internationally, the API should
rename almost every API with "Text" in the name as "Toy". You will
want to use SkShaper or SkParagraph to do any text layout which isn't
a label in a test image.
> --
> 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/ac302163-cc48-4ee4-9ac9-efe07ffb3f7an%40googlegroups.com.

Heidi Kurz

unread,
Apr 13, 2021, 7:27:12 AM4/13/21
to skia-discuss
Thanks for your answer. 
I found SkShaper and SkParagraph in the subdirectory modules. So it seems not a part of the core Skia library.
Have you any example how to use this classes to write arabic strings in a correct way?

Ben Wagner

unread,
Apr 13, 2021, 9:53:58 AM4/13/21
to skia-d...@googlegroups.com
In samplecode/SampleTextBox.cpp there is a simple example of how to
use SkShaper. In modules/skparagraph/gm/simple_gm.cpp there is a
simple example of how to use SkParagraph.
> To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/3068aca9-148d-4eb3-8346-c8095e2e42e4n%40googlegroups.com.

Heidi Kurz

unread,
Apr 19, 2021, 6:07:21 AM4/19/21
to skia-discuss
Hi, I use now SkShaper to write our strings. 
I wrote a method which contains this code: 

   SkTextBlobBuilderRunHandler builder(str, { 0, 0 });
    auto bidi = SkShaper::TrivialBiDiRunIterator(0, len);
    auto language = SkShaper::TrivialLanguageRunIterator("ar-SA", len);
    constexpr SkFourByteTag latn = SkSetFourByteTag('l', 'a', 't', 'n');
    auto script = SkShaper::TrivialScriptRunIterator(latn, len);
    auto fontIterator = SkShaper::TrivialFontRunIterator(skfont, len);
    shaper->shape(str, len, fontIterator, bidi, script, language, 2000, &builder);
    canvas->drawTextBlob(builder.makeBlob(),xx, yy, skPaint);



But when I try to write our arabic strings, it's still in the wrong direction.
abudhabi.PNG


Is there any attribute or property what I have to set in the method?
Unfortunately there is no documentation about SkShaper.
I would really very glad when somebody could help me.

BR, Heidi


Shachar Langbeheim

unread,
Apr 19, 2021, 6:49:12 AM4/19/21
to skia-discuss
constexpr SkFourByteTag latn = SkSetFourByteTag('l', 'a', 't', 'n'); -> that's the latin script tag. Try using 'Z','y','y','y' for undetermined script or `a','r','a','b' for arabic.
https://github.com/harfbuzz/icu-le-hb/blob/master/src/ScriptAndLanguageTags.cpp

Heidi Kurz

unread,
Apr 19, 2021, 7:38:01 AM4/19/21
to skia-discuss
OK, I tried this out, look at my code:

 SkTextBlobBuilderRunHandler builder(str, { 0, 0 });
    auto bidi = SkShaper::TrivialBiDiRunIterator(0, len);
    auto language = SkShaper::TrivialLanguageRunIterator("ARA", len);
    constexpr SkFourByteTag byteTag = SkSetFourByteTag('a', 'r', 'a', 'b');
    auto script = SkShaper::TrivialScriptRunIterator(byteTag, len);
    auto fontIterator = SkShaper::TrivialFontRunIterator(skfont, len);
    shaper->shape(str, len, fontIterator, bidi, script, language, 2000, &builder);
    canvas->drawTextBlob(builder.makeBlob(),xx, yy, skPaint);


But it doesn't work! 
The Arabian strings are still in the wrong direction. 

Ben Wagner

unread,
Apr 19, 2021, 10:54:23 AM4/19/21
to skia-d...@googlegroups.com
Perhaps I should have specified, the 'Trivial' classes in shaper are actually trivial, in that they don't actually do any real work. These 'Trivial' versions exist mostly for testing and a replacement for the old SkTextBox which was removed some time ago. You will need to use the classes that are in the 'ifdef' blocks in SkShaper.h for anything real to happen (probably exactly as samplecode/SampleTextBox.cpp does).

Heidi Kurz

unread,
Apr 20, 2021, 2:52:48 AM4/20/21
to skia-discuss
Thanks for your answer. 
Now I have an method which works.  
I found out that I also need a file called icudtl.dat in my current directory. 
This is need when I try this
fShaper = SkShaper::Make(fontmgr);

Only when I have icudtl.dat it really works. 
Reply all
Reply to author
Forward
0 new messages