File pdf.h of Package fax2pdf

// -*- mode: c++ -*-
// $Id: pdf.h,v 1.3 2002/06/18 04:26:35 stamfest Exp $
// 
//**********************************************************************
//
// Copyright (c) 2000 by Peter Stamfest <peter@stamfest.at>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//**********************************************************************

#include <vector>
#include <string>
#include <cstdio>
#include <cstring>

#define foreach(I,c)  for ( I = c.begin(); I != c.end() ; ++I ) 

class xrefentry
{
public:
    unsigned long onr, gennr;
    long offset;
    xrefentry(int o, int g, long off) : onr(o), gennr(g), offset(off) {};
};






class target
{
    unsigned long n;
public:
    ostream &o;
    
    target(ostream &oo) : n(0), o(oo) {};
	
    target &out(const char *s, unsigned long nn = 0) {
	if (nn == 0) nn = strlen((const char*)s);
	n += nn;
	o.write(s, nn);
	return *this;
    };
    target &out(const unsigned char *s, unsigned long nn = 0) {
	return out((char*)s, nn);
    };
    unsigned long report() { return n; };
};

class obj;  // forward decl

class xref
{
public:
    vector<void*> entries;
    unsigned long maxseen;

    xref() : maxseen(0) {};

    void add(const obj &ob, target &o);
    target &out(target &);

    ~xref();
};

class document;

class obj
{
    friend class document;
    static int nextnr;
    static int objcnt;   // debugging counter

protected:
    static xref XRef;

public:
    unsigned long onr, gennr;

    obj();
    unsigned long getnr();
    int getnrofobj() { return objcnt; };
    virtual target &out(target &);
    virtual void assign_numbers();

    target &id(target &o) {
	if (onr == 0) assign_numbers();
	XRef.add(*this, o);

	char buf[80];
	sprintf(buf, "%ld %ld obj\n", onr, gennr);
	return o.out(buf);
    };
    target &ind(target &o) {
	if (onr == 0) assign_numbers();
	char buf[80];
	sprintf(buf, "%ld %ld R ", onr, gennr);
	return o.out(buf);
    };
    string ind() {
	if (onr == 0) assign_numbers();
	char buf[80];
	sprintf(buf, "%ld %ld R ", onr, gennr);
	return buf;
    };
    virtual ~obj();
};




class mark : public obj
{
public:
    virtual target &xobject_resource(target &o) = 0;
    virtual target &contents_out(target &o) = 0;
    virtual ~mark();
};

class image : public mark
{
    static int cnt;
    string name;

    int w, h, bpp;
    int x, y, sx, sy;

    unsigned char * data;
    long leng;
    bool flate;

public:
    bool copied;

public:
    image(int width, int height, int depth,
	  int xx, int yy, int ssx, int ssy, unsigned char *d, long l);
    
    const string &getname() {
	if (name == "") {
	    char buf[80];
	    sprintf(buf, "Img%d", cnt++);
	    name = buf;
	}
	return name;
    };

    virtual target &out(target &);
    virtual target &xobject_resource(target &o);
    virtual target &contents_out(target &o);
    virtual long stream_out(target &o);

    virtual ~image();
};

class pages;

enum media_type { a4, letter, legal };

class page : public obj
{
public:
    int mediax, mediay;
    int cutx, cuty;
    bool streamed;

public:
    page(media_type = a4);
    void set_media(media_type);

    vector<void*> themarks;

    virtual target &out(target &, pages &);
    virtual void assign_numbers();

    void addmark(mark *m) {
	themarks.push_back(m);
    };

    void done(target &, pages &);
    virtual ~page();
};

class pages : public obj
{
public:
    vector<void*> thepages;

    virtual target &out(target &);
    virtual void assign_numbers();

    void addpage(page *p) {
	thepages.push_back(p);
    };

    virtual ~pages();
};


class catalog : public obj
{
public:
    virtual target &out(target &, pages &);
    virtual ~catalog();
};

class kv
{
public:
    string k, v;
    kv(const string &kk,
       const string &vv) : 
	k(kk), v(vv)
    {
    };
};

class info : public obj
{
    vector<void*> theinfos;
public:
    virtual target &out(target &);

    void addinfo(const string &k, const string &v);

    virtual ~info();
};

class document 
{
public:
    catalog cat;
    pages thepages;
    info theinfo;

    target &head(target &);

    virtual target &out(target &);
    virtual void assign_numbers();

    void addpage(page *p) {
	thepages.addpage(p);
    };
    virtual ~document();
};
openSUSE Build Service is sponsored by