Skip to content

Commit

Permalink
feat: Add support for PDF line, curve, and rectangle elements
Browse files Browse the repository at this point in the history
- Implement placeholder methods for handling LTLine, LTCurve, and LTRect elements
- Add logging warnings for unsupported curve and rectangle elements
- Update converter to route line, curve, and rectangle elements to respective handlers
  • Loading branch information
awwaawwa committed Feb 19, 2025
1 parent a19d391 commit 870ead5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions babeldoc/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def vflag(font: str, char: str): # 匹配公式(和角标)字体
self.il_creater.on_pdf_figure(child)
pass
elif isinstance(child, LTLine): # 线条
self.il_creater.on_ltline(child)
continue
layout = self.layout[ltpage.pageid]
# ltpage.height 可能是 fig 里面的高度,这里统一用 layout.shape
Expand All @@ -518,8 +519,10 @@ def vflag(font: str, char: str): # 匹配公式(和角标)字体
else: # 全局线条
lstk.append(child)
elif isinstance(child, LTCurve):
self.il_creater.on_ltcurve(child)
pass
elif isinstance(child, LTRect):
self.il_creater.on_ltrect(child)
pass
else:
pass
Expand Down
12 changes: 12 additions & 0 deletions babeldoc/document_il/frontend/il_creater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import pdfminer.pdfinterp
import pymupdf
from pdfminer.layout import LTChar
from pdfminer.layout import LTCurve
from pdfminer.layout import LTFigure
from pdfminer.layout import LTLine
from pdfminer.layout import LTRect
from pdfminer.pdffont import PDFCIDFont
from pdfminer.pdffont import PDFFont
from pdfminer.psparser import PSLiteral
Expand Down Expand Up @@ -353,3 +356,12 @@ def on_pdf_figure(self, figure: LTFigure):
figure.bbox[3],
)
self.current_page.pdf_figure.append(il_version_1.PdfFigure(box=box))

def on_ltline(self, line: LTLine):
pass

def on_ltcurve(self, curve: LTCurve):
logger.warning("curve is not supported yet")

def on_ltrect(self, rect: LTRect):
logger.warning("rect is not supported yet")

0 comments on commit 870ead5

Please sign in to comment.