1 17 18 19 20 package org.apache.fop.render.pcl; 21 22 import java.awt.Dimension ; 23 import java.awt.Rectangle ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import org.apache.fop.util.UnitConv; 28 29 32 public class PCLPageDefinition { 33 34 private static List pageDefinitions; 35 private static PCLPageDefinition defaultPageDefinition; 36 37 private String name; 38 private int selector; 39 private Dimension physicalPageSize; 40 private Rectangle logicalPageRect; 41 private boolean landscape; 42 43 static { 44 createPageDefinitions(); 45 } 46 47 55 public PCLPageDefinition(String name, int selector, Dimension physicalPageSize, 56 Rectangle logicalPageRect, boolean landscape) { 57 this.name = name; 58 this.selector = selector; 59 this.physicalPageSize = physicalPageSize; 60 this.logicalPageRect = logicalPageRect; 61 this.landscape = landscape; 62 } 63 64 65 public String getName() { 66 return this.name; 67 } 68 69 70 public int getSelector() { 71 return this.selector; 72 } 73 74 75 public boolean isLandscapeFormat() { 76 return this.landscape; 77 } 78 79 80 public Dimension getPhysicalPageSize() { 81 return this.physicalPageSize; 82 } 83 84 85 public Rectangle getLogicalPageRect() { 86 return this.logicalPageRect; 87 } 88 89 private boolean matches(long width, long height, int errorMargin) { 90 return (Math.abs(this.physicalPageSize.width - width) < errorMargin) 91 && (Math.abs(this.physicalPageSize.height - height) < errorMargin); 92 } 93 94 95 public String toString() { 96 return getName(); 97 } 98 99 106 public static PCLPageDefinition getPageDefinition(long width, long height, int errorMargin) { 107 Iterator iter = pageDefinitions.iterator(); 108 while (iter.hasNext()) { 109 PCLPageDefinition def = (PCLPageDefinition)iter.next(); 110 if (def.matches(width, height, errorMargin)) { 111 return def; 112 } 113 } 114 return null; 115 } 116 117 118 public static PCLPageDefinition getDefaultPageDefinition() { 119 return defaultPageDefinition; 120 } 121 122 128 private static int convert300dpiDotsToMpt(int offset) { 129 return (int)Math.round(((double)offset) * 72000 / 300); 130 } 131 132 private static Dimension createPhysicalPageSizeInch(float width, float height) { 133 return new Dimension ( 134 (int)Math.round(UnitConv.in2mpt(width)), 135 (int)Math.round(UnitConv.in2mpt(height))); 136 } 137 138 private static Dimension createPhysicalPageSizeMm(float width, float height) { 139 return new Dimension ( 140 (int)Math.round(UnitConv.mm2mpt(width)), 141 (int)Math.round(UnitConv.mm2mpt(height))); 142 } 143 144 private static Rectangle createLogicalPageRect(int x, int y, int width, int height) { 145 return new Rectangle (convert300dpiDotsToMpt(x), convert300dpiDotsToMpt(y), 146 convert300dpiDotsToMpt(width), convert300dpiDotsToMpt(height)); 147 } 148 149 private static void createPageDefinitions() { 150 pageDefinitions = new java.util.ArrayList (); 151 pageDefinitions.add(new PCLPageDefinition("Letter", 2, 152 createPhysicalPageSizeInch(8.5f, 11), 153 createLogicalPageRect(75, 0, 2400, 3300), false)); 154 defaultPageDefinition = new PCLPageDefinition("Legal", 3, 155 createPhysicalPageSizeInch(8.5f, 14), 156 createLogicalPageRect(75, 0, 2400, 4200), false); 157 pageDefinitions.add(defaultPageDefinition); 158 pageDefinitions.add(new PCLPageDefinition("Executive", 1, 159 createPhysicalPageSizeInch(7.25f, 10.5f), 160 createLogicalPageRect(75, 0, 2025, 3150), false)); 161 pageDefinitions.add(new PCLPageDefinition("Ledger", 6, 162 createPhysicalPageSizeInch(11, 17), 163 createLogicalPageRect(75, 0, 3150, 5100), false)); 164 pageDefinitions.add(new PCLPageDefinition("A4", 26, 165 createPhysicalPageSizeMm(210, 297), 166 createLogicalPageRect(71, 0, 2338, 3507), false)); 167 pageDefinitions.add(new PCLPageDefinition("A3", 27, 168 createPhysicalPageSizeMm(297, 420), 169 createLogicalPageRect(71, 0, 3365, 4960), false)); 170 171 173 pageDefinitions.add(new PCLPageDefinition("LetterL", 2, 174 createPhysicalPageSizeInch(11, 8.5f), 175 createLogicalPageRect(60, 0, 3180, 2550), true)); 176 pageDefinitions.add(new PCLPageDefinition("LegalL", 3, 177 createPhysicalPageSizeInch(14, 8.5f), 178 createLogicalPageRect(60, 0, 4080, 2550), true)); 179 pageDefinitions.add(new PCLPageDefinition("ExecutiveL", 1, 180 createPhysicalPageSizeInch(10.5f, 7.25f), 181 createLogicalPageRect(60, 0, 3030, 2175), true)); 182 pageDefinitions.add(new PCLPageDefinition("LedgerL", 6, 183 createPhysicalPageSizeInch(17, 11), 184 createLogicalPageRect(60, 0, 4980, 3300), true)); 185 pageDefinitions.add(new PCLPageDefinition("A4L", 26, 186 createPhysicalPageSizeMm(297, 210), 187 createLogicalPageRect(59, 0, 3389, 2480), true)); 188 pageDefinitions.add(new PCLPageDefinition("A3L", 27, 189 createPhysicalPageSizeMm(420, 297), 190 createLogicalPageRect(59, 0, 4842, 3507), true)); 191 } 192 193 } 194 | Popular Tags |