pub struct Typography { /* private fields */ }Implementations§
Source§impl Typography
impl Typography
Sourcepub fn default_font() -> Font
pub fn default_font() -> Font
Default font
Sourcepub fn new() -> Self
pub fn new() -> Self
Generate a blank Typography instance
Examples found in repository?
examples/typography.rs (line 11)
9fn main() {
10 let mut ctx = Context::new();
11 let mut typ = Typography::new();
12 typ.size(2.0);
13 typ.close(true);
14
15 ctx.stroke("black")
16 .fill("red")
17 .pen(0.5)
18 .pattern(Arc::new(Box::new(NoHatch {})))
19 // .pattern(LineHatch::gen())
20 // .typography(&"i".to_string(), 50.0, 50.0, &typ);
21 .typography(&"Left".to_string(), 50.0, 50.0, &typ);
22 typ.align(TextAlignment::Right);
23 ctx.typography(&"Right".to_string(), 50.0, 90.0, &typ);
24 typ.align(TextAlignment::Center);
25 ctx.typography(&"Center".to_string(), 50.0, 70.0, &typ);
26
27 let svg = ctx
28 .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
29 coord! {x:0.0, y:0.0},
30 coord! {x:100.0, y:100.0},
31 )))
32 .unwrap();
33 // Write it to the images folder, so we can use it as an example!
34 // Write it out to /images/$THIS_EXAMPLE_FILE.svg
35 let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
36 svg::save(format!("images/{}.svg", fname), &svg).unwrap();
37}More examples
examples/carlson_smith_gallery_nannou.rs (line 58)
46 fn generate(&self) -> AOERCTX {
47 let mut ctx = AOERCTX::new();
48 let mut count = 0;
49
50 ctx.pen(1.5).accuracy(0.3);
51 if self.settings.draft {
52 //ctx.pattern(Hatches::none());
53 ctx.pattern(Arc::new(Box::new(NoHatch {})));
54 } else {
55 //ctx.pattern(Hatches::line());
56 ctx.pattern(Arc::new(Box::new(LineHatch {})));
57 }
58 let mut typo = Typography::new();
59 typo.size(4.5).align(Center);
60
61 for (name, geo) in CarlsonSmithTruchet::full_set()
62 .iter()
63 .filter(|(x, _y)| !x.starts_with("^"))
64 {
65 println!("Plotting {}", name);
66 let yofs: f64 = -256.0f64 + 128.0f64 * <f64 as From<i32>>::from((count / 6) as i32);
67 let xofs: f64 = -512.0f64 + 96.0f64 * <f64 as From<i32>>::from((count % 6) as i32);
68 // println!("xy is {},{}", xofs, yofs);
69 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(64.0, 64.0);
70 count += 1;
71 ctx.transform(Some(&tx)).geometry(&geo);
72 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(1.0, -1.0);
73
74 ctx.transform(Some(&tx)).typography(&name, 0.0, 60.0, &typo);
75 }
76 count = 0;
77 for (name, geo) in self
78 .full_set
79 .clone()
80 .iter()
81 .filter(|(x, _y)| x.starts_with("^"))
82 {
83 println!("Plotting inverse scale/2 {}", name);
84 let yofs: f64 =
85 -256.0f64 - 16.0f64 + 128.0f64 * <f64 as From<i32>>::from((count / 6) as i32);
86 let xofs: f64 = -512.0f64
87 + (96.0f64 * 6.0f64)
88 + 96.0f64 * <f64 as From<i32>>::from((count % 6) as i32);
89 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(32.0, 32.0);
90 count += 1;
91 ctx.transform(Some(&tx)).geometry(&geo);
92 ctx.transform(Some(&tx)).geometry(&geo);
93 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(1.0, -1.0);
94
95 ctx.transform(Some(&tx)).typography(&name, 0.0, 40.0, &typo);
96 }
97 ctx
98 }examples/hatch_gallery.rs (line 58)
11fn main() {
12 let mut ctx = Context::new();
13
14 let fills: Vec<Arc<Box<dyn HatchPattern>>> = vec![
15 (Arc::new(Box::new(LineHatch {}))),
16 (Arc::new(Box::new(CrossHatch {}))),
17 (Arc::new(Box::new(RadiusHatch { x: 160., y: 32.0 }))),
18 (Arc::new(Box::new(CircleHatch {}))),
19 (Arc::new(Box::new(FastHexHatch {}))),
20 (Arc::new(Box::new(RadiusHatch { x: 160., y: 32.0 }))),
21 (Arc::new(Box::new(SpiralHatch {
22 x: 32.0,
23 y: 3. * 60.0,
24 direction: SpiralDirection::Widdershins,
25 }))),
26 (Arc::new(Box::new(SpiralHatch {
27 x: 64. + 32.0,
28 y: 3. * 60.0,
29 direction: SpiralDirection::Deasil,
30 }))),
31 ];
32
33 for (i, pattern) in fills.iter().enumerate() {
34 ctx.stroke("black")
35 .fill("black")
36 .pen(0.25)
37 .pattern(pattern.clone())
38 .hatch_scale(Some(3.))
39 .hatch(0.)
40 .poly(
41 vec![
42 ((i % 3) as f64 * 64. + 4., (i / 3) as f64 * 72. + 4.),
43 ((i % 3) as f64 * 64. + 4. + 56., (i / 3) as f64 * 72. + 4.),
44 (
45 (i % 3) as f64 * 64. + 56. + 4.,
46 (i / 3) as f64 * 72. + 56. + 4.,
47 ),
48 ((i % 3) as f64 * 64. + 4., (i / 3) as f64 * 72. + 4. + 56.),
49 ],
50 vec![],
51 )
52 .pen(0.2)
53 .pattern(Arc::new(Box::new(NoHatch {})))
54 .typography(
55 &format!("{:?}", pattern),
56 (i % 3) as f64 * 64. + 4.,
57 (i / 3) as f64 * 72. + 8. + 56.,
58 &Typography::new().size(1.2),
59 );
60 }
61
62 let svg = ctx
63 .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
64 coord! {x:0.0, y:0.0},
65 coord! {x:500.0, y:500.0},
66 )))
67 .unwrap();
68 // Write it to the images folder, so we can use it as an example!
69 // Write it out to /images/$THIS_EXAMPLE_FILE.svg
70 let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
71 svg::save(format!("images/{}.svg", fname), &svg).unwrap();
72}pub fn mm_per_em() -> f64
Sourcepub fn align(&mut self, align: TextAlignment) -> &mut Self
pub fn align(&mut self, align: TextAlignment) -> &mut Self
Examples found in repository?
examples/typography.rs (line 22)
9fn main() {
10 let mut ctx = Context::new();
11 let mut typ = Typography::new();
12 typ.size(2.0);
13 typ.close(true);
14
15 ctx.stroke("black")
16 .fill("red")
17 .pen(0.5)
18 .pattern(Arc::new(Box::new(NoHatch {})))
19 // .pattern(LineHatch::gen())
20 // .typography(&"i".to_string(), 50.0, 50.0, &typ);
21 .typography(&"Left".to_string(), 50.0, 50.0, &typ);
22 typ.align(TextAlignment::Right);
23 ctx.typography(&"Right".to_string(), 50.0, 90.0, &typ);
24 typ.align(TextAlignment::Center);
25 ctx.typography(&"Center".to_string(), 50.0, 70.0, &typ);
26
27 let svg = ctx
28 .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
29 coord! {x:0.0, y:0.0},
30 coord! {x:100.0, y:100.0},
31 )))
32 .unwrap();
33 // Write it to the images folder, so we can use it as an example!
34 // Write it out to /images/$THIS_EXAMPLE_FILE.svg
35 let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
36 svg::save(format!("images/{}.svg", fname), &svg).unwrap();
37}More examples
examples/carlson_smith_gallery_nannou.rs (line 59)
46 fn generate(&self) -> AOERCTX {
47 let mut ctx = AOERCTX::new();
48 let mut count = 0;
49
50 ctx.pen(1.5).accuracy(0.3);
51 if self.settings.draft {
52 //ctx.pattern(Hatches::none());
53 ctx.pattern(Arc::new(Box::new(NoHatch {})));
54 } else {
55 //ctx.pattern(Hatches::line());
56 ctx.pattern(Arc::new(Box::new(LineHatch {})));
57 }
58 let mut typo = Typography::new();
59 typo.size(4.5).align(Center);
60
61 for (name, geo) in CarlsonSmithTruchet::full_set()
62 .iter()
63 .filter(|(x, _y)| !x.starts_with("^"))
64 {
65 println!("Plotting {}", name);
66 let yofs: f64 = -256.0f64 + 128.0f64 * <f64 as From<i32>>::from((count / 6) as i32);
67 let xofs: f64 = -512.0f64 + 96.0f64 * <f64 as From<i32>>::from((count % 6) as i32);
68 // println!("xy is {},{}", xofs, yofs);
69 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(64.0, 64.0);
70 count += 1;
71 ctx.transform(Some(&tx)).geometry(&geo);
72 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(1.0, -1.0);
73
74 ctx.transform(Some(&tx)).typography(&name, 0.0, 60.0, &typo);
75 }
76 count = 0;
77 for (name, geo) in self
78 .full_set
79 .clone()
80 .iter()
81 .filter(|(x, _y)| x.starts_with("^"))
82 {
83 println!("Plotting inverse scale/2 {}", name);
84 let yofs: f64 =
85 -256.0f64 - 16.0f64 + 128.0f64 * <f64 as From<i32>>::from((count / 6) as i32);
86 let xofs: f64 = -512.0f64
87 + (96.0f64 * 6.0f64)
88 + 96.0f64 * <f64 as From<i32>>::from((count % 6) as i32);
89 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(32.0, 32.0);
90 count += 1;
91 ctx.transform(Some(&tx)).geometry(&geo);
92 ctx.transform(Some(&tx)).geometry(&geo);
93 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(1.0, -1.0);
94
95 ctx.transform(Some(&tx)).typography(&name, 0.0, 40.0, &typo);
96 }
97 ctx
98 }Sourcepub fn close(&mut self, close: bool) -> &mut Self
pub fn close(&mut self, close: bool) -> &mut Self
Examples found in repository?
examples/typography.rs (line 13)
9fn main() {
10 let mut ctx = Context::new();
11 let mut typ = Typography::new();
12 typ.size(2.0);
13 typ.close(true);
14
15 ctx.stroke("black")
16 .fill("red")
17 .pen(0.5)
18 .pattern(Arc::new(Box::new(NoHatch {})))
19 // .pattern(LineHatch::gen())
20 // .typography(&"i".to_string(), 50.0, 50.0, &typ);
21 .typography(&"Left".to_string(), 50.0, 50.0, &typ);
22 typ.align(TextAlignment::Right);
23 ctx.typography(&"Right".to_string(), 50.0, 90.0, &typ);
24 typ.align(TextAlignment::Center);
25 ctx.typography(&"Center".to_string(), 50.0, 70.0, &typ);
26
27 let svg = ctx
28 .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
29 coord! {x:0.0, y:0.0},
30 coord! {x:100.0, y:100.0},
31 )))
32 .unwrap();
33 // Write it to the images folder, so we can use it as an example!
34 // Write it out to /images/$THIS_EXAMPLE_FILE.svg
35 let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
36 svg::save(format!("images/{}.svg", fname), &svg).unwrap();
37}pub fn hint(&mut self, hint: HintingOptions) -> &mut Self
pub fn font(&mut self, font: &Font) -> &mut Self
Sourcepub fn size(&mut self, em: f64) -> &mut Self
pub fn size(&mut self, em: f64) -> &mut Self
Examples found in repository?
examples/typography.rs (line 12)
9fn main() {
10 let mut ctx = Context::new();
11 let mut typ = Typography::new();
12 typ.size(2.0);
13 typ.close(true);
14
15 ctx.stroke("black")
16 .fill("red")
17 .pen(0.5)
18 .pattern(Arc::new(Box::new(NoHatch {})))
19 // .pattern(LineHatch::gen())
20 // .typography(&"i".to_string(), 50.0, 50.0, &typ);
21 .typography(&"Left".to_string(), 50.0, 50.0, &typ);
22 typ.align(TextAlignment::Right);
23 ctx.typography(&"Right".to_string(), 50.0, 90.0, &typ);
24 typ.align(TextAlignment::Center);
25 ctx.typography(&"Center".to_string(), 50.0, 70.0, &typ);
26
27 let svg = ctx
28 .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
29 coord! {x:0.0, y:0.0},
30 coord! {x:100.0, y:100.0},
31 )))
32 .unwrap();
33 // Write it to the images folder, so we can use it as an example!
34 // Write it out to /images/$THIS_EXAMPLE_FILE.svg
35 let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
36 svg::save(format!("images/{}.svg", fname), &svg).unwrap();
37}More examples
examples/carlson_smith_gallery_nannou.rs (line 59)
46 fn generate(&self) -> AOERCTX {
47 let mut ctx = AOERCTX::new();
48 let mut count = 0;
49
50 ctx.pen(1.5).accuracy(0.3);
51 if self.settings.draft {
52 //ctx.pattern(Hatches::none());
53 ctx.pattern(Arc::new(Box::new(NoHatch {})));
54 } else {
55 //ctx.pattern(Hatches::line());
56 ctx.pattern(Arc::new(Box::new(LineHatch {})));
57 }
58 let mut typo = Typography::new();
59 typo.size(4.5).align(Center);
60
61 for (name, geo) in CarlsonSmithTruchet::full_set()
62 .iter()
63 .filter(|(x, _y)| !x.starts_with("^"))
64 {
65 println!("Plotting {}", name);
66 let yofs: f64 = -256.0f64 + 128.0f64 * <f64 as From<i32>>::from((count / 6) as i32);
67 let xofs: f64 = -512.0f64 + 96.0f64 * <f64 as From<i32>>::from((count % 6) as i32);
68 // println!("xy is {},{}", xofs, yofs);
69 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(64.0, 64.0);
70 count += 1;
71 ctx.transform(Some(&tx)).geometry(&geo);
72 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(1.0, -1.0);
73
74 ctx.transform(Some(&tx)).typography(&name, 0.0, 60.0, &typo);
75 }
76 count = 0;
77 for (name, geo) in self
78 .full_set
79 .clone()
80 .iter()
81 .filter(|(x, _y)| x.starts_with("^"))
82 {
83 println!("Plotting inverse scale/2 {}", name);
84 let yofs: f64 =
85 -256.0f64 - 16.0f64 + 128.0f64 * <f64 as From<i32>>::from((count / 6) as i32);
86 let xofs: f64 = -512.0f64
87 + (96.0f64 * 6.0f64)
88 + 96.0f64 * <f64 as From<i32>>::from((count % 6) as i32);
89 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(32.0, 32.0);
90 count += 1;
91 ctx.transform(Some(&tx)).geometry(&geo);
92 ctx.transform(Some(&tx)).geometry(&geo);
93 let tx = AOERCTX::translate_matrix(xofs, yofs) * AOERCTX::scale_matrix(1.0, -1.0);
94
95 ctx.transform(Some(&tx)).typography(&name, 0.0, 40.0, &typo);
96 }
97 ctx
98 }examples/hatch_gallery.rs (line 58)
11fn main() {
12 let mut ctx = Context::new();
13
14 let fills: Vec<Arc<Box<dyn HatchPattern>>> = vec![
15 (Arc::new(Box::new(LineHatch {}))),
16 (Arc::new(Box::new(CrossHatch {}))),
17 (Arc::new(Box::new(RadiusHatch { x: 160., y: 32.0 }))),
18 (Arc::new(Box::new(CircleHatch {}))),
19 (Arc::new(Box::new(FastHexHatch {}))),
20 (Arc::new(Box::new(RadiusHatch { x: 160., y: 32.0 }))),
21 (Arc::new(Box::new(SpiralHatch {
22 x: 32.0,
23 y: 3. * 60.0,
24 direction: SpiralDirection::Widdershins,
25 }))),
26 (Arc::new(Box::new(SpiralHatch {
27 x: 64. + 32.0,
28 y: 3. * 60.0,
29 direction: SpiralDirection::Deasil,
30 }))),
31 ];
32
33 for (i, pattern) in fills.iter().enumerate() {
34 ctx.stroke("black")
35 .fill("black")
36 .pen(0.25)
37 .pattern(pattern.clone())
38 .hatch_scale(Some(3.))
39 .hatch(0.)
40 .poly(
41 vec![
42 ((i % 3) as f64 * 64. + 4., (i / 3) as f64 * 72. + 4.),
43 ((i % 3) as f64 * 64. + 4. + 56., (i / 3) as f64 * 72. + 4.),
44 (
45 (i % 3) as f64 * 64. + 56. + 4.,
46 (i / 3) as f64 * 72. + 56. + 4.,
47 ),
48 ((i % 3) as f64 * 64. + 4., (i / 3) as f64 * 72. + 4. + 56.),
49 ],
50 vec![],
51 )
52 .pen(0.2)
53 .pattern(Arc::new(Box::new(NoHatch {})))
54 .typography(
55 &format!("{:?}", pattern),
56 (i % 3) as f64 * 64. + 4.,
57 (i / 3) as f64 * 72. + 8. + 56.,
58 &Typography::new().size(1.2),
59 );
60 }
61
62 let svg = ctx
63 .to_svg(&Arrangement::<f64>::unit(&Rect::<f64>::new(
64 coord! {x:0.0, y:0.0},
65 coord! {x:500.0, y:500.0},
66 )))
67 .unwrap();
68 // Write it to the images folder, so we can use it as an example!
69 // Write it out to /images/$THIS_EXAMPLE_FILE.svg
70 let fname = Path::new(file!()).file_stem().unwrap().to_str().unwrap();
71 svg::save(format!("images/{}.svg", fname), &svg).unwrap();
72}pub fn render( &self, text: &String, accuracy: f64, ) -> Result<Geometry<f64>, Box<dyn Error>>
Trait Implementations§
Source§impl Clone for Typography
impl Clone for Typography
Source§fn clone(&self) -> Typography
fn clone(&self) -> Typography
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for Typography
impl RefUnwindSafe for Typography
impl !Send for Typography
impl !Sync for Typography
impl Unpin for Typography
impl UnwindSafe for Typography
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Convert the source color to the destination color using the specified
method
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Convert the source color to the destination color using the bradford
method by default
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
Source§fn convert_into(self) -> U
fn convert_into(self) -> U
Convert into T with values clamped to the color defined bounds Read more
Source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
Convert into T. The resulting color might be invalid in its color space Read more
Source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
Convert into T, returning ok if the color is inside of its defined range,
otherwise an
OutOfBounds error is returned which contains the unclamped color. Read moreSource§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.