~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/gdiplus/gdiplus.c

Version: ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Copyright (C) 2007 Google (Evan Stade)
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the Free Software
 16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 17  */
 18 
 19 #include <stdarg.h>
 20 #include <math.h>
 21 
 22 #include "windef.h"
 23 #include "winbase.h"
 24 #include "winerror.h"
 25 #include "wine/debug.h"
 26 #include "wingdi.h"
 27 
 28 #include "objbase.h"
 29 
 30 #include "winreg.h"
 31 #include "shlwapi.h"
 32 
 33 #include "gdiplus.h"
 34 #include "gdiplus_private.h"
 35 
 36 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
 37 
 38 static Status WINAPI NotificationHook(ULONG_PTR *token)
 39 {
 40     TRACE("%p\n", token);
 41     if(!token)
 42         return InvalidParameter;
 43 
 44     return Ok;
 45 }
 46 
 47 static void WINAPI NotificationUnhook(ULONG_PTR token)
 48 {
 49     TRACE("%ld\n", token);
 50 }
 51 
 52 /*****************************************************
 53  *      DllMain
 54  */
 55 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
 56 {
 57     TRACE("(%p, %d, %p)\n", hinst, reason, reserved);
 58 
 59     switch(reason)
 60     {
 61     case DLL_WINE_PREATTACH:
 62         return FALSE;  /* prefer native version */
 63 
 64     case DLL_PROCESS_ATTACH:
 65         DisableThreadLibraryCalls( hinst );
 66         break;
 67     }
 68     return TRUE;
 69 }
 70 
 71 /*****************************************************
 72  *      GdiplusStartup [GDIPLUS.@]
 73  */
 74 Status WINAPI GdiplusStartup(ULONG_PTR *token, const struct GdiplusStartupInput *input,
 75                              struct GdiplusStartupOutput *output)
 76 {
 77     if(!token || !input)
 78         return InvalidParameter;
 79 
 80     TRACE("%p %p %p\n", token, input, output);
 81     TRACE("GdiplusStartupInput %d %p %d %d\n", input->GdiplusVersion,
 82           input->DebugEventCallback, input->SuppressBackgroundThread,
 83           input->SuppressExternalCodecs);
 84 
 85     if(input->GdiplusVersion != 1)
 86         return UnsupportedGdiplusVersion;
 87 
 88     if(input->SuppressBackgroundThread){
 89         if(!output)
 90             return InvalidParameter;
 91 
 92         output->NotificationHook = NotificationHook;
 93         output->NotificationUnhook = NotificationUnhook;
 94     }
 95 
 96     /* FIXME: DebugEventCallback ignored */
 97 
 98     return Ok;
 99 }
