googlefonts / googlefonts/fontations

Docu question: basic instructions

Open
#629 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
826
Forks
75
Avg merge
22h 33m
Merged PRs (30d)
75

Description

Hey there,

I am wondering if there are some basic instructions which may help a newbie (like me) to get familiar with the code and functionality of this repository? I use python and javascript to read/modify fonts (via code), but I see the potential of Rust. It's super fast :) It feels like it may become the new 'fonttools'. To be honest, I am very curious :)

But it's challenging to get familiar with the code without some example.
I am wondering if it would be possible to get some help (with common font related questions), eg:
How to loop through glyphs?
How to loop through all attributes of a font table? (Is there something similar like pythons dir() for Rust?)
How to get some basic information for each glyph (like unicode, width, outlines, composites, etc)
How to change a name table entry?
How to subset a font?
How to change the vertical metrics?
How to get the full name of a font?
How to get the variable font axes and coordinates?
How to get a list of the opentype features?
etc.

You know, something like:
```
// Get the glyph ID via unicode codepoint?
use read_fonts::{FontRef, TableProvider, tables::cmap::Cmap};

fn main() {
let path_to_my_font_file = std::path::Path::new("/Users/ollimeier/Documents/Vary-Black.otf");

let font_bytes = std::fs::read(path_to_my_font_file).unwrap();
let font = FontRef::new(&font_bytes).expect("failed to read font data");

let cp:u32 = 0x00041;
let cmap: Cmap = font.cmap().expect("missing 'cmap' table");
let gid = cmap.map_codepoint(cp);

println!("0x0041: {:?}", gid);
}

```

or

```
// Change the OS/2 usWeightClass?
use read_fonts::{FontRef, TableProvider};
use write_fonts::{
from_obj::ToOwnedTable,
tables::os2::Os2,
FontBuilder,
};

fn main() {
let path_to_my_font_file = std::path::Path::new("/Users/ollimeier/Documents/Vary-Black.otf");

let font_bytes = std::fs::read(path_to_my_font_file).unwrap();
let font = FontRef::new(&font_bytes).expect("failed to read font data");
let mut os2: Os2 = font.os2().expect("missing 'OS/2' table").to_owned_table();
os2.us_weight_class = 920;

let new_bytes = FontBuilder::new()
.add_table(&os2)//(&head)
.unwrap() // errors if we can't compile 'head', unlikely here
.copy_missing_tables(font)
.build();

std::fs::write("/Users/ollimeier/Documents/Vary-Black_mod_20230926.otf", &new_bytes).unwrap();
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

No file or test is named. Start by reviewing the read_fonts and write_fonts APIs used in the examples, including FontRef, TableProvider, Cmap, Os2, and FontBuilder. Done means a newcomer-oriented guide with working examples for the listed font inspection and modification tasks.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.