Bug 51596 - [PATCH] Cleanup and tests to TTFFile (subsetting Glyf)
Summary: [PATCH] Cleanup and tests to TTFFile (subsetting Glyf)
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: fonts (show other bugs)
Version: 1.0
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-01 15:17 UTC by Mehdi Houshmand
Modified: 2012-03-28 08:43 UTC (History)
0 users



Attachments
Cleanup and tests (25.24 KB, patch)
2011-08-01 15:17 UTC, Mehdi Houshmand
Details | Diff
Glyf Table (25.71 KB, patch)
2011-08-03 10:47 UTC, Mehdi Houshmand
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mehdi Houshmand 2011-08-01 15:17:59 UTC
Created attachment 27338 [details]
Cleanup and tests

This patch cleans up and adds some high level tests for the Glyf subsetting in TTFFile.
Comment 1 Simon Pepping 2011-08-01 18:52:11 UTC
Thanks for this work. Glyph is written with 'ph', not with 'f'.
Comment 2 Mehdi Houshmand 2011-08-01 19:25:37 UTC
Hi Simon,
Yeah, Glyf refers to the table within a TrueType font, not a glyph. I've discerned the difference between the two by spelling the table-name as it is represented in the font, as "glyf".

Hope that makes sense

Mehdi
Comment 3 Simon Pepping 2011-08-03 08:03:11 UTC
Thanks for your explanation.

The title suggests that the patch cleans up something; it does not; it implements a redesign.

Without knowing much detail about Glyf tables, I was a bit surprised about the method names GlyfFlags.offsetToNextComposedGlyf(int flags) and GlyfFlags.moreComposites(int flags). At first sight it suggests that there is some hidden iterator. After some more thought, I assume that flags contains pointers to data in the table, and that these allow one to calculate the extent of this glyf; if that is so, then offsetToNextComposedGlyf may be better called extentOfComposedGlyf.

Otherwise the design seems fine, but I am not able to judge about the correctness of the code.
Comment 4 Mehdi Houshmand 2011-08-03 08:40:41 UTC
Hi Simon,
I guess it's best to address each of these, individually:

>The title suggests that the patch cleans up something; it does not; it
>implements a redesign.

Well, I guess so, the reason I call it clean up is because previously there was a lot of duplicated code, magic numbers, poorly named variables... all the big names. I started it with the intention of not changing the working code, but as I got into it, it seemed that there the old code was iterating over the whole of the subset glyph list several times... A job that could have been made simpler through recursion. I didn't redesign it, because if I were to do so, I would have changed FontFileReader by removing the write method, and remapping the glyphs when the glyph data is extracted from "glyf". (see the TODO)

>Without knowing much detail about Glyf tables, I was a bit surprised about the
>method names GlyfFlags.offsetToNextComposedGlyf(int flags)...

Ok, for this you have to read the TTF spec. But, the flags represent the properties and parameters of the composed glyph and, depending on which flags are set, the number of bytes until the next glyph data.. That method returns the offset to the next composed by reading which flags are set, and which aren't. Since none of the glyph parameters are changed, we just want the offset to the next composed glyph.

> GlyfFlags.moreComposites(int flags)

This analyses the flags, checks whether the current data is the last glyph in the "glyf" data we are reading. It is simply used to control the do-while loop.

Hope that helps, the glyf table spec can be found at: http://www.microsoft.com/typography/otspec/glyf.htm

I think this change more is more consistent with the spec, since composite glyphs can be recursive, it seemed prudent to me to clean-up/redesign the code to match that.
Comment 5 Mehdi Houshmand 2011-08-03 10:47:20 UTC
Created attachment 27345 [details]
Glyf Table

Added javadocs to GlyfFlags and changed the method name to make it less ambiguous.
Comment 6 Simon Pepping 2011-08-03 17:06:10 UTC
Thanks for your explanations. Note that I will not commit this patch. I will leave that to committers who are more knowledgable about fonts.
Comment 7 Vincent Hennebert 2011-08-08 17:52:07 UTC
So a test was possible after all, this is great news. I've applied the patch with minor modifications to make the test run consistently on (hopefully) all JVMs. (I replaced two HashMap with TreeMap.)

Thanks!
Vincent