Fontwidth
Hi!
How can I get the Fontwidth in pixel?
I made a font with CreateFont() (Arial, 16)
Now I like to get the width of my strings.
Add up the individual character widths. You'll need access to the glyphmetrics info - the following snippet demonstrates the general idea.
void Cgle3DFont::GetStringSize(char* Text, GLfloat* XYZ)
{
unsigned char *str = (unsigned char *)Text;
int Index;
XYZ[0] = 0.0;
XYZ[1] = 0.0;
XYZ[2] = 0.0;
int StrLength = strlen(Text) - 1;
if (StrLength==0)
return;
XYZ[0]= 0.0;
XYZ[1]= 0.0;
XYZ[2]= m_fExtrusionDepth;
for (int i = 0; i < StrLength; i++)
{
Index= str- 32;
if ((Index < 0)||(Index > 95))
{
XYZ[0]=XYZ[1]=XYZ[2]=0.0;
return;
}
XYZ[0]+=m_fGlyphMetrics[Index].gmfCellIncX;
if (m_fGlyphMetrics[Index].gmfBlackBoxY > XYZ[1])
XYZ[1] = m_fGlyphMetrics[Index].gmfBlackBoxY;
}
Index = str[StrLength]- 32;
if ((Index < 0)||(Index > 95))
{
XYZ[0]=XYZ[1]=XYZ[2]=0.0;
return;
}
XYZ[0]+=m_fGlyphMetrics[Index].gmfBlackBoxX;
if (m_fGlyphMetrics[Index].gmfBlackBoxY > XYZ[1])
XYZ[1] = m_fGlyphMetrics[Index].gmfBlackBoxY;
return;
}
[edited by - Ferdinand the Bull on March 31, 2003 8:25:06 PM]
void Cgle3DFont::GetStringSize(char* Text, GLfloat* XYZ)
{
unsigned char *str = (unsigned char *)Text;
int Index;
XYZ[0] = 0.0;
XYZ[1] = 0.0;
XYZ[2] = 0.0;
int StrLength = strlen(Text) - 1;
if (StrLength==0)
return;
XYZ[0]= 0.0;
XYZ[1]= 0.0;
XYZ[2]= m_fExtrusionDepth;
for (int i = 0; i < StrLength; i++)
{
Index= str- 32;
if ((Index < 0)||(Index > 95))
{
XYZ[0]=XYZ[1]=XYZ[2]=0.0;
return;
}
XYZ[0]+=m_fGlyphMetrics[Index].gmfCellIncX;
if (m_fGlyphMetrics[Index].gmfBlackBoxY > XYZ[1])
XYZ[1] = m_fGlyphMetrics[Index].gmfBlackBoxY;
}
Index = str[StrLength]- 32;
if ((Index < 0)||(Index > 95))
{
XYZ[0]=XYZ[1]=XYZ[2]=0.0;
return;
}
XYZ[0]+=m_fGlyphMetrics[Index].gmfBlackBoxX;
if (m_fGlyphMetrics[Index].gmfBlackBoxY > XYZ[1])
XYZ[1] = m_fGlyphMetrics[Index].gmfBlackBoxY;
return;
}
[edited by - Ferdinand the Bull on March 31, 2003 8:25:06 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement