WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
+static const REAL mm_per_inch = 25.4;
+static const REAL point_per_inch = 72.0;
+
static Status WINAPI NotificationHook(ULONG_PTR *token)
{
TRACE("%p\n", token);
return;
stretched = gdiplus_atan2(sin(*angle) / fabs(rad_y), cos(*angle) / fabs(rad_x));
- revs_off = roundr(*angle / (2.0 * M_PI)) - roundr(stretched / (2.0 * M_PI));
+ revs_off = gdip_round(*angle / (2.0 * M_PI)) - gdip_round(stretched / (2.0 * M_PI));
stretched += ((REAL)revs_off) * M_PI * 2.0;
*angle = stretched;
}
}
/* converts a given unit to its value in pixels */
-REAL convert_unit(REAL logpixels, GpUnit unit)
+REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
{
- switch(unit)
+ switch (unit)
{
- case UnitInch:
- return logpixels;
- case UnitPoint:
- return logpixels / 72.0;
- case UnitDocument:
- return logpixels / 300.0;
- case UnitMillimeter:
- return logpixels / 25.4;
- case UnitWorld:
- ERR("cannot convert UnitWorld\n");
- return 0.0;
- case UnitPixel:
- case UnitDisplay:
- default:
- return 1.0;
+ case UnitPixel:
+ case UnitWorld:
+ case UnitDisplay:
+ return units;
+ case UnitPoint:
+ return units * dpi / point_per_inch;
+ case UnitInch:
+ return units * dpi;
+ case UnitDocument:
+ return units * dpi / 300.0; /* Per MSDN */
+ case UnitMillimeter:
+ return units * dpi / mm_per_inch;
+ default:
+ FIXME("Unhandled unit type: %d\n", unit);
+ return 0;
+ }
+}
+
+/* converts value in pixels to a given unit */
+REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
+{
+ switch (unit)
+ {
+ case UnitPixel:
+ case UnitWorld:
+ case UnitDisplay:
+ return pixels;
+ case UnitPoint:
+ return pixels * point_per_inch / dpi;
+ case UnitInch:
+ return pixels / dpi;
+ case UnitDocument:
+ return pixels * 300.0 / dpi;
+ case UnitMillimeter:
+ return pixels * mm_per_inch / dpi;
+ default:
+ FIXME("Unhandled unit type: %d\n", unit);
+ return 0;
}
}
+REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
+{
+ REAL pixels = units_to_pixels(1.0, from, dpi);
+ return pixels_to_units(pixels, to, dpi);
+}
+
/* Calculates Bezier points from cardinal spline points. */
void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
REAL *y1, REAL *x2, REAL *y2)
REAL tension, REAL *x, REAL *y)
{
/* tangent at endpoints is the line from the endpoint to the adjacent point */
- *x = roundr(tension * (xadj - xend) + xend);
- *y = roundr(tension * (yadj - yend) + yend);
+ *x = gdip_round(tension * (xadj - xend) + xend);
+ *y = gdip_round(tension * (yadj - yend) + yend);
}
/* make sure path has enough space for len more points */