#45908 - RichTextRun.setBullet(false) doesn't work, bullets still here

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711858 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-11-01 22:52:49 +00:00
parent 4bf040e711
commit 37236f2b52
4 changed files with 121 additions and 15 deletions

View File

@ -90,6 +90,11 @@ import org.apache.poi.util.Units;
* @author Yegor kozlov * @author Yegor kozlov
*/ */
public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable { public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable {
enum LoadSavePhase {
INIT, LOADED;
}
private static ThreadLocal<LoadSavePhase> loadSavePhase = new ThreadLocal<LoadSavePhase>();
// What we're based on // What we're based on
private HSLFSlideShowImpl _hslfSlideShow; private HSLFSlideShowImpl _hslfSlideShow;
@ -127,6 +132,8 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
* @param hslfSlideShow the HSLFSlideShow to base on * @param hslfSlideShow the HSLFSlideShow to base on
*/ */
public HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow) { public HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow) {
loadSavePhase.set(LoadSavePhase.INIT);
// Get useful things from our base slideshow // Get useful things from our base slideshow
_hslfSlideShow = hslfSlideShow; _hslfSlideShow = hslfSlideShow;
@ -142,6 +149,8 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
// Build up the model level Slides and Notes // Build up the model level Slides and Notes
buildSlidesAndNotes(); buildSlidesAndNotes();
loadSavePhase.set(LoadSavePhase.LOADED);
} }
/** /**
@ -154,6 +163,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
/** /**
* Constructs a Powerpoint document from an input stream. * Constructs a Powerpoint document from an input stream.
*/ */
@SuppressWarnings("resource")
public HSLFSlideShow(InputStream inputStream) throws IOException { public HSLFSlideShow(InputStream inputStream) throws IOException {
this(new HSLFSlideShowImpl(inputStream)); this(new HSLFSlideShowImpl(inputStream));
} }
@ -161,6 +171,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
/** /**
* Constructs a Powerpoint document from an POIFSFileSystem. * Constructs a Powerpoint document from an POIFSFileSystem.
*/ */
@SuppressWarnings("resource")
public HSLFSlideShow(NPOIFSFileSystem npoifs) throws IOException { public HSLFSlideShow(NPOIFSFileSystem npoifs) throws IOException {
this(new HSLFSlideShowImpl(npoifs)); this(new HSLFSlideShowImpl(npoifs));
} }
@ -168,10 +179,18 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
/** /**
* Constructs a Powerpoint document from an DirectoryNode. * Constructs a Powerpoint document from an DirectoryNode.
*/ */
@SuppressWarnings("resource")
public HSLFSlideShow(DirectoryNode root) throws IOException { public HSLFSlideShow(DirectoryNode root) throws IOException {
this(new HSLFSlideShowImpl(root)); this(new HSLFSlideShowImpl(root));
} }
/**
* @return the current loading/saving phase
*/
protected static LoadSavePhase getLoadSavePhase() {
return loadSavePhase.get();
}
/** /**
* Use the PersistPtrHolder entries to figure out what is the "most recent" * Use the PersistPtrHolder entries to figure out what is the "most recent"
* version of all the core records (Document, Notes, Slide etc), and save a * version of all the core records (Document, Notes, Slide etc), and save a
@ -454,8 +473,17 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
public void write(OutputStream out) throws IOException { public void write(OutputStream out) throws IOException {
// check for text paragraph modifications // check for text paragraph modifications
for (HSLFSlide sl : getSlides()) { for (HSLFSlide sl : getSlides()) {
for (HSLFShape sh : sl.getShapes()) { writeDirtyParagraphs(sl);
if (!(sh instanceof HSLFTextShape)) continue; }
_hslfSlideShow.write(out);
}
private void writeDirtyParagraphs(HSLFShapeContainer container) {
for (HSLFShape sh : container.getShapes()) {
if (sh instanceof HSLFShapeContainer) {
writeDirtyParagraphs((HSLFShapeContainer)sh);
} else if (sh instanceof HSLFTextShape) {
HSLFTextShape hts = (HSLFTextShape)sh; HSLFTextShape hts = (HSLFTextShape)sh;
boolean isDirty = false; boolean isDirty = false;
for (HSLFTextParagraph p : hts.getTextParagraphs()) { for (HSLFTextParagraph p : hts.getTextParagraphs()) {
@ -464,9 +492,6 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
if (isDirty) hts.storeText(); if (isDirty) hts.storeText();
} }
} }
_hslfSlideShow.write(out);
} }
/* /*

View File

@ -21,6 +21,7 @@ import static org.apache.poi.hslf.usermodel.HSLFTextParagraph.getPropVal;
import java.awt.Color; import java.awt.Color;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.hslf.model.textproperties.BitMaskTextProp; import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp; import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
import org.apache.poi.hslf.model.textproperties.TextProp; import org.apache.poi.hslf.model.textproperties.TextProp;
@ -97,7 +98,16 @@ public final class HSLFTextRun implements TextRun {
* Change the text * Change the text
*/ */
public void setText(String text) { public void setText(String text) {
_runText = HSLFTextParagraph.toInternalString(text); if (text == null) {
throw new HSLFException("text must not be null");
}
String newText = HSLFTextParagraph.toInternalString(text);
if (!newText.equals(_runText)) {
_runText = newText;
if (HSLFSlideShow.getLoadSavePhase() == HSLFSlideShow.LoadSavePhase.LOADED) {
parentParagraph.setDirty();
}
}
} }
// --------------- Internal helpers on rich text properties ------- // --------------- Internal helpers on rich text properties -------
@ -275,6 +285,7 @@ public final class HSLFTextRun implements TextRun {
@Override @Override
public void setFontFamily(String fontFamily) { public void setFontFamily(String fontFamily) {
HSLFSheet sheet = parentParagraph.getSheet(); HSLFSheet sheet = parentParagraph.getSheet();
@SuppressWarnings("resource")
HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow(); HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow();
if (sheet == null || slideShow == null) { if (sheet == null || slideShow == null) {
//we can't set font since slideshow is not assigned yet //we can't set font since slideshow is not assigned yet
@ -289,6 +300,7 @@ public final class HSLFTextRun implements TextRun {
@Override @Override
public String getFontFamily() { public String getFontFamily() {
HSLFSheet sheet = parentParagraph.getSheet(); HSLFSheet sheet = parentParagraph.getSheet();
@SuppressWarnings("resource")
HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow(); HSLFSlideShow slideShow = (sheet == null) ? null : sheet.getSlideShow();
if (sheet == null || slideShow == null) { if (sheet == null || slideShow == null) {
return _fontFamily; return _fontFamily;

View File

@ -26,7 +26,6 @@ import java.awt.Color;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -49,7 +48,6 @@ import org.apache.poi.hslf.record.Document;
import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.SlideListWithText; import org.apache.poi.hslf.record.SlideListWithText;
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet; import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
import org.apache.poi.hslf.record.StyleTextPropAtom;
import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.sl.draw.DrawPaint; import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PaintStyle; import org.apache.poi.sl.usermodel.PaintStyle;
@ -719,4 +717,75 @@ public final class TestBugs {
assertEquals(textExp, textAct); assertEquals(textExp, textAct);
ppt2.close(); ppt2.close();
} }
@Test
public void bug45908() throws IOException {
HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug45908.ppt"));
HSLFSlide slide = ppt1.getSlides().get(0);
HSLFAutoShape styleShape = (HSLFAutoShape)slide.getShapes().get(1);
HSLFTextParagraph tp0 = styleShape.getTextParagraphs().get(0);
HSLFTextRun tr0 = tp0.getTextRuns().get(0);
int rows = 5;
int cols = 2;
HSLFTable table = slide.createTable(rows, cols);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
HSLFTableCell cell = table.getCell(i, j);
cell.setText("Test");
HSLFTextParagraph tp = cell.getTextParagraphs().get(0);
tp.setBulletStyle('%', tp0.getBulletColor(), tp0.getBulletFont(), tp0.getBulletSize());
tp.setIndent(tp0.getIndent());
tp.setAlignment(tp0.getTextAlign());
tp.setIndentLevel(tp0.getIndentLevel());
tp.setSpaceAfter(tp0.getSpaceAfter());
tp.setSpaceBefore(tp0.getSpaceBefore());
tp.setBulletStyle();
HSLFTextRun tr = tp.getTextRuns().get(0);
tr.setBold(tr0.isBold());
// rt.setEmbossed();
tr.setFontColor(Color.BLACK);
tr.setFontFamily(tr0.getFontFamily());
tr.setFontSize(tr0.getFontSize());
tr.setItalic(tr0.isItalic());
tr.setShadowed(tr0.isShadowed());
tr.setStrikethrough(tr0.isStrikethrough());
tr.setUnderlined(tr0.isUnderlined());
}
}
table.moveTo(100, 100);
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
ppt1.close();
HSLFTable tab = (HSLFTable)ppt2.getSlides().get(0).getShapes().get(2);
HSLFTableCell c2 = tab.getCell(0, 0);
HSLFTextParagraph tp1 = c2.getTextParagraphs().get(0);
HSLFTextRun tr1 = tp1.getTextRuns().get(0);
assertFalse(tp1.isBullet());
assertEquals(tp0.getBulletColor(), tp1.getBulletColor());
assertEquals(tp0.getBulletFont(), tp1.getBulletFont());
assertEquals(tp0.getBulletSize(), tp1.getBulletSize());
assertEquals(tp0.getIndent(), tp1.getIndent());
assertEquals(tp0.getTextAlign(), tp1.getTextAlign());
assertEquals(tp0.getIndentLevel(), tp1.getIndentLevel());
assertEquals(tp0.getSpaceAfter(), tp1.getSpaceAfter());
assertEquals(tp0.getSpaceBefore(), tp1.getSpaceBefore());
assertEquals(tr0.isBold(), tr1.isBold());
assertEquals(Color.black, DrawPaint.applyColorTransform(tr1.getFontColor().getSolidColor()));
assertEquals(tr0.getFontFamily(), tr1.getFontFamily());
assertEquals(tr0.getFontSize(), tr1.getFontSize());
assertEquals(tr0.isItalic(), tr1.isItalic());
assertEquals(tr0.isShadowed(), tr1.isShadowed());
assertEquals(tr0.isStrikethrough(), tr1.isStrikethrough());
assertEquals(tr0.isUnderlined(), tr1.isUnderlined());
ppt2.close();
}
} }

Binary file not shown.