mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PDF Output: Serialize ToC string as UTF-16
PDF Output: Fix non-breaking space characters incorrectly rendered in PDF outline. Fixes #1223862 [PDF TOC - appears sometimes as €](https://bugs.launchpad.net/calibre/+bug/1223862)
This commit is contained in:
parent
ccf65bf82e
commit
725bb967e5
@ -100,11 +100,18 @@ class String(unicode):
|
||||
try:
|
||||
raw = s.encode('latin1')
|
||||
if raw.startswith(codecs.BOM_UTF16_BE):
|
||||
raise UnicodeEncodeError('')
|
||||
raw = codecs.BOM_UTF16_BE + s.encode('utf-16-be')
|
||||
except UnicodeEncodeError:
|
||||
raw = codecs.BOM_UTF16_BE + s.encode('utf-16-be')
|
||||
stream.write(b'('+raw+b')')
|
||||
|
||||
class UTF16String(unicode):
|
||||
|
||||
def pdf_serialize(self, stream):
|
||||
s = self.replace('\\', '\\\\').replace('(', r'\(').replace(')', r'\)')
|
||||
raw = codecs.BOM_UTF16_BE + s.encode('utf-16-be')
|
||||
stream.write(b'('+raw+b')')
|
||||
|
||||
class Dictionary(dict):
|
||||
|
||||
def pdf_serialize(self, stream):
|
||||
|
@ -11,7 +11,7 @@ import os
|
||||
from urlparse import urlparse
|
||||
from urllib2 import unquote
|
||||
|
||||
from calibre.ebooks.pdf.render.common import Array, Name, Dictionary, String
|
||||
from calibre.ebooks.pdf.render.common import Array, Name, Dictionary, String, UTF16String
|
||||
|
||||
class Destination(Array):
|
||||
|
||||
@ -131,7 +131,7 @@ class Links(object):
|
||||
a = self.anchors[path]
|
||||
dest = a.get(frag, a[None])
|
||||
item = Dictionary({'Parent':parentref, 'Dest':dest,
|
||||
'Title':String(toc.text or _('Unknown'))})
|
||||
'Title':UTF16String(toc.text or _('Unknown'))})
|
||||
return self.pdf.objects.add(item)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user