public interface ITextParagraph
The interface to work with paragraph
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();
}
| Modifier and Type | Method and Description |
|---|---|
void |
apply(ITextParagraph paragraph)
Applies the specified paragraph.
|
boolean |
getAutoHyphenate()
Gets or sets a value indicating whether [automatic hyphenate].
|
double |
getAutoLeading()
Gets or sets the automatic leading.
|
boolean |
getBurasagari()
Gets or sets a value indicating whether this
ITextParagraph is burasagiri. |
int |
getConsecutiveHyphens()
Gets or sets the consecutive hyphens.
|
double |
getEndIndent()
Gets or sets the end indent.
|
boolean |
getEveryLineComposer()
Gets or sets a value indicating whether [every line composer].
|
double |
getFirstLineIndent()
Gets or sets the first line indent.
|
double[] |
getGlyphSpacing()
Gets or sets the glyph spacing.
|
boolean |
getHanging()
Gets or sets a value indicating whether this
ITextParagraph is hanging. |
int |
getHyphenatedWordSize()
Gets or sets the size of the hyphenated word.
|
int |
getJustification()
Gets or sets the justification.
|
int |
getKinsokuOrder()
Gets or sets the kinsoku order.
|
int |
getLeadingType()
Gets or sets the type of the leading.
|
double[] |
getLetterSpacing()
Gets or sets the letter spacing.
|
int |
getPostHyphen()
Gets or sets the post hyphen.
|
int |
getPreHyphen()
Gets or sets the pre hyphen.
|
double |
getSpaceAfter()
Gets or sets the space after.
|
double |
getSpaceBefore()
Gets or sets the space before.
|
double |
getStartIndent()
Gets or sets the start indent.
|
double[] |
getWordSpacing()
Gets or sets the word spacing.
|
double |
getZone()
Gets or sets the zone.
|
boolean |
isEqual(ITextParagraph paragraph)
Determines whether the specified paragraph is equal.
|
void |
setAutoHyphenate(boolean value)
Gets or sets a value indicating whether [automatic hyphenate].
|
void |
setAutoLeading(double value)
Gets or sets the automatic leading.
|
void |
setBurasagari(boolean value)
Gets or sets a value indicating whether this
ITextParagraph is burasagiri. |
void |
setConsecutiveHyphens(int value)
Gets or sets the consecutive hyphens.
|
void |
setEndIndent(double value)
Gets or sets the end indent.
|
void |
setEveryLineComposer(boolean value)
Gets or sets a value indicating whether [every line composer].
|
void |
setFirstLineIndent(double value)
Gets or sets the first line indent.
|
void |
setGlyphSpacing(double[] value)
Gets or sets the glyph spacing.
|
void |
setHanging(boolean value)
Gets or sets a value indicating whether this
ITextParagraph is hanging. |
void |
setHyphenatedWordSize(int value)
Gets or sets the size of the hyphenated word.
|
void |
setJustification(int value)
Gets or sets the justification.
|
void |
setKinsokuOrder(int value)
Gets or sets the kinsoku order.
|
void |
setLeadingType(int value)
Gets or sets the type of the leading.
|
void |
setLetterSpacing(double[] value)
Gets or sets the letter spacing.
|
void |
setPostHyphen(int value)
Gets or sets the post hyphen.
|
void |
setPreHyphen(int value)
Gets or sets the pre hyphen.
|
void |
setSpaceAfter(double value)
Gets or sets the space after.
|
void |
setSpaceBefore(double value)
Gets or sets the space before.
|
void |
setStartIndent(double value)
Gets or sets the start indent.
|
void |
setWordSpacing(double[] value)
Gets or sets the word spacing.
|
void |
setZone(double value)
Gets or sets the zone.
|
int getJustification()
Gets or sets the justification.
Value: The justification.void setJustification(int value)
Gets or sets the justification.
Value: The justification.double getFirstLineIndent()
Gets or sets the first line indent.
Value: The first line indent.void setFirstLineIndent(double value)
Gets or sets the first line indent.
Value: The first line indent.double getStartIndent()
Gets or sets the start indent.
Value: The start indent.void setStartIndent(double value)
Gets or sets the start indent.
Value: The start indent.double getEndIndent()
Gets or sets the end indent.
Value: The end indent.void setEndIndent(double value)
Gets or sets the end indent.
Value: The end indent.double getSpaceBefore()
Gets or sets the space before.
Value: The space before.void setSpaceBefore(double value)
Gets or sets the space before.
Value: The space before.double getSpaceAfter()
Gets or sets the space after.
Value: The space after.void setSpaceAfter(double value)
Gets or sets the space after.
Value: The space after.boolean getAutoHyphenate()
Gets or sets a value indicating whether [automatic hyphenate].
Value:true if [automatic hyphenate]; otherwise, false.void setAutoHyphenate(boolean value)
Gets or sets a value indicating whether [automatic hyphenate].
Value:true if [automatic hyphenate]; otherwise, false.int getHyphenatedWordSize()
Gets or sets the size of the hyphenated word.
Value: The size of the hyphenated word.void setHyphenatedWordSize(int value)
Gets or sets the size of the hyphenated word.
Value: The size of the hyphenated word.int getPreHyphen()
Gets or sets the pre hyphen.
Value: The pre hyphen.void setPreHyphen(int value)
Gets or sets the pre hyphen.
Value: The pre hyphen.int getPostHyphen()
Gets or sets the post hyphen.
Value: The post hyphen.void setPostHyphen(int value)
Gets or sets the post hyphen.
Value: The post hyphen.int getConsecutiveHyphens()
Gets or sets the consecutive hyphens.
Value: The consecutive hyphens.void setConsecutiveHyphens(int value)
Gets or sets the consecutive hyphens.
Value: The consecutive hyphens.double getZone()
Gets or sets the zone.
Value: The zone.void setZone(double value)
Gets or sets the zone.
Value: The zone.double[] getWordSpacing()
Gets or sets the word spacing.
Value: The word spacing.void setWordSpacing(double[] value)
Gets or sets the word spacing.
Value: The word spacing.double[] getLetterSpacing()
Gets or sets the letter spacing.
Value: The letter spacing.void setLetterSpacing(double[] value)
Gets or sets the letter spacing.
Value: The letter spacing.double[] getGlyphSpacing()
Gets or sets the glyph spacing.
Value: The glyph spacing.void setGlyphSpacing(double[] value)
Gets or sets the glyph spacing.
Value: The glyph spacing.double getAutoLeading()
Gets or sets the automatic leading.
Value: The automatic leading.void setAutoLeading(double value)
Gets or sets the automatic leading.
Value: The automatic leading.int getLeadingType()
Gets or sets the type of the leading.
Value: The type of the leading.void setLeadingType(int value)
Gets or sets the type of the leading.
Value: The type of the leading.boolean getHanging()
Gets or sets a value indicating whether this ITextParagraph is hanging.
true if hanging; otherwise, false.void setHanging(boolean value)
Gets or sets a value indicating whether this ITextParagraph is hanging.
true if hanging; otherwise, false.boolean getBurasagari()
Gets or sets a value indicating whether this ITextParagraph is burasagiri.
true if burasagiri; otherwise, false.void setBurasagari(boolean value)
Gets or sets a value indicating whether this ITextParagraph is burasagiri.
true if burasagiri; otherwise, false.int getKinsokuOrder()
Gets or sets the kinsoku order.
Value: The kinsoku order.void setKinsokuOrder(int value)
Gets or sets the kinsoku order.
Value: The kinsoku order.boolean getEveryLineComposer()
Gets or sets a value indicating whether [every line composer].
Value:true if [every line composer]; otherwise, false.void setEveryLineComposer(boolean value)
Gets or sets a value indicating whether [every line composer].
Value:true if [every line composer]; otherwise, false.void apply(ITextParagraph paragraph)
Applies the specified paragraph.
paragraph - The paragraph.boolean isEqual(ITextParagraph paragraph)
Determines whether the specified paragraph is equal.
paragraph - The paragraph.true if the specified paragraph is equal; otherwise, false.Copyright (c) 2008-2020 Aspose Pty Ltd. All Rights Reserved.