wxArt2D
stylebase.h
Go to the documentation of this file.
1 /*! \file wx/artbase/stylebase.h
2 
3  \brief Stroke and fill base classes.
4 
5  Holds style classes, derived from a2dObject. All wxDrawer2D understand the style classes
6  which are set as a2dStroke a2dFill to them.
7  Style classes can be added to a2dCanvasObject's as properties, and this is how these object
8  can be drawn colours which are customizable by the user.
9 
10  \author Klaas Holwerda
11 
12  Copyright: 2000-2004 (c) Klaas Holwerda
13 
14  Licence: wxWidgets Licence
15 
16  RCS-ID: $Id: stylebase.h,v 1.57 2009/10/01 19:22:34 titato Exp $
17 */
18 
19 
20 #ifndef __STYLEBASE_H__
21 #define __STYLEBASE_H__
22 
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26 
27 #include <wx/fontenc.h>
28 #include <wx/encconv.h>
29 #include <wx/bitmap.h>
30 
31 #include "a2dprivate.h"
32 
33 #include "wx/geometry.h"
34 
35 #include <map>
36 
37 using namespace std;
38 
39 
40 #if wxART2D_USE_FREETYPE
41 #include <ft2build.h>
42 #ifdef _MSC_VER
43 // Do not use the define include for MSVC, because of a bug with precompiled
44 // headers. See (freetype)/doc/INSTALL.ANY for (some) more information
45 #include <freetype/freetype.h>
46 #include <freetype/ftglyph.h>
47 #include <freetype/ftoutln.h>
48 #else // _MSC_VER
49 // This is the way it should be included.
50 #include FT_FREETYPE_H
51 #include FT_GLYPH_H
52 #include <freetype/ftoutln.h>
53 #endif // _MSC_VER
54 #endif
55 
56 #include "wx/general/gen.h"
57 
58 #if wxART2D_USE_XMLPARSE
59 #include "wx/xmlparse/genxmlpars.h"
60 #endif //wxART2D_USE_XMLPARSE
61 
62 #include "wx/artbase/artglob.h"
63 #include "wx/artbase/liner.h"
64 #include "wx/artbase/afmatrix.h"
65 #include "wx/artbase/bbox.h"
66 
67 //! Normalization font size used for bigger size drawing of text.
68 #define NORMFONT 1000
69 #define SMALLTEXTTHRESHOLD 10
70 
71 class A2DARTBASEDLLEXP a2dBoundingBox;
72 class A2DARTBASEDLLEXP a2dAffineMatrix;
73 
74 class a2dDrawer2D;
75 class a2dVpath;
76 
77 //! General colour property id
79 
80 //!Filling styles for a2dFill
81 /*!
82  Transparent filling when bitmap/patternfill is monochrome and fill style is
83  wxSTIPPLE_MASK_OPAQUE_TRANSPARENT.
84  The fill colour will be used for non Transparent parts in the brush bitmap,
85  while other parts will be transparent.
86  a2dFILL_GRADIENT_FILL_LINEAR gradient filling using lines changing in colour from fill colour1 to fill colour2
87  a2dFILL_GRADIENT_FILL_RADIAL, gradient filling using circles changing in colour from fill colour1 to fill colour2
88 
89  \ingroup style
90 */
92 {
93  a2dFILL_TRANSPARENT, /*!< No fill is used.*/
94  a2dFILL_SOLID, /*!< Solid style. */
95  a2dFILL_BDIAGONAL_HATCH, /*!< Backward diagonal hatch.*/
96  a2dFILL_CROSSDIAG_HATCH, /*!< Cross-diagonal hatch.*/
97  a2dFILL_FDIAGONAL_HATCH, /*!< Forward diagonal hatch.*/
98  a2dFILL_CROSS_HATCH, /*!< Cross hatch.*/
99  a2dFILL_HORIZONTAL_HATCH, /*!< Horizontal hatch.*/
100  a2dFILL_VERTICAL_HATCH, /*!< Vertical hatch.*/
101  a2dFIRST_HATCH = a2dFILL_BDIAGONAL_HATCH,
102  a2dLAST_HATCH = a2dFILL_VERTICAL_HATCH,
103  a2dFILL_TWOCOL_BDIAGONAL_HATCH, /*!< Backward diagonal hatch.*/
104  a2dFILL_TWOCOL_CROSSDIAG_HATCH, /*!< Cross-diagonal hatch.*/
105  a2dFILL_TWOCOL_FDIAGONAL_HATCH, /*!< Forward diagonal hatch.*/
106  a2dFILL_TWOCOL_CROSS_HATCH, /*!< Cross hatch.*/
107  a2dFILL_TWOCOL_HORIZONTAL_HATCH, /*!< Horizontal hatch.*/
108  a2dFILL_TWOCOL_VERTICAL_HATCH, /*!< Vertical hatch.*/
109  a2dFIRST_TWOCOL_HATCH = a2dFILL_TWOCOL_BDIAGONAL_HATCH,
110  a2dLAST_TWOCOL_HATCH = a2dFILL_TWOCOL_VERTICAL_HATCH,
111  a2dFILL_STIPPLE, /*!< Use the stipple bitmap.*/
112  a2dFILL_STIPPLE_MASK_OPAQUE, /*!< Use the stipple bitmap.*/
113  a2dFILL_STIPPLE_MASK_OPAQUE_TRANSPARENT, /*!< Use the stipple bitmap.*/
114  a2dFILL_GRADIENT_FILL_XY_LINEAR, /*!< linear scan from colour 1 to colour two .*/
115  a2dFILL_GRADIENT_FILL_XY_RADIAL, /*!< circular scan from colour 1 to colour two .*/
116  a2dFILL_GRADIENT_FILL_XY_DROP, /*!< sort of side scan from colour 1 to colour two .*/
117  a2dFILL_INHERIT, /*!< Use the style of the parent object*/
118  a2dFILL_LAYER, /*!< Use the style of the layer from the layersettings */
119  a2dFILL_NULLFILL /*!< special NULL fill used for a2dNullFill */
120 };
121 
122 //! for a2dFill to define the type of filling.
123 /*!
124  \ingroup style
125 */
127 {
128  a2dFILL_NULL, /*!< null type */
129  a2dFILL_ONE_COLOUR, /*!< one colour */
130  a2dFILL_HATCH_TWO_COLOUR, /*!< two colour hatch*/
131  a2dFILL_GRADIENT_FILL_LINEAR, /*!< linear scan from colour one to colour two */
132  a2dFILL_GRADIENT_FILL_RADIAL, /*!< circular scan from colour one to colour two */
133  a2dFILL_BITMAP, /*!< using a bitmap */
134 };
135 
136 /*!
137  To set fill on a2dDrawer2D and a2dCanvasObject classes.
138 
139  When style is set a2dFILL_TRANSPARENT, the rest of the fill data is preserved until style is changed.
140 
141  \ingroup property style
142 */
143 class A2DARTBASEDLLEXP a2dFill : public wxObject
144 {
145 
146 #ifdef CLASS_MEM_MANAGEMENT
147  //! memory manager for speed up to replace system calls allocation and deallocation
148  static a2dMemManager sm_memManager;
149 public:
150  //! overloaded operator new for this class and all it's derived classes
151  void* operator new( size_t bytes )
152  {
153  return sm_memManager.Allocate( bytes );
154  }
155 
156  //! overloaded operator delete for this class and all it's derived classes
157  /*!
158  This function doesn't free to OS-system memory block by pointer 'space'.
159  It adds memory block by pointer 'space' to internal lists.
160  It is speed up.
161  */
162  void operator delete( void* space, size_t bytes )
163  {
164  sm_memManager.Deallocate( space, bytes );
165  }
166 #endif //CLASS_MEM_MANAGEMENT
167 
168 public:
169 
170  //!constructor
171  a2dFill( void );
172 
173  a2dFill( const a2dFill& fill );
174 
175  a2dFill( const wxBrush& brush );
176 
177  a2dFill( const wxColour& col, a2dFillStyle style = a2dFILL_SOLID );
178 
179  a2dFill( const wxColour& col, const wxColour& col2, a2dFillStyle style );
180 
181  a2dFill( const wxBitmap& stipple, a2dFillStyle style = a2dFILL_STIPPLE );
182 
183  a2dFill( const wxBitmap& stipple, const wxColour& col, const wxColour& col2, a2dFillStyle style = a2dFILL_STIPPLE );
184 
185  a2dFill( const wxFileName& filename, a2dFillStyle style = a2dFILL_STIPPLE );
186 
187  a2dFill( const wxFileName& filename, const wxColour& col, const wxColour& col2, a2dFillStyle style = a2dFILL_STIPPLE );
188 
189  a2dFill( const wxColour& col, const wxColour& col2,
190  double x1, double y1, double x2, double y2 );
191 
192  a2dFill( const wxColour& col, const wxColour& col2,
193  double xfc, double yfc, double xe, double ye, double radius );
194 
195  bool operator==( const a2dFill& a )
196  {
197  return m_refData == a.m_refData;
198  }
199 
200  bool operator!=( const a2dFill& a )
201  {
202  return m_refData != a.m_refData;
203  }
204 
205  friend inline bool operator==( const a2dFill& a, const a2dFill& b )
206  {
207  return a.m_refData == b.m_refData;
208  }
209 
210  friend inline bool operator!=( const a2dFill& a, const a2dFill& b )
211  {
212  return a.m_refData != b.m_refData;
213  }
214 
215  a2dFill& UnShare();
216 
217  wxObjectRefData* CreateRefData() const;
218 
219  wxObjectRefData* CloneRefData( const wxObjectRefData* data ) const;
220 
221  //!destructor
222  virtual ~a2dFill( void );
223 
224  a2dFillType GetType( void ) const;
225 
226  a2dFillStyle GetStyle() const;
227 
228  void SetStyle( a2dFillStyle style );
229 
230  a2dFillType GetTypeForStyle( a2dFillStyle style ) const;
231 
232  void SetStipple( const wxBitmap& stipple );
233 
234  const wxBitmap& GetStipple() const;
235 
236  //! return colour
237  wxColour GetColour() const;
238 
239  //! return colour 2
240  wxColour GetColour2() const;
241 
242  //! set colour used for gradient and wxSTIPPLE_MASK_OPAQUE filling.
243  void SetColour( const wxColour& col );
244 
245  //! set colour 2 used for gradient and wxSTIPPLE_MASK_OPAQUE filling.
246  void SetColour2( const wxColour& col );
247 
248  void SetAlpha( wxUint8 val );
249  wxUint8 GetAlpha() const;
250 
251  //!Get start for gradient fill colour change
252  a2dPoint2D GetStart() const;
253 
254  //!Get stop for gradient fill colour change
255  a2dPoint2D GetStop() const;
256 
257  //! time stamp gradient fill
258  wxUint32 GetStamp() const;
259 
260  //!Get start for gradient fill colour change
261  a2dPoint2D GetCenter() const;
262 
263  //!Get start for gradient fill colour change
264  a2dPoint2D GetFocal() const;
265 
266  //!Get stop for gradient fill colour change
267  double GetRadius() const;
268 
269  //! used to define fills that are not yielding (either need to be deleted,
270  //! or indicate that there is no fill defined for an object.
271  //! This is can be used on any fill. This method, is handy since one can still clone
272  //! such fills.
273  bool IsNoFill() const { return m_refData == NULL; }
274 
275  //! from now one this object defines as if no stroke is defined of the object having this stroke.
276  a2dFill* SetNoFill() { UnRef(); return this; }
277 
278  //! is set true, filling is on else filling is transparent.
279  //! This is to quickly switch to filling or not, without changing style.
280  void SetFilling( bool OnOff );
281 
282  //! if true, filling is on else filling is transparent.
283  bool GetFilling() const;
284 
285  DECLARE_DYNAMIC_CLASS( a2dFill )
286 
287 #if wxART2D_USE_CVGIO
288  virtual void Load( wxObject* parent, a2dIOHandlerXmlSerIn& parser );
289  virtual void Save( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dObjectList* towrite );
290 #endif //wxART2D_USE_CVGIO
291 
292 };
293 
294 //! stroke styles for a2dStroke
295 /*!
296  \ingroup style
297 */
299 {
300  a2dSTROKE_TRANSPARENT, /*!< No stroke is used.*/
301  a2dSTROKE_SOLID, /*!< Solid style. */
302  a2dSTROKE_DOT, /*!< Dotted style.*/
303  a2dSTROKE_LONG_DASH, /*!< Long dashed style.*/
304  a2dSTROKE_SHORT_DASH, /*!< Short dashed style.*/
305  a2dSTROKE_DOT_DASH, /*!< Dot and dash style.*/
306  a2dSTROKE_USER_DASH, /*!< Use the user dashes*/
307  a2dSTROKE_BDIAGONAL_HATCH, /*!< Backward diagonal hatch.*/
308  a2dSTROKE_CROSSDIAG_HATCH, /*!< Cross-diagonal hatch.*/
309  a2dSTROKE_FDIAGONAL_HATCH, /*!< Forward diagonal hatch.*/
310  a2dSTROKE_CROSS_HATCH, /*!< Cross hatch.*/
311  a2dSTROKE_HORIZONTAL_HATCH, /*!< Horizontal hatch.*/
312  a2dSTROKE_VERTICAL_HATCH, /*!< Vertical hatch.*/
313  a2dSTROKE_STIPPLE, /*!< Use the stipple bitmap.*/
314  a2dSTROKE_STIPPLE_MASK_OPAQUE, /*!< Use the stipple bitmap.*/
315  a2dSTROKE_STIPPLE_MASK_OPAQUE_TRANSPARENT, /*!< Use the stipple bitmap.*/
316  a2dSTROKE_OBJECTS, /*!< Use a a2dCanvasObject. */
317  a2dSTROKE_INHERIT, /*!< Use the style of the parent object*/
318  a2dSTROKE_LAYER, /*!< Use the style of the layer from the layersettings */
319  a2dSTROKE_NULLSTROKE /*!< special NULL fill used for a2dNullStroke */
320 };
321 
322 //! stroke types
323 //! TODO ( only Xwindows ) a2dPatternStroke(const wxBitmap& stipple, double width);
324 //! TODO ( only Xwindows ) a2dPatternStroke(const wxBitmap& stipple, int width);
326 {
327  a2dSTROKE_NULL,
328  a2dSTROKE_OBJECT,
329  a2dSTROKE_NORMAL, /*!< not using a bitmap or gradient */
330  a2dSTROKE_ONE_COLOUR, /*!< one colour */
331  //a2dSTROKE_GRADIENT_FILL_LINEAR, /*!< linear scan from colour one to colour two */
332  //a2dSTROKE_GRADIENT_FILL_RADIAL, /*!< circular scan from colour one to colour two */
333  a2dSTROKE_BITMAP, /*!< using a bitmap */
334 };
335 
336 typedef float a2dDash;
337 
338 #if !wxCHECK_VERSION(2,9,0)
339 typedef int wxPenJoin;
340 typedef int wxPenCap;
341 typedef int wxPolygonFillMode;
342 typedef int wxRasterOperationMode;
343 
344 // NOTE: these values cannot be combined together!
345 enum wxBrushStyle
346 {
347  wxBRUSHSTYLE_INVALID = -1,
348 
349  wxBRUSHSTYLE_SOLID = wxSOLID,
350  wxBRUSHSTYLE_TRANSPARENT = wxTRANSPARENT,
351  wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE = wxSTIPPLE_MASK_OPAQUE,
352  wxBRUSHSTYLE_STIPPLE_MASK = wxSTIPPLE_MASK,
353  wxBRUSHSTYLE_STIPPLE = wxSTIPPLE,
354  wxBRUSHSTYLE_BDIAGONAL_HATCH = wxBDIAGONAL_HATCH,
355  wxBRUSHSTYLE_CROSSDIAG_HATCH = wxCROSSDIAG_HATCH,
356  wxBRUSHSTYLE_FDIAGONAL_HATCH = wxFDIAGONAL_HATCH,
357  wxBRUSHSTYLE_CROSS_HATCH = wxCROSS_HATCH,
358  wxBRUSHSTYLE_HORIZONTAL_HATCH = wxHORIZONTAL_HATCH,
359  wxBRUSHSTYLE_VERTICAL_HATCH = wxVERTICAL_HATCH,
360  wxBRUSHSTYLE_FIRST_HATCH = wxFIRST_HATCH,
361  wxBRUSHSTYLE_LAST_HATCH = wxLAST_HATCH
362 };
363 
364 #endif
365 
366 //! Base class for all types of strokes, understood by a2dDrawer2D classes.
367 /*!
368 Any shape that needs to be stroked gets a a2dStroke derived class set for it.
369 The derived classes define the way the stroking is done.
370 The a2dCanvasView class needs to understand the different styles of stroking.
371 
372 The stroke can be set to be of pixel type,
373 which means it is a fixed size in pixels.
374 Depending on the constructor used a pixel or non pixel stroke will be created.
375 
376  \ingroup property style
377 */
378 class A2DARTBASEDLLEXP a2dStroke : public wxObject
379 {
380 #ifdef CLASS_MEM_MANAGEMENT
381 
382  //! memory manager for speed up to replace system calls allocation and deallocation
383  static a2dMemManager sm_memManager;
384 public:
385  //! overloaded operator new for this class and it all derived classes
386  void* operator new( size_t bytes )
387  {
388  return sm_memManager.Allocate( bytes );
389  }
390 
391  //! overloaded operator delete for this class and it all derived classes
392  /*!
393  This function doesn't free to OS-system memory block by pointer 'space'.
394  It adds memory block by pointer 'space' to internal lists.
395  It is speed up.
396  */
397  void operator delete( void* space, size_t bytes )
398  {
399  sm_memManager.Deallocate( space, bytes );
400  }
401 #endif //CLASS_MEM_MANAGEMENT
402 
403 public:
404 
405  //!constructor
406  a2dStroke( void );
407 
408  a2dStroke( const wxColour& col, a2dStrokeStyle style = a2dSTROKE_SOLID );
409 
410  a2dStroke( const wxColour& col, double width, a2dStrokeStyle style = a2dSTROKE_SOLID );
411 
412  //!width defined in world coordinates.
413  a2dStroke( const wxColour& col, int width, a2dStrokeStyle style = a2dSTROKE_SOLID );
414 
415  a2dStroke( const wxBitmap& stipple, a2dStrokeStyle style = a2dSTROKE_STIPPLE );
416 
417  a2dStroke( const wxBitmap& stipple, const wxColour& col, const wxColour& col2, a2dStrokeStyle style = a2dSTROKE_STIPPLE );
418 
419  a2dStroke( const wxFileName& filename, a2dStrokeStyle style = a2dSTROKE_STIPPLE );
420 
421  a2dStroke( const wxFileName& filename, const wxColour& col, const wxColour& col2, a2dStrokeStyle style = a2dSTROKE_STIPPLE );
422 
423  //!constructor
424  a2dStroke( const a2dStroke& stroke );
425 
426  //!width gets defined in pixels.
427  a2dStroke( const wxPen& stroke );
428 
429  //!destructor
430  virtual ~a2dStroke( void );
431 
432  a2dStroke& UnShare();
433 
434  bool operator==( const a2dStroke& a )
435  {
436  return m_refData == a.m_refData;
437  }
438 
439  bool operator!=( const a2dStroke& a )
440  {
441  return m_refData != a.m_refData;
442  }
443 
444  friend inline bool operator==( const a2dStroke& a, const a2dStroke& b )
445  {
446  return a.m_refData == b.m_refData;
447  }
448 
449  friend inline bool operator!=( const a2dStroke& a, const a2dStroke& b )
450  {
451  return a.m_refData != b.m_refData;
452  }
453 
454  wxObjectRefData* CreateRefData() const;
455 
456  wxObjectRefData* CloneRefData( const wxObjectRefData* data ) const;
457 
458  virtual a2dStrokeType GetType( void ) const;
459 
460  void SetStipple( const wxBitmap& stipple );
461 
462  const wxBitmap& GetStipple() const;
463 
464  //! return colour 1
465  wxColour GetColour() const;
466 
467  //! set colour used for gradient and wxSTROKE_MASK_OPAQUE filling.
468  void SetColour( const wxColour& col );
469 
470  //! return colour 2
471  wxColour GetColour2() const;
472 
473  //! set colour 2 used for gradient and wxSTROKE_MASK_OPAQUE filling.
474  void SetColour2( const wxColour& col );
475 
476  void SetJoin( wxPenJoin join_style );
477 
478  void SetCap( wxPenCap cap_style );
479 
480  wxPenCap GetCap() const;
481 
482  wxPenJoin GetJoin() const;
483 
484  //!Set width of stroke in world coordinates.
485  void SetWidth( float width );
486 
487  //!Get width of stroke in world or device coordinates.
488  //!(depending on pixel or non pixel stroke).
489  float GetWidth() const;
490  float GetExtend() const;
491 
492  //!set pixelstoke flag, stroke width is defined in pixels else in worldcoordinates
493  void SetPixelStroke( bool pixelstroke );
494 
495  //!if the width is pixels or not.
496  bool GetPixelStroke() const;
497 
498  void SetAlpha( wxUint8 val );
499 
500  wxUint8 GetAlpha() const;
501 
502  a2dStrokeStyle GetStyle() const;
503 
504  void SetStyle( a2dStrokeStyle style );
505 
506  //! used to define strokes that are not yielding (either need to be deleted,
507  //! or indicate that there is no stroke defined for an object.
508  //! This is can be used on any stroke. This method, is handy since one can still clone
509  //! such strokes.
510  bool IsNoStroke() const { return m_refData == NULL; }
511 
512  //! from now one this object defines as if no stroke is defined of the object having this stroke.
513  a2dStroke* SetNoStroke() { UnRef(); return this; }
514 
515  a2dStrokeType GetTypeForStyle( a2dStrokeStyle style ) const;
516 
517  DECLARE_DYNAMIC_CLASS( a2dStroke )
518 
519 #if wxART2D_USE_CVGIO
520  virtual void Load( wxObject* parent, a2dIOHandlerXmlSerIn& parser );
521  virtual void Save( wxObject* parent, a2dIOHandlerXmlSerOut& out, a2dObjectList* towrite );
522 #endif //wxART2D_USE_CVGIO
523 
524 };
525 
526 //----------------------------------------------------------------------------
527 // a2dFont
528 //----------------------------------------------------------------------------
529 
530 enum a2dFontType
531 {
532  a2dFONT_NULL,
533  a2dFONT_WXDC,
534  a2dFONT_FREETYPE,
535  a2dFONT_STROKED,
536 };
537 
538 #if defined(__WXMSW__)
539 #define __USE_WINAPI__
540 #endif
541 
543 //! A list of pointers to vertexlists. Ends with NULL.
544 typedef a2dVertexList** a2dStrokeGlyph;
545 
546 #if !wxART2D_USE_FREETYPE
547 // in case freetype is not used, define replacement types.
548 typedef void* FT_Glyph;
549 typedef void* FT_Vector;
550 typedef void* FT_Face;
551 typedef unsigned int FT_UInt;
552 #endif // wxART2D_USE_FREETYPE
553 
554 //! wxChar hashing function, used in hash maps.
555 /*!
556  \ingroup textrelated
557 */
558 class A2DARTBASEDLLEXP a2dCharHash
559 {
560 public:
561  a2dCharHash() { }
562  unsigned long operator()( const wxChar& k ) const
563  { return ( unsigned long ) k; }
564  a2dCharHash& operator=( const a2dCharHash& ) { return * this; }
565 };
566 //! wxChar equality class, used in hash maps.
567 /*!
568  \class a2dCharEqual stylebase.h artbase/stylebase.h
569  \ingroup textrelated
570 */
571 class A2DARTBASEDLLEXP a2dCharEqual
572 {
573 public:
574  a2dCharEqual() { }
575  bool operator()( const wxChar& a, const wxChar& b ) const
576  { return ( a == b ); }
577  a2dCharEqual& operator=( const a2dCharEqual& ) { return * this; }
578 };
579 
580 //! holes one glyph from a freetype font.
581 struct A2DARTBASEDLLEXP a2dGlyph
582 {
583 #if wxART2D_USE_FREETYPE
584  FT_UInt m_index;
585  FT_Glyph m_glyph;
586  FT_Int m_lsb;
587  FT_Int m_rsb;
588  FT_Face m_face;
589 #endif
590 
591  a2dGlyph()
592  {
593 #if wxART2D_USE_FREETYPE
594  m_index = ( FT_UInt ) - 1; m_glyph = NULL;
595 #endif
596  }
597  ~a2dGlyph()
598  {
599 #if wxART2D_USE_FREETYPE
600  if( m_glyph )
601  FT_Done_Glyph( m_glyph );
602 #endif
603  }
604 };
605 
606 /*! \class FT_GlyphHash stylebase.h artbase/stylebase.h
607  \brief A hash map, used for storage of freetype glyphs.
608  \ingroup textrelated
609 */
610 WX_DECLARE_HASH_MAP_WITH_DECL( wxChar, a2dGlyph, a2dCharHash, a2dCharEqual, a2dGlyphHash, class A2DARTBASEDLLEXP );
611 
612 
613 /*! \class DcWidthHash stylebase.h artbase/stylebase.h
614  \brief A hash map, used for storage of character widths of a font
615  \ingroup textrelated
616 */
617 WX_DECLARE_HASH_MAP_WITH_DECL( wxChar, double, a2dCharHash, a2dCharEqual, DcWidthHash, class A2DARTBASEDLLEXP );
618 
619 /*! \class DcKerningHash stylebase.h artbase/stylebase.h
620  \brief A hash map, used for storage of kerning between characters of a font
621  \ingroup textrelated
622 */
623 WX_DECLARE_HASH_MAP_WITH_DECL( wxString, double, wxStringHash, wxStringEqual, DcKerningHash, class A2DARTBASEDLLEXP );
624 
625 //! wxMINY and wxMAXY is defined as lowest and highest of a string boundingbox.
626 //! Understand on the canvas y axis can be up or down, but text is always written up.
627 //! Still de size and position of the boundingbox in wordl coordinates stays the same.
628 //! Fontsize is defined by EM square in world coordinates. And is NOT the highest Y all glyphs en lowest Y.
629 //! wxMINX (baseline start just before first character)
630 //! wxMAXX (baseline end after last character)
631 //! else middle of baseline, being width/2
632 //! wxBASELINE text origin at baseline
633 //! wxBASELINE_CONTRA text origin at baseline but seen from top of boundingbox
634 //! wxMINY lowest Y of bbox.
635 //! wxMAXY highest Y of bbox.
636 //! else middle Bbox in Y.
638 {
639  wxMIDY = 0x0000,
640  wxMIDX = wxMIDY,
641  wxMINX = 0x0001,
642  wxMAXX = 0x0002,
643  wxMINY = 0x0004,
644  wxMAXY = 0x0008,
645  wxBASELINE = 0x0010,
646  wxBASELINE_CONTRA = 0x0020,
647  a2dDEFAULT_ALIGNMENT = wxMAXY | wxMINX
648 };
649 
650 class a2dFont;
651 
652 //! Font info class, used as a single element for enumerating fonts.
653 /*!
654  The a2dFontInfo class is used as a font description class. Fonts can be generated from
655  this. It is also used for saving and loading a font.
656 
657  This class consists of six items
658  - type currently "Device Font", "Freetype Font" or "Stroke Font", but more might be added in the future.
659  - fontname: names like "Arial", "Courier New", etc.
660  - style: Font type dependant, e.g. "Bold Italic" or "Pixel Stroke".
661  - size: size in world coordinates.
662  - extra: This is used for extra information, e.g. the filename of the font.
663 
664  When a font description in string form is needed call CreateString(). (or the other way with
665  ParseString() ).
666 
667  This will create a string in the form of "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where
668  FAMILY-LIST is a comma separated list of families optionally terminated by a comma,
669  STYLE_OPTIONS is a whitespace separated list of words where each WORD describes one of
670  style, variant, weight, or stretch, and
671  SIZE is an decimal number (size in points). Any one of the options may be absent.
672  If FAMILY-LIST is absent, then the family_name field of the resulting font description will be
673  initialized to NULL. If STYLE-OPTIONS is missing, then all style options will be set to the
674  default values. If SIZE is missing, the size in the resulting font description will be set to 0.
675 
676  The string representation is compatible with the pango font descriptions.
677 
678  e.g.
679 
680  Device font-Arial For CAE-Light Italic-300.000000-
681 
682  Freetype font-Book Antiqua-Bold Italic-300.000000--ANTQUABI.TTF
683 
684  \ingroup style textrelated
685 */
686 class A2DARTBASEDLLEXP a2dFontInfo
687 {
688 public:
689  //! Constructor
691  //! Constructor
692  a2dFontInfo( const wxString& type, const wxString& name, const wxString& style = wxT( "" ),
693  double size = 1.0, const wxString& extra = wxT( "" ) );
694  //! Constructor
695  a2dFontInfo( const wxString& type, const wxString& name,
696  const wxString& style, const wxString& extra = wxT( "" ) );
697  //! Constructor
698  a2dFontInfo( const wxString& info );
699 
700  //! Assignment operator.
701  a2dFontInfo& operator=( const a2dFontInfo& other );
702 
703  //! Comparison operator.
704  bool operator == ( const a2dFontInfo& other ) const;
705 
706  //! Create this enumerated font
707  /*! This function will allways return a valid font. NULL will never be returned
708  */
709  a2dFont CreateFont( double size );
710 
711  //! Get type of font, e.g. Freetype or Stroke.
712  inline const wxString& GetType() const { return m_type; }
713  //! Set type of font, e.g. Freetype or Stroke.
714  inline void SetType( const wxString& type ) { m_type = type; }
715 
716  //! Get name of font, e.g. Arial.
717  inline const wxString& GetName() const { return m_name; }
718  //! Set name of font, e.g. Arial.
719  inline void SetName( const wxString& name ) { m_name = name; }
720 
721  //! Get style of font, e.g. Bold.
722  inline const wxString& GetStyle() const { return m_style; }
723  //! Set style of font, e.g. Bold.
724  inline void SetStyle( const wxString& style ) { m_style = style; }
725 
726  //! Get size of the font.
727  inline double GetSize() const { return m_size; }
728  //! Set size of the font.
729  /*!
730  Sets the size of the EM square in world coordinates. Characters/glyphs are designed on this square.
731  Glyphs can be bigger than it.
732  See freetype documentation.
733  The EM sqaure is often 2048 (font units) in size, meaning it has thus resolution.
734  */
735  inline void SetSize( double size ) { m_size = size; }
736 
737  //! Assemble a string containing this class in a readable format.
738  wxString CreateString() const;
739 
740  //! Fill this class from a string.
741  void ParseString( wxString string );
742 
743  //! Get the extra information ( e.g. the filename of the font )
744  inline const wxString& GetExtra() const { return m_extra; }
745 
746  //! Set the extra information ( e.g. the filename of the font )
747  inline void SetExtra( const wxString& extra ) { m_extra = extra; }
748 
749 protected:
750  //! Font type.
751  wxString m_type;
752  //! Font name.
753  wxString m_name;
754  //! Font style.
755  wxString m_style;
756  //! Font Size.
757  double m_size;
758  //! Extra information (e.g. the filename of the font).
759  wxString m_extra;
760 };
761 
762 /*! \class a2dFontInfoList stylebase.h artbase/stylebase.h
763  \brief A list used for enumerating fonts.
764  \sa a2dFontInfo
765  \ingroup textrelated
766 */
767 WX_DECLARE_LIST_WITH_DECL( a2dFontInfo, a2dFontInfoList, class A2DARTBASEDLLEXP );
768 
769 //----------------------------------------------------------------------------
770 // a2dFont
771 //----------------------------------------------------------------------------
772 
773 //! Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
774 /*!
775  There are 3 types of fonts as in a2dFontType. The a2dDrawer2D classes know how to draw strings with these fonts.
776 
777  \ingroup style textrelated
778 */
779 class A2DARTBASEDLLEXP a2dFont : public wxObject
780 {
781 public:
782 
783  a2dFontType GetType( void ) const;
784 
785  //! Constructor.
786  a2dFont();
787 
788  //! Copy constructor.
789  a2dFont( const a2dFont& other );
790 
791  //! Constructor.
792  /*! This constructor tries to locate the font file, belonging to the wxFont class, which
793  is then used for drawing. At present only a Windows version is implemented.
794  \param font Font format. The size of the font is not used and should be set using the next parameter.
795  \param size Size in world coordinates.
796  \param encoding endocing of font
797  */
798  a2dFont( const wxFont& font, double size, a2dFontType type = a2dFONT_WXDC, wxFontEncoding encoding = wxFONTENCODING_DEFAULT );
799 
800  //! Constructor
801  /*!
802  Creates a font object (see font encoding overview, in the wxWidgets documentation, for the meaning of the last parameter).
803  \param size Size in world coordinates.
804  \param family Font family, a generic way of referring to fonts without specifying actual facename. One of:
805  - wxDEFAULT Chooses a default font.
806  - wxDECORATIVE A decorative font.
807  - wxROMAN A formal, serif font.
808  - wxSCRIPT A handwriting font.
809  - wxSWISS A sans-serif font.
810  - wxMODERN A fixed pitch font.
811  \param style One of wxNORMAL, wxSLANT and wxITALIC.
812  \param weight One of wxNORMAL, wxLIGHT and wxBOLD.
813  \param underline The value can be true or false. At present this has an effect on Windows and Motif 2.x only.
814  \param faceName An optional string specifying the actual typeface to be used. If the empty string, a default typeface will chosen based on the family.
815  \param encoding An encoding which may be one of
816  - wxFONTENCODING_SYSTEM Default system encoding.
817  - wxFONTENCODING_DEFAULT Default application encoding.
818  - wxFONTENCODING_ISO8859_1...15 ISO8859 encodings.
819  - wxFONTENCODING_KOI8 The standard Russian encoding for Internet.
820  - wxFONTENCODING_CP1250...1252 Windows encodings similar to ISO8859 (but not identical).
821 
822  If the specified encoding isn't available, no font is created.
823 
824  wxFONTENCODING_DEFAULT is the encoding set by calls to SetDefaultEncoding and which
825  may be set to, say, KOI8 to create all fonts by default with KOI8 encoding. Initially,
826  the default application encoding is the same as default system encoding.
827  \remark
828  - If the desired font does not exist, the closest match will be chosen.
829  - Under Windows, only scalable TrueType fonts are used.
830  */
831  a2dFont( double size, int family, int style = wxNORMAL, int weight = wxNORMAL,
832  const bool underline = false, const wxString& faceName = wxT( "" ),
833  wxFontEncoding encoding = wxFONTENCODING_DEFAULT );
834 
835 #if wxART2D_USE_FREETYPE
836  //! constructor of Freetype font based on filename of fontfile.
837  a2dFont( const wxString& filename, double size = 0.0, wxFontEncoding encoding = wxFONTENCODING_DEFAULT, int faceindex = 0 );
838 #endif
839 
840  //! constructor of stroked font based on filename of fontfile. See a2dFontStrokeData
841  a2dFont( const wxString& filename, double size, bool monoSpaced, double weight = 0.0 );
842 
843  //! Destructor.
844  virtual ~a2dFont();
845 
846  //! return true if the same font (same reference)
847  bool operator==( const a2dFont& a )
848  {
849  return m_refData == a.m_refData;
850  }
851 
852  //! return true if not the same font (same reference)
853  bool operator!=( const a2dFont& a )
854  {
855  return m_refData != a.m_refData;
856  }
857 
858  //! return true if the same font (same reference)
859  friend inline bool operator==( const a2dFont& a, const a2dFont& b )
860  {
861  return a.m_refData == b.m_refData;
862  }
863 
864  //! return true if not the same font (same reference)
865  friend inline bool operator!=( const a2dFont& a, const a2dFont& b )
866  {
867  return a.m_refData != b.m_refData;
868  }
869 
870  //! Check font validity.
871  /*! \return True if this object is a valid font, false otherwise.
872  */
873  bool Ok() const;
874 
875  //! Get fontinfo of the font
876  const a2dFontInfo& GetFontInfo() const;
877 
878  //! Set the font size.
879  /*! \param size Font size in world coordinates. */
880  void SetSize( double size );
881 
882  //! Get the font size.
883  /*! \return The font size in world coordinates */
884  double GetSize() const;
885 
886  //! Get the line height.
887  /*! The line height is calculated from the text bounding box.
888  \return The line height in world coordinates.
889  */
890  double GetLineHeight() const;
891 
892  //! Get descent
893  /*! The descent is the distance from the basline to the bottom of the bounding box.
894  \return The descent in world coordinates.
895  */
896  double GetDescent() const;
897 
898  //! Get width of a single character
899  double GetWidth( wxChar c );
900 
901  //! Get kerning space between two characters.
902  /*! Kerning is a method, which moves characters closer together/further apart, to
903  improve the look of the font. Eg. the letter combination LT will be moved closer together.
904  The return value is negative or positive, to respectively move characters closer together, or further
905  apart.
906  */
907  double GetKerning( wxChar WXUNUSED( c1 ), wxChar WXUNUSED( c2 ) ) const;
908 
909  //! Get stroke width.
910  /*!
911  \return The stroke width in world coordinates. In case of a pixel font, 0.0 is returned.
912  \sa GetWeight()
913  */
914  double GetStrokeWidth() const;
915 
916  //! Get the glyph of a single character.
917  /*! \return The glyph of the character, in a coordinate space, normalized to the font size.
918  */
919  a2dStrokeGlyph GetGlyphStroke( wxChar c ) const;
920 
921  const a2dGlyph* GetGlyphFreetype( wxChar c ) const;
922 
923  void SetDeviceHeight( double sizeInPixels );
924 
925  double GetDeviceHeight();
926 
927 #if wxART2D_USE_FREETYPE && defined(__USE_WINAPI__)
928  //! Get the freetype equivalent of the font
929  a2dFont GetFreetypeFont();
930 #endif
931 
932  //! wxFont in case of a2dFONT_WXDC
933  wxFont& GetFont( void );
934 
935  //! Get the dimensions in world coordinates of the string.
936  /*! \param string The text string to measure (should be a single line of text).
937  \param alignment Alignment of the text (eg. wxLEFT)
938  \param w Total width in world coordinates.
939  \param h Total height in world coordinates.
940  \param descent The dimension from the baseline of the font to the bottom of the descender in
941  world coordinates.
942  \param externalLeading Any extra vertical space added to the font by the font designer in
943  world coordinates (usually is zero).
944  \return A bounding box, with the anchor point positioned at (0, 0).
945  */
946  a2dBoundingBox GetTextExtent( const wxString& string,
947  int alignment = wxMINX | wxMINY, double* w = NULL,
948  double* h = NULL, double* descent = NULL,
949  double* externalLeading = NULL ) const;
950 
951  //! Get the dimensions in world coordinates of the string.
952  /*! \param string The text string to measure (should be a single line of text).
953  \param w Total width in world coordinates.
954  \param h Total height in world coordinates.
955  \param descent The dimension from the baseline of the font to the bottom of the descender in
956  world coordinates.
957  \param externalLeading Any extra vertical space added to the font by the font designer in
958  world coordinates (usually is zero).
959  */
960  void GetTextExtent( const wxString& string, double& w, double& h,
961  double& descent, double& externalLeading ) const;
962 
963  //! Get the dimensions in world coordinates of the string.
964  /*! \param string The text string to measure (should be a single line of text).
965  \param w Total width in world coordinates.
966  \param h Total height in world coordinates.
967  */
968  void GetTextExtentWH( const wxString& string, double& w, double& h ) const;
969 
970  bool GetPartialTextExtents ( const wxString& text, wxArrayInt& widths ) const;
971 
972  //! Get the glyph of a single character as a vpath.
973  /*! The position, indicated by x and y, is the lowerleft bbox corner of the glyph.
974  \param c The character.
975  \param glyph A vectorpath, to which the glyph is added.
976  \param affine Position etc., where the glyph is constructed.
977  \return A boolean, indicating if the glyph was succesfully added.
978  */
979  bool GetVpath( wxChar c, a2dVpath& glyph, const a2dAffineMatrix& affine = a2dIDENTITY_MATRIX );
980 
981  //! Render a text string into a vector path
982  /*! The position, indicated by x and y, is the lowerleft bbox corner of the text.
983  \param text The string to render.
984  \param vpath The vectorpath, to which the string is rendered
985  \param x Position, where the string is constructed.
986  \param y Position, where the string is constructed.
987  \param alignment how to position text relative top position
988  \param yaxis up or down text
989  \param affine Position etc., where the text is constructed.
990  */
991  void GetVpath( const wxString& text, a2dVpath& vpath, double x = 0, double y = 0, int alignment = wxMINX | wxMINY, bool yaxis = true, const a2dAffineMatrix& affine = a2dIDENTITY_MATRIX );
992 
993  // Documented in base class
994  bool AlwaysWriteSerializationId() const { return true; }
995 
996  //! Append fonts of this type to the list
997  /*! Using a2dFont::GetInfoList(list), will enumerate all fonts, of all types
998  */
999  static void GetInfoList( a2dFontInfoList& list );
1000 
1001  //! Create the font from a fontinfo description.
1002  /*! The a2dFont::CreateFont will allways return a valid font. The derived fonts should
1003  return NULL.
1004 
1005  This routine will first try to find the exact font, as described in the fontinfo. If it does
1006  not find this font, it will try to create any font of any font type, that matches part of the
1007  string. eg. if a user asks for a dc-font called "Arial Black" and this is not installed on the
1008  system, this routine might return as a replacement a freetype-font called "Arial".
1009 
1010  \param info font info for creating font
1011  \param force This param does not have a function in a2dFont, but it should be used in
1012  its descendants. When force is false, only the exact match should be made. When true, the
1013  routine should try to match any likely candidate.
1014  */
1015  static a2dFont CreateFont( const a2dFontInfo& info, bool force = false );
1016 
1017  //! Create a string description of the font.
1018  /*! \return A string of the format type-name-style-size-alignment(-extra)
1019  */
1020  wxString CreateString();
1021 
1022  //! create a unique string presenting a a2dFONT_FREETYPE type font (see constructor for parameters)
1023  static wxString CreateString( const wxString& filename, double size, wxFontEncoding encoding, int weight );
1024  //! create a unique string presenting a a2dFONT_STROKED type font (see constructor for parameters)
1025  static wxString CreateString( const wxString& filename, double size, bool monoSpaced, double weight );
1026  //! create a unique string presenting a a2dFONT_WXDC type font (see constructor for parameters)
1027  static wxString CreateString( a2dFontType type, const wxFont& font, double size, wxFontEncoding encoding );
1028 
1029  //! Set the font filename and load the font.
1030  /*! \param filename The filename of the font. This may either be a full path, or just the
1031  fontname. In the latter case, the fontpath of a2dGlobals will be used to search the font.
1032  \sa a2dGlobal
1033  */
1034  void SetFilename( const wxString& filename );
1035  //! Get the font filename.
1036  /*! \param filenameonly The returned filename will be stripped of drive-letters and directories.
1037  \return The filename of the font.
1038  */
1039  wxString GetFilename( bool filenameonly = false ) const;
1040 
1041  //! Get the weight of the font.
1042  /*! \return The weight (in this case stroke width) in percentages of the font size. There are two exceptions.
1043  0: Draws the font with a pen of 1 pixel wide. -1: Draws the font with a normalized pen, as the font-designer intended it.
1044  */
1045  double GetWeight() const;
1046 
1047  //! Set the weight of the font.
1048  /*! \param weight The weight (in this case stroke width) in percentages of the font size. There are two exceptions.
1049  0: Draws the font with a pen of 1 pixel wide. -1: Draws the font with a normalized pen, as the font-designer intended it.
1050  */
1051  void SetWeight( double weight );
1052 
1053  //! Set the weight of the font, from a string.
1054  /*! \param weight One of: "Normalized Pen", "Pixel pen" or a string starting with the width in percentages, ending with %.
1055  */
1056  void SetWeight( const wxString& weight );
1057 
1058  //! load method of glyph, see Freetype refence for meaning of FT_LOAD_*
1060  {
1061  a2d_LOAD_DEFAULT = 0x0,
1062  a2d_LOAD_NO_SCALE = 0x1,
1063  a2d_LOAD_NO_HINTING = 0x2,
1064  a2d_LOAD_RENDER = 0x4,
1065  a2d_LOAD_NO_BITMAP = 0x8,
1066  a2d_LOAD_VERTICAL_LAYOUT = 0x10,
1067  a2d_LOAD_FORCE_AUTOHINT = 0x20,
1068  a2d_LOAD_CROP_BITMAP = 0x40,
1069  a2d_LOAD_PEDANTIC = 0x80,
1070  a2d_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH = 0x200,
1071  a2d_LOAD_NO_RECURSE = 0x400,
1072  a2d_LOAD_IGNORE_TRANSFORM = 0x800,
1073  a2d_LOAD_MONOCHROME = 0x1000,
1074  a2d_LOAD_LINEAR_DESIGN = 0x2000,
1075  a2d_LOAD_NO_AUTOHINT = 0x8000U
1076  };
1077 
1078  //! Set the way glyphs are loaded by freetype. Important for small fonts.
1079  //! a2d_LOAD_DEFAULT;
1080  //! a2d_LOAD_DEFAULT | a2d_LOAD_NO_HINTING;
1081  //! a2d_LOAD_DEFAULT | a2d_LOAD_FORCE_AUTOHINT;
1082  static void SetLoadFlags( wxInt32 loadMethodMask );
1083 
1084 
1085  wxObjectRefData* CreateRefData() const;
1086 
1087  wxObjectRefData* CloneRefData( const wxObjectRefData* data ) const;
1088 
1089 #if wxART2D_USE_CVGIO
1090 private:
1091  // Not implemented anymore, please use ...
1092  virtual void Load( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerIn& WXUNUSED( parser ), a2dXmlSer_flag WXUNUSED( xmlparts ) ) {}
1093  virtual void Save( wxObject* WXUNUSED( parent ), a2dIOHandlerXmlSerOut& WXUNUSED( out ), a2dXmlSer_flag WXUNUSED( xmlparts ) , a2dObjectList* WXUNUSED( towrite ) ) {}
1094 #endif //wxART2D_USE_CVGIO
1095 
1096 public:
1097 private:
1098  DECLARE_ABSTRACT_CLASS( a2dFont )
1099 
1100  static void ClearFontCache() { ms_fontCache.clear(); }
1101 
1102  static map< wxString, a2dFont > ms_fontCache;
1103 };
1104 
1105 
1106 /******************************************************************************
1107  predefined style properties
1108 *******************************************************************************/
1109 
1110 //! several predefined style properties
1111 /*! stock style objects
1112  \defgroup stockobjects predefined StyleProperties
1113 
1114  \ingroup property style
1115 */
1116 
1117 //! global a2dFill stock object for WHITE filling
1118 /*! \ingroup stockobjects */
1119 A2DARTBASEDLLEXP_DATA( extern const a2dFill* ) a2dWHITE_FILL;
1120 
1121 //! global a2dFill stock object for BLACK filling
1122 /*! \ingroup stockobjects */
1123 A2DARTBASEDLLEXP_DATA( extern const a2dFill* ) a2dBLACK_FILL;
1124 
1125 //! global a2dFill stock object for TRANSPARENT filling
1126 /*! \ingroup stockobjects */
1127 A2DARTBASEDLLEXP_DATA( extern const a2dFill* ) a2dTRANSPARENT_FILL;
1128 
1129 //! global a2dFill stock object for INHERTED from parent object filling
1130 /*! \ingroup stockobjects */
1131 A2DARTBASEDLLEXP_DATA( extern const a2dFill* ) a2dINHERIT_FILL;
1132 
1133 //! global a2dFill stock object for drawing fill of selected objects
1134 /*! \ingroup stockobjects */
1135 A2DARTBASEDLLEXP_DATA( extern const a2dFill* ) a2dSELECT_FILL;
1136 
1137 //! global a2dFill stock object for defining NO filling
1138 /*! If an a2dCanvasObject's fill is set to a2dNullFILL, it will use the layer
1139 fill, if there is one. If you want to make sure, that no fill is used,
1140 use a2dTRANSPARENT_FILL
1141 \ingroup stockobjects */
1142 A2DARTBASEDLLEXP_DATA( extern const a2dFill* ) a2dNullFILL;
1143 
1144 //! global a2dStroke stock object for BLACK stroking
1145 /*! \ingroup stockobjects */
1146 A2DARTBASEDLLEXP_DATA( extern const a2dStroke* ) a2dBLACK_STROKE;
1147 
1148 //! global a2dStroke stock object for WHITE stroking
1149 /*! \ingroup stockobjects */
1150 A2DARTBASEDLLEXP_DATA( extern const a2dStroke* ) a2dWHITE_STROKE;
1151 
1152 //! global a2dStroke stock object for TRANSPARENT stroking
1153 /*! \see wxNullStroke \ingroup stockobjects */
1154 A2DARTBASEDLLEXP_DATA( extern const a2dStroke* ) a2dTRANSPARENT_STROKE;
1155 
1156 //! global a2dStroke stock object for INHERTED from parent object stroking
1157 /*! \ingroup stockobjects */
1158 A2DARTBASEDLLEXP_DATA( extern const a2dStroke* ) a2dINHERIT_STROKE;
1159 
1160 //! global a2dStroke stock object for NO stroking
1161 /*! If an a2dCanvasObject's stroke is set to a2dNullSTROKE, it will use the layer
1162 stroke, if there is one. If you want to make sure, that no stroke is used,
1163 use a2dTRANSPARENT_STROKE
1164 \ingroup stockobjects */
1165 A2DARTBASEDLLEXP_DATA( extern const a2dStroke* ) a2dNullSTROKE;
1166 
1167 //! global a2dStroke stock object for SELECTED object stroking
1168 /*! \ingroup stockobjects */
1169 A2DARTBASEDLLEXP_DATA( extern const a2dStroke* ) a2dLAYER_SELECT_STROKE;
1170 
1171 //! global a2dFont stock object for NO font
1172 /*! \ingroup stockobjects */
1173 A2DARTBASEDLLEXP_DATA( extern const a2dFont* ) a2dNullFONT;
1174 
1175 //! global a2dFont stock object for default font
1176 /*! \ingroup stockobjects */
1177 A2DARTBASEDLLEXP_DATA( extern const a2dFont* ) a2dDEFAULT_CANVASFONT;
1178 
1179 //! to initialize stock style ( a2dStroke a2dFill ) objects.
1180 /*!
1181  \sa a2dCanvasModule
1182 
1183  \ingroup stockobjects
1184 
1185 */
1186 extern A2DARTBASEDLLEXP void a2dCanvasInitializeStockObjects ();
1187 
1188 //! to delete stock style ( a2dStroke a2dFill ) objects.
1189 /*!
1190  \sa a2dCanvasModule
1191 
1192  \ingroup stockobjects
1193 */
1194 extern A2DARTBASEDLLEXP void a2dCanvasDeleteStockObjects ();
1195 
1196 //!initiates Freetype library
1197 class A2DARTBASEDLLEXP a2dFreetypeModule : public wxModule
1198 {
1199 public:
1200 
1202 
1203  virtual bool OnInit();
1204  virtual void OnExit();
1205 
1206 private:
1207 
1208  DECLARE_DYNAMIC_CLASS( a2dFreetypeModule )
1209 };
1210 
1211 
1212 extern wxString StrokeStyle2String( a2dStrokeStyle style );
1213 extern a2dStrokeStyle StrokeString2Style( const wxString& stylestr );
1214 extern wxString FillStyle2String( a2dFillStyle style );
1215 extern a2dFillStyle FillString2Style( const wxString& stylestr );
1216 
1217 
1218 //===========================================================================
1219 // a2dExtStroke - a2dStroke and flags for validity of its attributes:
1220 //===========================================================================
1221 
1223 {
1224  static bool HasIndividualAttributes(a2dStrokeStyle style);
1225 public:
1226  a2dExtStroke();
1227  a2dExtStroke(const a2dStroke& stroke);
1228 
1229  // Initialises all attributes with <stroke>.
1230  void Set(const a2dStroke& stroke);
1231  // Compares with <stroke> and sets all unequal attributes to invalid.
1232  // Attributes that are still invalid will not compared again.
1233  void Mix(const a2dStroke& stroke);
1234  // Returns the result of setting all valid attributes to <stroke>.
1235  a2dStroke Get(const a2dStroke& stroke) const;
1236 
1237  // Default properties, used by ::Get(...) to initialise new stroke object
1238  // when replacing non-stroke-object style (e.g. 'transparent', 'layer' or 'inherit').
1239  void SetDefault(const a2dStroke& stroke) { m_Default = stroke; }
1240  const a2dStroke& GetDefault() const { return m_Default; }
1241 
1242  // -- style --
1243  void SetStyle(a2dStrokeStyle style);
1244  bool IsStyleValid() const { return m_bStyle; }
1245  a2dStrokeStyle GetStyle() const { return m_Style; }
1246 
1247  // Returns wether stroke attributes are initialised.
1248  bool IsInitialised() const { return m_bInitialised; }
1249 
1250  // Returns wether style has individual, editable attributes.
1251  // E.g. 'transparent', 'layer' or 'inherit' styles have no individual attributes.
1252  bool HasEditableStyle() const { return m_bEditable; }
1253 
1254  // -- color --
1255  void SetColor(const wxColour& color);
1256  bool IsColorValid() const { return m_bColor; }
1257  wxColour GetColor() const { return m_Color; }
1258 
1259  // -- width --
1260  void SetWidth(const float& width);
1261  bool IsWidthValid() const { return m_bWidth; }
1262  float GetWidth() const { return m_Width; }
1263 
1264  // -- cap --
1265  void SetCap(wxPenCap cap);
1266  bool IsCapValid() const { return m_bCap; }
1267  wxPenCap GetCap() const { return m_Cap; }
1268 
1269  // -- join --
1270  void SetJoin(wxPenJoin join);
1271  bool IsJoinValid() const { return m_bJoin; }
1272  wxPenJoin GetJoin() const { return m_Join; }
1273 
1274 private:
1275  void SetAttributes(const a2dStroke& stroke);
1276 
1277 private:
1278  a2dStroke m_Default;
1279 
1280  a2dStrokeStyle m_Style;
1281  wxColour m_Color;
1282  float m_Width;
1283  wxPenCap m_Cap;
1284  wxPenJoin m_Join;
1285 
1286  bool m_bStyle;
1287  bool m_bInitialised;
1288  bool m_bEditable;
1289  bool m_bColor;
1290  bool m_bWidth;
1291  bool m_bCap;
1292  bool m_bJoin;
1293 };
1294 
1295 
1296 //===========================================================================
1297 // a2dExtFill - a2dFill and flag for validity:
1298 //===========================================================================
1299 
1301 {
1302 public:
1303  a2dExtFill();
1304  a2dExtFill(const a2dFill& fill);
1305 
1306  // Initialises with <fill>.
1307  void Set(const a2dFill& fill);
1308  // Compares with <fill> and sets to invalid if unequal.
1309  void Mix(const a2dFill& fill);
1310  // Returns the a2dFill member object if valid, or <fill> instead.
1311  a2dFill Get(const a2dFill& fill) const;
1312 
1313  bool IsValid() const { return m_bFill; }
1314  // Returns the a2dFill member object.
1315  a2dFill Get() const { return m_Fill; }
1316 
1317 private:
1318  a2dFill m_Fill;
1319  bool m_bFill;
1320 };
1321 
1322 #endif /* __STYLEBASE_H__ */
1323 
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
Definition: artglob.h:47
a2dFillStyle FillString2Style(const wxString &stylestr)
convert a string to a style enum
Definition: stylebase.cpp:3455
const a2dFill * a2dSELECT_FILL
global a2dFill stock object for drawing fill of selected objects
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
bool IsNoStroke() const
Definition: stylebase.h:510
const wxString & GetName() const
Get name of font, e.g. Arial.
Definition: stylebase.h:717
Simple Memory manager for some objects which often create and destroy to replace OS-system calls...
Definition: a2dmemmgr.h:20
const a2dStroke * a2dBLACK_STROKE
global a2dStroke stock object for BLACK stroking
Font info class, used as a single element for enumerating fonts.
Definition: stylebase.h:686
fundamental classes used by all other modules.
const a2dFill * a2dINHERIT_FILL
global a2dFill stock object for INHERTED from parent object filling
wxChar hashing function, used in hash maps.
Definition: stylebase.h:558
a2dVertexList ** a2dStrokeGlyph
A list of pointers to vertexlists. Ends with NULL.
Definition: stylebase.h:542
const wxString & GetExtra() const
Get the extra information ( e.g. the filename of the font )
Definition: stylebase.h:744
const a2dFill * a2dBLACK_FILL
global a2dFill stock object for BLACK filling
double GetSize() const
Get size of the font.
Definition: stylebase.h:727
wxChar equality class, used in hash maps.
Definition: stylebase.h:571
wxString m_type
Font type.
Definition: stylebase.h:751
a2dFontAlignment
Definition: stylebase.h:637
Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
Definition: stylebase.h:779
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:819
bool IsNoFill() const
Definition: stylebase.h:273
const a2dFill * a2dWHITE_FILL
global a2dFill stock object for WHITE filling
void a2dCanvasInitializeStockObjects()
to initialize stock style ( a2dStroke a2dFill ) objects.
Definition: stylebase.cpp:3352
a2dAffineMatrix a2dIDENTITY_MATRIX
global a2dAffineMatrix to set/pass the identity matrix.
Definition: afmatrix.cpp:51
vertex list of line and arc segments.
Definition: polyver.h:600
wxString FillStyle2String(a2dFillStyle style)
convert a style enum to a string
Definition: stylebase.cpp:3420
void SetStyle(const wxString &style)
Set style of font, e.g. Bold.
Definition: stylebase.h:724
XML I/O classes which is Pull parser based for reading XML files.
a2dFillStyle
Filling styles for a2dFill.
Definition: stylebase.h:91
a2dStrokeStyle StrokeString2Style(const wxString &stylestr)
convert a string to a style enum
Definition: stylebase.cpp:5258
classes for initializing the artbase modules, and set paths to be used for fonts etc.
const wxString & GetType() const
Get type of font, e.g. Freetype or Stroke.
Definition: stylebase.h:712
a2dFontLoadMethod
load method of glyph, see Freetype refence for meaning of FT_LOAD_*
Definition: stylebase.h:1059
a2dStrokeType
Definition: stylebase.h:325
A hash map, used for storage of kerning between characters of a font.
const a2dFont * a2dNullFONT
global a2dFont stock object for NO font
wxString m_extra
Extra information (e.g. the filename of the font).
Definition: stylebase.h:759
bounding class for optimizing drawing speed.
Drawing context abstraction.
Definition: drawer2d.h:177
void * Allocate(size_t bytes)
function for allocating memory block by size bytes
Definition: a2dmemmgr.cpp:47
const a2dStroke * a2dINHERIT_STROKE
global a2dStroke stock object for INHERTED from parent object stroking
Input and output handler for the XmlSer format.
Definition: genxmlpars.h:862
const a2dFill * a2dNullFILL
global a2dFill stock object for defining NO filling
A hash map, used for storage of character widths of a font.
bool operator==(const a2dFont &a)
return true if the same font (same reference)
Definition: stylebase.h:847
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
wxString m_name
Font name.
Definition: stylebase.h:753
const a2dStroke * a2dNullSTROKE
global a2dStroke stock object for NO stroking
void SetName(const wxString &name)
Set name of font, e.g. Arial.
Definition: stylebase.h:719
const a2dStroke * a2dWHITE_STROKE
global a2dStroke stock object for WHITE stroking
holes one glyph from a freetype font.
Definition: stylebase.h:581
void SetExtra(const wxString &extra)
Set the extra information ( e.g. the filename of the font )
Definition: stylebase.h:747
const a2dFont * a2dDEFAULT_CANVASFONT
global a2dFont stock object for default font
void SetSize(double size)
Set size of the font.
Definition: stylebase.h:735
a2dFontInfo()
Constructor.
Definition: stylebase.h:690
a2dFill * SetNoFill()
from now one this object defines as if no stroke is defined of the object having this stroke...
Definition: stylebase.h:276
wxString StrokeStyle2String(a2dStrokeStyle style)
convert a style enum to a string
Definition: stylebase.cpp:5224
a2dFillType
for a2dFill to define the type of filling.
Definition: stylebase.h:126
wxString m_style
Font style.
Definition: stylebase.h:755
const wxString & GetStyle() const
Get style of font, e.g. Bold.
Definition: stylebase.h:722
friend bool operator!=(const a2dFont &a, const a2dFont &b)
return true if not the same font (same reference)
Definition: stylebase.h:865
const a2dStroke * a2dTRANSPARENT_STROKE
global a2dStroke stock object for TRANSPARENT stroking
A list used for enumerating fonts.
initiates Freetype library
Definition: stylebase.h:1197
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
double m_size
Font Size.
Definition: stylebase.h:757
a2dPropertyIdColour PROPID_colour
General colour property id.
void SetType(const wxString &type)
Set type of font, e.g. Freetype or Stroke.
Definition: stylebase.h:714
affine matrix class
a2dStroke * SetNoStroke()
from now one this object defines as if no stroke is defined of the object having this stroke...
Definition: stylebase.h:513
This template class is for property ids with a known data type.
Definition: id.h:477
Vector Path.
Definition: polyver.h:1211
a2dStrokeStyle
stroke styles for a2dStroke
Definition: stylebase.h:298
void a2dCanvasDeleteStockObjects()
to delete stock style ( a2dStroke a2dFill ) objects.
Definition: stylebase.cpp:3383
list of a2dObject&#39;s
Definition: gen.h:3157
WX_DECLARE_HASH_MAP_WITH_DECL(wxString, a2dCommandId *, wxStringHash, wxStringEqual, a2dHashMapCommandIds, class A2DGENERALDLLEXP)
This hash table is used for a2dCommandId with name.
basic 2 point line class for intersection and contouring routines.
const a2dStroke * a2dLAYER_SELECT_STROKE
global a2dStroke stock object for SELECTED object stroking
friend bool operator==(const a2dFont &a, const a2dFont &b)
return true if the same font (same reference)
Definition: stylebase.h:859
const a2dFill * a2dTRANSPARENT_FILL
global a2dFill stock object for TRANSPARENT filling
bool operator!=(const a2dFont &a)
return true if not the same font (same reference)
Definition: stylebase.h:853
stylebase.h Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation