[ 
https://issues.apache.org/jira/browse/PDFBOX-2677?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andrea Vacondio updated PDFBOX-2677:
------------------------------------
    Attachment: outline_wrong_first_has_prev.pdf
                outline_patch.diff
                outline_closed_patched.pdf
                outline_closed_negative_outlines_count_wrong_last.pdf

> Negative Outlines COUNT and various issues
> ------------------------------------------
>
>                 Key: PDFBOX-2677
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2677
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.0
>         Environment: 2.0.0-SNAPSHOT r1658566
>            Reporter: Andrea Vacondio
>              Labels: outline
>         Attachments: outline_closed_negative_outlines_count_wrong_last.pdf, 
> outline_closed_patched.pdf, outline_patch.diff, 
> outline_wrong_first_has_prev.pdf
>
>
> Hi,
> I started playing with the outline package few days ago mostly writing unit 
> tests but I found the current implementation has a number of issues and 
> started fixing them. I ended up with a quite substantial patch I'm going to 
> attach.
> So far I only addressed the addition of nodes.
> Current implementation suffers of some issues:
> * insertSiblingAfter doesn't set the LAST on its parent in case it's the last 
> node
> * Outlines COUNT can be negative (and often is) despite the spec table 152 
> states "The value cannot be negative."
> * invalid outline hierarchy with wrong COUNT can be created with no warning 
> with code like:
>       {code:java}
>       PDDocumentOutline outline = new PDDocumentOutline();
>         PDOutlineItem root = new PDOutlineItem();
>         root.setTitle("Root");
>         PDOutlineItem child1 = new PDOutlineItem();
>         child1.setTitle("child1");
>         PDOutlineItem child11 = new PDOutlineItem();
>         child11.setTitle("child11");
>         PDOutlineItem child12 = new PDOutlineItem();
>         child12.setTitle("child12");
>         PDOutlineItem child13 = new PDOutlineItem();
>         child13.setTitle("child13");
>         child11.insertSiblingAfter(child12);
>         child12.insertSiblingAfter(child13);
>         child1.appendChild(child12);
>         root.appendChild(child1);
>         outline.appendChild(root);
>       {code}
> I'm going to attach a couple of generated pdf showing the mentioned issues.
> The patch addresses:
> * PDFBOX-156
> * PDFBOX-996
> * PDFBOX-1209
> * Outlines COUNT is always positive  (table 152 "Total number of visible 
> outline items at all levels of the outline")
> * Outline items COUNT is correctly calculated
> * NEXT, PREV, LAST and FIRST are are consistently set
> * unit tested
> I added a restriction to methods adding nodes (children or siblings) that 
> throws an exception in case the node is already part of a list (i.e it has a 
> prev or a next) so basically with the patch you cannot create a list of nodes 
> and then add one of them as last child of another node but you'll have to 
> first add the first child and then add siblings to the child. 
> Those scenarios are currently silently accepted creating invalid outlines 
> (see the attached outline_wrong_first_has_prev.pdf) and would require quite 
> some work to handle all of them so, I'm not sure it's the best solution but 
> at least the user is guided with a message instead of creating an outline 
> where the FIRST item has a PREV.
> It breaks the current API and it might be reworked to be less intrusive but 
> since you are on 2.0.0-SNAPSHOT I thought it was ok.
> Please let me know if there's anything I can help with.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to