I am using ExtTextOut to print unicode characters. We create font using
CreateFontIndirect to print characters in different orientations. When we
use GB2312_CHARSET (chinese character set) with lfEscapement/orientation
set to 270 degrees the characters are printed in reverse order.
If the character to be printed is 'Chinese', it is printed as 'esenihc'.
The same character set works fine if lfEscapement/orientation is set to 0
deg.
The issue is present only in WINCE. The same code works fine in a Win32
application.
I have written a sample application.Find below the code from sample app
CSampView::OnDraw (CDC* pDisplayDC)
{
HDC hDC = CreateCompatibleDC(NULL);
HBITMAP hBmp = CreateCompatibleBitmap(hDC, width, height);
BITMAPINFO biBitmapInfo;
// font size may vary if screen resolution changes
biBitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
biBitmapInfo.bmiHeader.biWidth = 500;
biBitmapInfo.bmiHeader.biHeight = 500;
biBitmapInfo.bmiHeader.biPlanes = 1;
biBitmapInfo.bmiHeader.biBitCount = 1 ;
biBitmapInfo.bmiHeader.biCompression = BI_RGB;
biBitmapInfo.bmiHeader.biSizeImage = 0;
biBitmapInfo.bmiHeader.biXPelsPerMeter = 0;
biBitmapInfo.bmiHeader.biYPelsPerMeter = 0;
biBitmapInfo.bmiHeader.biClrUsed = 0;
biBitmapInfo.bmiHeader.biClrImportant = 0;
biBitmapInfo.bmiColors[0].rgbBlue = 0;
biBitmapInfo.bmiColors[0].rgbGreen = 0;
biBitmapInfo.bmiColors[0].rgbRed = 0;
biBitmapInfo.bmiColors[1].rgbBlue =1;
biBitmapInfo.bmiColors[1].rgbGreen = 1;
biBitmapInfo.bmiColors[1].rgbRed = 1;
CDC *pDC = CDC::FromHandle(hDC);
/*TCHAR szString[255] = {0x0043, 0x0068, 0x0069, 0x006E, 0x0065, 0x0073,
0x0065, 0x003A, 0x0020, 0x96C5,
0x864E, 0x641C, 0x661F, 0x575A, 0x51B3, 0x5426, 0x8BA4, 0x80E1,
0x6208, 0x63A5,
0x62CD, 0x96C5, 0x864E, 0x5E7F, 0x544A };*/
wchar_t szString[255] = _T("Print Test");
PUINT8 pui8ImageContent;
// Create rendering canvas
HBITMAP hBmp1 = CreateDIBSection(hDC,
&biBitmapInfo,
DIB_PAL_COLORS,
(void**)&pui8ImageContent,
NULL,
0);
HBITMAP holdObj = (HBITMAP)SelectObject(hDC, hBmp1);
if (NULL == holdObj)
{
AfxMessageBox(L"Bitmap Selection failed");
}
CBitmap* aBMP = CBitmap::FromHandle(hBmp);
BITMAP* abmpDim = NULL;
aBMP->GetBitmap(abmpDim);
memset(pui8ImageContent, 0, m_iOverallSizeInBytes);
LOGFONT SLogFont = {0};
memset(&SLogFont, 0, sizeof(LOGFONT));
SLogFont.lfHeight = 50;
SLogFont.lfWidth = 50;
SLogFont.lfCharSet = GB2312_CHARSET
/*HANGUL_CHARSET*//*DEFAULT_CHARSET*/;
SLogFont.lfEscapement = 2700;
SLogFont.lfOrientation = 2700;
SLogFont.lfItalic = FALSE;
SLogFont.lfUnderline = FALSE;
SLogFont.lfStrikeOut = FALSE;
SLogFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
SLogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
SLogFont.lfQuality = DEFAULT_QUALITY;
SLogFont.lfPitchAndFamily = VARIABLE_PITCH|FF_ROMAN;
wcscpy(SLogFont.lfFaceName,_T("@Simsun"));
HFONT hChFont = CreateFontIndirect(&SLogFont);
if (NULL == hChFont)
{
AfxMessageBox(L"Font Creation failed");
}
CFont* pFont = pDC->GetCurrentFont();
HFONT hFont = (HFONT)SelectObject(hDC, hChFont);
if (NULL == hFont)
{
AfxMessageBox(L"Font selection failed");
}
BOOL aStringWtitten = ExtTextOut(
hDC, // Rendering canvas
SSize.cy + iVerStartBit + 50, // x-offset
100, // y-offset
ETO_OPAQUE,
NULL,
szString,
wcslen(szString),
NULL);
if (false == aStringWtitten)
{
AfxMessageBox(_T("Write text failed"));
}
BitBlt(pDisplayDC->GetSafeHdc(),50, 0, 500, 500, hDC, 0, 0, SRCCOPY);
}

