Haru Free PDF Library
grid_sheet.c
/*
* << Haru Free PDF Library 2.0.0 >> -- grid_sheet.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 "utils.h"
void
print_grid (HPDF_Doc pdf,
HPDF_Page page)
{
HPDF_REAL height = HPDF_Page_GetHeight (page);
HPDF_REAL width = HPDF_Page_GetWidth (page);
HPDF_Font font = HPDF_GetFont (pdf, "Helvetica", NULL);
HPDF_UINT x, y;
HPDF_Page_SetFontAndSize (page, font, 5);
HPDF_Page_SetGrayFill (page, 0.5);
/* Draw horizontal lines */
y = 0;
while (y < height) {
if (y % 10 == 0)
else {
if (HPDF_Page_GetLineWidth (page) != 0.25)
HPDF_Page_SetLineWidth (page, 0.25);
}
HPDF_Page_MoveTo (page, 0, y);
HPDF_Page_LineTo (page, width, y);
if (y % 10 == 0 && y > 0) {
HPDF_Page_MoveTo (page, 0, y);
HPDF_Page_LineTo (page, 5, y);
}
y += 5;
}
/* Draw vertical lines */
x = 0;
while (x < width) {
if (x % 10 == 0)
else {
if (HPDF_Page_GetLineWidth (page) != 0.25)
HPDF_Page_SetLineWidth (page, 0.25);
}
HPDF_Page_MoveTo (page, x, 0);
HPDF_Page_LineTo (page, x, height);
if (x % 50 == 0 && x > 0) {
HPDF_Page_MoveTo (page, x, 0);
HPDF_Page_LineTo (page, x, 5);
HPDF_Page_MoveTo (page, x, height);
HPDF_Page_LineTo (page, x, height - 5);
}
x += 5;
}
/* Draw horizontal text */
y = 0;
while (y < height) {
if (y % 10 == 0 && y > 0) {
char buf[12];
HPDF_Page_MoveTextPos (page, 5, y - 2);
HPDF_snprintf (buf, 12, "%u", y);
HPDF_Page_ShowText (page, buf);
}
y += 5;
}
/* Draw vertical text */
x = 0;
while (x < width) {
if (x % 50 == 0 && x > 0) {
char buf[12];
HPDF_Page_MoveTextPos (page, x, 5);
HPDF_snprintf (buf, 12, "%u", x);
HPDF_Page_ShowText (page, buf);
HPDF_Page_MoveTextPos (page, x, height - 10);
HPDF_Page_ShowText (page, buf);
}
x += 5;
}
}
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_MoveTo(HPDF_Page page, HPDF_REAL x, HPDF_REAL y)
Start new subpath and move current point for drawing path.
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_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_ShowText(HPDF_Page page, const char *text)
Put text at the current text position on the page.
HPDF_STATUS HPDF_Page_SetGrayStroke(HPDF_Page page, HPDF_REAL value)
Set stroking color (Gray).
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_GetHeight(HPDF_Page page)
Get page height.
HPDF_REAL HPDF_Page_GetWidth(HPDF_Page page)
Get page width.
HPDF_REAL HPDF_Page_GetLineWidth(HPDF_Page page)
Get page current line 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