GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen) { GpStatus stat; TRACE("(%p, %p)\n", pen, clonepen); if(!pen || !clonepen) return InvalidParameter; *clonepen = heap_alloc_zero(sizeof(GpPen)); if(!*clonepen) return OutOfMemory; **clonepen = *pen; (*clonepen)->customstart = NULL; (*clonepen)->customend = NULL; (*clonepen)->brush = NULL; (*clonepen)->dashes = NULL; stat = GdipCloneBrush(pen->brush, &(*clonepen)->brush); if (stat == Ok && pen->customstart) stat = GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart); if (stat == Ok && pen->customend) stat = GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend); if (stat == Ok && pen->dashes) { (*clonepen)->dashes = heap_alloc_zero(pen->numdashes * sizeof(REAL)); if ((*clonepen)->dashes) memcpy((*clonepen)->dashes, pen->dashes, pen->numdashes * sizeof(REAL)); else stat = OutOfMemory; } if (stat != Ok) { GdipDeletePen(*clonepen); *clonepen = NULL; return stat; } TRACE("<-- %p\n", *clonepen); return Ok; }
GpStatus WINGDIPAPI GdipGetPenCustomEndCap (GpPen *pen, GpCustomLineCap **customCap) { if (!pen || !customCap) return InvalidParameter; if (!pen->custom_end_cap) { *customCap = NULL; return Ok; } return GdipCloneCustomLineCap (pen->custom_end_cap, customCap); }
GpStatus WINGDIPAPI GdipGetPenCustomStartCap(GpPen *pen, GpCustomLineCap** customCap) { TRACE("(%p, %p)\n", pen, customCap); if(!pen || !customCap) return InvalidParameter; if(!pen->customstart){ *customCap = NULL; return Ok; } return GdipCloneCustomLineCap(pen->customstart, customCap); }
GpStatus WINGDIPAPI GdipSetPenCustomEndCap (GpPen *pen, GpCustomLineCap *customCap) { GpStatus status; GpCustomLineCap *clonedCap; if (!pen) return InvalidParameter; status = GdipCloneCustomLineCap (customCap, &clonedCap); if (status == Ok) { pen->custom_end_cap = clonedCap; pen->end_cap = LineCapCustom; } return status; }
GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap) { GpCustomLineCap * cap; GpStatus ret; TRACE("(%p, %p)\n", pen, customCap); /* native crashes on pen == NULL, customCap != NULL */ if(!customCap) return InvalidParameter; if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){ GdipDeleteCustomLineCap(pen->customstart); pen->startcap = LineCapCustom; pen->customstart = cap; } return ret; }
// coverity[+alloc : arg-*1] GpStatus WINGDIPAPI GdipClonePen (GpPen *pen, GpPen **clonepen) { GpPen *result; if (!pen || !clonepen) return InvalidParameter; result = gdip_pen_new (); if (!result) { *clonepen = NULL; return OutOfMemory; } result->own_brush = pen->own_brush; result->color = pen->color; result->width = pen->width; result->miter_limit = pen->miter_limit; result->line_join = pen->line_join; result->dash_style = pen->dash_style; result->line_cap = pen->line_cap; result->end_cap = pen->end_cap; result->mode = pen->mode; result->dash_offset = pen->dash_offset; result->dash_count = pen->dash_count; result->own_dash_array = pen->own_dash_array; result->compound_count = pen->compound_count; result->unit = pen->unit; gdip_cairo_matrix_copy (&result->matrix, &pen->matrix); result->changed = pen->changed; /* Make a copy of dash array only if it is owned by the pen - i.e. it is not * a global array. */ if (pen->dash_count > 0 && pen->own_dash_array) { result->dash_array = (float *) GdipAlloc (pen->dash_count * sizeof (float)); if (!result->dash_array) goto error; memcpy (result->dash_array, pen->dash_array, pen->dash_count * sizeof (float)); } else result->dash_array = pen->dash_array; if (pen->compound_count > 0) { result->compound_array = (float *) GdipAlloc (pen->compound_count * sizeof (float)); if (!result->compound_array) goto error; memcpy (result->compound_array, pen->compound_array, pen->compound_count * sizeof (float)); } if (pen->custom_start_cap) { GpStatus status = GdipCloneCustomLineCap (pen->custom_start_cap, &result->custom_start_cap); if (status != Ok) goto error; } if (pen->custom_end_cap) { GpStatus status = GdipCloneCustomLineCap (pen->custom_end_cap, &result->custom_end_cap); if (status != Ok) goto error; } if (pen->own_brush) { GpSolidFill *oldBrush = (GpSolidFill *) pen->brush; GpStatus status = GdipCreateSolidFill (oldBrush->color, (GpSolidFill **) &result->brush); if (status != Ok) goto error; } else { result->brush = pen->brush; } *clonepen = result; return Ok; error: GdipDeletePen (result); *clonepen = NULL; return OutOfMemory; }