Commit 5af45efd authored by Federico Mena Quintero's avatar Federico Mena Quintero

Merge branch 'font-size-scaling' into 'master'

Font size scaling

See merge request !131
parents 1c63d21d dc4f5845
Pipeline #32766 failed with stages
in 19 minutes and 38 seconds
......@@ -516,7 +516,23 @@ impl<'a> DrawingCtx<'a> {
let cr = self.get_cairo_context();
pangocairo::functions::update_context(&cr, &context);
set_resolution(&context, self.dpi_x);
// 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.
set_resolution(&context, 72.0);
if self.is_testing {
let mut options = cairo::FontOptions::new();
......
......@@ -384,7 +384,7 @@ impl NodeTrait for NodeTSpan {
}
fn to_pango_units(v: f64) -> i32 {
(v * f64::from(pango::SCALE)) as i32
(v * f64::from(pango::SCALE) + 0.5) as i32
}
impl From<FontStyle> for pango::Style {
......
<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
<g fill="blue">
<rect x="48" y="48" width="48" height="48"/>
<text style="font-size: 48" x="96" y="96">Hello</text>
</g>
<g fill="green">
<rect x="1in" y="2.5in" width="1in" height="1in"/>
<text style="font-size: 1in" x="2in" y="3.5in">Hello</text>
</g>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment