Comments (4)
If an iterator pattern works then something like this is possible:
let names = face.tables().name.unwrap().names;
let fvar = face.tables().fvar.unwrap();
for instance in fvar.instances() {
let subfamily = names
.into_iter()
.find(|n| n.name_id == instance.subfamily_name_id && n.is_unicode())
.unwrap()
.to_string()
.unwrap();
let ps_name = instance
.ps_name_id
.and_then(|name_id| {
names
.into_iter()
.find(|n| n.name_id == name_id && n.is_unicode())
})
.and_then(|n| n.to_string());
println!("subfamily: {subfamily}, ps_name: {ps_name:?}");
for (axis, value) in fvar.axes.into_iter().zip(instance.user_tuples) {
let axis_name = axis.tag.to_string();
println!("\t{axis_name} {value:?}")
}
println!();
}
e.g.
./target/debug/examples/fvar ~/Library/Fonts/RobotoCondensed-VariableFont_wght.ttf
subfamily: Thin, ps_name: Some("RobotoCondensed-Thin")
wght Fixed(100.0)
subfamily: ExtraLight, ps_name: Some("RobotoCondensed-ExtraLight")
wght Fixed(200.0)
subfamily: Light, ps_name: Some("RobotoCondensed-Light")
wght Fixed(300.0)
subfamily: Regular, ps_name: Some("RobotoCondensed-Regular")
wght Fixed(400.0)
subfamily: Medium, ps_name: Some("RobotoCondensed-Medium")
wght Fixed(500.0)
subfamily: SemiBold, ps_name: Some("RobotoCondensed-SemiBold")
wght Fixed(600.0)
subfamily: Bold, ps_name: Some("RobotoCondensed-Bold")
wght Fixed(700.0)
subfamily: ExtraBold, ps_name: Some("RobotoCondensed-ExtraBold")
wght Fixed(800.0)
subfamily: Black, ps_name: Some("RobotoCondensed-Black")
wght Fixed(900.0)
https://github.com/inferiorhumanorgans/ttf-parser/tree/fvar-instance
I'll hold off on a PR until someone who actually wants this feature can chime in with a use case and whether or not this is sufficient.
from ttf-parser.
Yes, it is not implemented.
from ttf-parser.
@RazrFalcon do you mind if I submit a PR for this?
from ttf-parser.
Sure. Note that the PostScript name field is optional, making parsing more convoluted, since you cannot use read_array16
You can check it using:
let has_post_script_name = instance_length == (axes_count * 4) + 6;
I guess the only way to implement it is by creating a custom wrapper for InstanceRecords data blob with a get
method that will do the parsing.
from ttf-parser.
Related Issues (20)
- Can you add an example of how to create a simple letter and save as a font? HOT 3
- Serde feature HOT 1
- The direction of outline contour? HOT 3
- how to get a variable instance of a variable font HOT 2
- Support woff2 HOT 3
- Does it support monochrome fonts HOT 1
- parse_char_string_width does not take subroutines into account HOT 6
- Support GDEF Ligature Caret List Table HOT 3
- Getting the number of faces HOT 15
- font_collection_num_fonts_overflow test fails on 32-bit architectures HOT 4
- Face::set_variation change in behaviour HOT 1
- Request for Addition of an Interface to Extract Basic Font Information from Files to Support Directory Scan of All Fonts for Rendering Unicode Text HOT 2
- ttf-parser v0.20 fails to compile on Rust 1.76 HOT 2
- unicode_ranges Documentation is Incorrect HOT 1
- Vertical bearings does not exist when calling `glyph_ver_side_bearings` HOT 4
- Potential bug: LookupFlags.mark_attachment_type() always returns 0 HOT 1
- Support TrueType `ltag` table
- seac-glyph outlining fails HOT 11
- Symbol TTF Not Working? 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 ttf-parser.