Skip to content

Fix font measurement issues#56

Merged
Im-Madhur-Gupta merged 2 commits intomainfrom
vukasin/optically-align-info-icon-and-label
Jan 14, 2026
Merged

Fix font measurement issues#56
Im-Madhur-Gupta merged 2 commits intomainfrom
vukasin/optically-align-info-icon-and-label

Conversation

@iamvukasin
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Jan 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
execution-events-example Ready Ready Preview, Comment Jan 14, 2026 8:40am

@iamvukasin
Copy link
Contributor Author

The problem is that the font metrics weren't properly set. I used this Python script to fix the font files:

from fontTools.ttLib import TTFont
import os

INPUT_FILENAME = 'app/britti-sans-variable.woff2'
OUTPUT_FILENAME = 'app/britti-sans-variable-fixed.woff2'

def get_max_bounds(font):
    """Scans every glyph to find the absolute highest and lowest points."""
    # Start with the global values from the 'head' table
    head = font['head']
    ymax = head.yMax
    ymin = head.yMin

    # Check the 'glyf' table for precision (TrueType fonts)
    if 'glyf' in font:
        glyf_table = font['glyf']
        # iterate over glyph names, not values directly
        for glyph_name in glyf_table.keys(): 
            glyph = glyf_table[glyph_name]
            # Some glyphs (like space) might not have bounding boxes
            if hasattr(glyph, 'yMax'):
                if glyph.yMax > ymax: ymax = glyph.yMax
            if hasattr(glyph, 'yMin'):
                if glyph.yMin < ymin: ymin = glyph.yMin
            
    return ymin, ymax

def patch_font(input_path, output_path):
    print(f"Processing: {input_path}")
    font = TTFont(input_path)
    
    # Get exact bounding box
    ymin, ymax = get_max_bounds(font)
    print(f"Detected Bounding Box: Top={ymax}, Bottom={ymin}")
    
    # 1. hhea Table (Mac/iOS/CSS primary)
    hhea = font['hhea']
    hhea.ascent = ymax
    hhea.descent = ymin
    hhea.lineGap = 0       # FORCE 0 GAP

    # 2. OS/2 Table (Windows/Android)
    os2 = font['OS/2']
    # sTypo metrics (The 'ideal' layout)
    os2.sTypoAscender = ymax
    os2.sTypoDescender = ymin
    os2.sTypoLineGap = 0   # FORCE 0 GAP

    # usWin metrics (The 'clipping' zone)
    os2.usWinAscent = ymax
    os2.usWinDescent = abs(ymin) # Must be positive

    # 3. FORCE "Use Typo Metrics"
    # This bit (bit 7) tells browsers to respect sTypo values
    os2.fsSelection |= 0b10000000 

    # Save
    font.save(output_path)
    print(f"Saved Fixed Font: {output_path}")

if __name__ == "__main__":
    patch_font(INPUT_FILENAME, OUTPUT_FILENAME)

How to run:

cd frontend
pip install font-line fonttools brotli
python fix_font.py

@iamvukasin iamvukasin changed the title Optically align info icon and text label Fix font measurement issues Jan 13, 2026
@Im-Madhur-Gupta Im-Madhur-Gupta merged commit 90f607a into main Jan 14, 2026
6 checks passed
@Im-Madhur-Gupta Im-Madhur-Gupta deleted the vukasin/optically-align-info-icon-and-label branch January 14, 2026 08:44
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

Successfully merging this pull request may close these issues.

3 participants