00001
00033 #ifndef LL_LLFONTGL_H
00034 #define LL_LLFONTGL_H
00035
00036 #include "llfont.h"
00037 #include "llimagegl.h"
00038 #include "v2math.h"
00039 #include "llcoord.h"
00040 #include "llrect.h"
00041
00042 class LLColor4;
00043
00044 class LLFontGL : public LLFont
00045 {
00046 public:
00047 enum HAlign
00048 {
00049
00050 LEFT = 0,
00051 RIGHT = 1,
00052 HCENTER = 2,
00053 };
00054
00055 enum VAlign
00056 {
00057
00058 TOP = 3,
00059 VCENTER = 4,
00060 BASELINE = 5,
00061 BOTTOM = 6
00062 };
00063
00064 enum StyleFlags
00065 {
00066
00067 NORMAL = 0,
00068 BOLD = 1,
00069 ITALIC = 2,
00070 UNDERLINE = 4,
00071 DROP_SHADOW = 8,
00072 DROP_SHADOW_SOFT = 16
00073 };
00074
00075
00076 static U8 getStyleFromString(const LLString &style);
00077
00078 LLFontGL();
00079 LLFontGL(const LLFontGL &source);
00080 ~LLFontGL();
00081
00082 void init();
00083 void reset();
00084
00085 LLFontGL &operator=(const LLFontGL &source);
00086
00087 static BOOL initDefaultFonts(F32 screen_dpi, F32 x_scale, F32 y_scale,
00088 const LLString& monospace_file, F32 monospace_size,
00089 const LLString& sansserif_file,
00090 const LLString& sansserif_fallback_file, F32 ss_fallback_scale,
00091 F32 small_size, F32 medium_size, F32 large_size, F32 huge_size,
00092 const LLString& sansserif_bold_file, F32 bold_size,
00093 const LLString& app_dir = LLString::null);
00094
00095 static void destroyDefaultFonts();
00096 static void destroyGL();
00097
00098 static bool loadFaceFallback(LLFontList *fontp, const LLString& fontname, const F32 point_size);
00099 static bool loadFace(LLFontGL *fontp, const LLString& fontname, const F32 point_size, LLFontList *fallback_fontp);
00100 BOOL loadFace(const LLString& filename, const F32 point_size, const F32 vert_dpi, const F32 horz_dpi);
00101
00102
00103 S32 renderUTF8(const LLString &text, const S32 begin_offset,
00104 S32 x, S32 y,
00105 const LLColor4 &color) const
00106 {
00107 return renderUTF8(text, begin_offset, (F32)x, (F32)y, color,
00108 LEFT, BASELINE, NORMAL,
00109 S32_MAX, S32_MAX, NULL, FALSE);
00110 }
00111
00112 S32 renderUTF8(const LLString &text, const S32 begin_offset,
00113 S32 x, S32 y,
00114 const LLColor4 &color,
00115 HAlign halign, VAlign valign, U8 style = NORMAL) const
00116 {
00117 return renderUTF8(text, begin_offset, (F32)x, (F32)y, color,
00118 halign, valign, style,
00119 S32_MAX, S32_MAX, NULL, FALSE);
00120 }
00121
00122
00123 S32 renderUTF8(const LLString &text,
00124 S32 begin_offset,
00125 F32 x, F32 y,
00126 const LLColor4 &color,
00127 HAlign halign,
00128 VAlign valign,
00129 U8 style,
00130 S32 max_chars,
00131 S32 max_pixels,
00132 F32* right_x,
00133 BOOL use_ellipses) const;
00134
00135 S32 render(const LLWString &text, const S32 begin_offset,
00136 F32 x, F32 y,
00137 const LLColor4 &color) const
00138 {
00139 return render(text, begin_offset, x, y, color,
00140 LEFT, BASELINE, NORMAL,
00141 S32_MAX, S32_MAX, NULL, FALSE, FALSE);
00142 }
00143
00144
00145 S32 render(const LLWString &text,
00146 S32 begin_offset,
00147 F32 x, F32 y,
00148 const LLColor4 &color,
00149 HAlign halign = LEFT,
00150 VAlign valign = BASELINE,
00151 U8 style = NORMAL,
00152 S32 max_chars = S32_MAX,
00153 S32 max_pixels = S32_MAX,
00154 F32* right_x=NULL,
00155 BOOL use_embedded = FALSE,
00156 BOOL use_ellipses = FALSE) const;
00157
00158
00159 F32 getLineHeight() const { return (F32)llround(mLineHeight / sScaleY); }
00160 F32 getAscenderHeight() const { return (F32)llround(mAscender / sScaleY); }
00161 F32 getDescenderHeight() const { return (F32)llround(mDescender / sScaleY); }
00162
00163 virtual S32 getWidth(const LLString& utf8text) const;
00164 virtual S32 getWidth(const llwchar* wchars) const;
00165 virtual S32 getWidth(const LLString& utf8text, const S32 offset, const S32 max_chars ) const;
00166 virtual S32 getWidth(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE) const;
00167
00168 virtual F32 getWidthF32(const LLString& utf8text) const;
00169 virtual F32 getWidthF32(const llwchar* wchars) const;
00170 virtual F32 getWidthF32(const LLString& text, const S32 offset, const S32 max_chars ) const;
00171 virtual F32 getWidthF32(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE ) const;
00172
00173
00174
00175
00176 virtual S32 maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_chars = S32_MAX,
00177 BOOL end_on_word_boundary = FALSE, const BOOL use_embedded = FALSE,
00178 F32* drawn_pixels = NULL) const;
00179
00180
00181
00182 virtual S32 firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_len, S32 start_pos=S32_MAX, S32 max_chars = S32_MAX) const;
00183
00184
00185 virtual S32 charFromPixelOffset(const llwchar* wchars, const S32 char_offset,
00186 F32 x, F32 max_pixels=F32_MAX, S32 max_chars = S32_MAX,
00187 BOOL round = TRUE, BOOL use_embedded = FALSE) const;
00188
00189
00190 LLImageGL *getImageGL() const;
00191
00192 void addEmbeddedChar( llwchar wc, LLImageGL* image, const LLString& label);
00193 void addEmbeddedChar( llwchar wc, LLImageGL* image, const LLWString& label);
00194 void removeEmbeddedChar( llwchar wc );
00195
00196 static LLString nameFromFont(const LLFontGL* fontp);
00197 static LLFontGL* fontFromName(const LLString& name);
00198
00199 static LLString nameFromHAlign(LLFontGL::HAlign align);
00200 static LLFontGL::HAlign hAlignFromName(const LLString& name);
00201
00202 static LLString nameFromVAlign(LLFontGL::VAlign align);
00203 static LLFontGL::VAlign vAlignFromName(const LLString& name);
00204
00205 protected:
00206 struct embedded_data_t
00207 {
00208 embedded_data_t(LLImageGL* image, const LLWString& label) : mImage(image), mLabel(label) {}
00209 LLPointer<LLImageGL> mImage;
00210 LLWString mLabel;
00211 };
00212 const embedded_data_t* getEmbeddedCharData(const llwchar wch) const;
00213 F32 getEmbeddedCharAdvance(const embedded_data_t* ext_data) const;
00214 void clearEmbeddedChars();
00215 void renderQuad(const LLRectf& screen_rect, const LLRectf& uv_rect, F32 slant_amt) const;
00216 void drawGlyph(const LLRectf& screen_rect, const LLRectf& uv_rect, const LLColor4& color, U8 style, F32 drop_shadow_fade) const;
00217
00218 public:
00219 static F32 sVertDPI;
00220 static F32 sHorizDPI;
00221 static F32 sScaleX;
00222 static F32 sScaleY;
00223 static LLString sAppDir;
00224
00225 static LLFontGL* sMonospace;
00226
00227 static LLFontGL* sSansSerifSmall;
00228 static LLFontList* sSSSmallFallback;
00229 static LLFontGL* sSansSerif;
00230 static LLFontList* sSSFallback;
00231 static LLFontGL* sSansSerifBig;
00232 static LLFontList* sSSBigFallback;
00233 static LLFontGL* sSansSerifHuge;
00234 static LLFontList* sSSHugeFallback;
00235
00236 static LLFontGL* sSansSerifBold;
00237 static LLFontList* sSSBoldFallback;
00238
00239 static LLColor4 sShadowColor;
00240
00241 friend class LLTextBillboard;
00242 friend class LLHUDText;
00243
00244 protected:
00245 BOOL addChar(const llwchar wch);
00246 static LLString getFontPathLocal();
00247 static LLString getFontPathSystem();
00248
00249 protected:
00250 LLPointer<LLImageRaw> mRawImageGLp;
00251 LLPointer<LLImageGL> mImageGLp;
00252 typedef std::map<llwchar,embedded_data_t*> embedded_map_t;
00253 embedded_map_t mEmbeddedChars;
00254
00255 public:
00256 static LLCoordFont sCurOrigin;
00257 static std::vector<LLCoordFont> sOriginStack;
00258 };
00259
00260 #endif