コード例 #1
0
BOOL GdiplusUtilities::DrawTextOutline(Gdiplus::Graphics& graphics, 
					 LPCTSTR lpchText, int cchText, const Gdiplus::Rect& rc, const Gdiplus::StringFormat& format, 
					 const Gdiplus::Font& font, Gdiplus::Color fill, Gdiplus::Color outline, INT outlineWidth,
					 BOOL bCalcOnly/* = FALSE*/, Gdiplus::Rect* rcCalc/* = NULL*/)
{
	Gdiplus::FontFamily fontFamily;
	font.GetFamily(&fontFamily);
	Gdiplus::GraphicsPath path;
	path.AddString(lpchText, cchText, &fontFamily, font.GetStyle(), font.GetHeight(&graphics), rc, &format);

	if (rcCalc != NULL)
	{
		path.GetBounds(rcCalc);
		rcCalc->Inflate(outlineWidth, outlineWidth);
	}
	if (bCalcOnly)
		return TRUE;

	Gdiplus::Pen pen(outline, (Gdiplus::REAL) outlineWidth);
	if (graphics.DrawPath(&pen, &path) == Gdiplus::Ok)
	{
		Gdiplus::SolidBrush brush(fill);
		return graphics.FillPath(&brush, &path) == Gdiplus::Ok;
	}
	return FALSE;
}
コード例 #2
0
ファイル: zipk.cpp プロジェクト: wangch/zipk
static Gdiplus::Size getTxtSize(std::wstring txt) {
   Gdiplus::GraphicsPath path;
   Gdiplus::FontFamily ff;
   Gdiplus::Font* font = g_lv.f;
   font->GetFamily(&ff);

   Gdiplus::Rect rc;
   Gdiplus::Size sz;
   int len = txt.length();
   if (len == 0) {
      return sz;
   }

   bool is_space = false;
   if (txt[len - 1] == L' ') {
      txt[len - 1] = L'M';
      is_space = true;
   }

   path.AddString(txt.c_str(), 
      len, &ff, 
      font->GetStyle(), 
      font->GetSize(), 
      Gdiplus::Point(1, 0), 
      NULL);
   path.GetBounds(&rc);

   int sd = (int)(font->GetSize() / 4);
   sz.Width = rc.Width + sd;
   if (is_space) {
      sz.Width -= sd;
   }
   sz.Height = rc.Height;
   return sz;
}
コード例 #3
0
ファイル: cgGdiplusRender.cpp プロジェクト: cgcoolgame/cg
cgSizeF cgGdiplusRender::GetUICharSize( TCHAR ch, cgID idFont )
{
	Gdiplus::Font * pkFont = FindFont(idFont);
	if (pkFont)
	{
		int w = ch<128?pkFont->GetSize()/2:pkFont->GetSize();
		return cgSizeF(w, pkFont->GetSize());
	}
	return cgSizeF();
}
コード例 #4
0
ファイル: cgGdiplusRender.cpp プロジェクト: cgcoolgame/cg
int cgGdiplusRender::GetUICharWidth( TCHAR ch, cgID idFont )
{
	int nW = 0;
	Gdiplus::Font * pkFont = FindFont(idFont);
	if (pkFont)
	{
		int nSize = pkFont->GetSize(); 

		if (ch < 128)
			nW = nSize/2;
		else
			nW = nSize;
	}
	return nW;
}
コード例 #5
0
ファイル: ListView.cpp プロジェクト: okdevdo/UserLib
void CListViewNode::OnCalcRects(Gdiplus::Graphics* graphics, LPRECT pRect, LPINT maxWidth)
{
	if ( !m_listView )
		return;

	Gdiplus::Font* pFont = NULL;

	if ( m_selected )
		pFont = m_listView->get_Font(_T(".Font.Selected"), _T("ListView"));
	else
		pFont = m_listView->get_Font(_T(".Font.Normal"), _T("ListView"));

	Gdiplus::PointF pt; pt.X = (Gdiplus::REAL)(pRect->left); pt.Y = (Gdiplus::REAL)(pRect->top);
	Gdiplus::RectF textRect;

	if ( m_text.IsEmpty() )
	{
		textRect.X = pt.X; textRect.Y = pt.Y; textRect.Height = pFont->GetHeight(graphics); textRect.Width = 10;
	}
	else
		graphics->MeasureString(m_text.GetString(), m_textDisplayLength, pFont, pt, Gdiplus::StringFormat::GenericTypographic(), &textRect);

	Convert2Rect(pRect, &textRect);

	Gdiplus::Bitmap* image = NULL;
	LONG hImage = 0;

	if ( (m_imageIndex >= 0) && (((dword)m_imageIndex) < m_listView->get_ImageCount()) )
		image = m_listView->get_Image(m_imageIndex);
	if ( image && (image->GetHeight() > 0) )
		hImage = image->GetHeight();

	::SetRect(&m_iconRect, pRect->left, pRect->top, pRect->left + hImage, (hImage > 0)?(pRect->top + hImage):(pRect->bottom));
	if ( (hImage > 0) && ((pRect->bottom - pRect->top) > hImage) )
		::OffsetRect(&m_iconRect, 0, (pRect->bottom - pRect->top - hImage) / 2);
	::OffsetRect(pRect, hImage + 2, 0);
	::CopyRect(&m_textRect, pRect);
	if ( hImage > (pRect->bottom - pRect->top) )
		::OffsetRect(&m_textRect, 0,  (hImage - (pRect->bottom - pRect->top)) / 2);
	::CopyRect(&m_borderRect, &m_textRect);
	m_borderRect.right += 4; m_borderRect.bottom += 4;
	::OffsetRect(&m_textRect, 2, 2);
	if ( m_borderRect.right > *maxWidth )
		*maxWidth = m_borderRect.right;
	::OffsetRect(pRect, -(hImage + 2), 0);
	pRect->top = max(m_iconRect.bottom, m_borderRect.bottom);
	pRect->bottom = 0;
}
コード例 #6
0
TextDisplay::DisplayTexture TextDisplay::createTexture(const char* text)
{
	DisplayTexture displayTex;
	size_t textLen = strlen(text);
	displayTex.text = new char[textLen+1];
	strcpy_s(displayTex.text, textLen+1, text);
	Bitmap* bitmap;
	Gdiplus::Font* font;

	{
		pfc::stringcvt::string_wide_from_utf8 w_text(text);
		StringFormat strFormat;
		strFormat.SetAlignment(StringAlignmentCenter);
		strFormat.SetTrimming(StringTrimmingNone);
		strFormat.SetFormatFlags(StringFormatFlagsNoFitBlackBox |
								 StringFormatFlagsNoWrap |
								 StringFormatFlagsNoClip);
		RectF stringSize(0, 0, 1024, 128);

		{ // calculate Text Size
			Bitmap calcBitmap(5, 5, PixelFormat32bppARGB);
			Graphics graphics(&calcBitmap);

			HDC fontDC = graphics.GetHDC();
			font = new Gdiplus::Font(fontDC, &(cfgTitleFont.get_value()));
			graphics.ReleaseHDC(fontDC);
			if (!font->IsAvailable()){
				delete font;
				font = new Gdiplus::Font(L"Verdana", 8.0f);
			}

			graphics.MeasureString(w_text, -1, font, PointF(), &stringSize);
		}
		// round to multiples of two, so centering is consistent
		stringSize.Width = ceil(stringSize.Width / 2.0f) * 2;
		stringSize.Height = ceil(stringSize.Height);
		displayTex.texWidth  = displayTex.textWidth  = (int)stringSize.Width;
		displayTex.texHeight = displayTex.textHeight = (int)stringSize.Height;
		
		// Make the texture size a power of two
		displayTex.texWidth = 1;
		while (displayTex.texWidth < displayTex.textWidth)
			displayTex.texWidth = displayTex.texWidth << 1;

		displayTex.texHeight = 1;
		while (displayTex.texHeight < displayTex.textHeight)
			displayTex.texHeight = displayTex.texHeight << 1;

		bitmap = new Bitmap(displayTex.texWidth, displayTex.texHeight, PixelFormat32bppARGB);
		Graphics drawer(bitmap);
		drawer.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);

		Color textColor(255, 255, 255);
		textColor.SetFromCOLORREF(cfgTitleColor);
		SolidBrush textBrush(textColor);
		displayTex.color = cfgTitleColor;

		drawer.DrawString(w_text, -1, font, stringSize, &strFormat, &textBrush);
	}

	{
		bitmap->RotateFlip(RotateNoneFlipY);
		Rect rc(0,0,bitmap->GetWidth(),bitmap->GetHeight());
		BitmapData bitmapData;
		bitmap->LockBits(&rc,ImageLockModeRead,PixelFormat32bppARGB,&bitmapData);

		glGenTextures(1,&displayTex.glTex);
		glBindTexture(GL_TEXTURE_2D, displayTex.glTex);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);

		void* data = bitmapData.Scan0;
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, displayTex.texWidth, displayTex.texHeight, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE,data);

		bitmap->UnlockBits(&bitmapData);

	}
	delete bitmap;
	delete font;

	return displayTex;
}