[librsvg: 1/8] croco.rs: Minimal hand-written binding to the part of libcroco that we need
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/8] croco.rs: Minimal hand-written binding to the part of libcroco that we need
- Date: Wed, 26 Sep 2018 23:54:46 +0000 (UTC)
commit ff392a858218958ce5a5f3a84878a1eb014e6863
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Sep 25 08:35:03 2018 -0500
croco.rs: Minimal hand-written binding to the part of libcroco that we need
Makefile.am | 1 +
rsvg_internals/src/croco.rs | 121 ++++++++++++++++++++++++++++++++++++++++++++
rsvg_internals/src/lib.rs | 1 +
3 files changed, 123 insertions(+)
---
diff --git a/Makefile.am b/Makefile.am
index d8f7a80f..285a90d5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -53,6 +53,7 @@ RUST_SRC = \
rsvg_internals/src/color.rs \
rsvg_internals/src/cond.rs \
rsvg_internals/src/coord_units.rs \
+ rsvg_internals/src/croco.rs \
rsvg_internals/src/css.rs \
rsvg_internals/src/defs.rs \
rsvg_internals/src/drawing_ctx.rs \
diff --git a/rsvg_internals/src/croco.rs b/rsvg_internals/src/croco.rs
new file mode 100644
index 00000000..4ee67e72
--- /dev/null
+++ b/rsvg_internals/src/croco.rs
@@ -0,0 +1,121 @@
+// This is a hand-written binding to a very minimal part of libcroco. We don't use bindgen because
+// it wants to import pretty much all of glib's types and functions, and we just need a few.
+
+use glib_sys::{gboolean, gpointer, GList};
+use libc;
+
+// Opaque types from libcroco, or those which we only manipulate through libcroco functions
+pub type CRString = gpointer;
+pub type CRSimpleSel = gpointer;
+pub type CRParser = gpointer;
+pub type CRTerm = gpointer;
+
+pub type CRStatus = u32;
+
+pub type CREncoding = u32;
+pub const CREncoding_CR_UTF_8: CREncoding = 5;
+
+#[repr(C)]
+pub struct CRParsingLocation {
+ pub line: libc::c_uint,
+ pub column: libc::c_uint,
+ pub byte_offset: libc::c_uint,
+}
+
+#[repr(C)]
+pub struct CRSelector {
+ pub simple_sel: CRSimpleSel,
+
+ pub next: *mut CRSelector,
+ pub prev: *mut CRSelector,
+
+ pub location: CRParsingLocation,
+ pub ref_count: libc::c_long,
+}
+
+#[repr(C)]
+pub struct CRDocHandler {
+ pub priv_: gpointer,
+
+ pub app_data: gpointer,
+
+ pub start_document: gpointer,
+ pub end_document: gpointer,
+ pub charset: gpointer,
+
+ pub import_style: Option<
+ unsafe extern "C" fn(
+ a_this: *mut CRDocHandler,
+ a_media_list: *mut GList,
+ a_uri: CRString,
+ a_uri_default_ns: CRString,
+ a_location: CRParsingLocation,
+ ),
+ >,
+
+ pub import_style_result: gpointer,
+ pub namespace_declaration: gpointer,
+ pub comment: gpointer,
+
+ pub start_selector:
+ Option<unsafe extern "C" fn(a_this: *mut CRDocHandler, a_selector_list: *mut CRSelector)>,
+
+ pub end_selector:
+ Option<unsafe extern "C" fn(a_this: *mut CRDocHandler, a_selector_list: *mut CRSelector)>,
+
+ pub property: Option<
+ unsafe extern "C" fn(
+ a_this: *mut CRDocHandler,
+ a_name: CRString,
+ a_expression: CRTerm,
+ a_is_important: gboolean,
+ ),
+ >,
+
+ pub start_font_face: gpointer,
+ pub end_font_face: gpointer,
+ pub start_media: gpointer,
+ pub end_media: gpointer,
+ pub start_page: gpointer,
+ pub end_page: gpointer,
+ pub ignorable_at_rule: gpointer,
+
+ pub error: Option<unsafe extern "C" fn(a_this: *mut CRDocHandler)>,
+ pub unrecoverable_error: Option<unsafe extern "C" fn(a_this: *mut CRDocHandler)>,
+
+ pub resolve_import: gboolean,
+ pub ref_count: libc::c_ulong,
+}
+
+extern "C" {
+ pub fn cr_selector_ref(a_this: *mut CRSelector);
+ pub fn cr_selector_unref(a_this: *mut CRSelector) -> gboolean;
+
+ pub fn cr_simple_sel_to_string(a_this: CRSimpleSel) -> *mut libc::c_char;
+
+ pub fn cr_string_peek_raw_str(a_this: CRString) -> *const libc::c_char;
+ pub fn cr_string_peek_raw_str_len(a_this: CRString) -> libc::c_int;
+
+ pub fn cr_term_to_string(a_this: CRTerm) -> *mut libc::c_char;
+
+ pub fn cr_doc_handler_new() -> *mut CRDocHandler;
+ pub fn cr_doc_handler_unref(a_this: *mut CRDocHandler) -> gboolean;
+
+ pub fn cr_parser_new_from_buf(
+ a_buf: *mut libc::c_char,
+ a_len: libc::c_ulong,
+ a_enc: CREncoding,
+ a_free_buf: gboolean,
+ ) -> CRParser;
+
+ pub fn cr_parser_set_sac_handler(a_this: CRParser, a_handler: *mut CRDocHandler) -> CRStatus;
+
+ pub fn cr_parser_set_use_core_grammar(
+ a_this: CRParser,
+ a_use_core_grammar: gboolean,
+ ) -> CRStatus;
+
+ pub fn cr_parser_parse(a_this: CRParser) -> CRStatus;
+ pub fn cr_parser_destroy(a_this: CRParser);
+
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 08668927..cc5691e5 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -91,6 +91,7 @@ mod bbox;
mod clip_path;
mod color;
mod cond;
+mod croco;
mod css;
mod defs;
mod drawing_ctx;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]