From 8f8144c50993c4043d5b08ab9881e017e392d064 Mon Sep 17 00:00:00 2001 From: Mike Wey Date: Sun, 30 Jan 2011 20:47:20 +0100 Subject: Add the pattern porperties to Options and a few bug fixes --- dmagick/Image.d | 7 +++- dmagick/Options.d | 95 ++++++++++++++++++++++++------------------------------- dmagick/Utils.d | 7 ++-- 3 files changed, 53 insertions(+), 56 deletions(-) (limited to 'dmagick') diff --git a/dmagick/Image.d b/dmagick/Image.d index 3df6e00..e946433 100644 --- a/dmagick/Image.d +++ b/dmagick/Image.d @@ -30,10 +30,15 @@ class Image imageRef = ImageRef(AcquireImage(options.imageInfo)); } - this(string filename) + this(MagickCoreImage* image) { options = new Options(); + imageRef = ImageRef(image); + } + this(string filename) + { + options = new Options(); read(filename); } diff --git a/dmagick/Options.d b/dmagick/Options.d index a9e47ec..312e912 100644 --- a/dmagick/Options.d +++ b/dmagick/Options.d @@ -10,9 +10,11 @@ module dmagick.Options; import std.conv; +import std.math; import core.stdc.stdio; import core.stdc.string; +import dmagick.Image; import dmagick.Utils; import dmagick.c.cacheView; @@ -21,6 +23,7 @@ import dmagick.c.compress; import dmagick.c.draw; import dmagick.c.geometry; import dmagick.c.image; +import dmagick.c.list; import dmagick.c.magickType; import dmagick.c.memory; import dmagick.c.quantize; @@ -259,10 +262,15 @@ class Options } /** - * Text rendering _font. If the _font is a fully qualified - * X server _font name, the _font is obtained from an X server. - * To use a TrueType _font, precede the TrueType filename with an @. - * Otherwise, specify a Postscript _font name (e.g. "helvetica") + * 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 str) { @@ -734,54 +742,34 @@ class Options // //} - //** - // * Pattern image to use when filling drawn objects. - // */ - //void fillPattern(Image pattern) - //{ - // if (drawInfo.fill_pattern) - // destroy - // - // clone - //} - //ditto - //Image fillPattern() - //{ - // - //} - /** - * Rule to use when filling drawn objects. + * Pattern image to use when filling drawn objects. */ - void fillRule(FillRule rule) + //TODO: investigate if we need to clone the image. + void fillPattern(dmagick.Image.Image pattern) { - drawInfo.fill_rule = rule; + if (drawInfo.fill_pattern) + drawInfo.fill_pattern = DestroyImageList(drawInfo.fill_pattern); + + drawInfo.fill_pattern = ReferenceImage(pattern.imageRef); } ///ditto - FillRule fillRule() + dmagick.Image.Image fillPattern() { - return drawInfo.fill_rule; + return new dmagick.Image.Image(ReferenceImage(drawInfo.fill_pattern)); } /** - * 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". + * Rule to use when filling drawn objects. */ - void font(string str) + void fillRule(FillRule rule) { - copyString(imageInfo.font, str); + drawInfo.fill_rule = rule; } ///ditto - string font() + FillRule fillRule() { - return to!(string)(imageInfo.font); + return drawInfo.fill_rule; } /** @@ -897,21 +885,22 @@ class Options return drawInfo.miterlimit; } - //** - // * Pattern image to use while drawing object stroke - // */ - //void strokePattern(Image pattern) - //{ - // if (drawInfo.stroke_pattern) - // destroy - // - // clone - //} - //ditto - //Image fillPattern() - //{ - // - //} + /** + * Pattern image to use while drawing object stroke + */ + //TODO: investigate if we need to clone the image. + void strokePattern(dmagick.Image.Image pattern) + { + if (drawInfo.stroke_pattern) + drawInfo.stroke_pattern = DestroyImageList(drawInfo.stroke_pattern); + + drawInfo.stroke_pattern = ReferenceImage(pattern.imageRef); + } + ///ditto + dmagick.Image.Image fillPattern() + { + return new dmagick.Image.Image(ReferenceImage(drawInfo.stroke_pattern)); + } /** * Stroke _width for use when drawing vector objects diff --git a/dmagick/Utils.d b/dmagick/Utils.d index e8cef21..1396ddf 100644 --- a/dmagick/Utils.d +++ b/dmagick/Utils.d @@ -18,7 +18,7 @@ import dmagick.c.magickType; * Copy a string into a static array used * by ImageMagick for some atributes. */ -private void copyString(ref char[MaxTextExtent] dest, string source) +void copyString(ref char[MaxTextExtent] dest, string source) { if ( source.length < MaxTextExtent ) throw new Exception("text is to long"); //TODO: a proper exception. @@ -34,7 +34,7 @@ private void copyString(ref char[MaxTextExtent] dest, string source) * append a \0 to the end of the string, and the realocation * whould be wastefull if we are just going to copy it */ -private void copyString(ref char* dest, string source) +void copyString(ref char* dest, string source) { if ( source is null ) { @@ -93,6 +93,9 @@ struct RefCounted(alias pred, T) ~this() { + if ( !isInitialized ) + return; + (*refcount)--; if ( *refcount == 0 ) -- cgit v1.2.3