Haru Free PDF Library
arc_demo.c
Arc demo

This demo show HPDF_Page_Arc() and HPDF_Page_Circle() functions usage.

Pie chart is created using filled circle segments and central circle.

/*
* << Haru Free PDF Library 2.0.0 >> -- arc_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"
int
main (int argc, char **argv)
{
HPDF_Doc pdf;
HPDF_Page page;
char fname[256];
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);
HPDF_Page_SetHeight (page, 220);
HPDF_Page_SetWidth (page, 200);
/* draw grid to the page */
print_grid (pdf, page);
/* draw pie chart
*
* A: 45% Red
* B: 25% Blue
* C: 15% green
* D: other yellow
*/
/* A */
HPDF_Page_SetRGBFill (page, 1.0, 0, 0);
HPDF_Page_MoveTo (page, 100, 100);
HPDF_Page_LineTo (page, 100, 180);
HPDF_Page_Arc (page, 100, 100, 80, 0, 360 * 0.45);
HPDF_Page_LineTo (page, 100, 100);
/* B */
HPDF_Page_SetRGBFill (page, 0, 0, 1.0);
HPDF_Page_MoveTo (page, 100, 100);
HPDF_Page_LineTo (page, pos.x, pos.y);
HPDF_Page_Arc (page, 100, 100, 80, 360 * 0.45, 360 * 0.7);
HPDF_Page_LineTo (page, 100, 100);
/* C */
HPDF_Page_SetRGBFill (page, 0, 1.0, 0);
HPDF_Page_MoveTo (page, 100, 100);
HPDF_Page_LineTo (page, pos.x, pos.y);
HPDF_Page_Arc (page, 100, 100, 80, 360 * 0.7, 360 * 0.85);
HPDF_Page_LineTo (page, 100, 100);
/* D */
HPDF_Page_SetRGBFill (page, 1.0, 1.0, 0);
HPDF_Page_MoveTo (page, 100, 100);
HPDF_Page_LineTo (page, pos.x, pos.y);
HPDF_Page_Arc (page, 100, 100, 80, 360 * 0.85, 360);
HPDF_Page_LineTo (page, 100, 100);
/* draw center circle */
HPDF_Page_Circle (page, 100, 100, 30);
/* save the document to a file */
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_STATUS HPDF_Page_MoveTo(HPDF_Page page, HPDF_REAL x, HPDF_REAL y)
Start new subpath and move current point for drawing path.
HPDF_STATUS HPDF_Page_SetRGBFill(HPDF_Page page, HPDF_REAL r, HPDF_REAL g, HPDF_REAL b)
Set filling color (RGB).
HPDF_STATUS HPDF_Page_Arc(HPDF_Page page, HPDF_REAL x, HPDF_REAL y, HPDF_REAL radius, HPDF_REAL ang1, HPDF_REAL ang2)
Append circle arc to current path.
HPDF_STATUS HPDF_Page_Fill(HPDF_Page page)
Fill current path using non-zero winding number rule.
HPDF_STATUS HPDF_Page_Circle(HPDF_Page page, HPDF_REAL x, HPDF_REAL y, HPDF_REAL radius)
Append circle to current path.
HPDF_STATUS HPDF_Page_SetGrayFill(HPDF_Page page, HPDF_REAL value)
Set the filling color (Gray).
HPDF_STATUS HPDF_Page_LineTo(HPDF_Page page, HPDF_REAL x, HPDF_REAL y)
Append path from current point to specified point.
HPDF_STATUS HPDF_Page_SetGrayStroke(HPDF_Page page, HPDF_REAL value)
Set stroking color (Gray).
HPDF_Point HPDF_Page_GetCurrentPos(HPDF_Page page)
Get current position for path painting.
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.
Definition: hpdf_objects.h:421
Definition: hpdf_doc.h:36
Definition: hpdf_types.h:105
HPDF_REAL y
Definition: hpdf_types.h:107
HPDF_REAL x
Definition: hpdf_types.h:106