Skip to content

Commit

Permalink
refactor(styles_and_formulas): update is_translatable_formula regex
Browse files Browse the repository at this point in the history
- include spaces in the regex to allow formulas with spaces
- remove unnecessary text replacement for spaces
  • Loading branch information
awwaawwa committed Jan 20, 2025
1 parent eb92116 commit 2ffbb05
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions yadt/document_il/midend/styles_and_formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,11 @@ def update_formula_data(self, formula: PdfFormula):
formula.box = Box(min_x, min_y, max_x, max_y)

def is_translatable_formula(self, formula: PdfFormula) -> bool:
"""判断公式是否只包含需要正常翻译的字符(数字和英文逗号)"""
"""判断公式是否只包含需要正常翻译的字符(数字、空格和英文逗号)"""
text = "".join(char.char_unicode for char in formula.pdf_character)
# 去除空格后用正则表达式检查是否只包含数字和英文逗号
text = text.replace(" ", "")
if formula.y_offset > 0.1:
return False
return bool(re.match(r"^[0-9,]+$", text))
return bool(re.match(r"^[0-9, ]+$", text))

def is_formulas_font(self, font_name: str) -> bool:
if self.translation_config.formular_font_pattern:
Expand Down

0 comments on commit 2ffbb05

Please sign in to comment.