Reportlab 3.5变音符号在某些字体(Junicode)中的位置不正确

问题描述 投票:0回答:1

我正在python3.7中创建一个解析器,该解析器将xml文件作为输入并创建PDF文件作为输出。我正在使用reportlab 3.5,除了一件事之外,其他所有功能都在工作。我正在解析的文本使用一种称为“ Junicode”的字体。正确使用了字体,除了变音符号(应在另一个字母上方的字母,如“´”越过“ e”,如é)移到右侧。这里的一个例子:

Word with the diacritic shifted.

我正在使用SimpleDocTemplate,文本进入了表格。我简化了代码:

pdfmetrics.registerFont(TTFont('Junicode', './fonts/Junicode.ttf'))
pdfmetrics.registerFont(TTFont('JunicodeBd', './fonts/Junicode-Bold.ttf'))
pdfmetrics.registerFont(TTFont('JunicodeBI', './fonts/Junicode-BoldItalic.ttf'))
pdfmetrics.registerFont(TTFont('JunicodeIt', './fonts/Junicode-Italic.ttf'))

document = SimpleDocTemplate("output_pdf/" + os.path.splitext(os.path.basename(imgfile))[0] + ".pdf",
                                             pagesize=self.canvas_size,
                                             rightMargin=Helpers.mm_to_pts(self.margin_right),
                                             leftMargin=Helpers.mm_to_pts(self.margin_left),
                                             topMargin=Helpers.mm_to_pts(self.margin_top),
                                             bottomMargin=Helpers.mm_to_pts(self.margin_bottom))

frame = Frame(document.leftMargin, document.bottomMargin, document.width, document.height)

text_template = PageTemplate(id='textpage', frames=[frame], onPage=self.__draw_text_page)

document.addPageTemplates([text_template])

page_flow = [some_other_stuff , NextPageTemplate('textpage'), PageBreak()]

[... code to get line from xml]

table_data.append(['', line])

[...]

table_styles = [('ALIGN', (0, 0), (0, -1), 'RIGHT'),
                                ('ALIGN', (2, 0), (2, -1), 'RIGHT'),
                                ('SIZE', (0, 0), (-1, -1), self.font_size),
                                ('FONT', (0, 0), (-1, -1), 'Junicode'),
                                ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), ]

table = Table(table_data, rowHeights=self.table_row_height)

table.setStyle(TableStyle(table_styles))

page_flow.append(table)

document.build(page_flow)

[我试图将变音符号放在字母上方,例如在上图中,我希望90度倾斜的“:”位于y的顶部。

有人知道这是哪里来的,是否有解决方案?

谢谢,保罗

python python-3.x reportlab
1个回答
0
投票

解决方法:

我设法通过使用FontForge编辑字体来解决此问题。我将变音符号的x位置转换为负值,从而正确定位了它们。对于大写字母,我也必须增加y值,因此我创建了附加的变音符号(在未设置字母的字体位置),并增加了y值,如果前面有大写字母,则用新的变音符号代替。

© www.soinside.com 2019 - 2024. All rights reserved.