gfx/skia/trunk/src/pdf/SkPDFCatalog.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/pdf/SkPDFCatalog.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2010 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkPDFCatalog_DEFINED
    1.14 +#define SkPDFCatalog_DEFINED
    1.15 +
    1.16 +#include <sys/types.h>
    1.17 +
    1.18 +#include "SkPDFDocument.h"
    1.19 +#include "SkPDFTypes.h"
    1.20 +#include "SkRefCnt.h"
    1.21 +#include "SkTDArray.h"
    1.22 +
    1.23 +/** \class SkPDFCatalog
    1.24 +
    1.25 +    The PDF catalog manages object numbers and file offsets.  It is used
    1.26 +    to create the PDF cross reference table.
    1.27 +*/
    1.28 +class SkPDFCatalog {
    1.29 +public:
    1.30 +    /** Create a PDF catalog.
    1.31 +     */
    1.32 +    explicit SkPDFCatalog(SkPDFDocument::Flags flags);
    1.33 +    ~SkPDFCatalog();
    1.34 +
    1.35 +    /** Add the passed object to the catalog.  Refs obj.
    1.36 +     *  @param obj         The object to add.
    1.37 +     *  @param onFirstPage Is the object on the first page.
    1.38 +     *  @return The obj argument is returned.
    1.39 +     */
    1.40 +    SkPDFObject* addObject(SkPDFObject* obj, bool onFirstPage);
    1.41 +
    1.42 +    /** Inform the catalog of the object's position in the final stream.
    1.43 +     *  The object should already have been added to the catalog.  Returns
    1.44 +     *  the object's size.
    1.45 +     *  @param obj         The object to add.
    1.46 +     *  @param offset      The byte offset in the output stream of this object.
    1.47 +     */
    1.48 +    size_t setFileOffset(SkPDFObject* obj, off_t offset);
    1.49 +
    1.50 +    /** Output the object number for the passed object.
    1.51 +     *  @param obj         The object of interest.
    1.52 +     *  @param stream      The writable output stream to send the output to.
    1.53 +     */
    1.54 +    void emitObjectNumber(SkWStream* stream, SkPDFObject* obj);
    1.55 +
    1.56 +    /** Return the number of bytes that would be emitted for the passed
    1.57 +     *  object's object number.
    1.58 +     *  @param obj         The object of interest
    1.59 +     */
    1.60 +    size_t getObjectNumberSize(SkPDFObject* obj);
    1.61 +
    1.62 +    /** Return the document flags in effect for this catalog/document.
    1.63 +     */
    1.64 +    SkPDFDocument::Flags getDocumentFlags() const { return fDocumentFlags; }
    1.65 +
    1.66 +    /** Output the cross reference table for objects in the catalog.
    1.67 +     *  Returns the total number of objects.
    1.68 +     *  @param stream      The writable output stream to send the output to.
    1.69 +     *  @param firstPage   If true, include first page objects only, otherwise
    1.70 +     *                     include all objects not on the first page.
    1.71 +     */
    1.72 +    int32_t emitXrefTable(SkWStream* stream, bool firstPage);
    1.73 +
    1.74 +    /** Set substitute object for the passed object.
    1.75 +     */
    1.76 +    void setSubstitute(SkPDFObject* original, SkPDFObject* substitute);
    1.77 +
    1.78 +    /** Find and return any substitute object set for the passed object. If
    1.79 +     *  there is none, return the passed object.
    1.80 +     */
    1.81 +    SkPDFObject* getSubstituteObject(SkPDFObject* object);
    1.82 +
    1.83 +    /** Set file offsets for the resources of substitute objects.
    1.84 +     *  @param fileOffset Accumulated offset of current document.
    1.85 +     *  @param firstPage  Indicate whether this is for the first page only.
    1.86 +     *  @return           Total size of resources of substitute objects.
    1.87 +     */
    1.88 +    off_t setSubstituteResourcesOffsets(off_t fileOffset, bool firstPage);
    1.89 +
    1.90 +    /** Emit the resources of substitute objects.
    1.91 +     */
    1.92 +    void emitSubstituteResources(SkWStream* stream, bool firstPage);
    1.93 +
    1.94 +private:
    1.95 +    struct Rec {
    1.96 +        Rec(SkPDFObject* object, bool onFirstPage)
    1.97 +            : fObject(object),
    1.98 +              fFileOffset(0),
    1.99 +              fObjNumAssigned(false),
   1.100 +              fOnFirstPage(onFirstPage) {
   1.101 +        }
   1.102 +        SkPDFObject* fObject;
   1.103 +        off_t fFileOffset;
   1.104 +        bool fObjNumAssigned;
   1.105 +        bool fOnFirstPage;
   1.106 +    };
   1.107 +
   1.108 +    struct SubstituteMapping {
   1.109 +        SubstituteMapping(SkPDFObject* original, SkPDFObject* substitute)
   1.110 +            : fOriginal(original), fSubstitute(substitute) {
   1.111 +        }
   1.112 +        SkPDFObject* fOriginal;
   1.113 +        SkPDFObject* fSubstitute;
   1.114 +    };
   1.115 +
   1.116 +    // TODO(vandebo): Make this a hash if it's a performance problem.
   1.117 +    SkTDArray<struct Rec> fCatalog;
   1.118 +
   1.119 +    // TODO(arthurhsu): Make this a hash if it's a performance problem.
   1.120 +    SkTDArray<SubstituteMapping> fSubstituteMap;
   1.121 +    SkTSet<SkPDFObject*> fSubstituteResourcesFirstPage;
   1.122 +    SkTSet<SkPDFObject*> fSubstituteResourcesRemaining;
   1.123 +
   1.124 +    // Number of objects on the first page.
   1.125 +    uint32_t fFirstPageCount;
   1.126 +    // Next object number to assign (on page > 1).
   1.127 +    uint32_t fNextObjNum;
   1.128 +    // Next object number to assign on the first page.
   1.129 +    uint32_t fNextFirstPageObjNum;
   1.130 +
   1.131 +    SkPDFDocument::Flags fDocumentFlags;
   1.132 +
   1.133 +    int findObjectIndex(SkPDFObject* obj) const;
   1.134 +
   1.135 +    int assignObjNum(SkPDFObject* obj);
   1.136 +
   1.137 +    SkTSet<SkPDFObject*>* getSubstituteList(bool firstPage);
   1.138 +};
   1.139 +
   1.140 +#endif

mercurial