Hello Francesco, hello all, > On 23 February 2018 at 01:05 Francesco Pretto <cez...@gmail.com> wrote: > > > 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 ah, I see, I think I've found it: Do you mean that the GetKey() call in src/doc/PdfPagesTree.cpp line 620 throws then? I'll fix that probably on the coming weekend or before (if you haven't by then, I mean, if your solution will be correct, I'll commit it, maybe with some doc clarifying).
> 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. Ah, thanks. I'm looking forward to your next suggestion. > > > - 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). I didn't/don't want to change this API (including the special meaning of the index -1, I don't really understand why there are more negative ones). So it's currently "-1"-based as I see it, so my answer is "both". I'm not sure whether clamping is the best idea, though ... Best regards, mabri P.S. I wish you a sound sleep this night if you're located in Europe ;-). ------------------------------------------------------------------------------ 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 Podofoemail@example.com https://lists.sourceforge.net/lists/listinfo/podofo-users