Commit 3c87903c authored by Claudio Valerio's avatar Claudio Valerio

Updated xpdf library

parent 9b608897
/* aconf.h. Generated by configure. */
/*
* aconf.h
*
* Copyright 2002-2003 Glyph & Cog, LLC
*/
#ifndef ACONF_H
#define ACONF_H
#include <aconf2.h>
/*
* Enable multithreading support.
*/
#define MULTITHREADED 1
/*
* Enable C++ exceptions.
*/
#define USE_EXCEPTIONS 1
#undef SYSTEM_XPDFRC
/*
* Use FreeType 2.
*/
#define HAVE_FREETYPE_FREETYPE_H 1
/*
* Defined if the Splash library is avaiable.
*/
#define HAVE_SPLASH 1
#define HAVE_DIRENT_H 1
#define HAVE_STRINGS_H 1
#define HAVE_POPEN 1
#define HAVE_MKSTEMP 1
#ifdef __APPLE__ // Not available on Fedora 9
#define HAVE_MKSTEMPS 1
#endif
#define HAVE_FSEEKO 1
#define HAVE_XTAPPSETEXITFLAG 1
#endif
/*
* aconf2.h
*
* This gets included by aconf.h, and contains miscellaneous global
* settings not directly controlled by autoconf. This is a separate
* file because otherwise the configure script will munge any
* #define/#undef constructs.
*
* Copyright 2002-2003 Glyph & Cog, LLC
*/
#ifndef ACONF2_H
#define ACONF2_H
/*
* This controls the use of the interface/implementation pragmas.
*/
#ifdef __GNUC__
#define USE_GCC_PRAGMAS
#endif
/* There is a bug in the version of gcc which ships with MacOS X 10.2 */
#if defined(__APPLE__) && defined(__MACH__)
# include <AvailabilityMacros.h>
#endif
#ifdef MAC_OS_X_VERSION_MAX_ALLOWED
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2
# undef USE_GCC_PRAGMAS
# endif
#endif
/*
* Make sure WIN32 is defined if appropriate.
*/
#if defined(_WIN32) && !defined(WIN32)
# define WIN32
#endif
#endif
//========================================================================
//
// Array.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef ARRAY_H
#define ARRAY_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "Object.h"
class XRef;
//------------------------------------------------------------------------
// Array
//------------------------------------------------------------------------
class Array {
public:
// Constructor.
Array(XRef *xrefA);
// Destructor.
~Array();
// Reference counting.
int incRef() { return ++ref; }
int decRef() { return --ref; }
// Get number of elements.
int getLength() { return length; }
// Add an element.
void add(Object *elem);
// Accessors.
Object *get(int i, Object *obj);
Object *getNF(int i, Object *obj);
private:
XRef *xref; // the xref table for this PDF file
Object *elems; // array of elements
int size; // size of <elems> array
int length; // number of elements in array
int ref; // reference count
};
#endif
//========================================================================
//
// Catalog.h
//
// Copyright 1996-2007 Glyph & Cog, LLC
//
//========================================================================
#ifndef CATALOG_H
#define CATALOG_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "CharTypes.h"
class GList;
class PDFDoc;
class XRef;
class Object;
class Page;
class PageAttrs;
struct Ref;
class LinkDest;
class PageTreeNode;
//------------------------------------------------------------------------
// Catalog
//------------------------------------------------------------------------
class Catalog {
public:
// Constructor.
Catalog(PDFDoc *docA);
// Destructor.
~Catalog();
// Is catalog valid?
GBool isOk() { return ok; }
// Get number of pages.
int getNumPages() { return numPages; }
// Get a page.
Page *getPage(int i);
// Get the reference for a page object.
Ref *getPageRef(int i);
// Return base URI, or NULL if none.
GString *getBaseURI() { return baseURI; }
// Return the contents of the metadata stream, or NULL if there is
// no metadata.
GString *readMetadata();
// Return the structure tree root object.
Object *getStructTreeRoot() { return &structTreeRoot; }
// Find a page, given its object ID. Returns page number, or 0 if
// not found.
int findPage(int num, int gen);
// Find a named destination. Returns the link destination, or
// NULL if <name> is not a destination.
LinkDest *findDest(GString *name);
Object *getDests() { return &dests; }
Object *getNameTree() { return &nameTree; }
Object *getOutline() { return &outline; }
Object *getAcroForm() { return &acroForm; }
Object *getOCProperties() { return &ocProperties; }
// Get the list of embedded files.
int getNumEmbeddedFiles();
Unicode *getEmbeddedFileName(int idx);
int getEmbeddedFileNameLength(int idx);
Object *getEmbeddedFileStreamObj(int idx, Object *strObj);
private:
PDFDoc *doc;
XRef *xref; // the xref table for this PDF file
PageTreeNode *pageTree; // the page tree
Page **pages; // array of pages
Ref *pageRefs; // object ID for each page
int numPages; // number of pages
int pagesSize; // size of pages array
Object dests; // named destination dictionary
Object nameTree; // name tree
GString *baseURI; // base URI for URI-type links
Object metadata; // metadata stream
Object structTreeRoot; // structure tree root dictionary
Object outline; // outline dictionary
Object acroForm; // AcroForm dictionary
Object ocProperties; // OCProperties dictionary
GList *embeddedFiles; // embedded file list [EmbeddedFile]
GBool ok; // true if catalog is valid
Object *findDestInTree(Object *tree, GString *name, Object *obj);
GBool readPageTree(Object *catDict);
int countPageTree(Object *pagesObj);
void loadPage(int pg);
void loadPage2(int pg, int relPg, PageTreeNode *node);
void readEmbeddedFileList(Dict *catDict);
void readEmbeddedFileTree(Object *node);
};
#endif
//========================================================================
//
// CharTypes.h
//
// Copyright 2001-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef CHARTYPES_H
#define CHARTYPES_H
// Unicode character.
typedef unsigned int Unicode;
// Character ID for CID character collections.
typedef unsigned int CID;
// This is large enough to hold any of the following:
// - 8-bit char code
// - 16-bit CID
// - Unicode
typedef unsigned int CharCode;
#endif
//========================================================================
//
// Dict.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef DICT_H
#define DICT_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "Object.h"
//------------------------------------------------------------------------
// Dict
//------------------------------------------------------------------------
struct DictEntry {
char *key;
Object val;
};
class Dict {
public:
// Constructor.
Dict(XRef *xrefA);
// Destructor.
~Dict();
// Reference counting.
int incRef() { return ++ref; }
int decRef() { return --ref; }
// Get number of entries.
int getLength() { return length; }
// Add an entry. NB: does not copy key.
void add(char *key, Object *val);
// Check if dictionary is of specified type.
GBool is(char *type);
// Look up an entry and return the value. Returns a null object
// if <key> is not in the dictionary.
Object *lookup(char *key, Object *obj, int recursion = 0);
Object *lookupNF(char *key, Object *obj);
// Iterative accessors.
char *getKey(int i);
Object *getVal(int i, Object *obj);
Object *getValNF(int i, Object *obj);
// Set the xref pointer. This is only used in one special case: the
// trailer dictionary, which is read before the xref table is
// parsed.
void setXRef(XRef *xrefA) { xref = xrefA; }
private:
XRef *xref; // the xref table for this PDF file
DictEntry *entries; // array of entries
int size; // size of <entries> array
int length; // number of entries in dictionary
int ref; // reference count
DictEntry *find(char *key);
};
#endif
//========================================================================
//
// Function.h
//
// Copyright 2001-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef FUNCTION_H
#define FUNCTION_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "gtypes.h"
#include "Object.h"
class Dict;
class Stream;
struct PSObject;
class PSStack;
//------------------------------------------------------------------------
// Function
//------------------------------------------------------------------------
#define funcMaxInputs 32
#define funcMaxOutputs 32
#define sampledFuncMaxInputs 16
class Function {
public:
Function();
virtual ~Function();
// Construct a function. Returns NULL if unsuccessful.
static Function *parse(Object *funcObj, int recursion = 0);
// Initialize the entries common to all function types.
GBool init(Dict *dict);
virtual Function *copy() = 0;
// Return the function type:
// -1 : identity
// 0 : sampled
// 2 : exponential
// 3 : stitching
// 4 : PostScript
virtual int getType() = 0;
// Return size of input and output tuples.
int getInputSize() { return m; }
int getOutputSize() { return n; }
double getDomainMin(int i) { return domain[i][0]; }
double getDomainMax(int i) { return domain[i][1]; }
double getRangeMin(int i) { return range[i][0]; }
double getRangeMax(int i) { return range[i][1]; }
GBool getHasRange() { return hasRange; }
// Transform an input tuple into an output tuple.
virtual void transform(double *in, double *out) = 0;
virtual GBool isOk() = 0;
protected:
int m, n; // size of input and output tuples
double // min and max values for function domain
domain[funcMaxInputs][2];
double // min and max values for function range
range[funcMaxOutputs][2];
GBool hasRange; // set if range is defined
};
//------------------------------------------------------------------------
// IdentityFunction
//------------------------------------------------------------------------
class IdentityFunction: public Function {
public:
IdentityFunction();
virtual ~IdentityFunction();
virtual Function *copy() { return new IdentityFunction(); }
virtual int getType() { return -1; }
virtual void transform(double *in, double *out);
virtual GBool isOk() { return gTrue; }
private:
};
//------------------------------------------------------------------------
// SampledFunction
//------------------------------------------------------------------------
class SampledFunction: public Function {
public:
SampledFunction(Object *funcObj, Dict *dict);
virtual ~SampledFunction();
virtual Function *copy() { return new SampledFunction(this); }
virtual int getType() { return 0; }
virtual void transform(double *in, double *out);
virtual GBool isOk() { return ok; }
int getSampleSize(int i) { return sampleSize[i]; }
double getEncodeMin(int i) { return encode[i][0]; }
double getEncodeMax(int i) { return encode[i][1]; }
double getDecodeMin(int i) { return decode[i][0]; }
double getDecodeMax(int i) { return decode[i][1]; }
double *getSamples() { return samples; }
private:
SampledFunction(SampledFunction *func);
int // number of samples for each domain element
sampleSize[funcMaxInputs];
double // min and max values for domain encoder
encode[funcMaxInputs][2];
double // min and max values for range decoder
decode[funcMaxOutputs][2];
double // input multipliers
inputMul[funcMaxInputs];
int *idxOffset;
double *samples; // the samples
int nSamples; // size of the samples array
double *sBuf; // buffer for the transform function
double cacheIn[funcMaxInputs];
double cacheOut[funcMaxOutputs];
GBool ok;
};
//------------------------------------------------------------------------
// ExponentialFunction
//------------------------------------------------------------------------
class ExponentialFunction: public Function {
public:
ExponentialFunction(Object *funcObj, Dict *dict);
virtual ~ExponentialFunction();
virtual Function *copy() { return new ExponentialFunction(this); }
virtual int getType() { return 2; }
virtual void transform(double *in, double *out);
virtual GBool isOk() { return ok; }
double *getC0() { return c0; }
double *getC1() { return c1; }
double getE() { return e; }
private:
ExponentialFunction(ExponentialFunction *func);
double c0[funcMaxOutputs];
double c1[funcMaxOutputs];
double e;
GBool ok;
};
//------------------------------------------------------------------------
// StitchingFunction
//------------------------------------------------------------------------
class StitchingFunction: public Function {
public:
StitchingFunction(Object *funcObj, Dict *dict, int recursion);
virtual ~StitchingFunction();
virtual Function *copy() { return new StitchingFunction(this); }
virtual int getType() { return 3; }
virtual void transform(double *in, double *out);
virtual GBool isOk() { return ok; }
int getNumFuncs() { return k; }
Function *getFunc(int i) { return funcs[i]; }
double *getBounds() { return bounds; }
double *getEncode() { return encode; }
double *getScale() { return scale; }
private:
StitchingFunction(StitchingFunction *func);
int k;
Function **funcs;
double *bounds;
double *encode;
double *scale;
GBool ok;
};
//------------------------------------------------------------------------
// PostScriptFunction
//------------------------------------------------------------------------
class PostScriptFunction: public Function {
public:
PostScriptFunction(Object *funcObj, Dict *dict);
virtual ~PostScriptFunction();
virtual Function *copy() { return new PostScriptFunction(this); }
virtual int getType() { return 4; }
virtual void transform(double *in, double *out);
virtual GBool isOk() { return ok; }
GString *getCodeString() { return codeString; }
private:
PostScriptFunction(PostScriptFunction *func);
GBool parseCode(Stream *str, int *codePtr);
GString *getToken(Stream *str);
void resizeCode(int newSize);
void exec(PSStack *stack, int codePtr);
GString *codeString;
PSObject *code;
int codeSize;
GBool ok;
};
#endif
//========================================================================
//
// GMutex.h
//
// Portable mutex macros.
//
// Copyright 2002-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef GMUTEX_H
#define GMUTEX_H
// Usage:
//
// GMutex m;
// gInitMutex(&m);
// ...
// gLockMutex(&m);
// ... critical section ...
// gUnlockMutex(&m);
// ...
// gDestroyMutex(&m);
#ifdef WIN32
#include <windows.h>
typedef CRITICAL_SECTION GMutex;
#define gInitMutex(m) InitializeCriticalSection(m)
#define gDestroyMutex(m) DeleteCriticalSection(m)
#define gLockMutex(m) EnterCriticalSection(m)
#define gUnlockMutex(m) LeaveCriticalSection(m)
#else // assume pthreads
#include <pthread.h>
typedef pthread_mutex_t GMutex;
#define gInitMutex(m) pthread_mutex_init(m, NULL)
#define gDestroyMutex(m) pthread_mutex_destroy(m)
#define gLockMutex(m) pthread_mutex_lock(m)
#define gUnlockMutex(m) pthread_mutex_unlock(m)
#endif
#endif
//========================================================================
//
// GString.h
//
// Simple variable-length string type.
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef GSTRING_H
#define GSTRING_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <stdarg.h>
#include "gtypes.h"
class GString {
public:
// Create an empty string.
GString();
// Create a string from a C string.
GString(const char *sA);
// Create a string from <lengthA> chars at <sA>. This string
// can contain null characters.
GString(const char *sA, int lengthA);
// Create a string from <lengthA> chars at <idx> in <str>.
GString(GString *str, int idx, int lengthA);
// Copy a string.
GString(GString *str);
GString *copy() { return new GString(this); }
// Concatenate two strings.
GString(GString *str1, GString *str2);
// Convert an integer to a string.
static GString *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 -- GString *
// w -- blank space; arg determines width
// To get literal curly braces, use {{ or }}.
static GString *format(const char *fmt, ...);
static GString *formatv(const char *fmt, va_list argList);
// Destructor.
~GString();
// Get length.
int getLength() { return length; }
// Get C string.
char *getCString() { return s; }
// Get <i>th character.
char getChar(int i) { return s[i]; }
// Change <i>th character.
void setChar(int i, char c) { s[i] = c; }
// Clear string to zero length.
GString *clear();
// Append a character or string.
GString *append(char c);
GString *append(GString *str);
GString *append(const char *str);
GString *append(const char *str, int lengthA);
// Append a formatted string.
GString *appendf(const char *fmt, ...);
GString *appendfv(const char *fmt, va_list argList);
// Insert a character or string.
GString *insert(int i, char c);
GString *insert(int i, GString *str);
GString *insert(int i, const char *str);
GString *insert(int i, const char *str, int lengthA);
// Delete a character or range of characters.
GString *del(int i, int n = 1);
// Convert string to all-upper/all-lower case.
GString *upperCase();
GString *lowerCase();
// Compare two strings: -1:< 0:= +1:>
int cmp(GString *str);
int cmpN(GString *str, int n);
int cmp(const char *sA);
int cmpN(const char *sA, int n);
private:
int length;
char *s;
void resize(int length1);
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
This diff is collapsed.
This diff is collapsed.
//========================================================================
//
// Object.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef OBJECT_H
#define OBJECT_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <stdio.h>
#include <string.h>
#include "gtypes.h"
#include "gmem.h"
#include "GString.h"
class XRef;
class Array;
class Dict;
class Stream;
//------------------------------------------------------------------------
// Ref
//------------------------------------------------------------------------
struct Ref {
int num; // object number
int gen; // generation number
};
//------------------------------------------------------------------------
// object types
//------------------------------------------------------------------------
enum ObjType {
// simple objects
objBool, // boolean
objInt, // integer
objReal, // real
objString, // string
objName, // name
objNull, // null
// complex objects
objArray, // array
objDict, // dictionary
objStream, // stream
objRef, // indirect reference
// special objects
objCmd, // command name
objError, // error return from Lexer
objEOF, // end of file return from Lexer
objNone // uninitialized object
};
#define numObjTypes 14 // total number of object types
//------------------------------------------------------------------------
// Object
//------------------------------------------------------------------------
#ifdef DEBUG_MEM
#define initObj(t) ++numAlloc[type = t]
#else
#define initObj(t) type = t
#endif
class Object {
public:
// Default constructor.
Object():
type(objNone) {}
// Initialize an object.
Object *initBool(GBool boolnA)
{ initObj(objBool); booln = boolnA; return this; }
Object *initInt(int intgA)
{ initObj(objInt); intg = intgA; return this; }
Object *initReal(double realA)
{ initObj(objReal); real = realA; return this; }
Object *initString(GString *stringA)
{ initObj(objString); string = stringA; return this; }
Object *initName(char *nameA)
{ initObj(objName); name = copyString(nameA); return this; }
Object *initNull()
{ initObj(objNull); return this; }
Object *initArray(XRef *xref);
Object *initDict(XRef *xref);
Object *initDict(Dict *dictA);
Object *initStream(Stream *streamA);
Object *initRef(int numA, int genA)
{ initObj(objRef); ref.num = numA; ref.gen = genA; return this; }
Object *initCmd(char *cmdA)
{ initObj(objCmd); cmd = copyString(cmdA); return this; }
Object *initError()
{ initObj(objError); return this; }
Object *initEOF()
{ initObj(objEOF); return this; }
// Copy an object.
Object *copy(Object *obj);
// If object is a Ref, fetch and return the referenced object.
// Otherwise, return a copy of the object.
Object *fetch(XRef *xref, Object *obj, int recursion = 0);
// Free object contents.
void free();
// Type checking.
ObjType getType() { return type; }
GBool isBool() { return type == objBool; }
GBool isInt() { return type == objInt; }
GBool isReal() { return type == objReal; }
GBool isNum() { return type == objInt || type == objReal; }
GBool isString() { return type == objString; }
GBool isName() { return type == objName; }
GBool isNull() { return type == objNull; }
GBool isArray() { return type == objArray; }
GBool isDict() { return type == objDict; }
GBool isStream() { return type == objStream; }
GBool isRef() { return type == objRef; }
GBool isCmd() { return type == objCmd; }
GBool isError() { return type == objError; }
GBool isEOF() { return type == objEOF; }
GBool isNone() { return type == objNone; }
// Special type checking.
GBool isName(char *nameA)
{ return type == objName && !strcmp(name, nameA); }
GBool isDict(char *dictType);
GBool isStream(char *dictType);
GBool isCmd(char *cmdA)
{ return type == objCmd && !strcmp(cmd, cmdA); }
// Accessors. NB: these assume object is of correct type.
GBool getBool() { return booln; }
int getInt() { return intg; }
double getReal() { return real; }
double getNum() { return type == objInt ? (double)intg : real; }
GString *getString() { return string; }
char *getName() { return name; }
Array *getArray() { return array; }
Dict *getDict() { return dict; }
Stream *getStream() { return stream; }
Ref getRef() { return ref; }
int getRefNum() { return ref.num; }
int getRefGen() { return ref.gen; }
char *getCmd() { return cmd; }
// Array accessors.
int arrayGetLength();
void arrayAdd(Object *elem);
Object *arrayGet(int i, Object *obj);
Object *arrayGetNF(int i, Object *obj);
// Dict accessors.
int dictGetLength();
void dictAdd(char *key, Object *val);
GBool dictIs(char *dictType);
Object *dictLookup(char *key, Object *obj, int recursion = 0);
Object *dictLookupNF(char *key, Object *obj);
char *dictGetKey(int i);
Object *dictGetVal(int i, Object *obj);
Object *dictGetValNF(int i, Object *obj);
// Stream accessors.
GBool streamIs(char *dictType);
void streamReset();
void streamClose();
int streamGetChar();
int streamLookChar();
char *streamGetLine(char *buf, int size);
Guint streamGetPos();
void streamSetPos(Guint pos, int dir = 0);
Dict *streamGetDict();
// Output.
char *getTypeName();
void print(FILE *f = stdout);
// Memory testing.
static void memCheck(FILE *f);
private:
ObjType type; // object type
union { // value for each type:
GBool booln; // boolean
int intg; // integer
double real; // real
GString *string; // string
char *name; // name
Array *array; // array
Dict *dict; // dictionary
Stream *stream; // stream
Ref ref; // indirect reference
char *cmd; // command
};
#ifdef DEBUG_MEM
static int // number of each type of object
numAlloc[numObjTypes]; // currently allocated
#endif
};
//------------------------------------------------------------------------
// Array accessors.
//------------------------------------------------------------------------
#include "Array.h"
inline int Object::arrayGetLength()
{ return array->getLength(); }
inline void Object::arrayAdd(Object *elem)
{ array->add(elem); }
inline Object *Object::arrayGet(int i, Object *obj)
{ return array->get(i, obj); }
inline Object *Object::arrayGetNF(int i, Object *obj)
{ return array->getNF(i, obj); }
//------------------------------------------------------------------------
// Dict accessors.
//------------------------------------------------------------------------
#include "Dict.h"
inline int Object::dictGetLength()
{ return dict->getLength(); }
inline void Object::dictAdd(char *key, Object *val)
{ dict->add(key, val); }
inline GBool Object::dictIs(char *dictType)
{ return dict->is(dictType); }
inline GBool Object::isDict(char *dictType)
{ return type == objDict && dictIs(dictType); }
inline Object *Object::dictLookup(char *key, Object *obj, int recursion)
{ return dict->lookup(key, obj, recursion); }
inline Object *Object::dictLookupNF(char *key, Object *obj)
{ return dict->lookupNF(key, obj); }
inline char *Object::dictGetKey(int i)
{ return dict->getKey(i); }
inline Object *Object::dictGetVal(int i, Object *obj)
{ return dict->getVal(i, obj); }
inline Object *Object::dictGetValNF(int i, Object *obj)
{ return dict->getValNF(i, obj); }
//------------------------------------------------------------------------
// Stream accessors.
//------------------------------------------------------------------------
#include "Stream.h"
inline GBool Object::streamIs(char *dictType)
{ return stream->getDict()->is(dictType); }
inline GBool Object::isStream(char *dictType)
{ return type == objStream && streamIs(dictType); }
inline void Object::streamReset()
{ stream->reset(); }
inline void Object::streamClose()
{ stream->close(); }
inline int Object::streamGetChar()
{ return stream->getChar(); }
inline int Object::streamLookChar()
{ return stream->lookChar(); }
inline char *Object::streamGetLine(char *buf, int size)
{ return stream->getLine(buf, size); }
inline Guint Object::streamGetPos()
{ return stream->getPos(); }
inline void Object::streamSetPos(Guint pos, int dir)
{ stream->setPos(pos, dir); }
inline Dict *Object::streamGetDict()
{ return stream->getDict(); }
#endif
//========================================================================
//
// OutputDev.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef OUTPUTDEV_H
#define OUTPUTDEV_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "gtypes.h"
#include "CharTypes.h"
class GString;
class Gfx;
class GfxState;
struct GfxColor;
class GfxColorSpace;
class GfxImageColorMap;
class GfxFunctionShading;
class GfxAxialShading;
class GfxRadialShading;
class Stream;
class Links;
class Link;
class Catalog;
class Page;
class Function;
//------------------------------------------------------------------------
// OutputDev
//------------------------------------------------------------------------
class OutputDev {
public:
// Constructor.
OutputDev() {}
// Destructor.
virtual ~OutputDev() {}
//----- get info about output device
// Does this device use upside-down coordinates?
// (Upside-down means (0,0) is the top left corner of the page.)
virtual GBool upsideDown() = 0;
// Does this device use drawChar() or drawString()?
virtual GBool useDrawChar() = 0;
// Does this device use tilingPatternFill()? If this returns false,
// tiling pattern fills will be reduced to a series of other drawing
// operations.
virtual GBool useTilingPatternFill() { return gFalse; }
// Does this device use functionShadedFill(), axialShadedFill(), and
// radialShadedFill()? If this returns false, these shaded fills
// will be reduced to a series of other drawing operations.
virtual GBool useShadedFills() { return gFalse; }
// Does this device use drawForm()? If this returns false,
// form-type XObjects will be interpreted (i.e., unrolled).
virtual GBool useDrawForm() { return gFalse; }
// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual GBool interpretType3Chars() = 0;
// Does this device need non-text content?
virtual GBool needNonText() { return gTrue; }
// Does this device require incCharCount to be called for text on
// non-shown layers?
virtual GBool needCharCount() { return gFalse; }
//----- initialization and control
// Set default transform matrix.
virtual void setDefaultCTM(double *ctm);
// Check to see if a page slice should be displayed. If this
// returns false, the page display is aborted. Typically, an
// OutputDev will use some alternate means to display the page
// before returning false.
virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool crop,
int sliceX, int sliceY, int sliceW, int sliceH,
GBool printing,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL)
{ return gTrue; }
// Start a page.
virtual void startPage(int pageNum, GfxState *state) {}
// End a page.
virtual void endPage() {}
// Dump page contents to display.
virtual void dump() {}
//----- coordinate conversion
// Convert between device and user coordinates.
virtual void cvtDevToUser(double dx, double dy, double *ux, double *uy);
virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy);
double *getDefCTM() { return defCTM; }
double *getDefICTM() { return defICTM; }
//----- save/restore graphics state
virtual void saveState(GfxState *state) {}
virtual void restoreState(GfxState *state) {}
//----- update graphics state
virtual void updateAll(GfxState *state);
virtual void updateCTM(GfxState *state, double m11, double m12,
double m21, double m22, double m31, double m32) {}
virtual void updateLineDash(GfxState *state) {}
virtual void updateFlatness(GfxState *state) {}
virtual void updateLineJoin(GfxState *state) {}
virtual void updateLineCap(GfxState *state) {}
virtual void updateMiterLimit(GfxState *state) {}
virtual void updateLineWidth(GfxState *state) {}
virtual void updateStrokeAdjust(GfxState *state) {}
virtual void updateFillColorSpace(GfxState *state) {}
virtual void updateStrokeColorSpace(GfxState *state) {}
virtual void updateFillColor(GfxState *state) {}
virtual void updateStrokeColor(GfxState *state) {}
virtual void updateBlendMode(GfxState *state) {}
virtual void updateFillOpacity(GfxState *state) {}
virtual void updateStrokeOpacity(GfxState *state) {}
virtual void updateFillOverprint(GfxState *state) {}
virtual void updateStrokeOverprint(GfxState *state) {}
virtual void updateOverprintMode(GfxState *state) {}
virtual void updateTransfer(GfxState *state) {}
//----- update text state
virtual void updateFont(GfxState *state) {}
virtual void updateTextMat(GfxState *state) {}
virtual void updateCharSpace(GfxState *state) {}
virtual void updateRender(GfxState *state) {}
virtual void updateRise(GfxState *state) {}
virtual void updateWordSpace(GfxState *state) {}
virtual void updateHorizScaling(GfxState *state) {}
virtual void updateTextPos(GfxState *state) {}
virtual void updateTextShift(GfxState *state, double shift) {}
virtual void saveTextPos(GfxState *state) {}
virtual void restoreTextPos(GfxState *state) {}
//----- path painting
virtual void stroke(GfxState *state) {}
virtual void fill(GfxState *state) {}
virtual void eoFill(GfxState *state) {}
virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
int paintType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
double xStep, double yStep) {}
virtual GBool functionShadedFill(GfxState *state,
GfxFunctionShading *shading)
{ return gFalse; }
virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading)
{ return gFalse; }
virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading)
{ return gFalse; }
//----- path clipping
virtual void clip(GfxState *state) {}
virtual void eoClip(GfxState *state) {}
virtual void clipToStrokePath(GfxState *state) {}
//----- text drawing
virtual void beginStringOp(GfxState *state) {}
virtual void endStringOp(GfxState *state) {}
virtual void beginString(GfxState *state, GString *s) {}
virtual void endString(GfxState *state) {}
virtual void drawChar(GfxState *state, double x, double y,
double dx, double dy,
double originX, double originY,
CharCode code, int nBytes, Unicode *u, int uLen) {}
virtual void drawString(GfxState *state, GString *s) {}
virtual GBool beginType3Char(GfxState *state, double x, double y,
double dx, double dy,
CharCode code, Unicode *u, int uLen);
virtual void endType3Char(GfxState *state) {}
virtual void endTextObject(GfxState *state) {}
virtual void incCharCount(int nChars) {}
//----- image drawing
virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg);
virtual void setSoftMaskFromImageMask(GfxState *state,
Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg);
virtual void drawImage(GfxState *state, Object *ref, Stream *str,
int width, int height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg);
virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Stream *maskStr, int maskWidth, int maskHeight,
GBool maskInvert);
virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Stream *maskStr,
int maskWidth, int maskHeight,
GfxImageColorMap *maskColorMap);
#if OPI_SUPPORT
//----- OPI functions
virtual void opiBegin(GfxState *state, Dict *opiDict);
virtual void opiEnd(GfxState *state, Dict *opiDict);
#endif
//----- Type 3 font operators
virtual void type3D0(GfxState *state, double wx, double wy) {}
virtual void type3D1(GfxState *state, double wx, double wy,
double llx, double lly, double urx, double ury) {}
//----- form XObjects
virtual void drawForm(Ref id) {}
//----- PostScript XObjects
virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
//----- transparency groups and soft masks
virtual void beginTransparencyGroup(GfxState *state, double *bbox,
GfxColorSpace *blendingColorSpace,
GBool isolated, GBool knockout,
GBool forSoftMask) {}
virtual void endTransparencyGroup(GfxState *state) {}
virtual void paintTransparencyGroup(GfxState *state, double *bbox) {}
virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha,
Function *transferFunc, GfxColor *backdropColor) {}
virtual void clearSoftMask(GfxState *state) {}
//----- links
virtual void processLink(Link *link) {}
#if 1 //~tmp: turn off anti-aliasing temporarily
virtual void setInShading(GBool sh) {}
#endif
private:
double defCTM[6]; // default coordinate transform matrix
double defICTM[6]; // inverse of default CTM
};
#endif
//========================================================================
//
// PDFDoc.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef PDFDOC_H
#define PDFDOC_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <stdio.h>
#include "XRef.h"
#include "Catalog.h"
#include "Page.h"
class GString;
class BaseStream;
class OutputDev;
class Links;
class LinkAction;
class LinkDest;
class Outline;
class OptionalContent;
class PDFCore;
//------------------------------------------------------------------------
// PDFDoc
//------------------------------------------------------------------------
class PDFDoc {
public:
PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
GString *userPassword = NULL, PDFCore *coreA = NULL);
#ifdef WIN32
PDFDoc(wchar_t *fileNameA, int fileNameLen, GString *ownerPassword = NULL,
GString *userPassword = NULL, PDFCore *coreA = NULL);
#endif
PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
GString *userPassword = NULL, PDFCore *coreA = NULL);
~PDFDoc();
// Was PDF document successfully opened?
GBool isOk() { return ok; }
// Get the error code (if isOk() returns false).
int getErrorCode() { return errCode; }
// Get file name.
GString *getFileName() { return fileName; }
#ifdef WIN32
wchar_t *getFileNameU() { return fileNameU; }
#endif
// Get the xref table.
XRef *getXRef() { return xref; }
// Get catalog.
Catalog *getCatalog() { return catalog; }
// Get base stream.
BaseStream *getBaseStream() { return str; }
// Get page parameters.
double getPageMediaWidth(int page)
{ return catalog->getPage(page)->getMediaWidth(); }
double getPageMediaHeight(int page)
{ return catalog->getPage(page)->getMediaHeight(); }
double getPageCropWidth(int page)
{ return catalog->getPage(page)->getCropWidth(); }
double getPageCropHeight(int page)
{ return catalog->getPage(page)->getCropHeight(); }
int getPageRotate(int page)
{ return catalog->getPage(page)->getRotate(); }
// Get number of pages.
int getNumPages() { return catalog->getNumPages(); }
// Return the contents of the metadata stream, or NULL if there is
// no metadata.
GString *readMetadata() { return catalog->readMetadata(); }
// Return the structure tree root object.
Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
// Display a page.
void displayPage(OutputDev *out, int page,
double hDPI, double vDPI, int rotate,
GBool useMediaBox, GBool crop, GBool printing,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Display a range of pages.
void displayPages(OutputDev *out, int firstPage, int lastPage,
double hDPI, double vDPI, int rotate,
GBool useMediaBox, GBool crop, GBool printing,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Display part of a page.
void displayPageSlice(OutputDev *out, int page,
double hDPI, double vDPI, int rotate,
GBool useMediaBox, GBool crop, GBool printing,
int sliceX, int sliceY, int sliceW, int sliceH,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Find a page, given its object ID. Returns page number, or 0 if
// not found.
int findPage(int num, int gen) { return catalog->findPage(num, gen); }
// Returns the links for the current page, transferring ownership to
// the caller.
Links *getLinks(int page);
// Find a named destination. Returns the link destination, or
// NULL if <name> is not a destination.
LinkDest *findDest(GString *name)
{ return catalog->findDest(name); }
// Process the links for a page.
void processLinks(OutputDev *out, int page);
#ifndef DISABLE_OUTLINE
// Return the outline object.
Outline *getOutline() { return outline; }
#endif
// Return the OptionalContent object.
OptionalContent *getOptionalContent() { return optContent; }
// Is the file encrypted?
GBool isEncrypted() { return xref->isEncrypted(); }
// Check various permissions.
GBool okToPrint(GBool ignoreOwnerPW = gFalse)
{ return xref->okToPrint(ignoreOwnerPW); }
GBool okToChange(GBool ignoreOwnerPW = gFalse)
{ return xref->okToChange(ignoreOwnerPW); }
GBool okToCopy(GBool ignoreOwnerPW = gFalse)
{ return xref->okToCopy(ignoreOwnerPW); }
GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
{ return xref->okToAddNotes(ignoreOwnerPW); }
// Is this document linearized?
GBool isLinearized();
// Return the document's Info dictionary (if any).
Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
// Return the PDF version specified by the file.
double getPDFVersion() { return pdfVersion; }
// Save this file with another name.
GBool saveAs(GString *name);
// Return a pointer to the PDFCore object.
PDFCore *getCore() { return core; }
// Get the list of embedded files.
int getNumEmbeddedFiles() { return catalog->getNumEmbeddedFiles(); }
Unicode *getEmbeddedFileName(int idx)
{ return catalog->getEmbeddedFileName(idx); }
int getEmbeddedFileNameLength(int idx)
{ return catalog->getEmbeddedFileNameLength(idx); }
GBool saveEmbeddedFile(int idx, char *path);
#ifdef WIN32
GBool saveEmbeddedFile(int idx, wchar_t *path, int pathLen);
#endif
private:
GBool setup(GString *ownerPassword, GString *userPassword);
void checkHeader();
GBool checkEncryption(GString *ownerPassword, GString *userPassword);
GBool saveEmbeddedFile2(int idx, FILE *f);
GString *fileName;
#ifdef WIN32
wchar_t *fileNameU;
#endif
FILE *file;
BaseStream *str;
PDFCore *core;
double pdfVersion;
XRef *xref;
Catalog *catalog;
#ifndef DISABLE_OUTLINE
Outline *outline;
#endif
OptionalContent *optContent;
GBool ok;
int errCode;
};
#endif
//========================================================================
//
// Page.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef PAGE_H
#define PAGE_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "Object.h"
class Dict;
class PDFDoc;
class XRef;
class OutputDev;
class Links;
//------------------------------------------------------------------------
class PDFRectangle {
public:
double x1, y1, x2, y2;
PDFRectangle() { x1 = y1 = x2 = y2 = 0; }
PDFRectangle(double x1A, double y1A, double x2A, double y2A)
{ x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; }
GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
void clipTo(PDFRectangle *rect);
};
//------------------------------------------------------------------------
// PageAttrs
//------------------------------------------------------------------------
class PageAttrs {
public:
// Construct a new PageAttrs object by merging a dictionary
// (of type Pages or Page) into another PageAttrs object. If
// <attrs> is NULL, uses defaults.
PageAttrs(PageAttrs *attrs, Dict *dict);
// Construct a new PageAttrs object for an empty page (only used
// when there is an error in the page tree).
PageAttrs();
// Destructor.
~PageAttrs();
// Accessors.
PDFRectangle *getMediaBox() { return &mediaBox; }
PDFRectangle *getCropBox() { return &cropBox; }
GBool isCropped() { return haveCropBox; }
PDFRectangle *getBleedBox() { return &bleedBox; }
PDFRectangle *getTrimBox() { return &trimBox; }
PDFRectangle *getArtBox() { return &artBox; }
int getRotate() { return rotate; }
GString *getLastModified()
{ return lastModified.isString()
? lastModified.getString() : (GString *)NULL; }
Dict *getBoxColorInfo()
{ return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; }
Dict *getGroup()
{ return group.isDict() ? group.getDict() : (Dict *)NULL; }
Stream *getMetadata()
{ return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; }
Dict *getPieceInfo()
{ return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; }
Dict *getSeparationInfo()
{ return separationInfo.isDict()
? separationInfo.getDict() : (Dict *)NULL; }
Dict *getResourceDict()
{ return resources.isDict() ? resources.getDict() : (Dict *)NULL; }
// Clip all other boxes to the MediaBox.
void clipBoxes();
private:
GBool readBox(Dict *dict, char *key, PDFRectangle *box);
PDFRectangle mediaBox;
PDFRectangle cropBox;
GBool haveCropBox;
PDFRectangle bleedBox;
PDFRectangle trimBox;
PDFRectangle artBox;
int rotate;
Object lastModified;
Object boxColorInfo;
Object group;
Object metadata;
Object pieceInfo;
Object separationInfo;
Object resources;
};
//------------------------------------------------------------------------
// Page
//------------------------------------------------------------------------
class Page {
public:
// Constructor.
Page(PDFDoc *docA, int numA, Dict *pageDict, PageAttrs *attrsA);
// Create an empty page (only used when there is an error in the
// page tree).
Page(PDFDoc *docA, int numA);
// Destructor.
~Page();
// Is page valid?
GBool isOk() { return ok; }
// Get page parameters.
int getNum() { return num; }
PDFRectangle *getMediaBox() { return attrs->getMediaBox(); }
PDFRectangle *getCropBox() { return attrs->getCropBox(); }
GBool isCropped() { return attrs->isCropped(); }
double getMediaWidth()
{ return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; }
double getMediaHeight()
{ return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; }
double getCropWidth()
{ return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; }
double getCropHeight()
{ return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; }
PDFRectangle *getBleedBox() { return attrs->getBleedBox(); }
PDFRectangle *getTrimBox() { return attrs->getTrimBox(); }
PDFRectangle *getArtBox() { return attrs->getArtBox(); }
int getRotate() { return attrs->getRotate(); }
GString *getLastModified() { return attrs->getLastModified(); }
Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); }
Dict *getGroup() { return attrs->getGroup(); }
Stream *getMetadata() { return attrs->getMetadata(); }
Dict *getPieceInfo() { return attrs->getPieceInfo(); }
Dict *getSeparationInfo() { return attrs->getSeparationInfo(); }
// Get resource dictionary.
Dict *getResourceDict() { return attrs->getResourceDict(); }
// Get annotations array.
Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
// Return a list of links.
Links *getLinks();
// Get contents.
Object *getContents(Object *obj) { return contents.fetch(xref, obj); }
// Display a page.
void display(OutputDev *out, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool crop,
GBool printing,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Display part of a page.
void displaySlice(OutputDev *out, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool crop,
int sliceX, int sliceY, int sliceW, int sliceH,
GBool printing,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
void makeBox(double hDPI, double vDPI, int rotate,
GBool useMediaBox, GBool upsideDown,
double sliceX, double sliceY, double sliceW, double sliceH,
PDFRectangle *box, GBool *crop);
void processLinks(OutputDev *out);
// Get the page's default CTM.
void getDefaultCTM(double *ctm, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool upsideDown);
private:
PDFDoc *doc;
XRef *xref; // the xref table for this PDF file
int num; // page number
PageAttrs *attrs; // page attributes
Object annots; // annotations array
Object contents; // page contents
GBool ok; // true if page is valid
};
#endif
//========================================================================
//
// SplashBitmap.h
//
//========================================================================
#ifndef SPLASHBITMAP_H
#define SPLASHBITMAP_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <stdio.h>
#include "SplashTypes.h"
//------------------------------------------------------------------------
// SplashBitmap
//------------------------------------------------------------------------
class SplashBitmap {
public:
// Create a new bitmap. It will have <widthA> x <heightA> pixels in
// color mode <modeA>. Rows will be padded out to a multiple of
// <rowPad> bytes. If <topDown> is false, the bitmap will be stored
// upside-down, i.e., with the last row first in memory.
SplashBitmap(int widthA, int heightA, int rowPad,
SplashColorMode modeA, GBool alphaA,
GBool topDown = gTrue);
~SplashBitmap();
int getWidth() { return width; }
int getHeight() { return height; }
int getRowSize() { return rowSize; }
int getAlphaRowSize() { return width; }
SplashColorMode getMode() { return mode; }
SplashColorPtr getDataPtr() { return data; }
Guchar *getAlphaPtr() { return alpha; }
SplashError writePNMFile(char *fileName);
SplashError writePNMFile(FILE *f);
SplashError writeAlphaPGMFile(char *fileName);
void getPixel(int x, int y, SplashColorPtr pixel);
Guchar getAlpha(int x, int y);
// Caller takes ownership of the bitmap data. The SplashBitmap
// object is no longer valid -- the next call should be to the
// destructor.
SplashColorPtr takeData();
private:
int width, height; // size of bitmap
int rowSize; // size of one row of data, in bytes
// - negative for bottom-up bitmaps
SplashColorMode mode; // color mode
SplashColorPtr data; // pointer to row zero of the color data
Guchar *alpha; // pointer to row zero of the alpha data
// (always top-down)
friend class Splash;
};
#endif
//========================================================================
//
// SplashOutputDev.h
//
// Copyright 2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef SPLASHOUTPUTDEV_H
#define SPLASHOUTPUTDEV_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "gtypes.h"
#include "SplashTypes.h"
#include "config.h"
#include "OutputDev.h"
#include "GfxState.h"
class Gfx8BitFont;
class SplashBitmap;
class Splash;
class SplashPath;
class SplashPattern;
class SplashFontEngine;
class SplashFont;
class T3FontCache;
struct T3FontCacheTag;
struct T3GlyphStack;
struct SplashTransparencyGroup;
//------------------------------------------------------------------------
// number of Type 3 fonts to cache
#define splashOutT3FontCacheSize 8
//------------------------------------------------------------------------
// SplashOutputDev
//------------------------------------------------------------------------
class SplashOutputDev: public OutputDev {
public:
// Constructor.
SplashOutputDev(SplashColorMode colorModeA, int bitmapRowPadA,
GBool reverseVideoA, SplashColorPtr paperColorA,
GBool bitmapTopDownA = gTrue,
GBool allowAntialiasA = gTrue);
// Destructor.
virtual ~SplashOutputDev();
//----- get info about output device
// Does this device use upside-down coordinates?
// (Upside-down means (0,0) is the top left corner of the page.)
virtual GBool upsideDown() { return bitmapTopDown ^ bitmapUpsideDown; }
// Does this device use drawChar() or drawString()?
virtual GBool useDrawChar() { return gTrue; }
// Does this device use tilingPatternFill()? If this returns false,
// tiling pattern fills will be reduced to a series of other drawing
// operations.
virtual GBool useTilingPatternFill() { return gTrue; }
// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual GBool interpretType3Chars() { return gTrue; }
//----- initialization and control
// Start a page.
virtual void startPage(int pageNum, GfxState *state);
// End a page.
virtual void endPage();
//----- save/restore graphics state
virtual void saveState(GfxState *state);
virtual void restoreState(GfxState *state);
//----- update graphics state
virtual void updateAll(GfxState *state);
virtual void updateCTM(GfxState *state, double m11, double m12,
double m21, double m22, double m31, double m32);
virtual void updateLineDash(GfxState *state);
virtual void updateFlatness(GfxState *state);
virtual void updateLineJoin(GfxState *state);
virtual void updateLineCap(GfxState *state);
virtual void updateMiterLimit(GfxState *state);
virtual void updateLineWidth(GfxState *state);
virtual void updateStrokeAdjust(GfxState *state);
virtual void updateFillColor(GfxState *state);
virtual void updateStrokeColor(GfxState *state);
virtual void updateBlendMode(GfxState *state);
virtual void updateFillOpacity(GfxState *state);
virtual void updateStrokeOpacity(GfxState *state);
//----- update text state
virtual void updateFont(GfxState *state);
//----- path painting
virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
virtual void tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
int paintType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
double xStep, double yStep);
//----- path clipping
virtual void clip(GfxState *state);
virtual void eoClip(GfxState *state);
virtual void clipToStrokePath(GfxState *state);
//----- text drawing
virtual void drawChar(GfxState *state, double x, double y,
double dx, double dy,
double originX, double originY,
CharCode code, int nBytes, Unicode *u, int uLen);
virtual GBool beginType3Char(GfxState *state, double x, double y,
double dx, double dy,
CharCode code, Unicode *u, int uLen);
virtual void endType3Char(GfxState *state);
virtual void endTextObject(GfxState *state);
//----- image drawing
virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg);
virtual void setSoftMaskFromImageMask(GfxState *state,
Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg);
virtual void drawImage(GfxState *state, Object *ref, Stream *str,
int width, int height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg);
virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Stream *maskStr, int maskWidth, int maskHeight,
GBool maskInvert);
virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Stream *maskStr,
int maskWidth, int maskHeight,
GfxImageColorMap *maskColorMap);
//----- Type 3 font operators
virtual void type3D0(GfxState *state, double wx, double wy);
virtual void type3D1(GfxState *state, double wx, double wy,
double llx, double lly, double urx, double ury);
//----- transparency groups and soft masks
virtual void beginTransparencyGroup(GfxState *state, double *bbox,
GfxColorSpace *blendingColorSpace,
GBool isolated, GBool knockout,
GBool forSoftMask);
virtual void endTransparencyGroup(GfxState *state);
virtual void paintTransparencyGroup(GfxState *state, double *bbox);
virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha,
Function *transferFunc, GfxColor *backdropColor);
virtual void clearSoftMask(GfxState *state);
//----- special access
// Called to indicate that a new PDF document has been loaded.
void startDoc(XRef *xrefA);
void setPaperColor(SplashColorPtr paperColorA);
GBool isReverseVideo() { return reverseVideo; }
void setReverseVideo(GBool reverseVideoA) { reverseVideo = reverseVideoA; }
// Get the bitmap and its size.
SplashBitmap *getBitmap() { return bitmap; }
int getBitmapWidth();
int getBitmapHeight();
// Returns the last rasterized bitmap, transferring ownership to the
// caller.
SplashBitmap *takeBitmap();
// Set this flag to true to generate an upside-down bitmap (useful
// for Windows BMP files).
void setBitmapUpsideDown(GBool f) { bitmapUpsideDown = f; }
// Get the Splash object.
Splash *getSplash() { return splash; }
// Get the modified region.
void getModRegion(int *xMin, int *yMin, int *xMax, int *yMax);
// Clear the modified region.
void clearModRegion();
// Set the Splash fill color.
void setFillColor(int r, int g, int b);
// Get a font object for a Base-14 font, using the Latin-1 encoding.
SplashFont *getFont(GString *name, SplashCoord *textMatA);
SplashFont *getCurrentFont() { return font; }
// If <skipTextA> is true, don't draw any text.
void setSkipText(GBool skipTextA) { skipText = skipTextA; }
int getNestCount() { return nestCount; }
#if 1 //~tmp: turn off anti-aliasing temporarily
virtual void setInShading(GBool sh);
#endif
private:
void setupScreenParams(double hDPI, double vDPI);
SplashPattern *getColor(GfxGray gray);
SplashPattern *getColor(GfxRGB *rgb);
#if SPLASH_CMYK
SplashPattern *getColor(GfxCMYK *cmyk);
#endif
void setOverprintMask(GfxColorSpace *colorSpace, GBool overprintFlag,
int overprintMode, GfxColor *singleColor);
SplashPath *convertPath(GfxState *state, GfxPath *path);
void doUpdateFont(GfxState *state);
void drawType3Glyph(GfxState *state, T3FontCache *t3Font,
T3FontCacheTag *tag, Guchar *data);
static GBool imageMaskSrc(void *data, SplashColorPtr line);
static GBool imageSrc(void *data, SplashColorPtr colorLine,
Guchar *alphaLine);
static GBool alphaImageSrc(void *data, SplashColorPtr line,
Guchar *alphaLine);
static GBool maskedImageSrc(void *data, SplashColorPtr line,
Guchar *alphaLine);
SplashColorMode colorMode;
int bitmapRowPad;
GBool bitmapTopDown;
GBool bitmapUpsideDown;
GBool allowAntialias;
GBool vectorAntialias;
GBool reverseVideo; // reverse video mode
SplashColor paperColor; // paper color
SplashScreenParams screenParams;
GBool skipText;
XRef *xref; // xref table for current document
SplashBitmap *bitmap;
Splash *splash;
SplashFontEngine *fontEngine;
T3FontCache * // Type 3 font cache
t3FontCache[splashOutT3FontCacheSize];
int nT3Fonts; // number of valid entries in t3FontCache
T3GlyphStack *t3GlyphStack; // Type 3 glyph context stack
SplashFont *font; // current font
GBool needFontUpdate; // set when the font needs to be updated
SplashPath *textClipPath; // clipping path built with text object
SplashTransparencyGroup * // transparency group stack
transpGroupStack;
int nestCount;
};
#endif
//========================================================================
//
// SplashTypes.h
//
//========================================================================
#ifndef SPLASHTYPES_H
#define SPLASHTYPES_H
#include <aconf.h>
#include "gtypes.h"
//------------------------------------------------------------------------
// coordinates
//------------------------------------------------------------------------
#if USE_FIXEDPOINT
#include "FixedPoint.h"
typedef FixedPoint SplashCoord;
#else
typedef double SplashCoord;
#endif
//------------------------------------------------------------------------
// antialiasing
//------------------------------------------------------------------------
#define splashAASize 4
//------------------------------------------------------------------------
// colors
//------------------------------------------------------------------------
enum SplashColorMode {
splashModeMono1, // 1 bit per component, 8 pixels per byte,
// MSbit is on the left
splashModeMono8, // 1 byte per component, 1 byte per pixel
splashModeRGB8, // 1 byte per component, 3 bytes per pixel:
// RGBRGB...
splashModeBGR8 // 1 byte per component, 3 bytes per pixel:
// BGRBGR...
#if SPLASH_CMYK
,
splashModeCMYK8 // 1 byte per component, 4 bytes per pixel:
// CMYKCMYK...
#endif
};
// number of components in each color mode
// (defined in SplashState.cc)
extern int splashColorModeNComps[];
// max number of components in any SplashColor
#define splashMaxColorComps 3
#if SPLASH_CMYK
# undef splashMaxColorComps
# define splashMaxColorComps 4
#endif
typedef Guchar SplashColor[splashMaxColorComps];
typedef Guchar *SplashColorPtr;
// RGB8
static inline Guchar splashRGB8R(SplashColorPtr rgb8) { return rgb8[0]; }
static inline Guchar splashRGB8G(SplashColorPtr rgb8) { return rgb8[1]; }
static inline Guchar splashRGB8B(SplashColorPtr rgb8) { return rgb8[2]; }
// BGR8
static inline Guchar splashBGR8R(SplashColorPtr bgr8) { return bgr8[2]; }
static inline Guchar splashBGR8G(SplashColorPtr bgr8) { return bgr8[1]; }
static inline Guchar splashBGR8B(SplashColorPtr bgr8) { return bgr8[0]; }
#if SPLASH_CMYK
// CMYK8
static inline Guchar splashCMYK8C(SplashColorPtr cmyk8) { return cmyk8[0]; }
static inline Guchar splashCMYK8M(SplashColorPtr cmyk8) { return cmyk8[1]; }
static inline Guchar splashCMYK8Y(SplashColorPtr cmyk8) { return cmyk8[2]; }
static inline Guchar splashCMYK8K(SplashColorPtr cmyk8) { return cmyk8[3]; }
#endif
static inline void splashColorCopy(SplashColorPtr dest, SplashColorPtr src) {
dest[0] = src[0];
dest[1] = src[1];
dest[2] = src[2];
#if SPLASH_CMYK
dest[3] = src[3];
#endif
}
static inline void splashColorXor(SplashColorPtr dest, SplashColorPtr src) {
dest[0] ^= src[0];
dest[1] ^= src[1];
dest[2] ^= src[2];
#if SPLASH_CMYK
dest[3] ^= src[3];
#endif
}
//------------------------------------------------------------------------
// blend functions
//------------------------------------------------------------------------
typedef void (*SplashBlendFunc)(SplashColorPtr src, SplashColorPtr dest,
SplashColorPtr blend, SplashColorMode cm);
//------------------------------------------------------------------------
// screen parameters
//------------------------------------------------------------------------
enum SplashScreenType {
splashScreenDispersed,
splashScreenClustered,
splashScreenStochasticClustered
};
struct SplashScreenParams {
SplashScreenType type;
int size;
int dotRadius;
SplashCoord gamma;
SplashCoord blackThreshold;
SplashCoord whiteThreshold;
};
//------------------------------------------------------------------------
// error results
//------------------------------------------------------------------------
typedef int SplashError;
#endif
This diff is collapsed.
//========================================================================
//
// XRef.h
//
// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef XREF_H
#define XREF_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include "gtypes.h"
#include "Object.h"
class Dict;
class Stream;
class Parser;
class ObjectStream;
//------------------------------------------------------------------------
// XRef
//------------------------------------------------------------------------
enum XRefEntryType {
xrefEntryFree,
xrefEntryUncompressed,
xrefEntryCompressed
};
struct XRefEntry {
Guint offset;
int gen;
XRefEntryType type;
};
class XRef {
public:
// Constructor. Read xref table from stream.
XRef(BaseStream *strA);
// Destructor.
~XRef();
// Is xref table valid?
GBool isOk() { return ok; }
// Get the error code (if isOk() returns false).
int getErrorCode() { return errCode; }
// Set the encryption parameters.
void setEncryption(int permFlagsA, GBool ownerPasswordOkA,
Guchar *fileKeyA, int keyLengthA, int encVersionA,
CryptAlgorithm encAlgorithmA);
// Is the file encrypted?
GBool isEncrypted() { return encrypted; }
// Check various permissions.
GBool okToPrint(GBool ignoreOwnerPW = gFalse);
GBool okToChange(GBool ignoreOwnerPW = gFalse);
GBool okToCopy(GBool ignoreOwnerPW = gFalse);
GBool okToAddNotes(GBool ignoreOwnerPW = gFalse);
// Get catalog object.
Object *getCatalog(Object *obj) { return fetch(rootNum, rootGen, obj); }
// Fetch an indirect reference.
Object *fetch(int num, int gen, Object *obj, int recursion = 0);
// Return the document's Info dictionary (if any).
Object *getDocInfo(Object *obj);
Object *getDocInfoNF(Object *obj);
// Return the number of objects in the xref table.
int getNumObjects() { return last + 1; }
// Return the offset of the last xref table.
Guint getLastXRefPos() { return lastXRefPos; }
// Return the catalog object reference.
int getRootNum() { return rootNum; }
int getRootGen() { return rootGen; }
// Get end position for a stream in a damaged file.
// Returns false if unknown or file is not damaged.
GBool getStreamEnd(Guint streamStart, Guint *streamEnd);
// Direct access.
int getSize() { return size; }
XRefEntry *getEntry(int i) { return &entries[i]; }
Object *getTrailerDict() { return &trailerDict; }
private:
BaseStream *str; // input stream
Guint start; // offset in file (to allow for garbage
// at beginning of file)
XRefEntry *entries; // xref entries
int size; // size of <entries> array
int last; // last used index in <entries>
int rootNum, rootGen; // catalog dict
GBool ok; // true if xref table is valid
int errCode; // error code (if <ok> is false)
Object trailerDict; // trailer dictionary
Guint lastXRefPos; // offset of last xref table
Guint *streamEnds; // 'endstream' positions - only used in
// damaged files
int streamEndsLen; // number of valid entries in streamEnds
ObjectStream *objStr; // cached object stream
GBool encrypted; // true if file is encrypted
int permFlags; // permission bits
GBool ownerPasswordOk; // true if owner password is correct
Guchar fileKey[16]; // file decryption key
int keyLength; // length of key, in bytes
int encVersion; // encryption version
CryptAlgorithm encAlgorithm; // encryption algorithm
Guint getStartXref();
GBool readXRef(Guint *pos);
GBool readXRefTable(Parser *parser, Guint *pos);
GBool readXRefStreamSection(Stream *xrefStr, int *w, int first, int n);
GBool readXRefStream(Stream *xrefStr, Guint *pos);
GBool constructXRef();
Guint strToUnsigned(char *s);
};
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment