[librsvg: 18/37] PositionedChunk: Adjust the position based on the text_anchor
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 18/37] PositionedChunk: Adjust the position based on the text_anchor
- Date: Fri, 28 Dec 2018 03:25:29 +0000 (UTC)
commit f122dd2f0743323964824b389501b5c194889ea1
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Oct 31 08:23:51 2018 -0600
PositionedChunk: Adjust the position based on the text_anchor
rsvg_internals/src/text.rs | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index b0681092..69f4d0c9 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -124,6 +124,19 @@ impl PositionedChunk {
let mut x = x.normalize(&measured.values, ¶ms);
let mut y = y.normalize(&measured.values, ¶ms);
+ // Adjust the specified coordinates with the text_anchor
+
+ let adjusted_advance = text_anchor_advance(
+ measured.values.text_anchor,
+ measured.values.writing_mode,
+ measured.advance,
+ );
+
+ x += adjusted_advance.0;
+ y += adjusted_advance.1;
+
+ // Position each span
+
for measured_span in &measured.spans {
positioned.push(PositionedSpan::from_measured(measured_span, draw_ctx, x, y));
@@ -139,6 +152,26 @@ impl PositionedChunk {
}
}
+fn text_anchor_advance(
+ anchor: TextAnchor,
+ writing_mode: WritingMode,
+ advance: (f64, f64),
+) -> (f64, f64) {
+ if writing_mode.is_vertical() {
+ match anchor {
+ TextAnchor::Start => (0.0, 0.0),
+ TextAnchor::Middle => (0.0, -advance.1 / 2.0),
+ TextAnchor::End => (0.0, -advance.1),
+ }
+ } else {
+ match anchor {
+ TextAnchor::Start => (0.0, 0.0),
+ TextAnchor::Middle => (-advance.0 / 2.0, 0.0),
+ TextAnchor::End => (-advance.0, 0.0),
+ }
+ }
+}
+
impl Span {
fn new(text: &str, values: ComputedValues) -> Span {
Span {
@@ -158,7 +191,7 @@ impl MeasuredSpan {
let w = f64::from(w) / f64::from(pango::SCALE);
let h = f64::from(h) / f64::from(pango::SCALE);
- let (advance_x, advance_y) = if values.text_gravity_is_vertical() {
+ let advance = if values.writing_mode.is_vertical() {
(0.0, w)
} else {
(w, 0.0)
@@ -168,7 +201,7 @@ impl MeasuredSpan {
values,
layout,
layout_size: (w, h),
- advance: (advance_x, advance_y),
+ advance,
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]