20 #ifndef __STYLEBASE_H__
21 #define __STYLEBASE_H__
27 #include <wx/fontenc.h>
28 #include <wx/encconv.h>
29 #include <wx/bitmap.h>
31 #include "a2dprivate.h"
33 #include "wx/geometry.h"
40 #if wxART2D_USE_FREETYPE
45 #include <freetype/freetype.h>
46 #include <freetype/ftglyph.h>
47 #include <freetype/ftoutln.h>
50 #include FT_FREETYPE_H
52 #include <freetype/ftoutln.h>
58 #if wxART2D_USE_XMLPARSE
60 #endif //wxART2D_USE_XMLPARSE
69 #define SMALLTEXTTHRESHOLD 10
143 class A2DARTBASEDLLEXP
a2dFill :
public wxObject
146 #ifdef CLASS_MEM_MANAGEMENT
151 void*
operator new(
size_t bytes )
153 return sm_memManager.
Allocate( bytes );
162 void operator delete(
void* space,
size_t bytes )
164 sm_memManager.Deallocate( space, bytes );
166 #endif //CLASS_MEM_MANAGEMENT
175 a2dFill(
const wxBrush& brush );
189 a2dFill(
const wxColour& col,
const wxColour& col2,
190 double x1,
double y1,
double x2,
double y2 );
192 a2dFill(
const wxColour& col,
const wxColour& col2,
193 double xfc,
double yfc,
double xe,
double ye,
double radius );
195 bool operator==(
const a2dFill& a )
197 return m_refData == a.m_refData;
200 bool operator!=(
const a2dFill& a )
202 return m_refData != a.m_refData;
205 friend inline bool operator==(
const a2dFill& a,
const a2dFill& b )
207 return a.m_refData == b.m_refData;
210 friend inline bool operator!=(
const a2dFill& a,
const a2dFill& b )
212 return a.m_refData != b.m_refData;
217 wxObjectRefData* CreateRefData()
const;
219 wxObjectRefData* CloneRefData(
const wxObjectRefData* data )
const;
232 void SetStipple(
const wxBitmap& stipple );
234 const wxBitmap& GetStipple()
const;
237 wxColour GetColour()
const;
240 wxColour GetColour2()
const;
243 void SetColour(
const wxColour& col );
246 void SetColour2(
const wxColour& col );
248 void SetAlpha( wxUint8 val );
249 wxUint8 GetAlpha()
const;
258 wxUint32 GetStamp()
const;
267 double GetRadius()
const;
273 bool IsNoFill()
const {
return m_refData == NULL; }
280 void SetFilling(
bool OnOff );
283 bool GetFilling()
const;
285 DECLARE_DYNAMIC_CLASS(
a2dFill )
287 #if wxART2D_USE_CVGIO
290 #endif //wxART2D_USE_CVGIO
336 typedef float a2dDash;
338 #if !wxCHECK_VERSION(2,9,0)
339 typedef int wxPenJoin;
340 typedef int wxPenCap;
341 typedef int wxPolygonFillMode;
342 typedef int wxRasterOperationMode;
347 wxBRUSHSTYLE_INVALID = -1,
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
380 #ifdef CLASS_MEM_MANAGEMENT
386 void*
operator new(
size_t bytes )
388 return sm_memManager.
Allocate( bytes );
397 void operator delete(
void* space,
size_t bytes )
399 sm_memManager.Deallocate( space, bytes );
401 #endif //CLASS_MEM_MANAGEMENT
436 return m_refData == a.m_refData;
441 return m_refData != a.m_refData;
446 return a.m_refData == b.m_refData;
451 return a.m_refData != b.m_refData;
454 wxObjectRefData* CreateRefData()
const;
456 wxObjectRefData* CloneRefData(
const wxObjectRefData* data )
const;
460 void SetStipple(
const wxBitmap& stipple );
462 const wxBitmap& GetStipple()
const;
465 wxColour GetColour()
const;
468 void SetColour(
const wxColour& col );
471 wxColour GetColour2()
const;
474 void SetColour2(
const wxColour& col );
476 void SetJoin( wxPenJoin join_style );
478 void SetCap( wxPenCap cap_style );
480 wxPenCap GetCap()
const;
482 wxPenJoin GetJoin()
const;
485 void SetWidth(
float width );
489 float GetWidth()
const;
490 float GetExtend()
const;
493 void SetPixelStroke(
bool pixelstroke );
496 bool GetPixelStroke()
const;
498 void SetAlpha( wxUint8 val );
500 wxUint8 GetAlpha()
const;
519 #if wxART2D_USE_CVGIO
522 #endif //wxART2D_USE_CVGIO
538 #if defined(__WXMSW__)
539 #define __USE_WINAPI__
546 #if !wxART2D_USE_FREETYPE
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
562 unsigned long operator()(
const wxChar& k )
const
563 {
return (
unsigned long ) k; }
575 bool operator()(
const wxChar& a,
const wxChar& b )
const
576 {
return ( a == b ); }
583 #if wxART2D_USE_FREETYPE
593 #if wxART2D_USE_FREETYPE
594 m_index = ( FT_UInt ) - 1; m_glyph = NULL;
599 #if wxART2D_USE_FREETYPE
601 FT_Done_Glyph( m_glyph );
646 wxBASELINE_CONTRA = 0x0020,
647 a2dDEFAULT_ALIGNMENT = wxMAXY | wxMINX
692 a2dFontInfo(
const wxString& type,
const wxString& name,
const wxString& style = wxT(
"" ),
693 double size = 1.0,
const wxString& extra = wxT(
"" ) );
695 a2dFontInfo(
const wxString& type,
const wxString& name,
696 const wxString& style,
const wxString& extra = wxT(
"" ) );
704 bool operator == (
const a2dFontInfo& other )
const;
709 a2dFont CreateFont(
double size );
712 inline const wxString&
GetType()
const {
return m_type; }
714 inline void SetType(
const wxString& type ) { m_type = type; }
717 inline const wxString&
GetName()
const {
return m_name; }
719 inline void SetName(
const wxString& name ) { m_name = name; }
722 inline const wxString&
GetStyle()
const {
return m_style; }
724 inline void SetStyle(
const wxString& style ) { m_style = style; }
727 inline double GetSize()
const {
return m_size; }
735 inline void SetSize(
double size ) { m_size = size; }
738 wxString CreateString()
const;
741 void ParseString( wxString
string );
744 inline const wxString&
GetExtra()
const {
return m_extra; }
747 inline void SetExtra(
const wxString& extra ) { m_extra = extra; }
779 class A2DARTBASEDLLEXP
a2dFont :
public wxObject
783 a2dFontType GetType(
void )
const;
798 a2dFont(
const wxFont& font,
double size, a2dFontType type = a2dFONT_WXDC, wxFontEncoding encoding = wxFONTENCODING_DEFAULT );
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 );
835 #if wxART2D_USE_FREETYPE
837 a2dFont(
const wxString& filename,
double size = 0.0, wxFontEncoding encoding = wxFONTENCODING_DEFAULT,
int faceindex = 0 );
841 a2dFont(
const wxString& filename,
double size,
bool monoSpaced,
double weight = 0.0 );
849 return m_refData == a.m_refData;
855 return m_refData != a.m_refData;
861 return a.m_refData == b.m_refData;
867 return a.m_refData != b.m_refData;
880 void SetSize(
double size );
884 double GetSize()
const;
890 double GetLineHeight()
const;
896 double GetDescent()
const;
899 double GetWidth( wxChar c );
907 double GetKerning( wxChar WXUNUSED( c1 ), wxChar WXUNUSED( c2 ) )
const;
914 double GetStrokeWidth()
const;
921 const a2dGlyph* GetGlyphFreetype( wxChar c )
const;
923 void SetDeviceHeight(
double sizeInPixels );
925 double GetDeviceHeight();
927 #if wxART2D_USE_FREETYPE && defined(__USE_WINAPI__)
933 wxFont& GetFont(
void );
947 int alignment = wxMINX | wxMINY,
double* w = NULL,
948 double* h = NULL,
double* descent = NULL,
949 double* externalLeading = NULL )
const;
960 void GetTextExtent(
const wxString&
string,
double& w,
double& h,
961 double& descent,
double& externalLeading )
const;
968 void GetTextExtentWH(
const wxString&
string,
double& w,
double& h )
const;
970 bool GetPartialTextExtents (
const wxString& text, wxArrayInt& widths )
const;
994 bool AlwaysWriteSerializationId()
const {
return true; }
1020 wxString CreateString();
1023 static wxString CreateString(
const wxString& filename,
double size, wxFontEncoding encoding,
int weight );
1025 static wxString CreateString(
const wxString& filename,
double size,
bool monoSpaced,
double weight );
1027 static wxString CreateString( a2dFontType type,
const wxFont& font,
double size, wxFontEncoding encoding );
1034 void SetFilename(
const wxString& filename );
1039 wxString GetFilename(
bool filenameonly =
false )
const;
1045 double GetWeight()
const;
1051 void SetWeight(
double weight );
1056 void SetWeight(
const wxString& weight );
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
1082 static void SetLoadFlags( wxInt32 loadMethodMask );
1085 wxObjectRefData* CreateRefData()
const;
1087 wxObjectRefData* CloneRefData(
const wxObjectRefData* data )
const;
1089 #if wxART2D_USE_CVGIO
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
1098 DECLARE_ABSTRACT_CLASS(
a2dFont )
1100 static
void ClearFontCache() { ms_fontCache.clear(); }
1102 static map< wxString, a2dFont > ms_fontCache;
1203 virtual bool OnInit();
1204 virtual void OnExit();
1239 void SetDefault(
const a2dStroke& stroke) { m_Default = stroke; }
1240 const a2dStroke& GetDefault()
const {
return m_Default; }
1244 bool IsStyleValid()
const {
return m_bStyle; }
1248 bool IsInitialised()
const {
return m_bInitialised; }
1252 bool HasEditableStyle()
const {
return m_bEditable; }
1255 void SetColor(
const wxColour& color);
1256 bool IsColorValid()
const {
return m_bColor; }
1257 wxColour GetColor()
const {
return m_Color; }
1260 void SetWidth(
const float& width);
1261 bool IsWidthValid()
const {
return m_bWidth; }
1262 float GetWidth()
const {
return m_Width; }
1265 void SetCap(wxPenCap cap);
1266 bool IsCapValid()
const {
return m_bCap; }
1267 wxPenCap GetCap()
const {
return m_Cap; }
1270 void SetJoin(wxPenJoin join);
1271 bool IsJoinValid()
const {
return m_bJoin; }
1272 wxPenJoin GetJoin()
const {
return m_Join; }
1275 void SetAttributes(
const a2dStroke& stroke);
1287 bool m_bInitialised;
1307 void Set(
const a2dFill& fill);
1309 void Mix(
const a2dFill& fill);
1313 bool IsValid()
const {
return m_bFill; }
1315 a2dFill Get()
const {
return m_Fill; }
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
a2dFillStyle FillString2Style(const wxString &stylestr)
convert a string to a style enum
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.
const wxString & GetName() const
Get name of font, e.g. Arial.
Simple Memory manager for some objects which often create and destroy to replace OS-system calls...
const a2dStroke * a2dBLACK_STROKE
global a2dStroke stock object for BLACK stroking
Font info class, used as a single element for enumerating fonts.
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.
a2dVertexList ** a2dStrokeGlyph
A list of pointers to vertexlists. Ends with NULL.
const wxString & GetExtra() const
Get the extra information ( e.g. the filename of the font )
const a2dFill * a2dBLACK_FILL
global a2dFill stock object for BLACK filling
double GetSize() const
Get size of the font.
wxChar equality class, used in hash maps.
wxString m_type
Font type.
Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
Input and output handler for the XmlSer format.
const a2dFill * a2dWHITE_FILL
global a2dFill stock object for WHITE filling
void a2dCanvasInitializeStockObjects()
to initialize stock style ( a2dStroke a2dFill ) objects.
a2dAffineMatrix a2dIDENTITY_MATRIX
global a2dAffineMatrix to set/pass the identity matrix.
vertex list of line and arc segments.
wxString FillStyle2String(a2dFillStyle style)
convert a style enum to a string
void SetStyle(const wxString &style)
Set style of font, e.g. Bold.
XML I/O classes which is Pull parser based for reading XML files.
a2dFillStyle
Filling styles for a2dFill.
a2dStrokeStyle StrokeString2Style(const wxString &stylestr)
convert a string to a style enum
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.
a2dFontLoadMethod
load method of glyph, see Freetype refence for meaning of FT_LOAD_*
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).
bounding class for optimizing drawing speed.
Drawing context abstraction.
void * Allocate(size_t bytes)
function for allocating memory block by size bytes
const a2dStroke * a2dINHERIT_STROKE
global a2dStroke stock object for INHERTED from parent object stroking
Input and output handler for the XmlSer format.
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)
A 2x3 affine matrix class for 2D transformations.
wxString m_name
Font name.
const a2dStroke * a2dNullSTROKE
global a2dStroke stock object for NO stroking
void SetName(const wxString &name)
Set name of font, e.g. Arial.
const a2dStroke * a2dWHITE_STROKE
global a2dStroke stock object for WHITE stroking
holes one glyph from a freetype font.
void SetExtra(const wxString &extra)
Set the extra information ( e.g. the filename of the font )
const a2dFont * a2dDEFAULT_CANVASFONT
global a2dFont stock object for default font
void SetSize(double size)
Set size of the font.
a2dFontInfo()
Constructor.
a2dFill * SetNoFill()
from now one this object defines as if no stroke is defined of the object having this stroke...
wxString StrokeStyle2String(a2dStrokeStyle style)
convert a style enum to a string
a2dFillType
for a2dFill to define the type of filling.
wxString m_style
Font style.
const wxString & GetStyle() const
Get style of font, e.g. Bold.
friend bool operator!=(const a2dFont &a, const a2dFont &b)
return true if not the same font (same reference)
const a2dStroke * a2dTRANSPARENT_STROKE
global a2dStroke stock object for TRANSPARENT stroking
A list used for enumerating fonts.
initiates Freetype library
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
a2dPropertyIdColour PROPID_colour
General colour property id.
void SetType(const wxString &type)
Set type of font, e.g. Freetype or Stroke.
a2dStroke * SetNoStroke()
from now one this object defines as if no stroke is defined of the object having this stroke...
This template class is for property ids with a known data type.
a2dStrokeStyle
stroke styles for a2dStroke
void a2dCanvasDeleteStockObjects()
to delete stock style ( a2dStroke a2dFill ) objects.
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)
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)