Bug 130321 - Operator stretching: add hardcoded MATH data
Summary: Operator stretching: add hardcoded MATH data
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: MathML (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: http://www.ntg.nl/maps/38/03.pdf
Keywords:
Depends on:
Blocks: 122297 130322
  Show dependency treegraph
 
Reported: 2014-03-17 00:04 PDT by Frédéric Wang (:fredw)
Modified: 2014-06-05 22:40 PDT (History)
10 users (show)

See Also:


Attachments
Python script to extract the MATH data from the STIX Math & Latin Modern Math fonts (6.36 KB, text/x-python)
2014-03-17 01:30 PDT, Frédéric Wang (:fredw)
no flags Details
Patch (88.90 KB, patch)
2014-03-17 02:09 PDT, Frédéric Wang (:fredw)
no flags Details | Formatted Diff | Diff
Attempt to implement FontPlatformData::openTypeTable on Mac (1.41 KB, patch)
2014-03-21 00:49 PDT, Frédéric Wang (:fredw)
no flags Details | Formatted Diff | Diff
Attempt 2 to implement FontPlatformData::openTypeTable on Mac (1.43 KB, patch)
2014-03-21 01:03 PDT, Frédéric Wang (:fredw)
no flags Details | Formatted Diff | Diff
Attempt 3 to implement FontPlatformData::openTypeTable on Mac (1.47 KB, patch)
2014-03-21 01:06 PDT, Frédéric Wang (:fredw)
no flags Details | Formatted Diff | Diff
Attempt 4 to implement FontPlatformData::openTypeTable on Mac (1.46 KB, patch)
2014-03-21 01:17 PDT, Frédéric Wang (:fredw)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frédéric Wang (:fredw) 2014-03-17 00:04:32 PDT
I'm splitting attachment 226844 [details] for review.

The first step is to create the OpenTypeMathData class with associated hardcoded data for STIX and Latin Modern.
Comment 1 Frédéric Wang (:fredw) 2014-03-17 01:30:58 PDT
Created attachment 226895 [details]
Python script to extract the MATH data from the STIX Math & Latin Modern Math fonts
Comment 2 Frédéric Wang (:fredw) 2014-03-17 02:09:59 PDT
Created attachment 226896 [details]
Patch
Comment 3 Frédéric Wang (:fredw) 2014-03-18 10:57:47 PDT
I discussed that with Martin, and I'd like to get feedback on the right approach. In bug 99620 comment 5, I was told to use a sorted hardcoded constant array to implement the MathML dictionary. So I did the same approach here. However, I wonder if the situation here is a bit different and if I should try to integrate a script into the build system to generate HardCodedMathData.h?

Some things to consider:

1) These hardcoded data are only expected to be used on platforms that can not read the OpenType MATH table directly. I intend to replace them with direct access to the MATH table in bug 130324, for all but the Mac port. Does anyone think it would be possible to use some font libraries to read OpenType tables on Mac?

2) STIXMath does not have italic correction yet (http://sourceforge.net/p/stixfonts/tracking/50/). So at the moment that will mean bad placement of subscripts attached to displaystyle operator (especially slanted integrals). So the hardcoded data could still be useful in that case (even for fonts that can read the MATH table). However, I think we want to recommend Latin Modern Math as the default, which gives better rendering.

3) The dependencies for the script are Python & its fontforge module.
Comment 4 chris fleizach 2014-03-19 09:31:29 PDT
(In reply to comment #3)
> I discussed that with Martin, and I'd like to get feedback on the right approach. In bug 99620 comment 5, I was told to use a sorted hardcoded constant array to implement the MathML dictionary. So I did the same approach here. However, I wonder if the situation here is a bit different and if I should try to integrate a script into the build system to generate HardCodedMathData.h?

Do you foresee this data changing often (ever?)

> 
> Some things to consider:
> 
> 1) These hardcoded data are only expected to be used on platforms that can not read the OpenType MATH table directly. I intend to replace them with direct access to the MATH table in bug 130324, for all but the Mac port. Does anyone think it would be possible to use some font libraries to read OpenType tables on Mac?
> 

