Packages

 

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

Interface ITextParagraph



  • public interface ITextParagraph

    The interface to work with paragraph

    Code example:

    An example of editing text portions and their text style. It loads a predefined PSD file and verifies text properties of a single text layer then edits justification and styling of the text and saves a changed copy of the document as a new PSD file.


                
    final double tolerance = 0.0001;
    String inPsdFilePath = "ThreeColorsParagraphs.psd";
    String outPsdFilePath = "ThreeColorsParagraph_out.psd";
                
    // Load a predefine PSD file containing a text layer
    PsdImage psdImage = (PsdImage)Image.load(inPsdFilePath);
    try
    {
        for (Layer layer : psdImage.getLayers())
        {
            // Filter any non-text layer
            if (!(layer instanceof TextLayer))
            {
                continue;
            }
                
            TextLayer textLayer = (TextLayer)layer;
                
            ITextPortion[] portions = textLayer.getTextData().getItems();
                
            // Verify whether the text layer actually has predefined number of text portions
            if (portions.length != 4)
            {
                throw new Exception();
            }
                
            // Checking text of every portion
            if (!portions[0].getText().equals("Old ") ||
                    !portions[1].getText().equals("color") ||
                    !portions[2].getText().equals(" text\r") ||
                    !portions[3].getText().equals("Second paragraph\r"))
            {
                throw new Exception();
            }
                
            // Checking paragraphs data
            // Paragraphs have different justification (first three text portions are left
            // aligned and 4th one is aligned by center)
            if (portions[0].getParagraph().getJustification() != 0 ||
                    portions[1].getParagraph().getJustification() != 0 ||
                    portions[2].getParagraph().getJustification() != 0 ||
                    portions[3].getParagraph().getJustification() != 2)
            {
                throw new Exception();
            }
                
            // Checking all other properties of first and second paragraph
            for (ITextPortion iTextPortion : portions)
            {
                ITextParagraph paragraph = iTextPortion.getParagraph();
                
                if (Math.abs(paragraph.getAutoLeading() - 1.2) > tolerance ||
                        paragraph.getAutoHyphenate() ||
                        paragraph.getBurasagari() ||
                        paragraph.getConsecutiveHyphens() != 8 ||
                        Math.abs(paragraph.getStartIndent()) > tolerance ||
                        Math.abs(paragraph.getEndIndent()) > tolerance ||
                        paragraph.getEveryLineComposer() ||
                        Math.abs(paragraph.getFirstLineIndent()) > tolerance ||
                        paragraph.getGlyphSpacing().length != 3 ||
                        Math.abs(paragraph.getGlyphSpacing()[0] - 1) > tolerance ||
                        Math.abs(paragraph.getGlyphSpacing()[1] - 1) > tolerance ||
                        Math.abs(paragraph.getGlyphSpacing()[2] - 1) > tolerance ||
                        paragraph.getHanging() ||
                        paragraph.getHyphenatedWordSize() != 6 ||
                        paragraph.getKinsokuOrder() != 0 ||
                        paragraph.getLetterSpacing().length != 3 ||
                        Math.abs(paragraph.getLetterSpacing()[0]) > tolerance ||
                        Math.abs(paragraph.getLetterSpacing()[1]) > tolerance ||
                        Math.abs(paragraph.getLetterSpacing()[2]) > tolerance ||
                        paragraph.getLeadingType() != LeadingMode.Auto ||
                        paragraph.getPreHyphen() != 2 ||
                        paragraph.getPostHyphen() != 2 ||
                        Math.abs(paragraph.getSpaceBefore()) > tolerance ||
                        Math.abs(paragraph.getSpaceAfter()) > tolerance ||
                        paragraph.getWordSpacing().length != 3 ||
                        Math.abs(paragraph.getWordSpacing()[0] - 0.8) > tolerance ||
                        Math.abs(paragraph.getWordSpacing()[1] - 1.0) > tolerance ||
                        Math.abs(paragraph.getWordSpacing()[2] - 1.33) > tolerance ||
                        Math.abs(paragraph.getZone() - 36.0) > tolerance)
                {
                    throw new Exception();
                }
            }
                
            // Checking style data
            // Styles have different colors and font size
            if (Math.abs(portions[0].getStyle().getFontSize() - 12) > tolerance ||
                    Math.abs(portions[1].getStyle().getFontSize() - 12) > tolerance ||
                    Math.abs(portions[2].getStyle().getFontSize() - 12) > tolerance ||
                    Math.abs(portions[3].getStyle().getFontSize() - 10) > tolerance)
            {
                throw new Exception();
            }
                
            if (!portions[0].getStyle().getFillColor().equals(Color.fromArgb(255, 145, 0, 0)) ||
                    !portions[1].getStyle().getFillColor().equals(Color.fromArgb(255, 201, 128, 2)) ||
                    !portions[2].getStyle().getFillColor().equals(Color.fromArgb(255, 18, 143, 4)) ||
                    !portions[3].getStyle().getFillColor().equals(Color.fromArgb(255, 145, 42, 100)))
            {
                throw new Exception();
            }
                
            for (ITextPortion portion : portions)
            {
                ITextStyle style = portion.getStyle();
                
                if (style.getAutoLeading() ||
                        style.getHindiNumbers() ||
                        style.getKerning() != 0 ||
                        style.getLeading() != 0 ||
                        !style.getStrokeColor().equals(Color.fromArgb(255, 175, 90, 163)) ||
                        style.getTracking() != 50)
                {
                    throw new Exception();
                }
            }
                
            // Example of text editing
            portions[0].setText("Hello ");
            portions[1].setText("World");
                
            // Example of text portions removing
            textLayer.getTextData().removePortion(3);
            textLayer.getTextData().removePortion(2);
                
            // Example of adding new text portion
            ITextPortion createdPortion = textLayer.getTextData().producePortion();
            createdPortion.setText("!!!\r");
            textLayer.getTextData().addPortion(createdPortion);
                
            portions = textLayer.getTextData().getItems();
                
            // Example of paragraph and style editing for portions
            // Set right justification
            portions[0].getParagraph().setJustification(1);
            portions[1].getParagraph().setJustification(1);
            portions[2].getParagraph().setJustification(1);
                
            // Different colors for each style.
            // The colors will be changed, but rendering is not fully supported yet
            portions[0].getStyle().setFillColor(Color.getAquamarine());
            portions[1].getStyle().setFillColor(Color.getViolet());
            portions[2].getStyle().setFillColor(Color.getLightBlue());
                
            // Different font.
            // The font will be changed, but rendering is not fully supported yet
            portions[0].getStyle().setFontSize(6);
            portions[1].getStyle().setFontSize(8);
            portions[2].getStyle().setFontSize(10);
                
            // Apply the changes defined in the text portions to the text
            textLayer.getTextData().updateLayerData();
                
            // Save a copy of the loaded PSD file including the changes with the original image
            // options on the specified path
            psdImage.save(outPsdFilePath, new PsdOptions(psdImage));
                
            break;
        }
    }
    finally
    {
        psdImage.dispose();
    }
    

    • Method Detail

      • getJustification

        int getJustification()

        Gets or sets the justification.

        Value: The justification.
      • setJustification

        void setJustification(int value)

        Gets or sets the justification.

        Value: The justification.
      • getFirstLineIndent

        double getFirstLineIndent()

        Gets or sets the first line indent.

        Value: The first line indent.
      • setFirstLineIndent

        void setFirstLineIndent(double value)

        Gets or sets the first line indent.

        Value: The first line indent.
      • getStartIndent

        double getStartIndent()

        Gets or sets the start indent.

        Value: The start indent.
      • setStartIndent

        void setStartIndent(double value)

        Gets or sets the start indent.

        Value: The start indent.
      • getEndIndent

        double getEndIndent()

        Gets or sets the end indent.

        Value: The end indent.
      • setEndIndent

        void setEndIndent(double value)

        Gets or sets the end indent.

        Value: The end indent.
      • getSpaceBefore

        double getSpaceBefore()

        Gets or sets the space before.

        Value: The space before.
      • setSpaceBefore

        void setSpaceBefore(double value)

        Gets or sets the space before.

        Value: The space before.
      • getSpaceAfter

        double getSpaceAfter()

        Gets or sets the space after.

        Value: The space after.
      • setSpaceAfter

        void setSpaceAfter(double value)

        Gets or sets the space after.

        Value: The space after.
      • getAutoHyphenate

        boolean getAutoHyphenate()

        Gets or sets a value indicating whether [automatic hyphenate].

        Value: true if [automatic hyphenate]; otherwise, false.
      • setAutoHyphenate

        void setAutoHyphenate(boolean value)

        Gets or sets a value indicating whether [automatic hyphenate].

        Value: true if [automatic hyphenate]; otherwise, false.
      • getHyphenatedWordSize

        int getHyphenatedWordSize()

        Gets or sets the size of the hyphenated word.

        Value: The size of the hyphenated word.
      • setHyphenatedWordSize

        void setHyphenatedWordSize(int value)

        Gets or sets the size of the hyphenated word.

        Value: The size of the hyphenated word.
      • getPreHyphen

        int getPreHyphen()

        Gets or sets the pre hyphen.

        Value: The pre hyphen.
      • setPreHyphen

        void setPreHyphen(int value)

        Gets or sets the pre hyphen.

        Value: The pre hyphen.
      • getPostHyphen

        int getPostHyphen()

        Gets or sets the post hyphen.

        Value: The post hyphen.
      • setPostHyphen

        void setPostHyphen(int value)

        Gets or sets the post hyphen.

        Value: The post hyphen.
      • getConsecutiveHyphens

        int getConsecutiveHyphens()

        Gets or sets the consecutive hyphens.

        Value: The consecutive hyphens.
      • setConsecutiveHyphens

        void setConsecutiveHyphens(int value)

        Gets or sets the consecutive hyphens.

        Value: The consecutive hyphens.
      • getZone

        double getZone()

        Gets or sets the zone.

        Value: The zone.
      • setZone

        void setZone(double value)

        Gets or sets the zone.

        Value: The zone.
      • getWordSpacing

        double[] getWordSpacing()

        Gets or sets the word spacing.

        Value: The word spacing.
      • setWordSpacing

        void setWordSpacing(double[] value)

        Gets or sets the word spacing.

        Value: The word spacing.
      • getLetterSpacing

        double[] getLetterSpacing()

        Gets or sets the letter spacing.

        Value: The letter spacing.
      • setLetterSpacing

        void setLetterSpacing(double[] value)

        Gets or sets the letter spacing.

        Value: The letter spacing.
      • getGlyphSpacing

        double[] getGlyphSpacing()

        Gets or sets the glyph spacing.

        Value: The glyph spacing.
      • setGlyphSpacing

        void setGlyphSpacing(double[] value)

        Gets or sets the glyph spacing.

        Value: The glyph spacing.
      • getAutoLeading

        double getAutoLeading()

        Gets or sets the automatic leading.

        Value: The automatic leading.
      • setAutoLeading

        void setAutoLeading(double value)

        Gets or sets the automatic leading.

        Value: The automatic leading.
      • getLeadingType

        int getLeadingType()

        Gets or sets the type of the leading.

        Value: The type of the leading.
      • setLeadingType

        void setLeadingType(int value)

        Gets or sets the type of the leading.

        Value: The type of the leading.
      • getHanging

        boolean getHanging()

        Gets or sets a value indicating whether this ITextParagraph is hanging.

        Value: true if hanging; otherwise, false.
      • setHanging

        void setHanging(boolean value)

        Gets or sets a value indicating whether this ITextParagraph is hanging.

        Value: true if hanging; otherwise, false.
      • getBurasagari

        boolean getBurasagari()

        Gets or sets a value indicating whether this ITextParagraph is burasagiri.

        Value: true if burasagiri; otherwise, false.
      • setBurasagari

        void setBurasagari(boolean value)

        Gets or sets a value indicating whether this ITextParagraph is burasagiri.

        Value: true if burasagiri; otherwise, false.
      • getKinsokuOrder

        int getKinsokuOrder()

        Gets or sets the kinsoku order.

        Value: The kinsoku order.
      • setKinsokuOrder

        void setKinsokuOrder(int value)

        Gets or sets the kinsoku order.

        Value: The kinsoku order.
      • getEveryLineComposer

        boolean getEveryLineComposer()

        Gets or sets a value indicating whether [every line composer].

        Value: true if [every line composer]; otherwise, false.
      • setEveryLineComposer

        void setEveryLineComposer(boolean value)

        Gets or sets a value indicating whether [every line composer].

        Value: true if [every line composer]; otherwise, false.
      • apply

        void apply(ITextParagraph paragraph)

        Applies the specified paragraph.

        Parameters:
        paragraph - The paragraph.
      • isEqual

        boolean isEqual(ITextParagraph paragraph)

        Determines whether the specified paragraph is equal.

        Parameters:
        paragraph - The paragraph.
        Returns:
        true if the specified paragraph is equal; otherwise, false.