{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreihw63vsovq7wp3xiiwvih5mfnfkeyxcgvz3wi6yhagknttlvebpqm",
"uri": "at://did:plc:6dmfe46c76jjenq3kaxc5eds/app.bsky.feed.post/3mpzixlranfx2"
},
"path": "/b/2026/week-4-week-5-gsoc-update-almost-had-a-heart-attack",
"publishedAt": "2026-07-06T18:46:16.000Z",
"site": "https://ojasmaheshwari.github.io",
"textContent": "Ok, the title is **slightly** click-baity but hear me out.\n\nSo nearly 2 weeks ago, after writing a lot of code for making the font subsetting work for annotations, I found a flaw in my approach.\n\nI was never deleting the old original font after embedding it's subset version.\n\nSo what happened is that:\n\n * Suppose a user creates a new annotation in an empty PDF.\n * The subsetted font gets embedded and used in the PDF.\n * But the original font stays there, taking space.\n\n\n\nThis is actually slightly worse than when we had no subsetting at all.\n\nSo the solution should just be to delete the original font right? _Nope_\n\nIf we simply delete the original font, it would create the following problem:\n\n * Suppose a PDF with two annotations pointing / using the same font.\n * User edits the 1st annotation.\n * 1st annotation uses the subset font, and the old font gets deleted from the PDF.\n * The 2nd annotation is rendered useless.\n\n\n\nWhen I realized this, I thought I would need to completely change how I do subsetting, and almost all the code I had written will go to waste.\n\nMy new idea was to never let the full version of a font to exist inside the PDF. What I mean is subsetting immediately when the font is loaded from the disk and is about to be embedded as a `Font` object.\n\nBut I had a meeting with my mentor Albert Astals Cid yesterday, and we decided to settle on a simpler approach. We can simply detect if the font we want to delete is:- _a font we added ourselves_ or _a pre-existing font_ inside the PDF.\n\nIf we added it ourselves, we can safely remove it. Otherwise, let it stay there as it might be in use by other annotations.\n\nI implemented it today, and we have working font subsetting for freetext annotations right now (not merged).\nhttps://gitlab.freedesktop.org/poppler/poppler/-/merge_requests/2220\n\n## A simple size experiment\n\nHere's a simple experiment which demonstrates the impact of font subsetting on PDF file size:\n\nOriginal file size: 105820 bytes = 105.82 KB\n\nAfter adding an annotation with content \"hello world\":\n\nPoppler **without** font subsetting: 504699 bytes = 504.699 KB\n\nPoppler **with** font subsetting: 145806 bytes = 145.806 KB\n\nThat's like a 500% improvement...\n\n## What's next\n\n * Right now, I only do the subsetting for ttf/otf fonts and not for ttc fonts. I need to do that.\n * I need to make the subsetting work for forms as well.\n\n\n\n## Thank You\n\nGood Night!",
"title": "Week 4 + Week 5 GSoC update | Almost had a heart attack"
}