Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/plotters-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install fontconfig
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/plotters-bitmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install fontconfig
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
81 changes: 46 additions & 35 deletions .github/workflows/plotters-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install fontconfig
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -20,68 +22,77 @@ jobs:
msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.56.0
- name: Install fontconfig
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.88.0
override: true
args: --all-features
build_and_test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
with:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions-rs/toolchain@v1
with:
- name: Install fontconfig
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
- uses: actions-rs/cargo@v1
with:
command: test
args: --verbose
- uses: actions-rs/cargo@v1
with:
- uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --no-default-features --features=svg_backend --lib
test_all_features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions-rs/toolchain@v1
with:
- name: Install fontconfig
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
- uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --all-features
run_all_examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions-rs/cargo@v1
with:
- name: Install fontconfig
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/cargo@v1
with:
command: build
args: --verbose --release --examples
- name: Run all the examples
run: |
cd plotters
for example in examples/*.rs
do
../target/release/examples/$(basename ${example} .rs)
done
tar -czvf example-outputs.tar.gz plotters-doc-data
- uses: actions/upload-artifact@v4
with:
- name: Run all the examples
run: |
cd plotters
for example in examples/*.rs
do
../target/release/examples/$(basename ${example} .rs)
done
tar -czvf example-outputs.tar.gz plotters-doc-data
- uses: actions/upload-artifact@v4
with:
name: example-outputs
path: plotters/example-outputs.tar.gz
3 changes: 3 additions & 0 deletions .github/workflows/plotters-svg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install fontconfig
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rust-clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Install fontconfig
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev

- name: Install Rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install fontconfig
run: sudo apt-get update && sudo apt-get install -y libfontconfig-dev
- name: Install WASM tool chain
run: rustup target add wasm32-unknown-unknown
- name: Check WASM Target Compiles
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## Unreleased

### Changed

- Replace the `ttf` feature's `font-kit`-backed font backend with `fontique`
for native system font discovery and `swash` for glyph rasterization.
- Enabling the `ttf` feature now requires Rust 1.88 or newer; non-`ttf` builds
retain the crate's declared MSRV.
- The `fontconfig-dlopen` cargo feature now routes through
`fontique/fontconfig-dlopen`; behavior on Linux is unchanged.

### Breaking

- The `ttf` backend's `FontError` enum has been reshaped to drop
`font-kit`-typed payloads. Removed variants:
`GlyphError(Arc<font_kit::error::GlyphLoadingError>)` and
`FontHandleUnavailable`. Changed:
`FontLoadError(Arc<font_kit::error::FontLoadingError>)` is now
`FontLoadError(String)`. Downstream code that pattern-matches on these
variants must be updated. Glyph-loading failures are now reported via
`FontLoadError` / `FaceParseError` at font-load time rather than at draw
time.

### Removed

- Remove `font-kit` and `pathfinder_geometry` from the `ttf` dependency tree.

## Plotters 0.3.6 (2024-05-20)

### Added
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,17 +532,22 @@ The following list is a complete list of features that can be opted in or out.

| Name | Description | Additional Dependency |Default?|
|---------|--------------|--------|------------|
| bitmap\_encoder | Allow `BitMapBackend` to save the result to bitmap files | image, rusttype, font-kit | Yes |
| bitmap\_encoder | Allow `BitMapBackend` to save the result to bitmap files | image | Yes |
| svg\_backend | Enable `SVGBackend` Support | None | Yes |
| bitmap\_gif| Opt-in GIF animation Rendering support for `BitMapBackend`, implies `bitmap` enabled | gif | Yes |

- Font manipulation features

| Name | Description | Additional Dependency | Default? |
|----------|------------------------------------------|-----------------------|----------|
| ttf | Allows TrueType font support | font-kit | Yes |
| ttf | Allows TrueType font support | fontique, swash, ttf-parser, lazy_static | Yes |
| ab_glyph | Skips loading system fonts, unlike `ttf` | ab_glyph | No |

The `ttf` feature uses native system font discovery through `fontique` and
glyph rasterization through `swash`, while retaining `ttf-parser` for legacy
kerning table support. Enabling `ttf` requires Rust 1.88 or newer; builds that
disable `ttf` keep the crate's declared MSRV.

`ab_glyph` supports TrueType and OpenType fonts, but does not attempt to
load fonts provided by the system on which it is running.
It is pure Rust, and easier to cross compile.
Expand Down Expand Up @@ -646,4 +651,3 @@ pub struct RGBAColor(pub u8, pub u8, pub u8, pub f64);
In the case that error handling is important, you need manually call the `present()` method before the backend gets dropped.
For more information, please see the examples.


32 changes: 32 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

This documents contains the release notes for every major release since v0.3.

## Development Notes

### TTF Font Backend

The default `ttf` feature no longer depends on `font-kit` or
`pathfinder_geometry`. It uses `fontique` for native system font discovery and
`swash` for glyph rasterization, while retaining `ttf-parser` for legacy
kerning table support.

Enabling `ttf` now requires Rust 1.88 or newer. Builds that disable `ttf`
retain the crate's declared MSRV.

The `fontconfig-dlopen` cargo feature continues to enable runtime loading of
the fontconfig C library on Linux, now routed through `fontique`'s feature of
the same name.

#### Breaking changes in `FontError`

The `ttf` backend's public `FontError` enum has been reshaped to drop
`font-kit`-typed payloads:

- Removed: `GlyphError(Arc<font_kit::error::GlyphLoadingError>)` and
`FontHandleUnavailable`.
- Changed: `FontLoadError(Arc<font_kit::error::FontLoadingError>)` is now
`FontLoadError(String)`.

Downstream code that pattern-matches on these variants must be updated.
Glyph-loading failures previously surfaced through `GlyphError` at draw time;
they are now reported via `FontLoadError` / `FaceParseError` at font-load
time, so error handling around `FontDataInternal::new` and the surrounding
`text_anchor` / `IntoTextStyle` machinery should be reviewed.

## Plotters v0.3

Plotters v0.3 is shipped with multiple major improvements.
Expand Down
10 changes: 7 additions & 3 deletions doc-template/readme.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,22 @@ The following list is a complete list of features that can be opted in or out.

| Name | Description | Additional Dependency |Default?|
|---------|--------------|--------|------------|
| bitmap\_encoder | Allow `BitMapBackend` to save the result to bitmap files | image, rusttype, font-kit | Yes |
| bitmap\_encoder | Allow `BitMapBackend` to save the result to bitmap files | image | Yes |
| svg\_backend | Enable `SVGBackend` Support | None | Yes |
| bitmap\_gif| Opt-in GIF animation Rendering support for `BitMapBackend`, implies `bitmap` enabled | gif | Yes |

- Font manipulation features

| Name | Description | Additional Dependency | Default? |
|----------|------------------------------------------|-----------------------|----------|
| ttf | Allows TrueType font support | font-kit | Yes |
| ttf | Allows TrueType font support | fontique, swash, ttf-parser, lazy_static | Yes |
| ab_glyph | Skips loading system fonts, unlike `ttf` | ab_glyph | No |

The `ttf` feature uses native system font discovery through `fontique` and
glyph rasterization through `swash`, while retaining `ttf-parser` for legacy
kerning table support. Enabling `ttf` requires Rust 1.88 or newer; builds that
disable `ttf` keep the crate's declared MSRV.

`ab_glyph` supports TrueType and OpenType fonts, but does not attempt to
load fonts provided by the system on which it is running.
It is pure Rust, and easier to cross compile.
Expand Down Expand Up @@ -369,4 +374,3 @@ pub fn register_font(
For more information, please see the examples.

$$style$$

2 changes: 1 addition & 1 deletion plotters-svg/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ impl<'a> DrawingBackend for SVGBackend<'a> {

let color = image::ColorType::Rgb8;

encoder.write_image(src, w, h, color).map_err(|e| {
encoder.write_image(src, w, h, color.into()).map_err(|e| {
DrawingErrorKind::DrawingError(Error::new(
std::io::ErrorKind::Other,
format!("Image error: {}", e),
Expand Down
14 changes: 9 additions & 5 deletions plotters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ path = "../plotters-svg"
[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))'.dependencies]
ttf-parser = { version = "0.25.1", optional = true }
lazy_static = { version = "1.4.0", optional = true }
pathfinder_geometry = { version = "0.5.1", optional = true }
font-kit = { version = "0.14.2", optional = true }
fontique = { version = "0.9.0", optional = true }
swash = { version = "0.2.7", optional = true }
ab_glyph = { version = "0.2.12", optional = true }
once_cell = { version = "1.8.0", optional = true }

Expand Down Expand Up @@ -105,10 +105,15 @@ point_series = []
surface_series = []

# Font implementation
ttf = ["font-kit", "ttf-parser", "lazy_static", "pathfinder_geometry"]
ttf = [
"fontique",
"swash",
"ttf-parser",
"lazy_static",
]
# dlopen fontconfig C library at runtime instead of linking at build time
# Can be useful for cross compiling, especially considering fontconfig has lots of C dependencies
fontconfig-dlopen = ["font-kit/source-fontconfig-dlopen"]
fontconfig-dlopen = ["fontique/fontconfig-dlopen"]

ab_glyph = ["dep:ab_glyph", "once_cell"]

Expand Down Expand Up @@ -143,4 +148,3 @@ path = "benches/main.rs"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "doc_cfg"]

9 changes: 7 additions & 2 deletions plotters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,22 @@ The following list is a complete list of features that can be opted in or out.

| Name | Description | Additional Dependency |Default?|
|---------|--------------|--------|------------|
| bitmap\_encoder | Allow `BitMapBackend` to save the result to bitmap files | image, rusttype, font-kit | Yes |
| bitmap\_encoder | Allow `BitMapBackend` to save the result to bitmap files | image | Yes |
| svg\_backend | Enable `SVGBackend` Support | None | Yes |
| bitmap\_gif| Opt-in GIF animation Rendering support for `BitMapBackend`, implies `bitmap` enabled | gif | Yes |

- Font manipulation features

| Name | Description | Additional Dependency | Default? |
|----------|------------------------------------------|-----------------------|----------|
| ttf | Allows TrueType font support | font-kit | Yes |
| ttf | Allows TrueType font support | fontique, swash, ttf-parser, lazy_static | Yes |
| ab_glyph | Skips loading system fonts, unlike `ttf` | ab_glyph | No |

The `ttf` feature uses native system font discovery through `fontique` and
glyph rasterization through `swash`, while retaining `ttf-parser` for legacy
kerning table support. Enabling `ttf` requires Rust 1.88 or newer; builds that
disable `ttf` keep the crate's declared MSRV.

`ab_glyph` supports TrueType and OpenType fonts, but does not attempt to
load fonts provided by the system on which it is running.
It is pure Rust, and easier to cross compile.
Expand Down
4 changes: 2 additions & 2 deletions plotters/src/style/font/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl FontData for FontDataInternal {
}

/// Note: This is only a crude estimatation, since for some backend such as SVG, we have no way to
/// know the real size of the text anyway. Thus using font-kit is an overkill and doesn't helps
/// the layout.
/// know the real size of the text anyway. Thus using the system font backend is overkill and
/// doesn't help the layout.
fn estimate_layout(&self, size: f64, text: &str) -> Result<LayoutBox, Self::ErrorType> {
let em = size / 1.24 / 1.24;
Ok((
Expand Down
Loading
Loading