Do you have something in mind already? or are you asking if facilities already exist with platform API to read open type data?

> 2) STIXMath does not have italic correction yet (http://sourceforge.net/p/stixfonts/tracking/50/). So at the moment that will mean bad placement of subscripts attached to displaystyle operator (especially slanted integrals). So the hardcoded data could still be useful in that case (even for fonts that can read the MATH table). However, I think we want to recommend Latin Modern Math as the default, which gives better rendering.
> 
> 3) The dependencies for the script are Python & its fontforge module.
Comment 5 chris fleizach 2014-03-19 09:37:38 PDT
Comment on attachment 226896 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=226896&action=review

> Source/WebCore/platform/graphics/SimpleFontData.h:126
> +    bool hasMathData() const { return m_hasMathData; }

doesn't seem like it's too much of a win to cache this value, and it duplicates hasMathData() in two places (here and in m_mathData->hasMathData())

> Source/WebCore/platform/graphics/opentype/OpenTypeMathData.cpp:91
> +        ASSERT(m_mathFont == STIXMath);

will this fail if your math font is 
m_mathFont = UnknownFont;
if 
m_mathFont = UnknownFont;
is an unexpected state, perhaps you should assert there as well?

> Source/WebCore/platform/graphics/opentype/OpenTypeMathData.h:47
> +    // The order of the constants must match the order of the fields defined in the MATH table.

does the value of enum also matter, or is it only the relative order that matters?
Comment 6 Frédéric Wang (:fredw) 2014-03-19 09:49:29 PDT
(In reply to comment #4)

> Do you foresee this data changing often (ever?)

These data will need to be regenerated when new versions of Latin Modern Math and STIX Math are released, but I think new version of fonts do not happen so often.

Also, if that happens that will break backwards compatibility with old version of the fonts, so that hardcoded data approach is actually not desirable. That's just a first step because I could not find how to do otherwise on Mac but I hope we won't keep that in the long term. I think Apple could ensure synchronization with the font installed on Mac and the hardcoded data in WebKit but that will be a bit tedious.

> 
> > 
> > Some things to consider:
> > 
> > 1) These hardcoded data are only expected to be used on platforms that can not read the OpenType MATH table directly. I intend to replace them with direct access to the MATH table in bug 130324, for all but the Mac port. Does anyone think it would be possible to use some font libraries to read OpenType tables on Mac?
> > 
> 
> Do you have something in mind already? or are you asking if facilities already exist with platform API to read open type data?

I already know that I have an API on Linux (I tested the EFL and GTK ports) and I believe it also works on some Windows version (not tested). This is done in bug 130324 and the flag is #if USE(FREETYPE) || (PLATFORM(WIN) && (USE(CG) || USE(CAIRO)))

