Example:
Code: Select all
Console
{
type truetype
source console.ttf
size 32
resolution 72
fixed_width true
}
Code: Select all
@@ -59,7 +59,8 @@
Font::Font(ResourceManager* creator, const String& name, ResourceHandle handle,
const String& group, bool isManual, ManualResourceLoader* loader)
:Resource (creator, name, handle, group, isManual, loader),
- mType(FT_TRUETYPE), mTtfSize(0), mTtfResolution(0), mTtfMaxBearingY(0), mAntialiasColour(false)
+ mType(FT_TRUETYPE), mTtfSize(0), mTtfResolution(0), mTtfMaxBearingY(0), mAntialiasColour(false),
+ mTtfFixedWidth(false)
{
if (createParamDictionary("Font"))
@@ -101,6 +102,16 @@
return mType;
}
//---------------------------------------------------------------------
+ void Font::setFixedWidth(const bool enabled)
+ {
+ mTtfFixedWidth = enabled;
+ }
+ //---------------------------------------------------------------------
+ bool Font::getFixedWidth(void) const
+ {
+ return mTtfFixedWidth;
+ }
+ //---------------------------------------------------------------------
void Font::setSource(const String& source)
{
mSource = source;
@@ -267,6 +278,7 @@
//FILE *fo_def = stdout;
int max_height = 0, max_width = 0;
+ int max_fixed_width = 0;
// Backwards compatibility - if codepoints not supplied, assume 33-166
if (mCodePointRangeList.empty())
@@ -290,7 +302,10 @@
mTtfMaxBearingY = face->glyph->metrics.horiBearingY;
if( (face->glyph->advance.x >> 6 ) + ( face->glyph->metrics.horiBearingX >> 6 ) > max_width)
- max_width = (face->glyph->advance.x >> 6 ) + ( face->glyph->metrics.horiBearingX >> 6 );
+ {
+ max_fixed_width = (face->glyph->advance.x >> 6 );
+ max_width = max_fixed_width + ( face->glyph->metrics.horiBearingX >> 6 );
+ }
}
}
@@ -390,10 +405,21 @@
}
}
+ Real u2;
+
+ if( mTtfFixedWidth )
+ {
+ u2 = (Real)( l + max_fixed_width ) / (Real)finalWidth;
+ }
+ else
+ {
+ u2 = (Real)( l + ( face->glyph->advance.x >> 6 ) ) / (Real)finalWidth;
+ }
+
this->setGlyphTexCoords(cp,
(Real)l / (Real)finalWidth, // u1
(Real)m / (Real)finalHeight, // v1
- (Real)( l + ( face->glyph->advance.x >> 6 ) ) / (Real)finalWidth, // u2
+ u2, // u2
( m + ( max_height >> 6 ) ) / (Real)finalHeight, // v2
textureAspect
);
Code: Select all
@@ -123,6 +123,8 @@
/// Max distance to baseline of this (truetype) font
int mTtfMaxBearingY;
+ /// If 'true', all characters are set to a common width
+ bool mTtfFixedWidth;
public:
typedef Ogre::uint32 CodePoint;
@@ -184,6 +186,18 @@
/** Gets the type of font. */
FontType getType(void) const;
+ /** Enables fixed width font generation.
+ @remarks
+ If 'true', all characters are set to a common width.
+ @param enabled Enables fixed width fonts.
+ */
+ void setFixedWidth(const bool enabled);
+
+ /** Gets the fixed width state.
+ */
+ bool getFixedWidth(void) const;
+
+
/** Sets the source of the font.
@remarks
If you have created a font of type FT_IMAGE, this method tells the
Code: Select all
@@ -226,6 +226,17 @@
// Set
pFont->setAntialiasColour(StringConverter::parseBool(params[1]));
}
+ else if (attrib == "fixed_width")
+ {
+ // Check params
+ if (params.size() != 2)
+ {
+ logBadAttrib(line, pFont);
+ return;
+ }
+ // Set
+ pFont->setFixedWidth(StringConverter::parseBool(params[1]));
+ }
else if (attrib == "code_points")
{
for (size_t c = 1; c < params.size(); ++c)
OgreFont.h
Code: Select all
/// If 'true', all characters are set to a common width
bool mTtfFixedWidth;
/** Enables fixed width font generation.
@remarks
If 'true', all characters are set to a common width.
@param enabled Enables fixed width fonts.
*/
void setFixedWidth(const bool enabled);
/** Gets the fixed width state.
*/
bool getFixedWidth(void) const;
Code: Select all
... in Font::setSource()
int max_fixed_width = 0;
...
if( (face->glyph->advance.x >> 6 ) + ( face->glyph->metrics.horiBearingX >> 6 ) > max_width)
max_width = (face->glyph->advance.x >> 6 ) + ( face->glyph->metrics.horiBearingX >> 6 );
{
max_fixed_width = (face->glyph->advance.x >> 6 );
max_width = max_fixed_width + ( face->glyph->metrics.horiBearingX >> 6 );
}
...
Real u2;
if( mTtfFixedWidth )
{
u2 = (Real)( l + max_fixed_width ) / (Real)finalWidth;
}
else
{
u2 = (Real)( l + ( face->glyph->advance.x >> 6 ) ) / (Real)finalWidth;
}
this->setGlyphTexCoords(cp,
(Real)l / (Real)finalWidth, // u1
(Real)m / (Real)finalHeight, // v1
(Real)( l + ( face->glyph->advance.x >> 6 ) ) / (Real)finalWidth, // u2
u2, // u2
( m + ( max_height >> 6 ) ) / (Real)finalHeight, // v2
textureAspect
);
Code: Select all
... in FontManager::parseAttribute()
else if (attrib == "fixed_width")
{
// Check params
if (params.size() != 2)
{
logBadAttrib(line, pFont);
return;
}
// Set
pFont->setFixedWidth(StringConverter::parseBool(params[1]));
}