Haru Free PDF Library
font_demo.c
/*
* << Haru Free PDF Library 2.0.0 >> -- font_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 "handler.h"
const char *font_list[] = {
"Courier",
"Courier-Bold",
"Courier-Oblique",
"Courier-BoldOblique",
"Helvetica",
"Helvetica-Bold",
"Helvetica-Oblique",
"Helvetica-BoldOblique",
"Times-Roman",
"Times-Bold",
"Times-Italic",
"Times-BoldItalic",
"Symbol",
"ZapfDingbats",
NULL
};
int main (int argc, char **argv)
{
const char *page_title = "Font Demo";
HPDF_Doc pdf;
char fname[256];
HPDF_Page page;
HPDF_Font def_font;
HPDF_REAL height;
HPDF_REAL width;
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;
}
/* Add a new page object. */
page = HPDF_AddPage (pdf);
height = HPDF_Page_GetHeight (page);
width = HPDF_Page_GetWidth (page);
/* Print the lines of the page. */
HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110);
/* Print the title of the page (with positioning center). */
def_font = HPDF_GetFont (pdf, "Helvetica", NULL);
HPDF_Page_SetFontAndSize (page, def_font, 24);
tw = HPDF_Page_TextWidth (page, page_title);
HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title);
/* output subtitle. */
HPDF_Page_SetFontAndSize (page, def_font, 16);
HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>");
HPDF_Page_MoveTextPos (page, 60, height - 105);
i = 0;
while (font_list[i]) {
const char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
HPDF_Font font = HPDF_GetFont (pdf, font_list[i], NULL);
/* print a label of text */
HPDF_Page_SetFontAndSize (page, def_font, 9);
HPDF_Page_ShowText (page, font_list[i]);
HPDF_Page_MoveTextPos (page, 0, -18);
/* print a sample text. */
HPDF_Page_SetFontAndSize (page, font, 20);
HPDF_Page_ShowText (page, samp_text);
HPDF_Page_MoveTextPos (page, 0, -20);
i++;
}
HPDF_SaveToFile (pdf, fname);
/* clean up */
HPDF_Free (pdf);
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_Font HPDF_GetFont(HPDF_Doc pdf, const char *font_name, const char *encoding_name)
Get requested font object handle.
HPDF_STATUS HPDF_Page_SetLineWidth(HPDF_Page page, HPDF_REAL line_width)
Set width of the line used to stroke paths.
HPDF_STATUS HPDF_Page_Stroke(HPDF_Page page)
Paint current path.
HPDF_STATUS HPDF_Page_TextOut(HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, const char *text)
Put text to the specified position.
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_Rectangle(HPDF_Page page, HPDF_REAL x, HPDF_REAL y, HPDF_REAL width, HPDF_REAL height)
Append rectangle to the current path.
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_EndText(HPDF_Page page)
Finish text object.
HPDF_STATUS HPDF_Page_MoveTextPos(HPDF_Page page, HPDF_REAL x, HPDF_REAL y)
Change current text position using the specified offset values.
HPDF_REAL HPDF_Page_TextWidth(HPDF_Page page, const char *text)
Get text width in current font size, character spacing and word spacing.
HPDF_REAL HPDF_Page_GetHeight(HPDF_Page page)
Get page height.
HPDF_Page HPDF_AddPage(HPDF_Doc pdf)
Create new page and add it after the last page of document.
HPDF_REAL HPDF_Page_GetWidth(HPDF_Page page)
Get page width.
unsigned int HPDF_UINT
Definition: hpdf_types.h:45
float HPDF_REAL
Definition: hpdf_types.h:79
Definition: hpdf_objects.h:421
Definition: hpdf_doc.h:36