Skip to content

Commit

Permalink
Add parse name of tag in css
Browse files Browse the repository at this point in the history
  • Loading branch information
janczer committed Mar 6, 2017
1 parent a3a7118 commit f390cd7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
27 changes: 25 additions & 2 deletions box.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package htmlPDF

import "fmt"

type Dimensions struct {
content Rect

Expand Down Expand Up @@ -132,6 +134,7 @@ func buildLayoutTree(styleNode StyleNode) *LayoutBox {
case "block":
root.children[len(root.children)] = buildLayoutTree(child)
case "inline":
fmt.Println("some inline")
inline := root.getInlineContainer()
inline.style = child
inline.children[len(inline.children)] = buildLayoutTree(child)
Expand All @@ -147,8 +150,10 @@ func (l *LayoutBox) getInlineContainer() *LayoutBox {
boxT := l.box_type
switch boxT.(type) {
case AnonymousBlock, InlineNode:
fmt.Println("anonymous")
return l
case BlockNode:
fmt.Println("blocknode")
return NewLayoutBox(AnonymousBlock{}, StyleNode{})
default:
return l
Expand All @@ -169,15 +174,33 @@ func (l *LayoutBox) layout(containBlock *Dimensions) {
case BlockNode:
l.layoutBox(containBlock)
case InlineNode:
fmt.Println("layout inlinenode")
l.inlineBox(containBlock)
case AnonymousBlock:
//TODO
fmt.Println("layout anonymous")
l.anonymousBox(containBlock)
default:
}
}

func (l *LayoutBox) inlineBox(containBlock *Dimensions) {
l.dimensions.margin.top = 10
fmt.Printf("%+v", containBlock.content)

l.dimensions.content.x = containBlock.content.x
l.dimensions.content.y = containBlock.content.y
//l.dimensions.content.y = containBlock.content.height
}

func (l *LayoutBox) anonymousBox(containBlock *Dimensions) {
fmt.Printf("%+v", containBlock.content)
//block position is the same previous
l.dimensions.content.x = containBlock.content.x
l.dimensions.content.y = containBlock.content.y
l.dimensions.content.height = containBlock.content.height
l.dimensions.content.width = containBlock.content.width

//Recursibely layout the children of this box
l.layoutBlockChildren()
}

func (l *LayoutBox) layoutBox(containBlock *Dimensions) {
Expand Down
16 changes: 12 additions & 4 deletions css.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,19 @@ func (p *Parser) parseSelector() SimpleSelector {
m := SimpleSelector{class: map[int]string{}}
Loopsel:
for !p.eof() {
switch p.nextChar() {
case "#":
c := p.nextChar()
switch {
case c == "#":
p.consumeChar()
m.id = p.parseIdentifier()
case ".":
case c == ".":
p.consumeChar()
m.class[len(m.class)] = p.parseIdentifier()
case "*":
case c == "*":
// universal selector
p.consumeChar()
case validIdentifierChar(c):
m.tag_name = p.parseIdentifier()
default:
break Loopsel
}
Expand All @@ -239,6 +242,11 @@ Loopsel:
return m
}

func validIdentifierChar(c string) bool {
var valid = regexp.MustCompile("[a-zA-Z0-9-_]")
return valid.MatchString(c)
}

//Parse a property name or keyword
func (p *Parser) parseIdentifier() string {
var valid = regexp.MustCompile("[a-zA-Z0-9-_]")
Expand Down
2 changes: 2 additions & 0 deletions display.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package htmlPDF

import (
"fmt"
"github.com/jung-kurt/gofpdf"
)

Expand Down Expand Up @@ -66,6 +67,7 @@ func renderText(layoutBox *LayoutBox, list map[int]DisplayCommand) {
if len(text) == 0 {
return
}
fmt.Println(text)

list[len(list)] = DisplayCommand{
command: Text{
Expand Down

0 comments on commit f390cd7

Please sign in to comment.