Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"rtlm" OpenType feature for RTL mirroring #67

Open
fred-wang opened this issue Sep 23, 2019 · 5 comments
Open

"rtlm" OpenType feature for RTL mirroring #67

fred-wang opened this issue Sep 23, 2019 · 5 comments
Labels
i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. level-2 opentype/tex

Comments

@fred-wang
Copy link
Contributor

This is described in https://mathml-refresh.github.io/mathml-core/#opentype-features :

If on the element the CSS property direction is rtl, then user agents must enable the rtlm OpenType feature on text nodes [OPEN-FONT-FORMAT] unless it contradicts what the page author has specified with the font-feature-settings CSS property.

and in https://mathml-refresh.github.io/mathml-core/#radical-symbol :

The radical glyph is the glyph obtained for the character U+221A SQUARE ROOT, applying the rtlm OpenType feature if the CSS property direction is rtl [OPEN-FONT-FORMAT].

I think we need more experiments / tests for these.

@fred-wang
Copy link
Contributor Author

Consensus from 15 June 2020: remove the text above and move this to level 2.

In addition, I believe we need to perform glyph-level (rtlm) and character-level (Unicode) mirroring to obtain the glyph "corresponding to c" in https://mathml-refresh.github.io/mathml-core/#layout-of-operators ; before calling https://mathml-refresh.github.io/mathml-core/#algorithms-for-glyph-stretching

@NSoiffer
Copy link
Contributor

Since not part of level 1, I have removed the 'needs spec update' label.

@NSoiffer NSoiffer transferred this issue from w3c/mathml Jun 29, 2021
@fred-wang
Copy link
Contributor Author

OK, I'm adding the level-2 label.

@fred-wang
Copy link
Contributor Author

Additional note: Unicode has a Bidi_Mirrored property and some libraries like ICU allows to test that:

https://www.compart.com/en/unicode/mirrored
https://github.com/sillsdev/icu-dotnet/blob/164655115621f06333bfc3d2e4cd1ec2c984063e/source/icu.net/NativeMethods/NativeMethods.cs#L887

(so no need to store a property in the operator dictionary for that, as that was done in Firefox)

@xfq xfq added the i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. label Jul 18, 2023
@fred-wang
Copy link
Contributor Author

fred-wang commented Aug 7, 2024

Testcase demonstrating various cases of math mirroring:

<!DOCTYPE html>
<meta charset="utf-8">
<link
  rel="stylesheet"
  href="https://fred-wang.github.io/MathFonts/XITS/mathfonts.css" />
<style>
  table, th, td {
      border: 1px solid black;
  }
  td.example, math {
      font-size: 32pt;
      font-family: XITS Math;
  }
  .rtlm {
      font-feature-settings: "rtlm";
  }
  .overline {
      text-decoration: overline;
  }
