feat: updated font handling in older pdfs, along with tables

This commit is contained in:
Furqan-14
2026-06-26 11:33:28 +05:30
parent 52b45d82ea
commit e795eed63e
26 changed files with 995 additions and 67 deletions
+27
View File
@@ -294,6 +294,31 @@ def get_font_bytes(document_id: str, internal_font_id: str) -> Response:
headers={"Cache-Control": "public, max-age=31536000, immutable", "ETag": etag},
)
@router.get("/{document_id}/font-reconstructed")
def get_reconstructed_font_bytes(document_id: str, internal_font_id: str) -> Response:
"""Tier-2: a cmap-augmented copy of an embedded font (original glyph program + synthesized
Unicode cmap) so the WASM live preview can reuse the document's real glyphs and match the
saved result. 204 when reconstruction isn't possible -> frontend falls back to Tier-1."""
if not engine.is_available():
return Response(status_code=status.HTTP_204_NO_CONTENT)
if not internal_font_id or len(internal_font_id) > 256:
return Response(status_code=status.HTTP_204_NO_CONTENT)
doc_info = document_store.get_document(document_id)
if not doc_info:
return Response(status_code=status.HTTP_204_NO_CONTENT)
try:
data = bytes(doc_info["doc_instance"].get_reconstructed_font_data(internal_font_id))
except Exception:
data = b""
if not data or data[:4] not in _SFNT_TTF_MAGIC:
return Response(status_code=status.HTTP_204_NO_CONTENT)
etag = '"' + hashlib.sha256(data).hexdigest()[:32] + '"'
return Response(
content=data,
media_type="font/ttf",
headers={"Cache-Control": "public, max-age=31536000, immutable", "ETag": etag},
)
@router.get("/{document_id}/raw")
def get_document_raw(document_id: str) -> Response:
@@ -463,6 +488,7 @@ class TextRunModel(BaseModel):
h: float
object_indices: list[int] = []
color: str = "#000000"
font_fidelity: str = "exact"
class TextLineModel(BaseModel):
@@ -547,6 +573,7 @@ def get_page_model(document_id: str, page_index: int) -> PageModelResponse:
h=r.h,
object_indices=r.object_indices,
color=getattr(r, "fill_color", "#000000") or "#000000",
font_fidelity=getattr(r, "font_fidelity", "exact") or "exact",
)
)
lines.append(
+1
View File
@@ -214,6 +214,7 @@ class ReplaceTextData(BaseModel):
text: str
internalFontId: str
fontSize: float
disableJustify: bool = False
class ReplaceTextOperation(BaseModel):