CGM Objects Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
DrawSVG.h
1 // DrawSVG.h: interface for the CDrawSVG class.
2 //
5 
6 #if !defined(LST_DRAWPS_H__INCLUDED_)
7 #define LST_DRAWPS_H__INCLUDED_
8 
9 #ifdef WIN32
10  #define SNPRINTF sprintf_s
11 #else
12  #define SNPRINTF snprintf
13 #endif
14 
15 #pragma once
16 
17 #include <string>
18 #include <fstream>
19 
20 #include "CgmObjects/DrawBase.h"
21 #include "Utility/Color.h"
22 #include "Utility/LSTException.h"
23 
24 namespace Larson
25 {
26 
28 
29  class CDrawSVG : public CDrawBase
30  {
31  public:
32  enum ExceptionCodes {
33  ePolygonSetLessThan3Pts = EXC_DRAWPS,
34  eDiscontPolyBez4Pt = EXC_DRAWPS + 1
35  };
36 
37  // Used by app to define output parameters and passed to setDisplay
38  typedef struct {
39  std::wstring filename;
40  double width; // in PS user units (inch * 72)
41  double height; // in PS user units (inch * 72)
42  bool uncompressed;
44 
45  typedef struct {
46  std::string stroke;
47  std::string lnCap;
48  std::string lnJoin;
49  std::string mLimit;
50  std::string width;
51  std::string dashArray;
52  } strokeInfo;
53 
54  #define DEF_LNCAP "round"
55  #define DEF_LNJOIN "round"
56 
57  typedef struct {
58  std::string stroke;
59  std::string fill;
60  std::string lnCap;
61  std::string lnJoin;
62  std::string mLimit;
63  std::string width;
64  std::string dashArray;
65  } fillInfo;
66 
67  CDrawSVG();
68  virtual ~CDrawSVG();
69 
70  void PreProcess(CCgmObjects*, enum ProcessFlag);
71  void PostProcess(CCgmObjects*, enum ProcessFlag);
72 
73  void setTransform(DRect *window, DRect *viewport, DRect *clientRect, double rotation, int originFlag);
74  void clear();
75  void close();
76  void flush();
77  void open();
78 
79  void drawDCline(CCgmBaseObj *pCgmBaseObj, DPoint *pDa, long cnt, bool close);
80  void drawDCfill(CCgmBaseObj *pCgmBaseObj, DPoint *pDa, long cnt);
81  void drawDCdots(CCgmBaseObj *pCgmBaseObj, DPoint *pDa, long cnt);
82  void eraseDCarea(DRect *area);
83 
84  void drawRect(CCgmRect *pCgmRect);
85  void drawText(CCgmText *pCgmText);
86  void drawPoly(CCgmPoly *pCgmPoly);
87  void drawPolymarker(CCgmPoly *pCgmPoly);
88 
89  void drawCellArray(CCgmCellArray *pCCgmCellArray);
90  void drawCircle(CCgmCircle *pCgmCircle);
91  void drawEllipse(CCgmEllipse *pCgmEllipse);
92  void drawPath(CCgmBaseObj *pCgmBaseObj, Path *pPath, bool fill);
93  void drawFigure(CCgmFigure *pCgmFigure);
94 
95  void setDisplay(void* pDisplay, void* pOther = 0);
96 
97  std::string rgbStr(CColor color, bool bDevColor = true);
98 
99  std::string setStroke(CCgmBaseObj *pCgmBaseObj, bool bSolidAux);
100  std::string setFillStroke(CCgmBaseObj *pCgmBaseObj);
101 
102  void makeImage(double x, double y, double w, double h, long nx, long ny,
103  unsigned char *raw, long tuple, CColor fgc, CColor bgc, long rPad,
104  long bTrans, CColor tc);
105 
106  long setLineAttr(CCgmBaseObj *pCgmBaseObj) { return 0; };
107  long setFillAttr(CCgmBaseObj *pCgmBaseObj) { return 0; };
108 
109  long cantLineAttr(CCgmBaseObj *pCgmBaseObj);
110  long cantFillAttr(CCgmBaseObj *pCgmBaseObj, bool *bPat, double *xf, double *yf, double *ox, double *oy);
111 
112  bool applyClipping(CCgmBaseObj*, DRect *rect);
113  void unApplyClipping(CCgmBaseObj*);
114 
115  void begAps(CAppStruct *pAppStruct);
116  void endAps(CAppStruct *pAppStruct);
117 
118  Larson::CColor m_bgColor;
119 
120  double WeightToD(double scale, int specMode, double scaleFactor = 1.0);
121 
122  std::string minDigitStr(double v, int dps = 2);
123 
124  private:
125 
126  std::vector<strokeInfo> m_strokeInfo;
127  std::vector<std::string> m_fillInfo;
128 
129  long m_SVGcpIndexAPS;
130 
131  bool m_bCGM2SVGuri; // change .CGM extensions to .SVG extensions in URL references
132 
133  std::string stdW2stdS(std::wstring wstr, bool noDblDash = false);
134 
135  void xy(double x, double y, double xf, double yf, double ox, double oy);
136  void wh(double x, double y, double xf, double yf);
137  void moveto(double x, double y, double xf, double yf, double ox, double oy);
138  void lineto(double x, double y, char L, double xf, double yf, double ox, double oy);
139  void curveto(double x1, double y1, double x2, double y2, double x3, double y3, double xf, double yf, double ox, double oy);
140  void closepath();
141 
142  std::wstring m_outputFilename;
143  double m_outputWidth;
144  double m_outputHeight;
145  bool m_bUncompressed;
146 
147  bool m_bCommentAPS;
148 
149  long m_SVGcpIndex;
150 
151  ofstream svgStream;
152 
153  bool m_bEmulateText;
154 
155  long m_nCurHatchPatNumb;
156  std::vector<std::string> m_crossHatchWritten;
157 
158  std::vector<void*> m_compoundTextPathWritten;
159 
160  bool m_bPatternAsRects; // vs pattern as image
161  std::vector<void*> m_patternWritten;
162 
163  bool bStdout;
164  bool bPNGCompress;
165  double xScale;
166  double yScale;
167 
168  // Attribute state list
169  CColor lastColor; // PS only has one current color
170  unsigned char lastLineCap;
171  unsigned char lastLineDashCap;
172  unsigned char lastLineJoin;
173  char lastLineType;
174  double lastLineWidth;
175  long lastHatchPatternIndex;
176  long lastProtRegBundleIndex;
177  long lastClipRectIndex; // 0= no clipping, > 0 then index -1 into clipRects list
178 
179  double lastFontMat[6];
180  std::wstring lastFontname;
181  vector<string> fontsUsed;
182  };
183 };
184 
185 #endif // !defined(LST_DRAWPS_H__INCLUDED_)
long setFillAttr(CCgmBaseObj *pCgmBaseObj)
apply fill attributes
Definition: DrawSVG.h:107
CCgmCircle – Circle and CircularArc elements container class.
Definition: CgmObj.h:1258
void drawCellArray(CCgmCellArray *pCCgmCellArray)
draw a cell array as specfied by pCCgmCellArray, points are in VDC units
Definition: DrawSVG.cpp:1829
Definition: DrawSVG.h:57
CCgmEllipse – Ellipse and EllipticalArc elements container class.
Definition: CgmObj.h:1309
void drawDCline(CCgmBaseObj *pCgmBaseObj, DPoint *pDa, long cnt, bool close)
draw a series of connected or unconnected lines specified by pPts in device coordinates ...
Definition: DrawSVG.cpp:493
CCgmCellArray – CellArray element container class.
Definition: CgmObj.h:933
CCgmFigure – Figure and Compund Line element container class.
Definition: CgmObj.h:1110
Definition: DrawSVG.h:45
void close()
close device and release memory
Definition: DrawSVG.cpp:202
bool applyClipping(CCgmBaseObj *, DRect *rect)
apply clipping rectangle and protection regions if either or both are indicated
Definition: DrawSVG.cpp:746
void setTransform(DRect *window, DRect *viewport, DRect *clientRect, double rotation, int originFlag)
set VDC to device coordinates transform
Definition: DrawSVG.cpp:95
CCgmRect – Rectangle element container class.
Definition: CgmObj.h:751
CDrawBase – drawing base class from which all output specific draw classes are derived.
Definition: DrawBase.h:19
long setLineAttr(CCgmBaseObj *pCgmBaseObj)
apply line attributes
Definition: DrawSVG.h:106
Path – graphical path data container class.
Definition: Path.h:17
void clear()
clear display area and set to background color if indicated
Definition: DrawSVG.cpp:470
CCgmPoly – Poly elements container class(Polyline, PolyBezier, Polygon, Disjoint Polyline) ...
Definition: CgmObj.h:883
CDrawSVG – SVG drawing class.
Definition: DrawSVG.h:29
CCgmBaseObj – graphical element container base class.
Definition: CgmObj.h:121
CAppStruct – Application Structure (APS) container class.
Definition: AppStruct.h:23
CCgmText – Text and RestrictedText elements container class.
Definition: CgmObj.h:794
void open()
open device for drawing
Definition: DrawSVG.cpp:135
void setDisplay(void *pDisplay, void *pOther=0)
select target device
Definition: DrawSVG.cpp:105
CCgmObjects – CGM Picture container.
Definition: CgmObjects.h:472
void drawDCfill(CCgmBaseObj *pCgmBaseObj, DPoint *pDa, long cnt)
fill a polygonal area specified by pPts in device coordinates
Definition: DrawSVG.cpp:624