[librsvg] Bindings for text_gravity, font_family, font_style, font_weight, font_stretch
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Bindings for text_gravity, font_family, font_style, font_weight, font_stretch
- Date: Fri, 15 Dec 2017 18:53:37 +0000 (UTC)
commit 8904d626908bb4a94bd82b04eeda079c4535448e
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Dec 15 08:41:50 2017 -0600
Bindings for text_gravity, font_family, font_style, font_weight, font_stretch
rsvg-styles.c | 36 ++++++++++++++++++++++++++++++++++++
rsvg-styles.h | 19 +++++++++++++++++++
rsvg-text.c | 24 ++++++++++++++----------
rust/src/state.rs | 31 +++++++++++++++++++++++++++++++
4 files changed, 100 insertions(+), 10 deletions(-)
---
diff --git a/rsvg-styles.c b/rsvg-styles.c
index b66665d..7a9e895 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -1786,3 +1786,39 @@ rsvg_state_get_text_dir (RsvgState *state)
{
return state->text_dir;
}
+
+PangoGravity
+rsvg_state_get_text_gravity (RsvgState *state)
+{
+ return state->text_gravity;
+}
+
+const char *
+rsvg_state_get_font_family (RsvgState *state)
+{
+ return state->font_family;
+}
+
+PangoStyle
+rsvg_state_get_font_style (RsvgState *state)
+{
+ return state->font_style;
+}
+
+PangoVariant
+rsvg_state_get_font_variant (RsvgState *state)
+{
+ return state->font_variant;
+}
+
+PangoWeight
+rsvg_state_get_font_weight (RsvgState *state)
+{
+ return state->font_weight;
+}
+
+PangoStretch
+rsvg_state_get_font_stretch (RsvgState *state)
+{
+ return state->font_stretch;
+}
diff --git a/rsvg-styles.h b/rsvg-styles.h
index 176ceaf..1f4869c 100644
--- a/rsvg-styles.h
+++ b/rsvg-styles.h
@@ -263,6 +263,25 @@ UnicodeBidi rsvg_state_get_unicode_bidi (RsvgState *state);
G_GNUC_INTERNAL
PangoDirection rsvg_state_get_text_dir (RsvgState *state);
+G_GNUC_INTERNAL
+PangoGravity rsvg_state_get_text_gravity (RsvgState *state);
+
+G_GNUC_INTERNAL
+const char *rsvg_state_get_font_family (RsvgState *state);
+
+G_GNUC_INTERNAL
+PangoStyle rsvg_state_get_font_style (RsvgState *state);
+
+G_GNUC_INTERNAL
+PangoVariant rsvg_state_get_font_variant (RsvgState *state);
+
+G_GNUC_INTERNAL
+PangoWeight rsvg_state_get_font_weight (RsvgState *state);
+
+G_GNUC_INTERNAL
+PangoStretch rsvg_state_get_font_stretch (RsvgState *state);
+
+
G_END_DECLS
#endif /* RSVG_STYLES_H */
diff --git a/rsvg-text.c b/rsvg-text.c
index 5a856fe..1e00eda 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -575,18 +575,18 @@ rsvg_text_create_layout (RsvgDrawingCtx *ctx, const char *text)
pango_context_set_base_dir (context,
rsvg_state_get_text_dir (state));
- if (PANGO_GRAVITY_IS_VERTICAL (state->text_gravity))
- pango_context_set_base_gravity (context, state->text_gravity);
+ if (PANGO_GRAVITY_IS_VERTICAL (rsvg_state_get_text_gravity (state)))
+ pango_context_set_base_gravity (context, rsvg_state_get_text_gravity (state));
font_desc = pango_font_description_copy (pango_context_get_font_description (context));
- if (state->font_family)
- pango_font_description_set_family_static (font_desc, state->font_family);
+ if (rsvg_state_get_font_family (state))
+ pango_font_description_set_family (font_desc, rsvg_state_get_font_family (state));
- pango_font_description_set_style (font_desc, state->font_style);
- pango_font_description_set_variant (font_desc, state->font_variant);
- pango_font_description_set_weight (font_desc, state->font_weight);
- pango_font_description_set_stretch (font_desc, state->font_stretch);
+ pango_font_description_set_style (font_desc, rsvg_state_get_font_style (state));
+ pango_font_description_set_variant (font_desc, rsvg_state_get_font_variant (state));
+ pango_font_description_set_weight (font_desc, rsvg_state_get_font_weight (state));
+ pango_font_description_set_stretch (font_desc, rsvg_state_get_font_stretch (state));
rsvg_drawing_ctx_get_dpi (ctx, NULL, &dpi_y);
pango_font_description_set_size (font_desc,
@@ -641,6 +641,7 @@ rsvg_text_render_text (RsvgDrawingCtx * ctx, const char *text, gdouble * x, gdou
RsvgState *state;
gint w, h;
double offset_x, offset_y, offset;
+ PangoGravity gravity;
state = rsvg_current_state (ctx);
@@ -653,7 +654,10 @@ rsvg_text_render_text (RsvgDrawingCtx * ctx, const char *text, gdouble * x, gdou
iter = pango_layout_get_iter (layout);
offset = pango_layout_iter_get_baseline (iter) / (double) PANGO_SCALE;
offset += _rsvg_css_accumulate_baseline_shift (state, ctx);
- if (PANGO_GRAVITY_IS_VERTICAL (state->text_gravity)) {
+
+ gravity = rsvg_state_get_text_gravity (state);
+
+ if (PANGO_GRAVITY_IS_VERTICAL (gravity)) {
offset_x = -offset;
offset_y = 0;
} else {
@@ -662,7 +666,7 @@ rsvg_text_render_text (RsvgDrawingCtx * ctx, const char *text, gdouble * x, gdou
}
pango_layout_iter_free (iter);
ctx->render->render_pango_layout (ctx, layout, *x - offset_x, *y - offset_y);
- if (PANGO_GRAVITY_IS_VERTICAL (state->text_gravity))
+ if (PANGO_GRAVITY_IS_VERTICAL (gravity))
*y += w / (double)PANGO_SCALE;
else
*x += w / (double)PANGO_SCALE;
diff --git a/rust/src/state.rs b/rust/src/state.rs
index 81a8300..cd4dcba 100644
--- a/rust/src/state.rs
+++ b/rust/src/state.rs
@@ -17,6 +17,12 @@ extern "C" {
fn rsvg_state_get_language (state: *const RsvgState) -> *const libc::c_char;
fn rsvg_state_get_unicode_bidi (state: *const RsvgState) -> UnicodeBidi;
fn rsvg_state_get_text_dir (state: *const RsvgState) -> pango_sys::PangoDirection;
+ fn rsvg_state_get_text_gravity (state: *const RsvgState) -> pango_sys::PangoGravity;
+ fn rsvg_state_get_font_family (state: *const RsvgState) -> *const libc::c_char;
+ fn rsvg_state_get_font_style (state: *const RsvgState) -> pango_sys::PangoStyle;
+ fn rsvg_state_get_font_variant (state: *const RsvgState) -> pango_sys::PangoVariant;
+ fn rsvg_state_get_font_weight (state: *const RsvgState) -> pango_sys::PangoWeight;
+ fn rsvg_state_get_font_stretch (state: *const RsvgState) -> pango_sys::PangoStretch;
}
pub fn get_language(state: *const RsvgState) -> Option<String> {
@@ -32,3 +38,28 @@ pub fn get_unicode_bidi(state: *const RsvgState) -> UnicodeBidi {
pub fn get_text_dir(state: *const RsvgState) -> pango::Direction {
unsafe { from_glib(rsvg_state_get_text_dir(state)) }
}
+
+pub fn get_text_gravity(state: *const RsvgState) -> pango::Gravity {
+ unsafe { from_glib(rsvg_state_get_text_gravity(state)) }
+}
+
+pub fn get_font_family(state: *const RsvgState) -> String {
+ unsafe { from_glib_none(rsvg_state_get_font_family(state)) }
+}
+
+
+pub fn get_font_style(state: *const RsvgState) -> pango::Style {
+ unsafe { from_glib(rsvg_state_get_font_style(state)) }
+}
+
+pub fn get_font_variant(state: *const RsvgState) -> pango::Variant {
+ unsafe { from_glib(rsvg_state_get_font_variant(state)) }
+}
+
+pub fn get_font_weight(state: *const RsvgState) -> pango::Weight {
+ unsafe { from_glib(rsvg_state_get_font_weight(state)) }
+}
+
+pub fn get_font_stretch(state: *const RsvgState) -> pango::Stretch {
+ unsafe { from_glib(rsvg_state_get_font_stretch(state)) }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]