Skip to content

Commit 379245d

Browse files
committed
[cg] Add text module, move text stubs there
1 parent ce9ec4e commit 379245d

File tree

2 files changed

+95
-82
lines changed

2 files changed

+95
-82
lines changed

piet-coregraphics/src/lib.rs

Lines changed: 9 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! The CoreGraphics backend for the Piet 2D graphics abstraction.
22
3+
mod text;
4+
35
use std::borrow::Cow;
46
use std::sync::Arc;
57

@@ -15,9 +17,13 @@ use core_graphics::image::CGImage;
1517
use piet::kurbo::{Affine, PathEl, Point, QuadBez, Rect, Shape, Size};
1618

1719
use piet::{
18-
Color, Error, FixedGradient, Font, FontBuilder, HitTestPoint, HitTestTextPosition, ImageFormat,
19-
InterpolationMode, IntoBrush, LineCap, LineJoin, LineMetric, RenderContext, RoundInto,
20-
StrokeStyle, Text, TextLayout, TextLayoutBuilder,
20+
Color, Error, FixedGradient, ImageFormat, InterpolationMode, IntoBrush, LineCap, LineJoin,
21+
RenderContext, RoundInto, StrokeStyle,
22+
};
23+
24+
pub use crate::text::{
25+
CoreGraphicsFont, CoreGraphicsFontBuilder, CoreGraphicsText, CoreGraphicsTextLayout,
26+
CoreGraphicsTextLayoutBuilder,
2127
};
2228

2329
pub struct CoreGraphicsContext<'a> {
@@ -42,17 +48,6 @@ pub enum Brush {
4248
Gradient,
4349
}
4450

45-
pub struct CoreGraphicsFont;
46-
47-
pub struct CoreGraphicsFontBuilder;
48-
49-
#[derive(Clone)]
50-
pub struct CoreGraphicsTextLayout;
51-
52-
pub struct CoreGraphicsTextLayoutBuilder {}
53-
54-
pub struct CoreGraphicsText;
55-
5651
impl<'a> RenderContext for CoreGraphicsContext<'a> {
5752
type Brush = Brush;
5853
type Text = CoreGraphicsText;
@@ -226,74 +221,6 @@ impl<'a> RenderContext for CoreGraphicsContext<'a> {
226221
}
227222
}
228223

