jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
36 stars 6 forks source link

Give more flexibility for the destination of style declarations #57

Closed jferard closed 7 years ago

jferard commented 7 years ago

For TableCellStyles and TextStyles, one should be able to decide whether they go in styles.xml or content.xml.

Some ideas:

jferard commented 7 years ago

Every style may be in styles.xml > styles or in content.xml > automatic-styles. The meaning of the qualifier "automatic" is not obvious. I will use the term "hidden", which means "hidden to the end user in LO". Thus: every style may be hidden or not hidden. Steps:

  1. create a boolean isHidden() method in DataStyle and StyleTag interfaces;
  2. create a buildHidden() for each builder;
  3. create a hidden field in each object style (row style, cell style, table style, ...) and in data style;
  4. check in StylesContainer if the styles are in the right container.

If everything is fine, let StylesContainer choose the container on the isHidden value.

jferard commented 7 years ago

This method of OdsElements does type-checking:

public void addObjectStyle(final ObjectStyle objectStyle) {
    final String family = objectStyle.getFamily();
    if ("table-cell".equals(family))
        this.stylesContainer.addStyleToStylesCommonStyles(objectStyle);
    else if ("text".equals(family))
        this.stylesContainer.addStyleToStylesAutomaticStyles(objectStyle);
    else
        this.stylesContainer.addStyleToContentAutomaticStyles(objectStyle);
}

It will be replaced after refactoring by:

public void addObjectStyle(final ObjectStyle objectStyle) {
    if (objectStyle.isHidden()) // text
        this.stylesContainer.addStyleToStylesAutomaticStyles(objectStyle);
    else // table cell and other
        this.stylesContainer.addStyleToContentAutomaticStyles(objectStyle);
}