[lasem] vg_view: extract the marker paint code from fill and stroke.



commit f0c1041178060dede0921a6a7ca88b2be7488459
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Aug 9 14:44:57 2010 +0200

    vg_view: extract the marker paint code from fill and stroke.

 src/lsmsvgview.c |  298 ++++++++++++++++++++++++++++--------------------------
 1 files changed, 156 insertions(+), 142 deletions(-)
---
diff --git a/src/lsmsvgview.c b/src/lsmsvgview.c
index b815e65..aa5eb13 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -803,10 +803,163 @@ _set_color (LsmSvgView *view, LsmSvgViewPaintOperation operation,
 }
 
 static void
+paint_markers (LsmSvgView *view)
+{
+	const LsmSvgStyle *style;
+	LsmSvgElement *marker;
+	LsmSvgElement *marker_start;
+	LsmSvgElement *marker_mid;
+	LsmSvgElement *marker_end;
+	cairo_t *cairo;
+	cairo_path_t *path;
+	cairo_path_data_t *data;
+	cairo_path_data_t *next_data;
+	double stroke_width;
+	double prev_x, prev_y;
+	double x = 0;
+	double y = 0;
+	double next_x, next_y;
+	cairo_path_data_type_t type;
+	cairo_path_data_type_t next_type;
+	double angle;
+	int i;
+
+	style = view->style;
+
+	if ((style->marker->value == NULL ||       strcmp (style->marker->value, "none") == 0) &&
+	    (style->marker_mid->value == NULL ||   strcmp (style->marker_mid->value, "none") == 0) &&
+	    (style->marker_end->value == NULL ||   strcmp (style->marker_end->value, "none") == 0) &&
+	    (style->marker_start->value == NULL || strcmp (style->marker_start->value, "none") == 0))
+		return;
+
+	cairo = view->dom_view.cairo;
+
+	marker = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
+						      style->marker->value);
+	marker_start = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
+							    style->marker_start->value);
+	marker_mid = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
+							  style->marker_mid->value);
+	marker_end = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
+							  style->marker_end->value);
+	stroke_width = lsm_svg_view_normalize_length (view, &view->style->stroke_width->length,
+						      LSM_SVG_LENGTH_DIRECTION_DIAGONAL);
+
+	if (marker_start == NULL)
+		marker_start = marker;
+	if (marker_mid == NULL)
+		marker_mid = marker;
+	if (marker_end == NULL)
+		marker_end = marker;
+
+	path = cairo_copy_path (cairo);
+	cairo_new_path (cairo);
+
+	if (path->num_data > 0) {
+		next_data = &path->data[0];
+		next_type = next_data->header.type;
+
+		if (next_type == CAIRO_PATH_CURVE_TO) {
+			next_x = next_data[3].point.x;
+			next_y = next_data[3].point.y;
+		} else {
+			next_x = next_data[1].point.x;
+			next_y = next_data[1].point.y;
+		}
+
+		for (i = 0; i < path->num_data; i += path->data[i].header.length) {
+			data = next_data;
+
+			prev_x = x;
+			prev_y = y;
+			x = next_x;
+			y = next_y;
+			type = next_type;
+
+			if (i + path->data[i].header.length < path->num_data) {
+				next_data = &path->data[i + path->data[i].header.length];
+				next_type = next_data->header.type;
+
+				if (next_type == CAIRO_PATH_CURVE_TO) {
+					next_x = next_data[3].point.x;
+					next_y = next_data[3].point.y;
+				} else {
+					next_x = next_data[1].point.x;
+					next_y = next_data[1].point.y;
+				}
+			} else {
+				next_data = NULL;
+				next_type = CAIRO_PATH_MOVE_TO;
+				next_x = 0.0;
+				next_y = 0.0;
+			}
+
+			if (data->header.type == CAIRO_PATH_CLOSE_PATH) {
+				marker = NULL;
+			} else if (next_data == NULL ||
+				   next_data->header.type == CAIRO_PATH_MOVE_TO) {
+				marker = marker_end;
+				if (type == CAIRO_PATH_CURVE_TO)
+					angle = atan2 (y - data[2].point.y,
+						       x - data[2].point.x);
+				else
+					angle = atan2 (y - prev_y, x - prev_x);
+			} else if (data->header.type == CAIRO_PATH_MOVE_TO) {
+				marker = marker_start;
+				if (next_type == CAIRO_PATH_CURVE_TO)
+					angle = atan2 (data[1].point.y - y,
+						       data[1].point.x - x);
+				else
+					angle = atan2 (next_y - y, next_x - x);
+			} else {
+				double xdifin, ydifin, xdifout, ydifout, intot, outtot;
+
+				marker = marker_mid;
+
+				if (type == CAIRO_PATH_CURVE_TO) {
+					xdifin = x - data[2].point.x;
+					ydifin = y - data[2].point.y;
+				} else {
+					xdifin = x - prev_x;
+					ydifin = y - prev_y;
+				}
+				if (next_type == CAIRO_PATH_CURVE_TO) {
+					xdifout = data[3].point.x - x;
+					ydifout = data[3].point.y - y;
+				} else {
+					xdifout = next_x - x;
+					ydifout = next_y - y;
+				}
+
+				intot = sqrt (xdifin * xdifin + ydifin * ydifin);
+				outtot = sqrt (xdifout * xdifout + ydifout * ydifout);
+
+				xdifin /= intot;
+				ydifin /= intot;
+				xdifout /= outtot;
+				ydifout /= outtot;
+
+				angle = atan2 ((ydifin + ydifout) / 2, (xdifin + xdifout) / 2);
+			}
+
+			if (marker != NULL) {
+				cairo_save (cairo);
+				cairo_translate (cairo, x, y);
+				lsm_svg_marker_element_render (LSM_SVG_MARKER_ELEMENT (marker), view,
+							       stroke_width, angle);
+				cairo_restore (cairo);
+			}
+		}
+
+		cairo_path_destroy (path);
+	}
+}
+
+static void
 paint (LsmSvgView *view)
 {
-	LsmSvgElement *element;
 	const LsmSvgStyle *style;
+	LsmSvgElement *element;
 	cairo_t *cairo;
 	gboolean use_group;
 	double group_opacity;
@@ -897,148 +1050,9 @@ paint (LsmSvgView *view)
 		cairo_stroke_preserve (cairo);
 	}
 