</style>
<h1>RTL math mirroring (<a href="https://github.com/w3c/mathml-core/issues/67">issue #67</a>)</h1>
<p>The following table contains various math examples that involve mirroring of
  some operators.</p>
<p>
  The HTML ones should be supported by modern browsers and
  uses two techniques:
</p>
<ol>
<li>Character-level via Unicode. For example LEFT
  PARENTHESIS U+0028 becomes RIGHT PARENTHESIS U+0029</li>
<li>Glyph-level mirroring via the <a href="https://en.wikipedia.org/wiki/List_of_typographic_features#Features_depending_on_writing_direction">rtlm OpenType feature</a>. This is font-specific, in this case we rely on the
  <a href="https://github.com/fonts/xits-math?tab=readme-ov-file#the-xits-font-project">xits-math.otf font</a>. For example SQUARE ROOT U+221A has glyph name <code>uni221A</code> in that font, for which the <code>rtlm</code> mirrored form is the glyph called <code>uni221A.rtlm</code>.
</li>
</ol>
</p>

<p>The MathML ones contains various examples. For the one doing normal text layout, the HTML mirroring works. But when <a href="https://w3c.github.io/mathml-core/#dfn-shape-a-stretchy-glyph">shaping a stretchy glyph</a> or drawing a <a href="https://w3c.github.io/mathml-core/#layout-of-operators">large operator</a>, MathML Core does not define how to perform the mirroring.</p>

<p>Some browsers (e.g. Firefox) are able to perform glyph-level/character-level
  mirroring of MathML operators ; sometimes even mirroring via a
  "negative" scale transform.
  This latter approach allows to provide a fallback for math fonts that don't
  provide <code>rtlm</code> variants, but does not work for things like
  clockwise integrals and the like.</p>

<table>
  <tr>
    <th>Description</th>
    <th>Mirroring</th>
    <th>English (LTR)</th>
    <th>Arabic (RTL)</th>
  </tr>
  <tr>
    <td rowspan="2">HTML</td>
    <td>character-level via Unicode</td>
    <td class="example">(1,2]</td>
    <td class="example" dir="rtl">(١،٢]</td>
  </tr>
  <tr>
    <td>glyph-level mirroring via <code>rtlm</code></td>
    <td class="example">√<span class="overline">3÷4</span></td>
    <td class="example rtlm" dir="rtl">√<span class="overline">٣÷٤</span></td>
  </tr>
  <tr>
    <td>MathML <code>&lt;mo stretchy="false"&gt;</code></td>
    <td rowspan="2">character-level mirroring via Unicode</td>
    <td class="example">
      <math>
        <mrow>
          <mo stretchy="false">(</mo>
          <mn>1</mn>
          <mo>,</mo>
          <mn>2</mn>
          <mo stretchy="false">]</mo>
        </mrow>
      </math>
    </td>
    <td dir="rtl" class="example">
      <math dir="rtl">
        <mrow>
          <mo stretchy="false">(</mo>
          <mn>١</mn>
          <mo>،</mo>
          <mn>٢</mn>
          <mo stretchy="false">]</mo>
        </mrow>
      </math>
    </td>
  </tr>
  <tr>
    <td>MathML <code>&lt;mo stretchy="true"&gt;</code></td>
    <td class="example">
      <math>
        <mrow>
          <mo>{</mo>
          <mfrac>
            <mn>5</mn>
            <mn>6</mn>
          </mfrac>
          <mo>)</mo>
        </mrow>
      </math>
    </td>
    <td class="example" dir="rtl">
      <math dir="rtl">
        <mrow>
          <mo>{</mo>
          <mfrac>
            <mn>٥</mn>
            <mn>٦</mn>
          </mfrac>
          <mo>)</mo>
        </mrow>
      </math>
    </td>
  </tr>
  <tr>
    <td>MathML <code>&lt;mo largeop="true"&gt;</code></td>
    <td rowspan="2">glyph-level mirroring via <code>rtlm</code></td>
    <td class="example">
      <math displaystyle="true">
        <msub>
          <mo largeop="true">∲</mo>
          <mi>C</mi>
        </msub>
      </math>
    </td>
    <td class="example" dir="rtl">
      <math dir="rtl" displaystyle="true">
        <msub>
          <mo largeop="true">∲</mo>
          <mi>ج</mi>
        </msub>
      </math>
    </td>
  </tr>
  <tr>
    <td>MathML <code>msqrt</code></td>
    <td class="example">
      <math>
        <msqrt>
          <mfrac>
            <mn>3</mn>
            <mn>4</mn>
          </mfrac>
        </msqrt>
      </math>
    </td>
    <td class="example" dir="rtl">
      <math dir="rtl">
        <msqrt>
          <mfrac>
            <mn>٤</mn>
            <mn>٣</mn>
          </mfrac>
        </msqrt>
      </math>
    </td>
  </tr>
</table>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. level-2 opentype/tex
Projects
None yet
Development

No branches or pull requests

3 participants