229-
impl Text for CoreGraphicsText {
230-
type Font = CoreGraphicsFont;
231-
type FontBuilder = CoreGraphicsFontBuilder;
232-
type TextLayout = CoreGraphicsTextLayout;
233-
type TextLayoutBuilder = CoreGraphicsTextLayoutBuilder;
234-
235-
fn new_font_by_name(&mut self, _name: &str, _size: f64) -> Self::FontBuilder {
236-
unimplemented!();
237-
}
238-
239-
fn new_text_layout(
240-
&mut self,
241-
_font: &Self::Font,
242-
_text: &str,
243-
_width: impl Into<Option<f64>>,
244-
) -> Self::TextLayoutBuilder {
245-
unimplemented!();
246-
}
247-
}
248-
249-
impl Font for CoreGraphicsFont {}
250-
251-
impl FontBuilder for CoreGraphicsFontBuilder {
252-
type Out = CoreGraphicsFont;
253-
254-
fn build(self) -> Result<Self::Out, Error> {
255-
unimplemented!();
256-
}
257-
}
258-
259-
impl TextLayoutBuilder for CoreGraphicsTextLayoutBuilder {
260-
type Out = CoreGraphicsTextLayout;
261-
262-
fn build(self) -> Result<Self::Out, Error> {
263-
unimplemented!()
264-
}
265-
}
266-
267-
impl TextLayout for CoreGraphicsTextLayout {
268-
fn width(&self) -> f64 {
269-
0.0
270-
}
271-
272-
fn update_width(&mut self, _new_width: impl Into<Option<f64>>) -> Result<(), Error> {
273-
unimplemented!()
274-
}
275-
276-
fn line_text(&self, _line_number: usize) -> Option<&str> {
277-
unimplemented!()
278-
}
279-
280-
fn line_metric(&self, _line_number: usize) -> Option<LineMetric> {
281-
unimplemented!()
282-
}
283-
284-
fn line_count(&self) -> usize {
285-
unimplemented!()
286-
}
287-
288-
fn hit_test_point(&self, _point: Point) -> HitTestPoint {
289-
unimplemented!()
290-
}
291-
292-
fn hit_test_text_position(&self, _text_position: usize) -> Option<HitTestTextPosition> {
293-
unimplemented!()
294-
}
295-
}
296-
297224
impl<'a> IntoBrush<CoreGraphicsContext<'a>> for Brush {
298225
fn make_brush<'b>(
299226
&'b self,

piet-coregraphics/src/text.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//! Text related stuff for the coregraphics backend
2+
3+
use piet::kurbo::Point;
4+
use piet::{
5+
Error, Font, FontBuilder, HitTestPoint, HitTestTextPosition, LineMetric, Text, TextLayout,
6+
TextLayoutBuilder,
7+
};
8+
9+
pub struct CoreGraphicsFont;
10+
11+
pub struct CoreGraphicsFontBuilder;
12+
13+
#[derive(Clone)]
14+
pub struct CoreGraphicsTextLayout;
15+
16+
pub struct CoreGraphicsTextLayoutBuilder {}
17+
18+
pub struct CoreGraphicsText;
19+
20+
impl Text for CoreGraphicsText {
21+
type Font = CoreGraphicsFont;
22+
type FontBuilder = CoreGraphicsFontBuilder;
23+
type TextLayout = CoreGraphicsTextLayout;
24+
type TextLayoutBuilder = CoreGraphicsTextLayoutBuilder;
25+
26+
fn new_font_by_name(&mut self, _name: &str, _size: f64) -> Self::FontBuilder {
27+
unimplemented!();
28+
}
29+
30+
fn new_text_layout(
31+
&mut self,
32+
_font: &Self::Font,
33+
_text: &str,
34+
_width: impl Into<Option<f64>>,
35+
) -> Self::TextLayoutBuilder {
36+
unimplemented!();
37+
}
38+
}
39+
40+
impl Font for CoreGraphicsFont {}
41+
42+
impl FontBuilder for CoreGraphicsFontBuilder {
43+
type Out = CoreGraphicsFont;
44+
45+
fn build(self) -> Result<Self::Out, Error> {
46+
unimplemented!();
47+
}
48+
}
49+
50+
impl TextLayoutBuilder for CoreGraphicsTextLayoutBuilder {
51+
type Out = CoreGraphicsTextLayout;
52+
53+
fn build(self) -> Result<Self::Out, Error> {
54+
unimplemented!()
55+
}
56+
}
57+
58+
impl TextLayout for CoreGraphicsTextLayout {
59+
fn width(&self) -> f64 {
60+
0.0
61+
}
62+
63+
fn update_width(&mut self, _new_width: impl Into<Option<f64>>) -> Result<(), Error> {
64+
unimplemented!()
65+
}
66+
67+
fn line_text(&self, _line_number: usize) -> Option<&str> {
68+
unimplemented!()
69+
}
70+
71+
fn line_metric(&self, _line_number: usize) -> Option<LineMetric> {
72+
unimplemented!()
73+
}
74+
75+
fn line_count(&self) -> usize {
76+
unimplemented!()
77+
}
78+
79+
fn hit_test_point(&self, _point: Point) -> HitTestPoint {
80+
unimplemented!()
81+
}
82+
83+
fn hit_test_text_position(&self, _text_position: usize) -> Option<HitTestTextPosition> {
84+
unimplemented!()
85+
}
86+
}

0 commit comments

Comments
 (0)