[drgeo/goffice: 70/82] add getBounds method. ditto. ditto. ditto. ditto. add new files. implement



commit b75c83a9e6a3301621319b2736ff818fef858a91
Author: Jean Brefort <jean brefort normalesup org>
Date:   Sun Feb 5 12:55:47 2006 +0000

    add getBounds method. ditto. ditto. ditto. ditto. add new files. implement
    
    2006-02-05  Jean Brefort  <jean brefort normalesup org>
    
    	* geo/drgeo_figure.cc: add getBounds method.
    	* geo/drgeo_figure.h: ditto.
    	* geo/drgeo_geometricObject.h: ditto.
    	* geo/drgeo_point.cc: ditto.
    	* geo/drgeo_point.h: ditto.
    	* goffice/Makefile.am: add new files.
    	* goffice/drgeo.cc: implement size and drawing.
    	* goffice/drgeo_cairodrawable.cc: new drawable class using cairo.
    	* goffice/drgeo_cairodrawable.h: ditto.

 ChangeLog                      |   12 +++
 geo/drgeo_figure.cc            |   31 +++++++
 geo/drgeo_figure.h             |    2 +
 geo/drgeo_geometricObject.h    |    5 +
 geo/drgeo_point.cc             |    8 ++
 geo/drgeo_point.h              |    2 +
 goffice/Makefile.am            |    4 +-
 goffice/drgeo.cc               |   31 ++++++-
 goffice/drgeo_cairodrawable.cc |  194 ++++++++++++++++++++++++++++++++++++++++
 goffice/drgeo_cairodrawable.h  |   61 +++++++++++++
 10 files changed, 347 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f2751e4..845cb27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,18 @@
 
 	* configure.ac: Add "zh_HK" to ALL_LINGUAS.
 
+2006-02-05  Jean Brefort  <jean brefort normalesup org>
+
+	* geo/drgeo_figure.cc: add getBounds method.
+	* geo/drgeo_figure.h: ditto.
+	* geo/drgeo_geometricObject.h: ditto.
+	* geo/drgeo_point.cc: ditto.
+	* geo/drgeo_point.h: ditto.
+	* goffice/Makefile.am: add new files.
+	* goffice/drgeo.cc: implement size and drawing.
+	* goffice/drgeo_cairodrawable.cc: new drawable class using cairo.
+	* goffice/drgeo_cairodrawable.h: ditto.
+
 2006-02-04  Jean Brefort  <jean brefort normalesup org>
 
 	* Makefile.am: add goffice subdirectory and mime type management.
diff --git a/geo/drgeo_figure.cc b/geo/drgeo_figure.cc
index 1d59126..9fec01c 100644
--- a/geo/drgeo_figure.cc
+++ b/geo/drgeo_figure.cc
@@ -1509,3 +1509,34 @@ _freeKeyFromHash (gpointer key, gpointer value, gpointer data)
 {
   g_free (key);
 }
+
+gboolean drgeoFigure::getBounds (double &left, double &top,
+								double &right, double &bottom)
+{
+	gboolean result = false;
+	liste_elem *fig;
+	geometricObject *item;
+	double itleft, ittop, itright, itbottom;
+	fig = getFigureList ();
+	fig->init_lire ();
+	while ((item = (geometricObject *) fig->lire (0)) != NULL)
+		if (item->getBounds (itleft, ittop, itright, itbottom)) {
+			if (result) {
+				if (left > itleft)
+					left = itleft;
+				if (top < ittop)
+					top = ittop;
+				if (right < itright)
+					right = itright;
+				if (bottom > itbottom)
+					bottom = itbottom;
+			} else {
+				result = true;
+				left = itleft;
+				top = ittop;
+				right = itright;
+				bottom = itbottom;
+			}
+		}
+	return result;
+}
diff --git a/geo/drgeo_figure.h b/geo/drgeo_figure.h
index e147c3b..dba2e46 100644
--- a/geo/drgeo_figure.h
+++ b/geo/drgeo_figure.h
@@ -236,6 +236,8 @@ public:
 
   ScmInterface * getScmInterface ();
 
