01: package it.stefanochizzolini.clown.samples;
02:
03: import it.stefanochizzolini.clown.documents.Document;
04: import it.stefanochizzolini.clown.documents.Page;
05: import it.stefanochizzolini.clown.documents.contents.composition.AlignmentXEnum;
06: import it.stefanochizzolini.clown.documents.contents.composition.AlignmentYEnum;
07: import it.stefanochizzolini.clown.documents.contents.composition.BlockFilter;
08: import it.stefanochizzolini.clown.documents.contents.composition.PrimitiveFilter;
09: import it.stefanochizzolini.clown.documents.contents.fonts.StandardType1Font;
10: import it.stefanochizzolini.clown.documents.contents.entities.Image;
11: import it.stefanochizzolini.clown.files.File;
12:
13: import java.awt.Dimension;
14: import java.awt.geom.Dimension2D;
15: import java.awt.geom.Point2D;
16: import java.awt.geom.Rectangle2D;
17:
18: /**
19: This sample demonstrates how to spacially manipulate an image object.
20: */
21: public class TransformationSample implements ISample {
22: // <static>
23: // <fields>
24: private static final float Margin = 36;
25:
26: // </fields>
27: // </static>
28:
29: // <dynamic>
30: // <interface>
31: // <public>
32: // <ISample>
33: public void run(PDFClownSampleLoader loader) {
34: // 1. PDF file instantiation.
35: File file = new File();
36:
37: // 2. Content creation.
38: Document document = file.getDocument();
39: populate(document, loader);
40:
41: // (boilerplate metadata insertion -- ignore it)
42: loader.buildAccessories(document, this .getClass(),
43: "Transformation", "graphics object transformation");
44:
45: // 3. Serialize the PDF file (again, boilerplate code -- see the PDFClownSampleLoader class source code)!
46: loader.serialize(file, this .getClass().getSimpleName(), false);
47: }
48:
49: // </ISample>
50: // </public>
51:
52: // <private>
53: /**
54: Populates a PDF file with contents.
55: */
56: private void populate(Document document, PDFClownSampleLoader loader) {
57: Page page = new Page(document);
58: document.getPages().add(page);
59: Dimension2D pageSize = page.getSize();
60:
61: PrimitiveFilter builder = new PrimitiveFilter(page);
62: {
63: BlockFilter blockFilter = new BlockFilter(builder);
64: blockFilter.setHyphenation(true);
65: blockFilter.begin(new Rectangle2D.Double(Margin, Margin,
66: (float) pageSize.getWidth() - Margin * 2,
67: (float) pageSize.getHeight() - Margin * 2),
68: AlignmentXEnum.Justify, AlignmentYEnum.Top);
69: StandardType1Font bodyFont = new StandardType1Font(
70: document, StandardType1Font.FamilyNameEnum.Courier,
71: true, false);
72: builder.setFont(bodyFont, 32);
73: blockFilter.showText("Transformation sample");
74: blockFilter.showBreak();
75: builder.setFont(bodyFont, 16);
76: blockFilter
77: .showText("Showing the GNU logo placed on the page center, rotated by 25 degrees clockwise.");
78: blockFilter.end();
79: }
80: // Showing the 'GNU' image...
81: {
82: // Instantiate a jpeg image object!
83: Image image = Image.get(loader.getInputPath()
84: + java.io.File.separator + "images"
85: + java.io.File.separator + "gnu.jpg"); // Abstract image (entity).
86: // Show the image!
87: builder.showXObject(image.toXObject(document),
88: new Point2D.Double((float) pageSize.getWidth() / 2,
89: (float) pageSize.getHeight() / 2),
90: new Dimension(0, 0), AlignmentXEnum.Center,
91: AlignmentYEnum.Middle, -25);
92: }
93: builder.flush();
94: }
95: // </private>
96: // </interface>
97: // </dynamic>
98: }
|