This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package svg
|
||||
|
||||
import "fmt"
|
||||
|
||||
// TODO: consider reworking this WHOLE API/PACKAGE to make it more of a chaining API.
|
||||
|
||||
type (
|
||||
PreserveAspectRatio struct {
|
||||
Align *AlignValue
|
||||
MeetOrSlice MeetOrSliceValue
|
||||
}
|
||||
|
||||
AlignValue struct {
|
||||
X AlignValueComponent
|
||||
Y AlignValueComponent
|
||||
}
|
||||
AlignValueComponent int
|
||||
MeetOrSliceValue int
|
||||
)
|
||||
|
||||
const (
|
||||
AlignMid AlignValueComponent = iota
|
||||
AlignMin
|
||||
AlignMax
|
||||
|
||||
_ MeetOrSliceValue = iota
|
||||
Meet
|
||||
Slice
|
||||
)
|
||||
|
||||
func (r PreserveAspectRatio) PrintKey() string {
|
||||
return "preserveAspectRatio"
|
||||
}
|
||||
|
||||
func (r PreserveAspectRatio) PrintValue() (string, bool) {
|
||||
if mos := r.MeetOrSlice.String(); mos != "" {
|
||||
return fmt.Sprintf(`"%s %s"`, r.Align, mos), true
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%q", r.Align), true
|
||||
}
|
||||
|
||||
func (v *AlignValue) String() string {
|
||||
if v == nil {
|
||||
return "none"
|
||||
}
|
||||
return fmt.Sprintf("x%sY%s", v.X, v.Y)
|
||||
}
|
||||
|
||||
func (v AlignValueComponent) String() string {
|
||||
switch v {
|
||||
case AlignMin:
|
||||
return "Min"
|
||||
case AlignMax:
|
||||
return "Max"
|
||||
default:
|
||||
return "Mid"
|
||||
}
|
||||
}
|
||||
|
||||
func (v MeetOrSliceValue) String() string {
|
||||
switch v {
|
||||
case Meet:
|
||||
return "meet"
|
||||
case Slice:
|
||||
return "slice"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user