set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); if ($p->begin_document("", "") == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Unicode characters are referenced via character references */ $p->set_option("charref=true"); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title . ' $Revision: 1.9 $'); /* Start page */ $p->begin_page_ext(0, 0, "width=200 height=200"); /* * -------------------------------------------- * Step 1: Define the new font "CourierTurkish" * -------------------------------------------- */ /* Load the font from which the glyphs will be taken for creating * the glyph for U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE. */ $basefont = $p->load_font("Courier", "unicode", ""); if ($basefont == 0) throw new Exception("Error: " . $p->get_errmsg()); /* * Base the width of the new glyph on the width of the similar * character 'I', but any character could be used in this example * as Courier is a monospace font. Set the font size to 1000 because * the new font uses a 1000x1000 coordinate system. */ $glyphwidth = $p->info_textline("I", "width", "font=" . $basefont . " fontsize=1000"); $p->begin_font("CourierTurkish", 0.001, 0.0, 0.0, 0.001, 0.0, 0.0, ""); /* .notdef is required; the width of .notdef does not really * matter */ $p->begin_glyph_ext(0x0000, "width=600"); $p->end_glyph(); /* * The bounding box must be large enough to contain the * respective glyph. Better create the bounding box too large * than risk problems. */ $p->begin_glyph_ext(0x0130, "width=" . $glyphwidth . " " . "boundingbox={0 -250 600 800} " . "glyphname=Idottaccent"); $p->setfont($basefont, 1000); /* * Now for the crucial trick: Create a new glyph by combining * the two existing glyphs "I" ... */ $p->fit_textline("I", 0, 0, ""); /* * ... and U+02D9 DOT ABOVE. Shift the accent upwards to * nicely position it on top of the "I". */ $p->fit_textline("˙", 0.0, 160.0, ""); $p->end_glyph(); $p->end_font(); /* * ------------------------ * Step 2: Use the new font * ------------------------ */ /* * Load the Courier font, now with the "CourierTurkish" Type 3 * font as fallback font. */ $basefont = $p->load_font("Courier", "unicode", "fallbackfonts={{fontname=CourierTurkish encoding=unicode}}"); if ($basefont == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Output "Istanbul" */ $p->fit_textline("Istanbul", 50, 140, "font=" . $basefont . " fontsize=" . FONTSIZE); /* Output U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE and * "stanbul". */ $p->fit_textline("İstanbul", 50, 100, "font=" . $basefont . " fontsize=" . FONTSIZE); /* Finish page */ $p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=type3_turkish_character.pdf"); print $buf; } catch (PDFlibException $e) { die("PDFlib exception occurred:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); } catch (Exception $e) { die($e->getMessage()); } $p = 0; ?>