summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2023-03-09 13:51:03 -0600
committerMarge Bot <marge-bot@gnome.org>2023-03-23 01:41:14 +0000
commit607895ec8766e3b9c6b72ec195ad9802a66e94c9 (patch)
tree25fcbbf72e94e53621b99bcce2f9f5892e4511a2
parent6c92bbbcb0e55b11c11448b6e421ef54bdad1e67 (diff)
downloadlibrsvg-607895ec8766e3b9c6b72ec195ad9802a66e94c9.tar.gz
New function to get the transform that will be used for the stacking context
This fixes @notriddle's MR when rebased on top of the changes to have a ValidTransform instead of just Transform in DrawingCtx. The text code needs to know the actual transform that will be used on the target surface, which could be the temporary surface for compositing an isolated stacking context, or the "normal" surface without isolation. This is the transform that is passed to the draw_fn callback in with_discrete_layer(). Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/816>
-rw-r--r--src/drawing_ctx.rs22
-rw-r--r--src/text.rs8
2 files changed, 22 insertions, 8 deletions
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index c9cc9232..d6632888 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -358,8 +358,26 @@ impl DrawingCtx {
*self.initial_viewport.vbox
}
- pub fn toplevel_transform(&self) -> Transform {
- self.initial_viewport.transform.clone()
+ /// Gets the transform that will be used on the target surface,
+ /// whether using an isolated stacking context or not.
+ ///
+ /// This is only used in the text code, and we should probably try
+ /// to remove it.
+ pub fn get_transform_for_stacking_ctx(
+ &self,
+ stacking_ctx: &StackingContext,
+ ) -> Result<ValidTransform, RenderingError> {
+ if stacking_ctx.should_isolate() {
+ let affines = CompositingAffines::new(
+ *self.get_transform(),
+ self.initial_viewport.transform,
+ self.cr_stack.borrow().len(),
+ );
+
+ Ok(ValidTransform::try_from(affines.for_temporary_surface)?)
+ } else {
+ Ok(self.get_transform())
+ }
}
pub fn is_measuring(&self) -> bool {
diff --git a/src/text.rs b/src/text.rs
index ca3598cf..77e3fb60 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -784,11 +784,7 @@ impl ElementTrait for Text {
);
let layout_text = {
- let transform = if stacking_ctx.should_isolate() {
- draw_ctx.toplevel_transform()
- } else {
- draw_ctx.get_transform().into::<Transform>()
- };
+ let transform = draw_ctx.get_transform_for_stacking_ctx(&stacking_ctx)?;
let layout_context = LayoutContext {
writing_mode: values.writing_mode(),
@@ -829,7 +825,7 @@ impl ElementTrait for Text {
}
}
- let empty_bbox = BoundingBox::new().with_transform(transform);
+ let empty_bbox = BoundingBox::new().with_transform(*transform);
let text_bbox = layout_spans.iter().fold(empty_bbox, |mut bbox, span| {
if let Some(ref span_bbox) = span.bbox {