diff options
| -rw-r--r-- | dmagick/DrawingContext.d | 170 | ||||
| -rw-r--r-- | dmagick/Exception.d | 32 |
2 files changed, 159 insertions, 43 deletions
diff --git a/dmagick/DrawingContext.d b/dmagick/DrawingContext.d index b703efd..d303067 100644 --- a/dmagick/DrawingContext.d +++ b/dmagick/DrawingContext.d @@ -293,10 +293,28 @@ class DrawingContext } /** + * 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 encoding(FontEncoding encoding) + { + operations ~= format(" encoding %s", encoding); + } + + unittest + { + auto dc = new DrawingContext(); + dc.encoding(FontEncoding.Latin1); + + assert(dc.operations == " encoding Latin-1"); + } + + /** * Color to use when filling drawn objects. * The default is "black". */ - void fillColor(Color fillColor) + void fill(Color fillColor) { operations ~= format(" fill %s", fillColor); } @@ -350,24 +368,6 @@ class DrawingContext } /** - * 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) @@ -388,6 +388,9 @@ class DrawingContext */ void fontStretch(StretchType type) { + if ( type == StretchType.UndefinedStretch ) + throw new DrawException("Undefined Stretch type"); + operations ~= format(" font-stretch %s", to!(string)(type)[0 .. 7]); } @@ -396,6 +399,9 @@ class DrawingContext */ void fontStyle(StyleType type) { + if ( type == StyleType.UndefinedStyle ) + throw new DrawException("Undefined Style type"); + operations ~= format(" font-style %s", to!(string)(type)[0 .. 5]); } @@ -416,16 +422,114 @@ class DrawingContext operations ~= format("font-weight %s", weight); } -//gradient-units -//gravity -//interline-spacing -//interword-spacing -//kerning -//line -//matte -//offset -//opacity -//path + /** + * Specify how the text is positioned. The default is NorthWestGravity. + */ + void gravity(GravityType type) + { + if ( type == GravityType.UndefinedGravity ) + throw new DrawException("Undefined Gravity type"); + + operations ~= format(" gravity %s", to!(string)(type)[0 .. 7]); + } + + /** + * Modify the spacing between lines when text has multiple lines. + * + * If positive, inserts additional space between lines. If negative, + * removes space between lines. The amount of space inserted + * or removed depends on the font. + */ + void interlineSpacing(double spacing) + { + operations ~= format(" interline-spacing %s", spacing); + } + + /** + * Modify the spacing between words in text. + * + * If positive, inserts additional space between words. If negative, + * removes space between words. The amount of space inserted + * or removed depends on the font. + */ + void interwordSpacing(double spacing) + { + operations ~= format(" interword-spacing %s", spacing); + } + + /** + * Modify the spacing between letters in text. + * + * If positive, inserts additional space between letters. If negative, + * removes space between letters. The amount of space inserted or + * removed depends on the font but is usually measured in pixels. That + * is, the following call adds about 5 pixels between each letter. + */ + void kerning(double kerning) + { + operations ~= format(" kerning %s", kerning); + } + + /** + * Draw a line from start to end. + */ + void line(size_t xStart, size_t yStart, size_t xEnd, size_t yEnd) + { + operations ~= format(" line %s,%s %s,%s", + xStart, yStart, xEnd, yEnd); + } + + /** + * Make the image transparent according to the specified + * PaintMethod constant. + * + * If you use the PaintMethod.FillToBorderMethod, assign the border + * color with the DrawingContext.borderColor property. + */ + void matte(size_t x, size_t y, PaintMethod method) + { + if ( method == PaintMethod.UndefinedMethod ) + throw new DrawException("Undefined Paint Method"); + + operations ~= format(" matte %s,%s %s", x, y, to!(string)(method)[0 .. $-6]); + } + + /** + * Specify the fill and stroke opacities. + * + * Params: + * opacity = A number between 0 and 1. + */ + void opacity(double opacity) + in + { + assert(opacity >= 0); + assert(opacity <= 1); + } + body + { + operations ~= format(" opacity %s", opacity); + } + + /** + * Draw using SVG-compatible path drawing commands. + * + * See_Also: "$(LINK2 http://www.w3.org/TR/SVG/paths.html, + * Paths)" in the Scalable Vector Graphics (SVG) 1.1 Specification. + */ + void path(string svgPath) + { + operations ~= " path "~svgPath; + } + + /** + * Set the pixel at x,y to the fill color. + */ + void point(size_t x, size_t y) + { + operations ~= format(" point %s,%s", x,y); + } + //point //polyline //polygon @@ -437,7 +541,6 @@ class DrawingContext //scale //skewX //skewY -//stop-color for gradients. //stroke //stroke-antialias //stroke-dasharray @@ -455,6 +558,13 @@ class DrawingContext //translate //viewbox +//For gradients: +//gradient-units +//stop-color + +//Does this do anything? +//offset + private static string saveTempFile(Image image) { import std.datetime; diff --git a/dmagick/Exception.d b/dmagick/Exception.d index 17276a3..232376f 100644 --- a/dmagick/Exception.d +++ b/dmagick/Exception.d @@ -26,7 +26,7 @@ import dmagick.c.exception; */ class DMagickException : Exception { - this(string reason, string description = null) + this(string reason, string description = null, string file = __FILE__, size_t line = __LINE__) { string message = to!(string)(GetClientName()); @@ -35,7 +35,7 @@ class DMagickException : Exception if ( description.length > 0 ) message ~= " (" ~ description ~ ")"; - super(message); + super(message, file, line); } private enum string[] severities = [ "Blob", "Cache", "Coder", @@ -47,7 +47,7 @@ class DMagickException : Exception /** * Throws an Exception or error matching the ExceptionInfo. */ - static void throwException(ExceptionInfo* exception) + static void throwException(ExceptionInfo* exception, string file = __FILE__, size_t line = __LINE__) { if ( exception.severity == ExceptionType.UndefinedException ) return; @@ -67,11 +67,11 @@ class DMagickException : Exception { exceptions ~= "case ExceptionType."~ severity ~"Warning: - throw new "~ severity ~"Exception(reason, description); + throw new "~ severity ~"Exception(reason, description, file, line); break; case ExceptionType."~ severity ~"Error: case ExceptionType."~ severity ~"FatalError: - throw new "~ severity ~"Error(reason, description); + throw new "~ severity ~"Error(reason, description, file, line); break;"; } @@ -96,7 +96,7 @@ class DMagickException : Exception */ class DMagickError : Error { - this(string reason, string description = null) + this(string reason, string description = null, string file = __FILE__, size_t line = __LINE__) { string message = to!(string)(GetClientName()); @@ -105,7 +105,7 @@ class DMagickError : Error if ( description.length > 0 ) message ~= " (" ~ description ~ ")"; - super(message); + super(message, file, line); } } @@ -121,18 +121,18 @@ mixin( exceptions ~= "class " ~ severity ~ "Exception : DMagickException { - this(string reason, string description = null) + this(string reason, string description = null, string file = __FILE__, size_t line = __LINE__) { - super(reason, description); + super(reason, description, file, line); } }"; exceptions ~= "class " ~ severity ~ "Error : DMagickError { - this(string reason, string description = null) + this(string reason, string description = null, string file = __FILE__, size_t line = __LINE__) { - super(reason, description); + super(reason, description, file, line); } }"; } @@ -152,12 +152,15 @@ struct DMagickExceptionInfo { ExceptionInfo* exceptionInfo; + string file; + size_t line; + private bool isInitialized; private size_t* refcount; alias exceptionInfo this; - static DMagickExceptionInfo opCall() + static DMagickExceptionInfo opCall(string file = __FILE__, size_t line = __LINE__) { DMagickExceptionInfo info; @@ -167,6 +170,9 @@ struct DMagickExceptionInfo *(info.refcount) = 1; info.isInitialized = true; + info.file = file; + info.line = line; + return info; } @@ -185,7 +191,7 @@ struct DMagickExceptionInfo if ( *refcount == 0 ) { - DMagickException.throwException(exceptionInfo); + DMagickException.throwException(exceptionInfo, file, line); } } } |
