Ogre::Font::getTrueTypeMaxBearingY

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Ogre::Font::getTrueTypeMaxBearingY

Post by KungFooMasta »

When the Ogre::Font class loads a true type font, the max bearing y is already calculated:

File: OgreFont.cpp
Function: void Font::loadResource(Resource* res)
Code:

Code: Select all

		// Calculate maximum width, height and bearing
		size_t glyphCount = 0;
		for (CodePointRangeList::const_iterator r = mCodePointRangeList.begin();
			r != mCodePointRangeList.end(); ++r)
		{
			const CodePointRange& range = *r;
			for(CodePoint cp = range.first; cp <= range.second; ++cp, ++glyphCount)
			{
				FT_Load_Char( face, cp, FT_LOAD_RENDER );

				if( ( 2 * ( face->glyph->bitmap.rows << 6 ) - face->glyph->metrics.horiBearingY ) > max_height )
					max_height = ( 2 * ( face->glyph->bitmap.rows << 6 ) - face->glyph->metrics.horiBearingY );
				if( face->glyph->metrics.horiBearingY > max_bear )
					max_bear = 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 );
			}

		}
I would like to request that "max_bear" as used above is made into a member of the Ogre::Font class. With this information I will be able to format a line of text of multiple fonts so that they all line up on the same baseline.

Examples:

yyyy
jjjj

Again, I'm not asking for anything major, just that we keep track of the max bearingY value, and allow access to it. I can provide a patch if that is more welcome.
Creator of QuickGUI!
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Post by KungFooMasta »

No opposition or acceptance of this request?

Here is the patch:

Code: Select all

Index: include/OgreFont.h
===================================================================
--- include/OgreFont.h	(revision 7443)
+++ include/OgreFont.h	(working copy)
@@ -113,6 +113,8 @@
         Real mTtfSize;
         /// Resolution (dpi) of truetype font
         uint mTtfResolution;
+		/// Max distance to baseline of this (truetype) font
+		int mTtfMaxBearingY;
 
 
 	public:
@@ -220,6 +222,14 @@
             Only applicable for FT_TRUETYPE Font objects.
         */
         uint getTrueTypeResolution(void) const;
+		/** Gets the maximum baseline distance of all glyphs used in the texture.
+		@remarks
+			Only applicable for FT_TRUETYPE Font objects.
+			The baseline is the vertical origin of horizontal based glyphs.  The bearingY
+			attribute is the distance from the baseline (origin) to the top of the glyph's 
+			bounding box.
+		*/
+		int getTrueTypeMaxBearingY() const;
 
 
         /** Returns the texture coordinates of the associated glyph. 
Index: src/OgreFont.cpp
===================================================================
--- src/OgreFont.cpp	(revision 7443)
+++ src/OgreFont.cpp	(working copy)
@@ -58,7 +58,7 @@
 	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), mAntialiasColour(false)
+		mType(FT_TRUETYPE), mTtfSize(0), mTtfResolution(0), mTtfMaxBearingY(0), mAntialiasColour(false)
     {
 
 		if (createParamDictionary("Font"))
@@ -130,6 +130,11 @@
         return mTtfResolution;
     }
 	//---------------------------------------------------------------------
+	int Font::getTrueTypeMaxBearingY() const
+	{
+		return mTtfMaxBearingY;
+	}
+	//---------------------------------------------------------------------
 	const Font::GlyphInfo& Font::getGlyphInfo(CodePoint id) const
 	{
 		CodePointMap::const_iterator i = mCodePointMap.find(id);
@@ -257,7 +262,7 @@
 
         //FILE *fo_def = stdout;
 
-        int max_height = 0, max_width = 0, max_bear = 0;
+        int max_height = 0, max_width = 0;
 
 		// Backwards compatibility - if codepoints not supplied, assume 33-166
 		if (mCodePointRangeList.empty())
@@ -277,8 +282,8 @@
 
 				if( ( 2 * ( face->glyph->bitmap.rows << 6 ) - face->glyph->metrics.horiBearingY ) > max_height )
 					max_height = ( 2 * ( face->glyph->bitmap.rows << 6 ) - face->glyph->metrics.horiBearingY );
-				if( face->glyph->metrics.horiBearingY > max_bear )
-					max_bear = face->glyph->metrics.horiBearingY;
+				if( face->glyph->metrics.horiBearingY > mTtfMaxBearingY )
+					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 );
@@ -356,7 +361,7 @@
 					continue;
 				}
 
-				int y_bearnig = ( max_bear >> 6 ) - ( face->glyph->metrics.horiBearingY >> 6 );
+				int y_bearnig = ( mTtfMaxBearingY >> 6 ) - ( face->glyph->metrics.horiBearingY >> 6 );
 
 				for(int j = 0; j < face->glyph->bitmap.rows; j++ )
 				{
Just put it into the OgreMain folder and apply it! :)
Creator of QuickGUI!
User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post by Game_Ender »

Did/can you submit it to the SF patch tracker?
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Post by KungFooMasta »

Ok I sent in my licensing agreement and submitted the patch to the tracker. Hope it gets applied soon, its really a no-brainer patch that just stores and exposes what used to be a temporary variable. Thanks for setting me in the right direction!
Creator of QuickGUI!
Post Reply