1package sheet23// kindLabel names a format kind in undo labels: "format B3 as date time".4func kindLabel(k FormatKind) string {5 switch k {6 case FmtAuto:7 return "automatic"8 case FmtText:9 return "plain text"10 case FmtDateTime:11 return "date time"12 case FmtCustom:13 return "custom"14 }15 return k.String()16}1718// Align is a cell's horizontal alignment.19type Align uint82021const (22 AlignAuto Align = iota // numbers right, text left, booleans and errors centered23 AlignLeft //24 AlignCenter //25 AlignRight //26 // AlignFill is only returned by Display: the text spans the cell27 // exactly and isn't padded (Accounting's $ at the left edge).28 AlignFill29)3031var alignNames = [...]string{"", "left", "center", "right"}3233// String returns the alignment's name as stored in files.34func (a Align) String() string {35 if int(a) < len(alignNames) {36 return alignNames[a]37 }38 return ""39}4041// ParseAlign is the inverse of Align.String.42func ParseAlign(s string) (Align, bool) {43 for i, n := range alignNames {44 if n == s {45 return Align(i), true46 }47 }48 return AlignAuto, false49}5051// Wrap is what a cell's text does when it is wider than its column, as52// Sheets' Format > Wrapping.53type Wrap uint85455const (56 WrapOverflow Wrap = iota // run on into blank neighbors, Sheets' default57 WrapOn // break into lines; the row grows to fit them58 WrapClip // cut at the cell's edge59)6061var wrapNames = [...]string{"", "wrap", "clip"}6263// String returns the wrapping's name as stored in files.64func (w Wrap) String() string {65 if int(w) < len(wrapNames) {66 return wrapNames[w]67 }68 return ""69}7071// ParseWrap is the inverse of Wrap.String.72func ParseWrap(s string) (Wrap, bool) {73 for i, n := range wrapNames {74 if n == s {75 return Wrap(i), true76 }77 }78 return WrapOverflow, false79}8081// VAlign is where a cell's text sits in a row taller than it, as82// Sheets' Format > Alignment's top, middle and bottom.83type VAlign uint88485const (86 VAlignAuto VAlign = iota // the bottom, as in Sheets; the middle of a merged cell87 VAlignTop //88 VAlignMiddle //89 VAlignBottom //90)9192var valignNames = [...]string{"", "top", "middle", "bottom"}9394// String returns the vertical alignment's name as stored in files.95func (v VAlign) String() string {96 if int(v) < len(valignNames) {97 return valignNames[v]98 }99 return ""100}101102// ParseVAlign is the inverse of VAlign.String.103func ParseVAlign(s string) (VAlign, bool) {104 for i, n := range valignNames {105 if n == s {106 return VAlign(i), true107 }108 }109 return VAlignAuto, false110}111112// Offset is the line, of n a row has, where the first of k lines of113// text starts: the top, the middle or the bottom, the bottom for114// VAlignAuto unless merged is set, which centers it.115func (v VAlign) Offset(k, n int, merged bool) int {116 switch {117 case v == VAlignTop:118 return 0119 case v == VAlignMiddle, v == VAlignAuto && merged:120 return max(n-k, 0) / 2121 }122 return max(n-k, 0)123}124125// Style is a cell's text style, with its wrapping, alignment and126// borders. It is a plain value so cells can be copied freely, twelve127// bytes, which the end of a Cell has room for (see Cell).128type Style struct {129 Bold, Italic, Underline, Strikethrough bool130 Align Align131 Wrap Wrap132 VAlign VAlign133134 // own marks a cell's format and style as wholly its own, not falling135 // back on its row's or column's even where they are Automatic or136 // plain; see lines.go.137 own bool138139 Borders Borders // see borders.go140}141142// IsZero reports whether s is the default style.143func (s Style) IsZero() bool { return s == Style{} }