2011-07-28 14:26:00 +00:00
|
|
|
|
2010-09-24 22:25:30 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2010 The Android Open Source Project
|
2010-09-24 22:25:30 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-09-24 22:25:30 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2010-09-24 22:25:30 +00:00
|
|
|
#ifndef SkPDFCatalog_DEFINED
|
|
|
|
#define SkPDFCatalog_DEFINED
|
|
|
|
|
2011-01-26 21:59:00 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2011-07-20 17:39:01 +00:00
|
|
|
#include "SkPDFDocument.h"
|
2010-09-24 22:25:30 +00:00
|
|
|
#include "SkPDFTypes.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
|
|
|
|
/** \class SkPDFCatalog
|
|
|
|
|
2010-10-01 23:26:55 +00:00
|
|
|
The PDF catalog manages object numbers and file offsets. It is used
|
|
|
|
to create the PDF cross reference table.
|
2010-09-24 22:25:30 +00:00
|
|
|
*/
|
2011-03-30 20:14:49 +00:00
|
|
|
class SK_API SkPDFCatalog {
|
2010-09-24 22:25:30 +00:00
|
|
|
public:
|
|
|
|
/** Create a PDF catalog.
|
|
|
|
*/
|
2011-07-20 17:39:01 +00:00
|
|
|
explicit SkPDFCatalog(SkPDFDocument::Flags flags);
|
2010-10-01 23:26:55 +00:00
|
|
|
~SkPDFCatalog();
|
2010-09-24 22:25:30 +00:00
|
|
|
|
2011-02-01 22:19:44 +00:00
|
|
|
/** Add the passed object to the catalog. Refs obj.
|
2010-10-12 23:08:13 +00:00
|
|
|
* @param obj The object to add.
|
|
|
|
* @param onFirstPage Is the object on the first page.
|
2011-02-01 22:19:44 +00:00
|
|
|
* @return The obj argument is returned.
|
2010-09-24 22:25:30 +00:00
|
|
|
*/
|
2011-02-01 22:19:44 +00:00
|
|
|
SkPDFObject* addObject(SkPDFObject* obj, bool onFirstPage);
|
2010-09-24 22:25:30 +00:00
|
|
|
|
2010-10-12 23:08:13 +00:00
|
|
|
/** Inform the catalog of the object's position in the final stream.
|
|
|
|
* The object should already have been added to the catalog. Returns
|
|
|
|
* the object's size.
|
|
|
|
* @param obj The object to add.
|
|
|
|
* @param offset The byte offset in the output stream of this object.
|
|
|
|
*/
|
|
|
|
size_t setFileOffset(SkPDFObject* obj, size_t offset);
|
|
|
|
|
2010-09-24 22:25:30 +00:00
|
|
|
/** Output the object number for the passed object.
|
2010-10-12 23:08:13 +00:00
|
|
|
* @param obj The object of interest.
|
|
|
|
* @param stream The writable output stream to send the output to.
|
2010-09-24 22:25:30 +00:00
|
|
|
*/
|
|
|
|
void emitObjectNumber(SkWStream* stream, SkPDFObject* obj);
|
|
|
|
|
|
|
|
/** Return the number of bytes that would be emitted for the passed
|
|
|
|
* object's object number.
|
2010-10-12 23:08:13 +00:00
|
|
|
* @param obj The object of interest
|
2010-09-24 22:25:30 +00:00
|
|
|
*/
|
|
|
|
size_t getObjectNumberSize(SkPDFObject* obj);
|
|
|
|
|
2011-07-20 17:39:01 +00:00
|
|
|
/** Return the document flags in effect for this catalog/document.
|
|
|
|
*/
|
|
|
|
SkPDFDocument::Flags getDocumentFlags() const { return fDocumentFlags; }
|
|
|
|
|
2010-10-12 23:08:13 +00:00
|
|
|
/** Output the cross reference table for objects in the catalog.
|
|
|
|
* Returns the total number of objects.
|
|
|
|
* @param stream The writable output stream to send the output to.
|
|
|
|
* @param firstPage If true, include first page objects only, otherwise
|
|
|
|
* include all objects not on the first page.
|
|
|
|
*/
|
|
|
|
int32_t emitXrefTable(SkWStream* stream, bool firstPage);
|
|
|
|
|
2011-07-06 23:31:24 +00:00
|
|
|
/** Set substitute object for the passed object.
|
|
|
|
*/
|
|
|
|
void setSubstitute(SkPDFObject* original, SkPDFObject* substitute);
|
|
|
|
|
|
|
|
/** Find and return any substitute object set for the passed object. If
|
|
|
|
* there is none, return the passed object.
|
|
|
|
*/
|
|
|
|
SkPDFObject* getSubstituteObject(SkPDFObject* object);
|
|
|
|
|
|
|
|
/** Set file offsets for the resources of substitute objects.
|
|
|
|
* @param fileOffset Accumulated offset of current document.
|
|
|
|
* @param firstPage Indicate whether this is for the first page only.
|
2011-07-20 00:33:53 +00:00
|
|
|
* @return Total size of resources of substitute objects.
|
2011-07-06 23:31:24 +00:00
|
|
|
*/
|
|
|
|
off_t setSubstituteResourcesOffsets(off_t fileOffset, bool firstPage);
|
|
|
|
|
|
|
|
/** Emit the resources of substitute objects.
|
|
|
|
*/
|
|
|
|
void emitSubstituteResources(SkWStream* stream, bool firstPage);
|
|
|
|
|
2010-09-24 22:25:30 +00:00
|
|
|
private:
|
|
|
|
struct Rec {
|
|
|
|
Rec(SkPDFObject* object, bool onFirstPage)
|
|
|
|
: fObject(object),
|
|
|
|
fFileOffset(0),
|
|
|
|
fObjNumAssigned(false),
|
|
|
|
fOnFirstPage(onFirstPage) {
|
|
|
|
}
|
|
|
|
SkPDFObject* fObject;
|
|
|
|
off_t fFileOffset;
|
|
|
|
bool fObjNumAssigned;
|
|
|
|
bool fOnFirstPage;
|
|
|
|
};
|
|
|
|
|
2011-07-06 23:31:24 +00:00
|
|
|
struct SubstituteMapping {
|
|
|
|
SubstituteMapping(SkPDFObject* original, SkPDFObject* substitute)
|
|
|
|
: fOriginal(original), fSubstitute(substitute) {
|
|
|
|
}
|
|
|
|
SkPDFObject* fOriginal;
|
|
|
|
SkPDFObject* fSubstitute;
|
|
|
|
};
|
|
|
|
|
2011-08-20 00:36:18 +00:00
|
|
|
// TODO(vandebo): Make this a hash if it's a performance problem.
|
2010-09-24 22:25:30 +00:00
|
|
|
SkTDArray<struct Rec> fCatalog;
|
|
|
|
|
2011-08-20 00:36:18 +00:00
|
|
|
// TODO(arthurhsu): Make this a hash if it's a performance problem.
|
2011-07-06 23:31:24 +00:00
|
|
|
SkTDArray<SubstituteMapping> fSubstituteMap;
|
|
|
|
SkTDArray<SkPDFObject*> fSubstituteResourcesFirstPage;
|
|
|
|
SkTDArray<SkPDFObject*> fSubstituteResourcesRemaining;
|
|
|
|
|
2010-10-12 23:08:13 +00:00
|
|
|
// Number of objects on the first page.
|
|
|
|
uint32_t fFirstPageCount;
|
|
|
|
// Next object number to assign (on page > 1).
|
2010-09-24 22:25:30 +00:00
|
|
|
uint32_t fNextObjNum;
|
2010-10-12 23:08:13 +00:00
|
|
|
// Next object number to assign on the first page.
|
|
|
|
uint32_t fNextFirstPageObjNum;
|
2010-09-24 22:25:30 +00:00
|
|
|
|
2011-07-20 17:39:01 +00:00
|
|
|
SkPDFDocument::Flags fDocumentFlags;
|
|
|
|
|
2010-09-24 22:25:30 +00:00
|
|
|
int findObjectIndex(SkPDFObject* obj) const;
|
|
|
|
|
|
|
|
int assignObjNum(SkPDFObject* obj);
|
2011-07-06 23:31:24 +00:00
|
|
|
|
|
|
|
SkTDArray<SkPDFObject*>* getSubstituteList(bool firstPage);
|
2010-09-24 22:25:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|