/
font.go
43 lines (40 loc) · 1.38 KB
/
font.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pnml
import (
"encoding/xml"
"errors"
"fmt"
)
type Font struct {
XMLName xml.Name `xml:"font"`
Family *string `xml:"family,attr"` // optional
Style *string `xml:"style,attr"` // optional
Weight *string `xml:"weight,attr"` // optional
Size *string `xml:"size,attr"` // optional
Decoration *string `xml:"decoration,attr"` // optional (must be underline, overline, or line-through)
Align *string `xml:"align,attr"` // optional (must be left, center, or right)
Rotation *float32 `xml:"rotation,attr"` // optional
}
func (f *Font) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type font Font
var ff font
if err := d.DecodeElement(&ff, &start); err != nil {
return err
}
line, col := d.InputPos()
if ff.Decoration != nil &&
*ff.Decoration != "underline" &&
*ff.Decoration != "overline" &&
*ff.Decoration != "line-through" {
msg := fmt.Sprint(modelPath, " at line ", line, ", col ", col, ", font must have a decoration attribute which value is underline, overline, or line-through")
return errors.New(msg)
}
if ff.Align != nil &&
*ff.Align != "left" &&
*ff.Align != "center" &&
*ff.Align != "right" {
msg := fmt.Sprint(modelPath, " at line ", line, ", col ", col, ", font must have an align attribute which value is left, center, or right")
return errors.New(msg)
}
*f = Font(ff)
return nil
}