Comments (2)
As it happens just this afternoon I wrote a snippet of code that does exactly this. FYI calling subtable.glyph_index
on every character in a font (especially a CJK font with 1000s of characters) is expensive so I filter the range of unicode characters I want to rasterize.
This is almost copy-paste from fontdue's loading code, so +1 for adding an API to access the data fontdue is collecting! (Would also be nice to be able to filter to a list of ranges. By far, fontdue iterating every character in a large CJK font is the slowest part of my code.)
let character_ranges_to_include = vec![
(32, 128),
//(0x4e00, 0x5FCC) // large range of CJK characters for testing
];
let mut characters_to_include = vec![];
use ttf_parser::{Face, GlyphId, TableName};
let face = Face::from_slice(font_data, 0).unwrap();
for subtable in face.character_mapping_subtables() {
subtable.codepoints(|codepoint| {
for range in &character_ranges_to_include {
if codepoint >= range.0 && codepoint <= range.1 {
if let Some(glyph_id) = subtable.glyph_index(codepoint) {
//let name = face.glyph_name(glyph_id);
//println!("glyph codepoint: {} {:?} id: {:?} name: {:?}", codepoint, std::char::from_u32(codepoint), glyph_id, name);
characters_to_include.push(std::char::from_u32(codepoint).unwrap());
}
}
}
});
}
read metadata 0.40333298ms
load font to fontdue 232.11732ms <-- could be reduced by filtering ranges of characters
rasterize 0.7775ms
create rects to place 0.060416ms
generated placement for 512x512 texture in 0.148333ms
determined placement 0.431833ms
blit to single texture 0.173125ms
from fontdue.
You can achieve enumerating over all the glyph data like: https://github.com/mooman219/fontdue/blob/master/tests/letter_render_tests.rs#L70
I recently changed this to make it easier.
from fontdue.
Related Issues (20)
- C interface HOT 6
- Fonts with variable weight? HOT 2
- Adding an example for calculating the bounding box HOT 8
- can fontdue rasterize with fractional pixel offsets? HOT 5
- SDF texture generation HOT 1
- Ligature support- pairing with other libraries
- Rasterize a whole string HOT 3
- Glyph metrics are incorrect HOT 1
- Font line metrics don't match character metrics
- Png Support HOT 1
- How to rasterize colored emojis HOT 1
- Can you add an example of how to create a simple letter and save as a font? HOT 1
- Option to drop the rest of a line instead of wrapping HOT 2
- Bounding box of laid out text for easy shiftnig of the origin?
- Misaligned pointer dereference in `get_bitmap` HOT 4
- Custom font colors HOT 1
- Live demo error when a glagolitic character ( Ⱆ ) is used HOT 3
- 0.7.4 is a semver break HOT 3
- Slight layout performance regression
- No ability to query font for its name 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 fontdue.