Skip to content
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

[uforead] parse multiple attrs in xmlNode #1720

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions c/shared/source/uforead/uforead.c
Original file line number Diff line number Diff line change
Expand Up @@ -1682,8 +1682,11 @@ static void parseXMLGLIFKey(ufoCtx h, xmlNodePtr cur, unsigned long *unicode, in
xmlAttr *attr = cur->properties;
if (h->parseState.UFOFile == preParsingGLIF) { /* called from preParseGLIF */
if (xmlKeyEqual(cur, "advance")) {
if (xmlAttrEqual(attr, "width") || xmlAttrEqual(attr, "advance"))
setWidth(h, tag, strtolCheck(h, getXmlAttrValue(attr), false, NULL, 10));
while (attr != NULL) {
if (xmlAttrEqual(attr, "width") || xmlAttrEqual(attr, "advance"))
setWidth(h, tag, strtolCheck(h, getXmlAttrValue(attr), false, NULL, 10));
attr = attr->next;
}
} else if (xmlKeyEqual(cur, "unicode")) {
if (xmlAttrEqual(attr, "hex"))
*unicode = strtoulCheck(h, getXmlAttrValue(attr), false, NULL, 16);
Expand Down
53 changes: 53 additions & 0 deletions tests/tx_data/expected_output/ufo-advance-height-weight.pfa

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
'.notdef': ['w100', ['checkOutlines', 'autohint']],
'A': ['w400l47243l119456l353343l273183l173168', ['checkOutlines', 'autohint']],
'hashMapVersion': (1, 0),
'space': ['w200', ['checkOutlines', 'autohint']],
}
43 changes: 43 additions & 0 deletions tests/tx_data/input/ufo-advance-height-weight.ufo/fontinfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ascender</key>
<integer>750</integer>
<key>capHeight</key>
<integer>750</integer>
<key>descender</key>
<integer>-250</integer>
<key>familyName</key>
<string>Dummy</string>
<key>guidelines</key>
<array>
</array>
<key>postscriptBlueValues</key>
<array>
</array>
<key>postscriptFamilyBlues</key>
<array>
</array>
<key>postscriptFamilyOtherBlues</key>
<array>
</array>
<key>postscriptFontName</key>
<string>Dummy-Style_01</string>
<key>postscriptOtherBlues</key>
<array>
</array>
<key>postscriptStemSnapH</key>
<array>
</array>
<key>postscriptStemSnapV</key>
<array>
</array>
<key>styleName</key>
<string>Style_01</string>
<key>unitsPerEm</key>
<integer>1000</integer>
<key>xHeight</key>
<integer>500</integer>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="A" format="2">
<unicode hex="0041"/>
<advance height="600" width="400"/>
<outline>
<contour>
<point name="hintSet0000" x="47" y="243" type="line"/>
<point x="119" y="456" type="line"/>
<point x="353" y="343" type="line"/>
<point x="273" y="183" type="line"/>
<point x="173" y="168" type="line"/>
</contour>
</outline>
<lib>
<dict>
<key>com.adobe.type.autohint.v2</key>
<dict>
<key>hintSetList</key>
<array>
<dict>
<key>pointTag</key>
<string>hintSet0000</string>
<key>stems</key>
<array>
<string>hstem 168 288</string>
<string>vstem 47 306</string>
</array>
</dict>
</array>
<key>id</key>
<string>w400l47243l119456l353343l273183l173168</string>
</dict>
</dict>
</lib>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>A</key>
<string>A_.glif</string>
</dict>
</plist>
14 changes: 14 additions & 0 deletions tests/tx_data/input/ufo-advance-height-weight.ufo/glyphs/A_.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="A" format="2">
<unicode hex="0041"/>
<advance height="600" width="400"/>
<outline>
<contour>
<point x="47" y="243" type="line"/>
<point x="119" y="456" type="line"/>
<point x="353" y="343" type="line"/>
<point x="273" y="183" type="line"/>
<point x="173" y="168" type="line"/>
</contour>
</outline>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name=".notdef" format="2">
<advance width="100"/>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>.notdef</key>
<string>_notdef.glif</string>
<key>A</key>
<string>A_.glif</string>
<key>space</key>
<string>space.glif</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="space" format="2">
<unicode hex="0020"/>
<advance width="200"/>
</glyph>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<array>
<string>public.default</string>
<string>glyphs</string>
</array>
<array>
<string>com.adobe.type.processedglyphs</string>
<string>glyphs.com.adobe.type.processedglyphs</string>
</array>
</array>
</plist>
12 changes: 12 additions & 0 deletions tests/tx_data/input/ufo-advance-height-weight.ufo/lib.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>public.glyphOrder</key>
<array>
<string>.notdef</string>
<string>space</string>
<string>A</string>
</array>
</dict>
</plist>
10 changes: 10 additions & 0 deletions tests/tx_data/input/ufo-advance-height-weight.ufo/metainfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>creator</key>
<string>com.github.fonttools.ufoLib</string>
<key>formatVersion</key>
<integer>3</integer>
</dict>
</plist>
13 changes: 13 additions & 0 deletions tests/tx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,3 +1678,16 @@ def test_alt_missing_glyph():
expected_path = generate_ps_dump(expected_path)
output_path = generate_ps_dump(output_path)
assert differ([expected_path, output_path])


def test_parsing_attrs_bug1673():
"""
Test parsing nested attributes within an xmlNode.
"""
input_path = get_input_path("ufo-advance-height-weight.ufo")
expected_path = get_expected_path("ufo-advance-height-weight.pfa")
output_path = get_temp_file_path()
subprocess.call([TOOL, '-t1', '-o', output_path, input_path])
expected_path = generate_ps_dump(expected_path)
output_path = generate_ps_dump(output_path)
assert differ([expected_path, output_path, '-s', PFA_SKIP[0]])
Loading