Home | History | Annotate | Download | only in pdf
      1 /*
      2  * Copyright 2013 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkPDFResourceDict_DEFINED
      9 #define SkPDFResourceDict_DEFINED
     10 
     11 #include "SkPDFTypes.h"
     12 #include "SkTDArray.h"
     13 #include "SkTSet.h"
     14 #include "SkTypes.h"
     15 
     16 /** \class SkPDFResourceDict
     17 
     18     A resource dictionary, which maintains the relevant sub-dicts and
     19     allows generation of a list of referenced SkPDFObjects inserted with
     20     insertResourceAsRef.
     21 */
     22 class SkPDFResourceDict : public SkPDFDict {
     23 public:
     24     SK_DECLARE_INST_COUNT(SkPDFResourceDict)
     25 
     26      enum SkPDFResourceType{
     27         kExtGState_ResourceType,
     28         kPattern_ResourceType,
     29         kXObject_ResourceType,
     30         kFont_ResourceType,
     31         // These additional types are defined by the spec, but not
     32         // currently used by Skia: ColorSpace, Shading, Properties
     33         kResourceTypeCount
     34      };
     35 
     36     /** Create a PDF resource dictionary.
     37      *  The full set of ProcSet entries is automatically created for backwards
     38      *  compatibility, as recommended by the PDF spec.
     39      */
     40     SkPDFResourceDict();
     41 
     42     /** Add the value SkPDFObject as a reference to the resource dictionary
     43      *  with the give type and key.
     44      *  The relevant sub-dicts will be automatically generated, and the
     45      *  resource will be named by concatenating a type-specific prefix and
     46      *  the input key.
     47      *  This object will be part of the resource list when requested later.
     48      *  @param type  The type of resource being entered, like
     49      *    kPattern_ResourceType or kExtGState_ResourceType.
     50      *  @param key   The resource key, should be unique within its type.
     51      *  @param value The resource itself.
     52      *  @return The value argument is returned.
     53      */
     54     SkPDFObject* insertResourceAsReference(SkPDFResourceType type, int key,
     55                                            SkPDFObject* value);
     56 
     57     /**
     58      * Gets resources inserted into this dictionary as a reference.
     59      *
     60      * @param knownResourceObjects Set containing currently known resources.
     61      *     Resources in the dict and this set will not be added to the output.
     62      * @param newResourceObjects   Output set to which non-preexisting resources
     63      *     will be added.
     64      * @param recursive            Whether or not to add resources of resources.
     65      */
     66     void getReferencedResources(
     67             const SkTSet<SkPDFObject*>& knownResourceObjects,
     68             SkTSet<SkPDFObject*>* newResourceObjects,
     69             bool recursive) const;
     70 
     71     /**
     72      * Returns the name for the resource that will be generated by the resource
     73      * dict.
     74      *
     75      *  @param type  The type of resource being entered, like
     76      *    kPattern_ResourceType or kExtGState_ResourceType.
     77      *  @param key   The resource key, should be unique within its type.
     78      */
     79     static SkString getResourceName(SkPDFResourceType type, int key);
     80 
     81 private:
     82     /** Add the value to the dictionary with the given key.  Refs value.
     83      *  The relevant sub-dicts will be automatically generated, and the
     84      *  resource will be named by concatenating a type-specific prefix and
     85      *  the input key.
     86      *  The object will NOT be part of the resource list when requested later.
     87      *  @param type  The type of resource being entered.
     88      *  @param key   The resource key, should be unique within its type.
     89      *  @param value The resource itself.
     90      *  @return The value argument is returned.
     91      */
     92     SkPDFObject* insertResource(SkPDFResourceType type, int key,
     93                                 SkPDFObject* value);
     94 
     95     SkTSet<SkPDFObject*> fResources;
     96 
     97     SkTDArray<SkPDFDict*> fTypes;
     98     typedef SkPDFDict INHERITED;
     99 };
    100 
    101 #endif
    102