text.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package attr
  2. import (
  3. "image/color"
  4. "odf/model"
  5. "odf/xmlns/fo"
  6. "odf/xmlns/style"
  7. "odf/xmlns/text"
  8. )
  9. //TextAttributes is a Text Family fluent style builder
  10. type TextAttributes struct {
  11. fontFace string
  12. size int
  13. col color.Color
  14. bold bool
  15. italic bool
  16. named
  17. }
  18. func (t *TextAttributes) Equal(_a Attributes) (ok bool) {
  19. a, ok := _a.(*TextAttributes)
  20. if ok {
  21. ok = t.size == a.size && t.fontFace == a.fontFace && t.col == a.col && t.italic == a.italic && t.bold == a.bold
  22. }
  23. return
  24. }
  25. func (t *TextAttributes) Fit() model.LeafName { return text.Span }
  26. func (t *TextAttributes) Write(wr model.Writer) {
  27. wr.Attr(style.Family, style.FamilyText)
  28. wr.WritePos(New(style.TextProperties))
  29. if t.fontFace != "" {
  30. wr.Attr(style.FontName, t.fontFace)
  31. }
  32. if t.size != 0 {
  33. wr.Attr(fo.FontSize, t.size)
  34. }
  35. wr.Attr(fo.Color, t.col)
  36. if t.bold {
  37. wr.Attr(fo.FontWeight, fo.Bold)
  38. }
  39. if t.italic {
  40. wr.Attr(fo.FontStyle, fo.Italic)
  41. }
  42. }
  43. //Size of text in points
  44. func (t *TextAttributes) Size(s int) *TextAttributes {
  45. t.size = s
  46. return t
  47. }
  48. //FontFace of text (font-faces are registered in mappers.Formatter
  49. func (t *TextAttributes) FontFace(name string) *TextAttributes {
  50. t.fontFace = name
  51. return t
  52. }
  53. //Color of text
  54. func (t *TextAttributes) Color(col color.Color) *TextAttributes {
  55. t.col = col
  56. return t
  57. }
  58. //Bold style of text
  59. func (t *TextAttributes) Bold() *TextAttributes {
  60. t.bold = true
  61. return t
  62. }
  63. //Italic style of text
  64. func (t *TextAttributes) Italic() *TextAttributes {
  65. t.italic = true
  66. return t
  67. }