Packages

 

com.aspose.psd.fileformats.psd.layers.text

Interface IText



  • public interface IText

    Interface for Text Editing for Text Layers

    Code example:

    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();
    }
    

    • Method Detail

      • producePortion

        ITextPortion producePortion()

        Produces the new portion with default parameters

        Returns:
        Reference to newly created ITextPortion.
      • producePortions

        ITextPortion[] producePortions(String[] portionsOfText,
                                       ITextStyle stylePrototype,
                                       ITextParagraph paragraphPrototype)

        Produces the new portions with input or default parameters.

        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.
        Returns:
        Returns the new portions ITextPortion based on input parameters.
      • addPortion

        void addPortion(ITextPortion portion)

        Adds the portion of text to the end

        Parameters:
        portion - The portion.
      • insertPortion

        void insertPortion(ITextPortion portion,
                           int index)

        Inserts the ITextPortion to specified position

        Parameters:
        portion - The portion.
        index - The index.
      • removePortion

        void removePortion(int index)

        Removes the portion in specified index

        Parameters:
        index - The index.
      • updateLayerData

        void updateLayerData()

        Updates the layer data.

      • getItems

        ITextPortion[] getItems()

        Gets the items.

        Value: The items.
      • getText

        String getText()

        Gets the text.

        Value: The text.
      • getTextOrientation

        int getTextOrientation()

        Gets or sets the text orientation.

        Value: The text orientation.
      • setTextOrientation

        void setTextOrientation(int value)

        Gets or sets the text orientation.

        Value: The text orientation.