Skip to content

insert_textbox() will overflow at the bottom of the Rect when dealing with some fonts(especially china-ss) #2874

@hengrui0516

Description

@hengrui0516

Please provide all mandatory information!

Describe the bug (mandatory)

I insert a sequence of Chinese characters using the function page.insert_textbox().
But finally more than one line is out of the Rect, which is quite terrible for the whole layout.
I it is caused by a bug when calculating remaining space of the rectangle.

To Reproduce (mandatory)

I give a minimal code snippet as follows:
`import fitz

doc = fitz.open()

page = doc.new_page(width=1017, height=1458)

rect = fitz.Rect(519.0, 11.0, 667.9999593098959, 533.0)

buffer = '''  加强涉外法治建设既是以中国式现代化全面推进强国建设、民族复兴伟业的长远所需,也是推进高水平对外开放、应对外部风险挑战的当务之急。要从更好统筹国内国际两个大局、更好统筹发展和安全的高度,深刻认识做好涉外法治工作的重要性和紧迫性,建设同高质量发展、高水平开放要求相适应的涉外法治体系和能力,为中国式现代化行稳致远营造有利法治条件和外部环境
  ■法律是社会生活、国家治理的准绳。涉外法律制度是国家法制的重要组成部分,是涉外法治的基础,发挥着固根本、稳预期、利长远的重要作用。在强国建设、民族复兴新征程上,必须坚持正确政治方向,以更加积极的历史担当和创造精神,加快推进我国涉外法治体系和能力建设
  ■涉外法治作为中国特色社会主义法治体系的重要组成部分,事关全面依法治国,事关我国对外开放和外交工作大局。推进涉外法治工作,根本目的是用法治方式更好维护国家和人民利益,促进国际法治进步,推动构建人类命运共同体。必须坚定不移走中国特色社会主义法治道路
  ■涉外法治工作是一项涉及面广、联动性强的系统工程,必须统筹国内和国际,统筹发展和安全,坚持前瞻性思考、全局性谋划、战略性布局、整体性推进,加强顶层设计,一体推进涉外立法、执法、司法、守法和法律服务,形成涉外法治工作大协同格局
  ■要坚定维护以国际法为基础的国际秩序,主动参与国际规则制定,推进国际关系法治化。积极参与全球治理体系改革和建设,推动全球治理朝着更加公正合理的方向发展,以国际良法促进全球善治,助力构建人类命运共同体
  ■法治同开放相伴而行,对外开放向前推进一步,涉外法治建设就'''

page.insert_textbox(rect = rect, buffer = buffer, fontsize=9, fontname='china-ss')

annot = page.add_rect_annot(rect) # 在矩形坐标处添加注释对象
annot.set_colors(stroke=[0, 0, 1]) # 设置边框颜色为蓝色
annot.update()

print(fitz.version)

#doc.save('specific_test11.pdf')`

Expected behavior (optional)

I expect the last line is within the Rect rather than overflow.

Screenshots (optional)

code:
screenshot
result:
1702020851825

Your configuration (mandatory)

  • Operating system, potentially version and bitness
  • Python version, bitness
  • PyMuPDF version, installation method (wheel or generated from source).

Operating system:win10
Python version:3.10.10
PyMuPDF version:1.23.5 installed by pip

Additional context (optional)

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions