Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Does Graphics.DrawDriverString support the drawing of 4-byte UTF-16 characters?

$
0
0

Graphics.DrawDriverString cannot draw 4-byte (such as [𣱿]) characters correctly.
Our project is developed by VS2010, and the Character Set is [Unicode Character Set].

//sample test code as follows:

#include <gdiplus.h>
using namespace Gdiplus;
//class member for initialize Gdiplus
ULONG_PTR            m_gdiplusToken;
GdiplusStartupInput    m_gdiplusStartupInput;
//initialize Gdiplus
Gdiplus::GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);

/// <summary>
/// test function for both display and printing
/// </summary>
/// <param name=' pDC '></param>
/// <param name=' fTop '>the top position for drawing</param>
void CPage::MyCharacterTest(CDC* pDC, float fTop)
{
    StringAlignment eVAlign = StringAlignmentCenter;
    Graphics gs(pDC->GetSafeHdc(), FALSE);
    //m_strFontName = _T("Times New Roman")//_T("MS Pゴシック")
    Gdiplus::Font oFont(m_strFontName, 18.0f, FontStyleRegular, UnitPixel);
    StringFormat oFormat;
    oFormat.SetTrimming(StringTrimmingWord);
    oFormat.SetFormatFlags(StringFormatFlagsMeasureTrailingSpaces | StringFormatFlagsDisplayFormatControl);
    oFormat.SetAlignment(StringAlignmentNear);
    oFormat.SetLineAlignment(eVAlign);
    SolidBrush oMyBrush(Color(255, 255,0,0));
    RectF rcRect(20, fTop + 40, 200.0f, 40.0f);
    PointF oPtStart1(20, fTop + 30 + 40 * 2);
    PointF oPtStart2(20, fTop + 30 + 40 * 3);

    CString strContent = _T("DrawString:123𣱿456");
    CString strContent1 = _T("DrawDriverString1:123𣱿456");
    CString strContent2 = _T("DrawDriverString2:123𣱿456");
    TCHAR szText[100]=_T("123𣱿456");

    //DrawString: both of display and print are correct
    gs.DrawString(strContent, strContent.GetLength(), &oFont, rcRect, &oFormat, &oMyBrush);    
    //DrawDriverString: display is correct; but,
    //print by virtual printer (Microsoft XPS Document Writer) will lost the last character “6”
    //print by physical printer, it will lost the last character “6” and show unknown character
    gs.DrawDriverString((UINT16*)(LPCTSTR)strContent1,
             strContent1.GetLength(),
             &oFont,
             &oMyBrush,
             &oPtStart1,
             DriverStringOptionsCmapLookup | DriverStringOptionsRealizedAdvance,
             NULL);
    gs.DrawDriverString((UINT16*)(LPCTSTR)strContent2,
            -1,
             &oFont,
             &oMyBrush,
             &oPtStart2,
             DriverStringOptionsCmapLookup | DriverStringOptionsRealizedAdvance,
             NULL);
}

Through the test under different language's operating system(English OS, Japanese OS, Chinese OS), I find the display result("123𣱿123") draw by DrawString is absolutely right, as well as the result by Microsoft XPS Document Writer and physical printer if use the API DrawString. On the other hand, if we use the API DrawDriverString, the character "𣱿"will not show correctly, at the same time, the result by virtual printer and physical will be more strange(the last character "3"can not be print out, print out show a strange character).

I wonder if the DrawDriverString supported drawing characters outside the BMP(Basic Multilingual Plane) for printing, such as above [𣱿] a 4-byte character.



Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>