mirror of https://github.com/apache/poi.git
#64241 - shade and tint calculation are based now on scRGB (opposed to HSL) colorspace
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1875522 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a45f7bdcdd
commit
7a340230fd
|
@ -417,14 +417,18 @@ public class DrawPaint {
|
||||||
|
|
||||||
Color result = color.getColor();
|
Color result = color.getColor();
|
||||||
|
|
||||||
double alpha = getAlpha(result, color);
|
final double alpha = getAlpha(result, color);
|
||||||
|
|
||||||
|
final double[] scRGB = RGB2SCRGB(result);
|
||||||
|
applyShade(scRGB, color);
|
||||||
|
applyTint(scRGB, color);
|
||||||
|
result = SCRGB2RGB(scRGB);
|
||||||
|
|
||||||
// values are in the range [0..100] (usually ...)
|
// values are in the range [0..100] (usually ...)
|
||||||
double[] hsl = RGB2HSL(result);
|
double[] hsl = RGB2HSL(result);
|
||||||
applyHslModOff(hsl, 0, color.getHueMod(), color.getHueOff());
|
applyHslModOff(hsl, 0, color.getHueMod(), color.getHueOff());
|
||||||
applyHslModOff(hsl, 1, color.getSatMod(), color.getSatOff());
|
applyHslModOff(hsl, 1, color.getSatMod(), color.getSatOff());
|
||||||
applyHslModOff(hsl, 2, color.getLumMod(), color.getLumOff());
|
applyHslModOff(hsl, 2, color.getLumMod(), color.getLumOff());
|
||||||
applyShade(hsl, color);
|
|
||||||
applyTint(hsl, color);
|
|
||||||
|
|
||||||
result = HSL2RGB(hsl[0], hsl[1], hsl[2], alpha);
|
result = HSL2RGB(hsl[0], hsl[1], hsl[2], alpha);
|
||||||
|
|
||||||
|
@ -477,23 +481,22 @@ public class DrawPaint {
|
||||||
*
|
*
|
||||||
* For a shade, the equation is luminance * %tint.
|
* For a shade, the equation is luminance * %tint.
|
||||||
*/
|
*/
|
||||||
private static void applyShade(double[] hsl, ColorStyle fc) {
|
private static void applyShade(double[] scRGB, ColorStyle fc) {
|
||||||
int shade = fc.getShade();
|
int shade = fc.getShade();
|
||||||
if (shade == -1) {
|
if (shade == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double shadePct = shade / 100_000.;
|
final double shadePct = shade / 100_000.;
|
||||||
hsl[2] *= shadePct;
|
for (int i=0; i<3; i++) {
|
||||||
|
scRGB[i] = Math.max(0, Math.min(1, scRGB[i]*shadePct));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the tint
|
* Apply the tint
|
||||||
*
|
|
||||||
* For a tint, the equation is luminance * %tint + (1-%tint).
|
|
||||||
* (Note that 1-%tint is equal to the lumOff value in DrawingML.)
|
|
||||||
*/
|
*/
|
||||||
private static void applyTint(double[] hsl, ColorStyle fc) {
|
private static void applyTint(double[] scRGB, ColorStyle fc) {
|
||||||
int tint = fc.getTint();
|
int tint = fc.getTint();
|
||||||
if (tint == -1 || tint == 0) {
|
if (tint == -1 || tint == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -502,15 +505,8 @@ public class DrawPaint {
|
||||||
// see 18.8.19 fgColor (Foreground Color)
|
// see 18.8.19 fgColor (Foreground Color)
|
||||||
double tintPct = tint / 100_000.;
|
double tintPct = tint / 100_000.;
|
||||||
|
|
||||||
|
for (int i=0; i<3; i++) {
|
||||||
// The tint value is stored as a double from -1.0 .. 1.0, where -1.0 means 100% darken
|
scRGB[i] = 1 - (1 - scRGB[i]) * tintPct;
|
||||||
// and 1.0 means 100% lighten. Also, 0.0 means no change.
|
|
||||||
if (tintPct < 0) {
|
|
||||||
// Lum’ = Lum * (1.0 + tint)
|
|
||||||
hsl[2] *= (1 + tintPct);
|
|
||||||
} else {
|
|
||||||
// Lum‘ = Lum * (1.0-tint) + (HLSMAX – HLSMAX * (1.0-tint))
|
|
||||||
hsl[2] = hsl[2]*(1-tintPct) + (100-100*(1-tintPct));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,36 +745,50 @@ public class DrawPaint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert sRGB float component [0..1] from sRGB to linear RGB [0..100000]
|
* Convert sRGB Color to scRGB [0..1] (0:red,1:green,2:blue).
|
||||||
|
* Alpha needs to be handled separately.
|
||||||
*
|
*
|
||||||
* @see Color#getRGBColorComponents(float[])
|
* @see <a href="https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/Media/Color.cs,1048">.Net implementation sRgbToScRgb</a>
|
||||||
*/
|
*/
|
||||||
public static int srgb2lin(float sRGB) {
|
public static double[] RGB2SCRGB(Color color) {
|
||||||
// scRGB has a linear gamma of 1.0, scale the AWT-Color which is in sRGB to linear RGB
|
float[] rgb = color.getColorComponents(null);
|
||||||
// see https://en.wikipedia.org/wiki/SRGB (the reverse transformation)
|
double[] scRGB = new double[3];
|
||||||
if (sRGB <= 0.04045d) {
|
for (int i=0; i<3; i++) {
|
||||||
return (int)Math.rint(100000d * sRGB / 12.92d);
|
if (rgb[i] < 0) {
|
||||||
} else {
|
scRGB[i] = 0;
|
||||||
return (int)Math.rint(100000d * Math.pow((sRGB + 0.055d) / 1.055d, 2.4d));
|
} else if (rgb[i] <= 0.04045) {
|
||||||
|
scRGB[i] = rgb[i] / 12.92;
|
||||||
|
} else if (rgb[i] <= 1) {
|
||||||
|
scRGB[i] = Math.pow((rgb[i] + 0.055) / 1.055, 2.4);
|
||||||
|
} else {
|
||||||
|
scRGB[i] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return scRGB;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert linear RGB [0..100000] to sRGB float component [0..1]
|
* Convert scRGB [0..1] components (0:red,1:green,2:blue) to sRGB Color.
|
||||||
|
* Alpha needs to be handled separately.
|
||||||
*
|
*
|
||||||
* @see Color#getRGBColorComponents(float[])
|
* @see <a href="https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/Media/Color.cs,1075">.Net implementation ScRgbTosRgb</a>
|
||||||
*/
|
*/
|
||||||
public static float lin2srgb(int linRGB) {
|
public static Color SCRGB2RGB(double... scRGB) {
|
||||||
// color in percentage is in linear RGB color space, i.e. needs to be gamma corrected for AWT color
|
final double[] rgb = new double[3];
|
||||||
// see https://en.wikipedia.org/wiki/SRGB (The forward transformation)
|
for (int i=0; i<3; i++) {
|
||||||
if (linRGB <= 0.0031308d) {
|
if (scRGB[i] < 0) {
|
||||||
return (float)(linRGB / 100000d * 12.92d);
|
rgb[i] = 0;
|
||||||
} else {
|
} else if (scRGB[i] <= 0.0031308) {
|
||||||
return (float)(1.055d * Math.pow(linRGB / 100000d, 1.0d/2.4d) - 0.055d);
|
rgb[i] = scRGB[i] * 12.92;
|
||||||
|
} else if (scRGB[i] < 1) {
|
||||||
|
rgb[i] = 1.055 * Math.pow(scRGB[i], 1.0 / 2.4) - 0.055;
|
||||||
|
} else {
|
||||||
|
rgb[i] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return new Color((float)rgb[0],(float)rgb[1],(float)rgb[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void fillPaintWorkaround(Graphics2D graphics, Shape shape) {
|
static void fillPaintWorkaround(Graphics2D graphics, Shape shape) {
|
||||||
// the ibm jdk has a rendering/JIT bug, which throws an AIOOBE in
|
// the ibm jdk has a rendering/JIT bug, which throws an AIOOBE in
|
||||||
// TexturePaintContext$Int.setRaster(TexturePaintContext.java:476)
|
// TexturePaintContext$Int.setRaster(TexturePaintContext.java:476)
|
||||||
|
|
|
@ -111,8 +111,8 @@ public class XSLFColor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color toColor(CTScRgbColor scrgb) {
|
private Color toColor(CTScRgbColor scrgb) {
|
||||||
// color in percentage is in linear RGB color space, i.e. needs to be gamma corrected for AWT color
|
// percental [0..100000] scRGB color space needs to be gamma corrected for AWT/sRGB colorspace
|
||||||
return new Color(DrawPaint.lin2srgb(scrgb.getR()), DrawPaint.lin2srgb(scrgb.getG()), DrawPaint.lin2srgb(scrgb.getB()));
|
return DrawPaint.SCRGB2RGB(scrgb.getR()/100_000d,scrgb.getG()/100_000d,scrgb.getB()/100_000d);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color toColor(CTSRgbColor srgb) {
|
private Color toColor(CTSRgbColor srgb) {
|
||||||
|
@ -225,15 +225,16 @@ public class XSLFColor {
|
||||||
alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
|
alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
|
||||||
} else {
|
} else {
|
||||||
CTScRgbColor rgb = fill.addNewScrgbClr();
|
CTScRgbColor rgb = fill.addNewScrgbClr();
|
||||||
rgb.setR(DrawPaint.srgb2lin(rgbaf[0]));
|
double[] scRGB = DrawPaint.RGB2SCRGB(color);
|
||||||
rgb.setG(DrawPaint.srgb2lin(rgbaf[1]));
|
rgb.setR((int)Math.rint(scRGB[0]*100_000d));
|
||||||
rgb.setB(DrawPaint.srgb2lin(rgbaf[2]));
|
rgb.setG((int)Math.rint(scRGB[1]*100_000d));
|
||||||
|
rgb.setB((int)Math.rint(scRGB[2]*100_000d));
|
||||||
alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
|
alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// alpha (%)
|
// alpha (%)
|
||||||
if (alphaPct != null) {
|
if (alphaPct != null) {
|
||||||
alphaPct.setVal((int)(100000 * rgbaf[3]));
|
alphaPct.setVal((int)Math.rint(rgbaf[3]*100_000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.apache.poi.sl.TestCommonSL.sameColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -139,7 +139,7 @@ public class TestXSLFSlide {
|
||||||
assertEquals(40.0, r1.getFontSize(), 0);
|
assertEquals(40.0, r1.getFontSize(), 0);
|
||||||
assertTrue(r1.isBold());
|
assertTrue(r1.isBold());
|
||||||
assertTrue(r1.isItalic());
|
assertTrue(r1.isItalic());
|
||||||
assertTrue(sameColor(new Color(148, 198, 0), r1.getFontColor()));
|
assertEquals(new Color(148, 198, 0), getColor(r1.getFontColor()));
|
||||||
assertNull(sh1.getFillColor());
|
assertNull(sh1.getFillColor());
|
||||||
assertNull(sh1.getLineColor());
|
assertNull(sh1.getLineColor());
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class TestXSLFSlide {
|
||||||
assertEquals(18.0, r2.getFontSize(), 0);
|
assertEquals(18.0, r2.getFontSize(), 0);
|
||||||
assertFalse(r2.isBold());
|
assertFalse(r2.isBold());
|
||||||
assertFalse(r2.isItalic());
|
assertFalse(r2.isItalic());
|
||||||
assertTrue(sameColor(Color.white, r2.getFontColor()));
|
assertEquals(Color.white, getColor(r2.getFontColor()));
|
||||||
assertEquals(new Color(148, 198, 0), sh2.getFillColor());
|
assertEquals(new Color(148, 198, 0), sh2.getFillColor());
|
||||||
assertEquals(new Color(148, 198, 0), sh2.getLineColor()); // slightly different from PowerPoint!
|
assertEquals(new Color(148, 198, 0), sh2.getLineColor()); // slightly different from PowerPoint!
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ public class TestXSLFSlide {
|
||||||
//assertEquals(32.4.0, r3.getFontSize());
|
//assertEquals(32.4.0, r3.getFontSize());
|
||||||
assertTrue(r3.isBold());
|
assertTrue(r3.isBold());
|
||||||
assertTrue(r3.isItalic());
|
assertTrue(r3.isItalic());
|
||||||
assertTrue(sameColor(new Color(148, 198, 0), r3.getFontColor()));
|
assertEquals(new Color(148, 198, 0), getColor(r3.getFontColor()));
|
||||||
assertNull(sh3.getFillColor());
|
assertNull(sh3.getFillColor());
|
||||||
assertNull(sh3.getLineColor());
|
assertNull(sh3.getLineColor());
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.apache.poi.sl.TestCommonSL.sameColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -285,7 +285,7 @@ public class TestXSLFTextParagraph {
|
||||||
|
|
||||||
assertNull(p.getBulletFontColor());
|
assertNull(p.getBulletFontColor());
|
||||||
p.setBulletFontColor(Color.red);
|
p.setBulletFontColor(Color.red);
|
||||||
assertTrue(sameColor(Color.red, p.getBulletFontColor()));
|
assertEquals(Color.red, getColor(p.getBulletFontColor()));
|
||||||
|
|
||||||
assertNull(p.getBulletFontSize());
|
assertNull(p.getBulletFontSize());
|
||||||
p.setBulletFontSize(200.);
|
p.setBulletFontSize(200.);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.apache.poi.sl.TestCommonSL.sameColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -55,9 +55,9 @@ public class TestXSLFTextRun {
|
||||||
assertEquals(0., r.getCharacterSpacing(), 0);
|
assertEquals(0., r.getCharacterSpacing(), 0);
|
||||||
assertFalse(r.getRPr(true).isSetSpc());
|
assertFalse(r.getRPr(true).isSetSpc());
|
||||||
|
|
||||||
assertTrue(sameColor(Color.black, r.getFontColor()));
|
assertEquals(Color.black, getColor(r.getFontColor()));
|
||||||
r.setFontColor(Color.red);
|
r.setFontColor(Color.red);
|
||||||
assertTrue(sameColor(Color.red, r.getFontColor()));
|
assertEquals(Color.red, getColor(r.getFontColor()));
|
||||||
|
|
||||||
assertEquals("Calibri", r.getFontFamily());
|
assertEquals("Calibri", r.getFontFamily());
|
||||||
r.setFontFamily("Arial");
|
r.setFontFamily("Arial");
|
||||||
|
@ -78,7 +78,7 @@ public class TestXSLFTextRun {
|
||||||
assertTrue(r.isSubscript());
|
assertTrue(r.isSubscript());
|
||||||
r.setSubscript(false);
|
r.setSubscript(false);
|
||||||
assertFalse(r.isSubscript());
|
assertFalse(r.isSubscript());
|
||||||
|
|
||||||
ppt.close();
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.apache.poi.sl.TestCommonSL.sameColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
|
import static org.apache.poi.xslf.usermodel.TestXSLFSimpleShape.getSpPr;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -41,6 +41,7 @@ import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
||||||
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
||||||
import org.apache.poi.xddf.usermodel.text.XDDFBodyProperties;
|
import org.apache.poi.xddf.usermodel.text.XDDFBodyProperties;
|
||||||
import org.apache.poi.xddf.usermodel.text.XDDFTextBody;
|
import org.apache.poi.xddf.usermodel.text.XDDFTextBody;
|
||||||
|
import org.apache.poi.xddf.usermodel.text.XDDFTextParagraph;
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -76,7 +77,7 @@ public class TestXSLFTextShape {
|
||||||
verifySlide7(slide.get(6));
|
verifySlide7(slide.get(6));
|
||||||
verifySlide8(slide.get(7));
|
verifySlide8(slide.get(7));
|
||||||
verifySlide10(slide.get(9));
|
verifySlide10(slide.get(9));
|
||||||
|
|
||||||
ppt.close();
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +119,11 @@ public class TestXSLFTextShape {
|
||||||
// now check text properties
|
// now check text properties
|
||||||
assertEquals("Centered Title", shape1.getText());
|
assertEquals("Centered Title", shape1.getText());
|
||||||
assertEquals("Centered Title",
|
assertEquals("Centered Title",
|
||||||
tb1.getParagraphs().stream().map(p -> p.getText()).collect(Collectors.joining("\n")));
|
tb1.getParagraphs().stream().map(XDDFTextParagraph::getText).collect(Collectors.joining("\n")));
|
||||||
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
assertEquals(44.0, r1.getFontSize(), 0);
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertTrue(sameColor(Color.black, r1.getFontColor()));
|
assertEquals(Color.black, getColor(r1.getFontColor()));
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
XDDFTextBody tb2 = shape2.getTextBody();
|
XDDFTextBody tb2 = shape2.getTextBody();
|
||||||
|
@ -155,7 +156,7 @@ public class TestXSLFTextShape {
|
||||||
assertNull(tbp2.getAnchoring());
|
assertNull(tbp2.getAnchoring());
|
||||||
|
|
||||||
assertEquals("subtitle", shape2.getText());
|
assertEquals("subtitle", shape2.getText());
|
||||||
assertEquals("subtitle", tb2.getParagraphs().stream().map(p -> p.getText()).collect(Collectors.joining("\n")));
|
assertEquals("subtitle", tb2.getParagraphs().stream().map(XDDFTextParagraph::getText).collect(Collectors.joining("\n")));
|
||||||
XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals("Calibri", r2.getFontFamily());
|
assertEquals("Calibri", r2.getFontFamily());
|
||||||
assertEquals(32.0, r2.getFontSize(), 0);
|
assertEquals(32.0, r2.getFontSize(), 0);
|
||||||
|
@ -199,7 +200,7 @@ public class TestXSLFTextShape {
|
||||||
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
assertEquals(44.0, r1.getFontSize(), 0);
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertTrue(sameColor(Color.black, r1.getFontColor()));
|
assertEquals(Color.black, getColor(r1.getFontColor()));
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
CTPlaceholder ph2 = shape2.getPlaceholderDetails().getCTPlaceholder(false);
|
CTPlaceholder ph2 = shape2.getPlaceholderDetails().getCTPlaceholder(false);
|
||||||
|
@ -234,8 +235,8 @@ public class TestXSLFTextShape {
|
||||||
assertEquals("Content", pr1.getRawText());
|
assertEquals("Content", pr1.getRawText());
|
||||||
assertEquals("Calibri", pr1.getFontFamily());
|
assertEquals("Calibri", pr1.getFontFamily());
|
||||||
assertEquals(32.0, pr1.getFontSize(), 0);
|
assertEquals(32.0, pr1.getFontSize(), 0);
|
||||||
assertEquals(27.0, pr1.getParentParagraph().getLeftMargin(), 0);
|
assertEquals(27.0, pr1.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
|
XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
|
||||||
|
@ -310,7 +311,7 @@ public class TestXSLFTextShape {
|
||||||
assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
|
assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
assertEquals(40.0, r1.getFontSize(), 0);
|
assertEquals(40.0, r1.getFontSize(), 0);
|
||||||
assertTrue(sameColor(Color.black, r1.getFontColor()));
|
assertEquals(Color.black, getColor(r1.getFontColor()));
|
||||||
assertTrue(r1.isBold());
|
assertTrue(r1.isBold());
|
||||||
assertFalse(r1.isItalic());
|
assertFalse(r1.isItalic());
|
||||||
assertFalse(r1.isUnderlined());
|
assertFalse(r1.isUnderlined());
|
||||||
|
@ -384,7 +385,7 @@ public class TestXSLFTextShape {
|
||||||
assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
|
assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
assertEquals(44.0, r1.getFontSize(), 0);
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertTrue(sameColor(Color.black, r1.getFontColor()));
|
assertEquals(Color.black, getColor(r1.getFontColor()));
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
CTPlaceholder ph2 = shape2.getPlaceholderDetails().getCTPlaceholder(false);
|
CTPlaceholder ph2 = shape2.getPlaceholderDetails().getCTPlaceholder(false);
|
||||||
|
@ -452,7 +453,7 @@ public class TestXSLFTextShape {
|
||||||
assertEquals(0, pr5.getParentParagraph().getIndentLevel());
|
assertEquals(0, pr5.getParentParagraph().getIndentLevel());
|
||||||
assertEquals("Right", pr5.getRawText());
|
assertEquals("Right", pr5.getRawText());
|
||||||
assertEquals("Calibri", pr5.getFontFamily());
|
assertEquals("Calibri", pr5.getFontFamily());
|
||||||
assertTrue(sameColor(Color.black, pr5.getFontColor()));
|
assertEquals(Color.black, getColor(pr5.getFontColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -460,7 +461,7 @@ public class TestXSLFTextShape {
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
List<XSLFShape> shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySlide7(XSLFSlide slide){
|
void verifySlide7(XSLFSlide slide){
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
|
@ -492,7 +493,7 @@ public class TestXSLFTextShape {
|
||||||
assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
|
assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
assertEquals(44.0, r1.getFontSize(), 0);
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertTrue(sameColor(Color.black, r1.getFontColor()));
|
assertEquals(Color.black, getColor(r1.getFontColor()));
|
||||||
assertFalse(r1.isBold());
|
assertFalse(r1.isBold());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
|
@ -565,7 +566,7 @@ public class TestXSLFTextShape {
|
||||||
assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
|
assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
assertEquals(20.0, r1.getFontSize(), 0);
|
assertEquals(20.0, r1.getFontSize(), 0);
|
||||||
assertTrue(sameColor(Color.black, r1.getFontColor()));
|
assertEquals(Color.black, getColor(r1.getFontColor()));
|
||||||
assertTrue(r1.isBold());
|
assertTrue(r1.isBold());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
|
@ -652,8 +653,7 @@ public class TestXSLFTextShape {
|
||||||
assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
|
assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
assertEquals(12.0, r1.getFontSize(), 0);
|
assertEquals(12.0, r1.getFontSize(), 0);
|
||||||
// TODO calculation of tint might be incorrect
|
assertEquals(new Color(0x898989), getColor(r1.getFontColor()));
|
||||||
assertTrue(sameColor(new Color(191,191,191), r1.getFontColor()));
|
|
||||||
|
|
||||||
XSLFTextShape dt = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_DT);
|
XSLFTextShape dt = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_DT);
|
||||||
assertEquals("Friday, October 21, 2011", dt.getText());
|
assertEquals("Friday, October 21, 2011", dt.getText());
|
||||||
|
@ -741,7 +741,7 @@ public class TestXSLFTextShape {
|
||||||
assertEquals("Calibri", textRun.getFontFamily());
|
assertEquals("Calibri", textRun.getFontFamily());
|
||||||
lv5PPr.setAlgn(STTextAlignType.CTR);
|
lv5PPr.setAlgn(STTextAlignType.CTR);
|
||||||
assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
|
assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
|
||||||
|
|
||||||
ppt.close();
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,10 +945,10 @@ public class TestXSLFTextShape {
|
||||||
assertEquals("Calibri", r3.getFontFamily());
|
assertEquals("Calibri", r3.getFontFamily());
|
||||||
lv3PPr.setAlgn(STTextAlignType.CTR);
|
lv3PPr.setAlgn(STTextAlignType.CTR);
|
||||||
assertEquals(TextAlign.CENTER, p3.getTextAlign());
|
assertEquals(TextAlign.CENTER, p3.getTextAlign());
|
||||||
|
|
||||||
ppt.close();
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void metroBlob() throws IOException, ReflectiveOperationException {
|
public void metroBlob() throws IOException, ReflectiveOperationException {
|
||||||
assumeFalse(xslfOnly);
|
assumeFalse(xslfOnly);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.apache.poi.sl.TestCommonSL.sameColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -72,7 +72,7 @@ public class TestXSLFTheme {
|
||||||
|
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 3");
|
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 3");
|
||||||
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(Color.white, run1.getFontColor()));
|
assertEquals(Color.white, getColor(run1.getFontColor()));
|
||||||
assertEquals(new Color(79, 129, 189), sh1.getFillColor());
|
assertEquals(new Color(79, 129, 189), sh1.getFillColor());
|
||||||
assertTrue(sh1.getFillStyle().getPaint() instanceof SolidPaint) ; // solid fill
|
assertTrue(sh1.getFillStyle().getPaint() instanceof SolidPaint) ; // solid fill
|
||||||
|
|
||||||
|
@ -95,13 +95,13 @@ public class TestXSLFTheme {
|
||||||
|
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 4");
|
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 4");
|
||||||
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(Color.white, run1.getFontColor()));
|
assertEquals(Color.white, getColor(run1.getFontColor()));
|
||||||
assertEquals(new Color(148, 198, 0), sh1.getFillColor());
|
assertEquals(new Color(148, 198, 0), sh1.getFillColor());
|
||||||
assertTrue(sh1.getFillStyle().getPaint() instanceof SolidPaint) ; // solid fill
|
assertTrue(sh1.getFillStyle().getPaint() instanceof SolidPaint) ; // solid fill
|
||||||
|
|
||||||
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 3");
|
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 3");
|
||||||
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));
|
assertEquals(new Color(148, 198, 0), getColor(run2.getFontColor()));
|
||||||
assertNull(sh2.getFillColor()); // no fill
|
assertNull(sh2.getFillColor()); // no fill
|
||||||
|
|
||||||
assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
|
assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
|
||||||
|
@ -113,7 +113,7 @@ public class TestXSLFTheme {
|
||||||
|
|
||||||
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 1");
|
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 1");
|
||||||
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));
|
assertEquals(new Color(148, 198, 0), getColor(run2.getFontColor()));
|
||||||
assertNull(sh2.getFillColor()); // no fill
|
assertNull(sh2.getFillColor()); // no fill
|
||||||
// font size is 40pt and scale factor is 90%
|
// font size is 40pt and scale factor is 90%
|
||||||
assertEquals(36.0, run2.getFontSize(), 0);
|
assertEquals(36.0, run2.getFontSize(), 0);
|
||||||
|
@ -125,12 +125,12 @@ public class TestXSLFTheme {
|
||||||
|
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Subtitle 3");
|
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Subtitle 3");
|
||||||
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(new Color(66, 66, 66), run1.getFontColor()));
|
assertEquals(new Color(66, 66, 66), getColor(run1.getFontColor()));
|
||||||
assertNull(sh1.getFillColor()); // no fill
|
assertNull(sh1.getFillColor()); // no fill
|
||||||
|
|
||||||
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 2");
|
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 2");
|
||||||
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(new Color(148, 198, 0), run2.getFontColor()));
|
assertEquals(new Color(148, 198, 0), getColor(run2.getFontColor()));
|
||||||
assertNull(sh2.getFillColor()); // no fill
|
assertNull(sh2.getFillColor()); // no fill
|
||||||
|
|
||||||
assertFalse(slide.getSlideLayout().getFollowMasterGraphics());
|
assertFalse(slide.getSlideLayout().getFollowMasterGraphics());
|
||||||
|
@ -160,12 +160,12 @@ public class TestXSLFTheme {
|
||||||
|
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Title 3");
|
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Title 3");
|
||||||
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(Color.white, run1.getFontColor()));
|
assertEquals(Color.white, getColor(run1.getFontColor()));
|
||||||
assertNull(sh1.getFillColor()); // no fill
|
assertNull(sh1.getFillColor()); // no fill
|
||||||
|
|
||||||
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Subtitle 4");
|
XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Subtitle 4");
|
||||||
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertTrue(sameColor(Color.white, run2.getFontColor()));
|
assertEquals(Color.white, getColor(run2.getFontColor()));
|
||||||
assertNull(sh2.getFillColor()); // no fill
|
assertNull(sh2.getFillColor()); // no fill
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import static org.apache.poi.sl.TestCommonSL.sameColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -70,15 +70,10 @@ public final class TestShapes {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
InputStream is1 = null, is2 = null;
|
try (InputStream is1 = _slTests.openResourceAsStream("empty.ppt");
|
||||||
try {
|
InputStream is2 = _slTests.openResourceAsStream("empty_textbox.ppt")) {
|
||||||
is1 = _slTests.openResourceAsStream("empty.ppt");
|
|
||||||
ppt = new HSLFSlideShow(is1);
|
ppt = new HSLFSlideShow(is1);
|
||||||
is2 = _slTests.openResourceAsStream("empty_textbox.ppt");
|
|
||||||
pptB = new HSLFSlideShow(is2);
|
pptB = new HSLFSlideShow(is2);
|
||||||
} finally {
|
|
||||||
is1.close();
|
|
||||||
is2.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,13 +116,12 @@ public final class TestShapes {
|
||||||
|
|
||||||
assertTrue(shape.get(1) instanceof HSLFAutoShape); //group shape
|
assertTrue(shape.get(1) instanceof HSLFAutoShape); //group shape
|
||||||
assertEquals(ellipseAnchor, shape.get(1).getAnchor()); //group shape
|
assertEquals(ellipseAnchor, shape.get(1).getAnchor()); //group shape
|
||||||
|
|
||||||
ppt2.close();
|
ppt2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify that we can read TextBox shapes
|
* Verify that we can read TextBox shapes
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void textBoxRead() throws IOException {
|
public void textBoxRead() throws IOException {
|
||||||
|
@ -142,20 +136,29 @@ public final class TestShapes {
|
||||||
assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
|
assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
|
||||||
HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
|
HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
|
|
||||||
if (text.equals("Hello, World!!!")){
|
switch (text) {
|
||||||
assertEquals(32, rt.getFontSize(), 0);
|
case "Hello, World!!!":
|
||||||
assertTrue(rt.isBold());
|
assertNotNull(rt.getFontSize());
|
||||||
assertTrue(rt.isItalic());
|
assertEquals(32, rt.getFontSize(), 0);
|
||||||
} else if (text.equals("I am just a poor boy")){
|
assertTrue(rt.isBold());
|
||||||
assertEquals(44, rt.getFontSize(), 0);
|
assertTrue(rt.isItalic());
|
||||||
assertTrue(rt.isBold());
|
break;
|
||||||
} else if (text.equals("This is Times New Roman")){
|
case "I am just a poor boy":
|
||||||
assertEquals(16, rt.getFontSize(), 0);
|
assertNotNull(rt.getFontSize());
|
||||||
assertTrue(rt.isBold());
|
assertEquals(44, rt.getFontSize(), 0);
|
||||||
assertTrue(rt.isItalic());
|
assertTrue(rt.isBold());
|
||||||
assertTrue(rt.isUnderlined());
|
break;
|
||||||
} else if (text.equals("Plain Text")){
|
case "This is Times New Roman":
|
||||||
assertEquals(18, rt.getFontSize(), 0);
|
assertNotNull(rt.getFontSize());
|
||||||
|
assertEquals(16, rt.getFontSize(), 0);
|
||||||
|
assertTrue(rt.isBold());
|
||||||
|
assertTrue(rt.isItalic());
|
||||||
|
assertTrue(rt.isUnderlined());
|
||||||
|
break;
|
||||||
|
case "Plain Text":
|
||||||
|
assertNotNull(rt.getFontSize());
|
||||||
|
assertEquals(18, rt.getFontSize(), 0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,30 +182,30 @@ public final class TestShapes {
|
||||||
shape.setAnchor(new Rectangle2D.Double(100,100,100,10));
|
shape.setAnchor(new Rectangle2D.Double(100,100,100,10));
|
||||||
slide.addShape(shape);
|
slide.addShape(shape);
|
||||||
shape.resizeToFitText();
|
shape.resizeToFitText();
|
||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
ss.write(bos);
|
ss.write(bos);
|
||||||
|
|
||||||
ss = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
|
ss = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
|
||||||
slide = ss.getSlides().get(0);
|
slide = ss.getSlides().get(0);
|
||||||
HSLFTextBox tb = (HSLFTextBox)slide.getShapes().get(0);
|
HSLFTextBox tb = (HSLFTextBox)slide.getShapes().get(0);
|
||||||
List<HSLFTextParagraph> para = tb.getTextParagraphs();
|
List<HSLFTextParagraph> para = tb.getTextParagraphs();
|
||||||
HSLFTextRun tr = para.get(0).getTextRuns().get(0);
|
HSLFTextRun tr = para.get(0).getTextRuns().get(0);
|
||||||
assertEquals("para 1 run 1. ", tr.getRawText());
|
assertEquals("para 1 run 1. ", tr.getRawText());
|
||||||
assertTrue(sameColor(Color.black, tr.getFontColor()));
|
assertEquals(Color.black, getColor(tr.getFontColor()));
|
||||||
tr = para.get(0).getTextRuns().get(1);
|
tr = para.get(0).getTextRuns().get(1);
|
||||||
assertEquals("para 1 run 2.\r", tr.getRawText());
|
assertEquals("para 1 run 2.\r", tr.getRawText());
|
||||||
assertTrue(sameColor(Color.red, tr.getFontColor()));
|
assertEquals(Color.red, getColor(tr.getFontColor()));
|
||||||
tr = para.get(1).getTextRuns().get(0);
|
tr = para.get(1).getTextRuns().get(0);
|
||||||
assertEquals("para 2 run 1. ", tr.getRawText());
|
assertEquals("para 2 run 1. ", tr.getRawText());
|
||||||
assertTrue(sameColor(Color.yellow, tr.getFontColor()));
|
assertEquals(Color.yellow, getColor(tr.getFontColor()));
|
||||||
tr = para.get(1).getTextRuns().get(1);
|
tr = para.get(1).getTextRuns().get(1);
|
||||||
assertEquals("para 2 run 2. para 2 run 3.", tr.getRawText());
|
assertEquals("para 2 run 2. para 2 run 3.", tr.getRawText());
|
||||||
assertTrue(sameColor(Color.black, tr.getFontColor()));
|
assertEquals(Color.black, getColor(tr.getFontColor()));
|
||||||
assertTrue(tr.isStrikethrough());
|
assertTrue(tr.isStrikethrough());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify that we can add TextBox shapes to a slide
|
* Verify that we can add TextBox shapes to a slide
|
||||||
* and set some of the style attributes
|
* and set some of the style attributes
|
||||||
|
@ -230,12 +233,13 @@ public final class TestShapes {
|
||||||
// Check it before save
|
// Check it before save
|
||||||
rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
|
rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(val, rt.getRawText());
|
assertEquals(val, rt.getRawText());
|
||||||
|
assertNotNull(rt.getFontSize());
|
||||||
assertEquals(42, rt.getFontSize(), 0);
|
assertEquals(42, rt.getFontSize(), 0);
|
||||||
assertTrue(rt.isBold());
|
assertTrue(rt.isBold());
|
||||||
assertTrue(rt.isItalic());
|
assertTrue(rt.isItalic());
|
||||||
assertFalse(rt.isUnderlined());
|
assertFalse(rt.isUnderlined());
|
||||||
assertEquals("Arial", rt.getFontFamily());
|
assertEquals("Arial", rt.getFontFamily());
|
||||||
assertTrue(sameColor(Color.red, rt.getFontColor()));
|
assertEquals(Color.red, getColor(rt.getFontColor()));
|
||||||
|
|
||||||
// Serialize and read again
|
// Serialize and read again
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
@ -250,13 +254,14 @@ public final class TestShapes {
|
||||||
|
|
||||||
// Check after save
|
// Check after save
|
||||||
assertEquals(val, rt.getRawText());
|
assertEquals(val, rt.getRawText());
|
||||||
|
assertNotNull(rt.getFontSize());
|
||||||
assertEquals(42, rt.getFontSize(), 0);
|
assertEquals(42, rt.getFontSize(), 0);
|
||||||
assertTrue(rt.isBold());
|
assertTrue(rt.isBold());
|
||||||
assertTrue(rt.isItalic());
|
assertTrue(rt.isItalic());
|
||||||
assertFalse(rt.isUnderlined());
|
assertFalse(rt.isUnderlined());
|
||||||
assertEquals("Arial", rt.getFontFamily());
|
assertEquals("Arial", rt.getFontFamily());
|
||||||
assertTrue(sameColor(Color.red, rt.getFontColor()));
|
assertEquals(Color.red, getColor(rt.getFontColor()));
|
||||||
|
|
||||||
ppt2.close();
|
ppt2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +373,7 @@ public final class TestShapes {
|
||||||
|
|
||||||
line = (HSLFLine)grshape.get(1);
|
line = (HSLFLine)grshape.get(1);
|
||||||
assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
|
assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
|
||||||
|
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +426,6 @@ public final class TestShapes {
|
||||||
public void shapeId() throws IOException {
|
public void shapeId() throws IOException {
|
||||||
HSLFSlideShow ss = new HSLFSlideShow();
|
HSLFSlideShow ss = new HSLFSlideShow();
|
||||||
HSLFSlide slide = ss.createSlide();
|
HSLFSlide slide = ss.createSlide();
|
||||||
HSLFShape shape = null;
|
|
||||||
|
|
||||||
//EscherDgg is a document-level record which keeps track of the drawing groups
|
//EscherDgg is a document-level record which keeps track of the drawing groups
|
||||||
EscherDggRecord dgg = ss.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
|
EscherDggRecord dgg = ss.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
|
||||||
|
@ -434,7 +438,7 @@ public final class TestShapes {
|
||||||
int dgShapesUsed = dg.getNumShapes(); // number of shapes in the slide
|
int dgShapesUsed = dg.getNumShapes(); // number of shapes in the slide
|
||||||
//insert 3 shapes and make sure the Ids are properly incremented
|
//insert 3 shapes and make sure the Ids are properly incremented
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
shape = new HSLFLine();
|
HSLFShape shape = new HSLFLine();
|
||||||
assertEquals(0, shape.getShapeId());
|
assertEquals(0, shape.getShapeId());
|
||||||
slide.addShape(shape);
|
slide.addShape(shape);
|
||||||
assertTrue(shape.getShapeId() > 0);
|
assertTrue(shape.getShapeId() > 0);
|
||||||
|
@ -461,7 +465,7 @@ public final class TestShapes {
|
||||||
//make sure it is so
|
//make sure it is so
|
||||||
int numClusters = dgg.getNumIdClusters();
|
int numClusters = dgg.getNumIdClusters();
|
||||||
for (int i = 0; i < 1025; i++) {
|
for (int i = 0; i < 1025; i++) {
|
||||||
shape = new HSLFLine();
|
HSLFShape shape = new HSLFLine();
|
||||||
slide.addShape(shape);
|
slide.addShape(shape);
|
||||||
}
|
}
|
||||||
assertEquals(numClusters + 1, dgg.getNumIdClusters());
|
assertEquals(numClusters + 1, dgg.getNumIdClusters());
|
||||||
|
@ -492,7 +496,7 @@ public final class TestShapes {
|
||||||
assertEquals("Border width is 5 pt", sh4.getText());
|
assertEquals("Border width is 5 pt", sh4.getText());
|
||||||
assertEquals(Color.black, sh4.getLineColor());
|
assertEquals(Color.black, sh4.getLineColor());
|
||||||
assertEquals(5.0, sh4.getLineWidth(), 0);
|
assertEquals(5.0, sh4.getLineWidth(), 0);
|
||||||
|
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
package org.apache.poi.hslf.usermodel;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import static org.apache.poi.sl.TestCommonSL.sameColor;
|
import static org.apache.poi.sl.TestCommonSL.getColor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -31,7 +31,6 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.hslf.HSLFTestDataSamples;
|
import org.apache.poi.hslf.HSLFTestDataSamples;
|
||||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||||
import org.apache.poi.hslf.record.Record;
|
|
||||||
import org.apache.poi.hslf.record.TextBytesAtom;
|
import org.apache.poi.hslf.record.TextBytesAtom;
|
||||||
import org.apache.poi.hslf.record.TextCharsAtom;
|
import org.apache.poi.hslf.record.TextCharsAtom;
|
||||||
import org.apache.poi.hslf.record.TextHeaderAtom;
|
import org.apache.poi.hslf.record.TextHeaderAtom;
|
||||||
|
@ -42,6 +41,7 @@ import org.junit.Test;
|
||||||
/**
|
/**
|
||||||
* Tests for TextRuns
|
* Tests for TextRuns
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("UnusedAssignment")
|
||||||
public final class TestTextRun {
|
public final class TestTextRun {
|
||||||
// SlideShow primed on the test data
|
// SlideShow primed on the test data
|
||||||
private HSLFSlideShow ss;
|
private HSLFSlideShow ss;
|
||||||
|
@ -61,7 +61,7 @@ public final class TestTextRun {
|
||||||
ssRich.close();
|
ssRich.close();
|
||||||
ss.close();
|
ss.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to ensure that getting the text works correctly
|
* Test to ensure that getting the text works correctly
|
||||||
*/
|
*/
|
||||||
|
@ -125,7 +125,7 @@ public final class TestTextRun {
|
||||||
HSLFSlide slideOne = ss.getSlides().get(0);
|
HSLFSlide slideOne = ss.getSlides().get(0);
|
||||||
List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0);
|
List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0);
|
||||||
HSLFTextParagraph para = paras.get(0);
|
HSLFTextParagraph para = paras.get(0);
|
||||||
|
|
||||||
TextHeaderAtom tha = null;
|
TextHeaderAtom tha = null;
|
||||||
TextBytesAtom tba = null;
|
TextBytesAtom tba = null;
|
||||||
TextCharsAtom tca = null;
|
TextCharsAtom tca = null;
|
||||||
|
@ -150,14 +150,12 @@ public final class TestTextRun {
|
||||||
else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
|
else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
|
||||||
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
|
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
|
assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
|
||||||
assertNull(tca);
|
assertNull(tca);
|
||||||
assertNotNull(tba);
|
assertNotNull(tba);
|
||||||
|
|
||||||
// Bytes -> Chars
|
// Bytes -> Chars
|
||||||
assertNull(tca);
|
|
||||||
assertNotNull(tba);
|
|
||||||
assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
|
assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
|
||||||
|
|
||||||
String changeByteChar = "This is a test title with a '\u0121' g with a dot";
|
String changeByteChar = "This is a test title with a '\u0121' g with a dot";
|
||||||
|
@ -168,14 +166,13 @@ public final class TestTextRun {
|
||||||
if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
|
if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
|
||||||
else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
|
else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
|
||||||
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
|
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
|
assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
|
||||||
assertNotNull(tca);
|
assertNotNull(tca);
|
||||||
assertNull(tba);
|
assertNull(tba);
|
||||||
|
|
||||||
// Chars -> Chars
|
// Chars -> Chars
|
||||||
assertNull(tba);
|
|
||||||
assertNotNull(tca);
|
assertNotNull(tca);
|
||||||
assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
|
assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
|
||||||
|
|
||||||
|
@ -187,7 +184,7 @@ public final class TestTextRun {
|
||||||
if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
|
if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
|
||||||
else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
|
else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
|
||||||
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
|
else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(changeCharChar, HSLFTextParagraph.getRawText(paras));
|
assertEquals(changeCharChar, HSLFTextParagraph.getRawText(paras));
|
||||||
assertNotNull(tca);
|
assertNotNull(tca);
|
||||||
|
@ -445,7 +442,7 @@ public final class TestTextRun {
|
||||||
HSLFSlide sl = ppt.getSlides().get(0);
|
HSLFSlide sl = ppt.getSlides().get(0);
|
||||||
List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
|
List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
|
||||||
assertEquals(2, textParass.size());
|
assertEquals(2, textParass.size());
|
||||||
|
|
||||||
List<HSLFTextParagraph> textParas = textParass.get(0);
|
List<HSLFTextParagraph> textParas = textParass.get(0);
|
||||||
rt = textParass.get(0).get(0).getTextRuns();
|
rt = textParass.get(0).get(0).getTextRuns();
|
||||||
assertEquals(1, rt.size());
|
assertEquals(1, rt.size());
|
||||||
|
@ -541,7 +538,7 @@ public final class TestTextRun {
|
||||||
// tx.storeText();
|
// tx.storeText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
||||||
for(HSLFSlide slide : ppt2.getSlides()){
|
for(HSLFSlide slide : ppt2.getSlides()){
|
||||||
for(HSLFShape sh : slide.getShapes()){
|
for(HSLFShape sh : slide.getShapes()){
|
||||||
|
@ -550,7 +547,7 @@ public final class TestTextRun {
|
||||||
List<HSLFTextParagraph> run = tx.getTextParagraphs();
|
List<HSLFTextParagraph> run = tx.getTextParagraphs();
|
||||||
HSLFTextRun rt = run.get(0).getTextRuns().get(0);
|
HSLFTextRun rt = run.get(0).getTextRuns().get(0);
|
||||||
assertTrue(rt.isBold());
|
assertTrue(rt.isBold());
|
||||||
assertTrue(sameColor(Color.RED, rt.getFontColor()));
|
assertEquals(Color.RED, getColor(rt.getFontColor()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,11 +561,13 @@ public final class TestTextRun {
|
||||||
HSLFSlide slide = ppt.getSlides().get(0);
|
HSLFSlide slide = ppt.getSlides().get(0);
|
||||||
|
|
||||||
int[] sizes = {36, 24, 12, 32, 12, 12};
|
int[] sizes = {36, 24, 12, 32, 12, 12};
|
||||||
|
|
||||||
int i=0;
|
int i=0;
|
||||||
for (List<HSLFTextParagraph> textParas : slide.getTextParagraphs()) {
|
for (List<HSLFTextParagraph> textParas : slide.getTextParagraphs()) {
|
||||||
assertEquals("Arial", textParas.get(0).getTextRuns().get(0).getFontFamily());
|
HSLFTextRun first = textParas.get(0).getTextRuns().get(0);
|
||||||
assertEquals(sizes[i++], textParas.get(0).getTextRuns().get(0).getFontSize().intValue());
|
assertEquals("Arial", first.getFontFamily());
|
||||||
|
assertNotNull(first.getFontSize());
|
||||||
|
assertEquals(sizes[i++], first.getFontSize().intValue());
|
||||||
}
|
}
|
||||||
ppt.close();
|
ppt.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,10 @@ import org.junit.Ignore;
|
||||||
@Ignore
|
@Ignore
|
||||||
public class TestCommonSL {
|
public class TestCommonSL {
|
||||||
|
|
||||||
public static boolean sameColor(Color colorExpected, PaintStyle paintActual) {
|
public static Color getColor(PaintStyle paintActual) {
|
||||||
if (!(paintActual instanceof SolidPaint)) return false;
|
return (paintActual instanceof SolidPaint)
|
||||||
Color thisC = DrawPaint.applyColorTransform(((SolidPaint)paintActual).getSolidColor());
|
? DrawPaint.applyColorTransform(((SolidPaint)paintActual).getSolidColor())
|
||||||
return thisC.equals(colorExpected);
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue