Package org.pdfclown.objects

Examples of org.pdfclown.objects.PdfDictionary


      inside a B-tree. To keep it as efficient as possible, this implementation
      does NOT adopt recursion to deepen its search, opting for an iterative strategy
      instead.
    */
    int pageOffset = 0;
    PdfDictionary parent = getBaseDataObject();
    PdfArray kids = (PdfArray)File.resolve(parent.get(PdfName.Kids));
    for(
      int i = 0;
      i < kids.size();
      i++
      )
    {
      PdfReference kidReference = (PdfReference)kids.get(i);
      PdfDictionary kid = (PdfDictionary)File.resolve(kidReference);
      // Is current kid a page object?
      if(kid.get(PdfName.Type).equals(PdfName.Page)) // Page object.
      {
        // Did we reach the searched position?
        if(pageOffset == index) // Vertical scan (we finished).
        {
          // We got it!
          return Page.wrap(kidReference);
        }
        else // Horizontal scan (go past).
        {
          // Cumulate current page object count!
          pageOffset++;
        }
      }
      else // Page tree node.
      {
        // Does the current subtree contain the searched page?
        if(((PdfInteger)kid.get(PdfName.Count)).getRawValue() + pageOffset > index) // Vertical scan (deepen the search).
        {
          // Go down one level!
          parent = kid;
          kids = (PdfArray)File.resolve(parent.get(PdfName.Kids));
          i = -1;
        }
        else // Horizontal scan (go past).
        {
          // Cumulate current subtree count!
          pageOffset += ((PdfInteger)kid.get(PdfName.Count)).getRawValue();
        }
      }
    }
    return null;
  }
View Full Code Here


  public boolean remove(
    Object page
    )
  {
    Page pageObj = (Page)page;
    PdfDictionary pageData = pageObj.getBaseDataObject();
    // Get the parent tree node!
    PdfDirectObject parent = pageData.get(PdfName.Parent);
    PdfDictionary parentData = (PdfDictionary)File.resolve(parent);
    // Get the parent's page collection!
    PdfDirectObject kids = parentData.get(PdfName.Kids);
    PdfArray kidsData = (PdfArray)File.resolve(kids);
    // Remove the page!
    kidsData.remove(pageObj.getBaseObject());
    boolean updateParent = !File.update(kids); // Try to update the page collection.
    // Unbind the page from its parent!
    pageData.put(PdfName.Parent,null);
    pageObj.update();
    // Decrementing the pages counters...
    do
    {
      // Get the page collection counter!
      PdfDirectObject count = parentData.get(PdfName.Count);
      PdfNumber<?> countData = (PdfNumber<?>)File.resolve(count);
      // Decrement the counter at the current level!
      countData.setValue(countData.getNumberValue()-1);
      updateParent |= !File.update(count); // Try to update the counter.
      // Is the parent tree node to be updated?
      /*
        NOTE: It avoids to update the parent tree node if its modified fields are all
        indirect objects which perform independent updates.
      */
      if(updateParent)
      {
        File.update(parent);
        updateParent = false; // Reset.
      }

      // Iterate upward!
      parent = parentData.get(PdfName.Parent);
      parentData = (PdfDictionary)File.resolve(parent);
    } while(parent != null);

    return true;
  }
View Full Code Here

            kids = (PdfArray)File.resolve(parent.get(PdfName.Kids));
          }
          else // Page subtree incomplete.
          {
            PdfReference kidReference = (PdfReference)kids.get(levelIndex);
            PdfDictionary kid = (PdfDictionary)File.resolve(kidReference);
            // Is current kid a page object?
            if(kid.get(PdfName.Type).equals(PdfName.Page)) // Page object.
            {
              // 2. Page found.
              index++; // Absolute page index.
              levelIndex++; // Current level node index.
View Full Code Here

    int index,
    Collection<? extends Page> pages
    )
  {
    PdfDirectObject parent;
    PdfDictionary parentData;
    PdfDirectObject kids;
    PdfArray kidsData;
    int offset;
    // Append operation?
    if(index == -1) // Append operation.
    {
      // Get the parent tree node!
      parent = getBaseObject();
      parentData = getBaseDataObject();
      // Get the parent's page collection!
      kids = parentData.get(PdfName.Kids);
      kidsData = (PdfArray)File.resolve(kids);
      offset = 0; // Not used.
    }
    else // Insert operation.
    {
      // Get the page currently at the specified position!
      Page pivotPage = get(index);
      // Get the parent tree node!
      parent = pivotPage.getBaseDataObject().get(PdfName.Parent);
      parentData = (PdfDictionary)File.resolve(parent);
      // Get the parent's page collection!
      kids = parentData.get(PdfName.Kids);
      kidsData = (PdfArray)File.resolve(kids);
      // Get the insertion's relative position within the parent's page collection!
      offset = kidsData.indexOf(pivotPage.getBaseObject());
    }

    // Adding the pages...
    for(Page page : pages)
    {
      // Append?
      if(index == -1) // Append.
      {
        // Append the page to the collection!
        kidsData.add(page.getBaseObject());
      }
      else // Insert.
      {
        // Insert the page into the collection!
        kidsData.add(
          offset++,
          page.getBaseObject()
          );
      }
      // Bind the page to the collection!
      page.getBaseDataObject().put(PdfName.Parent,parent);
      page.update();
    }
    boolean updateParent = !File.update(kids); // Try to update the page collection.

    // Incrementing the pages counters...
    do
    {
      // Get the page collection counter!
      PdfDirectObject count = parentData.get(PdfName.Count);
      PdfInteger countData = (PdfInteger)File.resolve(count);
      // Increment the counter at the current level!
      countData.setValue(countData.getValue()+pages.size());
      updateParent |= !File.update(count); // Try to update the page counter.
      // Is the parent tree node to be updated?
      /*
        NOTE: It avoids to update the parent tree node if its modified fields are all
        indirect objects which perform independent updates.
      */
      if(updateParent)
      {
        File.update(parent);
        updateParent = false; // Reset.
      }

      // Iterate upward!
      parent = parentData.get(PdfName.Parent);
      parentData = (PdfDictionary)File.resolve(parent);
    } while(parent != null);

    return true;
  }
View Full Code Here

  // <dynamic>
  // <constructors>
  public Resources(
    Document context
    )
  {super(context.getFile(), new PdfDictionary());}
View Full Code Here

    )
  {
    super(
      context.getFile(),
      new PdfStream(
        new PdfDictionary(
          new PdfName[]{PdfName.Type},
          new PdfDirectObject[]{PdfName.Sound}
          )
        )
      );
View Full Code Here

    FileSpec fileSpec
    )
  {
    super(
      context.getFile(),
      new PdfDictionary()
      );

    setFileSpec(fileSpec);
  }
View Full Code Here

  {
    if(baseObject == null)
      return null;

    PdfDataObject dataObject = File.resolve(baseObject);
    PdfDictionary dictionary = getDictionary(dataObject);
    int patternType = ((PdfInteger)dictionary.get(PdfName.PatternType)).getRawValue();
    switch(patternType)
    {
      case PatternType1:
        return new TilingPattern(baseObject, container);
      case PatternType2:
View Full Code Here

  // <dynamic>
  // <constructors>
  protected ResourceItems(
    Document context
    )
  {super(context.getFile(), new PdfDictionary());}
View Full Code Here

    Document context
    )
  {
    super(
      context.getFile(),
      new PdfDictionary()
      );
  }
View Full Code Here

TOP

Related Classes of org.pdfclown.objects.PdfDictionary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.