mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 12:41:30 +11:00
commit
379fb1caaa
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -795,7 +795,7 @@ version = "0.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f923fb806c46266c02ab4a5b239735c144bdeda724a50ed058e5226f594cde3"
|
||||
dependencies = [
|
||||
"ttf-parser",
|
||||
"ttf-parser 0.6.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -855,6 +855,7 @@ dependencies = [
|
|||
"rand",
|
||||
"raw-window-handle",
|
||||
"roxmltree",
|
||||
"ttf-parser 0.12.0",
|
||||
"winit",
|
||||
]
|
||||
|
||||
|
@ -1156,6 +1157,12 @@ version = "0.6.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc"
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85e00391c1f3d171490a3f8bd79999b0002ae38d3da0d6a3a306c754b053d71b"
|
||||
|
||||
[[package]]
|
||||
name = "unic-bidi"
|
||||
version = "0.9.0"
|
||||
|
|
|
@ -46,6 +46,7 @@ fn gen_derive_def(name: &str, size: usize, def: &LayoutTypeDef) -> proc_macro2::
|
|||
encode_fields.extend(gen_encode_field(field_name, *offset, &ty.ty));
|
||||
}
|
||||
quote! {
|
||||
#[derive(Clone)]
|
||||
pub struct #name_id {
|
||||
#gen_fields
|
||||
}
|
||||
|
@ -104,6 +105,7 @@ fn gen_derive_def(name: &str, size: usize, def: &LayoutTypeDef) -> proc_macro2::
|
|||
cases.extend(case);
|
||||
}
|
||||
quote! {
|
||||
#[derive(Clone)]
|
||||
pub enum #name_id {
|
||||
#gen_variants
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ rand = "0.7.3"
|
|||
roxmltree = "0.13"
|
||||
winit = "0.23"
|
||||
clap = "2.33"
|
||||
ttf-parser = "0.12"
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
ndk = "0.3"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
mod pico_svg;
|
||||
mod render_ctx;
|
||||
mod text;
|
||||
|
||||
use std::convert::TryInto;
|
||||
|
||||
|
@ -7,8 +8,8 @@ pub use render_ctx::PietGpuRenderContext;
|
|||
|
||||
use rand::{Rng, RngCore};
|
||||
|
||||
use piet::kurbo::{BezPath, Circle, Point, Shape, Vec2};
|
||||
use piet::{Color, ImageFormat, RenderContext};
|
||||
use piet::kurbo::{Affine, BezPath, Circle, Point, Shape, Vec2};
|
||||
use piet::{Color, ImageFormat, RenderContext, Text, TextAttribute, TextLayoutBuilder};
|
||||
|
||||
use piet_gpu_types::encoder::Encode;
|
||||
|
||||
|
@ -77,6 +78,7 @@ pub fn render_scene(rc: &mut impl RenderContext) {
|
|||
//render_cardioid(rc);
|
||||
render_clip_test(rc);
|
||||
render_alpha_test(rc);
|
||||
render_text_test(rc);
|
||||
//render_tiger(rc);
|
||||
}
|
||||
|
||||
|
@ -158,6 +160,21 @@ fn diamond(origin: Point) -> impl Shape {
|
|||
return path;
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn render_text_test(rc: &mut impl RenderContext) {
|
||||
rc.save();
|
||||
//rc.transform(Affine::new([0.2, 0.0, 0.0, -0.2, 200.0, 800.0]));
|
||||
let layout = rc
|
||||
.text()
|
||||
.new_text_layout("hello piet-gpu text!")
|
||||
.default_attribute(TextAttribute::FontSize(100.0))
|
||||
.build()
|
||||
.unwrap();
|
||||
rc.draw_text(&layout, Point::new(110.0, 600.0));
|
||||
rc.draw_text(&layout, Point::new(110.0, 700.0));
|
||||
rc.restore();
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn render_tiger(rc: &mut impl RenderContext) {
|
||||
let xml_str = std::str::from_utf8(include_bytes!("../Ghostscript_Tiger.svg")).unwrap();
|
||||
|
|
|
@ -14,16 +14,11 @@ use piet_gpu_types::scene::{
|
|||
Clip, CubicSeg, Element, FillColor, LineSeg, QuadSeg, SetFillMode, SetLineWidth, Transform,
|
||||
};
|
||||
|
||||
use crate::text::Font;
|
||||
pub use crate::text::{PathEncoder, PietGpuText, PietGpuTextLayout, PietGpuTextLayoutBuilder};
|
||||
|
||||
pub struct PietGpuImage;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PietGpuTextLayout;
|
||||
|
||||
pub struct PietGpuTextLayoutBuilder;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PietGpuText;
|
||||
|
||||
pub struct PietGpuRenderContext {
|
||||
encoder: Encoder,
|
||||
elements: Vec<Element>,
|
||||
|
@ -69,7 +64,7 @@ struct ClipElement {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum FillMode {
|
||||
pub(crate) enum FillMode {
|
||||
// Fill path according to the non-zero winding rule.
|
||||
Nonzero = 0,
|
||||
// Fill stroked path.
|
||||
|
@ -82,7 +77,8 @@ impl PietGpuRenderContext {
|
|||
pub fn new() -> PietGpuRenderContext {
|
||||
let encoder = Encoder::new();
|
||||
let elements = Vec::new();
|
||||
let inner_text = PietGpuText;
|
||||
let font = Font::new();
|
||||
let inner_text = PietGpuText::new(font);
|
||||
let stroke_width = 0.0;
|
||||
PietGpuRenderContext {
|
||||
encoder,
|
||||
|
@ -115,14 +111,14 @@ impl PietGpuRenderContext {
|
|||
pub fn trans_count(&self) -> usize {
|
||||
self.trans_count
|
||||
}
|
||||
}
|
||||
|
||||
fn set_fill_mode(ctx: &mut PietGpuRenderContext, fill_mode: FillMode) {
|
||||
if ctx.fill_mode != fill_mode {
|
||||
ctx.elements.push(Element::SetFillMode(SetFillMode {
|
||||
pub(crate) fn set_fill_mode(&mut self, fill_mode: FillMode) {
|
||||
if self.fill_mode != fill_mode {
|
||||
self.elements.push(Element::SetFillMode(SetFillMode {
|
||||
fill_mode: fill_mode as u32,
|
||||
}));
|
||||
ctx.fill_mode = fill_mode;
|
||||
self.fill_mode = fill_mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +161,7 @@ impl RenderContext for PietGpuRenderContext {
|
|||
.push(Element::SetLineWidth(SetLineWidth { width: width_f32 }));
|
||||
self.stroke_width = width_f32;
|
||||
}
|
||||
set_fill_mode(self, FillMode::Stroke);
|
||||
self.set_fill_mode(FillMode::Stroke);
|
||||
let brush = brush.make_brush(self, || shape.bounding_box()).into_owned();
|
||||
match brush {
|
||||
PietGpuBrush::Solid(rgba_color) => {
|
||||
|
@ -197,7 +193,7 @@ impl RenderContext for PietGpuRenderContext {
|
|||
// Perhaps that should be added to kurbo.
|
||||
self.accumulate_bbox(|| shape.bounding_box());
|
||||
let path = shape.path_elements(TOLERANCE);
|
||||
set_fill_mode(self, FillMode::Nonzero);
|
||||
self.set_fill_mode(FillMode::Nonzero);
|
||||
self.encode_path(path, true);
|
||||
let fill = FillColor { rgba_color };
|
||||
self.elements.push(Element::FillColor(fill));
|
||||
|
@ -208,7 +204,7 @@ impl RenderContext for PietGpuRenderContext {
|
|||
fn fill_even_odd(&mut self, _shape: impl Shape, _brush: &impl IntoBrush<Self>) {}
|
||||
|
||||
fn clip(&mut self, shape: impl Shape) {
|
||||
set_fill_mode(self, FillMode::Nonzero);
|
||||
self.set_fill_mode(FillMode::Nonzero);
|
||||
let path = shape.path_elements(TOLERANCE);
|
||||
self.encode_path(path, true);
|
||||
let begin_ix = self.elements.len();
|
||||
|
@ -229,7 +225,9 @@ impl RenderContext for PietGpuRenderContext {
|
|||
&mut self.inner_text
|
||||
}
|
||||
|
||||
fn draw_text(&mut self, _layout: &Self::TextLayout, _pos: impl Into<Point>) {}
|
||||
fn draw_text(&mut self, layout: &Self::TextLayout, pos: impl Into<Point>) {
|
||||
layout.draw_text(self, pos.into());
|
||||
}
|
||||
|
||||
fn save(&mut self) -> Result<(), Error> {
|
||||
self.state_stack.push(State {
|
||||
|
@ -244,9 +242,7 @@ impl RenderContext for PietGpuRenderContext {
|
|||
if let Some(state) = self.state_stack.pop() {
|
||||
if state.rel_transform != Affine::default() {
|
||||
let a_inv = state.rel_transform.inverse();
|
||||
self.elements
|
||||
.push(Element::Transform(to_scene_transform(a_inv)));
|
||||
self.trans_count += 1;
|
||||
self.encode_transform(to_scene_transform(a_inv));
|
||||
}
|
||||
self.cur_transform = state.transform;
|
||||
for _ in 0..state.n_clip {
|
||||
|
@ -266,9 +262,7 @@ impl RenderContext for PietGpuRenderContext {
|
|||
}
|
||||
|
||||
fn transform(&mut self, transform: Affine) {
|
||||
self.elements
|
||||
.push(Element::Transform(to_scene_transform(transform)));
|
||||
self.trans_count += 1;
|
||||
self.encode_transform(to_scene_transform(transform));
|
||||
if let Some(tos) = self.state_stack.last_mut() {
|
||||
tos.rel_transform *= transform;
|
||||
}
|
||||
|
@ -486,84 +480,22 @@ impl PietGpuRenderContext {
|
|||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Text for PietGpuText {
|
||||
type TextLayout = PietGpuTextLayout;
|
||||
type TextLayoutBuilder = PietGpuTextLayoutBuilder;
|
||||
|
||||
fn load_font(&mut self, _data: &[u8]) -> Result<FontFamily, Error> {
|
||||
Ok(FontFamily::default())
|
||||
pub(crate) fn append_path_encoder(&mut self, path: &PathEncoder) {
|
||||
let elements = path.elements();
|
||||
self.elements.extend(elements.iter().cloned());
|
||||
self.pathseg_count += elements.len();
|
||||
}
|
||||
|
||||
fn new_text_layout(&mut self, _text: impl TextStorage) -> Self::TextLayoutBuilder {
|
||||
PietGpuTextLayoutBuilder
|
||||
pub(crate) fn fill_glyph(&mut self, rgba_color: u32) {
|
||||
let fill = FillColor { rgba_color };
|
||||
self.elements.push(Element::FillColor(fill));
|
||||
self.path_count += 1;
|
||||
}
|
||||
|
||||
fn font_family(&mut self, _family_name: &str) -> Option<FontFamily> {
|
||||
Some(FontFamily::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl TextLayoutBuilder for PietGpuTextLayoutBuilder {
|
||||
type Out = PietGpuTextLayout;
|
||||
|
||||
fn max_width(self, _width: f64) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn alignment(self, _alignment: piet::TextAlignment) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn default_attribute(self, _attribute: impl Into<TextAttribute>) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn range_attribute(
|
||||
self,
|
||||
_range: impl RangeBounds<usize>,
|
||||
_attribute: impl Into<TextAttribute>,
|
||||
) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn build(self) -> Result<Self::Out, Error> {
|
||||
Ok(PietGpuTextLayout)
|
||||
}
|
||||
}
|
||||
|
||||
impl TextLayout for PietGpuTextLayout {
|
||||
fn size(&self) -> Size {
|
||||
Size::ZERO
|
||||
}
|
||||
|
||||
fn image_bounds(&self) -> Rect {
|
||||
Rect::ZERO
|
||||
}
|
||||
|
||||
fn line_text(&self, _line_number: usize) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
|
||||
fn line_metric(&self, _line_number: usize) -> Option<LineMetric> {
|
||||
None
|
||||
}
|
||||
|
||||
fn line_count(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn hit_test_point(&self, _point: Point) -> HitTestPoint {
|
||||
HitTestPoint::default()
|
||||
}
|
||||
|
||||
fn hit_test_text_position(&self, _text_position: usize) -> HitTestPosition {
|
||||
HitTestPosition::default()
|
||||
}
|
||||
|
||||
fn text(&self) -> &str {
|
||||
""
|
||||
pub(crate) fn encode_transform(&mut self, transform: Transform) {
|
||||
self.elements.push(Element::Transform(transform));
|
||||
self.trans_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,7 +509,7 @@ impl IntoBrush<PietGpuRenderContext> for PietGpuBrush {
|
|||
}
|
||||
}
|
||||
|
||||
fn to_f32_2(point: Point) -> [f32; 2] {
|
||||
pub(crate) fn to_f32_2(point: Point) -> [f32; 2] {
|
||||
[point.x as f32, point.y as f32]
|
||||
}
|
||||
|
||||
|
|
297
piet-gpu/src/text.rs
Normal file
297
piet-gpu/src/text.rs
Normal file
|
@ -0,0 +1,297 @@
|
|||
use std::ops::RangeBounds;
|
||||
|
||||
use ttf_parser::{Face, GlyphId, OutlineBuilder};
|
||||
|
||||
use piet::kurbo::{Point, Rect, Size};
|
||||
use piet::{
|
||||
Error, FontFamily, HitTestPoint, HitTestPosition, LineMetric, Text, TextAttribute, TextLayout,
|
||||
TextLayoutBuilder, TextStorage,
|
||||
};
|
||||
|
||||
use piet_gpu_types::scene::{CubicSeg, Element, LineSeg, QuadSeg, Transform};
|
||||
|
||||
use crate::render_ctx::{self, FillMode};
|
||||
use crate::PietGpuRenderContext;
|
||||
|
||||
// This is very much a hack to get things working.
|
||||
const FONT_DATA: &[u8] = include_bytes!("../third-party/Roboto-Regular.ttf");
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Font {
|
||||
face: Face<'static>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PietGpuText {
|
||||
font: Font,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PietGpuTextLayout {
|
||||
font: Font,
|
||||
size: f64,
|
||||
glyphs: Vec<Glyph>,
|
||||
}
|
||||
|
||||
pub struct PietGpuTextLayoutBuilder {
|
||||
font: Font,
|
||||
text: String,
|
||||
size: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Glyph {
|
||||
glyph_id: GlyphId,
|
||||
x: f32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PathEncoder {
|
||||
start_pt: [f32; 2],
|
||||
cur_pt: [f32; 2],
|
||||
elements: Vec<Element>,
|
||||
}
|
||||
|
||||
impl PietGpuText {
|
||||
pub(crate) fn new(font: Font) -> PietGpuText {
|
||||
PietGpuText { font }
|
||||
}
|
||||
}
|
||||
|
||||
impl Text for PietGpuText {
|
||||
type TextLayout = PietGpuTextLayout;
|
||||
type TextLayoutBuilder = PietGpuTextLayoutBuilder;
|
||||
|
||||
fn load_font(&mut self, _data: &[u8]) -> Result<FontFamily, Error> {
|
||||
Ok(FontFamily::default())
|
||||
}
|
||||
|
||||
fn new_text_layout(&mut self, text: impl TextStorage) -> Self::TextLayoutBuilder {
|
||||
PietGpuTextLayoutBuilder::new(&self.font, &text.as_str())
|
||||
}
|
||||
|
||||
fn font_family(&mut self, _family_name: &str) -> Option<FontFamily> {
|
||||
Some(FontFamily::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl TextLayout for PietGpuTextLayout {
|
||||
fn size(&self) -> Size {
|
||||
Size::ZERO
|
||||
}
|
||||
|
||||
fn image_bounds(&self) -> Rect {
|
||||
Rect::ZERO
|
||||
}
|
||||
|
||||
fn line_text(&self, _line_number: usize) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
|
||||
fn line_metric(&self, _line_number: usize) -> Option<LineMetric> {
|
||||
None
|
||||
}
|
||||
|
||||
fn line_count(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn hit_test_point(&self, _point: Point) -> HitTestPoint {
|
||||
HitTestPoint::default()
|
||||
}
|
||||
|
||||
fn hit_test_text_position(&self, _text_position: usize) -> HitTestPosition {
|
||||
HitTestPosition::default()
|
||||
}
|
||||
|
||||
fn text(&self) -> &str {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
impl Font {
|
||||
pub fn new() -> Font {
|
||||
let face = Face::from_slice(FONT_DATA, 0).expect("error parsing font");
|
||||
Font { face }
|
||||
}
|
||||
|
||||
fn make_path(&self, glyph_id: GlyphId) -> PathEncoder {
|
||||
let mut encoder = PathEncoder::default();
|
||||
self.face.outline_glyph(glyph_id, &mut encoder);
|
||||
encoder
|
||||
}
|
||||
}
|
||||
|
||||
impl PietGpuTextLayout {
|
||||
pub(crate) fn make_layout(font: &Font, text: &str, size: f64) -> PietGpuTextLayout {
|
||||
let mut glyphs = Vec::new();
|
||||
let mut x = 0.0;
|
||||
let y = 0.0;
|
||||
for c in text.chars() {
|
||||
if let Some(glyph_id) = font.face.glyph_index(c) {
|
||||
let glyph = Glyph { glyph_id, x, y };
|
||||
glyphs.push(glyph);
|
||||
if let Some(adv) = font.face.glyph_hor_advance(glyph_id) {
|
||||
x += adv as f32;
|
||||
}
|
||||
}
|
||||
}
|
||||
PietGpuTextLayout {
|
||||
glyphs,
|
||||
font: font.clone(),
|
||||
size: size,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_text(&self, ctx: &mut PietGpuRenderContext, pos: Point) {
|
||||
const DEFAULT_UPEM: u16 = 1024;
|
||||
let scale = self.size as f32 / self.font.face.units_per_em().unwrap_or(DEFAULT_UPEM) as f32;
|
||||
let mut inv_transform = None;
|
||||
// TODO: handle y offsets also
|
||||
let mut last_x = 0.0;
|
||||
ctx.set_fill_mode(FillMode::Nonzero);
|
||||
for glyph in &self.glyphs {
|
||||
let transform = match &mut inv_transform {
|
||||
None => {
|
||||
let inv_scale = scale.recip();
|
||||
let translate = render_ctx::to_f32_2(pos);
|
||||
inv_transform = Some(Transform {
|
||||
mat: [inv_scale, 0.0, 0.0, -inv_scale],
|
||||
translate: [
|
||||
-translate[0] * inv_scale - glyph.x,
|
||||
translate[1] * inv_scale,
|
||||
],
|
||||
});
|
||||
let tpos = render_ctx::to_f32_2(pos);
|
||||
let translate = [tpos[0] + scale * glyph.x, tpos[1]];
|
||||
Transform {
|
||||
mat: [scale, 0.0, 0.0, -scale],
|
||||
translate,
|
||||
}
|
||||
}
|
||||
Some(inv) => {
|
||||
let delta_x = glyph.x - last_x;
|
||||
inv.translate[0] -= delta_x;
|
||||
Transform {
|
||||
mat: [1.0, 0.0, 0.0, 1.0],
|
||||
translate: [delta_x, 0.0],
|
||||
}
|
||||
}
|
||||
};
|
||||
last_x = glyph.x;
|
||||
//println!("{:?}, {:?}", transform.mat, transform.translate);
|
||||
ctx.encode_transform(transform);
|
||||
let path = self.font.make_path(glyph.glyph_id);
|
||||
ctx.append_path_encoder(&path);
|
||||
ctx.fill_glyph(0xff_ff_ff_ff);
|
||||
}
|
||||
if let Some(transform) = inv_transform {
|
||||
ctx.encode_transform(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PietGpuTextLayoutBuilder {
|
||||
pub(crate) fn new(font: &Font, text: &str) -> PietGpuTextLayoutBuilder {
|
||||
PietGpuTextLayoutBuilder {
|
||||
font: font.clone(),
|
||||
text: text.to_owned(),
|
||||
size: 12.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TextLayoutBuilder for PietGpuTextLayoutBuilder {
|
||||
type Out = PietGpuTextLayout;
|
||||
|
||||
fn max_width(self, _width: f64) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn alignment(self, _alignment: piet::TextAlignment) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn default_attribute(mut self, attribute: impl Into<TextAttribute>) -> Self {
|
||||
let attribute = attribute.into();
|
||||
match attribute {
|
||||
TextAttribute::FontSize(size) => self.size = size,
|
||||
_ => (),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
fn range_attribute(
|
||||
self,
|
||||
_range: impl RangeBounds<usize>,
|
||||
_attribute: impl Into<TextAttribute>,
|
||||
) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
fn build(self) -> Result<Self::Out, Error> {
|
||||
Ok(PietGpuTextLayout::make_layout(
|
||||
&self.font, &self.text, self.size,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl OutlineBuilder for PathEncoder {
|
||||
fn move_to(&mut self, x: f32, y: f32) {
|
||||
self.start_pt = [x, y];
|
||||
self.cur_pt = [x, y];
|
||||
}
|
||||
|
||||
fn line_to(&mut self, x: f32, y: f32) {
|
||||
let p1 = [x, y];
|
||||
let seg = LineSeg {
|
||||
p0: self.cur_pt,
|
||||
p1: p1,
|
||||
};
|
||||
self.cur_pt = p1;
|
||||
self.elements.push(Element::Line(seg));
|
||||
}
|
||||
|
||||
fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) {
|
||||
let p1 = [x1, y1];
|
||||
let p2 = [x, y];
|
||||
let seg = QuadSeg {
|
||||
p0: self.cur_pt,
|
||||
p1: p1,
|
||||
p2: p2,
|
||||
};
|
||||
self.cur_pt = p2;
|
||||
self.elements.push(Element::Quad(seg));
|
||||
}
|
||||
|
||||
fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) {
|
||||
let p1 = [x1, y1];
|
||||
let p2 = [x2, y2];
|
||||
let p3 = [x, y];
|
||||
let seg = CubicSeg {
|
||||
p0: self.cur_pt,
|
||||
p1: p1,
|
||||
p2: p2,
|
||||
p3: p3,
|
||||
};
|
||||
self.cur_pt = p3;
|
||||
self.elements.push(Element::Cubic(seg));
|
||||
}
|
||||
|
||||
fn close(&mut self) {
|
||||
if self.cur_pt != self.start_pt {
|
||||
let seg = LineSeg {
|
||||
p0: self.cur_pt,
|
||||
p1: self.start_pt,
|
||||
};
|
||||
self.elements.push(Element::Line(seg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PathEncoder {
|
||||
pub(crate) fn elements(&self) -> &[Element] {
|
||||
&self.elements
|
||||
}
|
||||
}
|
202
piet-gpu/third-party/LICENSE.txt
vendored
Normal file
202
piet-gpu/third-party/LICENSE.txt
vendored
Normal file
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
BIN
piet-gpu/third-party/Roboto-Regular.ttf
vendored
Normal file
BIN
piet-gpu/third-party/Roboto-Regular.ttf
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue