Skip to content

Commit

Permalink
B: fix various html empty lines related issues
Browse files Browse the repository at this point in the history
This adds support for multiple br tags in HTML mode. 

This fixes #303 and #305
  • Loading branch information
pgundlach committed Jan 19, 2021
1 parent cf260de commit 014b540
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 35 deletions.
Binary file modified qa/harfbuzz/accents/reference.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions qa/html/binp/data.xml
@@ -0,0 +1,4 @@
<data>
<p>a</p>
<p><b>b</b>text</p>
</data>
16 changes: 16 additions & 0 deletions qa/html/binp/layout.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<Layout xmlns="urn:speedata.de:2009/publisher/en" xmlns:sd="urn:speedata:2009/publisher/functions/en">

<Pageformat width="5cm" height="6cm" />
<DefineTextformat name="text" html-vertical-spacing="all" />

<Record element="data">
<PlaceObject>
<Textblock>
<Paragraph html="all">
<Value select="."/>
</Paragraph>
</Textblock>
</PlaceObject>
</Record>
</Layout>
Binary file added qa/html/binp/reference.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions qa/html/br/data.xml
@@ -0,0 +1,10 @@
<data>
<case>
<!-- three br -->
A<br/><br/><br/>B
</case>
<case>
<!-- par and two br-->
<p>A</p><br/><br/><p>B</p>
</case>
</data>
22 changes: 22 additions & 0 deletions qa/html/br/layout.xml
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<Layout
xmlns="urn:speedata.de:2009/publisher/en"
xmlns:sd="urn:speedata:2009/publisher/functions/en">

<Trace grid="yes"/>
<SetGrid height="12pt" nx="4" />
<Pageformat width="5cm" height="6cm"/>

<Record element="data">
<PlaceObject>
<Textblock>
<ForAll select="case">
<Paragraph>
<Value select="."/>
</Paragraph>
</ForAll>
</Textblock>
</PlaceObject>
</Record>

</Layout>
Binary file added qa/html/br/reference.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions qa/html/forallbr/data.xml
@@ -0,0 +1,7 @@
<data>
<part>A</part>
<part><br /></part>
<part><br /></part>
<part><br /></part>
<part>B</part>
</data>
20 changes: 20 additions & 0 deletions qa/html/forallbr/layout.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Layout
xmlns="urn:speedata.de:2009/publisher/en"
xmlns:sd="urn:speedata:2009/publisher/functions/en">
<!-- <Trace grid="yes"/> -->
<Pageformat width="5cm" height="6cm"/>
<SetGrid height="12pt" width="1cm" />
<Record element="data">
<Output>
<Text>
<Paragraph>
<ForAll select="part">
<Value select="."/>
</ForAll>
</Paragraph>
</Text>
</Output>
</Record>

</Layout>
Binary file added qa/html/forallbr/reference.pdf
Binary file not shown.
11 changes: 9 additions & 2 deletions src/go/css/tree.go
Expand Up @@ -355,8 +355,15 @@ func dumpElement(thisNode *html.Node, level int, direction mode) {
} else {
// keep dir
}
fmt.Fprintf(out, "%s { elementname = %q, direction = %q,\n", indent, eltname, newDir)

