[BIDITEXT] Add more demo code. (#842)

Add code that demonstrates the use of the lpOrder and lpCaretPos struct members of GCP_RESULTS w/ and  w/o GCP_REORDER flag.
Changed demo string literals to arrays containing character unicode values.
This commit is contained in:
Baruch Rutman 2018-09-07 10:59:59 +03:00 committed by Hermès Bélusca-Maïto
parent ab5fdcc01f
commit 1fc041c91a
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 80 additions and 7 deletions

View file

@ -60,7 +60,7 @@ wWinMain(HINSTANCE hInstance,
hAccelerators = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));
/* Show main window and force a paint */
ShowWindow(hWnd, nCmdShow);
ShowWindow(hWnd, nCmdShow | SW_MAXIMIZE);
UpdateWindow(hWnd);
/* Main message loop */
@ -171,24 +171,47 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
LPWSTR szString = L"אבגדהABCDוזחטי";
int Len = (int)wcslen(szString);
HDC hdc = BeginPaint(hWnd, &ps);
enum
{
ALEF = 0x5D0,
BET,
GIMEL,
DALET,
HEY,
VAV,
ZAYIN,
HET,
TET,
YUD
};
const WCHAR szString[] = {ALEF, BET, GIMEL, DALET, HEY, 'A', 'B', 'C', 'D', VAV, ZAYIN, HET, TET, YUD, 0};
const WCHAR szReversedString[] = {HEY, DALET, GIMEL, BET, ALEF, 'A', 'B', 'C', 'D', YUD, TET, HET, ZAYIN, VAV, 0};
int Len = wcslen(szString);
int i, xpos, tempLength;
WCHAR tempString[20] = { 0 };
WCHAR Glyphs[100] = { 0 };
WCHAR OutString[100] = { 0 };
INT lpCaretPos[100] = { 0 };
UINT lpOrder[100] = { 0 };
GCP_RESULTSW Results = { 0 };
Results.lStructSize = sizeof(Results);
Results.lpOutString = OutString;
Results.lpGlyphs = Glyphs;
Results.nGlyphs = 100;
Results.lpCaretPos = lpCaretPos;
Results.lpOrder = lpOrder;
SetBkMode(hdc, TRANSPARENT);
TextOutW(hdc, 10, 10, L"Proper (string being used):", 27);
TextOutW(hdc, 200, 10, szString, 14);
TextOutW(hdc, 10, 30, L"Reversed (example):", 19);
TextOutW(hdc, 200, 30, L"הדגבאABCDיטחזו", 14);
TextOutW(hdc, 200, 30, szReversedString, 14);
TextOutW(hdc, 10, 50, L"String with NULL LpkETO call (not reversed):", 44);
LpkExtTextOut(hdc, 10, 70, 0, NULL, szString, Len, NULL, 0);
@ -217,6 +240,55 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
TextOutW(hdc, 10, 370, L"String with ETO_RTLREADING ETO call (slight order change)", 57);
ExtTextOutW(hdc, 10, 390, ETO_RTLREADING, NULL, szString, Len, NULL);
GetCharacterPlacementW(hdc, szString, Len, 0, &Results, GCP_REORDER);
TextOutW(hdc, 10, 410, L"Glyph positions with GCP_REORDER flag", 37);
/* Prints per column the location of the character in the string, reordered location, its position and the character itself */
for (i = 0, xpos = 10; i < Len; i++, xpos += 30)
{
StringCchPrintfW(tempString, 20, L"%d", i);
tempLength = wcslen(tempString);
TextOutW(hdc, xpos, 430, tempString, tempLength);
StringCchPrintfW(tempString, 20, L"%d", lpOrder[i]);
tempLength = wcslen(tempString);
TextOutW(hdc, xpos, 450, tempString, tempLength);
StringCchPrintfW(tempString, 20, L"%d", lpCaretPos[i]);
tempLength = wcslen(tempString);
TextOutW(hdc, xpos, 470, tempString, tempLength);
TextOutW(hdc, xpos, 490, &szString[i], 1);
}
TextOutW(hdc, xpos, 430, L"Character location", 18);
TextOutW(hdc, xpos, 450, L"lpOrder[i]", 10);
TextOutW(hdc, xpos, 470, L"lpCaretPos[i]", 13);
TextOutW(hdc, xpos, 490, L"String[i]", 9);
GetCharacterPlacementW(hdc, szString, Len, 0, &Results, 0);
TextOutW(hdc, 10, 510, L"Glyph positions without GCP_REORDER flag", 40);
for (i = 0, xpos = 10; i < Len; i++, xpos += 30)
{
StringCchPrintfW(tempString, 20, L"%d", i);
tempLength = wcslen(tempString);
TextOutW(hdc, xpos, 530, tempString, tempLength);
StringCchPrintfW(tempString, 20, L"%d", lpOrder[i]);
tempLength = wcslen(tempString);
TextOutW(hdc, xpos, 550, tempString, tempLength);
StringCchPrintfW(tempString, 20, L"%d", lpCaretPos[i]);
tempLength = wcslen(tempString);
TextOutW(hdc, xpos, 570, tempString, tempLength);
TextOutW(hdc, xpos, 590, &szString[i], 1);
}
TextOutW(hdc, xpos, 530, L"Character location", 18);
TextOutW(hdc, xpos, 550, L"lpOrder[i]", 10);
TextOutW(hdc, xpos, 570, L"lpCaretPos[i]", 13);
TextOutW(hdc, xpos, 590, L"String[i]", 9);
EndPaint(hWnd, &ps);
break;
}

View file

@ -2,6 +2,7 @@
#include <windows.h>
#include <commctrl.h>
#include <strsafe.h>
/* Global instance handle */
extern HINSTANCE g_hInstance;