100 
101 /*****************************************************
102  *      GdiplusShutdown [GDIPLUS.@]
103  */
104 void WINAPI GdiplusShutdown(ULONG_PTR token)
105 {
106     /* FIXME: no object tracking */
107 }
108 
109 /*****************************************************
110  *      GdipAlloc [GDIPLUS.@]
111  */
112 void* WINGDIPAPI GdipAlloc(SIZE_T size)
113 {
114     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
115 }
116 
117 /*****************************************************
118  *      GdipFree [GDIPLUS.@]
119  */
120 void WINGDIPAPI GdipFree(void* ptr)
121 {
122     HeapFree(GetProcessHeap(), 0, ptr);
123 }
124 
125 /* Calculates the bezier points needed to fill in the arc portion starting at
126  * angle start and ending at end.  These two angles should be no more than 90
127  * degrees from each other.  x1, y1, x2, y2 describes the bounding box (upper
128  * left and width and height).  Angles must be in radians. write_first indicates
129  * that the first bezier point should be written out (usually this is false).
130  * pt is the array of GpPointFs that gets written to.
131  **/
132 static void add_arc_part(GpPointF * pt, REAL x1, REAL y1, REAL x2, REAL y2,
133     REAL start, REAL end, BOOL write_first)
134 {
135     REAL center_x, center_y, rad_x, rad_y, cos_start, cos_end,
136         sin_start, sin_end, a, half;
137     INT i;
138 
139     rad_x = x2 / 2.0;
140     rad_y = y2 / 2.0;
141     center_x = x1 + rad_x;
142     center_y = y1 + rad_y;
143 
144     cos_start = cos(start);
145     cos_end = cos(end);
146     sin_start = sin(start);
147     sin_end = sin(end);
148 
149     half = (end - start) / 2.0;
150     a = 4.0 / 3.0 * (1 - cos(half)) / sin(half);
151 
152     if(write_first){
153         pt[0].X = cos_start;
154         pt[0].Y = sin_start;
155     }
156     pt[1].X = cos_start - a * sin_start;
157     pt[1].Y = sin_start + a * cos_start;
158 
159     pt[3].X = cos_end;
160     pt[3].Y = sin_end;
161     pt[2].X = cos_end + a * sin_end;
162     pt[2].Y = sin_end - a * cos_end;
163 
164     /* expand the points back from the unit circle to the ellipse */
165     for(i = (write_first ? 0 : 1); i < 4; i ++){
166         pt[i].X = pt[i].X * rad_x + center_x;
167         pt[i].Y = pt[i].Y * rad_y + center_y;
168     }
169 }
170 
171 /* We plot the curve as if it is on a circle then stretch the points.  This
172  * adjusts the angles so that when we stretch the points they will end in the
173  * right place. This is only complicated because atan and atan2 do not behave
174  * conveniently. */
175 static void unstretch_angle(REAL * angle, REAL rad_x, REAL rad_y)
176 {
177     REAL stretched;
178     INT revs_off;
179 
180     *angle = deg2rad(*angle);
181 
182     if(fabs(cos(*angle)) < 0.00001 || fabs(sin(*angle)) < 0.00001)
183         return;
184 
185     stretched = gdiplus_atan2(sin(*angle) / fabs(rad_y), cos(*angle) / fabs(rad_x));
186     revs_off = roundr(*angle / (2.0 * M_PI)) - roundr(stretched / (2.0 * M_PI));
187     stretched += ((REAL)revs_off) * M_PI * 2.0;
188     *angle = stretched;
189 }
190 
191 /* Stores the bezier points that correspond to the arc in points.  If points is
192  * null, just return the number of points needed to represent the arc. */
193 INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
194     REAL startAngle, REAL sweepAngle)
195 {
196     INT i, count;
197     REAL end_angle, start_angle, endAngle;
198 
199     endAngle = startAngle + sweepAngle;
200     unstretch_angle(&startAngle, x2 / 2.0, y2 / 2.0);
201     unstretch_angle(&endAngle, x2 / 2.0, y2 / 2.0);
202 
203     count = ceilf(fabs(endAngle - startAngle) / M_PI_2) * 3 + 1;
204     /* don't make more than a full circle */
205     count = min(MAX_ARC_PTS, count);
206 
207     if(count == 1)
208         return 0;
209     if(!points)
210         return count;
211 
212     /* start_angle and end_angle are the iterative variables */
213     start_angle = startAngle;
214 
215     for(i = 0; i < count - 1; i += 3){
216         /* check if we've overshot the end angle */
217         if( sweepAngle > 0.0 )
218             end_angle = min(start_angle + M_PI_2, endAngle);
219         else
220             end_angle = max(start_angle - M_PI_2, endAngle);
221 
222         add_arc_part(&points[i], x1, y1, x2, y2, start_angle, end_angle, i == 0);
223 
224         start_angle += M_PI_2 * (sweepAngle < 0.0 ? -1.0 : 1.0);
225     }
226 
227     return count;
228 }
229 
230 COLORREF ARGB2COLORREF(ARGB color)
231 {
232     /*
233     Packing of these color structures:
234     COLORREF:   00bbggrr
235     ARGB:       aarrggbb
236     FIXME:doesn't handle alpha channel
237     */
238     return ((color & 0x0000ff) << 16) +
239            (color & 0x00ff00) +
240            ((color & 0xff0000) >> 16);
241 }
242 
243 /* Like atan2, but puts angle in correct quadrant if dx is 0. */
244 REAL gdiplus_atan2(REAL dy, REAL dx)
245 {
246     if((dx == 0.0) && (dy != 0.0))
247         return dy > 0.0 ? M_PI_2 : -M_PI_2;
248 
249     return atan2(dy, dx);
250 }
251 
252 GpStatus hresult_to_status(HRESULT res)
253 {
254     switch(res){
255         case S_OK:
256             return Ok;
257         case E_OUTOFMEMORY:
258             return OutOfMemory;
259         case E_INVALIDARG:
260             return InvalidParameter;
261         default:
262             return GenericError;
263     }
264 }
265 
266 /* converts a given unit to its value in pixels */
267 REAL convert_unit(HDC hdc, GpUnit unit)
268 {
269     switch(unit)
270     {
271         case UnitInch:
272             return (REAL) GetDeviceCaps(hdc, LOGPIXELSX);
273         case UnitPoint:
274             return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 72.0;
275         case UnitDocument:
276             return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 300.0;
277         case UnitMillimeter:
278             return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 25.4;
279         case UnitWorld:
280             ERR("cannot convert UnitWorld\n");
281             return 0.0;
282         case UnitPixel:
283         case UnitDisplay:
284         default:
285             return 1.0;
286     }
287 }
288 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.