Uploaded image for project: 'ODF Toolkit'
  1. ODF Toolkit
  2. ODFTOOLKIT-417

Missing methods for set and get background-color, subscripted and superscripted for a paragraph

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.6.2-incubating
    • 0.6.2-incubating
    • simple api
    • None

    Description

      in File:
      http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/ParagraphProperties.java

      are missing the methods:

      public void setBackgroundColor(Color bkColor);
      public String getBackgroundColorAttribute();

      in the File:
      http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/TextProperties.java

      are missing the methods:

      public void setSubscripted(Integer fontsizePercent);
      public void setSuperscripted(Integer fontsizePercent);
      public Integer getSubscripted();
      public Integer getSuperscripted();

      We suggest the following code:

      simple/src/main/java/org/odftoolkit/simple/style/ParagraphProperties.java:

      /**

      • sets backgroundColor
      • @param bkColor
        */
        public void setBackgroundColor(Color bkColor)
        {
        mElement.setFoBackgroundColorAttribute(bkColor.toString());
        }

      /**

      • gets backgroundColor
      • @return bkColor as String
        */
        public String getBackgroundColorAttribute()
        {
        return mElement.getFoBackgroundColorAttribute();
        }

      simple/src/main/java/org/odftoolkit/simple/style/TextProperties.java

      /**

      • sets textstyle subscripted
      • @param fontsizePercent font size in per cent for subscripted text. if null default is 58 %
        */
        public void setSubscripted(Integer fontsizePercent)
        {
        if (fontsizePercent != null)
        {
        mElement.setStyleTextPositionAttribute("sub " + fontsizePercent.toString() + "%");
        }
        else
        {
        mElement.setStyleTextPositionAttribute("sub 58%");
        }
        }

      /**

      • sets textstyle superscripted
      • @param fontsizePercent font size in per cent for superscripted text. if null default is 58 %
        */
        public void setSuperscripted(Integer fontsizePercent)
        {
        if (fontsizePercent != null)
        {
        mElement.setStyleTextPositionAttribute("super " + fontsizePercent.toString() + "%");
        }
        else
        {
        mElement.setStyleTextPositionAttribute("super 58%");
        }
        }

      /**

      • gets the per centage value of subscription or null
      • @return
        */
        public Integer getSubscripted()
        {

      String posAtt = mElement.getStyleTextPositionAttribute();
      if (posAtt != null)
      {
      if (posAtt.startsWith("sub"))
      {
      String value = posAtt.substring(4);
      int i = value.indexOf('%');
      if (i > 0)
      {
      try
      {
      value = value.substring(0, i);
      return Integer.parseInt(value);
      }
      catch (Exception e)
      {

      }
      }
      }
      }
      return null;
      }

      /**

      • gets the per centage value of superscription or null
      • @return
        */
        public Integer getSuperscripted()
        {

      String posAtt = mElement.getStyleTextPositionAttribute();
      if (posAtt != null)
      {
      if (posAtt.startsWith("super"))
      {
      String value = posAtt.substring(6);
      int i = value.indexOf('%');
      if (i > 0)
      {
      try
      {
      value = value.substring(0, i);
      return Integer.parseInt(value);
      }
      catch (Exception e)
      {

      }
      }
      }
      }

      return null;
      }

      and the following JUnit-Tests:

      src/test/java/org/odftoolkit/simple/style/ParagraphPropertiesTest.java

      @Test
      public void testGetSetBackgroundColor()
      {
      try
      {
      TextDocument doc = TextDocument.newTextDocument();
      Paragraph paragraph1 = doc.addParagraph("paragraph1");

      ParagraphStyleHandler psh = paragraph1.getStyleHandler();
      ParagraphProperties paraProp = psh.getParagraphPropertiesForWrite();
      paraProp.setBackgroundColor(new Color("#FF0000"));

      psh = paragraph1.getStyleHandler();
      paraProp = psh.getParagraphPropertiesForWrite();

      Assert.assertEquals("#FF0000", paraProp.getBackgroundColorAttribute());

      }
      catch (Exception e)
      {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail();
      }

      }

      and in:

      src/test/java/org/odftoolkit/simple/style/TextPropertiesTest.java

      @Test
      public void testSubscripted()
      {
      try
      {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Cell cell = table.getCellByPosition("A1");

      TextProperties textProperties = cell.getStyleHandler().getTextPropertiesForWrite();
      textProperties.setSubscripted(null);

      //validate
      Integer i = textProperties.getSubscripted();
      Assert.assertEquals(Integer.valueOf(58), i);

      }
      catch (Exception e)
      {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
      }
      }

      @Test
      public void testSuperscripted()
      {
      try
      {
      SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
      Table table = document.getTableByName("Sheet1");
      Cell cell = table.getCellByPosition("A1");

      TextProperties textProperties = cell.getStyleHandler().getTextPropertiesForWrite();
      textProperties.setSuperscripted(Integer.valueOf(50));

      //validate
      Integer i = textProperties.getSuperscripted();
      Assert.assertEquals(Integer.valueOf(50), i);

      }
      catch (Exception e)
      {
      LOGGER.log(Level.SEVERE, e.getMessage(), e);
      Assert.fail(e.getMessage());
      }
      }

      Attachments

        1. simpleApi-patch.zip
          12 kB
          Georg Füchsle

        Activity

          People

            svanteschubert Svante Schubert
            giofyxle Georg Füchsle
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: