/** * Checks if given line width is already set in PDF gstate and if not, update * the gstate accordingly. * \param page PDF page where the update needs to happen. * \param lineWidth Wanted line width. */ void pdfw_gs_linewidth(HPDF_Page page, float lineWidth) { if (lineWidth == pdfw_gs[pdfw_gs_level].lineWidth) return; pdfw_gs[pdfw_gs_level].lineWidth = lineWidth; HPDF_Page_SetLineWidth(page, lineWidth); }
void PDFGenerator::pdfDoc_AddPage(mlPDF::PAGE_SIZES pageSize, mlPDF::PAGE_DIRECTIONS pageDirection) { if (pdfDocument) { HPDF_Page newPage = HPDF_AddPage(pdfDocument); if (newPage) { pdfDocCurrentPage = newPage; pdfDocPages.push_back(newPage); if (pageSize == mlPDF::PAGESIZE_USER) // It is illegal to set this value manually... { pageSize = mlPDF::PAGESIZE_A4; // ... therefore set it to default value. } HPDF_Page_SetSize(newPage, (HPDF_PageSizes)pageSize, (HPDF_PageDirection)pageDirection); _currentPageSize = pageSize; HPDF_Page_SetFontAndSize(pdfDocCurrentPage, _currentFontSettings.font, _currentFontSettings.fontSize); HPDF_Page_SetLineWidth(pdfDocCurrentPage, 1); pdfDoc_SetStrokeColor(0, 0, 0); pdfDoc_SetFillColor(0, 0, 0); pdfDoc_CurrentXPos = 0; pdfDoc_CurrentYPos = 0; } else { _handleError("pdfDoc_AddPage(mlPDF::PAGE_SIZES pageSize, mlPDF::PAGE_DIRECTIONS pageDirection)"); } } }
/* * Class: org_libharu_PdfPage * Method: setLineWidth * Signature: (F)V */ JNIEXPORT void JNICALL Java_org_libharu_PdfPage_setLineWidth(JNIEnv *env, jobject obj, jfloat lineWidth) { jint page; /* Get mHPDFPagePointer */ page = (*env)->GetIntField(env, obj, mHPDFPagePointer); HPDF_Page_SetLineWidth((HPDF_Page) page, (HPDF_REAL) lineWidth); }
void PDFGenerator::pdfDoc_AddPage(float width, float height) { if (pdfDocument) { HPDF_Page newPage = HPDF_AddPage(pdfDocument); if (newPage) { pdfDocCurrentPage = newPage; pdfDocPages.push_back(newPage); HPDF_Page_SetWidth(newPage, width); HPDF_Page_SetHeight(newPage, height); _currentPageSize = mlPDF::PAGESIZE_USER; HPDF_Page_SetFontAndSize(pdfDocCurrentPage, _currentFontSettings.font, _currentFontSettings.fontSize); HPDF_Page_SetLineWidth(pdfDocCurrentPage, 1); pdfDoc_SetStrokeColor(0, 0, 0); pdfDoc_SetFillColor(0, 0, 0); pdfDoc_CurrentXPos = 0; pdfDoc_CurrentYPos = 0; } else { _handleError("pdfDoc_AddPage(float width, float height)"); } } }
JNIEXPORT void JNICALL Java_org_libharu_Page_setLineWidth (JNIEnv *env, jobject obj, jfloat width) { haru_setup_error_handler(env, __func__); HPDF_Page page = get_HPDF_Page(env, obj); HPDF_Page_SetLineWidth(page, width); haru_clear_error_handler(); }
void show_stripe_pattern (HPDF_Page page, HPDF_REAL x, HPDF_REAL y) { HPDF_UINT iy = 0; while (iy < 50) { HPDF_Page_SetRGBStroke (page, 0.0, 0.0, 0.5); HPDF_Page_SetLineWidth (page, 1); HPDF_Page_MoveTo (page, x, y + iy); HPDF_Page_LineTo (page, x + HPDF_Page_TextWidth (page, "ABCabc123"), y + iy); HPDF_Page_Stroke (page); iy += 3; } HPDF_Page_SetLineWidth (page, 2.5); }
void draw_graph (HPDF_Page page) { char buf[50]; int i; /* Draw 16 X 15 cells */ /* Draw vertical lines. */ HPDF_Page_SetLineWidth (page, 0.5); for (i = 0; i <= 17; i++) { int x = i * CELL_WIDTH + 40; HPDF_Page_MoveTo (page, x, PAGE_HEIGHT - 60); HPDF_Page_LineTo (page, x, 40); HPDF_Page_Stroke (page); if (i > 0 && i <= 16) { HPDF_Page_BeginText (page); HPDF_Page_MoveTextPos (page, x + 5, PAGE_HEIGHT - 75); #ifdef __WIN32__ _snprintf(buf, 5, "%X", i - 1); #else snprintf(buf, 5, "%X", i - 1); #endif HPDF_Page_ShowText (page, buf); HPDF_Page_EndText (page); } } /* Draw horizontal lines. */ for (i = 0; i <= 15; i++) { int y = i * CELL_HEIGHT + 40; HPDF_Page_MoveTo (page, 40, y); HPDF_Page_LineTo (page, PAGE_WIDTH - 40, y); HPDF_Page_Stroke (page); if (i < 14) { HPDF_Page_BeginText (page); HPDF_Page_MoveTextPos (page, 45, y + 5); #ifdef __WIN32__ _snprintf(buf, 5, "%X", 15 - i); #else snprintf(buf, 5, "%X", 15 - i); #endif HPDF_Page_ShowText (page, buf); HPDF_Page_EndText (page); } } }
int CHaruPdf::setLineWidth( int w ) {_STT(); // Sanity checks if ( !m_page ) return 0; // Set line width if ( HPDF_OK != HPDF_Page_SetLineWidth( m_page, w ) ) return 0; return 1; }
void draw_circles (HPDF_Page page, const char *description, HPDF_REAL x, HPDF_REAL y) { HPDF_Page_SetLineWidth (page, 1.0f); HPDF_Page_SetRGBStroke (page, 0.0f, 0.0f, 0.0f); HPDF_Page_SetRGBFill (page, 1.0f, 0.0f, 0.0f); HPDF_Page_Circle (page, x + 40, y + 40, 40); HPDF_Page_ClosePathFillStroke (page); HPDF_Page_SetRGBFill (page, 0.0f, 1.0f, 0.0f); HPDF_Page_Circle (page, x + 100, y + 40, 40); HPDF_Page_ClosePathFillStroke (page); HPDF_Page_SetRGBFill (page, 0.0f, 0.0f, 1.0f); HPDF_Page_Circle (page, x + 70, y + 74.64, 40); HPDF_Page_ClosePathFillStroke (page); HPDF_Page_SetRGBFill (page, 0.0f, 0.0f, 0.0f); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, x + 0.0f, y + 130.0f, description); HPDF_Page_EndText (page); }
int fileWriter(HPDF_Doc pdf, HPDF_Outline root, HPDF_Font font, const std::string curFile, const std::vector< std::string> vec) { auto func_footbar = [](std::string fileName)->std::string { std::ostringstream buffer; buffer << " File:" << fileName.c_str() << " Autor:XCL "; return buffer.str(); }; auto func_pageOutline = [&](HPDF_Page page, std::string curFile) { HPDF_Outline outline; HPDF_Destination dst; outline = HPDF_CreateOutline(pdf, root, curFile.c_str(), NULL); dst = HPDF_Page_CreateDestination(page); HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1);// 1 = 默认百分比100 HPDF_Outline_SetDestination(outline, dst); }; auto func_drawRow = [](HPDF_Page page,std::string rid,std::string row,int y ) { HPDF_Page_BeginText(page); HPDF_Page_MoveTextPos(page, config::ROWID_WIDTH, y - 2); HPDF_Page_ShowText(page, rid.c_str()); HPDF_Page_ShowText(page, row.c_str()); HPDF_Page_EndText(page); }; HPDF_Page page = nullptr; HPDF_REAL width,height; HPDF_UINT y = 0; // x =0, int currID = 0, pageID = 0, currRowCount; std::string ss, rid; for (int i = 0; i < vec.size(); i++) { if (i == 0 || currRowCount > config::PAGE_ROWNUM) { ////////////////////////////////////////////// page = HPDF_AddPage(pdf); width = HPDF_Page_GetWidth(page); height = HPDF_Page_GetHeight(page); // x = 0; y = height - config::ROW_HEIGHT; func_pageOutline(page, curFile); HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT); { HPDF_RGBColor c = HPDF_Page_GetRGBFill(page); HPDF_Page_SetRGBStroke(page, 0.0, 0.5, 0); HPDF_Page_SetFontAndSize(page, font, config::FOOTBAR_FONT_SIZE); HPDF_Page_SetLineWidth(page, 0.5); HPDF_Page_MoveTo(page, 0, 13); HPDF_Page_LineTo(page, width, 16); HPDF_Page_Stroke(page); HPDF_Page_SetRGBFill(page, 0.0, 0, 0.5); HPDF_Page_BeginText(page); HPDF_Page_MoveTextPos(page, 40, config::FOOTBAR_FONT_SIZE - 5); HPDF_Page_ShowText(page, func_footbar(curFile).c_str()); HPDF_Page_EndText(page); HPDF_Page_SetRGBFill(page, c.r, c.g, c.b); }; y = height - config::ROW_HEIGHT * 2; HPDF_Page_SetFontAndSize(page, font, config::PAGE_FONT_SIZE); pageID++; currRowCount = 1; ////////////////////////////////////////////// } /////////////////////////////////////////// ss = vec[i]; HPDF_REAL wrid = HPDF_Page_TextWidth(page, rid.c_str()); NEWROW: HPDF_REAL wss = HPDF_Page_TextWidth(page, ss.c_str()); rid = util::rowidWidth(currRowCount ); if (wrid + wss > width) { //简单处理:超过页宽,直接分成两行.足以应付大部份情况. int center = ss.length() / 2; func_drawRow(page, rid,ss.substr(0, center),y); y -= config::ROW_HEIGHT; currRowCount++; ss = ss.substr(center); goto NEWROW; } else { func_drawRow(page, rid, ss,y); y -= config::ROW_HEIGHT; currRowCount++; } ////////////////////////////////////////// } return 0; } //end func
void WPdfImage::setChanged(WFlags<PainterChangeFlag> flags) { if (!flags.empty()) { HPDF_Page_GRestore(page_); HPDF_Page_GSave(page_); HPDF_ExtGState gstate; gstate = HPDF_CreateExtGState (pdf_); currentFont_ = WFont(); if (painter()->hasClipping()) { const WTransform& t = painter()->clipPathTransform(); if (!painter()->clipPath().isEmpty()) { applyTransform(t); drawPlainPath(painter()->clipPath()); HPDF_Page_Clip(page_); HPDF_Page_EndPath(page_); applyTransform(t.inverted()); } } applyTransform(painter()->combinedTransform()); const WPen& pen = painter()->pen(); if (pen.style() != PenStyle::None) { const WColor& color = pen.color(); HPDF_Page_SetRGBStroke(page_, color.red() / 255., color.green() / 255., color.blue() / 255.); HPDF_ExtGState_SetAlphaStroke (gstate, color.alpha()/255.); WLength w = painter()->normalizedPenWidth(pen.width(), false); HPDF_Page_SetLineWidth(page_, w.toPixels()); switch (pen.capStyle()) { case PenCapStyle::Flat: HPDF_Page_SetLineCap(page_, HPDF_BUTT_END); break; case PenCapStyle::Square: HPDF_Page_SetLineCap(page_, HPDF_PROJECTING_SCUARE_END); // scuary ! break; case PenCapStyle::Round: HPDF_Page_SetLineCap(page_, HPDF_ROUND_END); break; } switch (pen.joinStyle()) { case PenJoinStyle::Miter: HPDF_Page_SetLineJoin(page_, HPDF_MITER_JOIN); break; case PenJoinStyle::Bevel: HPDF_Page_SetLineJoin(page_, HPDF_BEVEL_JOIN); break; case PenJoinStyle::Round: HPDF_Page_SetLineJoin(page_, HPDF_ROUND_JOIN); break; } switch (pen.style()) { case PenStyle::None: break; case PenStyle::SolidLine: HPDF_Page_SetDash(page_, nullptr, 0, 0); break; case PenStyle::DashLine: { const HPDF_UINT16 dash_ptn[] = { 4, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 2, 0); break; } case PenStyle::DotLine: { const HPDF_UINT16 dash_ptn[] = { 1, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 2, 0); break; } case PenStyle::DashDotLine: { const HPDF_UINT16 dash_ptn[] = { 4, 2, 1, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 4, 0); break; } case PenStyle::DashDotDotLine: { const HPDF_UINT16 dash_ptn[] = { 4, 2, 1, 2, 1, 2 }; HPDF_Page_SetDash(page_, dash_ptn, 6, 0); break; } } } const WBrush& brush = painter()->brush(); if (brush.style() != BrushStyle::None) { const WColor& color = painter()->brush().color(); HPDF_Page_SetRGBFill(page_, color.red() / 255., color.green() / 255., color.blue() / 255.); HPDF_ExtGState_SetAlphaFill (gstate, color.alpha()/255.); } HPDF_Page_SetExtGState (page_, gstate); const WFont& font = painter()->font(); if (font == currentFont_ && !trueTypeFonts_->busy()) return; /* * First, try a true type font. */ std::string ttfFont; if (trueTypeFonts_->busy()) { /* * We have a resolved true type font. */ ttfFont = trueTypeFonts_->drawingFontPath(); } else { FontSupport::FontMatch match = trueTypeFonts_->matchFont(font); if (match.matched()) ttfFont = match.fileName(); } LOG_DEBUG("font: " << ttfFont); if (font == currentFont_ && !ttfFont.empty() && currentTtfFont_ == ttfFont) return; currentFont_ = font; const char *font_name = nullptr; font_ = nullptr; if (!ttfFont.empty()) { bool fontOk = false; std::map<std::string, const char *>::const_iterator i = ttfFonts_.find(ttfFont); if (i != ttfFonts_.end()) { font_name = i->second; fontOk = true; } else if (ttfFont.length() > 4) { std::string suffix = Utils::lowerCase(ttfFont.substr(ttfFont.length() - 4)); if (suffix == ".ttf") { font_name = HPDF_LoadTTFontFromFile (pdf_, ttfFont.c_str(), HPDF_TRUE); } else if (suffix == ".ttc") { /* Oops, pango didn't tell us which font to load ... */ font_name = HPDF_LoadTTFontFromFile2(pdf_, ttfFont.c_str(), 0, HPDF_TRUE); } if (!font_name) HPDF_ResetError (pdf_); else { ttfFonts_[ttfFont] = font_name; fontOk = true; } } if (!fontOk) LOG_ERROR("cannot read font: '" << ttfFont << "': " "expecting a true type font (.ttf, .ttc)"); } if (!font_ && font_name) { font_ = HPDF_GetFont (pdf_, font_name, "UTF-8"); if (!font_) HPDF_ResetError (pdf_); else { trueTypeFont_ = true; currentTtfFont_ = ttfFont; } } if (!font_) { trueTypeFont_ = false; currentTtfFont_.clear(); std::string name = Pdf::toBase14Font(font); font_ = HPDF_GetFont(pdf_, name.c_str(), nullptr); } fontSize_ = font.sizeLength(12).toPixels(); HPDF_Page_SetFontAndSize (page_, font_, fontSize_); } }
void hpdf_doc::add_text(et_datachunk &dc) { et_type datatype = dc.type; wstring &out_string = dc.w_string; char *line = new char[4096]; memset(line, 0, 4096); _locale_t loceng; size_t size = 0; loceng = _create_locale(LC_ALL, "en-US"); int len = out_string.length(); // count of space int n_TX = (et_cp.TX > 0) ? et_cp.TX : et_cp.T, n_TY = (et_cp.TY > 0) ? et_cp.TY : et_cp.T; HPDF_REAL f_xpos = dc.rect.left, f_ypos = dc.rect.bottom; HPDF_REAL f_advance = 0.0; HPDF_REAL f_width = MMTEXT2PTX(et_cp.W * n_TX / 2); HPDF_REAL f_gap = MMTEXT2PTX(et_cp.X/2); HPDF_REAL f_space = MMTEXT2PTY((et_cp.Z * n_TY) + et_cp.L); HPDF_Page_BeginText(h_current_page); select_datatype_font(datatype); f_space = HPDF_Page_GetCurrentFontSize(h_current_page); if (f_space > f_linespace) f_linespace = f_space; switch (datatype) { case ET_LATAN: /* size = _wcstombs_l(line, out_string.c_str(), 4096, loceng); if (size == 0) goto END_PROC; HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line); f_advance = HPDF_Page_TextWidth(h_current_page, line); */ if (et_cp.CorE == 'C') f_width = f_width * 2; text_out_eng(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space, loceng); break; case ET_SPACE: f_advance += ((f_width + f_gap) * len); break; case ET_CJK: case ET_CJKFORM: case ET_BOXDRAW: if (et_cp.VorH == 'H' || datatype != ET_CJK) horizontal(f_xpos, f_ypos); else vertical(f_xpos, f_ypos); if (datatype == ET_BOXDRAW) resize_font_boxdraw(); /* size = wchar_to_utf8(out_string.c_str(), out_string.length(), line, 4096, NULL); if (size == 0) goto END_PROC; HPDF_Page_TextOut(h_current_page, f_xpos, f_ypos - f_linespace, line); //if (datatype == ET_BOXDRAW) // f_advance += (len * ((f_width + f_gap) * 2)); //else f_advance += HPDF_Page_TextWidth(h_current_page, line); //(len * ((f_width + f_gap) * 2)); */ text_out_cjk(f_xpos, f_ypos, out_string, f_advance, f_width, f_gap, f_space); break; } HPDF_Page_EndText(h_current_page); if (et_cp.U > 0) { HPDF_Page_SetLineWidth(h_current_page, 0.5); HPDF_Page_MoveTo(h_current_page, f_xpos, f_ypos - f_linespace); HPDF_Page_LineTo(h_current_page, f_xpos, f_ypos); HPDF_Page_Stroke(h_current_page); } f_xpos += f_advance; delete [] line; // free buffer _free_locale(loceng); }
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 tw; HPDF_REAL height; HPDF_REAL width; HPDF_UINT i; HPDF_Image image; double x; double y; double iw; double ih; HPDF_Stream stream; strcpy (fname, argv[0]); strcat (fname, ".pdf"); pdf = HPDF_New (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_SetLineWidth (page, 1); HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110); HPDF_Page_Stroke (page); /* 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_BeginText (page); HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title); HPDF_Page_EndText (page); /* output subtitle. */ HPDF_Page_BeginText (page); HPDF_Page_SetFontAndSize (page, def_font, 16); HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>"); HPDF_Page_EndText (page); HPDF_Page_BeginText (page); 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_Page_EndText (page); /* Add a new page object. */ page = HPDF_AddPage (pdf); height = HPDF_Page_GetHeight (page); width = HPDF_Page_GetWidth (page); /* load image file. */ image = HPDF_LoadPngImageFromFile (pdf, "test.png"); x = 100; y = 100; iw = HPDF_Image_GetWidth (image); ih = HPDF_Image_GetHeight (image); /* Draw image to the canvas. (normal-mode with actual size.)*/ HPDF_Page_DrawImage (page, image, x, y, iw, ih); HPDF_SaveToFile (pdf, fname); /* write something via zlib */ stream = HPDF_FileWriter_New( pdf->mmgr, "test2.raw" ); HPDF_Stream_WriteToStream( image->stream, stream, HPDF_STREAM_FILTER_FLATE_DECODE, NULL ); HPDF_Stream_Free (stream); /* clean up */ HPDF_Free (pdf); return 0; }
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 tw; HPDF_REAL height; HPDF_REAL width; HPDF_UINT i; strcpy (fname, argv[0]); strcat (fname, ".pdf"); pdf = HPDF_New (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_SetLineWidth (page, 1); HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110); HPDF_Page_Stroke (page); /* 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_BeginText (page); HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title); HPDF_Page_EndText (page); /* output subtitle. */ HPDF_Page_BeginText (page); HPDF_Page_SetFontAndSize (page, def_font, 16); HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>"); HPDF_Page_EndText (page); HPDF_Page_BeginText (page); 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], "CP1251"); /* 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_Page_EndText (page); HPDF_SaveToFile (pdf, fname); /* clean up */ HPDF_Free (pdf); return 0; }
int main (int argc, char **argv) { const char *page_title = "Text Demo"; HPDF_Doc pdf; HPDF_Font font; HPDF_Page page; char fname[256]; const char* samp_text = "abcdefgABCDEFG123!#$%&+-@?"; const char* samp_text2 = "The quick brown fox jumps over the lazy dog."; float tw; float fsize; int i; int len; float angle1; float angle2; float rad1; float rad2; float ypos; strcpy (fname, argv[0]); strcat (fname, ".pdf"); pdf = HPDF_New (error_handler, NULL); if (!pdf) { printf ("error: cannot create PdfDoc object\n"); return 1; } if (setjmp(env)) { HPDF_Free (pdf); return 1; } /* set compression mode */ HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL); /* create default-font */ font = HPDF_GetFont (pdf, "Helvetica", NULL); /* add a new page object. */ page = HPDF_AddPage (pdf); /* draw grid to the page */ print_grid (pdf, page); /* print the lines of the page. HPDF_Page_SetLineWidth (page, 1); HPDF_Page_Rectangle (page, 50, 50, HPDF_Page_GetWidth(page) - 100, HPDF_Page_GetHeight (page) - 110); HPDF_Page_Stroke (page); */ /* print the title of the page (with positioning center). */ HPDF_Page_SetFontAndSize (page, font, 24); tw = HPDF_Page_TextWidth (page, page_title); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, (HPDF_Page_GetWidth(page) - tw) / 2, HPDF_Page_GetHeight (page) - 50, page_title); HPDF_Page_EndText (page); HPDF_Page_BeginText (page); HPDF_Page_MoveTextPos (page, 60, HPDF_Page_GetHeight(page) - 60); /* * font size */ fsize = 8; while (fsize < 60) { char buf[50]; int len; /* set style and size of font. */ HPDF_Page_SetFontAndSize(page, font, fsize); /* set the position of the text. */ HPDF_Page_MoveTextPos (page, 0, -5 - fsize); /* measure the number of characters which included in the page. */ strcpy(buf, samp_text); len = HPDF_Page_MeasureText (page, samp_text, HPDF_Page_GetWidth(page) - 120, HPDF_FALSE, NULL); /* truncate the text. */ buf[len] = 0x00; HPDF_Page_ShowText (page, buf); /* print the description. */ HPDF_Page_MoveTextPos (page, 0, -10); HPDF_Page_SetFontAndSize(page, font, 8); #ifdef __WIN32__ _snprintf(buf, 50, "Fontsize=%.0f", fsize); #else snprintf(buf, 50, "Fontsize=%.0f", fsize); #endif HPDF_Page_ShowText (page, buf); fsize *= 1.5; } /* * font color */ HPDF_Page_SetFontAndSize(page, font, 8); HPDF_Page_MoveTextPos (page, 0, -30); HPDF_Page_ShowText (page, "Font color"); HPDF_Page_SetFontAndSize (page, font, 18); HPDF_Page_MoveTextPos (page, 0, -20); len = strlen (samp_text); for (i = 0; i < len; i++) { char buf[2]; float r = (float)i / (float)len; float g = 1 - ((float)i / (float)len); buf[0] = samp_text[i]; buf[1] = 0x00; HPDF_Page_SetRGBFill (page, r, g, 0.0); HPDF_Page_ShowText (page, buf); } HPDF_Page_MoveTextPos (page, 0, -25); for (i = 0; i < len; i++) { char buf[2]; float r = (float)i / (float)len; float b = 1 - ((float)i / (float)len); buf[0] = samp_text[i]; buf[1] = 0x00; HPDF_Page_SetRGBFill (page, r, 0.0, b); HPDF_Page_ShowText (page, buf); } HPDF_Page_MoveTextPos (page, 0, -25); for (i = 0; i < len; i++) { char buf[2]; float b = (float)i / (float)len; float g = 1 - ((float)i / (float)len); buf[0] = samp_text[i]; buf[1] = 0x00; HPDF_Page_SetRGBFill (page, 0.0, g, b); HPDF_Page_ShowText (page, buf); } HPDF_Page_EndText (page); ypos = 450; /* * Font rendering mode */ HPDF_Page_SetFontAndSize(page, font, 32); HPDF_Page_SetRGBFill (page, 0.5, 0.5, 0.0); HPDF_Page_SetLineWidth (page, 1.5); /* PDF_FILL */ show_description (page, 60, ypos, "RenderingMode=PDF_FILL"); HPDF_Page_SetTextRenderingMode (page, HPDF_FILL); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, ypos, "ABCabc123"); HPDF_Page_EndText (page); /* PDF_STROKE */ show_description (page, 60, ypos - 50, "RenderingMode=PDF_STROKE"); HPDF_Page_SetTextRenderingMode (page, HPDF_STROKE); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, ypos - 50, "ABCabc123"); HPDF_Page_EndText (page); /* PDF_FILL_THEN_STROKE */ show_description (page, 60, ypos - 100, "RenderingMode=PDF_FILL_THEN_STROKE"); HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_THEN_STROKE); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, ypos - 100, "ABCabc123"); HPDF_Page_EndText (page); /* PDF_FILL_CLIPPING */ show_description (page, 60, ypos - 150, "RenderingMode=PDF_FILL_CLIPPING"); HPDF_Page_GSave (page); HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_CLIPPING); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, ypos - 150, "ABCabc123"); HPDF_Page_EndText (page); show_stripe_pattern (page, 60, ypos - 150); HPDF_Page_GRestore (page); /* PDF_STROKE_CLIPPING */ show_description (page, 60, ypos - 200, "RenderingMode=PDF_STROKE_CLIPPING"); HPDF_Page_GSave (page); HPDF_Page_SetTextRenderingMode (page, HPDF_STROKE_CLIPPING); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, ypos - 200, "ABCabc123"); HPDF_Page_EndText (page); show_stripe_pattern (page, 60, ypos - 200); HPDF_Page_GRestore (page); /* PDF_FILL_STROKE_CLIPPING */ show_description (page, 60, ypos - 250, "RenderingMode=PDF_FILL_STROKE_CLIPPING"); HPDF_Page_GSave (page); HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_STROKE_CLIPPING); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, ypos - 250, "ABCabc123"); HPDF_Page_EndText (page); show_stripe_pattern (page, 60, ypos - 250); HPDF_Page_GRestore (page); /* Reset text attributes */ HPDF_Page_SetTextRenderingMode (page, HPDF_FILL); HPDF_Page_SetRGBFill (page, 0, 0, 0); HPDF_Page_SetFontAndSize(page, font, 30); /* * Rotating text */ angle1 = 30; /* A rotation of 30 degrees. */ rad1 = angle1 / 180 * 3.141592; /* Calcurate the radian value. */ show_description (page, 320, ypos - 60, "Rotating text"); HPDF_Page_BeginText (page); HPDF_Page_SetTextMatrix (page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1), 330, ypos - 60); HPDF_Page_ShowText (page, "ABCabc123"); HPDF_Page_EndText (page); /* * Skewing text. */ show_description (page, 320, ypos - 120, "Skewing text"); HPDF_Page_BeginText (page); angle1 = 10; angle2 = 20; rad1 = angle1 / 180 * 3.141592; rad2 = angle2 / 180 * 3.141592; HPDF_Page_SetTextMatrix (page, 1, tan(rad1), tan(rad2), 1, 320, ypos - 120); HPDF_Page_ShowText (page, "ABCabc123"); HPDF_Page_EndText (page); /* * scaling text (X direction) */ show_description (page, 320, ypos - 175, "Scaling text (X direction)"); HPDF_Page_BeginText (page); HPDF_Page_SetTextMatrix (page, 1.5, 0, 0, 1, 320, ypos - 175); HPDF_Page_ShowText (page, "ABCabc12"); HPDF_Page_EndText (page); /* * scaling text (Y direction) */ show_description (page, 320, ypos - 250, "Scaling text (Y direction)"); HPDF_Page_BeginText (page); HPDF_Page_SetTextMatrix (page, 1, 0, 0, 2, 320, ypos - 250); HPDF_Page_ShowText (page, "ABCabc123"); HPDF_Page_EndText (page); /* * char spacing, word spacing */ show_description (page, 60, 140, "char-spacing 0"); show_description (page, 60, 100, "char-spacing 1.5"); show_description (page, 60, 60, "char-spacing 1.5, word-spacing 2.5"); HPDF_Page_SetFontAndSize (page, font, 20); HPDF_Page_SetRGBFill (page, 0.1, 0.3, 0.1); /* char-spacing 0 */ HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, 140, samp_text2); HPDF_Page_EndText (page); /* char-spacing 1.5 */ HPDF_Page_SetCharSpace (page, 1.5); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, 100, samp_text2); HPDF_Page_EndText (page); /* char-spacing 1.5, word-spacing 3.5 */ HPDF_Page_SetWordSpace (page, 2.5); HPDF_Page_BeginText (page); HPDF_Page_TextOut (page, 60, 60, samp_text2); HPDF_Page_EndText (page); /* save the document to a file */ HPDF_SaveToFile (pdf, fname); /* clean up */ HPDF_Free (pdf); return 0; }