pdftext 0.3.4__tar.gz → 0.3.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pdftext-0.3.4 → pdftext-0.3.6}/PKG-INFO +1 -1
- {pdftext-0.3.4 → pdftext-0.3.6}/pdftext/pdf/chars.py +9 -9
- {pdftext-0.3.4 → pdftext-0.3.6}/pdftext/settings.py +1 -1
- {pdftext-0.3.4 → pdftext-0.3.6}/pyproject.toml +1 -1
- {pdftext-0.3.4 → pdftext-0.3.6}/LICENSE +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/README.md +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/extract_text.py +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/models/dt.joblib +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/pdftext/extraction.py +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/pdftext/inference.py +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/pdftext/model.py +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/pdftext/pdf/utils.py +0 -0
- {pdftext-0.3.4 → pdftext-0.3.6}/pdftext/postprocessing.py +0 -0
|
@@ -9,15 +9,13 @@ from pdftext.pdf.utils import get_fontname, pdfium_page_bbox_to_device_bbox, pag
|
|
|
9
9
|
from pdftext.settings import settings
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def update_previous_fonts(text_chars: Dict, i: int,
|
|
13
|
-
min_update = max(0, i - fontname_sample_freq
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if regather_font_info:
|
|
17
|
-
fontname, fontflags = get_fontname(text_page, j)
|
|
12
|
+
def update_previous_fonts(text_chars: Dict, i: int, prev_fontname: str, prev_fontflags: int, text_page, fontname_sample_freq: int):
|
|
13
|
+
min_update = max(0, i - fontname_sample_freq) # Minimum index to update
|
|
14
|
+
for j in range(i-1, min_update, -1): # Goes from i to min_update
|
|
15
|
+
fontname, fontflags = get_fontname(text_page, j)
|
|
18
16
|
|
|
19
17
|
# If we hit the region with the previous fontname, we can bail out
|
|
20
|
-
if fontname == prev_fontname:
|
|
18
|
+
if fontname == prev_fontname and fontflags == prev_fontflags:
|
|
21
19
|
break
|
|
22
20
|
text_chars["chars"][j]["font"]["name"] = fontname
|
|
23
21
|
text_chars["chars"][j]["font"]["flags"] = fontflags
|
|
@@ -70,12 +68,14 @@ def get_pdfium_chars(pdf, fontname_sample_freq=settings.FONTNAME_SAMPLE_FREQ, pa
|
|
|
70
68
|
fontweight = round(pdfium_c.FPDFText_GetFontWeight(text_page, i), 1)
|
|
71
69
|
if fontname is None or i % fontname_sample_freq == 0:
|
|
72
70
|
prev_fontname = fontname
|
|
71
|
+
prev_fontflags = fontflags
|
|
73
72
|
fontname, fontflags = get_fontname(text_page, i)
|
|
74
|
-
|
|
73
|
+
if (fontname != prev_fontname or fontflags != prev_fontflags) and i > 0:
|
|
74
|
+
update_previous_fonts(text_chars, i, prev_fontname, prev_fontflags, text_page, fontname_sample_freq)
|
|
75
75
|
|
|
76
76
|
rotation = pdfium_c.FPDFText_GetCharAngle(text_page, i)
|
|
77
77
|
rotation = rotation * 180 / math.pi # convert from radians to degrees
|
|
78
|
-
coords = text_page.get_charbox(i, loose=
|
|
78
|
+
coords = text_page.get_charbox(i, loose=rotation == 0) # Loose doesn't work properly when page is rotated
|
|
79
79
|
device_coords = page_bbox_to_device_bbox(page, coords, page_width, page_height, bl_origin, page_rotation, normalize=True)
|
|
80
80
|
|
|
81
81
|
char_info = {
|
|
@@ -8,7 +8,7 @@ class Settings(BaseSettings):
|
|
|
8
8
|
MODEL_PATH: str = os.path.join(BASE_PATH, "models", "dt.joblib")
|
|
9
9
|
|
|
10
10
|
# Fonts
|
|
11
|
-
FONTNAME_SAMPLE_FREQ: int =
|
|
11
|
+
FONTNAME_SAMPLE_FREQ: int = 4
|
|
12
12
|
|
|
13
13
|
# Inference
|
|
14
14
|
BLOCK_THRESHOLD: float = 0.8 # Confidence threshold for block detection
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|