本文整理汇总了C++中CFont::GetCharData方法的典型用法代码示例。如果您正苦于以下问题:C++ CFont::GetCharData方法的具体用法?C++ CFont::GetCharData怎么用?C++ CFont::GetCharData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFont
的用法示例。
在下文中一共展示了CFont::GetCharData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddLineWithToVec
/************************************************************************
* desc: Add up all the character widths
************************************************************************/
std::vector<float> CVisualComponent2d::CalcLineWidthOffset(
const CFont & font,
const std::string & str,
const CFontProperties & fontProp )
{
float firstCharOffset = 0;
float lastCharOffset = 0;
float spaceWidth = 0;
float width = 0;
int counter = 0;
std::vector<float> lineWidthOffsetVec;
for( size_t i = 0; i < str.size(); ++i )
{
char id = str[i];
// Line wrap if '|' character was used
if( id == '|' )
{
// Add the line width to the vector based on horz alignment
AddLineWithToVec( font, lineWidthOffsetVec, fontProp.m_hAlign, width, firstCharOffset, lastCharOffset );
counter = 0;
width = 0;
}
else
{
// Get the next character
const CCharData & charData = font.GetCharData( id );
if(counter == 0)
firstCharOffset = charData.offset.w;
spaceWidth = charData.xAdvance + fontProp.m_kerning + font.GetHorzPadding();
// Add in any additional spacing for the space character
if( id == ' ' )
spaceWidth += fontProp.m_spaceCharKerning;
width += spaceWidth;
if( id != ' ')
lastCharOffset = charData.offset.w;
++counter;
}
// Wrap to another line
if( (id == ' ') && (fontProp.m_lineWrapWidth > 0.f) )
{
float nextWord = 0.f;
// Get the length of the next word to see if if should wrap
for( size_t j = i+1; j < str.size(); ++j )
{
id = str[j];
if( id != '|' )
{
// See if we can find the character
const CCharData & charData = font.GetCharData(id);
// Break here when space is found
// Don't add the space to the size of the next word
if( id == ' ' )
break;
// Don't count the
nextWord += charData.xAdvance + fontProp.m_kerning + font.GetHorzPadding();
}
}
if( width + nextWord >= fontProp.m_lineWrapWidth )
{
// Add the line width to the vector based on horz alignment
AddLineWithToVec( font, lineWidthOffsetVec, fontProp.m_hAlign, width-spaceWidth, firstCharOffset, lastCharOffset );
counter = 0;
width = 0;
}
}
}
// Add the line width to the vector based on horz alignment
AddLineWithToVec( font, lineWidthOffsetVec, fontProp.m_hAlign, width, firstCharOffset, lastCharOffset );
return lineWidthOffsetVec;
} // CalcLineWidthOffset