[lasem/wip/emmanuel/extents: 1/2] wip: get_extents implementation



commit ecd913044364a94960961341c8f5ae1c709948dd
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Jul 4 14:54:12 2016 +0200

    wip: get_extents implementation
    
    A lot more work is needed !

 src/lsmdomview.c                |   34 +++++++++++++++++-
 src/lsmdomview.h                |   11 +++++-
 src/lsmmathmlview.c             |    8 ++++-
 src/lsmsvgsvgelement.c          |   13 +++++--
 src/lsmsvgsvgelement.h          |    5 ++-
 src/lsmsvgview.c                |    5 ++-
 tests/Makefile.am               |    5 ++-
 tests/data/svg/extents/rect.svg |    4 ++
 tests/extents.c                 |   75 +++++++++++++++++++++++++++++++++++++++
 9 files changed, 148 insertions(+), 12 deletions(-)
---
diff --git a/src/lsmdomview.c b/src/lsmdomview.c
index ed0d03f..ed99b01 100644
--- a/src/lsmdomview.c
+++ b/src/lsmdomview.c
@@ -169,7 +169,7 @@ lsm_dom_view_get_size (LsmDomView *view, double *width, double *height, double *
 
        view_class = LSM_DOM_VIEW_GET_CLASS (view);
        if (view_class->measure != NULL)
-               view_class->measure (view, width, height, baseline);
+               view_class->measure (view, LSM_DOM_VIEW_MEASUREMENT_VIEWPORT, NULL, NULL, width, height, 
baseline);
 }
 
 /**
@@ -210,6 +210,38 @@ lsm_dom_view_get_size_pixels (LsmDomView *view, unsigned int *width, unsigned in
                *baseline = (double) (0.5 + baseline_pt * resolution_ppi / 72.0);
 }
 
+void
+lsm_dom_view_get_extents (LsmDomView *view, double *x, double *y, double *width, double *height)
+{
+       LsmDomViewClass *view_class;
+       double dummy_x = 0.0;
+       double dummy_y = 0.0;
+       double dummy_width = 0.0;
+       double dummy_height = 0.0;
+       double baseline;
+
+       g_return_if_fail (LSM_IS_DOM_VIEW (view));
+       g_return_if_fail (view->document != NULL);
+
+       if (width == NULL)
+               width = &dummy_width;
+       if (height == NULL)
+               height = &dummy_height;
+       if (x == NULL)
+               x = &dummy_x;
+       if (y == NULL)
+               y = &dummy_y;
+
+       view_class = LSM_DOM_VIEW_GET_CLASS (view);
+       if (view_class->measure != NULL)
+               view_class->measure (view, LSM_DOM_VIEW_MEASUREMENT_EXTENTS, x, y, width, height, &baseline);
+}
+
+void
+lsm_dom_view_get_extents_pixels        (LsmDomView *view, unsigned *x, unsigned *y, unsigned *width, 
unsigned *height)
+{
+}
+
 static void
 lsm_dom_view_set_cairo_context (LsmDomView *view, cairo_t *cairo)
 {
diff --git a/src/lsmdomview.h b/src/lsmdomview.h
index f89a8ef..b5fc88d 100644
--- a/src/lsmdomview.h
+++ b/src/lsmdomview.h
@@ -31,6 +31,11 @@
 
 G_BEGIN_DECLS
 
+typedef enum {
+       LSM_DOM_VIEW_MEASUREMENT_VIEWPORT,
+       LSM_DOM_VIEW_MEASUREMENT_EXTENTS
+} LsmDomViewMeasurement;
+
 #define LSM_DOM_VIEW_DEFAULT_RESOLUTION         72.0
 #define LSM_DOM_VIEW_DEFAULT_VIEWBOX_WIDTH     320.0
 #define LSM_DOM_VIEW_DEFAULT_VIEWBOX_HEIGHT    200.0
@@ -64,7 +69,8 @@ struct _LsmDomViewClass {
 
        GType document_type;
 
-       void (*measure)         (LsmDomView *view, double *width, double *height, double *baseline);
+       void (*measure)         (LsmDomView *view, LsmDomViewMeasurement measurement,
+                                double *x, double *y, double *width, double *height, double *baseline);
        void (*render)          (LsmDomView *view);
        void (*set_debug)       (LsmDomView *view, const char *feature, gboolean enable);
 };
@@ -85,6 +91,9 @@ void          lsm_dom_view_get_size           (LsmDomView *view, double *width, double 
*height, d
 void           lsm_dom_view_get_size_pixels    (LsmDomView *view, unsigned int *width, unsigned int *height,
                                                 unsigned int *baseline);
 
+void           lsm_dom_view_get_extents        (LsmDomView *view, double *x, double *y, double *width, 
double *height);
+void           lsm_dom_view_get_extents_pixels (LsmDomView *view, unsigned *x, unsigned *y, unsigned *width, 
unsigned *height);
+
 void           lsm_dom_view_set_debug          (LsmDomView *view, const char *feature, gboolean enable);
 
 void           lsm_dom_view_set_document       (LsmDomView *view, LsmDomDocument *document);
diff --git a/src/lsmmathmlview.c b/src/lsmmathmlview.c
index 471d3f2..cfa5e5b 100644
--- a/src/lsmmathmlview.c
+++ b/src/lsmmathmlview.c
@@ -1249,9 +1249,15 @@ _view_measure (LsmMathmlView *view, double *width, double *height, double *basel
 }
 
 static void
-lsm_mathml_view_measure (LsmDomView *dom_view, double *width, double *height, double *baseline)
+lsm_mathml_view_measure (LsmDomView *dom_view, LsmDomViewMeasurement measurement, 
+                        double *x, double *y, double *width, double *height, double *baseline)
 {
        _view_measure (LSM_MATHML_VIEW (dom_view), width, height, baseline);
+
+       if (x != NULL)
+               *x = 0.0;
+       if (y != NULL)
+               *y = 0.0;
 }
 
 static void
diff --git a/src/lsmsvgsvgelement.c b/src/lsmsvgsvgelement.c
index a87d754..29597a5 100644
--- a/src/lsmsvgsvgelement.c
+++ b/src/lsmsvgsvgelement.c
@@ -42,7 +42,8 @@ lsm_svg_svg_element_get_node_name (LsmDomNode *node)
 /* LsmSvgElement implementation */
 
 void
