【问题标题】:Reportlab 3.5 diacritic's in text are mispositioned for certain fonts (Junicode)文本中的 Reportlab 3.5 变音符号对于某些字体(Junicode)的定位错误
【发布时间】:2020-02-20 13:09:15
【问题描述】:

我正在 python3.7 中创建一个解析器,它将 xml 文件作为输入并创建 PDF 文件作为输出。我正在使用reportlab 3.5,除了一件事外一切正常。我正在解析的文本使用了一种名为“Junicode”的字体。字体使用正确,除了变音符号(应该在另一个字母上方的字母,如“´”超过“e”,如这个é)被向右移动。这里有一个例子:

我正在使用 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)

我试图让字母上方的变音符号,f.e.在上图中,我希望 90 度倾斜的“:”位于 y 上方。

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

谢谢, 保罗

【问题讨论】:

    标签: python python-3.x reportlab


    【解决方案1】:

    解决方法:

    我设法通过使用 FontForge 编辑字体解决了这个问题。我将变音符号的 x 位置转换为负值,从而正确定位它们。对于大写字母,我也必须增加 y 值,所以我创建了额外的变音符号(在字体中没有设置字母的地方)增加了 y 值,如果前面有大写字母,则用新的替换旧的.

    【讨论】:

      猜你喜欢
      • 2019-03-03
      • 2016-05-05
      • 2018-02-03
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      相关资源
      最近更新 更多