Skip to content

Commit

Permalink
Merge pull request #22 from oakmound/feature/modsel-13-alt
Browse files Browse the repository at this point in the history
Add alternate version of css3-modsel-13
  • Loading branch information
Implausiblyfun committed May 27, 2023
2 parents 0ea03f8 + 7136f35 commit 3df8823
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
22 changes: 18 additions & 4 deletions html.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ func renderNode(node *ParsedNode, stack *trackingDrawStack, drawzone floatgeom.R
}
childDrawzoneModifier := floatgeom.Point2{}

skipChildren := false

// TODO: inline vs block / content categories
switch node.Tag {
case "div":
Expand Down Expand Up @@ -678,8 +680,17 @@ func renderNode(node *ParsedNode, stack *trackingDrawStack, drawzone floatgeom.R
case "ul":
if node.FirstChild != nil {

// TODO: better extraction of text from children nodes
// This points out that each node should decide how its children are rendered in context (dfs style, probably),
// instead of always drawing all children after handling each parent node.
textNode := node.FirstChild
if textNode.Raw.Type != html.TextNode && textNode.FirstChild != nil && textNode.FirstChild.Raw.Type == html.TextNode {
textNode = textNode.FirstChild
skipChildren = true
}

// TODO: Figure out a way to get actual content size rather than this crude version
text := node.FirstChild.Raw.Data
text := textNode.Raw.Data
textSize := 16.0
if size, ok := parseLength(node.Style["font-size"]); ok {
textSize = size
Expand Down Expand Up @@ -712,8 +723,8 @@ func renderNode(node *ParsedNode, stack *trackingDrawStack, drawzone floatgeom.R
drawBackground(node, stack, childDrawZone, textSize+textVBuffer, math.MaxFloat64)

// draw text
if node.FirstChild.Raw.Type == html.TextNode {
rText, _, bds := formatTextAsSprite(node, childDrawZone, 16.0, text)
if textNode.Raw.Type == html.TextNode {
rText, _, bds := formatTextAsSprite(textNode, drawzone, 16.0, text)
rText.SetPos(childDrawZone.Min.X(), childDrawZone.Min.Y())
stack.draw(rText)
drawzone.Min = drawzone.Min.Add(floatgeom.Point2{-bulletGap, textVBuffer + float64(bds.Dy())})
Expand Down Expand Up @@ -799,7 +810,10 @@ func renderNode(node *ParsedNode, stack *trackingDrawStack, drawzone floatgeom.R
}
}
drawzone.Min = drawzone.Min.Add(childDrawzoneModifier)
childrenHeight := renderNode(node.FirstChild, stack, drawzone, state)
var childrenHeight float64
if !skipChildren {
childrenHeight = renderNode(node.FirstChild, stack, drawzone, state)
}
drawzone.Min = drawzone.Min.Sub(childDrawzoneModifier)
drawzone.Min = drawzone.Min.Add(floatgeom.Point2{0, float64(childrenHeight)})

Expand Down
24 changes: 24 additions & 0 deletions testdata/htmlin/css3-modsel-13-alt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Class selectors</title>
<style type="text/css">li { background-color : red }
.t1 { background-color : lime }
li.t2 { background-color : lime }
.t3 { background-color : red }</style>
<link rel="first" href="css3-modsel-1.html" title="Groups of selectors">
<link rel="prev" href="css3-modsel-11.html" title="Substring matching attribute selector (contains)">
<link rel="next" href="css3-modsel-14.html" title="More than one class selector">
<link rel="last" href="css3-modsel-d4.html" title="Dynamic updating of :first-child and :last-child">
<link rel="up" href="./index.html">
<link rel="top" href="../../index.html">
</head>
<body>
<ul>
<li class="t1">This list item should have green background because its class is &quot;t1&quot;</li>
<li class="t2">This list item should have green background because its class is &quot;t2&quot;</li>
<li class="t2"><span class="t33">This list item should have green background because the inner SPAN does not match SPAN.t3</span>
</li>
</ul>
</body>
</html>
Binary file added testdata/htmlout/css3-modsel-13-alt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3df8823

Please sign in to comment.