-lsm_svg_svg_element_measure (LsmSvgSvgElement *self, LsmSvgView *view, double *width, double *height)
+lsm_svg_svg_element_measure (LsmSvgSvgElement *self, LsmSvgView *view, LsmDomViewMeasurement measurement,
+                            double *x, double *y, double *width, double *height)
 {
        LsmSvgViewbox *svg_viewbox;
        LsmBox viewport;
@@ -78,7 +79,7 @@ lsm_svg_svg_element_measure (LsmSvgSvgElement *self, LsmSvgView *view, double *w
 
        if (lsm_attribute_is_defined (&self->width.base))
                svg_width = lsm_svg_length_normalize (&self->width.length, svg_viewbox,
-                                                      font_size, LSM_SVG_LENGTH_DIRECTION_HORIZONTAL);
+                                                     font_size, LSM_SVG_LENGTH_DIRECTION_HORIZONTAL);
        else
                svg_width = viewport.width;
 
@@ -99,9 +100,13 @@ lsm_svg_svg_element_measure (LsmSvgSvgElement *self, LsmSvgView *view, double *w
        self->svg_box.height = svg_height;
 
        lsm_debug_measure ("[LsmSvgSvgElement::measure] Size = %g, %g, %g, %g",
-                  svg_x, svg_y, svg_width, svg_height);
-
+                          svg_x, svg_y, svg_width, svg_height);
        lsm_svg_viewbox_free (svg_viewbox);
+
+       if (x != NULL)
+               *x = 0.0;
+       if (y != NULL)
+               *y = 0.0;
 }
 
 /* LsmSvgGraphic implementation */
diff --git a/src/lsmsvgsvgelement.h b/src/lsmsvgsvgelement.h
index 992b3fb..2b4cc68 100644
--- a/src/lsmsvgsvgelement.h
+++ b/src/lsmsvgsvgelement.h
@@ -62,8 +62,9 @@ GType lsm_svg_svg_element_get_type (void);
 
 LsmDomNode *           lsm_svg_svg_element_new                 (void);
 
-void                   lsm_svg_svg_element_measure             (LsmSvgSvgElement *self,
-                                                                LsmSvgView *view, double *width, double 
*height);
+void                   lsm_svg_svg_element_measure             (LsmSvgSvgElement *self, LsmSvgView *view,
+                                                                LsmDomViewMeasurement measurement,
+                                                                double *x, double *y, double *width, double 
*height);
 void                   lsm_svg_svg_element_render              (LsmSvgSvgElement *svg_element, LsmSvgView 
*view);
 
 G_END_DECLS
diff --git a/src/lsmsvgview.c b/src/lsmsvgview.c
index 607a84d..ab6d22e 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -2657,7 +2657,8 @@ lsm_svg_view_get_clip_extents (LsmSvgView *view)
 }
 
 static void
