[Win32]TrueType+轨迹

本文由 Ocrosoft 于 2018-06-11 23:26:06 发表

TrueType字体是使用字体轮廓输出的,可以和轨迹/区域一起实现有趣的效果

程序使用了之前的ezfont.h、ezfont.c、eztest.c、main.c,只更改了eztest.c中的PaintRoutine函数

1.1.eztest.c

#include <windows.h>
#include "ezfont.h"

TCHAR szAppName[] = TEXT("FontOut");
TCHAR szTitle[] = TEXT("FontOut");

/*void PaintRoutine(HWND hwnd, HDC hdc, int cxArea, int cyArea)
{
	static TCHAR szString[] = TEXT("Outline");
	HFONT hFont;
	SIZE size;

	hFont = EzCreateFont(hdc, TEXT("Times New Roman"), 1440, 0, 0, TRUE);

	SelectObject(hdc, hFont);

	GetTextExtentPoint32(hdc, szString, lstrlen(szString), &size);

	// 开始绘制轨迹
	BeginPath(hdc);
	TextOut(hdc, (cxArea - size.cx) / 2, (cyArea - size.cy) / 2, szString, lstrlen(szString));
	// 结束绘制轨迹
	EndPath(hdc);
	
	// 显示轨迹
	StrokePath(hdc);

	SelectObject(hdc, GetStockObject(SYSTEM_FONT));
	DeleteObject(hFont);
}*/

/*void PaintRoutine(HWND hwnd, HDC hdc, int cxArea, int cyArea)
{
	static TCHAR szString[] = TEXT("Outline");
	HFONT hFont;
	LOGBRUSH lb;
	SIZE size;

	hFont = EzCreateFont(hdc, TEXT("Times New Roman"), 1440, 0, 0, TRUE);

	SelectObject(hdc, hFont);
	// 背景模式为透明,不会显示外面的边框
	SetBkMode(hdc, TRANSPARENT);

	GetTextExtentPoint32(hdc, szString, lstrlen(szString), &size);

	BeginPath(hdc);
	TextOut(hdc, (cxArea - size.cx) / 2, (cyArea - size.cy) / 2, szString, lstrlen(szString));
	EndPath(hdc);

	lb.lbStyle = BS_SOLID;
	lb.lbColor = RGB(255, 0, 0);
	lb.lbHatch = 0;

	// 不使用默认画笔,创建一个红色的点画笔,并选入设备描述表
	SelectObject(hdc, ExtCreatePen(PS_GEOMETRIC | PS_DOT, GetDeviceCaps(hdc, LOGPIXELSX) / 24, &lb, 0, NULL));

	StrokePath(hdc);

	SelectObject(hdc, GetStockObject(SYSTEM_FONT));
	DeleteObject(hFont);
}*/

/*void PaintRoutine(HWND hwnd, HDC hdc, int cxArea, int cyArea)
{
	static TCHAR szString[] = TEXT("Filling");
	HFONT hFont;
	SIZE size;

	hFont = EzCreateFont(hdc, TEXT("Times New Roman"), 1440, 0, 0, TRUE);

	SelectObject(hdc, hFont);
	// 设置背景色透明
	SetBkMode(hdc, TRANSPARENT);

	GetTextExtentPoint32(hdc, szString, lstrlen(szString), &size);

	BeginPath(hdc);
	TextOut(hdc, (cxArea - size.cx) / 2, (cyArea - size.cy) / 2, szString, lstrlen(szString));
	EndPath(hdc);

	// 使用红色,cross花纹的刷子
	SelectObject(hdc, CreateHatchBrush(HS_DIAGCROSS, RGB(255,0,0)));
	// 蓝色的背景色
	SetBkColor(hdc, RGB(0, 0, 255));
	// 设置背景色不透明
	SetBkMode(hdc, OPAQUE);

	StrokeAndFillPath(hdc);
	// 等效上面的函数,但是FillPath(hdc)需要在前
	//FillPath(hdc);
	//StrokePath(hdc);

	DeleteObject(SelectObject(hdc, GetStockObject(WHITE_BRUSH)));
	SelectObject(hdc, GetStockObject(SYSTEM_FONT));
	DeleteObject(hFont);
}*/

void PaintRoutine(HWND hwnd, HDC hdc, int cxArea, int cyArea)
{
	static TCHAR szString[] = TEXT("Clipping");
	HFONT hFont;
	int y, iOffset;
	POINT pt[4];
	SIZE size;

	hFont = EzCreateFont(hdc, TEXT("Times New Roman"), 1440, 0, 0, TRUE);
	SelectObject(hdc, hFont);

	GetTextExtentPoint32(hdc, szString, lstrlen(szString), &size);

	BeginPath(hdc);
	TextOut(hdc, (cxArea - size.cx) / 2, (cyArea - size.cy) / 2, szString, lstrlen(szString));
	EndPath(hdc);

	SelectClipPath(hdc, RGN_COPY);

	iOffset = (cxArea + cyArea) / 4;

	for (y = -iOffset; y < cyArea + iOffset; y++)
	{
		pt[0].x = 0;
		pt[0].y = y;
		pt[1].x = cxArea / 3;
		pt[1].y = y + iOffset;
		pt[2].x = 2 * cxArea / 3;
		pt[2].y = y - iOffset;
		pt[3].x = cxArea;
		pt[3].y = y;

		SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(rand() % 256, rand() % 256, rand() % 256)));

		PolyBezier(hdc, pt, 4);

		DeleteObject(SelectObject(hdc, GetStockObject(BLACK_PEN)));
	}

	DeleteObject(SelectObject(hdc, GetStockObject(WHITE_BRUSH)));
	SelectObject(hdc, GetStockObject(SYSTEM_FONT));
	DeleteObject(hFont);
}

欢迎转载,请保留出处与链接。Ocrosoft » [Win32]TrueType+轨迹

点赞 (0)or拍砖 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址