-	if ((style->marker->value != NULL && strcmp (style->marker->value, "none") != 0) ||
-	    (style->marker_mid->value != NULL && strcmp (style->marker_mid->value, "none") != 0) ||
-	    (style->marker_end->value != NULL && strcmp (style->marker_end->value, "none") != 0) ||
-	    (style->marker_start->value != NULL && strcmp (style->marker_start->value, "none") != 0)) {
-		LsmSvgElement *marker;
-		LsmSvgElement *marker_start;
-		LsmSvgElement *marker_mid;
-		LsmSvgElement *marker_end;
-		cairo_path_t *path;
-		cairo_path_data_t *data;
-		cairo_path_data_t *next_data;
-		double stroke_width;
-		double prev_x, prev_y;
-		double x = 0;
-		double y = 0;
-		double next_x, next_y;
-		cairo_path_data_type_t type;
-		cairo_path_data_type_t next_type;
-		double angle;
-		int i;
-
-		marker = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
-							      style->marker->value);
-		marker_start = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
-								    style->marker_start->value);
-		marker_mid = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
-								  style->marker_mid->value);
-		marker_end = lsm_svg_document_get_element_by_url (LSM_SVG_DOCUMENT (view->dom_view.document),
-								  style->marker_end->value);
-		stroke_width = lsm_svg_view_normalize_length (view, &view->style->stroke_width->length,
-							      LSM_SVG_LENGTH_DIRECTION_DIAGONAL);
-
-		if (marker_start == NULL)
-			marker_start = marker;
-		if (marker_mid == NULL)
-			marker_mid = marker;
-		if (marker_end == NULL)
-			marker_end = marker;
-
-		path = cairo_copy_path (cairo);
-		cairo_new_path (cairo);
-
-		if (path->num_data > 0) {
-			next_data = &path->data[0];
-			next_type = next_data->header.type;
-
-			if (next_type == CAIRO_PATH_CURVE_TO) {
-				next_x = next_data[3].point.x;
-				next_y = next_data[3].point.y;
-			} else {
-				next_x = next_data[1].point.x;
-				next_y = next_data[1].point.y;
-			}
+	paint_markers (view);
 
-			for (i = 0; i < path->num_data; i += path->data[i].header.length) {
-				data = next_data;
-
-				prev_x = x;
-				prev_y = y;
-				x = next_x;
-				y = next_y;
-				type = next_type;
-
-				if (i + path->data[i].header.length < path->num_data) {
-					next_data = &path->data[i + path->data[i].header.length];
-					next_type = next_data->header.type;
-
-					if (next_type == CAIRO_PATH_CURVE_TO) {
-						next_x = next_data[3].point.x;
-						next_y = next_data[3].point.y;
-					} else {
-						next_x = next_data[1].point.x;
-						next_y = next_data[1].point.y;
-					}
-				} else {
-					next_data = NULL;
-					next_type = CAIRO_PATH_MOVE_TO;
-					next_x = 0.0;
-					next_y = 0.0;
-				}
-
-				if (data->header.type == CAIRO_PATH_CLOSE_PATH) {
-					marker = NULL;
-				} else if (next_data == NULL ||
-					   next_data->header.type == CAIRO_PATH_MOVE_TO) {
-					marker = marker_end;
-					if (type == CAIRO_PATH_CURVE_TO)
-						angle = atan2 (y - data[2].point.y,
-							       x - data[2].point.x);
-					else
-						angle = atan2 (y - prev_y, x - prev_x);
-				} else if (data->header.type == CAIRO_PATH_MOVE_TO) {
-					marker = marker_start;
-					if (next_type == CAIRO_PATH_CURVE_TO)
-						angle = atan2 (data[1].point.y - y,
-							       data[1].point.x - x);
-					else
-						angle = atan2 (next_y - y, next_x - x);
-				} else {
-					double xdifin, ydifin, xdifout, ydifout, intot, outtot;
-
-					marker = marker_mid;
-
-					if (type == CAIRO_PATH_CURVE_TO) {
-						xdifin = x - data[2].point.x;
-						ydifin = y - data[2].point.y;
-					} else {
-						xdifin = x - prev_x;
-						ydifin = y - prev_y;
-					}
-					if (next_type == CAIRO_PATH_CURVE_TO) {
-						xdifout = data[3].point.x - x;
-						ydifout = data[3].point.y - y;
-					} else {
-						xdifout = next_x - x;
-						ydifout = next_y - y;
-					}
-
-					intot = sqrt (xdifin * xdifin + ydifin * ydifin);
-					outtot = sqrt (xdifout * xdifout + ydifout * ydifout);
-
-					xdifin /= intot;
-					ydifin /= intot;
-					xdifout /= outtot;
-					ydifout /= outtot;
-
-					angle = atan2 ((ydifin + ydifout) / 2, (xdifin + xdifout) / 2);
-				}
-
-				if (marker != NULL) {
-					cairo_save (cairo);
-					cairo_translate (cairo, x, y);
-					lsm_svg_marker_element_render (LSM_SVG_MARKER_ELEMENT (marker), view,
-								       stroke_width, angle);
-					cairo_restore (cairo);
-				}
-			}
-
-			cairo_path_destroy (path);
-		}
-	} else
-		cairo_new_path (cairo);
+	cairo_new_path (cairo);
 
 	if (use_group) {
 		cairo_pop_group_to_source (cairo);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]