1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/pdf/SkPDFResourceDict.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkPDFResourceDict_DEFINED 1.12 +#define SkPDFResourceDict_DEFINED 1.13 + 1.14 +#include "SkPDFTypes.h" 1.15 +#include "SkTDArray.h" 1.16 +#include "SkTSet.h" 1.17 +#include "SkTypes.h" 1.18 + 1.19 +/** \class SkPDFResourceDict 1.20 + 1.21 + A resource dictionary, which maintains the relevant sub-dicts and 1.22 + allows generation of a list of referenced SkPDFObjects inserted with 1.23 + insertResourceAsRef. 1.24 +*/ 1.25 +class SkPDFResourceDict : public SkPDFDict { 1.26 +public: 1.27 + SK_DECLARE_INST_COUNT(SkPDFResourceDict) 1.28 + 1.29 + enum SkPDFResourceType{ 1.30 + kExtGState_ResourceType, 1.31 + kPattern_ResourceType, 1.32 + kXObject_ResourceType, 1.33 + kFont_ResourceType, 1.34 + // These additional types are defined by the spec, but not 1.35 + // currently used by Skia: ColorSpace, Shading, Properties 1.36 + kResourceTypeCount 1.37 + }; 1.38 + 1.39 + /** Create a PDF resource dictionary. 1.40 + * The full set of ProcSet entries is automatically created for backwards 1.41 + * compatibility, as recommended by the PDF spec. 1.42 + */ 1.43 + SkPDFResourceDict(); 1.44 + 1.45 + /** Add the value SkPDFObject as a reference to the resource dictionary 1.46 + * with the give type and key. 1.47 + * The relevant sub-dicts will be automatically generated, and the 1.48 + * resource will be named by concatenating a type-specific prefix and 1.49 + * the input key. 1.50 + * This object will be part of the resource list when requested later. 1.51 + * @param type The type of resource being entered, like 1.52 + * kPattern_ResourceType or kExtGState_ResourceType. 1.53 + * @param key The resource key, should be unique within its type. 1.54 + * @param value The resource itself. 1.55 + * @return The value argument is returned. 1.56 + */ 1.57 + SkPDFObject* insertResourceAsReference(SkPDFResourceType type, int key, 1.58 + SkPDFObject* value); 1.59 + 1.60 + /** 1.61 + * Gets resources inserted into this dictionary as a reference. 1.62 + * 1.63 + * @param knownResourceObjects Set containing currently known resources. 1.64 + * Resources in the dict and this set will not be added to the output. 1.65 + * @param newResourceObjects Output set to which non-preexisting resources 1.66 + * will be added. 1.67 + * @param recursive Whether or not to add resources of resources. 1.68 + */ 1.69 + void getReferencedResources( 1.70 + const SkTSet<SkPDFObject*>& knownResourceObjects, 1.71 + SkTSet<SkPDFObject*>* newResourceObjects, 1.72 + bool recursive) const; 1.73 + 1.74 + /** 1.75 + * Returns the name for the resource that will be generated by the resource 1.76 + * dict. 1.77 + * 1.78 + * @param type The type of resource being entered, like 1.79 + * kPattern_ResourceType or kExtGState_ResourceType. 1.80 + * @param key The resource key, should be unique within its type. 1.81 + */ 1.82 + static SkString getResourceName(SkPDFResourceType type, int key); 1.83 + 1.84 +private: 1.85 + /** Add the value to the dictionary with the given key. Refs value. 1.86 + * The relevant sub-dicts will be automatically generated, and the 1.87 + * resource will be named by concatenating a type-specific prefix and 1.88 + * the input key. 1.89 + * The object will NOT be part of the resource list when requested later. 1.90 + * @param type The type of resource being entered. 1.91 + * @param key The resource key, should be unique within its type. 1.92 + * @param value The resource itself. 1.93 + * @return The value argument is returned. 1.94 + */ 1.95 + SkPDFObject* insertResource(SkPDFResourceType type, int key, 1.96 + SkPDFObject* value); 1.97 + 1.98 + SkTSet<SkPDFObject*> fResources; 1.99 + 1.100 + SkTDArray<SkPDFDict*> fTypes; 1.101 + typedef SkPDFDict INHERITED; 1.102 +}; 1.103 + 1.104 +#endif