TextLayer.GetFonts
Contents
[
Hide
]TextLayer.GetFonts method
Gets the fonts set of the text layer.
public TextFontInfo[] GetFonts()
Return Value
The fonts set of the text layer.
Examples
The following code demonstrates how Aspose.PSD gets properties of inline formatting of Text Layer.
[C#]
string sourceFile = "inline_formatting.psd";
List<ITextPortion> regularText = new List<ITextPortion>();
List<ITextPortion> boldText = new List<ITextPortion>();
List<ITextPortion> italicText = new List<ITextPortion>();
// Load an existing image into an instance of PsdImage class
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;
// gets fonts that contains in text 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();
}
}
}
}
}
See Also
- class TextFontInfo
- class TextLayer
- namespace Aspose.PSD.FileFormats.Psd.Layers
- assembly Aspose.PSD