Package org.odftoolkit.simple.style

Examples of org.odftoolkit.simple.style.Font


      SpreadsheetDocument document;
      document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table1 = document.getTableByName("Sheet1");
      Cell cell1 = table1.getCellByPosition("A1");
      cell1.setStringValue("abcdefg");
      Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
          StyleTypeDefinitions.TextLinePosition.THROUGH);
      cell1.setFont(font1);
      Font font11 = cell1.getFont();
      System.out.println(font11);
      if (!font11.equals(font1))
        Assert.fail();

      Cell cell2 = table1.getCellByPosition("A2");
      cell2.setStringValue("redstring");
      Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
          StyleTypeDefinitions.TextLinePosition.UNDER);
      cell2.setFont(font2);
      Font font22 = cell2.getFont();
      System.out.println(font22);
      if (!font22.equals(font2))
        Assert.fail();
      document.save(ResourceUtilities.newTestOutputFile("TestSetGetFont.ods"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
View Full Code Here


    }
  }

  @Test
  public void testCellSizeOptimal() {
    Font font1Base = new Font("Arial", FontStyle.REGULAR, 6, Color.GREEN, TextLinePosition.REGULAR);
    Font font2Base = new Font("Times New Roman", FontStyle.REGULAR, 13, Color.RED, TextLinePosition.REGULAR);
    Font font3Base = new Font("SimSun", FontStyle.REGULAR, 17, Color.BLUE, TextLinePosition.REGULAR);
    try {
      final SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      final Table table = doc.addTable();
      final String contentStr = "This is a long text content.";
     
      // basically the default font is of Arial type, so assume the default family
      final String nfFamilyName = "Arial";
     
      if (isFontAvailable(nfFamilyName)) {
        checkCellWidth(table.getCellByPosition(0, 0), null, 44.0977, contentStr);
      }
      if (isFontAvailable(font1Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(1, 1), font1Base, 24.3424, contentStr);
      }
      if (isFontAvailable(font2Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(2, 2), font2Base, 49.7414, contentStr);
      }
      if (isFontAvailable(font3Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(3, 3), font3Base, 88.899, contentStr);
      }
      doc.save(ResourceUtilities.newTestOutputFile("testCellSizeOptimal.ods"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, e);
View Full Code Here

  //column can fit the width to the text, if column.isOptimalWidth() is true.
  //since 0.5.5
  private void optimizeCellSize(String content){
    JTextField txtField = new JTextField();
    // map font to awt font
    Font font = getFont();
    String fontFamilyName = font.getFamilyName();
    if (fontFamilyName == null) {
      fontFamilyName = "Times New Roman";
    }
    int fontStyleNum = java.awt.Font.PLAIN;
    FontStyle fontStyle = font.getFontStyle();
    if (fontStyle != null) {
      switch (fontStyle) {
      case BOLD:
        fontStyleNum = java.awt.Font.BOLD;
        break;
      case REGULAR:
        fontStyleNum = java.awt.Font.PLAIN;
        break;
      case ITALIC:
        fontStyleNum = java.awt.Font.ITALIC;
        break;
      case BOLDITALIC:
        fontStyleNum = java.awt.Font.BOLD | java.awt.Font.ITALIC;
        break;
      default:
        fontStyleNum = java.awt.Font.PLAIN;
      }
    }
    double fontSize = font.getSize();
    if (fontSize < 0.0001) {
      fontSize = 10;
    }
    txtField.setFont(new java.awt.Font(fontFamilyName, fontStyleNum, (int)fontSize));
    FontMetrics fm = txtField.getFontMetrics(txtField.getFont());
View Full Code Here

  @Test
  public void testSetGetFont() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph1 = doc.addParagraph("paragraph1");
      Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
          StyleTypeDefinitions.TextLinePosition.THROUGH);
      paragraph1.setFont(font1);
      Font font11 = paragraph1.getFont();
      LOGGER.info(font11.toString());
      if (!font11.equals(font1)) {
        Assert.fail();
      }

      Paragraph paragraph2 = doc.addParagraph("paragraph2");
      Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
          StyleTypeDefinitions.TextLinePosition.UNDER);
      paragraph2.setFont(font2);
      Font font22 = paragraph2.getFont();
      LOGGER.info(font22.toString());
      if (!font22.equals(font2)) {
        Assert.fail();
      }

      Paragraph paragraph3 = doc.addParagraph("paragraph3");
      Font font3 = paragraph3.getFont();
      LOGGER.info(font3.toString());
      font3.setColor(Color.GREEN);
      font3.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD);
      paragraph3.setFont(font3);
      LOGGER.info(font3.toString());
      Font font33 = paragraph3.getFont();
      if (!font33.equals(font3)) {
        Assert.fail();
      }
      doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetFont.odt"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

  //column can fit the width to the text, if column.isOptimalWidth() is true.
  //since 0.5.5
  private void optimizeCellSize(String content){
    JTextField txtField = new JTextField();
    // map font to awt font
    Font font = getFont();
    String fontFamilyName = font.getFamilyName();
    if (fontFamilyName == null) {
      fontFamilyName = "Times New Roman";
    }
    int fontStyleNum = java.awt.Font.PLAIN;
    FontStyle fontStyle = font.getFontStyle();
    if (fontStyle != null) {
      switch (fontStyle) {
      case BOLD:
        fontStyleNum = java.awt.Font.BOLD;
        break;
      case REGULAR:
        fontStyleNum = java.awt.Font.PLAIN;
        break;
      case ITALIC:
        fontStyleNum = java.awt.Font.ITALIC;
        break;
      case BOLDITALIC:
        fontStyleNum = java.awt.Font.BOLD | java.awt.Font.ITALIC;
        break;
      default:
        fontStyleNum = java.awt.Font.PLAIN;
      }
    }
    double fontSize = font.getSize();
    if (fontSize < 0.0001) {
      fontSize = 10;
    }
    txtField.setFont(new java.awt.Font(fontFamilyName, fontStyleNum, (int)fontSize));
    FontMetrics fm = txtField.getFontMetrics(txtField.getFont());
View Full Code Here

      SpreadsheetDocument document;
      document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table1 = document.getTableByName("Sheet1");
      Cell cell1 = table1.getCellByPosition("A1");
      cell1.setStringValue("abcdefg");
      Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
          StyleTypeDefinitions.TextLinePosition.THROUGH);
      cell1.setFont(font1);
      Font font11 = cell1.getFont();
      System.out.println(font11);
      if (!font11.equals(font1))
        Assert.fail();

      Cell cell2 = table1.getCellByPosition("A2");
      cell2.setStringValue("redstring");
      Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
          StyleTypeDefinitions.TextLinePosition.UNDER);
      cell2.setFont(font2);
      Font font22 = cell2.getFont();
      System.out.println(font22);
      if (!font22.equals(font2))
        Assert.fail();
      document.save(ResourceUtilities.newTestOutputFile("TestSetGetFont.ods"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
View Full Code Here

    }
  }

  @Test
  public void testCellSizeOptimal() {
    Font font1Base = new Font("Arial", FontStyle.REGULAR, 6, Color.GREEN, TextLinePosition.REGULAR);
    Font font2Base = new Font("Times New Roman", FontStyle.REGULAR, 13, Color.RED, TextLinePosition.REGULAR);
    Font font3Base = new Font("SimSun", FontStyle.REGULAR, 17, Color.BLUE, TextLinePosition.REGULAR);
    try {
      final SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
      final Table table = doc.addTable();
      final String contentStr = "This is a long text content.";
     
      // basically the default font is of Arial type, so assume the default family
      final String nfFamilyName = "Arial";
     
      if (isFontAvailable(nfFamilyName)) {
        checkCellWidth(table.getCellByPosition(0, 0), null, 44.0977, contentStr);
      }
      if (isFontAvailable(font1Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(1, 1), font1Base, 24.3424, contentStr);
      }
      if (isFontAvailable(font2Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(2, 2), font2Base, 49.7414, contentStr);
      }
      if (isFontAvailable(font3Base.getFamilyName())) {
        checkCellWidth(table.getCellByPosition(3, 3), font3Base, 88.899, contentStr);
      }
      doc.save(ResourceUtilities.newTestOutputFile("testCellSizeOptimal.ods"));
    } catch (Exception e) {
      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, e);
View Full Code Here

      TextNavigation navigation = new TextNavigation("test", doc);
      TextSelection sel = (TextSelection) navigation.nextSelection();
      Span span = Span.newSpan(sel);
      TextHyperlink link = span.applyHyperlink(new URI("http://www.ibm.com"));
      DefaultStyleHandler handler = span.getStyleHandler();
      Font font1Base = new Font("Arial", FontStyle.ITALIC, 10, Color.BLACK, TextLinePosition.THROUGH);
      handler.getTextPropertiesForWrite().setFont(font1Base);
      doc.save(ResourceUtilities.newTestOutputFile("spantest.odt"));

      String content = span.getTextContent();
      Assert.assertEquals("test", content);
View Full Code Here

    try {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph = doc.addParagraph("paragraphTest");
      ParagraphStyleHandler paragraphHandler = paragraph.getStyleHandler();
     
      Font fontBase = new Font("Arial", FontStyle.ITALIC, 10, Color.BLACK, TextLinePosition.THROUGH);
      paragraphHandler.setFont(fontBase);
      //validate
      Font font = paragraphHandler.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(fontBase, font);
     
      paragraphHandler.setFont(fontBase, Locale.CHINESE);
      //validate
      Font font1 = paragraphHandler.getFont(Document.ScriptType.WESTERN);
      Assert.assertEquals(fontBase, font1);
     
      //save
      //doc.save(ResourceUtilities.newTestOutputFile("testParagraphStyleHandler.odt"));
    } catch (Exception e) {
View Full Code Here

  @Test
  public void testSetGetFont() {
    try {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph1 = doc.addParagraph("paragraph1");
      Font font1 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK,
          StyleTypeDefinitions.TextLinePosition.THROUGH);
      paragraph1.setFont(font1);
      Font font11 = paragraph1.getFont();
      LOGGER.info(font11.toString());
      if (!font11.equals(font1)) {
        Assert.fail();
      }

      Paragraph paragraph2 = doc.addParagraph("paragraph2");
      Font font2 = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.RED,
          StyleTypeDefinitions.TextLinePosition.UNDER);
      paragraph2.setFont(font2);
      Font font22 = paragraph2.getFont();
      LOGGER.info(font22.toString());
      if (!font22.equals(font2)) {
        Assert.fail();
      }

      Paragraph paragraph3 = doc.addParagraph("paragraph3");
      Font font3 = paragraph3.getFont();
      LOGGER.info(font3.toString());
      font3.setColor(Color.GREEN);
      font3.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD);
      paragraph3.setFont(font3);
      LOGGER.info(font3.toString());
      Font font33 = paragraph3.getFont();
      if (!font33.equals(font3)) {
        Assert.fail();
      }
      doc.save(ResourceUtilities.newTestOutputFile("TestParagraphSetGetFont.odt"));
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
View Full Code Here

TOP

Related Classes of org.odftoolkit.simple.style.Font

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.