short type = (short)((shapeType << 4) | 0x2);\r
spRecord.setOptions(type);\r
\r
- //set default properties for a line\r
+ //set default properties for an autoshape\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);\r
\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 134217732));\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 134217728));\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 1048592));\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 134217729));\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 524296));\r
- opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 134217730));\r
-\r
- opt.sortProperties();\r
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004));\r
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000));\r
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100010));\r
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001));\r
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80008));\r
+ opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002));\r
\r
return spcont;\r
}\r
/**\r
* Solid (continuous) pen\r
*/\r
- public static final int LineSolid = 1;\r
+ public static final int PEN_SOLID = 1;\r
/**\r
* PS_DASH system dash style\r
*/\r
- public static final int LineDashSys = 2;\r
+ public static final int PEN_PS_DASH = 2;\r
/**\r
* PS_DOT system dash style\r
*/\r
- public static final int LineDotSys = 3;\r
+ public static final int PEN_DOT = 3;\r
/**\r
* PS_DASHDOT system dash style\r
*/\r
- public static final int LineDashDotSys = 4;\r
-\r
+ public static final int PEN_DASHDOT = 4;\r
/**\r
* PS_DASHDOTDOT system dash style\r
*/\r
- public static final int LineDashDotDotSys = 5;\r
+ public static final int PEN_DASHDOTDOT = 5;\r
/**\r
* square dot style\r
*/\r
- public static final int LineDotGEL = 6;\r
+ public static final int PEN_DOTGEL = 6;\r
/**\r
* dash style\r
*/\r
- public static final int LineDashGEL = 7;\r
+ public static final int PEN_DASH = 7;\r
/**\r
* long dash style\r
*/\r
- public static final int LineLongDashGEL = 8;\r
+ public static final int PEN_LONGDASHGEL = 8;\r
/**\r
* dash short dash\r
*/\r
- public static final int LineDashDotGEL = 9;\r
+ public static final int PEN_DASHDOTGEL = 9;\r
/**\r
* long dash short dash\r
*/\r
- public static final int LineLongDashDotGEL = 10;\r
+ public static final int PEN_LONGDASHDOTGEL = 10;\r
/**\r
* long dash short dash short dash\r
*/\r
- public static final int LineLongDashDotDotGEL = 11;\r
+ public static final int PEN_LONGDASHDOTDOTGEL = 11;\r
\r
/**\r
- * Decoration of the end of line,\r
- * reserved in API but not supported.\r
+ * Single line (of width lineWidth)\r
*/\r
-\r
+ public static final int LINE_SIMPLE = 0;\r
/**\r
- * Line ends at end point\r
+ * Double lines of equal width\r
*/\r
- public static final int EndCapFlat = 0;\r
+ public static final int LINE_DOUBLE = 1;\r
/**\r
- * Rounded ends - the default\r
+ * Double lines, one thick, one thin\r
*/\r
- public static final int EndCapRound = 1;\r
+ public static final int LINE_THICKTHIN = 2;\r
/**\r
- * Square protrudes by half line width\r
+ * Double lines, reverse order\r
*/\r
- public static final int EndCapSquare = 2;\r
+ public static final int LINE_THINTHICK = 3;\r
+ /**\r
+ * Three lines, thin, thick, thin\r
+ */\r
+ public static final int LINE_TRIPLE = 4;\r
+\r
\r
protected Line(EscherContainerRecord escherRecord, Shape parent){\r
super(escherRecord, parent);\r
//set default properties for a line\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);\r
\r
- opt.sortProperties();\r
+ //default line properties\r
+ setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);\r
+ setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, 0x10000);\r
+ setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);\r
+ setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);\r
+ setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);\r
+ setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);\r
\r
return spcont;\r
}\r
--- /dev/null
+package org.apache.poi.hslf.model;
+
+/**
+ * The superclass of all master sheets - Slide masters, Notes masters, etc.
+ *
+ * For now it's empty. When we understand more about masters in ppt we will add the common functionality here.
+ *
+ * @author Yegor Kozlov
+ */
+public abstract class MasterSheet extends Sheet {
+
+}
import java.awt.geom.PathIterator;\r
import java.text.AttributedCharacterIterator;\r
import java.util.Map;\r
+import java.util.ArrayList;\r
\r
import org.apache.poi.ddf.EscherProperties;\r
+import org.apache.poi.hslf.usermodel.RichTextRun;\r
\r
/**\r
* Translates Graphics2D calls into PowerPoint.\r
private Color foreground;\r
private Color background = Color.white;\r
private Shape clip;\r
-\r
+ int count = 0;\r
/**\r
- * Construct an powerpoint Graphics object.\r
+ * Construct Java Graphics object which translates graphic calls in ppt drawing layer.\r
*\r
* @param group The shape group to write the graphics calls into.\r
*/\r
\r
public void draw(Shape shape){\r
if(clip != null) {\r
- if (!clip.getBounds().contains(transform.createTransformedShape(shape).getBounds())) {\r
- //return;\r
+ java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();\r
+ if (bounds.width == 0) bounds.width = 1;\r
+ if (bounds.height == 0) bounds.height = 1;\r
+ if (!clip.getBounds().contains(bounds)) {\r
+ return;\r
}\r
}\r
\r
if (stroke instanceof BasicStroke){\r
BasicStroke bs = (BasicStroke)stroke;\r
line.setLineWidth(bs.getLineWidth());\r
+ float[] dash = bs.getDashArray();\r
+ if (dash != null) line.setLineDashing(Line.PEN_DASH);\r
}\r
if(getColor() != null) line.setLineColor(getColor());\r
if (type == PathIterator.SEG_LINETO) {\r
}\r
\r
public void drawString(String string, float x, float y){\r
-\r
TextBox txt = new TextBox(group);\r
+ txt.getTextRun().supplySlideShow(group.getSheet().getSlideShow());\r
+ txt.getTextRun().setSheet(group.getSheet());\r
+ txt.setText(string);\r
+\r
+ RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];\r
+ rt.setFontSize(font.getSize());\r
+ rt.setFontName(font.getFamily());\r
+\r
+ if(getColor() != null) rt.setFontColor(getColor());\r
+ if (font.isBold()) rt.setBold(true);\r
+ if (font.isItalic()) rt.setItalic(true);\r
+\r
txt.setMarginBottom(0);\r
txt.setMarginTop(0);\r
txt.setMarginLeft(0);\r
txt.setMarginRight(0);\r
- txt.setText(string);\r
txt.setWordWrap(TextBox.WrapNone);\r
- \r
- if (font != null){\r
- txt.setFontSize(font.getSize());\r
- txt.setFontName(font.getName());\r
- if(getColor() != null) txt.setFontColor(getColor());\r
- if (font.isBold()) txt.setBold(true);\r
- if (font.isItalic()) txt.setItalic(true);\r
- }\r
-\r
- txt.resizeToFitText();\r
+\r
+ if (!"".equals(string)) txt.resizeToFitText();\r
int height = (int)txt.getAnchor().getHeight();\r
\r
/*\r
*/\r
txt.moveTo((int)x, (int)(y - height));\r
\r
- group.addShape(txt);\r
+ if(clip != null) {\r
+ if (!clip.getBounds().contains(txt.getAnchor())) {\r
+ ;//return;\r
+ }\r
+ }\r
+ group.addShape(txt);\r
}\r
\r
public void fill(Shape shape){\r
+ if(clip != null) {\r
+ java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();\r
+ if (bounds.width == 0) bounds.width = 1;\r
+ if (bounds.height == 0) bounds.height = 1;\r
+ if (!clip.getBounds().contains(bounds)) {\r
+ return;\r
+ }\r
+ }\r
+ PathIterator it = shape.getPathIterator(transform);\r
+ ArrayList pnt = new ArrayList();\r
+ double[] coords = new double[6];\r
+ while(!it.isDone()){\r
+ int type = it.currentSegment(coords);\r
+ if (type != PathIterator.SEG_CLOSE) {\r
+ pnt.add(new Point((int)coords[0], (int)coords[1]));\r
+ }\r
+ it.next();\r
+ }\r
+ int[] xPoints= new int[pnt.size()];\r
+ int[] yPoints= new int[pnt.size()];\r
+ for (int i = 0; i < pnt.size(); i++) {\r
+ Point p = (Point)pnt.get(i);\r
+ xPoints[i] = p.x;\r
+ yPoints[i] = p.y;\r
+ }\r
+\r
+ AutoShape r = new AutoShape(ShapeTypes.Rectangle);\r
if (paint instanceof Color){\r
Color color = (Color)paint;\r
+ r.setFillColor(color);\r
+ }\r
+ if(getColor() != null) r.setLineColor(getColor());\r
+ if (stroke instanceof BasicStroke){\r
+ BasicStroke bs = (BasicStroke)stroke;\r
+ r.setLineWidth(bs.getLineWidth());\r
+ float[] dash = bs.getDashArray();\r
+ if (dash != null) r.setLineDashing(Line.PEN_DASH);\r
}\r
\r
- throw new RuntimeException("Not implemented");\r
+ java.awt.Rectangle bounds = transform.createTransformedShape(shape).getBounds();\r
+ r.setAnchor(bounds);\r
+ group.addShape(r);\r
}\r
\r
public void translate(int x, int y) {\r
public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) {\r
throw new RuntimeException("Not implemented");\r
}\r
-\r
}\r
\r
int type = spRecord.getOptions() >> 4;\r
switch (type){\r
- case ShapeTypes.Rectangle:\r
- EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);\r
- if (txtbox == null) shape = new AutoShape(spContainer, parent);\r
- else{\r
- if(Shape.getEscherChild(spContainer, EscherClientDataRecord.RECORD_ID) != null )\r
- shape = new Placeholder(spContainer, parent);\r
- else\r
- shape = new TextBox(spContainer, parent);\r
- }\r
- break;\r
case ShapeTypes.TextBox:\r
shape = new TextBox(spContainer, parent);\r
break;\r
+ case ShapeTypes.Rectangle:\r
+ EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);\r
+ if (txtbox == null)\r
+ shape = new AutoShape(spContainer, parent);\r
+ else\r
+ shape = new TextBox(spContainer, parent);\r
+ break;\r
case ShapeTypes.PictureFrame:\r
shape = new Picture(spContainer, parent);\r
break;\r
shape = new Line(spContainer, parent);\r
break;\r
case ShapeTypes.NotPrimitive:\r
- shape = new ShapeGroup(spContainer, parent);\r
+ if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)\r
+ shape = new ShapeGroup(spContainer, parent);\r
+ else\r
+ shape = new AutoShape(spContainer, parent);\r
break;\r
default:\r
shape = new AutoShape(spContainer, parent);\r
LittleEndian.putInt(header, 4, 8);\r
clientAnchor.fillFields(header, 0, null);\r
\r
- clientAnchor.setFlag((short)anchor.y);\r
- clientAnchor.setCol1((short)anchor.x);\r
- clientAnchor.setDx1((short)(anchor.width + anchor.x));\r
- clientAnchor.setRow1((short)(anchor.height + anchor.y));\r
+ clientAnchor.setFlag((short)(anchor.y*MASTER_DPI/POINT_DPI));\r
+ clientAnchor.setCol1((short)(anchor.x*MASTER_DPI/POINT_DPI));\r
+ clientAnchor.setDx1((short)((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI));\r
+ clientAnchor.setRow1((short)((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI));\r
\r
EscherSpgrRecord spgr = (EscherSpgrRecord)getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);\r
\r
- spgr.setRectX1(anchor.x);\r
- spgr.setRectY1(anchor.y);\r
- spgr.setRectX2(anchor.x + anchor.width);\r
- spgr.setRectY2(anchor.y + anchor.height);\r
+ spgr.setRectX1(anchor.x*MASTER_DPI/POINT_DPI);\r
+ spgr.setRectY1(anchor.y*MASTER_DPI/POINT_DPI);\r
+ spgr.setRectX2((anchor.x + anchor.width)*MASTER_DPI/POINT_DPI);\r
+ spgr.setRectY2((anchor.y + anchor.height)*MASTER_DPI/POINT_DPI);\r
}\r
\r
/**\r
*/\r
public void addShape(Shape shape){\r
_escherContainer.addChildRecord(shape.getSpContainer());\r
+\r
+ Sheet sheet = getSheet();\r
+ shape.setSheet(sheet);\r
+ shape.afterInsert(sheet);\r
+\r
+ if(shape instanceof TextBox) {\r
+ TextBox tbox = (TextBox)shape;\r
+ getSheet().getPPDrawing().addTextboxWrapper(tbox._txtbox);\r
+ }\r
}\r
\r
/**\r
ppdrawing.addTextboxWrapper(tbox._txtbox);
}
}
-}
+
+ /**
+ * Return the master sheet .
+ */
+ public MasterSheet getMasterSheet(){
+ return null;
+ }
+
+ /**
+ * Color scheme for this sheet.
+ */
+ public ColorSchemeAtom getColorScheme(){
+ return null;
+ }
+}
\r
import org.apache.poi.ddf.*;\r
import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.hslf.record.ColorSchemeAtom;\r
\r
import java.awt.*;\r
\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();\r
setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);\r
+ setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, color == null ? 0x180010 : 0x180018);\r
}\r
\r
/**\r
*/\r
public Color getLineColor(){\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- EscherRGBProperty prop = (EscherRGBProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);\r
- Color color = Color.black;\r
- if (prop != null){\r
- Color swp = new Color(prop.getRgbColor());\r
- color = new Color(swp.getBlue(), swp.getGreen(), swp.getRed());\r
+\r
+ EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);\r
+ EscherSimpleProperty p2 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);\r
+ int p2val = p2 == null ? 0 : p2.getPropertyValue();\r
+ Color clr = null;\r
+ if (p1 != null && (p2val & 0x8) != 0){\r
+ int rgb = p1.getPropertyValue();\r
+ if (rgb >= 0x8000000) {\r
+ int idx = rgb % 0x8000000;\r
+ ColorSchemeAtom ca = getSheet().getColorScheme();\r
+ if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);\r
+ }\r
+ Color tmp = new Color(rgb, true);\r
+ clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());\r
}\r
- return color;\r
+ return clr;\r
+ }\r
+\r
+ /**\r
+ * Gets line dashing. One of the PEN_* constants defined in this class.\r
+ *\r
+ * @return dashing of the line.\r
+ */\r
+ public int getLineDashing(){\r
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+\r
+ EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);\r
+ return prop == null ? Line.PEN_SOLID : prop.getPropertyValue();\r
+ }\r
+\r
+ /**\r
+ * Sets line dashing. One of the PEN_* constants defined in this class.\r
+ *\r
+ * @param pen new style of the line.\r
+ */\r
+ public void setLineDashing(int pen){\r
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+\r
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == Line.PEN_SOLID ? -1 : pen);\r
}\r
\r
/**\r
*/\r
public void setLineStyle(int style){\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, style == Line.LineSolid ? -1 : style);\r
+ setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == Line.LINE_SIMPLE ? -1 : style);\r
}\r
\r
/**\r
*/\r
public int getLineStyle(){\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
- EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);\r
- return prop == null ? Line.LineSolid : prop.getPropertyValue();\r
+ EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);\r
+ return prop == null ? Line.LINE_SIMPLE : prop.getPropertyValue();\r
+ }\r
+\r
+ /**\r
+ * The color used to fill this shape.\r
+ *\r
+ * @param color the background color\r
+ */\r
+ public Color getFillColor(Color color){\r
+ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
+ EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.FILL__FILLCOLOR);\r
+ EscherSimpleProperty p2= (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);\r
+\r
+ int p2val = p2 == null ? 0 : p2.getPropertyValue();\r
+\r
+ Color clr = null;\r
+ if (p1 != null && (p2val & 0x10) != 0){\r
+ int rgb = p1.getPropertyValue();\r
+ if (rgb >= 0x8000000) {\r
+ int idx = rgb % 0x8000000;\r
+ ColorSchemeAtom ca = getSheet().getColorScheme();\r
+ rgb = ca.getColor(idx);\r
+ }\r
+ Color tmp = new Color(rgb, true);\r
+ clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());\r
+ }\r
+ return clr;\r
}\r
\r
/**\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();\r
setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);\r
- setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 1376273);\r
+ setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, color == null ? 0x150010 : 0x150011);\r
}\r
\r
-\r
}\r
import org.apache.poi.hslf.record.PPDrawing;
import org.apache.poi.hslf.record.SlideAtom;
import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
/**
int i=0;
for(i=0; i<textRuns.size(); i++) {
_runs[i] = (TextRun)textRuns.get(i);
+ _runs[i].setSheet(this);
}
// Grab text from slide's PPDrawing
for(int k=0; k<_otherRuns.length; i++, k++) {
_runs[i] = _otherRuns[k];
+ _runs[i].setSheet(this);
}
}
public TextBox addTitle() {
Placeholder pl = new Placeholder();
pl.setShapeType(ShapeTypes.Rectangle);
- pl.setTextType(TextHeaderAtom.TITLE_TYPE);
+ pl.getTextRun().setRunType(TextHeaderAtom.TITLE_TYPE);
pl.setText("Click to edit title");
pl.setAnchor(new java.awt.Rectangle(54, 48, 612, 90));
addShape(pl);
* which hold text data for this slide (typically for placeholders).
*/
protected SlideAtomsSet getSlideAtomsSet() { return _atomSet; }
-}
+
+ /**
+ * Returns the slide master associated with this slide.
+ *
+ * @return the slide master associated with this slide.
+ */
+ public MasterSheet getMasterSheet(){
+ SlideMaster[] master = getSlideShow().getSlidesMasters();
+ SlideAtom sa = _slide.getSlideAtom();
+ int masterId = sa.getMasterID();
+ for (int i = 0; i < master.length; i++) {
+ if (masterId == master[i]._getSheetNumber()) return master[i];
+ }
+ throw new RuntimeException("Master slide not found for slide " + _slideNo);
+ }
+
+ /**
+ * Change Master of this slide.
+ */
+ public void setMasterSheet(MasterSheet master){
+ SlideAtom sa = _slide.getSlideAtom();
+ int sheetNo = master._getSheetNumber();
+ sa.setMasterID(sheetNo);
+ }
+
+
+ public ColorSchemeAtom getColorScheme(){
+ return _slide.getColorScheme();
+ }
+
+}
--- /dev/null
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed 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 org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.record.StyleTextPropAtom.*;
+
+/**
+ * SlideMaster determines the graphics, layout, and formatting for all the slides in a given presentation.
+ * It stores information about default font styles, placeholder sizes and positions,
+ * background design, and color schemes.
+ *
+ * @author Yegor Kozlov
+ */
+public class SlideMaster extends MasterSheet {
+ private int _refSheetNo;
+ private int _sheetNo;
+ private MainMaster _master;
+ private TextRun[] _runs;
+
+ /**
+ * all TxMasterStyleAtoms available in this master
+ */
+ private TxMasterStyleAtom[] _txmaster;
+
+ /**
+ * Constructs a SlideMaster from the MainMaster record,
+ *
+ */
+ public SlideMaster(org.apache.poi.hslf.record.MainMaster rec, int slideId) {
+ _master = rec;
+
+ // Grab our internal sheet ID
+ _refSheetNo = rec.getSheetId();
+
+ // Grab the number of the slide we're for, via the NotesAtom
+ _sheetNo = slideId;
+
+ _runs = findTextRuns(_master.getPPDrawing());
+ }
+
+ /**
+ * Returns an array of all the TextRuns found
+ */
+ public TextRun[] getTextRuns() {
+ return _runs;
+ }
+
+ /**
+ * Returns the (internal, RefID based) sheet number, as used
+ * to in PersistPtr stuff.
+ */
+ public int _getSheetRefId() {
+ return _refSheetNo;
+ }
+
+ /**
+ * Returns the (internal, SlideIdentifer based) number of the
+ * slide we're attached to
+ */
+ public int _getSheetNumber() {
+ return _sheetNo;
+ }
+
+ /**
+ * Returns the PPDrawing associated with this slide master
+ */
+ protected PPDrawing getPPDrawing() {
+ return _master.getPPDrawing();
+ }
+
+ /**
+ * Pickup a style attribute from the master.
+ * This is the "workhorse" which returns the default style attrubutes.
+ */
+ public TextProp getStyleAttribute(int txtype, int level, String name, boolean isCharacter) {
+
+ TextProp prop = null;
+ for (int i = level; i >= 0; i--) {
+ TextPropCollection[] styles =
+ isCharacter ? _txmaster[txtype].getCharacterStyles() : _txmaster[txtype].getParagraphStyles();
+ if (i < styles.length) prop = styles[i].findByName(name);
+ if (prop != null) break;
+ }
+ if (prop == null) {
+ switch (txtype) {
+ case TextHeaderAtom.CENTRE_BODY_TYPE:
+ case TextHeaderAtom.HALF_BODY_TYPE:
+ case TextHeaderAtom.QUARTER_BODY_TYPE:
+ txtype = TextHeaderAtom.BODY_TYPE;
+ break;
+ case TextHeaderAtom.CENTER_TITLE_TYPE:
+ txtype = TextHeaderAtom.TITLE_TYPE;
+ break;
+ default:
+ return null;
+ }
+ prop = getStyleAttribute(txtype, level, name, isCharacter);
+ }
+ return prop;
+ }
+
+ /**
+ * Assign SlideShow for this slide master.
+ * (Used interanlly)
+ */
+ public void setSlideShow(SlideShow ss) {
+ super.setSlideShow(ss);
+
+ //after the slide show is assigned collect all available style records
+ if (_txmaster == null) {
+ _txmaster = new TxMasterStyleAtom[9];
+
+ TxMasterStyleAtom txdoc = getSlideShow().getDocumentRecord().getEnvironment().getTxMasterStyleAtom();
+ _txmaster[txdoc.getTextType()] = txdoc;
+
+ TxMasterStyleAtom[] txrec = _master.getTxMasterStyleAtoms();
+ for (int i = 0; i < txrec.length; i++) {
+ _txmaster[txrec[i].getTextType()] = txrec[i];
+ }
+ }
+ }
+
+ /**
+ * Returns the ColorSchemeAtom associated with this slide master
+ */
+ public ColorSchemeAtom getColorScheme(){
+ return _master.getColorScheme();
+ }
+
+}
public static final int AlignRight = 2;\r
public static final int AlignJustify = 3;\r
\r
- /**\r
- * Default font size\r
- */\r
- public static final int DefaultFontSize = 24;\r
-\r
/**\r
* Low-level object which holds actual text and format data\r
*/\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);\r
setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);\r
\r
- setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, 134217732);\r
- setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, 134217728);\r
- setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 1048576);\r
- setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 134217729);\r
- setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 524288);\r
- setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 134217730);\r
-\r
- opt.sortProperties();\r
+ setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, 0x8000004);\r
+ setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);\r
+ setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);\r
+ setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);\r
+ setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);\r
+ setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);\r
\r
//create EscherTextboxWrapper\r
_txtbox = new EscherTextboxWrapper();\r
tha.setParentRecord(_txtbox); // TextHeaderAtom is parent aware\r
_txtbox.appendChildRecord(tha);\r
\r
- TextBytesAtom tba = new TextBytesAtom();\r
- _txtbox.appendChildRecord(tba);\r
+ TextCharsAtom tca = new TextCharsAtom();\r
+ _txtbox.appendChildRecord(tca);\r
\r
StyleTextPropAtom sta = new StyleTextPropAtom(0);\r
_txtbox.appendChildRecord(sta);\r
\r
- _txtrun = new TextRun(tha,tba,sta);\r
+ _txtrun = new TextRun(tha,tca,sta);\r
_txtrun.setText("");\r
spcont.addChildRecord(_txtbox.getEscherRecord());\r
\r
}\r
\r
/**\r
- * Returns the bounds of this <code>TextFrame</code>.\r
- * <code>Note</b>, this is very primitive estimation, the precision is poor.\r
- *\r
- * @return the bounds of this <code>TextFrame</code>.\r
+ * Adjust the size of the TextBox so it encompasses the text inside it.\r
*/\r
- protected Dimension getTextDimensions(){\r
+ public void resizeToFitText(){\r
+ try{\r
FontRenderContext frc = new FontRenderContext(null, true, true);\r
RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
int size = rt.getFontSize();\r
- if (size == -1) size = TextBox.DefaultFontSize;\r
int style = 0;\r
if (rt.isBold()) style |= Font.BOLD;\r
if (rt.isItalic()) style |= Font.ITALIC;\r
String fntname = rt.getFontName();\r
- if (fntname == null) //get the default font from Document.Environment.FontCollection\r
- fntname = getSheet().getSlideShow().getDocumentRecord().getEnvironment().getFontCollection().getFontWithId(0);\r
Font font = new Font(fntname, style, size);\r
\r
TextLayout layout = new TextLayout(getText(), font, frc);\r
int width = Math.round(layout.getAdvance());\r
- width += getMarginLeft() + getMarginRight() + 2;\r
int height = Math.round(layout.getAscent());\r
- height += getMarginTop() + getMarginBottom() + 12;\r
- return new Dimension(width, height);\r
- }\r
\r
- /**\r
- * Adjust the size of the TextBox so it encompasses the text inside it.\r
- */\r
- public void resizeToFitText(){\r
- Dimension size = getTextDimensions();\r
+ Dimension txsize = new Dimension(width, height);\r
java.awt.Rectangle anchor = getAnchor();\r
- anchor.setSize(size);\r
+ anchor.setSize(txsize);\r
setAnchor(anchor);\r
+ } catch (Exception e){\r
+ e.printStackTrace();\r
+\r
+ }\r
}\r
\r
/**\r
public int getVerticalAlignment(){\r
EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);\r
EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);\r
- return prop == null ? AlignCenter : prop.getPropertyValue();\r
+ int valign;\r
+ if (prop == null){\r
+ int type = getTextRun().getRunType();\r
+ switch (type){\r
+ case TextHeaderAtom.TITLE_TYPE:\r
+ case TextHeaderAtom.CENTER_TITLE_TYPE:\r
+ valign = TextBox.AnchorMiddle;\r
+ break;\r
+ default:\r
+ valign = TextBox.AnchorTop;\r
+ break;\r
+ }\r
+ } else {\r
+ valign = prop.getPropertyValue();\r
+ }\r
+ return valign;\r
}\r
\r
/**\r
return _txtrun;\r
}\r
\r
- /**\r
- * @return array of RichTextRun objects which control text formatting in this text box\r
- */\r
- public RichTextRun[] getRichTextRuns(){\r
- return _txtrun.getRichTextRuns();\r
- }\r
-\r
- /**\r
- * Sets the <code>Font</code> object for this text frame\r
- *\r
- * @param size the size of the font\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public void setFontSize(int size){\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- rt.setFontSize(size);\r
- }\r
-\r
- /**\r
- *\r
- * @return the size of the font applied to this text shape\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public int getFontSize(){\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- return rt.getFontSize();\r
- }\r
-\r
- /**\r
- *\r
- * @return the size of the font applied to this text shape\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public Color getFontColor(){\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- Color color = new Color(rt.getFontColor());\r
- //in PowerPont RGB bytes are swapped,\r
- return new Color(color.getBlue(), color.getGreen(), color.getRed(), 255);\r
- }\r
-\r
- /**\r
- * Set whether to use bold or not\r
- *\r
- * @param bold <code>true</code> if the text should be bold, <code>false</code> otherwise\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public void setBold(boolean bold){\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- rt.setBold(bold);\r
- }\r
-\r
- /**\r
- * Set whether to use italic or not\r
- *\r
- * @param italic <code>true</code> if the text should be italic, <code>false</code> otherwise\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public void setItalic(boolean italic){\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- rt.setItalic(italic);\r
- }\r
-\r
- /**\r
- * Set whether to use underline or not\r
- *\r
- * @param underline <code>true</code> if the text should be underlined, <code>false</code> otherwise\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public void setUnderline(boolean underline){\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- rt.setUnderlined(underline);\r
- }\r
-\r
- /**\r
- * Sets the font of this text shape\r
- *\r
- * @param name the name of the font to be applied to this text shape\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public void setFontName(String name){\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- rt.setFontName(name);\r
- }\r
-\r
- /**\r
- * Sets the font color\r
- * @param color the font color\r
- *\r
- * @deprecated Use <code>RichTextRun</code> to work with the text format.\r
- * <p>This method will be permanently removed in a future version of the POI HSLF API.</p>\r
- */\r
- public void setFontColor(Color color){\r
- //in PowerPont RGB bytes are swapped,\r
- int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 254).getRGB();\r
- RichTextRun rt = _txtrun.getRichTextRuns()[0];\r
- rt.setFontColor(rgb);\r
- }\r
-\r
- /**\r
- * Set type of the text.\r
- * Must be one of the static constants defined in <code>TextHeaderAtom</code>\r
- *\r
- * @param type type of the text\r
- */\r
- public void setTextType(int type){\r
- _txtrun._headerAtom.setTextType(type);\r
- }\r
- \r
- public void setSheet(Sheet sheet){\r
+ public void setSheet(Sheet sheet){\r
_sheet = sheet;\r
\r
// Initialize _txtrun object.\r
}\r
\r
// Supply the sheet to our child RichTextRuns\r
+ _txtrun.setSheet(sheet);\r
RichTextRun[] rt = _txtrun.getRichTextRuns();\r
for (int i = 0; i < rt.length; i++) {\r
rt[i].supplySlideShow(_sheet.getSlideShow());\r
protected boolean _isUnicode;
protected RichTextRun[] _rtRuns;
private SlideShow slideShow;
+ private Sheet sheet;
/**
* Constructs a Text Run from a Unicode text block
public synchronized void setText(String s) {
// Save the new text to the atoms
storeText(s);
-
+ RichTextRun fst = _rtRuns[0];
+
// Finally, zap and re-do the RichTextRuns
for(int i=0; i<_rtRuns.length; i++) { _rtRuns[i] = null; }
_rtRuns = new RichTextRun[1];
+ _rtRuns[0] = fst;
// Now handle record stylings:
// If there isn't styling
LinkedList cStyles = _styleAtom.getCharacterStyles();
while(cStyles.size() > 1) { cStyles.removeLast(); }
- // Note - TextPropCollection's idea of the text length must
- // be one larger than it actually is!
- // (This indicates that new text added to the end should
- // get the same styling as the current text)
- TextPropCollection pCol = (TextPropCollection)pStyles.getFirst();
- TextPropCollection cCol = (TextPropCollection)cStyles.getFirst();
- pCol.updateTextSize(s.length()+1);
- cCol.updateTextSize(s.length()+1);
-
- // Recreate rich text run with first styling
- _rtRuns[0] = new RichTextRun(this,0,s.length(), pCol, cCol, false, false);
+ _rtRuns[0].setText(s);
} else {
// Recreate rich text run with no styling
_rtRuns[0] = new RichTextRun(this,0,s.length());
}
}
}
-}
+
+ public void setSheet(Sheet sheet){
+ this.sheet = sheet;
+ }
+
+ public Sheet getSheet(){
+ return this.sheet;
+ }
+}
writeLittleEndian(accentAndHyperlinkColourRGB,out);
writeLittleEndian(accentAndFollowingHyperlinkColourRGB,out);
}
+
+ /**
+ * Returns color by its index
+ *
+ * @param idx 0-based color index
+ * @return color by its index
+ */
+ public int getColor(int idx){
+ int[] clr = {backgroundColourRGB, textAndLinesColourRGB, shadowsColourRGB, titleTextColourRGB,
+ fillsColourRGB, accentColourRGB, accentAndHyperlinkColourRGB, accentAndFollowingHyperlinkColourRGB};
+ return clr[idx];
+ }
+
}
// Links to our more interesting children
private FontCollection fontCollection;
+ //master style for text with type=TextHeaderAtom.OTHER_TYPE
+ private TxMasterStyleAtom txmaster;
/**
* Returns the FontCollection of this Environment
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof FontCollection) {
fontCollection = (FontCollection)_children[i];
- }
+ } else if (_children[i] instanceof TxMasterStyleAtom){
+ txmaster = (TxMasterStyleAtom)_children[i];
+ }
}
if(fontCollection == null) {
}
}
+ public TxMasterStyleAtom getTxMasterStyleAtom(){
+ return txmaster;
+ }
/**
* We are of type 1010
--- /dev/null
+
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed 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.record;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Master slide
+ *
+ * @author Yegor Kozlov
+ */
+
+public class MainMaster extends PositionDependentRecordContainer
+{
+ private byte[] _header;
+ private static long _type = 1016;
+
+ // Links to our more interesting children
+ private SlideAtom slideAtom;
+ private PPDrawing ppDrawing;
+ private TxMasterStyleAtom[] txmasters;
+ private ColorSchemeAtom[] clrscheme;
+ private ColorSchemeAtom _colorScheme;
+
+ /**
+ * Returns the SlideAtom of this Slide
+ */
+ public SlideAtom getSlideAtom() { return slideAtom; }
+
+ /**
+ * Returns the PPDrawing of this Slide, which has all the
+ * interesting data in it
+ */
+ public PPDrawing getPPDrawing() { return ppDrawing; }
+
+ public TxMasterStyleAtom[] getTxMasterStyleAtoms() { return txmasters; }
+
+ public ColorSchemeAtom[] getColorSchemeAtoms() { return clrscheme; }
+
+ /**
+ * Set things up, and find our more interesting children
+ */
+ protected MainMaster(byte[] source, int start, int len) {
+ // Grab the header
+ _header = new byte[8];
+ System.arraycopy(source,start,_header,0,8);
+
+ // Find our children
+ _children = Record.findChildRecords(source,start+8,len-8);
+
+ ArrayList tx = new ArrayList();
+ ArrayList clr = new ArrayList();
+ // Find the interesting ones in there
+ for(int i=0; i<_children.length; i++) {
+ if(_children[i] instanceof SlideAtom) {
+ slideAtom = (SlideAtom)_children[i];
+ } else if(_children[i] instanceof PPDrawing) {
+ ppDrawing = (PPDrawing)_children[i];
+ } else if(_children[i] instanceof TxMasterStyleAtom) {
+ tx.add(_children[i]);
+ } else if(_children[i] instanceof ColorSchemeAtom) {
+ clr.add(_children[i]);
+ }
+
+ if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
+ _colorScheme = (ColorSchemeAtom)_children[i];
+ }
+
+ }
+ txmasters = (TxMasterStyleAtom[])tx.toArray(new TxMasterStyleAtom[tx.size()]);
+ clrscheme = (ColorSchemeAtom[])clr.toArray(new ColorSchemeAtom[clr.size()]);
+ }
+
+ /**
+ * We are of type 1016
+ */
+ public long getRecordType() { return _type; }
+
+ /**
+ * Write the contents of the record back, so it can be written
+ * to disk
+ */
+ public void writeOut(OutputStream out) throws IOException {
+ writeOut(_header[0],_header[1],_type,_children,out);
+ }
+
+ public ColorSchemeAtom getColorScheme(){
+ return _colorScheme;
+ }
+
+}
public static final Type Environment = new Type(1010,Environment.class);
public static final Type SlidePersistAtom = new Type(1011,SlidePersistAtom.class);
public static final Type SSlideLayoutAtom = new Type(1015,null);
- public static final Type MainMaster = new Type(1016,DummyPositionSensitiveRecordWithChildren.class);
+ public static final Type MainMaster = new Type(1016,MainMaster.class);
public static final Type SSSlideInfoAtom = new Type(1017,null);
public static final Type SlideViewInfo = new Type(1018,null);
public static final Type GuideAtom = new Type(1019,null);
// Links to our more interesting children
private SlideAtom slideAtom;
private PPDrawing ppDrawing;
+ private ColorSchemeAtom _colorScheme;
/**
* Returns the SlideAtom of this Slide
if(_children[i] instanceof SlideAtom) {
slideAtom = (SlideAtom)_children[i];
}
- if(_children[i] instanceof PPDrawing) {
+ else if(_children[i] instanceof PPDrawing) {
ppDrawing = (PPDrawing)_children[i];
}
+
+ if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
+ _colorScheme = (ColorSchemeAtom)_children[i];
+ }
}
}
public void writeOut(OutputStream out) throws IOException {
writeOut(_header[0],_header[1],_type,_children,out);
}
+
+ public ColorSchemeAtom getColorScheme(){
+ return _colorScheme;
+ }
}
/** Get the ID of the master slide used. 0 if this is a master slide, otherwise -2147483648 */
public int getMasterID() { return masterID; }
+ /** Change slide master. */
+ public void setMasterID(int id) { masterID = id; }
/** Get the ID of the notes for this slide. 0 if doesn't have one */
public int getNotesID() { return notesID; }
/** Get the embeded SSlideLayoutAtom */
package org.apache.poi.hslf.usermodel;
import org.apache.poi.hslf.model.TextRun;
+import org.apache.poi.hslf.model.Sheet;
+import org.apache.poi.hslf.model.SlideMaster;
import org.apache.poi.hslf.record.StyleTextPropAtom.CharFlagsTextProp;
import org.apache.poi.hslf.record.StyleTextPropAtom.TextProp;
import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
+import org.apache.poi.hslf.record.ColorSchemeAtom;
import java.awt.*;
/** How long a string (in the parent TextRun) we represent */
private int length;
- /**
+ private String _fontname;
+ /**
* Our paragraph and character style.
* Note - we may share these styles with other RichTextRuns
*/
private boolean sharingParagraphStyle;
private boolean sharingCharacterStyle;
- private String _fontname;
/**
* Create a new wrapper around a (currently not)
* rich text string
* text property won't be set if there's no CharFlagsTextProp.
*/
private boolean isCharFlagsTextPropVal(int index) {
- if(characterStyle == null) { return false; }
-
- CharFlagsTextProp cftp = (CharFlagsTextProp)
- characterStyle.findByName("char_flags");
-
- if(cftp == null) { return false; }
- return cftp.getSubValue(index);
+ CharFlagsTextProp cftp = null;
+ if (characterStyle != null){
+ cftp = (CharFlagsTextProp)characterStyle.findByName("char_flags");
+ }
+ if (cftp == null){
+ Sheet sheet = parentRun.getSheet();
+ int txtype = parentRun.getRunType();
+ SlideMaster master = (SlideMaster)sheet.getMasterSheet();
+ cftp = (CharFlagsTextProp)master.getStyleAttribute(txtype, getIndentLevel(), "char_flags", true);
+ }
+
+ return cftp == null ? false : cftp.getSubValue(index);
}
+
/**
* Set the value of the given flag in the CharFlagsTextProp, adding
* it if required.
* Master Sheet will apply.
*/
private int getCharTextPropVal(String propName) {
- if(characterStyle == null) { return -1; }
-
- TextProp cTextProp = characterStyle.findByName(propName);
- if(cTextProp == null) { return -1; }
- return cTextProp.getValue();
+ TextProp prop = null;
+ if (characterStyle != null){
+ prop = characterStyle.findByName(propName);
+ }
+
+ if (prop == null){
+ Sheet sheet = parentRun.getSheet();
+ int txtype = parentRun.getRunType();
+ SlideMaster master = (SlideMaster)sheet.getMasterSheet();
+ prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, true);
+ }
+ return prop == null ? -1 : prop.getValue();
}
/**
- * Fetch the value of the given Paragraph related TextProp.
- * Returns -1 if that TextProp isn't present.
- * If the TextProp isn't present, the value from the appropriate
+ * Fetch the value of the given Paragraph related TextProp.
+ * Returns -1 if that TextProp isn't present.
+ * If the TextProp isn't present, the value from the appropriate
* Master Sheet will apply.
*/
private int getParaTextPropVal(String propName) {
- if(paragraphStyle == null) { return -1; }
-
- TextProp pTextProp = paragraphStyle.findByName(propName);
- if(pTextProp == null) { return -1; }
- return pTextProp.getValue();
+ TextProp prop = null;
+ if (paragraphStyle != null){
+ prop = paragraphStyle.findByName(propName);
+ }
+ if (prop == null){
+ Sheet sheet = parentRun.getSheet();
+ int txtype = parentRun.getRunType();
+ SlideMaster master = (SlideMaster)sheet.getMasterSheet();
+ prop = master.getStyleAttribute(txtype, getIndentLevel(), propName, false);
+ }
+
+ return prop == null ? -1 : prop.getValue();
}
/**
if (slideShow == null) {
//we can't set font since slideshow is not assigned yet
_fontname = fontName;
- } else{
- // Get the index for this font (adding if needed)
- int fontIdx = slideShow.getFontCollection().addFont(fontName);
- setCharTextPropVal("font.index", fontIdx);
- }
+ } else {
+ // Get the index for this font (adding if needed)
+ int fontIdx = slideShow.getFontCollection().addFont(fontName);
+ setCharTextPropVal("font.index", fontIdx);
+ }
}
public String getFontName() {
- int fontIdx = getCharTextPropVal("font.index");
- if(fontIdx == -1) { return null; }
- return slideShow.getFontCollection().getFontWithId(fontIdx);
+ if (slideShow == null) {
+ return _fontname;
+ } else {
+ int fontIdx = getCharTextPropVal("font.index");
+ if(fontIdx == -1) { return null; }
+ return slideShow.getFontCollection().getFontWithId(fontIdx);
+ }
}
/**
* @return font color as RGB value
* @see java.awt.Color
*/
- public int getFontColor() {
- return getCharTextPropVal("font.color");
+ public Color getFontColor() {
+ int rgb = getCharTextPropVal("font.color");
+ if (rgb >= 0x8000000) {
+ int idx = rgb % 0x8000000;
+ ColorSchemeAtom ca = parentRun.getSheet().getColorScheme();
+ if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
+ }
+
+ Color tmp = new Color(rgb, true);
+ return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
}
+
/**
- * Sets color of the text, as a RGB value
+ * Sets color of the text, as a int rgb
* @see java.awt.Color
*/
public void setFontColor(int rgb) {
private Document _documentRecord;
// Friendly objects for people to deal with
+ private SlideMaster[] _masters;
private Slide[] _slides;
private Notes[] _notes;
private FontCollection _fonts;
- // MetaSheets (eg masters) not yet supported
- // private MetaSheets[] _msheets;
/* ===============================================================
SlideListWithText slidesSLWT = _documentRecord.getSlideSlideListWithText();
SlideListWithText notesSLWT = _documentRecord.getNotesSlideListWithText();
+ //find master slides
+ SlideAtomsSet[] masterSets = new SlideAtomsSet[0];
+ org.apache.poi.hslf.record.MainMaster[] masterRecords = null;
+ if (masterSLWT != null){
+
+ masterSets = masterSLWT.getSlideAtomsSets();
+ masterRecords = new org.apache.poi.hslf.record.MainMaster[masterSets.length];
+ for(int i=0; i<masterRecords.length; i++) {
+ masterRecords[i] = (org.apache.poi.hslf.record.MainMaster)getCoreRecordForSAS(masterSets[i]);
+ }
+ }
+
// Start by finding the notes records to go with the entries in
// notesSLWT
org.apache.poi.hslf.record.Notes[] notesRecords;
}
// Finally, generate model objects for everything
+ _masters = new SlideMaster[masterRecords.length];
+ for(int i=0; i<_masters.length; i++) {
+ SlideAtomsSet sas = masterSets[i];
+ int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
+ _masters[i] = new SlideMaster(masterRecords[i], sheetNo);
+ _masters[i].setSlideShow(this);
+ }
+
// Notes first
_notes = new Notes[notesRecords.length];
for(int i=0; i<_notes.length; i++) {
public Notes[] getNotes() { return _notes; }
/**
- * Returns an array of all the meta Sheets (master sheets etc)
- * found in the slideshow
+ * Returns an array of all the normal Slides found in the slideshow
*/
- //public MetaSheet[] getMetaSheets() { return _msheets; }
+ public SlideMaster[] getSlidesMasters() { return _masters; }
/**
* Returns the data of all the pictures attached to the SlideShow
--- /dev/null
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed 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 junit.framework.*;
+
+import java.io.FileOutputStream;
+import java.awt.*;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.HSLFSlideShow;
+
+/**
+ * Test Line shape.
+ *
+ * @author Yegor Kozlov
+ */
+public class TestLine extends TestCase {
+
+ public void setUp() throws Exception {
+
+ }
+
+ public void testCreateLines() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ slide.addTitle().setText("Lines tester");
+
+ Line line;
+
+ /**
+ * line styles
+ */
+ line = new Line();
+ line.setAnchor(new Rectangle(75, 200, 300, 0));
+ line.setLineStyle(Line.LINE_SIMPLE);
+ line.setLineColor(Color.blue);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(75, 230, 300, 0));
+ line.setLineStyle(Line.LINE_DOUBLE);
+ line.setLineWidth(3.5);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(75, 260, 300, 0));
+ line.setLineStyle(Line.LINE_TRIPLE);
+ line.setLineWidth(6);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(75, 290, 300, 0));
+ line.setLineStyle(Line.LINE_THICKTHIN);
+ line.setLineWidth(4.5);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(75, 320, 300, 0));
+ line.setLineStyle(Line.LINE_THINTHICK);
+ line.setLineWidth(5.5);
+ slide.addShape(line);
+
+ /**
+ * line dashing
+ */
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(450, 200, 300, 0));
+ line.setLineDashing(Line.PEN_SOLID);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(450, 230, 300, 0));
+ line.setLineDashing(Line.PEN_PS_DASH);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(450, 260, 300, 0));
+ line.setLineDashing(Line.PEN_DOT);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(450, 290, 300, 0));
+ line.setLineDashing(Line.PEN_DOTGEL);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(450, 320, 300, 0));
+ line.setLineDashing(Line.PEN_LONGDASHDOTDOTGEL);
+ slide.addShape(line);
+
+ /**
+ * Combinations
+ */
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(75, 400, 300, 0));
+ line.setLineDashing(Line.PEN_DASHDOT);
+ line.setLineStyle(Line.LINE_TRIPLE);
+ line.setLineWidth(5.0);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(75, 430, 300, 0));
+ line.setLineDashing(Line.PEN_DASH);
+ line.setLineStyle(Line.LINE_THICKTHIN);
+ line.setLineWidth(4.0);
+ slide.addShape(line);
+
+ line = new Line();
+ line.setAnchor(new java.awt.Rectangle(75, 460, 300, 0));
+ line.setLineDashing(Line.PEN_DOT);
+ line.setLineStyle(Line.LINE_DOUBLE);
+ line.setLineWidth(8.0);
+ slide.addShape(line);
+
+ }
+
+}
\r
// Create a new textbox, and give it lots of properties\r
TextBox txtbox = new TextBox();\r
+ rt = txtbox.getTextRun().getRichTextRuns()[0];\r
txtbox.setText(val);\r
- txtbox.setFontSize(42);\r
- txtbox.setBold(true);\r
- txtbox.setItalic(true);\r
- txtbox.setUnderline(false);\r
+ rt.setFontSize(42);\r
+ rt.setBold(true);\r
+ rt.setItalic(true);\r
+ rt.setUnderlined(false);\r
sl.addShape(txtbox);\r
\r
// Check it before save\r
- rt = txtbox.getRichTextRuns()[0];\r
+ rt = txtbox.getTextRun().getRichTextRuns()[0];\r
assertEquals(val, rt.getText());\r
assertEquals(42, rt.getFontSize());\r
assertTrue(rt.isBold());\r
sl = ppt.getSlides()[0];\r
\r
txtbox = (TextBox)sl.getShapes()[0];\r
- rt = txtbox.getRichTextRuns()[0];\r
+ rt = txtbox.getTextRun().getRichTextRuns()[0];\r
\r
// Check after save\r
assertEquals(val, rt.getText());\r
Line line = new Line();\r
java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);\r
line.setAnchor(lineAnchor);\r
- System.out.println(line.getAnchor());\r
line.setLineWidth(3);\r
- line.setLineStyle(Line.LineDashSys);\r
+ line.setLineStyle(Line.PEN_DASH);\r
line.setLineColor(Color.red);\r
slide.addShape(line);\r
\r
java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);\r
ellipse.setAnchor(ellipseAnchor);\r
ellipse.setLineWidth(2);\r
- ellipse.setLineStyle(Line.LineSolid);\r
+ ellipse.setLineStyle(Line.PEN_SOLID);\r
ellipse.setLineColor(Color.green);\r
ellipse.setFillColor(Color.lightGray);\r
slide.addShape(ellipse);\r
String text = txtbox.getText();\r
assertNotNull(text);\r
\r
- assertEquals(txtbox.getRichTextRuns().length, 1);\r
- RichTextRun rt = txtbox.getRichTextRuns()[0];\r
+ assertEquals(txtbox.getTextRun().getRichTextRuns().length, 1);\r
+ RichTextRun rt = txtbox.getTextRun().getRichTextRuns()[0];\r
\r
if (text.equals("Hello, World!!!")){\r
assertEquals(32, rt.getFontSize());\r
\r
// Create a new textbox, and give it lots of properties\r
TextBox txtbox = new TextBox();\r
+ rt = txtbox.getTextRun().getRichTextRuns()[0];\r
txtbox.setText(val);\r
- txtbox.setFontName("Arial");\r
- txtbox.setFontSize(42);\r
- txtbox.setBold(true);\r
- txtbox.setItalic(true);\r
- txtbox.setUnderline(false);\r
- txtbox.setFontColor(Color.red);\r
+ rt.setFontName("Arial");\r
+ rt.setFontSize(42);\r
+ rt.setBold(true);\r
+ rt.setItalic(true);\r
+ rt.setUnderlined(false);\r
+ rt.setFontColor(Color.red);\r
sl.addShape(txtbox);\r
\r
// Check it before save\r
- rt = txtbox.getRichTextRuns()[0];\r
+ rt = txtbox.getTextRun().getRichTextRuns()[0];\r
assertEquals(val, rt.getText());\r
assertEquals(42, rt.getFontSize());\r
assertTrue(rt.isBold());\r
assertTrue(rt.isItalic());\r
assertFalse(rt.isUnderlined());\r
assertEquals("Arial", rt.getFontName());\r
- assertEquals(Color.red, txtbox.getFontColor());\r
+ assertEquals(Color.red, rt.getFontColor());\r
\r
// Serialize and read again\r
ByteArrayOutputStream out = new ByteArrayOutputStream();\r
ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
\r
txtbox = (TextBox)sl.getShapes()[0];\r
- rt = txtbox.getRichTextRuns()[0];\r
+ rt = txtbox.getTextRun().getRichTextRuns()[0];\r
\r
// Check after save\r
assertEquals(val, rt.getText());\r
assertTrue(rt.isItalic());\r
assertFalse(rt.isUnderlined());\r
assertEquals("Arial", rt.getFontName());\r
- assertEquals(Color.red, txtbox.getFontColor());\r
+ assertEquals(Color.red, rt.getFontColor());\r
}\r
\r
/**\r
--- /dev/null
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed 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 junit.framework.TestCase;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.record.*;
+import org.apache.poi.hslf.record.StyleTextPropAtom.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Tests for SlideMaster
+ *
+ * @author Yegor Kozlov
+ */
+public class TestSlideMaster extends TestCase{
+ String home;
+
+ public void setUp() throws Exception {
+ home = System.getProperty("HSLF.testdata.path");
+ }
+
+ /**
+ * The reference ppt has two masters.
+ * Check we can read their attributes.
+ */
+ public void testSlideMaster() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
+
+ Environment env = ppt.getDocumentRecord().getEnvironment();
+
+ SlideMaster[] master = ppt.getSlidesMasters();
+ assertEquals(2, master.length);
+
+ //character attributes
+ assertEquals(40, master[0].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
+ assertEquals(48, master[1].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
+
+ int font1 = master[0].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
+ int font2 = master[1].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
+ assertEquals("Arial", env.getFontCollection().getFontWithId(font1));
+ assertEquals("Georgia", env.getFontCollection().getFontWithId(font2));
+
+ CharFlagsTextProp prop1 = (CharFlagsTextProp)master[0].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
+ assertEquals(false, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
+ assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+ assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+
+ CharFlagsTextProp prop2 = (CharFlagsTextProp)master[1].getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
+ assertEquals(false, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
+ assertEquals(true, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+ assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+
+ //now paragraph attributes
+ assertEquals(0x266B, master[0].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
+ assertEquals(0x2022, master[1].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
+
+ int b1 = master[0].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
+ int b2 = master[1].getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
+ assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
+ assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
+ }
+
+ /**
+ * If a style attribute is not set ensure it is read from the master
+ */
+ public void testMasterAttributes() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
+ Slide[] slide = ppt.getSlides();
+ assertEquals(2, slide.length);
+ TextRun[] trun;
+
+ trun = slide[0].getTextRuns();
+ for (int i = 0; i < trun.length; i++) {
+ if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
+ RichTextRun rt = trun[i].getRichTextRuns()[0];
+ assertEquals(40, rt.getFontSize());
+ assertEquals(true, rt.isUnderlined());
+ assertEquals("Arial", rt.getFontName());
+ } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
+ RichTextRun rt;
+ rt = trun[i].getRichTextRuns()[0];
+ assertEquals(0, rt.getIndentLevel());
+ assertEquals(32, rt.getFontSize());
+ assertEquals("Arial", rt.getFontName());
+
+ rt = trun[i].getRichTextRuns()[1];
+ assertEquals(1, rt.getIndentLevel());
+ assertEquals(28, rt.getFontSize());
+ assertEquals("Arial", rt.getFontName());
+
+ }
+ }
+
+ trun = slide[1].getTextRuns();
+ for (int i = 0; i < trun.length; i++) {
+ if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
+ RichTextRun rt = trun[i].getRichTextRuns()[0];
+ assertEquals(48, rt.getFontSize());
+ assertEquals(true, rt.isItalic());
+ assertEquals("Georgia", rt.getFontName());
+ } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
+ RichTextRun rt;
+ rt = trun[i].getRichTextRuns()[0];
+ assertEquals(0, rt.getIndentLevel());
+ assertEquals(32, rt.getFontSize());
+ assertEquals("Courier New", rt.getFontName());
+ }
+ }
+
+ }
+
+ /**
+ * Check we can dynamically assign a slide master to a slide.
+ */
+ public void testChangeSlideMaster() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
+ SlideMaster[] master = ppt.getSlidesMasters();
+ Slide[] slide = ppt.getSlides();
+ int sheetNo;
+
+ //each slide uses its own master
+ assertEquals(slide[0].getMasterSheet()._getSheetNumber(), master[0]._getSheetNumber());
+ assertEquals(slide[1].getMasterSheet()._getSheetNumber(), master[1]._getSheetNumber());
+
+ //all slides use the first master slide
+ sheetNo = master[0]._getSheetNumber();
+ for (int i = 0; i < slide.length; i++) {
+ slide[i].setMasterSheet(master[0]);
+ }
+
+ ByteArrayOutputStream out;
+
+ out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ master = ppt.getSlidesMasters();
+ slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ assertEquals(sheetNo, slide[i].getMasterSheet()._getSheetNumber());
+ }
+ }
+
+ /**
+ * Varify we can read attrubutes for different identtation levels.
+ * (typical for the "bullted body" placeholder)
+ */
+ public void testIndentation() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(home + "/slide_master.ppt"));
+ Slide slide = ppt.getSlides()[0];
+ TextRun[] trun;
+
+ trun = slide.getTextRuns();
+ for (int i = 0; i < trun.length; i++) {
+ if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
+ RichTextRun rt = trun[i].getRichTextRuns()[0];
+ assertEquals(40, rt.getFontSize());
+ assertEquals(true, rt.isUnderlined());
+ assertEquals("Arial", rt.getFontName());
+ } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
+ RichTextRun[] rt = trun[i].getRichTextRuns();
+ for (int j = 0; j < rt.length; j++) {
+ int indent = rt[j].getIndentLevel();
+ switch (indent){
+ case 0:
+ assertEquals(32, rt[j].getFontSize());
+ break;
+ case 1:
+ assertEquals(28, rt[j].getFontSize());
+ break;
+ case 2:
+ assertEquals(24, rt[j].getFontSize());
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+}
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.model.TextRun;
+import org.apache.poi.hslf.model.SlideMaster;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.SlideListWithText;
* rich text runs
*/
public void testFontSize() throws Exception {
- Slide slideOne = ss.getSlides()[0];
+ SlideMaster master;
+ Slide slideOne = ss.getSlides()[0];
TextRun[] textRuns = slideOne.getTextRuns();
RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
RichTextRun rtrRb = textRunsR[1].getRichTextRuns()[0];
RichTextRun rtrRc = textRunsR[1].getRichTextRuns()[3];
+ String defaultFont = "Arial";
+
// Start off with rich one
// First run has defaults
- assertEquals(-1, rtrRa.getFontSize());
- assertEquals(null, rtrRa.getFontName());
+ assertEquals(44, rtrRa.getFontSize());
+ assertEquals(defaultFont, rtrRa.getFontName());
+
// Second is size 20, default font
assertEquals(20, rtrRb.getFontSize());
- assertEquals(null, rtrRb.getFontName());
+ assertEquals(defaultFont, rtrRb.getFontName());
// Third is size 24, alt font
assertEquals(24, rtrRc.getFontSize());
assertEquals("Times New Roman", rtrRc.getFontName());
// Now do non rich one
- assertEquals(-1, rtr.getFontSize());
- assertEquals(null, rtr.getFontName());
+ assertEquals(44, rtr.getFontSize());
+ assertEquals(defaultFont, rtr.getFontName());
assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
assertNull(rtr._getRawCharacterStyle());
assertNull(rtr._getRawParagraphStyle());
// Change Font size
rtr.setFontSize(99);
assertEquals(99, rtr.getFontSize());
- assertEquals(null, rtr.getFontName());
+ assertEquals(defaultFont, rtr.getFontName());
assertNotNull(rtr._getRawCharacterStyle());
assertNotNull(rtr._getRawParagraphStyle());
assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default