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 STDMETHODIMP CLayer::InterfaceSupportsErrorInfo(REFIID riid)
12 static const IID* arr[] =
16 for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
18 if (IsEqualGUID(*arr[i],riid))
24 void CLayer::Draw(CDC dc)
26 //
\83h
\83\8d\81[
\83C
\83\93\83O
\83f
\81[
\83^
\81[
\82Ì
\95`
\89æ
28 //
\83y
\83\93\81A
\83u
\83\89\83V
\82Ì
\90Ý
\92è
29 HPEN hPen = CreatePen(PS_SOLID,0,COLORREF(m_dwColor));
30 HBRUSH hBrush = CreateSolidBrush(COLORREF(m_dwFillColor));
31 HPEN hOldPen = (HPEN)SelectObject(dc.m_hDC,hPen);
32 HBRUSH hOldBrush = (HBRUSH)SelectObject(dc.m_hDC,hBrush);
33 COLORREF oldColor = SetTextColor(dc.m_hDC,COLORREF(m_dwFontColor));
34 //
\83t
\83H
\83\93\83g
\82Ì
\91I
\91ð
35 int fntsiz = m_nFontSize;
36 if(m_bFontTextMappingMode){
38 HWND hWnd = GetDesktopWindow();
39 HDC hdc = GetDC(hWnd);
40 long height_mm = GetDeviceCaps(hdc,VERTSIZE) * 10;
41 long height_px = GetDeviceCaps(hdc,VERTRES);
42 fntsiz = MulDiv(fntsiz,height_mm,height_px);
45 HFONT hFont = CreateFont(fntsiz,0,0,0,0,false,false,false,SHIFTJIS_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,m_szFontName);
46 HFONT hOldFont = NULL;
48 hOldFont = (HFONT)SelectObject(dc.m_hDC,hFont);
50 //
\95`
\89æ
\83f
\81[
\83^
51 EnterCriticalSection(&m_objDrawingDataProtection);
52 list<drawdata*>::iterator p = m_lstDraw.begin();
53 while(p != m_lstDraw.end()){
57 LeaveCriticalSection(&m_objDrawingDataProtection);
58 //
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\89ð
\95ú
59 SelectObject(dc.m_hDC,hOldPen);
60 SelectObject(dc.m_hDC,hOldBrush);
63 SetTextColor(dc.m_hDC,oldColor);
65 SelectObject(dc.m_hDC,hOldFont);
71 void CLayer::FinalRelease()
73 ATLTRACE("CLeayer::FinalRelease\r\n");
74 //
\95`
\89æ
\83f
\81[
\83^
\81[
\82Ì
\94j
\8aü
76 //
\83N
\83\8a\83e
\83B
\83J
\83\8b\83Z
\83N
\83V
\83\87\83\93\82Ì
\89ð
\95ú
77 DeleteCriticalSection(&m_objDrawingDataProtection);
80 STDMETHODIMP CLayer::Text(VARIANT x,VARIANT y,VARIANT text)
83 if(str.ChangeType(VT_BSTR,&text) != S_OK){
84 return DISP_E_TYPEMISMATCH;
86 long lx = GetMappedValue(x);
87 long ly = GetMappedValue(y);
88 int len = SysStringByteLen(str.bstrVal);
89 LPSTR pBuf = new CHAR[len+1];
90 WideCharToMultiByte(GetACP(),0,str.bstrVal,len,pBuf,len,0,0);
92 AddDrawData(new textdata(lx,ly,pBuf,m_bTextMappingMode));
97 STDMETHODIMP CLayer::TextBox(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey, VARIANT text, VARIANT fmt)
100 long lsx = GetMappedValue(sx);
101 long lsy = GetMappedValue(sy);
102 long lex = GetMappedValue(ex);
103 long ley = GetMappedValue(ey);
105 if(cfmt.ChangeType(VT_I4,&fmt) == S_OK){
108 if(str.ChangeType(VT_BSTR,&text) != S_OK){
109 return DISP_E_TYPEMISMATCH;
111 int len = SysStringByteLen(str.bstrVal);
112 LPSTR pBuf = new CHAR[len+1];
113 int cnt = WideCharToMultiByte(GetACP(),0,str.bstrVal,-1,pBuf,len,0,0);
115 AddDrawData(new textboxdata(lsx,lsy,lex,ley,pBuf,ufmt,m_bTextMappingMode));
120 STDMETHODIMP CLayer::Circle(VARIANT x, VARIANT y, VARIANT radius)
122 long lx = GetMappedValue(x);
123 long ly = GetMappedValue(y);
124 long lr = GetMappedValue(radius);
125 AddDrawData(new circledata(lx,ly,lr,m_bTextMappingMode));
129 STDMETHODIMP CLayer::Line(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 linedata(lsx,lsy,lex,ley,m_bTextMappingMode));
139 STDMETHODIMP CLayer::Box(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
141 long lsx = GetMappedValue(sx);
142 long lsy = GetMappedValue(sy);
143 long lex = GetMappedValue(ex);
144 long ley = GetMappedValue(ey);
145 AddDrawData(new boxdata(lsx,lsy,lex,ley,m_bTextMappingMode));
149 STDMETHODIMP CLayer::Arc(VARIANT x1, VARIANT y1, VARIANT x2, VARIANT y2, VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
151 long lx1 = GetMappedValue(x1);
152 long ly1 = GetMappedValue(y1);
153 long lx2 = GetMappedValue(x2);
154 long ly2 = GetMappedValue(y2);
155 long lsx = GetMappedValue(sx);
156 long lsy = GetMappedValue(sy);
157 long lex = GetMappedValue(ex);
158 long ley = GetMappedValue(ey);
159 AddDrawData(new arcdata(lx1,ly1,lx2,ly2,lsx,lsy,lex,ley,m_bTextMappingMode));
163 STDMETHODIMP CLayer::Picture(VARIANT unk, VARIANT x, VARIANT y, VARIANT w, VARIANT h)
166 IPicture* pPicture = NULL;
167 if( cUnk.ChangeType(VT_UNKNOWN,&unk) != S_OK ||
168 cUnk.punkVal->QueryInterface(IID_IPicture,(void**)&pPicture) != S_OK){
169 return DISP_E_TYPEMISMATCH;
171 long lx = GetMappedValue(x);
172 long ly = GetMappedValue(y);
174 if(w.vt != VT_NULL && w.vt != VT_ERROR && w.vt != VT_EMPTY){
175 width = GetMappedValue(w,-1);
178 if(h.vt != VT_NULL && h.vt != VT_ERROR && h.vt != VT_EMPTY){
179 height = GetMappedValue(h,-1);
181 AddDrawData(new picturedata(pPicture,lx,ly,width,height,m_bTextMappingMode));
186 STDMETHODIMP CLayer::FillBox(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
188 long lsx = GetMappedValue(sx);
189 long lsy = GetMappedValue(sy);
190 long lex = GetMappedValue(ex);
191 long ley = GetMappedValue(ey);
192 AddDrawData(new fillboxdata(lsx,lsy,lex,ley,m_bTextMappingMode));
196 STDMETHODIMP CLayer::FillCircle(VARIANT x, VARIANT y, VARIANT radius)
198 long lx = GetMappedValue(x);
199 long ly = GetMappedValue(y);
200 long lr = GetMappedValue(radius);
201 AddDrawData(new fillcircledata(lx,ly,lr,m_bTextMappingMode));
205 STDMETHODIMP CLayer::FillArc(VARIANT x1, VARIANT y1, VARIANT x2, VARIANT y2, VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey)
207 long lx1 = GetMappedValue(x1);
208 long ly1 = GetMappedValue(y1);
209 long lx2 = GetMappedValue(x2);
210 long ly2 = GetMappedValue(y2);
211 long lsx = GetMappedValue(sx);
212 long lsy = GetMappedValue(sy);
213 long lex = GetMappedValue(ex);
214 long ley = GetMappedValue(ey);
215 AddDrawData(new fillarcdata(lx1,ly1,lx2,ly2,lsx,lsy,lex,ley,m_bTextMappingMode));
219 STDMETHODIMP CLayer::FillRBox(VARIANT sx, VARIANT sy, VARIANT ex, VARIANT ey, VARIANT w, VARIANT h)
221 long lsx = GetMappedValue(sx);
222 long lsy = GetMappedValue(sy);
223 long lex = GetMappedValue(ex);
224 long ley = GetMappedValue(ey);
225 long lw = GetMappedValue(w);
226 long lh = GetMappedValue(h);
227 AddDrawData(new fillrboxdata(lsx,lsy,lex,ley,lw,lh,m_bTextMappingMode));
231 STDMETHODIMP CLayer::Polygon(VARIANT cx, VARIANT cy, VARIANT arrayPt)
233 long lx = GetMappedValue(cx);
234 long ly = GetMappedValue(cy);
235 VARTYPE vt = VT_EMPTY;
236 SAFEARRAY* pArray = GetArrayFromVariant(arrayPt,&vt);
237 if(!pArray || vt != VT_VARIANT){
238 return DISP_E_TYPEMISMATCH;
245 int dm = SafeArrayGetDim(pArray);
246 SafeArrayGetLBound(pArray,1,&lb0); //
\8d¶
\91¤
\82Ì
\93Y
\82¦
\8e\9a
247 SafeArrayGetUBound(pArray,1,&ub0);
248 SafeArrayGetLBound(pArray,2,&lb); //
\89E
\91¤
\82Ì
\93Y
\82¦
\8e\9a
249 SafeArrayGetUBound(pArray,2,&ub);
250 if(dm == 2 && lb == 0 && lb0 == 0 && ub0 == 2 && ub > lb && ub > 2){
251 //
\94z
\97ñ
\82Ì
\8e\9f\8c³
\81A
\94Í
\88Í
\82ª
\97L
\8cø
\82Å
\82 \82é
\81B
252 //
\91½
\8ap
\8c`
\82ð
\8dì
\90¬
\82·
\82é
\82½
\82ß
\82É
\82Í
\92¸
\93_
\82Í3
\82Â
\88È
\8fã
\95K
\97v
\81B
253 pPt = new POINT[ub + 1];
255 for(int cnt = 0 ; cnt <= ub ; cnt++){
256 // VARIANT
\82Ì
\94z
\97ñ
\82Å
\82 \82é
257 CComVariant tmpX,tmpY;
260 SafeArrayGetElement(pArray,idx,&tmpX);
262 SafeArrayGetElement(pArray,idx,&tmpY);
263 pPt[cnt].x = GetMappedValue(tmpX) + lx;
264 pPt[cnt].y = GetMappedValue(tmpY) + ly;
268 //
\94z
\97ñ
\82Ì
\8eí
\97Þ
\82ª
\82È
\82ñ
\82¾
\82©
\95ª
\82©
\82ç
\82È
\82¢
\81B
269 ErrorInfo(IDS_ERR_NEED2DIM);
270 return DISP_E_EXCEPTION;
272 AddDrawData(new polygondata(pPt,ub,m_bTextMappingMode));
276 STDMETHODIMP CLayer::Clear()
278 //
\83h
\83\8d\81[
\83C
\83\93\83O
\83f
\81[
\83^
\81[
\82Ì
\94j
\8aü
279 EnterCriticalSection(&m_objDrawingDataProtection);
280 list<drawdata*>::iterator p = m_lstDraw.begin();
281 while(p != m_lstDraw.end()){
283 p = m_lstDraw.erase(p);
285 LeaveCriticalSection(&m_objDrawingDataProtection);
289 void CLayer::AddDrawData(drawdata *pDrawData)
291 //
\83f
\81[
\83^
\81[
\82Ì
\92Ç
\89Á
292 EnterCriticalSection(&m_objDrawingDataProtection);
293 m_lstDraw.push_back(pDrawData);
294 LeaveCriticalSection(&m_objDrawingDataProtection);
297 STDMETHODIMP CLayer::get_Color(long *pVal)
303 STDMETHODIMP CLayer::put_Color(long newVal)
310 STDMETHODIMP CLayer::get_FontColor(long *pVal)
312 *pVal = m_dwFontColor;
316 STDMETHODIMP CLayer::put_FontColor(long newVal)
318 m_dwFontColor = newVal;
322 STDMETHODIMP CLayer::get_Visible(BOOL *pVal)
328 STDMETHODIMP CLayer::put_Visible(BOOL newVal)
334 STDMETHODIMP CLayer::get_FontName(BSTR *pVal)
336 WCHAR wmes[MAX_PATH];
337 MultiByteToWideChar(GetACP(),0,m_szFontName,-1,wmes,MAX_PATH);
338 *pVal = SysAllocString(wmes);
342 STDMETHODIMP CLayer::put_FontName(BSTR newVal)
344 WideCharToMultiByte(GetACP(),0,newVal,-1,m_szFontName,MAX_PATH,NULL,NULL);
348 STDMETHODIMP CLayer::get_FillColor(long *pVal)
350 *pVal = m_dwFillColor;
354 STDMETHODIMP CLayer::put_FillColor(long newVal)
356 m_dwFillColor = newVal;
360 STDMETHODIMP CLayer::get_FontSize(short *pVal)
362 *pVal = (short)m_nFontSize;
366 STDMETHODIMP CLayer::put_FontSize(short newVal)
368 m_nFontSize = (int)newVal;
369 m_bFontTextMappingMode = m_bTextMappingMode;
374 STDMETHODIMP CLayer::SetMappingMode(VARIANT mode)
377 if(varMode.ChangeType(VT_I2,&mode) == S_OK){
378 m_bTextMappingMode = varMode.iVal;
383 long CLayer::GetMappedValue(VARIANT var, long def)
386 if(m_bTextMappingMode){
387 //
\83s
\83N
\83Z
\83\8b\92P
\88Ê
\82Ì
\8dÀ
\95W
\8ew
\92è
388 if(varTmp.ChangeType(VT_I4,&var) == S_OK){
393 //
\83~
\83\8a\92P
\88Ê
\82Ì
\8dÀ
\95W
\8ew
\92è (1
\92P
\88Ê 0.1mm)
394 if(varTmp.ChangeType(VT_R8,&var) == S_OK){
395 return (long)(varTmp.dblVal * 10);