Пример #1
0
//---------------------------------------------------------------------------
void GetCharacterSizes(Gdiplus::Font& font, Gdiplus::Graphics& charGraphics, FontAtlasSizeInfo* info /*OUT*/)
{
    using namespace Gdiplus;

    //
    // Make a string comprising all characters we'll have in the font.
    //
	WCHAR allChars[s_NumChars + 1];
	for ( WCHAR i = 0; i < s_NumChars; ++i )
    {
		allChars[i] = ( s_StartChar + i );
    }
	allChars[s_NumChars] = 0;

    //
    //  Measure the entire character set.
    //
	RectF sizeRect;
	charGraphics.MeasureString(allChars, s_NumChars, &font, PointF(0, 0), &sizeRect);
	info->characterRowHeight = (int)(sizeRect.Height + 0.5f);  

    //
	//  The texture's width is fixed and already determined, so compute
    //  how many rows we'll need to place all of the characters on it,
    //  and how tall the texture will need to be.
    //
	int numRows = (int)(sizeRect.Width / info->atlasTextureWidth) + 1;  
	info->atlasTextureHeight  = (int)(numRows*info->characterRowHeight) + 1;

    //
    //  No use "drawing" a space character. Just remember how much of
    //  a horizontal shift is needed to represent a space on the screen.
    //
    {
	    WCHAR charString[2] = {' ', 0};
	    charGraphics.MeasureString(charString, 1, &font, PointF(0, 0), &sizeRect);
	    info->spaceCharacterWidth = (int)(sizeRect.Width + 0.5f);
    }
  
    //
    //  For the gap between characters, apply a factor to the size of
    //  a basic character width.
    //
    {
        static const float kCharGapFactor = 0.10f;   // portion of a space character
	    WCHAR charString[2] = {'x', 0};
	    charGraphics.MeasureString(charString, 1, &font, PointF(0, 0), &sizeRect);
	    info->gapBetweenChars = (int)(sizeRect.Width * kCharGapFactor );
    }
}
Пример #2
0
void Graphics::MeasureString(const wchar_t* text,size_t length, const Font* font, const PointF& origin, RectF* boundingBox) {
    Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private);
    Gdiplus::Font* gdiFont = reinterpret_cast<Gdiplus::Font*>(font->_private);

    Gdiplus::RectF gdiBound;
    g->MeasureString(text, (int)length, gdiFont, ToGDIPoint<PointF, Gdiplus::PointF>(origin), &gdiBound);
    *boundingBox = RectF(gdiBound.X, gdiBound.Y, gdiBound.Width, gdiBound.Height);
}
Пример #3
0
Gdiplus::RectF GdiplusUtilities::DrawTextMeasure(Gdiplus::Graphics& graphics, LPCTSTR lpchText, int cchText, const Gdiplus::Font& font)
{
	Gdiplus::PointF p;
	Gdiplus::RectF rc;
	if (graphics.MeasureString(lpchText, cchText, &font, p, &rc))
	{
	}
	return rc;
}
Пример #4
0
void DxFont::MeasureChars(Gdiplus::Font & font, Gdiplus::Graphics & charGraphics)
{
    WCHAR allChars[ NumChars + 1 ];

    for( WCHAR i = 0; i < NumChars; ++i )
        allChars[i] = StartChar + i;

    allChars[ NumChars ] = 0;

    Gdiplus::RectF sizeRect;
    charGraphics.MeasureString( allChars, NumChars, &font, Gdiplus::PointF( 0, 0 ), &sizeRect );
    CharHeight = static_cast<int>( sizeRect.Height + 0.5f );

    int numRows = static_cast<int>( sizeRect.Width / TexWidth ) + 1;
    TexHeight   = static_cast<int>( numRows * CharHeight ) + 1;

    WCHAR charString[ 2 ] = { ' ', 0 };
    charGraphics.MeasureString( charString, 1, &font, Gdiplus::PointF( 0, 0 ), &sizeRect );
    SpaceWidth = static_cast<int>( sizeRect.Width + 0.5f );
}
Пример #5
0
void TextComponent::paint(Gdiplus::Graphics& graphics)
{
  Gdiplus::SolidBrush brush(Gdiplus::Color(m_r, m_g, m_b));
  Gdiplus::FontFamily fontFamily(L"Helvetica");
  Gdiplus::Font font(&fontFamily, (Gdiplus::REAL) m_fontSize, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
  Gdiplus::PointF pointF(m_x, m_y);
  Gdiplus::RectF boundingBox;
  graphics.MeasureString(m_text.c_str(), -1, &font, pointF, &boundingBox);
  m_width = boundingBox.Width;
  m_height = boundingBox.Height;
  graphics.DrawString(m_text.c_str(), -1, &font, pointF, &brush);
}
Пример #6
0
		void text_size(const char* str, Size* size)
		{
			size->w = 0;
			size->h = 0;

			st count = cl::StringUtil::char_to_wchar_count(str);
			wchar* wstr = cl_alloc_type_with_count(wchar, count);
			if(wstr == NULL) return;
			cl::StringUtil::char_to_wchar(wstr, count, str);

			Gdiplus::RectF limit(0, 0, 9999, 9999);
			Gdiplus::RectF result;
			graphics->MeasureString(wstr, -1, font, limit, &result);
			cl_free(wstr);
			size->set((st)result.Width, (st)result.Height);
		}