PDF Output: Dont fail if one of the embedded fonts has no names

This commit is contained in:
Kovid Goyal 2016-11-11 20:54:13 +05:30
parent 8de266af7d
commit 3dd90488dd

View File

@ -17,6 +17,7 @@ from calibre import as_unicode
from calibre.ebooks.pdf.render.common import (Array, String, Stream, from calibre.ebooks.pdf.render.common import (Array, String, Stream,
Dictionary, Name) Dictionary, Name)
from calibre.utils.fonts.sfnt.subset import pdf_subset, UnsupportedFont, NoGlyphs from calibre.utils.fonts.sfnt.subset import pdf_subset, UnsupportedFont, NoGlyphs
from calibre.utils.short_uuid import uuid4
STANDARD_FONTS = { STANDARD_FONTS = {
'Times-Roman', 'Helvetica', 'Courier', 'Symbol', 'Times-Bold', 'Times-Roman', 'Helvetica', 'Courier', 'Symbol', 'Times-Bold',
@ -118,9 +119,13 @@ class Font(object):
self.subset_tag = bytes(re.sub('.', lambda m: chr(int(m.group())+ord('A')), self.subset_tag = bytes(re.sub('.', lambda m: chr(int(m.group())+ord('A')),
oct(num))).rjust(6, b'A').decode('ascii') oct(num))).rjust(6, b'A').decode('ascii')
self.font_stream = FontStream(metrics.is_otf, compress=compress) self.font_stream = FontStream(metrics.is_otf, compress=compress)
try:
psname = metrics.postscript_name
except Exception:
psname = uuid4()
self.font_descriptor = Dictionary({ self.font_descriptor = Dictionary({
'Type': Name('FontDescriptor'), 'Type': Name('FontDescriptor'),
'FontName': Name('%s+%s'%(self.subset_tag, metrics.postscript_name)), 'FontName': Name('%s+%s'%(self.subset_tag, psname)),
'Flags': 0b100, # Symbolic font 'Flags': 0b100, # Symbolic font
'FontBBox': Array(metrics.pdf_bbox), 'FontBBox': Array(metrics.pdf_bbox),
'ItalicAngle': metrics.post.italic_angle, 'ItalicAngle': metrics.post.italic_angle,
@ -237,5 +242,3 @@ class FontManager(object):
def embed_fonts(self, debug): def embed_fonts(self, debug):
for font in self.fonts: for font in self.fonts:
font.embed(self.objects, debug) font.embed(self.objects, debug)