Commit 1d9fcaa3 authored by Kristian Høgsberg's avatar Kristian Høgsberg

File Edit Options Buffers Tools Help

2005-03-23  Kristian Høgsberg  <krh@redhat.com>

        * poppler/Catalog.cc (indexToLabel, labelToIndex): Add stricter
        checking of incoming labels and indices.

        * glib/test-poppler-glib.c (main): Change test program to take the
        page label from the command line.
parent a9bbb465
2005-03-23 Kristian Høgsberg <krh@redhat.com>
* poppler/Catalog.cc (indexToLabel, labelToIndex): Add stricter
checking of incoming labels and indices.
* glib/test-poppler-glib.c (main): Change test program to take the
page label from the command line.
* glib/poppler-page.cc:
* glib/poppler-page.h: Add poppler_page_get_index() and rename
popper_page_get_dimension() to popper_page_get_size()
......
......@@ -32,7 +32,10 @@ int main (int argc, char *argv[])
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 100, 100);
gdk_pixbuf_fill (pixbuf, 0x00106000);
page = poppler_document_get_page_by_label (document, "vi");
page = poppler_document_get_page_by_label (document, argv[2]);
if (page == NULL)
FAIL ("page not found");
poppler_page_get_size (page, &width, &height);
printf ("page size: %f inches by %f inches\n", width / 72, height / 72);
......
......@@ -101,6 +101,8 @@ Catalog::Catalog(XRef *xrefA) {
if (catDict.dictLookup("PageLabels", &obj)->isDict())
pageLabelInfo = new PageLabelInfo(&obj, numPages);
else
pageLabelInfo = NULL;
obj.free();
// read page mode
......@@ -426,10 +428,35 @@ void NameTree::free()
GBool Catalog::labelToIndex(GooString *label, int *index)
{
return pageLabelInfo->labelToIndex(label, index);
char *end;
if (pageLabelInfo != NULL) {
if (!pageLabelInfo->labelToIndex(label, index))
return gFalse;
} else {
*index = strtol(label->getCString(), &end, 10) - 1;
if (*end != '\0')
return gFalse;
}
if (*index < 0 || *index >= numPages)
return gFalse;
return gTrue;
}
GBool Catalog::indexToLabel(int index, GooString *label)
{
return pageLabelInfo->indexToLabel(index, label);
char buffer[32];
if (index < 0 || index >= numPages)
return gFalse;
if (pageLabelInfo != NULL) {
return pageLabelInfo->indexToLabel(index, label);
} else {
snprintf(buffer, sizeof (buffer), "%d", index + 1);
label->append(buffer);
return gTrue;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment