From 383fef0d7dc3598cce4ffc8401161efcbfc1760e Mon Sep 17 00:00:00 2001 From: Laurent Le Goff Date: Thu, 30 Apr 2015 12:20:22 +0200 Subject: [PATCH] clean Api --- graphics.go | 74 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/graphics.go b/graphics.go index c8387e9..47117f5 100644 --- a/graphics.go +++ b/graphics.go @@ -78,26 +78,84 @@ type SolidFillStyle struct { FillRule FillRule } -type VerticalAlign int +// Vertical Alignment of the text +type Valign int -type HorizontalAlign int +const ( + ValignTop Valign = iota + ValignTopCenter + ValignTopBottom + ValignTopBaseline +) + +// Horizontal Alignment of the text +type Halign int + +const ( + HalignLeft = iota + HalignCenter + HalignRight +) + +type ScalingPolicy int + +const ( + // ScalingNone no scaling applied + ScalingNone = iota + // ScalingStretch the image is stretched so that its width and height are exactly the given width and height + ScalingStretch + // ScalingWidth the image is scaled so that its width is exactly the given width + ScalingWidth + // ScalingHeight the image is scaled so that its height is exactly the given height + ScalingHeight + // ScalingFit the image is scaled to the largest scale that allow the image to fit within a rectangle width x height + ScalingFit + // ScalingSameArea the image is scaled so that its area is exactly the area of the given rectangle width x height + ScalingSameArea + // ScalingFill the image is scaled to the smallest scale that allow the image to fully cover a rectangle width x height + ScalingFill +) // TextStyle type TextStyle struct { // Color defines the color of text Color color.Color + // Size font size + Size float64 // The font to use Font FontData // Horizontal Alignment of the text - HorizontalAlign HorizontalAlign + Halign Halign // Vertical Alignment of the text - VerticalAlign VerticalAlign + Valign Valign +} + +// ImageStyle style attributes used to display the image +type ImageStyle struct { + // Horizontal Alignment of the image + Halign Halign + // Vertical Alignment of the image + Valign Valign + // Width Height used by scaling policy + Width, Height float64 + // ScalingPolicy defines the scaling policy to applied to the image + ScalingPolicy ScalingPolicy +} + +// Style defines properties that +type Style struct { + MatrixTransform MatrixTransform + StrokeStyle StrokeStyle + FillStyle FillStyle + TextStyle TextStyle + ImageStyle TextStyle } // Drawer can fill and stroke a path type Drawer interface { - setMatrix(MatrixTransform) - Fill(FillStyle, Path) - Stroke(StrokeStyle, Path) - Text(TextStyle, text string, x, y float64) + Style() *Style + Fill(Path) + Stroke(Path) + Text(text string, x, y float64) + Image(image image.Image, x, y float64) }