Get Shape Effective Properties from Presentations in Java
Overview
This topic explains the difference between local and effective properties. Local values are values that are set directly at a specific formatting level, such as:
- Portion properties on a slide.
- Prototype shape text styles on a layout or master slide, when the portion’s text frame shape has one.
- Global text settings in a presentation.
Local values can be defined or omitted at any level. When Aspose.Slides needs the final “as rendered” formatting, it resolves the inheritance chain and returns effective values. You can get them by calling the getEffective method on the local format object.
The following example shows how to get effective values. It assumes that the first shape on the first slide is an IAutoShape with a text frame and at least one portion.
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = (IAutoShape)slide.getShapes().get_Item(0);
ITextFrameFormat localTextFrameFormat = shape.getTextFrame().getTextFrameFormat();
ITextFrameFormatEffectiveData effectiveTextFrameFormat = localTextFrameFormat.getEffective();
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortion portion = paragraph.getPortions().get_Item(0);
IPortionFormat localPortionFormat = portion.getPortionFormat();
IPortionFormatEffectiveData effectivePortionFormat = localPortionFormat.getEffective();
} finally {
presentation.dispose();
}
getEffective again after changing parent or inherited formatting can refresh the cached data, and a previously obtained object may no longer represent the earlier state. If you need to preserve effective values for later reuse, copy the required properties, such as font height, fill color, font style, or alignment, into your own data object.
Get Effective Properties of a Camera
Aspose.Slides allows you to get effective properties of a camera. The ICameraEffectiveData interface represents an immutable object that contains effective camera properties. An ICameraEffectiveData instance is exposed through IThreeDFormatEffectiveData, which provides effective values for IThreeDFormat.
The following code sample shows how to get effective properties for the camera. It assumes that the first shape on the first slide has 3D formatting.
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IShape shape = slide.getShapes().get_Item(0);
IThreeDFormatEffectiveData threeDEffectiveData = shape.getThreeDFormat().getEffective();
ICameraEffectiveData cameraEffectiveData = threeDEffectiveData.getCamera();
int cameraType = cameraEffectiveData.getCameraType();
double fieldOfViewAngle = cameraEffectiveData.getFieldOfViewAngle();
double zoom = cameraEffectiveData.getZoom();
System.out.println("= Effective camera properties =");
System.out.println("Type: " + cameraType);
System.out.println("Field of view: " + fieldOfViewAngle);
System.out.println("Zoom: " + zoom);
} finally {
presentation.dispose();
}
Get Effective Properties of a Light Rig
Aspose.Slides allows you to get effective properties of a light rig. The ILightRigEffectiveData interface represents an immutable object that contains effective light rig properties. An ILightRigEffectiveData instance is exposed through IThreeDFormatEffectiveData, which provides effective values for IThreeDFormat.
The following code sample shows how to get effective properties for the light rig. It assumes that the first shape on the first slide has 3D formatting.
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IShape shape = slide.getShapes().get_Item(0);
IThreeDFormatEffectiveData threeDEffectiveData = shape.getThreeDFormat().getEffective();
ILightRigEffectiveData lightRigEffectiveData = threeDEffectiveData.getLightRig();
int lightType = lightRigEffectiveData.getLightType();
int direction = lightRigEffectiveData.getDirection();
System.out.println("= Effective light rig properties =");
System.out.println("Type: " + lightType);
System.out.println("Direction: " + direction);
} finally {
presentation.dispose();
}
Get Effective Properties of a Bevel Shape
Aspose.Slides allows you to get effective properties of a shape bevel. The IShapeBevelEffectiveData interface represents an immutable object that contains effective face-relief properties for a shape. An IShapeBevelEffectiveData instance is exposed through IThreeDFormatEffectiveData, which provides effective values for IThreeDFormat.
The following code sample shows how to get effective properties for the top bevel of a shape. It assumes that the first shape on the first slide has 3D formatting.
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IShape shape = slide.getShapes().get_Item(0);
IThreeDFormatEffectiveData threeDEffectiveData = shape.getThreeDFormat().getEffective();
IShapeBevelEffectiveData bevelTop = threeDEffectiveData.getBevelTop();
int bevelType = bevelTop.getBevelType();
double bevelWidth = bevelTop.getWidth();
double bevelHeight = bevelTop.getHeight();
System.out.println("= Effective shape's top face relief properties =");
System.out.println("Type: " + bevelType);
System.out.println("Width: " + bevelWidth);
System.out.println("Height: " + bevelHeight);
} finally {
presentation.dispose();
}
Get Effective Properties of a Text Frame
Using Aspose.Slides, you can get effective properties of a text frame. The ITextFrameFormatEffectiveData interface contains effective text frame formatting properties.
The following code sample shows how to get effective text frame formatting properties. It assumes that the first shape on the first slide is an IAutoShape with a text frame.
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = (IAutoShape)slide.getShapes().get_Item(0);
ITextFrameFormat textFrameFormat = shape.getTextFrame().getTextFrameFormat();
ITextFrameFormatEffectiveData effectiveTextFrameFormat = textFrameFormat.getEffective();
int anchoringType = effectiveTextFrameFormat.getAnchoringType();
int autofitType = effectiveTextFrameFormat.getAutofitType();
int textVerticalType = effectiveTextFrameFormat.getTextVerticalType();
double marginLeft = effectiveTextFrameFormat.getMarginLeft();
double marginTop = effectiveTextFrameFormat.getMarginTop();
double marginRight = effectiveTextFrameFormat.getMarginRight();
double marginBottom = effectiveTextFrameFormat.getMarginBottom();
System.out.println("Anchoring type: " + anchoringType);
System.out.println("Autofit type: " + autofitType);
System.out.println("Text vertical type: " + textVerticalType);
System.out.println("Margins");
System.out.println(" Left: " + marginLeft);
System.out.println(" Top: " + marginTop);
System.out.println(" Right: " + marginRight);
System.out.println(" Bottom: " + marginBottom);
} finally {
presentation.dispose();
}
Get Effective Properties of a Text Style
Using Aspose.Slides, you can get effective properties of a text style. The ITextStyleEffectiveData interface contains effective text style properties.
The following code sample shows how to get effective text style properties. It assumes that the first shape on the first slide is an IAutoShape with a text frame.
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = (IAutoShape)slide.getShapes().get_Item(0);
ITextStyleEffectiveData effectiveTextStyle = shape.getTextFrame().getTextFrameFormat().getTextStyle().getEffective();
int levelCount = 9;
for (int levelIndex = 0; levelIndex < levelCount; levelIndex++)
{
IParagraphFormatEffectiveData effectiveStyleLevel = effectiveTextStyle.getLevel(levelIndex);
int depth = effectiveStyleLevel.getDepth();
double indent = effectiveStyleLevel.getIndent();
int alignment = effectiveStyleLevel.getAlignment();
int fontAlignment = effectiveStyleLevel.getFontAlignment();
System.out.println("= Effective paragraph formatting for style level #" + levelIndex + " =");
System.out.println("Depth: " + depth);
System.out.println("Indent: " + indent);
System.out.println("Alignment: " + alignment);
System.out.println("Font alignment: " + fontAlignment);
}
} finally {
presentation.dispose();
}
Get the Effective Font Height Value
Using Aspose.Slides, you can get the effective font height. The following code demonstrates how a portion’s effective font height changes after local font height values are set at different presentation structure levels.
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 400, 75, false);
autoShape.addTextFrame("");
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getPortions().clear();
IPortion firstPortion = new Portion("Sample text with first portion");
IPortion secondPortion = new Portion(" and second portion.");
paragraph.getPortions().add(firstPortion);
paragraph.getPortions().add(secondPortion);
IPortionFormatEffectiveData firstPortionFormatEffectiveData = firstPortion.getPortionFormat().getEffective();
IPortionFormatEffectiveData secondPortionFormatEffectiveData = secondPortion.getPortionFormat().getEffective();
System.out.println("Effective font height just after creation:");
double firstPortionFontHeight = firstPortionFormatEffectiveData.getFontHeight();
double secondPortionFontHeight = secondPortionFormatEffectiveData.getFontHeight();
System.out.println("Portion #0: " + firstPortionFontHeight);
System.out.println("Portion #1: " + secondPortionFontHeight);
presentation.getDefaultTextStyle().getLevel(0).getDefaultPortionFormat().setFontHeight(24);
firstPortionFormatEffectiveData = firstPortion.getPortionFormat().getEffective();
secondPortionFormatEffectiveData = secondPortion.getPortionFormat().getEffective();
System.out.println("Effective font height after setting the presentation default font height:");
firstPortionFontHeight = firstPortionFormatEffectiveData.getFontHeight();
secondPortionFontHeight = secondPortionFormatEffectiveData.getFontHeight();
System.out.println("Portion #0: " + firstPortionFontHeight);
System.out.println("Portion #1: " + secondPortionFontHeight);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(40);
firstPortionFormatEffectiveData = firstPortion.getPortionFormat().getEffective();
secondPortionFormatEffectiveData = secondPortion.getPortionFormat().getEffective();
System.out.println("Effective font height after setting paragraph default font height:");
firstPortionFontHeight = firstPortionFormatEffectiveData.getFontHeight();
secondPortionFontHeight = secondPortionFormatEffectiveData.getFontHeight();
System.out.println("Portion #0: " + firstPortionFontHeight);
System.out.println("Portion #1: " + secondPortionFontHeight);
firstPortion.getPortionFormat().setFontHeight(55);
firstPortionFormatEffectiveData = firstPortion.getPortionFormat().getEffective();
secondPortionFormatEffectiveData = secondPortion.getPortionFormat().getEffective();
System.out.println("Effective font height after setting portion #0 font height:");
firstPortionFontHeight = firstPortionFormatEffectiveData.getFontHeight();
secondPortionFontHeight = secondPortionFormatEffectiveData.getFontHeight();
System.out.println("Portion #0: " + firstPortionFontHeight);
System.out.println("Portion #1: " + secondPortionFontHeight);
secondPortion.getPortionFormat().setFontHeight(18);
firstPortionFormatEffectiveData = firstPortion.getPortionFormat().getEffective();
secondPortionFormatEffectiveData = secondPortion.getPortionFormat().getEffective();
System.out.println("Effective font height after setting portion #1 font height:");
firstPortionFontHeight = firstPortionFormatEffectiveData.getFontHeight();
secondPortionFontHeight = secondPortionFormatEffectiveData.getFontHeight();
System.out.println("Portion #0: " + firstPortionFontHeight);
System.out.println("Portion #1: " + secondPortionFontHeight);
presentation.save("SetLocalFontHeightValues.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Get the Effective Fill Format for a Table
Using Aspose.Slides, you can get effective fill formatting for different table parts. The IFillFormatEffectiveData interface contains effective fill formatting properties. Cell formatting has higher priority than row formatting, row formatting has higher priority than column formatting, and column formatting has higher priority than whole-table formatting.
As a result, ICellFormatEffectiveData properties are used to draw the table cell. The following code sample shows how to get effective fill formatting for different table parts. It assumes that the first shape on the first slide is an ITable.
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
ITable table = (ITable)slide.getShapes().get_Item(0);
ITableFormatEffectiveData tableFormatEffective = table.getTableFormat().getEffective();
IRowFormatEffectiveData rowFormatEffective = table.getRows().get_Item(0).getRowFormat().getEffective();
IColumnFormatEffectiveData columnFormatEffective = table.getColumns().get_Item(0).getColumnFormat().getEffective();
ICellFormatEffectiveData cellFormatEffective = table.get_Item(0, 0).getCellFormat().getEffective();
IFillFormatEffectiveData tableFillFormatEffective = tableFormatEffective.getFillFormat();
IFillFormatEffectiveData rowFillFormatEffective = rowFormatEffective.getFillFormat();
IFillFormatEffectiveData columnFillFormatEffective = columnFormatEffective.getFillFormat();
IFillFormatEffectiveData cellFillFormatEffective = cellFormatEffective.getFillFormat();
} finally {
presentation.dispose();
}
FAQ
Does getEffective return a snapshot?
Not always. Effective data represents the calculated formatting after inheritance is applied, but some effective data objects can be cached internally. A subsequent getEffective call may recalculate formatting and refresh the cached data, so a previously obtained object should not be treated as a durable snapshot.
When should I read effective properties again?
Call getEffective again after changing local formatting, parent styles, layout formatting, master formatting, or presentation-level defaults. The next call re-evaluates the formatting hierarchy and returns the current effective result.
Does changing or removing a layout/master slide affect effective properties that have already been retrieved?
Yes, but the change is reflected on the next getEffective call. If a parent formatting source is changed or removed, previously obtained effective data may be stale. Once getEffective is called again, Aspose.Slides re-evaluates the formatting tree and the resulting fonts, colors, sizes, or other values may change.
Can I modify values through effective data objects?
No. Effective data objects expose calculated values. Make changes in the local formatting objects, and then obtain the effective values again.
What happens if a property is not set at the shape level, nor in the layout/master, nor in global settings?
The effective value is determined by the default mechanism, which includes PowerPoint and Aspose.Slides defaults. That resolved value becomes part of the current effective data.
From an effective font value, can I tell which level provided the size or typeface?
Not directly. Effective data returns the final value. To find the source, check local values at the portion, paragraph, text frame, and text styles at the layout, master, and presentation levels to see where the first explicit definition appears.
Why do effective values sometimes look identical to the local ones?
Because the local value ended up being final (no higher-level inheritance was needed). In such cases, the effective value matches the local one.
When should I use effective properties, and when should I work only with local ones?
Use effective data when you need the “as rendered” result after all inheritance is applied, such as to align colors, indents, or sizes. If you need to preserve those values regardless of later formatting changes, copy the required properties into your own object. If you need to change formatting at a specific level, modify local properties and then, if needed, read the effective data again to verify the outcome.