# Dictionary mapping a font group name to a list of obj_nums
# (in parsed_fonts).
font_groups = {}
# Dictionary mapping a font group name to a list of font names in it.
font_group_names = {}
if do_regenerate_all_fonts:
unified_obj_nums = set(type1c_objs)
else:
unified_obj_nums = set()
for obj_num in sorted(parsed_fonts): # !! sort by font name to get exacts
obj = self.objs[obj_num] # /Type/FontDescriptor
assert obj.stream is None
parsed_font = parsed_fonts[obj_num]
parsed_font['FontName'] = obj.Get('FontName')
if parsed_font['FontType'] != 2:
print >>sys.stderr, 'info: font %s is not Type 2, can not merge.' % parsed_font['FontName']
continue
if 'CharStrings' not in parsed_font:
print >>sys.stderr, 'info: font %s does not have CharStrings, can not merge.' % parsed_font['FontName']
continue
if 'FontMatrix' not in parsed_font:
print >>sys.stderr, 'info: font %s has no FontMatrix, can not merge.' % parsed_font['FontName']
continue
if 'Private' not in parsed_font:
print >>sys.stderr, 'info: can font %s has no Private data, can not merge.' % parsed_font['FontName']
continue
if 'PaintType' not in parsed_font:
print >>sys.stderr, 'info: font %s has no PaintType, can not merge.' % parsed_font['FontName']
continue
if 'FontInfo' not in parsed_font:
print >>sys.stderr, 'info: font %s has no FontInfo, can not merge.' % parsed_font['FontName']
continue
if 'CharStrings' not in parsed_font:
print >>sys.stderr, 'info: font %s has no CharStrings, can not merge.' % parsed_font['FontName']
continue
if 'Subrs' in parsed_font:
print >>sys.stderr, 'info: font %s has Subrs, can not merge.' % parsed_font['FontName']
continue
if 'Subrs' in parsed_font['Private']:
print >>sys.stderr, 'info: font %s has Private Subrs, can not merge.' % parsed_font['FontName']
continue
assert parsed_font['FontType'] == 2
assert 'CharStrings' in parsed_font
assert 'FontMatrix' in parsed_font
assert 'Private' in parsed_font
assert 'PaintType' in parsed_font
assert 'FontInfo' in parsed_font # !! delete eventually
assert 'CharStrings' in parsed_font
assert 'Subrs' not in parsed_font # !! add a test for Subrs, maybe not in toplevel dict; maybe not dumped (because of noexec? -- but other parts of private are dumped)
# for testing: pdfsizeopt_charts.pdf has this (list of hex strings:
# ['<abc42>', ...]).
assert 'Subrs' not in parsed_font['Private']
# Extra, not checked: 'UniqueID'
if 'FontBBox' in parsed_font:
# This is part of the /FontDescriptor, we don't need it in the Type1C
# font.
del parsed_font['FontBBox']
font_name = parsed_font['FontName']
# TODO(pts): Smarter initial grouping, even if name doesn't match.
match = PdfObj.SUBSET_FONT_NAME_PREFIX_RE.match(font_name)
# TODO(pts): use KZIP or something to further optimize the ZIP stream
# !! shortcut for sam2p (don't need pngtopnm)
# (add basic support for reading PNG to sam2p? -- just what GS produces)
# (or just add .gz support?)
obj_images.append(self.ConvertImage(
sourcefn=rendered_image_file_name,
targetfn='pso.conv-%d.sam2p-np.pdf' % obj_num,
# We specify -s here to explicitly exclude SF_Opaque for single-color
# images.
# !! do we need /ImageMask parsing if we exclude SF_Mask here as well?
# Original sam2p order: Opaque:Transparent:Gray1:Indexed1:Mask:Gray2:Indexed2:Rgb1:Gray4:Indexed4:Rgb2:Gray8:Indexed8:Rgb4:Rgb8:Transparent2:Transparent4:Transparent8
# !! reintroduce Opaque by hand (combine /FlateEncode and /RLEEncode; or /FlateEncode twice (!) to reduce zeroes in empty_page.pdf from !)