Esempio n. 1
0
 @Override
 protected void processDrawnObject(
     HWPFDocument doc,
     CharacterRun characterRun,
     OfficeDrawing officeDrawing,
     String path,
     Element block) {
   Element img = htmlDocumentFacade.createImage(path);
   block.appendChild(img);
 }
Esempio n. 2
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);
  }