summaryrefslogtreecommitdiff
path: root/bin/reportlab/pdfbase/_can_cmap_data.py
diff options
context:
space:
mode:
authorpinky <>2007-01-07 23:35:02 +0000
committerpinky <>2007-01-07 23:35:02 +0000
commit87b2a6bebceba02de5b98c2bd963cbb2e363c453 (patch)
treef884d8d6599d5d7988167827bb081442d11a96af /bin/reportlab/pdfbase/_can_cmap_data.py
parentac5f8444449ad5cae6a7ca5f4c7e313c9caa9fdb (diff)
RL2
bzr revid: pinky-9ee609e92f665d717ac2a51b921e52f7f73390c4
Diffstat (limited to 'bin/reportlab/pdfbase/_can_cmap_data.py')
-rw-r--r--bin/reportlab/pdfbase/_can_cmap_data.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/bin/reportlab/pdfbase/_can_cmap_data.py b/bin/reportlab/pdfbase/_can_cmap_data.py
new file mode 100644
index 00000000000..c4a7100f5cb
--- /dev/null
+++ b/bin/reportlab/pdfbase/_can_cmap_data.py
@@ -0,0 +1,58 @@
+#
+"""
+This is a utility to 'can' the widths data for certain CID fonts.
+Now we're using Unicode, we don't need 20 CMAP files for each Asian
+language, nor the widths of the non-normal characters encoded in each
+font. we just want a dictionary of the character widths in a given
+font which are NOT 1000 ems wide, keyed on Unicode character (not CID).
+
+Running off CMAP files we get the following widths...
+>>> font.stringWidth(unicode(','), 10)
+2.5
+>>> font.stringWidth(unicode('m'), 10)
+7.7800000000000002
+>>> font.stringWidth(u'\u6771\u4EAC', 10)
+20.0
+>>>
+
+"""
+
+from pprint import pprint as pp
+
+from reportlab.pdfbase._cidfontdata import defaultUnicodeEncodings
+from reportlab.pdfbase.cidfonts import UnicodeCIDFont
+
+
+def run():
+
+ buf = []
+ buf.append('widthsByUnichar = {}')
+ for (fontName, (language, encName)) in defaultUnicodeEncodings.items():
+ print 'handling %s : %s : %s' % (fontName, language, encName)
+
+ #this does just about all of it for us, as all the info
+ #we need is present.
+ font = UnicodeCIDFont(fontName)
+
+ widthsByCID = font.face._explicitWidths
+ cmap = font.encoding._cmap
+ nonStandardWidthsByUnichar = {}
+ for (codePoint, cid) in cmap.items():
+ width = widthsByCID.get(cid, 1000)
+ if width <> 1000:
+ nonStandardWidthsByUnichar[unichr(codePoint)] = width
+
+
+
+ print 'created font width map (%d items). ' % len(nonStandardWidthsByUnichar)
+
+ buf.append('widthsByUnichar["%s"] = %s' % (fontName, repr(nonStandardWidthsByUnichar)))
+
+
+ src = '\n'.join(buf) + '\n'
+ open('canned_widths.py','w').write(src)
+ print 'wrote canned_widths.py'
+
+if __name__=='__main__':
+ run()
+ \ No newline at end of file