1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /* $Id: PDFParentTree.java 1411352 2012-11-19 18:53:11Z vhennebert $ */ 19 20 package org.apache.fop.pdf; 21 22 /** 23 * Class representing a PDF /ParentTree. 24 */ 25 public class PDFParentTree extends PDFNumberTreeNode { 26 27 private static final int MAX_NUMS_ARRAY_SIZE = 50; 28 PDFParentTree()29 public PDFParentTree() { 30 put("Kids", new PDFArray()); 31 } 32 33 @Override addToNums(int num, Object object)34 public void addToNums(int num, Object object) { 35 int arrayIndex = num / MAX_NUMS_ARRAY_SIZE; 36 setNumOfKidsArrays(arrayIndex + 1); 37 insertItemToNumsArray(arrayIndex, num, object); 38 } 39 setNumOfKidsArrays(int numKids)40 private void setNumOfKidsArrays(int numKids) { 41 for (int i = getKids().length(); i < numKids; i++) { 42 PDFNumberTreeNode newArray = new PDFNumberTreeNode(); 43 newArray.setNums(new PDFNumsArray(newArray)); 44 newArray.setLowerLimit(i * MAX_NUMS_ARRAY_SIZE); 45 newArray.setUpperLimit(i * MAX_NUMS_ARRAY_SIZE); 46 addKid(newArray); 47 } 48 } 49 50 /** 51 * Registers a child object and adds it to the Kids array. 52 * @param kid The child PDF object to be added 53 */ addKid(PDFObject kid)54 private void addKid(PDFObject kid) { 55 assert getDocument() != null; 56 getDocument().assignObjectNumber(kid); 57 getDocument().addTrailerObject(kid); 58 ((PDFArray) get("Kids")).add(kid); 59 } 60 insertItemToNumsArray(int array, int num, Object object)61 private void insertItemToNumsArray(int array, int num, Object object) { 62 assert getKids().get(array) instanceof PDFNumberTreeNode; 63 PDFNumberTreeNode numsArray = (PDFNumberTreeNode) getKids().get(array); 64 numsArray.addToNums(num, object); 65 } 66 } 67 68 69 70 71