Bug 64999

Summary: XDDFRunProperties setFonts font override
Product: POI Reporter: fanjiajia <fanziang78>
Component: XDDFAssignee: POI Developers List <dev>
Status: RESOLVED CLOSED    
Severity: normal    
Priority: P2    
Version: 4.1.2-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description fanjiajia 2020-12-17 10:02:19 UTC
public void setFonts(XDDFFont[] fonts) {
        for (XDDFFont font : fonts) {
            CTTextFont xml = font.getXmlObject();
            switch (font.getGroup()) {
            case COMPLEX_SCRIPT:
                if (xml == null) {
                    if (props.isSetCs()) {
                        props.unsetCs();
                    }
                } else {
                    props.setCs(xml);
                }
            case EAST_ASIAN:
                if (xml == null) {
                    if (props.isSetEa()) {
                        props.unsetEa();
                    }
                } else {
                    props.setEa(xml);
                }
            case LATIN:
                if (xml == null) {
                    if (props.isSetLatin()) {
                        props.unsetLatin();
                    }
                } else {
                    props.setLatin(xml);
                }
            case SYMBOL:
                if (xml == null) {
                    if (props.isSetSym()) {
                        props.unsetSym();
                    }
                } else {
                    props.setSym(xml);
                }
            }
        }
    }

Add break to case.
Comment 1 PJ Fanning 2020-12-17 11:20:12 UTC
the latest source code does not look like this - could you review the latest code?
Comment 2 fanjiajia 2020-12-18 02:00:15 UTC
Version : 4.1.2

Maven confih: 
...
 <poi.version>4.1.2</poi.version>

...
<dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>${poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>${poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>${poi.version}</version>
        </dependency>
...


My java code:

XDDFFont[] fonts = new XDDFFont[2];
                fonts[0] = new XDDFFont(FontGroup.EAST_ASIAN, StringUtils.isBlank(fontStyle.getEastAsianFontFamily()) ? Constant.DEFAULT_EA_FONT :
                        title.getFont().getEastAsianFontFamily(), null, null, null);
                fonts[1] = new XDDFFont(FontGroup.LATIN, StringUtils.isBlank(fontStyle.getFontFamily()) ? Constant.DEFAULT_EN_FONT :
                        title.getFont().getFontFamily(), null, null, null);
                XDDFRunProperties xddfRunProperties = new XDDFRunProperties();
                xddfRunProperties.setFonts(fonts);

If I set LATIN to fonts[0],EAST_ASIAN font will override LATIN font.
Comment 3 PJ Fanning 2020-12-18 09:12:33 UTC
The thing is the code is fixed already. POI 5.0.0 will be released early next year. You can also use a nightly build or do a custom build of your own based on patching the source. https://ci-builds.apache.org/job/POI/job/POI-DSL-1.8/lastSuccessfulBuild/artifact/build/dist/