Пример #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
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
/* Creating of the options from the script. */
bool DIALOGUE::CreateOptions(){

	// atributes
	std::wstring text;
	Gdiplus::GraphicsPath path;
	// caused changes which will be paired with the options
	std::string state_name;
	std::vector<state_changes> changes; 

	if(!script.FindElem(L"OPTIONS")){
		TermLog("Options tag not found in the Dialogue scene, script.xml file is probably damaged.");
		return false;
	}
	script.IntoElem();

	// Going through the options
	if(!script.FindElem(L"OPTION")){
		script.OutOfElem();
		TermLog("No option to choose found in the dialogue scene.");
		return false;
	}
	else do {
		text = script.GetAttrib(L"text");
		
		line_top -= line_height; // Put the line above the previous
		stat = path.AddString(text.c_str(), -1, fontFamily, Gdiplus::FontStyleBold, text_size, Gdiplus::PointF(0, Gdiplus::REAL(line_top)), &strformat);
			if (stat != 0) StatusLog("GraphicPath.AddString()", stat, false);

		script.IntoElem();

		if(!CheckTests()){
			script.OutOfElem();
			continue;
		}


		// creates the map of state changes
		while(script.FindElem(L"STATECHANGE")){
			state_changes current_changes;
			current_changes.name = wstring2string(script.GetData());
			current_changes.value = atoi((wstring2string(script.GetAttrib(L"value"))).c_str());
			current_changes.replace = atoi((wstring2string(script.GetAttrib(L"replace"))).c_str())  != 0 ? true : false;
			changes.push_back(current_changes);
		}
		
		script.OutOfElem(); // Jumps out of the object

		options.push_back(OPTION(text, &path, changes));
		changes.clear();
		StatusLog("GraphicPath.Reset()", path.Reset(), false);

	} while(script.FindElem(L"OPTION"));

	script.OutOfElem();
	return true;
}
Пример #4
0
	void TextElement::DrawTextVector(RenderContext& ctx)
	{
		Gdiplus::RectF textrect;
		if (!RectFFromStyle(GetStyle(), textrect) || !m_font || m_text.empty())
			return;

		ctx.pGraphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);

		Gdiplus::FontFamily family(L"Tahoma");
		Gdiplus::StringFormat format;
		format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit);
		format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter);

		Gdiplus::GraphicsPath path;
		path.AddString(m_text.c_str(), -1, &family, Gdiplus::FontStyleBold, 12, textrect, &format);

		Gdiplus::Pen pen(Gdiplus::Color(192, 0, 0, 0), 0.0);
		Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255));
		ctx.pGraphics->FillPath(&brush, &path);
		ctx.pGraphics->DrawPath(&pen, &path);
	}
