/************************************************************************
*    desc:  Add the line width to the vector based on horz alignment
************************************************************************/
void CVisualComponent2d::AddLineWithToVec(
    const CFont & font,
    std::vector<float> & lineWidthOffsetVec,
    const NDefs::EHorzAlignment hAlign,
    float width,
    float firstCharOffset,
    float lastCharOffset )
{
    if( hAlign == NDefs::EHA_HORZ_LEFT )
        lineWidthOffsetVec.push_back(-(firstCharOffset + font.GetHorzPadding()));

    else if( hAlign == NDefs::EHA_HORZ_CENTER )
        lineWidthOffsetVec.push_back(-((width + (firstCharOffset + lastCharOffset)) / 2.f));

    else if( hAlign == NDefs::EHA_HORZ_RIGHT )
        lineWidthOffsetVec.push_back(-(width - lastCharOffset - font.GetHorzPadding()));

    // Remove any fractional component of the line height offset
    lineWidthOffsetVec.back() = (int)lineWidthOffsetVec.back();

}   // 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