[librsvg: 6/13] create_pango_context() - Turn into a free function
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 6/13] create_pango_context() - Turn into a free function
- Date: Fri, 5 Nov 2021 04:10:04 +0000 (UTC)
commit 96f6174818772e11f9f222f559ec30f7711977ee
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Nov 4 12:17:22 2021 -0600
create_pango_context() - Turn into a free function
Now that this function no longer uses &self, it can be free.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/626>
src/drawing_ctx.rs | 72 +++++++++++++++++++++++++++---------------------------
src/text.rs | 9 +++----
2 files changed, 40 insertions(+), 41 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 77863dc0c..59d8f0e03 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1773,50 +1773,50 @@ impl DrawingCtx {
FontOptions { options }
}
+}
- /// Create a Pango context with a particular configuration.
- pub fn create_pango_context(&self, font_options: &FontOptions, transform: &Transform) -> pango::Context {
- let font_map = pangocairo::FontMap::default().unwrap();
- let context = font_map.create_context().unwrap();
+/// Create a Pango context with a particular configuration.
+pub fn create_pango_context(font_options: &FontOptions, transform: &Transform) -> pango::Context {
+ let font_map = pangocairo::FontMap::default().unwrap();
+ let context = font_map.create_context().unwrap();
- context.set_round_glyph_positions(false);
+ context.set_round_glyph_positions(false);
- let pango_matrix = PangoMatrix {
- xx: transform.xx,
- xy: transform.xy,
- yx: transform.yx,
- yy: transform.yy,
- x0: transform.x0,
- y0: transform.y0,
- };
+ let pango_matrix = PangoMatrix {
+ xx: transform.xx,
+ xy: transform.xy,
+ yx: transform.yx,
+ yy: transform.yy,
+ x0: transform.x0,
+ y0: transform.y0,
+ };
- let pango_matrix_ptr: *const PangoMatrix = &pango_matrix;
+ let pango_matrix_ptr: *const PangoMatrix = &pango_matrix;
- let matrix = unsafe { pango::Matrix::from_glib_none(pango_matrix_ptr) };
- context.set_matrix(Some(&matrix));
+ let matrix = unsafe { pango::Matrix::from_glib_none(pango_matrix_ptr) };
+ context.set_matrix(Some(&matrix));
- pangocairo::functions::context_set_font_options(&context, Some(&font_options.options));
+ pangocairo::functions::context_set_font_options(&context, Some(&font_options.options));
- // Pango says this about pango_cairo_context_set_resolution():
- //
- // Sets the resolution for the context. This is a scale factor between
- // points specified in a #PangoFontDescription and Cairo units. The
- // default value is 96, meaning that a 10 point font will be 13
- // units high. (10 * 96. / 72. = 13.3).
- //
- // I.e. Pango font sizes in a PangoFontDescription are in *points*, not pixels.
- // However, we are normalizing everything to userspace units, which amount to
- // pixels. So, we will use 72.0 here to make Pango not apply any further scaling
- // to the size values we give it.
- //
- // An alternative would be to divide our font sizes by (dpi_y / 72) to effectively
- // cancel out Pango's scaling, but it's probably better to deal with Pango-isms
- // right here, instead of spreading them out through our Length normalization
- // code.
- pangocairo::functions::context_set_resolution(&context, 72.0);
+ // Pango says this about pango_cairo_context_set_resolution():
+ //
+ // Sets the resolution for the context. This is a scale factor between
+ // points specified in a #PangoFontDescription and Cairo units. The
+ // default value is 96, meaning that a 10 point font will be 13
+ // units high. (10 * 96. / 72. = 13.3).
+ //
+ // I.e. Pango font sizes in a PangoFontDescription are in *points*, not pixels.
+ // However, we are normalizing everything to userspace units, which amount to
+ // pixels. So, we will use 72.0 here to make Pango not apply any further scaling
+ // to the size values we give it.
+ //
+ // An alternative would be to divide our font sizes by (dpi_y / 72) to effectively
+ // cancel out Pango's scaling, but it's probably better to deal with Pango-isms
+ // right here, instead of spreading them out through our Length normalization
+ // code.
+ pangocairo::functions::context_set_resolution(&context, 72.0);
- context
- }
+ context
}
// https://www.w3.org/TR/css-masking-1/#ClipPathElement
diff --git a/src/text.rs b/src/text.rs
index f46fb9abf..cce9c7424 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -7,7 +7,7 @@ use std::rc::Rc;
use crate::bbox::BoundingBox;
use crate::document::{AcquiredNodes, NodeId};
-use crate::drawing_ctx::{DrawingCtx, FontOptions, ViewParams};
+use crate::drawing_ctx::{create_pango_context, DrawingCtx, FontOptions, ViewParams};
use crate::element::{Draw, Element, ElementResult, SetAttributes};
use crate::error::*;
use crate::layout::{self, FontProperties, StackingContext, Stroke, TextSpan};
@@ -355,8 +355,7 @@ impl MeasuredSpan {
);
let with_control_chars = wrap_with_direction_control_chars(&span.text, &bidi_control);
- let layout =
- create_pango_layout(layout_context, draw_ctx, &properties, &with_control_chars);
+ let layout = create_pango_layout(layout_context, &properties, &with_control_chars);
let (w, h) = layout.size();
let w = f64::from(w) / f64::from(pango::SCALE);
@@ -1186,11 +1185,11 @@ fn wrap_with_direction_control_chars(s: &str, bidi_control: &BidiControl) -> Str
fn create_pango_layout(
layout_context: &LayoutContext,
- draw_ctx: &DrawingCtx,
props: &FontProperties,
text: &str,
) -> pango::Layout {
- let pango_context = draw_ctx.create_pango_context(&layout_context.font_options,
&layout_context.transform);
+ let pango_context =
+ create_pango_context(&layout_context.font_options, &layout_context.transform);
if let XmlLang(Some(ref lang)) = props.xml_lang {
pango_context.set_language(&pango::Language::from_string(lang.as_str()));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]