Diff
diff --git a/cstyle/main.go b/cstyle/main.go
index 93c6d5d..3dd363a 100644
--- a/cstyle/main.go
+++ b/cstyle/main.go
@@ -63,0 +64 @@ func (c *CSS) CreateDocument(doc *html.Node) {
+ Node: n,
@@ -65,18 +66 @@ func (c *CSS) CreateDocument(doc *html.Node) {
- Properties: element.Properties{
- Id: "ROOT",
- X: 0,
- Y: 0,
- Width: c.Width,
- Height: c.Height,
- EM: 16,
- Type: 3,
- },
-
- Style: map[string]string{
- "width": strconv.FormatFloat(float64(c.Width), 'f', -1, 32) + "px",
- "height": strconv.FormatFloat(float64(c.Height), 'f', -1, 32) + "px",
- },
- },
- Properties: element.Properties{
- Node: n,
- Id: id,
+ Id: "ROOT",
@@ -85 +68,0 @@ func (c *CSS) CreateDocument(doc *html.Node) {
- Type: 3,
@@ -87,0 +71,6 @@ func (c *CSS) CreateDocument(doc *html.Node) {
+ EM: 16,
+ Type: 3,
+ Style: map[string]string{
+ "width": strconv.FormatFloat(float64(c.Width), 'f', -1, 32) + "px",
+ "height": strconv.FormatFloat(float64(c.Height), 'f', -1, 32) + "px",
+ },
@@ -88,0 +78,6 @@ func (c *CSS) CreateDocument(doc *html.Node) {
+ Id: id,
+ X: 0,
+ Y: 0,
+ Type: 3,
+ Width: c.Width,
+ Height: c.Height,
@@ -102,0 +98 @@ func CreateNode(parent element.Node, n *html.Node, slug string) element.Node {
+ Node: n,
@@ -103,0 +100 @@ func CreateNode(parent element.Node, n *html.Node, slug string) element.Node {
+ Type: n.Type,
@@ -105,5 +102 @@ func CreateNode(parent element.Node, n *html.Node, slug string) element.Node {
- Properties: element.Properties{
- Id: id,
- Type: n.Type,
- Node: n,
- },
+ Id: id,
@@ -129,3 +122,3 @@ func (c *CSS) Map() Mapped {
- if v.Properties.Type == html.ElementNode {
- if styleMap[v.Properties.Id] == nil {
- styleMap[v.Properties.Id] = styles
+ if v.Type == html.ElementNode {
+ if styleMap[v.Id] == nil {
+ styleMap[v.Id] = styles
@@ -133 +126 @@ func (c *CSS) Map() Mapped {
- styleMap[v.Properties.Id] = utils.Merge(styleMap[v.Properties.Id], styles)
+ styleMap[v.Id] = utils.Merge(styleMap[v.Id], styles)
@@ -170,4 +163,4 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- n.Properties.X = 0
- n.Properties.Y = 0
- n.Properties.Width = 0
- n.Properties.Height = 0
+ n.X = 0
+ n.Y = 0
+ n.Width = 0
+ n.Height = 0
@@ -177,2 +170,2 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- width, height := n.Properties.Width, n.Properties.Height
- x, y := n.Parent.Properties.X, n.Parent.Properties.Y
+ width, height := n.Width, n.Height
+ x, y := n.Parent.X, n.Parent.Y
@@ -185,2 +178,2 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- v, _ := utils.ConvertToPixels(styleMap["top"], float32(n.Properties.EM), n.Parent.Properties.Width)
- y = v + base.Properties.Y
+ v, _ := utils.ConvertToPixels(styleMap["top"], float32(n.EM), n.Parent.Width)
+ y = v + base.Y
@@ -190,2 +183,2 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- v, _ := utils.ConvertToPixels(styleMap["left"], float32(n.Properties.EM), n.Parent.Properties.Width)
- x = v + base.Properties.X
+ v, _ := utils.ConvertToPixels(styleMap["left"], float32(n.EM), n.Parent.Width)
+ x = v + base.X
@@ -195,2 +188,2 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- v, _ := utils.ConvertToPixels(styleMap["right"], float32(n.Properties.EM), n.Parent.Properties.Width)
- x = (base.Properties.Width - width) - v
+ v, _ := utils.ConvertToPixels(styleMap["right"], float32(n.EM), n.Parent.Width)
+ x = (base.Width - width) - v
@@ -200,2 +193,2 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- v, _ := utils.ConvertToPixels(styleMap["bottom"], float32(n.Properties.EM), n.Parent.Properties.Width)
- y = (base.Properties.Height - height) - v
+ v, _ := utils.ConvertToPixels(styleMap["bottom"], float32(n.EM), n.Parent.Width)
+ y = (base.Height - height) - v
@@ -206 +199 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- if v.Properties.Id == n.Properties.Id {
+ if v.Id == n.Id {
@@ -211 +204 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- y = sibling.Properties.Y
+ y = sibling.Y
@@ -213 +206 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- y = sibling.Properties.Y + sibling.Properties.Height
+ y = sibling.Y + sibling.Height
@@ -216 +209 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- y = sibling.Properties.Y + sibling.Properties.Height
+ y = sibling.Y + sibling.Height
@@ -221 +214 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- y += v.Properties.Margin.Top + v.Properties.Margin.Bottom + v.Properties.Padding.Top + v.Properties.Padding.Bottom + v.Properties.Height
+ y += v.Margin.Top + v.Margin.Bottom + v.Padding.Top + v.Padding.Bottom + v.Height
@@ -231 +224 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- x += n.Properties.Margin.Left
+ x += n.Margin.Left
@@ -234 +227 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- y += n.Properties.Margin.Top
+ y += n.Margin.Top
@@ -237 +230 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- x -= n.Properties.Margin.Right
+ x -= n.Margin.Right
@@ -240 +233 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- y -= n.Properties.Margin.Bottom
+ y -= n.Margin.Bottom
@@ -245 +238 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- if len(n.Properties.Text.Text) > 0 {
+ if len(n.Text.Text) > 0 {
@@ -249 +242 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- width = innerWidth + n.Properties.Padding.Left + n.Properties.Padding.Right
+ width = innerWidth + n.Padding.Left + n.Padding.Right
@@ -254,4 +247,4 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- n.Properties.X = x
- n.Properties.Y = y
- n.Properties.Width = width
- n.Properties.Height = height
+ n.X = x
+ n.Y = y
+ n.Width = width
+ n.Height = height
@@ -266,7 +259,7 @@ func ComputeNodeStyle(n element.Node, plugins []Plugin) element.Node {
- if n.Children[i].Style["position"] != "absolute" && n.Children[i].Properties.Y > childYOffset {
- childYOffset = n.Children[i].Properties.Y
- n.Properties.Height += n.Children[i].Properties.Height
- n.Properties.Height += n.Children[i].Properties.Margin.Top
- n.Properties.Height += n.Children[i].Properties.Margin.Bottom
- n.Properties.Height += n.Children[i].Properties.Padding.Top
- n.Properties.Height += n.Children[i].Properties.Padding.Bottom
+ if n.Children[i].Style["position"] != "absolute" && n.Children[i].Y > childYOffset {
+ childYOffset = n.Children[i].Y
+ n.Height += n.Children[i].Height
+ n.Height += n.Children[i].Margin.Top
+ n.Height += n.Children[i].Margin.Bottom
+ n.Height += n.Children[i].Padding.Top
+ n.Height += n.Children[i].Padding.Bottom
@@ -319,2 +312,2 @@ func inherit(n *element.Node, styleMap map[string]map[string]string) {
- if n.Properties.Type == html.ElementNode {
- pId := n.Parent.Properties.Id
+ if n.Type == html.ElementNode {
+ pId := n.Parent.Id
@@ -322,2 +315,2 @@ func inherit(n *element.Node, styleMap map[string]map[string]string) {
- if styleMap[n.Properties.Id] == nil {
- styleMap[n.Properties.Id] = make(map[string]string)
+ if styleMap[n.Id] == nil {
+ styleMap[n.Id] = make(map[string]string)
@@ -330 +323 @@ func inherit(n *element.Node, styleMap map[string]map[string]string) {
- styleMap[n.Properties.Id] = utils.Merge(styleMap[n.Properties.Id], inline)
+ styleMap[n.Id] = utils.Merge(styleMap[n.Id], inline)
@@ -332,2 +325,2 @@ func inherit(n *element.Node, styleMap map[string]map[string]string) {
- if styleMap[n.Properties.Id][v] == "" && styleMap[pId][v] != "" {
- styleMap[n.Properties.Id][v] = styleMap[pId][v]
+ if styleMap[n.Id][v] == "" && styleMap[pId][v] != "" {
+ styleMap[n.Id][v] = styleMap[pId][v]
@@ -337 +330 @@ func inherit(n *element.Node, styleMap map[string]map[string]string) {
- utils.SetMP(n.Properties.Id, styleMap)
+ utils.SetMP(n.Id, styleMap)
@@ -346 +339 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- n.Style = styleMap[n.Properties.Id]
+ n.Style = styleMap[n.Id]
@@ -349 +342 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- n.Properties.Border = border
+ n.Border = border
@@ -352,2 +345,2 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- fs, _ := utils.ConvertToPixels(n.Style["font-size"], n.Parent.Properties.EM, n.Parent.Properties.Width)
- n.Properties.EM = fs
+ fs, _ := utils.ConvertToPixels(n.Style["font-size"], n.Parent.EM, n.Parent.Width)
+ n.EM = fs
@@ -355,5 +348,5 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- mt, _ := utils.ConvertToPixels(n.Style["margin-top"], n.Properties.EM, n.Parent.Properties.Width)
- mr, _ := utils.ConvertToPixels(n.Style["margin-right"], n.Properties.EM, n.Parent.Properties.Width)
- mb, _ := utils.ConvertToPixels(n.Style["margin-bottom"], n.Properties.EM, n.Parent.Properties.Width)
- ml, _ := utils.ConvertToPixels(n.Style["margin-left"], n.Properties.EM, n.Parent.Properties.Width)
- n.Properties.Margin = element.Margin{
+ mt, _ := utils.ConvertToPixels(n.Style["margin-top"], n.EM, n.Parent.Width)
+ mr, _ := utils.ConvertToPixels(n.Style["margin-right"], n.EM, n.Parent.Width)
+ mb, _ := utils.ConvertToPixels(n.Style["margin-bottom"], n.EM, n.Parent.Width)
+ ml, _ := utils.ConvertToPixels(n.Style["margin-left"], n.EM, n.Parent.Width)
+ n.Margin = element.Margin{
@@ -366,5 +359,5 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- pt, _ := utils.ConvertToPixels(n.Style["padding-top"], n.Properties.EM, n.Parent.Properties.Width)
- pr, _ := utils.ConvertToPixels(n.Style["padding-right"], n.Properties.EM, n.Parent.Properties.Width)
- pb, _ := utils.ConvertToPixels(n.Style["padding-bottom"], n.Properties.EM, n.Parent.Properties.Width)
- pl, _ := utils.ConvertToPixels(n.Style["padding-left"], n.Properties.EM, n.Parent.Properties.Width)
- n.Properties.Padding = element.Padding{
+ pt, _ := utils.ConvertToPixels(n.Style["padding-top"], n.EM, n.Parent.Width)
+ pr, _ := utils.ConvertToPixels(n.Style["padding-right"], n.EM, n.Parent.Width)
+ pb, _ := utils.ConvertToPixels(n.Style["padding-bottom"], n.EM, n.Parent.Width)
+ pl, _ := utils.ConvertToPixels(n.Style["padding-left"], n.EM, n.Parent.Width)
+ n.Padding = element.Padding{
@@ -377 +370 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- width, _ := utils.ConvertToPixels(n.Style["width"], n.Properties.EM, n.Parent.Properties.Width)
+ width, _ := utils.ConvertToPixels(n.Style["width"], n.EM, n.Parent.Width)
@@ -379 +372 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- minWidth, _ := utils.ConvertToPixels(n.Style["min-width"], n.Properties.EM, n.Parent.Properties.Width)
+ minWidth, _ := utils.ConvertToPixels(n.Style["min-width"], n.EM, n.Parent.Width)
@@ -384 +377 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- maxWidth, _ := utils.ConvertToPixels(n.Style["max-width"], n.Properties.EM, n.Parent.Properties.Width)
+ maxWidth, _ := utils.ConvertToPixels(n.Style["max-width"], n.EM, n.Parent.Width)
@@ -388 +381 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- height, _ := utils.ConvertToPixels(n.Style["height"], n.Properties.EM, n.Parent.Properties.Height)
+ height, _ := utils.ConvertToPixels(n.Style["height"], n.EM, n.Parent.Height)
@@ -390 +383 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- minHeight, _ := utils.ConvertToPixels(n.Style["min-height"], n.Properties.EM, n.Parent.Properties.Height)
+ minHeight, _ := utils.ConvertToPixels(n.Style["min-height"], n.EM, n.Parent.Height)
@@ -395 +388 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- maxHeight, _ := utils.ConvertToPixels(n.Style["max-height"], n.Properties.EM, n.Parent.Properties.Height)
+ maxHeight, _ := utils.ConvertToPixels(n.Style["max-height"], n.EM, n.Parent.Height)
@@ -400,2 +393,2 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- n.Properties.Margin.Left = utils.Max((n.Parent.Properties.Width-width)/2, 0)
- n.Properties.Margin.Right = utils.Max((n.Parent.Properties.Width-width)/2, 0)
+ n.Margin.Left = utils.Max((n.Parent.Width-width)/2, 0)
+ n.Margin.Right = utils.Max((n.Parent.Width-width)/2, 0)
@@ -404,2 +397,2 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- n.Properties.Width = width
- n.Properties.Height = height
+ n.Width = width
+ n.Height = height
@@ -417,4 +410,4 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- f, _ := font.LoadFont(n.Style["font-family"], int(n.Properties.EM), bold, italic)
- letterSpacing, _ := utils.ConvertToPixels(n.Style["letter-spacing"], n.Properties.EM, width)
- wordSpacing, _ := utils.ConvertToPixels(n.Style["word-spacing"], n.Properties.EM, width)
- lineHeight, _ := utils.ConvertToPixels(n.Style["line-height"], n.Properties.EM, width)
+ f, _ := font.LoadFont(n.Style["font-family"], int(n.EM), bold, italic)
+ letterSpacing, _ := utils.ConvertToPixels(n.Style["letter-spacing"], n.EM, width)
+ wordSpacing, _ := utils.ConvertToPixels(n.Style["word-spacing"], n.EM, width)
+ lineHeight, _ := utils.ConvertToPixels(n.Style["line-height"], n.EM, width)
@@ -422 +415 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- lineHeight = n.Properties.EM + 3
+ lineHeight = n.EM + 3
@@ -425,5 +418,5 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- n.Properties.Text.LineHeight = int(lineHeight)
- n.Properties.Text.Text = n.InnerText()
- n.Properties.Text.Font = f
- n.Properties.Text.WordSpacing = int(wordSpacing)
- n.Properties.Text.LetterSpacing = int(letterSpacing)
+ n.Text.LineHeight = int(lineHeight)
+ n.Text.Text = n.InnerText()
+ n.Text.Font = f
+ n.Text.WordSpacing = int(wordSpacing)
+ n.Text.LetterSpacing = int(letterSpacing)
@@ -431 +424 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- n.Properties.Colors = color.Parse(n.Style)
+ n.Colors = color.Parse(n.Style)
@@ -433 +426 @@ func initNodes(n *element.Node, styleMap map[string]map[string]string) element.N
- if c.Properties.Type == html.ElementNode {
+ if c.Type == html.ElementNode {
@@ -455 +448 @@ func GetPositionOffsetNode(n *element.Node) *element.Node {
- if n.Parent.Properties.Node != nil {
+ if n.Parent.Node != nil {
@@ -508,4 +501,4 @@ func Print(n *element.Node, indent int) {
- fmt.Printf(pre+"%s\n", n.Properties.Id)
- fmt.Printf(pre+"-- Parent: %d\n", n.Parent.Properties.Id)
- fmt.Printf(pre+"\t-- Width: %f\n", n.Parent.Properties.Width)
- fmt.Printf(pre+"\t-- Height: %f\n", n.Parent.Properties.Height)
+ fmt.Printf(pre+"%s\n", n.Id)
+ fmt.Printf(pre+"-- Parent: %d\n", n.Parent.Id)
+ fmt.Printf(pre+"\t-- Width: %f\n", n.Parent.Width)
+ fmt.Printf(pre+"\t-- Height: %f\n", n.Parent.Height)
@@ -513,2 +506,2 @@ func Print(n *element.Node, indent int) {
- fmt.Printf(pre+"\t-- Font: %f\n", n.Properties.Colors.Font)
- fmt.Printf(pre+"\t-- Background: %f\n", n.Properties.Colors.Background)
+ fmt.Printf(pre+"\t-- Font: %f\n", n.Colors.Font)
+ fmt.Printf(pre+"\t-- Background: %f\n", n.Colors.Background)
@@ -516,6 +509,6 @@ func Print(n *element.Node, indent int) {
- fmt.Printf(pre+"-- EM: %f\n", n.Properties.EM)
- fmt.Printf(pre+"-- X: %f\n", n.Properties.X)
- fmt.Printf(pre+"-- Y: %f\n", n.Properties.Y)
- fmt.Printf(pre+"-- Width: %f\n", n.Properties.Width)
- fmt.Printf(pre+"-- Height: %f\n", n.Properties.Height)
- fmt.Printf(pre+"-- Border: %#v\n", n.Properties.Border)
+ fmt.Printf(pre+"-- EM: %f\n", n.EM)
+ fmt.Printf(pre+"-- X: %f\n", n.X)
+ fmt.Printf(pre+"-- Y: %f\n", n.Y)
+ fmt.Printf(pre+"-- Width: %f\n", n.Width)
+ fmt.Printf(pre+"-- Height: %f\n", n.Height)
+ fmt.Printf(pre+"-- Border: %#v\n", n.Border)
@@ -554,2 +547,2 @@ func genTextNode(n *element.Node, width, height *float32) {
- letterSpacing, _ := utils.ConvertToPixels(n.Style["letter-spacing"], n.Properties.EM, *width)
- wordSpacing, _ := utils.ConvertToPixels(n.Style["word-spacing"], n.Properties.EM, *width)
+ letterSpacing, _ := utils.ConvertToPixels(n.Style["letter-spacing"], n.EM, *width)
+ wordSpacing, _ := utils.ConvertToPixels(n.Style["word-spacing"], n.EM, *width)
@@ -562 +555 @@ func genTextNode(n *element.Node, width, height *float32) {
- dt, _ = utils.ConvertToPixels(n.Style["text-decoration-thickness"], n.Properties.EM, *width)
+ dt, _ = utils.ConvertToPixels(n.Style["text-decoration-thickness"], n.EM, *width)
@@ -567,13 +560,13 @@ func genTextNode(n *element.Node, width, height *float32) {
- n.Properties.Text.Color = c
- n.Properties.Text.Align = n.Style["text-align"]
- n.Properties.Text.WordBreak = wb
- n.Properties.Text.WordSpacing = int(wordSpacing)
- n.Properties.Text.LetterSpacing = int(letterSpacing)
- n.Properties.Text.WhiteSpace = n.Style["white-space"]
- n.Properties.Text.DecorationColor = n.Properties.Colors.TextDecoration
- n.Properties.Text.DecorationThickness = int(dt)
- n.Properties.Text.Overlined = n.Style["text-decoration"] == "overline"
- n.Properties.Text.Underlined = n.Style["text-decoration"] == "underline"
- n.Properties.Text.LineThrough = n.Style["text-decoration"] == "linethrough"
- n.Properties.Text.EM = int(n.Properties.EM)
- n.Properties.Text.Width = int(n.Parent.Properties.Width)
+ n.Text.Color = c
+ n.Text.Align = n.Style["text-align"]
+ n.Text.WordBreak = wb
+ n.Text.WordSpacing = int(wordSpacing)
+ n.Text.LetterSpacing = int(letterSpacing)
+ n.Text.WhiteSpace = n.Style["white-space"]
+ n.Text.DecorationColor = n.Colors.TextDecoration
+ n.Text.DecorationThickness = int(dt)
+ n.Text.Overlined = n.Style["text-decoration"] == "overline"
+ n.Text.Underlined = n.Style["text-decoration"] == "underline"
+ n.Text.LineThrough = n.Style["text-decoration"] == "linethrough"
+ n.Text.EM = int(n.EM)
+ n.Text.Width = int(n.Parent.Width)
@@ -582 +575 @@ func genTextNode(n *element.Node, width, height *float32) {
- n.Properties.Text.WordSpacing = font.MeasureSpace(&n.Properties.Text)
+ n.Text.WordSpacing = font.MeasureSpace(&n.Text)
@@ -584,2 +577,2 @@ func genTextNode(n *element.Node, width, height *float32) {
- if n.Parent.Properties.Width != 0 && n.Style["display"] != "inline" && n.Style["width"] == "" {
- *width = (n.Parent.Properties.Width - n.Properties.Padding.Right) - n.Properties.Padding.Left
+ if n.Parent.Width != 0 && n.Style["display"] != "inline" && n.Style["width"] == "" {
+ *width = (n.Parent.Width - n.Padding.Right) - n.Padding.Left
@@ -587 +580 @@ func genTextNode(n *element.Node, width, height *float32) {
- *width = utils.Max(*width, float32(font.MeasureLongest(&n.Properties.Text)))
+ *width = utils.Max(*width, float32(font.MeasureLongest(&n.Text)))
@@ -589 +582 @@ func genTextNode(n *element.Node, width, height *float32) {
- *width, _ = utils.ConvertToPixels(n.Style["width"], n.Properties.EM, n.Parent.Properties.Width)
+ *width, _ = utils.ConvertToPixels(n.Style["width"], n.EM, n.Parent.Width)
@@ -592 +585 @@ func genTextNode(n *element.Node, width, height *float32) {
- n.Properties.Text.Width = int(*width)
+ n.Text.Width = int(*width)