Пример #5
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
    switch (message)
    {
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // Parse the menu selections:
            switch (wmId)
            {
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
	case WM_RBUTTONUP:
		DialogBox(hInst, MAKEINTRESOURCE(IDD_SETTINGS), hWnd, Settings);
		{
			Gdiplus::Graphics g(hWnd);
			Gdiplus::GraphicsPath path;
			path.AddString(config.text,
							-1,
							new Gdiplus::FontFamily(config.font),
							Gdiplus::FontStyleRegular,
							config.height,
							config.position,
							new Gdiplus::StringFormat());
			g.RotateTransform(config.angle);
			g.ScaleTransform(config.scale, config.scale);
			if (config.antialiasing)
			{
				g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
			}
			Gdiplus::Region r(&path);
			RECT rect, rect1;
			GetClientRect(hWnd, &rect);
			ClientToScreen(hWnd, (LPPOINT)&rect);
			GetWindowRect(hWnd, &rect1);
			HRGN h = r.GetHRGN(&g);
			OffsetRgn(h, (rect.left - rect1.left), (rect.top - rect1.top));
			SetWindowRgn(hWnd, config.defaultRegion ? oldRgn : h, TRUE);
			InvalidateRect(hWnd, NULL, TRUE);
		}
		break;
    case WM_PAINT:
        {
			HDC hdc = BeginPaint(hWnd, &ps);
			{
				Gdiplus::Graphics g(hdc);
				Gdiplus::GraphicsPath path;
				path.AddString(config.text,
								-1,
								new Gdiplus::FontFamily(config.font),
								Gdiplus::FontStyleRegular,
								config.height,
								config.position,
								new Gdiplus::StringFormat);
				g.Clear(config.backgroundColor);
				g.RotateTransform(config.angle);
				g.ScaleTransform(config.scale, config.scale);
				if (config.antialiasing)
				{
					g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
				}
				//g.SetSmoothingMode(config.antialiasing ? Gdiplus::SmoothingModeHighQuality : );
				g.DrawPath(new Gdiplus::Pen(config.outlineColor, 2.f), &path);
				g.FillPath(new Gdiplus::SolidBrush(config.fillColor), &path);
			}
			EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Пример #6
0
void IrisBitmap::IrisDrawText(const IrisFont* fontIris, int x, int y, int width, int height, wstring str, int align){
	this->needRefreshTexture = true;

	if (x > this->width || y > this->height || x < 0 || y < 0)
		return;

	//this->needRefreshTexture = true;

	int size = IrisFont::defaultSize;
	IrisColor *color;
	wstring name;
	bool bold, shadow, italic;

	if(fontIris == NULL){
		name = IrisFont::defaultName;
		bold = IrisFont::defaultBold;
		shadow = IrisFont::defaultShadow;
		italic = IrisFont::defaultItalic;
		color = IrisFont::defaultColor;
	}
	else
	{
		name = fontIris->name;
		bold = fontIris->bold;
		shadow = fontIris->shadow;
		italic = fontIris->italic;
		color = fontIris->color;
	}

	// release
	

	Gdiplus::Bitmap *tBitmap = this->bitmap->Clone(0, 0, this->bitmap->GetWidth(), this->bitmap->GetHeight(), PixelFormat32bppARGB);
	Graphics tg(tBitmap);

	Gdiplus::FontFamily fontFamily(name.c_str());
	int fs = FontStyleRegular;
	
	if(bold)
		fs |= FontStyleBold;

	if(italic)
		fs |= FontStyleItalic;

	//lfont.lfWeight = 1000;
	Gdiplus::Font font(&fontFamily, (REAL)size, fs, UnitPixel);

	StringFormat strFormat;

	switch(align){
	case 0:
		strFormat.SetAlignment(StringAlignmentNear);
		break;
	case 1:
		strFormat.SetAlignment(StringAlignmentCenter);
		break;
	}

	Brush *brush;

	if(shadow)
		brush = new HatchBrush(HatchStyle90Percent, Color(color->red, color->green, color->blue));
	else
		brush = new SolidBrush(Color(color->red, color->green, color->blue));

	strFormat.SetFormatFlags(StringFormatFlagsNoWrap);
	Gdiplus::RectF r((REAL)x, (REAL)y, (REAL)width, (REAL)height);
	tg.SetSmoothingMode(SmoothingModeAntiAlias);
	tg.SetInterpolationMode(InterpolationModeHighQualityBicubic);
	Gdiplus::GraphicsPath path;
	path.AddString(str.c_str(), str.size(), &fontFamily, FontStyleRegular, 20, r, &strFormat);
	Gdiplus::Pen pen(Color(color->red, color->green, color->blue), 2);
	tg.DrawPath(&pen, &path);
	tg.FillPath(brush, &path);

	if(this->bitmap != 0){
		delete this->bitmap;
		this->bitmap = 0;
	}

	this->bitmap = tBitmap->Clone(0, 0, tBitmap->GetWidth(), tBitmap->GetHeight(), PixelFormat32bppARGB);

	//CLSID encoderClsid;
	//ModuleIrisGraphics::GetEncoderClsid(L"image/png", &encoderClsid);
	//this->bitmap->Save(L"string.png", &encoderClsid, NULL);

	delete brush;
	delete tBitmap;
	
}
void LayeredWindowBase::Render()
{
	wchar_t pszbuf[] = L"1.Text Designer中文字也可顯示\n2.Text Designer中文字也可顯示\n3.Text Designer中文字也可顯示\n4.Text Designer中文字也可顯示\n5.Text Designer中文字也可顯示\n6.Text Designer中文字也可顯示 Text Designer中文字也可顯示\n7.Text Designer中文字也可顯示\n8.Text Designer中文字也可顯示\n9.Text Designer中文字也可顯示\n10.Text Designer中文字也可顯示";
	int nStrLen = wcslen(pszbuf);

	if (m_techType & LayeredWindow_TechType_D2D)
	{
		//m_pWin.pD2D->BeginDraw();
		m_pWin.pD2D->m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White,0.5));
		//m_pWin.pD2D->m_pRenderTarget->DrawText(pszbuf,nStrLen,
		//
		//	IFR(m_spDWriteFactory->CreateTextFormat(
		//	msc_fontName,
		//	NULL,
		//	DWRITE_FONT_WEIGHT_NORMAL,
		//	DWRITE_FONT_STYLE_NORMAL,
		//	DWRITE_FONT_STRETCH_NORMAL,
		//	msc_fontSize,
		//	L"", //locale
		//	&m_spTextFormat
		//	));

		//// Center the text both horizontally and vertically.
		//m_spTextFormat->SetTextAlignment(
		//	DWRITE_TEXT_ALIGNMENT_CENTER
		//	);

		//m_spTextFormat->SetParagraphAlignment(
		//	DWRITE_PARAGRAPH_ALIGNMENT_CENTER
		//	);

		//m_pWin.pD2D->m_pRenderTarget->DrawText(
		//	pszbuf,nStrLen,
		//	m_spTextFormat,
		//	D2D1::RectF(
		//	0,0,rtSize.width, rtSize.height
		//	),
		//	m_spBlackBrush
		//	);)
		//m_pWin.pD2D->EndDraw();
	}
	else if (m_techType & LayeredWindow_TechType_GDI)
	{
		//m_pWin.pGDI->BeginDraw();
		//Gdiplus::Graphics graphics( m_pBitmap->GetDC() ); //#MOD
		m_pWin.pGDI->m_pGraphics->Clear( Gdiplus::Color( 128, 255, 255, 255 ) );


		Gdiplus::FontFamily fontFamily(L"微軟正黑體");
		Gdiplus::Font oMS( &fontFamily, 32, Gdiplus::FontStyle::FontStyleRegular, Gdiplus::Unit::UnitPixel );
		Gdiplus::StringFormat strformat;


		Gdiplus::GraphicsPath *Path;
		Gdiplus::GraphicsPath path;
		//		Region *aRegion;
		Gdiplus::RectF rectf;
		
		rectf.X = 10;
		rectf.Y = 10;
		rectf.Width = 500;
		rectf.Height = 500;


		path.AddString(pszbuf, nStrLen, &fontFamily, 
			Gdiplus::FontStyleRegular, 32,rectf,&strformat );

		Gdiplus::SolidBrush brush(Gdiplus::Color(255,100,255));
		m_pWin.pGDI->m_pGraphics->FillPath(&brush, &path);

		//SelectObject(m_bitmap.m_hdc, m_bitmap.m_bitmap);
		//m_pWin.pGDI->EndDraw();
	}

}