00001 // Filename: dynamicTextFont.I 00002 // Created by: drose (08Feb02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: DynamicTextFont::set_point_size 00022 // Access: Published 00023 // Description: Sets the point size of the font. This controls the 00024 // apparent size of the font onscreen. By convention, a 00025 // 10 point font is about 1 screen unit high. 00026 // 00027 // This should only be called before any characters have 00028 // been requested out of the font, or immediately after 00029 // calling clear(). 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE bool DynamicTextFont:: 00032 set_point_size(float point_size) { 00033 // If this assertion fails, you didn't call clear() first. RTFM. 00034 nassertr(get_num_pages() == 0, false); 00035 00036 _point_size = point_size; 00037 return reset_scale(); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: DynamicTextFont::get_point_size 00042 // Access: Published 00043 // Description: Returns the point size of the font. 00044 //////////////////////////////////////////////////////////////////// 00045 INLINE float DynamicTextFont:: 00046 get_point_size() const { 00047 return _point_size; 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: DynamicTextFont::set_pixels_per_unit 00052 // Access: Published 00053 // Description: Set the resolution of the texture map, and hence the 00054 // clarity of the resulting font. This sets the number 00055 // of pixels in the texture map that are used for each 00056 // onscreen unit. 00057 // 00058 // Setting this number larger results in an easier to 00059 // read font, but at the cost of more texture memory. 00060 // 00061 // This should only be called before any characters have 00062 // been requested out of the font, or immediately after 00063 // calling clear(). 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE bool DynamicTextFont:: 00066 set_pixels_per_unit(float pixels_per_unit) { 00067 // If this assertion fails, you didn't call clear() first. RTFM. 00068 nassertr(get_num_pages() == 0, false); 00069 00070 _tex_pixels_per_unit = pixels_per_unit; 00071 return reset_scale(); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: DynamicTextFont::get_pixels_per_unit 00076 // Access: Published 00077 // Description: Returns the resolution of the texture map. See 00078 // set_pixels_per_unit(). 00079 //////////////////////////////////////////////////////////////////// 00080 INLINE float DynamicTextFont:: 00081 get_pixels_per_unit() const { 00082 return _tex_pixels_per_unit; 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: DynamicTextFont::set_scale_factor 00087 // Access: Published 00088 // Description: Sets the factor by which the font is rendered larger 00089 // by the FreeType library before being filtered down to 00090 // its actual size in the texture as specified by 00091 // set_pixels_per_unit(). This may be set to a number 00092 // larger than 1.0 to improve the font's antialiasing 00093 // (since FreeType doesn't really do a swell job of 00094 // antialiasing by itself). There is some performance 00095 // implication for setting this different than 1.0. 00096 // 00097 // This should only be called before any characters have 00098 // been requested out of the font, or immediately after 00099 // calling clear(). 00100 //////////////////////////////////////////////////////////////////// 00101 INLINE bool DynamicTextFont:: 00102 set_scale_factor(float scale_factor) { 00103 // If this assertion fails, you didn't call clear() first. RTFM. 00104 nassertr(get_num_pages() == 0, false); 00105 00106 _scale_factor = scale_factor; 00107 return reset_scale(); 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: DynamicTextFont::get_scale_factor 00112 // Access: Published 00113 // Description: Returns the antialiasing scale factor. See 00114 // set_scale_factor(). 00115 //////////////////////////////////////////////////////////////////// 00116 INLINE float DynamicTextFont:: 00117 get_scale_factor() const { 00118 return _scale_factor; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: DynamicTextFont::set_texture_margin 00123 // Access: Published 00124 // Description: Sets the number of pixels of padding that is added 00125 // around the border of each glyph before adding it to 00126 // the texture map. This reduces the bleed in from 00127 // neighboring glyphs in the texture map. 00128 //////////////////////////////////////////////////////////////////// 00129 INLINE void DynamicTextFont:: 00130 set_texture_margin(int texture_margin) { 00131 _texture_margin = texture_margin; 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: DynamicTextFont::get_texture_margin 00136 // Access: Published 00137 // Description: Returns the number of pixels of padding that is added 00138 // around the border of each glyph in the texture map. 00139 // See set_texture_margin(). 00140 //////////////////////////////////////////////////////////////////// 00141 INLINE int DynamicTextFont:: 00142 get_texture_margin() const { 00143 return _texture_margin; 00144 } 00145 00146 //////////////////////////////////////////////////////////////////// 00147 // Function: DynamicTextFont::set_poly_margin 00148 // Access: Published 00149 // Description: Sets the number of pixels of padding that is included 00150 // around each glyph in the generated polygons. This 00151 // helps prevent the edges of the glyphs from being cut 00152 // off at small minifications. It is not related to the 00153 // amount of extra pixels reserved in the texture map 00154 // (but it should be set somewhat smaller than this 00155 // number, which is controlled by set_texture_margin(), 00156 // to prevent bleed-in from neighboring letters in the 00157 // texture). 00158 //////////////////////////////////////////////////////////////////// 00159 INLINE void DynamicTextFont:: 00160 set_poly_margin(float poly_margin) { 00161 _poly_margin = poly_margin; 00162 } 00163 00164 //////////////////////////////////////////////////////////////////// 00165 // Function: DynamicTextFont::get_poly_margin 00166 // Access: Published 00167 // Description: Returns the number of pixels of padding that is 00168 // included around each glyph in the generated polygons. 00169 // See set_poly_margin(). 00170 //////////////////////////////////////////////////////////////////// 00171 INLINE float DynamicTextFont:: 00172 get_poly_margin() const { 00173 return _poly_margin; 00174 } 00175 00176 //////////////////////////////////////////////////////////////////// 00177 // Function: DynamicTextFont::set_page_size 00178 // Access: Published 00179 // Description: Sets the x, y size of the textures that are created 00180 // for the DynamicTextFont. 00181 //////////////////////////////////////////////////////////////////// 00182 INLINE void DynamicTextFont:: 00183 set_page_size(int x_size, int y_size) { 00184 _page_x_size = x_size; 00185 _page_y_size = y_size; 00186 } 00187 00188 //////////////////////////////////////////////////////////////////// 00189 // Function: DynamicTextFont::get_page_x_size 00190 // Access: Published 00191 // Description: Returns the x size of the textures that are created 00192 // for the DynamicTextFont. See set_page_size(). 00193 //////////////////////////////////////////////////////////////////// 00194 INLINE int DynamicTextFont:: 00195 get_page_x_size() const { 00196 return _page_x_size; 00197 } 00198 00199 //////////////////////////////////////////////////////////////////// 00200 // Function: DynamicTextFont::get_page_y_size 00201 // Access: Published 00202 // Description: Returns the y size of the textures that are created 00203 // for the DynamicTextFont. See set_page_size(). 00204 //////////////////////////////////////////////////////////////////// 00205 INLINE int DynamicTextFont:: 00206 get_page_y_size() const { 00207 return _page_y_size; 00208 } 00209 00210 //////////////////////////////////////////////////////////////////// 00211 // Function: DynamicTextFont::set_minfilter 00212 // Access: Published 00213 // Description: Sets the filter type used when minimizing the 00214 // textures created for this font. 00215 //////////////////////////////////////////////////////////////////// 00216 INLINE void DynamicTextFont:: 00217 set_minfilter(Texture::FilterType filter) { 00218 _minfilter = filter; 00219 update_filters(); 00220 } 00221 00222 //////////////////////////////////////////////////////////////////// 00223 // Function: DynamicTextFont::get_minfilter 00224 // Access: Published 00225 // Description: Returns the filter type used when minimizing the 00226 // textures created for this font. 00227 //////////////////////////////////////////////////////////////////// 00228 INLINE Texture::FilterType DynamicTextFont:: 00229 get_minfilter() const { 00230 return _minfilter; 00231 } 00232 00233 //////////////////////////////////////////////////////////////////// 00234 // Function: DynamicTextFont::set_magfilter 00235 // Access: Published 00236 // Description: Sets the filter type used when enlarging the 00237 // textures created for this font. 00238 //////////////////////////////////////////////////////////////////// 00239 INLINE void DynamicTextFont:: 00240 set_magfilter(Texture::FilterType filter) { 00241 _magfilter = filter; 00242 update_filters(); 00243 } 00244 00245 //////////////////////////////////////////////////////////////////// 00246 // Function: DynamicTextFont::get_magfilter 00247 // Access: Published 00248 // Description: Returns the filter type used when enlarging the 00249 // textures created for this font. 00250 //////////////////////////////////////////////////////////////////// 00251 INLINE Texture::FilterType DynamicTextFont:: 00252 get_magfilter() const { 00253 return _magfilter; 00254 } 00255 00256 //////////////////////////////////////////////////////////////////// 00257 // Function: DynamicTextFont::set_anisotropic_degree 00258 // Access: Published 00259 // Description: Enables or disables anisotropic filtering on the 00260 // textures created for this font. The default value is 00261 // usually 1, or off. See 00262 // Texture::set_anisotropic_degree(). 00263 //////////////////////////////////////////////////////////////////// 00264 INLINE void DynamicTextFont:: 00265 set_anisotropic_degree(int anisotropic_degree) { 00266 _anisotropic_degree = anisotropic_degree; 00267 update_filters(); 00268 } 00269 00270 //////////////////////////////////////////////////////////////////// 00271 // Function: DynamicTextFont::get_anisotropic_degree 00272 // Access: Published 00273 // Description: Returns the current anisotropic degree for textures 00274 // created for this font. See set_anisotropic_degree(). 00275 //////////////////////////////////////////////////////////////////// 00276 INLINE int DynamicTextFont:: 00277 get_anisotropic_degree() const { 00278 return _anisotropic_degree; 00279 } 00280 00281 //////////////////////////////////////////////////////////////////// 00282 // Function: DynamicTextFont::set_update_cleared_glyphs 00283 // Access: Published, Static 00284 // Description: Sets the flag indicating whether texture memory 00285 // should be updated immediately as old glyphs are 00286 // removed. If this is true, texture memory will be 00287 // immediately updated when old glyphs are removed from 00288 // the pages. If this is false (the default), texture 00289 // memory may not be updated until the page is next 00290 // written to, that is, the next time a glyph is 00291 // recorded on that page. 00292 // 00293 // Most of the time, there is no reason to set this 00294 // true, unless you are debugging the DynamicTextFont 00295 // code and want to be able to see exactly what is in 00296 // each texture map at any given time. 00297 // 00298 // This is a global flag across all DynamicTextFont 00299 // objects. 00300 //////////////////////////////////////////////////////////////////// 00301 INLINE void DynamicTextFont:: 00302 set_update_cleared_glyphs(bool update_cleared_glyphs) { 00303 _update_cleared_glyphs = update_cleared_glyphs; 00304 } 00305 00306 //////////////////////////////////////////////////////////////////// 00307 // Function: DynamicTextFont::get_update_cleared_glyphs 00308 // Access: Published, Static 00309 // Description: Returns the flag indicating whether texture memory 00310 // should be updated immediately as old glyphs are 00311 // removed. See set_update_cleared_glyphs(). 00312 //////////////////////////////////////////////////////////////////// 00313 INLINE bool DynamicTextFont:: 00314 get_update_cleared_glyphs() { 00315 return _update_cleared_glyphs; 00316 }