using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents.composition;
using entitiesit.stefanochizzolini.clown.documents.contents.entities;
using it.stefanochizzolini.clown.documents.contents.fonts;
using filesit.stefanochizzolini.clown.files;
using System.Drawing;
using System.IO;
namespace it.stefanochizzolini.clown.samples{
/**
<summary>This sample demonstrates how to spacially manipulate an image object.</summary>
*/
public class TransformationSample
: ISample
{
#region static
#region fields
private static readonly float Margin = 36;
#endregion
#endregion
#region dynamic
#region interface
#region public
#region ISample
public void Run(
SampleLoader loader
)
{
// 1. PDF file instantiation.
files::File file = new files::File();
// 2. Content creation.
Document document = file.Document;
Populate(
document,
loader
);
// (boilerplate metadata insertion -- ignore it)
loader.BuildAccessories(document,this.GetType(),"Transformation","graphics object transformation");
// 3. Serialize the PDF file (again, boilerplate code -- see the SampleLoader class source code)!
loader.Serialize(file,this.GetType().Name,false);
}
#endregion
#endregion
#region private
/**
<summary>Populates a PDF file with contents.</summary>
*/
private void Populate(
Document document,
SampleLoader loader
)
{
Page page = new Page(document);
document.Pages.Add(page);
Size pageSize = page.Size.Value;
PrimitiveFilter builder = new PrimitiveFilter(page);
{
BlockFilter blockFilter = new BlockFilter(builder);
blockFilter.Hyphenation = true;
blockFilter.Begin(
new RectangleF(
Margin,
Margin,
(float)pageSize.Width - Margin * 2,
(float)pageSize.Height - Margin * 2
),
AlignmentXEnum.Justify,
AlignmentYEnum.Top
);
StandardType1Font bodyFont = new StandardType1Font(
document,
StandardType1Font.FamilyNameEnum.Courier,
true,
false
);
builder.SetFont(bodyFont,32);
blockFilter.ShowText("Transformation sample"); blockFilter.ShowBreak();
builder.SetFont(bodyFont,16);
blockFilter.ShowText("Showing the GNU logo placed on the page center, rotated by 25 degrees clockwise.");
blockFilter.End();
}
// Showing the 'GNU' image...
{
// Instantiate a jpeg image object!
entities::Image image = entities::Image.Get(
loader.InputPath + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar + "gnu.jpg"
); // Abstract image (entity).
// Show the image!
builder.ShowXObject(
image.ToXObject(document),
new PointF(
(float)pageSize.Width / 2,
(float)pageSize.Height / 2
),
new SizeF(0,0),
AlignmentXEnum.Center,
AlignmentYEnum.Middle,
-25
);
}
builder.Flush();
}
#endregion
#endregion
#endregion
}
}
|