summaryrefslogtreecommitdiff
path: root/dmagick/Geometry.d
diff options
context:
space:
mode:
authorMike Wey2011-02-24 23:46:03 +0100
committerMike Wey2011-02-24 23:46:03 +0100
commit846bd1de37e9dfbbcf33f21d86e755ac833c4e5d (patch)
tree5e6a26d97e0f1e9db0cd23f2d01dab98c9cd8e52 /dmagick/Geometry.d
parente8b49e7144796ae7a6c763f1a2836073a77bc661 (diff)
Add geometry argumants to Options.d, and add some documentation.
Diffstat (limited to 'dmagick/Geometry.d')
-rw-r--r--dmagick/Geometry.d47
1 files changed, 29 insertions, 18 deletions
diff --git a/dmagick/Geometry.d b/dmagick/Geometry.d
index 0547f49..afda819 100644
--- a/dmagick/Geometry.d
+++ b/dmagick/Geometry.d
@@ -1,6 +1,4 @@
/**
- * A class to specify a geometry argument.
- *
* Copyright: Mike Wey 2011
* License: To be determined
* Authors: Mike Wey
@@ -17,18 +15,25 @@ import dmagick.c.geometry;
import dmagick.c.magickString;
import dmagick.c.magickType;
+/**
+ * Geometry provides a convenient means to specify a geometry argument.
+ */
struct Geometry
{
- size_t width;
- size_t height;
- ssize_t xOffset;
- ssize_t yOffset;
- bool percent;
- bool minimum;
- bool keepAspect = true;
- bool greater;
- bool less;
-
+ size_t width; ///
+ size_t height; ///
+ ssize_t xOffset; ///
+ ssize_t yOffset; ///
+ bool percent; /// The width and/or height are percentages of the original.
+ bool minimum; /// The specified width and/or height is the minimum value.
+ bool keepAspect = true; ///Retain the aspect ratio.
+ bool greater; /// Resize only if the image is greater than the width and/or height.
+ bool less; /// Resize only if the image is smaller than the width and/or height.
+
+ /**
+ * Create a Geometry form a Imagemagick / X11 geometry string.
+ */
+ //TODO: expand the documentation for this constructor.
this(string geometry)
{
MagickStatusType flags;
@@ -64,7 +69,10 @@ struct Geometry
assert( geo.width == 595 && geo.height == 842);
}
- this(size_t width, size_t height, ssize_t xOffset, ssize_t yOffset)
+ /**
+ * Initialize with width heigt and offsets.
+ */
+ this(size_t width, size_t height, ssize_t xOffset = 0, ssize_t yOffset = 0)
{
this.width = width;
this.height = height;
@@ -72,6 +80,9 @@ struct Geometry
this.yOffset = yOffset;
}
+ /**
+ * Convert Geometry into a Imagemagick geometry string.
+ */
string toString()
{
string geometry;
@@ -82,9 +93,6 @@ struct Geometry
if ( height > 0 )
geometry ~= "x" ~ to!(string)(height);
- if ( xOffset != 0 && yOffset != 0 )
- geometry ~= format("%+s%+s", xOffset, yOffset);
-
geometry ~= format("%s%s%s%s%s",
percent ? "%" : "",
minimum ? "^" : "",
@@ -92,13 +100,16 @@ struct Geometry
less ? "<" : "",
greater ? ">" : "");
+ if ( xOffset != 0 && yOffset != 0 )
+ geometry ~= format("%+s%+s", xOffset, yOffset);
+
return geometry;
}
unittest
{
- Geometry geo = Geometry("200x150-50+25!");
- assert( geo.toString == "200x150-50+25!");
+ Geometry geo = Geometry("200x150!-50+25");
+ assert( geo.toString == "200x150!-50+25");
}
int opCmp(ref const Geometry geometry)