Commit bf7e0e98 authored by Albert Astals Cid's avatar Albert Astals Cid

Merge xpdf302branch in HEAD as noone vetoed it.

Testing more than welcome
parent ba74bb3b
2007-04-25 Albert Astals Cid <aacid@kde.org>
* ChangeLog:
* configure.ac:
* fofi/FoFiTrueType.cc:
* fofi/FoFiTrueType.h:
* fofi/FoFiType1.cc:
* fofi/FoFiType1C.cc:
* fofi/FoFiType1C.h:
* glib/poppler-action.cc:
* glib/poppler-document.cc:
* glib/poppler-page.cc:
* goo/FixedPoint.cc:
* goo/FixedPoint.h:
* goo/GooString.cc:
* goo/GooString.h:
* goo/Makefile.am:
* goo/gfile.cc:
* goo/gmem.cc:
* goo/gmem.h:
* poppler/ABWOutputDev.cc:
* poppler/ABWOutputDev.h:
* poppler/Annot.cc:
* poppler/Annot.h:
* poppler/ArthurOutputDev.cc:
* poppler/Catalog.cc:
* poppler/Catalog.h:
* poppler/CharCodeToUnicode.cc:
* poppler/DCTStream.cc:
* poppler/DCTStream.h:
* poppler/Decrypt.cc:
* poppler/Decrypt.h:
* poppler/Dict.cc:
* poppler/Dict.h:
* poppler/FontInfo.cc:
* poppler/Form.cc:
* poppler/Form.h:
* poppler/Function.cc:
* poppler/Function.h:
* poppler/Gfx.cc:
* poppler/Gfx.h:
* poppler/GfxFont.cc:
* poppler/GfxFont.h:
* poppler/GfxState.cc:
* poppler/GfxState.h:
* poppler/GlobalParams.cc:
* poppler/GlobalParams.h:
* poppler/JBIG2Stream.cc:
* poppler/JBIG2Stream.h:
* poppler/JPXStream.cc:
* poppler/JPXStream.h:
* poppler/Lexer.cc:
* poppler/Link.cc:
* poppler/Link.h:
* poppler/Makefile.am:
* poppler/Object.cc:
* poppler/Object.h:
* poppler/Outline.cc:
* poppler/OutputDev.cc:
* poppler/OutputDev.h:
* poppler/PDFDoc.cc:
* poppler/PDFDoc.h:
* poppler/PSOutputDev.cc:
* poppler/PSOutputDev.h:
* poppler/PSTokenizer.cc:
* poppler/Page.cc:
* poppler/Page.h:
* poppler/PageLabelInfo.cc:
* poppler/Parser.cc:
* poppler/Parser.h:
* poppler/PreScanOutputDev.cc:
* poppler/PreScanOutputDev.h:
* poppler/SecurityHandler.cc:
* poppler/SecurityHandler.h:
* poppler/SplashOutputDev.cc:
* poppler/SplashOutputDev.h:
* poppler/Stream.cc:
* poppler/Stream.h:
* poppler/TextOutputDev.cc:
* poppler/TextOutputDev.h:
* poppler/XRef.cc:
* poppler/XRef.h:
* qt/poppler-document.cc:
* qt/poppler-page-transition.cc:
* qt/poppler-page.cc:
* qt/poppler-private.h:
* qt4/src/poppler-annotation-helper.h:
* qt4/src/poppler-document.cc:
* qt4/src/poppler-embeddedfile.cc:
* qt4/src/poppler-form.cc:
* qt4/src/poppler-page.cc:
* qt4/src/poppler-private.h:
* splash/Splash.cc:
* splash/Splash.h:
* splash/SplashBitmap.cc:
* splash/SplashBitmap.h:
* splash/SplashClip.cc:
* splash/SplashClip.h:
* splash/SplashFTFont.cc:
* splash/SplashFTFont.h:
* splash/SplashFTFontEngine.cc:
* splash/SplashFTFontEngine.h:
* splash/SplashFTFontFile.cc:
* splash/SplashFTFontFile.h:
* splash/SplashFont.cc:
* splash/SplashFont.h:
* splash/SplashFontEngine.cc:
* splash/SplashFontEngine.h:
* splash/SplashFontFile.cc:
* splash/SplashFontFile.h:
* splash/SplashMath.h:
* splash/SplashPath.cc:
* splash/SplashPath.h:
* splash/SplashPattern.cc:
* splash/SplashPattern.h:
* splash/SplashScreen.cc:
* splash/SplashScreen.h:
* splash/SplashState.cc:
* splash/SplashState.h:
* splash/SplashT1Font.cc:
* splash/SplashT1Font.h:
* splash/SplashT1FontEngine.cc:
* splash/SplashT1FontFile.cc:
* splash/SplashT1FontFile.h:
* splash/SplashTypes.h:
* splash/SplashXPath.cc:
* splash/SplashXPath.h:
* splash/SplashXPathScanner.cc:
* splash/SplashXPathScanner.h:
* utils/HtmlOutputDev.cc:
* utils/HtmlOutputDev.h:
* utils/pdffonts.cc:
* utils/pdfinfo.cc:
* utils/pdftoabw.cc:
* utils/pdftohtml.cc:
* utils/pdftoppm.cc:
* utils/pdftops.cc:
* utils/pdftotext.cc:
Merge xpdf 3.02 changes
2007-04-15 Pino Toscano <pino@kde.org>
reviewed by: Albert Astals Cid <aacid@kde.org>
......
......@@ -40,6 +40,10 @@ dnl ##### Checks for header files.
AC_PATH_XTRA
AC_HEADER_DIRENT
AC_ARG_ENABLE(exceptions,
[ --enable-exceptions use C++ exceptions],
AC_DEFINE([USE_EXCEPTIONS], [], [Throw exceptions to deal with not enough memory and similar problems]))
dnl ##### Switch over to C++. This will make the checks below a little
dnl ##### bit stricter (requiring function prototypes in include files).
dnl ##### (99% of xpdf is written in C++.)
......
This diff is collapsed.
......@@ -34,9 +34,12 @@ public:
// Create a FoFiTrueType object from a file on disk.
static FoFiTrueType *load(char *fileName, int faceIndexA=0);
FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA=0);
virtual ~FoFiTrueType();
// Returns true if this an OpenType font containing CFF data, false
// if it's a TrueType font (or OpenType font with TrueType data).
GBool isOpenTypeCFF() { return openTypeCFF; }
// Return the number of cmaps defined by this font.
int getNumCmaps();
......@@ -58,6 +61,11 @@ public:
// font does not have a post table.
int mapNameToGID(char *name);
// Return the mapping from CIDs to GIDs, and return the number of
// CIDs in *<nCIDs>. This is only useful for CID fonts. (Only
// useful for OpenType CFF fonts.)
Gushort *getCIDToGIDMap(int *nCIDs);
// Returns the least restrictive embedding licensing right (as
// defined by the TrueType spec):
// * 4: OS/2 table is missing or invalid
......@@ -73,38 +81,63 @@ public:
// <encoding> array specifies the mapping from char codes to names.
// If <encoding> is NULL, the encoding is unknown or undefined. The
// <codeToGID> array specifies the mapping from char codes to GIDs.
// (Not useful for OpenType CFF fonts.)
void convertToType42(char *psName, char **encoding,
Gushort *codeToGID,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 1 font, suitable for embedding in a PostScript
// file. This is only useful with 8-bit fonts. If <newEncoding> is
// not NULL, it will be used in place of the encoding in the Type 1C
// font. If <ascii> is true the eexec section will be hex-encoded,
// otherwise it will be left as binary data. If <psName> is
// non-NULL, it will be used as the PostScript font name. (Only
// useful for OpenType CFF fonts.)
void convertToType1(char *psName, char **newEncoding, GBool ascii,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 2 CIDFont, suitable for embedding in a
// PostScript file. <psName> will be used as the PostScript font
// name (so we don't need to depend on the 'name' table in the
// font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs>
// entries.
// entries. (Not useful for OpenType CFF fonts.)
void convertToCIDType2(char *psName, Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 CIDFont, suitable for embedding in a
// PostScript file. <psName> will be used as the PostScript font
// name. (Only useful for OpenType CFF fonts.)
void convertToCIDType0(char *psName,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. <psName> will be used as the
// PostScript font name (so we don't need to depend on the 'name'
// table in the font). The <cidMap> array maps CIDs to GIDs; it has
// <nCIDs> entries.
// <nCIDs> entries. (Not useful for OpenType CFF fonts.)
void convertToType0(char *psName, Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. <psName> will be used as the
// PostScript font name. (Only useful for OpenType CFF fonts.)
void convertToType0(char *psName,
FoFiOutputFunc outputFunc, void *outputStream);
// Write a clean TTF file, filling in missing tables and correcting
// various other errors. If <name> is non-NULL, the font is renamed
// to <name>. If <codeToGID> is non-NULL, the font is re-encoded,
// using a Windows Unicode cmap. If <name> is NULL and the font is
// complete and correct, it will be written unmodified.
// complete and correct, it will be written unmodified. (Not useful
// for OpenType CFF fonts.)
void writeTTF(FoFiOutputFunc outputFunc, void *outputStream,
char *name = NULL, Gushort *codeToGID = NULL);
private:
FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA);
void cvtEncoding(char **encoding,
FoFiOutputFunc outputFunc,
void *outputStream);
......@@ -131,6 +164,7 @@ private:
int locaFmt;
int bbox[4];
GooHash *nameToGID;
GBool openTypeCFF;
GBool parsedOk;
int faceIndex;
......
......@@ -75,7 +75,7 @@ char **FoFiType1::getEncoding() {
void FoFiType1::writeEncoded(char **newEncoding,
FoFiOutputFunc outputFunc, void *outputStream) {
char buf[512];
char *line;
char *line, *line2, *p;
int i;
// copy everything up to the encoding
......@@ -101,19 +101,57 @@ void FoFiType1::writeEncoded(char **newEncoding,
}
(*outputFunc)(outputStream, "readonly def\n", 13);
// copy everything after the encoding
// find the end of the encoding data
//~ this ought to parse PostScript tokens
if (!strncmp(line, "/Encoding StandardEncoding def", 30)) {
line = getNextLine(line);
} else {
for (line = getNextLine(line);
line && strncmp(line, "readonly def", 12);
line = getNextLine(line)) ;
if (line) {
line = getNextLine(line);
// skip "/Encoding" + one whitespace char,
// then look for 'def' preceded by PostScript whitespace
p = line + 10;
line = NULL;
for (; p < (char *)file + len; ++p) {
if ((*p == ' ' || *p == '\t' || *p == '\x0a' ||
*p == '\x0d' || *p == '\x0c' || *p == '\0') &&
p + 4 <= (char *)file + len &&
!strncmp(p + 1, "def", 3)) {
line = p + 4;
break;
}
}
}
// some fonts have two /Encoding entries in their dictionary, so we
// check for a second one here
if (line) {
(*outputFunc)(outputStream, line, ((char *)file + len) - line);
for (line2 = line, i = 0;
i < 20 && line2 && strncmp(line2, "/Encoding", 9);
line2 = getNextLine(line2), ++i) ;
if (i < 20 && line2) {
(*outputFunc)(outputStream, line, line2 - line);
if (!strncmp(line2, "/Encoding StandardEncoding def", 30)) {
line = getNextLine(line2);
} else {
// skip "/Encoding" + one whitespace char,
// then look for 'def' preceded by PostScript whitespace
p = line2 + 10;
line = NULL;
for (; p < (char *)file + len; ++p) {
if ((*p == ' ' || *p == '\t' || *p == '\x0a' ||
*p == '\x0d' || *p == '\x0c' || *p == '\0') &&
p + 4 <= (char *)file + len &&
!strncmp(p + 1, "def", 3)) {
line = p + 4;
break;
}
}
}
}
// copy everything after the encoding
if (line) {
(*outputFunc)(outputStream, line, ((char *)file + len) - line);
}
}
}
......@@ -178,8 +216,15 @@ void FoFiType1::parse() {
if (*p2) {
c = *p2;
*p2 = '\0';
if ((code = atoi(p)) < 256) {
*p2 = c;
code = atoi(p);
*p2 = c;
if (code == 8 && *p2 == '#') {
code = 0;
for (++p2; *p2 >= '0' && *p2 <= '7'; ++p2) {
code = code * 8 + (*p2 - '0');
}
}
if (code < 256) {
for (p = p2; *p == ' ' || *p == '\t'; ++p) ;
if (*p == '/') {
++p;
......
This diff is collapsed.
......@@ -138,7 +138,6 @@ public:
// Create a FoFiType1C object from a file on disk.
static FoFiType1C *load(char *fileName);
FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
virtual ~FoFiType1C();
// Return the font name.
......@@ -156,8 +155,9 @@ public:
// file. This is only useful with 8-bit fonts. If <newEncoding> is
// not NULL, it will be used in place of the encoding in the Type 1C
// font. If <ascii> is true the eexec section will be hex-encoded,
// otherwise it will be left as binary data.
void convertToType1(char **newEncoding, GBool ascii,
// otherwise it will be left as binary data. If <psName> is non-NULL,
// it will be used as the PostScript font name.
void convertToType1(char *psName, char **newEncoding, GBool ascii,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 CIDFont, suitable for embedding in a
......@@ -174,6 +174,7 @@ public:
private:
FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
void eexecCvtGlyph(Type1CEexecBuf *eb, char *glyphName,
int offset, int nBytes,
Type1CIndex *subrIdx,
......
......@@ -16,8 +16,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <UGooString.h>
#include "poppler.h"
#include "poppler-private.h"
......@@ -267,7 +265,7 @@ dest_new_goto (PopplerDocument *document,
}
static PopplerDest *
dest_new_named (UGooString *named_dest)
dest_new_named (GooString *named_dest)
{
PopplerDest *dest;
gchar *name;
......@@ -280,9 +278,7 @@ dest_new_named (UGooString *named_dest)
}
dest->type = POPPLER_DEST_NAMED;
name = named_dest->getCString ();
dest->named_dest = g_strdup (name);
delete[] name;
dest->named_dest = g_strdup (named_dest->getCString ());
return dest;
}
......@@ -293,7 +289,7 @@ build_goto_dest (PopplerDocument *document,
LinkGoTo *link)
{
LinkDest *link_dest;
UGooString *named_dest;
GooString *named_dest;
/* Return if it isn't OK */
if (! link->isOk ()) {
......@@ -318,7 +314,7 @@ build_goto_remote (PopplerAction *action,
LinkGoToR *link)
{
LinkDest *link_dest;
UGooString *named_dest;
GooString *named_dest;
/* Return if it isn't OK */
if (! link->isOk ()) {
......
......@@ -28,7 +28,6 @@
#include <Stream.h>
#include <FontInfo.h>
#include <PDFDocEncoding.h>
#include <UGooString.h>
#include "poppler.h"
#include "poppler-private.h"
......@@ -388,12 +387,12 @@ poppler_document_find_dest (PopplerDocument *document,
{
PopplerDest *dest = NULL;
LinkDest *link_dest = NULL;
UGooString *g_link_name;
GooString *g_link_name;
g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL);
g_return_val_if_fail (link_name != NULL, NULL);
g_link_name = new UGooString (link_name);
g_link_name = new GooString (link_name);
if (g_link_name) {
link_dest = document->doc->findDest (g_link_name);
......
......@@ -332,7 +332,7 @@ poppler_page_render (PopplerPage *page,
0, 0,
(int) ceil (page->page->getCropWidth ()),
(int) ceil (page->page->getCropHeight ()),
NULL, /* links */
gFalse, /* printing */
page->document->doc->getCatalog ());
output_dev->setCairo (NULL);
......@@ -378,7 +378,7 @@ poppler_page_render_to_pixbuf (PopplerPage *page,
gTrue, /* Crop */
src_x, src_y,
src_width, src_height,
NULL, /* links */
gFalse, /* printing */
page->document->doc->getCatalog ());
poppler_page_copy_to_pixbuf (page, pixbuf, &data);
......@@ -395,7 +395,7 @@ poppler_page_get_text_output_dev (PopplerPage *page)
gFalse, /* useMediaBox */
gTrue, /* Crop */
-1, -1, -1, -1,
NULL, /* links */
gFalse, /* printing */
page->document->doc->getCatalog (),
NULL, NULL, NULL, NULL);
......@@ -744,7 +744,7 @@ poppler_page_find_text (PopplerPage *page,
poppler_page_get_size (page, NULL, &height);
page->page->display (output_dev, 72, 72, 0, gFalse,
gTrue, NULL, doc->getCatalog());
gTrue, gFalse, doc->getCatalog());
matches = NULL;
xMin = 0;
......
......@@ -18,13 +18,17 @@
#include "FixedPoint.h"
#define ln2 ((FixedPoint)0.69314718)
#define ln2 ((FixedPoint)0.69314718)
FixedPoint FixedPoint::sqrt(FixedPoint x) {
FixedPoint y0, y1, z;
if (x.val <= 0) {
y1.val = 0;
} else {
y1.val = x.val >> 1;
y1.val = x.val == 1 ? 2 : x.val >> 1;
do {
y0.val = y1.val;
z = x / y0;
......@@ -34,10 +38,9 @@ FixedPoint FixedPoint::sqrt(FixedPoint x) {
return y1;
}
//~ this is not very accurate
FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
FixedPoint t, t2, lnx0, lnx, z0, z;
int d, i;
int d, n, i;
if (y.val <= 0) {
z.val = 0;
......@@ -56,6 +59,8 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
lnx.val <<= 1;
t = y * lnx;
// exp(y * ln(x))
n = floor(t / ln2);
t -= ln2 * n;
t2 = t;
d = 1;
i = 1;
......@@ -67,6 +72,11 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
++i;
d *= i;
} while (::abs(z.val - z0.val) > 2 && d < (1 << fixptShift));
if (n >= 0) {
z.val <<= n;
} else if (n < 0) {
z.val >>= -n;
}
}
return z;
}
......@@ -92,4 +102,19 @@ int FixedPoint::div(int x, int y) {
#endif
}
GBool FixedPoint::divCheck(FixedPoint x, FixedPoint y, FixedPoint *result) {
#if 1 //~tmp
FixPtInt64 z;
z = ((FixPtInt64)x.val << fixptShift) / y.val;
if ((z == 0 && x != 0) ||
z >= ((FixPtInt64)1 << 31) || z < -((FixPtInt64)1 << 31)) {
return gFalse;
}
result->val = z;
return gTrue;
#else
#endif
}
#endif // USE_FIXEDPOINT
......@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "gtypes.h"
#define fixptShift 16
#define fixptMaskL ((1 << fixptShift) - 1)
......@@ -135,6 +136,10 @@ public:
static FixedPoint pow(FixedPoint x, FixedPoint y);
// Compute *result = x/y; return false if there is an underflow or
// overflow.
static GBool divCheck(FixedPoint x, FixedPoint y, FixedPoint *result);
private:
static FixedPoint make(int valA) { FixedPoint x; x.val = valA; return x; }
......
This diff is collapsed.
......@@ -8,13 +8,14 @@
//
//========================================================================
#ifndef GSTRING_H
#define GSTRING_H
#ifndef GooString_H
#define GooString_H
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <stdarg.h>
#include <stdlib.h> // for NULL
#include "gtypes.h"
......@@ -50,6 +51,30 @@ public:
// Convert an integer to a string.
static GooString *fromInt(int x);
// Create a formatted string. Similar to printf, but without the
// string overflow issues. Formatting elements consist of:
// {<arg>:[<width>][.<precision>]<type>}
// where:
// - <arg> is the argument number (arg 0 is the first argument
// following the format string) -- NB: args must be first used in
// order; they can be reused in any order
// - <width> is the field width -- negative to reverse the alignment;
// starting with a leading zero to zero-fill (for integers)
// - <precision> is the number of digits to the right of the decimal
// point (for floating point numbers)
// - <type> is one of:
// d, x, o, b -- int in decimal, hex, octal, binary
// ud, ux, uo, ub -- unsigned int
// ld, lx, lo, lb, uld, ulx, ulo, ulb -- long, unsigned long
// f, g -- double
// c -- char
// s -- string (char *)
// t -- GooString *
// w -- blank space; arg determines width
// To get literal curly braces, use {{ or }}.
static GooString *format(char *fmt, ...);
static GooString *formatv(char *fmt, va_list argList);
// Destructor.
~GooString();
......@@ -73,6 +98,10 @@ public:
GooString *append(GooString *str);
GooString *append(const char *str, int lengthA=CALC_STRING_LEN);
// Append a formatted string.
GooString *appendf(char *fmt, ...);
GooString *appendfv(char *fmt, va_list argList);
// Insert a character or string.
GooString *insert(int i, char c);
GooString *insert(int i, GooString *str);
......@@ -110,6 +139,14 @@ private:
char *s;
void resize(int newLength);
static void formatInt(long x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
char **p, int *len);
static void formatUInt(Gulong x, char *buf, int bufSize,
GBool zeroFill, int width, int base,
char **p, int *len);
static void formatDouble(double x, char *buf, int bufSize, int prec,
GBool trim, char **p, int *len);
};
#endif
......@@ -25,5 +25,5 @@ libgoo_la_SOURCES = \
GooList.cc \
GooTimer.cc \
GooString.cc \
gmem.c \
gmem.cc \
FixedPoint.cc
......@@ -10,7 +10,9 @@
#include <config.h>
#ifndef WIN32
#ifdef WIN32
# include <time.h>
#else
# if defined(MACOS)
# include <sys/stat.h>
# elif !defined(ACORN)
......@@ -440,21 +442,45 @@ time_t getModTime(char *fileName) {
GBool openTempFile(GooString **name, FILE **f, char *mode, char *ext) {
#if defined(WIN32)
//---------- Win32 ----------
char *s;
if (!(s = _tempnam(getenv("TEMP"), NULL))) {
return gFalse;
}
*name = new GooString(s);
free(s);
if (ext) {
(*name)->append(ext);
char *tempDir;
GString *s, *s2;
char buf[32];
FILE *f2;
int t, i;
// this has the standard race condition problem, but I haven't found
// a better way to generate temp file names with extensions on
// Windows
if ((tempDir = getenv("TEMP"))) {
s = new GString(tempDir);
s->append('\\');
} else {
s = new GString();
}
if (!(*f = fopen((*name)->getCString(), mode))) {
delete (*name);
return gFalse;
s->append("x");
t = (int)time(NULL);
for (i = 0; i < 1000; ++i) {
sprintf(buf, "%d", t + i);
s2 = s->copy()->append(buf);
if (ext) {
s2->append(ext);
}
if (!(f2 = fopen(s2->getCString(), "r"))) {
if (!(f2 = fopen(s2->getCString(), mode))) {