Skip to content

Commit

Permalink
Merge 879b05e into 186dbc1
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Aug 3, 2021
2 parents 186dbc1 + 879b05e commit b45d4c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 95 deletions.
28 changes: 1 addition & 27 deletions src/ufonormalizer/__init__.py
Expand Up @@ -8,7 +8,6 @@
import shutil
from xml.etree import cElementTree as ET
import plistlib
import textwrap
import datetime
import glob
from collections import OrderedDict
Expand Down Expand Up @@ -838,9 +837,7 @@ def _normalizeGlifNote(element, writer):
return
if not value.strip():
return
writer.beginElement("note")
writer.text(value)
writer.endElement("note")
writer.simpleElement("note", value=value)


def _normalizeGlifOutlineFormat1(element, writer):
Expand Down Expand Up @@ -1261,29 +1258,6 @@ def data(self, text):
line = "<![CDATA[%s]]>" % text
self.raw(line)

def text(self, text):
text = text.strip("\n")
text = dedent_tabs(text)
text = text.strip()
text = xmlEscapeText(text)
paragraphs = []
for paragraph in text.splitlines():
if not paragraph:
paragraphs.append("")
else:
paragraph = textwrap.wrap(
paragraph.rstrip(),
width=xmlTextMaxLineLength,
expand_tabs=False,
replace_whitespace=False,
drop_whitespace=False,
break_long_words=False,
break_on_hyphens=False
)
paragraphs.extend(paragraph)
for line in paragraphs:
self.raw(line)

def simpleElement(self, tag, attrs=None, value=None):
if attrs:
attrs = self.attributesToString(attrs)
Expand Down
4 changes: 1 addition & 3 deletions tests/data/glif/format2.glif
Expand Up @@ -35,7 +35,5 @@
<string>1,0,0,0.5</string>
</dict>
</lib>
<note>
arbitrary text about the glyph
</note>
<note>arbitrary text about the glyph</note>
</glyph>
82 changes: 17 additions & 65 deletions tests/test_ufonormalizer.py
Expand Up @@ -107,9 +107,7 @@
<string>1,0,0,0.5</string>
</dict>
</lib>
<note>
arbitrary text about the glyph
</note>
<note>arbitrary text about the glyph</note>
</glyph>
'''

Expand Down Expand Up @@ -767,25 +765,25 @@ def test_normalizeGLIF_lib_undefined(self):
self.assertEqual(writer.getText(), '')

def test_normalizeGLIF_note_defined(self):
""" Serialization of notes is non-fancy: we take the note text and
use it, unchanged, as the body of the <note>element</note>. In previous
version of ufonormalizer we would break the user text into lines. See
https://github.com/unified-font-object/ufoNormalizer/issues/85 for some
background.
"""

element = ET.fromstring("<note>Blah</note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(writer.getText(), "<note>\n\tBlah\n</note>")
self.assertEqual(writer.getText(), "<note>Blah</note>")

# trailing whitespace is preserved
element = ET.fromstring("<note> Blah \t\n\t </note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(writer.getText(), "<note>\n\tBlah\n</note>")

element = ET.fromstring(
tobytes("<note>Don't forget to check the béziers!!</note>",
encoding="utf8"))
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tDon't forget to check the b\xe9ziers!!\n</note>")
self.assertEqual(writer.getText(), "<note> Blah \t\n\t </note>")

# multiline strings are preserved
element = ET.fromstring(
tobytes("<note>A quick brown fox jumps over the lazy dog.\n"
"Příliš žluťoučký kůň úpěl ďábelské ódy.</note>",
Expand All @@ -794,64 +792,18 @@ def test_normalizeGLIF_note_defined(self):
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tA quick brown fox jumps over the lazy dog.\n\t"
"<note>A quick brown fox jumps over the lazy dog.\n"
"P\u0159\xedli\u0161 \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 "
"\xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy.\n</note>")

element = ET.fromstring(
"<note> Line1 \t\n\n Line3\t </note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tLine1\n\t\n\t Line3\n</note>")

# Normalizer should not indent Line2 and Line3 more than already indented
element = ET.fromstring(
"<note>\n\tLine1\n\tLine2\n\tLine3\n</note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tLine1\n\tLine2\n\tLine3\n</note>")

# Normalizer should keep the extra tab in line 2
element = ET.fromstring(
"<note>\n\tLine1\n\t\tLine2\n\tLine3\n</note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tLine1\n\t\tLine2\n\tLine3\n</note>")

# Normalizer should keep the extra spaces on line 2
element = ET.fromstring(
"<note>\n\tLine1\n\t Line2\n\tLine3\n</note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tLine1\n\t Line2\n\tLine3\n</note>")

# Normalizer should remove the extra tab all lines have in common,
# but leave the additional tab on line 2
element = ET.fromstring(
"<note>\n\t\tLine1\n\t\t\tLine2\n\t\tLine3\n</note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tLine1\n\t\tLine2\n\tLine3\n</note>")
"\xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy.</note>")

# Normalizer should remove the extra 4-space all lines have in common,
# but leave the additional 4-space on line 2
# Everything is always preserved
element = ET.fromstring(
"<note>\n Line1\n Line2\n Line3\n</note>")
"<note>\n\tLine1\n\t\tLine2\n\t Line3\n</note>")
writer = XMLWriter(declaration=None)
_normalizeGlifNote(element, writer)
self.assertEqual(
writer.getText(),
"<note>\n\tLine1\n\t Line2\n\tLine3\n</note>")
"<note>\n\tLine1\n\t\tLine2\n\t Line3\n</note>")

def test_normalizeGLIF_note_undefined(self):
element = ET.fromstring("<note></note>")
Expand Down

0 comments on commit b45d4c6

Please sign in to comment.