| 1 | package drawing |
| 2 | |
| 3 | import ( |
| 4 | "image/color" |
| 5 | |
| 6 | "github.com/golang/freetype/truetype" |
| 7 | ) |
| 8 | |
| 9 | // FillRule defines the type for fill rules |
| 10 | type FillRule int |
| 11 | |
| 12 | const ( |
| 13 | // FillRuleEvenOdd determines the "insideness" of a point in the shape |
| 14 | // by drawing a ray from that point to infinity in any direction |
| 15 | // and counting the number of path segments from the given shape that the ray crosses. |
| 16 | // If this number is odd, the point is inside; if even, the point is outside. |
| 17 | FillRuleEvenOdd FillRule = iota |
| 18 | // FillRuleWinding determines the "insideness" of a point in the shape |
| 19 | // by drawing a ray from that point to infinity in any direction |
| 20 | // and then examining the places where a segment of the shape crosses the ray. |
| 21 | // Starting with a count of zero, add one each time a path segment crosses |
| 22 | // the ray from left to right and subtract one each time |
| 23 | // a path segment crosses the ray from right to left. After counting the crossings, |
| 24 | // if the result is zero then the point is outside the path. Otherwise, it is inside. |
| 25 | FillRuleWinding |
| 26 | ) |
| 27 | |
| 28 | // LineCap is the style of line extremities |
| 29 | type LineCap int |
| 30 | |
| 31 | const ( |
| 32 | // RoundCap defines a rounded shape at the end of the line |
| 33 | RoundCap LineCap = iota |
| 34 | // ButtCap defines a squared shape exactly at the end of the line |
| 35 | ButtCap |
| 36 | // SquareCap defines a squared shape at the end of the line |
| 37 | SquareCap |
| 38 | ) |
| 39 | |
| 40 | // LineJoin is the style of segments joint |
| 41 | type LineJoin int |
| 42 | |
| 43 | const ( |
| 44 | // BevelJoin represents cut segments joint |
| 45 | BevelJoin LineJoin = iota |
| 46 | // RoundJoin represents rounded segments joint |
| 47 | RoundJoin |
| 48 | // MiterJoin represents peaker segments joint |
| 49 | MiterJoin |
| 50 | ) |
| 51 | |
| 52 | // StrokeStyle keeps stroke style attributes |
| 53 | // that is used by the Stroke method of a Drawer |
| 54 | type StrokeStyle struct { |
| 55 | // Color defines the color of stroke |
| 56 | Color color.Color |
| 57 | // Line width |
| 58 | Width float64 |
| 59 | // Line cap style rounded, butt or square |
| 60 | LineCap LineCap |
| 61 | // Line join style bevel, round or miter |
| 62 | LineJoin LineJoin |
| 63 | // offset of the first dash |
| 64 | DashOffset float64 |
| 65 | // array represented dash length pair values are plain dash and impair are space between dash |
| 66 | // if empty display plain line |
| 67 | Dash []float64 |
| 68 | } |
| 69 | |
| 70 | // SolidFillStyle define style attributes for a solid fill style |
| 71 | type SolidFillStyle struct { |
| 72 | // Color defines the line color |
| 73 | Color color.Color |
| 74 | // FillRule defines the file rule to used |
| 75 | FillRule FillRule |
| 76 | } |
| 77 | |
| 78 | // Valign Vertical Alignment of the text |
| 79 | type Valign int |
| 80 | |
| 81 | const ( |
| 82 | // ValignTop top align text |
| 83 | ValignTop Valign = iota |
| 84 | // ValignCenter centered text |
| 85 | ValignCenter |
| 86 | // ValignBottom bottom aligned text |
| 87 | ValignBottom |
| 88 | // ValignBaseline align text with the baseline of the font |
| 89 | ValignBaseline |
| 90 | ) |
| 91 | |
| 92 | // Halign Horizontal Alignment of the text |
| 93 | type Halign int |
| 94 | |
| 95 | const ( |
| 96 | // HalignLeft Horizontally align to left |
| 97 | HalignLeft = iota |
| 98 | // HalignCenter Horizontally align to center |
| 99 | HalignCenter |
| 100 | // HalignRight Horizontally align to right |
| 101 | HalignRight |
| 102 | ) |
| 103 | |
| 104 | // TextStyle describe text property |
| 105 | type TextStyle struct { |
| 106 | // Color defines the color of text |
| 107 | Color color.Color |
| 108 | // Size font size |
| 109 | Size float64 |
| 110 | // The font to use |
| 111 | Font *truetype.Font |
| 112 | // Horizontal Alignment of the text |
| 113 | Halign Halign |
| 114 | // Vertical Alignment of the text |
| 115 | Valign Valign |
| 116 | } |
| 117 | |
| 118 | // ScalingPolicy is a constant to define how to scale an image |
| 119 | type ScalingPolicy int |
| 120 | |
| 121 | const ( |
| 122 | // ScalingNone no scaling applied |
| 123 | ScalingNone ScalingPolicy = iota |
| 124 | // ScalingStretch the image is stretched so that its width and height are exactly the given width and height |
| 125 | ScalingStretch |
| 126 | // ScalingWidth the image is scaled so that its width is exactly the given width |
| 127 | ScalingWidth |
| 128 | // ScalingHeight the image is scaled so that its height is exactly the given height |
| 129 | ScalingHeight |
| 130 | // ScalingFit the image is scaled to the largest scale that allow the image to fit within a rectangle width x height |
| 131 | ScalingFit |
| 132 | // ScalingSameArea the image is scaled so that its area is exactly the area of the given rectangle width x height |
| 133 | ScalingSameArea |
| 134 | // ScalingFill the image is scaled to the smallest scale that allow the image to fully cover a rectangle width x height |
| 135 | ScalingFill |
| 136 | ) |
| 137 | |
| 138 | // ImageScaling style attributes used to display the image |
| 139 | type ImageScaling struct { |
| 140 | // Horizontal Alignment of the image |
| 141 | Halign Halign |
| 142 | // Vertical Alignment of the image |
| 143 | Valign Valign |
| 144 | // Width Height used by scaling policy |
| 145 | Width, Height float64 |
| 146 | // ScalingPolicy defines the scaling policy to applied to the image |
| 147 | ScalingPolicy ScalingPolicy |
| 148 | } |