Commit e3f242ea authored by Paolo Borelli's avatar Paolo Borelli

drawing_ctx: move get_pango_context to rust

Note that this requires adding the pangocairo-sys crate.
parent af78c6f5
......@@ -367,6 +367,7 @@ dependencies = [
"pango 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pango-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pangocairo 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pangocairo-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
......
......@@ -832,34 +832,10 @@ rsvg_drawing_ctx_get_dpi (RsvgDrawingCtx *ctx, double *out_dpi_x, double *out_dp
*out_dpi_y = ctx->dpi_y;
}
PangoContext *
rsvg_drawing_ctx_get_pango_context (RsvgDrawingCtx *ctx)
gboolean
rsvg_drawing_ctx_is_testing (RsvgDrawingCtx *ctx)
{
PangoFontMap *fontmap;
PangoContext *context;
double dpi_y;
fontmap = pango_cairo_font_map_get_default ();
context = pango_font_map_create_context (fontmap);
pango_cairo_update_context (ctx->cr, context);
rsvg_drawing_ctx_get_dpi (ctx, NULL, &dpi_y);
pango_cairo_context_set_resolution (context, dpi_y);
if (ctx->is_testing) {
cairo_font_options_t *options;
options = cairo_font_options_create ();
cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY);
cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_FULL);
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
pango_cairo_context_set_font_options (context, options);
cairo_font_options_destroy (options);
}
return context;
ctx->is_testing;
}
cairo_surface_t *
......
......@@ -117,9 +117,6 @@ void rsvg_drawing_ctx_get_view_box_size (RsvgDrawingCtx *ctx, double *out_width,
G_GNUC_INTERNAL
void rsvg_drawing_ctx_get_dpi (RsvgDrawingCtx *ctx, double *out_dpi_x, double *out_dpi_y);
G_GNUC_INTERNAL
PangoContext *rsvg_drawing_ctx_get_pango_context (RsvgDrawingCtx *ctx);
G_GNUC_INTERNAL
void rsvg_drawing_ctx_push_render_stack (RsvgDrawingCtx *ctx);
G_GNUC_INTERNAL
......@@ -131,6 +128,9 @@ cairo_surface_t *rsvg_drawing_ctx_get_surface_of_node (RsvgDrawingCtx *ctx,
double width,
double height);
G_GNUC_INTERNAL
gboolean rsvg_drawing_ctx_is_testing (RsvgDrawingCtx *ctx);
G_END_DECLS
#endif /*RSVG_DRAWING_CTX_H */
......@@ -27,6 +27,7 @@ itertools = "0.7.4"
pango = "0.4"
pangocairo = "0.5"
pango-sys = "0.6"
pangocairo-sys = "0.7"
cssparser = "0.23"
lazy_static = "1.0.0"
phf = "0.7.21"
......
......@@ -4,8 +4,9 @@ use cairo_sys;
use glib::translate::*;
use glib_sys;
use libc;
use pango;
use pango_sys;
use pango::{self, FontMapExt};
use pangocairo;
use pango_cairo_sys;
use bbox::{BoundingBox, RsvgBbox};
use length::LengthUnit;
......@@ -79,9 +80,7 @@ extern "C" {
clipping: glib_sys::gboolean,
);
fn rsvg_drawing_ctx_get_pango_context(
draw_ctx: *const RsvgDrawingCtx,
) -> *mut pango_sys::PangoContext;
fn rsvg_drawing_ctx_is_testing(draw_ctx: *const RsvgDrawingCtx) -> glib_sys::gboolean;
fn rsvg_drawing_ctx_push_render_stack(draw_ctx: *const RsvgDrawingCtx);
fn rsvg_drawing_ctx_pop_render_stack(draw_ctx: *const RsvgDrawingCtx);
......@@ -284,8 +283,43 @@ pub fn get_offset(draw_ctx: *const RsvgDrawingCtx) -> (f64, f64) {
(w, h)
}
// remove this binding once pangocairo-rs has ContextExt::set_resolution()
fn set_resolution(context: &pango::Context, dpi: f64) {
unsafe {
pango_cairo_sys::pango_cairo_context_set_resolution(context.to_glib_none().0, dpi);
}
}
// remove this binding once pangocairo-rs has ContextExt::set_font_options()
fn set_font_options(context: &pango::Context, options: &cairo::FontOptions) {
unsafe {
pango_cairo_sys::pango_cairo_context_set_font_options(
context.to_glib_none().0,
options.to_glib_none().0,
);
}
}
pub fn get_pango_context(draw_ctx: *const RsvgDrawingCtx) -> pango::Context {
unsafe { from_glib_full(rsvg_drawing_ctx_get_pango_context(draw_ctx)) }
let font_map = pangocairo::FontMap::get_default().unwrap();
let context = font_map.create_context().unwrap();
let cr = get_cairo_context(draw_ctx);
pangocairo::functions::update_context(&cr, &context);
set_resolution(&context, get_dpi(draw_ctx).1);
let testing = unsafe { from_glib(rsvg_drawing_ctx_is_testing(draw_ctx)) };
if testing {
let mut options = cairo::FontOptions::new();
options.set_antialias(cairo::Antialias::Gray);
options.set_hint_style(cairo::enums::HintStyle::Full);
options.set_hint_metrics(cairo::enums::HintMetrics::On);
set_font_options(&context, &options);
}
context
}
pub fn insert_bbox(draw_ctx: *const RsvgDrawingCtx, bbox: &BoundingBox) {
......
......@@ -11,6 +11,7 @@ extern crate glib_sys;
extern crate itertools;
extern crate libc;
extern crate pango;
extern crate pango_cairo_sys;
extern crate pango_sys;
extern crate pangocairo;
extern crate regex;
......
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