+  gboolean getBounds (double &left, double &top, double &right, double &bottom);
+
   // The following objects are responsible for selecting the items
   // that are valid in the context of the current mode.
   //
diff --git a/geo/drgeo_geometricObject.h b/geo/drgeo_geometricObject.h
index 68d7b34..87b0f7d 100644
--- a/geo/drgeo_geometricObject.h
+++ b/geo/drgeo_geometricObject.h
@@ -89,6 +89,11 @@ public:
 				    drgeoPoint & p, gint k)
   {
   };
+  virtual gboolean getBounds (double &left, double &top,
+				  double &right, double &bottom)
+  {
+	  return false;
+  };
 protected:
   liste_elem * figureList;
   drgeoStyle style;		/* the display style */
diff --git a/geo/drgeo_point.cc b/geo/drgeo_point.cc
index 052b0e2..20b3956 100644
--- a/geo/drgeo_point.cc
+++ b/geo/drgeo_point.cc
@@ -557,3 +557,11 @@ point::preferedShape (gchar *attr)
   else if (!strcmp (str, "SquarreEmpty"))
     return drgeoPointRecEmpty;
 }
+
+gboolean 
+point::getBounds (double &left, double &top, double &right, double &bottom)
+{
+	left = right = p.getX();
+	top = bottom = p.getY();
+	return true;
+}
diff --git a/geo/drgeo_point.h b/geo/drgeo_point.h
index befbcc5..6626196 100644
--- a/geo/drgeo_point.h
+++ b/geo/drgeo_point.h
@@ -53,6 +53,8 @@ public:
   gdouble getAbscissa ();
   void * getExtra ();
   drgeoPointType preferedShape (gchar *attr);
+  virtual gboolean getBounds (double &left, double &top,
+				  double &right, double &bottom);
 protected:
   drgeoPoint p;
   gdouble abscissa;
diff --git a/goffice/Makefile.am b/goffice/Makefile.am
index 83fdba3..733c43e 100644
--- a/goffice/Makefile.am
+++ b/goffice/Makefile.am
@@ -21,7 +21,9 @@ AM_CPPFLAGS = -I$(top_srcdir) -DGNOMELOCALEDIR=\"$(datadir)/locale\" @GODRGEO_CF
 drgeo_la_SOURCES =	\
 		drgeo.cc	\
 		goffice_mdi.cc	\
-		goffice_mdi.h
+		goffice_mdi.h	\
+		drgeo_cairodrawable.cc	\
+		drgeo_cairodrawable.h
 
 xml_in_files = plugin.xml.in
 xmldir	 = $(goffice_drgeodir)
diff --git a/goffice/drgeo.cc b/goffice/drgeo.cc
index d84e0df..d96e0ed 100644
--- a/goffice/drgeo.cc
+++ b/goffice/drgeo.cc
@@ -26,6 +26,7 @@
 #include <drgenius_help.h>
 #include <geo/drgeo_figure.h>
 #include "goffice_mdi.h"
+#include "drgeo_cairodrawable.h"
 
 #include <libxml/tree.h>
 #ifdef _
@@ -37,6 +38,7 @@
 #include <goffice/component/go-component.h>
 #include <gsf/gsf-impl-utils.h>
 #include <goffice/app/module-plugin-defs.h>
