summaryrefslogtreecommitdiff
path: root/misc/fonttools-3.34.2-psCharStrings.patch
blob: 7be3872012c57594970cee2140b33371340dcc69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--- a/fontTools/misc/psCharStrings.py
+++ b/fontTools/misc/psCharStrings.py
@@ -223,9 +223,16 @@
 	else:
 		return b"\xff" + pack(">l", value)  # encode the entire fixed point value
 
+
+realZeroBytes = bytechr(30) + bytechr(0xf)
+
 def encodeFloat(f):
 	# For CFF only, used in cffLib
-	s = str(f).upper()
+	if f == 0.0: # 0.0 == +0.0 == -0.0
+		return realZeroBytes
+	# Note: 14 decimal digits seems to be the limitation for CFF real numbers
+	# in macOS. However, we use 8 here to match the implementation of AFDKO.
+	s = "%.8G" % f
 	if s[:2] == "0.":
 		s = s[1:]
 	elif s[:3] == "-0.":
@@ -234,9 +241,13 @@
 	while s:
 		c = s[0]
 		s = s[1:]
-		if c == "E" and s[:1] == "-":
-			s = s[1:]
-			c = "E-"
+		if c == "E":
+			c2 = s[:1]
+			if c2 == "-":
+				s = s[1:]
+				c = "E-"
+			elif c2 == "+":
+				s = s[1:]
 		nibbles.append(realNibblesDict[c])
 	nibbles.append(0xf)
 	if len(nibbles) % 2: