Graphics Mill supports loading layers of different types from PSD files. Text layers store a text string and its appearance settings (font, color, paragraph, etc.) along with a bitmap. You can create personalized graphics by using text layers as placeholders in a PSD template. Just change text in a placeholder and merge PSD file layers. For more information see the Merging Layers topic. This article describes how to work with text layers, including transformed text and text on a curve.
To start reading a PSD file use the PsdReader(String) constructor, which accepts a filename as an argument.
While a PSD file is opened by Graphics Mill, no other application can delete or modify the file.
To access layers use the PsdReader.Frames property which returns a collection of PsdFrame instances. A text layer is represented by the PsdTextFrame class which extends the PsdFrame class with a text-specific functionality. For each text layer the following data can be obtained:
The following code reads a PSD file, iterates through its layers, and writes some information about a text layer to the console:
//create PSD reader
using (var reader = new PsdReader(@"Images\BusinessCard.psd"))
{
//read layers and check for a text layer
for (int i = 0; i < reader.Frames.Count; i++)
{
using (var frame = reader.Frames[i])
{
if (frame.Type == FrameType.Text)
{
var textFrame = (PsdTextFrame) frame;
Console.WriteLine("Font name: " + textFrame.Font.Name);
Console.WriteLine("Font size: " + textFrame.Font.Size);
Console.WriteLine("Text caps: " + textFrame.Caps);
Console.WriteLine("Text justification: " + textFrame.Justification);
Console.WriteLine("Paragraph first line indent: " + textFrame.Paragraph.FirstLineIndent);
Console.WriteLine("Text tracking: " + textFrame.Tracking);
Console.WriteLine("Text box: " + textFrame.TextBox);
break;
}
}
}
}
For transformed and curved text additionally you can extract
The following code reads a PSD file, iterates through its layers, and writes information to the console about a curve which the curved text is located along:
//create PSD reader
using (var reader = new PsdReader(@"Images\Seal.psd"))
{
//read layers and check for a text layer
for (int i = 0; i < reader.Frames.Count; i++)
{
using (var frame = reader.Frames[i])
{
if (frame.Type == FrameType.Text)
{
var textFrame = (PsdTextFrame)frame;
Console.WriteLine("Text path length in pixels: " + textFrame.Path.GetLength());
if (textFrame.Path.Points.Count > 0)
{
Console.WriteLine("Text path points: ");
for (int j = 0; j < textFrame.Path.Points.Count; j++)
Console.WriteLine("point " + j + ": " + textFrame.Path.Points[j].Type + " (" +
textFrame.Path.Points[j].X + ";" + textFrame.Path.Points[j].Y + ") ");
}
Console.WriteLine("Text box: " + textFrame.TextBox);
// break;
}
}
}
}
For more information about the paths, see the Working with Paths topic.
To get a layer transformation matrix you can do as follows:
//create PSD reader
using (var reader = new PsdReader(@"Images\Seal.psd"))
{
//read layers and check for a text layer
for (int i = 0; i < reader.Frames.Count; i++)
{
using (var frame = reader.Frames[i])
{
if (frame.Type == FrameType.Text)
{
var textFrame = (PsdTextFrame)frame;
Console.WriteLine("Text transformation matrix: ");
var matrix = textFrame.Transform.Elements;
Console.WriteLine("( " + matrix[0] + " " + matrix[2] + " " + matrix[4] + " )");
Console.WriteLine("( " + matrix[1] + " " + matrix[3] + " " + matrix[5] + " )");
// break;
}
}
}
}
For more information about transformation matrices, see the Affine and Projective Transformations topic.