[lasem] svg: add support for viewport-fill and viewport-opacity.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] svg: add support for viewport-fill and viewport-opacity.
- Date: Sat, 27 Oct 2012 16:28:54 +0000 (UTC)
commit f029b67613231181a09ab29b9bbe295992f8f404
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sat Oct 27 18:28:30 2012 +0200
svg: add support for viewport-fill and viewport-opacity.
src/lsmsvgimageelement.c | 2 +
src/lsmsvgstyle.c | 12 +++++++
src/lsmsvgstyle.h | 2 +
src/lsmsvgsvgelement.c | 2 +
src/lsmsvgview.c | 32 ++++++++++++++++++++
src/lsmsvgview.h | 1 +
tests/data/svg/suite/fill/fillrule-evenodd-ref.png | Bin 0 -> 6582 bytes
tests/data/svg/suite/fill/fillrule-evenodd.png | Bin 6568 -> 0 bytes
.../svg/suite/fill/viewport-aspect-ratio-ref.png | Bin 0 -> 413 bytes
.../data/svg/suite/fill/viewport-aspect-ratio.svg | 14 ++++++++
tests/data/svg/suite/fill/viewport-fill-ref.png | Bin 0 -> 377 bytes
tests/data/svg/suite/fill/viewport-fill.svg | 12 +++++++
12 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/src/lsmsvgimageelement.c b/src/lsmsvgimageelement.c
index ed4546d..ddba7db 100644
--- a/src/lsmsvgimageelement.c
+++ b/src/lsmsvgimageelement.c
@@ -122,6 +122,8 @@ lsm_svg_image_element_render (LsmSvgElement *self, LsmSvgView *view)
viewbox.width = gdk_pixbuf_get_width (image->pixbuf);
viewbox.height = gdk_pixbuf_get_height (image->pixbuf);
+ lsm_svg_view_show_viewport (view, &viewport);
+
lsm_svg_view_push_viewport (view, &viewport, &viewbox, &image->preserve_aspect_ratio.value, LSM_SVG_OVERFLOW_HIDDEN);
lsm_svg_view_show_pixbuf (view, image->pixbuf);
diff --git a/src/lsmsvgstyle.c b/src/lsmsvgstyle.c
index 1fb7ce1..d928d5e 100644
--- a/src/lsmsvgstyle.c
+++ b/src/lsmsvgstyle.c
@@ -205,6 +205,18 @@ static const LsmPropertyInfos lsm_svg_property_infos[] = {
.trait_default = "nonzero"
},
{
+ .name = "viewport-fill",
+ .id = LSM_PROPERTY_OFFSET_TO_ID (LsmSvgStyle, viewport_fill),
+ .trait_class = &lsm_svg_paint_trait_class,
+ .trait_default = "none"
+ },
+ {
+ .name = "viewport-opacity",
+ .id = LSM_PROPERTY_OFFSET_TO_ID (LsmSvgStyle, viewport_opacity),
+ .trait_class = &lsm_double_trait_class,
+ .trait_default = "1"
+ },
+ {
.name = "font",
.id = LSM_PROPERTY_OFFSET_TO_ID (LsmSvgStyle, font),
.trait_class = &lsm_null_trait_class,
diff --git a/src/lsmsvgstyle.h b/src/lsmsvgstyle.h
index f29a079..3ae926d 100644
--- a/src/lsmsvgstyle.h
+++ b/src/lsmsvgstyle.h
@@ -154,6 +154,8 @@ struct _LsmSvgStyle {
LsmSvgPaintProperty * fill;
LsmSvgDoubleProperty * fill_opacity;
LsmSvgFillRuleProperty * fill_rule;
+ LsmSvgPaintProperty * viewport_fill;
+ LsmSvgDoubleProperty * viewport_opacity;
LsmProperty * font;
LsmProperty * font_family;
LsmSvgLengthProperty * font_size;
diff --git a/src/lsmsvgsvgelement.c b/src/lsmsvgsvgelement.c
index 62f9a4b..d06a625 100644
--- a/src/lsmsvgsvgelement.c
+++ b/src/lsmsvgsvgelement.c
@@ -139,6 +139,8 @@ _svg_element_render (LsmSvgElement *self, LsmSvgView *view)
lsm_debug_render ("[LsmSvgSvgElement::render] viewport %g, %g, %g, %g",
viewport.x, viewport.y, viewport.width, viewport.height);
+ lsm_svg_view_show_viewport (view, &viewport);
+
lsm_svg_view_push_viewport (view, &viewport, is_viewbox_defined ? &svg->viewbox.value : NULL,
&svg->preserve_aspect_ratio.value, LSM_SVG_OVERFLOW_HIDDEN);
diff --git a/src/lsmsvgview.c b/src/lsmsvgview.c
index 006a548..f72123a 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -779,6 +779,38 @@ process_path (LsmSvgView *view, LsmSvgViewPathInfos *path_infos)
paint (view, path_infos);
}
+void
+lsm_svg_view_show_viewport (LsmSvgView*view, const LsmBox *viewport)
+{
+ LsmSvgPaint *paint;
+
+ g_return_if_fail (LSM_IS_SVG_VIEW (view));
+ g_return_if_fail (viewport != NULL);
+
+ paint = &view->style->viewport_fill->paint;
+
+ switch (paint->type) {
+ case LSM_SVG_PAINT_TYPE_RGB_COLOR:
+ cairo_set_source_rgba (view->dom_view.cairo,
+ paint->color.red,
+ paint->color.green,
+ paint->color.blue,
+ view->style->viewport_opacity->value);
+ break;
+ case LSM_SVG_PAINT_TYPE_CURRENT_COLOR:
+ cairo_set_source_rgba (view->dom_view.cairo,
+ view->style->color->value.red,
+ view->style->color->value.green,
+ view->style->color->value.blue,
+ view->style->viewport_opacity->value);
+ default:
+ return;
+ }
+
+ cairo_rectangle (view->dom_view.cairo, viewport->x, viewport->y, 0, 0);
+ cairo_paint (view->dom_view.cairo);
+}
+
/*
* Code for show_rectangle and show ellipse is inspired from
* the librsvg library (rsvg-shapes.c)
diff --git a/src/lsmsvgview.h b/src/lsmsvgview.h
index 2b9a8ef..23de59b 100644
--- a/src/lsmsvgview.h
+++ b/src/lsmsvgview.h
@@ -114,6 +114,7 @@ G_GNUC_WARN_UNUSED_RESULT gboolean
const LsmSvgMatrix *matrix,
LsmSvgViewSurfaceType surface_type) G_GNUC_WARN_UNUSED_RESULT;
+void lsm_svg_view_show_viewport (LsmSvgView*view, const LsmBox *viewport);
void lsm_svg_view_show_rectangle (LsmSvgView *view, double x, double y,
double width, double height,
double rx, double ry);
diff --git a/tests/data/svg/suite/fill/fillrule-evenodd-ref.png b/tests/data/svg/suite/fill/fillrule-evenodd-ref.png
new file mode 100644
index 0000000..94de0e2
Binary files /dev/null and b/tests/data/svg/suite/fill/fillrule-evenodd-ref.png differ
diff --git a/tests/data/svg/suite/fill/viewport-aspect-ratio-ref.png b/tests/data/svg/suite/fill/viewport-aspect-ratio-ref.png
new file mode 100644
index 0000000..d157442
Binary files /dev/null and b/tests/data/svg/suite/fill/viewport-aspect-ratio-ref.png differ
diff --git a/tests/data/svg/suite/fill/viewport-aspect-ratio.svg b/tests/data/svg/suite/fill/viewport-aspect-ratio.svg
new file mode 100644
index 0000000..26b5ace
--- /dev/null
+++ b/tests/data/svg/suite/fill/viewport-aspect-ratio.svg
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
+ width="100" height="100" viewBox="0 0 300 100" viewport-fill="yellow">
+
+ <desc>
+ The viewport has a yellow background.
+ The rectangle is filled and covers the viewport, so the yellow
+ background will only show through in the "leftovers" if the
+ aspect ratio of the viewport differs from that of the viewBox.
+ </desc>
+
+ <rect x="0" y="0" width="300" height="100" fill="red" fill-opacity="0.3" stroke="black"/>
+
+</svg>
diff --git a/tests/data/svg/suite/fill/viewport-fill-ref.png b/tests/data/svg/suite/fill/viewport-fill-ref.png
new file mode 100644
index 0000000..a12c4fd
Binary files /dev/null and b/tests/data/svg/suite/fill/viewport-fill-ref.png differ
diff --git a/tests/data/svg/suite/fill/viewport-fill.svg b/tests/data/svg/suite/fill/viewport-fill.svg
new file mode 100644
index 0000000..11c0703
--- /dev/null
+++ b/tests/data/svg/suite/fill/viewport-fill.svg
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
+ viewport-fill="red" height="100" width="100">
+
+ <desc>
+ Everything here has a red background.
+ The rectangle is not filled, so the red background will show through.
+ </desc>
+
+ <rect x="10.5" y="10.5" width="80" height="80" fill="none" stroke="black"/>
+
+</svg>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]