Skip to content

Commit

Permalink
Merge branch 'master' into shape_own
Browse files Browse the repository at this point in the history
  • Loading branch information
raphlinus committed Jan 12, 2019
2 parents 7bc5056 + ff0d74a commit 54b2138
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
os:
- osx
- linux

language: rust
Expand All @@ -13,6 +14,7 @@ cache: cargo
before_script:
- rustup component add rustfmt
script:
- if [[ "$TRAVIS_OS_NAME" = "osx" ]]; then brew update; brew install cairo; fi
- if [[ "$TRAVIS_RUST_VERSION" = stable ]]; then cargo fmt --all -- --check; fi
- RUSTFLAGS="-D warnings" cargo check --all --exclude piet-direct2d || exit
- cargo build --all --exclude piet-direct2d
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@ This repo is structured as a core API crate, "piet" and a separate crate for eac

A companion for Bézier path representation and geometry is [kurbo].

The library is of course named after [Piet Mondrian]. It's abstract and hopefully will be used for drawing lots of rectangles.
## Roadmap

Since the project is in its infant stages, there's not currently a set roadmap. For a good idea of what the library will eventually be capable of see [this list][resvg backend requirements] of requirements to be a backend 2D graphics library for the SVG rendering library resvg.

## Contributing

Contributions are welcome! It's in early stages, so there are lots of opportunities to fill things out.

You can find other collaborators at [xi.zulipchat.com][zulip] under the #druid stream.

## Inspirations

Piet's interface is largely inspired by the [Skia Graphics Library] as well as the [C++ 2D graphics api proposal] although piet aims to be much more lightweight and modular.

## The Name

The library is of course named after [Piet Mondrian]. It's abstract and hopefully will be used for drawing lots of rectangles.

[blog post]: https://raphlinus.github.io/rust/graphics/2018/10/11/2d-graphics.html
[druid]: https://github.com/xi-editor/druid
[kurbo]: https://github.com/linebender/kurbo
[resvg backend requirements]: https://github.com/RazrFalcon/resvg/blob/master/docs/backend_requirements.md
[zulip]: https://xi.zulipchat.com
[Skia Graphics Library]: https://skia.org
[C++ 2D graphics api proposal]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0267r8.pdf
[Piet Mondrian]: https://en.wikipedia.org/wiki/Piet_Mondrian
8 changes: 5 additions & 3 deletions piet-cairo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ The need for text shaping will be common to many low-level renderers that are no

## Building on non-Linux

Cairo is quite portable, and it is quite feasible to build on other systems. However, the [cairo-rs] crate seems to expect a library to be provided, rather than building it from sources. On Windows, I've been using prebuilt binary releases from [cairo-windows].
Cairo is quite portable, and it is quite feasible to build on other systems. However, the [cairo-rs] crate seems to expect a library to be provided, rather than building it from sources.

See the [Gtk-rs requirements] page for more detailed instructions how to get it properly installed. On macOS with Homebrew, the following should work:
On Windows, I've been using prebuilt binary releases from [cairo-windows].

On macOS with Homebrew, the following should work:

```shell
brew install gtk+3
brew install cairo
```

TODO: nicer installation instructions (contributions welcome)
Expand Down
8 changes: 4 additions & 4 deletions piet-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ fn draw_picture_0(rc: &mut impl RenderContext) {

rc.stroke(Line::new((80.0, 12.0), (80.0 + w, 12.0)), &brush, 1.0, None);

rc.save();
rc.transform(Affine::rotate(0.1));
rc.draw_text(&layout, (80.0, 10.0), &brush);
rc.restore();
rc.with_save(|rc| {
rc.transform(Affine::rotate(0.1));
rc.draw_text(&layout, (80.0, 10.0), &brush);
});

let clip_path = star(Vec2::new(90.0, 45.0), 10.0, 30.0, 24);
rc.clip(clip_path, FillRule::NonZero);
Expand Down
13 changes: 13 additions & 0 deletions piet/src/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ pub trait RenderContext {
/// Pushes the current context state onto a stack, to be popped by
/// [`restore`](#method.restore).
///
/// Prefer [`with_save`](#method.with_save) if possible, as that statically
/// enforces balance of save/restore pairs.
///
/// The context state currently consists of a clip region and an affine
/// transform, but is expected to grow in the near future.
fn save(&mut self);
Expand All @@ -118,6 +121,16 @@ pub trait RenderContext {
/// that method for details.
fn restore(&mut self);

/// Do graphics operations with the context state saved and then restored.
///
/// Equivalent to [`save`](#method.save), calling `f`, then
/// [`restore`](#method.restore). See those methods for more details.
fn with_save(&mut self, f: impl FnOnce(&mut Self)) {
self.save();
f(self);
self.restore();
}

/// Finish any pending operations.
///
/// This will generally be called by a shell after all user drawing
Expand Down

0 comments on commit 54b2138

Please sign in to comment.