8000 Remove .Format from Coverage, ClassDef, SingleSubst, LigatureSubst, AlternateSubst by behdad · Pull Request #2238 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove .Format from Coverage, ClassDef, SingleSubst, LigatureSubst, AlternateSubst #2238

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 14 commits into from
Mar 24, 2021

Conversation

behdad
Copy link
Member
@behdad behdad commented Mar 23, 2021

From fb0c60c#issuecomment-805132445

Initially ~470 tests failed. I fixed all; expect for 25 mtiLib tests still fail. I don't understand why. Help appreciated.

@anthrotype
Copy link
Member

in mti_test.py, if you move the order in which you dump to ttx and compile the table (by moving the dump from built table before the table.compile), then you get the expected ttx output (without Formats). I think it's because the preWrite methods called by compile re-add the Format attrs, so if you dump after a compile you still get those..

diff --git a/Tests/mtiLib/mti_test.py b/Tests/mtiLib/mti_test.py
index 1666dd45..6704751e 100644
--- a/Tests/mtiLib/mti_test.py
+++ b/Tests/mtiLib/mti_test.py
@@ -174,13 +174,6 @@ class MtiTest(unittest.TestCase):
             self.assertEqual(tableTag, table.tableTag)
         tableTag = table.tableTag

-        # Make sure it compiles.
-        blob = table.compile(font)
-
-        # Make sure it decompiles.
-        decompiled = table.__class__()
-        decompiled.decompile(blob, font)
-
         # XML from built object.
         writer = XMLWriter(StringIO(), newlinestr='\n')
         writer.begintag(tableTag); writer.newline()
@@ -188,6 +181,13 @@ class MtiTest(unittest.TestCase):
         writer.endtag(tableTag); writer.newline()
         xml_built = writer.file.getvalue()

+        # Make sure it compiles.
+        blob = table.compile(font)
+
+        # Make sure it decompiles.
+        decompiled = table.__class__()
+        decompiled.decompile(blob, font)
+
         # XML from decompiled object.
         writer = XMLWriter(StringIO(), newlinestr='\n')
         writer.begintag(tableTag); writer.newline()

@anthrotype
Copy link
Member

there's still one mtiLib test failing after I apply the above patch though.. Should you also del self.Format in MultipleSubst maybe?

Tests/mtiLib/mti_test.py::MtiTest::test_MtiFile_mti/gsubmultiple_GSUB FAILED [100%]

==================================== FAILURES ====================================
___________________ MtiTest.test_MtiFile_mti/gsubmultiple_GSUB ___________________

self = <mti_test.MtiTest testMethod=test_MtiFile_mti/gsubmultiple_GSUB>

>   return lambda self: self.check_mti_file(os.path.join(*name.split('/')), tableTag=tableTag)

Tests/mtiLib/mti_test.py:220:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Tests/mtiLib/mti_test.py:198: in check_mti_file
    self.expect_ttx(xml_binary,   xml_built, fromfile='decompiled',      tofile='built')
Tests/mtiLib/mti_test.py:154: in expect_ttx
    self.fail("TTX output is different from expected")
E   AssertionError: TTX output is different from expected
------------------------------ Captured stderr call ------------------------------

--- decompiled
+++ built
@@ -7,7 +7,7 @@
       <LookupType value="2"/>
       <LookupFlag value="0"/>
       <!-- SubTableCount=1 -->
-      <MultipleSubst index="0" Format="1">
+      <MultipleSubst index="0">
         <Substitution in="janyevoweltelugu" out="jaivoweltelugu,nyasubscripttelugu"/>
         <Substitution in="kassevoweltelugu" out="kaivoweltelugu,ssasubscripttelugu"/>
       </MultipleSubst>

@behdad behdad requested a review from anthrotype March 23, 2021 19:53
@behdad
Copy link
Member Author
behdad commented Mar 23, 2021

Ah, thanks. Let's keep the test code in same order so we test this route. I'll add a comment as well.

Will fix preWrites and MultipleSubst.

@behdad
Copy link
Member Author
behdad commented Mar 24, 2021

Okay! Ready to review / merge. All tests pass. :)

@behdad
Copy link
Member Author
behdad commented Mar 24, 2021

in mti_test.py, if you move the order in which you dump to ttx and compile the table (by moving the dump from built table before the table.compile), then you get the expected ttx output (without Formats). I think it's because the preWrite methods called by compile re-add the Format attrs, so if you dump after a compile you still get those..

So; we have feaLib/mtiLib/otlLib/fontBuilder building Python objects, then there's saving to binary and back, and to XML and back. Would be good if we can centralize testing of all that :))). Right now each test module does it's own.

But yeah, glad mti's had different order so I caught more to fix.

@madig
Copy link
Collaborator
madig commented Mar 24, 2021

I like the centralization idea but don't know enough to meaningfully review this PR or centralize anything in ttLib :o

table = self.preWrite(font)
deleteFormat = deleteFormat and hasattr(self, 'Format')
Copy link
Collabo 8000 rator
@madig madig Mar 24, 2021

Choose a reason for hiding this comment

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

What does this double check do? Why not just delete it when you hasattr it at the end?

Copy link
Member

Choose a reason for hiding this comment

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

it means "delete Format attribute if it wasn't there before calling preWrite and it's been added by the preWrite"

Copy link
Collaborator

Choose a reason for hiding this comment

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

So why delete it at the end of the function?

Copy link
Member

Choose a reason for hiding this comment

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

it's used when serializing the tables, we only want to delete after compile is completed

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just a hack. Ideally compilation shouldn't modify the objects. The preWrite methods are modifying by adding .Format. Eventually we will remove that, by rewriting how format-switching table machinery works. But for now, to make it work, I let preWrite add .Format, but will delete it at the end of compile when they are not needed anymore.

Another place we modify objects during compilation is when we split large lookups. But that's for another day...

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

@behdad behdad merged commit 7297659 into main Mar 24, 2021
@anthrotype anthrotype deleted the no-unused-Format branch March 24, 2021 15:05
behdad added a commit to behdad/ufo2ft that referenced this pull request Mar 26, 2021
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