Skip to content

Commit

Permalink
rename resfont
Browse files Browse the repository at this point in the history
  • Loading branch information
timelic committed Jan 6, 2025
1 parent 18169a1 commit 0954cc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 5 additions & 7 deletions pdf2zh/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@

log = logging.getLogger(__name__)

noto_name = "noto"


class PDFConverterEx(PDFConverter):
def __init__(
Expand Down Expand Up @@ -139,7 +137,7 @@ def __init__(
lang_in: str = "",
lang_out: str = "",
service: str = "",
resfont: str = "",
noto_name: str = "",
noto: Font = None,
envs: Dict = None,
prompt: List = None,
Expand All @@ -149,7 +147,7 @@ def __init__(
self.vchar = vchar
self.thread = thread
self.layout = layout
self.resfont = resfont
self.noto_name = noto_name
self.noto = noto
self.translator: BaseTranslator = None
param = service.split(":", 1)
Expand Down Expand Up @@ -360,7 +358,7 @@ def worker(s: str): # 多线程翻译
############################################################
# C. 新文档排版
def raw_string(fcur: str, cstk: str): # 编码字符串
if fcur == noto_name:
if fcur == self.noto_name:
return "".join(["%04x" % self.noto.has_glyph(ord(c)) for c in cstk])
elif isinstance(self.fontmap[fcur], PDFCIDFont): # 判断编码长度
return "".join(["%04x" % ord(c) for c in cstk])
Expand Down Expand Up @@ -404,8 +402,8 @@ def raw_string(fcur: str, cstk: str): # 编码字符串
except Exception:
pass
if fcur_ is None:
fcur_ = self.resfont # 默认非拉丁字体
if fcur_ == noto_name: # FIXME: change to CONST
fcur_ = self.noto_name # 默认非拉丁字体
if fcur_ == self.noto_name: # FIXME: change to CONST
adv = self.noto.char_lengths(ch, size)[0]
else:
adv = self.fontmap[fcur_].char_width(ord(ch)) * size
Expand Down
12 changes: 7 additions & 5 deletions pdf2zh/high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
from pdfminer.pdfparser import PDFParser
from pymupdf import Document, Font

from pdf2zh.converter import TranslateConverter, noto_name
from pdf2zh.converter import TranslateConverter
from pdf2zh.doclayout import OnnxModel
from pdf2zh.pdfinterp import PDFPageInterpreterEx

NOTO_NAME = "noto"

noto_list = [
"am", # Amharic
"ar", # Arabic
Expand Down Expand Up @@ -69,7 +71,7 @@ def translate_patch(
lang_in: str = "",
lang_out: str = "",
service: str = "",
resfont: str = "",
noto_name: str = "",
noto: Font = None,
callback: object = None,
cancellation_event: asyncio.Event = None,
Expand All @@ -89,7 +91,7 @@ def translate_patch(
lang_in,
lang_out,
service,
resfont,
noto_name,
noto,
envs,
prompt,
Expand Down Expand Up @@ -175,9 +177,9 @@ def translate_stream(
font_list = [("tiro", None)]

font_path = download_remote_fonts(lang_out.lower())
resfont = noto_name
noto_name = NOTO_NAME
noto = Font(noto_name, font_path)
font_list.append((resfont, font_path))
font_list.append((noto_name, font_path))

doc_en = Document(stream=stream)
stream = io.BytesIO()
Expand Down

0 comments on commit 0954cc5

Please sign in to comment.