graphic-context.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package mvg
  2. import "image/color"
  3. import "github.com/hajimehoshi/ebiten/v2"
  4. type Color color.RGBA
  5. func (c Color) Eval(gc *GraphicContext) Value {
  6. return c
  7. }
  8. type Compliance int
  9. const ComplianceSVG = Compliance(1)
  10. const ComplianceMVG = Compliance(2)
  11. type Stroke int
  12. const StrokeNone = 0
  13. const StrokeSolid = 1
  14. type FillRule = ebiten.FillRule
  15. const FillRuleAll = FillRule(0)
  16. const FillRuleEvenOdd = FillRule(1)
  17. type GradientUnits int
  18. const (
  19. GradientUnitUserSpace = GradientUnits(iota)
  20. GradientUnitUserSpaceOnUse = GradientUnits(iota)
  21. GradientUnitObjectBoundingBox = GradientUnits(iota)
  22. )
  23. func (LinearGradient) IsDef() {
  24. }
  25. type Encoding int
  26. // only utf-8 is supported for now.
  27. const EncodingUtf8 = Encoding(0)
  28. type Box struct {
  29. X, Y, W, H float32
  30. }
  31. type Coord struct {
  32. X, Y float32
  33. }
  34. type GraphicContext struct {
  35. Parent *GraphicContext
  36. Children []*GraphicContext
  37. Variables map[string]Value
  38. Name string
  39. Compliance
  40. Fill Color
  41. FillOpacity float32
  42. Stroke
  43. StrokeWidth float32
  44. FillRule
  45. Encoding
  46. ViewBox Box
  47. Affine ebiten.GeoM
  48. Defs map[string]DefValue
  49. FontSize float32
  50. FontStyle string
  51. FontWeight string
  52. FontFamily string
  53. }
  54. type Def interface {
  55. IsDef()
  56. }
  57. type DefValue struct {
  58. Def
  59. }
  60. func (d DefValue) Eval(gc *GraphicContext) Value {
  61. return d
  62. }
  63. type Stop []struct {
  64. Name string
  65. Index int
  66. Color Color
  67. }
  68. type CommonGradient struct {
  69. Name string
  70. Stops []Stop
  71. GradientUnits
  72. Affine ebiten.GeoM
  73. }
  74. func (CommonGradient) IsDef() {
  75. }
  76. type LinearGradient struct {
  77. From Coord
  78. To Coord
  79. CommonGradient
  80. }
  81. type RadialGradient struct {
  82. CommonGradient
  83. Center Coord
  84. Focus Coord
  85. Radius float32
  86. }
  87. /*
  88. push graphic-context "svg5"
  89. compliance "SVG"
  90. fill "black"
  91. fill-opacity 1
  92. stroke "none"
  93. stroke-width 1
  94. stroke-opacity 1
  95. fill-rule nonzero
  96. encoding "UTF-8"
  97. viewbox 0 0 794 1123
  98. affine 3.78095 0 0 3.78114 0 0
  99. push defs
  100. push gradient "linearGradient5432" linear 0,0 0,0
  101. stop-color "#ffff00" 0
  102. stop-color "#ffff00" 1
  103. pop gradient
  104. push gradient "linearGradient5344" linear 0,0 0,0
  105. stop-color "#0000ff" 0
  106. stop-color "#0000ff" 1
  107. pop gradient
  108. push gradient "linearGradient5346" linear 89.1931,92.1651 177.979,92.1651
  109. gradient-units "userSpaceOnUse"
  110. pop gradient
  111. push gradient "radialGradient5434" radial 70.2149,52.3642 70.2149,52.3642 39.4705
  112. affine 1 0 0 0.954439 0 2.38575
  113. gradient-units "userSpaceOnUse"
  114. pop gradient
  115. pop defs
  116. push graphic-context "layer1"
  117. push graphic-context "path49"
  118. fill "url(#radialGradient5434)"
  119. stroke-width 0.264583
  120. fill-opacity "1"
  121. class "ellipse"
  122. ellipse 70.2149,52.3642 39.4705,37.6722 0,360
  123. pop graphic-context
  124. push graphic-context "text1574"
  125. class "text"
  126. translate 59.1728,104.719
  127. font-size 10.5833
  128. font-style "normal"
  129. font-weight "normal"
  130. font-size 10.5833
  131. font-family "sans-serif"
  132. fill "#000000"
  133. fill-opacity "1"
  134. stroke "none"
  135. stroke-width 0.264583
  136. text 0,0 " "
  137. push graphic-context "tspan1576"
  138. stroke-width 0.264583
  139. class "tspan"
  140. text 0,0 "hello"
  141. pop graphic-context
  142. pop graphic-context
  143. push graphic-context "rect4440"
  144. fill "url(#linearGradient5346)"
  145. stroke-width 0.264583
  146. fill-opacity "1"
  147. class "rect"
  148. rectangle 89.1931,51.9326 177.979,132.398
  149. pop graphic-context
  150. push graphic-context "rect5458"
  151. fill "#0000ff"
  152. stroke-width 0.264583
  153. class "rect"
  154. rectangle 31.8962,133.123 68.7693,155.595
  155. pop graphic-context
  156. pop graphic-context
  157. pop graphic-context
  158. */