static void draw_rect(DiaRenderer *self, Point *ul_corner, Point *lr_corner, Color *fill, Color *stroke) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HPEN hPen; DIAG_NOTE(renderer, "draw_rect %f,%f -> %f,%f\n", ul_corner->x, ul_corner->y, lr_corner->x, lr_corner->y); if (fill) { W32::HGDIOBJ hBrush, hBrOld; W32::COLORREF rgb = W32COLOR(fill); hBrush = W32::CreateSolidBrush(rgb); hBrOld = W32::SelectObject(renderer->hFileDC, hBrush); W32::Rectangle (renderer->hFileDC, SCX(ul_corner->x), SCY(ul_corner->y), SCX(lr_corner->x), SCY(lr_corner->y)); W32::SelectObject (renderer->hFileDC, W32::GetStockObject (HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); } if (stroke) { hPen = UsePen(renderer, stroke); W32::Rectangle (renderer->hFileDC, SCX(ul_corner->x), SCY(ul_corner->y), SCX(lr_corner->x), SCY(lr_corner->y)); DonePen(renderer, hPen); } }
static void draw_ellipse(DiaRenderer *self, Point *center, real width, real height, Color *fill, Color *stroke) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HPEN hPen; W32::HGDIOBJ hBrush, hBrOld; DIAG_NOTE(renderer, "draw_ellipse %fx%f @ %f,%f\n", width, height, center->x, center->y); if (fill) { W32::COLORREF rgb = W32COLOR(fill); hBrush = W32::CreateSolidBrush(rgb); hBrOld = W32::SelectObject(renderer->hFileDC, hBrush); } if (stroke) hPen = UsePen(renderer, stroke); W32::Ellipse(renderer->hFileDC, SCX(center->x - width / 2), /* bbox corners */ SCY(center->y - height / 2), SCX(center->x + width / 2), SCY(center->y + height / 2)); if (stroke) DonePen(renderer, hPen); if (fill) { W32::SelectObject(renderer->hFileDC, W32::GetStockObject (HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); } }
/* not defined in compatibility layer */ static void fill_bezier(DiaRenderer *self, BezPoint *points, /* Last point must be same as first point */ int numpoints, Color *colour) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HGDIOBJ hBrush, hBrOld; W32::COLORREF rgb = W32COLOR(colour); DIAG_NOTE(renderer, "fill_bezier n:%d %fx%f ...\n", numpoints, points->p1.x, points->p1.y); hBrush = W32::CreateSolidBrush(rgb); hBrOld = W32::SelectObject(renderer->hFileDC, hBrush); W32::BeginPath (renderer->hFileDC); draw_bezier(self, points, numpoints, NULL); W32::EndPath (renderer->hFileDC); W32::FillPath (renderer->hFileDC); W32::SelectObject(renderer->hFileDC, W32::GetStockObject (HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); }
static void _bezier (DiaRenderer *self, BezPoint *points, int numpoints, Color *colour, gboolean fill, gboolean closed) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HGDIOBJ hBrush, hBrOld; W32::HPEN hPen; W32::COLORREF rgb = W32COLOR(colour); DIAG_NOTE(renderer, "_bezier n:%d %fx%f ...\n", numpoints, points->p1.x, points->p1.y); if (fill) { hBrush = W32::CreateSolidBrush(rgb); hBrOld = W32::SelectObject(renderer->hFileDC, hBrush); } else { hPen = UsePen(renderer, colour); } W32::BeginPath (renderer->hFileDC); for (int i = 0; i < numpoints; ++i) { switch (points[i].type) { case BezPoint::BEZ_MOVE_TO : W32::MoveToEx (renderer->hFileDC, SCX(points[i].p1.x), SCY(points[i].p1.y), NULL); break; case BezPoint::BEZ_LINE_TO : W32::LineTo (renderer->hFileDC, SCX(points[i].p1.x), SCY(points[i].p1.y)); break; case BezPoint::BEZ_CURVE_TO : { W32::POINT pts[3] = { {SCX(points[i].p1.x), SCY(points[i].p1.y)}, {SCX(points[i].p2.x), SCY(points[i].p2.y)}, {SCX(points[i].p3.x), SCY(points[i].p3.y)} }; W32::PolyBezierTo (renderer->hFileDC, pts, 3); } break; } } if (closed) W32::CloseFigure (renderer->hFileDC); W32::EndPath (renderer->hFileDC); if (fill) { W32::FillPath (renderer->hFileDC); W32::SelectObject(renderer->hFileDC, W32::GetStockObject (HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); } else { W32::StrokePath (renderer->hFileDC); DonePen(renderer, hPen); } }
static void fill_arc(DiaRenderer *self, Point *center, real width, real height, real angle1, real angle2, Color *colour) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HPEN hPen; W32::HGDIOBJ hBrush; W32::POINT ptStart, ptEnd; W32::COLORREF rgb = W32COLOR(colour); DIAG_NOTE(renderer, "fill_arc %fx%f <%f,<%f @%f,%f\n", width, height, angle1, angle2, center->x, center->y); if (angle1 > angle2) { /* make it counter-clockwise by swapping start/end */ real tmp = angle1; angle1 = angle2; angle2 = tmp; } /* calculate start and end points of arc */ ptStart.x = SCX(center->x + (width / 2.0) * cos((M_PI / 180.0) * angle1)); ptStart.y = SCY(center->y - (height / 2.0) * sin((M_PI / 180.0) * angle1)); ptEnd.x = SCX(center->x + (width / 2.0) * cos((M_PI / 180.0) * angle2)); ptEnd.y = SCY(center->y - (height / 2.0) * sin((M_PI / 180.0) * angle2)); hPen = UsePen(renderer, NULL); /* no border */ hBrush = W32::CreateSolidBrush(rgb); W32::SelectObject(renderer->hFileDC, hBrush); W32::Pie(renderer->hFileDC, SCX(center->x - width / 2), /* bbox corners */ SCY(center->y - height / 2), SCX(center->x + width / 2), SCY(center->y + height / 2), ptStart.x, ptStart.y, ptEnd.x, ptEnd.y); W32::SelectObject(renderer->hFileDC, W32::GetStockObject (HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); DonePen(renderer, hPen); }
static void draw_polygon(DiaRenderer *self, Point *points, int num_points, Color *fill, Color *stroke) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HPEN hPen; W32::POINT* pts; int i; W32::HBRUSH hBrush, hBrOld; W32::COLORREF rgb = fill ? W32COLOR(fill) : 0; DIAG_NOTE(renderer, "draw_polygon n:%d %f,%f ...\n", num_points, points->x, points->y); if (num_points < 2) return; pts = g_new (W32::POINT, num_points+1); for (i = 0; i < num_points; i++) { pts[i].x = SCX(points[i].x); pts[i].y = SCY(points[i].y); } if (stroke) hPen = UsePen(renderer, stroke); if (fill) { hBrush = W32::CreateSolidBrush(rgb); hBrOld = (W32::HBRUSH)W32::SelectObject(renderer->hFileDC, hBrush); } W32::Polygon(renderer->hFileDC, pts, num_points); if (stroke) DonePen(renderer, hPen); if (fill) { W32::SelectObject(renderer->hFileDC, W32::GetStockObject(HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); } g_free(pts); }
static void fill_rect(DiaRenderer *self, Point *ul_corner, Point *lr_corner, Color *colour) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HGDIOBJ hBrush, hBrOld; W32::COLORREF rgb = W32COLOR(colour); DIAG_NOTE(renderer, "fill_rect %f,%f -> %f,%f\n", ul_corner->x, ul_corner->y, lr_corner->x, lr_corner->y); hBrush = W32::CreateSolidBrush(rgb); hBrOld = W32::SelectObject(renderer->hFileDC, hBrush); draw_rect(self, ul_corner, lr_corner, NULL); W32::SelectObject(renderer->hFileDC, W32::GetStockObject (HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); }
static void fill_polygon(DiaRenderer *self, Point *points, int num_points, Color *colour) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HBRUSH hBrush, hBrOld; W32::COLORREF rgb = W32COLOR(colour); DIAG_NOTE(renderer, "fill_polygon n:%d %f,%f ...\n", num_points, points->x, points->y); hBrush = W32::CreateSolidBrush(rgb); hBrOld = (W32::HBRUSH)W32::SelectObject(renderer->hFileDC, hBrush); draw_polygon(self, points, num_points, NULL); W32::SelectObject(renderer->hFileDC, W32::GetStockObject(HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); }
static void fill_ellipse(DiaRenderer *self, Point *center, real width, real height, Color *colour) { WmfRenderer *renderer = WMF_RENDERER (self); W32::HPEN hPen; W32::HGDIOBJ hBrush, hBrOld; W32::COLORREF rgb = W32COLOR(colour); DIAG_NOTE(renderer, "fill_ellipse %fx%f @ %f,%f\n", width, height, center->x, center->y); hBrush = W32::CreateSolidBrush(rgb); hBrOld = W32::SelectObject(renderer->hFileDC, hBrush); draw_ellipse(self, center, width, height, NULL); W32::SelectObject(renderer->hFileDC, W32::GetStockObject (HOLLOW_BRUSH) ); W32::DeleteObject(hBrush); }
static void draw_string(DiaRenderer *self, const char *text, Point *pos, Alignment alignment, Color *colour) { WmfRenderer *renderer = WMF_RENDERER (self); int len; W32::HGDIOBJ hOld; W32::COLORREF rgb = W32COLOR(colour); DIAG_NOTE(renderer, "draw_string %f,%f %s\n", pos->x, pos->y, text); W32::SetTextColor(renderer->hFileDC, rgb); switch (alignment) { case ALIGN_LEFT: W32::SetTextAlign(renderer->hFileDC, TA_LEFT+TA_BASELINE); break; case ALIGN_CENTER: W32::SetTextAlign(renderer->hFileDC, TA_CENTER+TA_BASELINE); break; case ALIGN_RIGHT: W32::SetTextAlign(renderer->hFileDC, TA_RIGHT+TA_BASELINE); break; } /* work out size of first chunk of text */ len = strlen(text); hOld = W32::SelectObject(renderer->hFileDC, renderer->hFont); { // one way to go, but see below ... char* scp = NULL; /* convert from utf8 to active codepage */ static char codepage[10]; #ifndef HAVE_LIBEMF sprintf (codepage, "CP%d", W32::GetACP ()); #else /* GetACP() not available in libEMF */ sprintf (codepage, "CP1252"); #endif scp = g_convert (text, strlen (text), codepage, "UTF-8", NULL, NULL, NULL); if (scp) { W32::TextOut(renderer->hFileDC, SCX(pos->x), SCY(pos->y), scp, strlen(scp)); g_free (scp); } else // converson failed, write unicode { long wclen = 0; gunichar2* swc = g_utf8_to_utf16 (text, -1, NULL, &wclen, NULL); W32::TextOutW (renderer->hFileDC, SCX(pos->x), SCY(pos->y), reinterpret_cast<W32::LPCWSTR>(swc), wclen); g_free (swc); } } W32::SelectObject(renderer->hFileDC, hOld); }
G_END_DECLS /* * helper macros */ #define W32COLOR(c) \ (W32::COLORREF)( 0xff * c->red + \ ((unsigned char)(0xff * c->green)) * 256 + \ ((unsigned char)(0xff * c->blue)) * 65536) #define SC(a) ((int)((a)*renderer->scale)) #define SCX(a) ((int)(((a)+renderer->xoff)*renderer->scale)) #define SCY(a) ((int)(((a)+renderer->yoff)*renderer->scale)) /* * helper functions */ static W32::HPEN UsePen(WmfRenderer* renderer, Color* colour) { W32::HPEN hOldPen; if (colour) { W32::COLORREF rgb = W32COLOR(colour); #if defined(G_OS_WIN32) || HAVE_LIBEMF if ((renderer->platform_is_nt && renderer->hPrintDC) || renderer->target_emf) { W32::LOGBRUSH logbrush; W32::DWORD dashes[6]; int num_dashes = 0; int dashlen = renderer->nDashLen; int dotlen = renderer->nDashLen / 10; logbrush.lbStyle = BS_SOLID; logbrush.lbColor = rgb; logbrush.lbHatch = 0; switch (renderer->fnPenStyle & PS_STYLE_MASK) { case PS_SOLID : break; case PS_DASH : num_dashes = 2; dashes[0] = dashes[1] = dashlen; break; case PS_DASHDOT : num_dashes = 4; dashes[1] = dashes[3] = MAX((dashlen - dotlen) / 2, 1); dashes[0] = dashlen; dashes[2] = dotlen; break; case PS_DASHDOTDOT : num_dashes = 6; dashes[0] = dashlen; dashes[1] = dashes[3] = dashes[5] = MAX((dashlen - 2 * dotlen)/3, 1); dashes[2] = dashes[4] = dotlen; break; case PS_DOT : num_dashes = 2; dashes[0] = dashes[1] = dotlen; break; default : g_assert_not_reached (); } renderer->hPen = W32::ExtCreatePen ( (renderer->fnPenStyle & ~(PS_STYLE_MASK)) | (PS_GEOMETRIC | (num_dashes > 0 ? PS_USERSTYLE : 0)), renderer->nLineWidth, &logbrush, num_dashes, num_dashes > 0 ? dashes : 0); } else #endif /* G_OS_WIN32 */ { renderer->hPen = W32::CreatePen(renderer->fnPenStyle, renderer->nLineWidth, rgb); } } else { renderer->hPen = (W32::HPEN)W32::GetStockObject(NULL_PEN); } hOldPen = (W32::HPEN)W32::SelectObject(renderer->hFileDC, renderer->hPen); return hOldPen; }