예제 #1
0
  /** 加入图片 */
  protected void processImage(Element parent, CharacterRun cr) {
    if (this.picstab.hasPicture(cr)) {
      Picture pic = picstab.extractPicture(cr, false);

      String fileName = pic.suggestFullFileName();
      OutputStream out = null;
      try {

        //					TWIPS_PER_INCH/
        out = new FileOutputStream(new File(output.concat(File.separator).concat(fileName)));
        pic.writeImageContent(out);
        Element img = htmlDocumentFacade.getDocument().createElement("img");
        String uri = fileName.concat("image").concat(File.separator).concat(fileName);
        img.setAttribute("src", uri);
        if (pic.getWidth() > 600) img.setAttribute("style", "width: 600px;");
        Element imgBlock = htmlDocumentFacade.createBlock();
        this.htmlDocumentFacade.addStyleClass(imgBlock, "imgs", "text-align:center;");
        imgBlock.appendChild(img);
        parent.appendChild(imgBlock);

      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (out != null)
          try {
            out.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
      }
    }
  } // 图片END
예제 #2
0
 @Override
 protected void processImageWithoutPicturesManager(
     Element currentBlock, boolean inlined, Picture picture) {
   // no default implementation -- skip
   currentBlock.appendChild(
       htmlDocumentFacade.document.createComment(
           "Image link to '" + picture.suggestFullFileName() + "' can be here"));
 }
예제 #3
0
  @SuppressWarnings("deprecation")
  protected void processImage(
      Element currentBlock, boolean inlined, Picture picture, String imageSourcePath) {
    final int aspectRatioX = picture.getHorizontalScalingFactor();
    final int aspectRatioY = picture.getVerticalScalingFactor();

    StringBuilder style = new StringBuilder();

    final float imageWidth;
    final float imageHeight;

    final float cropTop;
    final float cropBottom;
    final float cropLeft;
    final float cropRight;

    if (aspectRatioX > 0) {
      imageWidth = picture.getDxaGoal() * aspectRatioX / 1000 / TWIPS_PER_INCH;
      cropRight = picture.getDxaCropRight() * aspectRatioX / 1000 / TWIPS_PER_INCH;
      cropLeft = picture.getDxaCropLeft() * aspectRatioX / 1000 / TWIPS_PER_INCH;
    } else {
      imageWidth = picture.getDxaGoal() / TWIPS_PER_INCH;
      cropRight = picture.getDxaCropRight() / TWIPS_PER_INCH;
      cropLeft = picture.getDxaCropLeft() / TWIPS_PER_INCH;
    }

    if (aspectRatioY > 0) {
      imageHeight = picture.getDyaGoal() * aspectRatioY / 1000 / TWIPS_PER_INCH;
      cropTop = picture.getDyaCropTop() * aspectRatioY / 1000 / TWIPS_PER_INCH;
      cropBottom = picture.getDyaCropBottom() * aspectRatioY / 1000 / TWIPS_PER_INCH;
    } else {
      imageHeight = picture.getDyaGoal() / TWIPS_PER_INCH;
      cropTop = picture.getDyaCropTop() / TWIPS_PER_INCH;
      cropBottom = picture.getDyaCropBottom() / TWIPS_PER_INCH;
    }

    Element root;
    if (cropTop != 0 || cropRight != 0 || cropBottom != 0 || cropLeft != 0) {
      float visibleWidth = Math.max(0, imageWidth - cropLeft - cropRight);
      float visibleHeight = Math.max(0, imageHeight - cropTop - cropBottom);

      root = htmlDocumentFacade.createBlock();
      htmlDocumentFacade.addStyleClass(
          root,
          "d",
          "vertical-align:text-bottom;width:"
              + visibleWidth
              + "in;height:"
              + visibleHeight
              + "in;");

      // complex
      Element inner = htmlDocumentFacade.createBlock();
      htmlDocumentFacade.addStyleClass(
          inner,
          "d",
          "position:relative;width:"
              + visibleWidth
              + "in;height:"
              + visibleHeight
              + "in;overflow:hidden;");
      root.appendChild(inner);

      Element image = htmlDocumentFacade.createImage(imageSourcePath);
      htmlDocumentFacade.addStyleClass(
          image,
          "i",
          "position:absolute;left:-"
              + cropLeft
              + ";top:-"
              + cropTop
              + ";width:"
              + imageWidth
              + "in;height:"
              + imageHeight
              + "in;");
      inner.appendChild(image);

      style.append("overflow:hidden;");
    } else {
      root = htmlDocumentFacade.createImage(imageSourcePath);
      root.setAttribute(
          "style",
          "width:" + imageWidth + "in;height:" + imageHeight + "in;vertical-align:text-bottom;");
    }

    currentBlock.appendChild(root);
  }