8000 Add glyf flags bit6 to ttx output by jenskutilek · Pull Request #1316 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add glyf flags bit6 to ttx output #1316

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

Merged
merged 4 commits into from
Sep 14, 2018
Merged

Add glyf flags bit6 to ttx output #1316

merged 4 commits into from
Sep 14, 2018

Conversation

jenskutilek
Copy link
Collaborator

Bit 6 of the flags of the first outline point in a glyph, indicating that there are overlaps in the glyph’s contours, got lost when roundtripping with ttx.

This patch preserves bit 6 in the most simple way, by adding it as an attribute of its contour point:

    <TTGlyph name="A" xMin="12" yMin="0" xMax="1172" yMax="1430">
      <contour>
        <pt x="501" y="1430" on="1" overlap="1"/>
        <pt x="683" y="1430" on="1"/>
        <pt x="1172" y="0" on="1"/>
        <pt x="983" y="0" on="1"/>
        <pt x="591" y="1193" on="1"/>
        <pt x="199" y="0" on="1"/>
        <pt x="12" y="0" on="1"/>
      </contour>
      <contour>
        <pt x="249" y="514" on="1"/>
        <pt x="935" y="514" on="1"/>
        <pt x="935" y="352" on="1"/>
        <pt x="249" y="352" on="1"/>
      </contour>
      <instructions/>
    </TTGlyph>

See issue #730.

@@ -263,6 +263,9 @@ def __len__(self):
flagReserved1 = 0x40
flagReserved2 = 0x80

# These flags are kept for XML output after decompiling the coordinates
keepFlags = flagOnCurve + flagReserved1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t flagReserved1 be renamed now? It is no longer a reserved flag in the current version of the spec (OVERLAP_SIMPLE in https://docs.microsoft.com/en-us/typography/opentype/spec/glyf).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

("on", self.flags[j] & flagOnCurve),
]
if self.flags[j] & flagReserved1:
# Apple's AAT uses flagReserved1 in the first contour/first pt to flag glyphs that contain overlapping contours
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an Apple rasterizer feature rather than an AAT-specific one (i.e. not related to layout tables being used).

flags.append(not not safeEval(attrs["on"]))
flag = not not safeEval(attrs["on"])
if "overlap" in attrs:
f = safeEval(attrs["overlap"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the same trick as in the line above for the on flag, by negating twice to obtain a boolean, or just call bool.

flag = not not safeEval(attrs["on"])
if "overlap" in attrs:
f = safeEval(attrs["overlap"])
flag += f * flagReserved1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use "or" bitwise operator instead of "+" here: flag |= f * flagReserved1
let's rename flagReserved1 to OVERLAP_SIMPLE

return re.sub(' ttLibVersion=".*"', '', string)


class glyfTableTest(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest of the tests in this file already use pytest-style tests (with plain assert statements), I would prefer that over unittest-style tests.. but anyway some tests is better than none, thanks anyway.

font['head'] = newTable('head')
font['loca'] = newTable('loca')
font['maxp'] = newTable('maxp')
font['maxp'].data = self.maxpData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you set data attribute here? I don't think it's needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was necessary, but actually isn’t. The only important thing is the tables need to be decompiled in the correct order because they depend on each other.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right

Copy link
Member
@anthrotype anthrotype left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, we can merge after the CI completes

@anthrotype
Copy link
Member

oh .. and what about the similar OVERLAP_COMPOUND flag? Don't we want to expose that too?

@jenskutilek
Copy link
Collaborator Author

oh .. and what about the similar OVERLAP_COMPOUND flag? Don't we want to expose that too?

That flag is at least already preserved because components show the flags as hex numbers in ttx:

    <TTGlyph name="Adieresis" xMin="-6" yMin="0" xMax="1495" yMax="1845">
      <component glyphName="A" x="0" y="0" flags="0x604"/>
      <component glyphName="dieresis.cap" x="233" y="0" flags="0x4"/>
    </TTGlyph>

Perhaps we should display all the flags in more human readable form here?

@anthrotype
Copy link
Member

Right ok. I’d say let’s keep it as is for now

@anthrotype anthrotype merged commit 7c8077a into master Sep 14, 2018
@anthrotype anthrotype deleted the glyf-flags-bit6 branch September 14, 2018 13:28
@jenskutilek
Copy link
Collaborator Author

Thanks!

@anthrotype
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0