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/llfont.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 'linden/indra/llrender/llfont.h')
-rw-r--r-- | linden/indra/llrender/llfont.h | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/linden/indra/llrender/llfont.h b/linden/indra/llrender/llfont.h new file mode 100644 index 0000000..dadeafd --- /dev/null +++ b/linden/indra/llrender/llfont.h | |||
@@ -0,0 +1,188 @@ | |||
1 | /** | ||
2 | * @file llfont.h | ||
3 | * @brief Font library wrapper | ||
4 | * | ||
5 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLFONT_H | ||
29 | #define LL_LLFONT_H | ||
30 | |||
31 | #include <map> | ||
32 | //#include "lllocalidhashmap.h" | ||
33 | #include "llmemory.h" | ||
34 | |||
35 | class LLImageRaw; | ||
36 | class LLFontManager; | ||
37 | class LLFont; | ||
38 | |||
39 | // Hack. FT_Face is just a typedef for a pointer to a struct, | ||
40 | // but there's no simple forward declarations file for FreeType, | ||
41 | // and the main include file is 200K. | ||
42 | // We'll forward declare the struct here. JC | ||
43 | struct FT_FaceRec_; | ||
44 | typedef struct FT_FaceRec_* LLFT_Face; | ||
45 | |||
46 | extern LLFontManager *gFontManagerp; | ||
47 | |||
48 | class LLFontManager | ||
49 | { | ||
50 | public: | ||
51 | static void initClass(); | ||
52 | static void cleanupClass(); | ||
53 | |||
54 | public: | ||
55 | LLFontManager(); | ||
56 | virtual ~LLFontManager(); | ||
57 | }; | ||
58 | |||
59 | class LLFontGlyphInfo | ||
60 | { | ||
61 | public: | ||
62 | LLFontGlyphInfo(U32 index); | ||
63 | public: | ||
64 | U32 mGlyphIndex; | ||
65 | // Metrics | ||
66 | S32 mWidth; // In pixels | ||
67 | S32 mHeight; // In pixels | ||
68 | F32 mXAdvance; // In pixels | ||
69 | F32 mYAdvance; // In pixels | ||
70 | |||
71 | // Information for actually rendering | ||
72 | BOOL mIsRendered; // We actually have rendered this glyph | ||
73 | S32 mXBitmapOffset; // Offset to the origin in the bitmap | ||
74 | S32 mYBitmapOffset; // Offset to the origin in the bitmap | ||
75 | S32 mXBearing; // Distance from baseline to left in pixels | ||
76 | S32 mYBearing; // Distance from baseline to top in pixels | ||
77 | }; | ||
78 | |||
79 | // Used for lists of fallback fonts | ||
80 | class LLFontList : public std::vector<LLFont*> | ||
81 | { | ||
82 | public: | ||
83 | LLFontList(); | ||
84 | ~LLFontList(); | ||
85 | void addAtEnd(LLFont *font); | ||
86 | }; | ||
87 | |||
88 | |||
89 | class LLFont | ||
90 | { | ||
91 | public: | ||
92 | LLFont(LLImageRaw *imagep = NULL); | ||
93 | virtual ~LLFont(); | ||
94 | |||
95 | // is_fallback should be true for fallback fonts that aren't used to render directly (Unicode backup, primarily) | ||
96 | virtual BOOL loadFace(const std::string& filename, | ||
97 | const F32 point_size, | ||
98 | const F32 vert_dpi, | ||
99 | const F32 horz_dpi, | ||
100 | const S32 components, | ||
101 | BOOL is_fallback); | ||
102 | void setFallbackFont(LLFontList *fontp) { mFallbackFontp = fontp; } | ||
103 | |||
104 | void setCharToGlyphMap(llwchar wch, U32 glyph_index) const; | ||
105 | void setRawImage( LLImageRaw *imagep ); | ||
106 | |||
107 | // Global font metrics - in units of pixels | ||
108 | virtual F32 getLineHeight() const; | ||
109 | virtual F32 getAscenderHeight() const; | ||
110 | virtual F32 getDescenderHeight() const; | ||
111 | |||
112 | |||
113 | // For a lowercase "g": | ||
114 | // | ||
115 | // ------------------------------ | ||
116 | // ^ ^ | ||
117 | // | | | ||
118 | // xxx x |Ascender | ||
119 | // x x | | | ||
120 | // --------- xxxx-------------- Baseline | ||
121 | // ^ x | | | ||
122 | // | descender x | | | ||
123 | // v xxxx v |LineHeight | ||
124 | // ----------------------- | | ||
125 | // v | ||
126 | // ------------------------------ | ||
127 | |||
128 | enum | ||
129 | { | ||
130 | FIRST_CHAR = 32, | ||
131 | NUM_CHARS = 127 - 32, | ||
132 | LAST_CHAR_BASIC = 127, | ||
133 | |||
134 | // Need full 8-bit ascii range for spanish | ||
135 | NUM_CHARS_FULL = 255 - 32, | ||
136 | LAST_CHAR_FULL = 255 | ||
137 | }; | ||
138 | |||
139 | const LLFontGlyphInfo &getMetrics(const llwchar wc) const; | ||
140 | F32 getXAdvance(const llwchar wc) const; | ||
141 | F32 getXKerning(const llwchar char_left, const llwchar char_right) const; // Get the kerning between the two characters | ||
142 | protected: | ||
143 | virtual BOOL hasGlyph(const llwchar wch) const; // Has a glyph for this character | ||
144 | virtual BOOL addChar(const llwchar wch); // Add a new character to the font if necessary | ||
145 | virtual BOOL addGlyph(const llwchar wch, const U32 glyph_index); // Add a new glyph to the existing font | ||
146 | virtual BOOL addGlyphFromFont(LLFont *fontp, const llwchar wch, const U32 glyph_index); // Add a glyph from this font to the other (returns the glyph_index, 0 if not found) | ||
147 | |||
148 | virtual LLFontGlyphInfo* getGlyphInfo(const llwchar wch) const; | ||
149 | |||
150 | void insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const; | ||
151 | void renderGlyph(const U32 glyph_index); | ||
152 | |||
153 | void resetBitmap(); // Reset bitmap to contain only the null glyph | ||
154 | protected: | ||
155 | std::string mName; | ||
156 | F32 mAscender; | ||
157 | F32 mDescender; | ||
158 | F32 mLineHeight; | ||
159 | |||
160 | S32 mNumComponents; | ||
161 | S32 mBitmapWidth; | ||
162 | S32 mBitmapHeight; | ||
163 | S32 mMaxCharWidth; | ||
164 | S32 mMaxCharHeight; | ||
165 | S32 mCurrentOffsetX; | ||
166 | S32 mCurrentOffsetY; | ||
167 | |||
168 | LLFT_Face mFTFace; | ||
169 | |||
170 | BOOL mIsFallback; | ||
171 | LLFontList *mFallbackFontp; // A list of fallback fonts to look for glyphs in (for Unicode chars) | ||
172 | |||
173 | typedef std::map<llwchar, LLFontGlyphInfo*> char_glyph_info_map_t; | ||
174 | mutable char_glyph_info_map_t mCharGlyphInfoMap; // Information about glyph location in bitmap | ||
175 | |||
176 | BOOL mValid; | ||
177 | void setSubImageLuminanceAlpha(const U32 x, | ||
178 | const U32 y, | ||
179 | const U32 width, | ||
180 | const U32 height, | ||
181 | const U8 *data, | ||
182 | S32 stride = 0); | ||
183 | |||
184 | private: | ||
185 | LLPointer<LLImageRaw> mRawImagep; // Bitmaps of glyphs are stored here. | ||
186 | }; | ||
187 | |||
188 | #endif // LL_FONT_ | ||