3 // This file is part of PosterDivider.
5 package jp.sourceforge.posterdivider;
8 import java.util.Locale;
9 import java.util.ResourceBundle;
11 import com.itextpdf.text.Image;
12 import com.itextpdf.text.PageSize;
13 import com.itextpdf.text.Rectangle;
14 import com.itextpdf.text.Utilities;
15 //import com.lowagie.text.*;
19 public final static int OS_WIN = 0;
20 public final static int OS_MAC = 1;
21 public final static int OS_OTHER = 2;
24 public final static int FT_NONE = 0;
25 public final static int FT_PDF = 1;
26 public final static int FT_BMP = 2;
27 public final static int FT_GIF = 3;
28 public final static int FT_JBIG2 = 4;
29 public final static int FT_JPEG = 5;
30 public final static int FT_JPEG2000 = 6;
31 public final static int FT_PNG = 7;
32 public final static int FT_TIFF = 8;
33 public final static int FT_WMF = 9;
34 public final static int FT_OTHERIMAGE = 10;
37 public final static double UNIT_POINT_POINT = 1.0;
38 public final static double UNIT_POINT_INCH = Utilities.pointsToInches(1);
39 public final static double UNIT_POINT_MM = Utilities.pointsToMillimeters(1);
40 public final static double UNIT_POINT_CM = UNIT_POINT_MM / 10;
41 public final static double UNIT_POINT_M = UNIT_POINT_MM / 1000;
42 public final static double UNIT_PIXEL_PIXEL = 1.0;
44 public static int getImageFileType(Image image) {
45 switch (image.getOriginalType()) {
46 case Image.ORIGINAL_BMP:
48 case Image.ORIGINAL_GIF:
50 case Image.ORIGINAL_JBIG2:
52 case Image.ORIGINAL_JPEG:
54 case Image.ORIGINAL_JPEG2000:
56 case Image.ORIGINAL_PNG:
58 case Image.ORIGINAL_TIFF:
60 case Image.ORIGINAL_WMF:
67 public static String getFileTypeName(int fileType) {
93 public static int judgeFileTypeFromExtention(File f) {
94 if(f == null) return FT_NONE;
95 String s = f.getName();
96 int p = f.getName().lastIndexOf(".");
97 if(p < 0) return FT_NONE;
98 s = s.substring(p).toLowerCase();
100 if(s.equals(".pdf")) {
102 } else if (s.equals(".bmp")) {
104 } else if (s.equals(".gif")) {
106 } else if (s.equals(".jbg") || s.equals(".jbig")) {
108 } else if (s.equals(".jpeg") || s.equals(".jpg") || s.equals(".jpe") || s.equals(".jfif") || s.equals(".jfi") || s.equals(".jif")) {
110 } else if (s.equals(".jp2") || s.equals(".j2c")) {
112 } else if (s.equals(".png")) {
114 } else if (s.equals(".tiff") || s.equals("tif")) {
116 } else if (s.equals(".wmf") || s.equals(".emf") || s.equals(".wmz") || s.equals(".emz")) {
123 private static String osName;
124 private static int os;
125 private static ResourceBundle resourceBundle;
127 osName = System.getProperty("os.name");
128 String lowerOSName = osName.toLowerCase();
129 if(lowerOSName.startsWith("win")) {
131 } else if(lowerOSName.startsWith("mac")) {
137 resourceBundle = ResourceBundle.getBundle("jp.sourceforge.posterdivider.Message", Locale.getDefault());
140 public static int getOS() {
143 public static String getOSName() {
147 public static String getMessage(String key) {
149 String value = resourceBundle.getString(key);
150 return new String(value.getBytes("ISO-8859-1"), "UTF-8");
151 } catch (Exception ex) {
156 public static byte[] FileReadAllBytes(File file) throws Exception {
159 is = new FileInputStream(file);
160 int length = is.available();
161 byte[] data = new byte[length];
169 public final static PaperSize A0 = new PaperSize(PageSize.A0);
170 public final static PaperSize A1 = new PaperSize(PageSize.A1);
171 public final static PaperSize A2 = new PaperSize(PageSize.A2);
172 public final static PaperSize A3 = new PaperSize(PageSize.A3);
173 public final static PaperSize A4 = new PaperSize(PageSize.A4);
174 public final static PaperSize A5 = new PaperSize(PageSize.A5);
175 public final static PaperSize A6 = new PaperSize(PageSize.A6);
176 public final static PaperSize B0 = new PaperSize(PageSize.B0);
177 public final static PaperSize B1 = new PaperSize(PageSize.B1);
178 public final static PaperSize B2 = new PaperSize(PageSize.B2);
179 public final static PaperSize B3 = new PaperSize(PageSize.B3);
180 public final static PaperSize B4 = new PaperSize(PageSize.B4);
181 public final static PaperSize B5 = new PaperSize(PageSize.B5);
182 public final static PaperSize B6 = new PaperSize(PageSize.B6);
183 public final static PaperSize CUSTOM = new PaperSize(true, 0, 0);
185 private boolean custom;
187 private float height;
189 public boolean isCustom() {
193 public float getWidth() {
197 public float getHeight() {
201 public PaperSize(boolean custom, float width, float height) {
202 this.custom = custom;
204 this.height = height;
207 private PaperSize(Rectangle rect) {
209 this.width = rect.getWidth();
210 this.height = rect.getHeight();