hey we are rasterizing right, just not loading into handle
Some checks failed
/ test (push) Has been cancelled
Some checks failed
/ test (push) Has been cancelled
This commit is contained in:
parent
d6b4cc6297
commit
6c8cb6c5b2
2 changed files with 128 additions and 97 deletions
|
@ -19,7 +19,7 @@ use cosmic::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
widget::{
|
widget::{
|
||||||
container, image, mouse_area, responsive, scrollable, text,
|
container, image, mouse_area, responsive, scrollable, text,
|
||||||
Column, Container, Id, Row, Space,
|
Column, Container, Id, Image, Row, Space,
|
||||||
},
|
},
|
||||||
Task,
|
Task,
|
||||||
};
|
};
|
||||||
|
@ -707,91 +707,100 @@ pub(crate) fn slide_view(
|
||||||
let slide_text = slide.text();
|
let slide_text = slide.text();
|
||||||
|
|
||||||
// let font = SvgFont::from(font).size(font_size.floor() as u8);
|
// let font = SvgFont::from(font).size(font_size.floor() as u8);
|
||||||
let text_container = if delegate {
|
// let text_container = if delegate {
|
||||||
// text widget based
|
// // text widget based
|
||||||
let font_size =
|
// let font_size =
|
||||||
scale_font(slide.font_size() as f32, width);
|
// scale_font(slide.font_size() as f32, width);
|
||||||
let lines = slide_text.lines();
|
// let lines = slide_text.lines();
|
||||||
let text: Vec<Element<Message>> = lines
|
// let text: Vec<Element<Message>> = lines
|
||||||
.map(|t| {
|
// .map(|t| {
|
||||||
rich_text([span(format!("{}\n", t))
|
// rich_text([span(format!("{}\n", t))
|
||||||
.background(
|
// .background(
|
||||||
Background::Color(Color::BLACK)
|
// Background::Color(Color::BLACK)
|
||||||
.scale_alpha(0.4),
|
// .scale_alpha(0.4),
|
||||||
)
|
// )
|
||||||
.border(border::rounded(10))
|
// .border(border::rounded(10))
|
||||||
.padding(10)])
|
// .padding(10)])
|
||||||
.size(font_size)
|
// .size(font_size)
|
||||||
.font(font)
|
// .font(font)
|
||||||
.center()
|
// .center()
|
||||||
.into()
|
// .into()
|
||||||
// let chars: Vec<Span> = t
|
// // let chars: Vec<Span> = t
|
||||||
// .chars()
|
// // .chars()
|
||||||
// .map(|c| -> Span {
|
// // .map(|c| -> Span {
|
||||||
// let character: String = format!("{}/n", c);
|
// // let character: String = format!("{}/n", c);
|
||||||
// span(character)
|
// // span(character)
|
||||||
// .size(font_size)
|
// // .size(font_size)
|
||||||
// .font(font)
|
// // .font(font)
|
||||||
// .background(
|
// // .background(
|
||||||
// Background::Color(Color::BLACK)
|
// // Background::Color(Color::BLACK)
|
||||||
// .scale_alpha(0.4),
|
// // .scale_alpha(0.4),
|
||||||
// )
|
// // )
|
||||||
// .border(border::rounded(10))
|
// // .border(border::rounded(10))
|
||||||
// .padding(10)
|
// // .padding(10)
|
||||||
})
|
// })
|
||||||
.collect();
|
// .collect();
|
||||||
let text = Column::with_children(text).spacing(26);
|
// let text = Column::with_children(text).spacing(26);
|
||||||
Container::new(text)
|
// Container::new(text)
|
||||||
.center(Length::Fill)
|
// .center(Length::Fill)
|
||||||
.align_x(Horizontal::Left)
|
// .align_x(Horizontal::Left)
|
||||||
} else {
|
// } else {
|
||||||
// SVG based
|
// // SVG based
|
||||||
let text: Element<Message> =
|
// let text: Element<Message> =
|
||||||
if let Some(text) = &slide.text_svg {
|
// if let Some(text) = &slide.text_svg {
|
||||||
text.view().map(|_| Message::None).into()
|
// if let Some(handle) = &text.handle {
|
||||||
} else {
|
// debug!("we made it boys");
|
||||||
Space::with_width(0).into()
|
// Image::new(handle)
|
||||||
};
|
// .content_fit(ContentFit::Cover)
|
||||||
Container::new(text)
|
// .width(Length::Fill)
|
||||||
.center(Length::Fill)
|
// .height(Length::Fill)
|
||||||
.align_x(Horizontal::Left)
|
// .into()
|
||||||
// text widget based
|
// } else {
|
||||||
// let font_size =
|
// Space::with_width(0).into()
|
||||||
// scale_font(slide.font_size() as f32, width);
|
// }
|
||||||
// let lines = slide_text.lines();
|
// } else {
|
||||||
// let text: Vec<Element<Message>> = lines
|
// Space::with_width(0).into()
|
||||||
// .map(|t| {
|
// };
|
||||||
// rich_text([span(format!("{}\n", t))
|
// Container::new(text)
|
||||||
// .background(
|
// .center(Length::Fill)
|
||||||
// Background::Color(Color::BLACK)
|
// .align_x(Horizontal::Left)
|
||||||
// .scale_alpha(0.4),
|
// // text widget based
|
||||||
// )
|
// // let font_size =
|
||||||
// .border(border::rounded(10))
|
// // scale_font(slide.font_size() as f32, width);
|
||||||
// .padding(10)])
|
// // let lines = slide_text.lines();
|
||||||
// .size(font_size)
|
// // let text: Vec<Element<Message>> = lines
|
||||||
// .font(font)
|
// // .map(|t| {
|
||||||
// .center()
|
// // rich_text([span(format!("{}\n", t))
|
||||||
// .into()
|
// // .background(
|
||||||
// // let chars: Vec<Span> = t
|
// // Background::Color(Color::BLACK)
|
||||||
// // .chars()
|
// // .scale_alpha(0.4),
|
||||||
// // .map(|c| -> Span {
|
// // )
|
||||||
// // let character: String = format!("{}/n", c);
|
// // .border(border::rounded(10))
|
||||||
// // span(character)
|
// // .padding(10)])
|
||||||
// // .size(font_size)
|
// // .size(font_size)
|
||||||
// // .font(font)
|
// // .font(font)
|
||||||
// // .background(
|
// // .center()
|
||||||
// // Background::Color(Color::BLACK)
|
// // .into()
|
||||||
// // .scale_alpha(0.4),
|
// // // let chars: Vec<Span> = t
|
||||||
// // )
|
// // // .chars()
|
||||||
// // .border(border::rounded(10))
|
// // // .map(|c| -> Span {
|
||||||
// // .padding(10)
|
// // // let character: String = format!("{}/n", c);
|
||||||
// })
|
// // // span(character)
|
||||||
// .collect();
|
// // // .size(font_size)
|
||||||
// let text = Column::with_children(text).spacing(26);
|
// // // .font(font)
|
||||||
// Container::new(text)
|
// // // .background(
|
||||||
// .center(Length::Fill)
|
// // // Background::Color(Color::BLACK)
|
||||||
// .align_x(Horizontal::Left)
|
// // // .scale_alpha(0.4),
|
||||||
};
|
// // // )
|
||||||
|
// // // .border(border::rounded(10))
|
||||||
|
// // // .padding(10)
|
||||||
|
// // })
|
||||||
|
// // .collect();
|
||||||
|
// // let text = Column::with_children(text).spacing(26);
|
||||||
|
// // Container::new(text)
|
||||||
|
// // .center(Length::Fill)
|
||||||
|
// // .align_x(Horizontal::Left)
|
||||||
|
// };
|
||||||
|
|
||||||
// let stroke_text_container = Container::new(stroke_text)
|
// let stroke_text_container = Container::new(stroke_text)
|
||||||
// .center(Length::Fill)
|
// .center(Length::Fill)
|
||||||
|
@ -799,6 +808,22 @@ pub(crate) fn slide_view(
|
||||||
|
|
||||||
// let text_stack =
|
// let text_stack =
|
||||||
// stack!(stroke_text_container, text_container);
|
// stack!(stroke_text_container, text_container);
|
||||||
|
|
||||||
|
let text: Element<Message> =
|
||||||
|
if let Some(text) = &slide.text_svg {
|
||||||
|
if let Some(handle) = &text.handle {
|
||||||
|
debug!("we made it boys");
|
||||||
|
Image::new(handle)
|
||||||
|
.content_fit(ContentFit::Cover)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.height(Length::Fill)
|
||||||
|
.into()
|
||||||
|
} else {
|
||||||
|
Space::with_width(0).into()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Space::with_width(0).into()
|
||||||
|
};
|
||||||
let black = Container::new(Space::new(0, 0))
|
let black = Container::new(Space::new(0, 0))
|
||||||
.style(|_| {
|
.style(|_| {
|
||||||
container::background(Background::Color(Color::BLACK))
|
container::background(Background::Color(Color::BLACK))
|
||||||
|
@ -806,7 +831,7 @@ pub(crate) fn slide_view(
|
||||||
.clip(true)
|
.clip(true)
|
||||||
.width(width)
|
.width(width)
|
||||||
.height(size.height);
|
.height(size.height);
|
||||||
let container = match slide.background().kind {
|
let background = match slide.background().kind {
|
||||||
BackgroundKind::Image => {
|
BackgroundKind::Image => {
|
||||||
let path = slide.background().path.clone();
|
let path = slide.background().path.clone();
|
||||||
Container::new(
|
Container::new(
|
||||||
|
@ -855,11 +880,8 @@ pub(crate) fn slide_view(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let stack = stack!(
|
let stack =
|
||||||
black,
|
stack!(black, background.center(Length::Fill), text);
|
||||||
container.center(Length::Fill),
|
|
||||||
text_container
|
|
||||||
);
|
|
||||||
Container::new(stack).center(Length::Fill).into()
|
Container::new(stack).center(Length::Fill).into()
|
||||||
});
|
});
|
||||||
// let vid = if let Some(video) = &video {
|
// let vid = if let Some(video) = &video {
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
io::Read,
|
io::Read,
|
||||||
|
path::PathBuf,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ pub struct TextSvg {
|
||||||
stroke: Option<Stroke>,
|
stroke: Option<Stroke>,
|
||||||
fill: Color,
|
fill: Color,
|
||||||
alignment: TextAlignment,
|
alignment: TextAlignment,
|
||||||
handle: Option<Handle>,
|
pub handle: Option<Handle>,
|
||||||
fontdb: Arc<resvg::usvg::fontdb::Database>,
|
fontdb: Arc<resvg::usvg::fontdb::Database>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +259,7 @@ impl TextSvg {
|
||||||
} else {
|
} else {
|
||||||
"".into()
|
"".into()
|
||||||
};
|
};
|
||||||
let size = Size::new(1920.0, 1080.0);
|
let size = Size::new(3840.0, 2160.0);
|
||||||
let total_lines = self.text.lines().count();
|
let total_lines = self.text.lines().count();
|
||||||
let half_lines = (total_lines / 2) as f32;
|
let half_lines = (total_lines / 2) as f32;
|
||||||
let middle_position = size.height / 2.0;
|
let middle_position = size.height / 2.0;
|
||||||
|
@ -291,8 +292,8 @@ impl TextSvg {
|
||||||
self.font.size,
|
self.font.size,
|
||||||
self.fill, stroke, text);
|
self.fill, stroke, text);
|
||||||
debug!("starting...");
|
debug!("starting...");
|
||||||
let resvg_tree = Tree::from_str(
|
let resvg_tree = Tree::from_data(
|
||||||
&final_svg,
|
&final_svg.as_bytes(),
|
||||||
&resvg::usvg::Options {
|
&resvg::usvg::Options {
|
||||||
fontdb: Arc::clone(&self.fontdb),
|
fontdb: Arc::clone(&self.fontdb),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -306,6 +307,14 @@ impl TextSvg {
|
||||||
.expect("opops");
|
.expect("opops");
|
||||||
resvg::render(&resvg_tree, transform, &mut pixmap.as_mut());
|
resvg::render(&resvg_tree, transform, &mut pixmap.as_mut());
|
||||||
// debug!(?pixmap);
|
// debug!(?pixmap);
|
||||||
|
// let mut path = dirs::data_local_dir().unwrap();
|
||||||
|
// path.push(PathBuf::from("lumina"));
|
||||||
|
// path.push(PathBuf::from("temp"));
|
||||||
|
// let file_title =
|
||||||
|
// &self.text.lines().next().unwrap().trim_end();
|
||||||
|
// path.push(PathBuf::from(file_title));
|
||||||
|
// path.set_extension("png");
|
||||||
|
// let _ = pixmap.save_png(path);
|
||||||
debug!("rendered");
|
debug!("rendered");
|
||||||
let handle = Handle::from_bytes(pixmap.take());
|
let handle = Handle::from_bytes(pixmap.take());
|
||||||
self.handle = Some(handle);
|
self.handle = Some(handle);
|
||||||
|
@ -315,7 +324,7 @@ impl TextSvg {
|
||||||
|
|
||||||
pub fn view<'a>(&self) -> Element<'a, Message> {
|
pub fn view<'a>(&self) -> Element<'a, Message> {
|
||||||
Image::new(self.handle.clone().unwrap())
|
Image::new(self.handle.clone().unwrap())
|
||||||
.content_fit(ContentFit::Contain)
|
.content_fit(ContentFit::Cover)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.into()
|
.into()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue