/* ** cg_swip_page() ** Do a rotation of the page. */ yerr_t cg_swip_page(cg_t *carta, cg_deck_t *deck) { PDF_rotate(carta->p, 180.0); PDF_translate(carta->p, -(YVAL2PT(deck->paper_width)), -(YVAL2PT(deck->paper_height))); return (YENOERR); }
void PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size) { // try to convert from utf8 to MacRoman encoding schema... int32 srcLen = size; int32 destLen = 1; char dest[3] = "\0\0"; int32 state = 0; bool embed = true; font_encoding encoding = macroman_encoding; char fontName[B_FONT_FAMILY_LENGTH+B_FONT_STYLE_LENGTH+1]; if (convert_from_utf8(B_MAC_ROMAN_CONVERSION, utf8, &srcLen, dest, &destLen, &state, 0) != B_OK || dest[0] == 0) { // could not convert to MacRoman font_encoding fenc; uint16 index = 0; uint8 enc; GetFontName(&fState->beFont, fontName); embed = EmbedFont(fontName); REPORT(kDebug, -1, "find_encoding unicode %d\n", (int)unicode); if (find_encoding(unicode, enc, index)) { // is code point in the Adobe Glyph List? // Note if rendering the glyphs only would be desired, we could // always use the second method below (MakeUserDefinedEncoding), // but extracting text from the generated PDF would be almost // impossible (OCR!) REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc, (int)index); // use one of the user pre-defined encodings if (fState->beFont.FileFormat() == B_TRUETYPE_WINDOWS) { encoding = font_encoding(enc + tt_encoding0); } else { encoding = font_encoding(enc + t1_encoding0); } *dest = index; } else if (embed) { // if the font is embedded, create a user defined encoding at runtime uint8 index; MakeUserDefinedEncoding(unicode, enc, index); *dest = index; encoding = font_encoding(user_defined_encoding_start + enc); } else if (find_in_cid_tables(unicode, fenc, index, fFontSearchOrder)) { // font is not embedded use one of the CJK fonts for substitution REPORT(kDebug, -1, "cid table %d index = %d", (int)fenc, (int)index); dest[0] = unicode / 256; dest[1] = unicode % 256; destLen = 2; encoding = fenc; embed = false; } else { static bool found = false; REPORT(kDebug, -1, "encoding for %x not found!", (int)unicode); if (!found) { found = true; REPORT(kError, fPage, "Could not find an encoding for character " "with unicode %d! Message is not repeated for other unicode " "values.", (int)unicode); } *dest = 0; // paint a box (is 0 a box in MacRoman) or return; // simply skip character } } else { REPORT(kDebug, -1, "macroman srcLen=%d destLen=%d dest= %d %d!", srcLen, destLen, (int)dest[0], (int)dest[1]); } // Note we have to build the user defined encoding before it is used in // PDF_find_font! if (!MakesPDF()) return; int font; GetFontName(&fState->beFont, fontName, embed, encoding); font = FindFont(fontName, embed, encoding); if (font < 0) { REPORT(kWarning, fPage, "**** PDF_findfont(%s) failed, back to default " "font", fontName); font = PDF_findfont(fPdf, "Helvetica", "macroman", 0); } fState->font = font; uint16 face = fState->beFont.Face(); PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0 ? "true" : "false"); PDF_set_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0 ? "true" : "false"); PDF_set_value(fPdf, "textrendering", (face & B_OUTLINED_FACE) != 0 ? 1 : 0); PDF_setfont(fPdf, fState->font, scale(fState->beFont.Size())); const float x = tx(fState->penX); const float y = ty(fState->penY); const float rotation = fState->beFont.Rotation(); const bool rotate = rotation != 0.0; if (rotate) { PDF_save(fPdf); PDF_translate(fPdf, x, y); PDF_rotate(fPdf, rotation); PDF_set_text_pos(fPdf, 0, 0); } else PDF_set_text_pos(fPdf, x, y); PDF_show2(fPdf, dest, destLen); if (rotate) { PDF_restore(fPdf); } }
int main(void) { PDF *p; float alpha; time_t timer; struct tm ltime; /* create a new PDFlib object */ if ((p = PDF_new()) == (PDF *) 0) { printf("Couldn't create PDFlib object (out of memory)!\n"); return(2); } PDF_TRY(p) { /* open new PDF file */ if (PDF_open_file(p, "pdfclock.pdf") == -1) { printf("Error: %s\n", PDF_get_errmsg(p)); return(2); } /* This line is required to avoid problems on Japanese systems */ PDF_set_parameter(p, "hypertextencoding", "host"); PDF_set_info(p, "Creator", "pdfclock.c"); PDF_set_info(p, "Author", "Thomas Merz"); PDF_set_info(p, "Title", "PDF clock (C)"); PDF_begin_page(p, (float) (2 * (RADIUS + MARGIN)), (float) (2 * (RADIUS + MARGIN))); PDF_translate(p, RADIUS + MARGIN, RADIUS + MARGIN); PDF_setcolor(p, "fillstroke", "rgb", 0, 0, 1, 0); PDF_save(p); /* minute strokes */ PDF_setlinewidth(p, 2); for (alpha = 0; alpha < 360; alpha += 6) { PDF_rotate(p, 6); PDF_moveto(p, RADIUS, 0); PDF_lineto(p, (float) (RADIUS-MARGIN/3), 0); PDF_stroke(p); } PDF_restore(p); PDF_save(p); /* 5 minute strokes */ PDF_setlinewidth(p, 3); for (alpha = 0; alpha < 360; alpha += 30) { PDF_rotate(p, 30); PDF_moveto(p, RADIUS, 0); PDF_lineto(p, RADIUS-MARGIN, 0); PDF_stroke(p); } time(&timer); ltime = *localtime(&timer); /* draw hour hand */ PDF_save(p); PDF_rotate(p, (float)(-((ltime.tm_min/60.0) + ltime.tm_hour - 3.0) * 30.0)); PDF_moveto(p, -RADIUS/10, -RADIUS/20); PDF_lineto(p, RADIUS/2, 0); PDF_lineto(p, -RADIUS/10, RADIUS/20); PDF_closepath(p); PDF_fill(p); PDF_restore(p); /* draw minute hand */ PDF_save(p); PDF_rotate(p, (float) (-((ltime.tm_sec/60.0) + ltime.tm_min - 15.0) * 6.0)); PDF_moveto(p, -RADIUS/10, -RADIUS/20); PDF_lineto(p, RADIUS * 0.8f, 0); PDF_lineto(p, -RADIUS/10, RADIUS/20); PDF_closepath(p); PDF_fill(p); PDF_restore(p); /* draw second hand */ PDF_setcolor(p, "fillstroke", "rgb", 1, 0, 0, 0); PDF_setlinewidth(p, 2); PDF_save(p); PDF_rotate(p, (float) -((ltime.tm_sec - 15.0) * 6.0)); PDF_moveto(p, -RADIUS/5, 0); PDF_lineto(p, RADIUS, 0); PDF_stroke(p); PDF_restore(p); /* draw little circle at center */ PDF_circle(p, 0, 0, (float) RADIUS/30); PDF_fill(p); PDF_restore(p); PDF_end_page(p); PDF_close(p); } PDF_CATCH(p) { printf("PDFlib exception occurred in pdfclock sample:\n"); printf("[%d] %s: %s\n", PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p)); PDF_delete(p); return(2); } PDF_delete(p); /* delete the PDFlib object */ return 0; }