public interface IText
Interface for Text Editing for Text Layers
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 |
---|---|
void |
addPortion(ITextPortion portion)
Adds the portion of text to the end
|
ITextPortion[] |
getItems()
Gets the items.
|
String |
getText()
Gets the text.
|
int |
getTextOrientation()
Gets or sets the text orientation.
|
void |
insertPortion(ITextPortion portion,
int index)
Inserts the
ITextPortion to specified position |
ITextPortion |
producePortion()
Produces the new portion with default parameters
|
ITextPortion[] |
producePortions(String[] portionsOfText,
ITextStyle stylePrototype,
ITextParagraph paragraphPrototype)
Produces the new portions with input or default parameters.
|
void |
removePortion(int index)
Removes the portion in specified index
|
void |
setTextOrientation(int value)
Gets or sets the text orientation.
|
void |
updateLayerData()
Updates the layer data.
|
ITextPortion producePortion()
Produces the new portion with default parameters
ITextPortion
.ITextPortion[] producePortions(String[] portionsOfText, ITextStyle stylePrototype, ITextParagraph paragraphPrototype)
Produces the new portions with input or default parameters.
portionsOfText
- The portions of text to create new ITextPortion
.stylePrototype
- A style that, if not null, will be applied in the new <see. Cref="ITextPortion"></see.>
, otherwise will be default.paragraphPrototype
- A paragraph that, if not null, will be applied in the new <see. Cref="ITextPortion"></see.>
, otherwise will be default.ITextPortion
based on input parameters.void addPortion(ITextPortion portion)
Adds the portion of text to the end
portion
- The portion.void insertPortion(ITextPortion portion, int index)
Inserts the ITextPortion
to specified position
portion
- The portion.index
- The index.void removePortion(int index)
Removes the portion in specified index
index
- The index.void updateLayerData()
Updates the layer data.
ITextPortion[] getItems()
Gets the items.
Value: The items.String getText()
Gets the text.
Value: The text.int getTextOrientation()
Gets or sets the text orientation.
Value: The text orientation.void setTextOrientation(int value)
Gets or sets the text orientation.
Value: The text orientation.