-
Notifications
You must be signed in to change notification settings - Fork 6
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
Possibility to enable passing unicode-range instead of glyphs? #6
Comments
Good idea. Should be fairly straightforward. I also wanted to look into whether it'd be possible to only include ligatures that might actually be exercised by the |
Hmm, yeah, the In terms of subsetting I guess it's fine to just expand that to all the possible values, whether or not those codepoints actually exists in the font (or in the Unicode repertoire 😅 ). The subsetting code should just ignore the codepoints that don't exist in the original font. |
This module looks like it's up to the task: /~https://github.com/Japont/unicode-range |
Good find! Yes, I made a super-naïve test-script, before I stumbled upon that
true … but isn't the text converted to a Set (of sorts, I'm not familiar with harfbuzz) and sorted? |
Great! Good luck! 🍀
Yes, I think we'll have to go even more low level when instructing harfbuzz about which glyphs to include -- if that's even supported 😬 |
const path = require('path');
const { readFile, writeFile } = require('fs').promises;
const subsetFont = require('subset-font');
const { UnicodeRange } = require('@japont/unicode-range');
const latinRange = 'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD';
// util to handle passing unicode-range as a string
function formatRange(range) {
if (typeof range === 'string') {
return range.replace(/\s*/g, '').split(',');
}
return range;
}
function getGlyphsFromUnicodeRange(range) {
// UnicodeRange currently requires an array of ranges …
const rangeArray = formatRange(range);
const glyphs = UnicodeRange.parse(rangeArray).map((cp) =>
String.fromCodePoint(cp)
);
return glyphs;
}
async function generateFont() {
const font = await readFile(
path.resolve(__dirname, 'woff2', 'SomeFontFile.woff2')
);
const glyphs = getGlyphsFromUnicodeRange(latinRange);
const result = await subsetFont(font, glyphs, {
targetFormat: 'woff2',
});
// ... and so on
} Did a quick try, and from what I can tell so far, that library does the trick 👍🏼 . I don't know how you feel, but figuring out which glyphs to subset might seem a bit out of scope for Skipping unused ligatures is an interesting one, depending on language group there might be some savings. I have mostly thought about it as a on/off thing, (ie. |
Great that you got it to work! Thanks for sharing your solution. I agree with your scope concern. Let's leave it here for now and see if it comes up as a common request. Maybe we can even add a link to this issue to the README.
I'll probably explore it one day when I have time. I'm not sure that the savings will be big either, it's mostly from a perfectionist angle. Spending years hunting down these kilobyte savings does that to you 🙈
Ah yes, that makes sense! Btw. |
I'd also be happy to entertain the idea of configuring |
Yes it could be a good fit within Regarding the per |
Yeah, that is the core use case, but I'm not opposed to exposing more controls like that. We could even do it as a custom CSS property in the @font-face {
font-family: foo;
src: ...;
font-weight: 700;
-subfont-unicode-range: U+0131, U+0152-0153, U+02BB-02BC;
} |
For what it's worth, Munter/subfont#161 implemented the ability to specify text to include in the subset via I'll close this for now. |
subset-font allows for passing in a string with glyphs to subset, but would it be interesting to also include an option to pass a
unicode-range
like possible withpyftsubset
?I'm aware that
subfont
provides a conversion utility to convert a string to aunicode-range
(for CSS output) but do you know if there's a standard-ish way of doing the opposite? I'm suspecting there might be a few weird exceptions to take into account?The text was updated successfully, but these errors were encountered: