Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/rnote-engine/src/engine/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ impl EngineSnapshot {
}
}
}

for new_xopptext in layers.texts.into_iter() {
match Stroke::from_xopptext(new_xopptext, offset, xopp_import_prefs.dpi)
{
Ok(new_text) => {
engine.store.insert_stroke(new_text, None);
}
Err(e) => {
error!(
"Creating Stroke from XoppText failed while loading Xopp bytes, Err: {e:?}",
);
}
}
}
}

// Only add to y offset, results in vertical pages
Expand Down
39 changes: 39 additions & 0 deletions crates/rnote-engine/src/strokes/stroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::vectorimage::VectorImage;
use super::{Content, TextStroke};
use crate::fileformats::xoppformat::{self, XoppColor};
use crate::store::chrono_comp::StrokeLayer;
use crate::strokes::textstroke::TextStyle;
use crate::{Drawable, utils};
use crate::{Engine, render};
use p2d::bounding_volume::Aabb;
Expand Down Expand Up @@ -427,6 +428,29 @@ impl Stroke {
Ok(Stroke::BitmapImage(BitmapImage { image, rectangle }))
}

pub fn from_xopptext(
xopp_text: xoppformat::XoppText,
offset: na::Vector2<f64>,
target_dpi: f64,
) -> Result<Self, anyhow::Error> {
let pos: na::Vector2<f64> = na::Vector2::<f64>::new(
crate::utils::convert_value_dpi(xopp_text.x, xoppformat::XoppFile::DPI, target_dpi),
crate::utils::convert_value_dpi(xopp_text.y, xoppformat::XoppFile::DPI, target_dpi),
);

let mut textstyle = TextStyle::default();
textstyle.color = crate::utils::color_from_xopp(xopp_text.color);
textstyle.font_size =
crate::utils::convert_value_dpi(xopp_text.size, xoppformat::XoppFile::DPI, target_dpi);
textstyle.font_family = xopp_text.font;

Ok(Stroke::TextStroke(TextStroke::new(
xopp_text.text,
pos + offset,
textstyle,
)))
}

pub fn into_xopp(self, current_dpi: f64) -> Option<xoppformat::XoppStrokeType> {
match self {
Stroke::BrushStroke(brushstroke) => {
Expand Down Expand Up @@ -496,6 +520,12 @@ impl Stroke {
))
}
Stroke::ShapeStroke(shapestroke) => {
// Remark
// We can transform shapes to a xopp brushstroke
// under the following conditions
// - if the stroke color is not none
// - if the fill color is transparent
// - if the style is not rough
let png_data = match shapestroke.export_to_bitmap_image_bytes(
image::ImageFormat::Png,
Engine::STROKE_EXPORT_IMAGE_SCALE,
Expand Down Expand Up @@ -540,6 +570,14 @@ impl Stroke {
Stroke::TextStroke(textstroke) => {
// Xournal++ text strokes do not support affine transformations, so we have to convert on best effort here.
// The best solution for now seems to be to export them as a bitmap image.
//
// We _could_ try to retain the text more but
// the hard part is a xopp text element is
// - a single font
// - a single emphasis mode (bold,italic ...) on all text
// - a single color
// So we'd have to cut the text into smaller xopp text elements
// to retain it ...
let png_data = match textstroke.export_to_bitmap_image_bytes(
image::ImageFormat::Png,
Engine::STROKE_EXPORT_IMAGE_SCALE,
Expand Down Expand Up @@ -582,6 +620,7 @@ impl Stroke {
))
}
Stroke::VectorImage(vectorimage) => {
// no svg support in xournalpp
let png_data = match vectorimage.export_to_bitmap_image_bytes(
image::ImageFormat::Png,
Engine::STROKE_EXPORT_IMAGE_SCALE,
Expand Down