[librsvg: 11/15] layout::TextSpan - carry the UserSpacePaintSources here
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 11/15] layout::TextSpan - carry the UserSpacePaintSources here
- Date: Mon, 18 Oct 2021 23:15:48 +0000 (UTC)
commit a671b7e85550992ae0b03746da13c0f611ab3815
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Oct 18 13:23:43 2021 -0500
layout::TextSpan - carry the UserSpacePaintSources here
I.e. resolve them early. This lets DrawingCtx::draw_text_span() not
need arguments for the ViewParams / ComputedValues.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/613>
src/drawing_ctx.rs | 14 +++----------
src/layout.rs | 7 ++++---
src/text.rs | 58 +++++++++++++++++++++++++++++++-----------------------
3 files changed, 40 insertions(+), 39 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 8121edb2..267619a0 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1359,16 +1359,12 @@ impl DrawingCtx {
pub fn draw_text_span(
&mut self,
- view_params: &ViewParams,
span: &TextSpan,
acquired_nodes: &mut AcquiredNodes<'_>,
- values: &ComputedValues,
clipping: bool,
) -> Result<BoundingBox, RenderingError> {
let transform = self.get_transform();
- let paint_order = values.paint_order();
-
if span.bbox.is_none() {
return Ok(self.empty_bbox());
}
@@ -1409,13 +1405,11 @@ impl DrawingCtx {
self.link_tag_begin(&link_target);
}
- for &target in &paint_order.targets {
+ for &target in &span.paint_order.targets {
match target {
PaintTarget::Fill => {
- let fill_paint =
- span.fill_paint.to_user_space(&bbox, view_params, values);
let had_paint_server =
- self.set_paint_source(&fill_paint, acquired_nodes)?;
+ self.set_paint_source(&span.fill_paint, acquired_nodes)?;
if had_paint_server {
self.cr.move_to(span.x, span.y);
@@ -1435,10 +1429,8 @@ impl DrawingCtx {
}
PaintTarget::Stroke => {
- let stroke_paint =
- span.stroke_paint.to_user_space(&bbox, view_params, values);
let had_paint_server =
- self.set_paint_source(&stroke_paint, acquired_nodes)?;
+ self.set_paint_source(&span.stroke_paint, acquired_nodes)?;
if had_paint_server {
self.cr.move_to(span.x, span.y);
diff --git a/src/layout.rs b/src/layout.rs
index 15eb28a8..243de5c0 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -12,7 +12,7 @@ use crate::document::AcquiredNodes;
use crate::element::Element;
use crate::length::*;
use crate::node::*;
-use crate::paint_server::PaintSource;
+use crate::paint_server::{PaintSource, UserSpacePaintSource};
use crate::path_builder::Path;
use crate::properties::{
ClipRule, ComputedValues, Direction, FillRule, Filter, FontFamily, FontStretch, FontStyle,
@@ -105,9 +105,10 @@ pub struct TextSpan {
pub is_visible: bool,
pub x: f64,
pub y: f64,
+ pub paint_order: PaintOrder,
pub stroke: Stroke,
- pub stroke_paint: PaintSource,
- pub fill_paint: PaintSource,
+ pub stroke_paint: UserSpacePaintSource,
+ pub fill_paint: UserSpacePaintSource,
pub text_rendering: TextRendering,
pub link_target: Option<String>,
}
diff --git a/src/text.rs b/src/text.rs
index 9af5d75f..400c0320 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -343,28 +343,41 @@ impl PositionedSpan {
let stroke = Stroke::new(&self.values, ¶ms);
- let stroke_paint = self.values.stroke().0.resolve(
- acquired_nodes,
- self.values.stroke_opacity().0,
- self.values.color().0,
- None,
- None,
- );
-
- let fill_paint = self.values.fill().0.resolve(
- acquired_nodes,
- self.values.fill_opacity().0,
- self.values.color().0,
- None,
- None,
- );
-
- let text_rendering = self.values.text_rendering();
-
let gravity = layout.context().unwrap().gravity();
let bbox = compute_text_box(&layout, x, y, draw_ctx.get_transform(), gravity);
+ let bbox_for_paint = bbox.unwrap_or_else(|| draw_ctx.empty_bbox());
+
+ let stroke_paint = self
+ .values
+ .stroke()
+ .0
+ .resolve(
+ acquired_nodes,
+ self.values.stroke_opacity().0,
+ self.values.color().0,
+ None,
+ None,
+ )
+ .to_user_space(&bbox_for_paint, view_params, &self.values);
+
+ let fill_paint = self
+ .values
+ .fill()
+ .0
+ .resolve(
+ acquired_nodes,
+ self.values.fill_opacity().0,
+ self.values.color().0,
+ None,
+ None,
+ )
+ .to_user_space(&bbox_for_paint, view_params, &self.values);
+
+ let paint_order = self.values.paint_order();
+ let text_rendering = self.values.text_rendering();
+
TextSpan {
layout,
gravity,
@@ -372,6 +385,7 @@ impl PositionedSpan {
is_visible,
x,
y,
+ paint_order,
stroke,
stroke_paint,
fill_paint,
@@ -679,13 +693,7 @@ impl Draw for Text {
for chunk in &positioned_chunks {
for span in &chunk.spans {
let layout_span = span.layout(an, dc, &view_params, chunk.link.clone());
- let span_bbox = dc.draw_text_span(
- &view_params,
- &layout_span,
- an,
- &span.values,
- clipping,
- )?;
+ let span_bbox = dc.draw_text_span(&layout_span, an, clipping)?;
bbox.insert(&span_bbox);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]