Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting the font size #24

Open
lsorber opened this issue Jan 7, 2025 · 1 comment
Open

Extracting the font size #24

lsorber opened this issue Jan 7, 2025 · 1 comment

Comments

@lsorber
Copy link

lsorber commented Jan 7, 2025

In RAGLite we need a dependable estimate of the font size of a span. I thought it might be interesting for you to know how we obtain it with pdftext:

def extract_font_size(span: dict[str, Any]) -> float:
    """Extract the font size from a text span."""
    font_size: float = 1.0
    if span["font"]["size"] > 1:  # A value of 1 appears to mean "unknown" in pdftext.
        font_size = span["font"]["size"]
    elif digit_sequences := re.findall(r"\d+", span["font"]["name"] or ""):
        font_size = float(digit_sequences[-1])
    elif "\n" not in span["text"]:  # Occasionally a span can contain a newline character.
        if round(span["rotation"]) in (0.0, 180.0, -180.0):
            font_size = span["bbox"][3] - span["bbox"][1]
        elif round(span["rotation"]) in (90.0, -90.0, 270.0, -270.0):
            font_size = span["bbox"][2] - span["bbox"][0]
    return font_size
@VikParuchuri
Copy link
Owner

Thanks for the note! We'll look into adding some font size heuristics for when it's missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants