summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2013-05-13 10:59:47 +0200
committerRemi Collet <fedora@famillecollet.com>2013-05-13 10:59:47 +0200
commit86ac8706f1ec6303db8e2610fac1d3dd075a51aa (patch)
tree9c0757ed77d082d4a9245c05211de60312cfeb57
parentf6c0c43d004b2a4bf813ec3fcd406f1fe5aec42d (diff)
php-tcpdf: update to 6.0.013, use available system TTF fonts
-rw-r--r--php-tcpdf.spec68
-rw-r--r--php-tcpdf_sysfonts.patch54
-rw-r--r--tcpdf_addfont.php78
3 files changed, 194 insertions, 6 deletions
diff --git a/php-tcpdf.spec b/php-tcpdf.spec
index b1f9059..a26473e 100644
--- a/php-tcpdf.spec
+++ b/php-tcpdf.spec
@@ -1,21 +1,40 @@
-%global dl_version 6_0_012
+%global dl_version 6_0_013
%global real_name tcpdf
Name: php-tcpdf
Summary: PHP class for generating PDF documents
-Version: 6.0.012
-Release: 3%{?dist}
+Version: 6.0.013
+Release: 1%{?dist}
-Source0: http://downloads.sourceforge.net/%{real_name}/%{real_name}_%{dl_version}.zip
URL: http://www.tcpdf.org
License: LGPLv3+
Group: Development/Libraries
-Patch0: php-tcpdf_badpath.patch
-Patch1: php-tcpdf_config.patch
+Source0: http://downloads.sourceforge.net/%{real_name}/%{real_name}_%{dl_version}.zip
+Source1: %{real_name}_addfont.php
+
+Patch0: %{name}_badpath.patch
+Patch1: %{name}_config.patch
+# https://sourceforge.net/p/tcpdf/patches/63/ - allow to use system fonts
+Patch2: %{name}_sysfonts.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
+BuildRequires: php-cli
+BuildRequires: dejavu-lgc-sans-fonts
+BuildRequires: dejavu-lgc-sans-mono-fonts
+BuildRequires: dejavu-lgc-serif-fonts
+BuildRequires: dejavu-sans-fonts
+BuildRequires: dejavu-sans-mono-fonts
+BuildRequires: dejavu-serif-fonts
+%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6
+BuildRequires: gnu-free-mono-fonts
+BuildRequires: gnu-free-sans-fonts
+BuildRequires: gnu-free-serif-fonts
+%else
+BuildRequires: freefont
+%endif
+
Requires: php(language) >= 5.2
Requires: php-openssl
@@ -33,6 +52,20 @@ Requires: php-pcre
Requires: php-posix
Requires: php-tidy
Requires: php-xml
+# System fonts
+Requires: dejavu-lgc-sans-fonts
+Requires: dejavu-lgc-sans-mono-fonts
+Requires: dejavu-lgc-serif-fonts
+Requires: dejavu-sans-fonts
+Requires: dejavu-sans-mono-fonts
+Requires: dejavu-serif-fonts
+%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6
+Requires: gnu-free-mono-fonts
+Requires: gnu-free-sans-fonts
+Requires: gnu-free-serif-fonts
+%else
+Requires: freefont
+%endif
%description
@@ -82,6 +115,7 @@ solution. You can optionally install php-pecl-imagick; TCPDF will use it.
%setup -qn %{real_name}
%patch0 -p1 -b .badpath
%patch1 -p1 -b .config
+%patch2 -p1 -b .sysfonts
: globally fix permissions, always broken...
find ./ -type d -exec chmod 755 {} \;
@@ -163,6 +197,23 @@ cp -a config/*.php $RPM_BUILD_ROOT%{_sysconfdir}/%{name}
install -d $RPM_BUILD_ROOT%{_localstatedir}/cache/%{name}
install -m 0644 README.cache $RPM_BUILD_ROOT%{_localstatedir}/cache/%{name}/README
+# Tools
+install -d $RPM_BUILD_ROOT%{_bindir}
+install -m 0755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/%{real_name}_addfont.php
+sed -e '/include/s|tcpdf.php|tcpdf/tcpdf.php|' \
+ -i $RPM_BUILD_ROOT%{_bindir}/%{real_name}_addfont.php
+
+# Fonts
+php %{SOURCE1} \
+ /usr/share/fonts/dejavu/*ttf \
+%if 0%{?fedora} >= 11 || 0%{?rhel} >= 6
+ /usr/share/fonts/gnu-free/*ttf \
+%else
+ /usr/share/fonts/freefont/*ttf \
+%endif
+ --link \
+ --out $RPM_BUILD_ROOT%{_datadir}/php/%{real_name}/fonts
+
%post
# We don't want to require "httpd" in case PHP is used with some other web
@@ -191,6 +242,7 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%doc LICENSE.TXT README.TXT CHANGELOG.TXT doc/* examples
+%{_bindir}/%{real_name}_addfont.php
%{_datadir}/php/%{real_name}
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/*
@@ -198,6 +250,10 @@ rm -rf $RPM_BUILD_ROOT
%changelog
+* Mon May 13 2013 Remi Collet <remi@fedoraproject.org> - 6.0.013-1
+- update to 6.0.013
+- use available system TTF fonts
+
* Sun May 10 2013 Johan Cwiklinski <johan AT x-tnd DOT be> - 6.0.012-3
- Fix README.cache file permissions
diff --git a/php-tcpdf_sysfonts.patch b/php-tcpdf_sysfonts.patch
new file mode 100644
index 0000000..1a847bc
--- /dev/null
+++ b/php-tcpdf_sysfonts.patch
@@ -0,0 +1,54 @@
+--- tcpdf/include/tcpdf_fonts.php.prev 2013-05-13 09:43:35.000000000 +0200
++++ tcpdf/include/tcpdf_fonts.php 2013-05-13 09:48:19.000000000 +0200
+@@ -57,12 +57,13 @@
+ * @param $platid (int) Platform ID for CMAP table to extract (when building a Unicode font for Windows this value should be 3, for Macintosh should be 1).
+ * @param $encid (int) Encoding ID for CMAP table to extract (when building a Unicode font for Windows this value should be 1, for Macintosh should be 0). When Platform ID is 3, legal values for Encoding ID are: 0=Symbol, 1=Unicode, 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab, 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
+ * @param $addcbbox (boolean) If true includes the character bounding box information on the php font file.
++ * @param $link (boolean) If true link to system font instead of copying the font data (not transportable).
+ * @return (string) TCPDF font name.
+ * @author Nicola Asuni
+ * @since 5.9.123 (2010-09-30)
+ * @public static
+ */
+- public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false) {
++ public static function addTTFfont($fontfile, $fonttype='', $enc='', $flags=32, $outpath='', $platid=3, $encid=1, $addcbbox=false, $link=false) {
+ if (!file_exists($fontfile)) {
+ // Could not find file
+ return false;
+@@ -92,7 +93,7 @@
+ // this font already exist (delete it from fonts folder to rebuild it)
+ return $font_name;
+ }
+- $fmetric['file'] = $font_name.'.z';
++ $fmetric['file'] = $font_name;
+ $fmetric['ctg'] = $font_name.'.ctg.z';
+ // get font data
+ $font = file_get_contents($fontfile);
+@@ -178,6 +179,7 @@
+ $encrypted = substr($font, (12 + $fmetric['size1']), $fmetric['size2']);
+ $data .= $encrypted;
+ // store compressed font
++ $fmetric['file'] .= '.z';
+ $fp = fopen($outpath.$fmetric['file'], 'wb');
+ fwrite($fp, gzcompress($data));
+ fclose($fp);
+@@ -347,10 +349,15 @@
+ } else {
+ // ---------- TRUE TYPE ----------
+ if ($fmetric['type'] != 'cidfont0') {
+- // store compressed font
+- $fp = fopen($outpath.$fmetric['file'], 'wb');
+- fwrite($fp, gzcompress($font));
+- fclose($fp);
++ if ($link) {
++ symlink($fontfile, $outpath.$fmetric['file']);
++ } else {
++ $fmetric['file'] .= '.z';
++ // store compressed font
++ $fp = fopen($outpath.$fmetric['file'], 'wb');
++ fwrite($fp, gzcompress($font));
++ fclose($fp);
++ }
+ }
+ $offset = 0; // offset position of the font data
+ if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
diff --git a/tcpdf_addfont.php b/tcpdf_addfont.php
new file mode 100644
index 0000000..5ea76a5
--- /dev/null
+++ b/tcpdf_addfont.php
@@ -0,0 +1,78 @@
+#!/usr/bin/php
+<?php
+
+include "tcpdf.php";
+
+function help() {
+ echo "usage ".$_SERVER['argv'][0]." [ options ] fontfile [ fontfile ... ]\n";
+
+ echo "\noptions:\n";
+ echo "\t-t\n\t--type TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT\n";
+ echo "\t-o\n\t--out Output path\n";
+ echo "\t-l\n\t--link Create link to original font (not a copy)\n";
+}
+
+$fontfiles = array();
+$type = '';
+$out = K_PATH_FONTS;
+$enc = '';
+$flags = 32;
+$platid = 3;
+$encid = 1;
+$addcbbox = false;
+$link = false;
+
+$args = $_SERVER['argv'];
+array_shift($args);
+
+while (count($args)) {
+ $arg = array_shift($args);
+ switch ($arg) {
+ case "-h":
+ case "--help":
+ help();
+ exit(0);
+ break;
+
+ case "-t":
+ case "--type":
+ if (count($args)) {
+ $type = array_shift($args);
+ } else {
+ die("Missing value for --type\n");
+ }
+ break;
+
+ case '-o':
+ case '--out':
+ if (count($args)) {
+ $out = realpath(array_shift($args)).'/';
+ } else {
+ die("Missing value for --out\n");
+ }
+ break;
+
+ case '-l':
+ case '--link':
+ $link = true;
+ break;
+
+ default:
+ if ($arg[0]=='-') {
+ die("unkown option $arg\n");
+ }
+ $fontfiles[] = $arg;
+ }
+}
+if (!is_dir($out) || !is_writable($out)) {
+ die("Can't write to $out\n");
+}
+echo "Output dir set to $out\n";
+if (count($fontfiles)) {
+ foreach ($fontfiles as $fontfile) {
+ $fontname = TCPDF_FONTS::addTTFfont($fontfile, $type, $enc, $flags, $out, $platid, $encid, $addcbbox, true);
+ echo "$fontfile added as $fontname\n";
+ }
+} else {
+ die("Missing fontfile (try --help for usage)\n");
+}