On 23 February 2018 at 00:13, Matthew Brincke <ma...@mailbox.org> wrote:
> where did it crash? What kind of crash was it, please? I've looked in
> the source code and couldn't find a reason for a crash, the index -1
> for InsertPage(int, PdfPage*) just means "insert before the first page".

Inserting page with index 0 in an empty document will crash. Following
common zero based index convention, the following code should work,
page count should be 3, and internal order of the pages should be
page2, page1, page3.

    PdfMemDocument document;
    PdfRect rect;
    auto page1 = document.InsertPage(rect, 0);
    auto page2  = document.InsertPage(rect, 0);
    auto page3 = document.InsertPage(rect, 2);
    int count = document.GetPageCount();

Having said this, my patch has **indeed** problems and doesn't really
work in the previous example. I didn't quite get how it works the
internal collection of pages. I will look at it tomorrow.

> - insertion before the first page through this wouldn't be possible [...]
> - insertion after the last one wouldn't work either [...]

I don't understand if you disagree with the zero based index API or
you just say that my patch doesn't work as intended (which is true).
Inserting before the first page is inserting at zero. Inserting after
last one is inserting at number of pages. Negative and out of range
indices can still be supported by clamping (in other notable APIs they
are usually treated as errors).

Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Podofo-users mailing list

Reply via email to