[librsvg: 8/22] DrawingCtx::create_pango_context - put this here, instead of an impl From<DrawingCtx>
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 8/22] DrawingCtx::create_pango_context - put this here, instead of an impl From<DrawingCtx>
- Date: Thu, 23 Sep 2021 18:42:11 +0000 (UTC)
commit 3aa998c19c3b8164b10f327cff95ce2d16d5ff5c
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Sep 23 10:36:49 2021 -0500
DrawingCtx::create_pango_context - put this here, instead of an impl From<DrawingCtx>
Creating a Pango context is not a conversion from a DrawingCtx, so
turn that into just a method instead of an impl From.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/593>
src/drawing_ctx.rs | 85 +++++++++++++++++++++++++++---------------------------
src/text.rs | 5 ++--
2 files changed, 45 insertions(+), 45 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 64e8fc31..2b074889 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1720,6 +1720,48 @@ impl DrawingCtx {
res
}
}
+
+ /// Create a Pango context based on the cr and `testing` flag from the DrawingCtx.
+ pub fn create_pango_context(&self) -> pango::Context {
+ let cr = self.cr.clone();
+
+ let mut options = cairo::FontOptions::new().unwrap();
+ if self.testing {
+ options.set_antialias(cairo::Antialias::Gray);
+ }
+
+ options.set_hint_style(cairo::HintStyle::None);
+ options.set_hint_metrics(cairo::HintMetrics::Off);
+
+ cr.set_font_options(&options);
+
+ let font_map = pangocairo::FontMap::default().unwrap();
+ let context = font_map.create_context().unwrap();
+
+ context.set_round_glyph_positions(false);
+
+ pangocairo::functions::update_context(&cr, &context);
+
+ // 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
+ }
}
// https://www.w3.org/TR/css-masking-1/#ClipPathElement
@@ -2041,49 +2083,6 @@ impl From<TextRendering> for cairo::Antialias {
}
}
-impl From<&DrawingCtx> for pango::Context {
- fn from(draw_ctx: &DrawingCtx) -> pango::Context {
- let cr = draw_ctx.cr.clone();
-
- let mut options = cairo::FontOptions::new().unwrap();
- if draw_ctx.testing {
- options.set_antialias(cairo::Antialias::Gray);
- }
-
- options.set_hint_style(cairo::HintStyle::None);
- options.set_hint_metrics(cairo::HintMetrics::Off);
-
- cr.set_font_options(&options);
-
- let font_map = pangocairo::FontMap::default().unwrap();
- let context = font_map.create_context().unwrap();
-
- context.set_round_glyph_positions(false);
-
- pangocairo::functions::update_context(&cr, &context);
-
- // 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
- }
-}
-
impl From<cairo::Matrix> for Transform {
#[inline]
fn from(m: cairo::Matrix) -> Self {
diff --git a/src/text.rs b/src/text.rs
index d22e648e..8f1bc4dd 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -556,7 +556,8 @@ impl Draw for Text {
let chunk_x = chunk.x.unwrap_or(x);
let chunk_y = chunk.y.unwrap_or(y);
- let positioned = PositionedChunk::from_measured(chunk, &view_params, chunk_x, chunk_y);
+ let positioned =
+ PositionedChunk::from_measured(chunk, &view_params, chunk_x, chunk_y);
x = positioned.next_chunk_x;
y = positioned.next_chunk_y;
@@ -809,7 +810,7 @@ impl From<WritingMode> for pango::Gravity {
}
fn create_pango_layout(draw_ctx: &DrawingCtx, props: &FontProperties, text: &str) -> pango::Layout {
- let pango_context = pango::Context::from(draw_ctx);
+ let pango_context = draw_ctx.create_pango_context();
if let XmlLang(Some(ref lang)) = props.xml_lang {
pango_context.set_language(&pango::Language::from_string(lang));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]