ASF Bugzilla – Attachment 32976 Details for
Bug 58217
support alpha channel on solid colors (fill, line, text)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch with proposed changes
0001-support-alpha-channel-on-solid-colors-fill-line-text.patch (text/plain), 9.30 KB, created by
mark.o
on 2015-08-06 11:10:52 UTC
(
hide
)
Description:
patch with proposed changes
Filename:
MIME Type:
Creator:
mark.o
Created:
2015-08-06 11:10:52 UTC
Size:
9.30 KB
patch
obsolete
>From 9d2fda5e906b33c7a60a214a86c3fc574469c304 Mon Sep 17 00:00:00 2001 >From: Mark Olesen <Mark.Olesen@faurecia.com> >Date: Thu, 6 Aug 2015 12:47:16 +0200 >Subject: [PATCH] support alpha channel on solid colors (fill, line, text) > >--- > .../org/apache/poi/xslf/usermodel/Tutorial3.java | 4 ++ > .../org/apache/poi/xslf/usermodel/XSLFColor.java | 34 ++++++++++++++ > .../apache/poi/xslf/usermodel/XSLFSimpleShape.java | 48 +++++++------------- > .../apache/poi/xslf/usermodel/XSLFTableCell.java | 4 +- > .../org/apache/poi/xslf/usermodel/XSLFTextRun.java | 15 +++---- > 5 files changed, 62 insertions(+), 43 deletions(-) > >diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java b/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java >index 54347b4..c1c95ff 100644 >--- a/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java >+++ b/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java >@@ -19,6 +19,7 @@ > > package org.apache.poi.xslf.usermodel; > >+import java.awt.Color; > import java.awt.Rectangle; > import java.io.FileOutputStream; > import java.io.IOException; >@@ -40,6 +41,9 @@ public class Tutorial3 { > titleShape.setText("This is a slide title"); > titleShape.setAnchor(new Rectangle(50, 50, 400, 100)); > >+ // set background, with 25% opacity >+ titleShape.setFillColor(new Color(255, 0, 0, 64)); >+ > FileOutputStream out = new FileOutputStream("title.pptx"); > ppt.write(out); > out.close(); >diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java >index 09e05d9..173b1cc 100644 >--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java >+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java >@@ -33,6 +33,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor; > import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor; > import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor; > import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor; >+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties; > import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor; > import org.w3c.dom.Node; > >@@ -388,6 +389,39 @@ public class XSLFColor { > } > > >+ >+ /** >+ * Set the solid fill colors - RGB and alpha. >+ * >+ * No sanity checks, the caller must handle null values itself. >+ * >+ * @param fill The solid fill properties >+ * @param color The color to use. >+ */ >+ /* package */ static void setFillColor(CTSolidColorFillProperties fill, Color color) >+ { >+ CTSRgbColor rgb = CTSRgbColor.Factory.newInstance(); >+ rgb.setVal(new byte[]{ >+ (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue() >+ }); >+ >+ // alpha (%) >+ int alpha = (int) (100000 * color.getAlpha() / 255.0); >+ if (alpha < 100000) >+ { >+ rgb.addNewAlpha().setVal(alpha); >+ } >+ >+ fill.setSrgbClr(rgb); >+ >+ if (fill.isSetHslClr()) fill.unsetHslClr(); >+ if (fill.isSetPrstClr()) fill.unsetPrstClr(); >+ if (fill.isSetSchemeClr()) fill.unsetSchemeClr(); >+ if (fill.isSetScrgbClr()) fill.unsetScrgbClr(); >+ if (fill.isSetSysClr()) fill.unsetSysClr(); >+ } >+ >+ > /** > * Preset colors defined in DrawingML > */ >diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java >index bd29667..ac50d9a 100644 >--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java >+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java >@@ -180,35 +180,29 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { > if (styleMatrix == null) return null; > CTLineStyleList lineStyles = styleMatrix.getLnStyleLst(); > if (lineStyles == null || lineStyles.sizeOfLnArray() < idx) return null; >- >+ > return lineStyles.getLnArray(idx - 1); > } > >+ > /** >- * @param color the color to paint the shape outline. >+ * @param color the color to paint the shape outline. > * A <code>null</code> value turns off the shape outline. > */ > public void setLineColor(Color color) { > CTShapeProperties spPr = getSpPr(); > if (color == null) { >- if (spPr.isSetLn() && spPr.getLn().isSetSolidFill()) >+ if (spPr.isSetLn() && spPr.getLn().isSetSolidFill()) { > spPr.getLn().unsetSolidFill(); >+ } > } else { >- CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr >- .addNewLn(); >+ CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr.addNewLn(); > >- CTSRgbColor rgb = CTSRgbColor.Factory.newInstance(); >- rgb.setVal(new byte[]{(byte) color.getRed(), >- (byte) color.getGreen(), (byte) color.getBlue()}); >- >- CTSolidColorFillProperties fill = ln.isSetSolidFill() ? ln >- .getSolidFill() : ln.addNewSolidFill(); >- fill.setSrgbClr(rgb); >- if(fill.isSetHslClr()) fill.unsetHslClr(); >- if(fill.isSetPrstClr()) fill.unsetPrstClr(); >- if(fill.isSetSchemeClr()) fill.unsetSchemeClr(); >- if(fill.isSetScrgbClr()) fill.unsetScrgbClr(); >- if(fill.isSetSysClr()) fill.unsetSysClr(); >+ XSLFColor.setFillColor >+ ( >+ ln.isSetSolidFill() ? ln.getSolidFill() : ln.addNewSolidFill(), >+ color >+ ); > } > } > >@@ -491,7 +485,7 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { > * specified color. > * > * @param color the solid color fill. The value of <code>null</code> unsets >- * the solidFIll attribute from the underlying xml >+ * the solidFill attribute from the underlying xml > */ > public void setFillColor(Color color) { > CTShapeProperties spPr = getSpPr(); >@@ -502,19 +496,11 @@ public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape { > } else { > if (spPr.isSetNoFill()) spPr.unsetNoFill(); > >- CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr >- .getSolidFill() : spPr.addNewSolidFill(); >- >- CTSRgbColor rgb = CTSRgbColor.Factory.newInstance(); >- rgb.setVal(new byte[]{(byte) color.getRed(), >- (byte) color.getGreen(), (byte) color.getBlue()}); >- >- fill.setSrgbClr(rgb); >- if(fill.isSetHslClr()) fill.unsetHslClr(); >- if(fill.isSetPrstClr()) fill.unsetPrstClr(); >- if(fill.isSetSchemeClr()) fill.unsetSchemeClr(); >- if(fill.isSetScrgbClr()) fill.unsetScrgbClr(); >- if(fill.isSetSysClr()) fill.unsetSysClr(); >+ XSLFColor.setFillColor >+ ( >+ spPr.isSetSolidFill() ? spPr.getSolidFill() : spPr.addNewSolidFill(), >+ color >+ ); > } > } > >diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java >index 9381152..2d83d2e 100644 >--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java >+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java >@@ -146,9 +146,7 @@ public class XSLFTableCell extends XSLFTextShape { > tl.setW(STLineEndWidth.MED); > tl.setLen(STLineEndLength.MED); > >- CTSRgbColor rgb = CTSRgbColor.Factory.newInstance(); >- rgb.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()}); >- ln.addNewSolidFill().setSrgbClr(rgb); >+ XSLFColor.setFillColor(ln.addNewSolidFill(), color); > } > } > >diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java >index 7a5c78b..a531d44 100644 >--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java >+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java >@@ -85,18 +85,15 @@ public class XSLFTextRun implements TextRun { > @Override > public void setFontColor(Color color) { > CTTextCharacterProperties rPr = getRPr(); >- CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill(); >- CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr(); >- clr.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()}); >- >- if(fill.isSetHslClr()) fill.unsetHslClr(); >- if(fill.isSetPrstClr()) fill.unsetPrstClr(); >- if(fill.isSetSchemeClr()) fill.unsetSchemeClr(); >- if(fill.isSetScrgbClr()) fill.unsetScrgbClr(); >- if(fill.isSetSysClr()) fill.unsetSysClr(); > >+ XSLFColor.setFillColor >+ ( >+ rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill(), >+ color >+ ); > } > >+ > @Override > public Color getFontColor(){ > final XSLFTheme theme = _p.getParentShape().getSheet().getTheme(); >-- >1.7.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 58217
: 32976