mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
7012bb1af2
commit
27a4657b2c
@ -251,9 +251,11 @@ class PdfEngine(QPaintEngine):
|
|||||||
try:
|
try:
|
||||||
self.pdf = PDFStream(self.file_object, (self.page_width,
|
self.pdf = PDFStream(self.file_object, (self.page_width,
|
||||||
self.page_height), compress=self.compress,
|
self.page_height), compress=self.compress,
|
||||||
mark_links=self.mark_links)
|
mark_links=self.mark_links,
|
||||||
|
debug=self.debug)
|
||||||
except:
|
except:
|
||||||
self.errors(traceback.format_exc())
|
self.errors(traceback.format_exc())
|
||||||
|
self.errors_occurred = True
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -270,6 +272,7 @@ class PdfEngine(QPaintEngine):
|
|||||||
self.pdf.end()
|
self.pdf.end()
|
||||||
except:
|
except:
|
||||||
self.errors(traceback.format_exc())
|
self.errors(traceback.format_exc())
|
||||||
|
self.errors_occurred = True
|
||||||
return False
|
return False
|
||||||
finally:
|
finally:
|
||||||
self.pdf = self.file_object = None
|
self.pdf = self.file_object = None
|
||||||
@ -581,7 +584,7 @@ if __name__ == '__main__':
|
|||||||
QBrush, QColor, QPoint, QPixmap
|
QBrush, QColor, QPoint, QPixmap
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
p = QPainter()
|
p = QPainter()
|
||||||
with open('/tmp/painter.pdf', 'wb') as f:
|
with open('/t/painter.pdf', 'wb') as f:
|
||||||
dev = PdfDevice(f, compress=False)
|
dev = PdfDevice(f, compress=False)
|
||||||
p.begin(dev)
|
p.begin(dev)
|
||||||
dev.init_page()
|
dev.init_page()
|
||||||
|
@ -47,7 +47,7 @@ class Links(object):
|
|||||||
for link in self.links:
|
for link in self.links:
|
||||||
path, href, frag = link[0]
|
path, href, frag = link[0]
|
||||||
page, rect = link[1:]
|
page, rect = link[1:]
|
||||||
combined_path = os.path.abspath(os.path.join(path, *href.split('/')))
|
combined_path = os.path.abspath(os.path.join(os.path.dirname(path), *href.split('/')))
|
||||||
is_local = not href or combined_path in self.anchors
|
is_local = not href or combined_path in self.anchors
|
||||||
annot = Dictionary({
|
annot = Dictionary({
|
||||||
'Type':Name('Annot'), 'Subtype':Name('Link'),
|
'Type':Name('Annot'), 'Subtype':Name('Link'),
|
||||||
@ -76,6 +76,9 @@ class Links(object):
|
|||||||
if 'Annots' not in page:
|
if 'Annots' not in page:
|
||||||
page['Annots'] = Array()
|
page['Annots'] = Array()
|
||||||
page['Annots'].append(self.pdf.objects.add(annot))
|
page['Annots'].append(self.pdf.objects.add(annot))
|
||||||
|
else:
|
||||||
|
self.pdf.debug('Could not find destination for link: %s in file %s'%
|
||||||
|
(href, path))
|
||||||
|
|
||||||
def add_outline(self, toc):
|
def add_outline(self, toc):
|
||||||
parent = Dictionary({'Type':Name('Outlines')})
|
parent = Dictionary({'Type':Name('Outlines')})
|
||||||
|
@ -281,7 +281,8 @@ class PDFStream(object):
|
|||||||
( True, True, 'evenodd') : 'B*',
|
( True, True, 'evenodd') : 'B*',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, stream, page_size, compress=False, mark_links=False):
|
def __init__(self, stream, page_size, compress=False, mark_links=False,
|
||||||
|
debug=print):
|
||||||
self.stream = HashingStream(stream)
|
self.stream = HashingStream(stream)
|
||||||
self.compress = compress
|
self.compress = compress
|
||||||
self.write_line(PDFVER)
|
self.write_line(PDFVER)
|
||||||
@ -298,6 +299,7 @@ class PDFStream(object):
|
|||||||
self.stroke_opacities, self.fill_opacities = {}, {}
|
self.stroke_opacities, self.fill_opacities = {}, {}
|
||||||
self.font_manager = FontManager(self.objects, self.compress)
|
self.font_manager = FontManager(self.objects, self.compress)
|
||||||
self.image_cache = {}
|
self.image_cache = {}
|
||||||
|
self.debug = debug
|
||||||
self.links = Links(self, mark_links)
|
self.links = Links(self, mark_links)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user