static GpPath *gdip_setup_path(struct _graphics *_this, GF_Path *path) { GpPath *tr = gdip_create_path(path); /*append current matrix*/ if (_this->mat) GdipTransformPath(tr, _this->mat); return tr; }
static void test_flatten(void) { GpStatus status; GpPath *path; GpMatrix *m; status = GdipCreatePath(FillModeAlternate, &path); expect(Ok, status); status = GdipCreateMatrix(&m); expect(Ok, status); /* NULL arguments */ status = GdipFlattenPath(NULL, NULL, 0.0); expect(InvalidParameter, status); status = GdipFlattenPath(NULL, m, 0.0); expect(InvalidParameter, status); /* flatten empty path */ status = GdipFlattenPath(path, NULL, 1.0); expect(Ok, status); status = GdipTransformPath(path, 0); expect(Ok, status); status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 50.0); expect(Ok, status); status = GdipFlattenPath(path, NULL, 1.0); expect(Ok, status); ok_path(path, flattenellipse_path, sizeof(flattenellipse_path)/sizeof(path_test_t), TRUE); status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 10.0, 50.0, 100.0); expect(Ok, status); status = GdipFlattenPath(path, NULL, 1.0); expect(Ok, status); ok_path(path, flattenline_path, sizeof(flattenline_path)/sizeof(path_test_t), FALSE); status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathArc(path, 0.0, 0.0, 100.0, 50.0, 0.0, 90.0); expect(Ok, status); status = GdipFlattenPath(path, NULL, 1.0); expect(Ok, status); ok_path(path, flattenarc_path, sizeof(flattenarc_path)/sizeof(path_test_t), TRUE); /* easy case - quater of a full circle */ status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathArc(path, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0); expect(Ok, status); status = GdipFlattenPath(path, NULL, 1.0); expect(Ok, status); ok_path(path, flattenquater_path, sizeof(flattenquater_path)/sizeof(path_test_t), FALSE); GdipDeleteMatrix(m); GdipDeletePath(path); }
/* * gdip_region_transform_tree: * @tree: a GpPathTree * @matrix: the GpMatrix to apply to the tree * * Recursively apply the @matrix to the @tree. */ GpStatus gdip_region_transform_tree (GpPathTree *tree, GpMatrix *matrix) { if (tree->path) { return GdipTransformPath (tree->path, matrix); } else { GpStatus status; status = gdip_region_transform_tree (tree->branch1, matrix); if (status == Ok) status = gdip_region_transform_tree (tree->branch2, matrix); return status; } }
static GF_Glyph *gdip_load_glyph(GF_FontReader *dr, u32 glyph_name) { GF_Rect bounds; GF_Glyph *glyph; GpPath *path_tmp; GpStringFormat *fmt; GpMatrix *mat; Float est_advance_h; unsigned short str[4]; int i; FontPriv *ctx = (FontPriv *)dr->udta; if (!ctx->font) return NULL; RectF rc; rc.X = rc.Y = 0; rc.Width = rc.Height = 0; GdipCreateStringFormat(StringFormatFlagsNoWrap | StringFormatFlagsNoFitBlackBox | StringFormatFlagsMeasureTrailingSpaces, LANG_NEUTRAL, &fmt); GdipSetStringFormatAlign(fmt, StringAlignmentNear); GdipCreatePath(FillModeAlternate, &path_tmp); if (glyph_name==0x20) { est_advance_h = ctx->whitespace_width; } else { /*to compute first glyph alignment (say 'x', we figure out its bounding full box by using the '_' char as wrapper (eg, "_x_") then the bounding box starting from xMin of the glyph ('x_'). The difference between both will give us a good approx of the glyph alignment*/ str[0] = glyph_name; str[1] = (unsigned short) '_'; str[2] = (unsigned short) 0; GdipAddPathString(path_tmp, (const WCHAR *)str, -1, ctx->font, ctx->font_style, ctx->em_size, &rc, fmt); GdipGetPathWorldBounds(path_tmp, &rc, NULL, NULL); est_advance_h = rc.Width - ctx->underscore_width; } GdipResetPath(path_tmp); str[0] = glyph_name; str[1] = (unsigned short) 0; rc.X = rc.Y = 0; rc.Width = rc.Height = 0; GdipAddPathString(path_tmp, (const WCHAR *)str, -1, ctx->font, ctx->font_style, ctx->em_size, &rc, fmt); GdipGetPathWorldBounds(path_tmp, &rc, NULL, NULL); /*flip so that we are in a font coordinate system - also move back the glyph to x=0 and y=baseline, GdiPlus doesn't do so*/ GdipCreateMatrix(&mat); GdipTranslateMatrix(mat, - rc.X, -ctx->ascent, MatrixOrderAppend); GdipScaleMatrix(mat, 1, -1, MatrixOrderAppend); GdipTransformPath(path_tmp, mat); GdipDeleteMatrix(mat); /*start enum*/ s32 count; GdipGetPointCount(path_tmp, &count); GpPointF *pts = new GpPointF[count]; BYTE *types = new BYTE[count]; GdipGetPathTypes(path_tmp, types, count); GdipGetPathPoints(path_tmp, pts, count); GF_SAFEALLOC(glyph, GF_Glyph); GF_SAFEALLOC(glyph->path, GF_Path); for (i=0; i<count; ) { BOOL closed = 0; s32 sub_type; sub_type = types[i] & PathPointTypePathTypeMask; if (sub_type == PathPointTypeStart) { gf_path_add_move_to(glyph->path, FLT2FIX(pts[i].X), FLT2FIX(pts[i].Y)); i++; } else if (sub_type == PathPointTypeLine) { gf_path_add_line_to(glyph->path, FLT2FIX(pts[i].X), FLT2FIX(pts[i].Y)); if (types[i] & PathPointTypeCloseSubpath) gf_path_close(glyph->path); i++; } else if (sub_type == PathPointTypeBezier) { assert(i+2<=count); gf_path_add_cubic_to(glyph->path, FLT2FIX(pts[i].X), FLT2FIX(pts[i].Y), FLT2FIX(pts[i+1].X), FLT2FIX(pts[i+1].Y), FLT2FIX(pts[i+2].X), FLT2FIX(pts[i+2].Y)); if (types[i+2] & PathPointTypeCloseSubpath) gf_path_close(glyph->path); i += 3; } else { assert(0); break; } } delete [] pts; delete [] types; GdipDeleteStringFormat(fmt); GdipDeletePath(path_tmp); glyph->ID = glyph_name; glyph->utf_name = glyph_name; glyph->vert_advance = (s32) (ctx->ascent-ctx->descent); glyph->horiz_advance = (s32) est_advance_h; gf_path_get_bounds(glyph->path, &bounds); glyph->width = FIX2INT(bounds.width); glyph->height = FIX2INT(bounds.height); return glyph; }
static M4Err gdip_add_text_to_path(FontRaster *dr, LPM4PATH path, Bool flipText, const unsigned short* string, Float left, Float top, Float x_scaling, Float y_scaling, Float ascent, M4Rect *bounds) { GpPath *path_tmp; GpMatrix *mat; GpStringFormat *fmt; Float real_start; unsigned short str[4]; FontPriv *ctx = (FontPriv *)dr->priv; if (!ctx->font) return M4BadParam; RectF rc; rc.X = rc.Y = 0; rc.Width = rc.Height = 0; /*find first non-space char and estimate its glyph pos since GDIplus doesn't give this info*/ s32 len = utf8_wcslen(string); s32 i=0; for (; i<len; i++) { if (string[i] != (unsigned short) ' ') break; } if (i>=len) return M4OK; GdipCreateStringFormat(StringFormatFlagsNoWrap | StringFormatFlagsNoFitBlackBox | StringFormatFlagsMeasureTrailingSpaces, LANG_NEUTRAL, &fmt); GdipSetStringFormatAlign(fmt, StringAlignmentNear); GdipCreatePath(FillModeAlternate, &path_tmp); /*to compute first glyph alignment (say 'x', we figure out its bounding full box by using the '_' char as wrapper (eg, "_x_") then the bounding box starting from xMin of the glyph ('x_'). The difference between both will give us a good approx of the glyph alignment*/ str[0] = (unsigned short) '_'; str[1] = string[i]; str[2] = (unsigned short) '_'; str[3] = (unsigned short) 0; GdipAddPathString(path_tmp, str, -1, ctx->font, ctx->font_style, ctx->font_size, &rc, fmt); GdipGetPathWorldBounds(path_tmp, &rc, NULL, NULL); Float w1 = rc.Width - 2 * ctx->underscore_width; GdipResetPath(path_tmp); str[0] = string[i]; str[1] = (unsigned short) '_'; str[2] = (unsigned short) 0; rc.X = rc.Y = 0; rc.Width = rc.Height = 0; GdipAddPathString(path_tmp, str, -1, ctx->font, ctx->font_style, ctx->font_size, &rc, fmt); GdipGetPathWorldBounds(path_tmp, &rc, NULL, NULL); real_start = w1 - (rc.Width - ctx->underscore_width); GdipResetPath(path_tmp); rc.X = rc.Y = 0; rc.Width = rc.Height = 0; GdipAddPathString(path_tmp, string, -1, ctx->font, ctx->font_style, ctx->font_size, &rc, fmt); GdipGetPathWorldBounds(path_tmp, &rc, NULL, NULL); GdipCreateMatrix(&mat); Float off_left = rc.X; Float off_left_real = rc.X; /*adjust all white space at begin*/ adjust_white_space(string, &off_left, -1*ctx->whitespace_width); if (flipText) { /*first translate in local system*/ GdipTranslateMatrix(mat, left - off_left + real_start, -top, MatrixOrderAppend); /*then scale as specified*/ GdipScaleMatrix(mat, x_scaling, -y_scaling, MatrixOrderAppend); } else { /*first translate in local system*/ GdipTranslateMatrix(mat, left - off_left + real_start, top-ascent, MatrixOrderAppend); /*then scale as specified*/ GdipScaleMatrix(mat, x_scaling, y_scaling, MatrixOrderAppend); } GdipTransformPath(path_tmp, mat); /*start enum*/ s32 count; GdipGetPointCount(path_tmp, &count); GpPointF *pts = new GpPointF[count]; BYTE *types = new BYTE[count]; GdipGetPathTypes(path_tmp, types, count); GdipGetPathPoints(path_tmp, pts, count); for (i=0; i<count; ) { BOOL closed = 0; s32 sub_type; sub_type = types[i] & PathPointTypePathTypeMask; if (sub_type == PathPointTypeStart) { m4_path_add_move_to(path, pts[i].X, pts[i].Y); i++; } else if (sub_type == PathPointTypeLine) { m4_path_add_line_to(path, pts[i].X, pts[i].Y); if (types[i] & PathPointTypeCloseSubpath) m4_path_close(path); i++; } else if (sub_type == PathPointTypeBezier) { assert(i+2<=count); m4_path_add_cubic_to(path, pts[i].X, pts[i].Y, pts[i+1].X, pts[i+1].Y, pts[i+2].X, pts[i+2].Y); if (types[i+2] & PathPointTypeCloseSubpath) m4_path_close(path); i += 3; } else { assert(0); break; } } delete [] pts; delete [] types; GdipResetPath(path_tmp); adjust_white_space(string, &rc.Width, ctx->whitespace_width); rc.X = off_left_real; rc.X = off_left; /*special case where string is just space*/ if (!rc.Height) rc.Height = 1; GdipAddPathRectangles(path_tmp, &rc, 1); GdipGetPathWorldBounds(path_tmp, &rc, mat, NULL); bounds->x = rc.X; bounds->y = rc.Y; bounds->width = rc.Width; bounds->height = rc.Height; GdipDeleteStringFormat(fmt); GdipDeletePath(path_tmp); GdipDeleteMatrix(mat); return M4OK; }
static GF_Err gdip_surface_fill(GF_SURFACE _this, GF_STENCIL stencil) { GpStatus ret; GpMatrix *newmat; struct _stencil *_sten; GPGRAPH(); if (!_this) return GF_BAD_PARAM; if (!_graph->current) return GF_OK; _sten = (struct _stencil *)stencil; assert(_sten); #ifdef NODRAW return GF_OK; #endif if (_graph->clip) GdipSetClipPath(_graph->graph, _graph->clip, CombineModeReplace); switch (_sten->type) { case GF_STENCIL_SOLID: assert(_sten->pSolid); GdipFillPath(_graph->graph, _sten->pSolid, _graph->current); break; case GF_STENCIL_LINEAR_GRADIENT: if (_sten->pMat) { /*rebuild gradient*/ gdip_recompute_line_gradient(_sten); GdipResetTextureTransform((GpTexture*)_sten->pLinear); if (_sten->pMat) { GdipCloneMatrix(_sten->pMat, &newmat); } else { GdipCreateMatrix(&newmat); } GdipMultiplyMatrix(newmat, _sten->pLinearMat, MatrixOrderPrepend); GdipSetTextureTransform((GpTexture*)_sten->pLinear, newmat); GdipDeleteMatrix(newmat); } GdipFillPath(_graph->graph, _sten->pLinear, _graph->current); break; case GF_STENCIL_RADIAL_GRADIENT: /*build gradient*/ gdip_recompute_radial_gradient(_sten); GdipSetCompositingQuality(_graph->graph, CompositingQualityHighSpeed); GdipSetInterpolationMode(_graph->graph, InterpolationModeLowQuality); GdipSetSmoothingMode(_graph->graph, SmoothingModeHighSpeed); /*check if we need to draw solid background (GDIplus doesn't implement padded mode on path gradients)*/ if (_sten->pSolid) { GpPath *tr; GdipClonePath(_sten->circle, &tr); GdipTransformPath(tr, _sten->pMat); GdipSetClipPath(_graph->graph, tr, CombineModeExclude); GdipFillPath(_graph->graph, _sten->pSolid, _graph->current); GdipDeletePath(tr); GdipResetClip(_graph->graph); if (_graph->clip) GdipSetClipPath(_graph->graph, _graph->clip, CombineModeReplace); } GdipFillPath(_graph->graph, _sten->pRadial, _graph->current); break; case GF_STENCIL_VERTEX_GRADIENT: assert(_sten->pRadial); if (_sten->pMat) GdipSetTextureTransform((GpTexture*)_sten->pRadial, _sten->pMat); ret = GdipFillPath(_graph->graph, _sten->pRadial, _graph->current); break; case GF_STENCIL_TEXTURE: gdip_load_texture(_sten); if (_sten->pTexture) { GpMatrix *newmat; GdipResetTextureTransform((GpTexture*)_sten->pTexture); if (_sten->pMat) { GdipCloneMatrix(_sten->pMat, &newmat); } else { GdipCreateMatrix(&newmat); } /*gdip flip*/ if (_graph->center_coords && !(_sten->tiling&GF_TEXTURE_FLIP) ) GdipScaleMatrix(newmat, 1, -1, MatrixOrderPrepend); else if (!_graph->center_coords && (_sten->tiling&GF_TEXTURE_FLIP) ) GdipScaleMatrix(newmat, 1, -1, MatrixOrderPrepend); GdipSetTextureTransform((GpTexture*)_sten->pTexture, newmat); GdipDeleteMatrix(newmat); GdipSetInterpolationMode(_graph->graph, (_sten->tFilter==GF_TEXTURE_FILTER_HIGH_QUALITY) ? InterpolationModeHighQuality : InterpolationModeLowQuality); GdipFillPath(_graph->graph, _sten->pTexture, _graph->current); } break; } return GF_OK; }