I have no ideas if the Mac port of WebKit can handle that and don't have a Mac to test anyway. However, for Gecko I've been able to read the OpenType MATH table using Harfbuzz (used on Mac too). I believe Blink is migrating to Harfbuzz on all platforms and I wonder if there are similar plans for the Mac port of WebKit. Or perhaps anyone knows how to do that with the current Mac API available?
Comment 7 chris fleizach 2014-03-20 17:49:15 PDT
(In reply to comment #6)
> (In reply to comment #4)
> 
> > Do you foresee this data changing often (ever?)
> 
> These data will need to be regenerated when new versions of Latin Modern Math and STIX Math are released, but I think new version of fonts do not happen so often.
> 
> Also, if that happens that will break backwards compatibility with old version of the fonts, so that hardcoded data approach is actually not desirable. That's just a first step because I could not find how to do otherwise on Mac but I hope we won't keep that in the long term. I think Apple could ensure synchronization with the font installed on Mac and the hardcoded data in WebKit but that will be a bit tedious.
> 
> > 
> > > 
> > > Some things to consider:
> > > 
> > > 1) These hardcoded data are only expected to be used on platforms that can not read the OpenType MATH table directly. I intend to replace them with direct access to the MATH table in bug 130324, for all but the Mac port. Does anyone think it would be possible to use some font libraries to read OpenType tables on Mac?
> > > 
> > 
> > Do you have something in mind already? or are you asking if facilities already exist with platform API to read open type data?
> 
> I already know that I have an API on Linux (I tested the EFL and GTK ports) and I believe it also works on some Windows version (not tested). This is done in bug 130324 and the flag is #if USE(FREETYPE) || (PLATFORM(WIN) && (USE(CG) || USE(CAIRO)))
> 
> I have no ideas if the Mac port of WebKit can handle that and don't have a Mac to test anyway. However, for Gecko I've been able to read the OpenType MATH table using Harfbuzz (used on Mac too). I believe Blink is migrating to Harfbuzz on all platforms and I wonder if there are similar plans for the Mac port of WebKit. Or perhaps anyone knows how to do that with the current Mac API available?

Are you going to attempt the Mac side of this? Or do we need to open a bug to track doing that work
Comment 8 Frédéric Wang (:fredw) 2014-03-20 23:27:33 PDT
(In reply to comment #7)
> Are you going to attempt the Mac side of this? Or do we need to open a bug to track doing that work

If we can read the table on Mac, then I think we can forget about hardcoded data, WONTFIX the bug and merge the remaining changes into bug 130324. I'll try to read more about the Mac API first.

The implementation of FontPlatformData::openTypeTable in Mac is actually orthogonal to the MATH font support and could be done in a separate bug. As I understand, this is what is preventing OPENTYPE_VERTICAL to be enabled on Mac and so is causing some test failures. See
https://bugs.webkit.org/show_bug.cgi?id=51450
http://trac.webkit.org/browser/trunk/LayoutTests/platform/mac/TestExpectations#L542
Comment 9 Frédéric Wang (:fredw) 2014-03-21 00:49:17 PDT
Created attachment 227391 [details]
Attempt to implement FontPlatformData::openTypeTable on Mac
Comment 10 Frédéric Wang (:fredw) 2014-03-21 01:03:30 PDT
Created attachment 227395 [details]
Attempt 2 to implement FontPlatformData::openTypeTable on Mac
Comment 11 Frédéric Wang (:fredw) 2014-03-21 01:06:53 PDT
Created attachment 227396 [details]
Attempt 3 to implement FontPlatformData::openTypeTable on Mac
Comment 12 Frédéric Wang (:fredw) 2014-03-21 01:17:28 PDT
Created attachment 227397 [details]
Attempt 4 to implement FontPlatformData::openTypeTable on Mac
Comment 13 chris fleizach 2014-03-21 09:02:16 PDT
Comment on attachment 227397 [details]
Attempt 4 to implement FontPlatformData::openTypeTable on Mac

View in context: https://bugs.webkit.org/attachment.cgi?id=227397&action=review

> Source/WebCore/platform/graphics/FontPlatformData.cpp:30
> +#if OS(DARWIN)

OS(DARWIN) might be correct, but my first guess would have been to use
PLATFORM(COCOA)

> Source/WebCore/platform/graphics/FontPlatformData.cpp:32
> +#include <ApplicationServices/ApplicationServices.h>

I think you want to import <CoreGraphics/CGFont.h>
for this usage. That should make it work on iOS as well

> Source/WebCore/platform/graphics/FontPlatformData.cpp:181
> +    CFDataRef data = CGFontCopyTableForTag(font, table);

no need to store CGFontRef font

if (CFDataRef data = CGFont(cgFont(), table))
    return SharedBuffer...

return nullptr;
Comment 14 Frédéric Wang (:fredw) 2014-03-21 09:05:20 PDT
(In reply to comment #13)
> (From update of attachment 227397 [details])

Thanks for the comment. I've moved the changes to bug 130572. And I'll WONTFIX bug 130321 if it turns out that we finally don't need these hardcoded data.
Comment 15 Frédéric Wang (:fredw) 2014-06-05 22:40:38 PDT
WONTFIX since we will directly read the MATH table.