blob: c213bad0242807ebce62a470b2274c9071faff9d [file] [log] [blame]
edisonn@google.com29247622013-06-18 16:28:29 +00001#ifndef __DEFINED__SkPdfCIDFontDictionary
2#define __DEFINED__SkPdfCIDFontDictionary
3
edisonn@google.comb857a0c2013-06-25 20:45:40 +00004#include "SkPdfUtils.h"
edisonn@google.com29247622013-06-18 16:28:29 +00005#include "SkPdfEnums_autogen.h"
6#include "SkPdfArray_autogen.h"
7#include "SkPdfFontDictionary_autogen.h"
8
edisonn@google.comafe5e9e2013-06-19 17:42:17 +00009// Entries in a CIDFont dictionary
edisonn@google.com29247622013-06-18 16:28:29 +000010class SkPdfCIDFontDictionary : public SkPdfFontDictionary {
11public:
edisonn@google.com59543d32013-06-18 22:00:40 +000012 virtual SkPdfObjectType getType() const { return kCIDFontDictionary_SkPdfObjectType;}
13 virtual SkPdfObjectType getTypeEnd() const { return (SkPdfObjectType)(kCIDFontDictionary_SkPdfObjectType + 1);}
edisonn@google.com29247622013-06-18 16:28:29 +000014public:
15 virtual SkPdfCIDFontDictionary* asCIDFontDictionary() {return this;}
16 virtual const SkPdfCIDFontDictionary* asCIDFontDictionary() const {return this;}
17
18private:
edisonn@google.com29247622013-06-18 16:28:29 +000019 virtual SkPdfType0FontDictionary* asType0FontDictionary() {return NULL;}
20 virtual const SkPdfType0FontDictionary* asType0FontDictionary() const {return NULL;}
21
22 virtual SkPdfType1FontDictionary* asType1FontDictionary() {return NULL;}
23 virtual const SkPdfType1FontDictionary* asType1FontDictionary() const {return NULL;}
24
25 virtual SkPdfMultiMasterFontDictionary* asMultiMasterFontDictionary() {return NULL;}
26 virtual const SkPdfMultiMasterFontDictionary* asMultiMasterFontDictionary() const {return NULL;}
27
edisonn@google.comff278442013-06-21 21:03:15 +000028 virtual SkPdfTrueTypeFontDictionary* asTrueTypeFontDictionary() {return NULL;}
29 virtual const SkPdfTrueTypeFontDictionary* asTrueTypeFontDictionary() const {return NULL;}
edisonn@google.com29247622013-06-18 16:28:29 +000030
edisonn@google.comb857a0c2013-06-25 20:45:40 +000031 virtual SkPdfType3FontDictionary* asType3FontDictionary() {return NULL;}
32 virtual const SkPdfType3FontDictionary* asType3FontDictionary() const {return NULL;}
33
edisonn@google.com29247622013-06-18 16:28:29 +000034public:
35private:
36public:
37 SkPdfCIDFontDictionary(const PdfMemDocument* podofoDoc = NULL, const PdfObject* podofoObj = NULL) : SkPdfFontDictionary(podofoDoc, podofoObj) {}
38
edisonn@google.comb857a0c2013-06-25 20:45:40 +000039 SkPdfCIDFontDictionary(const SkPdfCIDFontDictionary& from) : SkPdfFontDictionary(from.fPodofoDoc, from.fPodofoObj) {}
40
edisonn@google.com29247622013-06-18 16:28:29 +000041 virtual bool valid() const {return true;}
42
43 SkPdfCIDFontDictionary& operator=(const SkPdfCIDFontDictionary& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPodofoObj; return *this;}
44
edisonn@google.comafe5e9e2013-06-19 17:42:17 +000045/** (Required) The type of PDF object that this dictionary describes; must be
46 * Font for a CIDFont dictionary.
47**/
48 bool has_Type() const {
49 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "Type", "", NULL));
50 }
51
edisonn@google.com29247622013-06-18 16:28:29 +000052 std::string Type() const {
53 std::string ret;
54 if (NameFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "Type", "", &ret)) return ret;
55 // TODO(edisonn): warn about missing required field, assert for known good pdfs
56 return "";
57 }
58
edisonn@google.comafe5e9e2013-06-19 17:42:17 +000059/** (Required) The type of CIDFont; CIDFontType0 or CIDFontType2.
60**/
61 bool has_Subtype() const {
62 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "Subtype", "", NULL));
63 }
64
edisonn@google.com29247622013-06-18 16:28:29 +000065 std::string Subtype() const {
66 std::string ret;
67 if (NameFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "Subtype", "", &ret)) return ret;
68 // TODO(edisonn): warn about missing required field, assert for known good pdfs
69 return "";
70 }
71
edisonn@google.comafe5e9e2013-06-19 17:42:17 +000072/** (Required) The PostScript name of the CIDFont. For Type 0 CIDFonts, this
73 * is usually the value of the CIDFontName entry in the CIDFont program. For
74 * Type 2 CIDFonts, it is derived the same way as for a simple TrueType font;
75 * see Section 5.5.2, "TrueType Fonts." In either case, the name can have a sub-
76 * set prefix if appropriate; see Section 5.5.3, "Font Subsets."
77**/
78 bool has_BaseFont() const {
79 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "BaseFont", "", NULL));
80 }
81
edisonn@google.com29247622013-06-18 16:28:29 +000082 std::string BaseFont() const {
83 std::string ret;
84 if (NameFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "BaseFont", "", &ret)) return ret;
85 // TODO(edisonn): warn about missing required field, assert for known good pdfs
86 return "";
87 }
88
edisonn@google.comafe5e9e2013-06-19 17:42:17 +000089/** (Required) A dictionary containing entries that define the character collec-
90 * tion of the CIDFont. See Table 5.12 on page 337.
91**/
92 bool has_CIDSystemInfo() const {
93 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "CIDSystemInfo", "", NULL));
94 }
95
edisonn@google.com29247622013-06-18 16:28:29 +000096 SkPdfDictionary* CIDSystemInfo() const {
97 SkPdfDictionary* ret;
98 if (DictionaryFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "CIDSystemInfo", "", &ret)) return ret;
99 // TODO(edisonn): warn about missing required field, assert for known good pdfs
100 return NULL;
101 }
102
edisonn@google.comafe5e9e2013-06-19 17:42:17 +0000103/** (Required; must be an indirect reference) A font descriptor describing the
104 * CIDFont's default metrics other than its glyph widths (see Section 5.7,
105 * "Font Descriptors").
106**/
107 bool has_FontDescriptor() const {
108 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "FontDescriptor", "", NULL));
109 }
110
edisonn@google.com29247622013-06-18 16:28:29 +0000111 SkPdfDictionary* FontDescriptor() const {
112 SkPdfDictionary* ret;
113 if (DictionaryFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "FontDescriptor", "", &ret)) return ret;
114 // TODO(edisonn): warn about missing required field, assert for known good pdfs
115 return NULL;
116 }
117
edisonn@google.comafe5e9e2013-06-19 17:42:17 +0000118/** (Optional) The default width for glyphs in the CIDFont (see "Glyph Met-
119 * rics in CIDFonts" on page 340). Default value: 1000.
120**/
121 bool has_DW() const {
122 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "DW", "", NULL));
123 }
124
edisonn@google.com29247622013-06-18 16:28:29 +0000125 long DW() const {
126 long ret;
127 if (LongFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "DW", "", &ret)) return ret;
128 // TODO(edisonn): warn about missing required field, assert for known good pdfs
129 return 0;
130 }
131
edisonn@google.comafe5e9e2013-06-19 17:42:17 +0000132/** (Optional) A description of the widths for the glyphs in the CIDFont. The
133 * array's elements have a variable format that can specify individual widths
134 * for consecutive CIDs or one width for a range of CIDs (see "Glyph Metrics
135 * in CIDFonts" on page 340). Default value: none (the DW value is used for
136 * all glyphs).
137**/
138 bool has_W() const {
139 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "W", "", NULL));
140 }
141
edisonn@google.comb857a0c2013-06-25 20:45:40 +0000142 SkPdfArray* W() const {
143 SkPdfArray* ret;
edisonn@google.com29247622013-06-18 16:28:29 +0000144 if (ArrayFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "W", "", &ret)) return ret;
145 // TODO(edisonn): warn about missing required field, assert for known good pdfs
edisonn@google.comb857a0c2013-06-25 20:45:40 +0000146 return NULL;
edisonn@google.com29247622013-06-18 16:28:29 +0000147 }
148
edisonn@google.comafe5e9e2013-06-19 17:42:17 +0000149/** (Optional; applies only to CIDFonts used for vertical writing) An array of two
150 * numbers specifying the default metrics for vertical writing (see "Glyph
151 * Metrics in CIDFonts" on page 340). Default value: [880 -1000].
152**/
153 bool has_DW2() const {
154 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "DW2", "", NULL));
155 }
156
edisonn@google.comb857a0c2013-06-25 20:45:40 +0000157 SkPdfArray* DW2() const {
158 SkPdfArray* ret;
edisonn@google.com29247622013-06-18 16:28:29 +0000159 if (ArrayFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "DW2", "", &ret)) return ret;
160 // TODO(edisonn): warn about missing required field, assert for known good pdfs
edisonn@google.comb857a0c2013-06-25 20:45:40 +0000161 return NULL;
edisonn@google.com29247622013-06-18 16:28:29 +0000162 }
163
edisonn@google.comafe5e9e2013-06-19 17:42:17 +0000164/** (Optional; applies only to CIDFonts used for vertical writing) A description of
165 * the metrics for vertical writing for the glyphs in the CIDFont (see "Glyph
166 * Metrics in CIDFonts" on page 340). Default value: none (the DW2 value is
167 * used for all glyphs).
168**/
169 bool has_W2() const {
170 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "W2", "", NULL));
171 }
172
edisonn@google.comb857a0c2013-06-25 20:45:40 +0000173 SkPdfArray* W2() const {
174 SkPdfArray* ret;
edisonn@google.com29247622013-06-18 16:28:29 +0000175 if (ArrayFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "W2", "", &ret)) return ret;
176 // TODO(edisonn): warn about missing required field, assert for known good pdfs
edisonn@google.comb857a0c2013-06-25 20:45:40 +0000177 return NULL;
edisonn@google.com29247622013-06-18 16:28:29 +0000178 }
179
edisonn@google.comafe5e9e2013-06-19 17:42:17 +0000180/** (Optional; Type 2 CIDFonts only) A specification of the mapping from CIDs
181 * to glyph indices. If the value is a stream, the bytes in the stream contain the
182 * mapping from CIDs to glyph indices: the glyph index for a particular CID
183 * value c is a 2-byte value stored in bytes 2 x c and 2 x c + 1, where the first
184 * byte is the high-order byte. If the value of CIDToGIDMap is a name, it must
185 * be Identity, indicating that the mapping between CIDs and glyph indices is
186 * the identity mapping. Default value: Identity.
187 * This entry may appear only in a Type 2 CIDFont whose associated True-
188 * Type font program is embedded in the PDF file (see the next section).
189**/
190 bool has_CIDToGIDMap() const {
191 return (ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "CIDToGIDMap", "", NULL));
192 }
193
edisonn@google.com29247622013-06-18 16:28:29 +0000194 bool isCIDToGIDMapAStream() const {
195 SkPdfObject* ret = NULL;
196 if (!ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "CIDToGIDMap", "", &ret)) return false;
197 return ret->podofo()->HasStream();
198 }
199
edisonn@google.comff278442013-06-21 21:03:15 +0000200 SkPdfStream* getCIDToGIDMapAsStream() const {
201 SkPdfStream* ret = NULL;
edisonn@google.com29247622013-06-18 16:28:29 +0000202 if (StreamFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "CIDToGIDMap", "", &ret)) return ret;
203 // TODO(edisonn): warn about missing required field, assert for known good pdfs
edisonn@google.comff278442013-06-21 21:03:15 +0000204 return NULL;
edisonn@google.com29247622013-06-18 16:28:29 +0000205 }
206
207 bool isCIDToGIDMapAName() const {
208 SkPdfObject* ret = NULL;
209 if (!ObjectFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "CIDToGIDMap", "", &ret)) return false;
210 return ret->podofo()->GetDataType() == ePdfDataType_Name;
211 }
212
213 std::string getCIDToGIDMapAsName() const {
214 std::string ret = "";
215 if (NameFromDictionary(fPodofoDoc, fPodofoObj->GetDictionary(), "CIDToGIDMap", "", &ret)) return ret;
216 // TODO(edisonn): warn about missing required field, assert for known good pdfs
217 return "";
218 }
219
220};
221
222#endif // __DEFINED__SkPdfCIDFontDictionary