コード例 #1
0
ファイル: CSSBoxTree.java プロジェクト: winning1120xx/Pdf2Dom
 /**
  * Creates a new block box from the given element with the given parent. No style is assigned to
  * the resulting box.
  *
  * @param parent The parent box in the tree of boxes.
  * @param n The element that this box belongs to.
  * @param replaced When set to <code>true</code>, a replaced block box will be created. Otherwise,
  *     a normal non-replaced block will be created.
  * @return The new block box.
  */
 protected BlockBox createBlock(BlockBox parent, Element n, boolean replaced) {
   BlockBox root;
   if (replaced) {
     BlockReplacedBox rbox =
         new BlockReplacedBox(
             (Element) n,
             (Graphics2D) parent.getGraphics().create(),
             parent.getVisualContext().create());
     rbox.setViewport(viewport);
     rbox.setContentObj(
         new ReplacedImage(rbox, rbox.getVisualContext(), baseurl, n.getAttribute("src")));
     root = rbox;
   } else {
     root =
         new BlockBox(
             (Element) n,
             (Graphics2D) parent.getGraphics().create(),
             parent.getVisualContext().create());
     root.setViewport(viewport);
   }
   root.setBase(baseurl);
   root.setParent(parent);
   root.setContainingBlock(parent);
   root.setClipBlock(viewport);
   root.setOrder(next_order++);
   return root;
 }
コード例 #2
0
  private void buildBlockReplacedBox(List<ElementSpec> elements, BlockReplacedBox box) {
    // some content
    org.w3c.dom.Element elem = box.getElement();
    String text = "";
    // add some textual info, if picture
    if ("img".equalsIgnoreCase(elem.getTagName())) {
      text = " [" + elem.getAttribute("alt") + " Location: " + elem.getAttribute("src") + "] ";
    }

    MutableAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(SwingBoxDocument.ElementNameAttribute, Constants.BLOCK_REPLACED_BOX);
    attr.addAttribute(Constants.ATTRIBUTE_BOX_REFERENCE, box);
    attr.addAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE, new Anchor());
    attr.addAttribute(Constants.ATTRIBUTE_REPLACED_CONTENT, box.getContentObj());

    elements.add(
        new ElementSpec(attr, ElementSpec.ContentType, text.toCharArray(), 0, text.length()));
  }