001: /*****************************************************************************
002: * FontFamily.java
003: * ****************************************************************************/package org.openlaszlo.compiler;
004:
005: import org.openlaszlo.iv.flash.api.text.*;
006:
007: import java.awt.geom.Rectangle2D;
008:
009: /**
010: * Class for holding Font Families
011: *
012: * @author Eric Bloch
013: */
014: final class FontFamily {
015:
016: private Rectangle2D[] boundsPlain = null;
017: private Rectangle2D[] boundsBold = null;
018: private Rectangle2D[] boundsItalic = null;
019: private Rectangle2D[] boundsBitalic = null;
020:
021: public FontFamily() {
022: plain = null;
023: bold = null;
024: italic = null;
025: bitalic = null;
026: }
027:
028: /**
029: * Create a font description
030: */
031: public FontFamily(Font plain, Font bold, Font italic, Font bitalic) {
032: this .plain = plain;
033: this .bold = bold;
034: this .italic = italic;
035: this .bitalic = bitalic;
036: }
037:
038: /**
039: * @return the font font for the given style
040: */
041: public Font getStyle(int style) {
042: switch (style) {
043: case FontInfo.PLAIN:
044: return plain;
045: case FontInfo.BOLD:
046: return bold;
047: case FontInfo.ITALIC:
048: return italic;
049: case FontInfo.BOLDITALIC:
050: return bitalic;
051: default:
052: throw new CompilationError(
053: /* (non-Javadoc)
054: * @i18n.test
055: * @org-mes="Unknown style " + p[0]
056: */
057: org.openlaszlo.i18n.LaszloMessages.getMessage(
058: FontFamily.class.getName(), "051018-63",
059: new Object[] { new Integer(style) }));
060: }
061: }
062:
063: private String getBookRecommendations() {
064: return "http://www.wetmachine.com/books.html";
065: }
066:
067: /**
068: * @return the glpyh bounds array for this font
069: */
070: public Rectangle2D[] getBounds(int style) {
071: switch (style) {
072: case FontInfo.PLAIN:
073: if (plain != null && boundsPlain == null) {
074: boundsPlain = plain.getGlyphBounds();
075: }
076: return boundsPlain;
077: case FontInfo.BOLD:
078: if (bold != null && boundsBold == null) {
079: boundsBold = bold.getGlyphBounds();
080: }
081: return boundsBold;
082: case FontInfo.ITALIC:
083: if (italic != null && boundsItalic == null) {
084: boundsItalic = italic.getGlyphBounds();
085: }
086: return boundsItalic;
087: case FontInfo.BOLDITALIC:
088: if (bitalic != null && boundsBitalic == null) {
089: boundsBitalic = bitalic.getGlyphBounds();
090: }
091: return boundsBitalic;
092: default:
093: throw new CompilationError(
094: /* (non-Javadoc)
095: * @i18n.test
096: * @org-mes="Unknown style " + p[0]
097: */
098: org.openlaszlo.i18n.LaszloMessages.getMessage(
099: FontFamily.class.getName(), "051018-63",
100: new Object[] { new Integer(style) }));
101: }
102: }
103:
104: /** the plain font */
105: public Font plain = null;
106: /** the bold font */
107: public Font bold = null;
108: /** the italic font */
109: public Font italic = null;
110: /** the bold italic font */
111: public Font bitalic = null;
112: }
|