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

   *            - script type
   * @return the font definition for a specific script type
   */
  public Font getFont(ScriptType type) {
    // A font includes font family name, font style, font color, font size
    Font font = null;
    TextProperties textProperties = getTextPropertiesForRead();
    if (textProperties != null) {
      font = textProperties.getFont(type);
    } else {
      font = new Font(null, null, 0, (StyleTypeDefinitions.TextLinePosition) null);
    }

    if (font != null && font.getFamilyName() != null && font.getColor() != null && font.getSize() != 0
        && font.getFontStyle() != null && font.getTextLinePosition() != null) {
      return font;
    }

    boolean isDefault = isUseDefaultStyle;
    OdfStyleBase parentStyle = null;
    if (!isDefault) {
      parentStyle = getParentStyle((OdfStyle) getCurrentUsedStyle());
    }
    while ((!isDefault) && (parentStyle != null)) {
      TextProperties parentStyleSetting = TextProperties.getTextProperties(parentStyle);
      Font tempFont = parentStyleSetting.getFont(type);
      mergeFont(font, tempFont);
      if (font.getFamilyName() != null && font.getColor() != null && font.getSize() > 0
          && font.getFontStyle() != null && font.getTextLinePosition() != null) {
        return font;
      }
      // continue to get parent properties
      if (parentStyle instanceof OdfDefaultStyle) {
        isDefault = true;
      } else {
        parentStyle = getParentStyle((OdfStyle) parentStyle);
      }
    }
    if (!isDefault) {
      OdfDefaultStyle defaultStyle = getParagraphDefaultStyle();
      if (defaultStyle == null) {
        defaultStyle = getParagraphDefaultStyle();
      }
      if (defaultStyle != null) {
        TextProperties defaultStyleSetting = TextProperties.getTextProperties(defaultStyle);
        Font tempFont = defaultStyleSetting.getFont(type);
        mergeFont(font, tempFont);
      }
    }
    if (font.getColor() == null) {
      font.setColor(Color.BLACK);
View Full Code Here

   *            - script type
   * @return the font definition for a specific script type
   */
  public Font getFont(ScriptType type) {
    // A font includes font family name, font style, font color, font size
    Font font = null;
    TextProperties textProperties = getTextPropertiesForRead();
    if (textProperties != null)
      font = textProperties.getFont(type);
    else
      font = new Font(null, null, 0, (StyleTypeDefinitions.TextLinePosition) null);

    if (font != null && font.getFamilyName() != null && font.getColor() != null && font.getSize() != 0
        && font.getFontStyle() != null && font.getTextLinePosition() != null)
      return font;

    boolean isDefault = isUseDefaultStyle;
    OdfStyleBase parentStyle = null;
    if (!isDefault)
      parentStyle = getParentStyle((OdfStyle) getCurrentUsedStyle());
    while ((!isDefault) && (parentStyle != null)) {
      TextProperties parentStyleSetting = TextProperties.getTextProperties(parentStyle);
      Font tempFont = parentStyleSetting.getFont(type);
      mergeFont(font, tempFont);
      if (font.getFamilyName() != null && font.getColor() != null && font.getSize() > 0
          && font.getFontStyle() != null && font.getTextLinePosition() != null) {
        return font;
      }
      // continue to get parent properties
      if (parentStyle instanceof OdfDefaultStyle)
        isDefault = true;
      else
        parentStyle = getParentStyle((OdfStyle) parentStyle);
    }
    if (!isDefault) {
      OdfDefaultStyle defaultStyle = getCellDefaultStyle();
      // For text document, there is no default table cell style.
      // So use default font style in default paragraph style.
      if (defaultStyle == null) {
        defaultStyle = getParagraphDefaultStyle();
      }
      if (defaultStyle != null) {
        TextProperties defaultStyleSetting = TextProperties.getTextProperties(defaultStyle);
        Font tempFont = defaultStyleSetting.getFont(type);
        mergeFont(font, tempFont);
      }
    }

    if (font.getColor() == null)
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.