1 28 package net.sf.jasperreports.engine.base; 29 30 import java.awt.font.TextAttribute ; 31 import java.io.Serializable ; 32 import java.util.Map ; 33 34 import net.sf.jasperreports.engine.JRConstants; 35 import net.sf.jasperreports.engine.JRDefaultFontProvider; 36 import net.sf.jasperreports.engine.JRDefaultStyleProvider; 37 import net.sf.jasperreports.engine.JRFont; 38 import net.sf.jasperreports.engine.JRReportFont; 39 import net.sf.jasperreports.engine.JRStyle; 40 import net.sf.jasperreports.engine.util.JRStyleResolver; 41 import net.sf.jasperreports.engine.util.JRTextAttribute; 42 43 44 48 public class JRBaseFont implements JRFont, Serializable 49 { 50 51 52 55 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 56 57 60 protected JRDefaultFontProvider defaultFontProvider = null; 61 62 65 protected JRReportFont reportFont = null; 66 67 protected String fontName = null; 68 protected Boolean isBold = null; 69 protected Boolean isItalic = null; 70 protected Boolean isUnderline = null; 71 protected Boolean isStrikeThrough = null; 72 protected Integer fontSize = null; 73 protected String pdfFontName = null; 74 protected String pdfEncoding = null; 75 protected Boolean isPdfEmbedded = null; 76 77 78 81 public JRBaseFont() 82 { 83 } 84 85 86 89 public JRBaseFont(Map attributes) 90 { 91 String fontNameAttr = (String )attributes.get(TextAttribute.FAMILY); 92 if (fontNameAttr != null) 93 { 94 setFontName(fontNameAttr); 95 } 96 97 Object bold = attributes.get(TextAttribute.WEIGHT); 98 if (bold != null) 99 { 100 setBold(TextAttribute.WEIGHT_BOLD.equals(bold)); 101 } 102 103 Object italic = attributes.get(TextAttribute.POSTURE); 104 if (italic != null) 105 { 106 setItalic(TextAttribute.POSTURE_OBLIQUE.equals(italic)); 107 } 108 109 Float sizeAttr = (Float )attributes.get(TextAttribute.SIZE); 110 if (sizeAttr != null) 111 { 112 setFontSize(sizeAttr.intValue()); 113 } 114 115 Object underline = attributes.get(TextAttribute.UNDERLINE); 116 if (underline != null) 117 { 118 setUnderline(TextAttribute.UNDERLINE_ON.equals(underline)); 119 } 120 121 Object strikeThrough = attributes.get(TextAttribute.STRIKETHROUGH); 122 if (strikeThrough != null) 123 { 124 setStrikeThrough(TextAttribute.STRIKETHROUGH_ON.equals(strikeThrough)); 125 } 126 127 String pdfFontNameAttr = (String )attributes.get(JRTextAttribute.PDF_FONT_NAME); 128 if (pdfFontNameAttr != null) 129 { 130 setPdfFontName(pdfFontNameAttr); 131 } 132 133 String pdfEncodingAttr = (String )attributes.get(JRTextAttribute.PDF_ENCODING); 134 if (pdfEncodingAttr != null) 135 { 136 setPdfEncoding(pdfEncodingAttr); 137 } 138 139 Boolean isPdfEmbeddedAttr = (Boolean )attributes.get(JRTextAttribute.IS_PDF_EMBEDDED); 140 if (isPdfEmbeddedAttr != null) 141 { 142 setPdfEmbedded(isPdfEmbeddedAttr); 143 } 144 } 145 146 147 150 protected JRBaseFont(JRDefaultFontProvider defaultFontProvider) 151 { 152 this.defaultFontProvider = defaultFontProvider; 153 } 154 155 156 159 public JRBaseFont( 160 JRDefaultFontProvider defaultFontProvider, 161 JRReportFont reportFont, 162 JRFont font 163 ) 164 { 165 this.defaultFontProvider = defaultFontProvider; 166 167 this.reportFont = reportFont; 168 169 fontName = font.getOwnFontName(); 170 isBold = font.isOwnBold(); 171 isItalic = font.isOwnItalic(); 172 isUnderline = font.isOwnUnderline(); 173 isStrikeThrough = font.isOwnStrikeThrough(); 174 fontSize = font.getOwnFontSize(); 175 pdfFontName = font.getOwnPdfFontName(); 176 pdfEncoding = font.getOwnPdfEncoding(); 177 isPdfEmbedded = font.isOwnPdfEmbedded(); 178 } 179 180 181 184 public JRDefaultFontProvider getDefaultFontProvider() 185 { 186 return defaultFontProvider; 187 } 188 189 192 public JRDefaultStyleProvider getDefaultStyleProvider() 193 { 194 return null; 195 } 196 197 200 public JRStyle getStyle() 201 { 202 return null; 203 } 204 205 208 public JRReportFont getReportFont() 209 { 210 return reportFont; 211 } 212 213 216 public void setReportFont(JRReportFont reportFont) 217 { 218 this.reportFont = reportFont; 219 } 220 221 224 public String getFontName() 225 { 226 return JRStyleResolver.getFontName(this); 227 } 228 229 232 public String getOwnFontName() 233 { 234 return fontName; 235 } 236 237 240 public void setFontName(String fontName) 241 { 242 this.fontName = fontName; 243 } 244 245 246 249 public boolean isBold() 250 { 251 return JRStyleResolver.isBold(this); 252 } 253 254 257 public Boolean isOwnBold() 258 { 259 return isBold; 260 } 261 262 265 public void setBold(boolean isBold) 266 { 267 setBold(isBold ? Boolean.TRUE : Boolean.FALSE); 268 } 269 270 274 public void setBold(Boolean isBold) 275 { 276 this.isBold = isBold; 277 } 278 279 280 283 public boolean isItalic() 284 { 285 return JRStyleResolver.isItalic(this); 286 } 287 288 291 public Boolean isOwnItalic() 292 { 293 return isItalic; 294 } 295 296 299 public void setItalic(boolean isItalic) 300 { 301 setItalic(isItalic ? Boolean.TRUE : Boolean.FALSE); 302 } 303 304 308 public void setItalic(Boolean isItalic) 309 { 310 this.isItalic = isItalic; 311 } 312 313 316 public boolean isUnderline() 317 { 318 return JRStyleResolver.isUnderline(this); 319 } 320 321 324 public Boolean isOwnUnderline() 325 { 326 return isUnderline; 327 } 328 329 332 public void setUnderline(boolean isUnderline) 333 { 334 setUnderline(isUnderline ? Boolean.TRUE : Boolean.FALSE); 335 } 336 337 341 public void setUnderline(Boolean isUnderline) 342 { 343 this.isUnderline = isUnderline; 344 } 345 346 349 public boolean isStrikeThrough() 350 { 351 return JRStyleResolver.isStrikeThrough(this); 352 } 353 354 357 public Boolean isOwnStrikeThrough() 358 { 359 return isStrikeThrough; 360 } 361 362 365 public void setStrikeThrough(boolean isStrikeThrough) 366 { 367 setStrikeThrough(isStrikeThrough ? Boolean.TRUE : Boolean.FALSE); 368 } 369 370 374 public void setStrikeThrough(Boolean isStrikeThrough) 375 { 376 this.isStrikeThrough = isStrikeThrough; 377 } 378 379 382 public int getFontSize() 383 { 384 return JRStyleResolver.getFontSize(this); 385 } 386 387 390 public Integer getOwnFontSize() 391 { 392 return fontSize; 393 } 394 395 398 public void setFontSize(int fontSize) 399 { 400 setFontSize(new Integer (fontSize)); 401 } 402 403 407 public void setFontSize(Integer fontSize) 408 { 409 this.fontSize = fontSize; 410 } 411 412 415 public int getSize() 416 { 417 return getFontSize(); 418 } 419 420 423 public Integer getOwnSize() 424 { 425 return getOwnFontSize(); 426 } 427 428 431 public void setSize(int size) 432 { 433 setFontSize(size); 434 } 435 436 439 public void setSize(Integer size) 440 { 441 setFontSize(size) 442 ; } 443 444 447 public String getPdfFontName() 448 { 449 return JRStyleResolver.getPdfFontName(this); 450 } 451 452 455 public String getOwnPdfFontName() 456 { 457 return pdfFontName; 458 } 459 460 463 public void setPdfFontName(String pdfFontName) 464 { 465 this.pdfFontName = pdfFontName; 466 } 467 468 469 472 public String getPdfEncoding() 473 { 474 return JRStyleResolver.getPdfEncoding(this); 475 } 476 477 480 public String getOwnPdfEncoding() 481 { 482 return pdfEncoding; 483 } 484 485 488 public void setPdfEncoding(String pdfEncoding) 489 { 490 this.pdfEncoding = pdfEncoding; 491 } 492 493 494 497 public boolean isPdfEmbedded() 498 { 499 return JRStyleResolver.isPdfEmbedded(this); 500 } 501 502 505 public Boolean isOwnPdfEmbedded() 506 { 507 return isPdfEmbedded; 508 } 509 510 513 public void setPdfEmbedded(boolean isPdfEmbedded) 514 { 515 setPdfEmbedded(isPdfEmbedded ? Boolean.TRUE : Boolean.FALSE); 516 } 517 518 522 public void setPdfEmbedded(Boolean isPdfEmbedded) 523 { 524 this.isPdfEmbedded = isPdfEmbedded; 525 } 526 527 528 } 529 | Popular Tags |