Canvas.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/antigrain/Canvas.h
22 
23  \brief A canvas built on top of Anti Grain Geometry.
24  */
25 
26 #ifndef __TERRALIB_AGG_INTERNAL_CANVAS_H
27 #define __TERRALIB_AGG_INTERNAL_CANVAS_H
28 
29 #define PI 3.141592653589793238462643
30 
31 // TerraLib
32 #include "../maptools/Canvas.h"
33 #include "Config.h"
34 
35 #include <windows.h>
36 
37 // AGG
38 #include "font_win32_tt\agg_font_win32_tt.h"
39 #include "agg_font_cache_manager.h"
40 //#define AGG_BGR24
41 //#define AGG_RGB24
42 //#define AGG_RGBA32
43 #define DEPTH 32
44 //#include <d:\agg-2.5\examples\pixel_formats.h>
45 #include "agg_pixfmt_rgba.h"
46 #define pix_format agg::pix_format_rgba32
47 typedef agg::pixfmt_rgba32 pixfmt;
48 typedef agg::pixfmt_rgba32_pre pixfmt_pre;
49 typedef agg::rgba8 color_type;
50 typedef agg::order_rgba component_order;
51 
52 #include <agg_path_storage.h>
53 #include <agg_rendering_buffer.h>
54 #include <agg_pixfmt_rgb.h>
55 #include <agg_renderer_base.h>
56 #include <agg_trans_affine.h>
57 #include <agg_rasterizer_scanline_aa.h>
58 #include <agg_scanline_p.h>
59 #include <agg_renderer_markers.h>
60 #include <agg_conv_segmentator.h>
61 #include <agg_trans_single_path.h>
62 
63 namespace te
64 {
65  namespace ag
66  {
67  /*!
68  \class Canvas
69 
70  \brief A canvas built on top of Anti Grain Geometry.
71 
72  What is a Canvas?
73  <br>
74  It is an abstraction of a drawing area. You can use it to:
75  <ul>
76  <li>draw geographical objects from a layer, with a given visual (or style);</li>
77  <li>draw texts;</li>
78  <li>draw the map legend;</li>
79  <li>create a chart.</li>
80  </ul>
81  */
83  {
84  public:
85 
86  /** @name Initializer Methods
87  * Methods related to instantiation and destruction.
88  */
89  //@{
90 
91  /*! \brief It initializes a new Canvas. */
92  Canvas(int w, int h);
93 
94  /*! \brief Destructor. */
95  ~Canvas();
96 
97  //@}
98 
99  /** @name Accessor Methods
100  * Methods used to access internal attributes.
101  */
102  //@{
103 
104  /*!
105  \brief It sets the world (or window) coordinates area (supposing a cartesian reference system).
106 
107  \param llx Lower left x-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
108  \param lly Lower left y-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
109  \param urx Upper right x-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
110  \param ury Upper right y-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
111  */
112  void setWindow(const double& llx, const double& lly,
113  const double& urx, const double& ury);
114 
115  /*!
116  \brief It adjusts the world (or window) coordinates area (supposing a cartesian reference system).
117 
118  \param llx Lower left x-coordinate of the World.
119  \param lly Lower left y-coordinate of the World.
120  \param urx Upper right x-coordinate of the World.
121  \param ury Upper right y-coordinate of the World.
122  \param hAlign Horizontal Alignment. It can be left, center or right.
123  \param vAlign Vertical Alignment. It can be top, center or bottom.
124 
125  \note The input coordinates will be adjusted according to the alignment parameters provided.
126  */
127  void adjustWorldWindow(double& llx, double& lly, double& urx, double& ury,
128  const HAlignType& ha = HCenter, const VAlignType& va = VCenter);
129 
130  /*!
131  \brief It sets the canvas background color.
132 
133  The default is totally transparent (255, 255, 255, 100%).
134 
135  \param color The background color.
136 
137  \note When this method is called, all the canvas contents is dropped out.
138  */
139  void setBackgroundColor(const te::color::RGBAColor& color);
140 
141  /*!
142  \brief It returns the canvas background color.
143 
144  \return The canvas background color.
145  */
146  te::color::RGBAColor getBackgroundColor() const;
147 
148  /*! \brief It clears the canvas content and fills with the background color. */
149  void clear();
150 
151  /*!
152  \brief It adjusts the canvas size (width and height).
153 
154  \param w The new canvas width.
155  \param h The new canvas height.
156 
157  \note Remember to reset the world (or window) coordinates area before drawing.
158 
159  \note This will invalidate the internal transformation function (you must call the setWindow method again before drawing something in the canvas).
160  */
161  void resize(int w, int h);
162 
163  /*!
164  \brief It returns the canvas width.
165 
166  \return The canvas width.
167  */
168  int getWidth() const { return m_dwidth; }
169 
170  /*!
171  \brief It returns the canvas height.
172 
173  \return The canvas height.
174  */
175  int getHeight() const { return m_dheight; }
176 
177  //@}
178 
179  /** @name Geographical Objects Drawing Methods (WKB or EWKB)
180  * Methods used to draw geographical objects encoded as a WKB or EWKB.
181  * Note that the visual (style and symbol) used to draw geometries is affected by the visual methods.
182  */
183  //@{
184 
185  /*!
186  \brief It draws the geometry in WKB format on canvas.
187 
188  \param geom The geometry in WKB format.
189 
190  \return A pointer to the byte after the geometry data stream.
191 
192  \note The WKB must be in the machine byte order.
193  */
194  char* drawGeometry(char* geom);
195 
196  /*!
197  \brief It draws the point in WKB format on canvas.
198 
199  \param point The point in WKB format.
200 
201  \return A pointer to the byte after the point data stream.
202 
203  \note The WKB must be in the machine byte order.
204  */
205  char* drawPoint(char* point);
206 
207  /*!
208  \brief It draws the point in WKB format on canvas.
209 
210  \param point The point in WKB format.
211 
212  \return A pointer to the byte after the point data stream.
213 
214  \note The WKB must be in the machine byte order.
215  */
216  char* drawPointZ(char* point);
217 
218  /*!
219  \brief It draws the point in WKB format on canvas.
220 
221  \param point The point in WKB format.
222 
223  \return A pointer to the byte after the point data stream.
224 
225  \note The WKB must be in the machine byte order.
226  */
227  char* drawPointM(char* point);
228 
229  /*!
230  \brief It draws the point in WKB format on canvas.
231 
232  \param point The point in WKB format.
233 
234  \return A pointer to the byte after the point data stream.
235 
236  \note The WKB must be in the machine byte order.
237  */
238  char* drawPointZM(char* point);
239 
240  /*!
241  \brief It draws the multipoint in WKB format on canvas.
242 
243  \param mpoint The MultiPoint in WKB format.
244 
245  \return A pointer to the byte after the MultiPoint data stream.
246 
247  \note The WKB must be in the machine byte order.
248  */
249  char* drawMultiPoint(char* mpoint);
250 
251  /*!
252  \brief It draws the line string in WKB format on canvas.
253 
254  \param line The LineString in WKB format.
255 
256  \return A pointer to the byte after the LineString data stream.
257 
258  \note The WKB must be in the machine byte order.
259  */
260  char* drawLineString(char* line);
261 
262  /*!
263  \brief It draws the line string.
264 
265  \param v point array.
266 
267  \note This method becomes the owner of the point array and is responsible for its deletion.
268  */
269  void drawLineString(double* v, const size_t& size); // fazer metodo private
270 
271  /*!
272  \brief It draws the MultiLineString in WKB format on canvas.
273 
274  \param mline The MultiLineString in WKB format.
275 
276  \return A pointer to the byte after the MultiLineString data stream.
277 
278  \note The WKB must be in the machine byte order.
279  */
280  char* drawMultiLineString(char* mline);
281 
282  /*!
283  \brief It draws the polygon in WKB format on canvas.
284 
285  \param poly The polygon in WKB format.
286 
287  \return A pointer to the byte after the polygon data stream.
288 
289  \note The WKB must be in the machine byte order.
290  */
291  char* drawPolygon(char* poly);
292 
293  /*!
294  \brief It draws the polygon.
295 
296  //\param v Polygon vertex array.
297 
298  \param path The polygon path.
299 
300  \note This method becomes the owner of the path and is responsible for its deletion.
301  */
302  void drawPolygon(agg::path_storage& path, const int& index); // fazer metodo private
303 
304  /*!
305  \brief It draws the MultiPolygon in WKB format on canvas.
306 
307  \param mpoly The MultiPolygon in WKB format.
308 
309  \return A pointer to the byte after the MultiPolygon data stream.
310 
311  \note The WKB must be in the machine byte order.
312  */
313  char* drawMultiPolygon(char* mpoly);
314 
315  /*!
316  \brief It draws the GeometryCollection in WKB format on canvas.
317 
318  \param g The GeometryCollection in WKB format.
319 
320  \return A pointer to the byte after the GeometryCollection data stream.
321 
322  \note The WKB must be in the machine byte order.
323  */
324  char* drawGeometryCollection(char* g);
325 
326  //@}
327 
328  /** @name Geographical Objects Drawing Methods (TerraLib Geometry)
329  * Methods used to draw geographical objects encoded as a TerraLib Geometry.
330  * Note that the visual (style and symbol) used to draw geometries is affected by the visual methods.
331  */
332  //@{
333 
334  /*!
335  \brief It draws the geometry on canvas.
336 
337  \param geom Any geometry (point, line, polygon, ...).
338  */
339  void draw(te::gm::Geometry* geom);
340 
341  /*!
342  \brief It draws the point on canvas.
343 
344  \param point The point.
345  */
346  void draw(te::gm::Point* point);
347 
348  /*!
349  \brief It draws the point with Z coordinate on canvas.
350 
351  \param point The point-z.
352  */
353  void draw(te::gm::PointZ* point);
354 
355  /*!
356  \brief It draws the point associated to a M value on canvas.
357 
358  \param point The point-m.
359  */
360  void draw(te::gm::PointM* point);
361 
362  /*!
363  \brief It draws the point with Z and M values on canvas.
364 
365  \param point The point-zm.
366  */
367  void draw(te::gm::PointZM* point);
368 
369  /*!
370  \brief It draws the multipoint on canvas.
371 
372  \param mpoint The MultiPoint.
373  */
374  void draw(te::gm::MultiPoint* mpoint);
375 
376  /*!
377  \brief It draws the line string on canvas.
378 
379  \param line The LineString.
380  */
381  void draw(te::gm::LineString* line);
382 
383  /*!
384  \brief It draws the MultiLineString on canvas.
385 
386  \param mline The MultiLineString.
387  */
388  void draw(te::gm::MultiLineString* mline);
389 
390  /*!
391  \brief It draws the polygon on canvas.
392 
393  \param poly The polygon.
394  */
395  void draw(te::gm::Polygon* poly);
396 
397  /*!
398  \brief It draws the MultiPolygon on canvas.
399 
400  \param mpoly The MultiPolygon.
401  */
402  void draw(te::gm::MultiPolygon* mpoly);
403 
404  /*!
405  \brief It draws the GeometryCollection on canvas.
406 
407  \param g The GeometryCollection.
408  */
409  void draw(te::gm::GeometryCollection* g);
410 
411  //@}
412 
413  /** @name Image Handling
414  * Methods used to draw an image on Canvas.
415  */
416  //@{
417 
418  /*!
419  \brief It returns the internal contents as an image.
420 
421  \param t The image format type (see ImageType enum).
422  \param size The image size in bytes.
423 
424  \return The internal contents as an image. The caller will take the ownership of the returned pointer.
425 
426  \note Use canvas freeImage in order to release the returned image resources.
427  */
428  char* getImage(te::map::Canvas::ImageType t, size_t& size) const;
429 
430  /*!
431  \brief This is the method that you should use to release a image generated by the canvas.
432 
433  \param img A pointer to an image previously created by the canvas.
434  */
435  void freeImage(char* img) const;
436 
437  /*!
438  \brief It draws the src pixmap over the canvas.
439 
440  \param src The source pixmap.
441  */
442  void drawImage(char* src, int size, te::map::Canvas::ImageType t);
443 
444  /*!
445  \brief It draws the src pixmap over the canvas.
446 
447  \param src The source pixmap.
448  \param w The image width (number of columns).
449  \param h The image height (number of columns).
450  */
451  void drawImage(te::color::RGBAColor** src, int w, int h);
452 
453  /*!
454  \brief It draws the src pixmap over the canvas at the specified position (x, y).
455 
456  \param x The canvas start position where the src image will be drawn.
457  \param y The canvas start position where the src image will be drawn.
458  \param src The source pixmap.
459  */
460  void drawImage(int x, int y, char* src, int size, te::map::Canvas::ImageType t);
461 
462  /*!
463  \brief It draws the src pixmap over the canvas at the specified position (x, y).
464 
465  \param x The canvas start position where the src image will be drawn.
466  \param y The canvas start position where the src image will be drawn.
467  \param src The source pixmap.
468  \param w The image width (number of columns).
469  \param h The image height (number of columns).
470  */
471  void drawImage(int x, int y, te::color::RGBAColor** src, int w, int h);
472 
473  /*!
474  \brief It draws the pixmap into the rectangle at position (x, y) with the given width and height.
475 
476  \param x The canvas start position where the src image will be drawn.
477  \param y The canvas start position where the src image will be drawn.
478  \param w The rectangle width.
479  \param h The rectangle height.
480  \param src The source pixmap.
481  */
482  void drawImage(int x, int y, int w, int h, char* src, int size, te::map::Canvas::ImageType t);
483 
484  /*!
485  \brief It draws the pixmap into the rectangle at position (x, y) with the given width and height.
486 
487  \param x The canvas start position where the src image will be drawn.
488  \param y The canvas start position where the src image will be drawn.
489  \param w The rectangle width.
490  \param h The rectangle height.
491  \param src The source pixmap.
492  \param srcw The source image width (number of columns).
493  \param srch The source image height (number of columns).
494  */
495  void drawImage(int x, int y, int w, int h, te::color::RGBAColor** src, int srcw, int srch);
496 
497  /*!
498  \brief It draws the rectangular portion with the origin (sx, sy), width sw and height sh, of the given pixmap, at the point (x, y), with a width of w and a height of h. If sw or sh are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy.
499 
500  \param x The canvas start position where the src image will be drawn.
501  \param y The canvas start position where the src image will be drawn.
502  \param w The rectangle width.
503  \param h The rectangle height.
504  \param src The source pixmap.
505  \param sx The source pixmap position.
506  \param sy The source pixmap position.
507  \param sw The source pixmap rectangle width.
508  \param sh The source pixmap rectangle height.
509  */
510  void drawImage(int x, int y, int w, int h, char* src, int size, te::map::Canvas::ImageType t, int sx, int sy, int sw, int sh);
511 
512  /*!
513  \brief It draws the rectangular portion with the origin (sx, sy), width sw and height sh, of the given pixmap, at the point (x, y), with a width of w and a height of h. If sw or sh are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy.
514 
515  \param x The canvas start position where the src image will be drawn.
516  \param y The canvas start position where the src image will be drawn.
517  \param w The rectangle width.
518  \param h The rectangle height.
519  \param src The source pixmap.
520  \param sx The source pixmap start position.
521  \param sy The source pixmap start position.
522  \param sw The source pixmap rectangle width.
523  \param sh The source pixmap rectangle height.
524  */
525  void drawImage(int x, int y, int w, int h, te::color::RGBAColor** src, int sx, int sy, int sw, int sh);
526 
527  /*!
528  \brief It sets a pixel using the point pen.
529 
530  \param x Column.
531  \param y Line.
532  */
533  void drawPixel(int x, int y);
534 
535  /*!
536  \brief It sets a pixel to a particular color.
537 
538  The color must be an RGBA value. With the following range:
539  <ul>
540  <li>R: 0-255;</li>
541  <li>G: 0-255;</li>
542  <li>B: 0-255;</li>
543  <li>A: 0-255.</li>
544 
545  \param x Column.
546  \param y Line.
547  \param color Pixel color.
548 
549  \note This is not optimized for Canvas. Use a QImage instead.
550  */
551  void drawPixel(int x, int y, const te::color::RGBAColor& color);
552 
553  //@}
554 
555  /** @name Text Handling
556  * Methods used to draw a text on Canvas.
557  */
558  //@{
559 
560  /*!
561  \brief It draws a text.
562 
563  Color and font family should be defined in advance.
564 
565  \param x The text entry point x in device coordinate.
566  \param y The text entry point y in device coordinate.
567  \param tx The text to be drawed.
568  \param angle The text rotation.
569  \param hAlign The horizontal text alignment.
570  \param vAlign The vertical text alignment.
571  */
572  void drawText(int x, int y,
573  const std::string& tx,
574  float angle = 0.0,
577 
578  /*!
579  \brief It draws a text.
580 
581  Color and font family should be defined in advance.
582 
583  \param vin The line coordinate.
584  \param size The line size.
585  \param matrix The transformation matrix.
586  \param tx The text to be drawed.
587  */
588  void drawText(double* vin, const int& size, const agg::trans_affine& matrix, const std::string& tx);
589 
590  /*!
591  \brief It draws a text.
592 
593  Color and font family should be defined in advance.
594 
595  \param wp The text entry point in world coordinate.
596  \param tx The text to be drawed.
597  \param angle The text rotation.
598  \param hAlign The horizontal text alignment.
599  \param vAlign The vertical text alignment.
600  */
601  void drawText(const te::gm::Point& wp,
602  const std::string& tx,
603  float angle = 0.0,
606 
607  /*!
608  \brief It draws a text.
609 
610  Color and font family should be defined in advance.
611 
612  \param x The text entry point x in world coordinate.
613  \param y The text entry point y in world coordinate.
614  \param tx The text to be drawed.
615  \param angle The text rotation.
616  \param hAlign The horizontal text alignment.
617  \param vAlign The vertical text alignment.
618  */
619  void drawText(const double& x, const double& y,
620  const std::string& tx,
621  float angle = 0.0,
624 
625  /*!
626  \brief It draws a annotation text.
627 
628  \param tx Anotation text to be drawed.
629  */
630  void draw(te::at::Text* tx);
631 
632  /*!
633  \brief It draws the text boundary.
634 
635  Color and font family should be defined in advance.
636 
637  \param x The text entry point x in device coordinate.
638  \param y The text entry point y in device coordinate.
639  \param tx The text to be drawed.
640  \param angle The text rotation.
641  \param hAlign The horizontal text alignment.
642  \param vAlign The vertical text alignment.
643  */
644  void drawTextBoundary(int x, int y,
645  const std::string& tx,
646  float angle = 0.0,
649 
650  /*!
651  \brief It draws the text boundary.
652 
653  Color and font family should be defined in advance.
654 
655  \param wp The text entry point in world coordinate.
656  \param tx The text to be drawed.
657  \param angle The text rotation.
658  \param hAlign The horizontal text alignment.
659  \param vAlign The vertical text alignment.
660  */
661  void drawTextBoundary(const te::gm::Point& wp,
662  const std::string& tx,
663  float angle = 0.0,
666 
667  /*!
668  \brief It draws the text boundary.
669 
670  Color and font family should be defined in advance.
671 
672  \param x The text entry point x in world coordinate.
673  \param y The text entry point y in world coordinate.
674  \param tx The text to be drawed.
675  \param angle The text rotation.
676  \param hAlign The horizontal text alignment.
677  \param vAlign The vertical text alignment.
678  */
679  void drawTextBoundary(const double& x, const double& y,
680  const std::string& tx,
681  float angle = 0.0,
684 
685  /*!
686  \brief It returns text boundary.
687 
688  Color and font family should be defined in advance.
689 
690  \param x The text entry point x in device coordinate.
691  \param y The text entry point y in device coordinate.
692  \param tx The text to be drawed.
693  \param angle The text rotation.
694  \param hAlign The horizontal text alignment.
695  \param vAlign The vertical text alignment.
696 
697  \return The text boundary in world coordinate.
698 
699  \note The caller of this method will take the ownership of the returned Polygon.
700  */
701  te::gm::Polygon* getTextBoundary(int x, int y,
702  const std::string& tx,
703  float angle = 0.0,
706 
707  /*!
708  \brief It returns the text boundary.
709 
710  Color and font family should be defined in advance.
711 
712  \param wp The text entry point in world coordinate.
713  \param tx The text to be drawed.
714  \param angle The text rotation.
715  \param hAlign The horizontal text alignment.
716  \param vAlign The vertical text alignment.
717 
718  \return The text boundary in world coordinate.
719 
720  \note The caller of this method will take the ownership of the returned Polygon.
721  */
722  te::gm::Polygon* getTextBoundary(const te::gm::Point& wp,
723  const std::string& tx,
724  float angle = 0.0,
727 
728  /*!
729  \brief It returns the text boundary.
730 
731  Color and font family should be defined in advance.
732 
733  \param x The text entry point x in world coordinate.
734  \param y The text entry point y in world coordinate.
735  \param tx The text to be drawed.
736  \param angle The text rotation.
737  \param hAlign The horizontal text alignment.
738  \param vAlign The vertical text alignment.
739 
740  \return The text boundary in world coordinate.
741 
742  \note The caller of this method will take the ownership of the returned Polygon.
743  */
744  te::gm::Polygon* getTextBoundary(const double& x, const double& y,
745  const std::string& tx,
746  float angle = 0.0,
749 
750  /*!
751  \brief It sets the text drawing color.
752 
753  \param color The new color for drawing a text.
754  */
755  void setTextColor(const te::color::RGBAColor& color);
756 
757  /*!
758  \brief It sets the text opacity.
759 
760  \param opacity The new opacity for drawing a text.
761  */
762  void setTextOpacity(const int& opacity);
763 
764  /*!
765  \brief It sets the text font family.
766 
767  \param family The new font family for drawing a text.
768  */
769  void setFontFamily(const std::string& family);
770 
771  /*!
772  \brief It sets the text Point Size.
773 
774  \param psize The new point size for drawing a text.
775  */
776  void setTextPointSize(double psize);
777 
778  /*!
779  \brief It sets the text style.
780 
781  \param style The new style for drawing a text.
782  */
783  void setTextStyle(te::at::FontStyle style);
784 
785  /*!
786  \brief It sets the text weight.
787 
788  \param weight The new weight for drawing a text.
789  */
790  void setTextWeight(te::at::FontWeight weight);
791 
792  /*!
793  \brief It sets the text stretch.
794 
795  \param stretch The new stretch for drawing a text.
796 
797  \note QT defines the following values:
798  QFont::UltraCondensed 50 50
799  QFont::ExtraCondensed 62 62
800  QFont::Condensed 75 75
801  QFont::SemiCondensed 87 87
802  QFont::Unstretched 100 100
803  QFont::SemiExpanded 112 112
804  QFont::Expanded 125 125
805  QFont::ExtraExpanded 150 150
806  QFont::UltraExpanded 200 200
807  */
808  void setTextStretch(size_t stretch);
809 
810  /*!
811  \brief It sets the text underline flag.
812 
813  \param b True: for underline. False other wise.
814  */
815  void setTextUnderline(bool b);
816 
817  /*!
818  \brief It sets the text overline flag.
819 
820  \param b True: for overline. False other wise.
821  */
822  void setTextOverline(bool b);
823 
824  /*!
825  \brief It sets the text strike out flag.
826 
827  \param b True: for strike out. False other wise.
828  */
829  void setTextStrikeOut(bool b);
830 
831  /*!
832  \brief It sets the text strike out flag.
833 
834  \param color The new color for drawing text decoration.
835  */
836  void setTextDecorationColor(const te::color::RGBAColor& color);
837 
838  /*!
839  \brief It sets the text strike out flag.
840 
841  \param width The new width for drawing text decoration.
842  */
843  void setTextDecorationWidth(int width);
844 
845  /*!
846  \brief It sets the text boundary drawing color.
847 
848  \param color The new color for drawing a text boundary.
849  */
850  void setTextBoundaryColor(const te::color::RGBAColor& color);
851 
852  /*!
853  \brief It sets the text boundary opacity.
854 
855  \param opacity The new opacity for drawing a text boundary.
856  */
857  void setTextBoundaryOpacity(const int& opacity);
858 
859  /*!
860  \brief It sets the text boundary width.
861 
862  \param width The new width for drawing a text boundary.
863  */
864  void setTextBoundaryWidth(const int& width);
865 
866  /*!
867  \brief It sets the multi line text justification.
868 
869  \param just The new justification for drawing a multi line text.
870  */
871  void setTextMultiLineJustification(const te::at::LineJustification& just);
872 
873  /*!
874  \brief It sets the multi line text spacing.
875 
876  \param spacing The new spacing for drawing a multi line text.
877  */
878  void setTextMultiLineSpacing(const int& spacing);
879 
880 
881  //@}
882 
883  /** @name Visual and Style Configuration
884  * Note that the visual (style and symbol) used to draw geometries is affected by the visual methods.
885  */
886  //@{
887 
888  /*! \brief It sets the point drawing color.
889 
890  \param color The new color for drawing a point.
891  */
892  void setPointColor(const te::color::RGBAColor& color);
893 
894  /*! \brief It sets the point drawing color.
895 
896  \param w The new width for drawing a point.
897  */
898  void setPointWidth(int w);
899 
900  /*! \brief It sets the point marker type.
901 
902  \param type The point marker type.
903  */
904  void setPointMarkerType(const ptMarkerType& type);
905 
906  /*! \brief It sets the point style.
907 
908  The style is a matrix of int's, and each position corresponds to a RGBA color.
909 
910  \param style The style matrix: a square matrix of int's where each position corresponds to a RGBA color.
911  \param ncols Number of columns in the matrix.
912  \param nrows Number of rows in the matrix.
913  */
914  void setPointStyle(te::color::RGBAColor** style, int ncols, int nrows);
915 
916  /*! \brief It sets the point style.
917 
918  The style is a matrix of int's, and each position corresponds to a RGBA color.
919 
920  \param style The style matrix: a square matrix of int's where each position corresponds to a RGBA color.
921  \param t The image type used by the style.
922  */
923  void setPointStyle(char* style, int size, te::map::Canvas::ImageType t);
924 
925  /*! \brief It sets the point style.
926 
927  The style is given by an image file. You should only use images that QT can read.
928 
929  \param fileName The file name.
930  */
931  void setPointStyle(const std::string& fileName);
932 
933  /*! \brief It sets the pen color used to draw line geometries.
934 
935  \param r Red component color value.
936  \param g Green component color value.
937  \param b Blue component color value.
938  \param a Alpha component color.
939 
940  \note The alpha value will be an integer between 0 and 100,
941  where 0 is totaly opaque and 100 totaly transparent.
942  */
943  void setLineColor(const te::color::RGBAColor& color);
944 
945  /*! \brief It sets the line style.
946 
947  The style is a matrix of int's, and each position corresponds to a RGBA color.
948 
949  \param ncols Number of columns in the matrix.
950  \param nrows Number of rows in the matrix.
951  */
952  void setLineStyle(te::color::RGBAColor** style, int ncols, int nrows);
953 
954  /*! \brief It sets the line style.
955 
956  The style is a matrix of int's, and each position corresponds to a RGBA color.
957 
958  \param ncols Number of columns in the matrix.
959  \param nrows Number of rows in the matrix.
960  */
961  void setLineStyle(char* style, int size, te::map::Canvas::ImageType t);
962 
963  /*! \brief It sets the line style.
964 
965  The style is given by an image file. You should only use images that QT can read.
966 
967  \param fileName The file name.
968  */
969  void setLineStyle(const std::string& fileName);
970 
971  /*! \brief It sets the line width.
972 
973  \param w The line width.
974  */
975  void setLineWidth(const int& w);
976 
977  /*!
978  \brief It sets the color used to fill the draw of polygon geometries.
979 
980  \param r Red component color value.
981  \param g Green component color value.
982  \param b Blue component color value.
983  \param a Alpha component color.
984 
985  \note The alpha value will be an integer between 0 and 100,
986  where 0 is totaly opaque and 100 totaly transparent.
987  */
988  void setPolygonFillColor(const te::color::RGBAColor& color);
989 
990  /*!
991  \brief It sets the pen color used to draw the boundary of polygon geometries.
992 
993  \param r Red component color value.
994  \param g Green component color value.
995  \param b Blue component color value.
996  \param a Alpha component color.
997 
998  \note The alpha value will be an integer between 0 and 100,
999  where 0 is totaly opaque and 100 totaly transparent.
1000  */
1001  void setPolygonContourColor(const te::color::RGBAColor& color);
1002 
1003  /*!
1004  \brief It sets the polygon fill style.
1005 
1006  The style is a matrix of int's, and each position corresponds to a RGBA color.
1007 
1008  \param ncols Number of columns in the matrix.
1009  \param nrows Number of rows in the matrix.
1010  */
1011  void setPolygonFillStyle(te::color::RGBAColor** style, int ncols, int nrows);
1012 
1013  /*!
1014  \brief It sets the polygon fill style.
1015 
1016  The style is a matrix of int's, and each position corresponds to a RGBA color.
1017 
1018  \param ncols Number of columns in the matrix.
1019  \param nrows Number of rows in the matrix.
1020  */
1021  void setPolygonFillStyle(char* style, int size, te::map::Canvas::ImageType t);
1022 
1023  /*! \brief It sets the polygon fill style.
1024 
1025  The style is given by an image file. You should only use images that QT can read.
1026 
1027  \param fileName The file name.
1028  */
1029  void setPolygonFillStyle(const std::string& fileName);
1030 
1031  /*! \brief It sets the polycon brush icon width.
1032 
1033  \param w The icon width.
1034  */
1035  void setPolygonPatternWidth(const int& w);
1036 
1037  /*! \brief It sets the polycon brush icon width.
1038 
1039  \param w The icon width.
1040  */
1041  void setPolygonPatternOpacity(const unsigned char& opac);
1042 
1043  /*!
1044  \brief It sets the pen style used to draw the boundary of polygon geometries.
1045 
1046  The style is a matrix of int's, and each position corresponds to a RGBA color.
1047 
1048  \param style The style matrix.
1049  \param ncols Number of columns in the matrix.
1050  \param nrows Number of rows in the matrix.
1051  */
1052  void setPolygonContourStyle(te::color::RGBAColor** style, int ncols, int nrows);
1053 
1054  /*!
1055  \brief It sets the pen style used to draw the boundary of polygon geometries.
1056 
1057  The style is a matrix of int's, and each position corresponds to a RGBA color.
1058 
1059  \param ncols Number of columns in the matrix.
1060  \param nrows Number of rows in the matrix.
1061  */
1062  void setPolygonContourStyle(char* style, int size, te::map::Canvas::ImageType t);
1063 
1064  /*! \brief It sets the polygon contour style.
1065 
1066  The style is given by an image file. You should only use images that QT can read.
1067 
1068  \param fileName The file name.
1069  */
1070  void setPolygonContourStyle(const std::string& fileName);
1071 
1072  /*! \brief It sets the polycon contour width.
1073 
1074  \param w The contour width.
1075  */
1076  void setPolygonContourWidth(const int& w);
1077 
1078  //@}
1079 
1080  /** @name Image Generation Methods
1081  * These methods can be used to retrieve or save the canvas contents from/to an image.
1082  */
1083  //@{
1084 
1085  /*!
1086  \brief It saves the canvas content to a file image in the specified format type.
1087 
1088  \param fileName The file name and path where the image will be saved.
1089  \param t The image format type (see ImageType enum).
1090  \param quality JPEG quality, generally a value between 0 and 95.
1091  \param fg Foreground color for WBMP images.
1092 
1093  \warning Qt Canvas extended method.
1094  */
1095  void save(const char* fileName,
1097  int quality = 75,
1098  int fg = 0) const;
1099 
1100  /*!
1101  \brief It gets a RGBA colors from buffer.
1102 
1103  \return The Pointer RGBA colors.
1104 
1105  \note The caller of this method will take the ownership of the returned pointer.
1106  */
1107  te::color::RGBAColor** getColorsFromBuffer(int x=0, int y=0, int w=0, int h=0) const;
1108 
1109  /*!
1110  \brief It gets a RGBA colors from buffer.
1111 
1112  \return The Pointer RGBA colors.
1113 
1114  \note The caller of this method will take the ownership of the returned pointer.
1115  */
1116  unsigned char* getBuffer() const;
1117  //@}
1118 
1119  ///** @name Qt Canvas Specific Methos
1120  // * Methods that belongs only to Qt Canvas.
1121  // */
1122  ////@{
1123 
1124  ///*!
1125  // \brief It draws a text.
1126  //
1127  // Color and font family should be defined in advance.
1128 
1129  // \param p The text entry point i device coordinate.
1130  // \param tx The text to be drawed.
1131  // \param angle The text rotation.
1132  // \param hAlign The horizontal text alignment.
1133  // \param vAlign The vertical text alignment.
1134 
1135  // \note Qt Canvas extended method.
1136  // */
1137  //void drawText(const QPoint& p,
1138  // const std::string& tx,
1139  // float angle = 0.0,
1140  // te::at::HorizontalAlignment hAlign = te::at::Start,
1141  // te::at::VerticalAlignment vAlign = te::at::Baseline);
1142 
1143  ///*!
1144  // \brief It draws the text boundary.
1145  //
1146  // Color and font family should be defined in advance.
1147 
1148  // \param p The text entry point in device coordinate.
1149  // \param tx The text to be drawed.
1150  // \param angle The text rotation.
1151  // \param hAlign The horizontal text alignment.
1152  // \param vAlign The vertical text alignment.
1153 
1154  // \warning Qt Canvas extended method.
1155  // */
1156  //void drawTextBorder(const QPoint& p, const std::string& tx, float angle = 0.0, te::at::HorizontalAlignment hAlign = te::at::Start, te::at::VerticalAlignment vAlign = te::at::Baseline);
1157 
1158  ///*!
1159  // \brief It returns text boundary. Color and font family should be defined in advance.
1160 
1161  // \param p The text entry point in device coordinate.
1162  // \param tx The text to be drawed.
1163  // \param angle The text rotation.
1164  // \param hAlign The horizontal text alignment.
1165  // \param vAlign The vertical text alignment.
1166 
1167  // \return The text boundary in world coordinate.
1168 
1169  // \note The caller of this method will take the ownership of the returned Polygon.
1170 
1171  // \warning Qt Canvas extended method.
1172  // */
1173  //te::gm::Polygon* getTextBorder(const QPoint& p, const std::string& tx, float angle = 0.0, te::at::HorizontalAlignment hAlign = te::at::Start, te::at::VerticalAlignment vAlign = te::at::Baseline);
1174 
1175  ///*!
1176  // \brief It returns the internal pixmap used to draw geographical objects.
1177 
1178  // \return The internal pixmap used to draw geographical objects. Don't delete it!
1179 
1180  // \warning Qt Canvas extended method.
1181 
1182  // \note You can not delete this pointer.
1183  // */
1184  //QPixmap* getPixmap() const;
1185 
1186  ///*!
1187  // \brief It sets new device as QPrinter.
1188 
1189  // \param device The new paint device.
1190 
1191  // \note The canvas becomes owner of the device. You can not delete this pointer
1192  // */
1193  //void setDevice(QPaintDevice* device);
1194 
1195  ///*!
1196  // \brief It returns the device resolution.
1197 
1198  // \return The device resolution.
1199  // */
1200  //int getResolution();
1201 
1202  ///*!
1203  // \brief It returns the matrix.
1204 
1205  // \return The marix.
1206  // */
1207  //QMatrix getMatrix();
1208 
1209  //@}
1210 
1211  bool write_ppm(const std::string& file_name);
1212  char* getData(const std::string& file_name, int& w, int &h);
1213 
1214  private:
1215 
1216  /** @name Copy Constructor and Assignment Operator
1217  * Copy constructor and assignment operator not allowed.
1218  */
1219  //@{
1220 
1221  /*!
1222  \brief Copy constructor not allowed.
1223 
1224  \param rhs The right-hand-side copy that would be used to copy from.
1225  */
1226  Canvas(const Canvas& rhs);
1227 
1228  /*!
1229  \brief Assignment operator not allowed.
1230 
1231  \param rhs The right-hand-side copy that would be used to copy from.
1232 
1233  \return A reference to this object.
1234  */
1235  Canvas& operator=(const Canvas& rhs);
1236 
1237  //@}
1238 
1239  private:
1240 
1241  HDC m_hdc;
1242  int m_dwidth; //!< The device width.
1243  int m_dheight; //!< The device height.
1244  double m_wllx; //!< Lower left x-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
1245  double m_wlly; //!< Lower left y-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
1246  double m_wurx; //!< Upper right x-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
1247  double m_wury; //!< Upper right y-coordinate of the World (in the spatial coordinate system of the datasets to be drawn).
1248  unsigned char* m_buffer;
1249  agg::rendering_buffer m_renderingBuffer;
1251  agg::renderer_base<pixfmt> m_rendererBase;
1252  agg::rasterizer_scanline_aa<> m_rasterizer;
1253  agg::scanline_p8 m_scanline;
1254  agg::trans_affine m_matrix; //!< Matrix that transforms the world coordinate to device coordinate.
1255 
1256  color_type m_bgColor; //!< Canvas background color. Defaults: white fully transparent.
1257 
1258  color_type m_polyFillColor; //!< Polygon fill color.
1259  color_type m_polyContourColor; //!< Polygon contoyr color.
1260  double m_polyContourWidth; //!< Polygon contour width.
1261  unsigned int m_polyPatternWidth; //!< The pattern width used to fill a polygon.
1262  agg::int8u* m_polyPatternBuffer;
1263  agg::rendering_buffer m_polyPatternRenderingBuffer;
1264  unsigned char m_polyPatternOpacity; //!< The pattern opacity.
1266  agg::rendering_buffer m_contourPatternRenderingBuffer;
1267 
1268  color_type m_lineColor; //!< Line color.
1269  double m_lineWidth; //!< Line width.
1270  agg::int8u* m_linePatternBuffer;
1271  agg::rendering_buffer m_linePatternRenderingBuffer;
1272 
1273  color_type m_ptColor; //!< Point color.
1274  int m_ptWidth; //!< Point width.
1275  agg::marker_e m_ptMarkerType;
1276  agg::int8u* m_ptPatternBuffer;
1277  agg::rendering_buffer m_ptPatternRenderingBuffer;
1278 
1279  typedef agg::font_engine_win32_tt_int16 font_engine_type;
1280  typedef agg::font_cache_manager<font_engine_type> font_manager_type;
1281  typedef agg::conv_curve<font_manager_type::path_adaptor_type> conv_font_curve_type;
1282  typedef agg::conv_segmentator<conv_font_curve_type> conv_font_segm_type;
1283  typedef agg::conv_transform<conv_font_segm_type, agg::trans_single_path> conv_font_trans_type;
1284  font_engine_type *m_fontEngine;
1285  font_manager_type *m_fontManager;
1286  color_type m_txColor; //!< Text color.
1287  color_type m_txBoundaryColor; //!< Text boundary color.
1288  double m_txBoundaryWidth; //!< Text boundary color.
1289  double m_txXScale;
1290  int m_txDecorationType; //!< none=0, underline=1, overline=2 or strikeout=3.
1293  double m_textLetterSpacing; //!< Text letter spacing.
1294  double m_textWordSpacing; //!< Text word spacing.
1295  double m_textLineSpacing; //!< Text multi line spacing.
1296  int m_textLineJustification; //!< Text multi line justification.
1297  };
1298  } // end namespace agg
1299 } // end namespace te
1300 
1301 #endif // __TERRALIB_AGG_INTERNAL_CANVAS_H
1302 
double m_wllx
Lower left x-coordinate of the World (in the spatial coordinate system of the datasets to be drawn)...
Definition: Canvas.h:1244
agg::font_engine_win32_tt_int16 font_engine_type
Definition: Canvas.h:1279
agg::trans_affine m_matrix
Matrix that transforms the world coordinate to device coordinate.
Definition: Canvas.h:1254
ImageType
This enum specifies the possible input and output image formats supported by the canvas API...
Definition: Enums.h:38
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
double m_txXScale
Definition: Canvas.h:1289
font_engine_type * m_fontEngine
Definition: Canvas.h:1284
int getHeight() const
It returns the canvas height.
Definition: Canvas.h:175
FontWeight
Font weight for drawing text.
Definition: Enums.h:50
int m_dwidth
The device width.
Definition: Canvas.h:1242
double m_wurx
Upper right x-coordinate of the World (in the spatial coordinate system of the datasets to be drawn)...
Definition: Canvas.h:1246
color_type m_ptColor
Point color.
Definition: Canvas.h:1273
int getWidth() const
It returns the canvas width.
Definition: Canvas.h:168
A canvas built on top of Anti Grain Geometry.
Definition: Canvas.h:82
agg::rendering_buffer m_polyPatternRenderingBuffer
Definition: Canvas.h:1263
int m_txDecorationType
none=0, underline=1, overline=2 or strikeout=3.
Definition: Canvas.h:1290
agg::rendering_buffer m_contourPatternRenderingBuffer
Definition: Canvas.h:1266
color_type m_polyFillColor
Polygon fill color.
Definition: Canvas.h:1258
LineJustification
Line justification for drawing multi line text.
Definition: Enums.h:106
FontStyle
Font style for drawing text.
Definition: Enums.h:38
double m_wlly
Lower left y-coordinate of the World (in the spatial coordinate system of the datasets to be drawn)...
Definition: Canvas.h:1245
int m_dheight
The device height.
Definition: Canvas.h:1243
color_type m_bgColor
Canvas background color. Defaults: white fully transparent.
Definition: Canvas.h:1256
agg::int8u * m_contourPatternBuffer
Definition: Canvas.h:1265
agg::rendering_buffer m_ptPatternRenderingBuffer
Definition: Canvas.h:1277
color_type m_polyContourColor
Polygon contoyr color.
Definition: Canvas.h:1259
agg::conv_transform< conv_font_segm_type, agg::trans_single_path > conv_font_trans_type
Definition: Canvas.h:1283
agg::conv_segmentator< conv_font_curve_type > conv_font_segm_type
Definition: Canvas.h:1282
A Text may contain 1 or more Text Elements.
Definition: Text.h:51
font_manager_type * m_fontManager
Definition: Canvas.h:1285
unsigned int m_polyPatternWidth
The pattern width used to fill a polygon.
Definition: Canvas.h:1261
agg::rasterizer_scanline_aa m_rasterizer
Definition: Canvas.h:1252
double m_wury
Upper right y-coordinate of the World (in the spatial coordinate system of the datasets to be drawn)...
Definition: Canvas.h:1247
int m_textLineJustification
Text multi line justification.
Definition: Canvas.h:1296
Configuration flags for the TerraLib AGG.
agg::int8u * m_ptPatternBuffer
Definition: Canvas.h:1276
A point with a z-coordinate value and an associated measurement.
Definition: PointZM.h:51
unsigned char m_polyPatternOpacity
The pattern opacity.
Definition: Canvas.h:1264
A point with an associated measure.
Definition: PointM.h:51
color_type m_txBoundaryColor
Text boundary color.
Definition: Canvas.h:1287
agg::rgba8 color_type
Definition: Canvas.h:49
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
A point with z-coordinate value.
Definition: PointZ.h:51
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
HorizontalAlignment
Horizontal alignment for drawing text.
Definition: Enums.h:81
A point with x and y coordinate values.
Definition: Point.h:50
agg::marker_e m_ptMarkerType
Definition: Canvas.h:1275
URI C++ Library.
agg::pixfmt_rgba32_pre pixfmt_pre
Definition: Canvas.h:48
agg::int8u * m_polyPatternBuffer
Definition: Canvas.h:1262
double m_textWordSpacing
Text word spacing.
Definition: Canvas.h:1294
double m_textLineSpacing
Text multi line spacing.
Definition: Canvas.h:1295
agg::int8u * m_linePatternBuffer
Definition: Canvas.h:1270
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
agg::pixfmt_rgba32 pixfmt
Definition: Canvas.h:47
double m_textLetterSpacing
Text letter spacing.
Definition: Canvas.h:1293
MultiLineString is a MultiCurve whose elements are LineStrings.
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:92
unsigned char * m_buffer
Definition: Canvas.h:1248
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
VerticalAlignment
Vertical alignment for drawing text.
Definition: Enums.h:93
agg::font_cache_manager< font_engine_type > font_manager_type
Definition: Canvas.h:1280
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
color_type m_txColor
Text color.
Definition: Canvas.h:1286
agg::rendering_buffer m_linePatternRenderingBuffer
Definition: Canvas.h:1271
double m_txBoundaryWidth
Text boundary color.
Definition: Canvas.h:1288
double m_lineWidth
Line width.
Definition: Canvas.h:1269
agg::rendering_buffer m_renderingBuffer
Definition: Canvas.h:1249
double m_polyContourWidth
Polygon contour width.
Definition: Canvas.h:1260
pixfmt * m_pixfmt
Definition: Canvas.h:1250
color_type m_lineColor
Line color.
Definition: Canvas.h:1268
int m_ptWidth
Point width.
Definition: Canvas.h:1274
agg::scanline_p8 m_scanline
Definition: Canvas.h:1253
It is a collection of other geometric objects.
agg::conv_curve< font_manager_type::path_adaptor_type > conv_font_curve_type
Definition: Canvas.h:1281
color_type m_txDecorationColor
Definition: Canvas.h:1291
#define TEAGGEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:112
double m_txDecorationWidth
Definition: Canvas.h:1292
agg::order_rgba component_order
Definition: Canvas.h:50
agg::renderer_base< pixfmt > m_rendererBase
Definition: Canvas.h:1251