summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Wey2011-09-04 20:36:22 +0200
committerMike Wey2011-09-04 20:36:22 +0200
commitb49bf718965a6e14a38886b8d99c9be27924acbc (patch)
tree412221e28dc239d0b93276a1987b2ad338787bfa
parenta3a2d3901217e0bfa5875e1a037ee3c13d432183 (diff)
Add decorate, ellipse, fillColor, fillOpacity, fillRule, font, fontEncodeing, fontFamily, fontSize, fontStretch, fontStyle and fontWeight.
-rw-r--r--dmagick/ColorYUV.d3
-rw-r--r--dmagick/DrawingContext.d260
-rw-r--r--dmagick/Image.d22
-rw-r--r--dmagick/Options.d33
4 files changed, 271 insertions, 47 deletions
diff --git a/dmagick/ColorYUV.d b/dmagick/ColorYUV.d
index 19feebf..a69a27b 100644
--- a/dmagick/ColorYUV.d
+++ b/dmagick/ColorYUV.d
@@ -136,7 +136,8 @@ class ColorYUV : Color
assert(u <= 1 && u >= 0);
assert(v <= 1 && v >= 0);
}
- body {
+ body
+ {
// ⌈R⌉ ⌈ 1.000 0.000 1.140⌉ ⌈Y⌉
// |G|=| 1.000 -0.395 -0.581|·|U|
// ⌊B⌋ ⌊ 1.000 2.032 0.000⌋ ⌊V⌋
diff --git a/dmagick/DrawingContext.d b/dmagick/DrawingContext.d
index 026bf74..b703efd 100644
--- a/dmagick/DrawingContext.d
+++ b/dmagick/DrawingContext.d
@@ -133,18 +133,10 @@ class DrawingContext
*/
void clipRule(FillRule rule)
{
- final switch ( rule )
- {
- case FillRule.EvenOddRule:
- operations ~= " clip-rule evenodd";
- break;
- case FillRule.NonZeroRule:
- operations ~= " clip-rule nonzero";
- break;
- case FillRule.UndefinedRule:
- throw new DrawException("Undefined Fill Rule");
- break;
- }
+ if ( rule == FillRule.UndefinedRule )
+ throw new DrawException("Undefined Fill Rule");
+
+ operations ~= format(" clip-rule %s", to!(string)(rule)[0 .. 4]);
}
/**
@@ -203,13 +195,32 @@ class DrawingContext
operations ~= format(" color %s,%s %s", x, y, to!(string)(method)[0 .. $-6]);
}
+ /**
+ * Composite filename/image with the receiver image.
+ *
+ * Params:
+ * xOffset = The x-offset of the composited image,
+ * measured from the upper-left corner
+ * of the image.
+ * yOffset = The y-offset of the composited image,
+ * measured from the upper-left corner
+ * of the image.
+ * width = Scale the composite image to this size.
+ * If value is 0, the composite image is not scaled.
+ * height = Scale the composite image to this size.
+ * If value is 0, the composite image is not scaled.
+ * filename = Filename of the mage to use in the
+ * composite operation.
+ * image = Image to use in the composite operation.
+ * compositeOp = The composite operation to use.
+ */
void composite(
ssize_t xOffset,
ssize_t yOffset,
size_t width,
size_t height,
string filename,
- CompositeOperator compositeOp)
+ CompositeOperator compositeOp = CompositeOperator.OverCompositeOp)
{
if ( compositeOp == CompositeOperator.UndefinedCompositeOp)
throw new DrawException("Undefined Composite Operator");
@@ -218,13 +229,14 @@ class DrawingContext
to!(string)(compositeOp)[0 .. 11], xOffset, yOffset, width, height, filename);
}
+ ///ditto
void composite(
ssize_t xOffset,
ssize_t yOffset,
size_t width,
size_t height,
Image image,
- CompositeOperator compositeOp)
+ CompositeOperator compositeOp = CompositeOperator.OverCompositeOp)
{
if ( image.filename !is null && image.filename.exists && !image.changed )
{
@@ -237,18 +249,173 @@ class DrawingContext
composite(xOffset, yOffset, width, height, filename, compositeOp);
}
-//decorate
-//ellipse
-//encoding
-//fill
-//fill-opacity
-//fill-rule
-//font
-//font-family
-//font-size
-//font-stretch
-//font-style
-//font-weight
+ /**
+ * Specify text decoration.
+ */
+ void decorate(DecorationType decoration)
+ {
+ //TODO: support oring decorations together.
+ operations ~= " decorate ";
+
+ final switch ( decoration )
+ {
+ case DecorationType.NoDecoration:
+ operations ~= "none"; break;
+ case DecorationType.UnderlineDecoration:
+ operations ~= "underline"; break;
+ case DecorationType.OverlineDecoration:
+ operations ~= "overline"; break;
+ case DecorationType.LineThroughDecoration:
+ operations ~= "line-through"; break;
+
+ case DecorationType.UndefinedDecoration:
+ throw new DrawException("Undefined Decoration");
+ break;
+ }
+ }
+
+ /**
+ * Draw an ellipse.
+ *
+ * Params:
+ * xOrigin = The x coordinate of the ellipse.
+ * yOrigin = The y coordinate of the ellipse.
+ * width = The horizontal radii.
+ * height = The vertical radii.
+ * startDegrees = Where to start the ellipse.
+ * 0 degrees is at 3 o'clock.
+ * endDegrees = Whare to end the ellipse.
+ */
+ void ellipse(size_t xOrigin, size_t yOrigin, size_t width, size_t height, double startDegrees, double endDegrees)
+ {
+ operations ~= format(" ellipse %s,%s %s,%s %s,%s",
+ xOrigin, yOrigin, width, height, startDegrees, endDegrees);
+ }
+
+ /**
+ * Color to use when filling drawn objects.
+ * The default is "black".
+ */
+ void fillColor(Color fillColor)
+ {
+ operations ~= format(" fill %s", fillColor);
+ }
+
+ /**
+ * Specify the fill opacity.
+ *
+ * Params:
+ * opacity = A number between 0 and 1.
+ */
+ void fillOpacity(double opacity)
+ in
+ {
+ assert(opacity >= 0);
+ assert(opacity <= 1);
+ }
+ body
+ {
+ operations ~= format(" fill-opacity %s", opacity);
+ }
+
+ /**
+ * Specify how to determine if a point on the image is inside a shape.
+ *
+ * See_Also: $(LINK2 http://www.w3.org/TR/SVG/painting.html#FillRuleProperty,
+ * the 'fill-rule' property) in the Scalable Vector Graphics (SVG)
+ * 1.1 Specification.
+ */
+ void fillRule(FillRule rule)
+ {
+ if ( rule == FillRule.UndefinedRule )
+ throw new DrawException("Undefined Fill Rule");
+
+ operations ~= format(" fill-rule %s", to!(string)(rule)[0 .. 4]);
+ }
+
+ /**
+ * The _font name or filename.
+ * You can tag a _font to specify whether it is a Postscript,
+ * Truetype, or OPTION1 _font. For example, Arial.ttf is a
+ * Truetype _font, ps:helvetica is Postscript, and x:fixed is OPTION1.
+ *
+ * The _font name can be a complete filename such as
+ * "/mnt/windows/windows/fonts/Arial.ttf". The _font name can
+ * also be a fully qualified X font name such as
+ * "-urw-times-medium-i-normal--0-0-0-0-p-0-iso8859-13".
+ */
+ void font(string font)
+ {
+ operations ~= format(" font '%s'", font);
+ }
+
+ /**
+ * Specify the font encoding.
+ * Note: This specifies the character repertory (i.e., charset),
+ * and not the text encoding method (e.g., UTF-8, UTF-16, etc.).
+ */
+ void fontEncoding(FontEncoding encoding)
+ {
+ operations ~= format(" encoding %s", encoding);
+ }
+
+ unittest
+ {
+ auto dc = new DrawingContext();
+ dc.fontEncoding(FontEncoding.Latin1);
+
+ assert(dc.operations == " encoding Latin-1");
+ }
+
+ /**
+ * Specify the font family, such as "arial" or "helvetica".
+ */
+ void fontFamily(string family)
+ {
+ operations ~= format(" font-family '%s'", family);
+ }
+
+ /**
+ * Text rendering font point size
+ */
+ void fontSize(double pointSize)
+ {
+ operations ~= format(" font-size %s", pointSize);
+ }
+
+ /**
+ * Specify the spacing between text characters.
+ */
+ void fontStretch(StretchType type)
+ {
+ operations ~= format(" font-stretch %s", to!(string)(type)[0 .. 7]);
+ }
+
+ /**
+ * Specify the font style, i.e. italic, oblique, or normal.
+ */
+ void fontStyle(StyleType type)
+ {
+ operations ~= format(" font-style %s", to!(string)(type)[0 .. 5]);
+ }
+
+ /**
+ * Specify the font weight.
+ *
+ * Eighter use the FontWeight enum or specify a number
+ * between 100 and 900.
+ */
+ void fontWeight(size_t weight)
+ {
+ operations ~= format("font-weight %s", weight);
+ }
+
+ ///ditto
+ void fontWeight(FontWeight weight)
+ {
+ operations ~= format("font-weight %s", weight);
+ }
+
//gradient-units
//gravity
//interline-spacing
@@ -304,9 +471,9 @@ class DrawingContext
if ( tempPath is null )
tempPath = getenv("TEMP");
if ( tempPath is null )
- tempPath = join(getenv("USERPROFILE"), "AppData/Local/Temp");
+ tempPath = buildPath(getenv("USERPROFILE"), "AppData/Local/Temp");
if ( tempPath is null || !tempPath.exists )
- tempPath = join(getenv("WinDir"), "Temp");
+ tempPath = buildPath(getenv("WinDir"), "Temp");
}
else
{
@@ -319,7 +486,7 @@ class DrawingContext
do
{
- filename = join(tempPath, "DMagick."~to!(string)(Clock.currTime().stdTime));
+ filename = buildPath(tempPath, "DMagick."~to!(string)(Clock.currTime().stdTime));
if ( image.magick !is null && toLower(image.magick) != "canvas" )
filename ~= "."~image.magick;
@@ -343,3 +510,38 @@ class DrawingContext
remove(filename);
}
}
+
+/**
+ * This enumeration lists specific character repertories (i.e., charsets),
+ * and not text encoding methods (e.g., UTF-8, UTF-16, etc.).
+ */
+enum FontEncoding : string
+{
+ AdobeCustom = "AdobeCustom", ///
+ AdobeExpert = "AdobeExpert", ///ditto
+ AdobeStandard = "AdobeStandard", ///ditto
+ AppleRoman = "AppleRoman", ///ditto
+ BIG5 = "BIG5", ///ditto
+ GB2312 = "GB2312", ///ditto
+ Johab = "Johab", ///ditto
+ Latin1 = "Latin-1", ///ditto
+ Latin2 = "Latin-2", ///ditto
+ None = "None", ///ditto
+ SJIScode = "SJIScode", ///ditto
+ Symbol = "Symbol", ///ditto
+ Unicode = "Unicode", ///ditto
+ Wansung = "Wansung", ///ditto
+}
+
+/**
+ * The font weight can be specified as one of 100, 200, 300, 400, 500,
+ * 600, 700, 800, or 900, or one of the following constants.
+ */
+enum FontWeight : string
+{
+ Any = "all", /// No weight specified.
+ Normal = "normal", /// Normal weight, equivalent to 400.
+ Bold = "bold", /// Bold. equivalent to 700.
+ Bolder = "bolder", /// Increases weight by 100.
+ Lighter = "lighter", /// Decreases weight by 100.
+}
diff --git a/dmagick/Image.d b/dmagick/Image.d
index ba36135..b7bf41e 100644
--- a/dmagick/Image.d
+++ b/dmagick/Image.d
@@ -771,7 +771,7 @@ class Image
* Composites dest onto this image using the specified composite operator.
*
* Params:
- * overlay = Image to use in to composite operation.
+ * overlay = Image to use in the composite operation.
* compositeOp = The composite operation to use.
* xOffset = The x-offset of the composited image,
* measured from the upper-left corner
@@ -2768,7 +2768,7 @@ class Image
//Use the D GC to accolate the blob.
GetMagickMemoryMethods(&oldMalloc, &oldRealloc, &oldFree);
- SetMagickMemoryMethods(&GC.malloc, &GC.realloc, &GC.free);
+ SetMagickMemoryMethods(&Image.malloc, &Image.realloc, &Image.free);
scope(exit) SetMagickMemoryMethods(oldMalloc, oldRealloc, oldFree);
void* blob = ImageToBlob(options.imageInfo, imageRef, &length, DMagickExceptionInfo());
@@ -2776,6 +2776,24 @@ class Image
return blob[0 .. length];
}
+ private extern(C)
+ {
+ static void* malloc(ulong sz)
+ {
+ return GC.malloc(sz, GC.BlkAttr.NO_SCAN);
+ }
+
+ static void* realloc(void* p, ulong sz)
+ {
+ return GC.realloc(p, sz, GC.BlkAttr.NO_SCAN);
+ }
+
+ static void free(void* p)
+ {
+ GC.free(p);
+ }
+ }
+
/**
* Changes the opacity value of all the pixels that match color to
* the value specified by opacity. By default the pixel must match
diff --git a/dmagick/Options.d b/dmagick/Options.d
index 85e1c13..53a4f9f 100644
--- a/dmagick/Options.d
+++ b/dmagick/Options.d
@@ -343,6 +343,20 @@ class Options
}
/**
+ * Text rendering font point size
+ */
+ void fontSize(double size)
+ {
+ imageInfo.pointsize = size;
+ drawInfo.pointsize = size;
+ }
+ ///ditto
+ double fontSize() const
+ {
+ return drawInfo.pointsize;
+ }
+
+ /**
* Colors within this distance are considered equal.
* A number of algorithms search for a target color.
* By default the color must be exact. Use this option to match
@@ -448,20 +462,6 @@ class Options
}
/**
- * Text rendering font point size
- */
- void pointSize(double size)
- {
- imageInfo.pointsize = size;
- drawInfo.pointsize = size;
- }
- ///ditto
- double pointSize() const
- {
- return drawInfo.pointsize;
- }
-
- /**
* The compression level for JPEG, MPEG, JPEG-2000,
* MIFF, MNG, and PNG image format.
* The default is 75
@@ -872,6 +872,9 @@ class Options
return to!(string)(drawInfo.family);
}
+ /**
+ * Specify the spacing between text characters.
+ */
void fontStretch(StretchType type)
{
drawInfo.stretch = type;
@@ -896,7 +899,7 @@ class Options
}
/**
- * Specify the font style, i.e. italic, oblique, or normal.
+ * Specify the font weight.
*/
void fontWeight(size_t weight)
{