+#include <locale.h>
 
 extern "C" {
 
@@ -52,7 +54,7 @@ typedef struct
 {
 	GOComponent parent;
 	drgeoFigure *figure;
-
+	double xoffset, yoffset, width, height;
 } GODrGeoComponent;
 
 typedef GOComponentClass GODrGeoComponentClass;
@@ -79,6 +81,7 @@ go_drgeo_component_set_data (GOComponent *component, char const *data, int lengt
 {
 	GODrGeoComponent *godrgeo = GO_DRGEO_COMPONENT (component);
 	xmlDocPtr xml;
+	char *old_num_locale;
 	if (!(xml = xmlParseMemory(data, length)) ||
 		xml->children == NULL ||
 		strcmp((char*)xml->children->name, "drgenius")) {
@@ -86,14 +89,38 @@ go_drgeo_component_set_data (GOComponent *component, char const *data, int lengt
 			xmlFreeDoc (xml);
 		return;
 	}
+	old_num_locale = g_strdup (setlocale (LC_NUMERIC, NULL));
+	setlocale (LC_NUMERIC, "C");
 	godrgeo->figure = new drgeoFigure (xml->children->children);
+	setlocale (LC_NUMERIC, old_num_locale);
+	g_free (old_num_locale);
 	xmlFreeDoc (xml);
+	double left, top, right, bottom;
+	godrgeo->figure->getBounds (left, top, right, bottom);
+	godrgeo->xoffset = left - 0.2;
+	godrgeo->yoffset = top + 0.2;
+	godrgeo->height = top - bottom + 0.4;
+	godrgeo->width = right - left + 0.4;
+	component->ascent = godrgeo->height / 2.54;
+	component->descent = 0.;
+	component->width = godrgeo->width / 2.54;
 }
 
 static void
 go_drgeo_component_draw (GOComponent *component, int width_pixels, int height_pixels)
 {
 	GODrGeoComponent *godrgeo = GO_DRGEO_COMPONENT (component);
+	gdk_pixbuf_fill (component->pixbuf, 0);
+	cairo_surface_t* surface = cairo_image_surface_create_for_data (
+              				gdk_pixbuf_get_pixels (component->pixbuf),
+							CAIRO_FORMAT_ARGB32,
+							width_pixels, height_pixels, 
+               				gdk_pixbuf_get_rowstride (component->pixbuf));
+	drgeoCairoDrawable *drawable = new drgeoCairoDrawable (godrgeo->figure, surface);
+	drawable->scale = width_pixels / godrgeo->width;
+	drawable->setOffset (godrgeo->xoffset, godrgeo->yoffset);
+	godrgeo->figure->redraw (0);
+	delete drawable;
 }
 
 static void
@@ -117,7 +144,7 @@ go_drgeo_component_init (GOComponent *component)
 	GODrGeoComponent *godrgeo = GO_DRGEO_COMPONENT (component);
 	component->resizable = false;
 	component->editable = false;
-	component->needs_window = true;
+	component->needs_window = false;
 	godrgeo->figure = NULL;
 }
 
diff --git a/goffice/drgeo_cairodrawable.cc b/goffice/drgeo_cairodrawable.cc
new file mode 100644
index 0000000..049408d
--- /dev/null
+++ b/goffice/drgeo_cairodrawable.cc
@@ -0,0 +1,194 @@
+/* 
+ * DrGeo GOffice component
+ * drgeo_cairodrawable.cc
+ *
+ * Copyright (C) 2006
+ *
+ * Developed by Jean Bréfort <jean brefort normalesup org>
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of the GNU General Public License as 
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+ 
+#include <config.h>
+#include "drgeo_cairodrawable.h"
+#include <geo/couleur.h>
+
+static cairo_pattern_t *cairoColor[drgeoColorNumber] = {
+	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+drgeoCairoDrawable::drgeoCairoDrawable (drgeoFigure * figure, cairo_surface_t *surface)
+{
+	if (cairoColor[drgeoColorBlack] == NULL) {
+		cairoColor[drgeoColorBlack] = cairo_pattern_create_rgb (0., 0., 0.);
+		cairoColor[drgeoColorDarkGrey] = cairo_pattern_create_rgb (.333333, .333333, .333333);
+		cairoColor[drgeoColorGrey] = cairo_pattern_create_rgb (.666667, .666667, .666667);
+		cairoColor[drgeoColorWhite] = cairo_pattern_create_rgb (1., 1., 1.);
+		cairoColor[drgeoColorDarkGreen] = cairo_pattern_create_rgb (0., .392157, 0.);
+		cairoColor[drgeoColorGreen] = cairo_pattern_create_rgb (0., .921569, 0.);
+		cairoColor[drgeoColorDarkBlue] = cairo_pattern_create_rgb (1., .219608, .176471);
+		cairoColor[drgeoColorBlue] = cairo_pattern_create_rgb (1., .694118, .313725);
+		cairoColor[drgeoColorBordeaux] = cairo_pattern_create_rgb (0., 0., .568627);
+		cairoColor[drgeoColorRed] = cairo_pattern_create_rgb (0., 0., .921569);
+		cairoColor[drgeoColorOrange] = cairo_pattern_create_rgb (.168627, .6, 1.);
+		cairoColor[drgeoColorYellow] = cairo_pattern_create_rgb (.129412, .941176, 1.);
+		cairoColor[drgeoColorTips] = cairo_pattern_create_rgb (.752941, 1., 1.);
+		cairoColor[drgeoColorPrintingArea] = cairo_pattern_create_rgb (.941176, .941176, .941176);
+	}
+	setFigure (figure);
+	m_Surf = surface;
+	m_Cairo = cairo_create (surface);
+	figure->setDrawable (this);
+}
+
+drgeoCairoDrawable::~drgeoCairoDrawable ()
+{
+	if (m_Cairo)
+		cairo_destroy (m_Cairo);
+	if (m_Surf != NULL)
+		cairo_surface_destroy (m_Surf);
+}
+
+void drgeoCairoDrawable::drawPoint (drgeoStyle & style, drgeoPoint & point)
+{
+	if (style.mask == yes)
+		return;
+
+	double x = point.getX (), y = point.getY (), radius;
+
+	switch (style.thick)
+	{
+	case drgeoThicknessDashed:
+		radius = .05;
+	break;
+	case drgeoThicknessNormal:
+		radius = .075;
+	break;
+	case drgeoThicknessLarge:
+		radius = .1;
+	break;
+	}
+
+	cairo_set_source (m_Cairo, cairoColor[style.color]);
+
+	switch (style.pointShape)
+	{
+	case drgeoPointRound:
+		break;
+	case drgeoPointX:
+		cairo_set_line_width (m_Cairo, .05);
+		cairo_set_dash (m_Cairo, NULL, 0, 0.);
+		cairo_set_line_cap (m_Cairo, CAIRO_LINE_CAP_ROUND);
+		cairo_set_line_join (m_Cairo, CAIRO_LINE_JOIN_MITER);
+	
+		cairo_new_path (m_Cairo);
+		cairo_move_to (m_Cairo,	x - radius, y - radius);
+		cairo_line_to (m_Cairo,	x + radius, y + radius);
+		cairo_stroke (m_Cairo);
+		cairo_new_path (m_Cairo);
+		cairo_move_to (m_Cairo,	x - radius, y + radius);
+		cairo_line_to (m_Cairo,	x + radius, y - radius);
+		cairo_stroke (m_Cairo);
+		break;
+	case drgeoPointRec:
+		break;
+	case drgeoPointRoundEmpty:
+		break;
+	case drgeoPointRecEmpty:
+		break;
+	}
+}
+
+void drgeoCairoDrawable::drawPolygon (drgeoStyle & style, drgeoPoint * point, gint number)
+{
+}
+
+void drgeoCairoDrawable::drawLine (drgeoStyle & style, drgeoPoint & start, drgeoPoint & end)
+{
+}
+
+void drgeoCairoDrawable::drawHalfLine (drgeoStyle & style, drgeoPoint & start,
+		 drgeoVector & vect)
+{
+}
+
+void drgeoCairoDrawable::drawSegment (drgeoStyle & style, drgeoPoint & start, drgeoPoint & end)
+{
+	if (style.mask == yes)
+		return;
+
+	cairo_set_source (m_Cairo, cairoColor[style.color]);
+
+	switch (style.thick)
+	{
+	case drgeoThicknessDashed:
+		break;
+	case drgeoThicknessNormal:
+		cairo_set_line_width (m_Cairo, .025);
+		cairo_set_dash (m_Cairo, NULL, 0, 0.);
+		cairo_set_line_cap (m_Cairo, CAIRO_LINE_CAP_ROUND);
+		cairo_set_line_join (m_Cairo, CAIRO_LINE_JOIN_MITER);
+		break;
+	case drgeoThicknessLarge:
+		break;
+	}
+
+	// Draw the line.
+	cairo_new_path (m_Cairo);
+	cairo_move_to (m_Cairo,	start.getX (), start.getY ());
+	cairo_line_to (m_Cairo,	end.getX (), end.getY ());
+	cairo_stroke (m_Cairo);
+}
+
+void drgeoCairoDrawable::drawCircle (drgeoStyle & style, drgeoPoint & center, double radius)
+{
+}
+
+void drgeoCairoDrawable::drawCircle (drgeoStyle & style, drgeoPoint & center,
+	   drgeoPoint & point)
+{
+}
+
+void drgeoCairoDrawable::drawArc (drgeoStyle & style, drgeoPoint & center, double radius,
+	double start, double length)
+{
+}
+
+void drgeoCairoDrawable::drawText (drgeoPoint & where, char *text, drgeoColorType fontColor)
+{
+}
+
+double drgeoCairoDrawable::stringWidth (char *text)
+{
+}
+
+double drgeoCairoDrawable::stringHeight (char *text)
+{
+}
+
+drgeoPoint drgeoCairoDrawable::getAreaCenter ()
+{
+}
+
+drgeoPoint drgeoCairoDrawable::getAreaSize ()
+{
+}
+
+void drgeoCairoDrawable::setOffset (double xOffset, double yOffset)
+{
+	cairo_scale (m_Cairo, scale, -scale);
+	cairo_translate (m_Cairo, -xOffset, -yOffset);
+}
diff --git a/goffice/drgeo_cairodrawable.h b/goffice/drgeo_cairodrawable.h
new file mode 100644
index 0000000..f4d61a6
--- /dev/null
+++ b/goffice/drgeo_cairodrawable.h
@@ -0,0 +1,61 @@
+/* 
+ * DrGeo GOffice component
+ * drgeo_cairodrawable.h
+ *
+ * Copyright (C) 2006
+ *
+ * Developed by Jean Bréfort <jean brefort normalesup org>
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of the GNU General Public License as 
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef DRGEO_CAIRODRAWABLE_H
+#define DRGEO_CAIRODRAWABLE_H
+
+#include <geo/drgeo_drawable.h>
+#include <cairo/cairo.h>
+
+// Implementation of Cairo drawable.
+class drgeoCairoDrawable:public drgeoDrawable
+{
+public:
+	drgeoCairoDrawable (drgeoFigure * figure, cairo_surface_t *surface);
+	~drgeoCairoDrawable ();
+
+	void drawPoint (drgeoStyle & style, drgeoPoint & point);
+	void drawPolygon (drgeoStyle & style, drgeoPoint * point, gint number);
+	void drawLine (drgeoStyle & style, drgeoPoint & start, drgeoPoint & end);
+	void drawHalfLine (drgeoStyle & style, drgeoPoint & start,
+			 drgeoVector & vect);
+	void drawSegment (drgeoStyle & style, drgeoPoint & start, drgeoPoint & end);
+	void drawCircle (drgeoStyle & style, drgeoPoint & center, double radius);
+	void drawCircle (drgeoStyle & style, drgeoPoint & center,
+		   drgeoPoint & point);
+	void drawArc (drgeoStyle & style, drgeoPoint & center, double radius,
+		double start, double length);
+	void drawText (drgeoPoint & where, char *text, drgeoColorType fontColor);
+	double stringWidth (char *text);
+	double stringHeight (char *text);
+	drgeoPoint getAreaCenter ();
+	drgeoPoint getAreaSize ();
+	void setOffset (double xOffset, double yOffset);
+
+private:
+	cairo_surface_t *m_Surf;
+	cairo_t *m_Cairo;
+};
+
+#endif



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