feature = $feature; $this->additionaloptions = $additionaloptions; $this->description = $description; $this->text = $text; } } /* * Features supported by PDFlib along with common test strings. Change * the test strings to match the features in the tested font. */ $testcases = array( array( /* Western features */ new testcase("afrc", "", "alternative fractions", "1/2 1/4 3/4"), new testcase("c2pc", "", "petite capitals from capitals", "ABCDEFG"), new testcase("c2sc", "", "small capitals from capitals", "ABCDEFG"), new testcase("calt", "", "contextual alternates", "ABCDEFG"), new testcase("case", "", "case-sensitive forms", "(UN) [UN] (ISO693) »A-B«"), new testcase("ccmp", "", "glyph composition", "ABCDEFG"), new testcase("clig", "", "contextual ligatures", "ABCDEFG"), new testcase("cswh", "", "contextual swash", "ABCDEFG"), new testcase("dlig", "", "discretionary ligatures", "ch tz st c/o TEL"), new testcase("dnom", "", "denominators", "0123456789"), new testcase("falt", "", "final glyph alternates", "abcdefghijABCDEFGH0123"), new testcase("fina", "", "final forms", "σ"), new testcase("frac", "", "fractions", "1/2 1/4 3/4"), new testcase("hist", "", "historical forms", "s"), new testcase("hlig", "", "historical ligatures", "ct st&.longs;b &.longs;t"), new testcase("init", "", "initial forms", "abcdefghijABCDEFGH0123"), new testcase("isol", "", "isolated forms", "abcdefghijABCDEFGH0123"), new testcase("liga", "", "standard ligatures", "ff fi fl ffi ffl"), new testcase("lnum", "", "lining figures", "0123456789"), new testcase("locl", "script=latn language=ROM", "localized forms", "&.Scedilla;&.Tcedilla;"), new testcase("medi", "", "medial forms", "abcdefghijABCDFGH0123"), new testcase("mgrk", "", "mathematical Greek", "Σ"), new testcase("numr", "", "numerators", "0123456789"), new testcase("onum", "", "old-style figures", "0123456789"), new testcase("ordn", "", "ordinals", "No a o A O 1o 2a 3o"), new testcase("ornm", "", "ornaments", "• abcqrstuvwABC"), new testcase("pcap", "", "petite capitals", "ABCDEFG"), new testcase("pnum", "", "proportional figures", "0123456789"), new testcase("salt", "", "stylistic alternates", "& abcdefghij"), new testcase("sinf", "", "scientific inferiors", "H2SO4"), new testcase("smcp", "", "small capitals", "PostScript"), new testcase("subs", "", "subscript ", "0123456789"), new testcase("sups", "", "superscript", "0123456789"), new testcase("swsh", "", "swash", "PQRSTpqrst &"), new testcase("titl", "", "titling", "ABCDEFG"), new testcase("tnum", "", "tabular figures", "0123456789"), new testcase("unic", "", "unicase", "Filosofia"), new testcase("zero", "", "slashed zero", "0"), ), array( /* Stylistic Sets */ /* The text fragments are tuned for the stylistic sets which * are present in our sample font. * Modify the text as appropriate for your font. */ new testcase("ss01", "", "stylistic set 1", "[ÄÖÜ]"), new testcase("ss02", "", "stylistic set 2", "JKR"), new testcase("ss03", "", "stylistic set 3", "ß"), new testcase("ss04", "", "stylistic set 4", "&.Germandbls;"), new testcase("ss05", "", "stylistic set 5", "W"), new testcase("ss06", "", "stylistic set 6", "&"), new testcase("ss07", "", "stylistic set 7", "abcdefghijABCDEFGH0123"), new testcase("ss08", "", "stylistic set 8", "abcdefghijABCDEFGH0123"), new testcase("ss09", "", "stylistic set 9", "abcdefghijABCDEFGH0123"), new testcase("ss10", "", "stylistic set 10", "abcdefghijABCDEFGH0123"), new testcase("ss11", "", "stylistic set 11", "abcdefghijABCDEFGH0123"), new testcase("ss12", "", "stylistic set 12", "abcdefghijABCDEFGH0123"), new testcase("ss13", "", "stylistic set 13", "abcdefghijABCDEFGH0123"), new testcase("ss14", "", "stylistic set 14", "abcdefghijABCDEFGH0123"), new testcase("ss15", "", "stylistic set 15", "abcdefghijABCDEFGH0123"), new testcase("ss16", "", "stylistic set 16", "abcdefghijABCDEFGH0123"), new testcase("ss17", "", "stylistic set 17", "abcdefghijABCDEFGH0123"), new testcase("ss18", "", "stylistic set 18", "abcdefghijABCDEFGH0123"), new testcase("ss19", "", "stylistic set 19", "abcdefghijABCDEFGH0123"), new testcase("ss20", "", "stylistic set 20", "abcdefghijABCDEFGH0123"), ), array( /* CJK features */ new testcase("expt", "", "expert forms", "唖芦飴鹸鵠漣蓮" . "篝"), new testcase("fwid", "", "full widths", "0123-456(789)=25"), new testcase("hkna", "", "horizontal kana alternates", "ぁあぃい ァアィ" . "イュヤゴェ"), new testcase("hngl", "", "hangul", "伽"), new testcase("hojo", "", "Hojo kanji forms (JIS X 0212-1990)", "濹鬵舀鳦鬭霡衋"), new testcase("hwid", "", "half widths", "0123-456(789)=25"), new testcase("ital", "", "italics", "ABCD abcd 1234"), new testcase("jp04", "", "JIS2004 forms", "逢飴溢茨鰯淫迂"), new testcase("jp78", "", "JIS78 forms", "唖鰯倦叱掴這⿔" . "耀"), new testcase("jp83", "", "JIS83 forms", "魘鯆鯱鵈鼈⽗"), new testcase("jp90", "", "JIS90 forms", "啞"), new testcase("locl", "script=hani language=ZHS", "localized forms", "下与丐丑世丗"), new testcase("nalt", "", "alternate annotation forms", "⑴⑵⑶"), new testcase("nlck", "", "NLC kanji forms", "逢芦飴溢茨﨟煉"), new testcase("pkna", "", "proportional kana", "ぁあ ァア ヲ ァ"), new testcase("pwid", "", "proportional widths", "ぁあ ァア ACH" . "IM ABCD abcd 1234"), new testcase("qwid", "", "quarter widths", "0123-456(789)=25"), new testcase("ruby", "", "ruby notation forms", "あおぽオゼヱ◉" . "ㇰㇿ"), new testcase("smpl", "", "simplified forms", "檯 臺 颱"), new testcase("tnam", "", "traditional name forms", "亜"), new testcase("trad", "", "traditional forms", "台七与丱紛餒隸" . "隘陪鎚"), new testcase("twid", "", "third widths", "0123-456(789)=25"), /* The output creates horizontal text only, therefore the * vertical alternates will not be visible (even if present * in the font). */ new testcase("vert", "", "vertical alternates", "(a) {b} – —"), new testcase("vkna", "", "vertical kana alternates", "ぁあぃい ㇿㇸニ" . "セ"), new testcase("vrt2", "", "vertical alternates and rotation", "abcABC") ) ); try { $p = new PDFlib(); $row=0; $col=0; $p->set_option("searchpath={" . $searchpath . "}"); $p->set_option("charref=true"); $p->set_option("stringformat=utf8"); /* * This means that formatting and other errors will raise an * exception. This simplifies our sample code, but is not * recommended for production code. */ $p->set_option("errorpolicy=exception"); /* Set an output path according to the name of the topic */ if ($p->begin_document($outfile, "") == 0) { throw new Exception("Error: " . $p->get_apiname() . ": " . $p->get_errmsg()); } $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); $table = 0; $row = 1; $col = 1; /* Table header */ $optlist = "fittextline={fontname=Helvetica-Bold encoding=unicode " . "fontsize=12} margin=4"; $table = $p->add_table_cell($table, $col, $row++, "Supported OpenType features in font " . $testfont, $optlist . " colspan=4"); for ($i = 0; $i < count($headers); $i++) { $col = $i + 1; $table = $p->add_table_cell($table, $col, $row, $headers[$i], $optlist); } $row++; for ($group = 0; $group < count($testcases); $group += 1) { $featurecount = 0; $col = 1; $optlist = "fittextline={fontname=Helvetica-BoldOblique " . "encoding=unicode fontsize=12} " . "margin=4 colspan=4 rowjoingroup= " . $group; $table = $p->add_table_cell($table, $col, $row++, $groupdescriptions[$group], $optlist); /* * Create a table with feature samples, one feature per table * row */ for ($i = 0; $i < count($testcases[$group]); $i += 1) { $testcase = $testcases[$group][$i]; $col = 1; /* skip unavailable features */ $font = $p->load_font($testfont, "unicode", "embedding"); $optlist = "name=" . $testcase->feature; if ($p->info_font($font, "feature", $optlist) != 1) continue; $featurecount++; /* Common option list for columns 1-3 */ $optlist = "fittextline={fontname=Helvetica " . "encoding=unicode fontsize=12} margin=4"; /* Column 1: feature name */ $table = $p->add_table_cell($table, $col++, $row, $testcase->feature . " " . $testcase->additionaloptions, $optlist); /* Column 2: feature description */ $table = $p->add_table_cell($table, $col++, $row, $testcase->description, $optlist); /* Column 3: raw input text with feature disabled */ $optlist = "fittextline={fontname={" . $testfont . "} encoding=unicode fontsize=12 embedding} margin=4"; $table = $p->add_table_cell($table, $col++, $row, $testcase->text, $optlist); /* Column 4: text with enabled feature */ $optlist = "fittextline={fontname={" . $testfont . "} encoding=unicode fontsize=12 embedding " . "features={" . $testcase->feature . "} " . $testcase->additionaloptions . "} margin=4"; $table = $p->add_table_cell($table, $col++, $row, $testcase->text, $optlist); $row++; } if ($featurecount == 0) { $col = 1; $optlist = "fittextline={fontname=Helvetica " . "encoding=unicode fontsize=12} " . "margin=4 colspan=4 rowjoingroup= " . $group; $table = $p->add_table_cell($table, $col, $row++, "(none)", $optlist); } } /* * Loop until all of the table is placed; create new pages as long * as more table instances need to be placed. */ do { $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); $optlist = "header=2 fill={{area=rowodd fillcolor={gray 0.9}}} " . "stroke={{line=other}} "; /* Place the table instance */ $result = $p->fit_table($table, $llx, $lly, $urx, $ury, $optlist); if ($result == "_error") throw new Exception("Couldn't place table: " . $p->get_errmsg()); $p->end_page_ext(""); } while ($result == "_boxfull"); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=opentype_feature_tester.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e->getMessage()); exit(1); } $p = 0; ?>