Comments (6)
Nevermind, sorry! I was doing font.onload(callback)
instead of font.onload = callback
as I should have been doing. Onload is indeed called correctly for system fonts.
However, now I'll hijack this issue to ask a different question: Currently there is a 10ms wait before system fonts are processed. But the processing step itself also contains a 50ms timeout delay - which seems like it should obviate the need for the first delay. Are they both truly necessary or can the first 10ms delay be omitted? My limited testing in Chrome shows no problems with processing it immediately.
from lib-font.
And one more related question: The delayedValidate function is currently called with a setTimeout of 50ms in order to give the browser time to finish rendering/painting. This seems like it would a good use case for requestAnimationFrame
which should be called when the repaint is finished.
I tried plugging it in and it seems to work fine in latest versions of Chrome, Firefox and Opera, though I haven't tested extensively. Would this be a good improvement, or are there good reasons not to use RAF here? I can submit a PR if you'd like.
from lib-font.
Hmm, honestly at this point you're probably going to get better mileage out of the opentype.js linked to from the README.md. It shouldn't have any artificial delays I had to use back when I made this library.
from lib-font.
Unfortunately, it seems that Opentype does not support system fonts, nor does it have a font.measureText
equivalent.
I pretty much only have a single use case: get the bounding box of a string with a given (already loaded) font & size, before rendering to the DOM - this way you can do more interesting layout things faster. Otherwise you need to add to the DOM, measure, then remove, which is slow.
It seems like this is not a well-covered case by existing libraries. I may consider forking Font.js or Opentype.js to create a library that does only this.
from lib-font.
that's true, it won't do system font metrics since it shapes based on the actual font file. Both the 10ms and 50ms delays are mostly to move over to the next tick without immediately hijacking the thread again. Compared to the time necessary to do the canvas drawing and measuring, the combined 60ms (~4 frames if we're thinking in animation timing) is pretty much insignificant, but I didn't want to use 0ms or 1ms timeout values. Immediate processing will do terrible things if you're also loading other scripts at the same time, so you always want to bake in a few "breathing spaces" in long scripts to make sure it doesn't lock the page. I know requestAnimationFrame exists, but I don't use it for anything except literally that: animation draw loops.
from lib-font.
obsolete with the 2019 rewrite
from lib-font.
Related Issues (20)
- rollup is broken HOT 4
- rename font.js to lib-font HOT 1
- How to use lookup type 7 (Extension Substitution) HOT 3
- implement extension substitution for gsub lookuptype 7
- Fonts that trip up LibFont HOT 10
- Fix woff2 support
- add a github action for PRs that runs the tests HOT 2
- Add support for WOFF2 transformed table data for glyf/loca/htmx
- Flaticon.woff2 is not parsing correctly. HOT 15
- use node's zlib for brotli decode / gunzip HOT 1
- GSUB bug when decoding Castoro HOT 11
- Color font info HOT 1
- Error reading SVG table (ReferenceError: uint16 is not defined) HOT 5
- Investigate test framework not dealing with exceptions properly
- font.opentype.tables is not enumerable HOT 4
- GSUB lookup type 6 sometimes fails on inputGlyphCount HOT 12
- Prebuilt `lib-font.browser.js` bundle throws `Unexpected token 'export'` error HOT 4
- Modify font object HOT 2
- Use the lib-font browser bundle in a webpack project. HOT 4
- Supports CommonJS HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lib-font.