[librsvg] Add rsvg_state_get_unicode_bidi(), rsvg_state_get_text_dir(); bind them to Rust
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Add rsvg_state_get_unicode_bidi(), rsvg_state_get_text_dir(); bind them to Rust
- Date: Fri, 15 Dec 2017 18:53:32 +0000 (UTC)
commit 45c0af021dd158b927534111cb026d406c18949c
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Dec 15 07:05:06 2017 -0600
Add rsvg_state_get_unicode_bidi(), rsvg_state_get_text_dir(); bind them to Rust
rsvg-styles.c | 12 ++++++++++++
rsvg-styles.h | 6 ++++++
rsvg-text.c | 9 ++++++---
rust/src/state.rs | 22 +++++++++++++++++++++-
4 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/rsvg-styles.c b/rsvg-styles.c
index a5a2065..b66665d 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -1774,3 +1774,15 @@ rsvg_state_get_language (RsvgState *state)
{
return state->lang;
}
+
+UnicodeBidi
+rsvg_state_get_unicode_bidi (RsvgState *state)
+{
+ return state->unicode_bidi;
+}
+
+PangoDirection
+rsvg_state_get_text_dir (RsvgState *state)
+{
+ return state->text_dir;
+}
diff --git a/rsvg-styles.h b/rsvg-styles.h
index a459f2d..176ceaf 100644
--- a/rsvg-styles.h
+++ b/rsvg-styles.h
@@ -51,6 +51,7 @@ typedef enum {
TEXT_ANCHOR_END
} TextAnchor;
+/* Keep in sync with rust/src/state.c:UnicodeBidi */
typedef enum {
UNICODE_BIDI_NORMAL = 0,
UNICODE_BIDI_EMBED = 1,
@@ -256,6 +257,11 @@ guint32 rsvg_state_get_current_color (RsvgState *state);
G_GNUC_INTERNAL
const char *rsvg_state_get_language (RsvgState *state);
+G_GNUC_INTERNAL
+UnicodeBidi rsvg_state_get_unicode_bidi (RsvgState *state);
+
+G_GNUC_INTERNAL
+PangoDirection rsvg_state_get_text_dir (RsvgState *state);
G_END_DECLS
diff --git a/rsvg-text.c b/rsvg-text.c
index 17bfe6a..5a856fe 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -560,6 +560,7 @@ rsvg_text_create_layout (RsvgDrawingCtx *ctx, const char *text)
PangoAttribute *attribute;
double dpi_y;
const char *lang;
+ UnicodeBidi unicode_bidi;
state = rsvg_current_state (ctx);
@@ -569,8 +570,10 @@ rsvg_text_create_layout (RsvgDrawingCtx *ctx, const char *text)
if (lang)
pango_context_set_language (context, pango_language_from_string (lang));
- if (state->unicode_bidi == UNICODE_BIDI_OVERRIDE || state->unicode_bidi == UNICODE_BIDI_EMBED)
- pango_context_set_base_dir (context, state->text_dir);
+ unicode_bidi = rsvg_state_get_unicode_bidi (state);
+ if (unicode_bidi == UNICODE_BIDI_OVERRIDE || unicode_bidi == UNICODE_BIDI_EMBED)
+ 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);
@@ -622,7 +625,7 @@ rsvg_text_create_layout (RsvgDrawingCtx *ctx, const char *text)
else
pango_layout_set_text (layout, NULL, 0);
- pango_layout_set_alignment (layout, (state->text_dir == PANGO_DIRECTION_LTR) ?
+ pango_layout_set_alignment (layout, (rsvg_state_get_text_dir (state) == PANGO_DIRECTION_LTR) ?
PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
g_object_unref (context);
diff --git a/rust/src/state.rs b/rust/src/state.rs
index 8805f08..81a8300 100644
--- a/rust/src/state.rs
+++ b/rust/src/state.rs
@@ -1,10 +1,22 @@
use libc;
use glib::translate::*;
+use pango;
+use pango_sys;
pub enum RsvgState {}
+// Keep in sync with rsvg-styles.h:UnicodeBidi
+#[repr(C)]
+pub enum UnicodeBidi {
+ Normal,
+ Embed,
+ Override,
+}
+
extern "C" {
- fn rsvg_state_get_language(state: *const RsvgState) -> *const libc::c_char;
+ 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;
}
pub fn get_language(state: *const RsvgState) -> Option<String> {
@@ -12,3 +24,11 @@ pub fn get_language(state: *const RsvgState) -> Option<String> {
from_glib_none(rsvg_state_get_language(state))
}
}
+
+pub fn get_unicode_bidi(state: *const RsvgState) -> UnicodeBidi {
+ unsafe { rsvg_state_get_unicode_bidi(state) }
+}
+
+pub fn get_text_dir(state: *const RsvgState) -> pango::Direction {
+ unsafe { from_glib(rsvg_state_get_text_dir(state)) }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]