llfontgl.h

Go to the documentation of this file.
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                 // Horizontal location of x,y coord to render.
00050                 LEFT = 0,               // Left align
00051                 RIGHT = 1,              // Right align
00052                 HCENTER = 2,    // Center
00053         };
00054 
00055         enum VAlign
00056         {
00057                 // Vertical location of x,y coord to render.
00058                 TOP = 3,                // Top align
00059                 VCENTER = 4,    // Center
00060                 BASELINE = 5,   // Baseline
00061                 BOTTOM = 6              // Bottom
00062         };
00063 
00064         enum StyleFlags
00065         {
00066                 // text style to render.  May be combined (these are bit flags)
00067                 NORMAL = 0,     
00068                 BOLD = 1,
00069                 ITALIC = 2,
00070                 UNDERLINE = 4,
00071                 DROP_SHADOW = 8,
00072                 DROP_SHADOW_SOFT = 16
00073         };
00074         
00075         // Takes a string with potentially several flags, i.e. "NORMAL|BOLD|ITALIC"
00076         static U8 getStyleFromString(const LLString &style);
00077 
00078         LLFontGL();
00079         LLFontGL(const LLFontGL &source);
00080         ~LLFontGL();
00081 
00082         void init(); // Internal init, or reinitialization
00083         void reset(); // Reset a font after GL cleanup.  ONLY works on an already loaded font.
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         /* virtual*/ BOOL loadFace(const std::string& filename,
00101                                                             const F32 point_size, const F32 vert_dpi, const F32 horz_dpi,
00102                                                             const S32 components, BOOL is_fallback);
00103 
00104 
00105         S32 renderUTF8(const LLString &text, const S32 begin_offset,
00106                                    S32 x, S32 y,
00107                                    const LLColor4 &color) const
00108         {
00109                 return renderUTF8(text, begin_offset, (F32)x, (F32)y, color,
00110                                                   LEFT, BASELINE, NORMAL,
00111                                                   S32_MAX, S32_MAX, NULL, FALSE);
00112         }
00113         
00114         S32 renderUTF8(const LLString &text, const S32 begin_offset,
00115                                    S32 x, S32 y,
00116                                    const LLColor4 &color,
00117                                    HAlign halign, VAlign valign, U8 style = NORMAL) const
00118         {
00119                 return renderUTF8(text, begin_offset, (F32)x, (F32)y, color,
00120                                                   halign, valign, style,
00121                                                   S32_MAX, S32_MAX, NULL, FALSE);
00122         }
00123         
00124         // renderUTF8 does a conversion, so is slower!
00125         S32 renderUTF8(const LLString &text,
00126                 S32 begin_offset,
00127                 F32 x, F32 y,
00128                 const LLColor4 &color,
00129                 HAlign halign, 
00130                 VAlign valign,
00131                 U8 style,
00132                 S32 max_chars,
00133                 S32 max_pixels, 
00134                 F32* right_x,
00135                 BOOL use_ellipses) const;
00136 
00137         S32 render(const LLWString &text, const S32 begin_offset,
00138                            F32 x, F32 y,
00139                            const LLColor4 &color) const
00140         {
00141                 return render(text, begin_offset, x, y, color,
00142                                           LEFT, BASELINE, NORMAL,
00143                                           S32_MAX, S32_MAX, NULL, FALSE, FALSE);
00144         }
00145         
00146 
00147         S32 render(const LLWString &text,
00148                 S32 begin_offset,
00149                 F32 x, F32 y,
00150                 const LLColor4 &color,
00151                 HAlign halign = LEFT, 
00152                 VAlign valign = BASELINE,
00153                 U8 style = NORMAL,
00154                 S32 max_chars = S32_MAX,
00155                 S32 max_pixels = S32_MAX, 
00156                 F32* right_x=NULL,
00157                 BOOL use_embedded = FALSE,
00158                 BOOL use_ellipses = FALSE) const;
00159 
00160         // font metrics - override for LLFont that returns units of virtual pixels
00161         /*virtual*/ F32 getLineHeight() const           { return (F32)llround(mLineHeight / sScaleY); }
00162         /*virtual*/ F32 getAscenderHeight() const       { return (F32)llround(mAscender / sScaleY); }
00163         /*virtual*/ F32 getDescenderHeight() const      { return (F32)llround(mDescender / sScaleY); }
00164         
00165         virtual S32 getWidth(const LLString& utf8text) const;
00166         virtual S32 getWidth(const llwchar* wchars) const;
00167         virtual S32 getWidth(const LLString& utf8text, const S32 offset, const S32 max_chars ) const;
00168         virtual S32 getWidth(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE) const;
00169 
00170         virtual F32 getWidthF32(const LLString& utf8text) const;
00171         virtual F32 getWidthF32(const llwchar* wchars) const;
00172         virtual F32 getWidthF32(const LLString& text, const S32 offset, const S32 max_chars ) const;
00173         virtual F32 getWidthF32(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE ) const;
00174 
00175         // The following are called often, frequently with large buffers, so do not use a string interface
00176         
00177         // Returns the max number of complete characters from text (up to max_chars) that can be drawn in max_pixels
00178         virtual S32     maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_chars = S32_MAX,
00179                                                                  BOOL end_on_word_boundary = FALSE, const BOOL use_embedded = FALSE,
00180                                                                  F32* drawn_pixels = NULL) const;
00181 
00182         // Returns the index of the first complete characters from text that can be drawn in max_pixels
00183         // starting on the right side (at character start_pos).
00184         virtual S32     firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_len, S32 start_pos=S32_MAX, S32 max_chars = S32_MAX) const;
00185 
00186         // Returns the index of the character closest to pixel position x (ignoring text to the right of max_pixels and max_chars)
00187         virtual S32 charFromPixelOffset(const llwchar* wchars, const S32 char_offset,
00188                                                                         F32 x, F32 max_pixels=F32_MAX, S32 max_chars = S32_MAX,
00189                                                                         BOOL round = TRUE, BOOL use_embedded = FALSE) const;
00190 
00191 
00192         LLImageGL *getImageGL() const;
00193 
00194         void       addEmbeddedChar( llwchar wc, LLImageGL* image, const LLString& label);
00195         void       addEmbeddedChar( llwchar wc, LLImageGL* image, const LLWString& label);
00196         void       removeEmbeddedChar( llwchar wc );
00197 
00198         static LLString nameFromFont(const LLFontGL* fontp);
00199         static LLFontGL* fontFromName(const LLString& name);
00200 
00201         static LLString nameFromHAlign(LLFontGL::HAlign align);
00202         static LLFontGL::HAlign hAlignFromName(const LLString& name);
00203 
00204         static LLString nameFromVAlign(LLFontGL::VAlign align);
00205         static LLFontGL::VAlign vAlignFromName(const LLString& name);
00206 
00207         static void setFontDisplay(BOOL flag) { sDisplayFont = flag ; }
00208 
00209 protected:
00210         struct embedded_data_t
00211         {
00212                 embedded_data_t(LLImageGL* image, const LLWString& label) : mImage(image), mLabel(label) {}
00213                 LLPointer<LLImageGL> mImage;
00214                 LLWString                        mLabel;
00215         };
00216         const embedded_data_t* getEmbeddedCharData(const llwchar wch) const;
00217         F32 getEmbeddedCharAdvance(const embedded_data_t* ext_data) const;
00218         void clearEmbeddedChars();
00219         void renderQuad(const LLRectf& screen_rect, const LLRectf& uv_rect, F32 slant_amt) const;
00220         void drawGlyph(const LLRectf& screen_rect, const LLRectf& uv_rect, const LLColor4& color, U8 style, F32 drop_shadow_fade) const;
00221 
00222 public:
00223         static F32 sVertDPI;
00224         static F32 sHorizDPI;
00225         static F32 sScaleX;
00226         static F32 sScaleY;
00227         static BOOL     sDisplayFont ;
00228         static LLString sAppDir;                        // For loading fonts
00229                 
00230         static LLFontGL*        sMonospace;             // medium
00231         static LLFontList*      sMonospaceFallback;
00232 
00233         static LLFontGL*        sSansSerifSmall;        // small
00234         static LLFontList*      sSSSmallFallback;
00235         static LLFontGL*        sSansSerif;             // medium
00236         static LLFontList*      sSSFallback;
00237         static LLFontGL*        sSansSerifBig;          // large
00238         static LLFontList*      sSSBigFallback;
00239         static LLFontGL*        sSansSerifHuge; // very large
00240         static LLFontList*      sSSHugeFallback;
00241 
00242         static LLFontGL*        sSansSerifBold; // medium, bolded
00243         static LLFontList*      sSSBoldFallback;
00244 
00245         static LLColor4 sShadowColor;
00246 
00247         friend class LLTextBillboard;
00248         friend class LLHUDText;
00249 
00250 protected:
00251         /*virtual*/ BOOL addChar(const llwchar wch);
00252         static LLString getFontPathLocal();
00253         static LLString getFontPathSystem();    
00254 
00255 protected:
00256         LLPointer<LLImageRaw>   mRawImageGLp;
00257         LLPointer<LLImageGL>    mImageGLp;
00258         typedef std::map<llwchar,embedded_data_t*> embedded_map_t;
00259         embedded_map_t mEmbeddedChars;
00260         
00261 public:
00262         static LLCoordFont sCurOrigin;
00263         static std::vector<LLCoordFont> sOriginStack;
00264 };
00265 
00266 #endif

Generated on Fri May 16 08:32:49 2008 for SecondLife by  doxygen 1.5.5