[librsvg: 7/8] (#347): Set the ink_rect of Pango layouts, not just their objectBoundingBox rect
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 7/8] (#347): Set the ink_rect of Pango layouts, not just their objectBoundingBox rect
- Date: Tue, 25 Sep 2018 23:50:55 +0000 (UTC)
commit fb2612af6ad423f92197edfd6ebf37b80303b7d5
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Sep 25 18:12:42 2018 -0500
(#347): Set the ink_rect of Pango layouts, not just their objectBoundingBox rect
The ink rectangle of Pango layouts was only being "grown" onto the
current bbox if the text was being rendered with a stroke. We always
need a starting ink_rect, equal to the non-stroked bounds; we can grow
it later when needed.
This includes a new dimensions test for this issue.
https://gitlab.gnome.org/GNOME/librsvg/issues/347
rsvg_internals/src/drawing_ctx.rs | 16 ++-
tests/dimensions.c | 7 ++
tests/fixtures/dimensions/347-bamboo-16fg-s-pt.svg | 128 +++++++++++++++++++++
tests/fixtures/dimensions/347-wrapper.svg | 32 ++++++
4 files changed, 177 insertions(+), 6 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index b7f8ad22..bd3f7e81 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -869,21 +869,25 @@ fn compute_text_bbox(
let ink_width = f64::from(ink.width);
let ink_height = f64::from(ink.height);
- if gravity_is_vertical(gravity) {
- BoundingBox::new(affine).with_rect(Some(cairo::Rectangle {
+ let rect = if gravity_is_vertical(gravity) {
+ cairo::Rectangle {
x: x + (ink_x - ink_height) / pango_scale,
y: y + ink_y / pango_scale,
width: ink_height / pango_scale,
height: ink_width / pango_scale,
- }))
+ }
} else {
- BoundingBox::new(affine).with_rect(Some(cairo::Rectangle {
+ cairo::Rectangle {
x: x + ink_x / pango_scale,
y: y + ink_y / pango_scale,
width: ink_width / pango_scale,
height: ink_height / pango_scale,
- }))
- }
+ }
+ };
+
+ BoundingBox::new(affine)
+ .with_rect(Some(rect))
+ .with_ink_rect(Some(rect))
}
fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) -> BoundingBox {
diff --git a/tests/dimensions.c b/tests/dimensions.c
index 18cd42ff..94718994 100644
--- a/tests/dimensions.c
+++ b/tests/dimensions.c
@@ -93,6 +93,13 @@ static FixtureData fixtures[] =
0, 0, 44, 45,
FALSE, TRUE
},
+ {
+ "/dimensions/sub/text_position",
+ "dimensions/347-wrapper.svg",
+ "#LabelA",
+ 80, 48, 0, 0,
+ TRUE, FALSE
+ }
/* {"/dimensions/sub/rect with transform", "dimensions/bug564527.svg", "#back", 0, 0, 144, 203} */
};
diff --git a/tests/fixtures/dimensions/347-bamboo-16fg-s-pt.svg
b/tests/fixtures/dimensions/347-bamboo-16fg-s-pt.svg
new file mode 100644
index 00000000..de0237cf
--- /dev/null
+++ b/tests/fixtures/dimensions/347-bamboo-16fg-s-pt.svg
@@ -0,0 +1,128 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!--
+ Designed after data from http://www.wacom-asia.com/download/manuals/BambooUsersManual.pdf
+ Size and positions of controls may not be accurate
+ -->
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ style="color:#000000;stroke:#7f7f7f;fill:none;stroke-width:.25;font-size:8"
+ id="bamboo-16fg-s-pt"
+ width="248"
+ height="176">
+ <title
+ id="title">Wacom Bamboo Capture (CTH-470)</title>
+ <g>
+ <rect
+ id="ButtonA"
+ class="A Button"
+ rx=".5"
+ ry=".5"
+ x="28"
+ y="31"
+ width="28"
+ height="36" />
+ <circle
+ id="DotA"
+ cx="41.5"
+ cy="48.5"
+ r=".5" />
+ <path
+ id="LeaderA"
+ class="A Leader"
+ d="M 58 49 l 20 0" />
+ <text
+ id="LabelA"
+ class="A Label"
+ x="80"
+ y="49"
+ style="text-anchor:start;">A</text>
+ </g>
+ <g>
+ <rect
+ id="ButtonB"
+ class="B Button"
+ rx=".5"
+ ry=".5"
+ x="28"
+ y="68"
+ width="28"
+ height="18" />
+ <circle
+ id="DotB"
+ cx="41.5"
+ cy="77.5"
+ r=".5" />
+ <path
+ id="LeaderB"
+ class="B Leader"
+ d="M 58 78 l 20 0" />
+ <text
+ id="LabelB"
+ class="B Label"
+ x="80"
+ y="78"
+ style="text-anchor:start;">B</text>
+ </g>
+ <rect
+ rx="1"
+ ry="1"
+ x="28"
+ y="87"
+ width="28"
+ height="2" />
+ <g>
+ <rect
+ id="ButtonC"
+ class="C Button"
+ x="28"
+ y="90"
+ rx=".5"
+ ry=".5"
+ width="28"
+ height="18" />
+ <circle
+ id="DotC"
+ cx="41.5"
+ cy="99.5"
+ r=".5" />
+ <path
+ id="LeaderC"
+ class="C Leader"
+ d="M 58 100 l 20 0" />
+ <text
+ id="LabelC"
+ class="C Label"
+ x="80"
+ y="100"
+ style="text-anchor:start;">C</text>
+ </g>
+ <g>
+ <rect
+ id="ButtonD"
+ class="D Button"
+ x="28"
+ y="109"
+ rx=".5"
+ ry=".5"
+ width="28"
+ height="36" />
+ <circle
+ id="DotD"
+ cx="41.5"
+ cy="126.5"
+ r=".5" />
+ <path
+ id="LeaderD"
+ class="D Leader"
+ d="M 58 127 l 20 0" />
+ <text
+ id="LabelD"
+ class="D Label"
+ x="80"
+ y="127"
+ style="text-anchor:start;">D</text>
+ </g>
+</svg>
diff --git a/tests/fixtures/dimensions/347-wrapper.svg b/tests/fixtures/dimensions/347-wrapper.svg
new file mode 100644
index 00000000..cf4717bf
--- /dev/null
+++ b/tests/fixtures/dimensions/347-wrapper.svg
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xi="http://www.w3.org/2001/XInclude" width="248" height="176"> <style type="text/css">.Leader {
+ stroke-width: .5 !important;
+ stroke: #535353;
+ fill: none !important;
+}
+
+.Button {
+ stroke-width: .25;
+ stroke: #ededed;
+ fill: #ededed;
+}
+
+.Ring {
+ stroke-width: .5 !important;
+ stroke: #535353 !important;
+ fill: none !important;
+}
+
+.Label {
+ stroke: none !important;
+ stroke-width: .1 !important;
+ font-size: .1 !important;
+ fill: transparent !important;
+}
+
+.TouchStrip, .TouchRing {
+ stroke-width: .1 !important;
+ stroke: #ededed !important;
+ fill: #535353 !important;
+}
+.B { stroke: #729fcf !important; fill: #729fcf !important; } </style><xi:include
href="347-bamboo-16fg-s-pt.svg" /></svg>
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]