Haru Free PDF Library
chfont_demo.c
/*
* << Haru Free PDF Library 2.0.0 >> -- chfont_demo.c
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include "hpdf.h"
#include "grid_sheet.h"
#include "handler.h"
#include "utils.h"
int
main (int argc, char **argv)
{
HPDF_Doc pdf;
HPDF_Page page;
char fname[256];
char buf[1024];
FILE *cp932;
FILE *cp936;
const char *fcp936_name;
const char *fcp932_name;
HPDF_Font fcp936;
HPDF_Font fcp932;
if (argc < 4) {
printf ("chfont_demo <cp936-ttc-font-file-name> "
"<cp936-index> <cp932-ttc-font-file-name> <cp932-index>\n");
return 1;
}
strcpy (fname, "mbtext");
strcat (fname, FILE_SEPARATOR);
strcat (fname, "cp932.txt");
cp932 = fopen (fname, "rb");
if (!cp932) {
printf ("error: cannot open cp932.txt\n");
return 1;
}
strcpy (fname, "mbtext");
strcat (fname, FILE_SEPARATOR);
strcat (fname, "cp936.txt");
cp936 = fopen (fname, "rb");
if (!cp936) {
printf ("error: cannot open cp936.txt\n");
return 1;
}
strcpy (fname, argv[0]);
strcat (fname, ".pdf");
pdf = HPDF_New (demo_error_handler, NULL);
if (!pdf) {
printf ("error: cannot create PdfDoc object\n");
return 1;
}
if (setjmp(env)) {
HPDF_Free (pdf);
return 1;
}
fcp936_name = HPDF_LoadTTFontFromFile2 (pdf, argv[1], atoi(argv[2]),
fcp932_name = HPDF_LoadTTFontFromFile2 (pdf, argv[3], atoi(argv[4]),
/* add a new page object. */
page = HPDF_AddPage (pdf);
HPDF_Page_SetHeight (page, 300);
HPDF_Page_SetWidth (page, 550);
fcp936 = HPDF_GetFont (pdf, fcp936_name, "GBK-EUC-H");
fcp932 = HPDF_GetFont (pdf, fcp932_name, "90ms-RKSJ-H");
print_grid (pdf, page);
HPDF_Page_MoveTextPos (page, 50, 250);
while (fgets (buf, 1024, cp936)) {
HPDF_Page_SetFontAndSize (page, fcp936, 18);
buf [strlen (buf)] = 0;
HPDF_Page_ShowText (page, buf);
if (fgets (buf, 1024, cp932)) {
HPDF_Page_SetFontAndSize (page, fcp932, 18);
buf [strlen (buf)] = 0;
HPDF_Page_ShowText (page, buf);
}
}
/* save the document to a file */
HPDF_SaveToFile (pdf, fname);
/* clean up */
HPDF_Free (pdf);
fclose (cp936);
fclose (cp932);
return 0;
}
HPDF_STATUS HPDF_SaveToFile(HPDF_Doc pdf, const char *filename)
Saves the current document to file.
void HPDF_Free(HPDF_Doc pdf)
Revoke a document object and all resources.
HPDF_Doc HPDF_New(HPDF_Error_Handler user_error_fn, void *user_data)
Create an instance of a document object and initialize it.
HPDF_STATUS HPDF_UseCNSEncodings(HPDF_Doc pdf)
Enable simplified Chinese encodings.
HPDF_STATUS HPDF_UseJPEncodings(HPDF_Doc pdf)
Enable Japanese encodings.
HPDF_Font HPDF_GetFont(HPDF_Doc pdf, const char *font_name, const char *encoding_name)
Get requested font object handle.
const char * HPDF_LoadTTFontFromFile2(HPDF_Doc pdf, const char *filename, HPDF_UINT index, HPDF_BOOL embedding)
Load TrueType font from TrueType collection file *.ttc and register it in the document object.
HPDF_STATUS HPDF_Page_SetTextLeading(HPDF_Page page, HPDF_REAL value)
Set text leading (line spacing).
HPDF_STATUS HPDF_Page_SetFontAndSize(HPDF_Page page, HPDF_Font font, HPDF_REAL size)
Set the type of font and size leading.
HPDF_STATUS HPDF_Page_MoveToNextLine(HPDF_Page page)
Move current position for text showing depending on current text showing point and text leading.
HPDF_STATUS HPDF_Page_ShowText(HPDF_Page page, const char *text)
Put text at the current text position on the page.
HPDF_STATUS HPDF_Page_BeginText(HPDF_Page page)
Begin text object and set text position to (0, 0).
HPDF_STATUS HPDF_Page_MoveTextPos(HPDF_Page page, HPDF_REAL x, HPDF_REAL y)
Change current text position using the specified offset values.
HPDF_Page HPDF_AddPage(HPDF_Doc pdf)
Create new page and add it after the last page of document.
HPDF_STATUS HPDF_Page_SetWidth(HPDF_Page page, HPDF_REAL value)
Change page width.
HPDF_STATUS HPDF_Page_SetHeight(HPDF_Page page, HPDF_REAL value)
Change page height.
HPDF_STATUS HPDF_SetCompressionMode(HPDF_Doc pdf, HPDF_UINT mode)
Set compression mode.
#define HPDF_COMP_ALL
Definition: hpdf_consts.h:82
#define HPDF_TRUE
Definition: hpdf_consts.h:26
Definition: hpdf_objects.h:421
Definition: hpdf_doc.h:36