Skip to content

Misaligned RTL Text #27

@wolfmcnally

Description

@wolfmcnally

I am experimenting with this example of Arabic text:

    const divStyle: flow.DeclaredStyle = {
      direction: 'rtl',
    };

    const h = flow.h;
    const string = 'أية تقنية متقدمة بما فيه الكفاية لا يمكن تمييزها عن السحر.';

    const elem = h('div', { style: divStyle }, string);

    const root = flow.dom(elem);

    const container: flow.BlockContainer = flow.generate(root);
    flow.layout(container, 200, 200);
    let svg = flow.paintToSvg(container);
    console.log(beautifySvg(svg));

Which is outputting the following SVG:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
    <style type="text/css">@font-face {
    font-family: "Noto Sans Arabic";
    font-weight: 400;
    font-style: normal;
    font-stretch: normal;
    src: url("https://fonts.cdnfonts.com/css/noto-sans-arabic") format("opentype");
}</style>
    <defs>
    </defs>
    <text x="3.632000000000005" y="21.984" style="font: normal 400 normal 16px Noto Sans Arabic; white-space: pre; direction: rtl; unicode-bidi: bidi-override" fill="rgba(0, 0, 0, 1)">أية تقنية متقدمة بما فيه الكفاية</text>
    <text x="32.591999999999985" y="55.776" style="font: normal 400 normal 16px Noto Sans Arabic; white-space: pre; direction: rtl; unicode-bidi: bidi-override" fill="rgba(0, 0, 0, 1)">لا يمكن تمييزها عن السحر.</text>
</svg>

Which renders off the left side of the viewbox:

image

If I make the viewbox bigger:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="-200 0 400 200">
    <style type="text/css">@font-face {
    font-family: "Noto Sans Arabic";
    font-weight: 400;
    font-style: normal;
    font-stretch: normal;
    src: url("https://fonts.cdnfonts.com/css/noto-sans-arabic") format("opentype");
}</style>
    <defs>
    </defs>
    <text x="3.632000000000005" y="21.984" style="font: normal 400 normal 16px Noto Sans Arabic; white-space: pre; direction: rtl; unicode-bidi: bidi-override" fill="rgba(0, 0, 0, 1)">أية تقنية متقدمة بما فيه الكفاية</text>
    <text x="32.591999999999985" y="55.776" style="font: normal 400 normal 16px Noto Sans Arabic; white-space: pre; direction: rtl; unicode-bidi: bidi-override" fill="rgba(0, 0, 0, 1)">لا يمكن تمييزها عن السحر.</text>
</svg>

I can see the full text, each line is laid out right to left correctly, but clearly the positioning is wrong.

image

If I remove the white-space: pre; direction: rtl; unicode-bidi: bidi-override directives:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
    <style type="text/css">@font-face {
    font-family: "Noto Sans Arabic";
    font-weight: 400;
    font-style: normal;
    font-stretch: normal;
    src: url("https://fonts.cdnfonts.com/css/noto-sans-arabic") format("opentype");
}</style>
    <defs>
    </defs>
    <text x="3.632000000000005" y="21.984" style="font: normal 400 normal 16px Noto Sans Arabic;" fill="rgba(0, 0, 0, 1)">أية تقنية متقدمة بما فيه الكفاية</text>
    <text x="32.591999999999985" y="55.776" style="font: normal 400 normal 16px Noto Sans Arabic;" fill="rgba(0, 0, 0, 1)">لا يمكن تمييزها عن السحر.</text>
</svg>

Then the text is properly right-aligned, but the second line's punctuation is on the wrong end.

image

Is this a bug or am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions