using dia-manual.chm instead of dia.chm
[dia.git] / plug-ins / wmf / wmf_gdi.cpp
bloba466ff40020ce95685f888d6fc646e702b2ab984
1 /*
2 * WMF_GDI is an implementation of Windoze GDI functions required
3 * for saving of Windows Meta Files, if the Win32 API isn't
4 * available. It isn't finished yet but shoud be easily extendable
5 * for someone interested in Dia WMF support on non Windoze
6 * platforms.
8 * (c) 2000 Hans Breuer <Hans@Breuer.Org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "wmf_gdi.h"
27 namespace W32
31 * Private Helpers
33 #define fwrite_le(a,b,c,d) fwrite(a,b,c,d)
35 static void
36 WriteRecHead(HDC hdc, int iFn, int iNumPara)
38 DWORD dwSize = 3 + iNumPara; /* in WORDs ! */
39 guint16 fn = (guint16)iFn;
41 fwrite_le(&dwSize, sizeof(DWORD), 1, hdc->file);
42 fwrite_le(&fn, sizeof(guint16), 1, hdc->file);
46 * "Exported" functions
48 HGDIOBJ
49 SelectObject(HDC hdc, HGDIOBJ hobj)
51 HGDIOBJ hRet;
53 g_return_val_if_fail(hdc != NULL, NULL);
54 g_return_val_if_fail(hobj != NULL, NULL);
56 switch (hobj->Type)
58 case GDI_PEN :
59 hRet = hdc->hPen;
60 hdc->hPen = hobj;
61 break;
62 case GDI_BRUSH :
63 hRet = hdc->hBrush;
64 hdc->hBrush = hobj;
65 break;
66 case GDI_FONT :
67 hRet = hdc->hFont;
68 hdc->hFont = hobj;
69 break;
70 default :
71 hRet = NULL;
72 g_assert_not_reached();
75 return hRet;
78 BOOL
79 DeleteObject(HGDIOBJ hobj)
81 if (GDI_FONT == hobj->Type)
82 g_free(hobj->Font.sFaceName);
84 g_free(hobj);
86 return TRUE;
89 HGDIOBJ
90 GetStockObject(int iObj)
92 return NULL;
95 HBRUSH
96 CreateSolidBrush(COLORREF color)
98 HGDIOBJ hobj;
100 hobj = g_new0(struct _GdiObject, 1);
101 hobj->Type = GDI_BRUSH;
102 hobj->Brush.Color = color;
104 return hobj;
107 HPEN
108 CreatePen(wmfint iStyle, wmfint iWidth, COLORREF color)
110 HGDIOBJ hobj;
112 hobj = g_new0(struct _GdiObject, 1);
113 hobj->Type = GDI_PEN;
114 hobj->Pen.Color = color;
115 hobj->Pen.Width = iWidth;
116 hobj->Pen.Style = iStyle;
118 return hobj;
121 HFONT
122 CreateFont(int iWidth, int iHeight, int iEscapement, int iOrientation, int iWeight,
123 DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut,
124 DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision,
125 DWORD dwQuality, DWORD dwPitchAndFamily,
126 const char* sFaceName)
128 HGDIOBJ hobj;
130 hobj = g_new0(struct _GdiObject, 1);
131 hobj->Type = GDI_FONT;
133 hobj->Font.Width = iWidth;
134 hobj->Font.Height = iHeight;
135 hobj->Font.Escapement = iEscapement;
136 hobj->Font.Orientation = iOrientation;
137 hobj->Font.Weight = iWeight;
139 hobj->Font.dwItalic = dwItalic;
140 hobj->Font.dwUnderline = dwUnderline;
141 hobj->Font.dwStrikeOut = dwStrikeOut;
142 hobj->Font.dwCharSet = dwCharSet;
143 hobj->Font.dwOutPrecision = dwOutPrecision;
144 hobj->Font.dwClipPrecision = dwClipPrecision;
145 hobj->Font.dwQuality = dwQuality;
146 hobj->Font.dwPitchAndFamily = dwPitchAndFamily;
148 hobj->Font.sFaceName = g_strdup(sFaceName);
150 /* ... */
152 return hobj;
156 CreateEnhMetaFile(HDC hdcRef, const char* sName, RECT* pbox, const char* sDesc)
158 HDC hdc;
160 g_return_val_if_fail(NULL != sName, NULL);
162 hdc = g_new0(struct _MetaFileDeviceContext, 1);
164 hdc->file = fopen(sName, "wb"); /* write binary */
166 return hdc;
169 HENHMETAFILE
170 CloseEnhMetaFile(HDC hdc)
172 g_return_val_if_fail(NULL != hdc, NULL);
174 WriteRecHead(hdc, 0x0, 0);
176 fclose(hdc->file);
177 g_free(hdc);
179 return NULL;
182 BOOL
183 DeleteEnhMetaFile(HENHMETAFILE hemf)
185 return TRUE;
188 BOOL
189 SetTextAlign(HDC hdc, wmfint iMode)
191 g_return_val_if_fail(hdc != NULL, FALSE);
193 WriteRecHead(hdc, 0x012E, 1);
194 fwrite_le(&iMode, sizeof(wmfint), 1, hdc->file);
196 return TRUE;
199 COLORREF
200 SetTextColor(HDC hdc, COLORREF color)
202 g_return_val_if_fail(hdc != NULL, FALSE);
204 WriteRecHead(hdc, 0x0209, 1);
205 fwrite_le(&color, sizeof(COLORREF), 1, hdc->file);
207 return TRUE;
211 * Drawing Functions
213 BOOL
214 MoveToEx(HDC hdc, wmfint x, wmfint y, LPPOINT ppt)
217 g_return_val_if_fail(hdc != NULL, FALSE);
219 if (ppt)
220 *ppt = hdc->actPos;
222 hdc->actPos.x = x;
223 hdc->actPos.y = y;
225 WriteRecHead(hdc, 0x0214, 2);
226 fwrite_le(&y, sizeof(wmfint), 1, hdc->file);
227 fwrite_le(&x, sizeof(wmfint), 1, hdc->file);
229 return TRUE;
232 BOOL
233 LineTo(HDC hdc, wmfint x, wmfint y)
235 g_return_val_if_fail(hdc != NULL, FALSE);
237 hdc->actPos.x = x;
238 hdc->actPos.y = y;
240 WriteRecHead(hdc, 0x0213, 2);
241 fwrite_le(&y, sizeof(wmfint), 1, hdc->file);
242 fwrite_le(&x, sizeof(wmfint), 1, hdc->file);
244 return TRUE;
247 BOOL
248 Polyline(HDC hdc, LPPOINT ppts, wmfint iNum)
250 int i;
252 g_return_val_if_fail(hdc != NULL, FALSE);
254 WriteRecHead(hdc, 0x0325, 2*iNum);
255 fwrite_le(&iNum, sizeof(wmfint), 1, hdc->file);
256 for (i = iNum - 1; i > -1; i--)
258 fwrite_le(&(ppts[i].y), sizeof(wmfint), 1, hdc->file);
259 fwrite_le(&(ppts[i].x), sizeof(wmfint), 1, hdc->file);
262 return TRUE;
265 BOOL
266 Polygon(HDC hdc, LPPOINT ppts, wmfint iNum)
268 int i;
270 g_return_val_if_fail(hdc != NULL, FALSE);
272 WriteRecHead(hdc, 0x0324, 2*iNum+1);
273 fwrite_le(&iNum, sizeof(wmfint), 1, hdc->file);
274 for (i = iNum - 1; i > -1; i--)
276 fwrite_le(&(ppts[i].y), sizeof(wmfint), 1, hdc->file);
277 fwrite_le(&(ppts[i].x), sizeof(wmfint), 1, hdc->file);
280 return TRUE;
283 BOOL
284 Rectangle(HDC hdc, wmfint iLeft, wmfint iTop, wmfint iRight, wmfint iBottom)
286 g_return_val_if_fail(hdc != NULL, FALSE);
288 WriteRecHead(hdc, 0x041B, 4);
289 fwrite_le(&iBottom, sizeof(wmfint), 1, hdc->file);
290 fwrite_le(&iRight, sizeof(wmfint), 1, hdc->file);
291 fwrite_le(&iTop, sizeof(wmfint), 1, hdc->file);
292 fwrite_le(&iLeft, sizeof(wmfint), 1, hdc->file);
294 return TRUE;
297 BOOL
298 Arc(HDC hdc, wmfint iLeft, wmfint iTop, wmfint iRight, wmfint iBottom,
299 wmfint iStartX, wmfint iStartY, wmfint iEndX, wmfint iEndY)
301 g_return_val_if_fail(hdc != NULL, FALSE);
303 WriteRecHead(hdc, 0x0817, 8);
305 fwrite_le(&iEndY, sizeof(wmfint), 1, hdc->file);
306 fwrite_le(&iEndX, sizeof(wmfint), 1, hdc->file);
308 fwrite_le(&iStartY, sizeof(wmfint), 1, hdc->file);
309 fwrite_le(&iStartX, sizeof(wmfint), 1, hdc->file);
311 fwrite_le(&iBottom, sizeof(wmfint), 1, hdc->file);
312 fwrite_le(&iRight, sizeof(wmfint), 1, hdc->file);
313 fwrite_le(&iTop, sizeof(wmfint), 1, hdc->file);
314 fwrite_le(&iLeft, sizeof(wmfint), 1, hdc->file);
316 return TRUE;
319 BOOL
320 Ellipse(HDC hdc, wmfint iLeft, wmfint iTop, wmfint iRight, wmfint iBottom)
322 g_return_val_if_fail(hdc != NULL, FALSE);
324 WriteRecHead(hdc, 0x0418, 4);
325 fwrite_le(&iBottom, sizeof(wmfint), 1, hdc->file);
326 fwrite_le(&iRight, sizeof(wmfint), 1, hdc->file);
327 fwrite_le(&iTop, sizeof(wmfint), 1, hdc->file);
328 fwrite_le(&iLeft, sizeof(wmfint), 1, hdc->file);
330 return TRUE;
334 BOOL
335 PolyBezier(HDC hdc, LPPOINT ppts, int iNum)
337 g_return_val_if_fail(hdc != NULL, FALSE);
339 /* ... */
341 return TRUE;
345 BOOL
346 TextOut(HDC hdc, wmfint iX, wmfint iY, const char* s, wmfint iNumChars)
348 g_return_val_if_fail(hdc != NULL, FALSE);
350 WriteRecHead(hdc, 0x0521, 3 + (iNumChars % 2) ? iNumChars / 2 : iNumChars / 2 + 1);
352 fwrite_le(&iNumChars, sizeof(wmfint), 1, hdc->file);
354 fwrite_le(s, 1, iNumChars, hdc->file);
355 if (iNumChars % 2) // fill to WORD
356 fwrite(s, 1, 1, hdc->file);
358 fwrite_le(&iY, sizeof(wmfint), 1, hdc->file);
359 fwrite_le(&iX, sizeof(wmfint), 1, hdc->file);
361 return TRUE;
364 HDC GetDC(void* hwnd)
366 return NULL;
369 } // eof namespace