// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
+
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _FPDF_RESOURCE_
-#define _FPDF_RESOURCE_
-#ifndef _FPDF_PARSER_
-#include "fpdf_parser.h"
-#endif
-#ifndef _FX_FONT_H_
+#ifndef CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_
+#define CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_
+
+#include "../fxcrt/fx_system.h"
#include "../fxge/fx_font.h"
-#endif
-class CPDF_Font;
-class CPDF_Type1Font;
-class CPDF_TrueTypeFont;
+#include "fpdf_parser.h"
+
+class CFX_CTTGSUBTable;
+class CFX_DIBitmap;
+class CFX_Font;
+class CFX_SubstFont;
+class CPDF_CID2UnicodeMap;
class CPDF_CIDFont;
-class CPDF_Type3Font;
-class CPDF_FontEncoding;
class CPDF_CMap;
-class CPDF_CID2UnicodeMap;
-class CPDF_ColorSpace;
class CPDF_Color;
+class CPDF_ColorSpace;
+class CPDF_Face;
+class CPDF_Font;
+class CPDF_FontEncoding;
+class CPDF_Form;
class CPDF_Function;
+class CPDF_Image;
+class CPDF_ImageObject;
+class CPDF_Page;
class CPDF_Pattern;
-class CPDF_TilingPattern;
+class CPDF_RenderContext;
class CPDF_ShadingPattern;
-class CPDF_Image;
-class CPDF_Face;
+class CPDF_TilingPattern;
class CPDF_ToUnicodeMap;
-class CFX_SubstFont;
-class CFX_Font;
-class CPDF_RenderContext;
-class CPDF_Form;
-class CPDF_ImageObject;
-class CFX_DIBitmap;
+class CPDF_TrueTypeFont;
+class CPDF_Type1Font;
+class CPDF_Type3Font;
typedef struct FT_FaceRec_* FXFT_Face;
-class CFX_CTTGSUBTable;
-class CPDF_Page;
+
+template <class T> class CPDF_CountedObject
+{
+public:
+ explicit CPDF_CountedObject(T* ptr) : m_nCount(1), m_pObj(ptr) { }
+ void reset(T* ptr) { // CAUTION: tosses prior ref counts.
+ m_nCount = 1;
+ m_pObj = ptr;
+ }
+ void clear() { // Now you're all weak ptrs ...
+ delete m_pObj;
+ m_pObj = nullptr;
+ }
+ T* get() const { return m_pObj; }
+ T* AddRef() { FXSYS_assert(m_pObj); ++m_nCount; return m_pObj; }
+ void RemoveRef() { if (m_nCount) --m_nCount; }
+ size_t use_count() const { return m_nCount; }
+
+protected:
+ size_t m_nCount;
+ T* m_pObj;
+};
+using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace>;
+using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>;
+
#define PDFFONT_TYPE1 1
#define PDFFONT_TRUETYPE 2
#define PDFFONT_TYPE3 3
#define PDFFONT_USEEXTERNATTR 0x80000
FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR* name);
CFX_ByteString PDF_AdobeNameFromUnicode(FX_WCHAR unicode);
-class CPDF_Font : public CFX_Object
+class CPDF_Font
{
public:
-
static CPDF_Font* CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict);
-
- static CPDF_Font* GetStockFont(CPDF_Document* pDoc, FX_BSTR fontname);
+ static CPDF_Font* GetStockFont(CPDF_Document* pDoc, const CFX_ByteStringC& fontname);
virtual ~CPDF_Font();
-
-
-
- int GetFontType() const
- {
- return m_FontType;
- }
+ bool IsFontType(int fonttype) const { return fonttype == m_FontType; }
+ int GetFontType() const { return m_FontType; }
CFX_ByteString GetFontTypeName() const;
return m_Font.GetFace();
}
-
-
- virtual FX_DWORD GetNextChar(FX_LPCSTR pString, int& offset) const
+ virtual FX_DWORD GetNextChar(const FX_CHAR* pString, int nStrLen, int& offset) const
{
- return (FX_BYTE)pString[offset++];
+ if (offset < 0 || nStrLen < 1) {
+ return 0;
+ }
+ uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen-1];
+ return static_cast<FX_DWORD>(ch);
}
- virtual int CountChar(FX_LPCSTR pString, int size) const
+ virtual int CountChar(const FX_CHAR* pString, int size) const
{
return size;
}
void AppendChar(CFX_ByteString& str, FX_DWORD charcode) const;
- virtual int AppendChar(FX_LPSTR buf, FX_DWORD charcode) const
+ virtual int AppendChar(FX_CHAR* buf, FX_DWORD charcode) const
{
*buf = (FX_CHAR)charcode;
return 1;
class CFX_PathData* LoadGlyphPath(FX_DWORD charcode, int dest_width = 0);
CFX_Font m_Font;
-protected:
- CPDF_Font();
+protected:
+ explicit CPDF_Font(int fonttype);
FX_BOOL Initialize();
- int m_FontType;
-
CFX_ByteString m_BaseFont;
CPDF_StreamAcc* m_pFontFile;
int m_ItalicAngle;
+private:
+ const int m_FontType;
};
#define PDFFONT_ENCODING_BUILTIN 0
#define PDFFONT_ENCODING_WINANSI 1
#define PDFFONT_ENCODING_PDFDOC 7
#define PDFFONT_ENCODING_MS_SYMBOL 8
#define PDFFONT_ENCODING_UNICODE 9
-class CPDF_FontEncoding : public CFX_Object
+class CPDF_FontEncoding
{
public:
FX_BOOL IsIdentical(CPDF_FontEncoding* pAnother) const;
- FX_WCHAR UnicodeFromCharCode(FX_BYTE charcode) const
+ FX_WCHAR UnicodeFromCharCode(uint8_t charcode) const
{
return m_Unicodes[charcode];
}
int CharCodeFromUnicode(FX_WCHAR unicode) const;
- void SetUnicode(FX_BYTE charcode, FX_WCHAR unicode)
+ void SetUnicode(uint8_t charcode, FX_WCHAR unicode)
{
m_Unicodes[charcode] = unicode;
}
FX_WCHAR m_Unicodes[256];
};
+
class CPDF_SimpleFont : public CPDF_Font
{
public:
+ explicit CPDF_SimpleFont(int fonttype);
+ ~CPDF_SimpleFont() override;
- CPDF_SimpleFont();
-
- virtual ~CPDF_SimpleFont();
-
- CPDF_FontEncoding* GetEncoding()
+ CPDF_FontEncoding* GetEncoding()
{
return &m_Encoding;
}
- virtual int GetCharWidthF(FX_DWORD charcode, int level = 0);
- virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0);
- virtual int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL);
- virtual FX_BOOL IsUnicodeCompatible() const;
+ int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
+ void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
+ int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL) override;
+ FX_BOOL IsUnicodeCompatible() const override;
+
protected:
+ FX_BOOL LoadCommon();
- FX_BOOL LoadCommon();
+ void LoadSubstFont();
- void LoadSubstFont();
+ void LoadFaceMetrics();
- void LoadFaceMetrics();
+ virtual void LoadGlyphMap() = 0;
- virtual void LoadGlyphMap() = 0;
- virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const
+ FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override
{
- return m_Encoding.UnicodeFromCharCode((FX_BYTE)charcode);
+ return m_Encoding.UnicodeFromCharCode((uint8_t)charcode);
}
- virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const
+
+ FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override
{
return m_Encoding.CharCodeFromUnicode(Unicode);
}
+ void LoadCharMetrics(int charcode);
-
- CPDF_FontEncoding m_Encoding;
-
- FX_WORD m_GlyphIndex[256];
- FX_WORD m_ExtGID[256];
-
-
-
-
- CFX_ByteString* m_pCharNames;
-
- int m_BaseEncoding;
-
-
-
-
- FX_WORD m_CharWidth[256];
-
- FX_SMALL_RECT m_CharBBox[256];
-
- FX_BOOL m_bUseFontWidth;
-
- void LoadCharMetrics(int charcode);
-
+ CPDF_FontEncoding m_Encoding;
+ FX_WORD m_GlyphIndex[256];
+ FX_WORD m_ExtGID[256];
+ CFX_ByteString* m_pCharNames;
+ int m_BaseEncoding;
+ FX_WORD m_CharWidth[256];
+ FX_SMALL_RECT m_CharBBox[256];
+ FX_BOOL m_bUseFontWidth;
};
+
class CPDF_Type1Font : public CPDF_SimpleFont
{
public:
virtual FX_BOOL _Load();
virtual void LoadGlyphMap();
};
-class CPDF_Type3Char : public CFX_Object
+class CPDF_Type3Char
{
public:
{
public:
CPDF_Type3Font();
- virtual ~CPDF_Type3Font();
- void SetPageResources(CPDF_Dictionary* pResources)
+ ~CPDF_Type3Font() override;
+
+ void SetPageResources(CPDF_Dictionary* pResources)
{
m_pPageResources = pResources;
}
- CPDF_Type3Char* LoadChar(FX_DWORD charcode, int level = 0);
- virtual int GetCharWidthF(FX_DWORD charcode, int level = 0);
- virtual int GetCharTypeWidth(FX_DWORD charcode)
+ CPDF_Type3Char* LoadChar(FX_DWORD charcode, int level = 0);
+ int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
+ int GetCharTypeWidth(FX_DWORD charcode) override
{
return GetCharWidthF(charcode);
}
- virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0);
- CFX_AffineMatrix& GetFontMatrix()
+ void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
+ CFX_AffineMatrix& GetFontMatrix()
{
return m_FontMatrix;
}
- void CheckType3FontMetrics();
-private:
- virtual FX_BOOL _Load();
- virtual void LoadGlyphMap() {}
- int m_CharWidthL[256];
- CPDF_Dictionary* m_pCharProcs;
- CPDF_Dictionary* m_pPageResources;
- CPDF_Dictionary* m_pFontResources;
- CFX_MapPtrToPtr m_CacheMap;
- CFX_MapPtrToPtr m_DeletedMap;
+ void CheckType3FontMetrics();
+
protected:
- CFX_AffineMatrix m_FontMatrix;
+ CFX_AffineMatrix m_FontMatrix;
+
+private:
+ FX_BOOL _Load() override;
+ void LoadGlyphMap() override {}
+
+ int m_CharWidthL[256];
+ CPDF_Dictionary* m_pCharProcs;
+ CPDF_Dictionary* m_pPageResources;
+ CPDF_Dictionary* m_pFontResources;
+ CFX_MapPtrToPtr m_CacheMap;
+ CFX_MapPtrToPtr m_DeletedMap;
};
+
#define CIDSET_UNKNOWN 0
#define CIDSET_GB1 1
#define CIDSET_CNS1 2
#define CIDSET_JAPAN1 3
#define CIDSET_KOREA1 4
#define CIDSET_UNICODE 5
+#define NUMBER_OF_CIDSETS 6
+
class CPDF_CIDFont : public CPDF_Font
{
public:
CPDF_CIDFont();
- virtual ~CPDF_CIDFont();
-
- FX_BOOL LoadGB2312();
- virtual int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL);
- virtual int GetCharWidthF(FX_DWORD charcode, int level = 0);
- virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0);
+ ~CPDF_CIDFont() override;
- FX_WORD CIDFromCharCode(FX_DWORD charcode) const;
+ FX_BOOL LoadGB2312();
+ int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL) override;
+ int GetCharWidthF(FX_DWORD charcode, int level = 0) override;
+ void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override;
+ FX_WORD CIDFromCharCode(FX_DWORD charcode) const;
- FX_BOOL IsTrueType()
+ FX_BOOL IsTrueType() const
{
return !m_bType1;
}
+ virtual FX_DWORD GetNextChar(const FX_CHAR* pString, int nStrLen, int& offset) const override;
+ int CountChar(const FX_CHAR* pString, int size) const override;
+ int AppendChar(FX_CHAR* str, FX_DWORD charcode) const override;
+ int GetCharSize(FX_DWORD charcode) const override;
- virtual FX_DWORD GetNextChar(const FX_CHAR* pString, int& offset) const;
- virtual int CountChar(const FX_CHAR* pString, int size) const;
- virtual int AppendChar(FX_LPSTR str, FX_DWORD charcode) const;
- virtual int GetCharSize(FX_DWORD charcode) const;
-
-
- int GetCharset() const
+ int GetCharset() const
{
return m_Charset;
}
- FX_LPCBYTE GetCIDTransform(FX_WORD CID) const;
-
-
-
- virtual FX_BOOL IsVertWriting() const;
+ const uint8_t* GetCIDTransform(FX_WORD CID) const;
+ FX_BOOL IsVertWriting() const override;
+ short GetVertWidth(FX_WORD CID) const;
+ void GetVertOrigin(FX_WORD CID, short& vx, short& vy) const;
+ FX_BOOL IsUnicodeCompatible() const override;
+ virtual FX_BOOL IsFontStyleFromCharCode(FX_DWORD charcode) const;
- short GetVertWidth(FX_WORD CID) const;
-
- void GetVertOrigin(FX_WORD CID, short& vx, short& vy) const;
-
- virtual FX_BOOL IsUnicodeCompatible() const;
- virtual FX_BOOL IsFontStyleFromCharCode(FX_DWORD charcode) const;
protected:
- friend class CPDF_Font;
- virtual FX_BOOL _Load();
- virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const;
- virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const;
- int GetGlyphIndex(FX_DWORD unicodeb, FX_BOOL *pVertGlyph);
-
- CPDF_CMap* m_pCMap;
-
- CPDF_CMap* m_pAllocatedCMap;
-
- CPDF_CID2UnicodeMap* m_pCID2UnicodeMap;
-
- int m_Charset;
-
- FX_BOOL m_bType1;
-
- CPDF_StreamAcc* m_pCIDToGIDMap;
- FX_BOOL m_bCIDIsGID;
-
-
-
- FX_WORD m_DefaultWidth;
-
- FX_WORD* m_pAnsiWidths;
-
- FX_SMALL_RECT m_CharBBox[256];
-
- CFX_DWordArray m_WidthList;
-
- short m_DefaultVY;
-
- short m_DefaultW1;
-
- CFX_DWordArray m_VertMetrics;
-
-
- void LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result, int nElements);
-
- void LoadSubstFont();
-
- FX_BOOL m_bAdobeCourierStd;
-
- CFX_CTTGSUBTable* m_pTTGSUBTable;
+ friend class CPDF_Font;
+
+ FX_BOOL _Load() override;
+ FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override;
+ FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override;
+ int GetGlyphIndex(FX_DWORD unicodeb, FX_BOOL *pVertGlyph);
+ void LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result, int nElements);
+ void LoadSubstFont();
+
+ CPDF_CMap* m_pCMap;
+ CPDF_CMap* m_pAllocatedCMap;
+ CPDF_CID2UnicodeMap* m_pCID2UnicodeMap;
+ int m_Charset;
+ FX_BOOL m_bType1;
+ CPDF_StreamAcc* m_pCIDToGIDMap;
+ FX_BOOL m_bCIDIsGID;
+ FX_WORD m_DefaultWidth;
+ FX_WORD* m_pAnsiWidths;
+ FX_SMALL_RECT m_CharBBox[256];
+ CFX_DWordArray m_WidthList;
+ short m_DefaultVY;
+ short m_DefaultW1;
+ CFX_DWordArray m_VertMetrics;
+ FX_BOOL m_bAdobeCourierStd;
+ CFX_CTTGSUBTable* m_pTTGSUBTable;
};
-#define PDFCS_DEVICEGRAY 1
-
-#define PDFCS_DEVICERGB 2
-#define PDFCS_DEVICECMYK 3
-#define PDFCS_CALGRAY 4
-#define PDFCS_CALRGB 5
-#define PDFCS_LAB 6
-#define PDFCS_ICCBASED 7
-#define PDFCS_SEPARATION 8
-#define PDFCS_DEVICEN 9
-#define PDFCS_INDEXED 10
-#define PDFCS_PATTERN 11
-class CPDF_ColorSpace : public CFX_Object
+
+#define PDFCS_DEVICEGRAY 1
+#define PDFCS_DEVICERGB 2
+#define PDFCS_DEVICECMYK 3
+#define PDFCS_CALGRAY 4
+#define PDFCS_CALRGB 5
+#define PDFCS_LAB 6
+#define PDFCS_ICCBASED 7
+#define PDFCS_SEPARATION 8
+#define PDFCS_DEVICEN 9
+#define PDFCS_INDEXED 10
+#define PDFCS_PATTERN 11
+
+class CPDF_ColorSpace
{
public:
FX_BOOL SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const;
- virtual void TranslateImageLine(FX_LPBYTE dest_buf, FX_LPCBYTE src_buf, int pixels,
+ virtual void TranslateImageLine(uint8_t* dest_buf, const uint8_t* src_buf, int pixels,
int image_width, int image_height, FX_BOOL bTransMask = FALSE) const;
CPDF_Array*& GetArray()
FX_DWORD m_dwStdConversion;
};
-class CPDF_Color : public CFX_Object
+class CPDF_Color
{
public:
};
#define PATTERN_TILING 1
#define PATTERN_SHADING 2
-class CPDF_Pattern : public CFX_Object
+class CPDF_Pattern
{
public:
-
+
virtual ~CPDF_Pattern();
void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; }
int m_ShadingType;
- CPDF_ColorSpace* m_pCS;
+ CPDF_ColorSpace* m_pCS; // Still keep m_pCS as some CPDF_ColorSpace (name object) are not managed as counted objects. Refer to CPDF_DocPageData::GetColorSpace.
+ CPDF_CountedColorSpace* m_pCountedCS;
CPDF_Function* m_pFunctions[4];
FX_FLOAT x, y;
FX_FLOAT r, g, b;
};
-class CPDF_MeshStream : public CFX_Object
+class CPDF_MeshStream
{
public:
{
}
FX_ARGB* pMatteColor;
- FX_INT32 nQuality;
+ int32_t nQuality;
};
-class CPDF_Image : public CFX_Object
+class CPDF_Image
{
public:
- FX_INT32 GetPixelHeight() const
+ int32_t GetPixelHeight() const
{
return m_Height;
}
- FX_INT32 GetPixelWidth() const
+ int32_t GetPixelWidth() const
{
return m_Width;
}
- void SetImage(const CFX_DIBitmap* pDIBitmap, FX_INT32 iCompress, IFX_FileWrite *pFileWrite = NULL, IFX_FileRead *pFileRead = NULL, const CFX_DIBitmap* pMask = NULL, const CPDF_ImageSetParam* pParam = NULL);
+ void SetImage(const CFX_DIBitmap* pDIBitmap, int32_t iCompress, IFX_FileWrite *pFileWrite = NULL, IFX_FileRead *pFileRead = NULL, const CFX_DIBitmap* pMask = NULL, const CPDF_ImageSetParam* pParam = NULL);
- void SetJpegImage(FX_BYTE* pImageData, FX_DWORD size);
+ void SetJpegImage(uint8_t* pImageData, FX_DWORD size);
void SetJpegImage(IFX_FileRead *pFile);
FX_BOOL m_bInline;
CPDF_Dictionary* m_pInlineDict;
- FX_INT32 m_Height;
+ int32_t m_Height;
- FX_INT32 m_Width;
+ int32_t m_Width;
FX_BOOL m_bIsMask;
CPDF_Document* m_pDocument;
CPDF_Dictionary* m_pOC;
- CPDF_Dictionary* InitJPEG(FX_LPBYTE pData, FX_DWORD size);
+ CPDF_Dictionary* InitJPEG(uint8_t* pData, FX_DWORD size);
};
-#endif
+
+#endif // CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_