View | Details | Raw Unified | Return to bug 58217
Collapse All | Expand All

(-)a/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java (+4 lines)
Lines 19-24 Link Here
19
19
20
package org.apache.poi.xslf.usermodel;
20
package org.apache.poi.xslf.usermodel;
21
21
22
import java.awt.Color;
22
import java.awt.Rectangle;
23
import java.awt.Rectangle;
23
import java.io.FileOutputStream;
24
import java.io.FileOutputStream;
24
import java.io.IOException;
25
import java.io.IOException;
Lines 40-45 public class Tutorial3 { Link Here
40
        titleShape.setText("This is a slide title");
41
        titleShape.setText("This is a slide title");
41
        titleShape.setAnchor(new Rectangle(50, 50, 400, 100));
42
        titleShape.setAnchor(new Rectangle(50, 50, 400, 100));
42
43
44
        // set background, with 25% opacity
45
        titleShape.setFillColor(new Color(255, 0, 0, 64));
46
43
        FileOutputStream out = new FileOutputStream("title.pptx");
47
        FileOutputStream out = new FileOutputStream("title.pptx");
44
        ppt.write(out);
48
        ppt.write(out);
45
        out.close();
49
        out.close();
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java (+34 lines)
Lines 33-38 import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor; Link Here
33
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
33
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
34
import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor;
34
import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor;
35
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
35
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
36
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
36
import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
37
import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
37
import org.w3c.dom.Node;
38
import org.w3c.dom.Node;
38
39
Lines 388-393 public class XSLFColor { Link Here
388
    }
389
    }
389
390
390
391
392
393
    /**
394
     * Set the solid fill colors - RGB and alpha.
395
     *
396
     * No sanity checks, the caller must handle null values itself.
397
     *
398
     * @param fill    The solid fill properties
399
     * @param color   The color to use.
400
     */
401
    /* package */ static void setFillColor(CTSolidColorFillProperties fill, Color color)
402
    {
403
        CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
404
        rgb.setVal(new byte[]{
405
            (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()
406
        });
407
408
        // alpha (%)
409
        int alpha = (int) (100000 * color.getAlpha() / 255.0);
410
        if (alpha < 100000)
411
        {
412
            rgb.addNewAlpha().setVal(alpha);
413
        }
414
415
        fill.setSrgbClr(rgb);
416
417
        if (fill.isSetHslClr()) fill.unsetHslClr();
418
        if (fill.isSetPrstClr()) fill.unsetPrstClr();
419
        if (fill.isSetSchemeClr()) fill.unsetSchemeClr();
420
        if (fill.isSetScrgbClr()) fill.unsetScrgbClr();
421
        if (fill.isSetSysClr()) fill.unsetSysClr();
422
    }
423
424
391
    /**
425
    /**
392
     * Preset colors defined in DrawingML
426
     * Preset colors defined in DrawingML
393
     */
427
     */
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java (-31 / +17 lines)
Lines 180-214 public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { Link Here
180
        if (styleMatrix == null) return null;
180
        if (styleMatrix == null) return null;
181
        CTLineStyleList lineStyles = styleMatrix.getLnStyleLst();
181
        CTLineStyleList lineStyles = styleMatrix.getLnStyleLst();
182
        if (lineStyles == null || lineStyles.sizeOfLnArray() < idx) return null;
182
        if (lineStyles == null || lineStyles.sizeOfLnArray() < idx) return null;
183
        
183
184
        return lineStyles.getLnArray(idx - 1);
184
        return lineStyles.getLnArray(idx - 1);
185
    }
185
    }
186
186
187
187
    /**
188
    /**
188
    * @param color  the color to paint the shape outline.
189
     * @param color  the color to paint the shape outline.
189
     * A <code>null</code> value turns off the shape outline.
190
     * A <code>null</code> value turns off the shape outline.
190
     */
191
     */
