Byaidu před 1 rokem
rodič
revize
6c600beb1d
3 změnil soubory, kde provedl 12 přidání a 8 odebrání
  1. 8 6
      pdf2zh/converter.py
  2. 3 1
      pdf2zh/high_level.py
  3. 1 1
      pdf2zh/pdfinterp.py

+ 8 - 6
pdf2zh/converter.py

@@ -189,8 +189,6 @@ class TranslateConverter(PDFConverterEx):
         vmax: float = ltpage.width / 4  # 行内公式最大宽度
         ops: str = ""                   # 渲染结果
 
-
-
         def vflag(font: str, char: str):    # 匹配公式(和角标)字体
             if isinstance(font, bytes):     # 不一定能 decode,直接转 str
                 try:
@@ -382,12 +380,15 @@ class TranslateConverter(PDFConverterEx):
             "ja": 1.1, "ko": 1.2, "en": 1.2, "ar": 1.0, "ru": 0.8, "uk": 0.8, "ta": 0.8
         }
         default_line_height = LANG_LINEHEIGHT_MAP.get(self.translator.lang_out.lower(), 1.1) # 小语种默认1.1
-
         _x, _y = 0, 0
-
         ops_list = []
-        gen_op_txt = lambda font, size, x, y, rtxt: f"/{font} {size:f} Tf 1 0 0 1 {x:f} {y:f} Tm [<{rtxt}>] TJ "
-        gen_op_line = lambda x, y, xlen, ylen, linewidth: f"ET q 1 0 0 1 {x:f} {y:f} cm [] 0 d 0 J {linewidth:f} w 0 0 m {xlen:f} {ylen:f} l S Q BT "
+
+        def gen_op_txt(font, size, x, y, rtxt):
+            return f"/{font} {size:f} Tf 1 0 0 1 {x:f} {y:f} Tm [<{rtxt}>] TJ "
+
+        def gen_op_line(x, y, xlen, ylen, linewidth):
+            return f"ET q 1 0 0 1 {x:f} {y:f} cm [] 0 d 0 J {linewidth:f} w 0 0 m {xlen:f} {ylen:f} l S Q BT "
+
         for id, new in enumerate(news):
             x: float = pstk[id].x                       # 段落初始横坐标
             y: float = pstk[id].y                       # 段落初始纵坐标
@@ -528,6 +529,7 @@ class TranslateConverter(PDFConverterEx):
         ops = f"BT {''.join(ops_list)}ET "
         return ops
 
+
 class OpType(Enum):
     TEXT = "text"
     LINE = "line"

+ 3 - 1
pdf2zh/high_level.py

@@ -314,7 +314,9 @@ def translate(
     result_files = []
 
     for file in files:
-        if type(file) is str and (file.startswith("http://") or file.startswith("https://")):
+        if type(file) is str and (
+            file.startswith("http://") or file.startswith("https://")
+        ):
             print("Online files detected, downloading...")
             try:
                 r = requests.get(file, allow_redirects=True)

+ 1 - 1
pdf2zh/pdfinterp.py

@@ -361,4 +361,4 @@ class PDFPageInterpreterEx(PDFPageInterpreter):
             else:
                 self.push(obj)
         # print('REV DATA',ops)
-        return ops
+        return ops