1 50 51 package com.lowagie.text.pdf; 52 53 import com.lowagie.text.ExceptionConverter; 54 import com.lowagie.text.Image; 55 56 70 71 class PdfFont implements Comparable { 72 73 74 75 private BaseFont font; 76 77 78 private float size; 79 80 81 protected Image image; 82 83 protected float hScale = 1; 84 85 87 PdfFont(BaseFont bf, float size) { 88 this.size = size; 89 font = bf; 90 } 91 92 94 100 101 public int compareTo(Object object) { 102 if (image != null) 103 return 0; 104 if (object == null) { 105 return -1; 106 } 107 PdfFont pdfFont; 108 try { 109 pdfFont = (PdfFont) object; 110 if (font != pdfFont.font) { 111 return 1; 112 } 113 if (this.size() != pdfFont.size()) { 114 return 2; 115 } 116 return 0; 117 } 118 catch(ClassCastException cce) { 119 return -2; 120 } 121 } 122 123 128 129 float size() { 130 if (image == null) 131 return size; 132 else { 133 return image.getScaledHeight(); 134 } 135 } 136 137 142 143 float width() { 144 return width(' '); 145 } 146 147 153 154 float width(char character) { 155 if (image == null) 156 return font.getWidthPoint(character, size) * hScale; 157 else 158 return image.getScaledWidth(); 159 } 160 161 float width(String s) { 162 if (image == null) 163 return font.getWidthPoint(s, size) * hScale; 164 else 165 return image.getScaledWidth(); 166 } 167 168 BaseFont getFont() { 169 return font; 170 } 171 172 void setImage(Image image) { 173 this.image = image; 174 } 175 176 static PdfFont getDefaultFont() { 177 try { 178 BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false); 179 return new PdfFont(bf, 12); 180 } 181 catch (Exception ee) { 182 throw new ExceptionConverter(ee); 183 } 184 } 185 void setHorizontalScaling(float hScale) { 186 this.hScale = hScale; 187 } 188 } 189 | Popular Tags |