debian/0000755000000000000000000000000012322556410007166 5ustar debian/control0000644000000000000000000000346012322556367010607 0ustar Source: djview4 Section: graphics Priority: optional Maintainer: Ubuntu Developers XSBC-Original-Maintainer: Barak A. Pearlmutter Build-Depends: debhelper (>= 9), autotools-dev, dh-autoreconf, pkg-config, libdjvulibre-dev (>= 3.5.20), x11proto-core-dev, libx11-dev, libxext-dev, libxt-dev, libglib2.0-dev, libqt4-dev (>= 4.4), libqt4-opengl-dev (>= 4.4), libtiff5-dev | libtiff4-dev | libtiff3g-dev | libtiff-dev, netpbm, librsvg2-bin, imagemagick Vcs-Git: git://anonscm.debian.org/collab-maint/djview4.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/djview4.git Homepage: http://djvu.sourceforge.net/ Standards-Version: 3.9.4 Package: djview4 Architecture: any Provides: djvu-viewer Conflicts: djview (<= 3.5.20-5) Depends: ${shlibs:Depends}, ${misc:Depends} Recommends: djvulibre-desktop Suggests: djvulibre-bin, djview-plugin Description: Viewer for the DjVu image format DjVu viewer djview. Package: djview-plugin Section: web Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, djview4 | djview3 Provides: djvulibre-plugin Enhances: chromium-browser, mozilla-browser, mozilla, firefox, iceweasel, iceape-browser, konqueror, rekonq, galeon Recommends: chromium-browser | mozilla-browser | mozilla | firefox | iceweasel | iceape-browser | konqueror | galeon Suggests: mime-support Conflicts: djvulibre-bin (<< 3.5.19), djvulibre-plugin (<= 3.5.23-4) Description: Browser plugin for the DjVu image format DjVu browser plugin. Package: djvulibre-plugin Section: web Architecture: all Depends: ${shlibs:Depends}, ${misc:Depends}, djview-plugin Description: Transition package, djvulibre-plugin to djview-plugin Dummy dependency package to transition from djvulibre-plugin to djview-plugin. debian/djview-plugin.install0000644000000000000000000000006512226226647013354 0ustar usr/lib/*/plugins/*.so usr/share/man/man*/nsdejavu.* debian/djview4.menu0000644000000000000000000000040712226226646011441 0ustar ?package(djview4):needs="X11" \ section="Applications/Viewers" \ title="DjView4" command="/usr/bin/djview4" \ icon="/usr/share/icons/hicolor/32x32/apps/djvulibre-djview4.xpm" \ icon32x32="/usr/share/icons/hicolor/32x32/apps/djvulibre-djview4.xpm" debian/rules0000755000000000000000000000213012322555272010247 0ustar #!/usr/bin/make -f override_dh_auto_configure: dh_auto_configure -- --disable-desktopfiles icon=djvulibre-djview4 iconbasedir=debian/tmp/usr/share/icons/hicolor plugsubdir=mozilla/plugins plug=$(plugsubdir)/nsdejavu.so override_dh_auto_install: dh_auto_install -- \ plugindir=/usr/lib/$(plugsubdir) \ DESTDIR=$(CURDIR)/debian/tmp @echo "flush djview links, handled with debian alternatives system" rm debian/tmp/usr/bin/djview rm debian/tmp/usr/share/man/man1/djview.* @echo "install djview4 icons" mkdir --parents $(iconbasedir)/scalable/apps mkdir --parents $(iconbasedir)/32x32/apps mkdir --parents $(iconbasedir)/64x64/apps cp desktopfiles/hi-djview4.svgz \ $(iconbasedir)/scalable/apps/$(icon).svgz pngtopnm < desktopfiles/hi32-djview4.png \ | ppmtoxpm > $(iconbasedir)/32x32/apps/$(icon).xpm pngtopnm < desktopfiles/hi64-djview4.png \ | ppmtoxpm > $(iconbasedir)/64x64/apps/$(icon).xpm override_dh_installchangelogs: dh_installchangelogs NEWS override_dh_makeshlibs: dh_makeshlibs --version-info --exclude=/plugins %: dh $@ --with autotools_dev,autoreconf --parallel debian/djview4.postinst0000644000000000000000000000041112226226646012353 0ustar #! /bin/sh set -e case "$1" in configure) update-alternatives --quiet \ --install /usr/bin/djview djview /usr/bin/djview4 40 \ --slave \ /usr/share/man/man1/djview.1.gz djview.1.gz \ /usr/share/man/man1/djview4.1.gz ;; esac #DEBHELPER# debian/watch0000644000000000000000000000006312226226646010226 0ustar version=3 http://sf.net/djvu/djview4-(.*)\.tar\.gz debian/djview4.prerm0000644000000000000000000000021512226226647011620 0ustar #! /bin/sh set -e case "$1" in remove|deconfigure) update-alternatives --quiet --remove djview /usr/bin/djview4 ;; esac #DEBHELPER# debian/compat0000644000000000000000000000000212226226647010375 0ustar 9 debian/djview4.mime0000644000000000000000000000053612226226646011427 0ustar image/vnd.djvu; /usr/bin/djview4 %s; test=test -n "$DISPLAY"; description=DjVu file; nametemplate=%s.djvu; priority=6 image/x.djvu; /usr/bin/djview4 %s; test=test -n "$DISPLAY"; description=DjVu file; nametemplate=%s.djvu; priority=6 image/x-djvu; /usr/bin/djview4 %s; test=test -n "$DISPLAY"; description=DjVu file; nametemplate=%s.djvu; priority=6 debian/djview4.docs0000644000000000000000000000001012226226647011414 0ustar README* debian/djview4.install0000644000000000000000000000031112226226647012136 0ustar usr/bin/djview4 usr/share/man/*/djview4.* usr/share/djvu usr/share/icons debian/djvulibre-djview4.xpm usr/share/icons/hicolor/32x32/apps/ desktopfiles/djvulibre-djview4.desktop usr/share/applications/ debian/copyright0000644000000000000000000000575612226226647011147 0ustar This package was debianized by Barak Pearlmutter on Tue, 16 Jan 2007 20:01:58 -0500. It was downloaded from http://djvu.sourceforge.net/ git://djvu.git.sourceforge.net/gitroot/djvu/djview.git Upstream Authors: Leon Bottou Copyright: DjView4, Copyright (c) 2006-2008 Leon Bottou This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, either version 2 of the license or (at your option) any later version. This program depends on the DjVuLibre library. Starting with version 3.5.19, DjVuLibre is released under the GNU General Public License, either version 2 or (at your option) any later version. Prior to version 3.5.19, DjVuLibre was released under the GNU General Public License, version 2. On Debian GNU/Linux systems, the complete text of the GNU General Public License version 2 can be found in `/usr/share/common-licenses/GPL-2'. == Upstream copyright remarks: == In directory nsdejavu/npsdk, the source distribution contains files extracted from the Mozilla project. These files are available under the Mozilla Public License version 1.1 with permission to redistribute under either the GNU General Public License version 2 or the GNU Library General Public License version 2.1. These files are NOT USED for the compilation of the program djview4 under Debian. ==================================================================== Remark1: This program depends on the DjVuLibre library. Starting with version 3.5.19, DjVuLibre is released under the GNU General Public License, either version 2 or (at your option) any later version. Prior to version 3.5.19, DjVuLibre was released under the GNU General Public License, version 2. Remark2: Part of this software is derived from 'tiff2pdf' which comes with the following notice: | Copyright (c) 2003 Ross Finlayson | | Permission to use, copy, modify, distribute, and sell this software and | its documentation for any purpose is hereby granted without fee, provided | that (i) the above copyright notices and this permission notice appear in | all copies of the software and related documentation, and (ii) the name of | Ross Finlayson may not be used in any advertising or | publicity relating to the software without the specific, prior written | permission of Ross Finlayson. | | THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, | EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY | WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | | IN NO EVENT SHALL ROSS FINLAYSON BE LIABLE FOR | ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, | OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF | LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | OF THIS SOFTWARE. debian/source/0000755000000000000000000000000012226226647010477 5ustar debian/source/include-binaries0000644000000000000000000000003512226226647013635 0ustar debian/djvulibre-djview4.xpm debian/source/format0000644000000000000000000000001412226226647011705 0ustar 3.0 (quilt) debian/patches/0000755000000000000000000000000012322555140010614 5ustar debian/patches/debian-changes0000644000000000000000000061253512226226647013415 0ustar Description: TODO: Put a short summary on the line above and replace this paragraph with a longer explanation of this change. Complete the meta-information with other relevant fields (see below for details). To make it easier, the information below has been extracted from the changelog. Adjust it or drop it. . djview4 (4.9-4) unstable; urgency=low . * bump policy version (no changes needed) * clean some icons generated during build (closes: #679921) * update debian packaging repo urls to current naming scheme * the upstream changelog is called NEWS Author: Barak A. Pearlmutter Bug-Debian: http://bugs.debian.org/679921 --- The information above should follow the Patch Tagging Guidelines, please checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here are templates for supplementary fields that you might want to add: Origin: , Bug: Bug-Debian: http://bugs.debian.org/ Bug-Ubuntu: https://launchpad.net/bugs/ Forwarded: Reviewed-By: Last-Update: --- djview4-4.9.orig/src/djview.pro +++ djview4-4.9/src/djview.pro @@ -18,7 +18,7 @@ TEMPLATE = app TARGET = djview CONFIG += qt thread warn_on -QT += network +QT += network opengl # -- find libraries CONFIG(autoconf) { @@ -29,17 +29,13 @@ CONFIG(autoconf) { # QMAKE_CXXFLAGS += ... # QMAKE_CFLAGS += ... # QMAKE_LFLAGS += ... -} else:unix:!macx { - # for use under unix with pkgconfig - CONFIG += link_pkgconfig - PKGCONFIG += ddjvuapi } else { - # for use on other platforms - # LIBS += -ldjvulibre - # QMAKE_CXXFLAGS += ... (c++ flags) - # QMAKE_CFLAGS += ... (c flags) - # QMAKE_LFLAGS += ... (link flags) - # DEFINES += ... (definitions) + # customize below + LIBS += -ldjvulibre + #QMAKE_CXXFLAGS += + #QMAKE_CFLAGS += + #QMAKE_LFLAGS += + #DEFINES += } --- djview4-4.9.orig/src/qdjviewprefs.cpp +++ djview4-4.9/src/qdjviewprefs.cpp @@ -148,6 +148,7 @@ QDjViewPrefs::QDjViewPrefs(void) invertLuminance(false), mouseWheelZoom(false), restrictOverride(false), + openGLAccel(false), modifiersForLens(Qt::ControlModifier|Qt::ShiftModifier), modifiersForSelect(Qt::ControlModifier), modifiersForLinks(Qt::ShiftModifier), @@ -360,6 +361,8 @@ QDjViewPrefs::load() languageOverride = s.value("language").toString(); if (s.contains("restrictOverride")) restrictOverride = s.value("restrictOverride").toBool(); + if (s.contains("openGLAccel")) + openGLAccel = s.value("openGLAccel").toBool(); if (s.contains("modifiersForLens")) modifiersForLens = stringToModifiers(s.value("modifiersForLens").toString()); @@ -455,6 +458,7 @@ QDjViewPrefs::save(void) s.setValue("modifiersForLinks", modifiersToString(modifiersForLinks)); s.setValue("language", languageOverride); s.setValue("restrictOverride", restrictOverride); + s.setValue("openGLAccel", openGLAccel); s.setValue("thumbnailSize", thumbnailSize); s.setValue("thumbnailSmart", thumbnailSmart); @@ -944,6 +948,7 @@ QDjViewPrefsDialog::load(QDjView *djview d->ui.animationCheckBox->setChecked(prefs->enableAnimations); d->ui.textLabelCheckBox->setChecked(prefs->showTextLabel); d->ui.restrictOverrideCheckBox->setChecked(prefs->restrictOverride); + d->ui.openGLCheckBox->setChecked(prefs->openGLAccel); d->ui.printerManualCheckBox->setChecked(pgamma > 0); d->ui.printerGammaSpinBox->setValue((pgamma > 0) ? pgamma : 2.2); // no longer modified @@ -976,9 +981,10 @@ QDjViewPrefsDialog::loadLanguageComboBox { QString nlang = languages[i]; QString xlang = QString::null; - QTranslator *trans = new QTranslator(); - if (app->loadTranslator(trans, "djview", QStringList(nlang))) - xlang = trans->translate("Generic", thisLang[0].src); + QTranslator *dTrans = new QTranslator(); + QTranslator *qTrans = new QTranslator(); + if (app->loadTranslators(QStringList(nlang), dTrans, qTrans)) + xlang = dTrans->translate("Generic", thisLang[0].src); else if (nlang == "en" || nlang.startsWith("en")) xlang = "English"; if (lang == nlang && xlang.size() > 0) @@ -987,7 +993,8 @@ QDjViewPrefsDialog::loadLanguageComboBox index = cb->count(); if (xlang.size() > 0) cb->addItem(xlang, nlang); - delete trans; + delete dTrans; + delete qTrans; } db->setChecked(index >= 0 && lang.size() > 0); cb->setCurrentIndex(index); @@ -1043,6 +1050,7 @@ QDjViewPrefsDialog::apply() prefs->advancedFeatures = d->ui.advancedCheckBox->isChecked(); prefs->showTextLabel = d->ui.textLabelCheckBox->isChecked(); prefs->restrictOverride = d->ui.restrictOverrideCheckBox->isChecked(); + prefs->openGLAccel = d->ui.openGLCheckBox->isChecked(); prefs->printerGamma = 0; if (d->ui.printerManualCheckBox->isChecked()) prefs->printerGamma = d->ui.printerGammaSpinBox->value(); @@ -1088,14 +1096,16 @@ QDjViewPrefsDialog::reset() d->ui.lensSizeSpinBox->setValue(300); // 5- network tab d->ui.proxyCheckBox->setChecked(false); - // 6- advanced tab d->ui.pixelCacheSpinBox->setValue(1); d->ui.pageCacheSpinBox->setValue(10); + // 6- advanced tab d->ui.languageCheckBox->setChecked(false); - d->ui.printerManualCheckBox->setChecked(false); - d->ui.printerGammaSpinBox->setValue(2.2); + d->ui.animationCheckBox->setChecked(true); d->ui.advancedCheckBox->setChecked(false); d->ui.textLabelCheckBox->setChecked(false); + d->ui.openGLCheckBox->setChecked(false); + d->ui.printerManualCheckBox->setChecked(false); + d->ui.printerGammaSpinBox->setValue(2.2); } --- djview4-4.9.orig/src/qdjviewprefs.h +++ djview4-4.9/src/qdjviewprefs.h @@ -155,6 +155,7 @@ public: bool mouseWheelZoom; //!< Mouse wheel zooms instead of scroll. QString languageOverride; //!< Language settings bool restrictOverride; //!< Override noprint/nosave + bool openGLAccel; //!< Use opengl acceleration Qt::KeyboardModifiers modifiersForLens; //!< Keys for the lens. Qt::KeyboardModifiers modifiersForSelect; //!< Keys for selecting. Qt::KeyboardModifiers modifiersForLinks; //!< Keys for showing the links. --- djview4-4.9.orig/src/qdjvuwidget.h +++ djview4-4.9/src/qdjvuwidget.h @@ -165,6 +165,8 @@ public: QDjVuWidget(QWidget *parent=0); QDjVuWidget(QDjVuDocument *doc, QWidget *parent=0); + QDjVuWidget(bool opengl, QWidget *parent=0); + QDjVuWidget(QDjVuDocument *doc, bool opengl, QWidget *parent=0); QDjVuDocument *document(void) const; int page(void) const; --- djview4-4.9.orig/src/djview.h +++ djview4-4.9/src/djview.h @@ -46,7 +46,7 @@ class QDjViewApplication : public QAppli QDjViewApplication(int &argc, char **argv); QDjVuContext *djvuContext() { return &context; } QDjView *newWindow(); - bool loadTranslator(QTranslator *trans, QString name, QStringList langs); + bool loadTranslators(QStringList langs, QTranslator *dt, QTranslator *qt); protected: bool event(QEvent *ev); #ifdef Q_WS_X11 --- djview4-4.9.orig/src/djview_fr.ts +++ djview4-4.9/src/djview_fr.ts @@ -4,7 +4,7 @@ Generic - + thisLanguage Name of THIS language Français @@ -850,74 +850,74 @@ - + DjView DjView - + Cannot open file '%1'. Impossible d'ouvrir le fichier «%1». - + Cannot open URL '%1'. Impossible d'ouvrir l'URL «%1». - + Certificate validation error - DjView dialog caption Erreur de validation du certificat - DjView - + <html> %1 Do you want to continue anyway? </html> <html> %1 Voulez-vous continuer tout-de-même? </html> - + Cannot find page numbered: %1 Impossible de trouver la page numérotée «%1» - - + + Cannot find page named: %1 Impossible de trouver la page nommée «%1» - + Unrecognized sidebar options '%1'. L'option de panneau latéral «%1» n'est pas reconnue. - + <html> This file was served with printing restrictions. Do you want to print it anyway?</html> <html> This file was served with printing restrictions.Do you want to print it anyway?</html> <html>Ce fichier est servi avec une restriction d'impression. Voulez-vous l'imprimer quand même?</html> - + <html> This file was served with saving restrictions. Do you want to save it anyway?</html> <html> This file was served with saving restrictions.Do you want to save it anyway?</html> <html>Ce fichier est servi avec une restriction de sauvegarde. Voulez vous le sauver quand même?</html> - + Cannot determine file format. Filename '%1' has no suffix. Impossible de déterminer le format du fichier. Le nom «%1» n'a pas de suffixe. - + Image format %1 not supported. Le format de fichier image «%1» n'est pas supporté. - - + + Cannot write file '%1'. %2. Impossible d'écrire le fichier «%1». @@ -939,27 +939,27 @@ Le nom «%1» n'a pas de suffixe.Recherche - + Cannot decode page %1. Impossible de décoder la page «%1». - + Cannot decode document. Impossible de décoder le document. - + x=%1 y=%2 x=%1 y=%2 - + %3x%4+%1+%2 %3x%4+%1+%2 - + Go: %n pages forward. Avancer de %n page. @@ -967,7 +967,7 @@ Le nom «%1» n'a pas de suffixe. - + Go: %n pages backward. Reculer de %n page. @@ -975,59 +975,59 @@ Le nom «%1» n'a pas de suffixe. - + Go: page %1. Aller page %1. - + Go: %1 Link: %1 Aller à %1 - + Cannot resolve link '%1' Impossible d'interpréter le lien «%1» - + Cannot spawn a browser for url '%1' Impossible de lancer un navigateur pour l'URL «%1» - + Copy text (%1) Copier le texte (%1) - + Save text as... Enregistrer le texte... - + Copy image (%1x%2 pixels) Copier l'image (%1x%2) - + Save image as... Enregistrer l'image... - + Zoom to rectangle Zoomer sur ce rectangle - + About DjView À propos de DjView - + DjVu files Fichiers DjVu @@ -1042,7 +1042,7 @@ Le nom «%1» n'a pas de suffixe.Montre les informations sur l'encodage du document et sa structure. - + (in other window.) (dans une autre fenêtre.) @@ -1077,85 +1077,85 @@ Le nom «%1» n'a pas de suffixe.<html><b>Méta informations sur le document et la page.</b><br> Affiche un panneau montrant les informations supplémentaires qui se rapportent au document ou à une de ses pages.</html> - + Opening DjVu file Ouverture de fichier DjVu - + Opening DjVu document Ouverture de document DjVu - - + + Print - DjView dialog caption Imprimer - DjView - - + + Save - DjView dialog caption Sauver - DjView - + Text files save filter Fichiers texte - - + + All files save filter Tous les fichiers - + Save Text - DjView dialog caption Sauver le texte - DjView - - - + + + Error - DjView dialog caption Erreur - DjView - + Save Image - DjView dialog caption Enregistrement de l'image - DjView - + Decoding DjVu document Décodage de document DjVu - + P%1/%2 %3x%4 %5dpi P%1/%2 %3x%4 %5dpi - + <html><h2>DjVuLibre DjView %1</h2>%2<p>Viewer for DjVu documents<br><a href=%3>%3</a><br>Copyright © 2006-- Léon Bottou.</p><p align=justify><small>This program is free software. You can redistribute or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed <i>without any warranty</i>. See the GNU General Public License for more details.</small></p></html> <html><h2>DjVuLibre DjView %1</h2>%2<p>Afficheur pour documents DjVu<br><a href=%3>%3</a><br>Copyright © 2006-- Léon Bottou.</p><p align=justify><small>Ce programme est un logiciel libre. Vous pouvez le redistribuer ou le modifier au titre des clauses de la «GNU General Public License», telle que publiée par la Free Software Foundation. Ce programme est distribué <i>sans aucune garantie</i>. Voir la «GNU General Public License» pour plus de détails.</small></p></html> - + Information - DjView dialog caption Information - DjView - + Metadata - DjView dialog caption Meta-information - DjView @@ -1172,7 +1172,7 @@ Le nom «%1» n'a pas de suffixe.Exporte la page ou le document DjVu sous un autre format. - + Export - DjView dialog caption Export - DjView @@ -1195,7 +1195,7 @@ Le nom «%1» n'a pas de suffixe.Ouvrir un Fichier &Récent - + &Clear History &Effacer l'historique @@ -1253,18 +1253,18 @@ Le nom «%1» n'a pas de suffixe.Ctrl+F5 - + Open Location - DjView dialog caption Ouverture d'une URL - DjView - + Enter the URL of a DjVu document: Entrez l'URL d'un document DjVu: - + Open - DjView dialog caption Ouverture - DjView @@ -1288,13 +1288,13 @@ Le nom «%1» n'a pas de suffixe.Ligne d'é&tat - + %1 files (*.%2);; save image filter Fichiers %1 (*.%2) - + %n characters %n caractère @@ -1302,12 +1302,12 @@ Le nom «%1» n'a pas de suffixe. - + Go: 1 page forward. Avancer de 1 page. - + Go: 1 page backward. Reculer de 1 page. @@ -1335,47 +1335,47 @@ Le nom «%1» n'a pas de suffixe.Copie les &Annotations - + Copy text into the clipboard. Copie le texte correspondant à la sélection. - + Save text into a file. Enregistre le texte correspondant à la sélection dans un fichier. - + Copy image into the clipboard. Copie une image correspondant à la sélection. - + Save image into a file. Enregistre une image correspondant à la sélection dans un fichier. - + Zoom the selection to fit the window. Change le grossissement de façon à maximiser la sélection dans la fenêtre. - + Copy URL Copie l'URL - + Save into the clipboard an URL that highlights the selection. Copie une URL qui monte la page courante et met en valeur la sélection. - + Copy Maparea Copie la «Maparea» - + Save into the clipboard a maparea annotation expression for program djvused. Copie une directive d'annotation «maparea» correspondant à la sélection. @@ -1442,7 +1442,7 @@ Le nom «%1» n'a pas de suffixe.Affiche les pages de droite à gauche en mode côte-à-côte. - + All files Tous les fichiers @@ -1525,54 +1525,54 @@ Options fréquentes: QDjViewDjVuExporter - + Question - DjView dialog caption Question - DjView - + <html> This file belongs to a non empty directory. Saving an indirect document creates many files in this directory. Do you want to continue and risk overwriting files in this directory?</html> <html> Ce fichier appartient à un répertoire qui n'est pas vide. La sauvegarde d'un document DjVu indirect crée de nombreux fichiers dans ce répertoire. Voulez-vous continuer et prendre le risque de remplacer des fichiers dans ce répertoire?</html> - + Con&tinue Con&tinuer - + &Cancel &Annuler - + Save job creation failed! L'operation d'enregistrement a échoué! - + Unknown error. Erreur inconnue. - + System error: %1. Erreur système: %1. - + DjVu Bundled Document Document DjVu «bundled» - - + + DjVu Files (*.djvu *.djv) Fichiers DjVu (*.djvu *.djv) - + DjVu Indirect Document Document DjVu «indirect» @@ -2148,23 +2148,23 @@ Voulez-vous le remplacer? QDjViewImgExporter - + Cannot render page. Impossible de dessiner la page. - + Image format %1 not supported. Le format de fichier image «%1» n'est pas supporté. - + %1 Image JPG Image Images %1 - + %1 Files (*.%2) JPG Files Fichiers %1 (*.%2) @@ -2449,56 +2449,56 @@ Voulez-vous le remplacer? QDjViewPSExporter - + PostScript tab caption PostScript - + Position tab caption Position - + Booklet tab caption Fascicule - + <html><b>Producing booklets.</b><br>The booklet mode prints the selected pages as sheets suitable for folding one or several booklets. Several booklets might be produced when a maximum number of sheets per booklet is specified. You can either use a duplex printer or print rectos and versos separately.<p> Shifting rectos and versos is useful with poorly aligned duplex printers. The center margins determine how much space is left between the pages to fold the sheets. This space slowly increases from the inner sheet to the outer sheet.</html> <html><b>Production de fascicules.</b><br>Le mode fascicule permet d'imprimer des feuillets à plier en un ou plusieurs fascicules. Plusieurs fascicules sont nécessaires lorsqu'un nombre maximum de feuillets est spécifié. Vous pouvez utiliser une imprimante recto-verso ou imprimer séparément les rectos et les versos<p> Décaler les versos est utile pour les imprimantes recto-versos mal alignées. La marge centrale peut être modifiée et augmente lors de la progression du feuillet intérieur vers le feuillet extérieur.</html> - + Save job creation failed! L'operation d'enregistrement a échoué! - + <html><b>PostScript options.</b><br>Option <tt>Color</tt> enables color printing. Document pages can be decorated with frame and crop marks. PostScript language level 1 is only useful with very old printers. Level 2 works with most printers. Level 3 print color document faster on recent printers.</html> <html><b>Options PostScript.</b><br>L'option <tt>Couleur</tt> autorise l'impression en couleur. Les pages imprimées peuvent être décorées avec un cadre ou des marques de découpage. Le niveau PostScript 1 est utile pour les très vieilles imprimantes. Le niveau 2 fonctionne avec la plupart des imprimantes en service. Le niveau 3 imprime les documents en couleur plus rapidement sur des imprimantes récentes.</html> - + <html><b>Position and scaling.</b><br>Option <tt>Scale to fit</tt> accommodates whatever paper size your printer uses. Zoom factor <tt>100%</tt> reproduces the initial document size. Orientation <tt>Automatic</tt> chooses portrait or landscape on a page per page basis.</html> <html><b>Position and aggrandissement.</b><br>L'option <tt>Agrandir à la page</tt> choisit un grossissement adapté a la taille de papier utilisée par votre imprimante. Le facteur de grossissement <tt>100%</tt> reproduit la taille originale du document. L'orientation <tt>Automatique</tt> sélectionne portrait ou paysage en fonction de la taille de chaque page.</html> - + PostScript PostScript - - + + PostScript Files (*.ps *.eps) Fichiers PostScript (*.ps *.eps) - + Encapsulated PostScript PostScript Encapsulé @@ -2506,54 +2506,54 @@ Voulez-vous le remplacer? QDjViewPdfExporter - + PDF Document Document PDF - + PDF Files (*.pdf) Fichiers PDF (*.pdf) - + PDF Options tab caption Options PDF - + <html><b>PDF options.</b><br>These options control the characteristics of the images embedded in the exported PDF files. The resolution box limits their maximal resolution. Forcing bitonal G4 compression encodes all pages in black and white using the CCITT Group 4 compression. Allowing JPEG compression uses lossy JPEG for all non bitonal or subsampled images. Otherwise, allowing deflate compression produces more compact files. </html> <html><b>Options PDF.</b><br>Ces options s'appliquent aux images encapsulées dans les fichiers PDF exportés. La boite de résolution spécifie leur résolution maximale. Forcer la compression bitonale G4 encode toutes les pages en noir et blanc avec la compression CCITT Groupe 4. Autoriser la compression JPEG utilise JPEG pour toutes les images en niveaux de gris ou en couleurs. Sinon, autoriser la compression «deflate» produit des fichiers plus compacts.</html> - + Error while creating pdf file. Erreur pendant la création du fichier PDF. - + PDF export was not compiled. L'exportation de fichiers PDF n'a pas été compilée. - + Unable to create output file. Impossible de créer le fichier de sortie. - - + + System error: %1. Erreur système: %1. - + Unable to reopen temporary file. Impossible de réouvrir le fichier temporaire. - + Unable to create temporary file. Impossible de créer le fichier temporaire. @@ -2841,62 +2841,67 @@ Voulez-vous le remplacer? + Render with openGL when available + Utiliser openGL losrque c'est possible. + + + Override saving and printing restrictions Outrepasse les restrictions d'impression et de sauvegarde - + &Defaults &Défaults - + &Apply &Appliquer - + &Ok &Ok - + Cancel Annuler - + Preferences[*] - DjView Préférences[*] - DjView - + <html><b>Initial interface setup.</b><br>DjView can run as a standalone viewer, as a full screen viewer, as a full page browser plugin, or as a plugin embedded inside a html page. For each case, check the <tt>Remember</tt> box to automatically save and restore the interface setup. Otherwise, specify an initial configuration.</html> <html><b>Configuration initiale.</b><br>DjView peut fonctionner comme application normale, comme application plein-écran, comme plugin pleine-page, ou plugin en ligne dans une page web. Dans chaque cas, sélectionnez l'option <tt>Mémoriser...</tt> pour retenir la dernière configuration utilisée dans ce mode. Sinon, spécifiez les détails de la configuration initiale desirée.</html> - + <html><b>Modifiers keys.</b><br>Define which combination of modifier keys will show the manifying lens, temporarily enable the selection mode, or highlight the hyperlinks.</html> <html><b>Touches spéciales.</b><br>Definissez quelles combinaisons de touches spéciales seront affectées à la loupe, à la selection de texte et d;images, et à l'affichage temporaire des liens.</html> - + <html><b>Magnifying lens.</b><br>The magnifying lens appears when you depress the modifier keys specified in tab <tt>Keys</tt>. This panel lets you choose the power and the size of the magnifying lens.</html> <html><b>Loupe.</b><br>La loupe apparaît lorsque vous maintenez les touches spéciales définies dans l'onglet <tt>Touches</tt>. Ce panneau vous permet d'en spécifier la taille et le grossissement.</html> - + <html><b>Advanced.</b><br>You can override the default interface language, disable the page animations, or enable additional menu entries that are useful for authoring DjVu files.You can also disable the printing or saving restrictions dictated by certain web sites. The manual color correction can be useful with old printers.</html> <html><p><b>Advanced.</b>You can override the default interface language, disable the page animations, or enable additional menu entries that are useful for authoring DjVu files.You can also disable the printing or saving restrictions dictated by certain web sites. The manual color correction can be useful with old printers.</html> <html><b>Options avancées</b><br>Vous pouvez changer la langue de l'interface, supprimer les animations, ou dévoiler des entrées de menus supplémentaires utiles pour la création de documents DjVu. Vous pouvez également ignorer les restrictions d'impression et de sauvegarde spécifiées par le site web. La correction manuelle des couleurs d'impression peut être utile avec certaines vieilles imprimantes.</html> - + <html><b>Network proxy settings.</b><br>These proxy settings are used when the standalone djview viewer accesses a djvu document through a http url. The djview plugin always uses the proxy settings of the web browser.<p><b>Cache settings.</b><br>The <i>pixel cache</i> stores image data located outside the visible area. This cache makes panning smoother. The <i>decoded page cache</i> contains partially decoded pages. It provides faster response times when navigating a multipage document or when returning to a previously viewed page. Clearing this cache might be useful to reflect a change in the page data without restarting the DjVu viewer.</html> <html><b>Options du réseau.</b><br>Ce panneau permet de définir un proxy utilisé pour atteindre un document DjVu distant avec le protocole réseau HTTP. Ces options sont ignorées lorsque le programme fonctionne en mode plugin: les accès réseaux utilisent alors les options du navigateur hôte.<p><b>Caches.</b><br>Le <i>cache de pixels</i> contient des portions d'images situées en limite de la zone visible. Il permet des défilements plus fluides. Le <i>cache de page décodées</i> contient des pages partiellement décodées. Il permet de parcourir plus rapidement des documents à pages multiples. Effacer ce cache peut être utile pour prendre en compte un fichier modifié sans redemarrer l'application.</html> - + <html><b>Screen gamma correction.</b><br>The best color rendition is achieved by adjusting the gamma correction slider and choosing the position that makes the gray square as uniform as possible.<p><b>Screen resolution.</b><br>This option forces a particular resolution instead of using the unreliable resolution advertised by the operating system. Forcing the resolution to 100 dpi matches the behavior of the djvulibre command line tools.</html> <html><b>Correction de couleur pour l'écran.</b><br>Le meilleur rendu est obtenu en ajustant le potentiomètre de façon à rendre les niveaux de gris de la mire aussi proches que possible.<p><b>Résolution de l'écran.</b><br>Forcer une résolution particulière est utile quand le système donne une résolution qui ne correspond pas à la réalité. Forcer une résolution de 100dpi rend l'affichage compatible avec les programmes utilitaires de DjVuLibre.</html> @@ -2926,12 +2931,12 @@ Voulez-vous le remplacer? Divers - + Manual printer color correction Correction manuelle de couleur d'impression - + gamma= gamma= @@ -3017,7 +3022,7 @@ Voulez-vous le remplacer? - + &Cancel &Annuler @@ -3027,17 +3032,17 @@ Voulez-vous le remplacer? Stop - + This operation has failed. Cette opération a échoué. - + This operation has been interrupted. Cette opération a été interrompue. - + <html><b>Printing.</b><br/> You can print the whole document or a page range. Use the <tt>Choose</tt> button to select a print destination and specify printer options. Additional dialog tabs might appear to specify conversion options.</html> <html><b>Impression.</b><br/> Vous pouvez imprimer le document entier ou un intervalle de pages. Utilisez le bouton <tt>Choisir</tt> pour selectionner une destination d'impression. Des onglets supplémentaires peuvent apparaître pour spécifier des options de conversion adaptées à l'imprimante.</html> @@ -3062,37 +3067,37 @@ Voulez-vous le remplacer? Choisir - + All files save filter Tous les fichiers - + Print To File - DjView dialog caption Imprimer vers un fichier - DjView - + Question - DjView dialog caption Question - DjView - + A file with this name already exists. Do you want to replace it? Ce fichier existe déjà. Voulez-vous le remplacer? - + &Replace &Remplacer - + (invalid printer) (imprimante invalide) @@ -3100,28 +3105,28 @@ Voulez-vous le remplacer? QDjViewPrnExporter - + Printer data Données d'impression - + PRN Files (*.prn) Fichiers PRN (*.prn) - + Printing Options tab caption Options d'impression - + <html><b>Printing options.</b><br>Option <tt>Color</tt> enables color printing. Document pages can be decorated with a frame. Option <tt>Scale to fit</tt> accommodates whatever paper size your printer uses. Zoom factor <tt>100%</tt> reproduces the initial document size. Orientation <tt>Automatic</tt> chooses portrait or landscape on a page per page basis.</html> <html><b>Options d'impression.</b><br>L'option <tt>Couleur</tt> autorise l'impression en couleur. Les pages imprimées peuvent être décorées avec un cadre. L'option <tt>Agrandir à la page</tt> choisit un grossissement adapté a la taille de papier utilisée par votre imprimante. Le facteur de grossissement <tt>100%</tt> reproduit la taille originale du document. L'orientation <tt>Automatique</tt> sélectionne portrait ou paysage en fonction de la taille de chaque page.</html> - + Cannot render page %1. Impossible de dessiner la page «%1». @@ -3302,43 +3307,43 @@ Voulez-vous le remplacer? QDjViewTiffExporter - + TIFF Options tab caption Options TIFF - + Cannot open output file. Impossible d'ouvrir le fichier destination. - + Out of memory. Mémoire pleine. - + TIFF export has not been compiled. L'exportation de fichier TIFF n'est pas compilée. - + Internal error. Erreur interne. - + TIFF Document Documents TIFF - + TIFF Files (*.tiff *.tif) Fichiers TIFF (*.tiff *.tif) - + <html><b>TIFF options.</b><br>The resolution box specifies an upper limit for the resolution of the TIFF images. Forcing bitonal G4 compression encodes all pages in black and white using the CCITT Group 4 compression. Allowing JPEG compression uses lossy JPEG for all non bitonal or subsampled images. Otherwise, allowing deflate compression produces more compact (but less portable) files than the default packbits compression.</html> <html><b>Options TIFF.</b><br>La boite de résolution spécifie la résolution maximale de chaque image dans le fichier TIFF. Forcer la compression bitonale G4 encode toutes les pages en noir et blanc avec la compression CCITT Groupe 4. Autoriser la compression JPEG utilise JPEG pour toutes les images en niveaux de gris ou en couleurs. Sinon, autoriser la compression «deflate» produit des fichiers plus compacts (mais moins portables) que la compression par défaut «packbits».</html> --- djview4-4.9.orig/src/tiff2pdf.c +++ djview4-4.9/src/tiff2pdf.c @@ -14,78 +14,199 @@ //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //C- GNU General Public License for more details. //C- ------------------------------------------------------------------ +// +// The following code is derived from program "tiff2pdf" +// whose copyright notice is reproduced below. +// Changes were made to make it independent from the private +// include file tiffiop.h. */ -/* The following code is derived from program "tiff2pdf" - * whose copyright notice is reproduced below. - * Changes were made to make it independent from the private - * include file tiffiop.h. + +/* $Id: tiff2pdf.c,v 1.37.2.7 2009-01-01 00:10:43 bfriesen Exp $ + * + * tiff2pdf - converts a TIFF image to a PDF document * - * +-------------------------------------------------------------------- - * | tiff2pdf - converts a TIFF image to a PDF document - * | - * | Copyright (c) 2003 Ross Finlayson - * | - * | Permission to use, copy, modify, distribute, and sell this software and - * | its documentation for any purpose is hereby granted without fee, provided - * | that (i) the above copyright notices and this permission notice appear in - * | all copies of the software and related documentation, and (ii) the name of - * | Ross Finlayson may not be used in any advertising or - * | publicity relating to the software without the specific, prior written - * | permission of Ross Finlayson. - * | - * | THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * | EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * | WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * | - * | IN NO EVENT SHALL ROSS FINLAYSON BE LIABLE FOR - * | ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, - * | OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * | WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF - * | LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * | OF THIS SOFTWARE. - * +-------------------------------------------------------------------- + * Copyright (c) 2003 Ross Finlayson + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Ross Finlayson may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Ross Finlayson. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL ROSS FINLAYSON BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. */ #include "tiff2pdf.h" -#if HAVE_TIFF2PDF +#ifdef HAVE_TIFF2PDF #include #include #include #include #include + #if HAVE_UNISTD_H # include #endif -#ifndef NULL -# define NULL ((void*)0) + +#ifdef HAVE_FCNTL_H +# include #endif -#ifdef __GNUC__ -# define unused __attribute__((unused)) +#if defined(__GNUC__) || defined(HAVE_LONG_LONG_INT) +# define uint64 unsigned long long +#elif defined(_MSC_VER) +# define uint64 unsigned __int64 #else -# define unused /**/ +# define uint64 size_t +#endif + +#ifdef WIN32 +/* + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +static int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +static char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +static int +getopt(int argc, char * const argv[], const char *optstring) +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || *place == 0) { /* update scanning pointer */ + optreset = 0; + place = argv[optind]; + if (optind >= argc || *place++ != '-') { + /* Argument is absent or is not an option */ + place = EMSG; + return (-1); + } + optopt = *place++; + if (optopt == '-' && *place == 0) { + /* "--" => end of options */ + ++optind; + place = EMSG; + return (-1); + } + if (optopt == 0) { + /* Solitary '-', treat as a '-' option + if the program (eg su) is looking for it. */ + place = EMSG; + if (strchr(optstring, '-') == NULL) + return -1; + optopt = '-'; + } + } else + optopt = *place++; + + /* See if option letter is one the caller wanted... */ + if (optopt == ':' || (oli = strchr(optstring, optopt)) == NULL) { + if (*place == 0) + ++optind; + if (opterr && *optstring != ':') + (void)fprintf(stderr, + "unknown option -- %c\n", optopt); + return (BADCH); + } + + /* Does this option need an argument? */ + if (oli[1] != ':') { + /* don't need argument */ + optarg = NULL; + if (*place == 0) + ++optind; + } else { + /* Option-argument is either the rest of this argument or the + entire next argument. */ + if (*place) + optarg = place; + else if (argc > ++optind) + optarg = argv[optind]; + else { + /* option-argument absent */ + place = EMSG; + if (*optstring == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "option requires an argument -- %c\n", + optopt); + return (BADCH); + } + place = EMSG; + ++optind; + } + return (optopt); /* return option letter */ +} #endif -/* -------------------------------------------------- * - Tiff2Pdf declarations - * -------------------------------------------------- */ #define TIFF2PDF_MODULE "tiff2pdf" -#define T2P_VERSION "d" + +#define PS_UNIT_SIZE 72.0F /* This type is of PDF color spaces. */ -typedef enum{ - T2P_CS_BILEVEL=0x01, /* Bilevel, black and white */ - T2P_CS_GRAY=0x02, /* Single channel */ - T2P_CS_RGB=0x04, /* Three channel tristimulus RGB */ - T2P_CS_CMYK=0x08, /* Four channel CMYK print inkset */ - T2P_CS_LAB=0x10, /* Three channel L*a*b* color space */ - T2P_CS_PALETTE=0x1000 /* One of the above with a color map */ - , T2P_CS_CALGRAY=0x20 /* Calibrated single channel */ - , T2P_CS_CALRGB=0x40 /* Calibrated three channel tristimulus RGB */ - , T2P_CS_ICCBASED=0x80 /* ICC profile color specification */ +typedef enum { + T2P_CS_BILEVEL = 0x01, /* Bilevel, black and white */ + T2P_CS_GRAY = 0x02, /* Single channel */ + T2P_CS_RGB = 0x04, /* Three channel tristimulus RGB */ + T2P_CS_CMYK = 0x08, /* Four channel CMYK print inkset */ + T2P_CS_LAB = 0x10, /* Three channel L*a*b* color space */ + T2P_CS_PALETTE = 0x1000,/* One of the above with a color map */ + T2P_CS_CALGRAY = 0x20, /* Calibrated single channel */ + T2P_CS_CALRGB = 0x40, /* Calibrated three channel tristimulus RGB */ + T2P_CS_ICCBASED = 0x80 /* ICC profile color specification */ } t2p_cs_t; /* This type is of PDF compression types. */ @@ -181,9 +302,6 @@ typedef struct { uint16 tiff_orientation; toff_t tiff_dataoffset; tsize_t tiff_datasize; - TIFFReadWriteProc tiff_readproc; - TIFFReadWriteProc tiff_writeproc; - TIFFSeekProc tiff_seekproc; uint16 tiff_resunit; uint16 pdf_centimeters; uint16 pdf_overrideres; @@ -208,13 +326,13 @@ typedef struct { uint32 pdf_palettecs; uint16 pdf_fitwindow; uint32 pdf_startxref; - char* pdf_fileid; - char* pdf_datetime; - char* pdf_creator; - char* pdf_author; - char* pdf_title; - char* pdf_subject; - char* pdf_keywords; + unsigned char* pdf_fileid; + unsigned char* pdf_datetime; + unsigned char* pdf_creator; + unsigned char* pdf_author; + unsigned char* pdf_title; + unsigned char* pdf_subject; + unsigned char* pdf_keywords; t2p_cs_t pdf_colorspace; uint16 pdf_colorspace_invert; uint16 pdf_switchdecode; @@ -247,12 +365,10 @@ typedef struct { uint32 tiff_iccprofilelength; tdata_t tiff_iccprofile; - /* LB additional fields */ - FILE *outputfile; - int outputdisable; - tsize_t outputwritten; - - + /* fields for custom read/write procedures */ + FILE *outputfile; + int outputdisable; + tsize_t outputwritten; } T2P; /* These functions are called by main. */ @@ -261,10 +377,19 @@ static int tiff2pdf_match_paper_size(flo /* These functions are used to generate a PDF from a TIFF. */ +#ifdef __cplusplus +extern "C" { +#endif + static T2P* t2p_init(void); static void t2p_validate(T2P*); static tsize_t t2p_write_pdf(T2P*, TIFF*, TIFF*); static void t2p_free(T2P*); + +#ifdef __cplusplus +} +#endif + static void t2p_read_tiff_init(T2P*, TIFF*); static int t2p_cmp_t2p_page(const void*, const void*); static void t2p_read_tiff_data(T2P*, TIFF*); @@ -272,6 +397,8 @@ static void t2p_read_tiff_size(T2P*, TIF static void t2p_read_tiff_size_tile(T2P*, TIFF*, ttile_t); static int t2p_tile_is_right_edge(T2P_TILES, ttile_t); static int t2p_tile_is_bottom_edge(T2P_TILES, ttile_t); +/* static int t2p_tile_is_edge(T2P_TILES, ttile_t); */ +/* static int t2p_tile_is_corner_edge(T2P_TILES, ttile_t); */ static tsize_t t2p_readwrite_pdf_image(T2P*, TIFF*, TIFF*); static tsize_t t2p_readwrite_pdf_image_tile(T2P*, TIFF*, TIFF*, ttile_t); #ifdef OJPEG_SUPPORT @@ -291,7 +418,8 @@ static tsize_t t2p_sample_lab_signed_to_ static tsize_t t2p_write_pdf_header(T2P*, TIFF*); static tsize_t t2p_write_pdf_obj_start(uint32, TIFF*); static tsize_t t2p_write_pdf_obj_end(TIFF*); -static tsize_t t2p_write_pdf_string(char*, TIFF*); +/* static tsize_t t2p_write_pdf_name(unsigned char*, TIFF*); */ +static tsize_t t2p_write_pdf_string(unsigned char*, TIFF*); static tsize_t t2p_write_pdf_stream(tdata_t, tsize_t, TIFF*); static tsize_t t2p_write_pdf_stream_start(TIFF*); static tsize_t t2p_write_pdf_stream_end(TIFF*); @@ -308,6 +436,8 @@ static tsize_t t2p_write_pdf_page(uint32 static void t2p_compose_pdf_page(T2P*); static void t2p_compose_pdf_page_orient(T2P_BOX*, uint16); static void t2p_compose_pdf_page_orient_flip(T2P_BOX*, uint16); +/* static tsize_t t2p_write_pdf_page_content(T2P*, TIFF*); */ +static tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t, T2P*, TIFF*); static tsize_t t2p_write_pdf_xobject_cs(T2P*, TIFF*); static tsize_t t2p_write_pdf_transfer(T2P*, TIFF*); static tsize_t t2p_write_pdf_transfer_dict(T2P*, TIFF*, uint16); @@ -316,280 +446,142 @@ static tsize_t t2p_write_pdf_xobject_cal static tsize_t t2p_write_pdf_xobject_icccs(T2P*, TIFF*); static tsize_t t2p_write_pdf_xobject_icccs_dict(T2P*, TIFF*); static tsize_t t2p_write_pdf_xobject_icccs_stream(T2P*, TIFF*); +/* static tsize_t t2p_write_pdf_xobject_cs_stream(T2P*, TIFF*); */ static tsize_t t2p_write_pdf_xobject_decode(T2P*, TIFF*); static tsize_t t2p_write_pdf_xobject_stream_filter(ttile_t, T2P*, TIFF*); static tsize_t t2p_write_pdf_xreftable(T2P*, TIFF*); static tsize_t t2p_write_pdf_trailer(T2P*, TIFF*); - - -/* -------------------------------------------------- * - Replacement for tiffiop functions - * -------------------------------------------------- */ - - -static unused tsize_t -t2pReadFile(TIFF *tif, tdata_t data, tsize_t size) +static void +t2p_disable(TIFF *tif) { - thandle_t client = TIFFClientdata(tif); - TIFFReadWriteProc proc = TIFFGetReadProc(tif); - if (proc) - return proc(client, data, size); - return -1; + T2P *t2p = (T2P*) TIFFClientdata(tif); + t2p->outputdisable = 1; } -static unused tsize_t -t2pWriteFile(TIFF *tif, tdata_t data, tsize_t size) +static void +t2p_enable(TIFF *tif) { - thandle_t client = TIFFClientdata(tif); - TIFFReadWriteProc proc = TIFFGetWriteProc(tif); - if (proc) - return proc(client, data, size); - return -1; + T2P *t2p = (T2P*) TIFFClientdata(tif); + t2p->outputdisable = 0; } +/* + * Procs for TIFFClientOpen + */ -static unused toff_t -t2pSeekFile(TIFF *tif, toff_t offset, int whence) +static tsize_t +t2pReadFile(TIFF *tif, tdata_t data, tsize_t size) { - thandle_t client = TIFFClientdata(tif); - TIFFSeekProc proc = TIFFGetSeekProc(tif); - if (proc) - return proc(client, offset, whence); - return -1; + thandle_t client = TIFFClientdata(tif); + TIFFReadWriteProc proc = TIFFGetReadProc(tif); + if (proc) + return proc(client, data, size); + return -1; } -#ifdef TIFFReadFile -# undef TIFFReadFile -#endif -#ifndef TIFFReadFile -# define TIFFReadFile t2pReadFile -#endif - -#ifdef TIFFWriteFile -# undef TIFFWriteFile -#endif -#ifndef TIFFWriteFile -# define TIFFWriteFile t2pWriteFile -#endif - -#ifdef TIFFSeekFile -# undef TIFFSeekFile -#endif -#ifndef TIFFSeekFile -# define TIFFSeekFile t2pSeekFile -#endif - - -static void -t2p_disable(TIFF *tif) +static tsize_t +t2pWriteFile(TIFF *tif, tdata_t data, tsize_t size) { - T2P *t2p = (T2P*) TIFFClientdata(tif); - t2p->outputdisable = 1; + thandle_t client = TIFFClientdata(tif); + TIFFReadWriteProc proc = TIFFGetWriteProc(tif); + if (proc) + return proc(client, data, size); + return -1; } -static void -t2p_enable(TIFF *tif) +static toff_t +t2pSeekFile(TIFF *tif, toff_t offset, int whence) { - T2P *t2p = (T2P*) TIFFClientdata(tif); - t2p->outputdisable = 0; + thandle_t client = TIFFClientdata(tif); + TIFFSeekProc proc = TIFFGetSeekProc(tif); + if (proc) + return proc(client, offset, whence); + return -1; } - - -/* -------------------------------------------------- * - Procs for TIFFClientOpen - * -------------------------------------------------- */ - static tsize_t -t2p_readproc(thandle_t unused handle, tdata_t unused data , tsize_t unused size) -{ - return -1; +t2p_readproc(thandle_t handle, tdata_t data, tsize_t size) +{ + (void) handle, (void) data, (void) size; + return -1; } static tsize_t t2p_writeproc(thandle_t handle, tdata_t data, tsize_t size) { - T2P *t2p = (T2P*) handle; - if (t2p->outputdisable <= 0 && t2p->outputfile) - { - tsize_t written = fwrite(data, 1, size, t2p->outputfile); - t2p->outputwritten += written; - return written; - } - return size; + T2P *t2p = (T2P*) handle; + if (t2p->outputdisable <= 0 && t2p->outputfile) { + tsize_t written = fwrite(data, 1, size, t2p->outputfile); + t2p->outputwritten += written; + return written; + } + return size; } static toff_t t2p_seekproc(thandle_t handle, toff_t offset, int whence) { - T2P *t2p = (T2P*) handle; - if (t2p->outputdisable <= 0 && t2p->outputfile) - return fseek(t2p->outputfile, offset, whence); - return offset; + T2P *t2p = (T2P*) handle; + if (t2p->outputdisable <= 0 && t2p->outputfile) + return fseek(t2p->outputfile, offset, whence); + return offset; } static int -t2p_closeproc(thandle_t unused handle) +t2p_closeproc(thandle_t handle) { - return 0; + (void) handle; + return 0; } static toff_t -t2p_sizeproc(thandle_t unused handle) -{ - return -1; +t2p_sizeproc(thandle_t handle) +{ + (void) handle; + return -1; } static int -t2p_mapproc(thandle_t unused handle, tdata_t unused *data, toff_t unused *offset) +t2p_mapproc(thandle_t handle, tdata_t *data, toff_t *offset) { - return -1; + (void) handle, (void) data, (void) offset; + return -1; } static void -t2p_unmapproc(thandle_t unused handle, tdata_t unused data, toff_t unused offset) +t2p_unmapproc(thandle_t handle, tdata_t data, toff_t offset) { + (void) handle, (void) data, (void) offset; } - - -/* -------------------------------------------------- * - Ports - * -------------------------------------------------- */ - -#ifdef WIN32 -/* - * Copyright (c) 1987, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; -__RCSID("$NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $"); -#endif - -#include -#include - -int opterr = 1, /* if error message should be printed */ - optind = 1, /* index into parent argv vector */ - optopt, /* character checked for validity */ - optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -/* - * getopt -- - * Parse argc/argv argument vector. - */ -int -getopt(int argc, char * const argv[], const char *optstring) +static uint64 +checkAdd64(uint64 summand1, uint64 summand2, T2P* t2p) { - static char *place = EMSG; /* option letter processing */ - char *oli; /* option letter list index */ - - if (optreset || *place == 0) { /* update scanning pointer */ - optreset = 0; - place = argv[optind]; - if (optind >= argc || *place++ != '-') { - /* Argument is absent or is not an option */ - place = EMSG; - return (-1); - } - optopt = *place++; - if (optopt == '-' && *place == 0) { - /* "--" => end of options */ - ++optind; - place = EMSG; - return (-1); - } - if (optopt == 0) { - /* Solitary '-', treat as a '-' option - if the program (eg su) is looking for it. */ - place = EMSG; - if (strchr(optstring, '-') == NULL) - return -1; - optopt = '-'; - } - } else - optopt = *place++; + uint64 bytes = summand1 + summand2; - /* See if option letter is one the caller wanted... */ - if (optopt == ':' || (oli = strchr(optstring, optopt)) == NULL) { - if (*place == 0) - ++optind; - if (opterr && *optstring != ':') - (void)fprintf(stderr, - "unknown option -- %c\n", optopt); - return (BADCH); + if (bytes - summand1 != summand2) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; + bytes = 0; } - /* Does this option need an argument? */ - if (oli[1] != ':') { - /* don't need argument */ - optarg = NULL; - if (*place == 0) - ++optind; - } else { - /* Option-argument is either the rest of this argument or the - entire next argument. */ - if (*place) - optarg = place; - else if (argc > ++optind) - optarg = argv[optind]; - else { - /* option-argument absent */ - place = EMSG; - if (*optstring == ':') - return (BADARG); - if (opterr) - (void)fprintf(stderr, - "option requires an argument -- %c\n", - optopt); - return (BADCH); - } - place = EMSG; - ++optind; - } - return (optopt); /* return option letter */ + return bytes; } -#endif - - +static uint64 +checkMultiply64(uint64 first, uint64 second, T2P* t2p) +{ + uint64 bytes = first * second; -/* -------------------------------------------------- * - Main function - * -------------------------------------------------- */ + if (second && bytes / second != first) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; + bytes = 0; + } + return bytes; +} /* @@ -663,23 +655,21 @@ getopt(int argc, char * const argv[], co options: -o: output to file name - -j compress with JPEG (requires libjpeg configured with libtiff) - -z compress with Zip/Deflate (requires zlib configured with libtiff) + -j: compress with JPEG (requires libjpeg configured with libtiff) + -z: compress with Zip/Deflate (requires zlib configured with libtiff) -q: compression quality - -n no compressed data passthrough - -d do not compress (decompress) - - -i invert colors - + -n: no compressed data passthrough + -d: do not compress (decompress) + -i: invert colors -u: set distance unit, 'i' for inch, 'm' for centimeter -x: set x resolution default -y: set y resolution default -w: width in units -l: length in units -r: 'd' for resolution default, 'o' for resolution override - -p: paper size, eg "letter", "legal", "A4" - -f set PDF "Fit Window" user preference - -b set PDF "Interpolate" user preference + -p: paper size, eg "letter", "legal", "a4" + -f: set pdf "fit window" user preference + -b: set PDF "Interpolate" user preference -e: date, overrides image or current date/time default, YYYYMMDDHHMMSS -c: creator, overrides image software default -a: author, overrides image artist default @@ -687,7 +677,7 @@ getopt(int argc, char * const argv[], co -s: subject, overrides image image description default -k: keywords - -h usage + -h: usage examples: @@ -713,193 +703,253 @@ getopt(int argc, char * const argv[], co See also libtiff.3t, tiffcp. */ - int tiff2pdf(TIFF *input, FILE *outputfile, int argc, const char **argv) { - extern char *optarg; - const char *outfilename = ""; - T2P *t2p = NULL; - TIFF *output = NULL; - int c; - - /* T2P */ - t2p = t2p_init(); - if (t2p == NULL){ - TIFFError(TIFF2PDF_MODULE, "Can't initialize context"); - goto fail; - } - - /* Options */ - while (argv && - (c = getopt(argc, (char**)argv, - "o:q:u:x:y:w:l:r:p:e:c:a:t:s:k:jzndifbh")) != -1) { - switch (c) { - case 'o': - outfilename = optarg; - break; + char *outfilename = ""; + T2P *t2p = NULL; + TIFF *output = NULL; + tsize_t written = 0; + int c; + + (void)written; + + t2p = t2p_init(); + + if (t2p == NULL){ + TIFFError(TIFF2PDF_MODULE, "Can't initialize context"); + goto fail; + } + + while (argv && + (c = getopt(argc, (void*)argv, + "o:q:u:x:y:w:l:r:p:e:c:a:t:s:k:jzndifbh")) != -1){ + switch (c) { + case 'o': + outfilename = optarg; + break; #ifdef JPEG_SUPPORT - case 'j': - t2p->pdf_defaultcompression=T2P_COMPRESS_JPEG; - break; + case 'j': + t2p->pdf_defaultcompression=T2P_COMPRESS_JPEG; + break; +#endif +#ifndef JPEG_SUPPORT + case 'j': + TIFFWarning( + TIFF2PDF_MODULE, + "JPEG support in libtiff required for JPEG compression, ignoring option"); + break; #endif #ifdef ZIP_SUPPORT - case 'z': - t2p->pdf_defaultcompression=T2P_COMPRESS_ZIP; - break; -#endif - case 'q': - t2p->pdf_defaultcompressionquality=atoi(optarg); - break; - case 'n': - t2p->pdf_nopassthrough=1; - break; - case 'd': - t2p->pdf_defaultcompression=T2P_COMPRESS_NONE; - break; - case 'u': - if(optarg[0]=='m'){ - t2p->pdf_centimeters=1; - } - break; - case 'x': - t2p->pdf_defaultxres = - (float)atof(optarg) / (t2p->pdf_centimeters?2.54F:1.0F); - break; - case 'y': - t2p->pdf_defaultyres = - (float)atof(optarg) / (t2p->pdf_centimeters?2.54F:1.0F); - break; - case 'w': - t2p->pdf_overridepagesize=1; - t2p->pdf_defaultpagewidth = - ((float)atof(optarg) * 72.0F) / (t2p->pdf_centimeters?2.54F:1.0F); - break; - case 'l': - t2p->pdf_overridepagesize=1; - t2p->pdf_defaultpagelength = - ((float)atof(optarg) * 72.0F) / (t2p->pdf_centimeters?2.54F:1.0F); - break; - case 'r': - if(optarg[0]=='o'){ - t2p->pdf_overrideres=1; - } - break; - case 'p': - if(tiff2pdf_match_paper_size(&(t2p->pdf_defaultpagewidth), - &(t2p->pdf_defaultpagelength), - optarg)){ - t2p->pdf_overridepagesize=1; - } else { - TIFFWarning(TIFF2PDF_MODULE, - "Unknown paper size %s, ignoring option", - optarg); - } - break; - case 'i': - t2p->pdf_colorspace_invert=1; - break; - case 'f': - t2p->pdf_fitwindow=1; - break; - case 'e': - t2p->pdf_datetime = (char*)_TIFFmalloc(17); - if(t2p->pdf_datetime){ - if(strlen(optarg)==0){ - t2p->pdf_datetime[0]=0; - } else { - if(strlen(optarg)>14){optarg[14]=0;} - t2p->pdf_datetime[0]='D'; - t2p->pdf_datetime[1]=':'; - strcpy(&(t2p->pdf_datetime[2]), optarg); - } - } - break; - case 'c': - t2p->pdf_creator = (char *)_TIFFmalloc(strlen(optarg) + 1); - if(t2p->pdf_creator){ - strcpy(t2p->pdf_creator, optarg); - t2p->pdf_creator[strlen(optarg)]=0; - } - break; - case 'a': - t2p->pdf_author = (char *)_TIFFmalloc(strlen(optarg) + 1); - if(t2p->pdf_author){ - strcpy(t2p->pdf_author, optarg); - t2p->pdf_author[strlen(optarg)]=0; - } - break; - case 't': - t2p->pdf_title= (char*)_TIFFmalloc(strlen(optarg)+1); - if(t2p->pdf_title){ - strcpy(t2p->pdf_title, optarg); - t2p->pdf_title[strlen(optarg)]=0; - } - break; - case 's': - t2p->pdf_subject= (char*)_TIFFmalloc(strlen(optarg)+1); - if(t2p->pdf_subject){ - strcpy(t2p->pdf_subject, optarg); - t2p->pdf_subject[strlen(optarg)]=0; - } - break; - case 'k': - t2p->pdf_keywords= (char*)_TIFFmalloc(strlen(optarg)+1); - if(t2p->pdf_keywords){ - strcpy(t2p->pdf_keywords, optarg); - t2p->pdf_keywords[strlen(optarg)]=0; - } - break; - case 'b': - t2p->pdf_image_interpolate = 1; - break; - } - } - - /* Output */ - t2p->outputdisable = 0; - t2p->outputfile = outputfile; - output = TIFFClientOpen(outfilename, "w", (thandle_t) t2p, - t2p_readproc, t2p_writeproc, t2p_seekproc, - t2p_closeproc, t2p_sizeproc, - t2p_mapproc, t2p_unmapproc ); - if (output == NULL){ - TIFFError(TIFF2PDF_MODULE, "Can't initialize output descriptor"); - goto fail; - } - - /* Validate */ - t2p_validate(t2p); - TIFFSeekFile(output, (toff_t) 0, SEEK_SET); - - /* Write */ - t2p_write_pdf(t2p, input, output); - if(t2p->t2p_error != 0){ - TIFFError(TIFF2PDF_MODULE, "An error occurred creating output PDF file"); - goto fail; - } - - if (output != NULL) - TIFFClose(output); - if (t2p != NULL) - t2p_free(t2p); - return(EXIT_SUCCESS); + case 'z': + t2p->pdf_defaultcompression=T2P_COMPRESS_ZIP; + break; +#endif +#ifndef ZIP_SUPPORT + case 'z': + TIFFWarning( + TIFF2PDF_MODULE, + "Zip support in libtiff required for Zip compression, ignoring option"); + break; +#endif + case 'q': + t2p->pdf_defaultcompressionquality=atoi(optarg); + break; + case 'n': + t2p->pdf_nopassthrough=1; + break; + case 'd': + t2p->pdf_defaultcompression=T2P_COMPRESS_NONE; + break; + case 'u': + if(optarg[0]=='m'){ + t2p->pdf_centimeters=1; + } + break; + case 'x': + t2p->pdf_defaultxres = + (float)atof(optarg) / (t2p->pdf_centimeters?2.54F:1.0F); + break; + case 'y': + t2p->pdf_defaultyres = + (float)atof(optarg) / (t2p->pdf_centimeters?2.54F:1.0F); + break; + case 'w': + t2p->pdf_overridepagesize=1; + t2p->pdf_defaultpagewidth = + ((float)atof(optarg) * PS_UNIT_SIZE) / (t2p->pdf_centimeters?2.54F:1.0F); + break; + case 'l': + t2p->pdf_overridepagesize=1; + t2p->pdf_defaultpagelength = + ((float)atof(optarg) * PS_UNIT_SIZE) / (t2p->pdf_centimeters?2.54F:1.0F); + break; + case 'r': + if(optarg[0]=='o'){ + t2p->pdf_overrideres=1; + } + break; + case 'p': + if(tiff2pdf_match_paper_size( + &(t2p->pdf_defaultpagewidth), + &(t2p->pdf_defaultpagelength), + optarg)){ + t2p->pdf_overridepagesize=1; + } else { + TIFFWarning(TIFF2PDF_MODULE, + "Unknown paper size %s, ignoring option", + optarg); + } + break; + case 'i': + t2p->pdf_colorspace_invert=1; + break; + case 'f': + t2p->pdf_fitwindow=1; + break; + case 'e': + t2p->pdf_datetime = + (unsigned char*)_TIFFmalloc(17); + if(t2p->pdf_datetime==NULL){ + TIFFError(TIFF2PDF_MODULE, + "Can't allocate %u bytes of memory for main", + 17); + goto fail; + } + if(strlen(optarg)==0){ + t2p->pdf_datetime[0] = 0; + } else { + if(strlen(optarg)>14){optarg[14]=0;} + t2p->pdf_datetime[0] = 'D'; + t2p->pdf_datetime[1] = ':'; + strcpy((char *)t2p->pdf_datetime + 2, + optarg); + } + break; + case 'c': + t2p->pdf_creator = (unsigned char *) + _TIFFmalloc(strlen(optarg) + 1); + if(t2p->pdf_creator==NULL){ + TIFFError(TIFF2PDF_MODULE, + "Can't allocate %lu bytes of memory for main", + (long)strlen(optarg) + 1); + goto fail; + } + strcpy((char *)t2p->pdf_creator, optarg); + t2p->pdf_creator[strlen(optarg)] = 0; + break; + case 'a': + t2p->pdf_author = (unsigned char *) + _TIFFmalloc(strlen(optarg) + 1); + if(t2p->pdf_author==NULL){ + TIFFError( + TIFF2PDF_MODULE, + "Can't allocate %lu bytes of memory for main", + (long)strlen(optarg) + 1); + goto fail; + } + strcpy((char *)t2p->pdf_author, optarg); + t2p->pdf_author[strlen(optarg)]=0; + break; + case 't': + t2p->pdf_title = (unsigned char*) + _TIFFmalloc(strlen(optarg)+1); + if(t2p->pdf_title==NULL){ + TIFFError( + TIFF2PDF_MODULE, + "Can't allocate %lu bytes of memory for main", + (long)strlen(optarg) + 1); + goto fail; + } + strcpy((char *)t2p->pdf_title, optarg); + t2p->pdf_title[strlen(optarg)] = 0; + break; + case 's': + t2p->pdf_subject = (unsigned char*) + _TIFFmalloc(strlen(optarg) + 1); + if(t2p->pdf_subject==NULL){ + TIFFError( + TIFF2PDF_MODULE, + "Can't allocate %lu bytes of memory for main", + (long)strlen(optarg)+1); + goto fail; + } + strcpy((char *)t2p->pdf_subject, optarg); + t2p->pdf_subject[strlen(optarg)]=0; + break; + case 'k': + t2p->pdf_keywords = (unsigned char*) + _TIFFmalloc(strlen(optarg) + 1); + if(t2p->pdf_keywords==NULL){ + TIFFError( + TIFF2PDF_MODULE, + "Can't allocate %lu bytes of memory for main", + (long)strlen(optarg) + 1); + goto fail; + } + strcpy((char *)t2p->pdf_keywords, optarg); + t2p->pdf_keywords[strlen(optarg)] = 0; + break; + case 'b': + t2p->pdf_image_interpolate = 1; + break; + } + } + + /* + * Output + */ + t2p->outputdisable = 0; + t2p->outputfile = outputfile; + + output = TIFFClientOpen(outfilename, "w", (thandle_t) t2p, + t2p_readproc, t2p_writeproc, t2p_seekproc, + t2p_closeproc, t2p_sizeproc, + t2p_mapproc, t2p_unmapproc ); + if (output == NULL) { + TIFFError(TIFF2PDF_MODULE, + "Can't initialize output descriptor"); + goto fail; + } + + /* + * Validate + */ + t2p_validate(t2p); + t2pSeekFile(output, (toff_t) 0, SEEK_SET); + + /* + * Write + */ + written = t2p_write_pdf(t2p, input, output); + if (t2p->t2p_error != 0) { + TIFFError(TIFF2PDF_MODULE, + "An error occurred creating output PDF file"); + goto fail; + } + +/* success: */ + if (output != NULL) + TIFFClose(output); + if (t2p != NULL) + t2p_free(t2p); + return(EXIT_SUCCESS); fail: - if (output != NULL) - TIFFClose(output); - if (t2p != NULL) - t2p_free(t2p); - return(EXIT_FAILURE); + if(input != NULL) + TIFFClose(input); + if (output != NULL) + TIFFClose(output); + if (t2p != NULL) + t2p_free(t2p); + return(EXIT_FAILURE); + } -static int -tiff2pdf_match_paper_size(float* width, float* length, char* papersize) -{ +static int tiff2pdf_match_paper_size(float* width, float* length, char* papersize){ - int i=0; - int len=0; + size_t i, len; const char* sizes[]={ "LETTER", "A4", "LEGAL", "EXECUTIVE", "LETTER", "LEGAL", "LEDGER", "TABLOID", @@ -957,27 +1007,18 @@ tiff2pdf_match_paper_size(float* width, return(0); } - - - -/* -------------------------------------------------- * - Tiff2Pdf proper with minor changes - * -------------------------------------------------- */ - - - /* This function allocates and initializes a T2P context struct pointer. */ -static T2P* t2p_init() -{ +static T2P* t2p_init(){ + T2P* t2p = (T2P*) _TIFFmalloc(sizeof(T2P)); if(t2p==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_init", - (int)sizeof(T2P)); + "Can't allocate %lu bytes of memory for t2p_init", + (long)sizeof(T2P)); return( (T2P*) NULL ); } _TIFFmemset(t2p, 0x00, sizeof(T2P)); @@ -988,9 +1029,7 @@ static T2P* t2p_init() t2p->pdf_defaultpagewidth=612.0; t2p->pdf_defaultpagelength=792.0; t2p->pdf_xrefcount=3; /* Catalog, Info, Pages */ - t2p->outputfile = NULL; - t2p->outputdisable = 0; - t2p->outputwritten = 0; + return(t2p); } @@ -1061,7 +1100,7 @@ static void t2p_validate(T2P* t2p){ #ifdef JPEG_SUPPORT if(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){ - if(t2p->pdf_defaultcompressionquality<100 || + if(t2p->pdf_defaultcompressionquality>100 || t2p->pdf_defaultcompressionquality<1){ t2p->pdf_defaultcompressionquality=0; } @@ -1069,22 +1108,14 @@ static void t2p_validate(T2P* t2p){ #endif #ifdef ZIP_SUPPORT if(t2p->pdf_defaultcompression==T2P_COMPRESS_ZIP){ - switch (t2p->pdf_defaultcompressionquality){ - case 1: case 10: case 11: case 12: case 13: case 14: case 15: - case 101: case 110: case 111: case 112: case 113: case 114: case 115: - case 201: case 210: case 211: case 212: case 213: case 214: case 215: - case 301: case 310: case 311: case 312: case 313: case 314: case 315: - case 401: case 410: case 411: case 412: case 413: case 414: case 415: - case 501: case 510: case 511: case 512: case 513: case 514: case 515: - case 601: case 610: case 611: case 612: case 613: case 614: case 615: - case 701: case 710: case 711: case 712: case 713: case 714: case 715: - case 801: case 810: case 811: case 812: case 813: case 814: case 815: - case 901: case 910: case 911: case 912: case 913: case 914: case 915: - break; - default: - t2p->pdf_defaultcompressionquality=0; + uint16 m=t2p->pdf_defaultcompressionquality%100; + if(t2p->pdf_defaultcompressionquality/100 > 9 || + (m>1 && m<10) || m>15){ + t2p->pdf_defaultcompressionquality=0; } if(t2p->pdf_defaultcompressionquality%100 !=0){ + t2p->pdf_defaultcompressionquality/=100; + t2p->pdf_defaultcompressionquality*=100; TIFFError( TIFF2PDF_MODULE, "PNG Group predictor differencing not implemented, assuming compression quality %u", @@ -1120,8 +1151,8 @@ static void t2p_read_tiff_init(T2P* t2p, if(t2p->tiff_pages==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for tiff_pages array, %s", - directorycount * (int)sizeof(T2P_PAGE), + "Can't allocate %lu bytes of memory for tiff_pages array, %s", + directorycount * (long)sizeof(T2P_PAGE), TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1131,8 +1162,8 @@ static void t2p_read_tiff_init(T2P* t2p, if(t2p->tiff_tiles==NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for tiff_tiles array, %s", - directorycount * (int)sizeof(T2P_TILES), + "Can't allocate %lu bytes of memory for tiff_tiles array, %s", + directorycount * (long)sizeof(T2P_TILES), TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1147,6 +1178,7 @@ static void t2p_read_tiff_init(T2P* t2p, "Can't set directory %u of input file %s", i, TIFFFileName(input)); + t2p->t2p_error = T2P_ERR_ERROR; return; } if(TIFFGetField(input, TIFFTAG_PAGENUMBER, &pagen, &paged)){ @@ -1263,8 +1295,8 @@ static void t2p_read_tiff_init(T2P* t2p, if( t2p->tiff_tiles[i].tiles_tiles == NULL){ TIFFError( TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_read_tiff_init, %s", - t2p->tiff_tiles[i].tiles_tilecount * (int)sizeof(T2P_TILE), + "Can't allocate %lu bytes of memory for t2p_read_tiff_init, %s", + t2p->tiff_tiles[i].tiles_tilecount * (long)sizeof(T2P_TILE), TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; @@ -1276,8 +1308,9 @@ static void t2p_read_tiff_init(T2P* t2p, } /* - This function is used by qsort to sort a T2P_PAGE* array of page structures by page number. -*/ + * This function is used by qsort to sort a T2P_PAGE* array of page structures + * by page number. + */ static int t2p_cmp_t2p_page(const void* e1, const void* e2){ @@ -1503,7 +1536,7 @@ static void t2p_read_tiff_data(T2P* t2p, TIFFError( TIFF2PDF_MODULE, "No support for palettized image %s with not one sample per pixel", - TIFFFileName(input) ); + TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; } @@ -1572,7 +1605,7 @@ static void t2p_read_tiff_data(T2P* t2p, TIFFError( TIFF2PDF_MODULE, "No support for palettized CMYK image %s with not one sample per pixel", - TIFFFileName(input) ); + TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; } @@ -1605,7 +1638,7 @@ static void t2p_read_tiff_data(T2P* t2p, t2p->pdf_palette[(i*4)] = (unsigned char) (r[i]>>8); t2p->pdf_palette[(i*4)+1]= (unsigned char) (g[i]>>8); t2p->pdf_palette[(i*4)+2]= (unsigned char) (b[i]>>8); - t2p->pdf_palette[(i*4)+2]= (unsigned char) (a[i]>>8); + t2p->pdf_palette[(i*4)+3]= (unsigned char) (a[i]>>8); } t2p->pdf_palettesize *= 4; break; @@ -1712,13 +1745,15 @@ static void t2p_read_tiff_data(T2P* t2p, if(TIFFGetField(input, TIFFTAG_YRESOLUTION, &(t2p->tiff_yres) ) == 0){ t2p->tiff_yres=0.0; } - TIFFGetFieldDefaulted(input, TIFFTAG_RESOLUTIONUNIT, &(t2p->tiff_resunit) ); - if(t2p->tiff_resunit==RESUNIT_CENTIMETER){ - t2p->tiff_xres*=2.54F; - t2p->tiff_yres*=2.54F; - } else if (t2p->tiff_resunit!=RESUNIT_INCH && t2p->pdf_centimeters!=0){ - t2p->tiff_xres*=2.54F; - t2p->tiff_yres*=2.54F; + TIFFGetFieldDefaulted(input, TIFFTAG_RESOLUTIONUNIT, + &(t2p->tiff_resunit)); + if(t2p->tiff_resunit == RESUNIT_CENTIMETER) { + t2p->tiff_xres *= 2.54F; + t2p->tiff_yres *= 2.54F; + } else if (t2p->tiff_resunit != RESUNIT_INCH + && t2p->pdf_centimeters != 0) { + t2p->tiff_xres *= 2.54F; + t2p->tiff_yres *= 2.54F; } t2p_compose_pdf_page(t2p); @@ -1879,13 +1914,11 @@ static void t2p_read_tiff_size(T2P* t2p, uint32* sbc=NULL; #if defined(JPEG_SUPPORT) || defined (OJPEG_SUPPORT) unsigned char* jpt=NULL; - uint32 xuint32=0; tstrip_t i=0; tstrip_t stripcount=0; #endif -#ifdef OJPEG_SUPPORT - tsize_t k = 0; -#endif + uint64 k = 0; + if(t2p->pdf_transcode == T2P_TRANSCODE_RAW){ #ifdef CCITT_SUPPORT if(t2p->pdf_compression == T2P_COMPRESS_G4 ){ @@ -1912,19 +1945,25 @@ static void t2p_read_tiff_size(T2P* t2p, } stripcount=TIFFNumberOfStrips(input); for(i=0;itiff_dataoffset))){ if(t2p->tiff_dataoffset != 0){ if(TIFFGetField(input, TIFFTAG_JPEGIFBYTECOUNT, &(t2p->tiff_datasize))!=0){ - if(t2p->tiff_datasize < k) { - t2p->pdf_ojpegiflength=t2p->tiff_datasize; - t2p->tiff_datasize+=k; - t2p->tiff_datasize+=6; - t2p->tiff_datasize+=2*stripcount; + if((uint64)t2p->tiff_datasize < k) { TIFFWarning(TIFF2PDF_MODULE, "Input file %s has short JPEG interchange file byte count", TIFFFileName(input)); + t2p->pdf_ojpegiflength=t2p->tiff_datasize; + k = checkAdd64(k, t2p->tiff_datasize, t2p); + k = checkAdd64(k, 6, t2p); + k = checkAdd64(k, stripcount, t2p); + k = checkAdd64(k, stripcount, t2p); + t2p->tiff_datasize = (tsize_t) k; + if ((uint64) t2p->tiff_datasize != k) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; + } return; } return; @@ -1937,22 +1976,27 @@ static void t2p_read_tiff_size(T2P* t2p, } } } - t2p->tiff_datasize+=k; - t2p->tiff_datasize+=2*stripcount; - t2p->tiff_datasize+=2048; + k = checkAdd64(k, stripcount, t2p); + k = checkAdd64(k, stripcount, t2p); + k = checkAdd64(k, 2048, t2p); + t2p->tiff_datasize = (tsize_t) k; + if ((uint64) t2p->tiff_datasize != k) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; + } return; } #endif #ifdef JPEG_SUPPORT - if(t2p->tiff_compression == COMPRESSION_JPEG){ - t2p->tiff_datasize = 2048; /* safety margin (actually used!) */ - if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &xuint32, &jpt) != 0 ){ - if(xuint32>4){ - t2p->tiff_datasize+= xuint32; - t2p->tiff_datasize -=2; /* don't use EOI of header */ + if(t2p->tiff_compression == COMPRESSION_JPEG) { + uint32 count = 0; + if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0 ){ + if(count > 4){ + k += count; + k -= 2; /* don't use EOI of header */ } } else { - t2p->tiff_datasize=2; /* SOI for first strip */ + k = 2; /* SOI for first strip */ } stripcount=TIFFNumberOfStrips(input); if(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){ @@ -1963,18 +2007,32 @@ static void t2p_read_tiff_size(T2P* t2p, return; } for(i=0;itiff_datasize += sbc[i]; - t2p->tiff_datasize -=4; /* don't use SOI or EOI of strip */ + k = checkAdd64(k, sbc[i], t2p); + k -=4; /* don't use SOI or EOI of strip */ + } + k = checkAdd64(k, 2, t2p); /* use EOI of last strip */ + t2p->tiff_datasize = (tsize_t) k; + if ((uint64) t2p->tiff_datasize != k) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; } - t2p->tiff_datasize +=2; /* use EOI of last strip */ - return; } #endif (void) 0; } - t2p->tiff_datasize=TIFFScanlineSize(input) * t2p->tiff_length; + k = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p); if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){ - t2p->tiff_datasize*= t2p->tiff_samplesperpixel; + k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p); + } + if (k == 0) { + /* Assume we had overflow inside TIFFScanlineSize */ + t2p->t2p_error = T2P_ERR_ERROR; + } + + t2p->tiff_datasize = (tsize_t) k; + if ((uint64) t2p->tiff_datasize != k) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; } return; @@ -1990,10 +2048,10 @@ static void t2p_read_tiff_size_tile(T2P* uint32* tbc = NULL; uint16 edge=0; #ifdef JPEG_SUPPORT - uint32 xuint32=0; unsigned char* jpt; #endif - + uint64 k; + edge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile); edge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile); @@ -2004,41 +2062,62 @@ static void t2p_read_tiff_size_tile(T2P* #endif ){ t2p->tiff_datasize=TIFFTileSize(input); + if (t2p->tiff_datasize == 0) { + /* Assume we had overflow inside TIFFTileSize */ + t2p->t2p_error = T2P_ERR_ERROR; + } return; } else { TIFFGetField(input, TIFFTAG_TILEBYTECOUNTS, &tbc); - t2p->tiff_datasize=tbc[tile]; + k=tbc[tile]; #ifdef OJPEG_SUPPORT if(t2p->tiff_compression==COMPRESSION_OJPEG){ - t2p->tiff_datasize+=2048; - return; + k = checkAdd64(k, 2048, t2p); } #endif #ifdef JPEG_SUPPORT - if(t2p->tiff_compression==COMPRESSION_JPEG){ - if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &xuint32, &jpt)!=0){ - if(xuint32>4){ - t2p->tiff_datasize+=xuint32; - t2p->tiff_datasize-=4; /* don't use EOI of header or SOI of tile */ + if(t2p->tiff_compression==COMPRESSION_JPEG) { + uint32 count = 0; + if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt)!=0){ + if(count > 4){ + k = checkAdd64(k, count, t2p); + k -= 4; /* don't use EOI of header or SOI of tile */ + + } } } #endif + t2p->tiff_datasize = (tsize_t) k; + if ((uint64) t2p->tiff_datasize != k) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; + } return; } } - t2p->tiff_datasize=TIFFTileSize(input); + k = TIFFTileSize(input); if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){ - t2p->tiff_datasize*= t2p->tiff_samplesperpixel; + k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p); + } + if (k == 0) { + /* Assume we had overflow inside TIFFTileSize */ + t2p->t2p_error = T2P_ERR_ERROR; + } + + t2p->tiff_datasize = (tsize_t) k; + if ((uint64) t2p->tiff_datasize != k) { + TIFFError(TIFF2PDF_MODULE, "Integer overflow"); + t2p->t2p_error = T2P_ERR_ERROR; } return; } /* - This functions returns a non-zero value when the tile is on the right edge - and does not have full imaged tile width. -*/ + * This functions returns a non-zero value when the tile is on the right edge + * and does not have full imaged tile width. + */ static int t2p_tile_is_right_edge(T2P_TILES tiles, ttile_t tile){ @@ -2048,15 +2127,12 @@ static int t2p_tile_is_right_edge(T2P_TI } else { return(0); } - - return(0); - } /* - This functions returns a non-zero value when the tile is on the bottom edge - and does not have full imaged tile length. -*/ + * This functions returns a non-zero value when the tile is on the bottom edge + * and does not have full imaged tile length. + */ static int t2p_tile_is_bottom_edge(T2P_TILES tiles, ttile_t tile){ @@ -2066,8 +2142,6 @@ static int t2p_tile_is_bottom_edge(T2P_T } else { return(0); } - - return(0); } /* @@ -2099,9 +2173,6 @@ static tsize_t t2p_readwrite_pdf_image(T #endif #ifdef JPEG_SUPPORT unsigned char* jpt; - uint32 xuint32=0; - uint16 xuint16_1=0; - uint16 xuint16_2=0; float* xfloatp; uint32* sbc; unsigned char* stripbuffer; @@ -2109,78 +2180,108 @@ static tsize_t t2p_readwrite_pdf_image(T uint32 max_striplength=0; #endif + /* Fail if prior error (in particular, can't trust tiff_datasize) */ + if (t2p->t2p_error != T2P_ERR_OK) + return(0); + if(t2p->pdf_transcode == T2P_TRANSCODE_RAW){ #ifdef CCITT_SUPPORT if(t2p->pdf_compression == T2P_COMPRESS_G4){ - buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); - if(buffer==NULL){ + buffer = (unsigned char*) + _TIFFmalloc(t2p->tiff_datasize); + if (buffer == NULL) { TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); } - TIFFReadRawStrip(input, 0, (tdata_t) buffer, t2p->tiff_datasize); + TIFFReadRawStrip(input, 0, (tdata_t) buffer, + t2p->tiff_datasize); if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){ - /* make sure is lsb-to-msb bit-endianness fill order */ - TIFFReverseBits(buffer, t2p->tiff_datasize); + /* + * make sure is lsb-to-msb + * bit-endianness fill order + */ + TIFFReverseBits(buffer, + t2p->tiff_datasize); } - TIFFWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize); + t2pWriteFile(output, (tdata_t) buffer, + t2p->tiff_datasize); _TIFFfree(buffer); return(t2p->tiff_datasize); } #endif #ifdef ZIP_SUPPORT - if(t2p->pdf_compression == T2P_COMPRESS_ZIP){ - buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); + if (t2p->pdf_compression == T2P_COMPRESS_ZIP) { + buffer = (unsigned char*) + _TIFFmalloc(t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize); - if(buffer==NULL){ + if(buffer == NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); } - TIFFReadRawStrip(input, 0, (tdata_t) buffer, t2p->tiff_datasize); - if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){ - TIFFReverseBits(buffer, t2p->tiff_datasize); + TIFFReadRawStrip(input, 0, (tdata_t) buffer, + t2p->tiff_datasize); + if (t2p->tiff_fillorder==FILLORDER_LSB2MSB) { + TIFFReverseBits(buffer, + t2p->tiff_datasize); } - TIFFWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize); + t2pWriteFile(output, (tdata_t) buffer, + t2p->tiff_datasize); _TIFFfree(buffer); return(t2p->tiff_datasize); } #endif #ifdef OJPEG_SUPPORT - if(t2p->tiff_compression == COMPRESSION_OJPEG){ + if(t2p->tiff_compression == COMPRESSION_OJPEG) { - if(t2p->tiff_dataoffset != 0){ - buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); + if(t2p->tiff_dataoffset != 0) { + buffer = (unsigned char*) + _TIFFmalloc(t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize); - if(buffer==NULL){ + if(buffer == NULL) { TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); } if(t2p->pdf_ojpegiflength==0){ - inputoffset=TIFFSeekFile(input, 0, SEEK_CUR); - TIFFSeekFile(input, t2p->tiff_dataoffset, SEEK_SET); - TIFFReadFile(input, (tdata_t) buffer, t2p->tiff_datasize); - TIFFSeekFile(input, inputoffset, SEEK_SET); - TIFFWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize); + inputoffset=t2pSeekFile(input, 0, + SEEK_CUR); + t2pSeekFile(input, + t2p->tiff_dataoffset, + SEEK_SET); + t2pReadFile(input, (tdata_t) buffer, + t2p->tiff_datasize); + t2pSeekFile(input, inputoffset, + SEEK_SET); + t2pWriteFile(output, (tdata_t) buffer, + t2p->tiff_datasize); _TIFFfree(buffer); return(t2p->tiff_datasize); } else { - inputoffset=TIFFSeekFile(input, 0, SEEK_CUR); - TIFFSeekFile(input, t2p->tiff_dataoffset, SEEK_SET); - bufferoffset=TIFFReadFile(input, (tdata_t) buffer, t2p->pdf_ojpegiflength); - t2p->pdf_ojpegiflength=0; - TIFFSeekFile(input, inputoffset, SEEK_SET); - TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &h_samp, &v_samp); + inputoffset=t2pSeekFile(input, 0, + SEEK_CUR); + t2pSeekFile(input, + t2p->tiff_dataoffset, + SEEK_SET); + bufferoffset = t2pReadFile(input, + (tdata_t) buffer, + t2p->pdf_ojpegiflength); + t2p->pdf_ojpegiflength = 0; + t2pSeekFile(input, inputoffset, + SEEK_SET); + TIFFGetField(input, + TIFFTAG_YCBCRSUBSAMPLING, + &h_samp, &v_samp); buffer[bufferoffset++]= 0xff; buffer[bufferoffset++]= 0xdd; buffer[bufferoffset++]= 0x00; @@ -2188,7 +2289,9 @@ static tsize_t t2p_readwrite_pdf_image(T h_samp*=8; v_samp*=8; ri=(t2p->tiff_width+h_samp-1) / h_samp; - TIFFGetField(input, TIFFTAG_ROWSPERSTRIP, &rows); + TIFFGetField(input, + TIFFTAG_ROWSPERSTRIP, + &rows); ri*=(rows+v_samp-1)/v_samp; buffer[bufferoffset++]= (ri>>8) & 0xff; buffer[bufferoffset++]= ri & 0xff; @@ -2203,23 +2306,24 @@ static tsize_t t2p_readwrite_pdf_image(T (tdata_t) &(((unsigned char*)buffer)[bufferoffset]), -1); } - TIFFWriteFile(output, (tdata_t) buffer, bufferoffset); + t2pWriteFile(output, (tdata_t) buffer, bufferoffset); _TIFFfree(buffer); return(bufferoffset); } } else { if(! t2p->pdf_ojpegdata){ TIFFError(TIFF2PDF_MODULE, - "No support for OJPEG image %s with bad tables", + "No support for OJPEG image %s with bad tables", TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); } - buffer=(unsigned char*) _TIFFmalloc(t2p->tiff_datasize); + buffer = (unsigned char*) + _TIFFmalloc(t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -2242,11 +2346,11 @@ static tsize_t t2p_readwrite_pdf_image(T buffer[bufferoffset++]=0xff; buffer[bufferoffset++]=0xd9; } - TIFFWriteFile(output, (tdata_t) buffer, bufferoffset); + t2pWriteFile(output, (tdata_t) buffer, bufferoffset); _TIFFfree(buffer); return(bufferoffset); TIFFError(TIFF2PDF_MODULE, - "No support for OJPEG image %s with no JPEG File Interchange offset", + "No support for OJPEG image %s with no JPEG File Interchange offset", TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2255,21 +2359,23 @@ static tsize_t t2p_readwrite_pdf_image(T } #endif #ifdef JPEG_SUPPORT - if(t2p->tiff_compression == COMPRESSION_JPEG){ - buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); + if(t2p->tiff_compression == COMPRESSION_JPEG) { + uint32 count = 0; + buffer = (unsigned char*) + _TIFFmalloc(t2p->tiff_datasize); memset(buffer, 0, t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); } - if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &xuint32, &jpt) != 0){ - if(xuint32>4){ - _TIFFmemcpy(buffer, jpt, xuint32); - bufferoffset+=xuint32-2; + if (TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) { + if(count > 4) { + _TIFFmemcpy(buffer, jpt, count); + bufferoffset += count - 2; } } stripcount=TIFFNumberOfStrips(input); @@ -2277,10 +2383,11 @@ static tsize_t t2p_readwrite_pdf_image(T for(i=0;imax_striplength) max_striplength=sbc[i]; } - stripbuffer=(unsigned char*) _TIFFmalloc(max_striplength); + stripbuffer = (unsigned char*) + _TIFFmalloc(max_striplength); if(stripbuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", max_striplength, TIFFFileName(input)); _TIFFfree(buffer); @@ -2297,9 +2404,9 @@ static tsize_t t2p_readwrite_pdf_image(T i, t2p->tiff_length)){ TIFFError(TIFF2PDF_MODULE, - "Can't process JPEG data in input file %s", + "Can't process JPEG data in input file %s", TIFFFileName(input)); - _TIFFfree(stripbuffer); + _TIFFfree(samplebuffer); _TIFFfree(buffer); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2307,7 +2414,7 @@ static tsize_t t2p_readwrite_pdf_image(T } buffer[bufferoffset++]=0xff; buffer[bufferoffset++]=0xd9; - TIFFWriteFile(output, (tdata_t) buffer, bufferoffset); + t2pWriteFile(output, (tdata_t) buffer, bufferoffset); _TIFFfree(stripbuffer); _TIFFfree(buffer); return(bufferoffset); @@ -2321,7 +2428,7 @@ static tsize_t t2p_readwrite_pdf_image(T memset(buffer, 0, t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -2359,7 +2466,7 @@ static tsize_t t2p_readwrite_pdf_image(T memset(buffer, 0, t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -2368,7 +2475,7 @@ static tsize_t t2p_readwrite_pdf_image(T samplebuffer = (unsigned char*) _TIFFmalloc(stripsize); if(samplebuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -2384,7 +2491,7 @@ static tsize_t t2p_readwrite_pdf_image(T sepstripsize); if(read==-1){ TIFFError(TIFF2PDF_MODULE, - "Error on decoding strip %u of %s", + "Error on decoding strip %u of %s", i + j*stripcount, TIFFFileName(input)); _TIFFfree(buffer); @@ -2408,7 +2515,7 @@ static tsize_t t2p_readwrite_pdf_image(T memset(buffer, 0, t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -2441,7 +2548,7 @@ static tsize_t t2p_readwrite_pdf_image(T t2p->tiff_datasize * t2p->tiff_samplesperpixel); if(samplebuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -2471,7 +2578,7 @@ static tsize_t t2p_readwrite_pdf_image(T t2p->tiff_width*t2p->tiff_length*4); if(samplebuffer==NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", + "Can't allocate %u bytes of memory for t2p_readwrite_pdf_image, %s", t2p->tiff_datasize, TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; @@ -2488,7 +2595,7 @@ static tsize_t t2p_readwrite_pdf_image(T ORIENTATION_TOPLEFT, 0)){ TIFFError(TIFF2PDF_MODULE, - "Can't use TIFFReadRGBAImageOriented to extract RGB image from %s", + "Can't use TIFFReadRGBAImageOriented to extract RGB image from %s", TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return(0); @@ -2506,8 +2613,9 @@ static tsize_t t2p_readwrite_pdf_image(T } } - dataready: - t2p_disable(output); +dataready: + + t2p_disable(output); TIFFSetField(output, TIFFTAG_PHOTOMETRIC, t2p->tiff_photometric); TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, t2p->tiff_bitspersample); TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, t2p->tiff_samplesperpixel); @@ -2528,10 +2636,11 @@ static tsize_t t2p_readwrite_pdf_image(T #endif #ifdef JPEG_SUPPORT case T2P_COMPRESS_JPEG: - if(t2p->tiff_photometric==PHOTOMETRIC_YCBCR){ - if(TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &xuint16_1, &xuint16_2)!=0){ - if(xuint16_1 != 0 && xuint16_2 != 0){ - TIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, xuint16_1, xuint16_2); + if(t2p->tiff_photometric==PHOTOMETRIC_YCBCR) { + uint16 hor = 0, ver = 0; + if (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver) !=0 ) { + if(hor != 0 && ver != 0){ + TIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver); } } if(TIFFGetField(input, TIFFTAG_REFERENCEBLACKWHITE, &xfloatp)!=0){ @@ -2540,7 +2649,7 @@ static tsize_t t2p_readwrite_pdf_image(T } if(TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_JPEG)==0){ TIFFError(TIFF2PDF_MODULE, - "Unable to use JPEG compression for input %s and output %s", + "Unable to use JPEG compression for input %s and output %s", TIFFFileName(input), TIFFFileName(output)); _TIFFfree(buffer); @@ -2589,37 +2698,44 @@ static tsize_t t2p_readwrite_pdf_image(T default: break; } - - t2p_enable(output); - t2p->outputwritten = 0; + + t2p_enable(output); + t2p->outputwritten = 0; #ifdef JPEG_SUPPORT - if(t2p->pdf_compression==T2P_COMPRESS_JPEG && t2p->tiff_photometric==PHOTOMETRIC_YCBCR){ - bufferoffset=TIFFWriteEncodedStrip(output, (tstrip_t)0, buffer,stripsize*stripcount); + if(t2p->pdf_compression == T2P_COMPRESS_JPEG + && t2p->tiff_photometric == PHOTOMETRIC_YCBCR){ + bufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t)0, + buffer, + stripsize * stripcount); } else #endif - bufferoffset=TIFFWriteEncodedStrip(output, (tstrip_t)0, buffer, t2p->tiff_datasize); - if(buffer != NULL){ + { + bufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t)0, + buffer, + t2p->tiff_datasize); + } + if (buffer != NULL) { _TIFFfree(buffer); buffer=NULL; } - if(bufferoffset==(tsize_t)-1){ + if (bufferoffset == (tsize_t)-1) { TIFFError(TIFF2PDF_MODULE, - "Error writing encoded strip to output PDF %s", - TIFFFileName(output)); + "Error writing encoded strip to output PDF %s", + TIFFFileName(output)); t2p->t2p_error = T2P_ERR_ERROR; return(0); } - written= t2p->outputwritten; + written = t2p->outputwritten; return(written); } /* - This function reads the raster image data from the input TIFF for an image tile and writes - the data to the output PDF XObject image dictionary stream for the tile. It returns the - amount written or zero on error. -*/ + * This function reads the raster image data from the input TIFF for an image + * tile and writes the data to the output PDF XObject image dictionary stream + * for the tile. It returns the amount written or zero on error. + */ static tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_t tile){ @@ -2632,15 +2748,19 @@ static tsize_t t2p_readwrite_pdf_image_t tsize_t read=0; uint16 i=0; ttile_t tilecount=0; + tsize_t tilesize=0; ttile_t septilecount=0; tsize_t septilesize=0; #ifdef JPEG_SUPPORT unsigned char* jpt; - uint16 xuint16_1=0; - uint16 xuint16_2=0; float* xfloatp; uint32 xuint32=0; #endif + (void)tilesize; + + /* Fail if prior error (in particular, can't trust tiff_datasize) */ + if (t2p->t2p_error != T2P_ERR_OK) + return(0); edge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile); edge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile); @@ -2667,7 +2787,7 @@ static tsize_t t2p_readwrite_pdf_image_t if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){ TIFFReverseBits(buffer, t2p->tiff_datasize); } - TIFFWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize); + t2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize); _TIFFfree(buffer); return(t2p->tiff_datasize); } @@ -2688,7 +2808,7 @@ static tsize_t t2p_readwrite_pdf_image_t if (t2p->tiff_fillorder==FILLORDER_LSB2MSB){ TIFFReverseBits(buffer, t2p->tiff_datasize); } - TIFFWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize); + t2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize); _TIFFfree(buffer); return(t2p->tiff_datasize); } @@ -2735,7 +2855,7 @@ static tsize_t t2p_readwrite_pdf_image_t -1); ((unsigned char*)buffer)[bufferoffset++]=0xff; ((unsigned char*)buffer)[bufferoffset++]=0xd9; - TIFFWriteFile(output, (tdata_t) buffer, bufferoffset); + t2pWriteFile(output, (tdata_t) buffer, bufferoffset); _TIFFfree(buffer); return(bufferoffset); } @@ -2743,6 +2863,7 @@ static tsize_t t2p_readwrite_pdf_image_t #ifdef JPEG_SUPPORT if(t2p->tiff_compression == COMPRESSION_JPEG){ unsigned char table_end[2]; + uint32 count = 0; buffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ TIFFError(TIFF2PDF_MODULE, @@ -2753,14 +2874,14 @@ static tsize_t t2p_readwrite_pdf_image_t t2p->t2p_error = T2P_ERR_ERROR; return(0); } - if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &xuint16_1, &jpt) != 0) { - if(xuint16_1 > 0){ - _TIFFmemcpy(buffer, jpt, xuint16_1); - bufferoffset += xuint16_1 - 2; + if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) { + if (count > 0) { + _TIFFmemcpy(buffer, jpt, count); + bufferoffset += count - 2; table_end[0] = buffer[bufferoffset-2]; table_end[1] = buffer[bufferoffset-1]; } - if(xuint16_1 > 0) { + if (count > 0) { xuint32 = bufferoffset; bufferoffset += TIFFReadRawTile( input, @@ -2777,7 +2898,7 @@ static tsize_t t2p_readwrite_pdf_image_t -1); } } - TIFFWriteFile(output, (tdata_t) buffer, bufferoffset); + t2pWriteFile(output, (tdata_t) buffer, bufferoffset); _TIFFfree(buffer); return(bufferoffset); } @@ -2817,6 +2938,7 @@ static tsize_t t2p_readwrite_pdf_image_t if(t2p->pdf_sample == T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){ septilesize=TIFFTileSize(input); septilecount=TIFFNumberOfTiles(input); + tilesize=septilesize*t2p->tiff_samplesperpixel; tilecount=septilecount/t2p->tiff_samplesperpixel; buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize); if(buffer==NULL){ @@ -2933,7 +3055,8 @@ static tsize_t t2p_readwrite_pdf_image_t t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); } - t2p_disable(output); + + t2p_disable(output); TIFFSetField(output, TIFFTAG_PHOTOMETRIC, t2p->tiff_photometric); TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, t2p->tiff_bitspersample); TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, t2p->tiff_samplesperpixel); @@ -2981,10 +3104,11 @@ static tsize_t t2p_readwrite_pdf_image_t #endif #ifdef JPEG_SUPPORT case T2P_COMPRESS_JPEG: - if(t2p->tiff_photometric==PHOTOMETRIC_YCBCR){ - if(TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &xuint16_1, &xuint16_2)!=0){ - if(xuint16_1 != 0 && xuint16_2 != 0){ - TIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, xuint16_1, xuint16_2); + if (t2p->tiff_photometric==PHOTOMETRIC_YCBCR) { + uint16 hor = 0, ver = 0; + if (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver)!=0) { + if (hor != 0 && ver != 0) { + TIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver); } } if(TIFFGetField(input, TIFFTAG_REFERENCEBLACKWHITE, &xfloatp)!=0){ @@ -3034,20 +3158,23 @@ static tsize_t t2p_readwrite_pdf_image_t } t2p_enable(output); - t2p->outputwritten = 0; - bufferoffset=TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer, TIFFStripSize(output)); - if(buffer != NULL){ + t2p->outputwritten = 0; + bufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer, + TIFFStripSize(output)); + if (buffer != NULL) { _TIFFfree(buffer); - buffer=NULL; + buffer = NULL; } - if(bufferoffset==-1){ + if (bufferoffset == -1) { TIFFError(TIFF2PDF_MODULE, - "Error writing encoded tile to output PDF %s", - TIFFFileName(output)); + "Error writing encoded tile to output PDF %s", + TIFFFileName(output)); t2p->t2p_error = T2P_ERR_ERROR; return(0); } - written= t2p->outputwritten; + + written = t2p->outputwritten; + return(written); } @@ -3412,13 +3539,15 @@ static void t2p_tile_collapse_left( /* - This function calls TIFFWriteDirectory on the output after blanking its output by replacing the - read, write, and seek procedures with empty implementations, then it replaces the original - implementations. -*/ + * This function calls TIFFWriteDirectory on the output after blanking its + * output by replacing the read, write, and seek procedures with empty + * implementations, then it replaces the original implementations. + */ -static void t2p_write_advance_directory(T2P* t2p, TIFF* output){ - t2p_disable(output); +static void +t2p_write_advance_directory(T2P* t2p, TIFF* output) +{ + t2p_disable(output); if(!TIFFWriteDirectory(output)){ TIFFError(TIFF2PDF_MODULE, "Error writing virtual directory to output PDF %s", @@ -3426,14 +3555,14 @@ static void t2p_write_advance_directory( t2p->t2p_error = T2P_ERR_ERROR; return; } - t2p_enable(output); + t2p_enable(output); return; } static tsize_t t2p_sample_planar_separate_to_contig(T2P* t2p, - unsigned char* buffer, - unsigned char* samplebuffer, - tsize_t samplebuffersize){ + unsigned char* buffer, + unsigned char* samplebuffer, + tsize_t samplebuffersize){ tsize_t stride=0; tsize_t i=0; @@ -3569,8 +3698,8 @@ static tsize_t t2p_write_pdf_header(T2P* int buflen=0; buflen=sprintf(buffer, "%%PDF-%u.%u ", t2p->pdf_majorversion&0xff, t2p->pdf_minorversion&0xff); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t)"\r%\342\343\317\323\r\n", 8); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t)"\n%\342\343\317\323\n", 7); return(written); } @@ -3586,8 +3715,8 @@ static tsize_t t2p_write_pdf_obj_start(u int buflen=0; buflen=sprintf(buffer, "%lu", (unsigned long)number); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen ); - written += TIFFWriteFile(output, (tdata_t) " 0 obj\r", 7); + written += t2pWriteFile(output, (tdata_t) buffer, buflen ); + written += t2pWriteFile(output, (tdata_t) " 0 obj\n", 7); return(written); } @@ -3600,61 +3729,61 @@ static tsize_t t2p_write_pdf_obj_end(TIF tsize_t written=0; - written += TIFFWriteFile(output, (tdata_t) "endobj\r", 7); + written += t2pWriteFile(output, (tdata_t) "endobj\n", 7); return(written); } - /* This function writes a PDF string object to output. */ -static tsize_t t2p_write_pdf_string(char* pdfstr, TIFF* output){ +static tsize_t t2p_write_pdf_string(unsigned char* pdfstr, TIFF* output){ - tsize_t written=0; - uint32 i=0; - char buffer[5]; - uint32 len=0; + tsize_t written = 0; + uint32 i = 0; + char buffer[64]; + uint32 len = 0; - len=strlen(pdfstr); - written += TIFFWriteFile(output, (tdata_t) "(", 1); - for (i=0;i>\r", 4); + written += t2pWriteFile(output, (tdata_t) " >>\n", 4); return(written); } @@ -3758,8 +3887,8 @@ static tsize_t t2p_write_pdf_stream_leng int buflen=0; buflen=sprintf(buffer, "%lu", (unsigned long)len); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "\n", 1); return(written); } @@ -3774,18 +3903,18 @@ static tsize_t t2p_write_pdf_catalog(T2P char buffer[16]; int buflen=0; - written += TIFFWriteFile(output, - (tdata_t)"<< \r/Type /Catalog \r/Pages ", + written += t2pWriteFile(output, + (tdata_t)"<< \n/Type /Catalog \n/Pages ", 27); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_pages); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen ); - written += TIFFWriteFile(output, (tdata_t) " 0 R \r", 6); + written += t2pWriteFile(output, (tdata_t) buffer, buflen ); + written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); if(t2p->pdf_fitwindow){ - written += TIFFWriteFile(output, - (tdata_t) "/ViewerPreferences <>\r", + written += t2pWriteFile(output, + (tdata_t) "/ViewerPreferences <>\n", 39); } - written += TIFFWriteFile(output, (tdata_t)">>\r", 3); + written += t2pWriteFile(output, (tdata_t)">>\n", 3); return(written); } @@ -3796,116 +3925,139 @@ static tsize_t t2p_write_pdf_catalog(T2P static tsize_t t2p_write_pdf_info(T2P* t2p, TIFF* input, TIFF* output){ - tsize_t written=0; - char* info; + tsize_t written = 0; + unsigned char* info; char buffer[512]; - + int buflen = 0; + + (void) buflen; + if(t2p->pdf_datetime==NULL){ t2p_pdf_tifftime(t2p, input); } - if(strlen(t2p->pdf_datetime) > 0){ - written += TIFFWriteFile(output, (tdata_t) "<< \r/CreationDate ", 18); + if(strlen((char *)t2p->pdf_datetime) > 0){ + written += t2pWriteFile(output, (tdata_t) "<< \n/CreationDate ", 18); written += t2p_write_pdf_string(t2p->pdf_datetime, output); - written += TIFFWriteFile(output, (tdata_t) "\r/ModDate ", 10); + written += t2pWriteFile(output, (tdata_t) "\n/ModDate ", 10); written += t2p_write_pdf_string(t2p->pdf_datetime, output); } - written += TIFFWriteFile(output, (tdata_t) "\r/Producer ", 11); - _TIFFmemset((tdata_t)buffer, 0x00, 512); - sprintf(buffer, "libtiff / tiff2pdf - %d / %s", - TIFFLIB_VERSION, T2P_VERSION); - written += t2p_write_pdf_string(buffer, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n/Producer ", 11); + _TIFFmemset((tdata_t)buffer, 0x00, sizeof(buffer)); + buflen = sprintf(buffer, "libtiff / tiff2pdf - %d", TIFFLIB_VERSION); + written += t2p_write_pdf_string((unsigned char*)buffer, output); + written += t2pWriteFile(output, (tdata_t) "\n", 1); if(t2p->pdf_creator != NULL){ - if(strlen(t2p->pdf_creator)>0){ - if(strlen(t2p->pdf_creator)>511){t2p->pdf_creator[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Creator ", 9); + if(strlen((char *)t2p->pdf_creator)>0){ + if(strlen((char *)t2p->pdf_creator) > 511) { + t2p->pdf_creator[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Creator ", 9); written += t2p_write_pdf_string(t2p->pdf_creator, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } else{ if( TIFFGetField(input, TIFFTAG_SOFTWARE, &info) != 0){ - if(strlen(info)>511){info[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Creator ", 9); + if(strlen((char *)info) > 511) { + info[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Creator ", 9); written += t2p_write_pdf_string(info, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } - if(t2p->pdf_author != NULL){ - if(strlen(t2p->pdf_author)>0){ - if(strlen(t2p->pdf_author)>511){t2p->pdf_author[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Author ", 8); + if(t2p->pdf_author != NULL) { + if(strlen((char *)t2p->pdf_author) > 0) { + if(strlen((char *)t2p->pdf_author) > 511) { + t2p->pdf_author[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Author ", 8); written += t2p_write_pdf_string(t2p->pdf_author, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } else{ if( TIFFGetField(input, TIFFTAG_ARTIST, &info) != 0){ - if(strlen(info)>511){info[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Author ", 8); + if(strlen((char *)info) > 511) { + info[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Author ", 8); written += t2p_write_pdf_string(info, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } else if ( TIFFGetField(input, TIFFTAG_COPYRIGHT, &info) != 0){ - if(strlen(info)>511){info[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Author ", 8); + if(strlen((char *)info) > 511) { + info[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Author ", 8); written += t2p_write_pdf_string(info, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } - if(t2p->pdf_title != NULL){ - if(strlen(t2p->pdf_title)>0){ - if(strlen(t2p->pdf_title)>511){t2p->pdf_title[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Title ", 7); + if(t2p->pdf_title != NULL) { + if(strlen((char *)t2p->pdf_title) > 0) { + if(strlen((char *)t2p->pdf_title) > 511) { + t2p->pdf_title[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Title ", 7); written += t2p_write_pdf_string(t2p->pdf_title, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } else{ if( TIFFGetField(input, TIFFTAG_DOCUMENTNAME, &info) != 0){ - if(strlen(info)>511){info[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Title ", 7); + if(strlen((char *)info) > 511) { + info[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Title ", 7); written += t2p_write_pdf_string(info, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } - if(t2p->pdf_subject != NULL){ - if(strlen(t2p->pdf_subject)>0){ - if(strlen(t2p->pdf_subject)>511){t2p->pdf_subject[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Subject ", 9); + if(t2p->pdf_subject != NULL) { + if(strlen((char *)t2p->pdf_subject) > 0) { + if(strlen((char *)t2p->pdf_subject) > 511) { + t2p->pdf_subject[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Subject ", 9); written += t2p_write_pdf_string(t2p->pdf_subject, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } - } else{ - if( TIFFGetField(input, TIFFTAG_IMAGEDESCRIPTION, &info) != 0){ - if(strlen(info)>511){info[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Subject ", 9); + } else { + if(TIFFGetField(input, TIFFTAG_IMAGEDESCRIPTION, &info) != 0) { + if(strlen((char *)info) > 511) { + info[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Subject ", 9); written += t2p_write_pdf_string(info, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } - if(t2p->pdf_keywords != NULL){ - if(strlen(t2p->pdf_keywords)>0){ - if(strlen(t2p->pdf_keywords)>511){t2p->pdf_keywords[512]=(char)0;} - written += TIFFWriteFile(output, (tdata_t) "/Keywords ", 10); + if(t2p->pdf_keywords != NULL) { + if(strlen((char *)t2p->pdf_keywords) > 0) { + if(strlen((char *)t2p->pdf_keywords) > 511) { + t2p->pdf_keywords[512] = '\0'; + } + written += t2pWriteFile(output, (tdata_t) "/Keywords ", 10); written += t2p_write_pdf_string(t2p->pdf_keywords, output); - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } - written += TIFFWriteFile(output, (tdata_t) ">> \r", 4); + written += t2pWriteFile(output, (tdata_t) ">> \n", 4); return(written); } /* - This function fills a string of a T2P struct with the current time as a PDF date string, - it is called by t2p_pdf_tifftime. -*/ + * This function fills a string of a T2P struct with the current time as a PDF + * date string, it is called by t2p_pdf_tifftime. + */ -static void t2p_pdf_currenttime(T2P* t2p){ +static void t2p_pdf_currenttime(T2P* t2p) +{ struct tm* currenttime; time_t timenow; timenow=time(0); currenttime=localtime(&timenow); - sprintf(t2p->pdf_datetime, "D:%.4d%.2d%.2d%.2d%.2d%.2d", + sprintf((char *)t2p->pdf_datetime, "D:%.4d%.2d%.2d%.2d%.2d%.2d", (currenttime->tm_year+1900) % 65536, (currenttime->tm_mon+1) % 256, (currenttime->tm_mday) % 256, @@ -3917,25 +4069,24 @@ static void t2p_pdf_currenttime(T2P* t2p } /* - This function fills a string of a T2P struct with the date and time of a TIFF file if it - exists or the current time as a PDF date string. -*/ + * This function fills a string of a T2P struct with the date and time of a + * TIFF file if it exists or the current time as a PDF date string. + */ static void t2p_pdf_tifftime(T2P* t2p, TIFF* input){ char* datetime; - t2p->pdf_datetime= (char*) _TIFFmalloc(19); - if(t2p->pdf_datetime==NULL){ + t2p->pdf_datetime = (unsigned char*) _TIFFmalloc(19); + if(t2p->pdf_datetime == NULL){ TIFFError(TIFF2PDF_MODULE, - "Can't allocate %u bytes of memory for t2p_pdf_tiff_time", - 17); + "Can't allocate %u bytes of memory for t2p_pdf_tiff_time", 17); t2p->t2p_error = T2P_ERR_ERROR; return; } - t2p->pdf_datetime[16]=0; + t2p->pdf_datetime[16] = '\0'; if( TIFFGetField(input, TIFFTAG_DATETIME, &datetime) != 0 - && (strlen(datetime) >= 19) ){ + && (strlen(datetime) >= 19) ){ t2p->pdf_datetime[0]='D'; t2p->pdf_datetime[1]=':'; t2p->pdf_datetime[2]=datetime[0]; @@ -3960,28 +4111,26 @@ static void t2p_pdf_tifftime(T2P* t2p, T } /* - This function writes a PDF Pages Tree structure to output. -*/ - -static tsize_t t2p_write_pdf_pages(T2P* t2p, - TIFF* output){ + * This function writes a PDF Pages Tree structure to output. + */ +static tsize_t t2p_write_pdf_pages(T2P* t2p, TIFF* output) +{ tsize_t written=0; tdir_t i=0; char buffer[16]; int buflen=0; int page=0; - written += TIFFWriteFile(output, - (tdata_t) "<< \r/Type /Pages \r/Kids [ ", - 26); + written += t2pWriteFile(output, + (tdata_t) "<< \n/Type /Pages \n/Kids [ ", 26); page = t2p->pdf_pages+1; for (i=0;itiff_pagecount;i++){ buflen=sprintf(buffer, "%d", page); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); if ( ((i+1)%8)==0 ) { - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } page +=3; page += t2p->tiff_pages[i].page_extra; @@ -3991,11 +4140,11 @@ static tsize_t t2p_write_pdf_pages(T2P* page +=2; } } - written += TIFFWriteFile(output, (tdata_t) "] \r/Count ", 10); + written += t2pWriteFile(output, (tdata_t) "] \n/Count ", 10); _TIFFmemset(buffer, 0x00, 16); buflen=sprintf(buffer, "%d", t2p->tiff_pagecount); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " \r>> \r", 6); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " \n>> \n", 6); return(written); } @@ -4011,86 +4160,86 @@ static tsize_t t2p_write_pdf_page(uint32 char buffer[16]; int buflen=0; - written += TIFFWriteFile(output, (tdata_t) "<<\r/Type /Page \r/Parent ", 24); + written += t2pWriteFile(output, (tdata_t) "<<\n/Type /Page \n/Parent ", 24); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_pages); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R \r", 6); - written += TIFFWriteFile(output, (tdata_t) "/MediaBox [", 11); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); + written += t2pWriteFile(output, (tdata_t) "/MediaBox [", 11); buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.x1); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " ", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " ", 1); buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.y1); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " ", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " ", 1); buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.x2); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " ", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " ", 1); buflen=sprintf(buffer, "%.4f",t2p->pdf_mediabox.y2); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "] \r", 3); - written += TIFFWriteFile(output, (tdata_t) "/Contents ", 10); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "] \n", 3); + written += t2pWriteFile(output, (tdata_t) "/Contents ", 10); buflen=sprintf(buffer, "%lu", (unsigned long)(object + 1)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R \r", 6); - written += TIFFWriteFile(output, (tdata_t) "/Resources << \r", 15); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R \n", 6); + written += t2pWriteFile(output, (tdata_t) "/Resources << \n", 15); if( t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount != 0 ){ - written += TIFFWriteFile(output, (tdata_t) "/XObject <<\r", 12); + written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12); for(i=0;itiff_tiles[t2p->pdf_page].tiles_tilecount;i++){ - written += TIFFWriteFile(output, (tdata_t) "/Im", 3); + written += t2pWriteFile(output, (tdata_t) "/Im", 3); buflen = sprintf(buffer, "%u", t2p->pdf_page+1); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "_", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "_", 1); buflen = sprintf(buffer, "%u", i+1); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " ", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " ", 1); buflen = sprintf( buffer, "%lu", (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); if(i%4==3){ - written += TIFFWriteFile(output, (tdata_t) "\r", 1); + written += t2pWriteFile(output, (tdata_t) "\n", 1); } } - written += TIFFWriteFile(output, (tdata_t) ">>\r", 3); + written += t2pWriteFile(output, (tdata_t) ">>\n", 3); } else { - written += TIFFWriteFile(output, (tdata_t) "/XObject <<\r", 12); - written += TIFFWriteFile(output, (tdata_t) "/Im", 3); + written += t2pWriteFile(output, (tdata_t) "/XObject <<\n", 12); + written += t2pWriteFile(output, (tdata_t) "/Im", 3); buflen = sprintf(buffer, "%u", t2p->pdf_page+1); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " ", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " ", 1); buflen = sprintf( buffer, "%lu", (unsigned long)(object+3+(2*i)+t2p->tiff_pages[t2p->pdf_page].page_extra)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); - written += TIFFWriteFile(output, (tdata_t) ">>\r", 3); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) ">>\n", 3); } if(t2p->tiff_transferfunctioncount != 0) { - written += TIFFWriteFile(output, (tdata_t) "/ExtGState <<", 13); - TIFFWriteFile(output, (tdata_t) "/GS1 ", 5); + written += t2pWriteFile(output, (tdata_t) "/ExtGState <<", 13); + t2pWriteFile(output, (tdata_t) "/GS1 ", 5); buflen = sprintf( buffer, "%lu", (unsigned long)(object + 3)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); - written += TIFFWriteFile(output, (tdata_t) ">> \r", 4); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) ">> \n", 4); } - written += TIFFWriteFile(output, (tdata_t) "/ProcSet [ ", 11); + written += t2pWriteFile(output, (tdata_t) "/ProcSet [ ", 11); if(t2p->pdf_colorspace == T2P_CS_BILEVEL || t2p->pdf_colorspace == T2P_CS_GRAY ){ - written += TIFFWriteFile(output, (tdata_t) "/ImageB ", 8); + written += t2pWriteFile(output, (tdata_t) "/ImageB ", 8); } else { - written += TIFFWriteFile(output, (tdata_t) "/ImageC ", 8); + written += t2pWriteFile(output, (tdata_t) "/ImageC ", 8); if(t2p->pdf_colorspace & T2P_CS_PALETTE){ - written += TIFFWriteFile(output, (tdata_t) "/ImageI ", 8); + written += t2pWriteFile(output, (tdata_t) "/ImageI ", 8); } } - written += TIFFWriteFile(output, (tdata_t) "]\r>>\r>>\r", 8); + written += t2pWriteFile(output, (tdata_t) "]\n>>\n>>\n", 8); return(written); } @@ -4114,19 +4263,25 @@ static void t2p_compose_pdf_page(T2P* t2 t2p->pdf_xres = t2p->tiff_xres; t2p->pdf_yres = t2p->tiff_yres; - if(t2p->pdf_overrideres){ + if(t2p->pdf_overrideres) { t2p->pdf_xres = t2p->pdf_defaultxres; t2p->pdf_yres = t2p->pdf_defaultyres; } - if(t2p->pdf_xres==0.0){ + if(t2p->pdf_xres == 0.0) t2p->pdf_xres = t2p->pdf_defaultxres; - } - if(t2p->pdf_yres==0.0){ + if(t2p->pdf_yres == 0.0) t2p->pdf_yres = t2p->pdf_defaultyres; + if (t2p->tiff_resunit != RESUNIT_CENTIMETER /* RESUNIT_NONE and */ + && t2p->tiff_resunit != RESUNIT_INCH) { /* other cases */ + t2p->pdf_imagewidth = ((float)(t2p->tiff_width))/t2p->pdf_xres; + t2p->pdf_imagelength = ((float)(t2p->tiff_length))/t2p->pdf_yres; + } else { + t2p->pdf_imagewidth = + ((float)(t2p->tiff_width))*PS_UNIT_SIZE/t2p->pdf_xres; + t2p->pdf_imagelength = + ((float)(t2p->tiff_length))*PS_UNIT_SIZE/t2p->pdf_yres; } - t2p->pdf_imagewidth=((float)(t2p->tiff_width)) *72.0F / t2p->pdf_xres; - t2p->pdf_imagelength=((float)(t2p->tiff_length)) *72.0F / t2p->pdf_yres; - if(t2p->pdf_overridepagesize != 0){ + if(t2p->pdf_overridepagesize != 0) { t2p->pdf_pagewidth = t2p->pdf_defaultpagewidth; t2p->pdf_pagelength = t2p->pdf_defaultpagelength; } else { @@ -4429,7 +4584,7 @@ static tsize_t t2p_write_pdf_page_conten for(i=0;itiff_tiles[t2p->pdf_page].tiles_tilecount; i++){ box=t2p->tiff_tiles[t2p->pdf_page].tiles_tiles[i].tile_box; buflen=sprintf(buffer, - "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d_%ld Do Q\r", + "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d_%ld Do Q\n", t2p->tiff_transferfunctioncount?"/GS1 gs ":"", box.mat[0], box.mat[1], @@ -4444,7 +4599,7 @@ static tsize_t t2p_write_pdf_page_conten } else { box=t2p->pdf_imagebox; buflen=sprintf(buffer, - "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d Do Q\r", + "q %s %.4f %.4f %.4f %.4f %.4f %.4f cm /Im%d Do Q\n", t2p->tiff_transferfunctioncount?"/GS1 gs ":"", box.mat[0], box.mat[1], @@ -4472,17 +4627,17 @@ static tsize_t t2p_write_pdf_xobject_str int buflen=0; written += t2p_write_pdf_stream_dict(0, t2p->pdf_xrefcount+1, output); - written += TIFFWriteFile(output, - (tdata_t) "/Type /XObject \r/Subtype /Image \r/Name /Im", + written += t2pWriteFile(output, + (tdata_t) "/Type /XObject \n/Subtype /Image \n/Name /Im", 42); buflen=sprintf(buffer, "%u", t2p->pdf_page+1); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); if(tile != 0){ - written += TIFFWriteFile(output, (tdata_t) "_", 1); + written += t2pWriteFile(output, (tdata_t) "_", 1); buflen=sprintf(buffer, "%lu", (unsigned long)tile); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); } - written += TIFFWriteFile(output, (tdata_t) "\r/Width ", 8); + written += t2pWriteFile(output, (tdata_t) "\n/Width ", 8); _TIFFmemset((tdata_t)buffer, 0x00, 16); if(tile==0){ buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_width); @@ -4499,8 +4654,8 @@ static tsize_t t2p_write_pdf_xobject_str (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); } } - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "\r/Height ", 9); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "\n/Height ", 9); _TIFFmemset((tdata_t)buffer, 0x00, 16); if(tile==0){ buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_length); @@ -4517,16 +4672,16 @@ static tsize_t t2p_write_pdf_xobject_str (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); } } - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "\r/BitsPerComponent ", 19); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "\n/BitsPerComponent ", 19); _TIFFmemset((tdata_t)buffer, 0x00, 16); buflen=sprintf(buffer, "%u", t2p->tiff_bitspersample); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "\r/ColorSpace ", 13); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "\n/ColorSpace ", 13); written += t2p_write_pdf_xobject_cs(t2p, output); if (t2p->pdf_image_interpolate) - written += TIFFWriteFile(output, - (tdata_t) "\r/Interpolate true", 18); + written += t2pWriteFile(output, + (tdata_t) "\n/Interpolate true", 18); if( (t2p->pdf_switchdecode != 0) #ifdef CCITT_SUPPORT && ! (t2p->pdf_colorspace == T2P_CS_BILEVEL @@ -4560,66 +4715,66 @@ static tsize_t t2p_write_pdf_xobject_cs( return(written); } if( (t2p->pdf_colorspace & T2P_CS_PALETTE) != 0){ - written += TIFFWriteFile(output, (tdata_t) "[ /Indexed ", 11); + written += t2pWriteFile(output, (tdata_t) "[ /Indexed ", 11); t2p->pdf_colorspace ^= T2P_CS_PALETTE; written += t2p_write_pdf_xobject_cs(t2p, output); t2p->pdf_colorspace |= T2P_CS_PALETTE; buflen=sprintf(buffer, "%u", (0x0001 << t2p->tiff_bitspersample)-1 ); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " ", 1); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " ", 1); _TIFFmemset(buffer, 0x00, 16); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_palettecs ); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ]\r", 7); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ]\n", 7); return(written); } if(t2p->pdf_colorspace & T2P_CS_BILEVEL){ - written += TIFFWriteFile(output, (tdata_t) "/DeviceGray \r", 13); + written += t2pWriteFile(output, (tdata_t) "/DeviceGray \n", 13); } if(t2p->pdf_colorspace & T2P_CS_GRAY){ if(t2p->pdf_colorspace & T2P_CS_CALGRAY){ written += t2p_write_pdf_xobject_calcs(t2p, output); } else { - written += TIFFWriteFile(output, (tdata_t) "/DeviceGray \r", 13); + written += t2pWriteFile(output, (tdata_t) "/DeviceGray \n", 13); } } if(t2p->pdf_colorspace & T2P_CS_RGB){ if(t2p->pdf_colorspace & T2P_CS_CALRGB){ written += t2p_write_pdf_xobject_calcs(t2p, output); } else { - written += TIFFWriteFile(output, (tdata_t) "/DeviceRGB \r", 12); + written += t2pWriteFile(output, (tdata_t) "/DeviceRGB \n", 12); } } if(t2p->pdf_colorspace & T2P_CS_CMYK){ - written += TIFFWriteFile(output, (tdata_t) "/DeviceCMYK \r", 13); + written += t2pWriteFile(output, (tdata_t) "/DeviceCMYK \n", 13); } if(t2p->pdf_colorspace & T2P_CS_LAB){ - written += TIFFWriteFile(output, (tdata_t) "[/Lab << \r", 10); - written += TIFFWriteFile(output, (tdata_t) "/WhitePoint ", 12); + written += t2pWriteFile(output, (tdata_t) "[/Lab << \n", 10); + written += t2pWriteFile(output, (tdata_t) "/WhitePoint ", 12); X_W = t2p->tiff_whitechromaticities[0]; Y_W = t2p->tiff_whitechromaticities[1]; Z_W = 1.0F - (X_W + Y_W); X_W /= Y_W; Z_W /= Y_W; Y_W = 1.0F; - buflen=sprintf(buffer, "[%.4f %.4f %.4f] \r", X_W, Y_W, Z_W); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); X_W = 0.3457F; /* 0.3127F; */ /* D50, commented D65 */ Y_W = 0.3585F; /* 0.3290F; */ Z_W = 1.0F - (X_W + Y_W); X_W /= Y_W; Z_W /= Y_W; Y_W = 1.0F; - buflen=sprintf(buffer, "[%.4f %.4f %.4f] \r", X_W, Y_W, Z_W); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "/Range ", 7); - buflen=sprintf(buffer, "[%d %d %d %d] \r", + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "/Range ", 7); + buflen=sprintf(buffer, "[%d %d %d %d] \n", t2p->pdf_labrange[0], t2p->pdf_labrange[1], t2p->pdf_labrange[2], t2p->pdf_labrange[3]); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) ">>] \r", 5); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) ">>] \n", 5); } @@ -4632,30 +4787,30 @@ static tsize_t t2p_write_pdf_transfer(T2 char buffer[16]; int buflen=0; - written += TIFFWriteFile(output, (tdata_t) "<< /Type /ExtGState \r/TR ", 25); + written += t2pWriteFile(output, (tdata_t) "<< /Type /ExtGState \n/TR ", 25); if(t2p->tiff_transferfunctioncount == 1){ buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); } else { - written += TIFFWriteFile(output, (tdata_t) "[ ", 2); + written += t2pWriteFile(output, (tdata_t) "[ ", 2); buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 2)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 3)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R ", 5); - written += TIFFWriteFile(output, (tdata_t) "/Identity ] ", 12); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R ", 5); + written += t2pWriteFile(output, (tdata_t) "/Identity ] ", 12); } - written += TIFFWriteFile(output, (tdata_t) " >> \r", 5); + written += t2pWriteFile(output, (tdata_t) " >> \n", 5); return(written); } @@ -4667,12 +4822,12 @@ static tsize_t t2p_write_pdf_transfer_di int buflen=0; (void)i; // XXX - written += TIFFWriteFile(output, (tdata_t) "/FunctionType 0 \r", 17); - written += TIFFWriteFile(output, (tdata_t) "/Domain [0.0 1.0] \r", 19); - written += TIFFWriteFile(output, (tdata_t) "/Range [0.0 1.0] \r", 18); - buflen=sprintf(buffer, "/Size [%u] \r", (1<tiff_bitspersample)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "/BitsPerSample 16 \r", 19); + written += t2pWriteFile(output, (tdata_t) "/FunctionType 0 \n", 17); + written += t2pWriteFile(output, (tdata_t) "/Domain [0.0 1.0] \n", 19); + written += t2pWriteFile(output, (tdata_t) "/Range [0.0 1.0] \n", 18); + buflen=sprintf(buffer, "/Size [%u] \n", (1<tiff_bitspersample)); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "/BitsPerSample 16 \n", 19); written += t2p_write_pdf_stream_dict(1<<(t2p->tiff_bitspersample+1), 0, output); return(written); @@ -4725,9 +4880,9 @@ static tsize_t t2p_write_pdf_xobject_cal float G=1.0; float B=1.0; - written += TIFFWriteFile(output, (tdata_t) "[", 1); + written += t2pWriteFile(output, (tdata_t) "[", 1); if(t2p->pdf_colorspace & T2P_CS_CALGRAY){ - written += TIFFWriteFile(output, (tdata_t) "/CalGray ", 9); + written += t2pWriteFile(output, (tdata_t) "/CalGray ", 9); X_W = t2p->tiff_whitechromaticities[0]; Y_W = t2p->tiff_whitechromaticities[1]; Z_W = 1.0F - (X_W + Y_W); @@ -4736,7 +4891,7 @@ static tsize_t t2p_write_pdf_xobject_cal Y_W = 1.0F; } if(t2p->pdf_colorspace & T2P_CS_CALRGB){ - written += TIFFWriteFile(output, (tdata_t) "/CalRGB ", 8); + written += t2pWriteFile(output, (tdata_t) "/CalRGB ", 8); x_w = t2p->tiff_whitechromaticities[0]; y_w = t2p->tiff_whitechromaticities[1]; x_r = t2p->tiff_primarychromaticities[0]; @@ -4762,26 +4917,26 @@ static tsize_t t2p_write_pdf_xobject_cal Z_W /= Y_W; Y_W = 1.0; } - written += TIFFWriteFile(output, (tdata_t) "<< \r", 4); + written += t2pWriteFile(output, (tdata_t) "<< \n", 4); if(t2p->pdf_colorspace & T2P_CS_CALGRAY){ - written += TIFFWriteFile(output, (tdata_t) "/WhitePoint ", 12); - buflen=sprintf(buffer, "[%.4f %.4f %.4f] \r", X_W, Y_W, Z_W); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "/Gamma 2.2 \r", 12); + written += t2pWriteFile(output, (tdata_t) "/WhitePoint ", 12); + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "/Gamma 2.2 \n", 12); } if(t2p->pdf_colorspace & T2P_CS_CALRGB){ - written += TIFFWriteFile(output, (tdata_t) "/WhitePoint ", 12); - buflen=sprintf(buffer, "[%.4f %.4f %.4f] \r", X_W, Y_W, Z_W); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "/Matrix ", 8); - buflen=sprintf(buffer, "[%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f] \r", + written += t2pWriteFile(output, (tdata_t) "/WhitePoint ", 12); + buflen=sprintf(buffer, "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "/Matrix ", 8); + buflen=sprintf(buffer, "[%.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f] \n", X_R, Y_R, Z_R, X_G, Y_G, Z_G, X_B, Y_B, Z_B); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "/Gamma [2.2 2.2 2.2] \r", 22); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "/Gamma [2.2 2.2 2.2] \n", 22); } - written += TIFFWriteFile(output, (tdata_t) ">>] \r", 5); + written += t2pWriteFile(output, (tdata_t) ">>] \n", 5); return(written); } @@ -4796,10 +4951,10 @@ static tsize_t t2p_write_pdf_xobject_icc char buffer[16]; int buflen=0; - written += TIFFWriteFile(output, (tdata_t) "[/ICCBased ", 11); + written += t2pWriteFile(output, (tdata_t) "[/ICCBased ", 11); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_icccs); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " 0 R] \r", 7); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " 0 R] \n", 7); return(written); } @@ -4810,10 +4965,10 @@ static tsize_t t2p_write_pdf_xobject_icc char buffer[16]; int buflen=0; - written += TIFFWriteFile(output, (tdata_t) "/N ", 3); - buflen=sprintf(buffer, "%u \r", t2p->tiff_samplesperpixel); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) "/Alternate ", 11); + written += t2pWriteFile(output, (tdata_t) "/N ", 3); + buflen=sprintf(buffer, "%u \n", t2p->tiff_samplesperpixel); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) "/Alternate ", 11); t2p->pdf_colorspace ^= T2P_CS_ICCBASED; written += t2p_write_pdf_xobject_cs(t2p, output); t2p->pdf_colorspace |= T2P_CS_ICCBASED; @@ -4859,11 +5014,11 @@ static tsize_t t2p_write_pdf_xobject_dec tsize_t written=0; int i=0; - written += TIFFWriteFile(output, (tdata_t) "/Decode [ ", 10); + written += t2pWriteFile(output, (tdata_t) "/Decode [ ", 10); for (i=0;itiff_samplesperpixel;i++){ - written += TIFFWriteFile(output, (tdata_t) "1 0 ", 4); + written += t2pWriteFile(output, (tdata_t) "1 0 ", 4); } - written += TIFFWriteFile(output, (tdata_t) "]\r", 2); + written += t2pWriteFile(output, (tdata_t) "]\n", 2); return(written); } @@ -4882,93 +5037,93 @@ static tsize_t t2p_write_pdf_xobject_str if(t2p->pdf_compression==T2P_COMPRESS_NONE){ return(written); } - written += TIFFWriteFile(output, (tdata_t) "/Filter ", 8); + written += t2pWriteFile(output, (tdata_t) "/Filter ", 8); switch(t2p->pdf_compression){ #ifdef CCITT_SUPPORT case T2P_COMPRESS_G4: - written += TIFFWriteFile(output, (tdata_t) "/CCITTFaxDecode ", 16); - written += TIFFWriteFile(output, (tdata_t) "/DecodeParms ", 13); - written += TIFFWriteFile(output, (tdata_t) "<< /K -1 ", 9); + written += t2pWriteFile(output, (tdata_t) "/CCITTFaxDecode ", 16); + written += t2pWriteFile(output, (tdata_t) "/DecodeParms ", 13); + written += t2pWriteFile(output, (tdata_t) "<< /K -1 ", 9); if(tile==0){ - written += TIFFWriteFile(output, (tdata_t) "/Columns ", 9); + written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_width); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " /Rows ", 7); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->tiff_length); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { if(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){ - written += TIFFWriteFile(output, (tdata_t) "/Columns ", 9); + written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); buflen=sprintf( buffer, "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { - written += TIFFWriteFile(output, (tdata_t) "/Columns ", 9); + written += t2pWriteFile(output, (tdata_t) "/Columns ", 9); buflen=sprintf( buffer, "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); } if(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile-1)==0){ - written += TIFFWriteFile(output, (tdata_t) " /Rows ", 7); + written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); buflen=sprintf( buffer, "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); } else { - written += TIFFWriteFile(output, (tdata_t) " /Rows ", 7); + written += t2pWriteFile(output, (tdata_t) " /Rows ", 7); buflen=sprintf( buffer, "%lu", (unsigned long)t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); } } if(t2p->pdf_switchdecode == 0){ - written += TIFFWriteFile(output, (tdata_t) " /BlackIs1 true ", 16); + written += t2pWriteFile(output, (tdata_t) " /BlackIs1 true ", 16); } - written += TIFFWriteFile(output, (tdata_t) ">>\r", 3); + written += t2pWriteFile(output, (tdata_t) ">>\n", 3); break; #endif #ifdef JPEG_SUPPORT case T2P_COMPRESS_JPEG: - written += TIFFWriteFile(output, (tdata_t) "/DCTDecode ", 11); + written += t2pWriteFile(output, (tdata_t) "/DCTDecode ", 11); if(t2p->tiff_photometric != PHOTOMETRIC_YCBCR) { - written += TIFFWriteFile(output, (tdata_t) "/DecodeParms ", 13); - written += TIFFWriteFile(output, (tdata_t) "<< /ColorTransform 0 >>\r", 24); + written += t2pWriteFile(output, (tdata_t) "/DecodeParms ", 13); + written += t2pWriteFile(output, (tdata_t) "<< /ColorTransform 0 >>\n", 24); } break; #endif #ifdef ZIP_SUPPORT case T2P_COMPRESS_ZIP: - written += TIFFWriteFile(output, (tdata_t) "/FlateDecode ", 13); + written += t2pWriteFile(output, (tdata_t) "/FlateDecode ", 13); if(t2p->pdf_compressionquality%100){ - written += TIFFWriteFile(output, (tdata_t) "/DecodeParms ", 13); - written += TIFFWriteFile(output, (tdata_t) "<< /Predictor ", 14); + written += t2pWriteFile(output, (tdata_t) "/DecodeParms ", 13); + written += t2pWriteFile(output, (tdata_t) "<< /Predictor ", 14); _TIFFmemset(buffer, 0x00, 16); buflen=sprintf(buffer, "%u", t2p->pdf_compressionquality%100); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " /Columns ", 10); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " /Columns ", 10); _TIFFmemset(buffer, 0x00, 16); buflen = sprintf(buffer, "%lu", (unsigned long)t2p->tiff_width); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " /Colors ", 9); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " /Colors ", 9); _TIFFmemset(buffer, 0x00, 16); buflen=sprintf(buffer, "%u", t2p->tiff_samplesperpixel); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " /BitsPerComponent ", 19); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " /BitsPerComponent ", 19); _TIFFmemset(buffer, 0x00, 16); buflen=sprintf(buffer, "%u", t2p->tiff_bitspersample); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) ">>\r", 3); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) ">>\n", 3); } break; #endif @@ -4990,21 +5145,21 @@ static tsize_t t2p_write_pdf_xreftable(T int buflen=0; uint32 i=0; - written += TIFFWriteFile(output, (tdata_t) "xref\r0 ", 7); + written += t2pWriteFile(output, (tdata_t) "xref\n0 ", 7); buflen=sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount + 1)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); - written += TIFFWriteFile(output, (tdata_t) " \r0000000000 65535 f\r\n", 22); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) " \n0000000000 65535 f \n", 22); for (i=0;ipdf_xrefcount;i++){ - sprintf(buffer, "%.10lu 00000 n\r\n", + sprintf(buffer, "%.10lu 00000 n \n", (unsigned long)t2p->pdf_xrefoffsets[i]); - written += TIFFWriteFile(output, (tdata_t) buffer, 20); + written += t2pWriteFile(output, (tdata_t) buffer, 20); } return(written); } /* - * This function writes a PDF trailer to output. + * This function writes a PDF trailer to output. */ static tsize_t t2p_write_pdf_trailer(T2P* t2p, TIFF* output) @@ -5013,15 +5168,13 @@ static tsize_t t2p_write_pdf_trailer(T2P tsize_t written = 0; char buffer[32]; int buflen = 0; - int ifileidbuf[4]; - char *fileidbuf = (char*)ifileidbuf; + char fileidbuf[16]; int i = 0; - ifileidbuf[0] = rand(); - ifileidbuf[1] = rand(); - ifileidbuf[2] = rand(); - ifileidbuf[3] = rand(); - t2p->pdf_fileid = (char*)_TIFFmalloc(33); + for (i=0; i<(int)sizeof(fileidbuf); i++) + fileidbuf[i] = (char) rand(); + + t2p->pdf_fileid = (unsigned char*)_TIFFmalloc(33); if(t2p->pdf_fileid == NULL) { TIFFError( TIFF2PDF_MODULE, @@ -5031,29 +5184,31 @@ static tsize_t t2p_write_pdf_trailer(T2P return(0); } _TIFFmemset(t2p->pdf_fileid, 0x00, 33); - for (i=0; i<16; i++) - sprintf(&(t2p->pdf_fileid[2*i]), "%.2hhX", fileidbuf[i]); - written += TIFFWriteFile(output, (tdata_t) "trailer\r<<\r/Size ", 17); + for (i = 0; i < 16; i++) { + sprintf((char *)t2p->pdf_fileid + 2 * i, + "%.2hhX", fileidbuf[i]); + } + written += t2pWriteFile(output, (tdata_t) "trailer\n<<\n/Size ", 17); buflen = sprintf(buffer, "%lu", (unsigned long)(t2p->pdf_xrefcount+1)); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); _TIFFmemset(buffer, 0x00, 32); - written += TIFFWriteFile(output, (tdata_t) "\r/Root ", 7); + written += t2pWriteFile(output, (tdata_t) "\n/Root ", 7); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_catalog); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); _TIFFmemset(buffer, 0x00, 32); - written += TIFFWriteFile(output, (tdata_t) " 0 R \r/Info ", 12); + written += t2pWriteFile(output, (tdata_t) " 0 R \n/Info ", 12); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_info); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); _TIFFmemset(buffer, 0x00, 32); - written += TIFFWriteFile(output, (tdata_t) " 0 R \r/ID[<", 11); - written += TIFFWriteFile(output, (tdata_t) t2p->pdf_fileid, 32); - written += TIFFWriteFile(output, (tdata_t) "><", 2); - written += TIFFWriteFile(output, (tdata_t) t2p->pdf_fileid, 32); - written += TIFFWriteFile(output, (tdata_t) ">]\r>>\rstartxref\r", 16); + written += t2pWriteFile(output, (tdata_t) " 0 R \n/ID[<", 11); + written += t2pWriteFile(output, (tdata_t) t2p->pdf_fileid, 32); + written += t2pWriteFile(output, (tdata_t) "><", 2); + written += t2pWriteFile(output, (tdata_t) t2p->pdf_fileid, 32); + written += t2pWriteFile(output, (tdata_t) ">]\n>>\nstartxref\n", 16); buflen=sprintf(buffer, "%lu", (unsigned long)t2p->pdf_startxref); - written += TIFFWriteFile(output, (tdata_t) buffer, buflen); + written += t2pWriteFile(output, (tdata_t) buffer, buflen); _TIFFmemset(buffer, 0x00, 32); - written += TIFFWriteFile(output, (tdata_t) "\r%%EOF\r", 7); + written += t2pWriteFile(output, (tdata_t) "\n%%EOF\n", 7); return(written); } @@ -5067,7 +5222,7 @@ static tsize_t t2p_write_pdf_trailer(T2P library, and TIFFWriteEncodedStrip can be used to write compressed data to the output. The output is not actually a TIFF file, it is a PDF file. - This function uses only TIFFWriteFile and TIFFWriteEncodedStrip to write to + This function uses only t2pWriteFile and TIFFWriteEncodedStrip to write to the output TIFF file. When libtiff would otherwise be writing data to the output file, the write procedure of the TIFF structure is replaced with an empty implementation. @@ -5088,7 +5243,7 @@ static tsize_t t2p_write_pdf_trailer(T2P assert(output != NULL); if(output->tif_seekproc != NULL){ - TIFFSeekFile(output, (toff_t) 0, SEEK_SET); + t2pSeekFile(output, (toff_t) 0, SEEK_SET); } This function returns the file size of the output PDF file. On error it @@ -5112,7 +5267,7 @@ static tsize_t t2p_write_pdf(T2P* t2p, T TIFFError( TIFF2PDF_MODULE, "Can't allocate %lu bytes of memory for t2p_write_pdf", - t2p->pdf_xrefcount * sizeof(uint32) ); + t2p->pdf_xrefcount * (long)sizeof(uint32) ); return(written); } t2p->pdf_xrefcount=0; @@ -5252,13 +5407,14 @@ static tsize_t t2p_write_pdf(T2P* t2p, T written += t2p_write_pdf_obj_end(output); } } - t2p->pdf_startxref=written; + t2p->pdf_startxref = written; written += t2p_write_pdf_xreftable(t2p, output); written += t2p_write_pdf_trailer(t2p, output); - t2p_disable(output); + t2p_disable(output); + return(written); } -#endif - /* vim: set ts=8 sts=8 sw=8 noet: */ + +#endif --- djview4-4.9.orig/src/qdjviewprefsdialog.ui +++ djview4-4.9/src/qdjviewprefsdialog.ui @@ -7,7 +7,7 @@ 0 0 509 - 374 + 388 @@ -1126,6 +1126,16 @@ + + + Render with openGL when available + + + true + + + + Override saving and printing restrictions @@ -1317,6 +1327,7 @@ animationCheckBox advancedCheckBox textLabelCheckBox + openGLCheckBox restrictOverrideCheckBox printerManualCheckBox printerGammaSpinBox --- djview4-4.9.orig/src/djview.cpp +++ djview4-4.9/src/djview.cpp @@ -121,13 +121,18 @@ QDjViewApplication::QDjViewApplication(i // Install translators QStringList langs = getTranslationLangs(); - QTranslator *qtTrans = new QTranslator(this); - if (loadTranslator(qtTrans, "qt", langs)) - installTranslator(qtTrans); QTranslator *djviewTrans = new QTranslator(this); - if (loadTranslator(djviewTrans, "djview", langs)) - installTranslator(djviewTrans); - + QTranslator *qtTrans = new QTranslator(this); + if (loadTranslators(langs, djviewTrans, qtTrans)) + { + installTranslator(qtTrans); + installTranslator(djviewTrans); + } + else + { + delete qtTrans; + delete djviewTrans; + } // Application is ready appReady = true; } @@ -154,19 +159,6 @@ addDirectory(QStringList &dirs, QString } -static void -addLang(QStringList &langs, QString s) -{ - if (s.size() <= 0) - return; - if (! langs.contains(s)) - langs << s; - QString sl = s.toLower(); - if (sl != s && ! langs.contains(sl)) - langs << sl; -} - - QStringList QDjViewApplication::getTranslationDirs() { @@ -201,6 +193,24 @@ QDjViewApplication::getTranslationDirs() } +static void +addLang(QStringList &langs, QString s) +{ + if (s.size() > 0) + { + s = s.replace(QChar('-'), QChar('_')); + if (! langs.contains(s)) + langs << s; +#ifdef Q_WS_MAC + if (s == "zh_Hans" && ! langs.contains("zh_CN")) + langs << "zh_CN"; + if (s == "zh_Hant" && ! langs.contains("zh_TW")) + langs << "zh_TW"; +#endif + } +} + + QStringList QDjViewApplication::getTranslationLangs() { @@ -214,9 +224,7 @@ QDjViewApplication::getTranslationLangs( #ifdef LC_MESSAGES addLang(langs, QString::fromLocal8Bit(::setlocale(LC_MESSAGES, 0))); #endif -#ifdef LC_ALL - addLang(langs, QString::fromLocal8Bit(::setlocale(LC_ALL, 0))); -#endif + addLang(langs, QString::fromLocal8Bit(::getenv("LANG"))); #ifdef Q_WS_MAC QSettings g(".", "globalPreferences"); foreach (QString lang, g.value("AppleLanguages").toStringList()) @@ -229,26 +237,43 @@ QDjViewApplication::getTranslationLangs( } -bool -QDjViewApplication::loadTranslator(QTranslator *trans, - QString name, QStringList langs) +static bool loadOneTranslator(QTranslator *trans, + QString name, QString lang, QStringList dirs) { - foreach (QString lang, langs) + QString llang = lang.toLower(); + foreach (QString dir, dirs) { - foreach (QString dir, getTranslationDirs()) + dir = dir.replace(QRegExp("\\$LANG(?!\\w)"), lang); + QDir qdir(dir); + if (qdir.exists()) { - dir = dir.replace(QRegExp("\\$LANG(?!\\w)"), lang); - QDir qdir(dir); - if (qdir.exists()) - if (trans->load(name + "_" + lang, dir, "_.-")) - return true; - if (lang.startsWith("en_") || lang == "en" || lang == "c") - break; + if (trans->load(name + "_" + lang, dir, "_.-")) + return true; + if (lang != llang && trans->load(name + "_" + llang, dir, "_.-")) + return true; } } return false; } +bool +QDjViewApplication::loadTranslators(QStringList langs, + QTranslator *dTrans, QTranslator *qTrans) +{ + QStringList dirs = getTranslationDirs(); + foreach (QString lang, langs) + { + bool okay = true; + if (okay && dTrans && !loadOneTranslator(dTrans, "djview", lang, dirs)) + okay = false; + if (okay && qTrans && !loadOneTranslator(qTrans, "qt", lang, dirs)) + okay = false; + if (okay || lang.startsWith("en_") || lang == "en") + return okay; + } + return false; +} + bool QDjViewApplication::event(QEvent *ev) @@ -359,6 +384,7 @@ usage() exit(10); } + int main(int argc, char *argv[]) { @@ -369,11 +395,21 @@ main(int argc, char *argv[]) // Message handler qInstallMsgHandler(qtMessageHandler); + + // Set verbose flag as early as possible #ifdef Q_OS_UNIX const char *s = ::getenv("DJVIEW_VERBOSE"); if (s && strcmp(s,"0")) verbose = true; #endif + for (int i=1; iopenGLAccel, central); widget->setFrameShape(QFrame::NoFrame); if (viewerMode == STANDALONE) widget->setFrameShadow(QFrame::Sunken); --- djview4-4.9.orig/src/qdjvuwidget.cpp +++ djview4-4.9/src/qdjvuwidget.cpp @@ -53,6 +53,8 @@ #include #include #include +#include +#include #if DDJVUAPI_VERSION < 17 @@ -857,6 +859,7 @@ public: QCursor cursHandOpen; QCursor cursHandClosed; + void initWidget(bool noaccel); void changeLayout(int change, int delay=0); void getAnnotationsAndText(Page *p); bool requestPage(Page *p); @@ -1108,10 +1111,9 @@ QDjVuPrivate::makeLayout() for(int i=0; i= hiPage + 2) pageData[i].clear(); - if (continuous || sideBySide) - adjustSettings(PRIORITY_ANNO, miniexp_nil); - else - adjustSettings(PRIORITY_ANNO, pageLayout[0]->annotations); + // Display settings are unclear when showing multiple page. + // We use the annotations of the first displayed page as a proxy. + adjustSettings(PRIORITY_ANNO, pageLayout[0]->annotations); } // Layout page sizes else if (layoutChange & CHANGE_SIZE) @@ -1627,8 +1629,9 @@ QDjVuPrivate::getAnnotationsAndText(Page if (p->annotations == miniexp_dummy) { p->annotations = doc->getPageAnnotations(p->pageno); - if (p->annotations && !continuous && !sideBySide) - adjustSettings(PRIORITY_ANNO, p->annotations); + if (p->annotations) + if (pageLayout.size() > 0 && p == pageLayout[0]) + adjustSettings(PRIORITY_ANNO, p->annotations); if (p->annotations) prepareMapAreas(p); } @@ -1979,23 +1982,74 @@ QDjVuWidget::~QDjVuWidget() priv = 0; } +// This is a helper for the constructors +void +QDjVuPrivate::initWidget(bool opengl) +{ + // set widget policies + widget->setFocusPolicy(Qt::StrongFocus); + widget->setSizePolicy(QSizePolicy::MinimumExpanding, + QSizePolicy::MinimumExpanding); + // set opengl acceleration +#if QT_VERSION >= 0x040400 + if (opengl) + { + const char *ge = 0; + QGLWidget *gw = 0; + if (! QGLFormat::hasOpenGL()) + ge = "cannot find openGL on this system"; + if (!ge) + gw = new QGLWidget(); + if (gw && !ge && !gw->isValid()) + ge = "cannot setup openGL context"; + if (gw && !ge && !gw->format().directRendering()) + ge = "cannot setup openGL direct rendering"; + if (gw && !ge) + widget->setViewport(gw); + else if (gw) + delete gw; + if (ge) + qWarning("Using default rendering (%s)", ge); + else + qWarning("Using openGL rendering"); + } +#endif + // setup viewport + QWidget *vp = widget->viewport(); +#if QT_VERSION >= 0x040100 + vp->setAttribute(Qt::WA_OpaquePaintEvent); +#endif + vp->setAttribute(Qt::WA_NoSystemBackground); + vp->setAttribute(Qt::WA_StaticContents); + vp->setMouseTracking(true); +} + /*! Construct a \a QDjVuWidget instance. - Argument \a parent is the parent of this widget - in the \a QObject hierarchy. */ + Argument \a parent is the parent of this widget + in the \a QObject hierarchy. Setting argument + \a opengl to true enables openGL acceleration */ + +QDjVuWidget::QDjVuWidget(bool opengl, QWidget *parent) + : QAbstractScrollArea(parent), priv(new QDjVuPrivate(this)) +{ + priv->initWidget(opengl); +} + +/*! Overloaded constructor */ QDjVuWidget::QDjVuWidget(QWidget *parent) : QAbstractScrollArea(parent), priv(new QDjVuPrivate(this)) { - setFocusPolicy(Qt::StrongFocus); - setSizePolicy(QSizePolicy::MinimumExpanding, - QSizePolicy::MinimumExpanding); - // setup viewport -#if QT_VERSION >= 0x040100 - viewport()->setAttribute(Qt::WA_OpaquePaintEvent); -#endif - viewport()->setAttribute(Qt::WA_NoSystemBackground); - viewport()->setAttribute(Qt::WA_StaticContents); - viewport()->setMouseTracking(true); + priv->initWidget(false); +} + +/*! This overloaded constructor calls \a setDocument. */ + +QDjVuWidget::QDjVuWidget(QDjVuDocument *doc, bool opengl, QWidget *parent) + : QAbstractScrollArea(parent), priv(new QDjVuPrivate(this)) +{ + priv->initWidget(opengl); + setDocument(doc); } /*! This overloaded constructor calls \a setDocument. */ @@ -2003,15 +2057,7 @@ QDjVuWidget::QDjVuWidget(QWidget *parent QDjVuWidget::QDjVuWidget(QDjVuDocument *doc, QWidget *parent) : QAbstractScrollArea(parent), priv(new QDjVuPrivate(this)) { - setFocusPolicy(Qt::StrongFocus); - setSizePolicy(QSizePolicy::MinimumExpanding, - QSizePolicy::MinimumExpanding); -#if QT_VERSION >= 0x040100 - viewport()->setAttribute(Qt::WA_OpaquePaintEvent); -#endif - viewport()->setAttribute(Qt::WA_NoSystemBackground); - viewport()->setAttribute(Qt::WA_StaticContents); - viewport()->setMouseTracking(true); + priv->initWidget(false); setDocument(doc); } @@ -3545,8 +3591,7 @@ QDjVuPrivate::prepareMapAreas(Page *p) if (p->mapAreas[j].expr) p->mapAreas.removeAt(j); // parse annotations. - if (p->annotations && - p->annotations != miniexp_dummy) + if (p->annotations && p->annotations != miniexp_dummy) { miniexp_t *annos; annos = ddjvu_anno_get_hyperlinks(p->annotations); --- djview4-4.9.orig/src/qdjvunet.cpp +++ djview4-4.9/src/qdjvunet.cpp @@ -355,7 +355,7 @@ QDjVuNetDocument::setUrl(QDjVuContext *c void QDjVuNetDocument::newstream(int streamid, QString, QUrl url) { - // network request + QString message = tr("Requesting '%1'").arg(url.toString()); QNetworkRequest request(url); QString agent = "Djview/" + QDjViewPrefs::versionString(); request.setRawHeader("User-Agent", agent.toAscii()); @@ -368,9 +368,9 @@ QDjVuNetDocument::newstream(int streamid p, SLOT(sslErrors(const QList&)) ); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), p, SLOT(error(QNetworkReply::NetworkError)) ); - emit info(tr("Requesting '%1'").arg(url.toString())); p->reqid[reply] = streamid; p->reqok[reply] = false; + emit info(message); } --- djview4-4.9.orig/nsdejavu/nsdejavu.c +++ djview4-4.9/nsdejavu/nsdejavu.c @@ -322,9 +322,11 @@ static int WriteStringLen(int fd, const char *str, int length) { int type = TYPE_STRING; + static char zero = 0; if ( (Write(fd, &type, sizeof(type)) < 0) || (Write(fd, &length, sizeof(length)) < 0) || - (Write(fd, str, length+1) < 0) ) + (Write(fd, str, length) < 0) || + (Write(fd, &zero, 1) < 0) ) return -1; return 1; } @@ -1160,8 +1162,8 @@ LoadStatic(void) ********************************** Callbacks ********************************** *******************************************************************************/ -static int Detach(void * id); -static int Resize(void * id); +static int Detach(void *id); +static int Resize(void *id); static void CloseConnection(void); static int IsConnectionOK(int); static void ProgramDied(void); @@ -1659,7 +1661,7 @@ CloseConnection(void) } static int -Resize(void * id) +Resize(void *id) { /* Instead of selecting ConfigureEvent in the application I catch resizeCallback here and send the appropriate request to the @@ -1719,7 +1721,7 @@ Detach(void * id) } static int -Attach(Display * displ, Window window, void * id) +Attach(Display *displ, NPWindow *npw, void *id) { char *displ_str; Instance *inst; @@ -1728,6 +1730,7 @@ Attach(Display * displ, Window window, v Visual *visual; char protocol_str[128]; XWindowAttributes attributes; + Window window = (npw) ? (Window)npw->window : 0; int width, height; #if USE_XT XtAppContext app_context = 0; @@ -1790,7 +1793,11 @@ Attach(Display * displ, Window window, v /* Prepare protocol string */ protocol_str[0]=0; if (inst->xembed_mode) - strcpy(protocol_str, "XEMBED"); + { + width = (npw) ? npw->width : width; + height = (npw) ? npw->height : height; + strcpy(protocol_str, "XEMBED"); + } #if USE_XT else { @@ -2432,7 +2439,7 @@ NPP_SetWindow(NPP np_inst, NPWindow * wi new_window = (win_str) ? (Window) win_str->window : 0; if (cur_window) { - if (new_window==cur_window) + if (new_window == cur_window) { Resize(id); return NPERR_NO_ERROR; @@ -2450,7 +2457,7 @@ NPP_SetWindow(NPP np_inst, NPWindow * wi displ = ((NPSetWindowCallbackStruct *)(win_str->ws_info))->display; if (!IsConnectionOK(FALSE)) return NPERR_GENERIC_ERROR; - if (Attach(displ, new_window, id) < 0) + if (Attach(displ, win_str, id) < 0) { ProgramDied(); return NPERR_GENERIC_ERROR; debian/patches/aarch64_cpu_definitions.patch0000644000000000000000000000304012226211403016316 0ustar Description: Add CPU definitions for aarch64. Author: William Grant --- djview4-4.9.orig/nsdejavu/npsdk/prcpucfg.h +++ djview4-4.9/nsdejavu/npsdk/prcpucfg.h @@ -509,6 +509,52 @@ #define PR_BYTES_PER_WORD_LOG2 2 #define PR_BYTES_PER_DWORD_LOG2 3 +#elif defined(__aarch64__) + +#define IS_LITTLE_ENDIAN 1 +#undef IS_BIG_ENDIAN +#define IS_64 + +#define PR_BYTES_PER_BYTE 1 +#define PR_BYTES_PER_SHORT 2 +#define PR_BYTES_PER_INT 4 +#define PR_BYTES_PER_INT64 8 +#define PR_BYTES_PER_LONG 8 +#define PR_BYTES_PER_FLOAT 4 +#define PR_BYTES_PER_DOUBLE 8 +#define PR_BYTES_PER_WORD 4 +#define PR_BYTES_PER_DWORD 8 + +#define PR_BITS_PER_BYTE 8 +#define PR_BITS_PER_SHORT 16 +#define PR_BITS_PER_INT 32 +#define PR_BITS_PER_INT64 64 +#define PR_BITS_PER_LONG 64 +#define PR_BITS_PER_FLOAT 32 +#define PR_BITS_PER_DOUBLE 64 +#define PR_BITS_PER_WORD 32 + +#define PR_BITS_PER_BYTE_LOG2 3 +#define PR_BITS_PER_SHORT_LOG2 4 +#define PR_BITS_PER_INT_LOG2 5 +#define PR_BITS_PER_INT64_LOG2 6 +#define PR_BITS_PER_LONG_LOG2 6 +#define PR_BITS_PER_FLOAT_LOG2 5 +#define PR_BITS_PER_DOUBLE_LOG2 6 +#define PR_BITS_PER_WORD_LOG2 5 + +#define PR_ALIGN_OF_SHORT 2 +#define PR_ALIGN_OF_INT 4 +#define PR_ALIGN_OF_LONG 4 +#define PR_ALIGN_OF_INT64 8 +#define PR_ALIGN_OF_FLOAT 8 +#define PR_ALIGN_OF_DOUBLE 8 +#define PR_ALIGN_OF_POINTER 8 +#define PR_ALIGN_OF_WORD 4 + +#define PR_BYTES_PER_WORD_LOG2 2 +#define PR_BYTES_PER_DWORD_LOG2 3 + #elif defined(__hppa__) #undef IS_LITTLE_ENDIAN debian/patches/ppc64el.diff0000644000000000000000000000063112322555140012723 0ustar Index: b/nsdejavu/npsdk/prcpucfg.h =================================================================== --- a/nsdejavu/npsdk/prcpucfg.h +++ b/nsdejavu/npsdk/prcpucfg.h @@ -50,8 +50,13 @@ #ifdef __powerpc64__ +#ifdef __LITTLE_ENDIAN__ +#undef IS_BIG_ENDIAN +#define IS_LITTLE_ENDIAN 1 +#else #undef IS_LITTLE_ENDIAN #define IS_BIG_ENDIAN 1 +#endif #define IS_64 #define PR_BYTES_PER_BYTE 1 debian/patches/series0000644000000000000000000000007212322554615012036 0ustar debian-changes aarch64_cpu_definitions.patch ppc64el.diff debian/changelog0000644000000000000000000002151312322556403011044 0ustar djview4 (4.9-4ubuntu3) trusty; urgency=medium * Fix build on ppc64el. -- Matthias Klose Sun, 13 Apr 2014 18:41:40 +0000 djview4 (4.9-4ubuntu1) trusty; urgency=low * Merge from Debian unstable. Remaining changes: - debian/rules: Use dh_autotools-dev rather than dh-autoreconf, so config/config.{sub,guess} actually get updated. - nsdejavu/npsdk/prcpucfg.h: Add aarch64 CPU definitions. -- William Grant Mon, 28 Oct 2013 12:42:48 +1100 djview4 (4.9-4) unstable; urgency=low * bump policy version (no changes needed) * clean some icons generated during build (closes: #679921) * update debian packaging repo urls to current naming scheme * the upstream changelog is called NEWS -- Barak A. Pearlmutter Mon, 30 Sep 2013 12:17:34 +0100 djview4 (4.9-3ubuntu1) saucy; urgency=low * debian/rules: Use dh_autotools-dev rather than dh-autoreconf, so config/config.{sub,guess} actually get updated. * nsdejavu/npsdk/prcpucfg.h: Add aarch64 CPU definitions. -- William Grant Sat, 12 Oct 2013 20:10:34 +1100 djview4 (4.9-3) unstable; urgency=low * merge upstream fixes * add qt-opengl build dependency * allow libtiff5 to satisfy build dependency -- Barak A. Pearlmutter Mon, 12 Nov 2012 12:08:53 +0000 djview4 (4.9-2) unstable; urgency=low * fix plugin bug, see https://bugs.launchpad.net/ubuntu/+source/djvulibre/+bug/940853 -- Barak A. Pearlmutter Sun, 17 Jun 2012 00:20:11 +0100 djview4 (4.9-1) unstable; urgency=low [ Leon Bottou ] * new upstream version [ Barak A. Pearlmutter ] * switch deprecated rsvg to plug-compatible rsvg-convert (closes: #666474) * bump to dh 9 * bump debian policy version -- Barak A. Pearlmutter Wed, 04 Apr 2012 09:25:22 +0100 djview4 (4.8-3) unstable; urgency=low * upstream change giving user ability to allow print/save in plugin -- Barak A. Pearlmutter Sat, 26 Nov 2011 23:11:19 +0000 djview4 (4.8-2) unstable; urgency=low * single debian patch source option (closes: #643093) * ensure rsvg in build dependencies * silence lintian regarding duplicate sections * silence lintian regarding unneeded encoding in desktop file -- Barak A. Pearlmutter Fri, 07 Oct 2011 20:28:47 +0100 djview4 (4.8-1) unstable; urgency=low * new upstream release * tweak plugin installation location * silence some lintian issues: - bump debian standards version - add build-arch build-indep as debian/rules targets - convert djvulibre-djview4.xpm from PNG to XPM - switch empty binary package djvulibre-plugin to arch independent - generate and install not PNG but XPM icon files * work around rejection-inducing lintian bug -- Barak A. Pearlmutter Fri, 29 Jul 2011 14:05:56 +0100 djview4 (4.7-1) unstable; urgency=low * New upstream release -- Barak A. Pearlmutter Mon, 07 Mar 2011 17:21:01 +0000 djview4 (4.6-3) unstable; urgency=low * changes to debian/control - fiddle with sections - have djview-plugin conflict with old versions of djvulibre-plugin which contain the same plugin library (closes: #613352, #613374) * arch patch for Renesas SH from Nobuhiro Iwamatsu (closes: #613310) -- Barak A. Pearlmutter Wed, 16 Feb 2011 17:24:16 +0000 djview4 (4.6-2) unstable; urgency=low * move some debian maintenance to git (debian/README.Debian) - point to debian collab-maint repo (debian/control) - upstream has moved to git (debian/copyright, rm debian/README.Debian) * use dh autotools-dev stuff to update config.* files * enable nsdjvu plugin - generate package djview-plugin - generate transition package djvulibre-plugin * bump to debhelper 8 * dh --parallel -- Barak A. Pearlmutter Thu, 02 Dec 2010 13:45:14 +0000 djview4 (4.6-1) unstable; urgency=low * New upstream release * switch to dpkg-source 3.0 (quilt) format * really automatically clean generated bitmaps in debian/ (debian/clean) * bump policy (debian/control) -- Barak A. Pearlmutter Mon, 16 Aug 2010 22:17:28 +0200 djview4 (4.5-6) unstable; urgency=low * source depend (debian/control) on librsvg2-bin binary used by new imagemagick, and work around failure of direct conversion by convert via step-by-step manual convertion in debian/rules (closes: #574297) * automatically clean generated bitmaps in debian/ (debian/clean) -- Barak A. Pearlmutter Thu, 18 Mar 2010 14:51:54 +0000 djview4 (4.5-5) unstable; urgency=low * rev deb std * work around autobuilder inability to install B when build-dep: A | B -- Barak A. Pearlmutter Thu, 28 Jan 2010 20:34:54 +0100 djview4 (4.5-4) unstable; urgency=low * Build dependency on libwmf-bin for wmf2eps (closes: #556813) or libmagickcore2-extra to allow convert to do the job -- Barak A. Pearlmutter Mon, 30 Nov 2009 21:09:05 +0000 djview4 (4.5-3) unstable; urgency=low * missing dh debian/control misc:depends -- Barak A. Pearlmutter Tue, 29 Sep 2009 15:40:28 -0400 djview4 (4.5-2) unstable; urgency=low * rev deb std * fancier shorter debian/rules * lintian issues (stop ignoring errors in installation scripts) -- Barak A. Pearlmutter Mon, 28 Sep 2009 10:53:40 -0400 djview4 (4.5-1) unstable; urgency=low * Upstream release 4.5 * Man page typos (closes: #526091) thanks to "A. Costa" * Ack upstream fix, open dialog allows un-narrowed list (closes: #504281) -- Barak A. Pearlmutter Wed, 29 Apr 2009 09:36:07 +0100 djview4 (4.4-1) unstable; urgency=low * Upstream release 4.4 * Fully dh7-ianize * Upstream builds PNG from SVG using /usr/bin/convert, requiring build dependency upon imagemagick * Integrate new upstream icons -- Barak A. Pearlmutter Mon, 08 Sep 2008 08:37:16 +0100 djview4 (4.3-6) unstable; urgency=low * Gentler dependencies, update x-dev dependency * Upstream mods for man and GCC 4.x warnings * Include more upstream translated text * Minor lintian issues (debian/rules clean; deb scripts w/ command path) * Fix user interaction language selection issue harder (closes: #460714) -- Barak A. Pearlmutter Tue, 19 Aug 2008 13:10:25 +0100 djview4 (4.3-5) unstable; urgency=low * Upstream fix for disappearing search box (closes: #484522) * Unable to manifrest save-as giving zero-length file (closes: #468389) * Upstream fix for user interaction language selection (closes: #460714) * Provide virtual package djvu-viewer (see: #491012) * Minor updates to debian packaging info, rev to debhelper 7 -- Barak A. Pearlmutter Mon, 04 Aug 2008 11:34:53 +0100 djview4 (4.3-4) unstable; urgency=low * Add build dependency on pkg-config (closes: #477029) * Fix update-alternatives in installation scripts (closes: #476434) -- Barak A. Pearlmutter Wed, 23 Apr 2008 07:45:17 +0100 djview4 (4.3-3) unstable; urgency=low * Conflict with old djview containing /usr/bin/djview (closes: #473341) * Raise version number of qt4 needed for build (closes: #475021) -- Barak A. Pearlmutter Mon, 07 Apr 2008 23:53:08 -0700 djview4 (4.3-2) unstable; urgency=low * Upstream __sync_... build error fixes in libdjvu/atomic.cpp for sparc, mips, arm, hppa, mipsel, armel. -- Barak A. Pearlmutter Sun, 16 Mar 2008 18:58:53 +0000 djview4 (4.3-1) unstable; urgency=low * Upstream release * New german and czech translation * Remove xlibs-dev build dependency (closes #460254) * Menu section changed from Apps to Applications * avoid empty /usr/sbin/ -- Barak A. Pearlmutter Wed, 30 Jan 2008 11:36:31 +0000 djview4 (4.2-1) unstable; urgency=low * New feature "Undo/Redo". * New entry "Open Location" in "File" menu. * Add vcs-cvs and homepage fields to debian/control * Include (treating as Debian patch) mods in upstream release 4.2-1, which includes fix for bug number 452947 which occurs here as well as in djvulibre against which it was first reported. -- Barak A. Pearlmutter Tue, 20 Nov 2007 18:02:38 +0000 djview4 (4.1-2) unstable; urgency=low * Compatibility fixes for Qt-4.2. * New entry "Open recent" in "File" menu. -- Barak A. Pearlmutter Tue, 31 Jul 2007 23:26:46 +0500 djview4 (4.1-1) unstable; urgency=low * Bug fixes for Qt-4.2 and Qt-4.3. * PDF and TIFF Export. -- Barak A. Pearlmutter Sun, 7 Jul 2007 12:00:46 +0500 djview4 (4.0-1) unstable; urgency=low * Initial release. * Binary dependency on libdjvulibre should be deb-o-matic! * License clarification of mozilla plugin code. -- Barak A. Pearlmutter Thu, 26 Apr 2007 17:50:46 +0300 debian/djvulibre-djview4.xpm0000644000000000000000000001436512226226646013275 0ustar /* XPM */ static char *djvulibre_djview4[] = { /* columns rows colors chars-per-pixel */ "32 32 256 2 ", " c #2F3B62", ". c #3D3165", "X c #783C54", "o c #5B2E62", "O c #443067", "+ c #4E336E", "@ c #563066", "# c #55336B", "$ c #5B316A", "% c #4E3977", "& c #453B7C", "* c #4D3B7A", "= c #523572", "- c #5A3776", "; c #672B61", ": c #64326D", "> c #78306D", ", c #713576", "< c #29436E", "1 c #2C4671", "2 c #7E475E", "3 c #764D5E", "4 c #7D495F", "5 c #6E575F", "6 c #68585A", "7 c #71525E", "8 c #6B5B61", "9 c #645364", "0 c #735F67", "q c #765966", "w c #6F6267", "e c #6D6D6D", "r c #7D616C", "t c #757575", "y c #7C7C7C", "u c #7B7875", "i c #BD7C1C", "p c #AA732A", "a c #B67A2F", "s c #C27D21", "d c #802A5E", "f c #932A58", "g c #883F5D", "h c #823853", "j c #923057", "k c #922D6A", "l c #8F3D62", "z c #973562", "x c #993967", "c c #9B3C68", "v c #863275", "b c #A12D63", "n c #A6376C", "m c #A12F72", "M c #967040", "N c #BC6648", "B c #854361", "V c #8B4866", "C c #895E6E", "Z c #A2406E", "A c #8B6C6D", "S c #8A6374", "D c #94637A", "F c #936A7C", "G c #89737D", "H c #BE822E", "J c #D9890C", "K c #C5841A", "L c #D78911", "P c #DC8C11", "I c #DE931E", "U c #C3892C", "Y c #D69D3C", "T c #EEAF3D", "R c #B08B53", "E c #A08B7E", "W c #C38F45", "Q c #D0A86F", "! c #D1AB72", "~ c #EDC574", "^ c #F1CC73", "/ c #3E3F80", "( c #643C80", ") c #7A3F80", "_ c #314586", "` c #3C4282", "' c #405599", "] c #485B9D", "[ c #585997", "{ c #794B89", "} c #725E89", "| c #57609F", " . c #5A62A3", ".. c #6565A2", "X. c #7E6DA2", "o. c #864181", "O. c #8C558A", "+. c #955D83", "@. c #976B89", "#. c #857F81", "$. c #8B7B83", "%. c #8A6D98", "&. c #7788A3", "*. c #858484", "=. c #8B8B8B", "-. c #99858C", ";. c #86869E", ":. c #9D8A93", ">. c #929292", ",. c #9B9B9B", "<. c #A49495", "1. c #8C8DA3", "2. c #9292A7", "3. c #9A9BAD", "4. c #9595A9", "5. c #9F9FB1", "6. c #959FBC", "7. c #9FA0B3", "8. c #9EA5B9", "9. c #ABA9A9", "0. c #A7A4A5", "q. c #B0AEAE", "w. c #B6A9A6", "e. c #A0A0B3", "r. c #AFAFBF", "t. c #A5AABE", "y. c #AFB0BF", "u. c #B3B3B3", "i. c #BBBBBB", "p. c #CBAF83", "a. c #DCBA87", "s. c #BAD5A9", "d. c #F5D181", "f. c #FDDE80", "g. c #CEC7BE", "h. c #C8E2BD", "j. c #C3F0BE", "k. c #94A6C6", "l. c #97A8C8", "z. c #98A9C9", "x. c #9BA7C4", "c. c #A6ADC3", "v. c #AEB1C0", "b. c #A5B3C6", "n. c #B2B2C1", "m. c #BABAC7", "M. c #B5BBCA", "N. c #BEBECB", "B. c #AFBED4", "V. c #81B6E0", "C. c #84BCE5", "Z. c #8DC0DE", "A. c #9AC9DD", "S. c #9EDCDA", "D. c #B9C3CF", "F. c #A9CDDB", "G. c #A2CADA", "H. c #B3CDDA", "J. c #B7DCDD", "K. c #A9E6DD", "L. c #8AC3EB", "P. c #93C6E1", "I. c #97CAEC", "U. c #9DD2ED", "Y. c #95CBF5", "T. c #9BCAF3", "R. c #9DD1F7", "E. c #9ED6F8", "W. c #A4CDEA", "Q. c #A8CEEB", "!. c #B5CEEA", "~. c #A5D2E2", "^. c #ACD6E5", "/. c #A2D1EA", "(. c #A6D8EC", "). c #B3DAE4", "_. c #B3DBEC", "`. c #B4D5E7", "'. c #A3D4F4", "]. c #A3D9F5", "[. c #ADDDF3", "{. c #A2DAF9", "}. c #AADDFA", "|. c #B3DFF0", " X c #B5D8F5", ".X c #A9E2EF", "XX c #A9E2E2", "oX c #B7E1EC", "OX c #B5E5E3", "+X c #B8F2E6", "@X c #ADE1FA", "#X c #BDE6F1", "$X c #B4E4FA", "%X c #BCE9FA", "&X c #BAE5F5", "*X c #C3C3C3", "=X c #C7C8CA", "-X c #CBCBCB", ";X c #C7C7D2", ":X c #CBCBD4", ">X c #D6D6D6", ",X c #D3D4DC", " :.IXwXk.!.Y.{.}.cX_.zX~.kX+X+XoXoXVXZX;XIXIXLXy 3 = UXUXUX", "UXUXk q.LXk.x.T.Y.].U.zXkXZXP.~.hXjXA.).).VXM.&.IXDXy 3 = UXUXUX", "UXUXb =XLXx.c.T.E.}.U.&X`.#XoX~.hXOXF.xXG.CXM.< KXDXy 4 = UXUXUX", "UX& z >XLXl.c.Y.].@XV./.Z.#XVX`.hX).uXBXF.CXD.1 KXSXy 2 % UXUXUX", "UX- V AXLXx.6.I.L.C.I.|.P.xXNXxXjXJ.GXJXH.sX8.< KXAX*.B % UXUXUX", "UX, S AXKXdXy.W.U././.P.~.VXNXHX7X6XPXPXFXbX3.=XLX.SXSXDXKXy.Q.$X%XmXVXCXaXGX7X9XPXLXDXe.SXKXLX>X=.l & UXUXUX", "UXn ,.DXDXSXDXAXt.Q.%X%XMXVXaXCX7X9XPXFXM.e.n.KXDX>X=.z ` UXUXUX", "* c u.SXDXSXSXDX,X8.`.#XMXVXaXHXHXGXbXy.e.r.M.DX2X-X=.c / UXUXUX", "( V i.SXSXSXSXSXDX>X5.b.`.xXxXgXiXD.1.y.N.>X:X! I ! =.c ` UXUXUX", ") r *XSXSXSXSXSXSXSXSX:X5.4.;.2.2.m.SXSXSX,Xa.^ T P R Z _ UXUXUX", "o.q *.=.=.=.,.,.,.9.i.-XAXSX*XSXSXSXSXSXSX! ^ qXd.T P N _ UXUXUX", "UX{ { O.O.+.+.D F C r 0 w *.*.*.=.>.0.q.*Xg.Y f.qXd.T P M UXUXUX", "UXUXUXUXUXUXUXUXUXUX] | .. . .X.%.%.@.@.F F A U f.qXd.T L s UXUX", "UXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUX' [ } H f.qXd.T P i UX", "UXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXK f.qXd.T L a ", "UXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXK f.qX^ W -.", "UXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXK f.p.w.;.", "UXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXp <.1.UX", "UXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUX", "UXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUXUX" }; debian/clean0000644000000000000000000000013112226226647010177 0ustar desktopfiles/hi-djview4.svgz desktopfiles/hi32-djview4.png desktopfiles/hi64-djview4.png