# # This has been ported by Hiroshi Saito(hiroshi@winpg.jp) # Copyright notice of the original as below. # # # * # * << Haru Free PDF Library 2.0.0 >> -- text_demo2.c # * # * Copyright(c) 1999-2006 Takeshi Kanno # * # * 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. # * # @load "pdf" # ---- # function # ---- function tan(x) { return sin(x)/cos(x); } function PrintText(page) { pos = HPDF_Page_GetCurrentTextPos(page); split(pos, posX,","); no++; buf = sprintf(".[%d]%0.2f %0.2f", no, posX[1], posX[2]); HPDF_Page_ShowText(page, buf); } # ---- # main # ---- BEGIN { SAMP_TXT = "The quick brown fox jumps over the lazy dog. "; fname = "pdf_text.pdf"; pdf = HPDF_New(NULL, NULL); # add a new page object. page = HPDF_AddPage(pdf); HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A5, HPDF_PAGE_PORTRAIT); page_height = HPDF_Page_GetHeight(page); font = HPDF_GetFont(pdf, "Helvetica", NULL); HPDF_Page_SetTextLeading(page, 20); # text_rect method # HPDF_TALIGN_LEFT left = 25; top = 545; right = 200; bottom = top - 40; HPDF_Page_Rectangle(page, left, bottom, right - left, top - bottom); HPDF_Page_Stroke(page); HPDF_Page_BeginText(page); HPDF_Page_SetFontAndSize(page, font, 10); HPDF_Page_TextOut(page, left, top + 3, "HPDF_TALIGN_LEFT"); HPDF_Page_SetFontAndSize(page, font, 13); HPDF_Page_TextRect(page, left, top, right, bottom, SAMP_TXT, HPDF_TALIGN_LEFT, NULL); HPDF_Page_EndText(page); # HPDF_TALIGN_RIGTH left = 220; right = 395; HPDF_Page_Rectangle(page, left, bottom, right - left, top - bottom); HPDF_Page_Stroke(page); HPDF_Page_BeginText(page); HPDF_Page_SetFontAndSize(page, font, 10); HPDF_Page_TextOut(page, left, top + 3, "HPDF_TALIGN_RIGTH"); HPDF_Page_SetFontAndSize(page, font, 13); HPDF_Page_TextRect(page, left, top, right, bottom, SAMP_TXT, HPDF_TALIGN_RIGHT, NULL); HPDF_Page_EndText(page); # HPDF_TALIGN_CENTER left = 25; top = 475; right = 200; bottom = top - 40; HPDF_Page_Rectangle(page, left, bottom, right - left, top - bottom); HPDF_Page_Stroke(page); HPDF_Page_BeginText(page); HPDF_Page_SetFontAndSize(page, font, 10); HPDF_Page_TextOut(page, left, top + 3, "HPDF_TALIGN_CENTER"); HPDF_Page_SetFontAndSize(page, font, 13); HPDF_Page_TextRect(page, left, top, right, bottom, SAMP_TXT, HPDF_TALIGN_CENTER, NULL); HPDF_Page_EndText(page); # HPDF_TALIGN_JUSTIFY left = 220; right = 395; HPDF_Page_Rectangle(page, left, bottom, right - left, top - bottom); HPDF_Page_Stroke(page); HPDF_Page_BeginText(page); HPDF_Page_SetFontAndSize(page, font, 10); HPDF_Page_TextOut(page, left, top + 3, "HPDF_TALIGN_JUSTIFY"); HPDF_Page_SetFontAndSize(page, font, 13); HPDF_Page_TextRect(page, left, top, right, bottom, SAMP_TXT, HPDF_TALIGN_JUSTIFY, NULL); HPDF_Page_EndText(page); # Skewed coordinate system HPDF_Page_GSave(page); angle1 = 5; angle2 = 10; rad1 = angle1 / 180 * 3.141592; rad2 = angle2 / 180 * 3.141592; HPDF_Page_Concat(page, 1, tan(rad1), tan(rad2), 1, 25, 350); left = 0; top = 40; right = 175; bottom = 0; HPDF_Page_Rectangle(page, left, bottom, right - left, top - bottom); HPDF_Page_Stroke(page); HPDF_Page_BeginText(page); HPDF_Page_SetFontAndSize(page, font, 10); HPDF_Page_TextOut(page, left, top + 3, "Skewed coordinate system"); HPDF_Page_SetFontAndSize(page, font, 13); HPDF_Page_TextRect(page, left, top, right, bottom, SAMP_TXT, HPDF_TALIGN_LEFT, NULL); HPDF_Page_EndText(page); HPDF_Page_GRestore(page); # Rotated coordinate system HPDF_Page_GSave(page); angle1 = 5; rad1 = angle1 / 180 * 3.141592; HPDF_Page_Concat(page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), 220, 350); left = 0; top = 40; right = 175; bottom = 0; HPDF_Page_Rectangle(page, left, bottom, right - left, top - bottom); HPDF_Page_Stroke(page); HPDF_Page_BeginText(page); HPDF_Page_SetFontAndSize(page, font, 10); HPDF_Page_TextOut(page, left, top + 3, "Rotated coordinate system"); HPDF_Page_SetFontAndSize(page, font, 13); HPDF_Page_TextRect(page, left, top, right, bottom, SAMP_TXT, HPDF_TALIGN_LEFT, NULL); HPDF_Page_EndText(page); HPDF_Page_GRestore(page); # text along a circle HPDF_Page_SetGrayStroke(page, 0); HPDF_Page_Circle(page, 210, 190, 145); HPDF_Page_Circle(page, 210, 190, 113); HPDF_Page_Stroke(page); angle1 = 360 /(length(SAMP_TXT)); angle2 = 180; HPDF_Page_BeginText(page); font = HPDF_GetFont(pdf, "Courier-Bold", NULL); HPDF_Page_SetFontAndSize(page, font, 30); split(SAMP_TXT , SP_SAMP_TXT, ""); for(i = 0; i < length(SAMP_TXT); i++) { rad1 =(angle2 - 90) / 180 * 3.141592; rad2 = angle2 / 180 * 3.141592; x = 210 + cos(rad2) * 122; y = 190 + sin(rad2) * 122; HPDF_Page_SetTextMatrix(page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), x, y); buf = SP_SAMP_TXT[i]; HPDF_Page_ShowText(page, buf); angle2 -= angle1; } HPDF_Page_EndText(page); # save the document to a file HPDF_SaveToFile(pdf, fname); # clean up HPDF_Free(pdf); }