Examples of OdfDrawFrame


Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

   * @return         Returns the internal package path of the image, which was created based on the given URI.
   * */
  public String newImage(URI imageUri) {
    try {
      OdfContentDom contentDom = this.getContentDom();
      OdfDrawFrame drawFrame = contentDom.newOdfElement(OdfDrawFrame.class);
      XPath xpath = contentDom.getXPath();
      if (this instanceof OdfSpreadsheetDocument) {
        TableTableCellElement lastCell = (TableTableCellElement) xpath.evaluate("//table:table-cell[last()]", contentDom, XPathConstants.NODE);
        lastCell.appendChild(drawFrame);
        drawFrame.removeAttribute("text:anchor-type");

      } else if (this instanceof OdfTextDocument) {
        TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
        if (lastPara == null) {
          lastPara = ((OdfTextDocument) this).newParagraph();
        }
        lastPara.appendChild(drawFrame);
        drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
      } else if (this instanceof OdfPresentationDocument) {
        DrawPageElement lastPage = (DrawPageElement) xpath.evaluate("//draw:page[last()]", contentDom, XPathConstants.NODE);
        lastPage.appendChild(drawFrame);
      }
      OdfDrawImage image = (OdfDrawImage) drawFrame.newDrawImageElement();
      String imagePath = image.newImage(imageUri);
      return imagePath;
    } catch (Exception ex) {
      Logger.getLogger(OdfDocument.class.getName()).log(Level.SEVERE, null, ex);
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

  @Test
  public void testPresentationClassAttribute() {
    try {
      GraphicsDocument doc = GraphicsDocument.newGraphicsDocument();
      OdfFileDom dom = doc.getContentDom();
      OdfDrawFrame f = new OdfDrawFrame(dom);

      f.setPresentationClassAttribute(PresentationClassAttribute.Value.GRAPHIC.toString());
      Logger.getLogger(DocumentCreationTest.class.getName()).info(f.getPresentationClassAttribute());
    } catch (Exception e) {
      Logger.getLogger(PresentationTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
    }
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

      // FUTURE USAGE:
      // para.createDrawFrame().createDrawImage("/myweb.org/images/myHoliday.png",
      // "/Pictures/myHoliday.png");
      // Child access methods are still not part of the v0.6.x releases
      // CURRENT USAGE:
      OdfDrawFrame odfFrame = (OdfDrawFrame) OdfXMLFactory.newOdfElement(odfContent,
          DrawFrameElement.ELEMENT_NAME);
      para.appendChild(odfFrame);
      OdfDrawImage odfImage = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
      odfFrame.appendChild(odfImage);
      odfImage.newImage(ResourceUtilities.getURI(TEST_PIC));

      OdfDrawImage odfImage2 = (OdfDrawImage) OdfXMLFactory.newOdfElement(odfContent, OdfDrawImage.ELEMENT_NAME);
      odfFrame.appendChild(odfImage2);
      // Deactivated as test fail, when test machine is not online
      // (painful for offline work)
      // odfImage2.newImage(new
      // URI("http://odftoolkit.org/attachments/wiki_images/odftoolkit/Table_fruits_diagramm.jpg"));
      odfDoc.save(ResourceUtilities.newTestOutputFile("simple-wiki-dom.odt"));
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

  @Test
  public void testInsertImage_URI() throws Exception {
    LOG.info("insertImage from URI");
    OdfTextDocument odt = OdfTextDocument.newTextDocument();
    OdfTextParagraph para = (OdfTextParagraph) odt.getContentRoot().newTextPElement();
    OdfDrawFrame frame = (OdfDrawFrame) para.newDrawFrameElement();
    OdfDrawImage image = (OdfDrawImage) frame.newDrawImageElement();
    String packagePath = image.newImage(ResourceUtilities.getURI("testA.jpg"));
    assertEquals(image.getXlinkTypeAttribute(), "simple");
    LOG.info(frame.getSvgWidthAttribute());
    LOG.info(frame.getSvgHeightAttribute());
    assert (frame.getSvgWidthAttribute().startsWith("19.") && frame.getSvgWidthAttribute().endsWith("cm"));
    assert (frame.getSvgHeightAttribute().startsWith("6.") && frame.getSvgHeightAttribute().endsWith("cm"));
    assertEquals(odt.getPackage().getFileEntry(packagePath).getMediaTypeString(), "image/jpeg");
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

  @Test
  public void testInsertImage_InputStream() throws Exception {
    LOG.info("insertImage from InputStream");
    OdfTextDocument odt = OdfTextDocument.newTextDocument();
    OdfTextParagraph para = (OdfTextParagraph) odt.getContentRoot().newTextPElement();
    OdfDrawFrame frame = (OdfDrawFrame) para.newDrawFrameElement();
    OdfDrawImage image = (OdfDrawImage) frame.newDrawImageElement();
    String packagePath = "Pictures/myChosenImageName.jpg";
    String mediaType = "image/jpeg";
    image.newImage(new FileInputStream(ResourceUtilities.getAbsolutePath("testA.jpg")), packagePath, mediaType);
    assertEquals(image.getXlinkTypeAttribute(), "simple");
    assert (frame.getSvgWidthAttribute().startsWith("19.") && frame.getSvgWidthAttribute().endsWith("cm"));
    assert (frame.getSvgHeightAttribute().startsWith("6.") && frame.getSvgHeightAttribute().endsWith("cm"));
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

   *         based on the given URI.
   * */
  public String newImage(URI imageUri) {
    try {
      OdfContentDom contentDom = this.getContentDom();
      OdfDrawFrame drawFrame = contentDom.newOdfElement(OdfDrawFrame.class);
      XPath xpath = contentDom.getXPath();
      if (this instanceof SpreadsheetDocument) {
        TableTableCellElement lastCell = (TableTableCellElement) xpath.evaluate("//table:table-cell[last()]", contentDom, XPathConstants.NODE);
        lastCell.appendChild(drawFrame);
        drawFrame.removeAttribute("text:anchor-type");

      } else if (this instanceof TextDocument) {
        TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
        if (lastPara == null) {
          lastPara = ((TextDocument) this).newParagraph();
        }
        lastPara.appendChild(drawFrame);
        drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
      } else if (this instanceof PresentationDocument) {
        DrawPageElement lastPage = (DrawPageElement) xpath.evaluate("//draw:page[last()]", contentDom, XPathConstants.NODE);
        lastPage.appendChild(drawFrame);
      }
      OdfDrawImage image = (OdfDrawImage) drawFrame.newDrawImageElement();
      String imagePath = image.newImage(imageUri);
      return imagePath;
    } catch (Exception ex) {
      Logger.getLogger(Document.class.getName()).log(Level.SEVERE, null, ex);
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

      OdfTextDocument doc = OdfTextDocument.newTextDocument();
      String imagePath1 = doc.newImage(ResourceUtilities.getURI("testA.jpg"));
      Assert.assertTrue(getImageCount(doc) == 1);
      OdfDrawImage image = getImageByPath(doc, imagePath1).get(0);
      Assert.assertTrue(image.getImageUri().toString().equals(imagePath1));
      OdfDrawFrame frame1 = (OdfDrawFrame) image.getParentNode();
      frame1.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PAGE.toString());
      frame1.setTextAnchorPageNumberAttribute(1);

      //add paragraph
      OfficeTextElement office = doc.getContentRoot();
      OdfTextParagraph para1 = (OdfTextParagraph) office.newTextPElement();
      para1.setTextContent("insert an image here");
      String imagePath2 = doc.newImage(mImageUri_ODFDOM);

      OdfTextParagraph para2 = (OdfTextParagraph) office.newTextPElement();
      para2.setTextContent("another");
      String imagePath3 = doc.newImage(mImageUri_ODFDOM);
      OdfDrawImage image3 = getImageByPath(doc, imagePath3).get(1);
      OdfDrawFrame frame3 = (OdfDrawFrame) image3.getParentNode();
      frame3.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.CHAR.toString());

      doc.save(ResourceUtilities.newTestOutputFile("addimages.odt"));

      //load the file again
      OdfTextDocument doc1 = (OdfTextDocument) OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("addimages.odt"));
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

      OdfTextDocument doc = OdfTextDocument.newTextDocument();
      String imagePath1 = doc.newImage(ResourceUtilities.getURI("simple.svg"));
      Assert.assertTrue(getImageCount(doc) == 1);
      OdfDrawImage image = getImageByPath(doc, imagePath1).get(0);
      Assert.assertTrue(image.getImageUri().toString().equals(imagePath1));
      OdfDrawFrame frame1 = (OdfDrawFrame) image.getParentNode();
      frame1.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PAGE.toString());
      frame1.setTextAnchorPageNumberAttribute(1);

      doc.save(ResourceUtilities.newTestOutputFile("svg-image.odt"));

      //load the file again
      OdfTextDocument doc1 = (OdfTextDocument) OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("svg-image.odt"));
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
    }
  }

  private void addFrameForEmbeddedDoc(OdfFileDom dom, TextPElement para, String path) throws Exception {
    OdfDrawFrame drawFrame = new OdfDrawFrame(dom);
    drawFrame.setDrawNameAttribute(path);
    drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
    drawFrame.setSvgXAttribute("0.834cm");
    drawFrame.setSvgYAttribute("2.919cm");
    drawFrame.setSvgWidthAttribute("13.257cm");
    drawFrame.setSvgHeightAttribute("11.375cm");
    drawFrame.setDrawZIndexAttribute(0);

    DrawObjectElement object = new DrawObjectElement(dom);

    object.setXlinkHrefAttribute(path);
    object.setXlinkActuateAttribute("onLoad");
    object.setXlinkShowAttribute("embed");
    object.setXlinkTypeAttribute("simple");
    drawFrame.appendChild(object);
    para.appendChild(drawFrame);
  }
View Full Code Here

Examples of org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawFrame

   * @return         Returns the internal package path of the image, which was created based on the given URI.
   * */
  public String newImage(URI imageUri) {
    try {
      OdfContentDom contentDom = this.getContentDom();
      OdfDrawFrame drawFrame = contentDom.newOdfElement(OdfDrawFrame.class);
      XPath xpath = contentDom.getXPath();
      if (this instanceof OdfSpreadsheetDocument) {
        TableTableCellElement lastCell = (TableTableCellElement) xpath.evaluate("//table:table-cell[last()]", contentDom, XPathConstants.NODE);
        lastCell.appendChild(drawFrame);
        drawFrame.removeAttribute("text:anchor-type");

      } else if (this instanceof OdfTextDocument) {
        TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
        if (lastPara == null) {
          lastPara = ((OdfTextDocument) this).newParagraph();
        }
        lastPara.appendChild(drawFrame);
        drawFrame.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PARAGRAPH.toString());
      } else if (this instanceof OdfPresentationDocument) {
        DrawPageElement lastPage = (DrawPageElement) xpath.evaluate("//draw:page[last()]", contentDom, XPathConstants.NODE);
        lastPage.appendChild(drawFrame);
      }
      OdfDrawImage image = (OdfDrawImage) drawFrame.newDrawImageElement();
      String imagePath = image.newImage(imageUri);
      return imagePath;
    } catch (Exception ex) {
      Logger.getLogger(OdfDocument.class.getName()).log(Level.SEVERE, null, ex);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.