You are viewing a plain text version of this content. The canonical link for it is here.
Posted to odf-dev@incubator.apache.org by "Svante Schubert (JIRA)" <ji...@apache.org> on 2017/03/05 12:00:34 UTC

[jira] [Updated] (ODFTOOLKIT-417) Missing methods for set and get background-color, subscripted and superscripted for a paragraph

     [ https://issues.apache.org/jira/browse/ODFTOOLKIT-417?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Svante Schubert updated ODFTOOLKIT-417:
---------------------------------------
    Fix Version/s: 0.6.2-incubating

> Missing methods for set and get background-color, subscripted and superscripted for a paragraph
> -----------------------------------------------------------------------------------------------
>
>                 Key: ODFTOOLKIT-417
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-417
>             Project: ODF Toolkit
>          Issue Type: Improvement
>          Components: simple api
>    Affects Versions: 0.6.2-incubating
>            Reporter: Georg Füchsle
>            Assignee: Svante Schubert
>             Fix For: 0.6.2-incubating
>
>         Attachments: simpleApi-patch.zip
>
>
> in File:
> http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/ParagraphProperties.java
> are missing the methods:
> {quote}
> public void setBackgroundColor(Color bkColor);
> public String getBackgroundColorAttribute();
> {quote}
> 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:
> {quote}
> public void setSubscripted(Integer fontsizePercent);
> public void setSuperscripted(Integer fontsizePercent);
> public Integer getSubscripted();
> public Integer getSuperscripted();
> {quote}
> We suggest the following code:
> simple/src/main/java/org/odftoolkit/simple/style/ParagraphProperties.java:
> {quote}
>     /**
>      * 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();
>     \}
> {quote}
> simple/src/main/java/org/odftoolkit/simple/style/TextProperties.java
> {quote}
>     /**
>      * 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;
>     \}
> {quote}
> and the following JUnit-Tests:
> src/test/java/org/odftoolkit/simple/style/ParagraphPropertiesTest.java
> {quote}
>     @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();
> 	\}
>     \}
> {quote}
> and in:
> src/test/java/org/odftoolkit/simple/style/TextPropertiesTest.java
> {quote}
>     @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());
> 	\}
>     \}
> {quote}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)