committing intermediate results - hslf is mostly migrated to common interface - junit tests partly fail - still a few compile errors - xslf drawing works - hslf drawing is not yet tested
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1676365 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
652211b8d2
commit
e6413c3fe7
@ -60,22 +60,22 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
|
||||||
tr1.setText("POI-HSLF");
|
tr1.setText("POI-HSLF");
|
||||||
box1.setAnchor(new Rectangle(54, 78, 612, 115));
|
box1.setAnchor(new Rectangle(54, 78, 612, 115));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
|
tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
|
||||||
tr2.setText("Java API To Access Microsoft PowerPoint Format Files");
|
tr2.setText("Java API To Access Microsoft PowerPoint Format Files");
|
||||||
box2.setAnchor(new Rectangle(108, 204, 504, 138));
|
box2.setAnchor(new Rectangle(108, 204, 504, 138));
|
||||||
slide.addShape(box2);
|
slide.addShape(box2);
|
||||||
|
|
||||||
HSLFTextBox box3 = new HSLFTextBox();
|
HSLFTextBox box3 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr3 = box3.getTextParagraph();
|
HSLFTextParagraph tr3 = box3.getTextParagraphs();
|
||||||
tr3.getRichTextRuns()[0].setFontSize(32);
|
tr3.getTextRuns()[0].setFontSize(32);
|
||||||
box3.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
box3.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
||||||
tr3.setText(
|
tr3.setText(
|
||||||
"Yegor Kozlov\r" +
|
"Yegor Kozlov\r" +
|
||||||
@ -88,14 +88,14 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
||||||
tr1.setText("What is HSLF?");
|
tr1.setText("What is HSLF?");
|
||||||
box1.setAnchor(new Rectangle(36, 21, 648, 90));
|
box1.setAnchor(new Rectangle(36, 21, 648, 90));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +
|
tr2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +
|
||||||
"of the Powerpoint binary file format. \r" +
|
"of the Powerpoint binary file format. \r" +
|
||||||
@ -111,25 +111,25 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
||||||
tr1.setText("HSLF in a Nutshell");
|
tr1.setText("HSLF in a Nutshell");
|
||||||
box1.setAnchor(new Rectangle(36, 15, 648, 65));
|
box1.setAnchor(new Rectangle(36, 15, 648, 65));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr2.setText(
|
tr2.setText(
|
||||||
"HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +
|
"HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +
|
||||||
"Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +
|
"Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +
|
||||||
"Comprehensive support of PowerPoint objects");
|
"Comprehensive support of PowerPoint objects");
|
||||||
tr2.getRichTextRuns()[0].setFontSize(28);
|
tr2.getTextRuns()[0].setFontSize(28);
|
||||||
box2.setAnchor(new Rectangle(36, 80, 648, 200));
|
box2.setAnchor(new Rectangle(36, 80, 648, 200));
|
||||||
slide.addShape(box2);
|
slide.addShape(box2);
|
||||||
|
|
||||||
HSLFTextBox box3 = new HSLFTextBox();
|
HSLFTextBox box3 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr3 = box3.getTextParagraph();
|
HSLFTextParagraph tr3 = box3.getTextParagraphs();
|
||||||
tr3.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr3.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr3.setText(
|
tr3.setText(
|
||||||
"Rich text\r" +
|
"Rich text\r" +
|
||||||
@ -137,13 +137,13 @@ public final class ApacheconEU08 {
|
|||||||
"Shapes\r" +
|
"Shapes\r" +
|
||||||
"Pictures\r" +
|
"Pictures\r" +
|
||||||
"Master slides");
|
"Master slides");
|
||||||
tr3.getRichTextRuns()[0].setFontSize(24);
|
tr3.getTextRuns()[0].setFontSize(24);
|
||||||
tr3.getRichTextRuns()[0].setIndentLevel(1);
|
tr3.getTextRuns()[0].setIndentLevel(1);
|
||||||
box3.setAnchor(new Rectangle(36, 265, 648, 150));
|
box3.setAnchor(new Rectangle(36, 265, 648, 150));
|
||||||
slide.addShape(box3);
|
slide.addShape(box3);
|
||||||
|
|
||||||
HSLFTextBox box4 = new HSLFTextBox();
|
HSLFTextBox box4 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr4 = box4.getTextParagraph();
|
HSLFTextParagraph tr4 = box4.getTextParagraphs();
|
||||||
tr4.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr4.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr4.setText("Access to low level data structures");
|
tr4.setText("Access to low level data structures");
|
||||||
box4.setAnchor(new Rectangle(36, 430, 648, 50));
|
box4.setAnchor(new Rectangle(36, 430, 648, 50));
|
||||||
@ -162,8 +162,8 @@ public final class ApacheconEU08 {
|
|||||||
for (int j = 0; j < txt1[i].length; j++) {
|
for (int j = 0; j < txt1[i].length; j++) {
|
||||||
TableCell cell = table1.getCell(i, j);
|
TableCell cell = table1.getCell(i, j);
|
||||||
cell.setText(txt1[i][j]);
|
cell.setText(txt1[i][j]);
|
||||||
cell.getTextParagraph().getRichTextRuns()[0].setFontSize(10);
|
cell.getTextParagraphs().getTextRuns()[0].setFontSize(10);
|
||||||
HSLFTextRun rt = cell.getTextParagraph().getRichTextRuns()[0];
|
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
|
||||||
rt.setFontName("Arial");
|
rt.setFontName("Arial");
|
||||||
rt.setBold(true);
|
rt.setBold(true);
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
@ -197,10 +197,10 @@ public final class ApacheconEU08 {
|
|||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
box1.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
box1.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setText("The source code is available at\r" +
|
tr1.setText("The source code is available at\r" +
|
||||||
"http://people.apache.org/~yegor/apachecon_eu08/");
|
"http://people.apache.org/~yegor/apachecon_eu08/");
|
||||||
HSLFTextRun rt = tr1.getRichTextRuns()[0];
|
HSLFTextRun rt = tr1.getTextRuns()[0];
|
||||||
rt.setFontSize(24);
|
rt.setFontSize(24);
|
||||||
box1.setAnchor(new Rectangle(80, 356, 553, 65));
|
box1.setAnchor(new Rectangle(80, 356, 553, 65));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
@ -211,14 +211,14 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
||||||
tr1.setText("HSLF in Action - 1\rData Extraction");
|
tr1.setText("HSLF in Action - 1\rData Extraction");
|
||||||
box1.setAnchor(new Rectangle(36, 21, 648, 100));
|
box1.setAnchor(new Rectangle(36, 21, 648, 100));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr2.setText(
|
tr2.setText(
|
||||||
"Text from slides and notes\r" +
|
"Text from slides and notes\r" +
|
||||||
@ -234,22 +234,22 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
||||||
tr1.setText("HSLF in Action - 2");
|
tr1.setText("HSLF in Action - 2");
|
||||||
box1.setAnchor(new Rectangle(36, 20, 648, 90));
|
box1.setAnchor(new Rectangle(36, 20, 648, 90));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.getRichTextRuns()[0].setFontSize(18);
|
tr2.getTextRuns()[0].setFontSize(18);
|
||||||
tr2.setText("Creating a simple presentation from scratch");
|
tr2.setText("Creating a simple presentation from scratch");
|
||||||
box2.setAnchor(new Rectangle(170, 100, 364, 30));
|
box2.setAnchor(new Rectangle(170, 100, 364, 30));
|
||||||
slide.addShape(box2);
|
slide.addShape(box2);
|
||||||
|
|
||||||
HSLFTextBox box3 = new HSLFTextBox();
|
HSLFTextBox box3 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr3 = box3.getTextParagraph();
|
HSLFTextParagraph tr3 = box3.getTextParagraphs();
|
||||||
HSLFTextRun rt3 = tr3.getRichTextRuns()[0];
|
HSLFTextRun rt3 = tr3.getTextRuns()[0];
|
||||||
rt3.setFontName("Courier New");
|
rt3.setFontName("Courier New");
|
||||||
rt3.setFontSize(8);
|
rt3.setFontSize(8);
|
||||||
tr3.setText(
|
tr3.setText(
|
||||||
@ -296,7 +296,7 @@ public final class ApacheconEU08 {
|
|||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
box2.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
box2.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
||||||
box2.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
|
box2.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
|
||||||
box2.getTextParagraph().setText("Java Code");
|
box2.getTextParagraphs().setText("Java Code");
|
||||||
box2.getFill().setForegroundColor(new Color(187, 224, 227));
|
box2.getFill().setForegroundColor(new Color(187, 224, 227));
|
||||||
box2.setLineColor(Color.black);
|
box2.setLineColor(Color.black);
|
||||||
box2.setLineWidth(0.75);
|
box2.setLineWidth(0.75);
|
||||||
@ -306,7 +306,7 @@ public final class ApacheconEU08 {
|
|||||||
HSLFTextBox box3 = new HSLFTextBox();
|
HSLFTextBox box3 = new HSLFTextBox();
|
||||||
box3.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
box3.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
||||||
box3.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
|
box3.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
|
||||||
box3.getTextParagraph().setText("*.ppt file");
|
box3.getTextParagraphs().setText("*.ppt file");
|
||||||
box3.setLineWidth(0.75);
|
box3.setLineWidth(0.75);
|
||||||
box3.setLineColor(Color.black);
|
box3.setLineColor(Color.black);
|
||||||
box3.getFill().setForegroundColor(new Color(187, 224, 227));
|
box3.getFill().setForegroundColor(new Color(187, 224, 227));
|
||||||
@ -325,14 +325,14 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
||||||
tr1.setText("Wait, there is more!");
|
tr1.setText("Wait, there is more!");
|
||||||
box1.setAnchor(new Rectangle(36, 21, 648, 90));
|
box1.setAnchor(new Rectangle(36, 21, 648, 90));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr2.setText(
|
tr2.setText(
|
||||||
"Rich text\r" +
|
"Rich text\r" +
|
||||||
@ -347,22 +347,22 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
||||||
tr1.setText("HSLF in Action - 3");
|
tr1.setText("HSLF in Action - 3");
|
||||||
box1.setAnchor(new Rectangle(36, 20, 648, 50));
|
box1.setAnchor(new Rectangle(36, 20, 648, 50));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.getRichTextRuns()[0].setFontSize(18);
|
tr2.getTextRuns()[0].setFontSize(18);
|
||||||
tr2.setText("PPGraphics2D: PowerPoint Graphics2D driver");
|
tr2.setText("PPGraphics2D: PowerPoint Graphics2D driver");
|
||||||
box2.setAnchor(new Rectangle(178, 70, 387, 30));
|
box2.setAnchor(new Rectangle(178, 70, 387, 30));
|
||||||
slide.addShape(box2);
|
slide.addShape(box2);
|
||||||
|
|
||||||
HSLFTextBox box3 = new HSLFTextBox();
|
HSLFTextBox box3 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr3 = box3.getTextParagraph();
|
HSLFTextParagraph tr3 = box3.getTextParagraphs();
|
||||||
HSLFTextRun rt3 = tr3.getRichTextRuns()[0];
|
HSLFTextRun rt3 = tr3.getTextRuns()[0];
|
||||||
rt3.setFontName("Courier New");
|
rt3.setFontName("Courier New");
|
||||||
rt3.setFontSize(8);
|
rt3.setFontSize(8);
|
||||||
tr3.setText(
|
tr3.setText(
|
||||||
@ -449,16 +449,16 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
|
||||||
tr1.setText("HSLF Development Plans");
|
tr1.setText("HSLF Development Plans");
|
||||||
box1.setAnchor(new Rectangle(36, 21, 648, 90));
|
box1.setAnchor(new Rectangle(36, 21, 648, 90));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr2.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr2.getRichTextRuns()[0].setFontSize(32);
|
tr2.getTextRuns()[0].setFontSize(32);
|
||||||
tr2.setText(
|
tr2.setText(
|
||||||
"Support for more PowerPoint functionality\r" +
|
"Support for more PowerPoint functionality\r" +
|
||||||
"Rendering slides into java.awt.Graphics2D");
|
"Rendering slides into java.awt.Graphics2D");
|
||||||
@ -466,27 +466,27 @@ public final class ApacheconEU08 {
|
|||||||
slide.addShape(box2);
|
slide.addShape(box2);
|
||||||
|
|
||||||
HSLFTextBox box3 = new HSLFTextBox();
|
HSLFTextBox box3 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr3 = box3.getTextParagraph();
|
HSLFTextParagraph tr3 = box3.getTextParagraphs();
|
||||||
tr3.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr3.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr3.getRichTextRuns()[0].setIndentLevel(1);
|
tr3.getTextRuns()[0].setIndentLevel(1);
|
||||||
tr3.setText(
|
tr3.setText(
|
||||||
"A way to export slides into images or other formats");
|
"A way to export slides into images or other formats");
|
||||||
box3.setAnchor(new Rectangle(36, 220, 648, 70));
|
box3.setAnchor(new Rectangle(36, 220, 648, 70));
|
||||||
slide.addShape(box3);
|
slide.addShape(box3);
|
||||||
|
|
||||||
HSLFTextBox box4 = new HSLFTextBox();
|
HSLFTextBox box4 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr4 = box4.getTextParagraph();
|
HSLFTextParagraph tr4 = box4.getTextParagraphs();
|
||||||
tr4.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr4.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr4.getRichTextRuns()[0].setFontSize(32);
|
tr4.getTextRuns()[0].setFontSize(32);
|
||||||
tr4.setText(
|
tr4.setText(
|
||||||
"Integration with Apache FOP - Formatting Objects Processor");
|
"Integration with Apache FOP - Formatting Objects Processor");
|
||||||
box4.setAnchor(new Rectangle(36, 290, 648, 90));
|
box4.setAnchor(new Rectangle(36, 290, 648, 90));
|
||||||
slide.addShape(box4);
|
slide.addShape(box4);
|
||||||
|
|
||||||
HSLFTextBox box5 = new HSLFTextBox();
|
HSLFTextBox box5 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr5 = box5.getTextParagraph();
|
HSLFTextParagraph tr5 = box5.getTextParagraphs();
|
||||||
tr5.setRunType(TextHeaderAtom.BODY_TYPE);
|
tr5.setRunType(TextHeaderAtom.BODY_TYPE);
|
||||||
tr5.getRichTextRuns()[0].setIndentLevel(1);
|
tr5.getTextRuns()[0].setIndentLevel(1);
|
||||||
tr5.setText(
|
tr5.setText(
|
||||||
"Transformation of XSL-FO into PPT\r" +
|
"Transformation of XSL-FO into PPT\r" +
|
||||||
"PPT2PDF transcoder");
|
"PPT2PDF transcoder");
|
||||||
@ -498,14 +498,14 @@ public final class ApacheconEU08 {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox box1 = new HSLFTextBox();
|
HSLFTextBox box1 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr1 = box1.getTextParagraph();
|
HSLFTextParagraph tr1 = box1.getTextParagraphs();
|
||||||
tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
|
tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
|
||||||
tr1.setText("Questions?");
|
tr1.setText("Questions?");
|
||||||
box1.setAnchor(new Rectangle(54, 167, 612, 115));
|
box1.setAnchor(new Rectangle(54, 167, 612, 115));
|
||||||
slide.addShape(box1);
|
slide.addShape(box1);
|
||||||
|
|
||||||
HSLFTextBox box2 = new HSLFTextBox();
|
HSLFTextBox box2 = new HSLFTextBox();
|
||||||
HSLFTextParagraph tr2 = box2.getTextParagraph();
|
HSLFTextParagraph tr2 = box2.getTextParagraphs();
|
||||||
tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
|
tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
|
||||||
tr2.setText(
|
tr2.setText(
|
||||||
"http://poi.apache.org/hslf/\r" +
|
"http://poi.apache.org/hslf/\r" +
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.examples;
|
package org.apache.poi.hslf.examples;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
|
||||||
import org.apache.poi.hslf.model.HSLFSlide;
|
|
||||||
import org.apache.poi.hslf.model.HSLFTextBox;
|
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
@ -39,7 +36,7 @@ public final class BulletsDemo {
|
|||||||
HSLFSlide slide = ppt.createSlide();
|
HSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
HSLFTextBox shape = new HSLFTextBox();
|
HSLFTextBox shape = new HSLFTextBox();
|
||||||
HSLFTextRun rt = shape.getTextParagraph().getRichTextRuns()[0];
|
HSLFTextRun rt = shape.getTextParagraphs().getTextRuns()[0];
|
||||||
shape.setText(
|
shape.setText(
|
||||||
"January\r" +
|
"January\r" +
|
||||||
"February\r" +
|
"February\r" +
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.examples;
|
package org.apache.poi.hslf.examples;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.hslf.model.*;
|
import org.apache.poi.hslf.model.*;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -43,7 +43,7 @@ public final class CreateHyperlink {
|
|||||||
textBox1.setAnchor(new Rectangle(100, 100, 200, 50));
|
textBox1.setAnchor(new Rectangle(100, 100, 200, 50));
|
||||||
|
|
||||||
String text = textBox1.getText();
|
String text = textBox1.getText();
|
||||||
Hyperlink link = new Hyperlink();
|
HSLFHyperlink link = new HSLFHyperlink();
|
||||||
link.setAddress("http://www.apache.org");
|
link.setAddress("http://www.apache.org");
|
||||||
link.setTitle(textBox1.getText());
|
link.setTitle(textBox1.getText());
|
||||||
int linkId = ppt.addHyperlink(link);
|
int linkId = ppt.addHyperlink(link);
|
||||||
@ -58,7 +58,7 @@ public final class CreateHyperlink {
|
|||||||
textBox2.setText("Go to slide #3");
|
textBox2.setText("Go to slide #3");
|
||||||
textBox2.setAnchor(new Rectangle(100, 300, 200, 50));
|
textBox2.setAnchor(new Rectangle(100, 300, 200, 50));
|
||||||
|
|
||||||
Hyperlink link2 = new Hyperlink();
|
HSLFHyperlink link2 = new HSLFHyperlink();
|
||||||
link2.setAddress(slideC);
|
link2.setAddress(slideC);
|
||||||
ppt.addHyperlink(link2);
|
ppt.addHyperlink(link2);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.examples;
|
package org.apache.poi.hslf.examples;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.hslf.model.*;
|
import org.apache.poi.hslf.model.*;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hslf.examples;
|
package org.apache.poi.hslf.examples;
|
||||||
|
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
import org.apache.poi.hslf.model.HeadersFooters;
|
import org.apache.poi.hslf.model.HeadersFooters;
|
||||||
import org.apache.poi.hslf.model.HSLFSlide;
|
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
@ -17,11 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.examples;
|
package org.apache.poi.hslf.examples;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.hslf.model.HSLFSlide;
|
|
||||||
import org.apache.poi.hslf.model.HSLFTextParagraph;
|
|
||||||
import org.apache.poi.hslf.model.Hyperlink;
|
|
||||||
import org.apache.poi.hslf.model.HSLFShape;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
||||||
@ -44,12 +40,12 @@ public final class Hyperlinks {
|
|||||||
|
|
||||||
//read hyperlinks from the slide's text runs
|
//read hyperlinks from the slide's text runs
|
||||||
System.out.println("reading hyperlinks from the text runs");
|
System.out.println("reading hyperlinks from the text runs");
|
||||||
HSLFTextParagraph[] txt = slide[j].getTextRuns();
|
HSLFTextParagraph[] txt = slide[j].getTextParagraphs();
|
||||||
for (int k = 0; k < txt.length; k++) {
|
for (int k = 0; k < txt.length; k++) {
|
||||||
String text = txt[k].getText();
|
String text = txt[k].getRawText();
|
||||||
Hyperlink[] links = txt[k].getHyperlinks();
|
HSLFHyperlink[] links = txt[k].getHyperlinks();
|
||||||
if(links != null) for (int l = 0; l < links.length; l++) {
|
if(links != null) for (int l = 0; l < links.length; l++) {
|
||||||
Hyperlink link = links[l];
|
HSLFHyperlink link = links[l];
|
||||||
String title = link.getTitle();
|
String title = link.getTitle();
|
||||||
String address = link.getAddress();
|
String address = link.getAddress();
|
||||||
System.out.println(" " + title);
|
System.out.println(" " + title);
|
||||||
@ -65,7 +61,7 @@ public final class Hyperlinks {
|
|||||||
System.out.println(" reading hyperlinks from the slide's shapes");
|
System.out.println(" reading hyperlinks from the slide's shapes");
|
||||||
HSLFShape[] sh = slide[j].getShapes();
|
HSLFShape[] sh = slide[j].getShapes();
|
||||||
for (int k = 0; k < sh.length; k++) {
|
for (int k = 0; k < sh.length; k++) {
|
||||||
Hyperlink link = sh[k].getHyperlink();
|
HSLFHyperlink link = sh[k].getHyperlink();
|
||||||
if(link != null) {
|
if(link != null) {
|
||||||
String title = link.getTitle();
|
String title = link.getTitle();
|
||||||
String address = link.getAddress();
|
String address = link.getAddress();
|
||||||
|
@ -21,6 +21,7 @@ import org.apache.poi.hslf.usermodel.*;
|
|||||||
import org.apache.poi.hslf.model.*;
|
import org.apache.poi.hslf.model.*;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -21,6 +21,7 @@ import org.apache.poi.hslf.record.InteractiveInfo;
|
|||||||
import org.apache.poi.hslf.record.InteractiveInfoAtom;
|
import org.apache.poi.hslf.record.InteractiveInfoAtom;
|
||||||
import org.apache.poi.hslf.record.Record;
|
import org.apache.poi.hslf.record.Record;
|
||||||
import org.apache.poi.hslf.usermodel.*;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.examples;
|
package org.apache.poi.hslf.examples;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
|
||||||
import org.apache.poi.hslf.model.*;
|
import org.apache.poi.hslf.model.*;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -53,7 +52,7 @@ public final class TableDemo {
|
|||||||
for (int j = 0; j < txt1[i].length; j++) {
|
for (int j = 0; j < txt1[i].length; j++) {
|
||||||
TableCell cell = table1.getCell(i, j);
|
TableCell cell = table1.getCell(i, j);
|
||||||
cell.setText(txt1[i][j]);
|
cell.setText(txt1[i][j]);
|
||||||
HSLFTextRun rt = cell.getTextParagraph().getRichTextRuns()[0];
|
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
|
||||||
rt.setFontName("Arial");
|
rt.setFontName("Arial");
|
||||||
rt.setFontSize(10);
|
rt.setFontSize(10);
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
@ -92,7 +91,7 @@ public final class TableDemo {
|
|||||||
for (int j = 0; j < txt2[i].length; j++) {
|
for (int j = 0; j < txt2[i].length; j++) {
|
||||||
TableCell cell = table2.getCell(i, j);
|
TableCell cell = table2.getCell(i, j);
|
||||||
cell.setText(txt2[i][j]);
|
cell.setText(txt2[i][j]);
|
||||||
HSLFTextRun rt = cell.getTextParagraph().getRichTextRuns()[0];
|
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
|
||||||
rt.setFontSize(10);
|
rt.setFontSize(10);
|
||||||
rt.setFontName("Arial");
|
rt.setFontName("Arial");
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
|
@ -21,8 +21,8 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
|
|||||||
import org.apache.poi.poifs.filesystem.Entry;
|
import org.apache.poi.poifs.filesystem.Entry;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -52,10 +52,10 @@ public class Step1 {
|
|||||||
for(XSLFTextParagraph p : tsh){
|
for(XSLFTextParagraph p : tsh){
|
||||||
System.out.println("Paragraph level: " + p.getLevel());
|
System.out.println("Paragraph level: " + p.getLevel());
|
||||||
for(XSLFTextRun r : p){
|
for(XSLFTextRun r : p){
|
||||||
System.out.println(r.getText());
|
System.out.println(r.getRawText());
|
||||||
System.out.println(" bold: " + r.isBold());
|
System.out.println(" bold: " + r.isBold());
|
||||||
System.out.println(" italic: " + r.isItalic());
|
System.out.println(" italic: " + r.isItalic());
|
||||||
System.out.println(" underline: " + r.isUnderline());
|
System.out.println(" underline: " + r.isUnderlined());
|
||||||
System.out.println(" font.family: " + r.getFontFamily());
|
System.out.println(" font.family: " + r.getFontFamily());
|
||||||
System.out.println(" font.size: " + r.getFontSize());
|
System.out.println(" font.size: " + r.getFontSize());
|
||||||
System.out.println(" font.color: " + r.getFontColor());
|
System.out.println(" font.color: " + r.getFontColor());
|
||||||
|
@ -20,7 +20,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.xslf.XSLFSlideShow;
|
import org.apache.poi.xslf.XSLFSlideShow;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
@ -22,8 +22,8 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.Record;
|
import org.apache.poi.hslf.record.Record;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class HSLFFileHandler extends POIFSFileHandler {
|
public class HSLFFileHandler extends POIFSFileHandler {
|
||||||
|
@ -18,10 +18,7 @@
|
|||||||
package org.apache.poi.ddf;
|
package org.apache.poi.ddf;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
import org.apache.poi.util.HexDump;
|
import org.apache.poi.util.HexDump;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
@ -154,30 +151,9 @@ public final class EscherContainerRecord extends EscherRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<EscherRecord> getChildIterator() {
|
public Iterator<EscherRecord> getChildIterator() {
|
||||||
return new ReadOnlyIterator(_childRecords);
|
return Collections.unmodifiableList(_childRecords).iterator();
|
||||||
}
|
|
||||||
private static final class ReadOnlyIterator implements Iterator<EscherRecord> {
|
|
||||||
private final List<EscherRecord> _list;
|
|
||||||
private int _index;
|
|
||||||
|
|
||||||
public ReadOnlyIterator(List<EscherRecord> list) {
|
|
||||||
_list = list;
|
|
||||||
_index = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
|
||||||
return _index < _list.size();
|
|
||||||
}
|
|
||||||
public EscherRecord next() {
|
|
||||||
if (!hasNext()) {
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
}
|
|
||||||
return _list.get(_index++);
|
|
||||||
}
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* replaces the internal child list with the contents of the supplied <tt>childRecords</tt>
|
* replaces the internal child list with the contents of the supplied <tt>childRecords</tt>
|
||||||
*/
|
*/
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.apache.poi.xslf.extractor;
|
package org.apache.poi.xslf.extractor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLTextExtractor;
|
import org.apache.poi.POIXMLTextExtractor;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
@ -122,7 +123,7 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
|
|||||||
public String getText(boolean slideText, boolean notesText, boolean masterText) {
|
public String getText(boolean slideText, boolean notesText, boolean masterText) {
|
||||||
StringBuffer text = new StringBuffer();
|
StringBuffer text = new StringBuffer();
|
||||||
|
|
||||||
XSLFSlide[] slides = slideshow.getSlides();
|
List<XSLFSlide> slides = slideshow.getSlides();
|
||||||
XSLFCommentAuthors commentAuthors = slideshow.getCommentAuthors();
|
XSLFCommentAuthors commentAuthors = slideshow.getCommentAuthors();
|
||||||
|
|
||||||
for (XSLFSlide slide : slides) {
|
for (XSLFSlide slide : slides) {
|
||||||
|
@ -17,52 +17,20 @@
|
|||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
import java.util.*;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocument;
|
import org.apache.poi.*;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
|
||||||
import org.apache.poi.POIXMLException;
|
|
||||||
import org.apache.poi.POIXMLRelation;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.*;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.sl.usermodel.*;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.util.*;
|
||||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
|
||||||
import org.apache.poi.sl.usermodel.MasterSheet;
|
|
||||||
import org.apache.poi.sl.usermodel.Resources;
|
|
||||||
import org.apache.poi.sl.usermodel.SlideShow;
|
|
||||||
import org.apache.poi.util.Beta;
|
|
||||||
import org.apache.poi.util.IOUtils;
|
|
||||||
import org.apache.poi.util.Internal;
|
|
||||||
import org.apache.poi.util.POILogFactory;
|
|
||||||
import org.apache.poi.util.POILogger;
|
|
||||||
import org.apache.poi.util.PackageHelper;
|
|
||||||
import org.apache.poi.util.Units;
|
|
||||||
import org.apache.poi.xslf.XSLFSlideShow;
|
import org.apache.poi.xslf.XSLFSlideShow;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.*;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdList;
|
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry;
|
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
|
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList;
|
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize;
|
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument;
|
|
||||||
|
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|
||||||
|
|
||||||
import com.sun.org.apache.xml.internal.utils.UnImplNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High level representation of a ooxml slideshow.
|
* High level representation of a ooxml slideshow.
|
||||||
@ -334,7 +302,7 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
|||||||
|
|
||||||
XSLFTheme theme = (XSLFTheme) createRelationship(XSLFRelation.THEME,
|
XSLFTheme theme = (XSLFTheme) createRelationship(XSLFRelation.THEME,
|
||||||
XSLFFactory.getInstance(), themeIndex);
|
XSLFFactory.getInstance(), themeIndex);
|
||||||
theme.importTheme(getSlides()[0].getTheme());
|
theme.importTheme(getSlides().get(0).getTheme());
|
||||||
|
|
||||||
_notesMaster.addRelation(theme.getPackageRelationship().getId(), theme);
|
_notesMaster.addRelation(theme.getPackageRelationship().getId(), theme);
|
||||||
PackagePartName themePackagePartName = theme.getPackagePart().getPartName();
|
PackagePartName themePackagePartName = theme.getPackagePart().getPartName();
|
||||||
@ -350,15 +318,16 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
|||||||
return _notesMaster;
|
return _notesMaster;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSLFSlideMaster[] getSlideMasters() {
|
@Override
|
||||||
return _masters.values().toArray(new XSLFSlideMaster[_masters.size()]);
|
public List<XSLFSlideMaster> getSlideMasters() {
|
||||||
|
return new ArrayList<XSLFSlideMaster>(_masters.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all the slides in the slideshow
|
* Return all the slides in the slideshow
|
||||||
*/
|
*/
|
||||||
public XSLFSlide[] getSlides() {
|
public List<XSLFSlide> getSlides() {
|
||||||
return _slides.toArray(new XSLFSlide[_slides.size()]);
|
return _slides;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -496,10 +465,6 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSLFSlideMaster[] getMasterSheet() {
|
|
||||||
return getSlideMasters();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MasterSheet createMasterSheet() throws IOException {
|
public MasterSheet createMasterSheet() throws IOException {
|
||||||
// TODO: implement!
|
// TODO: implement!
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -27,8 +27,7 @@ import java.util.regex.Pattern;
|
|||||||
import org.apache.poi.openxml4j.opc.*;
|
import org.apache.poi.openxml4j.opc.*;
|
||||||
import org.apache.poi.sl.usermodel.PlaceableShape;
|
import org.apache.poi.sl.usermodel.PlaceableShape;
|
||||||
import org.apache.poi.sl.usermodel.ShapeGroup;
|
import org.apache.poi.sl.usermodel.ShapeGroup;
|
||||||
import org.apache.poi.util.Beta;
|
import org.apache.poi.util.*;
|
||||||
import org.apache.poi.util.Units;
|
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
||||||
@ -40,6 +39,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
|||||||
*/
|
*/
|
||||||
@Beta
|
@Beta
|
||||||
public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, ShapeGroup<XSLFShape> {
|
public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, ShapeGroup<XSLFShape> {
|
||||||
|
private static POILogger _logger = POILogFactory.getLogger(XSLFGroupShape.class);
|
||||||
|
|
||||||
private final List<XSLFShape> _shapes;
|
private final List<XSLFShape> _shapes;
|
||||||
private final CTGroupShapeProperties _grpSpPr;
|
private final CTGroupShapeProperties _grpSpPr;
|
||||||
private XSLFDrawing _drawing;
|
private XSLFDrawing _drawing;
|
||||||
@ -135,8 +136,9 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Sha
|
|||||||
*
|
*
|
||||||
* @return child shapes contained witin this group
|
* @return child shapes contained witin this group
|
||||||
*/
|
*/
|
||||||
public XSLFShape[] getShapes(){
|
@Override
|
||||||
return _shapes.toArray(new XSLFShape[_shapes.size()]);
|
public List<XSLFShape> getShapes(){
|
||||||
|
return _shapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,6 +248,13 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Sha
|
|||||||
return sh;
|
return sh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XSLFTable createTable(){
|
||||||
|
XSLFTable sh = getDrawing().createTable();
|
||||||
|
_shapes.add(sh);
|
||||||
|
sh.setParent(this);
|
||||||
|
return sh;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFlipHorizontal(boolean flip){
|
public void setFlipHorizontal(boolean flip){
|
||||||
getSafeXfrm().setFlipH(flip);
|
getSafeXfrm().setFlipH(flip);
|
||||||
@ -282,14 +291,36 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Sha
|
|||||||
@Override
|
@Override
|
||||||
void copy(XSLFShape src){
|
void copy(XSLFShape src){
|
||||||
XSLFGroupShape gr = (XSLFGroupShape)src;
|
XSLFGroupShape gr = (XSLFGroupShape)src;
|
||||||
// recursively update each shape
|
|
||||||
XSLFShape[] tgtShapes = getShapes();
|
|
||||||
XSLFShape[] srcShapes = gr.getShapes();
|
|
||||||
for(int i = 0; i < tgtShapes.length; i++){
|
|
||||||
XSLFShape s1 = srcShapes[i];
|
|
||||||
XSLFShape s2 = tgtShapes[i];
|
|
||||||
|
|
||||||
s2.copy(s1);
|
// clear shapes
|
||||||
|
clear();
|
||||||
|
|
||||||
|
// recursively update each shape
|
||||||
|
for(XSLFShape shape : gr.getShapes()) {
|
||||||
|
XSLFShape newShape = null;
|
||||||
|
if (shape instanceof XSLFTextBox) {
|
||||||
|
newShape = createTextBox();
|
||||||
|
} else if (shape instanceof XSLFAutoShape) {
|
||||||
|
newShape = createAutoShape();
|
||||||
|
} else if (shape instanceof XSLFConnectorShape) {
|
||||||
|
newShape = createConnector();
|
||||||
|
} else if (shape instanceof XSLFFreeformShape) {
|
||||||
|
newShape = createFreeform();
|
||||||
|
} else if (shape instanceof XSLFPictureShape) {
|
||||||
|
XSLFPictureShape p = (XSLFPictureShape)shape;
|
||||||
|
XSLFPictureData pd = p.getPictureData();
|
||||||
|
int picId = getSheet().getSlideShow().addPicture(pd.getData(), pd.getPictureType());
|
||||||
|
newShape = createPicture(picId);
|
||||||
|
} else if (shape instanceof XSLFGroupShape) {
|
||||||
|
newShape = createGroup();
|
||||||
|
} else if (shape instanceof XSLFTable) {
|
||||||
|
newShape = createTable();
|
||||||
|
} else {
|
||||||
|
_logger.log(POILogger.WARN, "copying of class "+shape.getClass()+" not supported.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
newShape.copy(shape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,12 +91,12 @@ public final class XSLFNotes extends XSLFSheet implements Notes<XSLFShape,XMLSli
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<XSLFTextParagraph> getTextParagraphs() {
|
public List<List<XSLFTextParagraph>> getTextParagraphs() {
|
||||||
List<XSLFTextParagraph> tp = new ArrayList<XSLFTextParagraph>();
|
List<List<XSLFTextParagraph>> tp = new ArrayList<List<XSLFTextParagraph>>();
|
||||||
for (XSLFShape sh : super.getShapes()) {
|
for (XSLFShape sh : super.getShapes()) {
|
||||||
if (sh instanceof XSLFTextShape) {
|
if (sh instanceof XSLFTextShape) {
|
||||||
XSLFTextShape txt = (XSLFTextShape)sh;
|
XSLFTextShape txt = (XSLFTextShape)sh;
|
||||||
tp.addAll(txt.getTextParagraphs());
|
tp.add(txt.getTextParagraphs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tp;
|
return tp;
|
||||||
|
@ -199,8 +199,8 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
|
|||||||
*
|
*
|
||||||
* @return an array of all shapes in this sheet
|
* @return an array of all shapes in this sheet
|
||||||
*/
|
*/
|
||||||
public XSLFShape[] getShapes(){
|
public List<XSLFShape> getShapes(){
|
||||||
return getShapeList().toArray(new XSLFShape[_shapes.size()]);
|
return getShapeList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,6 +301,9 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC
|
|||||||
_spTree = null;
|
_spTree = null;
|
||||||
_placeholders = null;
|
_placeholders = null;
|
||||||
|
|
||||||
|
// fix-me: wth would this ever happen to work ...
|
||||||
|
|
||||||
|
|
||||||
// first copy the source xml
|
// first copy the source xml
|
||||||
getSpTree().set(src.getSpTree());
|
getSpTree().set(src.getSpTree());
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
|||||||
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSlideShow> {
|
public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSlideShow, XSLFNotes> {
|
||||||
private final CTSlide _slide;
|
private final CTSlide _slide;
|
||||||
private XSLFSlideLayout _layout;
|
private XSLFSlideLayout _layout;
|
||||||
private XSLFComments _comments;
|
private XSLFComments _comments;
|
||||||
@ -245,7 +245,7 @@ public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSl
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotes(Notes<XSLFShape,XMLSlideShow> notes) {
|
public void setNotes(XSLFNotes notes) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
public String getText(){
|
public String getText(){
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
for (XSLFTextRun r : _runs) {
|
for (XSLFTextRun r : _runs) {
|
||||||
out.append(r.getText());
|
out.append(r.getRawText());
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
@ -171,6 +171,39 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FontAlign getFontAlign(){
|
||||||
|
ParagraphPropertyFetcher<FontAlign> fetcher = new ParagraphPropertyFetcher<FontAlign>(getLevel()){
|
||||||
|
public boolean fetch(CTTextParagraphProperties props){
|
||||||
|
if(props.isSetFontAlgn()){
|
||||||
|
FontAlign val = FontAlign.values()[props.getFontAlgn().intValue() - 1];
|
||||||
|
setValue(val);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchParagraphProperty(fetcher);
|
||||||
|
return fetcher.getValue() == null ? FontAlign.AUTO : fetcher.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the font alignment that is to be applied to the paragraph.
|
||||||
|
* Possible values for this include auto, top, center, baseline and bottom.
|
||||||
|
* see {@link org.apache.poi.sl.usermodel.TextParagraph.FontAlign}.
|
||||||
|
*
|
||||||
|
* @param align font align
|
||||||
|
*/
|
||||||
|
public void setFontAlign(FontAlign align){
|
||||||
|
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
|
||||||
|
if(align == null) {
|
||||||
|
if(pr.isSetFontAlgn()) pr.unsetFontAlgn();
|
||||||
|
} else {
|
||||||
|
pr.setFontAlgn(STTextFontAlignType.Enum.forInt(align.ordinal() + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the font to be used on bullet characters within a given paragraph
|
* @return the font to be used on bullet characters within a given paragraph
|
||||||
@ -306,6 +339,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
*
|
*
|
||||||
* @param value the indent in points.
|
* @param value the indent in points.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void setIndent(double value){
|
public void setIndent(double value){
|
||||||
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
|
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
|
||||||
if(value == -1) {
|
if(value == -1) {
|
||||||
@ -319,6 +353,7 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
*
|
*
|
||||||
* @return the indent applied to the first line of text in the paragraph.
|
* @return the indent applied to the first line of text in the paragraph.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public double getIndent(){
|
public double getIndent(){
|
||||||
|
|
||||||
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
|
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
|
||||||
@ -340,8 +375,9 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
* inset and applies only to this text paragraph. That is the text body Inset and the LeftMargin
|
* inset and applies only to this text paragraph. That is the text body Inset and the LeftMargin
|
||||||
* attributes are additive with respect to the text position.
|
* attributes are additive with respect to the text position.
|
||||||
*
|
*
|
||||||
* @param value the left margin of the paragraph
|
* @param value the left margin (in points) of the paragraph
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void setLeftMargin(double value){
|
public void setLeftMargin(double value){
|
||||||
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
|
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
|
||||||
if(value == -1) {
|
if(value == -1) {
|
||||||
@ -353,9 +389,9 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return the left margin (in points) of the paragraph
|
||||||
* @return the left margin of the paragraph
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public double getLeftMargin(){
|
public double getLeftMargin(){
|
||||||
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
|
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
|
||||||
public boolean fetch(CTTextParagraphProperties props){
|
public boolean fetch(CTTextParagraphProperties props){
|
||||||
@ -372,10 +408,28 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
return fetcher.getValue() == null ? 0 : fetcher.getValue();
|
return fetcher.getValue() == null ? 0 : fetcher.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the right margin of the paragraph. This is specified in addition to the text body
|
||||||
|
* inset and applies only to this text paragraph. That is the text body Inset and the RightMargin
|
||||||
|
* attributes are additive with respect to the text position.
|
||||||
|
*
|
||||||
|
* @param value the right margin (in points) of the paragraph
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setRightMargin(double value){
|
||||||
|
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
|
||||||
|
if(value == -1) {
|
||||||
|
if(pr.isSetMarR()) pr.unsetMarR();
|
||||||
|
} else {
|
||||||
|
pr.setMarR(Units.toEMU(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return the right margin of the paragraph
|
* @return the right margin of the paragraph
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public double getRightMargin(){
|
public double getRightMargin(){
|
||||||
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
|
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
|
||||||
public boolean fetch(CTTextParagraphProperties props){
|
public boolean fetch(CTTextParagraphProperties props){
|
||||||
@ -834,11 +888,13 @@ public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getDefaultFontSize() {
|
public double getDefaultFontSize() {
|
||||||
CTTextCharacterProperties endPr = _p.getEndParaRPr();
|
CTTextCharacterProperties endPr = _p.getEndParaRPr();
|
||||||
return (endPr == null || !endPr.isSetSz()) ? 12 : (endPr.getSz() / 100);
|
return (endPr == null || !endPr.isSetSz()) ? 12 : (endPr.getSz() / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDefaultFontFamily() {
|
public String getDefaultFontFamily() {
|
||||||
return (_runs.isEmpty() ? "Arial" : _runs.get(0).getFontFamily());
|
return (_runs.isEmpty() ? "Arial" : _runs.get(0).getFontFamily());
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
return _p;
|
return _p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText(){
|
public String getRawText(){
|
||||||
return _r.getT();
|
return _r.getT();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,7 +479,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
/**
|
/**
|
||||||
* @return whether this run of text is formatted as underlined text
|
* @return whether this run of text is formatted as underlined text
|
||||||
*/
|
*/
|
||||||
public boolean isUnderline(){
|
public boolean isUnderlined(){
|
||||||
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
CharacterPropertyFetcher<Boolean> fetcher = new CharacterPropertyFetcher<Boolean>(_p.getLevel()){
|
||||||
public boolean fetch(CTTextCharacterProperties props){
|
public boolean fetch(CTTextCharacterProperties props){
|
||||||
if(props.isSetU()){
|
if(props.isSetU()){
|
||||||
@ -499,7 +499,7 @@ public class XSLFTextRun implements TextRun {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "[" + getClass() + "]" + getText();
|
return "[" + getClass() + "]" + getRawText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSLFHyperlink createHyperlink(){
|
public XSLFHyperlink createHyperlink(){
|
||||||
@ -568,8 +568,8 @@ public class XSLFTextRun implements TextRun {
|
|||||||
boolean italic = r.isItalic();
|
boolean italic = r.isItalic();
|
||||||
if(italic != isItalic()) setItalic(italic);
|
if(italic != isItalic()) setItalic(italic);
|
||||||
|
|
||||||
boolean underline = r.isUnderline();
|
boolean underline = r.isUnderlined();
|
||||||
if(underline != isUnderline()) setUnderline(underline);
|
if(underline != isUnderlined()) setUnderline(underline);
|
||||||
|
|
||||||
boolean strike = r.isStrikethrough();
|
boolean strike = r.isStrikethrough();
|
||||||
if(strike != isStrikethrough()) setStrikethrough(strike);
|
if(strike != isStrikethrough()) setStrikethrough(strike);
|
||||||
|
@ -112,7 +112,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape
|
|||||||
* Sets the type of vertical alignment for the text.
|
* Sets the type of vertical alignment for the text.
|
||||||
*
|
*
|
||||||
* @param anchor - the type of alignment.
|
* @param anchor - the type of alignment.
|
||||||
* A <code>null</code> values unsets this property.
|
* A {@code null} values unsets this property.
|
||||||
*/
|
*/
|
||||||
public void setVerticalAlignment(VerticalAlignment anchor){
|
public void setVerticalAlignment(VerticalAlignment anchor){
|
||||||
CTTextBodyProperties bodyPr = getTextBodyPr();
|
CTTextBodyProperties bodyPr = getTextBodyPr();
|
||||||
@ -145,6 +145,40 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape
|
|||||||
return fetcher.getValue() == null ? VerticalAlignment.TOP : fetcher.getValue();
|
return fetcher.getValue() == null ? VerticalAlignment.TOP : fetcher.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if the paragraphs are horizontal centered
|
||||||
|
*
|
||||||
|
* @param isCentered true, if the paragraphs are horizontal centered
|
||||||
|
* A {@code null} values unsets this property.
|
||||||
|
*
|
||||||
|
* @see TextShape#isHorizontalCentered()
|
||||||
|
*/
|
||||||
|
public void setHorizontalCentered(Boolean isCentered){
|
||||||
|
CTTextBodyProperties bodyPr = getTextBodyPr();
|
||||||
|
if (bodyPr != null) {
|
||||||
|
if (isCentered == null) {
|
||||||
|
if (bodyPr.isSetAnchorCtr()) bodyPr.unsetAnchorCtr();
|
||||||
|
} else {
|
||||||
|
bodyPr.setAnchorCtr(isCentered);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHorizontalCentered(){
|
||||||
|
PropertyFetcher<Boolean> fetcher = new TextBodyPropertyFetcher<Boolean>(){
|
||||||
|
public boolean fetch(CTTextBodyProperties props){
|
||||||
|
if(props.isSetAnchorCtr()){
|
||||||
|
setValue(props.getAnchorCtr());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchShapeProperty(fetcher);
|
||||||
|
return fetcher.getValue() == null ? false : fetcher.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param orientation vertical orientation of the text
|
* @param orientation vertical orientation of the text
|
||||||
@ -266,7 +300,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the botom margin.
|
* Sets the bottom margin.
|
||||||
* @see #getBottomInset()
|
* @see #getBottomInset()
|
||||||
*
|
*
|
||||||
* @param margin the bottom margin
|
* @param margin the bottom margin
|
||||||
@ -429,9 +463,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Compute the cumulative height occupied by the text
|
|
||||||
*/
|
|
||||||
public double getTextHeight(){
|
public double getTextHeight(){
|
||||||
DrawFactory drawFact = DrawFactory.getInstance(null);
|
DrawFactory drawFact = DrawFactory.getInstance(null);
|
||||||
DrawTextShape<XSLFTextShape> dts = drawFact.getDrawable(this);
|
DrawTextShape<XSLFTextShape> dts = drawFact.getDrawable(this);
|
||||||
|
@ -24,12 +24,14 @@ import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
|||||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An utulity to convert slides of a .pptx slide show to a PNG image
|
* An utulity to convert slides of a .pptx slide show to a PNG image
|
||||||
@ -79,11 +81,11 @@ public class PPTX2PNG {
|
|||||||
int width = (int) (pgsize.width * scale);
|
int width = (int) (pgsize.width * scale);
|
||||||
int height = (int) (pgsize.height * scale);
|
int height = (int) (pgsize.height * scale);
|
||||||
|
|
||||||
XSLFSlide[] slide = ppt.getSlides();
|
List<XSLFSlide> slide = ppt.getSlides();
|
||||||
for (int i = 0; i < slide.length; i++) {
|
for (int i = 0; i < slide.size(); i++) {
|
||||||
if (slidenum != -1 && slidenum != (i + 1)) continue;
|
if (slidenum != -1 && slidenum != (i + 1)) continue;
|
||||||
|
|
||||||
String title = slide[i].getTitle();
|
String title = slide.get(i).getTitle();
|
||||||
System.out.println("Rendering slide " + (i + 1) + (title == null ? "" : ": " + title));
|
System.out.println("Rendering slide " + (i + 1) + (title == null ? "" : ": " + title));
|
||||||
|
|
||||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
@ -101,7 +103,7 @@ public class PPTX2PNG {
|
|||||||
graphics.scale(scale, scale);
|
graphics.scale(scale, scale);
|
||||||
|
|
||||||
// draw stuff
|
// draw stuff
|
||||||
slide[i].draw(graphics);
|
slide.get(i).draw(graphics);
|
||||||
|
|
||||||
// save the result
|
// save the result
|
||||||
int sep = file.lastIndexOf(".");
|
int sep = file.lastIndexOf(".");
|
||||||
|
@ -55,8 +55,8 @@ public class TestXSLFBugs {
|
|||||||
public void bug51187() throws Exception {
|
public void bug51187() throws Exception {
|
||||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("51187.pptx");
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("51187.pptx");
|
||||||
|
|
||||||
assertEquals(1, ss.getSlides().length);
|
assertEquals(1, ss.getSlides().size());
|
||||||
XSLFSlide slide = ss.getSlides()[0];
|
XSLFSlide slide = ss.getSlides().get(0);
|
||||||
|
|
||||||
// Check the relations on it
|
// Check the relations on it
|
||||||
// Note - rId3 is a self reference
|
// Note - rId3 is a self reference
|
||||||
@ -71,7 +71,7 @@ public class TestXSLFBugs {
|
|||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
||||||
assertEquals(1, ss.getSlides().length);
|
assertEquals(1, ss.getSlides().size());
|
||||||
|
|
||||||
slidePart = ss._getXSLFSlideShow().getSlidePart(
|
slidePart = ss._getXSLFSlideShow().getSlidePart(
|
||||||
ss._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
|
ss._getXSLFSlideShow().getSlideReferences().getSldIdArray(0)
|
||||||
@ -92,8 +92,8 @@ public class TestXSLFBugs {
|
|||||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("with_japanese.pptx");
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("with_japanese.pptx");
|
||||||
|
|
||||||
// Should have one slide
|
// Should have one slide
|
||||||
assertEquals(1, ss.getSlides().length);
|
assertEquals(1, ss.getSlides().size());
|
||||||
XSLFSlide slide = ss.getSlides()[0];
|
XSLFSlide slide = ss.getSlides().get(0);
|
||||||
|
|
||||||
// Check the relations from this
|
// Check the relations from this
|
||||||
List<POIXMLDocumentPart> rels = slide.getRelations();
|
List<POIXMLDocumentPart> rels = slide.getRelations();
|
||||||
@ -142,20 +142,20 @@ public class TestXSLFBugs {
|
|||||||
XSLFSlide slide;
|
XSLFSlide slide;
|
||||||
|
|
||||||
// Should find 4 slides
|
// Should find 4 slides
|
||||||
assertEquals(4, ss.getSlides().length);
|
assertEquals(4, ss.getSlides().size());
|
||||||
|
|
||||||
// Check the text, to see we got them in order
|
// Check the text, to see we got them in order
|
||||||
slide = ss.getSlides()[0];
|
slide = ss.getSlides().get(0);
|
||||||
assertContains("POI cannot read this", getSlideText(slide));
|
assertContains("POI cannot read this", getSlideText(slide));
|
||||||
|
|
||||||
slide = ss.getSlides()[1];
|
slide = ss.getSlides().get(1);
|
||||||
assertContains("POI can read this", getSlideText(slide));
|
assertContains("POI can read this", getSlideText(slide));
|
||||||
assertContains("Has a relationship to another slide", getSlideText(slide));
|
assertContains("Has a relationship to another slide", getSlideText(slide));
|
||||||
|
|
||||||
slide = ss.getSlides()[2];
|
slide = ss.getSlides().get(2);
|
||||||
assertContains("POI can read this", getSlideText(slide));
|
assertContains("POI can read this", getSlideText(slide));
|
||||||
|
|
||||||
slide = ss.getSlides()[3];
|
slide = ss.getSlides().get(3);
|
||||||
assertContains("POI can read this", getSlideText(slide));
|
assertContains("POI can read this", getSlideText(slide));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,13 +196,13 @@ public class TestXSLFBugs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Similar to TestFontRendering it doesn't make sense to compare images because of tiny rendering differences in windows/unix")
|
// @Ignore("Similar to TestFontRendering it doesn't make sense to compare images because of tiny rendering differences in windows/unix")
|
||||||
public void bug54542() throws Exception {
|
public void bug54542() throws Exception {
|
||||||
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("54542_cropped_bitmap.pptx");
|
XMLSlideShow ss = XSLFTestDataSamples.openSampleDocument("54542_cropped_bitmap.pptx");
|
||||||
|
|
||||||
Dimension pgsize = ss.getPageSize();
|
Dimension pgsize = ss.getPageSize();
|
||||||
|
|
||||||
XSLFSlide slide = ss.getSlides()[0];
|
XSLFSlide slide = ss.getSlides().get(0);
|
||||||
|
|
||||||
// render it
|
// render it
|
||||||
double zoom = 1;
|
double zoom = 1;
|
||||||
@ -265,10 +265,10 @@ public class TestXSLFBugs {
|
|||||||
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(slideTexts.length, ss.getSlides().length);
|
assertEquals(slideTexts.length, ss.getSlides().size());
|
||||||
|
|
||||||
for (int i = 0; i < slideTexts.length; i++) {
|
for (int i = 0; i < slideTexts.length; i++) {
|
||||||
XSLFSlide slide = ss.getSlides()[i];
|
XSLFSlide slide = ss.getSlides().get(i);
|
||||||
assertContains(getSlideText(slide), slideTexts[i]);
|
assertContains(getSlideText(slide), slideTexts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,19 +18,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.xslf.geom;
|
package org.apache.poi.xslf.geom;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.apache.poi.xslf.model.geom.Context;
|
|
||||||
import org.apache.poi.xslf.model.geom.CustomGeometry;
|
import org.apache.poi.sl.draw.binding.CTCustomGeometry2D;
|
||||||
import org.apache.poi.xslf.model.geom.Formula;
|
import org.apache.poi.sl.draw.geom.*;
|
||||||
import org.apache.poi.xslf.model.geom.Guide;
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date: 10/24/11
|
* Date: 10/24/11
|
||||||
*
|
*
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestFormulaParser extends TestCase {
|
public class TestFormulaParser {
|
||||||
|
@Test
|
||||||
public void testParse(){
|
public void testParse(){
|
||||||
|
|
||||||
Formula[] ops = {
|
Formula[] ops = {
|
||||||
@ -44,18 +44,18 @@ public class TestFormulaParser extends TestCase {
|
|||||||
new Guide("a5", "abs -2"),
|
new Guide("a5", "abs -2"),
|
||||||
};
|
};
|
||||||
|
|
||||||
CustomGeometry geom = new CustomGeometry(CTCustomGeometry2D.Factory.newInstance());
|
CustomGeometry geom = new CustomGeometry(new CTCustomGeometry2D());
|
||||||
Context ctx = new Context(geom, null, null);
|
Context ctx = new Context(geom, null, null);
|
||||||
for(Formula fmla : ops) {
|
for(Formula fmla : ops) {
|
||||||
ctx.evaluate(fmla);
|
ctx.evaluate(fmla);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(100.0, ctx.getValue("adj1"));
|
assertEquals(100.0, ctx.getValue("adj1"), 0.0);
|
||||||
assertEquals(200.0, ctx.getValue("adj2"));
|
assertEquals(200.0, ctx.getValue("adj2"), 0.0);
|
||||||
assertEquals(1.0, ctx.getValue("a1"));
|
assertEquals(1.0, ctx.getValue("a1"), 0.0);
|
||||||
assertEquals(101.0, ctx.getValue("a2"));
|
assertEquals(101.0, ctx.getValue("a2"), 0.0);
|
||||||
assertEquals(1.5, ctx.getValue("a3"));
|
assertEquals(1.5, ctx.getValue("a3"), 0.0);
|
||||||
assertEquals(200.0, ctx.getValue("a4"));
|
assertEquals(200.0, ctx.getValue("a4"), 0.0);
|
||||||
assertEquals(2.0, ctx.getValue("a5"));
|
assertEquals(2.0, ctx.getValue("a5"), 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,24 +18,23 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.xslf.geom;
|
package org.apache.poi.xslf.geom;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.apache.poi.xslf.model.geom.Context;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import org.apache.poi.xslf.model.geom.CustomGeometry;
|
|
||||||
import org.apache.poi.xslf.model.geom.Guide;
|
|
||||||
import org.apache.poi.xslf.model.geom.IAdjustableShape;
|
|
||||||
import org.apache.poi.xslf.model.geom.Path;
|
|
||||||
import org.apache.poi.xslf.model.geom.PresetGeometries;
|
|
||||||
|
|
||||||
import java.awt.geom.GeneralPath;
|
import java.awt.geom.GeneralPath;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.poi.sl.draw.geom.*;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date: 10/24/11
|
* Date: 10/24/11
|
||||||
*
|
*
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestPresetGeometries extends TestCase {
|
public class TestPresetGeometries {
|
||||||
|
@Test
|
||||||
public void testRead(){
|
public void testRead(){
|
||||||
|
|
||||||
Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
|
Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
|
||||||
|
@ -25,7 +25,7 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.TextPainter;
|
import org.apache.poi.sl.draw.Drawable;
|
||||||
import org.apache.poi.util.JvmBugs;
|
import org.apache.poi.util.JvmBugs;
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -56,10 +56,10 @@ public class TestPPTX2PNG {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void fixFonts(Graphics2D graphics) {
|
private void fixFonts(Graphics2D graphics) {
|
||||||
if (!JvmBugs.hasLineBreakMeasurerBug()) return;
|
if (!JvmBugs.hasLineBreakMeasurerBug()) return;
|
||||||
Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(TextPainter.KEY_FONTMAP);
|
Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(Drawable.FONT_MAP);
|
||||||
if (fontMap == null) fontMap = new HashMap<String,String>();
|
if (fontMap == null) fontMap = new HashMap<String,String>();
|
||||||
fontMap.put("Calibri", "Lucida Sans");
|
fontMap.put("Calibri", "Lucida Sans");
|
||||||
fontMap.put("Cambria", "Lucida Bright");
|
fontMap.put("Cambria", "Lucida Bright");
|
||||||
graphics.setRenderingHint(TextPainter.KEY_FONTMAP, fontMap);
|
graphics.setRenderingHint(Drawable.FONT_MAP, fontMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,23 +16,25 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesMasterIdListEntry;
|
import org.junit.Before;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry;
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry;
|
import org.openxmlformats.schemas.presentationml.x2006.main.*;
|
||||||
|
|
||||||
public class TestXMLSlideShow extends TestCase {
|
public class TestXMLSlideShow {
|
||||||
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
private OPCPackage pack;
|
private OPCPackage pack;
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
|
pack = OPCPackage.open(slTests.openResourceAsStream("sample.pptx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testContainsMainContentType() throws Exception {
|
public void testContainsMainContentType() throws Exception {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for(PackagePart part : pack.getParts()) {
|
for(PackagePart part : pack.getParts()) {
|
||||||
@ -43,6 +45,7 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertTrue(found);
|
assertTrue(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOpen() throws Exception {
|
public void testOpen() throws Exception {
|
||||||
XMLSlideShow xml;
|
XMLSlideShow xml;
|
||||||
|
|
||||||
@ -52,22 +55,20 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertNotNull(xml.getCTPresentation());
|
assertNotNull(xml.getCTPresentation());
|
||||||
|
|
||||||
// Check it has some slides
|
// Check it has some slides
|
||||||
assertNotNull(xml.getSlides().length);
|
assertFalse(xml.getSlides().isEmpty());
|
||||||
assertTrue(xml.getSlides().length > 0);
|
assertFalse(xml.getSlideMasters().isEmpty());
|
||||||
|
|
||||||
assertNotNull(xml.getSlideMasters().length);
|
|
||||||
assertTrue(xml.getSlideMasters().length > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void testSlideBasics() throws Exception {
|
public void testSlideBasics() throws Exception {
|
||||||
XMLSlideShow xml = new XMLSlideShow(pack);
|
XMLSlideShow xml = new XMLSlideShow(pack);
|
||||||
|
|
||||||
// Should have 1 master
|
// Should have 1 master
|
||||||
assertEquals(1, xml.getSlideMasters().length);
|
assertEquals(1, xml.getSlideMasters().size());
|
||||||
|
|
||||||
// Should have two sheets
|
// Should have two sheets
|
||||||
assertEquals(2, xml.getSlides().length);
|
assertEquals(2, xml.getSlides().size());
|
||||||
|
|
||||||
// Check they're as expected
|
// Check they're as expected
|
||||||
CTSlideIdListEntry[] slides = xml.getCTPresentation().getSldIdLst().getSldIdArray();
|
CTSlideIdListEntry[] slides = xml.getCTPresentation().getSldIdLst().getSldIdArray();
|
||||||
@ -78,19 +79,19 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertEquals("rId3", slides[1].getId2());
|
assertEquals("rId3", slides[1].getId2());
|
||||||
|
|
||||||
// Now get those objects
|
// Now get those objects
|
||||||
assertNotNull(xml.getSlides()[0]);
|
assertNotNull(xml.getSlides().get(0));
|
||||||
assertNotNull(xml.getSlides()[1]);
|
assertNotNull(xml.getSlides().get(1));
|
||||||
|
|
||||||
// And check they have notes as expected
|
// And check they have notes as expected
|
||||||
assertNotNull(xml.getSlides()[0].getNotes());
|
assertNotNull(xml.getSlides().get(0).getNotes());
|
||||||
assertNotNull(xml.getSlides()[1].getNotes());
|
assertNotNull(xml.getSlides().get(1).getNotes());
|
||||||
|
|
||||||
// Next up look for the slide master
|
// Next up look for the slide master
|
||||||
CTSlideMasterIdListEntry[] masters = xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdArray();
|
CTSlideMasterIdListEntry[] masters = xml.getCTPresentation().getSldMasterIdLst().getSldMasterIdArray();
|
||||||
|
|
||||||
assertEquals(2147483648l, masters[0].getId());
|
assertEquals(2147483648l, masters[0].getId());
|
||||||
assertEquals("rId1", masters[0].getId2());
|
assertEquals("rId1", masters[0].getId2());
|
||||||
assertNotNull(xml.getSlideMasters()[0]);
|
assertNotNull(xml.getSlideMasters().get(0));
|
||||||
|
|
||||||
// Finally look for the notes master
|
// Finally look for the notes master
|
||||||
CTNotesMasterIdListEntry notesMaster =
|
CTNotesMasterIdListEntry notesMaster =
|
||||||
@ -100,6 +101,7 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertNotNull(xml.getNotesMaster());
|
assertNotNull(xml.getNotesMaster());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMetadataBasics() throws Exception {
|
public void testMetadataBasics() throws Exception {
|
||||||
XMLSlideShow xml = new XMLSlideShow(pack);
|
XMLSlideShow xml = new XMLSlideShow(pack);
|
||||||
|
|
||||||
@ -114,6 +116,7 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
|
assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testComments() throws Exception {
|
public void testComments() throws Exception {
|
||||||
// Default sample file has none
|
// Default sample file has none
|
||||||
XMLSlideShow xml = new XMLSlideShow(pack);
|
XMLSlideShow xml = new XMLSlideShow(pack);
|
||||||
@ -134,8 +137,9 @@ public class TestXMLSlideShow extends TestCase {
|
|||||||
assertEquals("XPVMWARE01", xmlComments.getCommentAuthors().getAuthorById(0).getName());
|
assertEquals("XPVMWARE01", xmlComments.getCommentAuthors().getAuthorById(0).getName());
|
||||||
|
|
||||||
// First two slides have comments
|
// First two slides have comments
|
||||||
for (int i=0; i<xmlComments.getSlides().length; i++) {
|
int i = -1;
|
||||||
XSLFSlide slide = xmlComments.getSlides()[i];
|
for (XSLFSlide slide : xmlComments.getSlides()) {
|
||||||
|
i++;
|
||||||
|
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
assertNotNull(slide.getComments());
|
assertNotNull(slide.getComments());
|
||||||
|
@ -16,20 +16,22 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.poi.sl.usermodel.*;
|
import org.apache.poi.sl.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
||||||
import org.apache.poi.sl.usermodel.TextShape.TextAutofit;
|
import org.apache.poi.sl.usermodel.TextShape.TextAutofit;
|
||||||
import org.apache.poi.sl.usermodel.TextShape.TextDirection;
|
import org.apache.poi.sl.usermodel.TextShape.TextDirection;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
|
import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
|
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFAutoShape extends TestCase {
|
public class TestXSLFAutoShape {
|
||||||
|
@Test
|
||||||
public void testTextBodyProperies() {
|
public void testTextBodyProperies() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
@ -38,38 +40,38 @@ public class TestXSLFAutoShape extends TestCase {
|
|||||||
shape.addNewTextParagraph().addNewTextRun().setText("POI");
|
shape.addNewTextParagraph().addNewTextRun().setText("POI");
|
||||||
|
|
||||||
// default margins from slide master
|
// default margins from slide master
|
||||||
assertEquals(3.6, shape.getBottomInset());
|
assertEquals(3.6, shape.getBottomInset(), 0);
|
||||||
assertEquals(3.6, shape.getTopInset());
|
assertEquals(3.6, shape.getTopInset(), 0);
|
||||||
assertEquals(7.2, shape.getLeftInset());
|
assertEquals(7.2, shape.getLeftInset(), 0);
|
||||||
assertEquals(7.2, shape.getRightInset());
|
assertEquals(7.2, shape.getRightInset(), 0);
|
||||||
|
|
||||||
shape.setBottomInset(1.0);
|
shape.setBottomInset(1.0);
|
||||||
assertEquals(1.0, shape.getBottomInset());
|
assertEquals(1.0, shape.getBottomInset(), 0);
|
||||||
shape.setTopInset(2.0);
|
shape.setTopInset(2.0);
|
||||||
assertEquals(2.0, shape.getTopInset());
|
assertEquals(2.0, shape.getTopInset(), 0);
|
||||||
shape.setLeftInset(3.0);
|
shape.setLeftInset(3.0);
|
||||||
assertEquals(3.0, shape.getLeftInset());
|
assertEquals(3.0, shape.getLeftInset(), 0);
|
||||||
shape.setRightInset(4.0);
|
shape.setRightInset(4.0);
|
||||||
assertEquals(4.0, shape.getRightInset());
|
assertEquals(4.0, shape.getRightInset(), 0);
|
||||||
|
|
||||||
shape.setBottomInset(0.0);
|
shape.setBottomInset(0.0);
|
||||||
assertEquals(0.0, shape.getBottomInset());
|
assertEquals(0.0, shape.getBottomInset(), 0);
|
||||||
shape.setTopInset(0.0);
|
shape.setTopInset(0.0);
|
||||||
assertEquals(0.0, shape.getTopInset());
|
assertEquals(0.0, shape.getTopInset(), 0);
|
||||||
shape.setLeftInset(0.0);
|
shape.setLeftInset(0.0);
|
||||||
assertEquals(0.0, shape.getLeftInset());
|
assertEquals(0.0, shape.getLeftInset(), 0);
|
||||||
shape.setRightInset(0.0);
|
shape.setRightInset(0.0);
|
||||||
assertEquals(0.0, shape.getRightInset());
|
assertEquals(0.0, shape.getRightInset(), 0);
|
||||||
|
|
||||||
// unset to defauls
|
// unset to defauls
|
||||||
shape.setBottomInset(-1);
|
shape.setBottomInset(-1);
|
||||||
assertEquals(3.6, shape.getBottomInset());
|
assertEquals(3.6, shape.getBottomInset(), 0);
|
||||||
shape.setTopInset(-1);
|
shape.setTopInset(-1);
|
||||||
assertEquals(3.6, shape.getTopInset());
|
assertEquals(3.6, shape.getTopInset(), 0);
|
||||||
shape.setLeftInset(-1);
|
shape.setLeftInset(-1);
|
||||||
assertEquals(7.2, shape.getLeftInset());
|
assertEquals(7.2, shape.getLeftInset(), 0);
|
||||||
shape.setRightInset(-1);
|
shape.setRightInset(-1);
|
||||||
assertEquals(7.2, shape.getRightInset());
|
assertEquals(7.2, shape.getRightInset(), 0);
|
||||||
|
|
||||||
// shape
|
// shape
|
||||||
assertTrue(shape.getWordWrap());
|
assertTrue(shape.getWordWrap());
|
||||||
@ -102,31 +104,32 @@ public class TestXSLFAutoShape extends TestCase {
|
|||||||
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
|
assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTextParagraph() {
|
public void testTextParagraph() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertEquals(0, slide.getShapes().length);
|
assertTrue(slide.getShapes().isEmpty());
|
||||||
|
|
||||||
XSLFAutoShape shape = slide.createAutoShape();
|
XSLFAutoShape shape = slide.createAutoShape();
|
||||||
assertEquals(0, shape.getTextParagraphs().size());
|
assertEquals(0, shape.getTextParagraphs().size());
|
||||||
XSLFTextParagraph p = shape.addNewTextParagraph();
|
XSLFTextParagraph p = shape.addNewTextParagraph();
|
||||||
assertEquals(1, shape.getTextParagraphs().size());
|
assertEquals(1, shape.getTextParagraphs().size());
|
||||||
|
|
||||||
assertEquals(0., p.getIndent());
|
assertEquals(0., p.getIndent(), 0);
|
||||||
assertEquals(0., p.getLeftMargin());
|
assertEquals(0., p.getLeftMargin(), 0);
|
||||||
assertEquals(100., p.getLineSpacing());
|
assertEquals(100., p.getLineSpacing(), 0);
|
||||||
assertEquals(0., p.getSpaceAfter());
|
assertEquals(0., p.getSpaceAfter(), 0);
|
||||||
assertEquals(0., p.getSpaceBefore());
|
assertEquals(0., p.getSpaceBefore(), 0);
|
||||||
assertEquals(0, p.getLevel());
|
assertEquals(0, p.getLevel());
|
||||||
|
|
||||||
p.setIndent(2.0);
|
p.setIndent(2.0);
|
||||||
assertEquals(2.0, p.getIndent());
|
assertEquals(2.0, p.getIndent(), 0);
|
||||||
assertTrue(p.getXmlObject().getPPr().isSetIndent());
|
assertTrue(p.getXmlObject().getPPr().isSetIndent());
|
||||||
p.setIndent(-1);
|
p.setIndent(-1);
|
||||||
assertEquals(0.0, p.getIndent());
|
assertEquals(0.0, p.getIndent(), 0);
|
||||||
assertFalse(p.getXmlObject().getPPr().isSetIndent());
|
assertFalse(p.getXmlObject().getPPr().isSetIndent());
|
||||||
p.setIndent(10.0);
|
p.setIndent(10.0);
|
||||||
assertEquals(10., p.getIndent());
|
assertEquals(10., p.getIndent(), 0);
|
||||||
assertTrue(p.getXmlObject().getPPr().isSetIndent());
|
assertTrue(p.getXmlObject().getPPr().isSetIndent());
|
||||||
|
|
||||||
|
|
||||||
@ -138,10 +141,10 @@ public class TestXSLFAutoShape extends TestCase {
|
|||||||
assertEquals(2, p.getLevel());
|
assertEquals(2, p.getLevel());
|
||||||
|
|
||||||
p.setLeftMargin(2.0);
|
p.setLeftMargin(2.0);
|
||||||
assertEquals(2.0, p.getLeftMargin());
|
assertEquals(2.0, p.getLeftMargin(), 0);
|
||||||
assertTrue(p.getXmlObject().getPPr().isSetMarL());
|
assertTrue(p.getXmlObject().getPPr().isSetMarL());
|
||||||
p.setLeftMargin(10.0);
|
p.setLeftMargin(10.0);
|
||||||
assertEquals(10., p.getLeftMargin());
|
assertEquals(10., p.getLeftMargin(), 0);
|
||||||
assertEquals(Units.toEMU(10), p.getXmlObject().getPPr().getMarL());
|
assertEquals(Units.toEMU(10), p.getXmlObject().getPPr().getMarL());
|
||||||
|
|
||||||
|
|
||||||
@ -201,6 +204,7 @@ public class TestXSLFAutoShape extends TestCase {
|
|||||||
assertFalse(p.getXmlObject().getPPr().isSetAlgn());
|
assertFalse(p.getXmlObject().getPPr().isSetAlgn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTextRun() {
|
public void testTextRun() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
@ -214,7 +218,7 @@ public class TestXSLFAutoShape extends TestCase {
|
|||||||
assertEquals(1, p.getTextRuns().size());
|
assertEquals(1, p.getTextRuns().size());
|
||||||
assertSame(r, p.getTextRuns().get(0));
|
assertSame(r, p.getTextRuns().get(0));
|
||||||
|
|
||||||
assertEquals(18.0, r.getFontSize()); // default font size for text boxes
|
assertEquals(18.0, r.getFontSize(), 0); // default font size for text boxes
|
||||||
assertFalse(r.getXmlObject().getRPr().isSetSz());
|
assertFalse(r.getXmlObject().getRPr().isSetSz());
|
||||||
r.setFontSize(10.0);
|
r.setFontSize(10.0);
|
||||||
assertTrue(r.getXmlObject().isSetRPr());
|
assertTrue(r.getXmlObject().isSetRPr());
|
||||||
@ -256,20 +260,21 @@ public class TestXSLFAutoShape extends TestCase {
|
|||||||
assertTrue(r.isItalic());
|
assertTrue(r.isItalic());
|
||||||
assertEquals(true, r.getXmlObject().getRPr().getI());
|
assertEquals(true, r.getXmlObject().getRPr().getI());
|
||||||
|
|
||||||
assertFalse(r.isUnderline());
|
assertFalse(r.isUnderlined());
|
||||||
assertFalse(r.getXmlObject().getRPr().isSetU());
|
assertFalse(r.getXmlObject().getRPr().isSetU());
|
||||||
r.setUnderline(true);
|
r.setUnderline(true);
|
||||||
assertTrue(r.isUnderline());
|
assertTrue(r.isUnderlined());
|
||||||
assertEquals(STTextUnderlineType.SNG, r.getXmlObject().getRPr().getU());
|
assertEquals(STTextUnderlineType.SNG, r.getXmlObject().getRPr().getU());
|
||||||
|
|
||||||
r.setText("Apache");
|
r.setText("Apache");
|
||||||
assertEquals("Apache", r.getText());
|
assertEquals("Apache", r.getRawText());
|
||||||
r.setText("POI");
|
r.setText("POI");
|
||||||
assertEquals("POI", r.getText());
|
assertEquals("POI", r.getRawText());
|
||||||
r.setText(null);
|
r.setText(null);
|
||||||
assertNull(r.getText());
|
assertNull(r.getRawText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testShapeType() {
|
public void testShapeType() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
@ -46,7 +46,7 @@ public class TestXSLFChart extends TestCase {
|
|||||||
String chartTitle = "Apache POI"; // first line is chart title
|
String chartTitle = "Apache POI"; // first line is chart title
|
||||||
|
|
||||||
XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("pie-chart.pptx");
|
XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument("pie-chart.pptx");
|
||||||
XSLFSlide slide = pptx.getSlides()[0];
|
XSLFSlide slide = pptx.getSlides().get(0);
|
||||||
|
|
||||||
// find chart in the slide
|
// find chart in the slide
|
||||||
XSLFChart chart = null;
|
XSLFChart chart = null;
|
||||||
|
@ -16,28 +16,31 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;
|
import org.apache.poi.sl.usermodel.LineDecoration.DecorationShape;
|
||||||
import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
|
import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;
|
||||||
import org.apache.poi.sl.usermodel.*;
|
import org.apache.poi.sl.usermodel.*;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTConnector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFConnectorShape extends TestCase {
|
public class TestXSLFConnectorShape {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLineDecorations() {
|
public void testLineDecorations() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
XSLFConnectorShape shape = slide.createConnector();
|
XSLFConnectorShape shape = slide.createConnector();
|
||||||
assertEquals(1, slide.getShapes().length);
|
assertEquals(1, slide.getShapes().size());
|
||||||
|
|
||||||
assertFalse(shape.getSpPr().getLn().isSetHeadEnd());
|
assertFalse(shape.getSpPr().getLn().isSetHeadEnd());
|
||||||
assertFalse(shape.getSpPr().getLn().isSetTailEnd());
|
assertFalse(shape.getSpPr().getLn().isSetTailEnd());
|
||||||
@ -112,6 +115,7 @@ public class TestXSLFConnectorShape extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAddConnector(){
|
public void testAddConnector(){
|
||||||
XMLSlideShow pptx = new XMLSlideShow();
|
XMLSlideShow pptx = new XMLSlideShow();
|
||||||
XSLFSlide slide = pptx.createSlide();
|
XSLFSlide slide = pptx.createSlide();
|
||||||
|
@ -16,17 +16,20 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.geom.Ellipse2D;
|
import java.awt.geom.Ellipse2D;
|
||||||
import java.awt.geom.GeneralPath;
|
import java.awt.geom.GeneralPath;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFFreeformShape extends TestCase {
|
public class TestXSLFFreeformShape {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetPath() {
|
public void testSetPath() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
@ -16,16 +16,19 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFGroupShape extends TestCase {
|
public class TestXSLFGroupShape {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateShapes() {
|
public void testCreateShapes() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
@ -33,7 +36,7 @@ public class TestXSLFGroupShape extends TestCase {
|
|||||||
ppt.setPageSize(new Dimension(792, 612));
|
ppt.setPageSize(new Dimension(792, 612));
|
||||||
|
|
||||||
XSLFGroupShape group = slide.createGroup();
|
XSLFGroupShape group = slide.createGroup();
|
||||||
assertEquals(1, slide.getShapes().length);
|
assertEquals(1, slide.getShapes().size());
|
||||||
|
|
||||||
Rectangle2D interior = new Rectangle2D.Double(-10, -10, 20, 20);
|
Rectangle2D interior = new Rectangle2D.Double(-10, -10, 20, 20);
|
||||||
group.setInteriorAnchor(interior);
|
group.setInteriorAnchor(interior);
|
||||||
@ -43,45 +46,46 @@ public class TestXSLFGroupShape extends TestCase {
|
|||||||
group.setAnchor(anchor);
|
group.setAnchor(anchor);
|
||||||
assertEquals(anchor, group.getAnchor());
|
assertEquals(anchor, group.getAnchor());
|
||||||
|
|
||||||
assertEquals(0, group.getShapes().length);
|
assertTrue(group.getShapes().isEmpty());
|
||||||
|
|
||||||
XSLFTextBox shape1 = group.createTextBox();
|
XSLFTextBox shape1 = group.createTextBox();
|
||||||
assertEquals(1, group.getShapes().length);
|
assertEquals(1, group.getShapes().size());
|
||||||
assertSame(shape1, group.getShapes()[0]);
|
assertSame(shape1, group.getShapes().get(0));
|
||||||
assertEquals(3, shape1.getShapeId());
|
assertEquals(3, shape1.getShapeId());
|
||||||
|
|
||||||
XSLFAutoShape shape2 = group.createAutoShape();
|
XSLFAutoShape shape2 = group.createAutoShape();
|
||||||
assertEquals(2, group.getShapes().length);
|
assertEquals(2, group.getShapes().size());
|
||||||
assertSame(shape1, group.getShapes()[0]);
|
assertSame(shape1, group.getShapes().get(0));
|
||||||
assertSame(shape2, group.getShapes()[1]);
|
assertSame(shape2, group.getShapes().get(1));
|
||||||
assertEquals(4, shape2.getShapeId());
|
assertEquals(4, shape2.getShapeId());
|
||||||
|
|
||||||
XSLFConnectorShape shape3 = group.createConnector();
|
XSLFConnectorShape shape3 = group.createConnector();
|
||||||
assertEquals(3, group.getShapes().length);
|
assertEquals(3, group.getShapes().size());
|
||||||
assertSame(shape3, group.getShapes()[2]);
|
assertSame(shape3, group.getShapes().get(2));
|
||||||
assertEquals(5, shape3.getShapeId());
|
assertEquals(5, shape3.getShapeId());
|
||||||
|
|
||||||
XSLFGroupShape shape4 = group.createGroup();
|
XSLFGroupShape shape4 = group.createGroup();
|
||||||
assertEquals(4, group.getShapes().length);
|
assertEquals(4, group.getShapes().size());
|
||||||
assertSame(shape4, group.getShapes()[3]);
|
assertSame(shape4, group.getShapes().get(3));
|
||||||
assertEquals(6, shape4.getShapeId());
|
assertEquals(6, shape4.getShapeId());
|
||||||
|
|
||||||
group.removeShape(shape2);
|
group.removeShape(shape2);
|
||||||
assertEquals(3, group.getShapes().length);
|
assertEquals(3, group.getShapes().size());
|
||||||
assertSame(shape1, group.getShapes()[0]);
|
assertSame(shape1, group.getShapes().get(0));
|
||||||
assertSame(shape3, group.getShapes()[1]);
|
assertSame(shape3, group.getShapes().get(1));
|
||||||
assertSame(shape4, group.getShapes()[2]);
|
assertSame(shape4, group.getShapes().get(2));
|
||||||
|
|
||||||
group.removeShape(shape3);
|
group.removeShape(shape3);
|
||||||
assertEquals(2, group.getShapes().length);
|
assertEquals(2, group.getShapes().size());
|
||||||
assertSame(shape1, group.getShapes()[0]);
|
assertSame(shape1, group.getShapes().get(0));
|
||||||
assertSame(shape4, group.getShapes()[1]);
|
assertSame(shape4, group.getShapes().get(1));
|
||||||
|
|
||||||
group.removeShape(shape1);
|
group.removeShape(shape1);
|
||||||
group.removeShape(shape4);
|
group.removeShape(shape4);
|
||||||
assertEquals(0, group.getShapes().length);
|
assertTrue(group.getShapes().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveShapes() {
|
public void testRemoveShapes() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
@ -16,24 +16,29 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFHyperlink extends TestCase {
|
public class TestXSLFHyperlink {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRead(){
|
public void testRead(){
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
|
|
||||||
XSLFSlide slide = ppt.getSlides()[4];
|
XSLFSlide slide = ppt.getSlides().get(4);
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
XSLFTable tbl = (XSLFTable)shapes[0];
|
XSLFTable tbl = (XSLFTable)shapes.get(0);
|
||||||
XSLFTableCell cell1 = tbl.getRows().get(1).getCells().get(0);
|
XSLFTableCell cell1 = tbl.getRows().get(1).getCells().get(0);
|
||||||
assertEquals("Web Page", cell1.getText());
|
assertEquals("Web Page", cell1.getText());
|
||||||
XSLFHyperlink link1 = cell1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
XSLFHyperlink link1 = cell1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
|
||||||
@ -53,6 +58,7 @@ public class TestXSLFHyperlink extends TestCase {
|
|||||||
assertEquals(URI.create("mailto:dev@poi.apache.org?subject=Hi%20There"), link3.getTargetURI());
|
assertEquals(URI.create("mailto:dev@poi.apache.org?subject=Hi%20There"), link3.getTargetURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreate() throws Exception {
|
public void testCreate() throws Exception {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide1 = ppt.createSlide();
|
XSLFSlide slide1 = ppt.createSlide();
|
||||||
|
@ -16,22 +16,20 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFPictureShape extends TestCase {
|
public class TestXSLFPictureShape {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreate() {
|
public void testCreate() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
assertEquals(0, ppt.getAllPictures().size());
|
assertEquals(0, ppt.getAllPictures().size());
|
||||||
@ -61,11 +59,12 @@ public class TestXSLFPictureShape extends TestCase {
|
|||||||
assertArrayEquals(data1, pics.get(0).getData());
|
assertArrayEquals(data1, pics.get(0).getData());
|
||||||
assertArrayEquals(data2, pics.get(1).getData());
|
assertArrayEquals(data2, pics.get(1).getData());
|
||||||
|
|
||||||
XSLFShape[] shapes = ppt.getSlides()[0].getShapes();
|
List<XSLFShape> shapes = ppt.getSlides().get(0).getShapes();
|
||||||
assertArrayEquals(data1, ((XSLFPictureShape) shapes[0]).getPictureData().getData());
|
assertArrayEquals(data1, ((XSLFPictureShape) shapes.get(0)).getPictureData().getData());
|
||||||
assertArrayEquals(data2, ((XSLFPictureShape) shapes[1]).getPictureData().getData());
|
assertArrayEquals(data2, ((XSLFPictureShape) shapes.get(1)).getPictureData().getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateMultiplePictures() {
|
public void testCreateMultiplePictures() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide1 = ppt.createSlide();
|
XSLFSlide slide1 = ppt.createSlide();
|
||||||
@ -118,6 +117,7 @@ public class TestXSLFPictureShape extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testImageCaching() {
|
public void testImageCaching() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
byte[] img1 = new byte[]{1,2,3};
|
byte[] img1 = new byte[]{1,2,3};
|
||||||
@ -137,6 +137,7 @@ public class TestXSLFPictureShape extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMerge() {
|
public void testMerge() {
|
||||||
XMLSlideShow ppt1 = new XMLSlideShow();
|
XMLSlideShow ppt1 = new XMLSlideShow();
|
||||||
byte[] data1 = new byte[100];
|
byte[] data1 = new byte[100];
|
||||||
@ -150,7 +151,7 @@ public class TestXSLFPictureShape extends TestCase {
|
|||||||
XMLSlideShow ppt2 = new XMLSlideShow();
|
XMLSlideShow ppt2 = new XMLSlideShow();
|
||||||
|
|
||||||
XSLFSlide slide2 = ppt2.createSlide().importContent(slide1);
|
XSLFSlide slide2 = ppt2.createSlide().importContent(slide1);
|
||||||
XSLFPictureShape shape2 = (XSLFPictureShape)slide2.getShapes()[0];
|
XSLFPictureShape shape2 = (XSLFPictureShape)slide2.getShapes().get(0);
|
||||||
|
|
||||||
assertArrayEquals(data1, shape2.getPictureData().getData());
|
assertArrayEquals(data1, shape2.getPictureData().getData());
|
||||||
|
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
|
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -25,17 +27,18 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFShape extends TestCase {
|
public class TestXSLFShape {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadTextShapes() {
|
public void testReadTextShapes() {
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
XSLFSlide[] slides = ppt.getSlides();
|
List<XSLFSlide> slides = ppt.getSlides();
|
||||||
|
|
||||||
XSLFSlide slide1 = slides[0];
|
XSLFSlide slide1 = slides.get(0);
|
||||||
XSLFShape[] shapes1 = slide1.getShapes();
|
List<XSLFShape> shapes1 = slide1.getShapes();
|
||||||
assertEquals(7, shapes1.length);
|
assertEquals(7, shapes1.size());
|
||||||
assertEquals("TextBox 3", shapes1[0].getShapeName());
|
assertEquals("TextBox 3", shapes1.get(0).getShapeName());
|
||||||
XSLFAutoShape sh0 = (XSLFAutoShape) shapes1[0];
|
XSLFAutoShape sh0 = (XSLFAutoShape) shapes1.get(0);
|
||||||
assertEquals("Learning PPTX", sh0.getText());
|
assertEquals("Learning PPTX", sh0.getText());
|
||||||
List<XSLFTextParagraph> paragraphs0 = sh0.getTextParagraphs();
|
List<XSLFTextParagraph> paragraphs0 = sh0.getTextParagraphs();
|
||||||
assertEquals(1, paragraphs0.size());
|
assertEquals(1, paragraphs0.size());
|
||||||
@ -43,28 +46,28 @@ public class TestXSLFShape extends TestCase {
|
|||||||
assertEquals("Learning PPTX", p0.getText());
|
assertEquals("Learning PPTX", p0.getText());
|
||||||
assertEquals(1, p0.getTextRuns().size());
|
assertEquals(1, p0.getTextRuns().size());
|
||||||
XSLFTextRun r0 = p0.getTextRuns().get(0);
|
XSLFTextRun r0 = p0.getTextRuns().get(0);
|
||||||
assertEquals("Learning PPTX", r0.getText());
|
assertEquals("Learning PPTX", r0.getRawText());
|
||||||
|
|
||||||
XSLFSlide slide2 = slides[1];
|
XSLFSlide slide2 = slides.get(1);
|
||||||
XSLFShape[] shapes2 = slide2.getShapes();
|
List<XSLFShape> shapes2 = slide2.getShapes();
|
||||||
assertTrue(shapes2[0] instanceof XSLFAutoShape);
|
assertTrue(shapes2.get(0) instanceof XSLFAutoShape);
|
||||||
assertEquals("PPTX Title", ((XSLFAutoShape) shapes2[0]).getText());
|
assertEquals("PPTX Title", ((XSLFAutoShape) shapes2.get(0)).getText());
|
||||||
XSLFAutoShape sh1 = (XSLFAutoShape) shapes2[0];
|
XSLFAutoShape sh1 = (XSLFAutoShape) shapes2.get(0);
|
||||||
List<XSLFTextParagraph> paragraphs1 = sh1.getTextParagraphs();
|
List<XSLFTextParagraph> paragraphs1 = sh1.getTextParagraphs();
|
||||||
assertEquals(1, paragraphs1.size());
|
assertEquals(1, paragraphs1.size());
|
||||||
XSLFTextParagraph p1 = paragraphs1.get(0);
|
XSLFTextParagraph p1 = paragraphs1.get(0);
|
||||||
assertEquals("PPTX Title", p1.getText());
|
assertEquals("PPTX Title", p1.getText());
|
||||||
List<XSLFTextRun> r2 = paragraphs1.get(0).getTextRuns();
|
List<XSLFTextRun> r2 = paragraphs1.get(0).getTextRuns();
|
||||||
assertEquals(2, r2.size());
|
assertEquals(2, r2.size());
|
||||||
assertEquals("PPTX ", r2.get(0).getText());
|
assertEquals("PPTX ", r2.get(0).getRawText());
|
||||||
assertEquals("Title", r2.get(1).getText());
|
assertEquals("Title", r2.get(1).getRawText());
|
||||||
// Title is underlined
|
// Title is underlined
|
||||||
assertEquals(STTextUnderlineType.SNG, r2.get(1).getXmlObject().getRPr().getU());
|
assertEquals(STTextUnderlineType.SNG, r2.get(1).getXmlObject().getRPr().getU());
|
||||||
|
|
||||||
|
|
||||||
assertTrue(shapes2[1] instanceof XSLFAutoShape);
|
assertTrue(shapes2.get(1) instanceof XSLFAutoShape);
|
||||||
assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape) shapes2[1]).getText());
|
assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape) shapes2.get(1)).getText());
|
||||||
XSLFAutoShape sh2 = (XSLFAutoShape) shapes2[1];
|
XSLFAutoShape sh2 = (XSLFAutoShape) shapes2.get(1);
|
||||||
List<XSLFTextParagraph> paragraphs2 = sh2.getTextParagraphs();
|
List<XSLFTextParagraph> paragraphs2 = sh2.getTextParagraphs();
|
||||||
assertEquals(2, paragraphs2.size());
|
assertEquals(2, paragraphs2.size());
|
||||||
assertEquals("Subtitle", paragraphs2.get(0).getText());
|
assertEquals("Subtitle", paragraphs2.get(0).getText());
|
||||||
@ -73,20 +76,20 @@ public class TestXSLFShape extends TestCase {
|
|||||||
assertEquals(1, paragraphs2.get(0).getTextRuns().size());
|
assertEquals(1, paragraphs2.get(0).getTextRuns().size());
|
||||||
assertEquals(1, paragraphs2.get(1).getTextRuns().size());
|
assertEquals(1, paragraphs2.get(1).getTextRuns().size());
|
||||||
|
|
||||||
assertEquals("Subtitle", paragraphs2.get(0).getTextRuns().get(0).getText());
|
assertEquals("Subtitle", paragraphs2.get(0).getTextRuns().get(0).getRawText());
|
||||||
assertTrue(paragraphs2.get(0).getTextRuns().get(0).getXmlObject().getRPr().getB());
|
assertTrue(paragraphs2.get(0).getTextRuns().get(0).getXmlObject().getRPr().getB());
|
||||||
assertEquals("And second line", paragraphs2.get(1).getTextRuns().get(0).getText());
|
assertEquals("And second line", paragraphs2.get(1).getTextRuns().get(0).getRawText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateShapes() {
|
public void testCreateShapes() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertEquals(0, slide.getShapes().length);
|
assertTrue(slide.getShapes().isEmpty());
|
||||||
|
|
||||||
XSLFTextBox textBox = slide.createTextBox();
|
XSLFTextBox textBox = slide.createTextBox();
|
||||||
|
|
||||||
assertEquals(1, slide.getShapes().length);
|
assertEquals(1, slide.getShapes().size());
|
||||||
assertSame(textBox, slide.getShapes()[0]);
|
assertSame(textBox, slide.getShapes().get(0));
|
||||||
|
|
||||||
assertEquals("", textBox.getText());
|
assertEquals("", textBox.getText());
|
||||||
assertEquals(0, textBox.getTextParagraphs().size());
|
assertEquals(0, textBox.getTextParagraphs().size());
|
||||||
|
@ -18,35 +18,40 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test common operations on containers of shapes (sheets and groups of shapes)
|
* test common operations on containers of shapes (sheets and groups of shapes)
|
||||||
*
|
*
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFShapeContainer extends TestCase {
|
public class TestXSLFShapeContainer {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Test
|
||||||
public void verifyContainer(XSLFShapeContainer container) {
|
public void verifyContainer(XSLFShapeContainer container) {
|
||||||
container.clear();
|
container.clear();
|
||||||
assertEquals(0, container.getShapes().length);
|
assertEquals(0, container.getShapes().size());
|
||||||
|
|
||||||
XSLFGroupShape shape1 = container.createGroup();
|
XSLFGroupShape shape1 = container.createGroup();
|
||||||
assertEquals(1, container.getShapes().length);
|
assertEquals(1, container.getShapes().size());
|
||||||
|
|
||||||
XSLFTextBox shape2 = container.createTextBox();
|
XSLFTextBox shape2 = container.createTextBox();
|
||||||
assertEquals(2, container.getShapes().length);
|
assertEquals(2, container.getShapes().size());
|
||||||
|
|
||||||
XSLFAutoShape shape3 = container.createAutoShape();
|
XSLFAutoShape shape3 = container.createAutoShape();
|
||||||
assertEquals(3, container.getShapes().length);
|
assertEquals(3, container.getShapes().size());
|
||||||
|
|
||||||
XSLFConnectorShape shape4 = container.createConnector();
|
XSLFConnectorShape shape4 = container.createConnector();
|
||||||
assertEquals(4, container.getShapes().length);
|
assertEquals(4, container.getShapes().size());
|
||||||
|
|
||||||
container.clear();
|
container.clear();
|
||||||
assertEquals(0, container.getShapes().length);
|
assertEquals(0, container.getShapes().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSheet() {
|
public void testSheet() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSheet sheet = ppt.createSlide();
|
XSLFSheet sheet = ppt.createSlide();
|
||||||
|
@ -16,50 +16,56 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test common properties for sheets (slides, masters, layouts, etc.)
|
* test common properties for sheets (slides, masters, layouts, etc.)
|
||||||
*
|
*
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFSheet extends TestCase {
|
public class TestXSLFSheet {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateShapes(){
|
public void testCreateShapes(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertEquals(0, slide.getShapes().length);
|
assertTrue(slide.getShapes().isEmpty());
|
||||||
|
|
||||||
XSLFSimpleShape shape1 = slide.createAutoShape();
|
XSLFSimpleShape shape1 = slide.createAutoShape();
|
||||||
assertEquals(1, slide.getShapes().length);
|
assertEquals(1, slide.getShapes().size());
|
||||||
assertSame(shape1, slide.getShapes()[0]);
|
assertSame(shape1, slide.getShapes().get(0));
|
||||||
|
|
||||||
XSLFTextBox shape2 = slide.createTextBox();
|
XSLFTextBox shape2 = slide.createTextBox();
|
||||||
assertEquals(2, slide.getShapes().length);
|
assertEquals(2, slide.getShapes().size());
|
||||||
assertSame(shape1, slide.getShapes()[0]);
|
assertSame(shape1, slide.getShapes().get(0));
|
||||||
assertSame(shape2, slide.getShapes()[1]);
|
assertSame(shape2, slide.getShapes().get(1));
|
||||||
|
|
||||||
XSLFConnectorShape shape3 = slide.createConnector();
|
XSLFConnectorShape shape3 = slide.createConnector();
|
||||||
assertEquals(3, slide.getShapes().length);
|
assertEquals(3, slide.getShapes().size());
|
||||||
assertSame(shape1, slide.getShapes()[0]);
|
assertSame(shape1, slide.getShapes().get(0));
|
||||||
assertSame(shape2, slide.getShapes()[1]);
|
assertSame(shape2, slide.getShapes().get(1));
|
||||||
assertSame(shape3, slide.getShapes()[2]);
|
assertSame(shape3, slide.getShapes().get(2));
|
||||||
|
|
||||||
XSLFGroupShape shape4 = slide.createGroup();
|
XSLFGroupShape shape4 = slide.createGroup();
|
||||||
assertEquals(4, slide.getShapes().length);
|
assertEquals(4, slide.getShapes().size());
|
||||||
assertSame(shape1, slide.getShapes()[0]);
|
assertSame(shape1, slide.getShapes().get(0));
|
||||||
assertSame(shape2, slide.getShapes()[1]);
|
assertSame(shape2, slide.getShapes().get(1));
|
||||||
assertSame(shape3, slide.getShapes()[2]);
|
assertSame(shape3, slide.getShapes().get(2));
|
||||||
assertSame(shape4, slide.getShapes()[3]);
|
assertSame(shape4, slide.getShapes().get(3));
|
||||||
|
|
||||||
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
||||||
slide = ppt.getSlides()[0];
|
slide = ppt.getSlides().get(0);
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals(4, shapes.length);
|
assertEquals(4, shapes.size());
|
||||||
|
|
||||||
assertTrue(shapes[0] instanceof XSLFAutoShape);
|
assertTrue(shapes.get(0) instanceof XSLFAutoShape);
|
||||||
assertTrue(shapes[1] instanceof XSLFTextBox);
|
assertTrue(shapes.get(1) instanceof XSLFTextBox);
|
||||||
assertTrue(shapes[2] instanceof XSLFConnectorShape);
|
assertTrue(shapes.get(2) instanceof XSLFConnectorShape);
|
||||||
assertTrue(shapes[3] instanceof XSLFGroupShape);
|
assertTrue(shapes.get(3) instanceof XSLFGroupShape);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,30 +16,34 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import java.awt.Color;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import java.awt.Color;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
|
import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
|
||||||
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
|
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFSimpleShape extends TestCase {
|
public class TestXSLFSimpleShape {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLineStyles() {
|
public void testLineStyles() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
|
||||||
XSLFSimpleShape shape = slide.createAutoShape();
|
XSLFSimpleShape shape = slide.createAutoShape();
|
||||||
assertEquals(1, slide.getShapes().length);
|
assertEquals(1, slide.getShapes().size());
|
||||||
// line properties are not set by default
|
// line properties are not set by default
|
||||||
assertFalse(shape.getSpPr().isSetLn());
|
assertFalse(shape.getSpPr().isSetLn());
|
||||||
|
|
||||||
assertEquals(0., shape.getLineWidth());
|
assertEquals(0., shape.getLineWidth(), 0);
|
||||||
assertEquals(null, shape.getLineColor());
|
assertEquals(null, shape.getLineColor());
|
||||||
assertEquals(null, shape.getLineDash());
|
assertEquals(null, shape.getLineDash());
|
||||||
assertEquals(null, shape.getLineCap());
|
assertEquals(null, shape.getLineCap());
|
||||||
@ -54,10 +58,10 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
|
|
||||||
// line width
|
// line width
|
||||||
shape.setLineWidth(1.0);
|
shape.setLineWidth(1.0);
|
||||||
assertEquals(1.0, shape.getLineWidth());
|
assertEquals(1.0, shape.getLineWidth(), 0);
|
||||||
assertEquals(Units.EMU_PER_POINT, shape.getSpPr().getLn().getW());
|
assertEquals(Units.EMU_PER_POINT, shape.getSpPr().getLn().getW());
|
||||||
shape.setLineWidth(5.5);
|
shape.setLineWidth(5.5);
|
||||||
assertEquals(5.5, shape.getLineWidth());
|
assertEquals(5.5, shape.getLineWidth(), 0);
|
||||||
assertEquals(Units.toEMU(5.5), shape.getSpPr().getLn().getW());
|
assertEquals(Units.toEMU(5.5), shape.getSpPr().getLn().getW());
|
||||||
shape.setLineWidth(0.0);
|
shape.setLineWidth(0.0);
|
||||||
// setting line width to zero unsets the W attribute
|
// setting line width to zero unsets the W attribute
|
||||||
@ -108,17 +112,18 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
ln2.setLineDash(LineDash.DOT);
|
ln2.setLineDash(LineDash.DOT);
|
||||||
assertEquals(LineDash.DOT, ln2.getLineDash());
|
assertEquals(LineDash.DOT, ln2.getLineDash());
|
||||||
ln2.setLineWidth(0.);
|
ln2.setLineWidth(0.);
|
||||||
assertEquals(0., ln2.getLineWidth());
|
assertEquals(0., ln2.getLineWidth(), 0);
|
||||||
|
|
||||||
XSLFSimpleShape ln3 = slide.createAutoShape();
|
XSLFSimpleShape ln3 = slide.createAutoShape();
|
||||||
ln3.setLineWidth(1.);
|
ln3.setLineWidth(1.);
|
||||||
assertEquals(1., ln3.getLineWidth());
|
assertEquals(1., ln3.getLineWidth(), 0);
|
||||||
ln3.setLineDash(null);
|
ln3.setLineDash(null);
|
||||||
assertEquals(null, ln3.getLineDash());
|
assertEquals(null, ln3.getLineDash());
|
||||||
ln3.setLineCap(null);
|
ln3.setLineCap(null);
|
||||||
assertEquals(null, ln3.getLineDash());
|
assertEquals(null, ln3.getLineDash());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFill() {
|
public void testFill() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
@ -143,29 +148,30 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
assertFalse(shape.getSpPr().isSetSolidFill());
|
assertFalse(shape.getSpPr().isSetSolidFill());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDefaultProperties() {
|
public void testDefaultProperties() {
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
|
|
||||||
XSLFSlide slide6 = ppt.getSlides()[5];
|
XSLFSlide slide6 = ppt.getSlides().get(5);
|
||||||
XSLFShape[] shapes = slide6.getShapes();
|
List<XSLFShape> shapes = slide6.getShapes();
|
||||||
for(int i = 1; i < shapes.length; i++){
|
for(XSLFShape xs : shapes){
|
||||||
XSLFSimpleShape s = (XSLFSimpleShape) shapes[i];
|
XSLFSimpleShape s = (XSLFSimpleShape)xs;
|
||||||
// all shapes have a theme color="accent1"
|
// all shapes have a theme color="accent1"
|
||||||
assertEquals("accent1", s.getSpStyle().getFillRef().getSchemeClr().getVal().toString());
|
assertEquals("accent1", s.getSpStyle().getFillRef().getSchemeClr().getVal().toString());
|
||||||
assertEquals(2.0, s.getLineWidth());
|
assertEquals(2.0, s.getLineWidth(), 0);
|
||||||
assertEquals(LineCap.FLAT, s.getLineCap());
|
assertEquals(LineCap.FLAT, s.getLineCap());
|
||||||
// YK: calculated color is slightly different from PowerPoint
|
// YK: calculated color is slightly different from PowerPoint
|
||||||
assertEquals(new Color(39, 64, 94), s.getLineColor());
|
assertEquals(new Color(39, 64, 94), s.getLineColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
XSLFSimpleShape s0 = (XSLFSimpleShape) shapes[0];
|
XSLFSimpleShape s0 = (XSLFSimpleShape) shapes.get(0);
|
||||||
// fill is not set
|
// fill is not set
|
||||||
assertNull(s0.getSpPr().getSolidFill());
|
assertNull(s0.getSpPr().getSolidFill());
|
||||||
//assertEquals(slide6.getTheme().getColor("accent1").getColor(), s0.getFillColor());
|
//assertEquals(slide6.getTheme().getColor("accent1").getColor(), s0.getFillColor());
|
||||||
assertEquals(new Color(79, 129, 189), s0.getFillColor());
|
assertEquals(new Color(79, 129, 189), s0.getFillColor());
|
||||||
|
|
||||||
// lighter 80%
|
// lighter 80%
|
||||||
XSLFSimpleShape s1 = (XSLFSimpleShape)shapes[1];
|
XSLFSimpleShape s1 = (XSLFSimpleShape)shapes.get(1);
|
||||||
CTSchemeColor ref1 = s1.getSpPr().getSolidFill().getSchemeClr();
|
CTSchemeColor ref1 = s1.getSpPr().getSolidFill().getSchemeClr();
|
||||||
assertEquals(1, ref1.sizeOfLumModArray());
|
assertEquals(1, ref1.sizeOfLumModArray());
|
||||||
assertEquals(1, ref1.sizeOfLumOffArray());
|
assertEquals(1, ref1.sizeOfLumOffArray());
|
||||||
@ -175,7 +181,7 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
assertEquals(new Color(220, 230, 242), s1.getFillColor());
|
assertEquals(new Color(220, 230, 242), s1.getFillColor());
|
||||||
|
|
||||||
// lighter 60%
|
// lighter 60%
|
||||||
XSLFSimpleShape s2 = (XSLFSimpleShape)shapes[2];
|
XSLFSimpleShape s2 = (XSLFSimpleShape)shapes.get(2);
|
||||||
CTSchemeColor ref2 = s2.getSpPr().getSolidFill().getSchemeClr();
|
CTSchemeColor ref2 = s2.getSpPr().getSolidFill().getSchemeClr();
|
||||||
assertEquals(1, ref2.sizeOfLumModArray());
|
assertEquals(1, ref2.sizeOfLumModArray());
|
||||||
assertEquals(1, ref2.sizeOfLumOffArray());
|
assertEquals(1, ref2.sizeOfLumOffArray());
|
||||||
@ -185,7 +191,7 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
assertEquals(new Color(185, 205, 229), s2.getFillColor());
|
assertEquals(new Color(185, 205, 229), s2.getFillColor());
|
||||||
|
|
||||||
// lighter 40%
|
// lighter 40%
|
||||||
XSLFSimpleShape s3 = (XSLFSimpleShape)shapes[3];
|
XSLFSimpleShape s3 = (XSLFSimpleShape)shapes.get(3);
|
||||||
CTSchemeColor ref3 = s3.getSpPr().getSolidFill().getSchemeClr();
|
CTSchemeColor ref3 = s3.getSpPr().getSolidFill().getSchemeClr();
|
||||||
assertEquals(1, ref3.sizeOfLumModArray());
|
assertEquals(1, ref3.sizeOfLumModArray());
|
||||||
assertEquals(1, ref3.sizeOfLumOffArray());
|
assertEquals(1, ref3.sizeOfLumOffArray());
|
||||||
@ -195,7 +201,7 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
assertEquals(new Color(149, 179, 215), s3.getFillColor());
|
assertEquals(new Color(149, 179, 215), s3.getFillColor());
|
||||||
|
|
||||||
// darker 25%
|
// darker 25%
|
||||||
XSLFSimpleShape s4 = (XSLFSimpleShape)shapes[4];
|
XSLFSimpleShape s4 = (XSLFSimpleShape)shapes.get(4);
|
||||||
CTSchemeColor ref4 = s4.getSpPr().getSolidFill().getSchemeClr();
|
CTSchemeColor ref4 = s4.getSpPr().getSolidFill().getSchemeClr();
|
||||||
assertEquals(1, ref4.sizeOfLumModArray());
|
assertEquals(1, ref4.sizeOfLumModArray());
|
||||||
assertEquals(0, ref4.sizeOfLumOffArray());
|
assertEquals(0, ref4.sizeOfLumOffArray());
|
||||||
@ -204,7 +210,7 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
// YK: calculated color is slightly different from PowerPoint
|
// YK: calculated color is slightly different from PowerPoint
|
||||||
assertEquals(new Color(59, 97, 142), s4.getFillColor());
|
assertEquals(new Color(59, 97, 142), s4.getFillColor());
|
||||||
|
|
||||||
XSLFSimpleShape s5 = (XSLFSimpleShape)shapes[5];
|
XSLFSimpleShape s5 = (XSLFSimpleShape)shapes.get(5);
|
||||||
CTSchemeColor ref5 = s5.getSpPr().getSolidFill().getSchemeClr();
|
CTSchemeColor ref5 = s5.getSpPr().getSolidFill().getSchemeClr();
|
||||||
assertEquals(1, ref5.sizeOfLumModArray());
|
assertEquals(1, ref5.sizeOfLumModArray());
|
||||||
assertEquals(0, ref5.sizeOfLumOffArray());
|
assertEquals(0, ref5.sizeOfLumOffArray());
|
||||||
@ -214,26 +220,27 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
assertEquals(new Color(40, 65, 95), s5.getFillColor());
|
assertEquals(new Color(40, 65, 95), s5.getFillColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAnchor(){
|
public void testAnchor(){
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
XSLFSlide[] slide = ppt.getSlides();
|
List<XSLFSlide> slide = ppt.getSlides();
|
||||||
|
|
||||||
XSLFSlide slide2 = slide[1];
|
XSLFSlide slide2 = slide.get(1);
|
||||||
XSLFSlideLayout layout2 = slide2.getSlideLayout();
|
XSLFSlideLayout layout2 = slide2.getSlideLayout();
|
||||||
XSLFShape[] shapes2 = slide2.getShapes();
|
List<XSLFShape> shapes2 = slide2.getShapes();
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)shapes2[0];
|
XSLFTextShape sh1 = (XSLFTextShape)shapes2.get(0);
|
||||||
assertEquals(Placeholder.CENTERED_TITLE, sh1.getTextType());
|
assertEquals(Placeholder.CENTERED_TITLE, sh1.getTextType());
|
||||||
assertEquals("PPTX Title", sh1.getText());
|
assertEquals("PPTX Title", sh1.getText());
|
||||||
assertNull(sh1.getSpPr().getXfrm()); // xfrm is not set, the query is delegated to the slide layout
|
assertNull(sh1.getSpPr().getXfrm()); // xfrm is not set, the query is delegated to the slide layout
|
||||||
assertEquals(sh1.getAnchor(), layout2.getTextShapeByType(Placeholder.CENTERED_TITLE).getAnchor());
|
assertEquals(sh1.getAnchor(), layout2.getTextShapeByType(Placeholder.CENTERED_TITLE).getAnchor());
|
||||||
|
|
||||||
XSLFTextShape sh2 = (XSLFTextShape)shapes2[1];
|
XSLFTextShape sh2 = (XSLFTextShape)shapes2.get(1);
|
||||||
assertEquals("Subtitle\nAnd second line", sh2.getText());
|
assertEquals("Subtitle\nAnd second line", sh2.getText());
|
||||||
assertEquals(Placeholder.SUBTITLE, sh2.getTextType());
|
assertEquals(Placeholder.SUBTITLE, sh2.getTextType());
|
||||||
assertNull(sh2.getSpPr().getXfrm()); // xfrm is not set, the query is delegated to the slide layout
|
assertNull(sh2.getSpPr().getXfrm()); // xfrm is not set, the query is delegated to the slide layout
|
||||||
assertEquals(sh2.getAnchor(), layout2.getTextShapeByType(Placeholder.SUBTITLE).getAnchor());
|
assertEquals(sh2.getAnchor(), layout2.getTextShapeByType(Placeholder.SUBTITLE).getAnchor());
|
||||||
|
|
||||||
XSLFSlide slide5 = slide[4];
|
XSLFSlide slide5 = slide.get(4);
|
||||||
XSLFSlideLayout layout5 = slide5.getSlideLayout();
|
XSLFSlideLayout layout5 = slide5.getSlideLayout();
|
||||||
XSLFTextShape shTitle = slide5.getTextShapeByType(Placeholder.TITLE);
|
XSLFTextShape shTitle = slide5.getTextShapeByType(Placeholder.TITLE);
|
||||||
assertEquals("Hyperlinks", shTitle.getText());
|
assertEquals("Hyperlinks", shTitle.getText());
|
||||||
@ -247,6 +254,7 @@ public class TestXSLFSimpleShape extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "deprecation", "unused" })
|
@SuppressWarnings({ "deprecation", "unused" })
|
||||||
|
@Test
|
||||||
public void testShadowEffects(){
|
public void testShadowEffects(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
|
@ -16,88 +16,91 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.util.List;
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFSlide extends TestCase {
|
public class TestXSLFSlide {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReadShapes(){
|
public void testReadShapes(){
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
XSLFSlide[] slides = ppt.getSlides();
|
List<XSLFSlide> slides = ppt.getSlides();
|
||||||
|
|
||||||
XSLFSlide slide1 = slides[0];
|
XSLFSlide slide1 = slides.get(0);
|
||||||
XSLFShape[] shapes1 = slide1.getShapes();
|
List<XSLFShape> shapes1 = slide1.getShapes();
|
||||||
assertEquals(7, shapes1.length);
|
assertEquals(7, shapes1.size());
|
||||||
assertEquals("TextBox 3", shapes1[0].getShapeName());
|
assertEquals("TextBox 3", shapes1.get(0).getShapeName());
|
||||||
assertTrue(shapes1[0] instanceof XSLFTextBox);
|
assertTrue(shapes1.get(0) instanceof XSLFTextBox);
|
||||||
XSLFAutoShape sh0 = (XSLFAutoShape)shapes1[0];
|
XSLFAutoShape sh0 = (XSLFAutoShape)shapes1.get(0);
|
||||||
assertEquals("Learning PPTX", sh0.getText());
|
assertEquals("Learning PPTX", sh0.getText());
|
||||||
|
|
||||||
|
|
||||||
assertEquals("Straight Connector 5", shapes1[1].getShapeName());
|
assertEquals("Straight Connector 5", shapes1.get(1).getShapeName());
|
||||||
assertTrue(shapes1[1] instanceof XSLFConnectorShape);
|
assertTrue(shapes1.get(1) instanceof XSLFConnectorShape);
|
||||||
|
|
||||||
assertEquals("Freeform 6", shapes1[2].getShapeName());
|
assertEquals("Freeform 6", shapes1.get(2).getShapeName());
|
||||||
assertTrue(shapes1[2] instanceof XSLFFreeformShape);
|
assertTrue(shapes1.get(2) instanceof XSLFFreeformShape);
|
||||||
XSLFAutoShape sh2 = (XSLFAutoShape)shapes1[2];
|
XSLFAutoShape sh2 = (XSLFAutoShape)shapes1.get(2);
|
||||||
assertEquals("Cloud", sh2.getText());
|
assertEquals("Cloud", sh2.getText());
|
||||||
|
|
||||||
assertEquals("Picture 1", shapes1[3].getShapeName());
|
assertEquals("Picture 1", shapes1.get(3).getShapeName());
|
||||||
assertTrue(shapes1[3] instanceof XSLFPictureShape);
|
assertTrue(shapes1.get(3) instanceof XSLFPictureShape);
|
||||||
|
|
||||||
assertEquals("Table 2", shapes1[4].getShapeName());
|
assertEquals("Table 2", shapes1.get(4).getShapeName());
|
||||||
assertTrue(shapes1[4] instanceof XSLFGraphicFrame);
|
assertTrue(shapes1.get(4) instanceof XSLFGraphicFrame);
|
||||||
|
|
||||||
assertEquals("Straight Arrow Connector 7", shapes1[5].getShapeName());
|
assertEquals("Straight Arrow Connector 7", shapes1.get(5).getShapeName());
|
||||||
assertTrue(shapes1[5] instanceof XSLFConnectorShape);
|
assertTrue(shapes1.get(5) instanceof XSLFConnectorShape);
|
||||||
|
|
||||||
assertEquals("Elbow Connector 9", shapes1[6].getShapeName());
|
assertEquals("Elbow Connector 9", shapes1.get(6).getShapeName());
|
||||||
assertTrue(shapes1[6] instanceof XSLFConnectorShape);
|
assertTrue(shapes1.get(6) instanceof XSLFConnectorShape);
|
||||||
|
|
||||||
// titles on slide2
|
// titles on slide2
|
||||||
XSLFSlide slide2 = slides[1];
|
XSLFSlide slide2 = slides.get(1);
|
||||||
XSLFShape[] shapes2 = slide2.getShapes();
|
List<XSLFShape> shapes2 = slide2.getShapes();
|
||||||
assertEquals(2, shapes2.length);
|
assertEquals(2, shapes2.size());
|
||||||
assertTrue(shapes2[0] instanceof XSLFAutoShape);
|
assertTrue(shapes2.get(0) instanceof XSLFAutoShape);
|
||||||
assertEquals("PPTX Title", ((XSLFAutoShape)shapes2[0]).getText());
|
assertEquals("PPTX Title", ((XSLFAutoShape)shapes2.get(0)).getText());
|
||||||
assertTrue(shapes2[1] instanceof XSLFAutoShape);
|
assertTrue(shapes2.get(1) instanceof XSLFAutoShape);
|
||||||
assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape)shapes2[1]).getText());
|
assertEquals("Subtitle\nAnd second line", ((XSLFAutoShape)shapes2.get(1)).getText());
|
||||||
|
|
||||||
// group shape on slide3
|
// group shape on slide3
|
||||||
XSLFSlide slide3 = slides[2];
|
XSLFSlide slide3 = slides.get(2);
|
||||||
XSLFShape[] shapes3 = slide3.getShapes();
|
List<XSLFShape> shapes3 = slide3.getShapes();
|
||||||
assertEquals(1, shapes3.length);
|
assertEquals(1, shapes3.size());
|
||||||
assertTrue(shapes3[0] instanceof XSLFGroupShape);
|
assertTrue(shapes3.get(0) instanceof XSLFGroupShape);
|
||||||
XSLFShape[] groupShapes = ((XSLFGroupShape)shapes3[0]).getShapes();
|
List<XSLFShape> groupShapes = ((XSLFGroupShape)shapes3.get(0)).getShapes();
|
||||||
assertEquals(3, groupShapes.length);
|
assertEquals(3, groupShapes.size());
|
||||||
assertTrue(groupShapes[0] instanceof XSLFAutoShape);
|
assertTrue(groupShapes.get(0) instanceof XSLFAutoShape);
|
||||||
assertEquals("Rectangle 1", groupShapes[0].getShapeName());
|
assertEquals("Rectangle 1", groupShapes.get(0).getShapeName());
|
||||||
|
|
||||||
assertTrue(groupShapes[1] instanceof XSLFAutoShape);
|
assertTrue(groupShapes.get(1) instanceof XSLFAutoShape);
|
||||||
assertEquals("Oval 2", groupShapes[1].getShapeName());
|
assertEquals("Oval 2", groupShapes.get(1).getShapeName());
|
||||||
|
|
||||||
assertTrue(groupShapes[2] instanceof XSLFAutoShape);
|
assertTrue(groupShapes.get(2) instanceof XSLFAutoShape);
|
||||||
assertEquals("Right Arrow 3", groupShapes[2].getShapeName());
|
assertEquals("Right Arrow 3", groupShapes.get(2).getShapeName());
|
||||||
|
|
||||||
XSLFSlide slide4 = slides[3];
|
XSLFSlide slide4 = slides.get(3);
|
||||||
XSLFShape[] shapes4 = slide4.getShapes();
|
List<XSLFShape> shapes4 = slide4.getShapes();
|
||||||
assertEquals(1, shapes4.length);
|
assertEquals(1, shapes4.size());
|
||||||
assertTrue(shapes4[0] instanceof XSLFTable);
|
assertTrue(shapes4.get(0) instanceof XSLFTable);
|
||||||
XSLFTable tbl = (XSLFTable)shapes4[0];
|
XSLFTable tbl = (XSLFTable)shapes4.get(0);
|
||||||
assertEquals(3, tbl.getNumberOfColumns());
|
assertEquals(3, tbl.getNumberOfColumns());
|
||||||
assertEquals(6, tbl.getNumberOfRows());
|
assertEquals(6, tbl.getNumberOfRows());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateSlide(){
|
public void testCreateSlide(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
assertEquals(0, ppt.getSlides().length);
|
assertEquals(0, ppt.getSlides().size());
|
||||||
|
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertTrue(slide.getFollowMasterGraphics());
|
assertTrue(slide.getFollowMasterGraphics());
|
||||||
@ -107,34 +110,35 @@ public class TestXSLFSlide extends TestCase {
|
|||||||
assertTrue(slide.getFollowMasterGraphics());
|
assertTrue(slide.getFollowMasterGraphics());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testImportContent(){
|
public void testImportContent(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
|
|
||||||
XMLSlideShow src = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
XMLSlideShow src = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
||||||
|
|
||||||
// create a blank slide and import content from the 4th slide of themes.pptx
|
// create a blank slide and import content from the 4th slide of themes.pptx
|
||||||
XSLFSlide slide1 = ppt.createSlide().importContent(src.getSlides()[3]);
|
XSLFSlide slide1 = ppt.createSlide().importContent(src.getSlides().get(3));
|
||||||
XSLFShape[] shapes1 = slide1.getShapes();
|
List<XSLFShape> shapes1 = slide1.getShapes();
|
||||||
assertEquals(2, shapes1.length);
|
assertEquals(2, shapes1.size());
|
||||||
|
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)shapes1[0];
|
XSLFTextShape sh1 = (XSLFTextShape)shapes1.get(0);
|
||||||
assertEquals("Austin Theme", sh1.getText());
|
assertEquals("Austin Theme", sh1.getText());
|
||||||
XSLFTextRun r1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals("Century Gothic", r1.getFontFamily());
|
assertEquals("Century Gothic", r1.getFontFamily());
|
||||||
assertEquals(40.0, r1.getFontSize());
|
assertEquals(40.0, r1.getFontSize(), 0);
|
||||||
assertTrue(r1.isBold());
|
assertTrue(r1.isBold());
|
||||||
assertTrue(r1.isItalic());
|
assertTrue(r1.isItalic());
|
||||||
assertEquals(new Color(148, 198, 0), r1.getFontColor());
|
assertEquals(new Color(148, 198, 0), r1.getFontColor());
|
||||||
assertNull(sh1.getFillColor());
|
assertNull(sh1.getFillColor());
|
||||||
assertNull(sh1.getLineColor());
|
assertNull(sh1.getLineColor());
|
||||||
|
|
||||||
XSLFTextShape sh2 = (XSLFTextShape)shapes1[1];
|
XSLFTextShape sh2 = (XSLFTextShape)shapes1.get(1);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Text in a autoshape is white\n" +
|
"Text in a autoshape is white\n" +
|
||||||
"Fill: RGB(148, 198,0)", sh2.getText());
|
"Fill: RGB(148, 198,0)", sh2.getText());
|
||||||
XSLFTextRun r2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals("Century Gothic", r2.getFontFamily());
|
assertEquals("Century Gothic", r2.getFontFamily());
|
||||||
assertEquals(18.0, r2.getFontSize());
|
assertEquals(18.0, r2.getFontSize(), 0);
|
||||||
assertFalse(r2.isBold());
|
assertFalse(r2.isBold());
|
||||||
assertFalse(r2.isItalic());
|
assertFalse(r2.isItalic());
|
||||||
assertEquals(Color.white, r2.getFontColor());
|
assertEquals(Color.white, r2.getFontColor());
|
||||||
@ -142,11 +146,11 @@ public class TestXSLFSlide extends TestCase {
|
|||||||
assertEquals(new Color(74, 99, 0), sh2.getLineColor()); // slightly different from PowerPoint!
|
assertEquals(new Color(74, 99, 0), sh2.getLineColor()); // slightly different from PowerPoint!
|
||||||
|
|
||||||
// the 5th slide has a picture and a texture fill
|
// the 5th slide has a picture and a texture fill
|
||||||
XSLFSlide slide2 = ppt.createSlide().importContent(src.getSlides()[4]);
|
XSLFSlide slide2 = ppt.createSlide().importContent(src.getSlides().get(4));
|
||||||
XSLFShape[] shapes2 = slide2.getShapes();
|
List<XSLFShape> shapes2 = slide2.getShapes();
|
||||||
assertEquals(2, shapes2.length);
|
assertEquals(2, shapes2.size());
|
||||||
|
|
||||||
XSLFTextShape sh3 = (XSLFTextShape)shapes2[0];
|
XSLFTextShape sh3 = (XSLFTextShape)shapes2.get(0);
|
||||||
assertEquals("This slide overrides master background with a texture fill", sh3.getText());
|
assertEquals("This slide overrides master background with a texture fill", sh3.getText());
|
||||||
XSLFTextRun r3 = sh3.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r3 = sh3.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals("Century Gothic", r3.getFontFamily());
|
assertEquals("Century Gothic", r3.getFontFamily());
|
||||||
@ -157,11 +161,12 @@ public class TestXSLFSlide extends TestCase {
|
|||||||
assertNull(sh3.getFillColor());
|
assertNull(sh3.getFillColor());
|
||||||
assertNull(sh3.getLineColor());
|
assertNull(sh3.getLineColor());
|
||||||
|
|
||||||
XSLFPictureShape sh4 = (XSLFPictureShape)shapes2[1];
|
XSLFPictureShape sh4 = (XSLFPictureShape)shapes2.get(1);
|
||||||
XSLFPictureShape srcPic = (XSLFPictureShape)src.getSlides()[4].getShapes()[1];
|
XSLFPictureShape srcPic = (XSLFPictureShape)src.getSlides().get(4).getShapes().get(1);
|
||||||
assertArrayEquals(sh4.getPictureData().getData(), srcPic.getPictureData().getData());
|
assertArrayEquals(sh4.getPictureData().getData(), srcPic.getPictureData().getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMergeSlides(){
|
public void testMergeSlides(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
String[] pptx = {"shapes.pptx", "themes.pptx", "layouts.pptx", "backgrounds.pptx"};
|
String[] pptx = {"shapes.pptx", "themes.pptx", "layouts.pptx", "backgrounds.pptx"};
|
||||||
@ -173,6 +178,6 @@ public class TestXSLFSlide extends TestCase {
|
|||||||
ppt.createSlide().importContent(srcSlide);
|
ppt.createSlide().importContent(srcSlide);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(30, ppt.getSlides().length);
|
assertEquals(30, ppt.getSlides().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,63 +16,68 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFSlideShow extends TestCase {
|
public class TestXSLFSlideShow {
|
||||||
|
@Test
|
||||||
public void testCreateSlide(){
|
public void testCreateSlide(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
assertEquals(0, ppt.getSlides().length);
|
assertEquals(0, ppt.getSlides().size());
|
||||||
|
|
||||||
XSLFSlide slide1 = ppt.createSlide();
|
XSLFSlide slide1 = ppt.createSlide();
|
||||||
assertEquals(1, ppt.getSlides().length);
|
assertEquals(1, ppt.getSlides().size());
|
||||||
assertSame(slide1, ppt.getSlides()[0]);
|
assertSame(slide1, ppt.getSlides().get(0));
|
||||||
|
|
||||||
List<POIXMLDocumentPart> rels = slide1.getRelations();
|
List<POIXMLDocumentPart> rels = slide1.getRelations();
|
||||||
assertEquals(1, rels.size());
|
assertEquals(1, rels.size());
|
||||||
assertEquals(slide1.getSlideMaster().getLayout(SlideLayout.BLANK), rels.get(0));
|
assertEquals(slide1.getSlideMaster().getLayout(SlideLayout.BLANK), rels.get(0));
|
||||||
|
|
||||||
XSLFSlide slide2 = ppt.createSlide();
|
XSLFSlide slide2 = ppt.createSlide();
|
||||||
assertEquals(2, ppt.getSlides().length);
|
assertEquals(2, ppt.getSlides().size());
|
||||||
assertSame(slide2, ppt.getSlides()[1]);
|
assertSame(slide2, ppt.getSlides().get(1));
|
||||||
|
|
||||||
ppt.setSlideOrder(slide2, 0);
|
ppt.setSlideOrder(slide2, 0);
|
||||||
assertSame(slide2, ppt.getSlides()[0]);
|
assertSame(slide2, ppt.getSlides().get(0));
|
||||||
assertSame(slide1, ppt.getSlides()[1]);
|
assertSame(slide1, ppt.getSlides().get(1));
|
||||||
|
|
||||||
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
||||||
assertEquals(2, ppt.getSlides().length);
|
assertEquals(2, ppt.getSlides().size());
|
||||||
rels = ppt.getSlides()[0].getRelations();
|
rels = ppt.getSlides().get(0).getRelations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRemoveSlide(){
|
public void testRemoveSlide(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
assertEquals(0, ppt.getSlides().length);
|
assertEquals(0, ppt.getSlides().size());
|
||||||
|
|
||||||
XSLFSlide slide1 = ppt.createSlide();
|
XSLFSlide slide1 = ppt.createSlide();
|
||||||
XSLFSlide slide2 = ppt.createSlide();
|
XSLFSlide slide2 = ppt.createSlide();
|
||||||
|
|
||||||
assertEquals(2, ppt.getSlides().length);
|
assertEquals(2, ppt.getSlides().size());
|
||||||
assertSame(slide1, ppt.getSlides()[0]);
|
assertSame(slide1, ppt.getSlides().get(0));
|
||||||
assertSame(slide2, ppt.getSlides()[1]);
|
assertSame(slide2, ppt.getSlides().get(1));
|
||||||
|
|
||||||
XSLFSlide removedSlide = ppt.removeSlide(0);
|
XSLFSlide removedSlide = ppt.removeSlide(0);
|
||||||
assertSame(slide1, removedSlide);
|
assertSame(slide1, removedSlide);
|
||||||
|
|
||||||
assertEquals(1, ppt.getSlides().length);
|
assertEquals(1, ppt.getSlides().size());
|
||||||
assertSame(slide2, ppt.getSlides()[0]);
|
assertSame(slide2, ppt.getSlides().get(0));
|
||||||
|
|
||||||
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
ppt = XSLFTestDataSamples.writeOutAndReadBack(ppt);
|
||||||
assertEquals(1, ppt.getSlides().length);
|
assertEquals(1, ppt.getSlides().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDimension(){
|
public void testDimension(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
Dimension sz = ppt.getPageSize();
|
Dimension sz = ppt.getPageSize();
|
||||||
@ -84,24 +89,26 @@ public class TestXSLFSlideShow extends TestCase {
|
|||||||
assertEquals(612, sz.height);
|
assertEquals(612, sz.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSlideMasters(){
|
public void testSlideMasters(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlideMaster[] masters = ppt.getSlideMasters();
|
List<XSLFSlideMaster> masters = ppt.getSlideMasters();
|
||||||
assertEquals(1, masters.length);
|
assertEquals(1, masters.size());
|
||||||
|
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
assertSame(masters[0], slide.getSlideMaster());
|
assertSame(masters.get(0), slide.getSlideMaster());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSlideLayout(){
|
public void testSlideLayout(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlideMaster[] masters = ppt.getSlideMasters();
|
List<XSLFSlideMaster> masters = ppt.getSlideMasters();
|
||||||
assertEquals(1, masters.length);
|
assertEquals(1, masters.size());
|
||||||
|
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
assertNotNull(layout);
|
assertNotNull(layout);
|
||||||
|
|
||||||
assertSame(masters[0], layout.getSlideMaster());
|
assertSame(masters.get(0), layout.getSlideMaster());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
|
||||||
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
|
import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
|
||||||
|
|
||||||
@ -29,16 +30,16 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFTable extends TestCase {
|
public class TestXSLFTable {
|
||||||
|
@Test
|
||||||
public void testRead(){
|
public void testRead(){
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
|
||||||
|
|
||||||
XSLFSlide slide = ppt.getSlides()[3];
|
XSLFSlide slide = ppt.getSlides().get(3);
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals(1, shapes.length);
|
assertEquals(1, shapes.size());
|
||||||
assertTrue(shapes[0] instanceof XSLFTable);
|
assertTrue(shapes.get(0) instanceof XSLFTable);
|
||||||
XSLFTable tbl = (XSLFTable)shapes[0];
|
XSLFTable tbl = (XSLFTable)shapes.get(0);
|
||||||
assertEquals(3, tbl.getNumberOfColumns());
|
assertEquals(3, tbl.getNumberOfColumns());
|
||||||
assertEquals(6, tbl.getNumberOfRows());
|
assertEquals(6, tbl.getNumberOfRows());
|
||||||
assertNotNull(tbl.getCTTable());
|
assertNotNull(tbl.getCTTable());
|
||||||
@ -46,13 +47,13 @@ public class TestXSLFTable extends TestCase {
|
|||||||
List<XSLFTableRow> rows = tbl.getRows();
|
List<XSLFTableRow> rows = tbl.getRows();
|
||||||
assertEquals(6, rows.size());
|
assertEquals(6, rows.size());
|
||||||
|
|
||||||
assertEquals(90.0, tbl.getColumnWidth(0));
|
assertEquals(90.0, tbl.getColumnWidth(0), 0);
|
||||||
assertEquals(240.0, tbl.getColumnWidth(1));
|
assertEquals(240.0, tbl.getColumnWidth(1), 0);
|
||||||
assertEquals(150.0, tbl.getColumnWidth(2));
|
assertEquals(150.0, tbl.getColumnWidth(2), 0);
|
||||||
|
|
||||||
for(XSLFTableRow row : tbl){
|
for(XSLFTableRow row : tbl){
|
||||||
// all rows have the same height
|
// all rows have the same height
|
||||||
assertEquals(29.2, row.getHeight());
|
assertEquals(29.2, row.getHeight(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
XSLFTableRow row0 = rows.get(0);
|
XSLFTableRow row0 = rows.get(0);
|
||||||
@ -70,6 +71,7 @@ public class TestXSLFTable extends TestCase {
|
|||||||
assertEquals("C1", cells1.get(2).getText());
|
assertEquals("C1", cells1.get(2).getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreate() {
|
public void testCreate() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
@ -92,9 +94,9 @@ public class TestXSLFTable extends TestCase {
|
|||||||
assertNotNull(row0.getXmlObject());
|
assertNotNull(row0.getXmlObject());
|
||||||
assertEquals(1, tbl.getNumberOfRows());
|
assertEquals(1, tbl.getNumberOfRows());
|
||||||
assertSame(row0, tbl.getRows().get(0));
|
assertSame(row0, tbl.getRows().get(0));
|
||||||
assertEquals(20.0, row0.getHeight());
|
assertEquals(20.0, row0.getHeight(), 0);
|
||||||
row0.setHeight(30.0);
|
row0.setHeight(30.0);
|
||||||
assertEquals(30.0, row0.getHeight());
|
assertEquals(30.0, row0.getHeight(), 0);
|
||||||
|
|
||||||
assertEquals(0, row0.getCells().size());
|
assertEquals(0, row0.getCells().size());
|
||||||
XSLFTableCell cell0 = row0.addCell();
|
XSLFTableCell cell0 = row0.addCell();
|
||||||
@ -108,41 +110,41 @@ public class TestXSLFTable extends TestCase {
|
|||||||
|
|
||||||
assertSame(cell0, row0.getCells().get(0));
|
assertSame(cell0, row0.getCells().get(0));
|
||||||
assertEquals(1, tbl.getNumberOfColumns());
|
assertEquals(1, tbl.getNumberOfColumns());
|
||||||
assertEquals(100.0, tbl.getColumnWidth(0));
|
assertEquals(100.0, tbl.getColumnWidth(0), 0);
|
||||||
cell0.addNewTextParagraph().addNewTextRun().setText("POI");
|
cell0.addNewTextParagraph().addNewTextRun().setText("POI");
|
||||||
assertEquals("POI", cell0.getText());
|
assertEquals("POI", cell0.getText());
|
||||||
|
|
||||||
XSLFTableCell cell1 = row0.addCell();
|
XSLFTableCell cell1 = row0.addCell();
|
||||||
assertSame(cell1, row0.getCells().get(1));
|
assertSame(cell1, row0.getCells().get(1));
|
||||||
assertEquals(2, tbl.getNumberOfColumns());
|
assertEquals(2, tbl.getNumberOfColumns());
|
||||||
assertEquals(100.0, tbl.getColumnWidth(1));
|
assertEquals(100.0, tbl.getColumnWidth(1), 0);
|
||||||
cell1.addNewTextParagraph().addNewTextRun().setText("Apache");
|
cell1.addNewTextParagraph().addNewTextRun().setText("Apache");
|
||||||
assertEquals("Apache", cell1.getText());
|
assertEquals("Apache", cell1.getText());
|
||||||
|
|
||||||
assertEquals(1.0, cell1.getBorderBottom());
|
assertEquals(1.0, cell1.getBorderBottom(), 0);
|
||||||
cell1.setBorderBottom(2.0);
|
cell1.setBorderBottom(2.0);
|
||||||
assertEquals(2.0, cell1.getBorderBottom());
|
assertEquals(2.0, cell1.getBorderBottom(), 0);
|
||||||
assertNull(cell1.getBorderBottomColor());
|
assertNull(cell1.getBorderBottomColor());
|
||||||
cell1.setBorderBottomColor(Color.yellow);
|
cell1.setBorderBottomColor(Color.yellow);
|
||||||
assertEquals(Color.yellow, cell1.getBorderBottomColor());
|
assertEquals(Color.yellow, cell1.getBorderBottomColor());
|
||||||
|
|
||||||
assertEquals(1.0, cell1.getBorderTop());
|
assertEquals(1.0, cell1.getBorderTop(), 0);
|
||||||
cell1.setBorderTop(2.0);
|
cell1.setBorderTop(2.0);
|
||||||
assertEquals(2.0, cell1.getBorderTop());
|
assertEquals(2.0, cell1.getBorderTop(), 0);
|
||||||
assertNull(cell1.getBorderTopColor());
|
assertNull(cell1.getBorderTopColor());
|
||||||
cell1.setBorderTopColor(Color.yellow);
|
cell1.setBorderTopColor(Color.yellow);
|
||||||
assertEquals(Color.yellow, cell1.getBorderTopColor());
|
assertEquals(Color.yellow, cell1.getBorderTopColor());
|
||||||
|
|
||||||
assertEquals(1.0, cell1.getBorderLeft());
|
assertEquals(1.0, cell1.getBorderLeft(), 0);
|
||||||
cell1.setBorderLeft(2.0);
|
cell1.setBorderLeft(2.0);
|
||||||
assertEquals(2.0, cell1.getBorderLeft());
|
assertEquals(2.0, cell1.getBorderLeft(), 0);
|
||||||
assertNull(cell1.getBorderLeftColor());
|
assertNull(cell1.getBorderLeftColor());
|
||||||
cell1.setBorderLeftColor(Color.yellow);
|
cell1.setBorderLeftColor(Color.yellow);
|
||||||
assertEquals(Color.yellow, cell1.getBorderLeftColor());
|
assertEquals(Color.yellow, cell1.getBorderLeftColor());
|
||||||
|
|
||||||
assertEquals(1.0, cell1.getBorderRight());
|
assertEquals(1.0, cell1.getBorderRight(), 0);
|
||||||
cell1.setBorderRight(2.0);
|
cell1.setBorderRight(2.0);
|
||||||
assertEquals(2.0, cell1.getBorderRight());
|
assertEquals(2.0, cell1.getBorderRight(), 0);
|
||||||
assertNull(cell1.getBorderRightColor());
|
assertNull(cell1.getBorderRightColor());
|
||||||
cell1.setBorderRightColor(Color.yellow);
|
cell1.setBorderRightColor(Color.yellow);
|
||||||
assertEquals(Color.yellow, cell1.getBorderRightColor());
|
assertEquals(Color.yellow, cell1.getBorderRightColor());
|
||||||
|
@ -16,14 +16,18 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFTableStyles extends TestCase {
|
public class TestXSLFTableStyles {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRead(){
|
public void testRead(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFTableStyles tblStyles = ppt.getTableStyles();
|
XSLFTableStyles tblStyles = ppt.getTableStyles();
|
||||||
@ -32,6 +36,8 @@ public class TestXSLFTableStyles extends TestCase {
|
|||||||
assertEquals(0, tblStyles.getStyles().size());
|
assertEquals(0, tblStyles.getStyles().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Test
|
||||||
public void testStyle(){
|
public void testStyle(){
|
||||||
CTTableStyle obj = CTTableStyle.Factory.newInstance();
|
CTTableStyle obj = CTTableStyle.Factory.newInstance();
|
||||||
XSLFTableStyle style = new XSLFTableStyle(obj);
|
XSLFTableStyle style = new XSLFTableStyle(obj);
|
||||||
|
@ -16,14 +16,18 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFTextBox extends TestCase {
|
public class TestXSLFTextBox {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPlaceholder() {
|
public void testPlaceholder() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
@ -40,6 +44,7 @@ public class TestXSLFTextBox extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* text box inherits default text proeprties from presentation.xml
|
* text box inherits default text proeprties from presentation.xml
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testDefaultTextStyle() {
|
public void testDefaultTextStyle() {
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
XSLFSlide slide = ppt.createSlide();
|
XSLFSlide slide = ppt.createSlide();
|
||||||
@ -55,12 +60,12 @@ public class TestXSLFTextBox extends TestCase {
|
|||||||
XSLFTextRun r = shape.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r = shape.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
|
|
||||||
assertEquals(1800, pPr.getSz());
|
assertEquals(1800, pPr.getSz());
|
||||||
assertEquals(18.0, r.getFontSize());
|
assertEquals(18.0, r.getFontSize(), 0);
|
||||||
assertEquals("Calibri", r.getFontFamily());
|
assertEquals("Calibri", r.getFontFamily());
|
||||||
|
|
||||||
pPr.setSz(900);
|
pPr.setSz(900);
|
||||||
pPr.getLatin().setTypeface("Arial");
|
pPr.getLatin().setTypeface("Arial");
|
||||||
assertEquals(9.0, r.getFontSize());
|
assertEquals(9.0, r.getFontSize(), 0);
|
||||||
assertEquals("Arial", r.getFontFamily());
|
assertEquals("Arial", r.getFontFamily());
|
||||||
|
|
||||||
// unset font size in presentation.xml. The value should be taken from master slide
|
// unset font size in presentation.xml. The value should be taken from master slide
|
||||||
@ -68,12 +73,12 @@ public class TestXSLFTextBox extends TestCase {
|
|||||||
ppt.getCTPresentation().getDefaultTextStyle().getLvl1PPr().getDefRPr().unsetSz();
|
ppt.getCTPresentation().getDefaultTextStyle().getLvl1PPr().getDefRPr().unsetSz();
|
||||||
pPr = slide.getSlideMaster().getXmlObject().getTxStyles().getOtherStyle().getLvl1PPr().getDefRPr();
|
pPr = slide.getSlideMaster().getXmlObject().getTxStyles().getOtherStyle().getLvl1PPr().getDefRPr();
|
||||||
assertEquals(1800, pPr.getSz());
|
assertEquals(1800, pPr.getSz());
|
||||||
assertEquals(18.0, r.getFontSize());
|
assertEquals(18.0, r.getFontSize(), 0);
|
||||||
pPr.setSz(2000);
|
pPr.setSz(2000);
|
||||||
assertEquals(20.0, r.getFontSize());
|
assertEquals(20.0, r.getFontSize(), 0);
|
||||||
|
|
||||||
pPr.unsetSz(); // Should never be
|
pPr.unsetSz(); // Should never be
|
||||||
assertEquals(-1.0, r.getFontSize());
|
assertEquals(-1.0, r.getFontSize(), 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -242,14 +242,14 @@ public class TestXSLFTextParagraph {
|
|||||||
@Test
|
@Test
|
||||||
public void testThemeInheritance(){
|
public void testThemeInheritance(){
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("prProps.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("prProps.pptx");
|
||||||
XSLFShape[] shapes = ppt.getSlides()[0].getShapes();
|
List<XSLFShape> shapes = ppt.getSlides().get(0).getShapes();
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)shapes[0];
|
XSLFTextShape sh1 = (XSLFTextShape)shapes.get(0);
|
||||||
assertEquals("Apache", sh1.getText());
|
assertEquals("Apache", sh1.getText());
|
||||||
assertEquals(TextAlign.CENTER, sh1.getTextParagraphs().get(0).getTextAlign());
|
assertEquals(TextAlign.CENTER, sh1.getTextParagraphs().get(0).getTextAlign());
|
||||||
XSLFTextShape sh2 = (XSLFTextShape)shapes[1];
|
XSLFTextShape sh2 = (XSLFTextShape)shapes.get(1);
|
||||||
assertEquals("Software", sh2.getText());
|
assertEquals("Software", sh2.getText());
|
||||||
assertEquals(TextAlign.CENTER, sh2.getTextParagraphs().get(0).getTextAlign());
|
assertEquals(TextAlign.CENTER, sh2.getTextParagraphs().get(0).getTextAlign());
|
||||||
XSLFTextShape sh3 = (XSLFTextShape)shapes[2];
|
XSLFTextShape sh3 = (XSLFTextShape)shapes.get(2);
|
||||||
assertEquals("Foundation", sh3.getText());
|
assertEquals("Foundation", sh3.getText());
|
||||||
assertEquals(TextAlign.CENTER, sh3.getTextParagraphs().get(0).getTextAlign());
|
assertEquals(TextAlign.CENTER, sh3.getTextParagraphs().get(0).getTextAlign());
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ public class TestXSLFTextParagraph {
|
|||||||
XSLFTextRun r1 = p.addNewTextRun();
|
XSLFTextRun r1 = p.addNewTextRun();
|
||||||
r1.setText("Hello,");
|
r1.setText("Hello,");
|
||||||
XSLFTextRun r2 = p.addLineBreak();
|
XSLFTextRun r2 = p.addLineBreak();
|
||||||
assertEquals("\n", r2.getText());
|
assertEquals("\n", r2.getRawText());
|
||||||
r2.setFontSize(10.0);
|
r2.setFontSize(10.0);
|
||||||
assertEquals(10.0, r2.getFontSize(), 0);
|
assertEquals(10.0, r2.getFontSize(), 0);
|
||||||
XSLFTextRun r3 = p.addNewTextRun();
|
XSLFTextRun r3 = p.addNewTextRun();
|
||||||
|
@ -16,9 +16,10 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import java.awt.Color;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import java.awt.Color;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
|
||||||
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
||||||
@ -30,28 +31,28 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
|
|||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFTextShape extends TestCase {
|
public class TestXSLFTextShape {
|
||||||
|
|
||||||
public void testLayouts(){
|
public void testLayouts(){
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("layouts.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("layouts.pptx");
|
||||||
|
|
||||||
XSLFSlide[] slide = ppt.getSlides();
|
List<XSLFSlide> slide = ppt.getSlides();
|
||||||
|
|
||||||
verifySlide1(slide[0]);
|
verifySlide1(slide.get(0));
|
||||||
verifySlide2(slide[1]);
|
verifySlide2(slide.get(1));
|
||||||
verifySlide3(slide[2]);
|
verifySlide3(slide.get(2));
|
||||||
verifySlide4(slide[3]);
|
verifySlide4(slide.get(3));
|
||||||
verifySlide7(slide[6]);
|
verifySlide7(slide.get(6));
|
||||||
verifySlide8(slide[7]);
|
verifySlide8(slide.get(7));
|
||||||
verifySlide10(slide[9]);
|
verifySlide10(slide.get(9));
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySlide1(XSLFSlide slide){
|
void verifySlide1(XSLFSlide slide){
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals("Title Slide",layout.getName());
|
assertEquals("Title Slide",layout.getName());
|
||||||
|
|
||||||
XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
|
XSLFTextShape shape1 = (XSLFTextShape)shapes.get(0);
|
||||||
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.CTR_TITLE, ph1.getType());
|
assertEquals(STPlaceholderType.CTR_TITLE, ph1.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -68,20 +69,20 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
||||||
!bodyPr1.isSetAnchor()
|
!bodyPr1.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape1.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape1.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape1.getRightInset()); // 0.1"
|
assertEquals(7.2, shape1.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape1.getTopInset()); // 0.05"
|
assertEquals(3.6, shape1.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape1.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape1.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
||||||
|
|
||||||
// now check text properties
|
// now check text properties
|
||||||
assertEquals("Centered Title", shape1.getText());
|
assertEquals("Centered Title", shape1.getText());
|
||||||
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());
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertEquals(Color.black, r1.getFontColor());
|
assertEquals(Color.black, r1.getFontColor());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.SUB_TITLE, ph2.getType());
|
assertEquals(STPlaceholderType.SUB_TITLE, ph2.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -98,26 +99,26 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
||||||
!bodyPr2.isSetAnchor()
|
!bodyPr2.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape2.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape2.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape2.getRightInset()); // 0.1"
|
assertEquals(7.2, shape2.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape2.getTopInset()); // 0.05"
|
assertEquals(3.6, shape2.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape2.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape2.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
||||||
|
|
||||||
assertEquals("subtitle", shape2.getText());
|
assertEquals("subtitle", shape2.getText());
|
||||||
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());
|
assertEquals(32.0, r2.getFontSize(), 0);
|
||||||
// TODO fix calculation of tint
|
// TODO fix calculation of tint
|
||||||
//assertEquals(new Color(137, 137, 137), r2.getFontColor());
|
//assertEquals(new Color(137, 137, 137), r2.getFontColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySlide2(XSLFSlide slide){
|
void verifySlide2(XSLFSlide slide){
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals("Title and Content",layout.getName());
|
assertEquals("Title and Content",layout.getName());
|
||||||
|
|
||||||
XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
|
XSLFTextShape shape1 = (XSLFTextShape)shapes.get(0);
|
||||||
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -137,20 +138,20 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
||||||
!bodyPr1.isSetAnchor()
|
!bodyPr1.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape1.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape1.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape1.getRightInset()); // 0.1"
|
assertEquals(7.2, shape1.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape1.getTopInset()); // 0.05"
|
assertEquals(3.6, shape1.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape1.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape1.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
||||||
|
|
||||||
// now check text properties
|
// now check text properties
|
||||||
assertEquals("Title", shape1.getText());
|
assertEquals("Title", shape1.getText());
|
||||||
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());
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertEquals(Color.black, r1.getFontColor());
|
assertEquals(Color.black, r1.getFontColor());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
||||||
assertFalse(ph2.isSetType()); // <p:ph idx="1"/>
|
assertFalse(ph2.isSetType()); // <p:ph idx="1"/>
|
||||||
assertTrue(ph2.isSetIdx());
|
assertTrue(ph2.isSetIdx());
|
||||||
@ -172,54 +173,54 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
||||||
!bodyPr2.isSetAnchor()
|
!bodyPr2.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape2.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape2.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape2.getRightInset()); // 0.1"
|
assertEquals(7.2, shape2.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape2.getTopInset()); // 0.05"
|
assertEquals(3.6, shape2.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape2.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape2.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
||||||
|
|
||||||
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(0, pr1.getParentParagraph().getLevel());
|
assertEquals(0, pr1.getParentParagraph().getLevel());
|
||||||
assertEquals("Content", pr1.getText());
|
assertEquals("Content", pr1.getRawText());
|
||||||
assertEquals("Calibri", pr1.getFontFamily());
|
assertEquals("Calibri", pr1.getFontFamily());
|
||||||
assertEquals(32.0, pr1.getFontSize());
|
assertEquals(32.0, pr1.getFontSize(), 0);
|
||||||
assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
|
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);
|
||||||
assertEquals(1, pr2.getParentParagraph().getLevel());
|
assertEquals(1, pr2.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 2", pr2.getText());
|
assertEquals("Level 2", pr2.getRawText());
|
||||||
assertEquals("Calibri", pr2.getFontFamily());
|
assertEquals("Calibri", pr2.getFontFamily());
|
||||||
assertEquals(28.0, pr2.getFontSize());
|
assertEquals(28.0, pr2.getFontSize(), 0);
|
||||||
assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
|
assertEquals(58.5, pr2.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
|
XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
|
||||||
assertEquals(2, pr3.getParentParagraph().getLevel());
|
assertEquals(2, pr3.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 3", pr3.getText());
|
assertEquals("Level 3", pr3.getRawText());
|
||||||
assertEquals("Calibri", pr3.getFontFamily());
|
assertEquals("Calibri", pr3.getFontFamily());
|
||||||
assertEquals(24.0, pr3.getFontSize());
|
assertEquals(24.0, pr3.getFontSize(), 0);
|
||||||
assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
|
assertEquals(90.0, pr3.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
|
XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
|
||||||
assertEquals(3, pr4.getParentParagraph().getLevel());
|
assertEquals(3, pr4.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 4", pr4.getText());
|
assertEquals("Level 4", pr4.getRawText());
|
||||||
assertEquals("Calibri", pr4.getFontFamily());
|
assertEquals("Calibri", pr4.getFontFamily());
|
||||||
assertEquals(20.0, pr4.getFontSize());
|
assertEquals(20.0, pr4.getFontSize(), 0);
|
||||||
assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
|
assertEquals(126.0, pr4.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
XSLFTextRun pr5 = shape2.getTextParagraphs().get(4).getTextRuns().get(0);
|
XSLFTextRun pr5 = shape2.getTextParagraphs().get(4).getTextRuns().get(0);
|
||||||
assertEquals(4, pr5.getParentParagraph().getLevel());
|
assertEquals(4, pr5.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 5", pr5.getText());
|
assertEquals("Level 5", pr5.getRawText());
|
||||||
assertEquals("Calibri", pr5.getFontFamily());
|
assertEquals("Calibri", pr5.getFontFamily());
|
||||||
assertEquals(20.0, pr5.getFontSize());
|
assertEquals(20.0, pr5.getFontSize(), 0);
|
||||||
assertEquals(162.0, pr5.getParentParagraph().getLeftMargin());
|
assertEquals(162.0, pr5.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u00bb", pr5.getParentParagraph().getBulletCharacter());
|
assertEquals("\u00bb", pr5.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr5.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr5.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
@ -227,10 +228,10 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
|
|
||||||
void verifySlide3(XSLFSlide slide){
|
void verifySlide3(XSLFSlide slide){
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals("Section Header",layout.getName());
|
assertEquals("Section Header",layout.getName());
|
||||||
|
|
||||||
XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
|
XSLFTextShape shape1 = (XSLFTextShape)shapes.get(0);
|
||||||
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -247,10 +248,10 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
||||||
!bodyPr1.isSetAnchor()
|
!bodyPr1.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape1.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape1.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape1.getRightInset()); // 0.1"
|
assertEquals(7.2, shape1.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape1.getTopInset()); // 0.05"
|
assertEquals(3.6, shape1.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape1.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape1.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.TOP, shape1.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, shape1.getVerticalAlignment());
|
||||||
|
|
||||||
// now check text properties
|
// now check text properties
|
||||||
@ -258,13 +259,13 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
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());
|
assertEquals(40.0, r1.getFontSize(), 0);
|
||||||
assertEquals(Color.black, r1.getFontColor());
|
assertEquals(Color.black, r1.getFontColor());
|
||||||
assertTrue(r1.isBold());
|
assertTrue(r1.isBold());
|
||||||
assertFalse(r1.isItalic());
|
assertFalse(r1.isItalic());
|
||||||
assertFalse(r1.isUnderline());
|
assertFalse(r1.isUnderlined());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.BODY, ph2.getType());
|
assertEquals(STPlaceholderType.BODY, ph2.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -281,27 +282,27 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
||||||
!bodyPr2.isSetAnchor()
|
!bodyPr2.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape2.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape2.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape2.getRightInset()); // 0.1"
|
assertEquals(7.2, shape2.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape2.getTopInset()); // 0.05"
|
assertEquals(3.6, shape2.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape2.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape2.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.BOTTOM, shape2.getVerticalAlignment());
|
assertEquals(VerticalAlignment.BOTTOM, shape2.getVerticalAlignment());
|
||||||
|
|
||||||
assertEquals("Section Header", shape2.getText());
|
assertEquals("Section Header", shape2.getText());
|
||||||
XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(TextAlign.LEFT, r2.getParentParagraph().getTextAlign());
|
assertEquals(TextAlign.LEFT, r2.getParentParagraph().getTextAlign());
|
||||||
assertEquals("Calibri", r2.getFontFamily());
|
assertEquals("Calibri", r2.getFontFamily());
|
||||||
assertEquals(20.0, r2.getFontSize());
|
assertEquals(20.0, r2.getFontSize(), 0);
|
||||||
// TODO fix calculation of tint
|
// TODO fix calculation of tint
|
||||||
//assertEquals(new Color(137, 137, 137), r2.getFontColor());
|
//assertEquals(new Color(137, 137, 137), r2.getFontColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySlide4(XSLFSlide slide){
|
void verifySlide4(XSLFSlide slide){
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals("Two Content",layout.getName());
|
assertEquals("Two Content",layout.getName());
|
||||||
|
|
||||||
XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
|
XSLFTextShape shape1 = (XSLFTextShape)shapes.get(0);
|
||||||
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -321,10 +322,10 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
||||||
!bodyPr1.isSetAnchor()
|
!bodyPr1.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape1.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape1.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape1.getRightInset()); // 0.1"
|
assertEquals(7.2, shape1.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape1.getTopInset()); // 0.05"
|
assertEquals(3.6, shape1.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape1.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape1.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
||||||
|
|
||||||
// now check text properties
|
// now check text properties
|
||||||
@ -332,10 +333,10 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
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());
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertEquals(Color.black, r1.getFontColor());
|
assertEquals(Color.black, r1.getFontColor());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
||||||
assertFalse(ph2.isSetType());
|
assertFalse(ph2.isSetType());
|
||||||
assertTrue(ph2.isSetIdx());
|
assertTrue(ph2.isSetIdx());
|
||||||
@ -354,18 +355,18 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
||||||
!bodyPr2.isSetAnchor()
|
!bodyPr2.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape2.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape2.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape2.getRightInset()); // 0.1"
|
assertEquals(7.2, shape2.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape2.getTopInset()); // 0.05"
|
assertEquals(3.6, shape2.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape2.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape2.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
||||||
|
|
||||||
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(0, pr1.getParentParagraph().getLevel());
|
assertEquals(0, pr1.getParentParagraph().getLevel());
|
||||||
assertEquals("Left", pr1.getText());
|
assertEquals("Left", pr1.getRawText());
|
||||||
assertEquals("Calibri", pr1.getFontFamily());
|
assertEquals("Calibri", pr1.getFontFamily());
|
||||||
assertEquals(28.0, pr1.getFontSize());
|
assertEquals(28.0, pr1.getFontSize(), 0);
|
||||||
assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
|
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());
|
||||||
|
|
||||||
@ -373,8 +374,8 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(1, pr2.getParentParagraph().getLevel());
|
assertEquals(1, pr2.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 2", pr2.getParentParagraph().getText());
|
assertEquals("Level 2", pr2.getParentParagraph().getText());
|
||||||
assertEquals("Calibri", pr2.getFontFamily());
|
assertEquals("Calibri", pr2.getFontFamily());
|
||||||
assertEquals(24.0, pr2.getFontSize());
|
assertEquals(24.0, pr2.getFontSize(), 0);
|
||||||
assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
|
assertEquals(58.5, pr2.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
@ -382,8 +383,8 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(2, pr3.getParentParagraph().getLevel());
|
assertEquals(2, pr3.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 3", pr3.getParentParagraph().getText());
|
assertEquals("Level 3", pr3.getParentParagraph().getText());
|
||||||
assertEquals("Calibri", pr3.getFontFamily());
|
assertEquals("Calibri", pr3.getFontFamily());
|
||||||
assertEquals(20.0, pr3.getFontSize());
|
assertEquals(20.0, pr3.getFontSize(), 0);
|
||||||
assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
|
assertEquals(90.0, pr3.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
@ -391,31 +392,32 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(3, pr4.getParentParagraph().getLevel());
|
assertEquals(3, pr4.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 4", pr4.getParentParagraph().getText());
|
assertEquals("Level 4", pr4.getParentParagraph().getText());
|
||||||
assertEquals("Calibri", pr4.getFontFamily());
|
assertEquals("Calibri", pr4.getFontFamily());
|
||||||
assertEquals(18.0, pr4.getFontSize());
|
assertEquals(18.0, pr4.getFontSize(), 0);
|
||||||
assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
|
assertEquals(126.0, pr4.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
|
XSLFTextShape shape3 = (XSLFTextShape)shapes.get(2);
|
||||||
XSLFTextRun pr5 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun pr5 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(0, pr5.getParentParagraph().getLevel());
|
assertEquals(0, pr5.getParentParagraph().getLevel());
|
||||||
assertEquals("Right", pr5.getText());
|
assertEquals("Right", pr5.getRawText());
|
||||||
assertEquals("Calibri", pr5.getFontFamily());
|
assertEquals("Calibri", pr5.getFontFamily());
|
||||||
assertEquals(Color.black, pr5.getFontColor());
|
assertEquals(Color.black, pr5.getFontColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
void verifySlide5(XSLFSlide slide){
|
void verifySlide5(XSLFSlide slide){
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
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();
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals("Blank",layout.getName());
|
assertEquals("Blank",layout.getName());
|
||||||
|
|
||||||
XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
|
XSLFTextShape shape1 = (XSLFTextShape)shapes.get(0);
|
||||||
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -428,10 +430,10 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
||||||
!bodyPr1.isSetAnchor()
|
!bodyPr1.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape1.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape1.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape1.getRightInset()); // 0.1"
|
assertEquals(7.2, shape1.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape1.getTopInset()); // 0.05"
|
assertEquals(3.6, shape1.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape1.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape1.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
|
||||||
|
|
||||||
// now check text properties
|
// now check text properties
|
||||||
@ -439,11 +441,11 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
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());
|
assertEquals(44.0, r1.getFontSize(), 0);
|
||||||
assertEquals(Color.black, r1.getFontColor());
|
assertEquals(Color.black, r1.getFontColor());
|
||||||
assertFalse(r1.isBold());
|
assertFalse(r1.isBold());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
|
|
||||||
CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
|
CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
|
||||||
// none of the following properties are set in the shapes and fetched from the master shape
|
// none of the following properties are set in the shapes and fetched from the master shape
|
||||||
@ -452,19 +454,19 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
||||||
!bodyPr2.isSetAnchor()
|
!bodyPr2.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape2.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape2.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape2.getRightInset()); // 0.1"
|
assertEquals(7.2, shape2.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape2.getTopInset()); // 0.05"
|
assertEquals(3.6, shape2.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape2.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape2.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
||||||
|
|
||||||
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(0, pr1.getParentParagraph().getLevel());
|
assertEquals(0, pr1.getParentParagraph().getLevel());
|
||||||
assertEquals("Default Text", pr1.getText());
|
assertEquals("Default Text", pr1.getRawText());
|
||||||
assertEquals("Calibri", pr1.getFontFamily());
|
assertEquals("Calibri", pr1.getFontFamily());
|
||||||
assertEquals(18.0, pr1.getFontSize());
|
assertEquals(18.0, pr1.getFontSize(), 0);
|
||||||
|
|
||||||
XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
|
XSLFTextShape shape3 = (XSLFTextShape)shapes.get(2);
|
||||||
assertEquals("Default", shape3.getTextParagraphs().get(0).getText());
|
assertEquals("Default", shape3.getTextParagraphs().get(0).getText());
|
||||||
assertEquals("Text with levels", shape3.getTextParagraphs().get(1).getText());
|
assertEquals("Text with levels", shape3.getTextParagraphs().get(1).getText());
|
||||||
assertEquals("Level 1", shape3.getTextParagraphs().get(2).getText());
|
assertEquals("Level 1", shape3.getTextParagraphs().get(2).getText());
|
||||||
@ -474,16 +476,16 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
for(int p = 0; p < 5; p++) {
|
for(int p = 0; p < 5; p++) {
|
||||||
XSLFTextParagraph pr = shape3.getTextParagraphs().get(p);
|
XSLFTextParagraph pr = shape3.getTextParagraphs().get(p);
|
||||||
assertEquals("Calibri", pr.getTextRuns().get(0).getFontFamily());
|
assertEquals("Calibri", pr.getTextRuns().get(0).getFontFamily());
|
||||||
assertEquals(18.0, pr.getTextRuns().get(0).getFontSize());
|
assertEquals(18.0, pr.getTextRuns().get(0).getFontSize(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySlide8(XSLFSlide slide){
|
void verifySlide8(XSLFSlide slide){
|
||||||
XSLFSlideLayout layout = slide.getSlideLayout();
|
XSLFSlideLayout layout = slide.getSlideLayout();
|
||||||
XSLFShape[] shapes = slide.getShapes();
|
List<XSLFShape> shapes = slide.getShapes();
|
||||||
assertEquals("Content with Caption",layout.getName());
|
assertEquals("Content with Caption",layout.getName());
|
||||||
|
|
||||||
XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
|
XSLFTextShape shape1 = (XSLFTextShape)shapes.get(0);
|
||||||
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
CTPlaceholder ph1 = shape1.getCTPlaceholder();
|
||||||
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
assertEquals(STPlaceholderType.TITLE, ph1.getType());
|
||||||
// anchor is not defined in the shape
|
// anchor is not defined in the shape
|
||||||
@ -501,10 +503,10 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
!bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
|
||||||
!bodyPr1.isSetAnchor()
|
!bodyPr1.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape1.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape1.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape1.getRightInset()); // 0.1"
|
assertEquals(7.2, shape1.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape1.getTopInset()); // 0.05"
|
assertEquals(3.6, shape1.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape1.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape1.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.BOTTOM, shape1.getVerticalAlignment());
|
assertEquals(VerticalAlignment.BOTTOM, shape1.getVerticalAlignment());
|
||||||
|
|
||||||
// now check text properties
|
// now check text properties
|
||||||
@ -512,11 +514,11 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
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());
|
assertEquals(20.0, r1.getFontSize(), 0);
|
||||||
assertEquals(Color.black, r1.getFontColor());
|
assertEquals(Color.black, r1.getFontColor());
|
||||||
assertTrue(r1.isBold());
|
assertTrue(r1.isBold());
|
||||||
|
|
||||||
XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
|
XSLFTextShape shape2 = (XSLFTextShape)shapes.get(1);
|
||||||
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
CTPlaceholder ph2 = shape2.getCTPlaceholder();
|
||||||
assertFalse(ph2.isSetType());
|
assertFalse(ph2.isSetType());
|
||||||
assertTrue(ph2.isSetIdx());
|
assertTrue(ph2.isSetIdx());
|
||||||
@ -535,18 +537,18 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
!bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
|
||||||
!bodyPr2.isSetAnchor()
|
!bodyPr2.isSetAnchor()
|
||||||
);
|
);
|
||||||
assertEquals(7.2, shape2.getLeftInset()); // 0.1"
|
assertEquals(7.2, shape2.getLeftInset(), 0); // 0.1"
|
||||||
assertEquals(7.2, shape2.getRightInset()); // 0.1"
|
assertEquals(7.2, shape2.getRightInset(), 0); // 0.1"
|
||||||
assertEquals(3.6, shape2.getTopInset()); // 0.05"
|
assertEquals(3.6, shape2.getTopInset(), 0); // 0.05"
|
||||||
assertEquals(3.6, shape2.getBottomInset()); // 0.05"
|
assertEquals(3.6, shape2.getBottomInset(), 0); // 0.05"
|
||||||
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
|
||||||
|
|
||||||
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(0, pr1.getParentParagraph().getLevel());
|
assertEquals(0, pr1.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 1", pr1.getText());
|
assertEquals("Level 1", pr1.getRawText());
|
||||||
assertEquals("Calibri", pr1.getFontFamily());
|
assertEquals("Calibri", pr1.getFontFamily());
|
||||||
assertEquals(32.0, pr1.getFontSize());
|
assertEquals(32.0, pr1.getFontSize(), 0);
|
||||||
assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
|
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());
|
||||||
|
|
||||||
@ -554,8 +556,8 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(1, pr2.getParentParagraph().getLevel());
|
assertEquals(1, pr2.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 2", pr2.getParentParagraph().getText());
|
assertEquals("Level 2", pr2.getParentParagraph().getText());
|
||||||
assertEquals("Calibri", pr2.getFontFamily());
|
assertEquals("Calibri", pr2.getFontFamily());
|
||||||
assertEquals(28.0, pr2.getFontSize());
|
assertEquals(28.0, pr2.getFontSize(), 0);
|
||||||
assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
|
assertEquals(58.5, pr2.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
@ -563,8 +565,8 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(2, pr3.getParentParagraph().getLevel());
|
assertEquals(2, pr3.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 3", pr3.getParentParagraph().getText());
|
assertEquals("Level 3", pr3.getParentParagraph().getText());
|
||||||
assertEquals("Calibri", pr3.getFontFamily());
|
assertEquals("Calibri", pr3.getFontFamily());
|
||||||
assertEquals(24.0, pr3.getFontSize());
|
assertEquals(24.0, pr3.getFontSize(), 0);
|
||||||
assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
|
assertEquals(90.0, pr3.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
@ -572,20 +574,20 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(3, pr4.getParentParagraph().getLevel());
|
assertEquals(3, pr4.getParentParagraph().getLevel());
|
||||||
assertEquals("Level 4", pr4.getParentParagraph().getText());
|
assertEquals("Level 4", pr4.getParentParagraph().getText());
|
||||||
assertEquals("Calibri", pr4.getFontFamily());
|
assertEquals("Calibri", pr4.getFontFamily());
|
||||||
assertEquals(20.0, pr4.getFontSize());
|
assertEquals(20.0, pr4.getFontSize(), 0);
|
||||||
assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
|
assertEquals(126.0, pr4.getParentParagraph().getLeftMargin(), 0);
|
||||||
assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
|
assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
|
||||||
assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
|
assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
|
||||||
|
|
||||||
XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
|
XSLFTextShape shape3 = (XSLFTextShape)shapes.get(2);
|
||||||
assertEquals(VerticalAlignment.TOP, shape3.getVerticalAlignment());
|
assertEquals(VerticalAlignment.TOP, shape3.getVerticalAlignment());
|
||||||
assertEquals("Content with caption", shape3.getText());
|
assertEquals("Content with caption", shape3.getText());
|
||||||
|
|
||||||
pr1 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
|
pr1 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(0, pr1.getParentParagraph().getLevel());
|
assertEquals(0, pr1.getParentParagraph().getLevel());
|
||||||
assertEquals("Content with caption", pr1.getText());
|
assertEquals("Content with caption", pr1.getRawText());
|
||||||
assertEquals("Calibri", pr1.getFontFamily());
|
assertEquals("Calibri", pr1.getFontFamily());
|
||||||
assertEquals(14.0, pr1.getFontSize());
|
assertEquals(14.0, pr1.getFontSize(), 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,7 +601,7 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
XSLFTextRun r1 = footer.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun r1 = footer.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
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());
|
assertEquals(12.0, r1.getFontSize(), 0);
|
||||||
// TODO calculation of tint is incorrect
|
// TODO calculation of tint is incorrect
|
||||||
assertEquals(new Color(64,64,64), r1.getFontColor());
|
assertEquals(new Color(64,64,64), r1.getFontColor());
|
||||||
|
|
||||||
@ -614,14 +616,14 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
public void testTitleStyles(){
|
public void testTitleStyles(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
|
|
||||||
XSLFSlideMaster master = ppt.getSlideMasters()[0];
|
XSLFSlideMaster master = ppt.getSlideMasters().get(0);
|
||||||
XSLFTheme theme = master.getTheme();
|
XSLFTheme theme = master.getTheme();
|
||||||
XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE);
|
XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE);
|
||||||
XSLFSlide slide = ppt.createSlide(layout) ;
|
XSLFSlide slide = ppt.createSlide(layout) ;
|
||||||
assertSame(layout, slide.getSlideLayout());
|
assertSame(layout, slide.getSlideLayout());
|
||||||
assertSame(master, slide.getSlideMaster());
|
assertSame(master, slide.getSlideMaster());
|
||||||
|
|
||||||
XSLFTextShape titleShape = (XSLFTextShape)slide.getPlaceholder(0);
|
XSLFTextShape titleShape = slide.getPlaceholder(0);
|
||||||
titleShape.setText("Apache POI");
|
titleShape.setText("Apache POI");
|
||||||
XSLFTextParagraph paragraph = titleShape.getTextParagraphs().get(0);
|
XSLFTextParagraph paragraph = titleShape.getTextParagraphs().get(0);
|
||||||
XSLFTextRun textRun = paragraph.getTextRuns().get(0);
|
XSLFTextRun textRun = paragraph.getTextRuns().get(0);
|
||||||
@ -631,12 +633,12 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
CTTextParagraphProperties lv1PPr = master.getXmlObject().getTxStyles().getTitleStyle().getLvl1PPr();
|
CTTextParagraphProperties lv1PPr = master.getXmlObject().getTxStyles().getTitleStyle().getLvl1PPr();
|
||||||
CTTextCharacterProperties lv1CPr = lv1PPr.getDefRPr();
|
CTTextCharacterProperties lv1CPr = lv1PPr.getDefRPr();
|
||||||
assertEquals(4400, lv1CPr.getSz());
|
assertEquals(4400, lv1CPr.getSz());
|
||||||
assertEquals(44.0, textRun.getFontSize());
|
assertEquals(44.0, textRun.getFontSize(), 0);
|
||||||
assertEquals("+mj-lt", lv1CPr.getLatin().getTypeface());
|
assertEquals("+mj-lt", lv1CPr.getLatin().getTypeface());
|
||||||
assertEquals("Calibri", theme.getMajorFont());
|
assertEquals("Calibri", theme.getMajorFont());
|
||||||
assertEquals("Calibri", textRun.getFontFamily());
|
assertEquals("Calibri", textRun.getFontFamily());
|
||||||
lv1CPr.setSz(3200);
|
lv1CPr.setSz(3200);
|
||||||
assertEquals(32.0, textRun.getFontSize());
|
assertEquals(32.0, textRun.getFontSize(), 0);
|
||||||
lv1CPr.getLatin().setTypeface("Arial");
|
lv1CPr.getLatin().setTypeface("Arial");
|
||||||
assertEquals("Arial", textRun.getFontFamily());
|
assertEquals("Arial", textRun.getFontFamily());
|
||||||
assertEquals(STTextAlignType.CTR, lv1PPr.getAlgn());
|
assertEquals(STTextAlignType.CTR, lv1PPr.getAlgn());
|
||||||
@ -650,7 +652,7 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
CTTextParagraphProperties lv2PPr = tx2.getTextBody(true).getLstStyle().addNewLvl1PPr();
|
CTTextParagraphProperties lv2PPr = tx2.getTextBody(true).getLstStyle().addNewLvl1PPr();
|
||||||
CTTextCharacterProperties lv2CPr = lv2PPr.addNewDefRPr();
|
CTTextCharacterProperties lv2CPr = lv2PPr.addNewDefRPr();
|
||||||
lv2CPr.setSz(3300);
|
lv2CPr.setSz(3300);
|
||||||
assertEquals(33.0, textRun.getFontSize());
|
assertEquals(33.0, textRun.getFontSize(), 0);
|
||||||
lv2CPr.addNewLatin().setTypeface("Times");
|
lv2CPr.addNewLatin().setTypeface("Times");
|
||||||
assertEquals("Times", textRun.getFontFamily());
|
assertEquals("Times", textRun.getFontFamily());
|
||||||
lv2PPr.setAlgn(STTextAlignType.R);
|
lv2PPr.setAlgn(STTextAlignType.R);
|
||||||
@ -663,7 +665,7 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
CTTextParagraphProperties lv3PPr = tx3.getTextBody(true).getLstStyle().addNewLvl1PPr();
|
CTTextParagraphProperties lv3PPr = tx3.getTextBody(true).getLstStyle().addNewLvl1PPr();
|
||||||
CTTextCharacterProperties lv3CPr = lv3PPr.addNewDefRPr();
|
CTTextCharacterProperties lv3CPr = lv3PPr.addNewDefRPr();
|
||||||
lv3CPr.setSz(3400);
|
lv3CPr.setSz(3400);
|
||||||
assertEquals(34.0, textRun.getFontSize());
|
assertEquals(34.0, textRun.getFontSize(), 0);
|
||||||
lv3CPr.addNewLatin().setTypeface("Courier New");
|
lv3CPr.addNewLatin().setTypeface("Courier New");
|
||||||
assertEquals("Courier New", textRun.getFontFamily());
|
assertEquals("Courier New", textRun.getFontFamily());
|
||||||
lv3PPr.setAlgn(STTextAlignType.CTR);
|
lv3PPr.setAlgn(STTextAlignType.CTR);
|
||||||
@ -674,7 +676,7 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
CTTextParagraphProperties lv4PPr = titleShape.getTextBody(true).getLstStyle().addNewLvl1PPr();
|
CTTextParagraphProperties lv4PPr = titleShape.getTextBody(true).getLstStyle().addNewLvl1PPr();
|
||||||
CTTextCharacterProperties lv4CPr = lv4PPr.addNewDefRPr();
|
CTTextCharacterProperties lv4CPr = lv4PPr.addNewDefRPr();
|
||||||
lv4CPr.setSz(3500);
|
lv4CPr.setSz(3500);
|
||||||
assertEquals(35.0, textRun.getFontSize());
|
assertEquals(35.0, textRun.getFontSize(), 0);
|
||||||
lv4CPr.addNewLatin().setTypeface("Arial");
|
lv4CPr.addNewLatin().setTypeface("Arial");
|
||||||
assertEquals("Arial", textRun.getFontFamily());
|
assertEquals("Arial", textRun.getFontFamily());
|
||||||
lv4PPr.setAlgn(STTextAlignType.L);
|
lv4PPr.setAlgn(STTextAlignType.L);
|
||||||
@ -684,7 +686,7 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
CTTextParagraphProperties lv5PPr = paragraph.getXmlObject().addNewPPr();
|
CTTextParagraphProperties lv5PPr = paragraph.getXmlObject().addNewPPr();
|
||||||
CTTextCharacterProperties lv5CPr = textRun.getXmlObject().getRPr();
|
CTTextCharacterProperties lv5CPr = textRun.getXmlObject().getRPr();
|
||||||
lv5CPr.setSz(3600);
|
lv5CPr.setSz(3600);
|
||||||
assertEquals(36.0, textRun.getFontSize());
|
assertEquals(36.0, textRun.getFontSize(), 0);
|
||||||
lv5CPr.addNewLatin().setTypeface("Calibri");
|
lv5CPr.addNewLatin().setTypeface("Calibri");
|
||||||
assertEquals("Calibri", textRun.getFontFamily());
|
assertEquals("Calibri", textRun.getFontFamily());
|
||||||
lv5PPr.setAlgn(STTextAlignType.CTR);
|
lv5PPr.setAlgn(STTextAlignType.CTR);
|
||||||
@ -694,14 +696,14 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
public void testBodyStyles(){
|
public void testBodyStyles(){
|
||||||
XMLSlideShow ppt = new XMLSlideShow();
|
XMLSlideShow ppt = new XMLSlideShow();
|
||||||
|
|
||||||
XSLFSlideMaster master = ppt.getSlideMasters()[0];
|
XSLFSlideMaster master = ppt.getSlideMasters().get(0);
|
||||||
XSLFTheme theme = master.getTheme();
|
XSLFTheme theme = master.getTheme();
|
||||||
XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE_AND_CONTENT);
|
XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE_AND_CONTENT);
|
||||||
XSLFSlide slide = ppt.createSlide(layout) ;
|
XSLFSlide slide = ppt.createSlide(layout) ;
|
||||||
assertSame(layout, slide.getSlideLayout());
|
assertSame(layout, slide.getSlideLayout());
|
||||||
assertSame(master, slide.getSlideMaster());
|
assertSame(master, slide.getSlideMaster());
|
||||||
|
|
||||||
XSLFTextShape tx1 = (XSLFTextShape)slide.getPlaceholder(1);
|
XSLFTextShape tx1 = slide.getPlaceholder(1);
|
||||||
tx1.clearText();
|
tx1.clearText();
|
||||||
|
|
||||||
XSLFTextParagraph p1 = tx1.addNewTextParagraph();
|
XSLFTextParagraph p1 = tx1.addNewTextParagraph();
|
||||||
@ -731,12 +733,12 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
CTTextCharacterProperties lv3CPr = lv3PPr.getDefRPr();
|
CTTextCharacterProperties lv3CPr = lv3PPr.getDefRPr();
|
||||||
// lv1
|
// lv1
|
||||||
assertEquals(3200, lv1CPr.getSz());
|
assertEquals(3200, lv1CPr.getSz());
|
||||||
assertEquals(32.0, r1.getFontSize());
|
assertEquals(32.0, r1.getFontSize(), 0);
|
||||||
assertEquals("+mn-lt", lv1CPr.getLatin().getTypeface());
|
assertEquals("+mn-lt", lv1CPr.getLatin().getTypeface());
|
||||||
assertEquals("Calibri", theme.getMinorFont());
|
assertEquals("Calibri", theme.getMinorFont());
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
lv1CPr.setSz(3300);
|
lv1CPr.setSz(3300);
|
||||||
assertEquals(33.0, r1.getFontSize());
|
assertEquals(33.0, r1.getFontSize(), 0);
|
||||||
lv1CPr.getLatin().setTypeface("Arial");
|
lv1CPr.getLatin().setTypeface("Arial");
|
||||||
assertEquals("Arial", r1.getFontFamily());
|
assertEquals("Arial", r1.getFontFamily());
|
||||||
assertEquals(STTextAlignType.L, lv1PPr.getAlgn());
|
assertEquals(STTextAlignType.L, lv1PPr.getAlgn());
|
||||||
@ -745,9 +747,9 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(TextAlign.RIGHT, p1.getTextAlign());
|
assertEquals(TextAlign.RIGHT, p1.getTextAlign());
|
||||||
//lv2
|
//lv2
|
||||||
assertEquals(2800, lv2CPr.getSz());
|
assertEquals(2800, lv2CPr.getSz());
|
||||||
assertEquals(28.0, r2.getFontSize());
|
assertEquals(28.0, r2.getFontSize(), 0);
|
||||||
lv2CPr.setSz(3300);
|
lv2CPr.setSz(3300);
|
||||||
assertEquals(33.0, r2.getFontSize());
|
assertEquals(33.0, r2.getFontSize(), 0);
|
||||||
lv2CPr.getLatin().setTypeface("Times");
|
lv2CPr.getLatin().setTypeface("Times");
|
||||||
assertEquals("Times", r2.getFontFamily());
|
assertEquals("Times", r2.getFontFamily());
|
||||||
assertEquals(STTextAlignType.L, lv2PPr.getAlgn());
|
assertEquals(STTextAlignType.L, lv2PPr.getAlgn());
|
||||||
@ -756,9 +758,9 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
assertEquals(TextAlign.RIGHT, p2.getTextAlign());
|
assertEquals(TextAlign.RIGHT, p2.getTextAlign());
|
||||||
//lv3
|
//lv3
|
||||||
assertEquals(2400, lv3CPr.getSz());
|
assertEquals(2400, lv3CPr.getSz());
|
||||||
assertEquals(24.0, r3.getFontSize());
|
assertEquals(24.0, r3.getFontSize(), 0);
|
||||||
lv3CPr.setSz(2500);
|
lv3CPr.setSz(2500);
|
||||||
assertEquals(25.0, r3.getFontSize());
|
assertEquals(25.0, r3.getFontSize(), 0);
|
||||||
lv3CPr.getLatin().setTypeface("Courier New");
|
lv3CPr.getLatin().setTypeface("Courier New");
|
||||||
assertEquals("Courier New", r3.getFontFamily());
|
assertEquals("Courier New", r3.getFontFamily());
|
||||||
assertEquals(STTextAlignType.L, lv3PPr.getAlgn());
|
assertEquals(STTextAlignType.L, lv3PPr.getAlgn());
|
||||||
@ -780,21 +782,21 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
lv3CPr = lv3PPr.addNewDefRPr();
|
lv3CPr = lv3PPr.addNewDefRPr();
|
||||||
|
|
||||||
lv1CPr.setSz(3300);
|
lv1CPr.setSz(3300);
|
||||||
assertEquals(33.0, r1.getFontSize());
|
assertEquals(33.0, r1.getFontSize(), 0);
|
||||||
lv1CPr.addNewLatin().setTypeface("Times");
|
lv1CPr.addNewLatin().setTypeface("Times");
|
||||||
assertEquals("Times", r1.getFontFamily());
|
assertEquals("Times", r1.getFontFamily());
|
||||||
lv1PPr.setAlgn(STTextAlignType.L);
|
lv1PPr.setAlgn(STTextAlignType.L);
|
||||||
assertEquals(TextAlign.LEFT, p1.getTextAlign());
|
assertEquals(TextAlign.LEFT, p1.getTextAlign());
|
||||||
|
|
||||||
lv2CPr.setSz(3300);
|
lv2CPr.setSz(3300);
|
||||||
assertEquals(33.0, r2.getFontSize());
|
assertEquals(33.0, r2.getFontSize(), 0);
|
||||||
lv2CPr.addNewLatin().setTypeface("Times");
|
lv2CPr.addNewLatin().setTypeface("Times");
|
||||||
assertEquals("Times", r2.getFontFamily());
|
assertEquals("Times", r2.getFontFamily());
|
||||||
lv2PPr.setAlgn(STTextAlignType.L);
|
lv2PPr.setAlgn(STTextAlignType.L);
|
||||||
assertEquals(TextAlign.LEFT, p2.getTextAlign());
|
assertEquals(TextAlign.LEFT, p2.getTextAlign());
|
||||||
|
|
||||||
lv3CPr.setSz(3300);
|
lv3CPr.setSz(3300);
|
||||||
assertEquals(33.0, r3.getFontSize());
|
assertEquals(33.0, r3.getFontSize(), 0);
|
||||||
lv3CPr.addNewLatin().setTypeface("Times");
|
lv3CPr.addNewLatin().setTypeface("Times");
|
||||||
assertEquals("Times", r3.getFontFamily());
|
assertEquals("Times", r3.getFontFamily());
|
||||||
lv3PPr.setAlgn(STTextAlignType.L);
|
lv3PPr.setAlgn(STTextAlignType.L);
|
||||||
@ -812,21 +814,21 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
lv3CPr = lv3PPr.addNewDefRPr();
|
lv3CPr = lv3PPr.addNewDefRPr();
|
||||||
|
|
||||||
lv1CPr.setSz(3400);
|
lv1CPr.setSz(3400);
|
||||||
assertEquals(34.0, r1.getFontSize());
|
assertEquals(34.0, r1.getFontSize(), 0);
|
||||||
lv1CPr.addNewLatin().setTypeface("Courier New");
|
lv1CPr.addNewLatin().setTypeface("Courier New");
|
||||||
assertEquals("Courier New", r1.getFontFamily());
|
assertEquals("Courier New", r1.getFontFamily());
|
||||||
lv1PPr.setAlgn(STTextAlignType.CTR);
|
lv1PPr.setAlgn(STTextAlignType.CTR);
|
||||||
assertEquals(TextAlign.CENTER, p1.getTextAlign());
|
assertEquals(TextAlign.CENTER, p1.getTextAlign());
|
||||||
|
|
||||||
lv2CPr.setSz(3400);
|
lv2CPr.setSz(3400);
|
||||||
assertEquals(34.0, r2.getFontSize());
|
assertEquals(34.0, r2.getFontSize(), 0);
|
||||||
lv2CPr.addNewLatin().setTypeface("Courier New");
|
lv2CPr.addNewLatin().setTypeface("Courier New");
|
||||||
assertEquals("Courier New", r2.getFontFamily());
|
assertEquals("Courier New", r2.getFontFamily());
|
||||||
lv2PPr.setAlgn(STTextAlignType.CTR);
|
lv2PPr.setAlgn(STTextAlignType.CTR);
|
||||||
assertEquals(TextAlign.CENTER, p2.getTextAlign());
|
assertEquals(TextAlign.CENTER, p2.getTextAlign());
|
||||||
|
|
||||||
lv3CPr.setSz(3400);
|
lv3CPr.setSz(3400);
|
||||||
assertEquals(34.0, r3.getFontSize());
|
assertEquals(34.0, r3.getFontSize(), 0);
|
||||||
lv3CPr.addNewLatin().setTypeface("Courier New");
|
lv3CPr.addNewLatin().setTypeface("Courier New");
|
||||||
assertEquals("Courier New", r3.getFontFamily());
|
assertEquals("Courier New", r3.getFontFamily());
|
||||||
lv3PPr.setAlgn(STTextAlignType.CTR);
|
lv3PPr.setAlgn(STTextAlignType.CTR);
|
||||||
@ -842,21 +844,21 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
lv3CPr = lv3PPr.addNewDefRPr();
|
lv3CPr = lv3PPr.addNewDefRPr();
|
||||||
|
|
||||||
lv1CPr.setSz(3500);
|
lv1CPr.setSz(3500);
|
||||||
assertEquals(35.0, r1.getFontSize());
|
assertEquals(35.0, r1.getFontSize(), 0);
|
||||||
lv1CPr.addNewLatin().setTypeface("Arial");
|
lv1CPr.addNewLatin().setTypeface("Arial");
|
||||||
assertEquals("Arial", r1.getFontFamily());
|
assertEquals("Arial", r1.getFontFamily());
|
||||||
lv1PPr.setAlgn(STTextAlignType.L);
|
lv1PPr.setAlgn(STTextAlignType.L);
|
||||||
assertEquals(TextAlign.LEFT, p1.getTextAlign());
|
assertEquals(TextAlign.LEFT, p1.getTextAlign());
|
||||||
|
|
||||||
lv2CPr.setSz(3500);
|
lv2CPr.setSz(3500);
|
||||||
assertEquals(35.0, r2.getFontSize());
|
assertEquals(35.0, r2.getFontSize(), 0);
|
||||||
lv2CPr.addNewLatin().setTypeface("Arial");
|
lv2CPr.addNewLatin().setTypeface("Arial");
|
||||||
assertEquals("Arial", r2.getFontFamily());
|
assertEquals("Arial", r2.getFontFamily());
|
||||||
lv2PPr.setAlgn(STTextAlignType.L);
|
lv2PPr.setAlgn(STTextAlignType.L);
|
||||||
assertEquals(TextAlign.LEFT, p2.getTextAlign());
|
assertEquals(TextAlign.LEFT, p2.getTextAlign());
|
||||||
|
|
||||||
lv3CPr.setSz(3500);
|
lv3CPr.setSz(3500);
|
||||||
assertEquals(35.0, r3.getFontSize());
|
assertEquals(35.0, r3.getFontSize(), 0);
|
||||||
lv3CPr.addNewLatin().setTypeface("Arial");
|
lv3CPr.addNewLatin().setTypeface("Arial");
|
||||||
assertEquals("Arial", r3.getFontFamily());
|
assertEquals("Arial", r3.getFontFamily());
|
||||||
lv3PPr.setAlgn(STTextAlignType.L);
|
lv3PPr.setAlgn(STTextAlignType.L);
|
||||||
@ -871,21 +873,21 @@ public class TestXSLFTextShape extends TestCase {
|
|||||||
lv3CPr = r3.getXmlObject().getRPr();
|
lv3CPr = r3.getXmlObject().getRPr();
|
||||||
|
|
||||||
lv1CPr.setSz(3600);
|
lv1CPr.setSz(3600);
|
||||||
assertEquals(36.0, r1.getFontSize());
|
assertEquals(36.0, r1.getFontSize(), 0);
|
||||||
lv1CPr.addNewLatin().setTypeface("Calibri");
|
lv1CPr.addNewLatin().setTypeface("Calibri");
|
||||||
assertEquals("Calibri", r1.getFontFamily());
|
assertEquals("Calibri", r1.getFontFamily());
|
||||||
lv1PPr.setAlgn(STTextAlignType.CTR);
|
lv1PPr.setAlgn(STTextAlignType.CTR);
|
||||||
assertEquals(TextAlign.CENTER, p1.getTextAlign());
|
assertEquals(TextAlign.CENTER, p1.getTextAlign());
|
||||||
|
|
||||||
lv2CPr.setSz(3600);
|
lv2CPr.setSz(3600);
|
||||||
assertEquals(36.0, r2.getFontSize());
|
assertEquals(36.0, r2.getFontSize(), 0);
|
||||||
lv2CPr.addNewLatin().setTypeface("Calibri");
|
lv2CPr.addNewLatin().setTypeface("Calibri");
|
||||||
assertEquals("Calibri", r2.getFontFamily());
|
assertEquals("Calibri", r2.getFontFamily());
|
||||||
lv2PPr.setAlgn(STTextAlignType.CTR);
|
lv2PPr.setAlgn(STTextAlignType.CTR);
|
||||||
assertEquals(TextAlign.CENTER, p2.getTextAlign());
|
assertEquals(TextAlign.CENTER, p2.getTextAlign());
|
||||||
|
|
||||||
lv3CPr.setSz(3600);
|
lv3CPr.setSz(3600);
|
||||||
assertEquals(36.0, r3.getFontSize());
|
assertEquals(36.0, r3.getFontSize(), 0);
|
||||||
lv3CPr.addNewLatin().setTypeface("Calibri");
|
lv3CPr.addNewLatin().setTypeface("Calibri");
|
||||||
assertEquals("Calibri", r3.getFontFamily());
|
assertEquals("Calibri", r3.getFontFamily());
|
||||||
lv3PPr.setAlgn(STTextAlignType.CTR);
|
lv3PPr.setAlgn(STTextAlignType.CTR);
|
||||||
|
@ -16,32 +16,39 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
import org.apache.poi.xslf.XSLFTestDataSamples;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.TexturePaint;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.sl.usermodel.*;
|
||||||
|
import org.apache.poi.sl.usermodel.PaintStyle.GradientPaint;
|
||||||
|
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
|
||||||
|
import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
|
||||||
|
import org.apache.poi.xslf.XSLFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test reading properties from a multi-theme and multi-master document
|
* test reading properties from a multi-theme and multi-master document
|
||||||
*
|
*
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public class TestXSLFTheme extends TestCase {
|
public class TestXSLFTheme {
|
||||||
|
@Test
|
||||||
public void testRead(){
|
public void testRead(){
|
||||||
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("themes.pptx");
|
||||||
XSLFSlide[] slides = ppt.getSlides();
|
List<XSLFSlide> slides = ppt.getSlides();
|
||||||
|
|
||||||
slide1(slides[0]);
|
slide1(slides.get(0));
|
||||||
slide2(slides[1]);
|
slide2(slides.get(1));
|
||||||
slide3(slides[2]);
|
slide3(slides.get(2));
|
||||||
slide4(slides[3]);
|
slide4(slides.get(3));
|
||||||
slide5(slides[4]);
|
slide5(slides.get(4));
|
||||||
slide6(slides[5]);
|
slide6(slides.get(5));
|
||||||
slide7(slides[6]);
|
slide7(slides.get(6));
|
||||||
slide8(slides[7]);
|
slide8(slides.get(7));
|
||||||
slide9(slides[8]);
|
slide9(slides.get(8));
|
||||||
slide10(slides[9]);
|
slide10(slides.get(9));
|
||||||
}
|
}
|
||||||
|
|
||||||
private XSLFShape getShape(XSLFSheet sheet, String name){
|
private XSLFShape getShape(XSLFSheet sheet, String name){
|
||||||
@ -58,11 +65,10 @@ public class TestXSLFTheme extends TestCase {
|
|||||||
assertEquals("Office Theme", theme.getName());
|
assertEquals("Office Theme", theme.getName());
|
||||||
|
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 3");
|
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 3");
|
||||||
RenderableShape rsh1 = new RenderableShape(sh1);
|
|
||||||
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(Color.white, run1.getFontColor());
|
assertEquals(Color.white, run1.getFontColor());
|
||||||
assertEquals(new Color(79, 129, 189), sh1.getFillColor());
|
assertEquals(new Color(79, 129, 189), sh1.getFillColor());
|
||||||
assertTrue(rsh1.getFillPaint(null) instanceof Color) ; // solid fill
|
assertTrue(sh1.getFillStyle().getPaint() instanceof SolidPaint) ; // solid fill
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,20 +79,19 @@ public class TestXSLFTheme extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void slide3(XSLFSlide slide){
|
void slide3(XSLFSlide slide){
|
||||||
assertNull(slide.getBackground().getFillColor());
|
PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
|
||||||
assertTrue(slide.getBackground().getPaint(null).getClass().getName().indexOf("Gradient") > 0);
|
assertTrue(fs instanceof GradientPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void slide4(XSLFSlide slide){
|
void slide4(XSLFSlide slide){
|
||||||
assertNull(slide.getBackground().getFillColor());
|
PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
|
||||||
assertTrue(slide.getBackground().getPaint(null).getClass().getName().indexOf("Gradient") > 0);
|
assertTrue(fs instanceof GradientPaint);
|
||||||
|
|
||||||
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 4");
|
XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 4");
|
||||||
RenderableShape rsh1 = new RenderableShape(sh1);
|
|
||||||
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
assertEquals(Color.white, run1.getFontColor());
|
assertEquals(Color.white, run1.getFontColor());
|
||||||
assertEquals(new Color(148, 198, 0), sh1.getFillColor());
|
assertEquals(new Color(148, 198, 0), sh1.getFillColor());
|
||||||
assertTrue(rsh1.getFillPaint(null) instanceof Color) ; // 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);
|
||||||
@ -97,14 +102,15 @@ public class TestXSLFTheme extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void slide5(XSLFSlide slide){
|
void slide5(XSLFSlide slide){
|
||||||
assertTrue(slide.getBackground().getPaint(null) instanceof TexturePaint);
|
PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
|
||||||
|
assertTrue(fs instanceof TexturePaint);
|
||||||
|
|
||||||
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);
|
||||||
assertEquals(new Color(148, 198, 0), run2.getFontColor());
|
assertEquals(new Color(148, 198, 0), 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());
|
assertEquals(36.0, run2.getFontSize(), 0);
|
||||||
|
|
||||||
assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
|
assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
|
||||||
}
|
}
|
||||||
@ -133,15 +139,18 @@ public class TestXSLFTheme extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void slide8(XSLFSlide slide){
|
void slide8(XSLFSlide slide){
|
||||||
assertTrue(slide.getBackground().getPaint(null) instanceof TexturePaint);
|
PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
|
||||||
|
assertTrue(fs instanceof TexturePaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void slide9(XSLFSlide slide){
|
void slide9(XSLFSlide slide){
|
||||||
assertTrue(slide.getBackground().getPaint(null) instanceof TexturePaint);
|
PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
|
||||||
|
assertTrue(fs instanceof TexturePaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void slide10(XSLFSlide slide){
|
void slide10(XSLFSlide slide){
|
||||||
assertTrue(slide.getBackground().getPaint(null).getClass().getName().indexOf("Gradient") > 0);
|
PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
|
||||||
|
assertTrue(fs instanceof GradientPaint);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -18,13 +18,14 @@
|
|||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -35,7 +35,7 @@ public final class DIB extends Bitmap {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return type of this picture
|
* @return type of this picture
|
||||||
* @see org.apache.poi.hslf.model.HSLFPictureShape#DIB
|
* @see org.apache.poi.hslf.usermodel.HSLFPictureShape#DIB
|
||||||
*/
|
*/
|
||||||
public int getType(){
|
public int getType(){
|
||||||
return HSLFPictureShape.DIB;
|
return HSLFPictureShape.DIB;
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
import org.apache.poi.hslf.model.HSLFShape;
|
import org.apache.poi.hslf.usermodel.HSLFShape;
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a JPEG picture data in a PPT file
|
* Represents a JPEG picture data in a PPT file
|
||||||
@ -28,7 +28,7 @@ public final class JPEG extends Bitmap {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return type of this picture
|
* @return type of this picture
|
||||||
* @see org.apache.poi.hslf.model.HSLFPictureShape#JPEG
|
* @see org.apache.poi.hslf.usermodel.HSLFPictureShape#JPEG
|
||||||
*/
|
*/
|
||||||
public int getType(){
|
public int getType(){
|
||||||
return HSLFPictureShape.JPEG;
|
return HSLFPictureShape.JPEG;
|
||||||
|
@ -23,8 +23,8 @@ import java.io.IOException;
|
|||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
import org.apache.poi.hslf.model.HSLFShape;
|
import org.apache.poi.hslf.usermodel.HSLFShape;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Macintosh PICT picture data.
|
* Represents Macintosh PICT picture data.
|
||||||
@ -102,7 +102,7 @@ public final class PICT extends Metafile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.poi.hslf.model.HSLFPictureShape#PICT
|
* @see org.apache.poi.hslf.usermodel.HSLFPictureShape#PICT
|
||||||
*/
|
*/
|
||||||
public int getType(){
|
public int getType(){
|
||||||
return HSLFPictureShape.PICT;
|
return HSLFPictureShape.PICT;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.blip;
|
package org.apache.poi.hslf.blip;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
import org.apache.poi.util.PngUtils;
|
import org.apache.poi.util.PngUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +46,7 @@ public final class PNG extends Bitmap {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return type of this picture
|
* @return type of this picture
|
||||||
* @see org.apache.poi.hslf.model.HSLFPictureShape#PNG
|
* @see org.apache.poi.hslf.usermodel.HSLFPictureShape#PNG
|
||||||
*/
|
*/
|
||||||
public int getType(){
|
public int getType(){
|
||||||
return HSLFPictureShape.PNG;
|
return HSLFPictureShape.PNG;
|
||||||
|
@ -19,8 +19,8 @@ package org.apache.poi.hslf.blip;
|
|||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
|
||||||
import org.apache.poi.hslf.model.HSLFShape;
|
import org.apache.poi.hslf.usermodel.HSLFShape;
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
package org.apache.poi.hslf.dev;
|
package org.apache.poi.hslf.dev;
|
||||||
|
|
||||||
import org.apache.poi.hslf.*;
|
import org.apache.poi.hslf.*;
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.*;
|
import org.apache.poi.hslf.record.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.dev;
|
package org.apache.poi.hslf.dev;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.Document;
|
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.RecordTypes;
|
import org.apache.poi.hslf.record.RecordTypes;
|
||||||
import org.apache.poi.hslf.record.SlideListWithText;
|
import org.apache.poi.hslf.record.SlideListWithText;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses record level code to Documents.
|
* Uses record level code to Documents.
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
package org.apache.poi.hslf.dev;
|
package org.apache.poi.hslf.dev;
|
||||||
|
|
||||||
import org.apache.poi.hslf.*;
|
import org.apache.poi.hslf.*;
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.*;
|
import org.apache.poi.hslf.record.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses record level code to locate SlideListWithText entries.
|
* Uses record level code to locate SlideListWithText entries.
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
package org.apache.poi.hslf.dev;
|
package org.apache.poi.hslf.dev;
|
||||||
|
|
||||||
import org.apache.poi.hslf.*;
|
import org.apache.poi.hslf.*;
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.*;
|
import org.apache.poi.hslf.record.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,6 @@ package org.apache.poi.hslf.dev;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.Document;
|
import org.apache.poi.hslf.record.Document;
|
||||||
import org.apache.poi.hslf.record.Notes;
|
import org.apache.poi.hslf.record.Notes;
|
||||||
import org.apache.poi.hslf.record.NotesAtom;
|
import org.apache.poi.hslf.record.NotesAtom;
|
||||||
@ -32,6 +31,7 @@ import org.apache.poi.hslf.record.SlideAtom;
|
|||||||
import org.apache.poi.hslf.record.SlideListWithText;
|
import org.apache.poi.hslf.record.SlideListWithText;
|
||||||
import org.apache.poi.hslf.record.SlidePersistAtom;
|
import org.apache.poi.hslf.record.SlidePersistAtom;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +21,6 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.Record;
|
import org.apache.poi.hslf.record.Record;
|
||||||
import org.apache.poi.util.HexDump;
|
import org.apache.poi.util.HexDump;
|
||||||
import org.apache.poi.ddf.DefaultEscherRecordFactory;
|
import org.apache.poi.ddf.DefaultEscherRecordFactory;
|
||||||
@ -32,6 +31,7 @@ import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
|||||||
import org.apache.poi.hslf.record.TextCharsAtom;
|
import org.apache.poi.hslf.record.TextCharsAtom;
|
||||||
import org.apache.poi.hslf.record.TextBytesAtom;
|
import org.apache.poi.hslf.record.TextBytesAtom;
|
||||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a way to view the contents of a powerpoint file.
|
* This class provides a way to view the contents of a powerpoint file.
|
||||||
|
@ -17,14 +17,11 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.dev;
|
package org.apache.poi.hslf.dev;
|
||||||
|
|
||||||
import org.apache.poi.hslf.*;
|
import java.util.List;
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.model.textproperties.BitMaskTextProp;
|
|
||||||
import org.apache.poi.hslf.model.textproperties.TextProp;
|
|
||||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
|
||||||
import org.apache.poi.hslf.record.*;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import org.apache.poi.hslf.model.textproperties.*;
|
||||||
|
import org.apache.poi.hslf.record.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses record level code to locate StyleTextPropAtom entries.
|
* Uses record level code to locate StyleTextPropAtom entries.
|
||||||
@ -73,19 +70,19 @@ public final class TextStyleListing {
|
|||||||
public static void showStyleTextPropAtom(StyleTextPropAtom stpa) {
|
public static void showStyleTextPropAtom(StyleTextPropAtom stpa) {
|
||||||
System.out.println("\nFound a StyleTextPropAtom");
|
System.out.println("\nFound a StyleTextPropAtom");
|
||||||
|
|
||||||
LinkedList paragraphStyles = stpa.getParagraphStyles();
|
List<TextPropCollection> paragraphStyles = stpa.getParagraphStyles();
|
||||||
System.out.println("Contains " + paragraphStyles.size() + " paragraph styles:");
|
System.out.println("Contains " + paragraphStyles.size() + " paragraph styles:");
|
||||||
for(int i=0; i<paragraphStyles.size(); i++) {
|
for(int i=0; i<paragraphStyles.size(); i++) {
|
||||||
TextPropCollection tpc = (TextPropCollection)paragraphStyles.get(i);
|
TextPropCollection tpc = paragraphStyles.get(i);
|
||||||
System.out.println(" In paragraph styling " + i + ":");
|
System.out.println(" In paragraph styling " + i + ":");
|
||||||
System.out.println(" Characters covered is " + tpc.getCharactersCovered());
|
System.out.println(" Characters covered is " + tpc.getCharactersCovered());
|
||||||
showTextProps(tpc);
|
showTextProps(tpc);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkedList charStyles = stpa.getCharacterStyles();
|
List<TextPropCollection> charStyles = stpa.getCharacterStyles();
|
||||||
System.out.println("Contains " + charStyles.size() + " character styles:");
|
System.out.println("Contains " + charStyles.size() + " character styles:");
|
||||||
for(int i=0; i<charStyles.size(); i++) {
|
for(int i=0; i<charStyles.size(); i++) {
|
||||||
TextPropCollection tpc = (TextPropCollection)charStyles.get(i);
|
TextPropCollection tpc = charStyles.get(i);
|
||||||
System.out.println(" In character styling " + i + ":");
|
System.out.println(" In character styling " + i + ":");
|
||||||
System.out.println(" Characters covered is " + tpc.getCharactersCovered());
|
System.out.println(" Characters covered is " + tpc.getCharactersCovered());
|
||||||
showTextProps(tpc);
|
showTextProps(tpc);
|
||||||
@ -93,10 +90,10 @@ public final class TextStyleListing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void showTextProps(TextPropCollection tpc) {
|
public static void showTextProps(TextPropCollection tpc) {
|
||||||
LinkedList textProps = tpc.getTextPropList();
|
List<TextProp> textProps = tpc.getTextPropList();
|
||||||
System.out.println(" Contains " + textProps.size() + " TextProps");
|
System.out.println(" Contains " + textProps.size() + " TextProps");
|
||||||
for(int i=0; i<textProps.size(); i++) {
|
for(int i=0; i<textProps.size(); i++) {
|
||||||
TextProp tp = (TextProp)textProps.get(i);
|
TextProp tp = textProps.get(i);
|
||||||
System.out.println(" " + i + " - " + tp.getName());
|
System.out.println(" " + i + " - " + tp.getName());
|
||||||
System.out.println(" = " + tp.getValue());
|
System.out.println(" = " + tp.getValue());
|
||||||
System.out.println(" @ " + tp.getMask());
|
System.out.println(" @ " + tp.getMask());
|
||||||
|
@ -20,12 +20,12 @@ package org.apache.poi.hslf.dev;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
import org.apache.poi.hslf.record.CurrentUserAtom;
|
import org.apache.poi.hslf.record.CurrentUserAtom;
|
||||||
import org.apache.poi.hslf.record.PersistPtrHolder;
|
import org.apache.poi.hslf.record.PersistPtrHolder;
|
||||||
import org.apache.poi.hslf.record.PositionDependentRecord;
|
import org.apache.poi.hslf.record.PositionDependentRecord;
|
||||||
import org.apache.poi.hslf.record.Record;
|
import org.apache.poi.hslf.record.Record;
|
||||||
import org.apache.poi.hslf.record.UserEditAtom;
|
import org.apache.poi.hslf.record.UserEditAtom;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.extractor;
|
package org.apache.poi.hslf.extractor;
|
||||||
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
|
||||||
import org.apache.poi.hslf.model.HSLFPictureShape;
|
|
||||||
import org.apache.poi.hslf.model.HSLFSlideShowImpl;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -17,19 +17,13 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.extractor;
|
package org.apache.poi.hslf.extractor;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.util.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.apache.poi.POIOLE2TextExtractor;
|
import org.apache.poi.POIOLE2TextExtractor;
|
||||||
import org.apache.poi.hslf.model.*;
|
import org.apache.poi.hslf.model.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
import org.apache.poi.poifs.filesystem.*;
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class can be used to extract text from a PowerPoint file. Can optionally
|
* This class can be used to extract text from a PowerPoint file. Can optionally
|
||||||
@ -40,7 +34,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|||||||
public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
||||||
private HSLFSlideShowImpl _hslfshow;
|
private HSLFSlideShowImpl _hslfshow;
|
||||||
private HSLFSlideShow _show;
|
private HSLFSlideShow _show;
|
||||||
private HSLFSlide[] _slides;
|
private List<HSLFSlide> _slides;
|
||||||
|
|
||||||
private boolean _slidesByDefault = true;
|
private boolean _slidesByDefault = true;
|
||||||
private boolean _notesByDefault = false;
|
private boolean _notesByDefault = false;
|
||||||
@ -74,6 +68,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
|
|
||||||
PowerPointExtractor ppe = new PowerPointExtractor(file);
|
PowerPointExtractor ppe = new PowerPointExtractor(file);
|
||||||
System.out.println(ppe.getText(true, notes, comments, master));
|
System.out.println(ppe.getText(true, notes, comments, master));
|
||||||
|
ppe.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,13 +183,10 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
public List<OLEShape> getOLEShapes() {
|
public List<OLEShape> getOLEShapes() {
|
||||||
List<OLEShape> list = new ArrayList<OLEShape>();
|
List<OLEShape> list = new ArrayList<OLEShape>();
|
||||||
|
|
||||||
for (int i = 0; i < _slides.length; i++) {
|
for (HSLFSlide slide : _slides) {
|
||||||
HSLFSlide slide = _slides[i];
|
for (HSLFShape shape : slide.getShapes()) {
|
||||||
|
if (shape instanceof OLEShape) {
|
||||||
HSLFShape[] shapes = slide.getShapes();
|
list.add((OLEShape) shape);
|
||||||
for (int j = 0; j < shapes.length; j++) {
|
|
||||||
if (shapes[j] instanceof OLEShape) {
|
|
||||||
list.add((OLEShape) shapes[j]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,7 +211,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
|
|
||||||
if (getSlideText) {
|
if (getSlideText) {
|
||||||
if (getMasterText) {
|
if (getMasterText) {
|
||||||
for (SlideMaster master : _show.getSlidesMasters()) {
|
for (HSLFSlideMaster master : _show.getSlideMasters()) {
|
||||||
for(HSLFShape sh : master.getShapes()){
|
for(HSLFShape sh : master.getShapes()){
|
||||||
if(sh instanceof HSLFTextShape){
|
if(sh instanceof HSLFTextShape){
|
||||||
if(HSLFMasterSheet.isPlaceholder(sh)) {
|
if(HSLFMasterSheet.isPlaceholder(sh)) {
|
||||||
@ -241,8 +233,8 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < _slides.length; i++) {
|
for (int i = 0; i < _slides.size(); i++) {
|
||||||
HSLFSlide slide = _slides[i];
|
HSLFSlide slide = _slides.get(i);
|
||||||
|
|
||||||
// Slide header, if set
|
// Slide header, if set
|
||||||
HeadersFooters hf = slide.getHeadersFooters();
|
HeadersFooters hf = slide.getHeadersFooters();
|
||||||
@ -251,7 +243,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slide text
|
// Slide text
|
||||||
textRunsToText(ret, slide.getTextRuns());
|
textRunsToText(ret, slide.getTextParagraphs());
|
||||||
|
|
||||||
// Table text
|
// Table text
|
||||||
for (HSLFShape shape : slide.getShapes()){
|
for (HSLFShape shape : slide.getShapes()){
|
||||||
@ -284,8 +276,8 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
HashSet<Integer> seenNotes = new HashSet<Integer>();
|
HashSet<Integer> seenNotes = new HashSet<Integer>();
|
||||||
HeadersFooters hf = _show.getNotesHeadersFooters();
|
HeadersFooters hf = _show.getNotesHeadersFooters();
|
||||||
|
|
||||||
for (int i = 0; i < _slides.length; i++) {
|
for (int i = 0; i < _slides.size(); i++) {
|
||||||
HSLFNotes notes = _slides[i].getNotesSheet();
|
HSLFNotes notes = _slides.get(i).getNotes();
|
||||||
if (notes == null) {
|
if (notes == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -301,7 +293,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notes text
|
// Notes text
|
||||||
textRunsToText(ret, notes.getTextRuns());
|
textRunsToText(ret, notes.getTextParagraphs());
|
||||||
|
|
||||||
// Repeat the notes footer, if set
|
// Repeat the notes footer, if set
|
||||||
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
|
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
|
||||||
@ -330,17 +322,17 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
|
|||||||
ret.append('\n');
|
ret.append('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void textRunsToText(StringBuffer ret, HSLFTextParagraph[] runs) {
|
private void textRunsToText(StringBuffer ret, List<List<HSLFTextParagraph>> paragraphs) {
|
||||||
if (runs==null) {
|
if (paragraphs==null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < runs.length; j++) {
|
for (List<HSLFTextParagraph> lp : paragraphs) {
|
||||||
HSLFTextParagraph run = runs[j];
|
for (HSLFTextParagraph p : lp) {
|
||||||
if (run != null) {
|
for (HSLFTextRun r : p.getTextRuns()) {
|
||||||
String text = run.getText();
|
ret.append(r.getRawText());
|
||||||
ret.append(text);
|
}
|
||||||
if (!text.endsWith("\n")) {
|
if (ret.length() > 0 && ret.charAt(ret.length()-1) != '\n') {
|
||||||
ret.append("\n");
|
ret.append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,20 +17,13 @@
|
|||||||
|
|
||||||
package org.apache.poi.hslf.extractor;
|
package org.apache.poi.hslf.extractor;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.HSLFTextParagraph;
|
import org.apache.poi.hslf.record.*;
|
||||||
import org.apache.poi.hslf.record.CString;
|
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
|
||||||
import org.apache.poi.hslf.record.Record;
|
import org.apache.poi.hslf.usermodel.HSLFTextShape;
|
||||||
import org.apache.poi.hslf.record.RecordTypes;
|
|
||||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextBytesAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextCharsAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextHeaderAtom;
|
|
||||||
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
@ -174,18 +167,19 @@ public final class QuickButCruddyTextExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, check the type to see if it's text
|
// Otherwise, check the type to see if it's text
|
||||||
long type = LittleEndian.getUShort(pptContents,startPos+2);
|
int type = LittleEndian.getUShort(pptContents,startPos+2);
|
||||||
HSLFTextParagraph trun = null;
|
|
||||||
|
|
||||||
// TextBytesAtom
|
// TextBytesAtom
|
||||||
if(type == RecordTypes.TextBytesAtom.typeID) {
|
if(type == RecordTypes.TextBytesAtom.typeID) {
|
||||||
TextBytesAtom tba = (TextBytesAtom)Record.createRecordForType(type, pptContents, startPos, len+8);
|
TextBytesAtom tba = (TextBytesAtom)Record.createRecordForType(type, pptContents, startPos, len+8);
|
||||||
trun = new HSLFTextParagraph((TextHeaderAtom)null,tba,(StyleTextPropAtom)null);
|
String text = HSLFTextParagraph.toExternalString(tba.getText(), -1);
|
||||||
|
textV.add(text);
|
||||||
}
|
}
|
||||||
// TextCharsAtom
|
// TextCharsAtom
|
||||||
if(type == RecordTypes.TextCharsAtom.typeID) {
|
if(type == RecordTypes.TextCharsAtom.typeID) {
|
||||||
TextCharsAtom tca = (TextCharsAtom)Record.createRecordForType(type, pptContents, startPos, len+8);
|
TextCharsAtom tca = (TextCharsAtom)Record.createRecordForType(type, pptContents, startPos, len+8);
|
||||||
trun = new HSLFTextParagraph((TextHeaderAtom)null,tca,(StyleTextPropAtom)null);
|
String text = HSLFTextParagraph.toExternalString(tca.getText(), -1);
|
||||||
|
textV.add(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CString (doesn't go via a TextRun)
|
// CString (doesn't go via a TextRun)
|
||||||
@ -201,10 +195,6 @@ public final class QuickButCruddyTextExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we found text via a TextRun, save it in the vector
|
|
||||||
if(trun != null) {
|
|
||||||
textV.add(trun.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wind on by the atom length, and check we're not at the end
|
// Wind on by the atom length, and check we're not at the end
|
||||||
int newPos = (startPos + 8 + len);
|
int newPos = (startPos + 8 + len);
|
||||||
|
@ -34,6 +34,7 @@ import org.apache.poi.hslf.record.ExObjList;
|
|||||||
import org.apache.poi.hslf.record.OEShapeAtom;
|
import org.apache.poi.hslf.record.OEShapeAtom;
|
||||||
import org.apache.poi.hslf.record.Record;
|
import org.apache.poi.hslf.record.Record;
|
||||||
import org.apache.poi.hslf.record.RecordTypes;
|
import org.apache.poi.hslf.record.RecordTypes;
|
||||||
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
import org.apache.poi.sl.usermodel.ShapeType;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
@ -1,388 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
|
||||||
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Arc2D;
|
|
||||||
import java.awt.geom.Ellipse2D;
|
|
||||||
import java.awt.geom.GeneralPath;
|
|
||||||
import java.awt.geom.Line2D;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.awt.geom.RoundRectangle2D;
|
|
||||||
|
|
||||||
import org.apache.poi.ddf.EscherProperties;
|
|
||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores definition of auto-shapes.
|
|
||||||
* See the Office Drawing 97-2007 Binary Format Specification for details.
|
|
||||||
*
|
|
||||||
* TODO: follow the spec and define all the auto-shapes
|
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public final class AutoShapes {
|
|
||||||
protected static final ShapeOutline[] shapes;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return shape outline by shape type
|
|
||||||
* @param type shape type see {@link ShapeTypes}
|
|
||||||
*
|
|
||||||
* @return the shape outline
|
|
||||||
*/
|
|
||||||
public static ShapeOutline getShapeOutline(ShapeType type){
|
|
||||||
ShapeOutline outline = shapes[type.nativeId];
|
|
||||||
return outline;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-shapes are defined in the [0,21600] coordinate system.
|
|
||||||
* We need to transform it into normal slide coordinates
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static java.awt.Shape transform(java.awt.Shape outline, Rectangle2D anchor){
|
|
||||||
AffineTransform at = new AffineTransform();
|
|
||||||
at.translate(anchor.getX(), anchor.getY());
|
|
||||||
at.scale(
|
|
||||||
1.0f/21600*anchor.getWidth(),
|
|
||||||
1.0f/21600*anchor.getHeight()
|
|
||||||
);
|
|
||||||
return at.createTransformedShape(outline);
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
shapes = new ShapeOutline[255];
|
|
||||||
|
|
||||||
shapes[ShapeType.RECT.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
Rectangle2D path = new Rectangle2D.Float(0, 0, 21600, 21600);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.ROUND_RECT.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
RoundRectangle2D path = new RoundRectangle2D.Float(0, 0, 21600, 21600, adjval, adjval);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.ELLIPSE.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
Ellipse2D path = new Ellipse2D.Float(0, 0, 21600, 21600);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.DIAMOND.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(10800, 0);
|
|
||||||
path.lineTo(21600, 10800);
|
|
||||||
path.lineTo(10800, 21600);
|
|
||||||
path.lineTo(0, 10800);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//m@0,l,21600r21600
|
|
||||||
shapes[ShapeType.TRIANGLE.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 10800);
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(adjval, 0);
|
|
||||||
path.lineTo(0, 21600);
|
|
||||||
path.lineTo(21600, 21600);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.RT_TRIANGLE.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(0, 0);
|
|
||||||
path.lineTo(21600, 21600);
|
|
||||||
path.lineTo(0, 21600);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.PARALLELOGRAM.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(adjval, 0);
|
|
||||||
path.lineTo(21600, 0);
|
|
||||||
path.lineTo(21600 - adjval, 21600);
|
|
||||||
path.lineTo(0, 21600);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.TRAPEZOID.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(0, 0);
|
|
||||||
path.lineTo(adjval, 21600);
|
|
||||||
path.lineTo(21600 - adjval, 21600);
|
|
||||||
path.lineTo(21600, 0);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.HEXAGON.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(adjval, 0);
|
|
||||||
path.lineTo(21600 - adjval, 0);
|
|
||||||
path.lineTo(21600, 10800);
|
|
||||||
path.lineTo(21600 - adjval, 21600);
|
|
||||||
path.lineTo(adjval, 21600);
|
|
||||||
path.lineTo(0, 10800);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.OCTAGON.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 6326);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(adjval, 0);
|
|
||||||
path.lineTo(21600 - adjval, 0);
|
|
||||||
path.lineTo(21600, adjval);
|
|
||||||
path.lineTo(21600, 21600-adjval);
|
|
||||||
path.lineTo(21600-adjval, 21600);
|
|
||||||
path.lineTo(adjval, 21600);
|
|
||||||
path.lineTo(0, 21600-adjval);
|
|
||||||
path.lineTo(0, adjval);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.PLUS.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(adjval, 0);
|
|
||||||
path.lineTo(21600 - adjval, 0);
|
|
||||||
path.lineTo(21600 - adjval, adjval);
|
|
||||||
path.lineTo(21600, adjval);
|
|
||||||
path.lineTo(21600, 21600-adjval);
|
|
||||||
path.lineTo(21600-adjval, 21600-adjval);
|
|
||||||
path.lineTo(21600-adjval, 21600);
|
|
||||||
path.lineTo(adjval, 21600);
|
|
||||||
path.lineTo(adjval, 21600-adjval);
|
|
||||||
path.lineTo(0, 21600-adjval);
|
|
||||||
path.lineTo(0, adjval);
|
|
||||||
path.lineTo(adjval, adjval);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.PENTAGON.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(10800, 0);
|
|
||||||
path.lineTo(21600, 8259);
|
|
||||||
path.lineTo(21600 - 4200, 21600);
|
|
||||||
path.lineTo(4200, 21600);
|
|
||||||
path.lineTo(0, 8259);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.DOWN_ARROW.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
//m0@0 l@1@0 @1,0 @2,0 @2@0,21600@0,10800,21600xe
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
|
|
||||||
int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(0, adjval);
|
|
||||||
path.lineTo(adjval2, adjval);
|
|
||||||
path.lineTo(adjval2, 0);
|
|
||||||
path.lineTo(21600-adjval2, 0);
|
|
||||||
path.lineTo(21600-adjval2, adjval);
|
|
||||||
path.lineTo(21600, adjval);
|
|
||||||
path.lineTo(10800, 21600);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.UP_ARROW.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
//m0@0 l@1@0 @1,21600@2,21600@2@0,21600@0,10800,xe
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(0, adjval);
|
|
||||||
path.lineTo(adjval2, adjval);
|
|
||||||
path.lineTo(adjval2, 21600);
|
|
||||||
path.lineTo(21600-adjval2, 21600);
|
|
||||||
path.lineTo(21600-adjval2, adjval);
|
|
||||||
path.lineTo(21600, adjval);
|
|
||||||
path.lineTo(10800, 0);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.RIGHT_ARROW.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
//m@0, l@0@1 ,0@1,0@2@0@2@0,21600,21600,10800xe
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 16200);
|
|
||||||
int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(adjval, 0);
|
|
||||||
path.lineTo(adjval, adjval2);
|
|
||||||
path.lineTo(0, adjval2);
|
|
||||||
path.lineTo(0, 21600-adjval2);
|
|
||||||
path.lineTo(adjval, 21600-adjval2);
|
|
||||||
path.lineTo(adjval, 21600);
|
|
||||||
path.lineTo(21600, 10800);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.LEFT_ARROW.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
//m@0, l@0@1,21600@1,21600@2@0@2@0,21600,,10800xe
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 5400);
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(adjval, 0);
|
|
||||||
path.lineTo(adjval, adjval2);
|
|
||||||
path.lineTo(21600, adjval2);
|
|
||||||
path.lineTo(21600, 21600-adjval2);
|
|
||||||
path.lineTo(adjval, 21600-adjval2);
|
|
||||||
path.lineTo(adjval, 21600);
|
|
||||||
path.lineTo(0, 10800);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.CAN.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
//m10800,qx0@1l0@2qy10800,21600,21600@2l21600@1qy10800,xem0@1qy10800@0,21600@1nfe
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(0, 0, 21600, adjval, 0, 180, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(0, adjval/2);
|
|
||||||
|
|
||||||
path.lineTo(0, 21600 - adjval/2);
|
|
||||||
path.closePath();
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(0, 21600 - adjval, 21600, adjval, 180, 180, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(21600, 21600 - adjval/2);
|
|
||||||
|
|
||||||
path.lineTo(21600, adjval/2);
|
|
||||||
path.append(new Arc2D.Float(0, 0, 21600, adjval, 180, 180, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(0, adjval/2);
|
|
||||||
path.closePath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.LEFT_BRACE.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
//m21600,qx10800@0l10800@2qy0@11,10800@3l10800@1qy21600,21600e
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
|
|
||||||
int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(21600, 0);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(10800, 0, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(10800, adjval);
|
|
||||||
|
|
||||||
path.lineTo(10800, adjval2 - adjval);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(-10800, adjval2 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(0, adjval2);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(-10800, adjval2, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(10800, adjval2 + adjval);
|
|
||||||
|
|
||||||
path.lineTo(10800, 21600 - adjval);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(10800, 21600 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.RIGHT_BRACE.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
//m,qx10800@0 l10800@2qy21600@11,10800@3l10800@1qy,21600e
|
|
||||||
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 1800);
|
|
||||||
int adjval2 = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUST2VALUE, 10800);
|
|
||||||
|
|
||||||
GeneralPath path = new GeneralPath();
|
|
||||||
path.moveTo(0, 0);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(-10800, 0, 21600, adjval*2, 0, 90, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(10800, adjval);
|
|
||||||
|
|
||||||
path.lineTo(10800, adjval2 - adjval);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(10800, adjval2 - 2*adjval, 21600, adjval*2, 180, 90, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(21600, adjval2);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(10800, adjval2, 21600, adjval*2, 90, 90, Arc2D.OPEN), false);
|
|
||||||
path.moveTo(10800, adjval2 + adjval);
|
|
||||||
|
|
||||||
path.lineTo(10800, 21600 - adjval);
|
|
||||||
|
|
||||||
path.append(new Arc2D.Float(-10800, 21600 - 2*adjval, 21600, adjval*2, 270, 90, Arc2D.OPEN), false);
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
shapes[ShapeType.STRAIGHT_CONNECTOR_1.nativeId] = new ShapeOutline(){
|
|
||||||
public java.awt.Shape getOutline(HSLFShape shape){
|
|
||||||
return new Line2D.Float(0, 0, 21600, 21600);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,744 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
|
||||||
import org.apache.poi.hslf.record.PPDrawing;
|
|
||||||
import org.apache.poi.hslf.record.Record;
|
|
||||||
import org.apache.poi.hslf.record.RecordContainer;
|
|
||||||
import org.apache.poi.hslf.record.SlideListWithText;
|
|
||||||
import org.apache.poi.hslf.record.StyleTextProp9Atom;
|
|
||||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextBytesAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextCharsAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextHeaderAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextRulerAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextSpecInfoAtom;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
|
||||||
import org.apache.poi.sl.usermodel.TextParagraph;
|
|
||||||
import org.apache.poi.util.StringUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents a run of text in a powerpoint document. That
|
|
||||||
* run could be text on a sheet, or text in a note.
|
|
||||||
* It is only a very basic class for now
|
|
||||||
*
|
|
||||||
* @author Nick Burch
|
|
||||||
*/
|
|
||||||
|
|
||||||
public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun>
|
|
||||||
{
|
|
||||||
// Note: These fields are protected to help with unit testing
|
|
||||||
// Other classes shouldn't really go playing with them!
|
|
||||||
protected TextHeaderAtom _headerAtom;
|
|
||||||
protected TextBytesAtom _byteAtom;
|
|
||||||
protected TextCharsAtom _charAtom;
|
|
||||||
protected StyleTextPropAtom _styleAtom;
|
|
||||||
protected TextRulerAtom _ruler;
|
|
||||||
protected boolean _isUnicode;
|
|
||||||
protected HSLFTextRun[] _rtRuns;
|
|
||||||
protected HSLFTextShape _parentShape;
|
|
||||||
// private SlideShow slideShow;
|
|
||||||
private HSLFSheet _sheet;
|
|
||||||
private int shapeId;
|
|
||||||
private int slwtIndex = -1; //position in the owning SlideListWithText
|
|
||||||
/**
|
|
||||||
* all text run records that follow TextHeaderAtom.
|
|
||||||
* (there can be misc InteractiveInfo, TxInteractiveInfo and other records)
|
|
||||||
*/
|
|
||||||
protected Record[] _records;
|
|
||||||
// private StyleTextPropAtom styleTextPropAtom;
|
|
||||||
private StyleTextProp9Atom styleTextProp9Atom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a Text Run from a Unicode text block
|
|
||||||
*
|
|
||||||
* @param tha the TextHeaderAtom that defines what's what
|
|
||||||
* @param tca the TextCharsAtom containing the text
|
|
||||||
* @param sta the StyleTextPropAtom which defines the character stylings
|
|
||||||
*/
|
|
||||||
public HSLFTextParagraph(TextHeaderAtom tha, TextCharsAtom tca, StyleTextPropAtom sta) {
|
|
||||||
this(tha,null,tca,sta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a Text Run from a Ascii text block
|
|
||||||
*
|
|
||||||
* @param tha the TextHeaderAtom that defines what's what
|
|
||||||
* @param tba the TextBytesAtom containing the text
|
|
||||||
* @param sta the StyleTextPropAtom which defines the character stylings
|
|
||||||
*/
|
|
||||||
public HSLFTextParagraph(TextHeaderAtom tha, TextBytesAtom tba, StyleTextPropAtom sta) {
|
|
||||||
this(tha,tba,null,sta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal constructor and initializer
|
|
||||||
*/
|
|
||||||
private HSLFTextParagraph(TextHeaderAtom tha, TextBytesAtom tba, TextCharsAtom tca, StyleTextPropAtom sta) {
|
|
||||||
_headerAtom = tha;
|
|
||||||
_styleAtom = sta;
|
|
||||||
if(tba != null) {
|
|
||||||
_byteAtom = tba;
|
|
||||||
_isUnicode = false;
|
|
||||||
} else {
|
|
||||||
_charAtom = tca;
|
|
||||||
_isUnicode = true;
|
|
||||||
}
|
|
||||||
String runRawText = getText();
|
|
||||||
|
|
||||||
// Figure out the rich text runs
|
|
||||||
LinkedList<TextPropCollection> pStyles = new LinkedList<TextPropCollection>();
|
|
||||||
LinkedList<TextPropCollection> cStyles = new LinkedList<TextPropCollection>();
|
|
||||||
if(_styleAtom != null) {
|
|
||||||
// Get the style atom to grok itself
|
|
||||||
_styleAtom.setParentTextSize(runRawText.length());
|
|
||||||
pStyles = _styleAtom.getParagraphStyles();
|
|
||||||
cStyles = _styleAtom.getCharacterStyles();
|
|
||||||
}
|
|
||||||
buildRichTextRuns(pStyles, cStyles, runRawText);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buildRichTextRuns(LinkedList<TextPropCollection> pStyles, LinkedList<TextPropCollection> cStyles, String runRawText){
|
|
||||||
|
|
||||||
// Handle case of no current style, with a default
|
|
||||||
if(pStyles.size() == 0 || cStyles.size() == 0) {
|
|
||||||
_rtRuns = new HSLFTextRun[1];
|
|
||||||
_rtRuns[0] = new HSLFTextRun(this, 0, runRawText.length());
|
|
||||||
} else {
|
|
||||||
// Build up Rich Text Runs, one for each
|
|
||||||
// character/paragraph style pair
|
|
||||||
List<HSLFTextRun> rtrs = new ArrayList<HSLFTextRun>();
|
|
||||||
|
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
int curP = 0;
|
|
||||||
int curC = 0;
|
|
||||||
int pLenRemain = -1;
|
|
||||||
int cLenRemain = -1;
|
|
||||||
|
|
||||||
// Build one for each run with the same style
|
|
||||||
while(pos <= runRawText.length() && curP < pStyles.size() && curC < cStyles.size()) {
|
|
||||||
// Get the Props to use
|
|
||||||
TextPropCollection pProps = pStyles.get(curP);
|
|
||||||
TextPropCollection cProps = cStyles.get(curC);
|
|
||||||
|
|
||||||
int pLen = pProps.getCharactersCovered();
|
|
||||||
int cLen = cProps.getCharactersCovered();
|
|
||||||
|
|
||||||
// Handle new pass
|
|
||||||
boolean freshSet = false;
|
|
||||||
if(pLenRemain == -1 && cLenRemain == -1) { freshSet = true; }
|
|
||||||
if(pLenRemain == -1) { pLenRemain = pLen; }
|
|
||||||
if(cLenRemain == -1) { cLenRemain = cLen; }
|
|
||||||
|
|
||||||
// So we know how to build the eventual run
|
|
||||||
int runLen = -1;
|
|
||||||
boolean pShared = false;
|
|
||||||
boolean cShared = false;
|
|
||||||
|
|
||||||
// Same size, new styles - neither shared
|
|
||||||
if(pLen == cLen && freshSet) {
|
|
||||||
runLen = cLen;
|
|
||||||
pShared = false;
|
|
||||||
cShared = false;
|
|
||||||
curP++;
|
|
||||||
curC++;
|
|
||||||
pLenRemain = -1;
|
|
||||||
cLenRemain = -1;
|
|
||||||
} else {
|
|
||||||
// Some sharing
|
|
||||||
|
|
||||||
// See if we are already in a shared block
|
|
||||||
if(pLenRemain < pLen) {
|
|
||||||
// Existing shared p block
|
|
||||||
pShared = true;
|
|
||||||
|
|
||||||
// Do we end with the c block, or either side of it?
|
|
||||||
if(pLenRemain == cLenRemain) {
|
|
||||||
// We end at the same time
|
|
||||||
cShared = false;
|
|
||||||
runLen = pLenRemain;
|
|
||||||
curP++;
|
|
||||||
curC++;
|
|
||||||
pLenRemain = -1;
|
|
||||||
cLenRemain = -1;
|
|
||||||
} else if(pLenRemain < cLenRemain) {
|
|
||||||
// We end before the c block
|
|
||||||
cShared = true;
|
|
||||||
runLen = pLenRemain;
|
|
||||||
curP++;
|
|
||||||
cLenRemain -= pLenRemain;
|
|
||||||
pLenRemain = -1;
|
|
||||||
} else {
|
|
||||||
// We end after the c block
|
|
||||||
cShared = false;
|
|
||||||
runLen = cLenRemain;
|
|
||||||
curC++;
|
|
||||||
pLenRemain -= cLenRemain;
|
|
||||||
cLenRemain = -1;
|
|
||||||
}
|
|
||||||
} else if(cLenRemain < cLen) {
|
|
||||||
// Existing shared c block
|
|
||||||
cShared = true;
|
|
||||||
|
|
||||||
// Do we end with the p block, or either side of it?
|
|
||||||
if(pLenRemain == cLenRemain) {
|
|
||||||
// We end at the same time
|
|
||||||
pShared = false;
|
|
||||||
runLen = cLenRemain;
|
|
||||||
curP++;
|
|
||||||
curC++;
|
|
||||||
pLenRemain = -1;
|
|
||||||
cLenRemain = -1;
|
|
||||||
} else if(cLenRemain < pLenRemain) {
|
|
||||||
// We end before the p block
|
|
||||||
pShared = true;
|
|
||||||
runLen = cLenRemain;
|
|
||||||
curC++;
|
|
||||||
pLenRemain -= cLenRemain;
|
|
||||||
cLenRemain = -1;
|
|
||||||
} else {
|
|
||||||
// We end after the p block
|
|
||||||
pShared = false;
|
|
||||||
runLen = pLenRemain;
|
|
||||||
curP++;
|
|
||||||
cLenRemain -= pLenRemain;
|
|
||||||
pLenRemain = -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Start of a shared block
|
|
||||||
if(pLenRemain < cLenRemain) {
|
|
||||||
// Shared c block
|
|
||||||
pShared = false;
|
|
||||||
cShared = true;
|
|
||||||
runLen = pLenRemain;
|
|
||||||
curP++;
|
|
||||||
cLenRemain -= pLenRemain;
|
|
||||||
pLenRemain = -1;
|
|
||||||
} else {
|
|
||||||
// Shared p block
|
|
||||||
pShared = true;
|
|
||||||
cShared = false;
|
|
||||||
runLen = cLenRemain;
|
|
||||||
curC++;
|
|
||||||
pLenRemain -= cLenRemain;
|
|
||||||
cLenRemain = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wind on
|
|
||||||
int prevPos = pos;
|
|
||||||
pos += runLen;
|
|
||||||
// Adjust for end-of-run extra 1 length
|
|
||||||
if(pos > runRawText.length()) {
|
|
||||||
runLen--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save
|
|
||||||
HSLFTextRun rtr = new HSLFTextRun(this, prevPos, runLen, pProps, cProps, pShared, cShared);
|
|
||||||
rtrs.add(rtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the array
|
|
||||||
_rtRuns = rtrs.toArray(new HSLFTextRun[rtrs.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update methods follow
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the supplied text onto the end of the TextRun,
|
|
||||||
* creating a new RichTextRun (returned) for it to
|
|
||||||
* sit in.
|
|
||||||
* In many cases, before calling this, you'll want to add
|
|
||||||
* a newline onto the end of your last RichTextRun
|
|
||||||
*/
|
|
||||||
public HSLFTextRun appendText(String s) {
|
|
||||||
// We will need a StyleTextProp atom
|
|
||||||
ensureStyleAtomPresent();
|
|
||||||
|
|
||||||
// First up, append the text to the
|
|
||||||
// underlying text atom
|
|
||||||
int oldSize = getRawText().length();
|
|
||||||
storeText(
|
|
||||||
getRawText() + s
|
|
||||||
);
|
|
||||||
|
|
||||||
// If either of the previous styles overran
|
|
||||||
// the text by one, we need to shuffle that
|
|
||||||
// extra character onto the new ones
|
|
||||||
int pOverRun = _styleAtom.getParagraphTextLengthCovered() - oldSize;
|
|
||||||
int cOverRun = _styleAtom.getCharacterTextLengthCovered() - oldSize;
|
|
||||||
if(pOverRun > 0) {
|
|
||||||
TextPropCollection tpc = _styleAtom.getParagraphStyles().getLast();
|
|
||||||
tpc.updateTextSize(
|
|
||||||
tpc.getCharactersCovered() - pOverRun
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if(cOverRun > 0) {
|
|
||||||
TextPropCollection tpc = _styleAtom.getCharacterStyles().getLast();
|
|
||||||
tpc.updateTextSize(
|
|
||||||
tpc.getCharactersCovered() - cOverRun
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, add the styles for its paragraph and characters
|
|
||||||
TextPropCollection newPTP =
|
|
||||||
_styleAtom.addParagraphTextPropCollection(s.length()+pOverRun);
|
|
||||||
TextPropCollection newCTP =
|
|
||||||
_styleAtom.addCharacterTextPropCollection(s.length()+cOverRun);
|
|
||||||
|
|
||||||
// Now, create the new RichTextRun
|
|
||||||
HSLFTextRun nr = new HSLFTextRun(
|
|
||||||
this, oldSize, s.length(),
|
|
||||||
newPTP, newCTP, false, false
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add the new RichTextRun onto our list
|
|
||||||
HSLFTextRun[] newRuns = new HSLFTextRun[_rtRuns.length+1];
|
|
||||||
System.arraycopy(_rtRuns, 0, newRuns, 0, _rtRuns.length);
|
|
||||||
newRuns[newRuns.length-1] = nr;
|
|
||||||
_rtRuns = newRuns;
|
|
||||||
|
|
||||||
// And return the new run to the caller
|
|
||||||
return nr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the given string to the records. Doesn't
|
|
||||||
* touch the stylings.
|
|
||||||
*/
|
|
||||||
private void storeText(String s) {
|
|
||||||
// Store in the appropriate record
|
|
||||||
if(_isUnicode) {
|
|
||||||
// The atom can safely convert to unicode
|
|
||||||
_charAtom.setText(s);
|
|
||||||
} else {
|
|
||||||
// Will it fit in a 8 bit atom?
|
|
||||||
boolean hasMultibyte = StringUtil.hasMultibyte(s);
|
|
||||||
if(! hasMultibyte) {
|
|
||||||
// Fine to go into 8 bit atom
|
|
||||||
byte[] text = new byte[s.length()];
|
|
||||||
StringUtil.putCompressedUnicode(s,text,0);
|
|
||||||
_byteAtom.setText(text);
|
|
||||||
} else {
|
|
||||||
// Need to swap a TextBytesAtom for a TextCharsAtom
|
|
||||||
|
|
||||||
// Build the new TextCharsAtom
|
|
||||||
_charAtom = new TextCharsAtom();
|
|
||||||
_charAtom.setText(s);
|
|
||||||
|
|
||||||
// Use the TextHeaderAtom to do the swap on the parent
|
|
||||||
RecordContainer parent = _headerAtom.getParentRecord();
|
|
||||||
Record[] cr = parent.getChildRecords();
|
|
||||||
for(int i=0; i<cr.length; i++) {
|
|
||||||
// Look for TextBytesAtom
|
|
||||||
if(cr[i].equals(_byteAtom)) {
|
|
||||||
// Found it, so replace, then all done
|
|
||||||
cr[i] = _charAtom;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flag the change
|
|
||||||
_byteAtom = null;
|
|
||||||
_isUnicode = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* If TextSpecInfoAtom is present, we must update the text size in it,
|
|
||||||
* otherwise the ppt will be corrupted
|
|
||||||
*/
|
|
||||||
if(_records != null) for (int i = 0; i < _records.length; i++) {
|
|
||||||
if(_records[i] instanceof TextSpecInfoAtom){
|
|
||||||
TextSpecInfoAtom specAtom = (TextSpecInfoAtom)_records[i];
|
|
||||||
if((s.length() + 1) != specAtom.getCharactersCovered()){
|
|
||||||
specAtom.reset(s.length() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles an update to the text stored in one of the Rich Text Runs
|
|
||||||
* @param run
|
|
||||||
* @param s
|
|
||||||
*/
|
|
||||||
public void changeTextInRichTextRun(HSLFTextRun run, String s) {
|
|
||||||
// Figure out which run it is
|
|
||||||
int runID = -1;
|
|
||||||
for(int i=0; i<_rtRuns.length; i++) {
|
|
||||||
if(run.equals(_rtRuns[i])) {
|
|
||||||
runID = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(runID == -1) {
|
|
||||||
throw new IllegalArgumentException("Supplied RichTextRun wasn't from this TextRun");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure a StyleTextPropAtom is present, adding if required
|
|
||||||
ensureStyleAtomPresent();
|
|
||||||
|
|
||||||
// Update the text length for its Paragraph and Character stylings
|
|
||||||
// If it's shared:
|
|
||||||
// * calculate the new length based on the run's old text
|
|
||||||
// * this should leave in any +1's for the end of block if needed
|
|
||||||
// If it isn't shared:
|
|
||||||
// * reset the length, to the new string's length
|
|
||||||
// * add on +1 if the last block
|
|
||||||
// The last run needs its stylings to be 1 longer than the raw
|
|
||||||
// text is. This is to define the stylings that any new text
|
|
||||||
// that is added will inherit
|
|
||||||
TextPropCollection pCol = run._getRawParagraphStyle();
|
|
||||||
TextPropCollection cCol = run._getRawCharacterStyle();
|
|
||||||
int newSize = s.length();
|
|
||||||
if(runID == _rtRuns.length-1) {
|
|
||||||
newSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(run._isParagraphStyleShared()) {
|
|
||||||
pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length() );
|
|
||||||
} else {
|
|
||||||
pCol.updateTextSize(newSize);
|
|
||||||
}
|
|
||||||
if(run._isCharacterStyleShared()) {
|
|
||||||
cCol.updateTextSize( cCol.getCharactersCovered() - run.getLength() + s.length() );
|
|
||||||
} else {
|
|
||||||
cCol.updateTextSize(newSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build up the new text
|
|
||||||
// As we go through, update the start position for all subsequent runs
|
|
||||||
// The building relies on the old text still being present
|
|
||||||
StringBuffer newText = new StringBuffer();
|
|
||||||
for(int i=0; i<_rtRuns.length; i++) {
|
|
||||||
int newStartPos = newText.length();
|
|
||||||
|
|
||||||
// Build up the new text
|
|
||||||
if(i != runID) {
|
|
||||||
// Not the affected run, so keep old text
|
|
||||||
newText.append(_rtRuns[i].getRawText());
|
|
||||||
} else {
|
|
||||||
// Affected run, so use new text
|
|
||||||
newText.append(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do we need to update the start position of this run?
|
|
||||||
// (Need to get the text before we update the start pos)
|
|
||||||
if(i <= runID) {
|
|
||||||
// Change is after this, so don't need to change start position
|
|
||||||
} else {
|
|
||||||
// Change has occured, so update start position
|
|
||||||
_rtRuns[i].updateStartPosition(newStartPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can save the new text
|
|
||||||
storeText(newText.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the text, and sets it all to have the same styling
|
|
||||||
* as the the first character has.
|
|
||||||
* If you care about styling, do setText on a RichTextRun instead
|
|
||||||
*/
|
|
||||||
public void setRawText(String s) {
|
|
||||||
// Save the new text to the atoms
|
|
||||||
storeText(s);
|
|
||||||
HSLFTextRun fst = _rtRuns[0];
|
|
||||||
|
|
||||||
// Finally, zap and re-do the RichTextRuns
|
|
||||||
for(int i=0; i<_rtRuns.length; i++) { _rtRuns[i] = null; }
|
|
||||||
_rtRuns = new HSLFTextRun[1];
|
|
||||||
_rtRuns[0] = fst;
|
|
||||||
|
|
||||||
// Now handle record stylings:
|
|
||||||
// If there isn't styling
|
|
||||||
// no change, stays with no styling
|
|
||||||
// If there is styling:
|
|
||||||
// everthing gets the same style that the first block has
|
|
||||||
// Update the lengths +1 for since these will be the only runs
|
|
||||||
if(_styleAtom != null) {
|
|
||||||
LinkedList<TextPropCollection> pStyles = _styleAtom.getParagraphStyles();
|
|
||||||
while(pStyles.size() > 1) { pStyles.removeLast(); }
|
|
||||||
|
|
||||||
if (!pStyles.isEmpty()) {
|
|
||||||
pStyles.getFirst().updateTextSize( s.length()+1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkedList<TextPropCollection> cStyles = _styleAtom.getCharacterStyles();
|
|
||||||
while(cStyles.size() > 1) { cStyles.removeLast(); }
|
|
||||||
|
|
||||||
if (!cStyles.isEmpty()) {
|
|
||||||
cStyles.getFirst().updateTextSize( s.length()+1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
_rtRuns[0].setText(s);
|
|
||||||
} else {
|
|
||||||
// Recreate rich text run with no styling
|
|
||||||
_rtRuns[0] = new HSLFTextRun(this,0,s.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the text.
|
|
||||||
* Converts '\r' into '\n'
|
|
||||||
*/
|
|
||||||
public void setText(String s) {
|
|
||||||
String text = normalize(s);
|
|
||||||
setRawText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure a StyleTextPropAtom is present for this run,
|
|
||||||
* by adding if required. Normally for internal TextRun use.
|
|
||||||
*/
|
|
||||||
public void ensureStyleAtomPresent() {
|
|
||||||
if(_styleAtom != null) {
|
|
||||||
// All there
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new one at the right size
|
|
||||||
_styleAtom = new StyleTextPropAtom(getRawText().length() + 1);
|
|
||||||
|
|
||||||
// Use the TextHeader atom to get at the parent
|
|
||||||
RecordContainer runAtomsParent = _headerAtom.getParentRecord();
|
|
||||||
|
|
||||||
// Add the new StyleTextPropAtom after the TextCharsAtom / TextBytesAtom
|
|
||||||
Record addAfter = _byteAtom;
|
|
||||||
if(_byteAtom == null) { addAfter = _charAtom; }
|
|
||||||
runAtomsParent.addChildAfter(_styleAtom, addAfter);
|
|
||||||
|
|
||||||
// Feed this to our sole rich text run
|
|
||||||
if(_rtRuns.length != 1) {
|
|
||||||
throw new IllegalStateException("Needed to add StyleTextPropAtom when had many rich text runs");
|
|
||||||
}
|
|
||||||
// These are the only styles for now
|
|
||||||
_rtRuns[0].supplyTextProps(
|
|
||||||
_styleAtom.getParagraphStyles().get(0),
|
|
||||||
_styleAtom.getCharacterStyles().get(0),
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accesser methods follow
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the text content of the run, which has been made safe
|
|
||||||
* for printing and other use.
|
|
||||||
*/
|
|
||||||
public String getText() {
|
|
||||||
String rawText = getRawText();
|
|
||||||
|
|
||||||
// PowerPoint seems to store files with \r as the line break
|
|
||||||
// The messes things up on everything but a Mac, so translate
|
|
||||||
// them to \n
|
|
||||||
String text = rawText.replace('\r','\n');
|
|
||||||
|
|
||||||
int type = _headerAtom == null ? 0 : _headerAtom.getTextType();
|
|
||||||
if(type == TextHeaderAtom.TITLE_TYPE || type == TextHeaderAtom.CENTER_TITLE_TYPE){
|
|
||||||
//0xB acts like cariage return in page titles and like blank in the others
|
|
||||||
text = text.replace((char) 0x0B, '\n');
|
|
||||||
} else {
|
|
||||||
text = text.replace((char) 0x0B, ' ');
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the raw text content of the run. This hasn't had any
|
|
||||||
* changes applied to it, and so is probably unlikely to print
|
|
||||||
* out nicely.
|
|
||||||
*/
|
|
||||||
public String getRawText() {
|
|
||||||
if(_isUnicode) {
|
|
||||||
return _charAtom.getText();
|
|
||||||
}
|
|
||||||
return _byteAtom.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the rich text runs (runs of text with the same styling) that
|
|
||||||
* are contained within this block of text
|
|
||||||
*/
|
|
||||||
public HSLFTextRun[] getRichTextRuns() {
|
|
||||||
return _rtRuns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type of the text, from the TextHeaderAtom.
|
|
||||||
* Possible values can be seen from TextHeaderAtom
|
|
||||||
* @see org.apache.poi.hslf.record.TextHeaderAtom
|
|
||||||
*/
|
|
||||||
public int getRunType() {
|
|
||||||
return _headerAtom.getTextType();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the type of the text. Values should be taken
|
|
||||||
* from TextHeaderAtom. No checking is done to ensure you
|
|
||||||
* set this to a valid value!
|
|
||||||
* @see org.apache.poi.hslf.record.TextHeaderAtom
|
|
||||||
*/
|
|
||||||
public void setRunType(int type) {
|
|
||||||
_headerAtom.setTextType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Supply the Sheet we belong to, which might have an assigned SlideShow
|
|
||||||
* Also passes it on to our child RichTextRuns
|
|
||||||
*/
|
|
||||||
public void supplySheet(HSLFSheet sheet){
|
|
||||||
this._sheet = sheet;
|
|
||||||
|
|
||||||
if (_rtRuns == null) return;
|
|
||||||
for(HSLFTextRun rt : _rtRuns) {
|
|
||||||
rt.updateSheet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HSLFSheet getSheet(){
|
|
||||||
return this._sheet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Shape ID
|
|
||||||
*/
|
|
||||||
protected int getShapeId(){
|
|
||||||
return shapeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param id Shape ID
|
|
||||||
*/
|
|
||||||
protected void setShapeId(int id){
|
|
||||||
shapeId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return 0-based index of the text run in the SLWT container
|
|
||||||
*/
|
|
||||||
protected int getIndex(){
|
|
||||||
return slwtIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param id 0-based index of the text run in the SLWT container
|
|
||||||
*/
|
|
||||||
protected void setIndex(int id){
|
|
||||||
slwtIndex = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this Text Run one from a {@link PPDrawing}, or is it
|
|
||||||
* one from the {@link SlideListWithText}?
|
|
||||||
*/
|
|
||||||
public boolean isDrawingBased() {
|
|
||||||
return (slwtIndex == -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the array of all hyperlinks in this text run
|
|
||||||
*
|
|
||||||
* @return the array of all hyperlinks in this text run
|
|
||||||
* or <code>null</code> if not found.
|
|
||||||
*/
|
|
||||||
public Hyperlink[] getHyperlinks(){
|
|
||||||
return Hyperlink.find(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch RichTextRun at a given position
|
|
||||||
*
|
|
||||||
* @param pos 0-based index in the text
|
|
||||||
* @return RichTextRun or null if not found
|
|
||||||
*/
|
|
||||||
public HSLFTextRun getRichTextRunAt(int pos){
|
|
||||||
for (int i = 0; i < _rtRuns.length; i++) {
|
|
||||||
int start = _rtRuns[i].getStartIndex();
|
|
||||||
int end = _rtRuns[i].getEndIndex();
|
|
||||||
if(pos >= start && pos < end) return _rtRuns[i];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextRulerAtom getTextRuler(){
|
|
||||||
if(_ruler == null){
|
|
||||||
if(_records != null) for (int i = 0; i < _records.length; i++) {
|
|
||||||
if(_records[i] instanceof TextRulerAtom) {
|
|
||||||
_ruler = (TextRulerAtom)_records[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return _ruler;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextRulerAtom createTextRuler(){
|
|
||||||
_ruler = getTextRuler();
|
|
||||||
if(_ruler == null){
|
|
||||||
_ruler = TextRulerAtom.getParagraphInstance();
|
|
||||||
_headerAtom.getParentRecord().appendChildRecord(_ruler);
|
|
||||||
}
|
|
||||||
return _ruler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new string with line breaks converted into internal ppt representation
|
|
||||||
*/
|
|
||||||
public String normalize(String s){
|
|
||||||
String ns = s.replaceAll("\\r?\\n", "\r");
|
|
||||||
return ns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns records that make up this text run
|
|
||||||
*
|
|
||||||
* @return text run records
|
|
||||||
*/
|
|
||||||
public Record[] getRecords(){
|
|
||||||
return _records;
|
|
||||||
}
|
|
||||||
/** Numbered List info */
|
|
||||||
public void setStyleTextProp9Atom(final StyleTextProp9Atom styleTextProp9Atom) {
|
|
||||||
this.styleTextProp9Atom = styleTextProp9Atom;
|
|
||||||
}
|
|
||||||
/** Numbered List info */
|
|
||||||
public StyleTextProp9Atom getStyleTextProp9Atom() {
|
|
||||||
return this.styleTextProp9Atom;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Characters covered */
|
|
||||||
public StyleTextPropAtom getStyleTextPropAtom() {
|
|
||||||
return this._styleAtom;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,639 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
|
||||||
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.font.FontRenderContext;
|
|
||||||
import java.awt.font.TextLayout;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
|
||||||
import org.apache.poi.ddf.EscherOptRecord;
|
|
||||||
import org.apache.poi.ddf.EscherProperties;
|
|
||||||
import org.apache.poi.ddf.EscherSimpleProperty;
|
|
||||||
import org.apache.poi.ddf.EscherSpRecord;
|
|
||||||
import org.apache.poi.ddf.EscherTextboxRecord;
|
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
|
||||||
import org.apache.poi.hslf.record.EscherTextboxWrapper;
|
|
||||||
import org.apache.poi.hslf.record.InteractiveInfo;
|
|
||||||
import org.apache.poi.hslf.record.InteractiveInfoAtom;
|
|
||||||
import org.apache.poi.hslf.record.OEPlaceholderAtom;
|
|
||||||
import org.apache.poi.hslf.record.OutlineTextRefAtom;
|
|
||||||
import org.apache.poi.hslf.record.PPDrawing;
|
|
||||||
import org.apache.poi.hslf.record.Record;
|
|
||||||
import org.apache.poi.hslf.record.RecordTypes;
|
|
||||||
import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
|
|
||||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextBytesAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextCharsAtom;
|
|
||||||
import org.apache.poi.hslf.record.TextHeaderAtom;
|
|
||||||
import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
|
||||||
import org.apache.poi.util.POILogger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A common superclass of all shapes that can hold text.
|
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public abstract class HSLFTextShape extends HSLFSimpleShape {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* How to anchor the text
|
|
||||||
*/
|
|
||||||
public static final int AnchorTop = 0;
|
|
||||||
public static final int AnchorMiddle = 1;
|
|
||||||
public static final int AnchorBottom = 2;
|
|
||||||
public static final int AnchorTopCentered = 3;
|
|
||||||
public static final int AnchorMiddleCentered = 4;
|
|
||||||
public static final int AnchorBottomCentered = 5;
|
|
||||||
public static final int AnchorTopBaseline = 6;
|
|
||||||
public static final int AnchorBottomBaseline = 7;
|
|
||||||
public static final int AnchorTopCenteredBaseline = 8;
|
|
||||||
public static final int AnchorBottomCenteredBaseline = 9;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* How to wrap the text
|
|
||||||
*/
|
|
||||||
public static final int WrapSquare = 0;
|
|
||||||
public static final int WrapByPoints = 1;
|
|
||||||
public static final int WrapNone = 2;
|
|
||||||
public static final int WrapTopBottom = 3;
|
|
||||||
public static final int WrapThrough = 4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* How to align the text
|
|
||||||
*/
|
|
||||||
public static final int AlignLeft = 0;
|
|
||||||
public static final int AlignCenter = 1;
|
|
||||||
public static final int AlignRight = 2;
|
|
||||||
public static final int AlignJustify = 3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TextRun object which holds actual text and format data
|
|
||||||
*/
|
|
||||||
protected HSLFTextParagraph _txtrun;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Escher container which holds text attributes such as
|
|
||||||
* TextHeaderAtom, TextBytesAtom ot TextCharsAtom, StyleTextPropAtom etc.
|
|
||||||
*/
|
|
||||||
protected EscherTextboxWrapper _txtbox;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to calculate text bounds
|
|
||||||
*/
|
|
||||||
protected static final FontRenderContext _frc = new FontRenderContext(null, true, true);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a TextBox object and initialize it from the supplied Record container.
|
|
||||||
*
|
|
||||||
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
|
|
||||||
* @param parent the parent of the shape
|
|
||||||
*/
|
|
||||||
protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
|
|
||||||
super(escherRecord, parent);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new TextBox. This constructor is used when a new shape is created.
|
|
||||||
*
|
|
||||||
* @param parent the parent of this Shape. For example, if this text box is a cell
|
|
||||||
* in a table then the parent is Table.
|
|
||||||
*/
|
|
||||||
public HSLFTextShape(ShapeContainer<HSLFShape> parent){
|
|
||||||
super(null, parent);
|
|
||||||
_escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new TextBox. This constructor is used when a new shape is created.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public HSLFTextShape(){
|
|
||||||
this(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HSLFTextParagraph createTextRun(){
|
|
||||||
_txtbox = getEscherTextboxWrapper();
|
|
||||||
if(_txtbox == null) _txtbox = new EscherTextboxWrapper();
|
|
||||||
|
|
||||||
_txtrun = getTextParagraph();
|
|
||||||
if(_txtrun == null){
|
|
||||||
TextHeaderAtom tha = new TextHeaderAtom();
|
|
||||||
tha.setParentRecord(_txtbox);
|
|
||||||
_txtbox.appendChildRecord(tha);
|
|
||||||
|
|
||||||
TextCharsAtom tca = new TextCharsAtom();
|
|
||||||
_txtbox.appendChildRecord(tca);
|
|
||||||
|
|
||||||
StyleTextPropAtom sta = new StyleTextPropAtom(0);
|
|
||||||
_txtbox.appendChildRecord(sta);
|
|
||||||
|
|
||||||
_txtrun = new HSLFTextParagraph(tha,tca,sta);
|
|
||||||
_txtrun._records = new Record[]{tha, tca, sta};
|
|
||||||
_txtrun.setText("");
|
|
||||||
|
|
||||||
_escherContainer.addChildRecord(_txtbox.getEscherRecord());
|
|
||||||
|
|
||||||
setDefaultTextProperties(_txtrun);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _txtrun;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set default properties for the TextRun.
|
|
||||||
* Depending on the text and shape type the defaults are different:
|
|
||||||
* TextBox: align=left, valign=top
|
|
||||||
* AutoShape: align=center, valign=middle
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected void setDefaultTextProperties(HSLFTextParagraph _txtrun){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the text contained in this text frame.
|
|
||||||
*
|
|
||||||
* @return the text string for this textbox.
|
|
||||||
*/
|
|
||||||
public String getText(){
|
|
||||||
HSLFTextParagraph tx = getTextParagraph();
|
|
||||||
return tx == null ? null : tx.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the text contained in this text frame.
|
|
||||||
*
|
|
||||||
* @param text the text string used by this object.
|
|
||||||
*/
|
|
||||||
public void setText(String text){
|
|
||||||
HSLFTextParagraph tx = getTextParagraph();
|
|
||||||
if(tx == null){
|
|
||||||
tx = createTextRun();
|
|
||||||
}
|
|
||||||
tx.setText(text);
|
|
||||||
setTextId(text.hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When a textbox is added to a sheet we need to tell upper-level
|
|
||||||
* <code>PPDrawing</code> about it.
|
|
||||||
*
|
|
||||||
* @param sh the sheet we are adding to
|
|
||||||
*/
|
|
||||||
protected void afterInsert(HSLFSheet sh){
|
|
||||||
super.afterInsert(sh);
|
|
||||||
|
|
||||||
EscherTextboxWrapper _txtbox = getEscherTextboxWrapper();
|
|
||||||
if(_txtbox != null){
|
|
||||||
PPDrawing ppdrawing = sh.getPPDrawing();
|
|
||||||
ppdrawing.addTextboxWrapper(_txtbox);
|
|
||||||
// Ensure the escher layer knows about the added records
|
|
||||||
try {
|
|
||||||
_txtbox.writeOut(null);
|
|
||||||
} catch (IOException e){
|
|
||||||
throw new HSLFException(e);
|
|
||||||
}
|
|
||||||
if(getAnchor().equals(new Rectangle()) && !"".equals(getText())) resizeToFitText();
|
|
||||||
}
|
|
||||||
if(_txtrun != null) {
|
|
||||||
_txtrun.setShapeId(getShapeId());
|
|
||||||
sh.onAddTextShape(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EscherTextboxWrapper getEscherTextboxWrapper(){
|
|
||||||
if(_txtbox == null){
|
|
||||||
EscherTextboxRecord textRecord = getEscherChild(EscherTextboxRecord.RECORD_ID);
|
|
||||||
if(textRecord != null) _txtbox = new EscherTextboxWrapper(textRecord);
|
|
||||||
}
|
|
||||||
return _txtbox;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Adjust the size of the TextShape so it encompasses the text inside it.
|
|
||||||
*
|
|
||||||
* @return a <code>Rectangle2D</code> that is the bounds of this <code>TextShape</code>.
|
|
||||||
*/
|
|
||||||
public Rectangle2D resizeToFitText(){
|
|
||||||
String txt = getText();
|
|
||||||
if(txt == null || txt.length() == 0) return new Rectangle2D.Float();
|
|
||||||
|
|
||||||
HSLFTextRun rt = getTextParagraph().getRichTextRuns()[0];
|
|
||||||
int size = rt.getFontSize();
|
|
||||||
int style = 0;
|
|
||||||
if (rt.isBold()) style |= Font.BOLD;
|
|
||||||
if (rt.isItalic()) style |= Font.ITALIC;
|
|
||||||
String fntname = rt.getFontName();
|
|
||||||
Font font = new Font(fntname, style, size);
|
|
||||||
|
|
||||||
float width = 0, height = 0, leading = 0;
|
|
||||||
String[] lines = txt.split("\n");
|
|
||||||
for (int i = 0; i < lines.length; i++) {
|
|
||||||
if(lines[i].length() == 0) continue;
|
|
||||||
|
|
||||||
TextLayout layout = new TextLayout(lines[i], font, _frc);
|
|
||||||
|
|
||||||
leading = Math.max(leading, layout.getLeading());
|
|
||||||
width = Math.max(width, layout.getAdvance());
|
|
||||||
height = Math.max(height, (height + (layout.getDescent() + layout.getAscent())));
|
|
||||||
}
|
|
||||||
|
|
||||||
// add one character to width
|
|
||||||
Rectangle2D charBounds = font.getMaxCharBounds(_frc);
|
|
||||||
width += getMarginLeft() + getMarginRight() + charBounds.getWidth();
|
|
||||||
|
|
||||||
// add leading to height
|
|
||||||
height += getMarginTop() + getMarginBottom() + leading;
|
|
||||||
|
|
||||||
Rectangle2D anchor = getAnchor2D();
|
|
||||||
anchor.setRect(anchor.getX(), anchor.getY(), width, height);
|
|
||||||
setAnchor(anchor);
|
|
||||||
|
|
||||||
return anchor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type of vertical alignment for the text.
|
|
||||||
* One of the <code>Anchor*</code> constants defined in this class.
|
|
||||||
*
|
|
||||||
* @return the type of alignment
|
|
||||||
*/
|
|
||||||
public int getVerticalAlignment(){
|
|
||||||
EscherOptRecord opt = getEscherOptRecord();
|
|
||||||
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
|
|
||||||
int valign = HSLFTextShape.AnchorTop;
|
|
||||||
if (prop == null){
|
|
||||||
/**
|
|
||||||
* If vertical alignment was not found in the shape properties then try to
|
|
||||||
* fetch the master shape and search for the align property there.
|
|
||||||
*/
|
|
||||||
int type = getTextParagraph().getRunType();
|
|
||||||
HSLFMasterSheet master = getSheet().getMasterSheet();
|
|
||||||
if(master != null){
|
|
||||||
HSLFTextShape masterShape = master.getPlaceholderByTextType(type);
|
|
||||||
if(masterShape != null) valign = masterShape.getVerticalAlignment();
|
|
||||||
} else {
|
|
||||||
//not found in the master sheet. Use the hardcoded defaults.
|
|
||||||
switch (type){
|
|
||||||
case TextHeaderAtom.TITLE_TYPE:
|
|
||||||
case TextHeaderAtom.CENTER_TITLE_TYPE:
|
|
||||||
valign = HSLFTextShape.AnchorMiddle;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
valign = HSLFTextShape.AnchorTop;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
valign = prop.getPropertyValue();
|
|
||||||
}
|
|
||||||
return valign;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the type of vertical alignment for the text.
|
|
||||||
* One of the <code>Anchor*</code> constants defined in this class.
|
|
||||||
*
|
|
||||||
* @param align - the type of alignment
|
|
||||||
*/
|
|
||||||
public void setVerticalAlignment(int align){
|
|
||||||
setEscherProperty(EscherProperties.TEXT__ANCHORTEXT, align);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the type of horizontal alignment for the text.
|
|
||||||
* One of the <code>Align*</code> constants defined in this class.
|
|
||||||
*
|
|
||||||
* @param align - the type of horizontal alignment
|
|
||||||
*/
|
|
||||||
public void setHorizontalAlignment(int align){
|
|
||||||
HSLFTextParagraph tx = getTextParagraph();
|
|
||||||
if(tx != null) tx.getRichTextRuns()[0].setAlignment(align);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the type of horizontal alignment for the text.
|
|
||||||
* One of the <code>Align*</code> constants defined in this class.
|
|
||||||
*
|
|
||||||
* @return align - the type of horizontal alignment
|
|
||||||
*/
|
|
||||||
public int getHorizontalAlignment(){
|
|
||||||
HSLFTextParagraph tx = getTextParagraph();
|
|
||||||
return tx == null ? -1 : tx.getRichTextRuns()[0].getAlignment();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distance (in points) between the bottom of the text frame
|
|
||||||
* and the bottom of the inscribed rectangle of the shape that contains the text.
|
|
||||||
* Default value is 1/20 inch.
|
|
||||||
*
|
|
||||||
* @return the botom margin
|
|
||||||
*/
|
|
||||||
public float getMarginBottom(){
|
|
||||||
EscherOptRecord opt = getEscherOptRecord();
|
|
||||||
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM);
|
|
||||||
int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
|
|
||||||
return (float)val/EMU_PER_POINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the botom margin.
|
|
||||||
* @see #getMarginBottom()
|
|
||||||
*
|
|
||||||
* @param margin the bottom margin
|
|
||||||
*/
|
|
||||||
public void setMarginBottom(float margin){
|
|
||||||
setEscherProperty(EscherProperties.TEXT__TEXTBOTTOM, (int)(margin*EMU_PER_POINT));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distance (in points) between the left edge of the text frame
|
|
||||||
* and the left edge of the inscribed rectangle of the shape that contains
|
|
||||||
* the text.
|
|
||||||
* Default value is 1/10 inch.
|
|
||||||
*
|
|
||||||
* @return the left margin
|
|
||||||
*/
|
|
||||||
public float getMarginLeft(){
|
|
||||||
EscherOptRecord opt = getEscherOptRecord();
|
|
||||||
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT);
|
|
||||||
int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
|
|
||||||
return (float)val/EMU_PER_POINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the left margin.
|
|
||||||
* @see #getMarginLeft()
|
|
||||||
*
|
|
||||||
* @param margin the left margin
|
|
||||||
*/
|
|
||||||
public void setMarginLeft(float margin){
|
|
||||||
setEscherProperty(EscherProperties.TEXT__TEXTLEFT, (int)(margin*EMU_PER_POINT));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distance (in points) between the right edge of the
|
|
||||||
* text frame and the right edge of the inscribed rectangle of the shape
|
|
||||||
* that contains the text.
|
|
||||||
* Default value is 1/10 inch.
|
|
||||||
*
|
|
||||||
* @return the right margin
|
|
||||||
*/
|
|
||||||
public float getMarginRight(){
|
|
||||||
EscherOptRecord opt = getEscherOptRecord();
|
|
||||||
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTRIGHT);
|
|
||||||
int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue();
|
|
||||||
return (float)val/EMU_PER_POINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the right margin.
|
|
||||||
* @see #getMarginRight()
|
|
||||||
*
|
|
||||||
* @param margin the right margin
|
|
||||||
*/
|
|
||||||
public void setMarginRight(float margin){
|
|
||||||
setEscherProperty(EscherProperties.TEXT__TEXTRIGHT, (int)(margin*EMU_PER_POINT));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distance (in points) between the top of the text frame
|
|
||||||
* and the top of the inscribed rectangle of the shape that contains the text.
|
|
||||||
* Default value is 1/20 inch.
|
|
||||||
*
|
|
||||||
* @return the top margin
|
|
||||||
*/
|
|
||||||
public float getMarginTop(){
|
|
||||||
EscherOptRecord opt = getEscherOptRecord();
|
|
||||||
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTTOP);
|
|
||||||
int val = prop == null ? EMU_PER_INCH/20 : prop.getPropertyValue();
|
|
||||||
return (float)val/EMU_PER_POINT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the top margin.
|
|
||||||
* @see #getMarginTop()
|
|
||||||
*
|
|
||||||
* @param margin the top margin
|
|
||||||
*/
|
|
||||||
public void setMarginTop(float margin){
|
|
||||||
setEscherProperty(EscherProperties.TEXT__TEXTTOP, (int)(margin*EMU_PER_POINT));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the value indicating word wrap.
|
|
||||||
*
|
|
||||||
* @return the value indicating word wrap.
|
|
||||||
* Must be one of the <code>Wrap*</code> constants defined in this class.
|
|
||||||
*/
|
|
||||||
public int getWordWrap(){
|
|
||||||
EscherOptRecord opt = getEscherOptRecord();
|
|
||||||
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
|
|
||||||
return prop == null ? WrapSquare : prop.getPropertyValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies how the text should be wrapped
|
|
||||||
*
|
|
||||||
* @param wrap the value indicating how the text should be wrapped.
|
|
||||||
* Must be one of the <code>Wrap*</code> constants defined in this class.
|
|
||||||
*/
|
|
||||||
public void setWordWrap(int wrap){
|
|
||||||
setEscherProperty(EscherProperties.TEXT__WRAPTEXT, wrap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return id for the text.
|
|
||||||
*/
|
|
||||||
public int getTextId(){
|
|
||||||
EscherOptRecord opt = getEscherOptRecord();
|
|
||||||
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
|
|
||||||
return prop == null ? 0 : prop.getPropertyValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets text ID
|
|
||||||
*
|
|
||||||
* @param id of the text
|
|
||||||
*/
|
|
||||||
public void setTextId(int id){
|
|
||||||
setEscherProperty(EscherProperties.TEXT__TEXTID, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the TextRun object for this text box
|
|
||||||
*/
|
|
||||||
public HSLFTextParagraph getTextParagraph(){
|
|
||||||
if (null == this._txtrun) initTextRun();
|
|
||||||
if (null == this._txtrun && null != this._txtbox) {
|
|
||||||
TextHeaderAtom tha = null;
|
|
||||||
TextBytesAtom tba = null;
|
|
||||||
TextCharsAtom tca = null;
|
|
||||||
StyleTextPropAtom sta = null;
|
|
||||||
Record[] childRecords = this._txtbox.getChildRecords();
|
|
||||||
for (Record r : childRecords) {
|
|
||||||
if (r instanceof TextHeaderAtom) {
|
|
||||||
tha = (TextHeaderAtom) r;
|
|
||||||
} else if (r instanceof TextBytesAtom) {
|
|
||||||
tba = (TextBytesAtom) r;
|
|
||||||
} else if (r instanceof TextCharsAtom) {
|
|
||||||
tca = (TextCharsAtom) r;
|
|
||||||
} else if (r instanceof StyleTextPropAtom) {
|
|
||||||
sta = (StyleTextPropAtom) r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tba != null) {
|
|
||||||
this._txtrun = new HSLFTextParagraph(tha, tba, sta);
|
|
||||||
} else if (tca != null) {
|
|
||||||
this._txtrun = new HSLFTextParagraph(tha, tca, sta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _txtrun;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSheet(HSLFSheet sheet) {
|
|
||||||
_sheet = sheet;
|
|
||||||
|
|
||||||
// Initialize _txtrun object.
|
|
||||||
// (We can't do it in the constructor because the sheet
|
|
||||||
// is not assigned then, it's only built once we have
|
|
||||||
// all the records)
|
|
||||||
HSLFTextParagraph tx = getTextParagraph();
|
|
||||||
if (tx != null) {
|
|
||||||
// Supply the sheet to our child RichTextRuns
|
|
||||||
tx.supplySheet(_sheet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initTextRun(){
|
|
||||||
EscherTextboxWrapper txtbox = getEscherTextboxWrapper();
|
|
||||||
HSLFSheet sheet = getSheet();
|
|
||||||
|
|
||||||
if(sheet == null || txtbox == null) return;
|
|
||||||
|
|
||||||
OutlineTextRefAtom ota = null;
|
|
||||||
|
|
||||||
Record[] child = txtbox.getChildRecords();
|
|
||||||
for (int i = 0; i < child.length; i++) {
|
|
||||||
if (child[i] instanceof OutlineTextRefAtom) {
|
|
||||||
ota = (OutlineTextRefAtom)child[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HSLFTextParagraph[] runs = _sheet.getTextRuns();
|
|
||||||
if (ota != null) {
|
|
||||||
int idx = ota.getTextIndex();
|
|
||||||
for (int i = 0; i < runs.length; i++) {
|
|
||||||
if(runs[i].getIndex() == idx){
|
|
||||||
_txtrun = runs[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(_txtrun == null) {
|
|
||||||
logger.log(POILogger.WARN, "text run not found for OutlineTextRefAtom.TextIndex=" + idx);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
EscherSpRecord escherSpRecord = getEscherChild(EscherSpRecord.RECORD_ID);
|
|
||||||
int shapeId = escherSpRecord.getShapeId();
|
|
||||||
if(runs != null) for (int i = 0; i < runs.length; i++) {
|
|
||||||
if(runs[i].getShapeId() == shapeId){
|
|
||||||
_txtrun = runs[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure the same references child records of TextRun
|
|
||||||
if(_txtrun != null) {
|
|
||||||
for (int i = 0; i < child.length; i++) {
|
|
||||||
for (Record r : _txtrun.getRecords()) {
|
|
||||||
if (child[i].getRecordType() == r.getRecordType()) {
|
|
||||||
child[i] = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(Graphics2D graphics){
|
|
||||||
AffineTransform at = graphics.getTransform();
|
|
||||||
ShapePainter.paint(this, graphics);
|
|
||||||
new TextPainter(this).paint(graphics);
|
|
||||||
graphics.setTransform(at);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return <code>OEPlaceholderAtom</code>, the atom that describes a placeholder.
|
|
||||||
*
|
|
||||||
* @return <code>OEPlaceholderAtom</code> or <code>null</code> if not found
|
|
||||||
*/
|
|
||||||
public OEPlaceholderAtom getPlaceholderAtom(){
|
|
||||||
return getClientDataRecord(RecordTypes.OEPlaceholderAtom.typeID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Assigns a hyperlink to this text shape
|
|
||||||
*
|
|
||||||
* @param linkId id of the hyperlink, @see org.apache.poi.hslf.usermodel.SlideShow#addHyperlink(Hyperlink)
|
|
||||||
* @param beginIndex the beginning index, inclusive.
|
|
||||||
* @param endIndex the ending index, exclusive.
|
|
||||||
* @see org.apache.poi.hslf.usermodel.HSLFSlideShow#addHyperlink(Hyperlink)
|
|
||||||
*/
|
|
||||||
public void setHyperlink(int linkId, int beginIndex, int endIndex){
|
|
||||||
//TODO validate beginIndex and endIndex and throw IllegalArgumentException
|
|
||||||
|
|
||||||
InteractiveInfo info = new InteractiveInfo();
|
|
||||||
InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
|
|
||||||
infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);
|
|
||||||
infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);
|
|
||||||
infoAtom.setHyperlinkID(linkId);
|
|
||||||
|
|
||||||
_txtbox.appendChildRecord(info);
|
|
||||||
|
|
||||||
TxInteractiveInfoAtom txiatom = new TxInteractiveInfoAtom();
|
|
||||||
txiatom.setStartIndex(beginIndex);
|
|
||||||
txiatom.setEndIndex(endIndex);
|
|
||||||
_txtbox.appendChildRecord(txiatom);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPlaceholder() {
|
|
||||||
OEPlaceholderAtom oep = getPlaceholderAtom();
|
|
||||||
if (oep != null) return true;
|
|
||||||
|
|
||||||
//special case for files saved in Office 2007
|
|
||||||
RoundTripHFPlaceholder12 hldr = getClientDataRecord(RecordTypes.RoundTripHFPlaceholder12.typeID);
|
|
||||||
if (hldr != null) return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -18,7 +18,7 @@
|
|||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import org.apache.poi.hslf.record.*;
|
import org.apache.poi.hslf.record.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Header / Footer settings.
|
* Header / Footer settings.
|
||||||
@ -240,7 +240,7 @@ public final class HeadersFooters {
|
|||||||
private boolean isVisible(int flag, int placeholderId){
|
private boolean isVisible(int flag, int placeholderId){
|
||||||
boolean visible;
|
boolean visible;
|
||||||
if(_ppt2007){
|
if(_ppt2007){
|
||||||
HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
|
HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlideMasters().get(0);
|
||||||
HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
|
HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
|
||||||
visible = placeholder != null && placeholder.getText() != null;
|
visible = placeholder != null && placeholder.getText() != null;
|
||||||
} else {
|
} else {
|
||||||
@ -252,7 +252,7 @@ public final class HeadersFooters {
|
|||||||
private String getPlaceholderText(int placeholderId, CString cs){
|
private String getPlaceholderText(int placeholderId, CString cs){
|
||||||
String text = null;
|
String text = null;
|
||||||
if(_ppt2007){
|
if(_ppt2007){
|
||||||
HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlidesMasters()[0];
|
HSLFSheet master = _sheet != null ? _sheet : _ppt.getSlideMasters().get(0);
|
||||||
HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
|
HSLFTextShape placeholder = master.getPlaceholder(placeholderId);
|
||||||
if(placeholder != null) text = placeholder.getText();
|
if(placeholder != null) text = placeholder.getText();
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
import org.apache.poi.sl.usermodel.ShapeType;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ import java.awt.geom.Line2D;
|
|||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public final class Line extends HSLFSimpleShape {
|
public final class Line extends HSLFSimpleShape {
|
||||||
protected Line(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
|
public Line(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
|
||||||
super(escherRecord, parent);
|
super(escherRecord, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import org.apache.poi.ddf.EscherContainerRecord;
|
|||||||
import org.apache.poi.ddf.EscherProperties;
|
import org.apache.poi.ddf.EscherProperties;
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
import org.apache.poi.hslf.record.*;
|
import org.apache.poi.hslf.record.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,7 +67,7 @@ public final class MovieShape extends HSLFPictureShape {
|
|||||||
* this picture in the <code>Slide</code>
|
* this picture in the <code>Slide</code>
|
||||||
* @param parent the parent shape of this picture
|
* @param parent the parent shape of this picture
|
||||||
*/
|
*/
|
||||||
protected MovieShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
|
public MovieShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
|
||||||
super(escherRecord, parent);
|
super(escherRecord, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFObjectData;
|
|
||||||
import org.apache.poi.hslf.record.ExObjList;
|
import org.apache.poi.hslf.record.ExObjList;
|
||||||
import org.apache.poi.hslf.record.Record;
|
import org.apache.poi.hslf.record.Record;
|
||||||
import org.apache.poi.hslf.record.ExEmbed;
|
import org.apache.poi.hslf.record.ExEmbed;
|
||||||
@ -63,7 +62,7 @@ public final class OLEShape extends HSLFPictureShape {
|
|||||||
* this picture in the <code>Slide</code>
|
* this picture in the <code>Slide</code>
|
||||||
* @param parent the parent shape of this picture
|
* @param parent the parent shape of this picture
|
||||||
*/
|
*/
|
||||||
protected OLEShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
|
public OLEShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
|
||||||
super(escherRecord, parent);
|
super(escherRecord, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,19 +19,20 @@ package org.apache.poi.hslf.model;
|
|||||||
|
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.Shape;
|
import java.awt.font.*;
|
||||||
import java.awt.font.FontRenderContext;
|
import java.awt.geom.*;
|
||||||
import java.awt.font.GlyphVector;
|
|
||||||
import java.awt.font.TextLayout;
|
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
import java.awt.image.renderable.RenderableImage;
|
import java.awt.image.renderable.RenderableImage;
|
||||||
import java.awt.geom.*;
|
|
||||||
import java.text.AttributedCharacterIterator;
|
import java.text.AttributedCharacterIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
|
import org.apache.poi.sl.usermodel.StrokeStyle;
|
||||||
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
||||||
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates Graphics2D calls into PowerPoint.
|
* Translates Graphics2D calls into PowerPoint.
|
||||||
@ -251,10 +252,10 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
|
|||||||
*/
|
*/
|
||||||
public void drawString(String s, float x, float y) {
|
public void drawString(String s, float x, float y) {
|
||||||
HSLFTextBox txt = new HSLFTextBox(_group);
|
HSLFTextBox txt = new HSLFTextBox(_group);
|
||||||
txt.getTextParagraph().supplySheet(_group.getSheet());
|
txt.getTextParagraphs().get(0).supplySheet(_group.getSheet());
|
||||||
txt.setText(s);
|
txt.setText(s);
|
||||||
|
|
||||||
HSLFTextRun rt = txt.getTextParagraph().getRichTextRuns()[0];
|
HSLFTextRun rt = txt.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
rt.setFontSize(_font.getSize());
|
rt.setFontSize(_font.getSize());
|
||||||
rt.setFontName(_font.getFamily());
|
rt.setFontName(_font.getFamily());
|
||||||
|
|
||||||
@ -262,13 +263,13 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
|
|||||||
if (_font.isBold()) rt.setBold(true);
|
if (_font.isBold()) rt.setBold(true);
|
||||||
if (_font.isItalic()) rt.setItalic(true);
|
if (_font.isItalic()) rt.setItalic(true);
|
||||||
|
|
||||||
txt.setMarginBottom(0);
|
txt.setBottomInset(0);
|
||||||
txt.setMarginTop(0);
|
txt.setTopInset(0);
|
||||||
txt.setMarginLeft(0);
|
txt.setLeftInset(0);
|
||||||
txt.setMarginRight(0);
|
txt.setRightInset(0);
|
||||||
txt.setWordWrap(HSLFTextBox.WrapNone);
|
txt.setWordWrap(HSLFTextBox.WrapNone);
|
||||||
txt.setHorizontalAlignment(HSLFTextBox.AlignLeft);
|
txt.setHorizontalCentered(false);
|
||||||
txt.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
|
txt.setVerticalAlignment(VerticalAlignment.MIDDLE);
|
||||||
|
|
||||||
|
|
||||||
TextLayout layout = new TextLayout(s, _font, getFontRenderContext());
|
TextLayout layout = new TextLayout(s, _font, getFontRenderContext());
|
||||||
@ -1794,7 +1795,7 @@ public final class PPGraphics2D extends Graphics2D implements Cloneable {
|
|||||||
float[] dash = bs.getDashArray();
|
float[] dash = bs.getDashArray();
|
||||||
if (dash != null) {
|
if (dash != null) {
|
||||||
//TODO: implement more dashing styles
|
//TODO: implement more dashing styles
|
||||||
shape.setLineDashing(Line.PEN_DASH);
|
shape.setLineDashing(StrokeStyle.LineDash.DASH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ package org.apache.poi.hslf.model;
|
|||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.*;
|
||||||
import org.apache.poi.hslf.record.OEPlaceholderAtom;
|
import org.apache.poi.hslf.record.OEPlaceholderAtom;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFShape;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFTextBox;
|
||||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
import org.apache.poi.sl.usermodel.ShapeType;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Date: Apr 17, 2008
|
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public interface ShapeOutline {
|
|
||||||
java.awt.Shape getOutline(HSLFShape shape);
|
|
||||||
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Stroke;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
|
|
||||||
import org.apache.poi.util.POILogFactory;
|
|
||||||
import org.apache.poi.util.POILogger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Paint a shape into java.awt.Graphics2D
|
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public final class ShapePainter {
|
|
||||||
protected static final POILogger logger = POILogFactory.getLogger(ShapePainter.class);
|
|
||||||
|
|
||||||
public static void paint(HSLFSimpleShape shape, Graphics2D graphics){
|
|
||||||
Rectangle2D anchor = shape.getLogicalAnchor2D();
|
|
||||||
java.awt.Shape outline = shape.getOutline();
|
|
||||||
|
|
||||||
//flip vertical
|
|
||||||
if(shape.getFlipVertical()){
|
|
||||||
graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
|
|
||||||
graphics.scale(1, -1);
|
|
||||||
graphics.translate(-anchor.getX(), -anchor.getY());
|
|
||||||
}
|
|
||||||
//flip horizontal
|
|
||||||
if(shape.getFlipHorizontal()){
|
|
||||||
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
|
|
||||||
graphics.scale(-1, 1);
|
|
||||||
graphics.translate(-anchor.getX() , -anchor.getY());
|
|
||||||
}
|
|
||||||
|
|
||||||
//rotate transform
|
|
||||||
double angle = shape.getRotation();
|
|
||||||
|
|
||||||
if(angle != 0){
|
|
||||||
double centerX = anchor.getX() + anchor.getWidth()/2;
|
|
||||||
double centerY = anchor.getY() + anchor.getHeight()/2;
|
|
||||||
|
|
||||||
graphics.translate(centerX, centerY);
|
|
||||||
graphics.rotate(Math.toRadians(angle));
|
|
||||||
graphics.translate(-centerX, -centerY);
|
|
||||||
}
|
|
||||||
|
|
||||||
//fill
|
|
||||||
Color fillColor = shape.getFill().getForegroundColor();
|
|
||||||
if (fillColor != null) {
|
|
||||||
//TODO: implement gradient and texture fill patterns
|
|
||||||
graphics.setPaint(fillColor);
|
|
||||||
graphics.fill(outline);
|
|
||||||
}
|
|
||||||
|
|
||||||
//border
|
|
||||||
Color lineColor = shape.getLineColor();
|
|
||||||
if (lineColor != null){
|
|
||||||
graphics.setPaint(lineColor);
|
|
||||||
float width = (float)shape.getLineWidth();
|
|
||||||
|
|
||||||
int dashing = shape.getLineDashing();
|
|
||||||
//TODO: implement more dashing styles
|
|
||||||
float[] dashptrn = null;
|
|
||||||
switch(dashing){
|
|
||||||
case Line.PEN_SOLID:
|
|
||||||
dashptrn = null;
|
|
||||||
break;
|
|
||||||
case Line.PEN_PS_DASH:
|
|
||||||
dashptrn = new float[]{width, width};
|
|
||||||
break;
|
|
||||||
case Line.PEN_DOTGEL:
|
|
||||||
dashptrn = new float[]{width*4, width*3};
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
logger.log(POILogger.WARN, "unsupported dashing: " + dashing);
|
|
||||||
dashptrn = new float[]{width, width};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Stroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashptrn, 0.0f);
|
|
||||||
graphics.setStroke(stroke);
|
|
||||||
graphics.draw(outline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,6 +18,7 @@
|
|||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.model;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.*;
|
||||||
|
import org.apache.poi.hslf.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
@ -319,9 +320,9 @@ public final class Table extends HSLFGroupShape {
|
|||||||
private Line cloneBorder(Line line){
|
private Line cloneBorder(Line line){
|
||||||
Line border = createBorder();
|
Line border = createBorder();
|
||||||
border.setLineWidth(line.getLineWidth());
|
border.setLineWidth(line.getLineWidth());
|
||||||
border.setLineStyle(line.getStrokeStyle());
|
|
||||||
border.setLineDashing(line.getLineDashing());
|
border.setLineDashing(line.getLineDashing());
|
||||||
border.setLineColor(line.getLineColor());
|
border.setLineColor(line.getLineColor());
|
||||||
|
border.setLineCompound(line.getLineCompound());
|
||||||
return border;
|
return border;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ import java.awt.Rectangle;
|
|||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
import org.apache.poi.ddf.EscherOptRecord;
|
import org.apache.poi.ddf.EscherOptRecord;
|
||||||
import org.apache.poi.ddf.EscherProperties;
|
import org.apache.poi.ddf.EscherProperties;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFShape;
|
||||||
|
import org.apache.poi.hslf.usermodel.HSLFTextBox;
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
import org.apache.poi.sl.usermodel.ShapeType;
|
||||||
|
|
||||||
|
@ -1,418 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.RenderingHints;
|
|
||||||
import java.awt.font.FontRenderContext;
|
|
||||||
import java.awt.font.LineBreakMeasurer;
|
|
||||||
import java.awt.font.TextAttribute;
|
|
||||||
import java.awt.font.TextLayout;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.text.AttributedCharacterIterator;
|
|
||||||
import java.text.AttributedString;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.poi.hslf.record.TextRulerAtom;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFTextRun;
|
|
||||||
import org.apache.poi.util.POILogFactory;
|
|
||||||
import org.apache.poi.util.POILogger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Paint text into java.awt.Graphics2D
|
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
|
||||||
public final class TextPainter {
|
|
||||||
public static final Key KEY_FONTFALLBACK = new Key(50, "Font fallback map");
|
|
||||||
public static final Key KEY_FONTMAP = new Key(51, "Font map");
|
|
||||||
|
|
||||||
protected POILogger logger = POILogFactory.getLogger(this.getClass());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display unicode square if a bullet char can't be displayed,
|
|
||||||
* for example, if Wingdings font is used.
|
|
||||||
* TODO: map Wingdngs and Symbol to unicode Arial
|
|
||||||
*/
|
|
||||||
protected static final char DEFAULT_BULLET_CHAR = '\u25a0';
|
|
||||||
|
|
||||||
protected HSLFTextShape _shape;
|
|
||||||
|
|
||||||
public TextPainter(HSLFTextShape shape){
|
|
||||||
_shape = shape;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AttributedString getAttributedString(HSLFTextParagraph txrun) {
|
|
||||||
return getAttributedString(txrun, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the underlying set of rich text runs into java.text.AttributedString
|
|
||||||
*/
|
|
||||||
public AttributedString getAttributedString(HSLFTextParagraph txrun, Graphics2D graphics){
|
|
||||||
String text = txrun.getText();
|
|
||||||
//TODO: properly process tabs
|
|
||||||
text = text.replace('\t', ' ');
|
|
||||||
text = text.replace((char)160, ' ');
|
|
||||||
|
|
||||||
AttributedString at = new AttributedString(text);
|
|
||||||
HSLFTextRun[] rt = txrun.getRichTextRuns();
|
|
||||||
for (int i = 0; i < rt.length; i++) {
|
|
||||||
int start = rt[i].getStartIndex();
|
|
||||||
int end = rt[i].getEndIndex();
|
|
||||||
if(start == end) {
|
|
||||||
logger.log(POILogger.INFO, "Skipping RichTextRun with zero length");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String mappedFont = rt[i].getFontName();
|
|
||||||
String fallbackFont = Font.SANS_SERIF;
|
|
||||||
if (graphics != null) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(KEY_FONTMAP);
|
|
||||||
if (fontMap != null && fontMap.containsKey(mappedFont)) {
|
|
||||||
mappedFont = fontMap.get(mappedFont);
|
|
||||||
}
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String,String> fallbackMap = (Map<String,String>)graphics.getRenderingHint(KEY_FONTFALLBACK);
|
|
||||||
if (fallbackMap != null && fallbackMap.containsKey(mappedFont)) {
|
|
||||||
fallbackFont = fallbackMap.get(mappedFont);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
at.addAttribute(TextAttribute.FAMILY, mappedFont, start, end);
|
|
||||||
at.addAttribute(TextAttribute.SIZE, new Float(rt[i].getFontSize()), start, end);
|
|
||||||
at.addAttribute(TextAttribute.FOREGROUND, rt[i].getFontColor(), start, end);
|
|
||||||
if(rt[i].isBold()) at.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, start, end);
|
|
||||||
if(rt[i].isItalic()) at.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, start, end);
|
|
||||||
if(rt[i].isUnderlined()) {
|
|
||||||
at.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, start, end);
|
|
||||||
at.addAttribute(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_TWO_PIXEL, start, end);
|
|
||||||
}
|
|
||||||
if(rt[i].isStrikethrough()) at.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, start, end);
|
|
||||||
int superScript = rt[i].getSuperscript();
|
|
||||||
if(superScript != 0) at.addAttribute(TextAttribute.SUPERSCRIPT, superScript > 0 ? TextAttribute.SUPERSCRIPT_SUPER : TextAttribute.SUPERSCRIPT_SUB, start, end);
|
|
||||||
|
|
||||||
|
|
||||||
int style = (rt[i].isBold() ? Font.BOLD : 0) | (rt[i].isItalic() ? Font.ITALIC : 0);
|
|
||||||
Font f = new Font(mappedFont, style, rt[i].getFontSize());
|
|
||||||
|
|
||||||
// check for unsupported characters and add a fallback font for these
|
|
||||||
char textChr[] = text.toCharArray();
|
|
||||||
int nextEnd = f.canDisplayUpTo(textChr, start, end);
|
|
||||||
boolean isNextValid = nextEnd == start;
|
|
||||||
for (int last = start; nextEnd != -1 && nextEnd <= end; ) {
|
|
||||||
if (isNextValid) {
|
|
||||||
nextEnd = f.canDisplayUpTo(textChr, nextEnd, end);
|
|
||||||
isNextValid = false;
|
|
||||||
} else {
|
|
||||||
if (nextEnd >= end || f.canDisplay(Character.codePointAt(textChr, nextEnd, end)) ) {
|
|
||||||
at.addAttribute(TextAttribute.FAMILY, fallbackFont, last, Math.min(nextEnd,end));
|
|
||||||
if (nextEnd >= end) break;
|
|
||||||
last = nextEnd;
|
|
||||||
isNextValid = true;
|
|
||||||
} else {
|
|
||||||
boolean isHS = Character.isHighSurrogate(textChr[nextEnd]);
|
|
||||||
nextEnd+=(isHS?2:1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return at;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void paint(Graphics2D graphics){
|
|
||||||
AffineTransform tx = graphics.getTransform();
|
|
||||||
|
|
||||||
Rectangle2D anchor = _shape.getLogicalAnchor2D();
|
|
||||||
TextElement[] elem = getTextElements((float)anchor.getWidth(), graphics.getFontRenderContext(), graphics);
|
|
||||||
if(elem == null) return;
|
|
||||||
|
|
||||||
float textHeight = 0;
|
|
||||||
for (int i = 0; i < elem.length; i++) {
|
|
||||||
textHeight += elem[i].ascent + elem[i].descent;
|
|
||||||
}
|
|
||||||
|
|
||||||
int valign = _shape.getVerticalAlignment();
|
|
||||||
double y0 = anchor.getY();
|
|
||||||
switch (valign){
|
|
||||||
case HSLFTextShape.AnchorTopBaseline:
|
|
||||||
case HSLFTextShape.AnchorTop:
|
|
||||||
y0 += _shape.getMarginTop();
|
|
||||||
break;
|
|
||||||
case HSLFTextShape.AnchorBottom:
|
|
||||||
y0 += anchor.getHeight() - textHeight - _shape.getMarginBottom();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case HSLFTextShape.AnchorMiddle:
|
|
||||||
float delta = (float)anchor.getHeight() - textHeight - _shape.getMarginTop() - _shape.getMarginBottom();
|
|
||||||
y0 += _shape.getMarginTop() + delta/2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Transform of text in flipped shapes is special.
|
|
||||||
// At this point the flip and rotation transform is already applied
|
|
||||||
// (see XSLFShape#applyTransform ), but we need to restore it to avoid painting "upside down".
|
|
||||||
// See Bugzilla 54210.
|
|
||||||
if(_shape.getFlipVertical()){
|
|
||||||
graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
|
|
||||||
graphics.scale(1, -1);
|
|
||||||
graphics.translate(-anchor.getX(), -anchor.getY());
|
|
||||||
|
|
||||||
// text in vertically flipped shapes is rotated by 180 degrees
|
|
||||||
double centerX = anchor.getX() + anchor.getWidth()/2;
|
|
||||||
double centerY = anchor.getY() + anchor.getHeight()/2;
|
|
||||||
graphics.translate(centerX, centerY);
|
|
||||||
graphics.rotate(Math.toRadians(180));
|
|
||||||
graphics.translate(-centerX, -centerY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Horizontal flipping applies only to shape outline and not to the text in the shape.
|
|
||||||
// Applying flip second time restores the original not-flipped transform
|
|
||||||
if(_shape.getFlipHorizontal()){
|
|
||||||
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
|
|
||||||
graphics.scale(-1, 1);
|
|
||||||
graphics.translate(-anchor.getX() , -anchor.getY());
|
|
||||||
}
|
|
||||||
|
|
||||||
//finally draw the text fragments
|
|
||||||
for (int i = 0; i < elem.length; i++) {
|
|
||||||
y0 += elem[i].ascent;
|
|
||||||
|
|
||||||
Point2D.Double pen = new Point2D.Double();
|
|
||||||
pen.y = y0;
|
|
||||||
switch (elem[i]._align) {
|
|
||||||
default:
|
|
||||||
case HSLFTextShape.AlignLeft:
|
|
||||||
pen.x = anchor.getX() + _shape.getMarginLeft();
|
|
||||||
break;
|
|
||||||
case HSLFTextShape.AlignCenter:
|
|
||||||
pen.x = anchor.getX() + _shape.getMarginLeft() +
|
|
||||||
(anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight()) / 2;
|
|
||||||
break;
|
|
||||||
case HSLFTextShape.AlignRight:
|
|
||||||
pen.x = anchor.getX() + _shape.getMarginLeft() +
|
|
||||||
(anchor.getWidth() - elem[i].advance - _shape.getMarginLeft() - _shape.getMarginRight());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(elem[i]._bullet != null){
|
|
||||||
graphics.drawString(elem[i]._bullet.getIterator(), (float)(pen.x + elem[i]._bulletOffset), (float)pen.y);
|
|
||||||
}
|
|
||||||
AttributedCharacterIterator chIt = elem[i]._text.getIterator();
|
|
||||||
if(chIt.getEndIndex() > chIt.getBeginIndex()) {
|
|
||||||
graphics.drawString(chIt, (float)(pen.x + elem[i]._textOffset), (float)pen.y);
|
|
||||||
}
|
|
||||||
y0 += elem[i].descent;
|
|
||||||
}
|
|
||||||
|
|
||||||
graphics.setTransform(tx);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextElement[] getTextElements(float textWidth, FontRenderContext frc){
|
|
||||||
return getTextElements(textWidth, frc, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextElement[] getTextElements(float textWidth, FontRenderContext frc, Graphics2D graphics){
|
|
||||||
HSLFTextParagraph run = _shape.getTextParagraph();
|
|
||||||
if (run == null) return null;
|
|
||||||
|
|
||||||
String text = run.getText();
|
|
||||||
if (text == null || text.equals("")) return null;
|
|
||||||
|
|
||||||
AttributedString at = getAttributedString(run, graphics);
|
|
||||||
|
|
||||||
AttributedCharacterIterator it = at.getIterator();
|
|
||||||
int paragraphStart = it.getBeginIndex();
|
|
||||||
int paragraphEnd = it.getEndIndex();
|
|
||||||
|
|
||||||
List<TextElement> lines = new ArrayList<TextElement>();
|
|
||||||
LineBreakMeasurer measurer = new LineBreakMeasurer(it, frc);
|
|
||||||
measurer.setPosition(paragraphStart);
|
|
||||||
while (measurer.getPosition() < paragraphEnd) {
|
|
||||||
int startIndex = measurer.getPosition();
|
|
||||||
int nextBreak = text.indexOf('\n', measurer.getPosition() + 1);
|
|
||||||
|
|
||||||
boolean prStart = text.charAt(startIndex) == '\n';
|
|
||||||
if(prStart) measurer.setPosition(startIndex++);
|
|
||||||
|
|
||||||
HSLFTextRun rt = run.getRichTextRunAt(startIndex == text.length() ? (startIndex-1) : startIndex);
|
|
||||||
if(rt == null) {
|
|
||||||
logger.log(POILogger.WARN, "RichTextRun not found at pos" + startIndex + "; text.length: " + text.length());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
float wrappingWidth = textWidth - _shape.getMarginLeft() - _shape.getMarginRight();
|
|
||||||
int bulletOffset = rt.getBulletOffset();
|
|
||||||
int textOffset = rt.getTextOffset();
|
|
||||||
int indent = rt.getIndentLevel();
|
|
||||||
|
|
||||||
TextRulerAtom ruler = run.getTextRuler();
|
|
||||||
if(ruler != null) {
|
|
||||||
int bullet_val = ruler.getBulletOffsets()[indent]*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
|
|
||||||
int text_val = ruler.getTextOffsets()[indent]*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
|
|
||||||
if(bullet_val > text_val){
|
|
||||||
int a = bullet_val;
|
|
||||||
bullet_val = text_val;
|
|
||||||
text_val = a;
|
|
||||||
}
|
|
||||||
if(bullet_val != 0 ) bulletOffset = bullet_val;
|
|
||||||
if(text_val != 0) textOffset = text_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bulletOffset > 0 || prStart || startIndex == 0) wrappingWidth -= textOffset;
|
|
||||||
|
|
||||||
if (_shape.getWordWrap() == HSLFTextShape.WrapNone) {
|
|
||||||
wrappingWidth = _shape.getSheet().getSlideShow().getPageSize().width;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextLayout textLayout = measurer.nextLayout(wrappingWidth + 1,
|
|
||||||
nextBreak == -1 ? paragraphEnd : nextBreak, true);
|
|
||||||
if (textLayout == null) {
|
|
||||||
textLayout = measurer.nextLayout(textWidth,
|
|
||||||
nextBreak == -1 ? paragraphEnd : nextBreak, false);
|
|
||||||
}
|
|
||||||
if(textLayout == null){
|
|
||||||
logger.log(POILogger.WARN, "Failed to break text into lines: wrappingWidth: "+wrappingWidth+
|
|
||||||
"; text: " + rt.getText());
|
|
||||||
measurer.setPosition(rt.getEndIndex());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int endIndex = measurer.getPosition();
|
|
||||||
|
|
||||||
float lineHeight = (float)textLayout.getBounds().getHeight();
|
|
||||||
int linespacing = rt.getLineSpacing();
|
|
||||||
if(linespacing == 0) linespacing = 100;
|
|
||||||
|
|
||||||
TextElement el = new TextElement();
|
|
||||||
if(linespacing >= 0){
|
|
||||||
el.ascent = textLayout.getAscent()*linespacing/100;
|
|
||||||
} else {
|
|
||||||
el.ascent = -linespacing*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
|
|
||||||
}
|
|
||||||
|
|
||||||
el._align = rt.getAlignment();
|
|
||||||
el.advance = textLayout.getAdvance();
|
|
||||||
el._textOffset = textOffset;
|
|
||||||
el._text = new AttributedString(it, startIndex, endIndex);
|
|
||||||
el.textStartIndex = startIndex;
|
|
||||||
el.textEndIndex = endIndex;
|
|
||||||
|
|
||||||
if (prStart){
|
|
||||||
int sp = rt.getSpaceBefore();
|
|
||||||
float spaceBefore;
|
|
||||||
if(sp >= 0){
|
|
||||||
spaceBefore = lineHeight * sp/100;
|
|
||||||
} else {
|
|
||||||
spaceBefore = -sp*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
|
|
||||||
}
|
|
||||||
el.ascent += spaceBefore;
|
|
||||||
}
|
|
||||||
|
|
||||||
float descent;
|
|
||||||
if(linespacing >= 0){
|
|
||||||
descent = (textLayout.getDescent() + textLayout.getLeading())*linespacing/100;
|
|
||||||
} else {
|
|
||||||
descent = -linespacing*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
|
|
||||||
}
|
|
||||||
if (prStart){
|
|
||||||
int sp = rt.getSpaceAfter();
|
|
||||||
float spaceAfter;
|
|
||||||
if(sp >= 0){
|
|
||||||
spaceAfter = lineHeight * sp/100;
|
|
||||||
} else {
|
|
||||||
spaceAfter = -sp*HSLFShape.POINT_DPI/HSLFShape.MASTER_DPI;
|
|
||||||
}
|
|
||||||
el.ascent += spaceAfter;
|
|
||||||
}
|
|
||||||
el.descent = descent;
|
|
||||||
|
|
||||||
if(rt.isBullet() && (prStart || startIndex == 0)){
|
|
||||||
it.setIndex(startIndex);
|
|
||||||
|
|
||||||
AttributedString bat = new AttributedString(Character.toString(rt.getBulletChar()));
|
|
||||||
Color clr = rt.getBulletColor();
|
|
||||||
if (clr != null) bat.addAttribute(TextAttribute.FOREGROUND, clr);
|
|
||||||
else bat.addAttribute(TextAttribute.FOREGROUND, it.getAttribute(TextAttribute.FOREGROUND));
|
|
||||||
|
|
||||||
int fontIdx = rt.getBulletFont();
|
|
||||||
if(fontIdx == -1) fontIdx = rt.getFontIndex();
|
|
||||||
PPFont bulletFont = _shape.getSheet().getSlideShow().getFont(fontIdx);
|
|
||||||
bat.addAttribute(TextAttribute.FAMILY, bulletFont.getFontName());
|
|
||||||
|
|
||||||
int bulletSize = rt.getBulletSize();
|
|
||||||
int fontSize = rt.getFontSize();
|
|
||||||
if(bulletSize != -1) fontSize = Math.round(fontSize*bulletSize*0.01f);
|
|
||||||
bat.addAttribute(TextAttribute.SIZE, new Float(fontSize));
|
|
||||||
|
|
||||||
if(!new Font(bulletFont.getFontName(), Font.PLAIN, 1).canDisplay(rt.getBulletChar())){
|
|
||||||
bat.addAttribute(TextAttribute.FAMILY, "Arial");
|
|
||||||
bat = new AttributedString("" + DEFAULT_BULLET_CHAR, bat.getIterator().getAttributes());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(text.substring(startIndex, endIndex).length() > 1){
|
|
||||||
el._bullet = bat;
|
|
||||||
el._bulletOffset = bulletOffset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lines.add(el);
|
|
||||||
}
|
|
||||||
|
|
||||||
//finally draw the text fragments
|
|
||||||
TextElement[] elems = new TextElement[lines.size()];
|
|
||||||
return lines.toArray(elems);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TextElement {
|
|
||||||
public AttributedString _text;
|
|
||||||
public int _textOffset;
|
|
||||||
public AttributedString _bullet;
|
|
||||||
public int _bulletOffset;
|
|
||||||
public int _align;
|
|
||||||
public float ascent, descent;
|
|
||||||
public float advance;
|
|
||||||
public int textStartIndex, textEndIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Key extends RenderingHints.Key {
|
|
||||||
String description;
|
|
||||||
|
|
||||||
public Key(int paramInt, String paramString) {
|
|
||||||
super(paramInt);
|
|
||||||
this.description = paramString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int getIndex() {
|
|
||||||
return intKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String toString() {
|
|
||||||
return this.description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCompatibleValue(Object paramObject) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,7 @@ package org.apache.poi.hslf.model.textproperties;
|
|||||||
* of the property is itself a mask, encoding several different
|
* of the property is itself a mask, encoding several different
|
||||||
* (but related) properties
|
* (but related) properties
|
||||||
*/
|
*/
|
||||||
public class BitMaskTextProp extends TextProp implements Cloneable {
|
public abstract class BitMaskTextProp extends TextProp implements Cloneable {
|
||||||
private String[] subPropNames;
|
private String[] subPropNames;
|
||||||
private int[] subPropMasks;
|
private int[] subPropMasks;
|
||||||
private boolean[] subPropMatches;
|
private boolean[] subPropMatches;
|
||||||
@ -91,7 +91,8 @@ public class BitMaskTextProp extends TextProp implements Cloneable {
|
|||||||
subPropMatches[idx] = value;
|
subPropMatches[idx] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone(){
|
@Override
|
||||||
|
public BitMaskTextProp clone(){
|
||||||
BitMaskTextProp newObj = (BitMaskTextProp)super.clone();
|
BitMaskTextProp newObj = (BitMaskTextProp)super.clone();
|
||||||
|
|
||||||
// Don't carry over matches, but keep everything
|
// Don't carry over matches, but keep everything
|
||||||
|
@ -41,7 +41,7 @@ public class IndentProp {
|
|||||||
public int getCharactersCovered() { return charactersCovered; }
|
public int getCharactersCovered() { return charactersCovered; }
|
||||||
|
|
||||||
public int getIndentLevel() {
|
public int getIndentLevel() {
|
||||||
return (int)indentLevel;
|
return indentLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,113 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.hslf.model.textproperties;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
import org.apache.poi.util.LittleEndianConsts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Container for tabstop lists
|
||||||
|
*/
|
||||||
|
public class TabStopPropCollection extends TextProp {
|
||||||
|
public enum TabStopType {
|
||||||
|
LEFT(0), CENTER(1), RIGHT(2), DECIMAL(3);
|
||||||
|
private final int val;
|
||||||
|
TabStopType(int val) {
|
||||||
|
this.val = val;
|
||||||
|
}
|
||||||
|
public static TabStopType fromRecordVal(int val) {
|
||||||
|
for (TabStopType tst : values()) {
|
||||||
|
if (tst.val == val) return tst;
|
||||||
|
}
|
||||||
|
return LEFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TabStop {
|
||||||
|
/**
|
||||||
|
* If the TextPFException record that contains this TabStop structure also contains a
|
||||||
|
* leftMargin, then the value of position is relative to the left margin of the paragraph;
|
||||||
|
* otherwise, the value is relative to the left side of the paragraph.
|
||||||
|
*
|
||||||
|
* If a TextRuler record contains this TabStop structure, the value is relative to the
|
||||||
|
* left side of the text ruler.
|
||||||
|
*/
|
||||||
|
private int position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A enumeration that specifies how text aligns at the tab stop.
|
||||||
|
*/
|
||||||
|
private TabStopType type;
|
||||||
|
|
||||||
|
public TabStop(int position, TabStopType type) {
|
||||||
|
this.position = position;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(int position) {
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TabStopType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(TabStopType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TabStop> tabStops = new ArrayList<TabStop>();
|
||||||
|
|
||||||
|
public TabStopPropCollection() {
|
||||||
|
super(0, 0x100000, "tabStops");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the tabstops from TxMasterStyle record
|
||||||
|
*
|
||||||
|
* @param data the data stream
|
||||||
|
* @param offset the offset within the data
|
||||||
|
* @return the new offset
|
||||||
|
*/
|
||||||
|
public void parseProperty(byte data[], int offset) {
|
||||||
|
int count = LittleEndian.getUShort(data, offset);
|
||||||
|
offset += LittleEndianConsts.SHORT_SIZE;
|
||||||
|
for (int i=0; i<count; i++) {
|
||||||
|
int position = LittleEndian.getShort(data, offset);
|
||||||
|
offset += LittleEndianConsts.SHORT_SIZE;
|
||||||
|
int recVal = LittleEndian.getShort(data, offset);
|
||||||
|
TabStopType type = TabStopType.fromRecordVal(recVal);
|
||||||
|
offset += LittleEndianConsts.SHORT_SIZE;
|
||||||
|
tabStops.add(new TabStop(position, type));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return LittleEndianConsts.SHORT_SIZE + tabStops.size()*LittleEndianConsts.INT_SIZE;
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,16 @@ public class TextProp implements Cloneable {
|
|||||||
this.dataValue = 0;
|
this.dataValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones the property
|
||||||
|
*/
|
||||||
|
public TextProp(TextProp other) {
|
||||||
|
this.sizeOfDataBlock = other.sizeOfDataBlock;
|
||||||
|
this.maskInHeader = other.maskInHeader;
|
||||||
|
this.propName = other.propName;
|
||||||
|
this.dataValue = other.dataValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the text property
|
* Name of the text property
|
||||||
*/
|
*/
|
||||||
@ -79,11 +89,36 @@ public class TextProp implements Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Clone, eg when you want to actually make use of one of these.
|
* Clone, eg when you want to actually make use of one of these.
|
||||||
*/
|
*/
|
||||||
public Object clone(){
|
@Override
|
||||||
|
public TextProp clone(){
|
||||||
try {
|
try {
|
||||||
return super.clone();
|
return (TextProp)super.clone();
|
||||||
} catch(CloneNotSupportedException e) {
|
} catch(CloneNotSupportedException e) {
|
||||||
throw new InternalError(e.getMessage());
|
throw new InternalError(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + dataValue;
|
||||||
|
result = prime * result + maskInHeader;
|
||||||
|
result = prime * result + ((propName == null) ? 0 : propName.hashCode());
|
||||||
|
result = prime * result + sizeOfDataBlock;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null) return false;
|
||||||
|
if (getClass() != obj.getClass()) return false;
|
||||||
|
TextProp other = (TextProp) obj;
|
||||||
|
if (dataValue != other.dataValue) return false;
|
||||||
|
if (maskInHeader != other.maskInHeader) return false;
|
||||||
|
if (propName == null) {
|
||||||
|
if (other.propName != null) return false;
|
||||||
|
} else if (!propName.equals(other.propName)) return false;
|
||||||
|
if (sizeOfDataBlock != other.sizeOfDataBlock) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@ package org.apache.poi.hslf.model.textproperties;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.LinkedList;
|
import java.util.*;
|
||||||
|
|
||||||
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
import org.apache.poi.hslf.record.StyleTextPropAtom;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
@ -33,7 +33,7 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
public class TextPropCollection {
|
public class TextPropCollection {
|
||||||
private int charactersCovered;
|
private int charactersCovered;
|
||||||
private short reservedField;
|
private short reservedField;
|
||||||
private LinkedList<TextProp> textPropList;
|
private List<TextProp> textPropList;
|
||||||
private int maskSpecial = 0;
|
private int maskSpecial = 0;
|
||||||
|
|
||||||
public int getSpecialMask() { return maskSpecial; }
|
public int getSpecialMask() { return maskSpecial; }
|
||||||
@ -41,7 +41,7 @@ public class TextPropCollection {
|
|||||||
/** Fetch the number of characters this styling applies to */
|
/** Fetch the number of characters this styling applies to */
|
||||||
public int getCharactersCovered() { return charactersCovered; }
|
public int getCharactersCovered() { return charactersCovered; }
|
||||||
/** Fetch the TextProps that define this styling */
|
/** Fetch the TextProps that define this styling */
|
||||||
public LinkedList<TextProp> getTextPropList() { return textPropList; }
|
public List<TextProp> getTextPropList() { return textPropList; }
|
||||||
|
|
||||||
/** Fetch the TextProp with this name, or null if it isn't present */
|
/** Fetch the TextProp with this name, or null if it isn't present */
|
||||||
public TextProp findByName(String textPropName) {
|
public TextProp findByName(String textPropName) {
|
||||||
@ -73,7 +73,7 @@ public class TextPropCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a copy of this property, in the right place to the list
|
// Add a copy of this property, in the right place to the list
|
||||||
TextProp textProp = (TextProp)base.clone();
|
TextProp textProp = base.clone();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for(int i=0; i<textPropList.size(); i++) {
|
for(int i=0; i<textPropList.size(); i++) {
|
||||||
TextProp curProp = textPropList.get(i);
|
TextProp curProp = textPropList.get(i);
|
||||||
@ -95,28 +95,30 @@ public class TextPropCollection {
|
|||||||
|
|
||||||
// For each possible entry, see if we match the mask
|
// For each possible entry, see if we match the mask
|
||||||
// If we do, decode that, save it, and shuffle on
|
// If we do, decode that, save it, and shuffle on
|
||||||
for(int i=0; i<potentialProperties.length; i++) {
|
for(TextProp tp : potentialProperties) {
|
||||||
// Check there's still data left to read
|
// Check there's still data left to read
|
||||||
|
|
||||||
// Check if this property is found in the mask
|
// Check if this property is found in the mask
|
||||||
if((containsField & potentialProperties[i].getMask()) != 0) {
|
if((containsField & tp.getMask()) != 0) {
|
||||||
if(dataOffset+bytesPassed >= data.length) {
|
if(dataOffset+bytesPassed >= data.length) {
|
||||||
// Out of data, can't be any more properties to go
|
// Out of data, can't be any more properties to go
|
||||||
// remember the mask and return
|
// remember the mask and return
|
||||||
maskSpecial |= potentialProperties[i].getMask();
|
maskSpecial |= tp.getMask();
|
||||||
return bytesPassed;
|
return bytesPassed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bingo, data contains this property
|
// Bingo, data contains this property
|
||||||
TextProp prop = (TextProp)potentialProperties[i].clone();
|
TextProp prop = tp.clone();
|
||||||
int val = 0;
|
int val = 0;
|
||||||
if(prop.getSize() == 2) {
|
if (prop instanceof TabStopPropCollection) {
|
||||||
|
((TabStopPropCollection)prop).parseProperty(data, dataOffset+bytesPassed);
|
||||||
|
} else if (prop.getSize() == 2) {
|
||||||
val = LittleEndian.getShort(data,dataOffset+bytesPassed);
|
val = LittleEndian.getShort(data,dataOffset+bytesPassed);
|
||||||
} else if(prop.getSize() == 4) {
|
} else if(prop.getSize() == 4) {
|
||||||
val = LittleEndian.getInt(data,dataOffset+bytesPassed);
|
val = LittleEndian.getInt(data,dataOffset+bytesPassed);
|
||||||
} else if (prop.getSize() == 0) {
|
} else if (prop.getSize() == 0) {
|
||||||
//remember "special" bits.
|
//remember "special" bits.
|
||||||
maskSpecial |= potentialProperties[i].getMask();
|
maskSpecial |= tp.getMask();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
prop.setValue(val);
|
prop.setValue(val);
|
||||||
@ -137,7 +139,7 @@ public class TextPropCollection {
|
|||||||
public TextPropCollection(int charactersCovered, short reservedField) {
|
public TextPropCollection(int charactersCovered, short reservedField) {
|
||||||
this.charactersCovered = charactersCovered;
|
this.charactersCovered = charactersCovered;
|
||||||
this.reservedField = reservedField;
|
this.reservedField = reservedField;
|
||||||
textPropList = new LinkedList<TextProp>();
|
textPropList = new ArrayList<TextProp>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,7 +149,27 @@ public class TextPropCollection {
|
|||||||
public TextPropCollection(int textSize) {
|
public TextPropCollection(int textSize) {
|
||||||
charactersCovered = textSize;
|
charactersCovered = textSize;
|
||||||
reservedField = -1;
|
reservedField = -1;
|
||||||
textPropList = new LinkedList<TextProp>();
|
textPropList = new ArrayList<TextProp>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones the given text properties
|
||||||
|
*/
|
||||||
|
public void copy(TextPropCollection other) {
|
||||||
|
this.charactersCovered = other.charactersCovered;
|
||||||
|
this.reservedField = other.reservedField;
|
||||||
|
this.textPropList.clear();
|
||||||
|
for (TextProp tp : other.textPropList) {
|
||||||
|
TextProp tpCopy = tp.clone();
|
||||||
|
if (tpCopy instanceof BitMaskTextProp) {
|
||||||
|
BitMaskTextProp bmt = (BitMaskTextProp)tpCopy;
|
||||||
|
boolean matches[] = ((BitMaskTextProp)tp).getSubPropMatches();
|
||||||
|
for (int i=0; i<matches.length; i++) {
|
||||||
|
bmt.setSubValue(matches[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.textPropList.add(tpCopy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,7 +195,7 @@ public class TextPropCollection {
|
|||||||
// Then the mask field
|
// Then the mask field
|
||||||
int mask = maskSpecial;
|
int mask = maskSpecial;
|
||||||
for(int i=0; i<textPropList.size(); i++) {
|
for(int i=0; i<textPropList.size(); i++) {
|
||||||
TextProp textProp = (TextProp)textPropList.get(i);
|
TextProp textProp = textPropList.get(i);
|
||||||
//sometimes header indicates that the bitmask is present but its value is 0
|
//sometimes header indicates that the bitmask is present but its value is 0
|
||||||
|
|
||||||
if (textProp instanceof BitMaskTextProp) {
|
if (textProp instanceof BitMaskTextProp) {
|
||||||
@ -204,4 +226,44 @@ public class TextPropCollection {
|
|||||||
public void setReservedField(short val){
|
public void setReservedField(short val){
|
||||||
reservedField = val;
|
reservedField = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + charactersCovered;
|
||||||
|
result = prime * result + maskSpecial;
|
||||||
|
result = prime * result + reservedField;
|
||||||
|
result = prime * result + ((textPropList == null) ? 0 : textPropList.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* compares most properties apart of the covered characters length
|
||||||
|
*/
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (this == other) return true;
|
||||||
|
if (other == null) return false;
|
||||||
|
if (getClass() != other.getClass()) return false;
|
||||||
|
|
||||||
|
TextPropCollection o = (TextPropCollection)other;
|
||||||
|
if (o.maskSpecial != this.maskSpecial || o.reservedField != this.reservedField) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textPropList == null) {
|
||||||
|
return (o.textPropList == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String,TextProp> m = new HashMap<String,TextProp>();
|
||||||
|
for (TextProp tp : o.textPropList) {
|
||||||
|
m.put(tp.getName(), tp);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TextProp tp : this.textPropList) {
|
||||||
|
TextProp otp = m.get(tp.getName());
|
||||||
|
if (!tp.equals(otp)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -273,8 +273,8 @@ public final class RecordTypes {
|
|||||||
* offers methods to get either back out.
|
* offers methods to get either back out.
|
||||||
*/
|
*/
|
||||||
public static class Type {
|
public static class Type {
|
||||||
public int typeID;
|
public final int typeID;
|
||||||
public Class<? extends Record> handlingClass;
|
public final Class<? extends Record> handlingClass;
|
||||||
public Type(int typeID, Class<? extends Record> handlingClass) {
|
public Type(int typeID, Class<? extends Record> handlingClass) {
|
||||||
this.typeID = typeID;
|
this.typeID = typeID;
|
||||||
this.handlingClass = handlingClass;
|
this.handlingClass = handlingClass;
|
||||||
|
@ -22,11 +22,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.apache.poi.hslf.model.textproperties.AlignmentTextProp;
|
import org.apache.poi.hslf.model.textproperties.*;
|
||||||
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
|
|
||||||
import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
|
|
||||||
import org.apache.poi.hslf.model.textproperties.TextProp;
|
|
||||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
|
||||||
import org.apache.poi.util.HexDump;
|
import org.apache.poi.util.HexDump;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
@ -51,7 +47,7 @@ import org.apache.poi.util.POILogger;
|
|||||||
public final class StyleTextPropAtom extends RecordAtom
|
public final class StyleTextPropAtom extends RecordAtom
|
||||||
{
|
{
|
||||||
private byte[] _header;
|
private byte[] _header;
|
||||||
private static long _type = 4001l;
|
private static final long _type = RecordTypes.StyleTextPropAtom.typeID;
|
||||||
private byte[] reserved;
|
private byte[] reserved;
|
||||||
|
|
||||||
private byte[] rawContents; // Holds the contents between write-outs
|
private byte[] rawContents; // Holds the contents between write-outs
|
||||||
@ -118,7 +114,9 @@ public final class StyleTextPropAtom extends RecordAtom
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** All the different kinds of paragraph properties we might handle */
|
/** All the different kinds of paragraph properties we might handle */
|
||||||
public static final TextProp[] paragraphTextPropTypes = new TextProp[] {
|
public static final TextProp[] paragraphTextPropTypes = {
|
||||||
|
// TextProp order is according to 2.9.20 TextPFException,
|
||||||
|
// bitmask order can be different
|
||||||
new TextProp(0, 0x1, "hasBullet"),
|
new TextProp(0, 0x1, "hasBullet"),
|
||||||
new TextProp(0, 0x2, "hasBulletFont"),
|
new TextProp(0, 0x2, "hasBulletFont"),
|
||||||
new TextProp(0, 0x4, "hasBulletColor"),
|
new TextProp(0, 0x4, "hasBulletColor"),
|
||||||
@ -129,16 +127,22 @@ public final class StyleTextPropAtom extends RecordAtom
|
|||||||
new TextProp(2, 0x40, "bullet.size"),
|
new TextProp(2, 0x40, "bullet.size"),
|
||||||
new TextProp(4, 0x20, "bullet.color"),
|
new TextProp(4, 0x20, "bullet.color"),
|
||||||
new AlignmentTextProp(),
|
new AlignmentTextProp(),
|
||||||
new TextProp(2, 0x100, "text.offset"),
|
|
||||||
new TextProp(2, 0x400, "bullet.offset"),
|
|
||||||
new TextProp(2, 0x1000, "linespacing"),
|
new TextProp(2, 0x1000, "linespacing"),
|
||||||
new TextProp(2, 0x2000, "spacebefore"),
|
new TextProp(2, 0x2000, "spacebefore"),
|
||||||
new TextProp(2, 0x4000, "spaceafter"),
|
new TextProp(2, 0x4000, "spaceafter"),
|
||||||
|
new TextProp(2, 0x100, "text.offset"), // left margin
|
||||||
|
// 0x200 - Undefined and MUST be ignored
|
||||||
|
new TextProp(2, 0x400, "bullet.offset"), // indent
|
||||||
new TextProp(2, 0x8000, "defaultTabSize"),
|
new TextProp(2, 0x8000, "defaultTabSize"),
|
||||||
new TextProp(2, 0x100000, "tabStops"),
|
new TabStopPropCollection(), // tabstops size is variable!
|
||||||
new TextProp(2, 0x10000, "fontAlign"),
|
new TextProp(2, 0x10000, "fontAlign"),
|
||||||
new TextProp(2, 0xA0000, "wrapFlags"),
|
new TextProp(2, 0xE0000, "wrapFlags"), // charWrap | wordWrap | overflow
|
||||||
new TextProp(2, 0x200000, "textDirection")
|
new TextProp(2, 0x200000, "textDirection"),
|
||||||
|
// 0x400000 MUST be zero and MUST be ignored
|
||||||
|
new TextProp(0, 0x800000, "bullet.blip"), // TODO: check size
|
||||||
|
new TextProp(0, 0x1000000, "bullet.scheme"), // TODO: check size
|
||||||
|
new TextProp(0, 0x2000000, "hasBulletScheme"), // TODO: check size
|
||||||
|
// 0xFC000000 MUST be zero and MUST be ignored
|
||||||
};
|
};
|
||||||
/** All the different kinds of character properties we might handle */
|
/** All the different kinds of character properties we might handle */
|
||||||
public static final TextProp[] characterTextPropTypes = new TextProp[] {
|
public static final TextProp[] characterTextPropTypes = new TextProp[] {
|
||||||
@ -391,6 +395,14 @@ public final class StyleTextPropAtom extends RecordAtom
|
|||||||
initialised = false;
|
initialised = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear styles, so new collections can be added
|
||||||
|
*/
|
||||||
|
public void clearStyles() {
|
||||||
|
paragraphStyles.clear();
|
||||||
|
charStyles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Paragraph TextPropCollection, and add it to the list
|
* Create a new Paragraph TextPropCollection, and add it to the list
|
||||||
* @param charactersCovered The number of characters this TextPropCollection will cover
|
* @param charactersCovered The number of characters this TextPropCollection will cover
|
||||||
|
@ -35,7 +35,7 @@ import java.io.OutputStream;
|
|||||||
public final class TextBytesAtom extends RecordAtom
|
public final class TextBytesAtom extends RecordAtom
|
||||||
{
|
{
|
||||||
private byte[] _header;
|
private byte[] _header;
|
||||||
private static long _type = 4008l;
|
private static long _type = RecordTypes.TextBytesAtom.typeID;
|
||||||
|
|
||||||
/** The bytes that make up the text */
|
/** The bytes that make up the text */
|
||||||
private byte[] _text;
|
private byte[] _text;
|
||||||
|
@ -33,7 +33,7 @@ import java.io.OutputStream;
|
|||||||
public final class TextCharsAtom extends RecordAtom
|
public final class TextCharsAtom extends RecordAtom
|
||||||
{
|
{
|
||||||
private byte[] _header;
|
private byte[] _header;
|
||||||
private static long _type = 4000l;
|
private static long _type = RecordTypes.TextCharsAtom.typeID;
|
||||||
|
|
||||||
/** The bytes that make up the text */
|
/** The bytes that make up the text */
|
||||||
private byte[] _text;
|
private byte[] _text;
|
||||||
|
@ -32,7 +32,7 @@ import java.io.OutputStream;
|
|||||||
public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecord
|
public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecord
|
||||||
{
|
{
|
||||||
private byte[] _header;
|
private byte[] _header;
|
||||||
private static long _type = 3999l;
|
private static long _type = RecordTypes.TextHeaderAtom.typeID;
|
||||||
private RecordContainer parentRecord;
|
private RecordContainer parentRecord;
|
||||||
|
|
||||||
public static final int TITLE_TYPE = 0;
|
public static final int TITLE_TYPE = 0;
|
||||||
@ -46,10 +46,22 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor
|
|||||||
|
|
||||||
/** The kind of text it is */
|
/** The kind of text it is */
|
||||||
private int textType;
|
private int textType;
|
||||||
|
/** position in the owning SlideListWithText */
|
||||||
|
private int index = -1;
|
||||||
|
|
||||||
public int getTextType() { return textType; }
|
public int getTextType() { return textType; }
|
||||||
public void setTextType(int type) { textType = type; }
|
public void setTextType(int type) { textType = type; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 0-based index of the text run in the SLWT container
|
||||||
|
*/
|
||||||
|
public int getIndex() { return index; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id 0-based index of the text run in the SLWT container
|
||||||
|
*/
|
||||||
|
public void setIndex(int index) { this.index = index; }
|
||||||
|
|
||||||
public RecordContainer getParentRecord() { return parentRecord; }
|
public RecordContainer getParentRecord() { return parentRecord; }
|
||||||
public void setParentRecord(RecordContainer record) { this.parentRecord = record; }
|
public void setParentRecord(RecordContainer record) { this.parentRecord = record; }
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@ import java.util.ArrayList;
|
|||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
*/
|
*/
|
||||||
public final class TextSpecInfoAtom extends RecordAtom {
|
public final class TextSpecInfoAtom extends RecordAtom {
|
||||||
|
private static final long _type = RecordTypes.TextSpecInfoAtom.typeID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Record header.
|
* Record header.
|
||||||
*/
|
*/
|
||||||
@ -62,7 +64,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
|
|||||||
* Gets the record type.
|
* Gets the record type.
|
||||||
* @return the record type.
|
* @return the record type.
|
||||||
*/
|
*/
|
||||||
public long getRecordType() { return RecordTypes.TextSpecInfoAtom.typeID; }
|
public long getRecordType() { return _type; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the contents of the record back, so it can be written
|
* Write the contents of the record back, so it can be written
|
||||||
|
@ -48,6 +48,37 @@ public final class TxMasterStyleAtom extends RecordAtom {
|
|||||||
*/
|
*/
|
||||||
public static final int MAX_INDENT = 5;
|
public static final int MAX_INDENT = 5;
|
||||||
|
|
||||||
|
/*
|
||||||
|
private static TextProp paragraphSpecialPropTypes[] = {
|
||||||
|
new ParagraphFlagsTextProp(),
|
||||||
|
new TextProp(2, 0x80, "bullet.char"),
|
||||||
|
new TextProp(2, 0x10, "bullet.font"),
|
||||||
|
new TextProp(2, 0x40, "bullet.size"),
|
||||||
|
new TextProp(4, 0x20, "bullet.color"),
|
||||||
|
new TextProp(2, 0xD00, "alignment"),
|
||||||
|
new TextProp(2, 0x1000, "linespacing"),
|
||||||
|
new TextProp(2, 0x2000, "spacebefore"),
|
||||||
|
new TextProp(2, 0x4000, "spaceafter"),
|
||||||
|
new TextProp(2, 0x8000, "text.offset"),
|
||||||
|
new TextProp(2, 0x10000, "bullet.offset"),
|
||||||
|
new TextProp(2, 0x20000, "defaulttab"),
|
||||||
|
new TextProp(2, 0x40000, "para_unknown_2"),
|
||||||
|
new TextProp(2, 0x80000, "para_unknown_3"),
|
||||||
|
new TextProp(2, 0x100000, "para_unknown_4"),
|
||||||
|
new TextProp(2, 0x200000, "para_unknown_5")
|
||||||
|
};
|
||||||
|
|
||||||
|
private static TextProp characterSpecialPropTypes[] = {
|
||||||
|
new CharFlagsTextProp(),
|
||||||
|
new TextProp(2, 0x10000, "font.index"),
|
||||||
|
new TextProp(2, 0x20000, "char_unknown_1"),
|
||||||
|
new TextProp(4, 0x40000, "char_unknown_2"),
|
||||||
|
new TextProp(2, 0x80000, "font.size"),
|
||||||
|
new TextProp(2, 0x100000, "char_unknown_3"),
|
||||||
|
new TextProp(4, 0x200000, "font.color"),
|
||||||
|
new TextProp(2, 0x800000, "char_unknown_4")
|
||||||
|
};
|
||||||
|
*/
|
||||||
private byte[] _header;
|
private byte[] _header;
|
||||||
private static long _type = 4003;
|
private static long _type = 4003;
|
||||||
private byte[] _data;
|
private byte[] _data;
|
||||||
@ -126,6 +157,7 @@ public final class TxMasterStyleAtom extends RecordAtom {
|
|||||||
/**
|
/**
|
||||||
* parse the record data and initialize styles
|
* parse the record data and initialize styles
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
protected void init(){
|
protected void init(){
|
||||||
//type of the text
|
//type of the text
|
||||||
int type = getTextType();
|
int type = getTextType();
|
||||||
@ -170,28 +202,10 @@ public final class TxMasterStyleAtom extends RecordAtom {
|
|||||||
* ones, or the standard StyleTextPropAtom ones
|
* ones, or the standard StyleTextPropAtom ones
|
||||||
*/
|
*/
|
||||||
protected TextProp[] getParagraphProps(int type, int level){
|
protected TextProp[] getParagraphProps(int type, int level){
|
||||||
if (level != 0 || type >= MAX_INDENT){
|
|
||||||
return StyleTextPropAtom.paragraphTextPropTypes;
|
return StyleTextPropAtom.paragraphTextPropTypes;
|
||||||
}
|
// return (level != 0 || type >= MAX_INDENT)
|
||||||
return new TextProp[] {
|
// ? StyleTextPropAtom.paragraphTextPropTypes
|
||||||
new ParagraphFlagsTextProp(),
|
// : paragraphSpecialPropTypes;
|
||||||
new TextProp(2, 0x80, "bullet.char"),
|
|
||||||
new TextProp(2, 0x10, "bullet.font"),
|
|
||||||
new TextProp(2, 0x40, "bullet.size"),
|
|
||||||
new TextProp(4, 0x20, "bullet.color"),
|
|
||||||
new TextProp(2, 0xD00, "alignment"),
|
|
||||||
new TextProp(2, 0x1000, "linespacing"),
|
|
||||||
new TextProp(2, 0x2000, "spacebefore"),
|
|
||||||
new TextProp(2, 0x4000, "spaceafter"),
|
|
||||||
new TextProp(2, 0x8000, "text.offset"),
|
|
||||||
new TextProp(2, 0x10000, "bullet.offset"),
|
|
||||||
new TextProp(2, 0x20000, "defaulttab"),
|
|
||||||
new TextProp(2, 0x40000, "para_unknown_2"),
|
|
||||||
new TextProp(2, 0x80000, "para_unknown_3"),
|
|
||||||
new TextProp(2, 0x100000, "para_unknown_4"),
|
|
||||||
new TextProp(2, 0x200000, "para_unknown_5")
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,18 +215,9 @@ public final class TxMasterStyleAtom extends RecordAtom {
|
|||||||
* ones, or the standard StyleTextPropAtom ones
|
* ones, or the standard StyleTextPropAtom ones
|
||||||
*/
|
*/
|
||||||
protected TextProp[] getCharacterProps(int type, int level){
|
protected TextProp[] getCharacterProps(int type, int level){
|
||||||
if (level != 0 || type >= MAX_INDENT){
|
|
||||||
return StyleTextPropAtom.characterTextPropTypes;
|
return StyleTextPropAtom.characterTextPropTypes;
|
||||||
}
|
// return (level != 0 || type >= MAX_INDENT)
|
||||||
return new TextProp[] {
|
// ? StyleTextPropAtom.characterTextPropTypes
|
||||||
new CharFlagsTextProp(),
|
// : characterSpecialPropTypes;
|
||||||
new TextProp(2, 0x10000, "font.index"),
|
|
||||||
new TextProp(2, 0x20000, "char_unknown_1"),
|
|
||||||
new TextProp(4, 0x40000, "char_unknown_2"),
|
|
||||||
new TextProp(2, 0x80000, "font.size"),
|
|
||||||
new TextProp(2, 0x100000, "char_unknown_3"),
|
|
||||||
new TextProp(4, 0x200000, "font.color"),
|
|
||||||
new TextProp(2, 0x800000, "char_unknown_4")
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,16 +15,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
import org.apache.poi.sl.draw.geom.CustomGeometry;
|
import org.apache.poi.ddf.EscherProperties;
|
||||||
import org.apache.poi.sl.draw.geom.Guide;
|
|
||||||
import org.apache.poi.sl.usermodel.*;
|
import org.apache.poi.sl.usermodel.*;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.ss.usermodel.ShapeTypes;
|
||||||
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an AutoShape.
|
* Represents an AutoShape.
|
||||||
@ -69,8 +65,8 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFTextPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setDefaultTextProperties(HSLFTextParagraph _txtrun){
|
protected void setDefaultTextProperties(HSLFTextParagraph _txtrun){
|
||||||
setVerticalAlignment(HSLFTextBox.AnchorMiddle);
|
setVerticalAlignment(VerticalAlignment.MIDDLE);
|
||||||
setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
setHorizontalCentered(true);
|
||||||
setWordWrap(HSLFTextBox.WrapNone);
|
setWordWrap(HSLFTextBox.WrapNone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,15 +105,4 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFTextPa
|
|||||||
|
|
||||||
setEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx), val);
|
setEscherProperty((short)(EscherProperties.GEOMETRY__ADJUSTVALUE + idx), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.awt.Shape getOutline(){
|
|
||||||
ShapeOutline outline = AutoShapes.getShapeOutline(getShapeType());
|
|
||||||
Rectangle2D anchor = getLogicalAnchor2D();
|
|
||||||
if(outline == null){
|
|
||||||
logger.log(POILogger.WARN, "Outline not found for " + getShapeType().nativeName);
|
|
||||||
return anchor;
|
|
||||||
}
|
|
||||||
java.awt.Shape shape = outline.getOutline(this);
|
|
||||||
return AutoShapes.transform(shape, anchor);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
import org.apache.poi.sl.usermodel.Background;
|
import org.apache.poi.sl.usermodel.Background;
|
@ -15,7 +15,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -24,8 +24,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.*;
|
||||||
import org.apache.poi.hslf.record.Document;
|
import org.apache.poi.hslf.record.Document;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
|
||||||
import org.apache.poi.sl.usermodel.*;
|
import org.apache.poi.sl.usermodel.*;
|
||||||
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
|
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
|
||||||
import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
|
import org.apache.poi.sl.usermodel.PaintStyle.TexturePaint;
|
@ -15,7 +15,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.GeneralPath;
|
import java.awt.geom.GeneralPath;
|
@ -15,21 +15,12 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.model;
|
package org.apache.poi.hslf.usermodel;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.poi.ddf.EscherChildAnchorRecord;
|
import org.apache.poi.ddf.*;
|
||||||
import org.apache.poi.ddf.EscherClientAnchorRecord;
|
|
||||||
import org.apache.poi.ddf.EscherContainerRecord;
|
|
||||||
import org.apache.poi.ddf.EscherRecord;
|
|
||||||
import org.apache.poi.ddf.EscherSpRecord;
|
|
||||||
import org.apache.poi.ddf.EscherSpgrRecord;
|
|
||||||
import org.apache.poi.sl.usermodel.ShapeContainer;
|
import org.apache.poi.sl.usermodel.ShapeContainer;
|
||||||
import org.apache.poi.sl.usermodel.ShapeType;
|
import org.apache.poi.sl.usermodel.ShapeType;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
@ -61,13 +52,9 @@ public class HSLFGroupShape extends HSLFShape implements ShapeContainer<HSLFShap
|
|||||||
super(escherRecord, parent);
|
super(escherRecord, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @return the shapes contained in this group container
|
public List<HSLFShape> getShapes() {
|
||||||
*/
|
return getShapeList();
|
||||||
public HSLFShape[] getShapes() {
|
|
||||||
List<HSLFShape> shapeList = getShapeList();
|
|
||||||
HSLFShape[] shapes = shapeList.toArray(new HSLFShape[shapeList.size()]);
|
|
||||||
return shapes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,11 +183,11 @@ public class HSLFGroupShape extends HSLFShape implements ShapeContainer<HSLFShap
|
|||||||
anchor.translate(dx, dy);
|
anchor.translate(dx, dy);
|
||||||
setAnchor(anchor);
|
setAnchor(anchor);
|
||||||
|
|
||||||
HSLFShape[] shape = getShapes();
|
|
||||||
for (int i = 0; i < shape.length; i++) {
|
for (HSLFShape shape : getShapes()) {
|
||||||
java.awt.Rectangle chanchor = shape[i].getAnchor();
|
java.awt.Rectangle chanchor = shape.getAnchor();
|
||||||
chanchor.translate(dx, dy);
|
chanchor.translate(dx, dy);
|
||||||
shape[i].setAnchor(chanchor);
|
shape.setAnchor(chanchor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,22 +236,10 @@ public class HSLFGroupShape extends HSLFShape implements ShapeContainer<HSLFShap
|
|||||||
*
|
*
|
||||||
* @return <code>null</code>.
|
* @return <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public Hyperlink getHyperlink(){
|
public HSLFHyperlink getHyperlink(){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics2D graphics){
|
|
||||||
|
|
||||||
AffineTransform at = graphics.getTransform();
|
|
||||||
|
|
||||||
HSLFShape[] sh = getShapes();
|
|
||||||
for (int i = 0; i < sh.length; i++) {
|
|
||||||
sh[i].draw(graphics);
|
|
||||||
}
|
|
||||||
|
|
||||||
graphics.setTransform(at);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends EscherRecord> T getEscherChild(int recordId){
|
public <T extends EscherRecord> T getEscherChild(int recordId){
|
||||||
EscherContainerRecord groupInfoContainer = (EscherContainerRecord)_escherContainer.getChild(0);
|
EscherContainerRecord groupInfoContainer = (EscherContainerRecord)_escherContainer.getChild(0);
|
||||||
@ -298,7 +273,7 @@ public class HSLFGroupShape extends HSLFShape implements ShapeContainer<HSLFShap
|
|||||||
if(r instanceof EscherContainerRecord) {
|
if(r instanceof EscherContainerRecord) {
|
||||||
// Create the Shape for it
|
// Create the Shape for it
|
||||||
EscherContainerRecord container = (EscherContainerRecord)r;
|
EscherContainerRecord container = (EscherContainerRecord)r;
|
||||||
HSLFShape shape = ShapeFactory.createShape(container, this);
|
HSLFShape shape = HSLFShapeFactory.createShape(container, this);
|
||||||
shape.setSheet(getSheet());
|
shape.setSheet(getSheet());
|
||||||
shapeList.add( shape );
|
shapeList.add( shape );
|
||||||
} else {
|
} else {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user