Home | History | Annotate | Download | only in fpdfapi
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_
      8 #define CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_
      9 
     10 #include <map>
     11 
     12 #include "core/include/fxcrt/fx_system.h"
     13 #include "core/include/fxge/fx_font.h"
     14 #include "fpdf_parser.h"
     15 
     16 class CFX_CTTGSUBTable;
     17 class CFX_DIBitmap;
     18 class CFX_Font;
     19 class CFX_SubstFont;
     20 class CPDF_CID2UnicodeMap;
     21 class CPDF_CIDFont;
     22 class CPDF_CMap;
     23 class CPDF_Color;
     24 class CPDF_ColorSpace;
     25 class CPDF_Face;
     26 class CPDF_FontEncoding;
     27 class CPDF_Form;
     28 class CPDF_Function;
     29 class CPDF_Image;
     30 class CPDF_ImageObject;
     31 class CPDF_Page;
     32 class CPDF_Pattern;
     33 class CPDF_RenderContext;
     34 class CPDF_ShadingPattern;
     35 class CPDF_TilingPattern;
     36 class CPDF_ToUnicodeMap;
     37 class CPDF_TrueTypeFont;
     38 class CPDF_Type1Font;
     39 class CPDF_Type3Font;
     40 typedef struct FT_FaceRec_* FXFT_Face;
     41 
     42 FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR* name);
     43 CFX_ByteString PDF_AdobeNameFromUnicode(FX_WCHAR unicode);
     44 const FX_CHAR* FCS_GetAltStr(FX_WCHAR unicode);
     45 const FX_CHAR* PDF_CharNameFromPredefinedCharSet(int encoding,
     46                                                  uint8_t charcode);
     47 
     48 FX_WCHAR FT_UnicodeFromCharCode(int encoding, FX_DWORD charcode);
     49 FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode);
     50 const FX_WORD* PDF_UnicodesForPredefinedCharSet(int encoding);
     51 const FX_CHAR* GetAdobeCharName(int iBaseEncoding,
     52                                 const CFX_ByteString* pCharNames,
     53                                 int charcode);
     54 
     55 template <class T>
     56 class CPDF_CountedObject {
     57  public:
     58   explicit CPDF_CountedObject(T* ptr) : m_nCount(1), m_pObj(ptr) {}
     59   void reset(T* ptr) {  // CAUTION: tosses prior ref counts.
     60     m_nCount = 1;
     61     m_pObj = ptr;
     62   }
     63   void clear() {  // Now you're all weak ptrs ...
     64     delete m_pObj;
     65     m_pObj = nullptr;
     66   }
     67   T* get() const { return m_pObj; }
     68   T* AddRef() {
     69     FXSYS_assert(m_pObj);
     70     ++m_nCount;
     71     return m_pObj;
     72   }
     73   void RemoveRef() {
     74     if (m_nCount)
     75       --m_nCount;
     76   }
     77   size_t use_count() const { return m_nCount; }
     78 
     79  protected:
     80   size_t m_nCount;
     81   T* m_pObj;
     82 };
     83 using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace>;
     84 using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>;
     85 #define PDFFONT_TYPE1 1
     86 #define PDFFONT_TRUETYPE 2
     87 #define PDFFONT_TYPE3 3
     88 #define PDFFONT_CIDFONT 4
     89 #define PDFFONT_FIXEDPITCH 1
     90 #define PDFFONT_SERIF 2
     91 #define PDFFONT_SYMBOLIC 4
     92 #define PDFFONT_SCRIPT 8
     93 #define PDFFONT_NONSYMBOLIC 32
     94 #define PDFFONT_ITALIC 64
     95 #define PDFFONT_ALLCAP 0x10000
     96 #define PDFFONT_SMALLCAP 0x20000
     97 #define PDFFONT_FORCEBOLD 0x40000
     98 #define PDFFONT_USEEXTERNATTR 0x80000
     99 class CPDF_Font {
    100  public:
    101   static CPDF_Font* CreateFontF(CPDF_Document* pDoc,
    102                                 CPDF_Dictionary* pFontDict);
    103   static CPDF_Font* GetStockFont(CPDF_Document* pDoc,
    104                                  const CFX_ByteStringC& fontname);
    105   static const FX_DWORD kInvalidCharCode = static_cast<FX_DWORD>(-1);
    106 
    107   virtual ~CPDF_Font();
    108 
    109   bool IsFontType(int fonttype) const { return fonttype == m_FontType; }
    110   int GetFontType() const { return m_FontType; }
    111 
    112   CFX_ByteString GetFontTypeName() const;
    113 
    114   const CFX_ByteString& GetBaseFont() const { return m_BaseFont; }
    115 
    116   const CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); }
    117 
    118   FX_DWORD GetFlags() const { return m_Flags; }
    119 
    120   virtual FX_BOOL IsVertWriting() const;
    121 
    122   CPDF_Type1Font* GetType1Font() const {
    123     return m_FontType == PDFFONT_TYPE1 ? (CPDF_Type1Font*)(void*)this : NULL;
    124   }
    125 
    126   CPDF_TrueTypeFont* GetTrueTypeFont() const {
    127     return m_FontType == PDFFONT_TRUETYPE ? (CPDF_TrueTypeFont*)(void*)this
    128                                           : NULL;
    129   }
    130 
    131   CPDF_CIDFont* GetCIDFont() const {
    132     return (m_FontType == PDFFONT_CIDFONT) ? (CPDF_CIDFont*)(void*)this : NULL;
    133   }
    134 
    135   CPDF_Type3Font* GetType3Font() const {
    136     return (m_FontType == PDFFONT_TYPE3) ? (CPDF_Type3Font*)(void*)this : NULL;
    137   }
    138 
    139   FX_BOOL IsEmbedded() const {
    140     return m_FontType == PDFFONT_TYPE3 || m_pFontFile != NULL;
    141   }
    142 
    143   virtual FX_BOOL IsUnicodeCompatible() const { return FALSE; }
    144 
    145   CPDF_StreamAcc* GetFontFile() const { return m_pFontFile; }
    146 
    147   CPDF_Dictionary* GetFontDict() const { return m_pFontDict; }
    148 
    149   FX_BOOL IsStandardFont() const;
    150 
    151   FXFT_Face GetFace() const { return m_Font.GetFace(); }
    152 
    153   virtual FX_DWORD GetNextChar(const FX_CHAR* pString,
    154                                int nStrLen,
    155                                int& offset) const {
    156     if (offset < 0 || nStrLen < 1) {
    157       return 0;
    158     }
    159     uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1];
    160     return static_cast<FX_DWORD>(ch);
    161   }
    162 
    163   virtual int CountChar(const FX_CHAR* pString, int size) const { return size; }
    164 
    165   void AppendChar(CFX_ByteString& str, FX_DWORD charcode) const;
    166 
    167   virtual int AppendChar(FX_CHAR* buf, FX_DWORD charcode) const {
    168     *buf = (FX_CHAR)charcode;
    169     return 1;
    170   }
    171 
    172   virtual int GetCharSize(FX_DWORD charcode) const { return 1; }
    173 
    174   virtual int GlyphFromCharCode(FX_DWORD charcode,
    175                                 FX_BOOL* pVertGlyph = NULL) = 0;
    176   virtual int GlyphFromCharCodeExt(FX_DWORD charcode) {
    177     return GlyphFromCharCode(charcode);
    178   }
    179 
    180   CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const;
    181 
    182   FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const;
    183 
    184   CFX_CharMap* GetCharMap() { return m_pCharMap; }
    185 
    186   CFX_ByteString EncodeString(const CFX_WideString& str) const;
    187 
    188   CFX_WideString DecodeString(const CFX_ByteString& str) const;
    189 
    190   void GetFontBBox(FX_RECT& rect) const { rect = m_FontBBox; }
    191 
    192   int GetTypeAscent() const { return m_Ascent; }
    193 
    194   int GetTypeDescent() const { return m_Descent; }
    195 
    196   int GetItalicAngle() const { return m_ItalicAngle; }
    197 
    198   int GetStemV() const { return m_StemV; }
    199 
    200   int GetStringWidth(const FX_CHAR* pString, int size);
    201 
    202   virtual int GetCharWidthF(FX_DWORD charcode, int level = 0) = 0;
    203 
    204   virtual int GetCharTypeWidth(FX_DWORD charcode);
    205 
    206   virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) = 0;
    207 
    208   CPDF_Document* m_pDocument;
    209 
    210   class CFX_PathData* LoadGlyphPath(FX_DWORD charcode, int dest_width = 0);
    211 
    212   CFX_Font m_Font;
    213 
    214  protected:
    215   explicit CPDF_Font(int fonttype);
    216 
    217   FX_BOOL Initialize();
    218 
    219   FX_BOOL Load();
    220 
    221   virtual FX_BOOL _Load() = 0;
    222 
    223   virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const = 0;
    224 
    225   virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const = 0;
    226 
    227   void LoadUnicodeMap();
    228 
    229   void LoadPDFEncoding(CPDF_Object* pEncoding,
    230                        int& iBaseEncoding,
    231                        CFX_ByteString*& pCharNames,
    232                        FX_BOOL bEmbedded,
    233                        FX_BOOL bTrueType);
    234 
    235   void LoadFontDescriptor(CPDF_Dictionary*);
    236 
    237   void LoadCharWidths(FX_WORD* pWidths);
    238 
    239   void CheckFontMetrics();
    240 
    241   CFX_CharMap* m_pCharMap;
    242 
    243   CFX_ByteString m_BaseFont;
    244 
    245   CPDF_StreamAcc* m_pFontFile;
    246 
    247   CPDF_Dictionary* m_pFontDict;
    248 
    249   CPDF_ToUnicodeMap* m_pToUnicodeMap;
    250 
    251   FX_BOOL m_bToUnicodeLoaded;
    252 
    253   int m_Flags;
    254 
    255   FX_RECT m_FontBBox;
    256 
    257   int m_StemV;
    258 
    259   int m_Ascent;
    260 
    261   int m_Descent;
    262 
    263   int m_ItalicAngle;
    264 
    265  private:
    266   const int m_FontType;
    267 };
    268 #define PDFFONT_ENCODING_BUILTIN 0
    269 #define PDFFONT_ENCODING_WINANSI 1
    270 #define PDFFONT_ENCODING_MACROMAN 2
    271 #define PDFFONT_ENCODING_MACEXPERT 3
    272 #define PDFFONT_ENCODING_STANDARD 4
    273 #define PDFFONT_ENCODING_ADOBE_SYMBOL 5
    274 #define PDFFONT_ENCODING_ZAPFDINGBATS 6
    275 #define PDFFONT_ENCODING_PDFDOC 7
    276 #define PDFFONT_ENCODING_MS_SYMBOL 8
    277 #define PDFFONT_ENCODING_UNICODE 9
    278 class CPDF_FontEncoding {
    279  public:
    280   CPDF_FontEncoding();
    281 
    282   CPDF_FontEncoding(int PredefinedEncoding);
    283 
    284   void LoadEncoding(CPDF_Object* pEncoding);
    285 
    286   FX_BOOL IsIdentical(CPDF_FontEncoding* pAnother) const;
    287 
    288   FX_WCHAR UnicodeFromCharCode(uint8_t charcode) const {
    289     return m_Unicodes[charcode];
    290   }
    291 
    292   int CharCodeFromUnicode(FX_WCHAR unicode) const;
    293 
    294   void SetUnicode(uint8_t charcode, FX_WCHAR unicode) {
    295     m_Unicodes[charcode] = unicode;
    296   }
    297 
    298   CPDF_Object* Realize();
    299 
    300  public:
    301   FX_WCHAR m_Unicodes[256];
    302 };
    303 
    304 class CPDF_SimpleFont : public CPDF_Font {
    305  public:
    306   explicit CPDF_SimpleFont(int fonttype);
    307   ~CPDF_SimpleFont() override;
    308 
    309   CPDF_FontEncoding* GetEncoding() { return &m_Encoding; }
    310   int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
    311   void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
    312   int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override;
    313   FX_BOOL IsUnicodeCompatible() const override;
    314 
    315  protected:
    316   FX_BOOL LoadCommon();
    317 
    318   void LoadSubstFont();
    319 
    320   void LoadFaceMetrics();
    321 
    322   virtual void LoadGlyphMap() = 0;
    323 
    324   FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override {
    325     return m_Encoding.UnicodeFromCharCode((uint8_t)charcode);
    326   }
    327 
    328   FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override {
    329     return m_Encoding.CharCodeFromUnicode(Unicode);
    330   }
    331 
    332   void LoadCharMetrics(int charcode);
    333 
    334   CPDF_FontEncoding m_Encoding;
    335   FX_WORD m_GlyphIndex[256];
    336   FX_WORD m_ExtGID[256];
    337   CFX_ByteString* m_pCharNames;
    338   int m_BaseEncoding;
    339   FX_WORD m_CharWidth[256];
    340   FX_SMALL_RECT m_CharBBox[256];
    341   FX_BOOL m_bUseFontWidth;
    342 };
    343 
    344 class CPDF_Type1Font : public CPDF_SimpleFont {
    345  public:
    346   CPDF_Type1Font();
    347 
    348   int GetBase14Font() { return m_Base14Font; }
    349 
    350  protected:
    351   // CPDF_SimpleFont:
    352   int GlyphFromCharCodeExt(FX_DWORD charcode) override;
    353   FX_BOOL _Load() override;
    354   void LoadGlyphMap() override;
    355 
    356   int m_Base14Font;
    357 };
    358 class CPDF_TrueTypeFont : public CPDF_SimpleFont {
    359  public:
    360   CPDF_TrueTypeFont();
    361 
    362  protected:
    363   // CPDF_SimpleFont:
    364   FX_BOOL _Load() override;
    365   void LoadGlyphMap() override;
    366 };
    367 
    368 class CPDF_Type3Char {
    369  public:
    370   // Takes ownership of |pForm|.
    371   explicit CPDF_Type3Char(CPDF_Form* pForm);
    372   ~CPDF_Type3Char();
    373 
    374   FX_BOOL LoadBitmap(CPDF_RenderContext* pContext);
    375 
    376   CPDF_Form* m_pForm;
    377   CFX_DIBitmap* m_pBitmap;
    378   FX_BOOL m_bColored;
    379   int m_Width;
    380   CFX_Matrix m_ImageMatrix;
    381   FX_RECT m_BBox;
    382 };
    383 
    384 class CPDF_Type3Font : public CPDF_SimpleFont {
    385  public:
    386   CPDF_Type3Font();
    387   ~CPDF_Type3Font() override;
    388 
    389   void SetPageResources(CPDF_Dictionary* pResources) {
    390     m_pPageResources = pResources;
    391   }
    392   CPDF_Type3Char* LoadChar(FX_DWORD charcode, int level = 0);
    393   int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
    394   int GetCharTypeWidth(FX_DWORD charcode) override {
    395     return GetCharWidthF(charcode);
    396   }
    397   void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
    398   CFX_Matrix& GetFontMatrix() { return m_FontMatrix; }
    399   void CheckType3FontMetrics();
    400 
    401  protected:
    402   CFX_Matrix m_FontMatrix;
    403 
    404  private:
    405   FX_BOOL _Load() override;
    406   void LoadGlyphMap() override {}
    407 
    408   int m_CharWidthL[256];
    409   CPDF_Dictionary* m_pCharProcs;
    410   CPDF_Dictionary* m_pPageResources;
    411   CPDF_Dictionary* m_pFontResources;
    412   std::map<FX_DWORD, CPDF_Type3Char*> m_CacheMap;
    413 };
    414 
    415 enum CIDSet {
    416   CIDSET_UNKNOWN,
    417   CIDSET_GB1,
    418   CIDSET_CNS1,
    419   CIDSET_JAPAN1,
    420   CIDSET_KOREA1,
    421   CIDSET_UNICODE,
    422   CIDSET_NUM_SETS
    423 };
    424 
    425 class CPDF_CIDFont : public CPDF_Font {
    426  public:
    427   CPDF_CIDFont();
    428 
    429   ~CPDF_CIDFont() override;
    430 
    431   static FX_FLOAT CIDTransformToFloat(uint8_t ch);
    432 
    433   // CPDF_Font:
    434   int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override;
    435   int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
    436   void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
    437   FX_DWORD GetNextChar(const FX_CHAR* pString,
    438                        int nStrLen,
    439                        int& offset) const override;
    440   int CountChar(const FX_CHAR* pString, int size) const override;
    441   int AppendChar(FX_CHAR* str, FX_DWORD charcode) const override;
    442   int GetCharSize(FX_DWORD charcode) const override;
    443   FX_BOOL IsVertWriting() const override;
    444   FX_BOOL IsUnicodeCompatible() const override;
    445   FX_BOOL _Load() override;
    446   FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override;
    447   FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override;
    448 
    449   FX_BOOL LoadGB2312();
    450   FX_WORD CIDFromCharCode(FX_DWORD charcode) const;
    451   FX_BOOL IsTrueType() const { return !m_bType1; }
    452   const uint8_t* GetCIDTransform(FX_WORD CID) const;
    453   short GetVertWidth(FX_WORD CID) const;
    454   void GetVertOrigin(FX_WORD CID, short& vx, short& vy) const;
    455   virtual FX_BOOL IsFontStyleFromCharCode(FX_DWORD charcode) const;
    456 
    457  protected:
    458   friend class CPDF_Font;
    459 
    460   int GetGlyphIndex(FX_DWORD unicodeb, FX_BOOL* pVertGlyph);
    461   void LoadMetricsArray(CPDF_Array* pArray,
    462                         CFX_DWordArray& result,
    463                         int nElements);
    464   void LoadSubstFont();
    465 
    466   CPDF_CMap* m_pCMap;
    467   CPDF_CMap* m_pAllocatedCMap;
    468   CPDF_CID2UnicodeMap* m_pCID2UnicodeMap;
    469   CIDSet m_Charset;
    470   FX_BOOL m_bType1;
    471   CPDF_StreamAcc* m_pCIDToGIDMap;
    472   FX_BOOL m_bCIDIsGID;
    473   FX_WORD m_DefaultWidth;
    474   FX_WORD* m_pAnsiWidths;
    475   FX_SMALL_RECT m_CharBBox[256];
    476   CFX_DWordArray m_WidthList;
    477   short m_DefaultVY;
    478   short m_DefaultW1;
    479   CFX_DWordArray m_VertMetrics;
    480   FX_BOOL m_bAdobeCourierStd;
    481   CFX_CTTGSUBTable* m_pTTGSUBTable;
    482 };
    483 
    484 #define PDFCS_DEVICEGRAY 1
    485 #define PDFCS_DEVICERGB 2
    486 #define PDFCS_DEVICECMYK 3
    487 #define PDFCS_CALGRAY 4
    488 #define PDFCS_CALRGB 5
    489 #define PDFCS_LAB 6
    490 #define PDFCS_ICCBASED 7
    491 #define PDFCS_SEPARATION 8
    492 #define PDFCS_DEVICEN 9
    493 #define PDFCS_INDEXED 10
    494 #define PDFCS_PATTERN 11
    495 
    496 class CPDF_ColorSpace {
    497  public:
    498   static CPDF_ColorSpace* GetStockCS(int Family);
    499 
    500   static CPDF_ColorSpace* Load(CPDF_Document* pDoc, CPDF_Object* pCSObj);
    501 
    502   void ReleaseCS();
    503 
    504   int GetBufSize() const;
    505 
    506   FX_FLOAT* CreateBuf();
    507 
    508   void GetDefaultColor(FX_FLOAT* buf) const;
    509 
    510   int CountComponents() const { return m_nComponents; }
    511 
    512   int GetFamily() const { return m_Family; }
    513 
    514   virtual void GetDefaultValue(int iComponent,
    515                                FX_FLOAT& value,
    516                                FX_FLOAT& min,
    517                                FX_FLOAT& max) const {
    518     value = 0;
    519     min = 0;
    520     max = 1.0f;
    521   }
    522 
    523   FX_BOOL sRGB() const;
    524 
    525   virtual FX_BOOL GetRGB(FX_FLOAT* pBuf,
    526                          FX_FLOAT& R,
    527                          FX_FLOAT& G,
    528                          FX_FLOAT& B) const = 0;
    529 
    530   virtual FX_BOOL SetRGB(FX_FLOAT* pBuf,
    531                          FX_FLOAT R,
    532                          FX_FLOAT G,
    533                          FX_FLOAT B) const {
    534     return FALSE;
    535   }
    536 
    537   FX_BOOL GetCMYK(FX_FLOAT* pBuf,
    538                   FX_FLOAT& c,
    539                   FX_FLOAT& m,
    540                   FX_FLOAT& y,
    541                   FX_FLOAT& k) const;
    542 
    543   FX_BOOL SetCMYK(FX_FLOAT* pBuf,
    544                   FX_FLOAT c,
    545                   FX_FLOAT m,
    546                   FX_FLOAT y,
    547                   FX_FLOAT k) const;
    548 
    549   virtual void TranslateImageLine(uint8_t* dest_buf,
    550                                   const uint8_t* src_buf,
    551                                   int pixels,
    552                                   int image_width,
    553                                   int image_height,
    554                                   FX_BOOL bTransMask = FALSE) const;
    555 
    556   CPDF_Array*& GetArray() { return m_pArray; }
    557 
    558   int GetMaxIndex() const;
    559 
    560   virtual CPDF_ColorSpace* GetBaseCS() const { return NULL; }
    561 
    562   virtual void EnableStdConversion(FX_BOOL bEnabled);
    563 
    564   CPDF_Document* const m_pDocument;
    565 
    566  protected:
    567   CPDF_ColorSpace(CPDF_Document* pDoc, int family, int nComponents)
    568       : m_pDocument(pDoc),
    569         m_Family(family),
    570         m_nComponents(nComponents),
    571         m_pArray(nullptr),
    572         m_dwStdConversion(0) {}
    573   virtual ~CPDF_ColorSpace() {}
    574   virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
    575     return TRUE;
    576   }
    577   virtual FX_BOOL v_GetCMYK(FX_FLOAT* pBuf,
    578                             FX_FLOAT& c,
    579                             FX_FLOAT& m,
    580                             FX_FLOAT& y,
    581                             FX_FLOAT& k) const {
    582     return FALSE;
    583   }
    584   virtual FX_BOOL v_SetCMYK(FX_FLOAT* pBuf,
    585                             FX_FLOAT c,
    586                             FX_FLOAT m,
    587                             FX_FLOAT y,
    588                             FX_FLOAT k) const {
    589     return FALSE;
    590   }
    591 
    592   int m_Family;
    593 
    594   int m_nComponents;
    595 
    596   CPDF_Array* m_pArray;
    597 
    598   FX_DWORD m_dwStdConversion;
    599 };
    600 class CPDF_Color {
    601  public:
    602   CPDF_Color() : m_pCS(NULL), m_pBuffer(NULL) {}
    603 
    604   CPDF_Color(int family);
    605 
    606   ~CPDF_Color();
    607 
    608   FX_BOOL IsNull() const { return !m_pBuffer; }
    609 
    610   FX_BOOL IsEqual(const CPDF_Color& other) const;
    611 
    612   FX_BOOL IsPattern() const {
    613     return m_pCS && m_pCS->GetFamily() == PDFCS_PATTERN;
    614   }
    615 
    616   void Copy(const CPDF_Color* pSrc);
    617 
    618   void SetColorSpace(CPDF_ColorSpace* pCS);
    619 
    620   void SetValue(FX_FLOAT* comp);
    621 
    622   void SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comp, int ncomps);
    623 
    624   FX_BOOL GetRGB(int& R, int& G, int& B) const;
    625 
    626   CPDF_Pattern* GetPattern() const;
    627 
    628   CPDF_ColorSpace* GetPatternCS() const;
    629 
    630   FX_FLOAT* GetPatternColor() const;
    631 
    632   CPDF_ColorSpace* m_pCS;
    633 
    634  protected:
    635   void ReleaseBuffer();
    636   void ReleaseColorSpace();
    637   FX_FLOAT* m_pBuffer;
    638 };
    639 
    640 class CPDF_Pattern {
    641  public:
    642   enum PatternType { TILING = 1, SHADING };
    643 
    644   virtual ~CPDF_Pattern();
    645 
    646   void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; }
    647 
    648   const PatternType m_PatternType;
    649   CPDF_Document* const m_pDocument;
    650   CPDF_Object* const m_pPatternObj;
    651   CFX_Matrix m_Pattern2Form;
    652   CFX_Matrix m_ParentMatrix;
    653 
    654  protected:
    655   CPDF_Pattern(PatternType type,
    656                CPDF_Document* pDoc,
    657                CPDF_Object* pObj,
    658                const CFX_Matrix* pParentMatrix);
    659 
    660   FX_BOOL m_bForceClear;
    661 };
    662 
    663 class CPDF_TilingPattern : public CPDF_Pattern {
    664  public:
    665   CPDF_TilingPattern(CPDF_Document* pDoc,
    666                      CPDF_Object* pPatternObj,
    667                      const CFX_Matrix* parentMatrix);
    668 
    669   ~CPDF_TilingPattern() override;
    670 
    671   FX_BOOL Load();
    672 
    673   FX_BOOL m_bColored;
    674 
    675   CFX_FloatRect m_BBox;
    676 
    677   FX_FLOAT m_XStep;
    678 
    679   FX_FLOAT m_YStep;
    680 
    681   CPDF_Form* m_pForm;
    682 };
    683 
    684 typedef enum {
    685   kInvalidShading = 0,
    686   kFunctionBasedShading = 1,
    687   kAxialShading = 2,
    688   kRadialShading = 3,
    689   kFreeFormGouraudTriangleMeshShading = 4,
    690   kLatticeFormGouraudTriangleMeshShading = 5,
    691   kCoonsPatchMeshShading = 6,
    692   kTensorProductPatchMeshShading = 7,
    693   kMaxShading = 8
    694 } ShadingType;
    695 
    696 class CPDF_ShadingPattern : public CPDF_Pattern {
    697  public:
    698   CPDF_ShadingPattern(CPDF_Document* pDoc,
    699                       CPDF_Object* pPatternObj,
    700                       FX_BOOL bShading,
    701                       const CFX_Matrix* parentMatrix);
    702 
    703   ~CPDF_ShadingPattern() override;
    704 
    705   bool IsMeshShading() const {
    706     return m_ShadingType == kFreeFormGouraudTriangleMeshShading ||
    707            m_ShadingType == kLatticeFormGouraudTriangleMeshShading ||
    708            m_ShadingType == kCoonsPatchMeshShading ||
    709            m_ShadingType == kTensorProductPatchMeshShading;
    710   }
    711   FX_BOOL Load();
    712 
    713   ShadingType m_ShadingType;
    714   FX_BOOL m_bShadingObj;
    715   CPDF_Object* m_pShadingObj;
    716 
    717   // Still keep |m_pCS| as some CPDF_ColorSpace (name object) are not managed
    718   // as counted objects. Refer to CPDF_DocPageData::GetColorSpace.
    719   CPDF_ColorSpace* m_pCS;
    720 
    721   CPDF_CountedColorSpace* m_pCountedCS;
    722   CPDF_Function* m_pFunctions[4];
    723   int m_nFuncs;
    724 };
    725 
    726 struct CPDF_MeshVertex {
    727   FX_FLOAT x, y;
    728   FX_FLOAT r, g, b;
    729 };
    730 class CPDF_MeshStream {
    731  public:
    732   FX_BOOL Load(CPDF_Stream* pShadingStream,
    733                CPDF_Function** pFuncs,
    734                int nFuncs,
    735                CPDF_ColorSpace* pCS);
    736 
    737   FX_DWORD GetFlag();
    738 
    739   void GetCoords(FX_FLOAT& x, FX_FLOAT& y);
    740 
    741   void GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b);
    742 
    743   FX_DWORD GetVertex(CPDF_MeshVertex& vertex, CFX_Matrix* pObject2Bitmap);
    744 
    745   FX_BOOL GetVertexRow(CPDF_MeshVertex* vertex,
    746                        int count,
    747                        CFX_Matrix* pObject2Bitmap);
    748   CPDF_Function** m_pFuncs;
    749   CPDF_ColorSpace* m_pCS;
    750   FX_DWORD m_nFuncs, m_nCoordBits, m_nCompBits, m_nFlagBits, m_nComps;
    751   FX_DWORD m_CoordMax, m_CompMax;
    752   FX_FLOAT m_xmin, m_xmax, m_ymin, m_ymax;
    753   FX_FLOAT m_ColorMin[8], m_ColorMax[8];
    754   CPDF_StreamAcc m_Stream;
    755   CFX_BitStream m_BitStream;
    756 };
    757 #define PDF_IMAGE_NO_COMPRESS 0x0000
    758 #define PDF_IMAGE_LOSSY_COMPRESS 0x0001
    759 #define PDF_IMAGE_LOSSLESS_COMPRESS 0x0002
    760 #define PDF_IMAGE_MASK_LOSSY_COMPRESS 0x0004
    761 #define PDF_IMAGE_MASK_LOSSLESS_COMPRESS 0x0008
    762 class CPDF_ImageSetParam {
    763  public:
    764   CPDF_ImageSetParam() : pMatteColor(NULL), nQuality(80) {}
    765   FX_ARGB* pMatteColor;
    766   int32_t nQuality;
    767 };
    768 class CPDF_Image {
    769  public:
    770   CPDF_Image(CPDF_Document* pDoc);
    771 
    772   ~CPDF_Image();
    773 
    774   FX_BOOL LoadImageF(CPDF_Stream* pImageStream, FX_BOOL bInline);
    775 
    776   void Release();
    777 
    778   CPDF_Image* Clone();
    779 
    780   FX_BOOL IsInline() { return m_bInline; }
    781 
    782   void SetInlineDict(CPDF_Dictionary* pDict) { m_pInlineDict = pDict; }
    783 
    784   CPDF_Dictionary* GetInlineDict() const { return m_pInlineDict; }
    785 
    786   CPDF_Stream* GetStream() const { return m_pStream; }
    787 
    788   CPDF_Dictionary* GetDict() const {
    789     return m_pStream ? m_pStream->GetDict() : NULL;
    790   }
    791 
    792   CPDF_Dictionary* GetOC() const { return m_pOC; }
    793 
    794   CPDF_Document* GetDocument() const { return m_pDocument; }
    795 
    796   int32_t GetPixelHeight() const { return m_Height; }
    797 
    798   int32_t GetPixelWidth() const { return m_Width; }
    799 
    800   FX_BOOL IsMask() const { return m_bIsMask; }
    801 
    802   FX_BOOL IsInterpol() const { return m_bInterpolate; }
    803 
    804   CFX_DIBSource* LoadDIBSource(CFX_DIBSource** ppMask = NULL,
    805                                FX_DWORD* pMatteColor = NULL,
    806                                FX_BOOL bStdCS = FALSE,
    807                                FX_DWORD GroupFamily = 0,
    808                                FX_BOOL bLoadMask = FALSE) const;
    809 
    810   void SetImage(const CFX_DIBitmap* pDIBitmap,
    811                 int32_t iCompress,
    812                 IFX_FileWrite* pFileWrite = NULL,
    813                 IFX_FileRead* pFileRead = NULL,
    814                 const CFX_DIBitmap* pMask = NULL,
    815                 const CPDF_ImageSetParam* pParam = NULL);
    816 
    817   void SetJpegImage(uint8_t* pImageData, FX_DWORD size);
    818 
    819   void SetJpegImage(IFX_FileRead* pFile);
    820 
    821   void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap);
    822 
    823  public:
    824   FX_BOOL StartLoadDIBSource(CPDF_Dictionary* pFormResource,
    825                              CPDF_Dictionary* pPageResource,
    826                              FX_BOOL bStdCS = FALSE,
    827                              FX_DWORD GroupFamily = 0,
    828                              FX_BOOL bLoadMask = FALSE);
    829   FX_BOOL Continue(IFX_Pause* pPause);
    830   CFX_DIBSource* DetachBitmap();
    831   CFX_DIBSource* DetachMask();
    832   CFX_DIBSource* m_pDIBSource;
    833   CFX_DIBSource* m_pMask;
    834   FX_DWORD m_MatteColor;
    835 
    836  private:
    837   CPDF_Stream* m_pStream;
    838   FX_BOOL m_bInline;
    839   CPDF_Dictionary* m_pInlineDict;
    840 
    841   int32_t m_Height;
    842 
    843   int32_t m_Width;
    844 
    845   FX_BOOL m_bIsMask;
    846 
    847   FX_BOOL m_bInterpolate;
    848 
    849   CPDF_Document* m_pDocument;
    850 
    851   CPDF_Dictionary* m_pOC;
    852   CPDF_Dictionary* InitJPEG(uint8_t* pData, FX_DWORD size);
    853 };
    854 
    855 #endif  // CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_
    856