[lasem] dom_view: move resolution and viewport function to dom_view.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] dom_view: move resolution and viewport function to dom_view.
- Date: Wed, 12 Oct 2011 18:13:35 +0000 (UTC)
commit 505280800302cee3b687dd5a92bda352d3800198
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Wed Oct 12 20:11:40 2011 +0200
dom_view: move resolution and viewport function to dom_view.
Instead of dom_document.
docs/reference/lasem/lasem-sections.txt | 18 ++++----
src/lasemrender.c | 3 +-
src/lsmdomdocument.c | 71 -----------------------------
src/lsmdomdocument.h | 15 ------
src/lsmdomview.c | 76 +++++++++++++++++++++++++++++--
src/lsmdomview.h | 26 +++++++++--
src/lsmmathmlview.c | 2 +-
src/lsmsvgsvgelement.c | 10 +---
src/lsmsvgsvgelement.h | 3 +-
src/lsmsvgview.c | 4 +-
tests/lsmtest.c | 4 +-
tests/suite.c | 5 +-
12 files changed, 117 insertions(+), 120 deletions(-)
---
diff --git a/docs/reference/lasem/lasem-sections.txt b/docs/reference/lasem/lasem-sections.txt
index b1c9470..14dd85c 100644
--- a/docs/reference/lasem/lasem-sections.txt
+++ b/docs/reference/lasem/lasem-sections.txt
@@ -90,9 +90,6 @@ lsm_dom_named_node_map_get_type
<SECTION>
<FILE>lsmdomdocument</FILE>
<TITLE>LsmDomDocument</TITLE>
-LSM_DOM_DOCUMENT_DEFAULT_RESOLUTION
-LSM_DOM_DOCUMENT_DEFAULT_VIEWBOX_WIDTH
-LSM_DOM_DOCUMENT_DEFAULT_VIEWBOX_HEIGHT
LsmDomDocument
LsmDomDocumentCreateFunction
lsm_dom_implementation_create_document
@@ -111,12 +108,6 @@ lsm_dom_document_create_text_node
lsm_dom_document_get_element_by_id
lsm_dom_document_register_element
lsm_dom_document_create_view
-lsm_dom_document_get_resolution
-lsm_dom_document_set_resolution
-lsm_dom_document_set_viewport
-lsm_dom_document_set_viewport_px
-lsm_dom_document_get_viewport
-lsm_dom_document_get_viewport_px
lsm_dom_document_get_url
lsm_dom_document_set_url
lsm_dom_document_set_path
@@ -171,7 +162,16 @@ LSM_DOM_ELEMENT_GET_CLASS
<SECTION>
<FILE>lsmdomview</FILE>
<TITLE>LsmDomView</TITLE>
+LSM_DOM_VIEW_DEFAULT_RESOLUTION
+LSM_DOM_VIEW_DEFAULT_VIEWBOX_HEIGHT
+LSM_DOM_VIEW_DEFAULT_VIEWBOX_WIDTH
LsmDomView
+lsm_dom_view_get_resolution
+lsm_dom_view_get_viewport
+lsm_dom_view_get_viewport_pixels
+lsm_dom_view_set_resolution
+lsm_dom_view_set_viewport
+lsm_dom_view_set_viewport_pixels
lsm_dom_view_render
lsm_dom_view_get_size
lsm_dom_view_get_size_pixels
diff --git a/src/lasemrender.c b/src/lasemrender.c
index ae55d78..4847507 100644
--- a/src/lasemrender.c
+++ b/src/lasemrender.c
@@ -180,9 +180,8 @@ int main(int argc, char **argv)
}
}
- lsm_dom_document_set_resolution (document, option_ppi);
-
view = lsm_dom_document_create_view (document);
+ lsm_dom_view_set_resolution (view, option_ppi);
width_pt = 2.0;
height_pt = 2.0;
diff --git a/src/lsmdomdocument.c b/src/lsmdomdocument.c
index a1efc50..50a8f23 100644
--- a/src/lsmdomdocument.c
+++ b/src/lsmdomdocument.c
@@ -96,71 +96,6 @@ lsm_dom_document_create_view (LsmDomDocument *self)
return LSM_DOM_DOCUMENT_GET_CLASS (self)->create_view (self);
}
-double
-lsm_dom_document_get_resolution (LsmDomDocument *self)
-{
- g_return_val_if_fail (LSM_IS_DOM_DOCUMENT (self), 0.0);
-
- return self->resolution_ppi;
-}
-
-void
-lsm_dom_document_set_resolution (LsmDomDocument *self, double ppi)
-{
- g_return_if_fail (LSM_IS_DOM_DOCUMENT (self));
-
- if (ppi < 0.0)
- self->resolution_ppi = LSM_DOM_DOCUMENT_DEFAULT_RESOLUTION;
- else
- self->resolution_ppi = ppi;
-}
-
-void
-lsm_dom_document_set_viewport (LsmDomDocument *self, const LsmBox *viewport_pt)
-{
- g_return_if_fail (LSM_IS_DOM_DOCUMENT (self));
- g_return_if_fail (viewport_pt != NULL);
-
- self->viewport_pt = *viewport_pt;
-}
-
-void
-lsm_dom_document_set_viewport_px (LsmDomDocument *self, const LsmBox *viewport)
-{
- g_return_if_fail (LSM_IS_DOM_DOCUMENT (self));
- g_return_if_fail (viewport != NULL);
-
- self->viewport_pt.x = viewport->x * 72.0 / self->resolution_ppi;
- self->viewport_pt.y = viewport->y * 72.0 / self->resolution_ppi;
- self->viewport_pt.width = viewport->width * 72.0 / self->resolution_ppi;
- self->viewport_pt.height = viewport->height * 72.0 / self->resolution_ppi;
-}
-
-LsmBox
-lsm_dom_document_get_viewport (LsmDomDocument *self)
-{
- static const LsmBox null_viewport = {0, 0, 0, 0};
-
- g_return_val_if_fail (LSM_IS_DOM_DOCUMENT (self), null_viewport);
-
- return self->viewport_pt;
-}
-
-LsmBox
-lsm_dom_document_get_viewport_px (LsmDomDocument *self)
-{
- LsmBox viewport = {0, 0, 0, 0};
-
- g_return_val_if_fail (LSM_IS_DOM_DOCUMENT (self), viewport);
-
- viewport.x = self->viewport_pt.x * self->resolution_ppi / 72.0;
- viewport.y = self->viewport_pt.y * self->resolution_ppi / 72.0;
- viewport.width = self->viewport_pt.width * self->resolution_ppi / 72.0;
- viewport.height = self->viewport_pt.height * self->resolution_ppi / 72.0;
-
- return viewport;
-}
-
LsmDomElement *
lsm_dom_document_get_element_by_id (LsmDomDocument *self, const char *id)
{
@@ -272,12 +207,6 @@ lsm_dom_document_init (LsmDomDocument *document)
{
document->ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
document->elements = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL);
-
- document->resolution_ppi = LSM_DOM_DOCUMENT_DEFAULT_RESOLUTION;
- document->viewport_pt.x = 0;
- document->viewport_pt.y = 0;
- document->viewport_pt.width = LSM_DOM_DOCUMENT_DEFAULT_VIEWBOX_WIDTH;
- document->viewport_pt.height = LSM_DOM_DOCUMENT_DEFAULT_VIEWBOX_HEIGHT;
}
static void
diff --git a/src/lsmdomdocument.h b/src/lsmdomdocument.h
index 2480e9e..f6566c0 100644
--- a/src/lsmdomdocument.h
+++ b/src/lsmdomdocument.h
@@ -31,10 +31,6 @@
G_BEGIN_DECLS
-#define LSM_DOM_DOCUMENT_DEFAULT_RESOLUTION 72.0
-#define LSM_DOM_DOCUMENT_DEFAULT_VIEWBOX_WIDTH 320.0
-#define LSM_DOM_DOCUMENT_DEFAULT_VIEWBOX_HEIGHT 200.0
-
#define LSM_TYPE_DOM_DOCUMENT (lsm_dom_document_get_type ())
#define LSM_DOM_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_DOM_DOCUMENT, LsmDomDocument))
#define LSM_DOM_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_DOM_DOCUMENT, LsmDomDocumentClass))
@@ -52,9 +48,6 @@ struct _LsmDomDocument {
char * url;
- /* Not really a document property, but that simplifies things greatly */
- double resolution_ppi;
- LsmBox viewport_pt;
};
struct _LsmDomDocumentClass {
@@ -78,14 +71,6 @@ void lsm_dom_document_register_element (LsmDomDocument *self, LsmDomElement *
LsmDomView* lsm_dom_document_create_view (LsmDomDocument *self);
-double lsm_dom_document_get_resolution (LsmDomDocument *self);
-void lsm_dom_document_set_resolution (LsmDomDocument *self, double ppi);
-
-void lsm_dom_document_set_viewport (LsmDomDocument *self, const LsmBox *viewport);
-void lsm_dom_document_set_viewport_px (LsmDomDocument *self, const LsmBox *viewport);
-LsmBox lsm_dom_document_get_viewport (LsmDomDocument *self);
-LsmBox lsm_dom_document_get_viewport_px (LsmDomDocument *self);
-
const char * lsm_dom_document_get_url (LsmDomDocument *self);
void lsm_dom_document_set_url (LsmDomDocument *self, const char *url);
void lsm_dom_document_set_path (LsmDomDocument *self, const char *path);
diff --git a/src/lsmdomview.c b/src/lsmdomview.c
index 63dd27f..c35ec75 100644
--- a/src/lsmdomview.c
+++ b/src/lsmdomview.c
@@ -32,6 +32,71 @@
static GObjectClass *parent_class;
+double
+lsm_dom_view_get_resolution (LsmDomView *self)
+{
+ g_return_val_if_fail (LSM_IS_DOM_VIEW (self), 0.0);
+
+ return self->resolution_ppi;
+}
+
+void
+lsm_dom_view_set_resolution (LsmDomView *self, double ppi)
+{
+ g_return_if_fail (LSM_IS_DOM_VIEW (self));
+
+ if (ppi < 0.0)
+ self->resolution_ppi = LSM_DOM_VIEW_DEFAULT_RESOLUTION;
+ else
+ self->resolution_ppi = ppi;
+}
+
+void
+lsm_dom_view_set_viewport (LsmDomView *self, const LsmBox *viewport_pt)
+{
+ g_return_if_fail (LSM_IS_DOM_VIEW (self));
+ g_return_if_fail (viewport_pt != NULL);
+
+ self->viewport_pt = *viewport_pt;
+}
+
+void
+lsm_dom_view_set_viewport_pixels (LsmDomView *self, const LsmBox *viewport)
+{
+ g_return_if_fail (LSM_IS_DOM_VIEW (self));
+ g_return_if_fail (viewport != NULL);
+
+ self->viewport_pt.x = viewport->x * 72.0 / self->resolution_ppi;
+ self->viewport_pt.y = viewport->y * 72.0 / self->resolution_ppi;
+ self->viewport_pt.width = viewport->width * 72.0 / self->resolution_ppi;
+ self->viewport_pt.height = viewport->height * 72.0 / self->resolution_ppi;
+}
+
+LsmBox
+lsm_dom_view_get_viewport (LsmDomView *self)
+{
+ static const LsmBox null_viewport = {0, 0, 0, 0};
+
+ g_return_val_if_fail (LSM_IS_DOM_VIEW (self), null_viewport);
+
+ return self->viewport_pt;
+}
+
+LsmBox
+lsm_dom_view_get_viewport_pixels (LsmDomView *self)
+{
+ LsmBox viewport = {0, 0, 0, 0};
+
+ g_return_val_if_fail (LSM_IS_DOM_VIEW (self), viewport);
+
+ viewport.x = self->viewport_pt.x * self->resolution_ppi / 72.0;
+ viewport.y = self->viewport_pt.y * self->resolution_ppi / 72.0;
+ viewport.width = self->viewport_pt.width * self->resolution_ppi / 72.0;
+ viewport.height = self->viewport_pt.height * self->resolution_ppi / 72.0;
+
+ return viewport;
+}
+
void
lsm_dom_view_get_size (LsmDomView *view, double *width, double *height, double *baseline)
{
@@ -63,7 +128,7 @@ lsm_dom_view_get_size_pixels (LsmDomView *view, unsigned int *width, unsigned in
g_return_if_fail (LSM_IS_DOM_VIEW (view));
g_return_if_fail (view->document != NULL);
- resolution_ppi = lsm_dom_document_get_resolution (view->document);
+ resolution_ppi = view->resolution_ppi;
g_return_if_fail (resolution_ppi > 0.0);
width_pt = width != NULL ? *width * 72.0 / resolution_ppi : 0.0;
@@ -138,7 +203,6 @@ void
lsm_dom_view_render (LsmDomView *view, cairo_t *cairo, double x, double y)
{
LsmDomViewClass *view_class;
- double resolution_ppi;
g_return_if_fail (LSM_IS_DOM_VIEW (view));
g_return_if_fail (LSM_IS_DOM_DOCUMENT (view->document));
@@ -146,8 +210,6 @@ lsm_dom_view_render (LsmDomView *view, cairo_t *cairo, double x, double y)
lsm_dom_view_set_cairo_context (view, cairo);
- resolution_ppi = lsm_dom_document_get_resolution (view->document);
-
cairo_save (view->cairo);
cairo_translate (view->cairo, x, y);
@@ -189,6 +251,12 @@ lsm_dom_view_init (LsmDomView *view)
PangoContext *pango_context;
cairo_font_options_t *font_options;
+ view->resolution_ppi = LSM_DOM_VIEW_DEFAULT_RESOLUTION;
+ view->viewport_pt.x = 0;
+ view->viewport_pt.y = 0;
+ view->viewport_pt.width = LSM_DOM_VIEW_DEFAULT_VIEWBOX_WIDTH;
+ view->viewport_pt.height = LSM_DOM_VIEW_DEFAULT_VIEWBOX_HEIGHT;
+
view->font_description = pango_font_description_new ();
font_map = pango_cairo_font_map_get_default ();
diff --git a/src/lsmdomview.h b/src/lsmdomview.h
index da7fba6..73bd8af 100644
--- a/src/lsmdomview.h
+++ b/src/lsmdomview.h
@@ -25,11 +25,16 @@
#define LSM_DOM_VIEW_H
#include <lsmdomtypes.h>
+#include <lsmtypes.h>
#include <cairo.h>
#include <pango/pangocairo.h>
G_BEGIN_DECLS
+#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
+
#define LSM_TYPE_DOM_VIEW (lsm_dom_view_get_type ())
#define LSM_DOM_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LSM_TYPE_DOM_VIEW, LsmDomView))
#define LSM_DOM_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LSM_TYPE_DOM_VIEW, LsmDomViewClass))
@@ -49,6 +54,9 @@ struct _LsmDomView {
PangoLayout * measure_pango_layout;
cairo_t * cairo;
gboolean is_vector;
+
+ double resolution_ppi;
+ LsmBox viewport_pt;
};
struct _LsmDomViewClass {
@@ -62,11 +70,21 @@ struct _LsmDomViewClass {
GType lsm_dom_view_get_type (void);
-void lsm_dom_view_render (LsmDomView *view, cairo_t *cairo, double x, double y);
-void lsm_dom_view_get_size (LsmDomView *view, double *width, double *height, double *baseline);
-void lsm_dom_view_get_size_pixels (LsmDomView *view, unsigned int *width, unsigned int *height, unsigned int *baseline);
+double lsm_dom_view_get_resolution (LsmDomView *self);
+void lsm_dom_view_set_resolution (LsmDomView *self, double ppi);
+
+void lsm_dom_view_set_viewport (LsmDomView *self, const LsmBox *viewport);
+void lsm_dom_view_set_viewport_pixels(LsmDomView *self, const LsmBox *viewport);
+LsmBox lsm_dom_view_get_viewport (LsmDomView *self);
+LsmBox lsm_dom_view_get_viewport_pixels(LsmDomView *self);
+
+void lsm_dom_view_render (LsmDomView *view, cairo_t *cairo, double x, double y);
+
+void lsm_dom_view_get_size (LsmDomView *view, double *width, double *height, double *baseline);
+void lsm_dom_view_get_size_pixels (LsmDomView *view, unsigned int *width, unsigned int *height,
+ unsigned int *baseline);
-void lsm_dom_view_set_document (LsmDomView *view, LsmDomDocument *document);
+void lsm_dom_view_set_document (LsmDomView *view, LsmDomDocument *document);
G_END_DECLS
diff --git a/src/lsmmathmlview.c b/src/lsmmathmlview.c
index 44c1088..f3b790d 100644
--- a/src/lsmmathmlview.c
+++ b/src/lsmmathmlview.c
@@ -977,7 +977,7 @@ lsm_mathml_view_render (LsmDomView *dom_view)
if (math_element == NULL)
return;
- resolution_ppi = lsm_dom_document_get_resolution (view->dom_view.document);
+ resolution_ppi = lsm_dom_view_get_resolution (dom_view);
bbox = _view_measure (view, NULL, NULL, NULL);
diff --git a/src/lsmsvgsvgelement.c b/src/lsmsvgsvgelement.c
index 56bf168..fa7dd80 100644
--- a/src/lsmsvgsvgelement.c
+++ b/src/lsmsvgsvgelement.c
@@ -41,9 +41,8 @@ lsm_svg_svg_element_get_node_name (LsmDomNode *node)
/* LsmSvgElement implementation */
void
-lsm_svg_svg_element_measure (LsmSvgSvgElement *self, double *width, double *height)
+lsm_svg_svg_element_measure (LsmSvgSvgElement *self, LsmSvgView *view, double *width, double *height)
{
- LsmDomDocument *document;
LsmSvgViewbox *svg_viewbox;
LsmBox viewport;
gboolean is_outermost_svg;
@@ -56,11 +55,8 @@ lsm_svg_svg_element_measure (LsmSvgSvgElement *self, double *width, double *heig
g_return_if_fail (LSM_IS_SVG_SVG_ELEMENT (self));
- document = LSM_DOM_DOCUMENT (LSM_DOM_NODE (self)->parent_node);
- g_return_if_fail (LSM_IS_DOM_DOCUMENT (document));
-
- resolution_ppi = lsm_dom_document_get_resolution (document);
- viewport = lsm_dom_document_get_viewport_px (document);
+ resolution_ppi = lsm_dom_view_get_resolution (LSM_DOM_VIEW (view));
+ viewport = lsm_dom_view_get_viewport_pixels (LSM_DOM_VIEW (view));
svg_viewbox = lsm_svg_viewbox_new (resolution_ppi, &viewport);
font_size = 10 * resolution_ppi / 72.0;
diff --git a/src/lsmsvgsvgelement.h b/src/lsmsvgsvgelement.h
index 848e946..41a7592 100644
--- a/src/lsmsvgsvgelement.h
+++ b/src/lsmsvgsvgelement.h
@@ -61,7 +61,8 @@ GType lsm_svg_svg_element_get_type (void);
LsmDomNode * lsm_svg_svg_element_new (void);
-void lsm_svg_svg_element_measure (LsmSvgSvgElement *self, double *width, double *height);
+void lsm_svg_svg_element_measure (LsmSvgSvgElement *self,
+ LsmSvgView *view, 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 a2781d2..87be673 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -2055,7 +2055,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, width, height);
+ lsm_svg_svg_element_measure (svg_element, LSM_SVG_VIEW (view), width, height);
if (baseline)
*baseline = *height;
}
@@ -2082,7 +2082,7 @@ lsm_svg_view_render (LsmDomView *view)
svg_view->is_pango_layout_in_use = FALSE;
svg_view->pango_layout = view->pango_layout;
- svg_view->resolution_ppi = lsm_dom_document_get_resolution (view->document);
+ svg_view->resolution_ppi = lsm_dom_view_get_resolution (view);
lsm_svg_svg_element_render (svg_element, svg_view);
diff --git a/tests/lsmtest.c b/tests/lsmtest.c
index 48ab51d..dc473b4 100644
--- a/tests/lsmtest.c
+++ b/tests/lsmtest.c
@@ -133,8 +133,8 @@ lasem_test_render (char const *filename)
viewport.width = 480.0;
viewport.height = 360.0;
- lsm_dom_document_set_resolution (document, option_ppi);
- lsm_dom_document_set_viewport_px (document, &viewport);
+ lsm_dom_view_set_resolution (view, option_ppi);
+ lsm_dom_view_set_viewport_pixels (view, &viewport);
lsm_dom_view_get_size_pixels (LSM_DOM_VIEW (view), &width, &height, NULL);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width + 2, height + 2);
diff --git a/tests/suite.c b/tests/suite.c
index 4305c84..1c97745 100644
--- a/tests/suite.c
+++ b/tests/suite.c
@@ -65,8 +65,9 @@ render_test (gconstpointer user_data)
viewport.width = 480.0;
viewport.height = 360.0;
- lsm_dom_document_set_resolution (document, 96);
- lsm_dom_document_set_viewport_px (document, &viewport);
+ lsm_dom_view_set_resolution (view, 96);
+ lsm_dom_view_set_viewport_pixels (view, &viewport);
+
lsm_dom_view_get_size_pixels (LSM_DOM_VIEW (view), &width, &height, NULL);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]