php-font-lib-0.2.2+dfsg.orig/ 0000755 0000000 0000000 00000000000 12273210464 014367 5 ustar root root php-font-lib-0.2.2+dfsg.orig/.gitattributes 0000644 0000000 0000000 00000000234 12273210464 017261 0 ustar root root *.json text *.xml text *.php text *.LGPL text *.md text *.skel text *.css text *.inc text *.js text *.html text *.txt text *.svg text php-font-lib-0.2.2+dfsg.orig/.gitignore 0000644 0000000 0000000 00000000056 12273210464 016360 0 ustar root root .DS_Store composer.lock vendor .idea .project php-font-lib-0.2.2+dfsg.orig/.htaccess 0000644 0000000 0000000 00000000016 12273210464 016162 0 ustar root root #deny from all php-font-lib-0.2.2+dfsg.orig/LICENSE 0000644 0000000 0000000 00000057452 12273210464 015411 0 ustar root root GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. php-font-lib-0.2.2+dfsg.orig/README.md 0000644 0000000 0000000 00000000726 12273210464 015653 0 ustar root root This library can be used to: * Read TrueType, OpenType (with TrueType glyphs), WOFF font files * Extract basic info (name, style, etc) * Extract advanced info (horizontal metrics, glyph names, glyph shapes, etc) * Make an Adobe Font Metrics (AFM) file from a font You can find a demo GUI [here](http://pxd.me/php-font-lib/www/font_explorer.html). This project was initiated by the need to read font files in the [DOMPDF project](https://github.com/dompdf/dompdf). php-font-lib-0.2.2+dfsg.orig/classes/ 0000755 0000000 0000000 00000000000 12273210464 016024 5 ustar root root php-font-lib-0.2.2+dfsg.orig/classes/Adobe_Font_Metrics.php 0000644 0000000 0000000 00000013631 12273210464 022227 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ require_once dirname(__FILE__) . "/Encoding_Map.php"; /** * Adobe Font Metrics file creation utility class. * * @package php-font-lib */ class Adobe_Font_Metrics { private $f; /** * @var Font_TrueType */ private $font; function __construct(Font_TrueType $font) { $this->font = $font; } function write($file, $encoding = null){ $map_data = array(); if ($encoding) { $encoding = preg_replace("/[^a-z0-9-_]/", "", $encoding); $map_file = dirname(__FILE__)."/../maps/$encoding.map"; if (!file_exists($map_file)) { throw new Exception("Unkown encoding ($encoding)"); } $map = new Encoding_Map($map_file); $map_data = $map->parse(); } $this->f = fopen($file, "w+"); $font = $this->font; $this->startSection("FontMetrics", 4.1); $this->addPair("Notice", "Converted by PHP-font-lib"); $this->addPair("Comment", "https://github.com/PhenX/php-font-lib"); $encoding_scheme = ($encoding ? $encoding : "FontSpecific"); $this->addPair("EncodingScheme", $encoding_scheme); $records = $font->getData("name", "records"); foreach($records as $id => $record) { if (!isset(Font_Table_name::$nameIdCodes[$id]) || preg_match("/[\r\n]/", $record->string)) { continue; } $this->addPair(Font_Table_name::$nameIdCodes[$id], $record->string); } $os2 = $font->getData("OS/2"); $this->addPair("Weight", ($os2["usWeightClass"] > 400 ? "Bold" : "Medium")); $post = $font->getData("post"); $this->addPair("ItalicAngle", $post["italicAngle"]); $this->addPair("IsFixedPitch", ($post["isFixedPitch"] ? "true" : "false")); $this->addPair("UnderlineThickness", $font->normalizeFUnit($post["underlineThickness"])); $this->addPair("UnderlinePosition", $font->normalizeFUnit($post["underlinePosition"])); $hhea = $font->getData("hhea"); if (isset($hhea["ascent"])) { $this->addPair("FontHeightOffset", $font->normalizeFUnit($hhea["lineGap"])); $this->addPair("Ascender", $font->normalizeFUnit($hhea["ascent"])); $this->addPair("Descender", $font->normalizeFUnit($hhea["descent"])); } else { $this->addPair("FontHeightOffset", $font->normalizeFUnit($os2["typoLineGap"])); $this->addPair("Ascender", $font->normalizeFUnit($os2["typoAscender"])); $this->addPair("Descender", -abs($font->normalizeFUnit($os2["typoDescender"]))); } $head = $font->getData("head"); $this->addArray("FontBBox", array( $font->normalizeFUnit($head["xMin"]), $font->normalizeFUnit($head["yMin"]), $font->normalizeFUnit($head["xMax"]), $font->normalizeFUnit($head["yMax"]), )); $glyphIndexArray = $font->getUnicodeCharMap(); if ($glyphIndexArray) { $hmtx = $font->getData("hmtx"); $names = $font->getData("post", "names"); $this->startSection("CharMetrics", count($hmtx)); if ($encoding) { foreach($map_data as $code => $value) { list($c, $name) = $value; if (!isset($glyphIndexArray[$c])) continue; $g = $glyphIndexArray[$c]; if (!isset($hmtx[$g])) { $hmtx[$g] = $hmtx[0]; } $this->addMetric(array( "C" => ($code > 255 ? -1 : $code), "WX" => $font->normalizeFUnit($hmtx[$g][0]), "N" => $name, )); } } else { foreach($glyphIndexArray as $c => $g) { if (!isset($hmtx[$g])) { $hmtx[$g] = $hmtx[0]; } $this->addMetric(array( "U" => $c, "WX" => $font->normalizeFUnit($hmtx[$g][0]), "N" => (isset($names[$g]) ? $names[$g] : sprintf("uni%04x", $c)), "G" => $g, )); } } $this->endSection("CharMetrics"); $kern = $font->getData("kern", "subtable"); $tree = $kern["tree"]; if (!$encoding && is_array($tree)) { $this->startSection("KernData"); $this->startSection("KernPairs", count($tree, COUNT_RECURSIVE) - count($tree)); foreach($tree as $left => $values) { if (!is_array($values)) continue; if (!isset($glyphIndexArray[$left])) continue; $left_gid = $glyphIndexArray[$left]; if (!isset($names[$left_gid])) continue; $left_name = $names[$left_gid]; $this->addLine(""); foreach($values as $right => $value) { if (!isset($glyphIndexArray[$right])) continue; $right_gid = $glyphIndexArray[$right]; if (!isset($names[$right_gid])) continue; $right_name = $names[$right_gid]; $this->addPair("KPX", "$left_name $right_name $value"); } } $this->endSection("KernPairs"); $this->endSection("KernData"); } } $this->endSection("FontMetrics"); } function addLine($line) { fwrite($this->f, "$line\n"); } function addPair($key, $value) { $this->addLine("$key $value"); } function addArray($key, $array) { $this->addLine("$key ".implode(" ", $array)); } function addMetric($data) { $array = array(); foreach($data as $key => $value) { $array[] = "$key $value"; } $this->addLine(implode(" ; ", $array)); } function startSection($name, $value = "") { $this->addLine("Start$name $value"); } function endSection($name) { $this->addLine("End$name"); } } php-font-lib-0.2.2+dfsg.orig/classes/Encoding_Map.php 0000644 0000000 0000000 00000001477 12273210464 021071 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ /** * Encoding map used to map a code point to a Unicode char. * * @package php-font-lib */ class Encoding_Map { private $f; function __construct($file) { $this->f = fopen($file, "r"); } function parse(){ $map = array(); while($line = fgets($this->f)) { if (preg_match("/^[\!\=]([0-9A-F]{2,})\s+U\+([0-9A-F]{2})([0-9A-F]{2})\s+([^\s]+)/", $line, $matches)) { $unicode = (hexdec($matches[2]) << 8) + hexdec($matches[3]); $map[hexdec($matches[1])] = array($unicode, $matches[4]); } } ksort($map); return $map; } } php-font-lib-0.2.2+dfsg.orig/classes/Font.php 0000644 0000000 0000000 00000003176 12273210464 017452 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ /** * Generic font file. * * @package php-font-lib */ class Font { static $debug = false; /** * @param string $file The font file * @return Font_TrueType|null $file */ public static function load($file) { $header = file_get_contents($file, false, null, null, 4); $class = null; switch($header) { case "\x00\x01\x00\x00": case "true": case "typ1": $class = "Font_TrueType"; break; case "OTTO": $class = "Font_OpenType"; break; case "wOFF": $class = "Font_WOFF"; break; case "ttcf": $class = "Font_TrueType_Collection"; break; // Unknown type or EOT default: $magicNumber = file_get_contents($file, false, null, 34, 2); if ($magicNumber === "LP") { $class = "Font_EOT"; } } if ($class) { /** @noinspection PhpIncludeInspection */ require_once dirname(__FILE__)."/$class.php"; /** @var Font_TrueType $obj */ $obj = new $class; $obj->load($file); return $obj; } return null; } static function d($str) { if (!self::$debug) return; echo "$str\n"; } static function UTF16ToUTF8($str) { return mb_convert_encoding($str, "utf-8", "utf-16"); } static function UTF8ToUTF16($str) { return mb_convert_encoding($str, "utf-16", "utf-8"); } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Binary_Stream.php 0000644 0000000 0000000 00000020700 12273210464 022261 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ /** * Generic font file binary stream. * * @package php-font-lib */ class Font_Binary_Stream { /** * @var resource The file pointer */ protected $f; const uint8 = 1; const int8 = 2; const uint16 = 3; const int16 = 4; const uint32 = 5; const int32 = 6; const shortFrac = 7; const Fixed = 8; const FWord = 9; const uFWord = 10; const F2Dot14 = 11; const longDateTime = 12; const char = 13; const modeRead = "rb"; const modeWrite = "wb"; const modeReadWrite = "rb+"; static function backtrace(){ var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); } /** * Open a font file in read mode * * @param string $filename The file name of the font to open * * @return bool */ public function load($filename) { return $this->open($filename, self::modeRead); } /** * Open a font file in a chosen mode * * @param string $filename The file name of the font to open * @param string $mode The opening mode * * @throws Exception * @return bool */ public function open($filename, $mode = self::modeRead) { if (!in_array($mode, array(self::modeRead, self::modeWrite, self::modeReadWrite))) { throw new Exception("Unkown file open mode"); } $this->f = fopen($filename, $mode); return $this->f != false; } /** * Close the internal file pointer */ public function close() { return fclose($this->f) != false; } /** * Change the internal file pointer * * @param resource $fp * * @throws Exception */ public function setFile($fp) { if (!is_resource($fp)) { throw new Exception('$fp is not a valid resource'); } $this->f = $fp; } /** * Create a temporary file in write mode * * @param bool $allow_memory Allow in-memory files * * @return resource the temporary file pointer resource */ public static function getTempFile($allow_memory = true) { $f = null; if ($allow_memory) { // PHP 5.1+ @fopen("php://temp", "rb+"); } if (!$f) { $f = fopen(tempnam(sys_get_temp_dir(), "fnt"), "rb+"); } return $f; } /** * Move the internal file pinter to $offset bytes * * @param int $offset * * @return bool True if the $offset position exists in the file */ public function seek($offset) { return fseek($this->f, $offset, SEEK_SET) == 0; } /** * Gives the current position in the file * * @return int The current position */ public function pos() { return ftell($this->f); } public function skip($n) { fseek($this->f, $n, SEEK_CUR); } public function read($n) { if ($n < 1) { return ""; } return fread($this->f, $n); } public function write($data, $length = null) { if ($data === null || $data === "") { return 0; } return fwrite($this->f, $data, $length); } public function readUInt8() { return ord($this->read(1)); } public function writeUInt8($data) { return $this->write(chr($data), 1); } public function readInt8() { $v = $this->readUInt8(); if ($v >= 0x80) { $v -= 0x100; } return $v; } public function writeInt8($data) { if ($data < 0) { $data += 0x100; } return $this->writeUInt8($data); } public function readUInt16() { $a = unpack("nn", $this->read(2)); return $a["n"]; } public function readUFWord(){ return $this->readUInt16(); } public function writeUInt16($data) { return $this->write(pack("n", $data), 2); } public function writeUFWord($data){ return $this->writeUInt16($data); } public function readInt16() { $v = $this->readUInt16(); if ($v >= 0x8000) { $v -= 0x10000; } return $v; } public function readFWord(){ return $this->readInt16(); } public function writeInt16($data) { if ($data < 0) { $data += 0x10000; } return $this->writeUInt16($data); } public function writeFWord($data){ return $this->writeInt16($data); } public function readUInt32() { $a = unpack("NN", $this->read(4)); return $a["N"]; } public function writeUInt32($data) { return $this->write(pack("N", $data), 4); } public function readFixed() { $d = $this->readInt16(); $d2 = $this->readUInt16(); return round($d + $d2 / 0x10000, 4); } public function writeFixed($data) { $left = floor($data); $right = ($data - $left) * 0x10000; return $this->writeInt16($left) + $this->writeUInt16($right); } public function readLongDateTime() { $this->readUInt32(); // ignored $date = $this->readUInt32() - 2082844800; return strftime("%Y-%m-%d %H:%M:%S", $date); } public function writeLongDateTime($data) { $date = strtotime($data); $date += 2082844800; return $this->writeUInt32(0) + $this->writeUInt32($date); } public function unpack($def) { $d = array(); foreach($def as $name => $type) { $d[$name] = $this->r($type); } return $d; } public function pack($def, $data) { $bytes = 0; foreach($def as $name => $type) { $bytes += $this->w($type, $data[$name]); } return $bytes; } /** * Read a data of type $type in the file from the current position * * @param mixed $type The data type to read * * @return mixed The data that was read */ public function r($type) { switch($type) { case self::uint8: return $this->readUInt8(); case self::int8: return $this->readInt8(); case self::uint16: return $this->readUInt16(); case self::int16: return $this->readInt16(); case self::uint32: return $this->readUInt32(); case self::int32: return $this->readUInt32(); case self::shortFrac: return $this->readFixed(); case self::Fixed: return $this->readFixed(); case self::FWord: return $this->readInt16(); case self::uFWord: return $this->readUInt16(); case self::F2Dot14: return $this->readInt16(); case self::longDateTime: return $this->readLongDateTime(); case self::char: return $this->read(1); default: if ( is_array($type) ) { if ($type[0] == self::char) { return $this->read($type[1]); } $ret = array(); for($i = 0; $i < $type[1]; $i++) { $ret[] = $this->r($type[0]); } return $ret; } return null; } } /** * Write $data of type $type in the file from the current position * * @param mixed $type The data type to write * @param mixed $data The data to write * * @return int The number of bytes read */ public function w($type, $data) { switch($type) { case self::uint8: return $this->writeUInt8($data); case self::int8: return $this->writeInt8($data); case self::uint16: return $this->writeUInt16($data); case self::int16: return $this->writeInt16($data); case self::uint32: return $this->writeUInt32($data); case self::int32: return $this->writeUInt32($data); case self::shortFrac: return $this->writeFixed($data); case self::Fixed: return $this->writeFixed($data); case self::FWord: return $this->writeInt16($data); case self::uFWord: return $this->writeUInt16($data); case self::F2Dot14: return $this->writeInt16($data); case self::longDateTime: return $this->writeLongDateTime($data); case self::char: return $this->write($data, 1); default: if ( is_array($type) ) { if ($type[0] == self::char) { return $this->write($data, $type[1]); } $ret = 0; for($i = 0; $i < $type[1]; $i++) { $ret += $this->w($type[0], $data[$i]); } return $ret; } return null; } } /** * Converts a Uint32 value to string * * @param int $uint32 * * @return string The string */ public function convertUInt32ToStr($uint32) { return chr(($uint32 >> 24) & 0xFF).chr(($uint32 >> 16) & 0xFF).chr(($uint32 >> 8) & 0xFF).chr($uint32 & 0xFF); } } php-font-lib-0.2.2+dfsg.orig/classes/Font_EOT.php 0000644 0000000 0000000 00000006514 12273210464 020160 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ require_once dirname(__FILE__) . "/Font_TrueType.php"; require_once dirname(__FILE__) . "/Font_EOT_Header.php"; /** * EOT font file. * * @package php-font-lib */ class Font_EOT extends Font_TrueType { const TTEMBED_SUBSET = 0x00000001; const TTEMBED_TTCOMPRESSED = 0x00000004; const TTEMBED_FAILIFVARIATIONSIMULATED = 0x00000010; const TTMBED_EMBEDEUDC = 0x00000020; const TTEMBED_VALIDATIONTESTS = 0x00000040; // Deprecated const TTEMBED_WEBOBJECT = 0x00000080; const TTEMBED_XORENCRYPTDATA = 0x10000000; /** * @var Font_EOT_Header */ public $header; function parseHeader(){ if (!empty($this->header)) { return; } $this->header = new Font_EOT_Header($this); $this->header->parse(); } function parse() { $this->parseHeader(); $flags = $this->header->data["Flags"]; if ($flags & self::TTEMBED_TTCOMPRESSED) { $mtx_version = $this->readUInt8(); $mtx_copy_limit = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8(); $mtx_offset_1 = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8(); $mtx_offset_2 = $this->readUInt8() << 16 | $this->readUInt8() << 8 | $this->readUInt8(); /* var_dump("$mtx_version $mtx_copy_limit $mtx_offset_1 $mtx_offset_2"); $pos = $this->pos(); $size = $mtx_offset_1 - $pos; var_dump("pos: $pos"); var_dump("size: $size");*/ } if ($flags & self::TTEMBED_XORENCRYPTDATA) { // Process XOR } // TODO Read font data ... } /** * Little endian version of the read method */ public function read($n) { if ($n < 1) { return ""; } $string = fread($this->f, $n); $chunks = str_split($string, 2); $chunks = array_map("strrev", $chunks); return implode("", $chunks); } public function readUInt32(){ $uint32 = parent::readUInt32(); return $uint32 >> 16 & 0x0000FFFF | $uint32 << 16 & 0xFFFF0000; } /** * Get font copyright * * @return string|null */ function getFontCopyright(){ return null; } /** * Get font name * * @return string|null */ function getFontName(){ return $this->header->data["FamilyName"]; } /** * Get font subfamily * * @return string|null */ function getFontSubfamily(){ return $this->header->data["StyleName"]; } /** * Get font subfamily ID * * @return string|null */ function getFontSubfamilyID(){ return $this->header->data["StyleName"]; } /** * Get font full name * * @return string|null */ function getFontFullName(){ return $this->header->data["FullName"]; } /** * Get font version * * @return string|null */ function getFontVersion(){ return $this->header->data["VersionName"]; } /** * Get font weight * * @return string|null */ function getFontWeight(){ return $this->header->data["Weight"]; } /** * Get font Postscript name * * @return string|null */ function getFontPostscriptName(){ return null; } } php-font-lib-0.2.2+dfsg.orig/classes/Font_EOT_Header.php 0000644 0000000 0000000 00000006170 12273210464 021426 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ require_once dirname(__FILE__) . "/Font_Header.php"; /** * TrueType font file header. * * @package php-font-lib * * @property Font_EOT $font */ class Font_EOT_Header extends Font_Header { protected $def = array( "format" => self::uint32, "numTables" => self::uint16, "searchRange" => self::uint16, "entrySelector" => self::uint16, "rangeShift" => self::uint16, ); public function parse(){ $font = $this->font; $this->data = $font->unpack(array( "EOTSize" => self::uint32, "FontDataSize" => self::uint32, "Version" => self::uint32, "Flags" => self::uint32, "FontPANOSE" => array(self::uint8, 10), "Charset" => self::uint8, "Italic" => self::uint8, "Weight" => self::uint32, "fsType" => self::uint16, "MagicNumber" => self::uint16, "UnicodeRange1" => self::uint32, "UnicodeRange2" => self::uint32, "UnicodeRange3" => self::uint32, "UnicodeRange4" => self::uint32, "CodePageRange1" => self::uint32, "CodePageRange2" => self::uint32, "CheckSumAdjustment" => self::uint32, "Reserved1" => self::uint32, "Reserved2" => self::uint32, "Reserved3" => self::uint32, "Reserved4" => self::uint32, )); $this->data["Padding1"] = $font->readUInt16(); $this->readString("FamilyName"); $this->data["Padding2"] = $font->readUInt16(); $this->readString("StyleName"); $this->data["Padding3"] = $font->readUInt16(); $this->readString("VersionName"); $this->data["Padding4"] = $font->readUInt16(); $this->readString("FullName"); switch ($this->data["Version"]) { default: throw new Exception("Unknown EOT version ".$this->data["Version"]); case 0x00010000: // Nothing to do more break; case 0x00020001: $this->data["Padding5"] = $font->readUInt16(); $this->readString("RootString"); break; case 0x00020002: $this->data["Padding5"] = $font->readUInt16(); $this->readString("RootString"); $this->data["RootStringCheckSum"] = $font->readUInt32(); $this->data["EUDCCodePage"] = $font->readUInt32(); $this->data["Padding6"] = $font->readUInt16(); $this->readString("Signature"); $this->data["EUDCFlags"] = $font->readUInt32(); $this->data["EUDCFontSize"] = $font->readUInt32(); break; } if (!empty($this->data["RootString"])) { $this->data["RootString"] = explode("\0", $this->data["RootString"]); } } private function readString($name) { $font = $this->font; $size = $font->readUInt16(); $this->data["{$name}Size"] = $size; $this->data[$name] = Font::UTF16ToUTF8($font->read($size)); } public function encode(){ //return $this->font->pack($this->def, $this->data); } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Glyph_Outline.php 0000644 0000000 0000000 00000004474 12273210464 022316 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $ */ /** * `glyf` font table. * * @package php-font-lib */ class Font_Glyph_Outline extends Font_Binary_Stream { /** * @var Font_Table_glyf */ protected $table; protected $offset; protected $size; // Data public $numberOfContours; public $xMin; public $yMin; public $xMax; public $yMax; public $raw; /** * @param Font_Table_glyf $table * @param $offset * @param $size * * @return Font_Glyph_Outline */ static function init(Font_Table_glyf $table, $offset, $size) { $font = $table->getFont(); $font->seek($offset); if ($font->readInt16() > -1) { /** @var Font_Glyph_Outline_Simple $glyph */ $glyph = new Font_Glyph_Outline_Simple($table, $offset, $size); } else { /** @var Font_Glyph_Outline_Composite $glyph */ $glyph = new Font_Glyph_Outline_Composite($table, $offset, $size); } $glyph->parse(); return $glyph; } /** * @return Font_TrueType */ function getFont() { return $this->table->getFont(); } function __construct(Font_Table_glyf $table, $offset = null, $size = null) { $this->table = $table; $this->offset = $offset; $this->size = $size; } function parse() { $font = $this->getFont(); $font->seek($this->offset); if (!$this->size) { return; } $this->raw = $font->read($this->size); } function parseData(){ $font = $this->getFont(); $font->seek($this->offset); $this->numberOfContours = $font->readInt16(); $this->xMin = $font->readFWord(); $this->yMin = $font->readFWord(); $this->xMax = $font->readFWord(); $this->yMax = $font->readFWord(); } function encode(){ $font = $this->getFont(); return $font->write($this->raw, strlen($this->raw)); } function getSVGContours() { // Inherit } function getGlyphIDs(){ return array(); } } require_once dirname(__FILE__) . "/Font_Glyph_Outline_Simple.php"; require_once dirname(__FILE__) . "/Font_Glyph_Outline_Composite.php"; php-font-lib-0.2.2+dfsg.orig/classes/Font_Glyph_Outline_Component.php 0000644 0000000 0000000 00000001264 12273210464 024332 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $ */ /** * Glyph outline component * * @package php-font-lib */ class Font_Glyph_Outline_Component { public $flags; public $glyphIndex; public $a, $b, $c, $d, $e, $f; public $point_compound; public $point_component; public $instructions; function getMatrix(){ return array( $this->a, $this->b, $this->c, $this->d, $this->e, $this->f, ); } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Glyph_Outline_Composite.php 0000644 0000000 0000000 00000014720 12273210464 024333 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $ */ require_once dirname(__FILE__) . "/Font_Glyph_Outline_Component.php"; /** * Composite glyph outline * * @package php-font-lib */ class Font_Glyph_Outline_Composite extends Font_Glyph_Outline { const ARG_1_AND_2_ARE_WORDS = 0x0001; const ARGS_ARE_XY_VALUES = 0x0002; const ROUND_XY_TO_GRID = 0x0004; const WE_HAVE_A_SCALE = 0x0008; const MORE_COMPONENTS = 0x0020; const WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; const WE_HAVE_A_TWO_BY_TWO = 0x0080; const WE_HAVE_INSTRUCTIONS = 0x0100; const USE_MY_METRICS = 0x0200; const OVERLAP_COMPOUND = 0x0400; /** * @var Font_Glyph_Outline_Component[] */ public $components = array(); function getGlyphIDs(){ if (empty($this->components)) { $this->parseData(); } $glyphIDs = array(); foreach ($this->components as $_component) { $glyphIDs[] = $_component->glyphIndex; $_glyph = $this->table->data[$_component->glyphIndex]; $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); } return $glyphIDs; } /*function parse() { //$this->parseData(); }*/ function parseData(){ parent::parseData(); $font = $this->getFont(); do { $flags = $font->readUInt16(); $glyphIndex = $font->readUInt16(); $a = 1.0; $b = 0.0; $c = 0.0; $d = 1.0; $e = 0.0; $f = 0.0; $point_compound = null; $point_component = null; $instructions = null; if ($flags & self::ARG_1_AND_2_ARE_WORDS) { if ($flags & self::ARGS_ARE_XY_VALUES) { $e = $font->readInt16(); $f = $font->readInt16(); } else { $point_compound = $font->readUInt16(); $point_component = $font->readUInt16(); } } else { if ($flags & self::ARGS_ARE_XY_VALUES) { $e = $font->readInt8(); $f = $font->readInt8(); } else { $point_compound = $font->readUInt8(); $point_component = $font->readUInt8(); } } if ($flags & self::WE_HAVE_A_SCALE) { $a = $d = $font->readInt16(); } elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { $a = $font->readInt16(); $d = $font->readInt16(); } elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { $a = $font->readInt16(); $b = $font->readInt16(); $c = $font->readInt16(); $d = $font->readInt16(); } //if ($flags & self::WE_HAVE_INSTRUCTIONS) { // //} $component = new Font_Glyph_Outline_Component(); $component->flags = $flags; $component->glyphIndex = $glyphIndex; $component->a = $a; $component->b = $b; $component->c = $c; $component->d = $d; $component->e = $e; $component->f = $f; $component->point_compound = $point_compound; $component->point_component = $point_component; $component->instructions = $instructions; $this->components[] = $component; } while ($flags & self::MORE_COMPONENTS); } function encode(){ $font = $this->getFont(); $gids = $font->getSubset(); $size = $font->writeInt16(-1); $size += $font->writeFWord($this->xMin); $size += $font->writeFWord($this->yMin); $size += $font->writeFWord($this->xMax); $size += $font->writeFWord($this->yMax); foreach ($this->components as $_i => $_component) { $flags = 0; if ($_component->point_component === null && $_component->point_compound === null) { $flags |= self::ARGS_ARE_XY_VALUES; if (abs($_component->e) > 0x7F || abs($_component->f) > 0x7F) { $flags |= self::ARG_1_AND_2_ARE_WORDS; } } elseif ($_component->point_component > 0xFF || $_component->point_compound > 0xFF) { $flags |= self::ARG_1_AND_2_ARE_WORDS; } if ($_component->b == 0 && $_component->c == 0) { if ($_component->a == $_component->d) { if ($_component->a != 1.0) { $flags |= self::WE_HAVE_A_SCALE; } } else { $flags |= self::WE_HAVE_AN_X_AND_Y_SCALE; } } else { $flags |= self::WE_HAVE_A_TWO_BY_TWO; } if ($_i < count($this->components)-1) { $flags |= self::MORE_COMPONENTS; } $size += $font->writeUInt16($flags); $new_gid = array_search($_component->glyphIndex, $gids); $size += $font->writeUInt16($new_gid); if ($flags & self::ARG_1_AND_2_ARE_WORDS) { if ($flags & self::ARGS_ARE_XY_VALUES) { $size += $font->writeInt16($_component->e); $size += $font->writeInt16($_component->f); } else { $size += $font->writeUInt16($_component->point_compound); $size += $font->writeUInt16($_component->point_component); } } else { if ($flags & self::ARGS_ARE_XY_VALUES) { $size += $font->writeInt8($_component->e); $size += $font->writeInt8($_component->f); } else { $size += $font->writeUInt8($_component->point_compound); $size += $font->writeUInt8($_component->point_component); } } if ($flags & self::WE_HAVE_A_SCALE) { $size += $font->writeInt16($_component->a); } elseif ($flags & self::WE_HAVE_AN_X_AND_Y_SCALE) { $size += $font->writeInt16($_component->a); $size += $font->writeInt16($_component->d); } elseif ($flags & self::WE_HAVE_A_TWO_BY_TWO) { $size += $font->writeInt16($_component->a); $size += $font->writeInt16($_component->b); $size += $font->writeInt16($_component->c); $size += $font->writeInt16($_component->d); } } return $size; } public function getSVGContours(){ $contours = array(); /** @var Font_Table_glyf $glyph_data */ $glyph_data = $this->getFont()->getTableObject("glyf"); /** @var Font_Glyph_Outline[] $glyphs */ $glyphs = $glyph_data->data; foreach ($this->components as $component) { $contours[] = array( "contours" => $glyphs[$component->glyphIndex]->getSVGContours(), "transform" => $component->getMatrix(), ); } return $contours; } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Glyph_Outline_Simple.php 0000644 0000000 0000000 00000020367 12273210464 023626 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $ */ /** * `glyf` font table. * * @package php-font-lib */ class Font_Glyph_Outline_Simple extends Font_Glyph_Outline { const ON_CURVE = 0x01; const X_SHORT_VECTOR = 0x02; const Y_SHORT_VECTOR = 0x04; const REPEAT = 0x08; const THIS_X_IS_SAME = 0x10; const THIS_Y_IS_SAME = 0x20; public $instructions; public $points; function parseData(){ parent::parseData(); if (!$this->size) { return; } $font = $this->getFont(); $noc = $this->numberOfContours; if ($noc == 0) { return; } $endPtsOfContours = $font->r(array(self::uint16, $noc)); $instructionLength = $font->readUInt16(); $this->instructions = $font->r(array(self::uint8, $instructionLength)); $count = $endPtsOfContours[$noc-1] + 1; // Flags $flags = array(); for ($index = 0; $index < $count; $index++) { $flags[$index] = $font->readUInt8(); if ($flags[$index] & self::REPEAT) { $repeats = $font->readUInt8(); for ($i = 1; $i <= $repeats; $i++) { $flags[$index+$i] = $flags[$index]; } $index += $repeats; } } $points = array(); foreach ($flags as $i => $flag) { $points[$i]["onCurve"] = $flag & self::ON_CURVE; $points[$i]["endOfContour"] = in_array($i, $endPtsOfContours); } // X Coords $x = 0; for($i = 0; $i < $count; $i++) { $flag = $flags[$i]; if ($flag & self::THIS_X_IS_SAME) { if ($flag & self::X_SHORT_VECTOR) { $x += $font->readUInt8(); } } else { if ($flag & self::X_SHORT_VECTOR) { $x -= $font->readUInt8(); } else { $x += $font->readInt16(); } } $points[$i]["x"] = $x; } // Y Coords $y = 0; for($i = 0; $i < $count; $i++) { $flag = $flags[$i]; if ($flag & self::THIS_Y_IS_SAME) { if ($flag & self::Y_SHORT_VECTOR) { $y += $font->readUInt8(); } } else { if ($flag & self::Y_SHORT_VECTOR) { $y -= $font->readUInt8(); } else { $y += $font->readInt16(); } } $points[$i]["y"] = $y; } $this->points = $points; } public function splitSVGPath($path) { preg_match_all('/([a-z])|(-?\d+(?:\.\d+)?)/i', $path, $matches, PREG_PATTERN_ORDER); return $matches[0]; } public function makePoints($path) { $path = $this->splitSVGPath($path); $l = count($path); $i = 0; $points = array(); while($i < $l) { switch($path[$i]) { // moveTo case "M": $points[] = array( "onCurve" => true, "x" => $path[++$i], "y" => $path[++$i], "endOfContour" => false, ); break; // lineTo case "L": $points[] = array( "onCurve" => true, "x" => $path[++$i], "y" => $path[++$i], "endOfContour" => false, ); break; // quadraticCurveTo case "Q": $points[] = array( "onCurve" => false, "x" => $path[++$i], "y" => $path[++$i], "endOfContour" => false, ); $points[] = array( "onCurve" => true, "x" => $path[++$i], "y" => $path[++$i], "endOfContour" => false, ); break; // closePath /** @noinspection PhpMissingBreakStatementInspection */ case "z": $points[count($points)-1]["endOfContour"] = true; default: $i++; break; } } return $points; } function encode(){ if (empty($this->points)) { return parent::encode(); } return $this->size = $this->encodePoints($this->points); } public function encodePoints($points) { $endPtsOfContours = array(); $flags = array(); $coords_x = array(); $coords_y = array(); $last_x = 0; $last_y = 0; $xMin = $yMin = 0xFFFF; $xMax = $yMax = -0xFFFF; foreach($points as $i => $point) { $flag = 0; if ($point["onCurve"]) { $flag |= self::ON_CURVE; } if ($point["endOfContour"]) { $endPtsOfContours[] = $i; } // Simplified, we could do some optimizations if ($point["x"] == $last_x) { $flag |= self::THIS_X_IS_SAME; } else { $x = intval($point["x"]); $xMin = min($x, $xMin); $xMax = max($x, $xMax); $coords_x[] = $x-$last_x; // int16 } // Simplified, we could do some optimizations if ($point["y"] == $last_y) { $flag |= self::THIS_Y_IS_SAME; } else { $y = intval($point["y"]); $yMin = min($y, $yMin); $yMax = max($y, $yMax); $coords_y[] = $y-$last_y; // int16 } $flags[] = $flag; $last_x = $point["x"]; $last_y = $point["y"]; } $font = $this->getFont(); $l = 0; $l += $font->writeInt16(count($endPtsOfContours)); // endPtsOfContours $l += $font->writeFWord(isset($this->xMin) ? $this->xMin : $xMin); // xMin $l += $font->writeFWord(isset($this->yMin) ? $this->yMin : $yMin); // yMin $l += $font->writeFWord(isset($this->xMax) ? $this->xMax : $xMax); // xMax $l += $font->writeFWord(isset($this->yMax) ? $this->yMax : $yMax); // yMax // Simple glyf $l += $font->w(array(self::uint16, count($endPtsOfContours)), $endPtsOfContours); // endPtsOfContours $l += $font->writeUInt16(0); // instructionLength $l += $font->w(array(self::uint8, count($flags)), $flags); // flags $l += $font->w(array(self::int16, count($coords_x)), $coords_x); // xCoordinates $l += $font->w(array(self::int16, count($coords_y)), $coords_y); // yCoordinates return $l; } public function getSVGContours($points = null){ $path = ""; if (!$points) { if (empty($this->points)) { $this->parseData(); } $points = $this->points; } $length = count($points); $firstIndex = 0; $count = 0; for($i = 0; $i < $length; $i++) { $count++; if ($points[$i]["endOfContour"]) { $path .= $this->getSVGPath($points, $firstIndex, $count); $firstIndex = $i + 1; $count = 0; } } return $path; } protected function getSVGPath($points, $startIndex, $count) { $offset = 0; $path = ""; while($offset < $count) { $point = $points[ $startIndex + $offset %$count ]; $point_p1 = $points[ $startIndex + ($offset+1)%$count ]; if($offset == 0) { $path .= "M{$point['x']},{$point['y']} "; } if ($point["onCurve"]) { if ($point_p1["onCurve"]) { $path .= "L{$point_p1['x']},{$point_p1['y']} "; $offset++; } else { $point_p2 = $points[ $startIndex + ($offset+2)%$count ]; if ($point_p2["onCurve"]){ $path .= "Q{$point_p1['x']},{$point_p1['y']},{$point_p2['x']},{$point_p2['y']} "; } else { $path .= "Q{$point_p1['x']},{$point_p1['y']},".$this->midValue($point_p1['x'], $point_p2['x']).",".$this->midValue($point_p1['y'], $point_p2['y'])." "; } $offset += 2; } } else { if ($point_p1["onCurve"]) { $path .= "Q{$point['x']},{$point['y']},{$point_p1['x']},{$point_p1['y']} "; } else { $path .= "Q{$point['x']},{$point['y']},".$this->midValue($point['x'], $point_p1['x']).",".$this->midValue($point['y'], $point_p1['y'])." "; } $offset++; } } $path .= "z "; return $path; } function midValue($a, $b){ return $a + ($b - $a)/2; } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Header.php 0000644 0000000 0000000 00000001311 12273210464 020707 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ /** * Font header container. * * @package php-font-lib */ abstract class Font_Header extends Font_Binary_Stream { /** * @var Font_TrueType */ protected $font; protected $def = array(); public $data; public function __construct(Font_TrueType $font) { $this->font = $font; } public function encode(){ return $this->font->pack($this->def, $this->data); } public function parse(){ $this->data = $this->font->unpack($this->def); } } php-font-lib-0.2.2+dfsg.orig/classes/Font_OpenType.php 0000644 0000000 0000000 00000000764 12273210464 021275 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ require_once dirname(__FILE__) . "/Font_TrueType.php"; require_once dirname(__FILE__) . "/Font_OpenType_Table_Directory_Entry.php"; /** * Open Type font, the same as a TrueType one. * * @package php-font-lib */ class Font_OpenType extends Font_TrueType { // } php-font-lib-0.2.2+dfsg.orig/classes/Font_OpenType_Table_Directory_Entry.php 0000644 0000000 0000000 00000000767 12273210464 025614 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ require_once dirname(__FILE__) . "/Font_TrueType_Table_Directory_Entry.php"; /** * Open Type Table directory entry, the same as a TrueType one. * * @package php-font-lib */ class Font_OpenType_Table_Directory_Entry extends Font_TrueType_Table_Directory_Entry { } php-font-lib-0.2.2+dfsg.orig/classes/Font_Table.php 0000644 0000000 0000000 00000003400 12273210464 020547 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ /** * Generic font table. * * @package php-font-lib */ class Font_Table extends Font_Binary_Stream { /** * @var Font_Table_Directory_Entry */ protected $entry; protected $def = array(); public $data; final public function __construct(Font_Table_Directory_Entry $entry) { $this->entry = $entry; $entry->setTable($this); } /** * @return Font_TrueType */ public function getFont(){ return $this->entry->getFont(); } protected function _encode(){ if (empty($this->data)) { Font::d(" >> Table is empty"); return 0; } return $this->getFont()->pack($this->def, $this->data); } protected function _parse(){ $this->data = $this->getFont()->unpack($this->def); } protected function _parseRaw(){ $this->data = $this->getFont()->read($this->entry->length); } protected function _encodeRaw(){ return $this->getFont()->write($this->data, $this->entry->length); } public function toHTML(){ return "
".var_export($this->data, true).""; } final public function encode(){ $this->entry->startWrite(); if (false && empty($this->def)) { $length = $this->_encodeRaw(); } else { $length = $this->_encode(); } $this->entry->endWrite(); return $length; } final public function parse(){ $this->entry->startRead(); if (false && empty($this->def)) { $this->_parseRaw(); } else { $this->_parse(); } $this->entry->endRead(); } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Table_Directory_Entry.php 0000644 0000000 0000000 00000004661 12273210464 023766 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ /** * Generic Font table directory entry. * * @package php-font-lib */ class Font_Table_Directory_Entry extends Font_Binary_Stream { /** * @var Font_TrueType */ protected $font; /** * @var Font_Table */ protected $font_table; public $entryLength = 4; public $tag; public $checksum; public $offset; public $length; protected $origF; static function computeChecksum($data){ $len = strlen($data); $mod = $len % 4; if ($mod) { $data = str_pad($data, $len + (4 - $mod), "\0"); } $len = strlen($data); $hi = 0x0000; $lo = 0x0000; for ($i = 0; $i < $len; $i += 4) { $hi += (ord($data[$i] ) << 8) + ord($data[$i+1]); $lo += (ord($data[$i+2]) << 8) + ord($data[$i+3]); $hi += $lo >> 16; $lo = $lo & 0xFFFF; $hi = $hi & 0xFFFF; } return ($hi << 8) + $lo; } function __construct(Font_TrueType $font) { $this->font = $font; $this->f = $font->f; } function parse() { $this->tag = $this->font->read(4); } function open($filename, $mode = self::modeRead) { // void } function setTable(Font_Table $font_table) { $this->font_table = $font_table; } function encode($entry_offset){ Font::d("\n==== $this->tag ===="); //Font::d("Entry offset = $entry_offset"); $data = $this->font_table; $font = $this->font; $table_offset = $font->pos(); $this->offset = $table_offset; $table_length = $data->encode(); $font->seek($table_offset); $table_data = $font->read($table_length); $font->seek($entry_offset); $font->write($this->tag, 4); $font->writeUInt32(self::computeChecksum($table_data)); $font->writeUInt32($table_offset); $font->writeUInt32($table_length); Font::d("Bytes written = $table_length"); $font->seek($table_offset + $table_length); } /** * @return Font_TrueType */ function getFont() { return $this->font; } function startRead() { $this->font->seek($this->offset); } function endRead() { // } function startWrite() { $this->font->seek($this->offset); } function endWrite() { // } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Table_cmap.php 0000644 0000000 0000000 00000016126 12273210464 021560 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ /** * `cmap` font table. * * @package php-font-lib */ class Font_Table_cmap extends Font_Table { private static $header_format = array( "version" => self::uint16, "numberSubtables" => self::uint16, ); private static $subtable_header_format = array( "platformID" => self::uint16, "platformSpecificID" => self::uint16, "offset" => self::uint32, ); private static $subtable_v4_format = array( "length" => self::uint16, "language" => self::uint16, "segCountX2" => self::uint16, "searchRange" => self::uint16, "entrySelector" => self::uint16, "rangeShift" => self::uint16, ); protected function _parse(){ $font = $this->getFont(); $cmap_offset = $font->pos(); $data = $font->unpack(self::$header_format); $subtables = array(); for($i = 0; $i < $data["numberSubtables"]; $i++){ $subtables[] = $font->unpack(self::$subtable_header_format); } $data["subtables"] = $subtables; foreach($data["subtables"] as $i => &$subtable) { $font->seek($cmap_offset + $subtable["offset"]); $subtable["format"] = $font->readUInt16(); // @todo Only CMAP version 4 if($subtable["format"] != 4) { unset($data["subtables"][$i]); $data["numberSubtables"]--; continue; } $subtable += $font->unpack(self::$subtable_v4_format); $segCount = $subtable["segCountX2"] / 2; $subtable["segCount"] = $segCount; $endCode = $font->r(array(self::uint16, $segCount)); $font->readUInt16(); // reservedPad $startCode = $font->r(array(self::uint16, $segCount)); $idDelta = $font->r(array(self::int16, $segCount)); $ro_start = $font->pos(); $idRangeOffset = $font->r(array(self::uint16, $segCount)); $glyphIndexArray = array(); for($i = 0; $i < $segCount; $i++) { $c1 = $startCode[$i]; $c2 = $endCode[$i]; $d = $idDelta[$i]; $ro = $idRangeOffset[$i]; if($ro > 0) $font->seek($subtable["offset"] + 2 * $i + $ro); for($c = $c1; $c <= $c2; $c++) { if ($ro == 0) $gid = ($c + $d) & 0xFFFF; else { $offset = ($c - $c1) * 2 + $ro; $offset = $ro_start + 2 * $i + $offset; $font->seek($offset); $gid = $font->readUInt16(); if ($gid != 0) $gid = ($gid + $d) & 0xFFFF; } if($gid > 0) { $glyphIndexArray[$c] = $gid; } } } $subtable += array( "endCode" => $endCode, "startCode" => $startCode, "idDelta" => $idDelta, "idRangeOffset" => $idRangeOffset, "glyphIndexArray" => $glyphIndexArray, ); } $this->data = $data; } function _encode(){ $font = $this->getFont(); $subset = $font->getSubset(); $glyphIndexArray = $font->getUnicodeCharMap(); $newGlyphIndexArray = array(); foreach ($glyphIndexArray as $code => $gid) { $new_gid = array_search($gid, $subset); if ($new_gid !== false) { $newGlyphIndexArray[$code] = $new_gid; } } ksort($newGlyphIndexArray); // Sort by char code $segments = array(); $i = -1; $prevCode = 0xFFFF; $prevGid = 0xFFFF; foreach($newGlyphIndexArray as $code => $gid) { if ( $prevCode + 1 != $code || $prevGid + 1 != $gid ) { $i++; $segments[$i] = array(); } $segments[$i][] = array($code, $gid); $prevCode = $code; $prevGid = $gid; } $segments[][] = array(0xFFFF, 0xFFFF); $startCode = array(); $endCode = array(); $idDelta = array(); foreach($segments as $codes){ $start = reset($codes); $end = end($codes); $startCode[] = $start[0]; $endCode[] = $end[0]; $idDelta[] = $start[1] - $start[0]; } $segCount = count($startCode); $idRangeOffset = array_fill(0, $segCount, 0); $searchRange = 1; $entrySelector = 0; while ($searchRange * 2 <= $segCount) { $searchRange *= 2; $entrySelector++; } $searchRange *= 2; $rangeShift = $segCount * 2 - $searchRange; $subtables = array( array( // header "platformID" => 3, // Unicode "platformSpecificID" => 1, "offset" => null, // subtable "format" => 4, "length" => null, "language" => 0, "segCount" => $segCount, "segCountX2" => $segCount * 2, "searchRange" => $searchRange, "entrySelector" => $entrySelector, "rangeShift" => $rangeShift, "startCode" => $startCode, "endCode" => $endCode, "idDelta" => $idDelta, "idRangeOffset" => $idRangeOffset, "glyphIndexArray" => $newGlyphIndexArray, ) ); $data = array( "version" => 0, "numberSubtables" => count($subtables), "subtables" => $subtables, ); $length = $font->pack(self::$header_format, $data); $subtable_headers_size = $data["numberSubtables"] * 8; // size of self::$subtable_header_format $subtable_headers_offset = $font->pos(); $length += $font->write(str_repeat("\0", $subtable_headers_size), $subtable_headers_size); // write subtables data foreach($data["subtables"] as $i => $subtable) { $length_before = $length; $data["subtables"][$i]["offset"] = $length; $length += $font->writeUInt16($subtable["format"]); $before_subheader = $font->pos(); $length += $font->pack(self::$subtable_v4_format, $subtable); $segCount = $subtable["segCount"]; $length += $font->w(array(self::uint16, $segCount), $subtable["endCode"]); $length += $font->writeUInt16(0); // reservedPad $length += $font->w(array(self::uint16, $segCount), $subtable["startCode"]); $length += $font->w(array(self::int16, $segCount), $subtable["idDelta"]); $length += $font->w(array(self::uint16, $segCount), $subtable["idRangeOffset"]); $length += $font->w(array(self::uint16, $segCount), array_values($subtable["glyphIndexArray"])); $after_subtable = $font->pos(); $subtable["length"] = $length - $length_before; $font->seek($before_subheader); $length += $font->pack(self::$subtable_v4_format, $subtable); $font->seek($after_subtable); } // write subtables headers $font->seek($subtable_headers_offset); foreach($data["subtables"] as $subtable) { $font->pack(self::$subtable_header_format, $subtable); } return $length; } } php-font-lib-0.2.2+dfsg.orig/classes/Font_Table_glyf.php 0000644 0000000 0000000 00000007736 12273210464 021610 0 ustar root root * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ require_once dirname(__FILE__) . "/Font_Glyph_Outline.php"; /** * `glyf` font table. * * @package php-font-lib * @property Font_Glyph_Outline[] $data */ class Font_Table_glyf extends Font_Table { protected function _parse(){ $font = $this->getFont(); $offset = $font->pos(); $loca = $font->getData("loca"); $real_loca = array_slice($loca, 0, -1); // Not the last dummy loca entry $data = array(); foreach($real_loca as $gid => $location) { $_offset = $offset + $loca[$gid]; $_size = $loca[$gid+1] - $loca[$gid]; $data[$gid] = Font_Glyph_Outline::init($this, $_offset, $_size); } $this->data = $data; } public function getGlyphIDs($gids = array()){ $glyphIDs = array(); foreach ($gids as $_gid) { $_glyph = $this->data[$_gid]; $glyphIDs = array_merge($glyphIDs, $_glyph->getGlyphIDs()); } return array_unique(array_merge($gids, $glyphIDs)); } public function toHTML(){ $max = 160; $font = $this->getFont(); $head = $font->getData("head"); $head_json = json_encode($head); $os2 = $font->getData("OS/2"); $os2_json = json_encode($os2); $hmtx = $font->getData("hmtx"); $hmtx_json = json_encode($hmtx); $names = $font->getData("post", "names"); $glyphIndexArray = array_flip($font->getUnicodeCharMap()); $width = (abs($head["xMin"]) + $head["xMax"]); $height = (abs($head["yMin"]) + $head["yMax"]); $ratio = 1; if ($width > $max || $height > $max) { $ratio = max($width, $height) / $max; $width = round($width/$ratio); $height = round($height/$ratio); } $n = 500; $s = "