1 // Layer.cpp : CLayer
\82Ì
\83C
\83\93\83v
\83\8a\83\81\83\93\83e
\81[
\83V
\83\87\83\93
3 #include "SeraphyScriptTools.h"
7 /////////////////////////////////////////////////////////////////////////////
10 void CLayer::Draw(CDC dc)
12 //
\83h
\83\8d\81[
\83C
\83\93\83O
\83f
\81[
\83^
\81[
\82Ì
\95`
\89æ
14 //
\83y
\83\93\81A
\83u
\83\89\83V
\82Ì
\90Ý
\92è
15 HPEN hPen = CreatePen(PS_SOLID, 0, COLORREF(m_dwColor));
16 HBRUSH hBrush = CreateSolidBrush(COLORREF(m_dwFillColor));
17 HPEN hOldPen = (HPEN)SelectObject(dc.m_hDC, hPen);
18 HBRUSH hOldBrush = (HBRUSH)SelectObject(dc.m_hDC, hBrush);
19 COLORREF oldColor = SetTextColor(dc.m_hDC, COLORREF(m_dwFontColor));
20 //
\83t
\83H
\83\93\83g
\82Ì
\91I
\91ð
21 int fntsiz = m_nFontSize;
22 if (m_bFontTextMappingMode) {
24 HWND hWnd = GetDesktopWindow();
25 HDC hdc = GetDC(hWnd);
26 long height_mm = GetDeviceCaps(hdc, VERTSIZE) * 10;
27 long height_px = GetDeviceCaps(hdc, VERTRES);
28 fntsiz = MulDiv(fntsiz, height_mm, height_px);
31 HFONT hFont = CreateFont(fntsiz, 0, 0, 0, 0, false, false, false,
32 SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, m_szFontName);
33 HFONT hOldFont = NULL;
35 hOldFont = (HFONT)SelectObject(dc.m_hDC, hFont);
37 //
\95`
\89æ
\83f
\81[
\83^
38 EnterCriticalSection(&m_objDrawingDataProtection);
39 std::list<drawdata*>::iterator p = m_lstDraw.begin();
40 while (p != m_lstDraw.end()) {
44 LeaveCriticalSection(&m_objDrawingDataProtection);
45 //
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\89ð
\95ú
46 SelectObject(dc.m_hDC, hOldPen);
47 SelectObject(dc.m_hDC, hOldBrush);
50 SetTextColor(dc.m_hDC, oldColor);
52 SelectObject(dc.m_hDC, hOldFont);
58 void CLayer::FinalRelease()
60 ATLTRACE("CLeayer::FinalRelease\r\n");
61 //
\95`
\89æ
\83f
\81[
\83^
\81[
\82Ì
\94j
\8aü
63 //
\83N
\83\8a\83e
\83B
\83J
\83\8b\83Z
\83N
\83V
\83\87\83\93\82Ì
\89ð
\95ú
64 DeleteCriticalSection(&m_objDrawingDataProtection);
67 STDMETHODIMP CLayer::Text(VARIANT x, VARIANT y, VARIANT text)
70 HRESULT hr = str.ChangeType(VT_BSTR, &text);
75 long lx = GetMappedValue(x);
76 long ly = GetMappedValue(y);
77 int len = SysStringByteLen(str.bstrVal);
79 ATL::CString buf(str.bstrVal);
81 AddDrawData(new textdata(lx, ly, buf, m_bTextMappingMode));
85 STDMETHODIMP CLayer::TextBox(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey, VARIANT text, VARIANT fmt)
87 long lsx = GetMappedValue(sx);
88 long lsy = GetMappedValue(sy);
89 long lex = GetMappedValue(ex);
90 long ley = GetMappedValue(ey);
94 if (cfmt.ChangeType(VT_I4, &fmt) == S_OK) {
99 HRESULT hr = str.ChangeType(VT_BSTR, &text);
104 ATL::CString buf(str.bstrVal);
106 AddDrawData(new textboxdata(lsx, lsy, lex, ley, buf, ufmt, m_bTextMappingMode));
110 STDMETHODIMP CLayer::Circle(VARIANT x, VARIANT y, VARIANT radius)
112 long lx = GetMappedValue(x);
113 long ly = GetMappedValue(y);
114 long lr = GetMappedValue(radius);
115 AddDrawData(new circledata(lx, ly, lr, m_bTextMappingMode));
119 STDMETHODIMP CLayer::Line(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
121 long lsx = GetMappedValue(sx);
122 long lsy = GetMappedValue(sy);
123 long lex = GetMappedValue(ex);
124 long ley = GetMappedValue(ey);
125 AddDrawData(new linedata(lsx, lsy, lex, ley, m_bTextMappingMode));
129 STDMETHODIMP CLayer::Box(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
131 long lsx = GetMappedValue(sx);
132 long lsy = GetMappedValue(sy);
133 long lex = GetMappedValue(ex);
134 long ley = GetMappedValue(ey);
135 AddDrawData(new boxdata(lsx, lsy, lex, ley, m_bTextMappingMode));
139 STDMETHODIMP CLayer::Arc(VARIANT x1, VARIANT y1, VARIANT x2, VARIANT y2, VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
141 long lx1 = GetMappedValue(x1);
142 long ly1 = GetMappedValue(y1);
143 long lx2 = GetMappedValue(x2);
144 long ly2 = GetMappedValue(y2);
145 long lsx = GetMappedValue(sx);
146 long lsy = GetMappedValue(sy);
147 long lex = GetMappedValue(ex);
148 long ley = GetMappedValue(ey);
149 AddDrawData(new arcdata(lx1, ly1, lx2, ly2, lsx, lsy, lex, ley, m_bTextMappingMode));
153 STDMETHODIMP CLayer::Picture(VARIANT unk, VARIANT x, VARIANT y, VARIANT w, VARIANT h)
156 IPicture* pPicture = NULL;
157 if (cUnk.ChangeType(VT_UNKNOWN, &unk) != S_OK ||
158 cUnk.punkVal->QueryInterface(IID_IPicture, (void**)&pPicture) != S_OK) {
159 return DISP_E_TYPEMISMATCH;
161 long lx = GetMappedValue(x);
162 long ly = GetMappedValue(y);
164 if (w.vt != VT_NULL && w.vt != VT_ERROR && w.vt != VT_EMPTY) {
165 width = GetMappedValue(w, -1);
168 if (h.vt != VT_NULL && h.vt != VT_ERROR && h.vt != VT_EMPTY) {
169 height = GetMappedValue(h, -1);
171 AddDrawData(new picturedata(pPicture, lx, ly, width, height, m_bTextMappingMode));
176 STDMETHODIMP CLayer::FillBox(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
178 long lsx = GetMappedValue(sx);
179 long lsy = GetMappedValue(sy);
180 long lex = GetMappedValue(ex);
181 long ley = GetMappedValue(ey);
182 AddDrawData(new fillboxdata(lsx, lsy, lex, ley, m_bTextMappingMode));
186 STDMETHODIMP CLayer::FillCircle(VARIANT x, VARIANT y, VARIANT radius)
188 long lx = GetMappedValue(x);
189 long ly = GetMappedValue(y);
190 long lr = GetMappedValue(radius);
191 AddDrawData(new fillcircledata(lx, ly, lr, m_bTextMappingMode));
195 STDMETHODIMP CLayer::FillArc(VARIANT x1, VARIANT y1, VARIANT x2, VARIANT y2, VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
197 long lx1 = GetMappedValue(x1);
198 long ly1 = GetMappedValue(y1);
199 long lx2 = GetMappedValue(x2);
200 long ly2 = GetMappedValue(y2);
201 long lsx = GetMappedValue(sx);
202 long lsy = GetMappedValue(sy);
203 long lex = GetMappedValue(ex);
204 long ley = GetMappedValue(ey);
205 AddDrawData(new fillarcdata(lx1, ly1, lx2, ly2, lsx, lsy, lex, ley, m_bTextMappingMode));
209 STDMETHODIMP CLayer::FillRBox(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey, VARIANT w, VARIANT h)
211 long lsx = GetMappedValue(sx);
212 long lsy = GetMappedValue(sy);
213 long lex = GetMappedValue(ex);
214 long ley = GetMappedValue(ey);
215 long lw = GetMappedValue(w);
216 long lh = GetMappedValue(h);
217 AddDrawData(new fillrboxdata(lsx, lsy, lex, ley, lw, lh, m_bTextMappingMode));
221 STDMETHODIMP CLayer::Polygon(VARIANT cx, VARIANT cy, VARIANT arrayPt)
223 long lx = GetMappedValue(cx);
224 long ly = GetMappedValue(cy);
225 VARTYPE vt = VT_EMPTY;
226 SAFEARRAY* pArray = GetArrayFromVariant(arrayPt, &vt);
227 if (!pArray || vt != VT_VARIANT) {
228 return DISP_E_TYPEMISMATCH;
235 int dm = SafeArrayGetDim(pArray);
236 SafeArrayGetLBound(pArray, 1, &lb0); //
\8d¶
\91¤
\82Ì
\93Y
\82¦
\8e\9a
237 SafeArrayGetUBound(pArray, 1, &ub0);
238 SafeArrayGetLBound(pArray, 2, &lb); //
\89E
\91¤
\82Ì
\93Y
\82¦
\8e\9a
239 SafeArrayGetUBound(pArray, 2, &ub);
240 if (dm == 2 && lb == 0 && lb0 == 0 && ub0 == 2 && ub > lb && ub > 2) {
241 //
\94z
\97ñ
\82Ì
\8e\9f\8c³
\81A
\94Í
\88Í
\82ª
\97L
\8cø
\82Å
\82 \82é
\81B
242 //
\91½
\8ap
\8c`
\82ð
\8dì
\90¬
\82·
\82é
\82½
\82ß
\82É
\82Í
\92¸
\93_
\82Í3
\82Â
\88È
\8fã
\95K
\97v
\81B
243 pPt = new POINT[ub + 1];
245 for (int cnt = 0; cnt <= ub; cnt++) {
246 // VARIANT
\82Ì
\94z
\97ñ
\82Å
\82 \82é
247 CComVariant tmpX, tmpY;
250 SafeArrayGetElement(pArray, idx, &tmpX);
252 SafeArrayGetElement(pArray, idx, &tmpY);
253 pPt[cnt].x = GetMappedValue(tmpX) + lx;
254 pPt[cnt].y = GetMappedValue(tmpY) + ly;
258 //
\94z
\97ñ
\82Ì
\8eí
\97Þ
\82ª
\82È
\82ñ
\82¾
\82©
\95ª
\82©
\82ç
\82È
\82¢
\81B
259 return Error(IDS_ERR_NEED2DIM);
261 AddDrawData(new polygondata(pPt, ub, m_bTextMappingMode));
265 STDMETHODIMP CLayer::Clear()
267 //
\83h
\83\8d\81[
\83C
\83\93\83O
\83f
\81[
\83^
\81[
\82Ì
\94j
\8aü
268 EnterCriticalSection(&m_objDrawingDataProtection);
269 std::list<drawdata*>::iterator p = m_lstDraw.begin();
270 while (p != m_lstDraw.end()) {
272 p = m_lstDraw.erase(p);
274 LeaveCriticalSection(&m_objDrawingDataProtection);
278 void CLayer::AddDrawData(drawdata *pDrawData)
280 //
\83f
\81[
\83^
\81[
\82Ì
\92Ç
\89Á
281 EnterCriticalSection(&m_objDrawingDataProtection);
282 m_lstDraw.push_back(pDrawData);
283 LeaveCriticalSection(&m_objDrawingDataProtection);
286 STDMETHODIMP CLayer::get_Color(long *pVal)
292 STDMETHODIMP CLayer::put_Color(long newVal)
299 STDMETHODIMP CLayer::get_FontColor(long *pVal)
301 *pVal = m_dwFontColor;
305 STDMETHODIMP CLayer::put_FontColor(long newVal)
307 m_dwFontColor = newVal;
311 STDMETHODIMP CLayer::get_Visible(BOOL *pVal)
317 STDMETHODIMP CLayer::put_Visible(BOOL newVal)
323 STDMETHODIMP CLayer::get_FontName(BSTR *pVal)
325 CComBSTR ret(m_szFontName);
326 *pVal = ret.Detach();
330 STDMETHODIMP CLayer::put_FontName(BSTR newVal)
332 m_szFontName = newVal;
336 STDMETHODIMP CLayer::get_FillColor(long *pVal)
338 *pVal = m_dwFillColor;
342 STDMETHODIMP CLayer::put_FillColor(long newVal)
344 m_dwFillColor = newVal;
348 STDMETHODIMP CLayer::get_FontSize(short *pVal)
350 *pVal = (short)m_nFontSize;
354 STDMETHODIMP CLayer::put_FontSize(short newVal)
356 m_nFontSize = (int)newVal;
357 m_bFontTextMappingMode = m_bTextMappingMode;
362 STDMETHODIMP CLayer::SetMappingMode(VARIANT mode)
365 if (varMode.ChangeType(VT_I2, &mode) == S_OK) {
366 m_bTextMappingMode = varMode.iVal;
371 long CLayer::GetMappedValue(VARIANT var, long def)
374 if (m_bTextMappingMode) {
375 //
\83s
\83N
\83Z
\83\8b\92P
\88Ê
\82Ì
\8dÀ
\95W
\8ew
\92è
376 if (varTmp.ChangeType(VT_I4, &var) == S_OK) {
381 //
\83~
\83\8a\92P
\88Ê
\82Ì
\8dÀ
\95W
\8ew
\92è (1
\92P
\88Ê 0.1mm)
382 if (varTmp.ChangeType(VT_R8, &var) == S_OK) {
383 return (long)(varTmp.dblVal * 10);