-
Notifications
You must be signed in to change notification settings - Fork 24
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
Initial glyph loading/scaling crate #191
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
70d40a8
initial pared down glyph loader
dfrg 675b274
oh, clippy
dfrg e9a0c0c
simplify high level glyph representation
dfrg 0385640
add C API mockup doc
dfrg 051427e
C requires parens around if conditions
dfrg 6d694d0
Merge branch 'googlefonts:main' into load-glyphs
dfrg 3b2654a
Update punchcut/README.md
dfrg 17dd7ab
Update punchcut/src/scaler.rs
dfrg 0b44e5d
Update punchcut/src/source/glyf/scaler.rs
dfrg aa55c79
Update punchcut/src/scaler.rs comment formatting
dfrg 675d406
Merge branch 'googlefonts:main' into load-glyphs
dfrg 6b374a6
update read-fonts version
dfrg 737e0e9
break GlyphScaler::load() into separate functions
dfrg 7c28f2c
rename hinting modes
dfrg 3671a00
change CacheSlot::Cached to a struct variant with named fields
dfrg f5a4fa7
remove currently unused math functions
dfrg e5fa151
Remove Outline type and add PathSink trait
dfrg a3342dd
derive Default for Context
dfrg e276383
update README source matrix
dfrg ecba6f3
feature gate hinting code
dfrg 96d007d
Remove peniko/kurbo dependency and...
dfrg 582a590
Improve single letter variable names and rename CONIC -> QUAD
dfrg 3ad6a4e
derive debug and clone for more types
dfrg 3008574
move variation setup in ScalerBuilder::build() to separate function
dfrg 3e10a07
Merge branch 'googlefonts:main' into load-glyphs
dfrg 5483eee
Address more review feedback
dfrg dd7134d
fmt and fix mismatched args in feature gated code
dfrg c81c504
fmt --all
dfrg 40d4cdc
fix weird clippy lint
dfrg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ members = [ | |
"font-codegen", | ||
"write-fonts", | ||
"otexplorer", | ||
"punchcut", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "punchcut" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT/Apache-2.0" | ||
description = "Loading glyphs from OpenType font files." | ||
repository = "https://github.com/googlefonts/fontations" | ||
readme = "README.md" | ||
categories = ["text-processing", "parsing", "graphics"] | ||
|
||
[features] | ||
hinting = [] | ||
|
||
[dependencies] | ||
read-fonts = { version = "0.0.5", path = "../read-fonts" } | ||
|
||
[dev-dependencies] | ||
read-fonts = { version = "0.0.5", path = "../read-fonts", features = ["test_data"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# punchcut | ||
|
||
This is a library for high level loading of glyph outlines (and eventually color outlines and bitmaps) | ||
from font files. The intention is fully featured (e.g. variations and hinting) support for all glyph sources | ||
except for the SVG table. | ||
|
||
This is part of the [oxidize](https://github.com/googlefonts/oxidize) project. | ||
|
||
## Features | ||
|
||
Current (✔️), near term (🔜) and planned (⌛) feature matrix: | ||
|
||
| Source | Loading | Variations | Hinting | | ||
|--------|---------|------------|---------| | ||
| glyf | ✔️ | 🔜 | ⌛* | | ||
| CFF | ⌛ | ⌛ | ⌛ | | ||
| CFF2 | ⌛ | ⌛ | ⌛ | | ||
| COLRv0 | 🔜 | 🔜 | * | | ||
| COLRv1 | 🔜 | 🔜 | * | | ||
| EBDT | 🔜 | - | - | | ||
| CBDT | 🔜 | - | - | | ||
| sbix | 🔜 | - | - | | ||
|
||
\* A working implementation exists for hinting but is not yet merged. | ||
|
||
\*\* This will be supported but is probably not desirable due the general affine transforms | ||
present in the paint graph. | ||
|
||
## The name? | ||
|
||
Wikipedia says "[punchcutting](https://en.wikipedia.org/wiki/Punchcutting) is a craft used in traditional | ||
typography to cut letter punches in steel as the first stage of making metal type." The punches carry the | ||
outline of the desired letter which can be used to create a mold to transfer the design to various | ||
surfaces. | ||
|
||
The primary purpose of this crate is the generation of outlines from font data, so the name seemed | ||
appropriate. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use read_fonts::{types::GlyphId, ReadError}; | ||
dfrg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use std::fmt; | ||
|
||
/// Errors that may occur when loading glyphs. | ||
#[derive(Clone, Debug)] | ||
pub enum Error { | ||
/// No viable sources were available. | ||
NoSources, | ||
/// The requested glyph was not present in the font. | ||
GlyphNotFound(GlyphId), | ||
/// Exceeded a recursion limit when loading a glyph. | ||
RecursionLimitExceeded(GlyphId), | ||
/// Error occured during hinting. | ||
#[cfg(feature = "hinting")] | ||
HintingFailed(GlyphId), | ||
/// An anchor point had invalid indices. | ||
InvalidAnchorPoint(GlyphId, u16), | ||
/// Error occured when reading font data. | ||
Read(ReadError), | ||
} | ||
|
||
impl From<ReadError> for Error { | ||
fn from(e: ReadError) -> Self { | ||
Self::Read(e) | ||
} | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
Self::NoSources => write!(f, "No glyph sources are available for the given font"), | ||
Self::GlyphNotFound(gid) => write!(f, "Glyph {} was not found in the given font", gid), | ||
Self::RecursionLimitExceeded(gid) => write!( | ||
dfrg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
f, | ||
"Recursion limit ({}) exceeded when loading composite component {}", | ||
crate::GLYF_COMPOSITE_RECURSION_LIMIT, | ||
gid | ||
), | ||
#[cfg(feature = "hinting")] | ||
Self::HintingFailed(gid) => write!(f, "Bad hinting bytecode for glyph {}", gid), | ||
dfrg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Self::InvalidAnchorPoint(gid, index) => write!( | ||
f, | ||
"Invalid anchor point index ({}) for composite glyph {}", | ||
index, gid | ||
), | ||
Self::Read(e) => write!(f, "{}", e), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for Error {} | ||
|
||
/// Result type for errors that may occur when loading glyphs. | ||
pub type Result<T> = core::result::Result<T, Error>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide (a link could suffice) a basic example of use, say loading a font from a file and getting the outline of something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add some example code. Inline is fairly common in Rust READMEs