pub struct TextOptions {
pub letter_spacing: f32,
pub space_width: f32,
}Fields§
§letter_spacing: f32§space_width: f32Implementations§
Source§impl TextOptions
impl TextOptions
Sourcepub fn default() -> Self
pub fn default() -> Self
Examples found in repository?
examples/image.rs (line 13)
5fn main() {
6 // Create the image
7 let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
8 // Create the font
9 let font = SiFont::from_network(
10 "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
11 );
12 // Render some text
13 let text_options = TextOptions::default();
14 // img.render_text("Hello, World!", 64.0, 480.0, 254.0, None, &font, &text_options);
15 // Render something else
16 // img.render_text("Hello, World!", 48.0, 480.0, 320.0, None, &font, &text_options);
17 // Or do chained
18 img = img
19 .clone()
20 .render_text(
21 "Hello, World!",
22 64.0,
23 480.0,
24 254.0,
25 None,
26 &font,
27 &text_options,
28 )
29 .render_text(
30 "Hello, Another!",
31 48.0,
32 480.0,
33 320.0,
34 None,
35 &font,
36 &text_options,
37 );
38 // Write it
39 let mut file = fs::OpenOptions::new()
40 .create(true) // To create a new file
41 .write(true) // To write
42 .open("out.png")
43 .unwrap();
44 file.write_all(&img.to_bytes()).unwrap();
45}More examples
examples/macros.rs (line 13)
7fn main() {
8 // Create it with macro
9 preset! {
10 my_preset(img, font: SiFont, title: String, tagline: String) {
11 println!("{}", title);
12 let mut new = img;
13 render!(new: title; 480.0, 254.0; "font" &font, "scale" 64.0, "opts" &TextOptions::default(), "color" None);
14 render!(new: tagline; 480.0, 320.0; "font" &font, "scale" 48.0, "opts" &TextOptions::default(), "color" Some(String::from("#FFFFFF")));
15 new
16 }
17 };
18
19 // Use it
20 // Create the image
21 let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
22 // Create the font
23 let font = SiFont::from_network(
24 "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
25 );
26 img.load_preset(
27 my_preset,
28 anymap! {
29 font: font,
30 title: "Hello, World!".to_string(),
31 tagline: "Cool!".to_string()
32 },
33 );
34 let mut file = fs::OpenOptions::new()
35 .create(true) // To create a new file
36 .write(true)
37 // either use the ? operator or unwrap since it returns a Result
38 .open("out.png")
39 .unwrap();
40 file.write_all(&img.to_bytes()).unwrap();
41}examples/preset.rs (line 47)
5fn main() {
6 // Create the preset
7 let preset = SiPreset::new(Box::new(|img, vals| {
8 let new_img = img.clone();
9 // img is the full image
10 println!("Dimensions: {}x{}", img.width(), img.height());
11 println!("Values: {:?}", vals);
12 // Get the font
13 let font = match vals.get("font") {
14 Some(font) => {
15 // Do type checking
16 if font.type_id() == std::any::TypeId::of::<SiFont>() {
17 // Downcast it
18 font.downcast_ref::<SiFont>().unwrap()
19 } else {
20 panic!(
21 "Expected type: {:?}\nFound type: {:?}",
22 std::any::TypeId::of::<SiFont>(),
23 font.type_id()
24 );
25 }
26 }
27 None => panic!("No font provided"),
28 };
29 // Render something on the image with that font
30 // Get the title
31 let title = match vals.get("title") {
32 Some(title) => {
33 // Do type checking
34 if title.type_id() == std::any::TypeId::of::<String>() {
35 // Downcast it
36 title.downcast_ref::<String>().unwrap()
37 } else {
38 panic!(
39 "Expected type: {:?}\nFound type: {:?}",
40 std::any::TypeId::of::<String>(),
41 title.type_id()
42 );
43 }
44 }
45 None => panic!("No title provided"),
46 };
47 let text_options = TextOptions::default();
48 // Render it
49 new_img.render_text(title, 64.0, 480.0, 254.0, None, font, &text_options)
50 }));
51
52 // Use it
53 // Create the image
54 let mut img = SiImage::from_network("https://res.cloudinary.com/zype/image/upload/regraphic");
55 // Create the font
56 let font = SiFont::from_network(
57 "https://github.com/Zype-Z/ShareImage.js/raw/main/assets/fonts/sirin-stencil.ttf",
58 );
59 let font_val: Box<dyn std::any::Any> = Box::new(font);
60 let title_val: Box<dyn std::any::Any> = Box::new("Hello, World!".to_string());
61 let values: HashMap<String, Box<dyn std::any::Any>> = HashMap::from([
62 ("font".to_string(), font_val),
63 ("title".to_string(), title_val),
64 ]);
65 img.load_preset(preset, values);
66 let mut file = fs::OpenOptions::new()
67 .create(true) // To create a new file
68 .write(true)
69 // either use the ? operator or unwrap since it returns a Result
70 .open("out.png")
71 .unwrap();
72 file.write_all(&img.to_bytes()).unwrap();
73}Trait Implementations§
Source§impl Clone for TextOptions
impl Clone for TextOptions
Source§fn clone(&self) -> TextOptions
fn clone(&self) -> TextOptions
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 moreSource§impl From<TextOptions> for JsValue
impl From<TextOptions> for JsValue
Source§fn from(value: TextOptions) -> Self
fn from(value: TextOptions) -> Self
Converts to this type from the input type.
Source§impl FromWasmAbi for TextOptions
impl FromWasmAbi for TextOptions
Source§impl IntoWasmAbi for TextOptions
impl IntoWasmAbi for TextOptions
Source§impl LongRefFromWasmAbi for TextOptions
impl LongRefFromWasmAbi for TextOptions
Source§impl OptionFromWasmAbi for TextOptions
impl OptionFromWasmAbi for TextOptions
Source§impl OptionIntoWasmAbi for TextOptions
impl OptionIntoWasmAbi for TextOptions
Source§impl RefFromWasmAbi for TextOptions
impl RefFromWasmAbi for TextOptions
Source§type Anchor = RcRef<TextOptions>
type Anchor = RcRef<TextOptions>
The type that holds the reference to
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for TextOptions
impl RefMutFromWasmAbi for TextOptions
Source§impl TryFromJsValue for TextOptions
impl TryFromJsValue for TextOptions
Source§impl VectorFromWasmAbi for TextOptions
impl VectorFromWasmAbi for TextOptions
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[TextOptions]>
Source§impl VectorIntoWasmAbi for TextOptions
impl VectorIntoWasmAbi for TextOptions
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[TextOptions]>) -> Self::Abi
Source§impl WasmDescribeVector for TextOptions
impl WasmDescribeVector for TextOptions
impl SupportsConstructor for TextOptions
impl SupportsInstanceProperty for TextOptions
impl SupportsStaticProperty for TextOptions
Auto Trait Implementations§
impl Freeze for TextOptions
impl RefUnwindSafe for TextOptions
impl Send for TextOptions
impl Sync for TextOptions
impl Unpin for TextOptions
impl UnwindSafe for TextOptions
Blanket Implementations§
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§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<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.