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

Method execute

pdf2zh/pdfinterp.py:301–366  ·  view source on GitHub ↗
(self, streams: Sequence[object])

Source from the content-addressed store, hash-verified

299 return self.execute(list_value(streams))
300
301 def execute(self, streams: Sequence[object]) -> None:
302 # 重载返回指令流
303 ops = ""
304 try:
305 parser = PDFContentParser(streams)
306 except PSEOF:
307 # empty page
308 return
309 while True:
310 try:
311 (_, obj) = parser.nextobject()
312 except PSEOF:
313 break
314 if isinstance(obj, PSKeyword):
315 name = keyword_name(obj)
316 method = "do_%s" % name.replace("*", "_a").replace('"', "_w").replace(
317 "'",
318 "_q",
319 )
320 if hasattr(self, method):
321 func = getattr(self, method)
322 nargs = func.__code__.co_argcount - 1
323 if nargs:
324 args = self.pop(nargs)
325 # log.debug("exec: %s %r", name, args)
326 if len(args) == nargs:
327 func(*args)
328 if not (
329 name[0] == "T"
330 or name in ['"', "'", "EI", "MP", "DP", "BMC", "BDC"]
331 ): # 过滤 T 系列文字指令,因为 EI 的参数是 obj 所以也需要过滤(只在少数文档中画横线时使用),过滤 marked 系列指令
332 p = " ".join(
333 [
334 (
335 f"{x:f}"
336 if isinstance(x, float)
337 else str(x).replace("'", "")
338 )
339 for x in args
340 ]
341 )
342 ops += f"{p} {name} "
343 else:
344 # log.debug("exec: %s", name)
345 targs = func()
346 if targs is None:
347 targs = []
348 if not (name[0] == "T" or name in ["BI", "ID", "EMC"]):
349 p = " ".join(
350 [
351 (
352 f"{x:f}"
353 if isinstance(x, float)
354 else str(x).replace("'", "")
355 )
356 for x in targs
357 ]
358 )

Callers 1

render_contentsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected