speedata / publisher

speedata Publisher - a professional database Publishing system
https://www.speedata.de/
GNU Affero General Public License v3.0
296 stars 36 forks source link

Image prevents a new line #341

Closed pgundlach closed 3 years ago

pgundlach commented 3 years ago

Commit 980e88785029a99898bfcacde53548942a42611a introduced a bug in newline handling in this case:

<Layout xmlns="urn:speedata.de:2009/publisher/en" xmlns:sd="urn:speedata:2009/publisher/functions/en">
    <Pageformat height="5cm" width="6cm" />
    <Record element="data">
        <PlaceObject>
            <Textblock>
                <Paragraph>
                    <Value>A</Value>
                    <Image width="2cm" file="_samplea.pdf"></Image>
                </Paragraph>
                <Paragraph>
                    <Value>B</Value>
                </Paragraph>
            </Textblock>
        </PlaceObject>
    </Record>
</Layout>

This is the result:

nl-bad

This is expected:

nl-good
pgundlach commented 3 years ago

A fix would be something like

diff --git a/src/lua/par.lua b/src/lua/par.lua
index 1cc6cf8a..9f8373df 100644
--- a/src/lua/par.lua
+++ b/src/lua/par.lua
@@ -351,7 +351,7 @@ function Par:mknodelist( options )
         if nodelist == nil then
             -- the beginning of a new line (perhaps the first new line)
             nodelist = thisself
-        elseif thisself.id == publisher.vlist_node or publisher.getprop(thisself,"split") then
+        elseif publisher.getprop(thisself,"split") then
             -- text right after a  newline, so push stuff that we have into the objects list and
             -- put what we have into the node list
             if nodelist.id == publisher.glue_node and nodelist.prev == nil and nodelist.next == nil then
@@ -360,6 +360,16 @@ function Par:mknodelist( options )
                 table.insert(objects,nodelist)
             end
             nodelist = thisself
+        elseif thisself.id == publisher.vlist_node then
+            -- this node is a vlist, so it should appear on a new line
+            if nodelist.id == publisher.glue_node and nodelist.prev == nil and nodelist.next == nil then
+                -- ignore, just glue
+                nodelist = thisself
+            else
+                table.insert(objects,nodelist)
+                table.insert(objects,thisself)
+                nodelist = nil
+            end
         else
             -- just objects to be appended to the node list
             local tail = node.tail(nodelist)

But I am not sure if the current behaviour is better than the last.

pgundlach commented 3 years ago

Actually, I think it works as intended, so I close this bug.