Skip to content

Commit

Permalink
Merge #12
Browse files Browse the repository at this point in the history
12: quality of life changes r=Veykril a=Veykril

Fixes #8 

Co-authored-by: Lukas Wirth <[email protected]>
  • Loading branch information
bors[bot] and Veykril committed May 11, 2019
2 parents e30afdc + 15af5cf commit 24d01a8
Show file tree
Hide file tree
Showing 28 changed files with 319 additions and 300 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/Veykril/blend2d-rs"
license = "MIT/Apache-2.0"
categories = ["api-bindings"]
readme = "README.md"
exclude = ["examples"]
exclude = ["assets", "examples"]

[dependencies]
ffi = { package = "blend2d-sys", version = "0.2.0-pre", path = "blend2d-sys" }
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ You can find the examples [here](./examples).

## Current Design Decision
- The [Clone Trait](https://doc.rust-lang.org/std/clone/trait.Clone.html)
is currently only implemented for types that allow to be deeply cloned
by blend2d. Ref-counting clones are currently in general avoided. This
might change due to restrictions this decision might incur. [See Issue #8](https://github.com/Veykril/blend2d-rs/issues/8).

is currently implemented in such a way that it does weak clones by using
the underlying ref-counting of blend2d. Deep clones can be achieved by
using the corresponding DeepClone Trait.
- OutOfMemory errors returned by blend2d will as of now panic the
program by default.
## License

Licensed under either of
Expand Down
2 changes: 1 addition & 1 deletion blend2d-sys/blend2d
Submodule blend2d updated 119 files
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The examples here mimic the ones shown on the official [blend2d getting started

[Getting Started 7: Text Rendering](./text_rendering).rs)

[Getting Started 7: Glyph Buffer](./glyph_buffer.rs)
[Getting Started 8: Glyph Buffer](./glyph_buffer.rs)

Other:

Expand Down
16 changes: 7 additions & 9 deletions examples/composition.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
format::ImageFormat,
gradient::{Gradient, LinearGradientValues, RadialGradientValues},
image::Image,
prelude::*,
ExtendMode,
};

Expand Down Expand Up @@ -54,9 +51,10 @@ fn main() {
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-5.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-5.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
23 changes: 8 additions & 15 deletions examples/glyph_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
font::FontFace,
format::ImageFormat,
geometry::PointD,
glyph_buffer::GlyphBuffer,
image::Image,
};
use blend2d::{font::FontFace, geometry::PointD, glyph_buffer::GlyphBuffer, prelude::*};

fn main() {
let mut img = Image::new(480, 480, ImageFormat::PRgb32).expect("Unable to create image");
Expand All @@ -16,7 +8,7 @@ fn main() {
ctx.fill_all()?;
ctx.set_fill_style_rgba32(0xFFFFFFFF)?;

let font_face = FontFace::from_path("assets/NotoSans-Regular.ttf")?;
let font_face = FontFace::from_path("assets/NotoSans-Regular.ttf", DataAccessFlags::READ)?;
let font = font_face.create_font(20.0)?;
let fm = font.font_metrics();

Expand All @@ -41,9 +33,10 @@ fn main() {
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-8.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-8.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
16 changes: 7 additions & 9 deletions examples/gradient.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
format::ImageFormat,
gradient::{LinearGradient, LinearGradientValues},
image::Image,
prelude::*,
ExtendMode,
};

Expand Down Expand Up @@ -43,9 +40,10 @@ fn main() {
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-2.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-2.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
19 changes: 7 additions & 12 deletions examples/path.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
format::ImageFormat,
image::Image,
path::Path,
};
use blend2d::{path::Path, prelude::*};

fn main() {
let mut img = Image::new(480, 480, ImageFormat::PRgb32).expect("Unable to create image");
Expand Down Expand Up @@ -33,9 +27,10 @@ fn main() {
render(ctx).expect("Rendering to context failed");

// Let's use some built-in codecs provided by Blend2D.
let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-1.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-1.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
21 changes: 8 additions & 13 deletions examples/pattern.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
format::ImageFormat,
image::Image,
pattern::Pattern,
};
use blend2d::{pattern::Pattern, prelude::*};

fn main() {
let mut img = Image::new(480, 480, ImageFormat::PRgb32).expect("Unable to create image");
Expand All @@ -14,7 +8,7 @@ fn main() {
ctx.fill_all()?;

// Read an image from file.
let texture = Image::from_path("assets/ferris.png", ImageCodec::built_in_codecs())?;
let texture = Image::from_path("assets/ferris.png", &ImageCodec::built_in_codecs())?;

// Create a pattern and use it to fill a rounded-rect.
let pattern = Pattern::new(&texture, None, Default::default(), None);
Expand All @@ -30,9 +24,10 @@ fn main() {
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-3.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-3.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
19 changes: 9 additions & 10 deletions examples/rust_bl_logo.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
format::ImageFormat,
geometry::SizeI,
gradient::{Gradient, GradientStop, LinearGradientValues, RadialGradientValues},
image::{Image, ImageScaleFilter},
image::ImageScaleFilter,
matrix::Matrix2D,
pattern::Pattern,
prelude::*,
ExtendMode,
};

Expand Down Expand Up @@ -52,7 +50,7 @@ fn main() {
// your image.
let mut logo = Image::from_path(
"assets/rust-logo-512x512-blk.png",
ImageCodec::built_in_codecs(),
&ImageCodec::built_in_codecs(),
)?;
logo.scale(
SizeI {
Expand Down Expand Up @@ -101,9 +99,10 @@ fn main() {
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("rust_bl_logo.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"rust_bl_logo.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
16 changes: 7 additions & 9 deletions examples/stroking.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
format::ImageFormat,
gradient::{LinearGradient, LinearGradientValues},
image::Image,
path::{Path, StrokeCap},
prelude::*,
ExtendMode,
};

Expand Down Expand Up @@ -44,9 +41,10 @@ fn main() {
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-6.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-6.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
25 changes: 9 additions & 16 deletions examples/text_rendering.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
font::FontFace,
format::ImageFormat,
geometry::PointD,
image::Image,
matrix::MatrixTransform,
};
use blend2d::{font::FontFace, geometry::PointD, prelude::*};

fn main() {
let mut img = Image::new(480, 480, ImageFormat::PRgb32).expect("Unable to create image");
Expand All @@ -15,21 +7,22 @@ fn main() {
ctx.set_comp_op(CompOp::SrcCopy)?;
ctx.fill_all()?;

let font_face = FontFace::from_path("assets/NotoSans-Regular.ttf")?;
let font_face = FontFace::from_path("assets/NotoSans-Regular.ttf", DataAccessFlags::READ)?;
let font = font_face.create_font(50.0)?;

ctx.set_fill_style_rgba32(0xFFFFFFFF)?;
ctx.fill_utf8_text(PointD { x: 60.0, y: 80.0 }, &font, "Hello Blend2D!")?;

ctx.rotate(core::f64::consts::FRAC_PI_4)?;
ctx.fill_utf8_text(PointD { x: 250.0, y: 80.0 }, &font, "Rotated Text!")?;
ctx.fill_utf8_text(PointD { x: 250.0, y: 80.0 }, &font, "Rotated Text")?;
ctx.end()
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-7.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-7.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
22 changes: 8 additions & 14 deletions examples/transformation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
use blend2d::{
codec::ImageCodec,
context::{CompOp, Context},
format::ImageFormat,
image::Image,
matrix::MatrixTransform,
pattern::Pattern,
};
use blend2d::{pattern::Pattern, prelude::*};

fn main() {
let mut img = Image::new(480, 480, ImageFormat::PRgb32).expect("Unable to create image");
Expand All @@ -15,7 +8,7 @@ fn main() {
ctx.fill_all()?;

// Read an image from file.
let texture = Image::from_path("assets/ferris.png", ImageCodec::built_in_codecs())?;
let texture = Image::from_path("assets/ferris.png", &ImageCodec::built_in_codecs())?;

// Create a pattern and use it to fill a rounded-rect.
let pattern = Pattern::new(&texture, None, Default::default(), None);
Expand All @@ -33,9 +26,10 @@ fn main() {
};
render(ctx).expect("Rendering to context failed");

let codec = ImageCodec::built_in_codecs()
.find_codec_by_name("BMP")
.unwrap();
img.write_to_file("bl-getting-started-4.bmp", codec)
.expect("Writing to file failed");
let codecs = ImageCodec::built_in_codecs();
img.write_to_file(
"bl-getting-started-4.bmp",
codecs.find_codec_by_name("BMP").unwrap(),
)
.expect("Writing to file failed");
}
5 changes: 5 additions & 0 deletions run_all_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os
import subprocess

for path in map(lambda path: path.replace(".rs", ""), filter(lambda path: path.endswith(".rs"), os.listdir("examples"))):
subprocess.run(["cargo", "run", "--example", path])
6 changes: 2 additions & 4 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ impl<T: ArrayType> PartialEq for Array<T> {

impl<T: ArrayType + Copy> Clone for Array<T> {
fn clone(&self) -> Self {
let mut new = Self::new();
unsafe { ffi::blArrayAssignDeep(new.core_mut(), self.core()) };
new
Self::from_core(self.init_weak())
}
}

Expand Down Expand Up @@ -543,7 +541,7 @@ mod test_array {
Image::new(4, 4, Default::default()).unwrap(),
Image::new(5, 5, Default::default()).unwrap(),
];
let mut arr = Array::<Image<'static>>::new();
let mut arr = Array::<Image>::new();
arr.push(img[0].clone());
arr.push(img[1].clone());
arr.push(img[2].clone());
Expand Down
Loading

0 comments on commit 24d01a8

Please sign in to comment.