00001 // Filename: freetypeFont.I 00002 // Created by: drose (07Sep03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: FreetypeFont::Destructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE FreetypeFont:: 00022 ~FreetypeFont() { 00023 unload_font(); 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: FreetypeFont::set_point_size 00028 // Access: Public 00029 // Description: Sets the point size of the font. This controls the 00030 // apparent size of the font onscreen. By convention, a 00031 // 10 point font is about 1 screen unit high. 00032 // 00033 // This should only be called before any characters have 00034 // been requested out of the font, or immediately after 00035 // calling clear(). 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE bool FreetypeFont:: 00038 set_point_size(PN_stdfloat point_size) { 00039 _point_size = point_size; 00040 return reset_scale(); 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: FreetypeFont::get_point_size 00045 // Access: Public 00046 // Description: Returns the point size of the font. 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE PN_stdfloat FreetypeFont:: 00049 get_point_size() const { 00050 return _point_size; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: FreetypeFont::set_pixels_per_unit 00055 // Access: Public 00056 // Description: Set the resolution of the texture map, and hence the 00057 // clarity of the resulting font. This sets the number 00058 // of pixels in the texture map that are used for each 00059 // onscreen unit. 00060 // 00061 // Setting this number larger results in an easier to 00062 // read font, but at the cost of more texture memory. 00063 // 00064 // This should only be called before any characters have 00065 // been requested out of the font, or immediately after 00066 // calling clear(). 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE bool FreetypeFont:: 00069 set_pixels_per_unit(PN_stdfloat pixels_per_unit) { 00070 _requested_pixels_per_unit = pixels_per_unit; 00071 return reset_scale(); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: FreetypeFont::get_pixels_per_unit 00076 // Access: Public 00077 // Description: Returns the resolution of the texture map. See 00078 // set_pixels_per_unit(). 00079 //////////////////////////////////////////////////////////////////// 00080 INLINE PN_stdfloat FreetypeFont:: 00081 get_pixels_per_unit() const { 00082 return _tex_pixels_per_unit; 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: FreetypeFont::set_pixel_size 00087 // Access: Public 00088 // Description: Computes the appropriate pixels_per_unit value to set 00089 // the size of the font in the texture to the indicated 00090 // number of pixels. This is just another way to 00091 // specify pixels_per_unit(). 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE bool FreetypeFont:: 00094 set_pixel_size(PN_stdfloat pixel_size) { 00095 return set_pixels_per_unit(pixel_size * _points_per_unit / _point_size); 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: FreetypeFont::get_pixel_size 00100 // Access: Public 00101 // Description: Returns the size of the font in pixels, as it appears 00102 // in the texture. 00103 //////////////////////////////////////////////////////////////////// 00104 INLINE PN_stdfloat FreetypeFont:: 00105 get_pixel_size() const { 00106 return _tex_pixels_per_unit * _point_size / _points_per_unit; 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: FreetypeFont::set_scale_factor 00111 // Access: Public 00112 // Description: Sets the factor by which the font is rendered larger 00113 // by the FreeType library before being filtered down to 00114 // its actual size in the texture as specified by 00115 // set_pixels_per_unit(). This may be set to a number 00116 // larger than 1.0 to improve the font's antialiasing 00117 // (since FreeType doesn't really do a swell job of 00118 // antialiasing by itself). There is some performance 00119 // implication for setting this different than 1.0. 00120 // 00121 // This should only be called before any characters have 00122 // been requested out of the font, or immediately after 00123 // calling clear(). 00124 //////////////////////////////////////////////////////////////////// 00125 INLINE bool FreetypeFont:: 00126 set_scale_factor(PN_stdfloat scale_factor) { 00127 _requested_scale_factor = scale_factor; 00128 return reset_scale(); 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: FreetypeFont::get_scale_factor 00133 // Access: Public 00134 // Description: Returns the antialiasing scale factor. See 00135 // set_scale_factor(). 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE PN_stdfloat FreetypeFont:: 00138 get_scale_factor() const { 00139 return _scale_factor; 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: FreetypeFont::set_native_antialias 00144 // Access: Public 00145 // Description: Sets whether the Freetype library's built-in 00146 // antialias mode is enabled. There are two unrelated 00147 // ways to achieve antialiasing: with Freetype's native 00148 // antialias mode, and with the use of a scale_factor 00149 // greater than one. By default, both modes are 00150 // enabled. 00151 // 00152 // At low resolutions, some fonts may do better with one 00153 // mode or the other. In general, Freetype's native 00154 // antialiasing will produce less blurry results, but 00155 // may introduce more artifacts. 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE void FreetypeFont:: 00158 set_native_antialias(bool native_antialias) { 00159 _native_antialias = native_antialias; 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: FreetypeFont::get_native_antialias 00164 // Access: Public 00165 // Description: Returns whether Freetype's built-in antialias mode is 00166 // enabled. See set_native_antialias(). 00167 //////////////////////////////////////////////////////////////////// 00168 INLINE bool FreetypeFont:: 00169 get_native_antialias() const { 00170 return _native_antialias; 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: FreetypeFont::get_font_pixel_size 00175 // Access: Public 00176 // Description: This is used to report whether the requested pixel 00177 // size is being only approximated by a fixed-pixel-size 00178 // font. This returns 0 in the normal case, in which a 00179 // scalable font is used, or the fixed-pixel-size font 00180 // has exactly the requested pixel size. 00181 // 00182 // If this returns non-zero, it is the pixel size of the 00183 // font that we are using to approximate our desired 00184 // size. 00185 //////////////////////////////////////////////////////////////////// 00186 INLINE int FreetypeFont:: 00187 get_font_pixel_size() const { 00188 return _pixel_height; 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: FreetypeFont::get_line_height 00193 // Access: Public 00194 // Description: Returns the number of units high each line of text 00195 // is. 00196 //////////////////////////////////////////////////////////////////// 00197 INLINE PN_stdfloat FreetypeFont:: 00198 get_line_height() const { 00199 return _line_height; 00200 } 00201 00202 //////////////////////////////////////////////////////////////////// 00203 // Function: FreetypeFont::get_space_advance 00204 // Access: Public 00205 // Description: Returns the number of units wide a space is. 00206 //////////////////////////////////////////////////////////////////// 00207 INLINE PN_stdfloat FreetypeFont:: 00208 get_space_advance() const { 00209 return _space_advance; 00210 } 00211 00212 //////////////////////////////////////////////////////////////////// 00213 // Function: FreetypeFont::get_points_per_unit 00214 // Access: Public, Static 00215 // Description: Returns the point size of the font that is one Panda 00216 // unit high. This is an arbitrary Panda convention for 00217 // text, and is set to 10.0. 00218 //////////////////////////////////////////////////////////////////// 00219 INLINE PN_stdfloat FreetypeFont:: 00220 get_points_per_unit() { 00221 return _points_per_unit; 00222 } 00223 00224 //////////////////////////////////////////////////////////////////// 00225 // Function: FreetypeFont::get_points_per_inch 00226 // Access: Public, Static 00227 // Description: Returns the number of points in one inch. This is a 00228 // universal typographic convention. 00229 //////////////////////////////////////////////////////////////////// 00230 INLINE PN_stdfloat FreetypeFont:: 00231 get_points_per_inch() { 00232 return _points_per_inch; 00233 } 00234 00235 //////////////////////////////////////////////////////////////////// 00236 // Function: FreetypeFont::acquire_face 00237 // Access: Protected 00238 // Description: Retrieves the internal freetype face, and also 00239 // acquires the lock. 00240 // 00241 // You must call release_face() when you are done using 00242 // it, to release the lock. 00243 //////////////////////////////////////////////////////////////////// 00244 INLINE FT_Face FreetypeFont:: 00245 acquire_face() const { 00246 nassertr(_face != NULL, NULL); 00247 return _face->acquire_face(_char_size, _dpi, _pixel_width, _pixel_height); 00248 } 00249 00250 //////////////////////////////////////////////////////////////////// 00251 // Function: FreetypeFont::release_face 00252 // Access: Protected 00253 // Description: Releases the lock acquired by a previous call to 00254 // acquire_face(), and allows another thread to use the 00255 // face. 00256 //////////////////////////////////////////////////////////////////// 00257 INLINE void FreetypeFont:: 00258 release_face(FT_Face face) const { 00259 nassertv(_face != NULL); 00260 _face->release_face(face); 00261 }