isBlock := false
if eltname == "address" || eltname == "article" || eltname == "aside" || eltname == "audio" || eltname == "video" || eltname == "blockquote" || eltname == "canvas" || eltname == "dd" || eltname == "div" || eltname == "dl" || eltname == "fieldset" || eltname == "figcaption" || eltname == "figure" || eltname == "footer" || eltname == "form" || eltname == "h1" || eltname == "h2" || eltname == "h3" || eltname == "h4" || eltname == "h5" || eltname == "h6" || eltname == "header" || eltname == "hgroup" || eltname == "hr" || eltname == "noscript" || eltname == "ol" || eltname == "output" || eltname == "p" || eltname == "pre" || eltname == "section" || eltname == "table" || eltname == "tfoot" || eltname == "ul" {
isBlock = true
}
fmt.Fprintf(out, "%s { elementname = %q, direction = %q,", indent, eltname, newDir)
if isBlock {
fmt.Fprint(out, " block=true,")
}
fmt.Fprintln(out)
attributes := thisNode.Attr
if len(attributes) > 0 {
fmt.Fprintf(out, "%s attributes = {", indent)
Expand Down
3 changes: 2 additions & 1 deletion src/lua/par.lua
Expand Up @@ -224,8 +224,9 @@ local function flatten(self,items,options)
for tb=1,#thisblock do
local tbc = thisblock[tb].contents
local dir = publisher.getprop(tbc,"direction")
local mode = thisblock.mode
if tbc then
if c > startnewline and ( has_contents == false ) and dir ~= "" then
if (tb == 1 and mode == "block" ) or ( c > startnewline and ( has_contents == false ) and dir ~= "" ) then
publisher.setprop(tbc,"split",true)
publisher.setprop(tbc,"padding_left",thisblock.padding_left)
publisher.setprop(tbc,"prependnodelist",thisblock.prependnodelist)
Expand Down
2 changes: 1 addition & 1 deletion src/lua/publisher.lua
Expand Up @@ -917,7 +917,6 @@ do
ret = ret or {}
parameter = parameter or {}
local indent = box.indent_amount or 0
-- w("fb: indent %gpt",indent / factor)
if indent and parameter.indent then
indent = parameter.indent + indent
end
Expand Down Expand Up @@ -961,6 +960,7 @@ do
else
-- a box with paragraphs inside
flatten_boxes(thisbox,new_parameter,ret)
if thisbox.mode == "block" then ret.mode = "block" end
end
end
return ret
Expand Down
85 changes: 54 additions & 31 deletions src/lua/publisher/html.lua
Expand Up @@ -721,6 +721,7 @@ function build_nodelist(elt,options,before_box,caller )
options = options or {}
-- ret is a nested table of boxes and paragraphs
local ret = {}
local prevdir = "vertical"
for i=1,#elt do
local thiselt = elt[i]
local thiseltname = thiselt.elementname
Expand Down Expand Up @@ -862,7 +863,10 @@ function build_nodelist(elt,options,before_box,caller )
end
end
if appended then
prevdir = "horizontal"
ret[#ret + 1] = a
else
prevdir = "vertical"
end
else
local box = Box:new()
Expand All @@ -872,6 +876,7 @@ function build_nodelist(elt,options,before_box,caller )
box.width = styles.calculated_width - margin_left - margin_right - padding_left - padding_right

if thiseltname == "table" then
prevdir = "vertical"
-- w("html/table")
local nl = build_html_table(thiselt)
local tabpar = par:new(nil,"html table (a)")
Expand All @@ -882,6 +887,7 @@ function build_nodelist(elt,options,before_box,caller )
box[#box + 1] = tabpar
ret[#ret + 1] = box
elseif thiseltname == "ol" or thiseltname == "ul" then
prevdir = "vertical"
styles.olullisttype = thiseltname
styles.listindent = padding_left
styles.listlevel = styles.listlevel + 1
Expand All @@ -904,6 +910,7 @@ function build_nodelist(elt,options,before_box,caller )
end
ret[#ret + 1] = box
elseif thiseltname == "li" then
prevdir = "vertical"
olcounter[styles.listlevel] = olcounter[styles.listlevel] or 0
olcounter[styles.listlevel] = olcounter[styles.listlevel] + 1
local n = build_nodelist(thiselt,options,before_box,"build_nodelist/ li" )
Expand All @@ -920,43 +927,59 @@ function build_nodelist(elt,options,before_box,caller )
ret[#ret + 1] = a
end
elseif thiseltname == "br" then
local a = par:new(tf,"html.lua (br)")
a:append(node.new("hlist"))
box[#box + 1] = a
ret[#ret + 1] = box
if prevdir == "vertical" then
local a = par:new(tf,"html.lua (br)")
local strutheight = publisher.fonts.lookup_fontfamily_number_instance[fam].baselineskip
local strut = node.new("rule")
strut.width=0
strut.height = strutheight*0.75
strut.depth = strutheight*0.25
local hlist = node.hpack(strut)

a:append(hlist)
box[#box + 1] = a
ret[#ret + 1] = box
end
prevdir = "vertical"
else
prevdir = "vertical"
local n = build_nodelist(thiselt,options,before_box,string.format("build_nodelist/ any element name %q",thiseltname))
before_box = nil
box.draw_border = attributes.has_border
box.border = {
borderstart = true,
border_top_style = border_top_style,
border_right_style = border_right_style,
border_bottom_style = border_bottom_style,
border_left_style = border_left_style,
padding_top = padding_top,
padding_right = padding_right,
padding_bottom = padding_bottom,
padding_left = padding_left,
rule_width_top = rule_width_top,
rule_width_right = rule_width_right,
rule_width_bottom = rule_width_bottom,
rule_width_left = rule_width_left,
border_top_color = border_top_color,
border_right_color = border_right_color,
border_bottom_color = border_bottom_color,
border_left_color = border_left_color,
border_bottom_right_radius = tex.sp(border_bottom_right_radius),
border_bottom_left_radius = tex.sp(border_bottom_left_radius),
border_top_right_radius = tex.sp(border_top_right_radius),
border_top_left_radius = tex.sp(border_top_left_radius),
margin_top = margin_top,
margin_right = margin_right,
margin_bottom = margin_bottom,
margin_left = margin_left,
}
if box.draw_border then
box.border = {
borderstart = true,
border_top_style = border_top_style,
border_right_style = border_right_style,
border_bottom_style = border_bottom_style,
border_left_style = border_left_style,
padding_top = padding_top,
padding_right = padding_right,
padding_bottom = padding_bottom,
padding_left = padding_left,
rule_width_top = rule_width_top,
rule_width_right = rule_width_right,
rule_width_bottom = rule_width_bottom,
rule_width_left = rule_width_left,
border_top_color = border_top_color,
border_right_color = border_right_color,
border_bottom_color = border_bottom_color,
border_left_color = border_left_color,
border_bottom_right_radius = tex.sp(border_bottom_right_radius),
border_bottom_left_radius = tex.sp(border_bottom_left_radius),
border_top_right_radius = tex.sp(border_top_right_radius),
border_top_left_radius = tex.sp(border_top_left_radius),
margin_top = margin_top,
margin_right = margin_right,
margin_bottom = margin_bottom,
margin_left = margin_left,
}
end
local mode
if thiselt.block then mode = "block" end
for i = 1,#n do
box[#box + 1] = n[i]
box[#box].mode = mode
end
ret[#ret + 1] = box
end
Expand Down

0 comments on commit 014b540

Please sign in to comment.