1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 00:21:15 +03:00

Use font codepoints instead of Unicode codepoints

This commit is contained in:
Guillaume Ayoub 2020-05-08 17:14:45 +02:00
parent 6e3214eea8
commit d53b86053d
2 changed files with 23 additions and 9 deletions

View File

@ -97,7 +97,7 @@ class Font:
def add_glyphs(self, glyph_item):
glyph_string = glyph_item.glyphs
num_glyphs = glyph_string.num_glyphs
self.glyphs += {
self.glyphs |= {
glyph_string.glyphs[x].glyph for x in range(num_glyphs)}
def compute_glyphs_values(self):
@ -949,14 +949,16 @@ class Document:
pdf.add_object(font_stream)
font.compute_glyphs_values()
font_dictionary = pydyf.Dictionary({
subfont_dictionary = pydyf.Dictionary({
'Type': '/Font',
'Subtype': '/TrueType',
'Subtype': '/CIDFontType2',
'BaseFont': font.name,
'FirstChar': font.first_char,
'LastChar': font.last_char,
'Encoding': '/WinAnsiEncoding',
'Widths': pydyf.Array(font.widths),
'CIDSystemInfo': pydyf.Dictionary({
'Registry': pydyf.String('Adobe'),
'Ordering': pydyf.String('Identity'),
'Supplement': 0,
}),
'W': pydyf.Array([font.first_char, pydyf.Array(font.widths)]),
'FontDescriptor': pydyf.Dictionary({
'FontName': font.name,
'FontFamily': pydyf.String(font.family),
@ -969,7 +971,15 @@ class Document:
'StemV': font.stemv,
'StemH': font.stemh,
'FontFile': font_stream.reference,
})
}),
})
pdf.add_object(subfont_dictionary)
font_dictionary = pydyf.Dictionary({
'Type': '/Font',
'Subtype': '/Type0',
'BaseFont': font.name,
'Encoding': '/Identity-H',
'DescendantFonts': pydyf.Array([subfont_dictionary.reference]),
})
pdf.add_object(font_dictionary)
resources['Font'][str(font_hash)] = font_dictionary.reference

View File

@ -1315,6 +1315,9 @@ def show_first_line(context, textbox, text_overflow):
run = first_line.runs[0]
while True:
glyph_item = ffi.cast('PangoGlyphItem *', run.data)
glyph_string = glyph_item.glyphs
num_glyphs = glyph_string.num_glyphs
glyphs = [glyph_string.glyphs[x].glyph for x in range(num_glyphs)]
pango_font = glyph_item.item.analysis.font
hb_font = pango.pango_font_get_hb_font(pango_font)
data = harfbuzz.hb_blob_get_data(harfbuzz.hb_face_reference_blob(
@ -1327,10 +1330,11 @@ def show_first_line(context, textbox, text_overflow):
run = run.next
ffi.release(length)
pdf_glyphs = ''.join(f'<{glyph:04x}>' for glyph in glyphs)
context.stream.append('BT')
context.stream.append('12 0 0 -12 62.25 72.945312 Tm')
context.stream.append(f'/{font_hash} 1 Tf')
context.stream.append(f'[({textbox.text})]TJ')
context.stream.append(f'[{pdf_glyphs}]TJ')
context.stream.append('ET')