TextLayer.GetFonts
TextLayer.GetFonts method
获取文字图层的字体集。
public TextFontInfo[] GetFonts()
返回值
文字层的字体集。
例子
下面的代码演示了 Aspose.PSD 如何获取文本层内联格式的属性。
[C#]
string sourceFile = "inline_formatting.psd";
List<ITextPortion> regularText = new List<ITextPortion>();
List<ITextPortion> boldText = new List<ITextPortion>();
List<ITextPortion> italicText = new List<ITextPortion>();
// 将现有图像加载到 PsdImage 类的实例中
using (var psdImage = (PsdImage)Image.Load(sourceFile))
{
var layers = psdImage.Layers;
for (int index = 0; index < layers.Length; index++)
{
var layer = layers[index];
if (!(layer is TextLayer))
{
continue;
}
var textLayer = (TextLayer)layer;
// 获取包含在文本层中的字体
var fonts = textLayer.GetFonts();
var textPortions = textLayer.TextData.Items;
foreach (var textPortion in textPortions)
{
TextFontInfo font = fonts[textPortion.Style.FontIndex];
if (font != null)
{
switch (font.Style)
{
case FontStyle.Regular:
regularText.Add(textPortion);
break;
case FontStyle.Bold:
boldText.Add(textPortion);
break;
case FontStyle.Italic:
italicText.Add(textPortion);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
}
也可以看看
- class TextFontInfo
- class TextLayer
- 命名空间 Aspose.PSD.FileFormats.Psd.Layers
- 部件 Aspose.PSD