Skip to content

Commit

Permalink
feat: Adjust bounding box calculation for PDF formulas and characters
Browse files Browse the repository at this point in the history
- Update vertical positioning of PDF formula bounding boxes
- Calculate min and max y-coordinates from character bounding boxes
- Improve vertical positioning accuracy for formula components
  • Loading branch information
awwaawwa committed Feb 20, 2025
1 parent 85b1601 commit cbd9dbe
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions babeldoc/document_il/midend/remove_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ def get_font(

# Handle characters in PdfFormula
elif comp.pdf_formula:
formula_bboxs = []
for char in comp.pdf_formula.pdf_character:
if font := get_font(char.pdf_style.font_id, char.xobj_id):
descent = self._remove_char_descent(char, font)
if descent is not None:
formula_bboxs.append(char.box)
descent_values.append(descent)
vertical_chars.append(char.vertical)
if formula_bboxs:
min_y = min(bbox.y for bbox in formula_bboxs)
max_y = max(bbox.y2 for bbox in formula_bboxs)
comp.pdf_formula.box.y = min_y
comp.pdf_formula.box.y2 = max_y

# Handle characters in PdfSameStyleCharacters
elif comp.pdf_same_style_characters:
Expand Down

0 comments on commit cbd9dbe

Please # to comment.