From 4f56f5d36482e5750ceb18f0cd34f16a08d7b829 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Thu, 13 Jan 2005 00:06:25 +0000 Subject: [PATCH] PR: Obtained from: Submitted by: Reviewed by: "starting-state" property implemented for fo:bookmark. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198265 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/area/BookmarkData.java | 34 +++++++++++-------- .../fop/fo/pagination/bookmarks/Bookmark.java | 14 +++++--- src/java/org/apache/fop/pdf/PDFDocument.java | 2 +- src/java/org/apache/fop/pdf/PDFFactory.java | 8 +++-- src/java/org/apache/fop/pdf/PDFOutline.java | 25 ++++++++------ .../apache/fop/render/pdf/PDFRenderer.java | 9 +++-- 6 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/java/org/apache/fop/area/BookmarkData.java b/src/java/org/apache/fop/area/BookmarkData.java index 3659d1fb1..55efeae33 100644 --- a/src/java/org/apache/fop/area/BookmarkData.java +++ b/src/java/org/apache/fop/area/BookmarkData.java @@ -33,9 +33,12 @@ import org.apache.fop.fo.pagination.bookmarks.Bookmark; public class BookmarkData extends OffDocumentItem implements Resolvable { private ArrayList subData = new ArrayList(); - // bookmark-title for this bookmark + // bookmark-title for this fo:bookmark private String bookmarkTitle = null; + // indicator of whether to initially display/hide child bookmarks of this object + private boolean bShow = true; + // ID Reference for this bookmark private String idRef; @@ -55,6 +58,8 @@ public class BookmarkData extends OffDocumentItem implements Resolvable { public BookmarkData(BookmarkTree bookmarkTree) { idRef = null; whenToProcess = END_OF_DOC; + // top level defined in Rec to show all child bookmarks + bShow = true; for (int count = 0; count < bookmarkTree.getBookmarks().size(); count++) { Bookmark bkmk = (Bookmark)(bookmarkTree.getBookmarks()).get(count); @@ -68,10 +73,12 @@ public class BookmarkData extends OffDocumentItem implements Resolvable { * with a idref. During processing, this idref will be * subsequently resolved to a particular PageViewport. * - * @param idref the id reference + * @param bookmark the fo:bookmark object */ - public BookmarkData(String idref) { - this.idRef = idref; + public BookmarkData(Bookmark bookmark) { + bookmarkTitle = bookmark.getBookmarkTitle(); + bShow = bookmark.showChildItems(); + this.idRef = bookmark.getInternalDestination(); unresolvedIDRefs.put(idRef, this); } @@ -100,21 +107,21 @@ public class BookmarkData extends OffDocumentItem implements Resolvable { } /** - * Set the title for this bookmark. + * Get the title for this bookmark object. * - * @param title the bookmark title + * @return the bookmark title */ - public void setBookmarkTitle(String title) { - bookmarkTitle = title; + public String getBookmarkTitle() { + return bookmarkTitle; } /** - * Get the title for this bookmark object. + * Indicator of whether to initially display child bookmarks. * - * @return the bookmark title + * @return true to initially display child bookmarks, false otherwise */ - public String getBookmarkTitle() { - return bookmarkTitle; + public boolean showChildItems() { + return bShow; } /** @@ -204,8 +211,7 @@ public class BookmarkData extends OffDocumentItem implements Resolvable { * @return the new bookmark data */ private BookmarkData createBookmarkData(Bookmark bookmark) { - BookmarkData data = new BookmarkData(bookmark.getInternalDestination()); - data.setBookmarkTitle(bookmark.getBookmarkTitle()); + BookmarkData data = new BookmarkData(bookmark); for (int count = 0; count < bookmark.getChildBookmarks().size(); count++) { Bookmark bkmk = (Bookmark)(bookmark.getChildBookmarks()).get(count); data.addSubData(createBookmarkData(bkmk)); diff --git a/src/java/org/apache/fop/fo/pagination/bookmarks/Bookmark.java b/src/java/org/apache/fop/fo/pagination/bookmarks/Bookmark.java index 4a2587ec7..1c8ee70b6 100644 --- a/src/java/org/apache/fop/fo/pagination/bookmarks/Bookmark.java +++ b/src/java/org/apache/fop/fo/pagination/bookmarks/Bookmark.java @@ -42,7 +42,7 @@ public class Bookmark extends FObj { private CommonAccessibility commonAccessibility; private String internalDestination; private String externalDestination; - private int startingState; + private boolean bShow = true; // from starting-state property /** * Create a new bookmark object. @@ -60,7 +60,7 @@ public class Bookmark extends FObj { commonAccessibility = pList.getAccessibilityProps(); externalDestination = pList.get(PR_EXTERNAL_DESTINATION).getString(); internalDestination = pList.get(PR_INTERNAL_DESTINATION).getString(); - // startingState = pList.get(PR_STARTING_STATE); + bShow = (pList.get(PR_STARTING_STATE).getEnum() == EN_SHOW); // per spec, internal takes precedence if both specified if (internalDestination.length() > 0) { @@ -130,8 +130,14 @@ public class Bookmark extends FObj { return externalDestination; } - public int getStartingState() { - return startingState; + /** + * Determines if this fo:bookmark's subitems should be initially displayed + * or hidden, based on the starting-state property set on this FO. + * + * @return true if this bookmark's starting-state is "show", false if "hide". + */ + public boolean showChildItems() { + return bShow; } public ArrayList getChildBookmarks() { diff --git a/src/java/org/apache/fop/pdf/PDFDocument.java b/src/java/org/apache/fop/pdf/PDFDocument.java index 12960d6c3..4dd9f53fc 100644 --- a/src/java/org/apache/fop/pdf/PDFDocument.java +++ b/src/java/org/apache/fop/pdf/PDFDocument.java @@ -741,7 +741,7 @@ public class PDFDocument { return outlineRoot; } - outlineRoot = new PDFOutline(null, null); + outlineRoot = new PDFOutline(null, null, true); assignObjectNumber(outlineRoot); addTrailerObject(outlineRoot); root.setRootOutline(outlineRoot); diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java index 501b22a4a..28a14e8ef 100644 --- a/src/java/org/apache/fop/pdf/PDFFactory.java +++ b/src/java/org/apache/fop/pdf/PDFFactory.java @@ -897,13 +897,15 @@ public class PDFFactory { * @param label the title for the new outline object * @param destination the reference string for the action to go to * @param yoffset the yoffset on the destination page + * @param showSubItems whether to initially display child outline items * @return the new PDF outline object */ public PDFOutline makeOutline(PDFOutline parent, String label, - String destination, float yoffset) { - String goToRef = getGoToReference(destination, yoffset); + String destination, float yoffset, + boolean showSubItems) { - PDFOutline obj = new PDFOutline(label, goToRef); + String goToRef = getGoToReference(destination, yoffset); + PDFOutline obj = new PDFOutline(label, goToRef, showSubItems); if (parent != null) { parent.addOutline(obj); diff --git a/src/java/org/apache/fop/pdf/PDFOutline.java b/src/java/org/apache/fop/pdf/PDFOutline.java index d9e555b6e..3bba94a35 100644 --- a/src/java/org/apache/fop/pdf/PDFOutline.java +++ b/src/java/org/apache/fop/pdf/PDFOutline.java @@ -49,7 +49,10 @@ public class PDFOutline extends PDFObject { private PDFOutline last; private int count; - + + // whether to show this outline item's child outline items + private boolean openItem = false; + /** * title to display for the bookmark entry */ @@ -62,8 +65,9 @@ public class PDFOutline extends PDFObject { * * @param title the title of the outline entry (can only be null for root Outlines obj) * @param action the action for this outline + * @param openItem indicator of whether child items are visible or not */ - public PDFOutline(String title, String action) { + public PDFOutline(String title, String action, boolean openItem) { super(); subentries = new java.util.ArrayList(); count = 0; @@ -74,6 +78,7 @@ public class PDFOutline extends PDFObject { last = null; this.title = title; actionRef = action; + this.openItem = openItem; } /** @@ -136,30 +141,28 @@ public class PDFOutline extends PDFObject { // no count... we start with the outline completely closed for now } } else { - // subentry Outline object + // subentry Outline item object bout.write(encode(" /Title ")); bout.write(encodeText(this.title)); bout.write(encode("\n")); bout.write(encode(" /Parent " + parent.referencePDF() + "\n")); - if (first != null && last != null) { - bout.write(encode(" /First " + first.referencePDF() + "\n")); - bout.write(encode(" /Last " + last.referencePDF() + "\n")); - } if (prev != null) { bout.write(encode(" /Prev " + prev.referencePDF() + "\n")); } if (next != null) { bout.write(encode(" /Next " + next.referencePDF() + "\n")); } + if (first != null && last != null) { + bout.write(encode(" /First " + first.referencePDF() + "\n")); + bout.write(encode(" /Last " + last.referencePDF() + "\n")); + } if (count > 0) { - bout.write(encode(" /Count -" + count + "\n")); + bout.write(encode(" /Count " + (openItem ? "" : "-") + + count + "\n")); } - if (actionRef != null) { bout.write(encode(" /A " + actionRef + "\n")); } - - } bout.write(encode(">> endobj\n")); } catch (IOException ioe) { diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index f922ca0fb..223ebdd81 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -125,6 +125,7 @@ public class PDFRenderer extends PrintRenderer { * for pdf this means we need the pdf page reference */ protected Map pageReferences = new java.util.HashMap(); + /** Page viewport references */ protected Map pvReferences = new java.util.HashMap(); @@ -316,10 +317,14 @@ public class PDFRenderer extends PrintRenderer { if (parentBookmarkItem == null) { PDFOutline outlineRoot = pdfDoc.getOutlineRoot(); pdfOutline = pdfDoc.getFactory().makeOutline(outlineRoot, - bookmarkItem.getBookmarkTitle(), intDest, yoffset); + bookmarkItem.getBookmarkTitle(), + intDest, yoffset, + bookmarkItem.showChildItems()); } else { pdfOutline = pdfDoc.getFactory().makeOutline(parentBookmarkItem, - bookmarkItem.getBookmarkTitle(), intDest, yoffset); + bookmarkItem.getBookmarkTitle(), + intDest, yoffset, + bookmarkItem.showChildItems()); } } -- 2.39.5