Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background color support in ODTDefaultStyle #404

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@

/**
* Default implementation : - uses OOo default styles for headers - uses default but renamed styles for others
*
*
* @author <a href="mailto:[email protected]">Tiry</a>
*/
public class ODTDefaultStylesGenerator
implements IODTStylesGenerator
implements IODTStylesGenerator
{
protected static final String HEADER_PREFIX = "Heading_20_";

protected static final Pattern HEADER_PATTERN = Pattern.compile(HEADER_PREFIX + "(\\d+).*");

protected static final String[] BULLET_CHARS = { "\u2022", "\u25e6", "\u25aa" };
Expand Down Expand Up @@ -156,9 +156,9 @@ public String generateTextStyles()
region.append( generateStyle( BOLD_STYLE_NAME, "fo:font-weight=\"bold\"" ) );
region.append( generateStyle( ITALIC_STYLE_NAME, "fo:font-style=\"italic\"" ) );
region.append( generateStyle( UNDERLINE_STYLE_NAME,
"style:text-underline-style=\"solid\" style:text-underline-width=\"auto\" style:text-underline-color=\"font-color\"" ) );
"style:text-underline-style=\"solid\" style:text-underline-width=\"auto\" style:text-underline-color=\"font-color\"" ) );
region.append( generateStyle( STRIKE_STYLE_NAME,
"style:text-line-through-style=\"solid\" style:text-underline-style=\"none\"" ) );
"style:text-line-through-style=\"solid\" style:text-underline-style=\"none\"" ) );
region.append( generateStyle( SUBSCRIPT_STYLE_NAME, "style:text-position=\"sub\"" ) );
region.append( generateStyle( SUPERSCRIPT_STYLE_NAME, "style:text-position=\"super\"" ) );
return region.toString();
Expand Down Expand Up @@ -363,7 +363,7 @@ public String getParaBreakAfterStyleName()
private String generateStylePageBreak( boolean pageBreakBefore )
{
String styleName =
pageBreakBefore ? PAGE_BREAK_BEFORE_PARAGRAPH_STYLE_NAME : PAGE_BREAK_AFTER_PARAGRAPH_STYLE_NAME;
pageBreakBefore ? PAGE_BREAK_BEFORE_PARAGRAPH_STYLE_NAME : PAGE_BREAK_AFTER_PARAGRAPH_STYLE_NAME;
StringBuilder style = new StringBuilder();
style.append( "<style:style style:name=\"" );
style.append( styleName );
Expand Down Expand Up @@ -449,6 +449,10 @@ public String getTextStyleName( ContainerProperties properties )
startStyleIfNeeded(properties.getType(), properties.getStyleName());
dynamicStyles.append( "style:text-position=\"super\" " );
}
if (properties.getBackgroundColor() != null){
startStyleIfNeeded(properties.getType(), properties.getStyleName());
dynamicStyles.append( "fo:background-color=\""+ properties.getBackgroundColor()+ "\" ");
}

// <style:paragraph-properties fo:text-align="center" style:justify-single-word="false" />
setPropertiesKind( ODTStyleProperties.PARAGRAPH );
Expand Down Expand Up @@ -513,7 +517,7 @@ private void startStyleIfNeeded(ContainerType type, String baseStyleName) {
{
dynamicStyles.append( "\" style:family=\"text\">" );
}

}
if ( !this.hasPropertiesKind )
{
Expand All @@ -539,4 +543,4 @@ private void endStyleIfNeeded()
dynamicStyles.append( "/></style:style>" );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static Map<String, String> parse( String style )

/**
* Create {@link ParagraphProperties} from inline style.
*
*
* @param style
* @return
*/
Expand All @@ -96,7 +96,7 @@ public static ParagraphProperties createParagraphProperties( String style )

/**
* Create {@link HeaderProperties} from inline style.
*
*
* @param style
* @return
*/
Expand All @@ -114,7 +114,7 @@ public static HeaderProperties createHeaderProperties( String style )

/**
* Create {@link ListItemProperties} from inline style.
*
*
* @param style
* @return
*/
Expand All @@ -132,7 +132,7 @@ public static ListItemProperties createListItemProperties( String style )

/**
* Create {@link ListProperties} from inline style.
*
*
* @param style
* @return
*/
Expand All @@ -150,7 +150,7 @@ public static ListProperties createListProperties( String style )

/**
* Create {@link SpanProperties} from inline style.
*
*
* @param style
* @return
*/
Expand Down Expand Up @@ -268,6 +268,13 @@ else if ( "inherit".equals( textAlignment ) )
if (styleName != null) {
properties.setStyleName(styleName);
}

// background-color
String backgroundColor = stylesMap.get("background-color");
if(backgroundColor != null) {
properties.setBackgroundColor(backgroundColor);
}

}

public static TableProperties createTableProperties( Attributes attributes )
Expand All @@ -287,4 +294,4 @@ public static TableCellProperties createTableCellProperties( Attributes attribut
TableCellProperties properties = new TableCellProperties();
return properties;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public enum ContainerType

private boolean superscript;

private String backgroundColor;

private TextAlignment textAlignment;

private String styleName;
Expand Down Expand Up @@ -165,4 +167,11 @@ public void setStyleName(String styleName) {
this.styleName = styleName;
}

public String getBackgroundColor() {
return backgroundColor;
}

public void setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
}
}