[librsvg: 14/15] state: cleanup markers code
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 14/15] state: cleanup markers code
- Date: Sun, 8 Apr 2018 00:01:42 +0000 (UTC)
commit 4e6421bbb3180673821927bcf1f2e3d08a0fd7cd
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Apr 7 23:26:28 2018 +0200
state: cleanup markers code
librsvg/rsvg-base.c | 24 --------------------
librsvg/rsvg-private.h | 7 ------
librsvg/rsvg-styles.c | 18 +++++++++++++++
librsvg/rsvg-styles.h | 9 ++++++++
rsvg_internals/src/marker.rs | 52 ++++++++++----------------------------------
rsvg_internals/src/state.rs | 37 +++++++++++++++++++++++++++++++
6 files changed, 75 insertions(+), 72 deletions(-)
---
diff --git a/librsvg/rsvg-base.c b/librsvg/rsvg-base.c
index 6081c67a..7f7ab52b 100644
--- a/librsvg/rsvg-base.c
+++ b/librsvg/rsvg-base.c
@@ -540,30 +540,6 @@ rsvg_drawing_ctx_get_pango_context (RsvgDrawingCtx *draw_ctx)
return rsvg_cairo_get_pango_context (draw_ctx);
}
-const char *
-rsvg_get_start_marker (RsvgDrawingCtx *ctx)
-{
- RsvgState *state = rsvg_drawing_ctx_get_current_state (ctx);
-
- return state->startMarker;
-}
-
-const char *
-rsvg_get_middle_marker (RsvgDrawingCtx *ctx)
-{
- RsvgState *state = rsvg_drawing_ctx_get_current_state (ctx);
-
- return state->middleMarker;
-}
-
-const char *
-rsvg_get_end_marker (RsvgDrawingCtx *ctx)
-{
- RsvgState *state = rsvg_drawing_ctx_get_current_state (ctx);
-
- return state->endMarker;
-}
-
void
rsvg_drawing_ctx_insert_bbox (RsvgDrawingCtx *draw_ctx, RsvgBbox *bbox)
{
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index 79940def..dd7fcfaf 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -470,13 +470,6 @@ void rsvg_drawing_ctx_draw_node_from_stack (RsvgDrawingCtx *ctx,
int dominate,
gboolean clipping);
-G_GNUC_INTERNAL
-const char *rsvg_get_start_marker (RsvgDrawingCtx *ctx);
-G_GNUC_INTERNAL
-const char *rsvg_get_middle_marker (RsvgDrawingCtx *ctx);
-G_GNUC_INTERNAL
-const char *rsvg_get_end_marker (RsvgDrawingCtx *ctx);
-
G_GNUC_INTERNAL
void rsvg_render_free (RsvgRender * render);
diff --git a/librsvg/rsvg-styles.c b/librsvg/rsvg-styles.c
index a63f1b06..6be39abb 100644
--- a/librsvg/rsvg-styles.c
+++ b/librsvg/rsvg-styles.c
@@ -1484,6 +1484,24 @@ rsvg_state_get_enable_background (RsvgState *state)
return rsvg_state_rust_get_enable_background (state->state_rust);
}
+const char *
+rsvg_state_get_start_marker (RsvgState *state)
+{
+ return state->startMarker;
+}
+
+const char *
+rsvg_state_get_middle_marker (RsvgState *state)
+{
+ return state->middleMarker;
+}
+
+const char *
+rsvg_state_get_end_marker (RsvgState *state)
+{
+ return state->endMarker;
+}
+
State *
rsvg_state_get_state_rust (RsvgState *state)
{
diff --git a/librsvg/rsvg-styles.h b/librsvg/rsvg-styles.h
index 7f2f5c5b..44c54bef 100644
--- a/librsvg/rsvg-styles.h
+++ b/librsvg/rsvg-styles.h
@@ -212,6 +212,15 @@ cairo_operator_t rsvg_state_get_comp_op (RsvgState *state);
G_GNUC_INTERNAL
RsvgEnableBackgroundType rsvg_state_get_enable_background (RsvgState *state);
+G_GNUC_INTERNAL
+const char *rsvg_state_get_start_marker (RsvgState *state);
+
+G_GNUC_INTERNAL
+const char *rsvg_state_get_middle_marker (RsvgState *state);
+
+G_GNUC_INTERNAL
+const char *rsvg_state_get_end_marker (RsvgState *state);
+
G_GNUC_INTERNAL
void rsvg_state_dominate (RsvgState *state, const RsvgState *src);
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index baeb6fd1..78f29137 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -21,7 +21,6 @@ use parsers::ParseError;
use path_builder::*;
use property_bag::PropertyBag;
use state::{self, StrokeWidth};
-use util::utf8_cstr;
use viewbox::*;
// markerUnits attribute: https://www.w3.org/TR/SVG/painting.html#MarkerElement
@@ -589,19 +588,13 @@ enum MarkerType {
fn emit_marker_by_name(
draw_ctx: *mut RsvgDrawingCtx,
- marker_name: *const libc::c_char,
+ name: &str,
xpos: f64,
ypos: f64,
computed_angle: f64,
line_width: f64,
clipping: bool,
) {
- if marker_name.is_null() {
- return;
- }
-
- let name = unsafe { utf8_cstr(marker_name) };
-
if let Some(acquired) = drawing_ctx::get_acquired_node_of_type(draw_ctx, name, NodeType::Marker)
{
let node = acquired.get();
@@ -620,17 +613,6 @@ fn emit_marker_by_name(
}
}
-fn get_marker_name_from_drawing_ctx(
- draw_ctx: *const RsvgDrawingCtx,
- marker_type: MarkerType,
-) -> *const libc::c_char {
- match marker_type {
- MarkerType::Start => unsafe { rsvg_get_start_marker(draw_ctx) },
- MarkerType::Middle => unsafe { rsvg_get_middle_marker(draw_ctx) },
- MarkerType::End => unsafe { rsvg_get_end_marker(draw_ctx) },
- }
-}
-
#[derive(Debug, Copy, Clone, PartialEq)]
enum MarkerEndpoint {
Start,
@@ -658,18 +640,6 @@ fn emit_marker<E>(
emit_fn(marker_type, x, y, orient);
}
-extern "C" {
- fn rsvg_get_start_marker(draw_ctx: *const RsvgDrawingCtx) -> *const libc::c_char;
- fn rsvg_get_middle_marker(draw_ctx: *const RsvgDrawingCtx) -> *const libc::c_char;
- fn rsvg_get_end_marker(draw_ctx: *const RsvgDrawingCtx) -> *const libc::c_char;
-}
-
-fn drawing_ctx_has_markers(draw_ctx: *const RsvgDrawingCtx) -> bool {
- (!get_marker_name_from_drawing_ctx(draw_ctx, MarkerType::Start).is_null()
- || !get_marker_name_from_drawing_ctx(draw_ctx, MarkerType::Middle).is_null()
- || !get_marker_name_from_drawing_ctx(draw_ctx, MarkerType::End).is_null())
-}
-
pub fn render_markers_for_path_builder(
builder: &PathBuilder,
draw_ctx: *mut RsvgDrawingCtx,
@@ -686,22 +656,22 @@ pub fn render_markers_for_path_builder(
return;
}
- if !drawing_ctx_has_markers(draw_ctx) {
+ if state::get_start_marker(state).is_none() && state::get_middle_marker(state).is_none()
+ && state::get_end_marker(state).is_none()
+ {
return;
}
emit_markers_for_path_builder(
builder,
&mut |marker_type: MarkerType, x: f64, y: f64, computed_angle: f64| {
- emit_marker_by_name(
- draw_ctx,
- get_marker_name_from_drawing_ctx(draw_ctx, marker_type),
- x,
- y,
- computed_angle,
- line_width,
- clipping,
- );
+ if let Some(marker) = match marker_type {
+ MarkerType::Start => state::get_start_marker(state),
+ MarkerType::Middle => state::get_middle_marker(state),
+ MarkerType::End => state::get_end_marker(state),
+ } {
+ emit_marker_by_name(draw_ctx, marker, x, y, computed_angle, line_width, clipping);
+ }
},
);
}
diff --git a/rsvg_internals/src/state.rs b/rsvg_internals/src/state.rs
index 93946184..bac7f89c 100644
--- a/rsvg_internals/src/state.rs
+++ b/rsvg_internals/src/state.rs
@@ -258,6 +258,10 @@ extern "C" {
fn rsvg_state_get_fill(state: *const RsvgState) -> *const PaintServer;
fn rsvg_state_get_fill_opacity(state: *const RsvgState) -> u8;
+ fn rsvg_state_get_start_marker(state: *const RsvgState) -> *const libc::c_char;
+ fn rsvg_state_get_middle_marker(state: *const RsvgState) -> *const libc::c_char;
+ fn rsvg_state_get_end_marker(state: *const RsvgState) -> *const libc::c_char;
+
fn rsvg_state_dominate(state: *mut RsvgState, src: *const RsvgState);
fn rsvg_state_force(state: *mut RsvgState, src: *const RsvgState);
fn rsvg_state_inherit(state: *mut RsvgState, src: *const RsvgState);
@@ -425,6 +429,39 @@ pub fn get_fill_opacity(state: *const RsvgState) -> u8 {
unsafe { rsvg_state_get_fill_opacity(state) }
}
+pub fn get_start_marker<'a>(state: *const RsvgState) -> Option<&'a str> {
+ unsafe {
+ let marker = rsvg_state_get_start_marker(state);
+ if marker.is_null() {
+ None
+ } else {
+ Some(utf8_cstr(marker))
+ }
+ }
+}
+
+pub fn get_middle_marker<'a>(state: *const RsvgState) -> Option<&'a str> {
+ unsafe {
+ let marker = rsvg_state_get_middle_marker(state);
+ if marker.is_null() {
+ None
+ } else {
+ Some(utf8_cstr(marker))
+ }
+ }
+}
+
+pub fn get_end_marker<'a>(state: *const RsvgState) -> Option<&'a str> {
+ unsafe {
+ let marker = rsvg_state_get_end_marker(state);
+ if marker.is_null() {
+ None
+ } else {
+ Some(utf8_cstr(marker))
+ }
+ }
+}
+
pub fn dominate(state: *mut RsvgState, src: *const RsvgState) {
unsafe {
rsvg_state_dominate(state, src);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]