static bool HHVM_METHOD(ImagickDraw, pathCurveToRelative, double x1, double y1, double x2, double y2, double x, double y) { auto wand = getDrawingWandResource(Object{this_}); DrawPathCurveToRelative(wand->getWand(), x1, y1, x2, y2, x, y); return true; }
static bool HHVM_METHOD(ImagickDraw, setTextUnderColor, const Variant& under_color) { auto wand = getDrawingWandResource(Object{this_}); auto pixel(buildColorWand(under_color)); DrawSetTextUnderColor(wand->getWand(), pixel->getWand()); return true; }
static bool HHVM_METHOD(ImagickDraw, setStrokeColor, const Variant& stroke_pixel) { auto wand = getDrawingWandResource(Object{this_}); auto pixel(buildColorWand(stroke_pixel)); DrawSetStrokeColor(wand->getWand(), pixel->getWand()); return true; }
static bool HHVM_METHOD(ImagickDraw, arc, double sx, double sy, double ex, double ey, double sd, double ed) { auto wand = getDrawingWandResource(Object{this_}); DrawArc(wand->getWand(), sx, sy, ex, ey, sd, ed); return true; }
static bool HHVM_METHOD(ImagickDraw, roundRectangle, double x1, double y1, double x2, double y2, double rx, double ry) { auto wand = getDrawingWandResource(Object{this_}); DrawRoundRectangle(wand->getWand(), x1, y1, x2, y2, rx, ry); return true; }
static bool HHVM_METHOD(ImagickDraw, ellipse, double ox, double oy, double rx, double ry, double start, double end) { auto wand = getDrawingWandResource(Object{this_}); DrawEllipse(wand->getWand(), ox, oy, rx, ry, start, end); return true; }
static bool HHVM_METHOD(ImagickPixel, setColor, const String& color) { auto wand = getPixelWandResource(this_); if (PixelSetColor(wand->getWand(), color.c_str()) == MagickFalse) { IMAGICKPIXEL_THROW("Unable to set ImagickPixel color"); } return true; }
static bool HHVM_METHOD(ImagickDraw, popPattern) { auto wand = getDrawingWandResource(Object{this_}); auto status = DrawPopPattern(wand->getWand()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to terminate the pattern definition"); } return true; }
static bool HHVM_METHOD(ImagickDraw, push) { auto wand = getDrawingWandResource(Object{this_}); auto status = PushDrawingWand(wand->getWand()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to push the current ImagickDraw object"); } return true; }
req::ptr<WandResource<PixelWand>> buildOpacityWand(const Variant& opacity) { if (!opacity.isInteger() && !opacity.isDouble()) { return getPixelWand(opacity); } auto ret = newPixelWand(); PixelSetOpacity(ret->getWand(), opacity.toDouble()); return ret; }
static Array HHVM_METHOD(ImagickPixel, getHSL) { auto wand = getPixelWandResource(this_); double hue, saturation, luminosity; PixelGetHSL(wand->getWand(), &hue, &saturation, &luminosity); return make_map_array( s_hue, hue, s_saturation, saturation, s_luminosity, luminosity); }
static bool HHVM_METHOD(ImagickDraw, setFillPatternURL, const String& fill_url) { auto wand = getDrawingWandResource(this_); auto status = DrawSetFillPatternURL(wand->getWand(), fill_url.c_str()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to set fill pattern URL"); } return true; }
static void HHVM_METHOD(ImagickDraw, __clone) { auto wand = getDrawingWandResource(Object{this_}); auto newWand = CloneDrawingWand(wand->getWand()); if (newWand == nullptr) { IMAGICKDRAW_THROW("Failed to allocate DrawingWand structure"); } else { setWandResource(s_ImagickDraw, Object{this_}, newWand); } }
static bool HHVM_METHOD(ImagickDraw, setStrokePatternURL, const String& stroke_url) { auto wand = getDrawingWandResource(Object{this_}); auto status = DrawSetStrokePatternURL(wand->getWand(), stroke_url.c_str()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to set stroke pattern URL"); } return true; }
static bool HHVM_METHOD(ImagickDraw, pathEllipticArcRelative, double rx, double ry, double x_axis_rotation, bool large_arc_flag, bool sweep_flag, double x, double y) { auto wand = getDrawingWandResource(Object{this_}); DrawPathEllipticArcRelative(wand->getWand(), rx, ry, x_axis_rotation, toMagickBool(large_arc_flag), toMagickBool(sweep_flag), x, y); return true; }
static bool HHVM_METHOD(ImagickDraw, setClipPath, const String& clip_mask) { auto wand = getDrawingWandResource(Object{this_}); auto status = DrawSetClipPath(wand->getWand(), clip_mask.c_str()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to set clipping path"); } return true; }
static bool HHVM_METHOD(ImagickDraw, setVectorGraphics, const String& xml) { auto wand = getDrawingWandResource(Object{this_}); auto status = DrawSetVectorGraphics(wand->getWand(), xml.c_str()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to set the vector graphics"); } return true; }
static bool HHVM_METHOD(ImagickDraw, bezier, const Array& coordinates) { auto wand = getDrawingWandResource(Object{this_}); auto points = toPointInfoArray(coordinates); if (points.empty()) { IMAGICKDRAW_THROW("Unable to read coordinate array"); } DrawBezier(wand->getWand(), points.size(), points.data()); return true; }
static bool HHVM_METHOD(ImagickDraw, setStrokeDashArray, const Array& dashArray) { auto wand = getDrawingWandResource(Object{this_}); auto dashes = toDoubleArray(dashArray); if (dashes.empty()) { IMAGICKDRAW_THROW("Cannot read stroke dash array parameter"); } DrawSetStrokeDashArray(wand->getWand(), dashes.size(), dashes.data()); return true; }
static bool HHVM_METHOD(ImagickDraw, render) { auto wand = getDrawingWandResource(Object{this_}); auto status = withMagickLocaleFix([&wand]{ return DrawRender(wand->getWand()); }); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to render the drawing commands"); } return true; }
static bool HHVM_METHOD(ImagickDraw, setFontWeight, int64_t font_weight) { auto wand = getDrawingWandResource(Object{this_}); if (100 <= font_weight && font_weight <= 900) { DrawSetFontWeight(wand->getWand(), font_weight); return true; } else { IMAGICKDRAW_THROW("Font weight valid range is 100-900"); } }
req::ptr<WandResource<PixelWand>> buildColorWand(const Variant& color) { if (!color.isString()) { return getPixelWand(color); } auto ret = newPixelWand(); auto status = PixelSetColor(ret->getWand(), color.toCStrRef().c_str()); if (status == MagickFalse) { IMAGICKPIXEL_THROW("Unrecognized color string"); } return ret; }
ALWAYS_INLINE req::ptr<WandResource<PixelWand>> getPixelWand(const Variant& obj) { if (!obj.isObject()) { IMAGICKPIXEL_THROW("Invalid color parameter provided"); } else if (!obj.getObjectData()->instanceof(s_ImagickPixel)) { IMAGICKPIXEL_THROW( "The parameter must be an instance of ImagickPixel or a string"); } else { auto wand = getPixelWandResource(obj.toCObjRef()); return req::make<WandResource<PixelWand>>(wand->getWand(), false); } }
static bool HHVM_METHOD(ImagickDraw, affine, const Array& affine) { auto wand = getDrawingWandResource(Object{this_}); AffineMatrix affineMatrix; getAffineMatrixElement(affine, s_sx, affineMatrix.sx); getAffineMatrixElement(affine, s_rx, affineMatrix.rx); getAffineMatrixElement(affine, s_ry, affineMatrix.ry); getAffineMatrixElement(affine, s_sy, affineMatrix.sy); getAffineMatrixElement(affine, s_tx, affineMatrix.tx); getAffineMatrixElement(affine, s_ty, affineMatrix.ty); DrawAffine(wand->getWand(), &affineMatrix); return true; }
static bool HHVM_METHOD(ImagickDraw, setFontFamily, const String& font_family) { auto wand = getDrawingWandResource(Object{this_}); if (font_family.empty()) { IMAGICKDRAW_THROW("Can not set empty font family"); } auto status = DrawSetFontFamily(wand->getWand(), font_family.c_str()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to set font family"); } return true; }
static bool HHVM_METHOD(ImagickDraw, setResolution, double x, double y) { auto wand = getDrawingWandResource(Object{this_}); std::ostringstream density; density << x << "x" << y; auto drawInfo = PeekDrawingWand(wand->getWand()); drawInfo->density = AcquireString(density.str().c_str()); auto drawWand = DrawAllocateWand(drawInfo, nullptr); if (drawWand == nullptr) { IMAGICKDRAW_THROW("Failed to allocate new DrawingWand structure"); } setWandResource(s_ImagickDraw, Object{this_}, drawWand); return true; }
static bool HHVM_METHOD(ImagickDraw, setFont, const String& font_name) { auto wand = getDrawingWandResource(Object{this_}); if (font_name.empty()) { IMAGICKDRAW_THROW("Can not set empty font"); } auto font = magickResolveFont(font_name); if (font.isNull()) { IMAGICKDRAW_THROW("Unable to set font, file path expansion failed"); } auto status = DrawSetFont(wand->getWand(), font.c_str()); if (status == MagickFalse) { IMAGICKDRAW_THROW("Unable to set font"); } return true; }
static double HHVM_METHOD(ImagickPixel, getColorValue, int64_t color) { static const PixelGetFunction pixelGet[] = { PixelGetBlack, PixelGetBlue, PixelGetCyan, PixelGetGreen, PixelGetRed, PixelGetYellow, PixelGetMagenta, PixelGetOpacity, PixelGetAlpha, PixelGetFuzz }; if (0 <= color && color < sizeof(pixelGet) / sizeof(pixelGet[0])) { auto wand = getPixelWandResource(this_); return pixelGet[color](wand->getWand()); } else { IMAGICKPIXEL_THROW("Unknown color type"); } }
static Array HHVM_METHOD(ImagickPixel, getColor, bool normalized) { static const PixelGetFunction pixelGet[4] = { PixelGetRed, PixelGetGreen, PixelGetBlue, PixelGetAlpha }; static const StaticString key[4] = { s_r, s_g, s_b, s_a }; auto wand = getPixelWandResource(this_); ArrayInit ret(4, ArrayInit::Map{}); for (int i = 0; i < 4; ++i) { double color = pixelGet[i](wand->getWand()); if (i < 3 && !normalized) { color *= 255; ret.set(key[i], (int64_t)(color > 0.0 ? color + 0.5 : color - 0.5)); } else { ret.set(key[i], color); } } return ret.toArray(); }
static bool HHVM_METHOD(ImagickDraw, translate, double x, double y) { auto wand = getDrawingWandResource(Object{this_}); DrawTranslate(wand->getWand(), x, y); return true; }