wafuの技術

技術習得の努力メモです。

C++でlibharu UTF-8とか

UTF-8での作成に成功しましたが、難しいですね。

 

Ruby+Prawnならもっと簡単にできるのですが  

■フォントとUTF-8の指定です。

 wcscat(FontPath,L"\\Fonts\\ARIALUNI.ttf");
 HPDF_UseUTFEncodings(pdf);
 const char *fontname;
 fontname = HPDF_LoadTTFontFromFile(pdf, FontPath, HPDF_TRUE);
 font = HPDF_GetFont(pdf, fontname, "UTF-8");
 HPDF_SetCurrentEncoder(pdf, "UTF-8");

■テキストの出力

wchar_t wtext[] = L"テキストです。";
char text[2048];
WideCharToMultiByte(CP_UTF8,NULL,wtext,-1,text,2048,NULL,NULL);
HPDF_Page_TextRect (page, 50, 800, 580, 770,text, HPDF_TALIGN_CENTER, NULL);

HPDF_Page_EndText (page);

 

■文字サイズの指定

HPDF_Page_SetFontAndSize (page, font, 10);