Skip to content

Commit

Permalink
fix: Update font matching logic to handle bold and serif attributes c…
Browse files Browse the repository at this point in the history
…orrectly
  • Loading branch information
awwaawwa committed Mar 4, 2025
1 parent 074ef54 commit bac75bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion babeldoc/document_il/midend/styles_and_formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ def is_translatable_formula(self, formula: PdfFormula) -> bool:
return bool(re.match(r"^[0-9, ]+$", text))

def is_formulas_font(self, font_name: str) -> bool:
pattern2 = r"^(Cambria|Cambria-BoldItalic|Cambria-Bold|Cambria-Italic)$"
pattern2 = (
r"^(Cambria|Cambria-BoldItalic|Cambria-Bold|Cambria-Italic|EUAlbertina.+)$"
)
if self.translation_config.formular_font_pattern:
pattern = self.translation_config.formular_font_pattern
else:
Expand Down
6 changes: 3 additions & 3 deletions babeldoc/document_il/utils/fontmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ def map_in_type(
for font in self.type2font[font_type]:
if not font.has_glyph(current_char):
continue
if bold != font.is_bold:
if bool(bold) != bool(font.is_bold):
continue
# 不知道什么原因,思源黑体的 serif 属性为 1,先 workaround
if serif == 1 and "serif" not in font.font_id.lower():
if bool(serif) and "serif" not in font.font_id.lower():
continue
if serif == 0 and "serif" in font.font_id.lower():
if not bool(serif) and "serif" in font.font_id.lower():
continue
return font

Expand Down

0 comments on commit bac75bb

Please sign in to comment.