Rectangle aligns the area within the rectangle returning the aligned area. The area must fall within the rectangle.
(rect image.Rectangle, ar image.Rectangle, h align.Horizontal, v align.Vertical)
| 72 | // Rectangle aligns the area within the rectangle returning the |
| 73 | // aligned area. The area must fall within the rectangle. |
| 74 | func Rectangle(rect image.Rectangle, ar image.Rectangle, h align.Horizontal, v align.Vertical) (image.Rectangle, error) { |
| 75 | if !ar.In(rect) { |
| 76 | return image.ZR, fmt.Errorf("cannot align area %v inside rectangle %v, the area falls outside of the rectangle", ar, rect) |
| 77 | } |
| 78 | |
| 79 | aligned, err := hAlign(rect, ar, h) |
| 80 | if err != nil { |
| 81 | return image.ZR, err |
| 82 | } |
| 83 | aligned, err = vAlign(rect, aligned, v) |
| 84 | if err != nil { |
| 85 | return image.ZR, err |
| 86 | } |
| 87 | return aligned, nil |
| 88 | } |
| 89 | |
| 90 | // Text aligns the text within the given rectangle, returns the start point for the text. |
| 91 | // For the purposes of the alignment this assumes that text will be trimmed if |