Some mathvariant choices cannot be emulated via CSS, so they must be implemented via character replacement. These include double-struck, Fraktur, bold Fraktur, script, and bold script.
Created attachment 186277 [details]
A few notes to reviewers about this patch: First, this is all quite new to me, so I wouldn't be surprised if the patch is wildly wrong. Apologies in advance and thanks for any guidance you can give me!
To be completely honest, I took this approach initially as it's a similar situation to CSS text transformations. The issue is that in the case of MathML mathvariant, the transformation is from characters in the BMP to out of the BMP. In practical terms this means that the UTF-16 encoded text value of the RenderText will be a different length than the DOM string (non-BMP characters can take two UTF-16 code units). This causes havoc with the Range and TextIterator classes, leading, for instance, to corrupted paste data.
The issues with Range and TextIterator are probably solvable issues (and probably should be solved), but as I was looking at it, I noticed a startling large amount of yak hair accumulating on the floor. I went instead with this simpler approach that was less correct.
The other thing to notice about this patch is that I did not do mappings for transformations that are now handled via CSS. I hope to do that in a future patch. I see mapping even CSS-emulatable mathvariants as a good thing, because it means that you can copy and paste while maintaining some semantic meaning. The MathML spec stresses that mathvariant carries semantics.
Finally, judging by https://bugzilla.mozilla.org/show_bug.cgi?id=449396 it seems that the mathvariant attribute shouldn't be inherited. This is reflected in my patch. It doesn't look like we support mstyle yet.
Comment on attachment 186277 [details]
Attachment 186277 [details] did not pass mac-wk2-ews (mac-wk2):
Created attachment 186282 [details]
Try to fix the Mac build
Comment on attachment 186282 [details]
Try to fix the Mac build
Clearing the review flag. Daniel and I talked about this patch and my approach is indeed problematic.
To follow-up yesterday discussion and for the record:
- I have the impression that the attribute is still used a lot. I asked to the LaTeXML folks to directly use the Unicode code point but MathJax still relies on mathvariant. So that's why this is blocking the MathJax tracking bug :)
- As Martin said above, mathvariant is available on <mstyle> too. Although I think most of mstyle should be removed (http://lists.w3.org/Archives/Public/www-math/2012Sep/0002.html) I believe mstyle@mathvariant is actually one of the attribute used in real content.
- Like Neil and David said, some characters are invariant to italic change for example U+210E (PLANCK CONSTANT) and the italic style should not be applied to them. Similarly, style="font-weight: bold;" should in theory not apply to e.g. fraktur letters.
- MathJax and Gecko "implements" this via CSS using different fonts. So instead of remapping the Unicode code point, they change the style (italic, bold, font-face). That could be a temporary solution. See http://mxr.mozilla.org/mozilla-central/source/layout/mathml/mathml.css#124
As Dave said, I plan to implement that in Gecko using a private -moz-mathvariant CSS property. Basically, the mathvariant attribute on mstyle and token elements will be mapped to this property and then the text rendering code will use that property to choose the right transform to perform. So I agree with you that this is related to the italic mi issue and could be handled the same way.
(In reply to comment #6)
> As Dave said, I plan to implement that in Gecko using a private -moz-mathvariant CSS property. Basically, the mathvariant attribute on mstyle and token elements will be mapped to this property and then the text rendering code will use that property to choose the right transform to perform. So I agree with you that this is related to the italic mi issue and could be handled the same way.
FYI, James Kitchener has taken over my work and is currently implementing that via -moz-mathvariant CSS property and text transformations:
I was about to try to work on this bug. My plan was:
- add a CSS property mathvariant that is inherited and has initial value "auto".
- rules in mathml.css should be replaced by direct mapping in Source/WebCore/mathml/ for math/mstyle and token elements.
- when mathvariant is "auto", RenderMathMLToken::updateStyle should switch to "italic" for single char <mi> (at the moment it updates the font-style, which is not quite correct and does not work well with inherited mathvariant values)
- add a TextMathTransformer class that would be called in RenderText to do a similar job as applyTextTransform. The RenderStyle will be used to decide the mathvariant.
Now I noticed Martin's comment about the issue with change of string length, so that will need more work in Range and TextIterator...
BTW, Gecko's implementation has more transforms and mathvariant values, see https://hg.mozilla.org/mozilla-central/file/923f1411f42f/layout/generic/MathMLTextRunFactory.cpp. The case of italic/bold/bold-italic is not handled yet (https://bugzilla.mozilla.org/show_bug.cgi?id=930504).
I think this bug becomes important to migrate to MATH fonts, since they don't have separate font files for italic/bold style but only a single font with the mathvariants in the Plane 1.
Created attachment 235110 [details]
font-style=italic in WebKit VS italic math alphanum in Gecko (Latin Modern Math)
Thinking again about how to fix this bug, I believe we could just add a special case in the RenderMathMLToken class to paint mathvariant-transformed characters with a non-standard code path (like what we do for RenderMathMLOperator to draw stretchy operators). For example, it seems we could rely on the TextPainter class for that purpose. Of course, just like RenderMathMLOperator this could cause other issues like (e.g. for selection) but will allow to get correct rendering.
In my opinion, the priority is to support the "automatic mathvariant italic" for single-char <mi> because the current text-style=italic CSS gives poor rendering (cf attachment 235110 [details]).
(In reply to comment #10)
> In my opinion, the priority is to support the "automatic mathvariant italic"
> for single-char <mi> because the current text-style=italic CSS gives poor
> rendering (cf attachment 235110 [details]).
This one is now done in Alex's MathMLLayout branch.