public interface ITextPortion
Interface to manipulate text portions
An example of applying different text styles to a single text layer of a PSD file. It modifies the text style of an existing text layer and adds to one a few new text portions styled differently then saves a changed copy of the document as a new PSD file.
String inPsdFilePath = "text212.psd"; String outPsdFilePath = "Output_text212.psd"; // Load a PSD file containing predefined text layers PsdImage psdImage = (PsdImage)Image.load(inPsdFilePath); try { // Obtain a text container of a first layer TextLayer textLayer = (TextLayer)psdImage.getLayers()[1]; IText textData = textLayer.getTextData(); // Define a default text style ITextStyle defaultStyle = textData.producePortion().getStyle(); defaultStyle.setFillColor(Color.getDimGray()); defaultStyle.setFontSize(51); // Define a default text paragraph ITextParagraph defaultParagraph = textData.producePortion().getParagraph(); // Style an existing text portion textData.getItems()[1].getStyle().setStrikethrough(true); // Create a few new text portions with default styling ITextPortion[] newTextPortions = textData.producePortions(new String[] { "E=mc", "2\r", "Bold", "Italic\r", "Lowercasetext" }, defaultStyle, defaultParagraph); // Style the text portions differently newTextPortions[0].getStyle().setUnderline(true); // edit text style of "E=mc" newTextPortions[1].getStyle().setFontBaseline(FontBaseline.Superscript); // edit text style of "2\r" newTextPortions[2].getStyle().setFauxBold(true); // edit text style of "Bold" newTextPortions[3].getStyle().setFauxItalic(true); // edit text style of "Italic\r" newTextPortions[3].getStyle().setBaselineShift(-25); // edit text style of "Italic\r" newTextPortions[4].getStyle().setFontCaps(FontCaps.SmallCaps); // edit text style of "Lowercasetext" // Bind the text portions to the text layer for (ITextPortion newTextPortion : newTextPortions) { textData.addPortion(newTextPortion); } // Apply changes defined in the text portions to the text layer textData.updateLayerData(); // Save a copy of loaded PSD file including the changes on the specified path psdImage.save(outPsdFilePath); } finally { psdImage.dispose(); }
Modifier and Type | Method and Description |
---|---|
ITextParagraph |
getParagraph()
Sets the style.
|
ITextStyle |
getStyle()
Gets the style.
|
String |
getText()
Gets or sets the text.
|
void |
setText(String value)
Gets or sets the text.
|
String getText()
Gets or sets the text.
Value: The text.void setText(String value)
Gets or sets the text.
Value: The text.ITextStyle getStyle()
Gets the style.
Value: The style.ITextParagraph getParagraph()
Sets the style.
Value: The paragraph.