/*
Test application illustrating https://bugzilla.gnome.org/show_bug.cgi?id=768679
Link with kernel32, user32, gdi32, gobject, pango, pangowin32
*/

#define UNICODE
#include <windows.h>

#include <pango/pango.h>
#include <pango/pangowin32.h>

PangoContext *pango_ctx;

void PaintWindow(HWND hWnd)
{
	PAINTSTRUCT ps;
	HDC hDC = BeginPaint(hWnd, &ps);
	PangoLayout *layout = pango_layout_new(pango_ctx);

	SetTextAlign(hDC, TA_BASELINE | TA_LEFT);
	
	pango_layout_set_markup(layout, "<span font='Arial'>Hello</span>", -1);
	pango_win32_render_layout(hDC, layout, 100, 100);
	pango_layout_set_markup(layout, "<span bgcolor='blue'><span color='#f00'>W</span><span size='32000'><span color='#f80' underline='double' underline_color='pink'>o</span><span color='#ff0'>r</span></span><span color='#8f0'>l</span><span color='#0f0'>d</span></span>", -1);
	pango_win32_render_layout(hDC, layout, 200, 200);
	g_object_unref(layout);

	EndPaint(hWnd, &ps);
}

/* Only boring boilerplate code past this point */
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_PAINT:
		PaintWindow(hWnd);
		return 0;
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}

int wmain(int argc, wchar_t **argv)
{
	HINSTANCE inst = GetModuleHandle(NULL);
	WNDCLASSEX wndcls = {0};
	HWND wnd;
	MSG msg;
	PangoFontMap *pango_fm = pango_win32_font_map_for_display();
	pango_ctx = pango_font_map_create_context(pango_fm);

	wndcls.cbSize = sizeof(wndcls);
	wndcls.hInstance = inst;
	wndcls.style = CS_HREDRAW | CS_VREDRAW;
	wndcls.lpfnWndProc = &WindowProc;
	wndcls.lpszClassName = TEXT("wndc");
	wndcls.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

	RegisterClassEx(&wndcls);

	wnd = CreateWindow(wndcls.lpszClassName, TEXT("pango-test"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, inst, NULL);
	ShowWindow(wnd, SW_NORMAL);

	while (GetMessage(&msg, NULL, 0, 0) != 0)
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return 0;
}