-lsm_svg_view_measure (LsmDomView *view, double *width, double *height, double *baseline)
+lsm_svg_view_measure (LsmDomView *view, LsmDomViewMeasurement measurement,
+                     double *x, double *y, double *width, double *height, double *baseline)
 {
        LsmSvgSvgElement *svg_element;
 
@@ -2665,7 +2666,7 @@ lsm_svg_view_measure (LsmDomView *view, double *width, double *height, double *b
        if (svg_element == NULL)
                return;
 
-       lsm_svg_svg_element_measure (svg_element, LSM_SVG_VIEW (view), width, height);
+       lsm_svg_svg_element_measure (svg_element, LSM_SVG_VIEW (view), measurement, x, y, width, height);
        if (baseline)
                *baseline = *height;
 }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 308962b..f99e5b1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,7 +14,7 @@ noinst_PROGRAMS = lsm-test
 lsm_test_SOURCES = lsmtest.c
 lsm_test_LDADD = $(test_progs_ldadd)
 
-TEST_PROGS += dom str filter suite
+TEST_PROGS += dom str filter suite extents
 
 noinst_PROGRAMS += $(TEST_PROGS)
 
@@ -27,6 +27,9 @@ dom_LDADD = $(test_progs_ldadd)
 filter_SOURCES = filter.c
 filter_LDADD = $(test_progs_ldadd)
 
+extents_SOURCES = extents.c
+extents_LDADD = $(test_progs_ldadd)
+
 suite_SOURCES = suite.c
 suite_LDADD = $(test_progs_ldadd)
 suite_CFLAGS = -DSUITE_DATA_DIRECTORY="\"$(top_srcdir)/tests/data\"" 
-DSUITE_OPTION_FILE="\"$(top_srcdir)/tests/suite.ini\""
diff --git a/tests/data/svg/extents/rect.svg b/tests/data/svg/extents/rect.svg
new file mode 100644
index 0000000..4563204
--- /dev/null
+++ b/tests/data/svg/extents/rect.svg
@@ -0,0 +1,4 @@
+<!-- Exercize of clipping of <use> content with default width and height attributes (100%). --> 
+<svg xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/xlink"; width="40" height="40">
+       <rect x="10" y="10" width="10" height="10">
+</svg>
diff --git a/tests/extents.c b/tests/extents.c
new file mode 100644
index 0000000..fcd91a6
--- /dev/null
+++ b/tests/extents.c
@@ -0,0 +1,75 @@
+#include <lsm.h>
+#include <lsmdom.h>
+
+typedef struct {
+       const char *name;
+       const char *filename;
+       double x;
+       double y;
+       double width;
+       double height;
+} ObjectsData;
+
+ObjectsData objects_data[] = {
+       {"/extents/rect",       "rect.svg",     10.0, 10.0, 10.0, 10.0}
+}; 
+
+static void
+objects (ObjectsData *data)
+{
+       LsmDomDocument *document;
+       LsmDomView *view;
+       char *filename;
+       double x, y, width, height;
+       LsmBox viewport;
+
+       filename = g_build_filename ("data", "svg", "extents", data->filename, NULL);
+       document = lsm_dom_document_new_from_path (filename, NULL);
+       g_free (filename);
+       g_assert (LSM_IS_DOM_DOCUMENT (document));
+
+       view = lsm_dom_document_create_view (document);
+       g_assert (LSM_IS_DOM_VIEW (view));
+
+       viewport.x = 0.0;
+       viewport.y = 0.0;
+       viewport.width = 480.0;
+       viewport.height = 360.0;
+
+       lsm_dom_view_set_resolution (view, 96);
+       lsm_dom_view_set_viewport_pixels (view, &viewport);
+
+       lsm_dom_view_get_extents (view, &x, &y, &width, &height);
+       g_assert_cmpfloat (x, ==, data->x);
+       g_assert_cmpfloat (y, ==, data->y);
+       g_assert_cmpfloat (width, ==, data->width);
+       g_assert_cmpfloat (height, ==, data->height);
+
+       g_object_unref (view);
+       g_object_unref (document);
+}
+
+int
+main (int argc, char *argv[])
+{
+       int result;
+       unsigned i;
+
+       g_test_init (&argc, &argv, NULL);
+
+#if !GLIB_CHECK_VERSION(2,36,0)
+       g_type_init ();
+#endif
+
+       for (i = 0; i < G_N_ELEMENTS (objects_data); i++)
+               g_test_add_data_func (objects_data[i].name,
+                                     &objects_data[i],
+                                     (void *) objects);
+
+       result = g_test_run ();
+
+       lsm_shutdown ();
+
+       return result;
+}
+


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