MCPcopy Index your code
hub / github.com/PDFMathTranslate/PDFMathTranslate / process_page

Method process_page

pdf2zh/pdfinterp.py:254–278  ·  view source on GitHub ↗
(self, page: PDFPage)

Source from the content-addressed store, hash-verified

252 pass
253
254 def process_page(self, page: PDFPage) -> None:
255 # 重载设置 page 的 obj_patch
256 # log.debug("Processing page: %r", page)
257 # print(page.mediabox,page.cropbox)
258 # (x0, y0, x1, y1) = page.mediabox
259 (x0, y0, x1, y1) = page.cropbox
260 if page.rotate == 90:
261 ctm = (0, -1, 1, 0, -y0, x1)
262 elif page.rotate == 180:
263 ctm = (-1, 0, 0, -1, x1, y1)
264 elif page.rotate == 270:
265 ctm = (0, 1, -1, 0, y1, -x0)
266 else:
267 ctm = (1, 0, 0, 1, -x0, -y0)
268 self.device.begin_page(page, ctm)
269 ops_base = self.render_contents(page.resources, page.contents, ctm=ctm)
270 self.device.fontid = self.fontid
271 self.device.fontmap = self.fontmap
272 ops_new = self.device.end_page(page)
273 # 上面渲染的时候会根据 cropbox 减掉页面偏移得到真实坐标,这里输出的时候需要用 cm 把页面偏移加回来
274 self.obj_patch[page.page_xref] = (
275 f"q {ops_base}Q 1 0 0 1 {x0} {y0} cm {ops_new}" # ops_base 里可能有图,需要让 ops_new 里的文字覆盖在上面,使用 q/Q 重置位置矩阵
276 )
277 for obj in page.contents:
278 self.obj_patch[obj.objid] = ""
279
280 def render_contents(
281 self,

Callers 1

translate_patchFunction · 0.95

Calls 3

render_contentsMethod · 0.95
begin_pageMethod · 0.80
end_pageMethod · 0.80

Tested by

no test coverage detected