Interface ITextParagraph
内容
[
隐藏
]ITextParagraph interface
使用段落 的界面
public interface ITextParagraph
特性
姓名 | 描述 |
---|---|
AutoHyphenate { get; set; } | 获取或设置一个值,该值指示是否[自动连字符]. |
AutoLeading { get; set; } | 获取或设置自动行距。 |
Burasagari { get; set; } | 获取或设置一个值,指示是否这ITextParagraph 是 burasagiri. |
ConsecutiveHyphens { get; set; } | 获取或设置连续的连字符。 |
EndIndent { get; set; } | 获取或设置结束缩进。 |
EveryLineComposer { get; set; } | 获取或设置一个值,该值指示是否[每一行作曲家]. |
FirstLineIndent { get; set; } | 获取或设置首行缩进。 |
GlyphSpacing { get; set; } | 获取或设置字形间距。 |
Hanging { get; set; } | 获取或设置一个值,指示是否这ITextParagraph 挂了. |
HyphenatedWordSize { get; set; } | 获取或设置连字词的大小。 |
Justification { get; set; } | 获取或设置对齐方式。 |
KinsokuOrder { get; set; } | 获取或设置避头尾顺序。 |
LeadingType { get; set; } | 获取或设置前导的类型。 |
LetterSpacing { get; set; } | 获取或设置字母间距。 |
PostHyphen { get; set; } | 获取或设置后连字符。 |
PreHyphen { get; set; } | 获取或设置前置连字符。 |
SpaceAfter { get; set; } | 获取或设置. 之后的空间 |
SpaceBefore { get; set; } | 获取或设置之前的空间。 |
StartIndent { get; set; } | 获取或设置开始缩进。 |
WordSpacing { get; set; } | 获取或设置字间距。 |
Zone { get; set; } | 获取或设置区域。 |
方法
姓名 | 描述 |
---|---|
Apply(ITextParagraph) | 应用指定段落。 |
IsEqual(ITextParagraph) | 判断指定段落是否相等。 |
例子
以下示例演示了通过 ITextPortion 对从右到左的语言进行的文本对齐可以正常工作。
[C#]
string sourceFilePath = "bidi.psd";
string exportFilePath = "bidiOutput.psd";
using (PsdImage image = (PsdImage)Image.Load(sourceFilePath))
{
TextLayer layer = (TextLayer)image.Layers[2];
ITextPortion[] portions = layer.TextData.Items;
portions[0].Paragraph.Justification = JustificationMode.Center;
layer.TextData.UpdateLayerData();
image.Save(exportFilePath);
}
以下代码示例演示了编辑文本部分及其文本样式。
[C#]
const double Tolerance = 0.0001;
var filePath = "ThreeColorsParagraphs.psd";
var outputPath = "ThreeColorsParagraph_out.psd";
using (var im = (PsdImage)Image.Load(filePath))
{
for (int i = 0; i < im.Layers.Length; i++)
{
var layer = im.Layers[i] as TextLayer;
if (layer != null)
{
var portions = layer.TextData.Items;
if (portions.Length != 4)
{
throw new Exception();
}
// 检查每一部分的文本
if (portions[0].Text != "Old " ||
portions[1].Text != "color" ||
portions[2].Text != " text\r" ||
portions[3].Text != "Second paragraph\r")
{
throw new Exception();
}
// 检查段落数据
// 段落有不同的理由
if (
(int)portions[0].Paragraph.Justification != 0 ||
(int)portions[1].Paragraph.Justification != 0 ||
(int)portions[2].Paragraph.Justification != 0 ||
(int)portions[3].Paragraph.Justification != 2)
{
throw new Exception();
}
// 第一段和第二段的所有其他属性都相等
for (int j = 0; j < portions.Length; j++)
{
var paragraph = portions[j].Paragraph;
if (Math.Abs(paragraph.AutoLeading - 1.2) > Tolerance ||
paragraph.AutoHyphenate != false ||
paragraph.Burasagari != false ||
paragraph.ConsecutiveHyphens != 8 ||
Math.Abs(paragraph.StartIndent) > Tolerance ||
Math.Abs(paragraph.EndIndent) > Tolerance ||
paragraph.EveryLineComposer != false ||
Math.Abs(paragraph.FirstLineIndent) > Tolerance ||
paragraph.GlyphSpacing.Length != 3 ||
Math.Abs(paragraph.GlyphSpacing[0] - 1) > Tolerance ||
Math.Abs(paragraph.GlyphSpacing[1] - 1) > Tolerance ||
Math.Abs(paragraph.GlyphSpacing[2] - 1) > Tolerance ||
paragraph.Hanging != false ||
paragraph.HyphenatedWordSize != 6 ||
paragraph.KinsokuOrder != 0 ||
paragraph.LetterSpacing.Length != 3 ||
Math.Abs(paragraph.LetterSpacing[0]) > Tolerance ||
Math.Abs(paragraph.LetterSpacing[1]) > Tolerance ||
Math.Abs(paragraph.LetterSpacing[2]) > Tolerance ||
paragraph.LeadingType != LeadingMode.Auto ||
paragraph.PreHyphen != 2 ||
paragraph.PostHyphen != 2 ||
Math.Abs(paragraph.SpaceBefore) > Tolerance ||
Math.Abs(paragraph.SpaceAfter) > Tolerance ||
paragraph.WordSpacing.Length != 3 ||
Math.Abs(paragraph.WordSpacing[0] - 0.8) > Tolerance ||
Math.Abs(paragraph.WordSpacing[1] - 1.0) > Tolerance ||
Math.Abs(paragraph.WordSpacing[2] - 1.33) > Tolerance ||
Math.Abs(paragraph.Zone - 36.0) > Tolerance)
{
throw new Exception();
}
}
// 检查样式数据
// 样式有不同的颜色和字体大小
if (Math.Abs(portions[0].Style.FontSize - 12) > Tolerance ||
Math.Abs(portions[1].Style.FontSize - 12) > Tolerance ||
Math.Abs(portions[2].Style.FontSize - 12) > Tolerance ||
Math.Abs(portions[3].Style.FontSize - 10) > Tolerance)
{
throw new Exception();
}
if (portions[0].Style.FillColor != Color.FromArgb(255, 145, 0, 0) ||
portions[1].Style.FillColor != Color.FromArgb(255, 201, 128, 2) ||
portions[2].Style.FillColor != Color.FromArgb(255, 18, 143, 4) ||
portions[3].Style.FillColor != Color.FromArgb(255, 145, 42, 100))
{
throw new Exception();
}
for (int j = 0; j < portions.Length; j++)
{
var style = portions[j].Style;
if (style.AutoLeading != true ||
style.HindiNumbers != false ||
style.Kerning != 0 ||
style.Leading != 0 ||
style.StrokeColor != Color.FromArgb(255, 175, 90, 163) ||
style.Tracking != 50)
{
throw new Exception();
}
}
// 文本编辑示例
portions[0].Text = "Hello ";
portions[1].Text = "World";
// 文本部分删除示例
layer.TextData.RemovePortion(3);
layer.TextData.RemovePortion(2);
// 添加新文本部分的示例
var createdPortion = layer.TextData.ProducePortion();
createdPortion.Text = "!!!\r";
layer.TextData.AddPortion(createdPortion);
portions = layer.TextData.Items;
// 部分段落和样式编辑示例
// 设置右对齐
portions[0].Paragraph.Justification = JustificationMode.Right;
portions[1].Paragraph.Justification = JustificationMode.Right;
portions[2].Paragraph.Justification = JustificationMode.Right;
// 每种样式的不同颜色。将更改,但不完全支持渲染
portions[0].Style.FillColor = Color.Aquamarine;
portions[1].Style.FillColor = Color.Violet;
portions[2].Style.FillColor = Color.LightBlue;
// 不同的字体。将更改,但不完全支持渲染
portions[0].Style.FontSize = 6;
portions[1].Style.FontSize = 8;
portions[2].Style.FontSize = 10;
layer.TextData.UpdateLayerData();
im.Save(outputPath, new PsdOptions(im));
break;
}
}
}