191
    public void setLineColor(Color color) {
192
    public void setLineColor(Color color) {
192
        CTShapeProperties spPr = getSpPr();
193
        CTShapeProperties spPr = getSpPr();
193
        if (color == null) {
194
        if (color == null) {
194
            if (spPr.isSetLn() && spPr.getLn().isSetSolidFill())
195
            if (spPr.isSetLn() && spPr.getLn().isSetSolidFill()) {
195
                spPr.getLn().unsetSolidFill();
196
                spPr.getLn().unsetSolidFill();
197
            }
196
        } else {
198
        } else {
197
            CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr
199
            CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr.addNewLn();
198
                    .addNewLn();
199
200
200
            CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
201
            XSLFColor.setFillColor
201
            rgb.setVal(new byte[]{(byte) color.getRed(),
202
            (
202
                    (byte) color.getGreen(), (byte) color.getBlue()});
203
                ln.isSetSolidFill() ? ln.getSolidFill() : ln.addNewSolidFill(),
203
204
                color
204
            CTSolidColorFillProperties fill = ln.isSetSolidFill() ? ln
205
            );
205
                    .getSolidFill() : ln.addNewSolidFill();
206
            fill.setSrgbClr(rgb);
207
            if(fill.isSetHslClr()) fill.unsetHslClr();
208
            if(fill.isSetPrstClr()) fill.unsetPrstClr();
209
            if(fill.isSetSchemeClr()) fill.unsetSchemeClr();
210
            if(fill.isSetScrgbClr()) fill.unsetScrgbClr();
211
            if(fill.isSetSysClr()) fill.unsetSysClr();
212
        }
206
        }
213
    }
207
    }
214
208
Lines 491-497 public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { Link Here
491
     * specified color.
485
     * specified color.
492
     *
486
     *
493
     * @param color the solid color fill. The value of <code>null</code> unsets
487
     * @param color the solid color fill. The value of <code>null</code> unsets
494
     *              the solidFIll attribute from the underlying xml
488
     *              the solidFill attribute from the underlying xml
495
     */
489
     */
496
    public void setFillColor(Color color) {
490
    public void setFillColor(Color color) {
497
        CTShapeProperties spPr = getSpPr();
491
        CTShapeProperties spPr = getSpPr();
Lines 502-520 public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { Link Here
502
        } else {
496
        } else {
503
            if (spPr.isSetNoFill()) spPr.unsetNoFill();
497
            if (spPr.isSetNoFill()) spPr.unsetNoFill();
504
498
505
            CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr
499
            XSLFColor.setFillColor
506
                    .getSolidFill() : spPr.addNewSolidFill();
500
            (
507
501
                spPr.isSetSolidFill() ? spPr.getSolidFill() : spPr.addNewSolidFill(),
508
            CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
502
                color
509
            rgb.setVal(new byte[]{(byte) color.getRed(),
503
            );
510
                    (byte) color.getGreen(), (byte) color.getBlue()});
511
512
            fill.setSrgbClr(rgb);
513
            if(fill.isSetHslClr()) fill.unsetHslClr();
514
            if(fill.isSetPrstClr()) fill.unsetPrstClr();
515
            if(fill.isSetSchemeClr()) fill.unsetSchemeClr();
516
            if(fill.isSetScrgbClr()) fill.unsetScrgbClr();
517
            if(fill.isSetSysClr()) fill.unsetSysClr();
518
        }
504
        }
519
    }
505
    }
520
506
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java (-3 / +1 lines)
Lines 146-154 public class XSLFTableCell extends XSLFTextShape { Link Here
146
            tl.setW(STLineEndWidth.MED);
146
            tl.setW(STLineEndWidth.MED);
147
            tl.setLen(STLineEndLength.MED);
147
            tl.setLen(STLineEndLength.MED);
148
148
149
            CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();
149
            XSLFColor.setFillColor(ln.addNewSolidFill(), color);
150
            rgb.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()});
151
            ln.addNewSolidFill().setSrgbClr(rgb);
152
        }
150
        }
153
    }    
151
    }    
154
    
152
    
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java (-10 / +6 lines)
Lines 85-102 public class XSLFTextRun implements TextRun { Link Here
85
    @Override
85
    @Override
86
    public void setFontColor(Color color) {
86
    public void setFontColor(Color color) {
87
        CTTextCharacterProperties rPr = getRPr();
87
        CTTextCharacterProperties rPr = getRPr();
88
        CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
89
        CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
90
        clr.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()});
91
92
        if(fill.isSetHslClr()) fill.unsetHslClr();
93
        if(fill.isSetPrstClr()) fill.unsetPrstClr();
94
        if(fill.isSetSchemeClr()) fill.unsetSchemeClr();
95
        if(fill.isSetScrgbClr()) fill.unsetScrgbClr();
96
        if(fill.isSetSysClr()) fill.unsetSysClr();
97
88
89
        XSLFColor.setFillColor
90
        (
91
            rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill(),
92
            color
93
        );
98
    }
94
    }
99
95
96
100
    @Override
97
    @Override
101
    public Color getFontColor(){
98
    public Color getFontColor(){
102
        final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
99
        final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
103
- 

Return to bug 58217