当前位置: 首页>>代码示例>>C++>>正文


C++ CFont::GetCharData方法代码示例

本文整理汇总了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
开发者ID:GameCodingNinja,项目名称:SampleCode,代码行数:92,代码来源:visualcomponent2d.cpp


注:本文中的CFont::GetCharData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。