Skip to content

Commit 7056fcc

Browse files
authored
Merge pull request #424 from Monadic-Cat/update-font-docs
update font backend documentation
2 parents 6156a27 + dc34dac commit 7056fcc

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

doc-template/readme.template.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,38 @@ The following list is a complete list of features that can be opt in and out.
278278

279279
- Font manipulation features
280280

281-
| Name | Description | Additional Dependency |Default?|
282-
|---------|--------------|--------|------------|
283-
| ttf | Allows TrueType font support | rusttype, font-kit | Yes |
281+
| Name | Description | Additional Dependency | Default? |
282+
|----------|------------------------------------------|-----------------------|----------|
283+
| ttf | Allows TrueType font support | font-kit | Yes |
284+
| ab_glyph | Skips loading system fonts, unlike `ttf` | ab_glyph | No |
285+
286+
`ab_glyph` supports TrueType and OpenType fonts, but does not attempt to
287+
load fonts provided by the system on which it is running.
288+
It is pure Rust, and easier to cross compile.
289+
To use this, you *must* call `plotters::style::register_font` before
290+
using any `plotters` functions which require the ability to render text.
291+
This function only exists when the `ab_glyph` feature is enabled.
292+
```rust
293+
/// Register a font in the fonts table.
294+
///
295+
/// The `name` parameter gives the name this font shall be referred to
296+
/// in the other APIs, like `"sans-serif"`.
297+
///
298+
/// Unprovided font styles for a given name will fallback to `FontStyle::Normal`
299+
/// if that is available for that name, when other functions lookup fonts which
300+
/// are registered with this function.
301+
///
302+
/// The `bytes` parameter should be the complete contents
303+
/// of an OpenType font file, like:
304+
/// ```ignore
305+
/// include_bytes!("FiraGO-Regular.otf")
306+
/// ```
307+
pub fn register_font(
308+
name: &str,
309+
style: FontStyle,
310+
bytes: &'static [u8],
311+
) -> Result<(), InvalidFont>
312+
```
284313

285314
- Coordinate features
286315

plotters/src/style/font/ab_glyph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub struct InvalidFont {
4141
/// The `name` parameter gives the name this font shall be referred to
4242
/// in the other APIs, like `"sans-serif"`.
4343
///
44+
/// Unprovided font styles for a given name will fallback to `FontStyle::Normal`
45+
/// if that is available for that name, when other functions lookup fonts which
46+
/// are registered with this function.
47+
///
4448
/// The `bytes` parameter should be the complete contents
4549
/// of an OpenType font file, like:
4650
/// ```ignore

0 commit comments

Comments
 (0)