diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llrender/llfontgl.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llrender/llfontgl.h | 252 |
1 files changed, 252 insertions, 0 deletions
diff --git a/linden/indra/llrender/llfontgl.h b/linden/indra/llrender/llfontgl.h new file mode 100644 index 0000000..bcb8dfb --- /dev/null +++ b/linden/indra/llrender/llfontgl.h | |||
@@ -0,0 +1,252 @@ | |||
1 | /** | ||
2 | * @file llfontgl.h | ||
3 | * @author Doug Soo | ||
4 | * @brief Wrapper around FreeType | ||
5 | * | ||
6 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
9 | * to you under the terms of the GNU General Public License, version 2.0 | ||
10 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
11 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
12 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
13 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
14 | * | ||
15 | * There are special exceptions to the terms and conditions of the GPL as | ||
16 | * it is applied to this Source Code. View the full text of the exception | ||
17 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
18 | * online at http://secondlife.com/developers/opensource/flossexception | ||
19 | * | ||
20 | * By copying, modifying or distributing this software, you acknowledge | ||
21 | * that you have read and understood your obligations described above, | ||
22 | * and agree to abide by those obligations. | ||
23 | * | ||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
26 | * COMPLETENESS OR PERFORMANCE. | ||
27 | */ | ||
28 | |||
29 | #ifndef LL_LLFONTGL_H | ||
30 | #define LL_LLFONTGL_H | ||
31 | |||
32 | #include "llfont.h" | ||
33 | #include "llimagegl.h" | ||
34 | #include "v2math.h" | ||
35 | #include "llcoord.h" | ||
36 | |||
37 | class LLColor4; | ||
38 | |||
39 | class LLFontGL : public LLFont | ||
40 | { | ||
41 | public: | ||
42 | enum HAlign | ||
43 | { | ||
44 | // Horizontal location of x,y coord to render. | ||
45 | LEFT = 0, // Left align | ||
46 | RIGHT = 1, // Right align | ||
47 | HCENTER = 2, // Center | ||
48 | }; | ||
49 | |||
50 | enum VAlign | ||
51 | { | ||
52 | // Vertical location of x,y coord to render. | ||
53 | TOP = 3, // Top align | ||
54 | VCENTER = 4, // Center | ||
55 | BASELINE = 5, // Baseline | ||
56 | BOTTOM = 6 // Bottom | ||
57 | }; | ||
58 | |||
59 | enum StyleFlags | ||
60 | { | ||
61 | // text style to render. May be combined (these are bit flags) | ||
62 | NORMAL = 0, | ||
63 | BOLD = 1, | ||
64 | ITALIC = 2, | ||
65 | UNDERLINE = 4, | ||
66 | DROP_SHADOW = 8 | ||
67 | }; | ||
68 | |||
69 | // Takes a string with potentially several flags, i.e. "NORMAL|BOLD|ITALIC" | ||
70 | static U8 getStyleFromString(const LLString &style); | ||
71 | |||
72 | LLFontGL(); | ||
73 | LLFontGL(const LLFontGL &source); | ||
74 | ~LLFontGL(); | ||
75 | |||
76 | void init(); // Internal init, or reinitialization | ||
77 | void reset(); // Reset a font after GL cleanup. ONLY works on an already loaded font. | ||
78 | |||
79 | LLFontGL &operator=(const LLFontGL &source); | ||
80 | |||
81 | static BOOL initDefaultFonts(F32 screen_dpi, F32 x_scale, F32 y_scale, | ||
82 | const LLString& monospace_file, F32 monospace_size, | ||
83 | const LLString& sansserif_file, | ||
84 | const LLString& sansserif_fallback_file, F32 ss_fallback_scale, | ||
85 | F32 small_size, F32 medium_size, F32 large_size, F32 huge_size, | ||
86 | const LLString& sansserif_bold_file, F32 bold_size, | ||
87 | const LLString& app_dir = LLString::null); | ||
88 | |||
89 | static void destroyDefaultFonts(); | ||
90 | static void destroyGL(); | ||
91 | |||
92 | static bool loadFaceFallback(LLFontList *fontp, const LLString& fontname, const F32 point_size); | ||
93 | static bool loadFace(LLFontGL *fontp, const LLString& fontname, const F32 point_size, LLFontList *fallback_fontp); | ||
94 | BOOL loadFace(const LLString& filename, const F32 point_size, const F32 vert_dpi, const F32 horz_dpi); | ||
95 | |||
96 | |||
97 | S32 renderUTF8(const LLString &text, const S32 begin_offset, | ||
98 | S32 x, S32 y, | ||
99 | const LLColor4 &color) const | ||
100 | { | ||
101 | return renderUTF8(text, begin_offset, (F32)x, (F32)y, color, | ||
102 | LEFT, BASELINE, NORMAL, | ||
103 | S32_MAX, S32_MAX, NULL, FALSE); | ||
104 | } | ||
105 | |||
106 | S32 renderUTF8(const LLString &text, const S32 begin_offset, | ||
107 | S32 x, S32 y, | ||
108 | const LLColor4 &color, | ||
109 | HAlign halign, VAlign valign, U8 style = NORMAL) const | ||
110 | { | ||
111 | return renderUTF8(text, begin_offset, (F32)x, (F32)y, color, | ||
112 | halign, valign, style, | ||
113 | S32_MAX, S32_MAX, NULL, FALSE); | ||
114 | } | ||
115 | |||
116 | // renderUTF8 does a conversion, so is slower! | ||
117 | S32 renderUTF8(const LLString &text, | ||
118 | S32 begin_offset, | ||
119 | F32 x, F32 y, | ||
120 | const LLColor4 &color, | ||
121 | HAlign halign, | ||
122 | VAlign valign, | ||
123 | U8 style, | ||
124 | S32 max_chars, | ||
125 | S32 max_pixels, | ||
126 | F32* right_x, | ||
127 | BOOL use_ellipses) const; | ||
128 | |||
129 | S32 render(const LLWString &text, const S32 begin_offset, | ||
130 | F32 x, F32 y, | ||
131 | const LLColor4 &color) const | ||
132 | { | ||
133 | return render(text, begin_offset, x, y, color, | ||
134 | LEFT, BASELINE, NORMAL, | ||
135 | S32_MAX, S32_MAX, NULL, FALSE, FALSE); | ||
136 | } | ||
137 | |||
138 | |||
139 | S32 render(const LLWString &text, | ||
140 | S32 begin_offset, | ||
141 | F32 x, F32 y, | ||
142 | const LLColor4 &color, | ||
143 | HAlign halign = LEFT, | ||
144 | VAlign valign = BASELINE, | ||
145 | U8 style = NORMAL, | ||
146 | S32 max_chars = S32_MAX, | ||
147 | S32 max_pixels = S32_MAX, | ||
148 | F32* right_x=NULL, | ||
149 | BOOL use_embedded = FALSE, | ||
150 | BOOL use_ellipses = FALSE) const; | ||
151 | |||
152 | // font metrics - override for LLFont that returns units of virtual pixels | ||
153 | /*virtual*/ F32 getLineHeight() const { return (F32)llround(mLineHeight / sScaleY); } | ||
154 | /*virtual*/ F32 getAscenderHeight() const { return (F32)llround(mAscender / sScaleY); } | ||
155 | /*virtual*/ F32 getDescenderHeight() const { return (F32)llround(mDescender / sScaleY); } | ||
156 | |||
157 | virtual S32 getWidth(const LLString& utf8text) const; | ||
158 | virtual S32 getWidth(const llwchar* wchars) const; | ||
159 | virtual S32 getWidth(const LLString& utf8text, const S32 offset, const S32 max_chars ) const; | ||
160 | virtual S32 getWidth(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE) const; | ||
161 | |||
162 | virtual F32 getWidthF32(const LLString& utf8text) const; | ||
163 | virtual F32 getWidthF32(const llwchar* wchars) const; | ||
164 | virtual F32 getWidthF32(const LLString& text, const S32 offset, const S32 max_chars ) const; | ||
165 | virtual F32 getWidthF32(const llwchar* wchars, const S32 offset, const S32 max_chars, BOOL use_embedded = FALSE ) const; | ||
166 | |||
167 | // The following are called often, frequently with large buffers, so do not use a string interface | ||
168 | |||
169 | // Returns the max number of complete characters from text (up to max_chars) that can be drawn in max_pixels | ||
170 | virtual S32 maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_chars = S32_MAX, | ||
171 | BOOL end_on_word_boundary = FALSE, const BOOL use_embedded = FALSE, | ||
172 | F32* drawn_pixels = NULL) const; | ||
173 | |||
174 | // Returns the index of the first complete characters from text that can be drawn in max_pixels | ||
175 | // starting on the right side (at character start_pos). | ||
176 | virtual S32 firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_len, S32 start_pos=S32_MAX, S32 max_chars = S32_MAX) const; | ||
177 | |||
178 | // Returns the index of the character closest to pixel position x (ignoring text to the right of max_pixels and max_chars) | ||
179 | virtual S32 charFromPixelOffset(const llwchar* wchars, const S32 char_offset, | ||
180 | F32 x, F32 max_pixels=F32_MAX, S32 max_chars = S32_MAX, | ||
181 | BOOL round = TRUE, BOOL use_embedded = FALSE) const; | ||
182 | |||
183 | |||
184 | LLImageGL *getImageGL() const; | ||
185 | |||
186 | void addEmbeddedChar( llwchar wc, LLImageGL* image, const LLString& label); | ||
187 | void addEmbeddedChar( llwchar wc, LLImageGL* image, const LLWString& label); | ||
188 | void removeEmbeddedChar( llwchar wc ); | ||
189 | |||
190 | static LLString nameFromFont(const LLFontGL* fontp); | ||
191 | static LLFontGL* fontFromName(const LLString& name); | ||
192 | |||
193 | static LLString nameFromHAlign(LLFontGL::HAlign align); | ||
194 | static LLFontGL::HAlign hAlignFromName(const LLString& name); | ||
195 | |||
196 | static LLString nameFromVAlign(LLFontGL::VAlign align); | ||
197 | static LLFontGL::VAlign vAlignFromName(const LLString& name); | ||
198 | |||
199 | protected: | ||
200 | struct embedded_data_t | ||
201 | { | ||
202 | embedded_data_t(LLImageGL* image, const LLWString& label) : mImage(image), mLabel(label) {} | ||
203 | LLPointer<LLImageGL> mImage; | ||
204 | LLWString mLabel; | ||
205 | }; | ||
206 | const embedded_data_t* getEmbeddedCharData(const llwchar wch) const; | ||
207 | F32 getEmbeddedCharAdvance(const embedded_data_t* ext_data) const; | ||
208 | void clearEmbeddedChars(); | ||
209 | |||
210 | public: | ||
211 | static F32 sVertDPI; | ||
212 | static F32 sHorizDPI; | ||
213 | static F32 sScaleX; | ||
214 | static F32 sScaleY; | ||
215 | static LLString sAppDir; // For loading fonts | ||
216 | |||
217 | static LLFontGL* sMonospace; // medium | ||
218 | |||
219 | static LLFontGL* sSansSerifSmall; // small | ||
220 | static LLFontList* sSSSmallFallback; | ||
221 | static LLFontGL* sSansSerif; // medium | ||
222 | static LLFontList* sSSFallback; | ||
223 | static LLFontGL* sSansSerifBig; // large | ||
224 | static LLFontList* sSSBigFallback; | ||
225 | static LLFontGL* sSansSerifHuge; // very large | ||
226 | static LLFontList* sSSHugeFallback; | ||
227 | |||
228 | static LLFontGL* sSansSerifBold; // medium, bolded | ||
229 | static LLFontList* sSSBoldFallback; | ||
230 | |||
231 | static LLColor4 sShadowColor; | ||
232 | |||
233 | friend class LLTextBillboard; | ||
234 | friend class LLHUDText; | ||
235 | |||
236 | protected: | ||
237 | /*virtual*/ BOOL addChar(const llwchar wch); | ||
238 | static LLString getFontPathLocal(); | ||
239 | static LLString getFontPathSystem(); | ||
240 | |||
241 | protected: | ||
242 | LLPointer<LLImageRaw> mRawImageGLp; | ||
243 | LLPointer<LLImageGL> mImageGLp; | ||
244 | typedef std::map<llwchar,embedded_data_t*> embedded_map_t; | ||
245 | embedded_map_t mEmbeddedChars; | ||
246 | |||
247 | public: | ||
248 | static LLCoordFont sCurOrigin; | ||
249 | static std::vector<LLCoordFont> sOriginStack; | ||
250 | }; | ||
251 | |||
252 | #endif | ||