Use Courier as debug font

This commit is contained in:
James R. Barlow
2024-01-06 14:24:25 -08:00
parent b71d16dd96
commit 7e608fd1df
2 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ from ocrmypdf.exceptions import (
)
from ocrmypdf.helpers import IMG2PDF_KWARGS, Resolution, safe_symlink
from ocrmypdf.hocrtransform import DebugRenderOptions, HocrTransform
from ocrmypdf.hocrtransform._font import Helvetica
from ocrmypdf.hocrtransform._font import Courier
from ocrmypdf.pdfa import generate_pdfa_ps
from ocrmypdf.pdfinfo import Colorspace, Encoding, PageInfo, PdfInfo
from ocrmypdf.pluginspec import OrientationConfidence
@@ -753,7 +753,7 @@ def render_hocr_page(hocr: Path, page_context: PageContext) -> Path:
render_paragraph_bbox=False,
render_space_bbox=False,
),
font=Helvetica(),
font=Courier(),
)
HocrTransform(
hocr_filename=hocr, dpi=dpi.to_scalar(), **debug_kwargs # square
+4 -4
View File
@@ -120,12 +120,12 @@ class GlyphlessFont(EncodableFont):
return basefont
class Helvetica(EncodableFont):
"""Helvetica font."""
class Courier(EncodableFont):
"""Courier font."""
def text_width(self, text: str, fontsize: float) -> float:
"""Estimate the width of a text string when rendered with the given font."""
return len(text) * fontsize / 2.0
return len(text) * fontsize
def text_encode(self, text: str) -> bytes:
return text.encode('pdfdoc', errors='ignore')
@@ -134,7 +134,7 @@ class Helvetica(EncodableFont):
"""Register the font."""
return pdf.make_indirect(
Dictionary(
BaseFont=Name.Helvetica,
BaseFont=Name.Courier,
Type=Name.Font,
Subtype=Name.Type1,
)