libharu — кириллица не отображается вменяемо
Ну собственно. Выводится вот так —›Ñ‚—¾ Ñ—¿—‚Ñ—¾—” —‡—¾Ñ€Ñˆ—”—¾—†.
Код:
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include "hpdf.h"
jmp_buf env;
#ifdef HPDF_DLL
void __stdcall
#else
void
#endif
error_handler (HPDF_STATUS error_no,
HPDF_STATUS detail_no,
void *user_data)
{
printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
(HPDF_UINT)detail_no);
longjmp(env, 1);
}
int main (int argc, char **argv)
{
const char *page_title = "LINNAEUS 0.0.1";
HPDF_Doc pdf;
char fname[256];
HPDF_Page page;
HPDF_Font def_font;
HPDF_REAL height;
HPDF_REAL width;
const char *detail_font_name;
HPDF_REAL tw;
strcpy (fname, "plants");
strcat (fname, ".pdf");
pdf = HPDF_New (error_handler, NULL);
detail_font_name = HPDF_LoadTTFontFromFile (pdf, "Courier.ttf", HPDF_FALSE);
if (!pdf) {
printf ("error: cannot create PdfDoc object\n");
return 1;
}
if (setjmp(env)) {
HPDF_Free (pdf);
return 1;
}
/* Add a new page object. */
page = HPDF_AddPage (pdf);
height = HPDF_Page_GetHeight (page);
width = HPDF_Page_GetWidth (page);
/* Print the title of the page (with positioning center). */
def_font = HPDF_GetFont (pdf, detail_font_name, NULL);
HPDF_Page_SetFontAndSize (page, def_font, 12);
tw = HPDF_Page_TextWidth (page, page_title);
HPDF_Page_BeginText (page);
HPDF_Page_TextOut (page, (width - tw) / 50, height - 20, page_title);
HPDF_Page_EndText (page);
/* output subtitle. */
HPDF_Page_BeginText (page);
HPDF_Page_SetFontAndSize (page, def_font, 12);
HPDF_Page_TextOut (page, 10, height - 40, "16.12.1983");
HPDF_Page_EndText (page);
HPDF_Page_BeginText (page);
HPDF_Page_MoveTextPos (page, 10, height - 105);
const char* samp_text = "Это список горшков";
/* print a label of text */
HPDF_Page_SetFontAndSize (page, def_font, 12);
HPDF_Page_MoveTextPos (page, 0, -18);
/* print a sample text. */
HPDF_Page_ShowText (page, samp_text);
HPDF_Page_ShowText (page, HPDF_Font_GetEncodingName (detail_font));
HPDF_Page_MoveTextPos (page, 0, -20);
HPDF_Page_EndText (page);
HPDF_SaveToFile (pdf, fname);
/* clean up */
HPDF_Free (pdf);
return 0;
}