summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_font
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fpdfapi/fpdf_font')
-rw-r--r--core/src/fpdfapi/fpdf_font/common.h34
-rw-r--r--core/src/fpdfapi/fpdf_font/font_int.h402
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp3526
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_charset.cpp1250
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp3432
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp194
-rw-r--r--core/src/fpdfapi/fpdf_font/ttgsubtable.cpp904
-rw-r--r--core/src/fpdfapi/fpdf_font/ttgsubtable.h838
8 files changed, 5290 insertions, 5290 deletions
diff --git a/core/src/fpdfapi/fpdf_font/common.h b/core/src/fpdfapi/fpdf_font/common.h
index 1c11b281a4..4b37a44ccc 100644
--- a/core/src/fpdfapi/fpdf_font/common.h
+++ b/core/src/fpdfapi/fpdf_font/common.h
@@ -1,17 +1,17 @@
-// 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 COMMON_H
-#define COMMON_H
-typedef signed char TT_int8_t;
-typedef unsigned char TT_uint8_t;
-typedef signed short TT_int16_t;
-typedef unsigned short TT_uint16_t;
-typedef FX_INT32 TT_int32_t;
-typedef FX_DWORD TT_uint32_t;
-typedef FX_INT64 TT_int64_t;
-typedef FX_UINT64 TT_uint64_t;
-#endif
+// 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 COMMON_H
+#define COMMON_H
+typedef signed char TT_int8_t;
+typedef unsigned char TT_uint8_t;
+typedef signed short TT_int16_t;
+typedef unsigned short TT_uint16_t;
+typedef FX_INT32 TT_int32_t;
+typedef FX_DWORD TT_uint32_t;
+typedef FX_INT64 TT_int64_t;
+typedef FX_UINT64 TT_uint64_t;
+#endif
diff --git a/core/src/fpdfapi/fpdf_font/font_int.h b/core/src/fpdfapi/fpdf_font/font_int.h
index 779f58ee5d..b151d78b51 100644
--- a/core/src/fpdfapi/fpdf_font/font_int.h
+++ b/core/src/fpdfapi/fpdf_font/font_int.h
@@ -1,201 +1,201 @@
-// 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
-
-typedef void* FXFT_Library;
-class CPDF_CMapManager : public CFX_Object
-{
-public:
- CPDF_CMapManager();
- ~CPDF_CMapManager();
- FX_LPVOID GetPackage(FX_BOOL bPrompt);
- CPDF_CMap* GetPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPrompt);
- CPDF_CID2UnicodeMap* GetCID2UnicodeMap(int charset, FX_BOOL bPrompt);
- void ReloadAll();
-private:
- CPDF_CMap* LoadPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPrompt);
- CPDF_CID2UnicodeMap* LoadCID2UnicodeMap(int charset, FX_BOOL bPrompt);
- void DropAll(FX_BOOL bReload);
-#ifndef _FPDFAPI_MINI_
- FX_BOOL m_bPrompted;
- FX_LPVOID m_pPackage;
-#endif
- CFX_MapByteStringToPtr m_CMaps;
- CPDF_CID2UnicodeMap* m_CID2UnicodeMaps[6];
-};
-class CPDF_FontGlobals : public CFX_Object
-{
-public:
- CPDF_FontGlobals();
- ~CPDF_FontGlobals();
- void ClearAll();
- void Clear(void* key);
- CPDF_Font* Find(void* key, int index);
- void Set(void* key, int index, CPDF_Font* pFont);
- CFX_MapPtrToPtr m_pStockMap;
- CPDF_CMapManager m_CMapManager;
- struct {
- const struct FXCMAP_CMap* m_pMapList;
- int m_Count;
- } m_EmbeddedCharsets[5];
- struct {
- const FX_WORD* m_pMap;
- int m_Count;
- } m_EmbeddedToUnicodes[5];
- FX_LPBYTE m_pContrastRamps;
-};
-struct _CMap_CodeRange {
- int m_CharSize;
- FX_BYTE m_Lower[4];
- FX_BYTE m_Upper[4];
-};
-class CPDF_CMapParser : public CFX_Object
-{
-public:
- CPDF_CMapParser();
- ~CPDF_CMapParser() {}
- FX_BOOL Initialize(CPDF_CMap*);
- void ParseWord(FX_BSTR str);
- CFX_BinaryBuf m_AddMaps;
-private:
- CPDF_CMap* m_pCMap;
- int m_Status;
- int m_CodeSeq;
- FX_DWORD m_CodePoints[4];
- CFX_ArrayTemplate<_CMap_CodeRange> m_CodeRanges;
- CFX_ByteString m_Registry, m_Ordering, m_Supplement;
- CFX_ByteString m_LastWord;
-};
-#define CIDCODING_UNKNOWN 0
-#define CIDCODING_GB 1
-#define CIDCODING_BIG5 2
-#define CIDCODING_JIS 3
-#define CIDCODING_KOREA 4
-#define CIDCODING_UCS2 5
-#define CIDCODING_CID 6
-#define CIDCODING_UTF16 7
-class CPDF_CMap : public CFX_Object
-{
-public:
- CPDF_CMap();
- FX_BOOL LoadPredefined(CPDF_CMapManager* pMgr, const FX_CHAR* name, FX_BOOL bPromptCJK);
- FX_BOOL LoadEmbedded(FX_LPCBYTE pData, FX_DWORD dwSize);
- void Release();
- FX_BOOL IsLoaded() const
- {
- return m_bLoaded;
- }
- int GetCharset()
- {
- return m_Charset;
- }
- FX_BOOL IsVertWriting() const
- {
- return m_bVertical;
- }
- FX_WORD CIDFromCharCode(FX_DWORD charcode) const;
- FX_DWORD CharCodeFromCID(FX_WORD CID) const;
- int GetCharSize(FX_DWORD charcode) const;
- FX_DWORD GetNextChar(const FX_CHAR* pString, int& offset) const;
- int CountChar(const FX_CHAR* pString, int size) const;
- int AppendChar(FX_LPSTR str, FX_DWORD charcode) const;
- typedef enum {OneByte, TwoBytes, MixedTwoBytes, MixedFourBytes} CodingScheme;
-protected:
- ~CPDF_CMap();
- friend class CPDF_CMapParser;
- friend class CPDF_CMapManager;
- friend class CPDF_CIDFont;
-protected:
- CFX_ByteString m_PredefinedCMap;
- FX_BOOL m_bVertical;
- int m_Charset, m_Coding;
- CodingScheme m_CodingScheme;
- int m_nCodeRanges;
- FX_BYTE* m_pLeadingBytes;
- FX_WORD* m_pMapping;
- FX_LPBYTE m_pAddMapping;
- FX_BOOL m_bLoaded;
- const FXCMAP_CMap* m_pEmbedMap;
- CPDF_CMap* m_pUseMap;
-};
-class CPDF_PredefinedCMap
-{
-public:
- FX_LPCSTR m_pName;
- int m_Charset;
- int m_Coding;
- CPDF_CMap::CodingScheme m_CodingScheme;
- FX_DWORD m_LeadingSegCount;
- FX_BYTE m_LeadingSegs[4];
-};
-typedef struct _FileHeader {
- FX_BYTE btTag[4];
- FX_BYTE btVersion;
- FX_BYTE btFormat;
- FX_BYTE btReserved1[2];
- FX_DWORD dwStartIndex;
- FX_DWORD dwEndIndex;
- FX_DWORD dwDataSize;
- FX_DWORD dwDataOffset;
- FX_DWORD dwRecordSize;
-} FXMP_FILEHEADER;
-class CPDF_FXMP : public CFX_Object
-{
-public:
- CPDF_FXMP()
- {
- m_pHeader = NULL;
- m_pTable = NULL;
- }
- ~CPDF_FXMP()
- {
- if (m_pHeader) {
- FX_Free(m_pHeader);
- }
- }
- FX_BOOL IsLoaded()
- {
- return m_pTable != NULL;
- }
- FX_BOOL LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid);
- FX_LPBYTE GetRecord(FX_DWORD index);
-private:
- FXMP_FILEHEADER* m_pHeader;
- FX_LPBYTE m_pTable;
-};
-class CPDF_CID2UnicodeMap : public CFX_Object
-{
-public:
- CPDF_CID2UnicodeMap();
- ~CPDF_CID2UnicodeMap();
- FX_BOOL Initialize();
- FX_BOOL IsLoaded();
- void Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPromptCJK);
- FX_WCHAR UnicodeFromCID(FX_WORD CID);
-protected:
- int m_Charset;
- const FX_WORD* m_pEmbeddedMap;
- FX_DWORD m_EmbeddedCount;
-#ifndef _FPDFAPI_MINI_
- CPDF_FXMP* m_pExternalMap;
-#endif
-};
-class CPDF_ToUnicodeMap : public CFX_Object
-{
-public:
- void Load(CPDF_Stream* pStream);
- CFX_WideString Lookup(FX_DWORD charcode);
- FX_DWORD ReverseLookup(FX_WCHAR unicode);
-protected:
- CFX_CMapDWordToDWord m_Map;
- CPDF_CID2UnicodeMap* m_pBaseMap;
- CFX_WideTextBuf m_MultiCharBuf;
-};
-class CPDF_FontCharMap : public CFX_CharMap, public CFX_Object
-{
-public:
- CPDF_FontCharMap(CPDF_Font* pFont);
- CPDF_Font* m_pFont;
-};
+// 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
+
+typedef void* FXFT_Library;
+class CPDF_CMapManager : public CFX_Object
+{
+public:
+ CPDF_CMapManager();
+ ~CPDF_CMapManager();
+ FX_LPVOID GetPackage(FX_BOOL bPrompt);
+ CPDF_CMap* GetPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPrompt);
+ CPDF_CID2UnicodeMap* GetCID2UnicodeMap(int charset, FX_BOOL bPrompt);
+ void ReloadAll();
+private:
+ CPDF_CMap* LoadPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPrompt);
+ CPDF_CID2UnicodeMap* LoadCID2UnicodeMap(int charset, FX_BOOL bPrompt);
+ void DropAll(FX_BOOL bReload);
+#ifndef _FPDFAPI_MINI_
+ FX_BOOL m_bPrompted;
+ FX_LPVOID m_pPackage;
+#endif
+ CFX_MapByteStringToPtr m_CMaps;
+ CPDF_CID2UnicodeMap* m_CID2UnicodeMaps[6];
+};
+class CPDF_FontGlobals : public CFX_Object
+{
+public:
+ CPDF_FontGlobals();
+ ~CPDF_FontGlobals();
+ void ClearAll();
+ void Clear(void* key);
+ CPDF_Font* Find(void* key, int index);
+ void Set(void* key, int index, CPDF_Font* pFont);
+ CFX_MapPtrToPtr m_pStockMap;
+ CPDF_CMapManager m_CMapManager;
+ struct {
+ const struct FXCMAP_CMap* m_pMapList;
+ int m_Count;
+ } m_EmbeddedCharsets[5];
+ struct {
+ const FX_WORD* m_pMap;
+ int m_Count;
+ } m_EmbeddedToUnicodes[5];
+ FX_LPBYTE m_pContrastRamps;
+};
+struct _CMap_CodeRange {
+ int m_CharSize;
+ FX_BYTE m_Lower[4];
+ FX_BYTE m_Upper[4];
+};
+class CPDF_CMapParser : public CFX_Object
+{
+public:
+ CPDF_CMapParser();
+ ~CPDF_CMapParser() {}
+ FX_BOOL Initialize(CPDF_CMap*);
+ void ParseWord(FX_BSTR str);
+ CFX_BinaryBuf m_AddMaps;
+private:
+ CPDF_CMap* m_pCMap;
+ int m_Status;
+ int m_CodeSeq;
+ FX_DWORD m_CodePoints[4];
+ CFX_ArrayTemplate<_CMap_CodeRange> m_CodeRanges;
+ CFX_ByteString m_Registry, m_Ordering, m_Supplement;
+ CFX_ByteString m_LastWord;
+};
+#define CIDCODING_UNKNOWN 0
+#define CIDCODING_GB 1
+#define CIDCODING_BIG5 2
+#define CIDCODING_JIS 3
+#define CIDCODING_KOREA 4
+#define CIDCODING_UCS2 5
+#define CIDCODING_CID 6
+#define CIDCODING_UTF16 7
+class CPDF_CMap : public CFX_Object
+{
+public:
+ CPDF_CMap();
+ FX_BOOL LoadPredefined(CPDF_CMapManager* pMgr, const FX_CHAR* name, FX_BOOL bPromptCJK);
+ FX_BOOL LoadEmbedded(FX_LPCBYTE pData, FX_DWORD dwSize);
+ void Release();
+ FX_BOOL IsLoaded() const
+ {
+ return m_bLoaded;
+ }
+ int GetCharset()
+ {
+ return m_Charset;
+ }
+ FX_BOOL IsVertWriting() const
+ {
+ return m_bVertical;
+ }
+ FX_WORD CIDFromCharCode(FX_DWORD charcode) const;
+ FX_DWORD CharCodeFromCID(FX_WORD CID) const;
+ int GetCharSize(FX_DWORD charcode) const;
+ FX_DWORD GetNextChar(const FX_CHAR* pString, int& offset) const;
+ int CountChar(const FX_CHAR* pString, int size) const;
+ int AppendChar(FX_LPSTR str, FX_DWORD charcode) const;
+ typedef enum {OneByte, TwoBytes, MixedTwoBytes, MixedFourBytes} CodingScheme;
+protected:
+ ~CPDF_CMap();
+ friend class CPDF_CMapParser;
+ friend class CPDF_CMapManager;
+ friend class CPDF_CIDFont;
+protected:
+ CFX_ByteString m_PredefinedCMap;
+ FX_BOOL m_bVertical;
+ int m_Charset, m_Coding;
+ CodingScheme m_CodingScheme;
+ int m_nCodeRanges;
+ FX_BYTE* m_pLeadingBytes;
+ FX_WORD* m_pMapping;
+ FX_LPBYTE m_pAddMapping;
+ FX_BOOL m_bLoaded;
+ const FXCMAP_CMap* m_pEmbedMap;
+ CPDF_CMap* m_pUseMap;
+};
+class CPDF_PredefinedCMap
+{
+public:
+ FX_LPCSTR m_pName;
+ int m_Charset;
+ int m_Coding;
+ CPDF_CMap::CodingScheme m_CodingScheme;
+ FX_DWORD m_LeadingSegCount;
+ FX_BYTE m_LeadingSegs[4];
+};
+typedef struct _FileHeader {
+ FX_BYTE btTag[4];
+ FX_BYTE btVersion;
+ FX_BYTE btFormat;
+ FX_BYTE btReserved1[2];
+ FX_DWORD dwStartIndex;
+ FX_DWORD dwEndIndex;
+ FX_DWORD dwDataSize;
+ FX_DWORD dwDataOffset;
+ FX_DWORD dwRecordSize;
+} FXMP_FILEHEADER;
+class CPDF_FXMP : public CFX_Object
+{
+public:
+ CPDF_FXMP()
+ {
+ m_pHeader = NULL;
+ m_pTable = NULL;
+ }
+ ~CPDF_FXMP()
+ {
+ if (m_pHeader) {
+ FX_Free(m_pHeader);
+ }
+ }
+ FX_BOOL IsLoaded()
+ {
+ return m_pTable != NULL;
+ }
+ FX_BOOL LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid);
+ FX_LPBYTE GetRecord(FX_DWORD index);
+private:
+ FXMP_FILEHEADER* m_pHeader;
+ FX_LPBYTE m_pTable;
+};
+class CPDF_CID2UnicodeMap : public CFX_Object
+{
+public:
+ CPDF_CID2UnicodeMap();
+ ~CPDF_CID2UnicodeMap();
+ FX_BOOL Initialize();
+ FX_BOOL IsLoaded();
+ void Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPromptCJK);
+ FX_WCHAR UnicodeFromCID(FX_WORD CID);
+protected:
+ int m_Charset;
+ const FX_WORD* m_pEmbeddedMap;
+ FX_DWORD m_EmbeddedCount;
+#ifndef _FPDFAPI_MINI_
+ CPDF_FXMP* m_pExternalMap;
+#endif
+};
+class CPDF_ToUnicodeMap : public CFX_Object
+{
+public:
+ void Load(CPDF_Stream* pStream);
+ CFX_WideString Lookup(FX_DWORD charcode);
+ FX_DWORD ReverseLookup(FX_WCHAR unicode);
+protected:
+ CFX_CMapDWordToDWord m_Map;
+ CPDF_CID2UnicodeMap* m_pBaseMap;
+ CFX_WideTextBuf m_MultiCharBuf;
+};
+class CPDF_FontCharMap : public CFX_CharMap, public CFX_Object
+{
+public:
+ CPDF_FontCharMap(CPDF_Font* pFont);
+ CPDF_Font* m_pFont;
+};
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 886199b120..4bec3337b1 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -1,1763 +1,1763 @@
-// 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
-
-#include "../../../include/fpdfapi/fpdf_page.h"
-#include "../../../include/fpdfapi/fpdf_module.h"
-#include "../../../include/fpdfapi/fpdf_pageobj.h"
-#include "font_int.h"
-#include "../fpdf_page/pageint.h"
-#include "../../../include/fxge/fx_freetype.h"
-FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id)
-{
- for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i ++) {
- if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == platform_id &&
- FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == encoding_id) {
- FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]);
- return TRUE;
- }
- }
- return FALSE;
-}
-extern const FX_WORD* PDF_UnicodesForPredefinedCharSet(int);
-CPDF_FontGlobals::CPDF_FontGlobals()
-{
- FXSYS_memset32(m_EmbeddedCharsets, 0, sizeof m_EmbeddedCharsets);
- FXSYS_memset32(m_EmbeddedToUnicodes, 0, sizeof m_EmbeddedToUnicodes);
- m_pContrastRamps = NULL;
-}
-CPDF_FontGlobals::~CPDF_FontGlobals()
-{
- ClearAll();
- if (m_pContrastRamps) {
- FX_Free(m_pContrastRamps);
- }
-}
-class CFX_StockFontArray : public CFX_Object
-{
-public:
- CFX_StockFontArray()
- {
- FXSYS_memset32(m_pStockFonts, 0, sizeof(CPDF_Font*) * 14);
- }
- CPDF_Font* m_pStockFonts[14];
-};
-CPDF_Font* CPDF_FontGlobals::Find(void* key, int index)
-{
- void* value = NULL;
- if (!m_pStockMap.Lookup(key, value)) {
- return NULL;
- }
- if (!value) {
- return NULL;
- }
- return ((CFX_StockFontArray*)value)->m_pStockFonts[index];
-}
-void CPDF_FontGlobals::Set(void* key, int index, CPDF_Font* pFont)
-{
- void* value = NULL;
- if (m_pStockMap.Lookup(key, value)) {
- ((CFX_StockFontArray*)value)->m_pStockFonts[index] = pFont;
- return;
- }
- CFX_StockFontArray* pFonts = FX_NEW CFX_StockFontArray();
- if (pFonts) {
- pFonts->m_pStockFonts[index] = pFont;
- }
- m_pStockMap.SetAt(key, pFonts);
-}
-void CPDF_FontGlobals::Clear(void* key)
-{
- void* value = NULL;
- if (!m_pStockMap.Lookup(key, value)) {
- return;
- }
- if (value) {
- CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value;
- for (int i = 0; i < 14; i ++) {
- if (pStockFonts->m_pStockFonts[i]) {
- pStockFonts->m_pStockFonts[i]->GetFontDict()->Release();
- delete pStockFonts->m_pStockFonts[i];
- }
- }
- delete pStockFonts;
- }
- m_pStockMap.RemoveKey(key);
-}
-void CPDF_FontGlobals::ClearAll()
-{
- FX_POSITION pos = m_pStockMap.GetStartPosition();
- while (pos) {
- void *key = NULL;
- void* value = NULL;
- m_pStockMap.GetNextAssoc(pos, key, value);
- if (value) {
- CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value;
- for (int i = 0; i < 14; i ++) {
- if (pStockFonts->m_pStockFonts[i]) {
- pStockFonts->m_pStockFonts[i]->GetFontDict()->Release();
- delete pStockFonts->m_pStockFonts[i];
- }
- }
- delete pStockFonts;
- }
- m_pStockMap.RemoveKey(key);
- }
-}
-CPDF_Font::CPDF_Font()
-{
- m_FontType = 0;
- m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0;
- m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0;
- m_pFontFile = NULL;
- m_Flags = 0;
- m_pToUnicodeMap = NULL;
- m_bToUnicodeLoaded = FALSE;
- m_pCharMap = NULL;
-}
-FX_BOOL CPDF_Font::Initialize()
-{
- m_pCharMap = FX_NEW CPDF_FontCharMap(this);
- return TRUE;
-}
-CPDF_Font::~CPDF_Font()
-{
- if (m_pCharMap) {
- FX_Free(m_pCharMap);
- m_pCharMap = NULL;
- }
- if (m_pToUnicodeMap) {
- delete m_pToUnicodeMap;
- m_pToUnicodeMap = NULL;
- }
- if (m_pFontFile) {
- m_pDocument->GetPageData()->ReleaseFontFileStreamAcc((CPDF_Stream*)m_pFontFile->GetStream());
- }
-}
-FX_BOOL CPDF_Font::IsVertWriting() const
-{
- FX_BOOL bVertWriting = FALSE;
- CPDF_CIDFont* pCIDFont = GetCIDFont();
- if (pCIDFont) {
- bVertWriting = pCIDFont->IsVertWriting();
- } else {
- bVertWriting = m_Font.IsVertical();
- }
- return bVertWriting;
-}
-CFX_ByteString CPDF_Font::GetFontTypeName() const
-{
- switch (m_FontType) {
- case PDFFONT_TYPE1:
- return FX_BSTRC("Type1");
- case PDFFONT_TRUETYPE:
- return FX_BSTRC("TrueType");
- case PDFFONT_TYPE3:
- return FX_BSTRC("Type3");
- case PDFFONT_CIDFONT:
- return FX_BSTRC("Type0");
- }
- return CFX_ByteString();
-}
-void CPDF_Font::AppendChar(CFX_ByteString& str, FX_DWORD charcode) const
-{
- char buf[4];
- int len = AppendChar(buf, charcode);
- if (len == 1) {
- str += buf[0];
- } else {
- str += CFX_ByteString(buf, len);
- }
-}
-CFX_WideString CPDF_Font::UnicodeFromCharCode(FX_DWORD charcode) const
-{
- if (!m_bToUnicodeLoaded) {
- ((CPDF_Font*)this)->LoadUnicodeMap();
- }
- if (m_pToUnicodeMap) {
- CFX_WideString wsRet = m_pToUnicodeMap->Lookup(charcode);
- if (!wsRet.IsEmpty()) {
- return wsRet;
- }
- }
- FX_WCHAR unicode = _UnicodeFromCharCode(charcode);
- if (unicode == 0) {
- return CFX_WideString();
- }
- return unicode;
-}
-FX_DWORD CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const
-{
- if (!m_bToUnicodeLoaded) {
- ((CPDF_Font*)this)->LoadUnicodeMap();
- }
- if (m_pToUnicodeMap) {
- FX_DWORD charcode = m_pToUnicodeMap->ReverseLookup(unicode);
- if (charcode) {
- return charcode;
- }
- }
- return _CharCodeFromUnicode(unicode);
-}
-CFX_WideString CPDF_Font::DecodeString(const CFX_ByteString& str) const
-{
- CFX_WideString result;
- int src_len = str.GetLength();
- result.Reserve(src_len);
- FX_LPCSTR src_buf = str;
- int src_pos = 0;
- while (src_pos < src_len) {
- FX_DWORD charcode = GetNextChar(src_buf, src_pos);
- CFX_WideString unicode = UnicodeFromCharCode(charcode);
- if (!unicode.IsEmpty()) {
- result += unicode;
- } else {
- result += (FX_WCHAR)charcode;
- }
- }
- return result;
-}
-CFX_ByteString CPDF_Font::EncodeString(const CFX_WideString& str) const
-{
- CFX_ByteString result;
- int src_len = str.GetLength();
- FX_LPSTR dest_buf = result.GetBuffer(src_len * 2);
- FX_LPCWSTR src_buf = str;
- int dest_pos = 0;
- for (int src_pos = 0; src_pos < src_len; src_pos ++) {
- FX_DWORD charcode = CharCodeFromUnicode(src_buf[src_pos]);
- dest_pos += AppendChar(dest_buf + dest_pos, charcode);
- }
- result.ReleaseBuffer(dest_pos);
- return result;
-}
-void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc)
-{
- m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags"), PDFFONT_NONSYMBOLIC);
- int ItalicAngle = 0;
- FX_BOOL bExistItalicAngle = FALSE;
- if (pFontDesc->KeyExist(FX_BSTRC("ItalicAngle"))) {
- ItalicAngle = pFontDesc->GetInteger(FX_BSTRC("ItalicAngle"));
- bExistItalicAngle = TRUE;
- }
- if (ItalicAngle < 0) {
- m_Flags |= PDFFONT_ITALIC;
- m_ItalicAngle = ItalicAngle;
- }
- FX_BOOL bExistStemV = FALSE;
- if (pFontDesc->KeyExist(FX_BSTRC("StemV"))) {
- m_StemV = pFontDesc->GetInteger(FX_BSTRC("StemV"));
- bExistStemV = TRUE;
- }
- FX_BOOL bExistAscent = FALSE;
- if (pFontDesc->KeyExist(FX_BSTRC("Ascent"))) {
- m_Ascent = pFontDesc->GetInteger(FX_BSTRC("Ascent"));
- bExistAscent = TRUE;
- }
- FX_BOOL bExistDescent = FALSE;
- if (pFontDesc->KeyExist(FX_BSTRC("Descent"))) {
- m_Descent = pFontDesc->GetInteger(FX_BSTRC("Descent"));
- bExistDescent = TRUE;
- }
- FX_BOOL bExistCapHeight = FALSE;
- if (pFontDesc->KeyExist(FX_BSTRC("CapHeight"))) {
- bExistCapHeight = TRUE;
- }
- if (bExistItalicAngle && bExistAscent && bExistCapHeight && bExistDescent && bExistStemV) {
- m_Flags |= PDFFONT_USEEXTERNATTR;
- }
- if (m_Descent > 10) {
- m_Descent = -m_Descent;
- }
- CPDF_Array* pBBox = pFontDesc->GetArray(FX_BSTRC("FontBBox"));
- if (pBBox) {
- m_FontBBox.left = pBBox->GetInteger(0);
- m_FontBBox.bottom = pBBox->GetInteger(1);
- m_FontBBox.right = pBBox->GetInteger(2);
- m_FontBBox.top = pBBox->GetInteger(3);
- }
- CPDF_Stream* pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile"));
- if (pFontFile == NULL) {
- pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile2"));
- }
- if (pFontFile == NULL) {
- pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile3"));
- }
- if (pFontFile) {
- m_pFontFile = m_pDocument->LoadFontFile(pFontFile);
- if (m_pFontFile == NULL) {
- return;
- }
- FX_LPCBYTE pFontData = m_pFontFile->GetData();
- FX_DWORD dwFontSize = m_pFontFile->GetSize();
- m_Font.LoadEmbedded(pFontData, dwFontSize);
- if (m_Font.m_Face == NULL) {
- m_pFontFile = NULL;
- }
- }
-}
-short TT2PDF(int m, FXFT_Face face)
-{
- int upm = FXFT_Get_Face_UnitsPerEM(face);
- if (upm == 0) {
- return (short)m;
- }
- return (m * 1000 + upm / 2) / upm;
-}
-void CPDF_Font::CheckFontMetrics()
-{
- if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 && m_FontBBox.right == 0) {
- if (m_Font.m_Face) {
- m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(m_Font.m_Face), m_Font.m_Face);
- m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(m_Font.m_Face), m_Font.m_Face);
- m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(m_Font.m_Face), m_Font.m_Face);
- m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(m_Font.m_Face), m_Font.m_Face);
- m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(m_Font.m_Face), m_Font.m_Face);
- m_Descent = TT2PDF(FXFT_Get_Face_Descender(m_Font.m_Face), m_Font.m_Face);
- } else {
- FX_BOOL bFirst = TRUE;
- for (int i = 0; i < 256; i ++) {
- FX_RECT rect;
- GetCharBBox(i, rect);
- if (rect.left == rect.right) {
- continue;
- }
- if (bFirst) {
- m_FontBBox = rect;
- bFirst = FALSE;
- } else {
- if (m_FontBBox.top < rect.top) {
- m_FontBBox.top = rect.top;
- }
- if (m_FontBBox.right < rect.right) {
- m_FontBBox.right = rect.right;
- }
- if (m_FontBBox.left > rect.left) {
- m_FontBBox.left = rect.left;
- }
- if (m_FontBBox.bottom > rect.bottom) {
- m_FontBBox.bottom = rect.bottom;
- }
- }
- }
- }
- }
- if (m_Ascent == 0 && m_Descent == 0) {
- FX_RECT rect;
- GetCharBBox('A', rect);
- if (rect.bottom == rect.top) {
- m_Ascent = m_FontBBox.top;
- } else {
- m_Ascent = rect.top;
- }
- GetCharBBox('g', rect);
- if (rect.bottom == rect.top) {
- m_Descent = m_FontBBox.bottom;
- } else {
- m_Descent = rect.bottom;
- }
- }
-}
-void CPDF_Font::LoadUnicodeMap()
-{
- m_bToUnicodeLoaded = TRUE;
- CPDF_Stream* pStream = m_pFontDict->GetStream(FX_BSTRC("ToUnicode"));
- if (pStream == NULL) {
- return;
- }
- m_pToUnicodeMap = FX_NEW CPDF_ToUnicodeMap;
- m_pToUnicodeMap->Load(pStream);
-}
-int CPDF_Font::GetStringWidth(FX_LPCSTR pString, int size)
-{
- int offset = 0;
- int width = 0;
- while (offset < size) {
- FX_DWORD charcode = GetNextChar(pString, offset);
- width += GetCharWidthF(charcode);
- }
- return width;
-}
-int CPDF_Font::GetCharTypeWidth(FX_DWORD charcode)
-{
- if (m_Font.m_Face == NULL) {
- return 0;
- }
- int glyph_index = GlyphFromCharCode(charcode);
- if (glyph_index == 0xffff) {
- return 0;
- }
- return m_Font.GetGlyphWidth(glyph_index);
-}
-int _PDF_GetStandardFontName(CFX_ByteString& name);
-CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, FX_BSTR name)
-{
- CFX_ByteString fontname(name);
- int font_id = _PDF_GetStandardFontName(fontname);
- if (font_id < 0) {
- return NULL;
- }
- CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id);
- if (pFont) {
- return pFont;
- }
- CPDF_Dictionary* pDict = CPDF_Dictionary::Create();
- pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Font"));
- pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Type1"));
- pDict->SetAtName(FX_BSTRC("BaseFont"), fontname);
- pDict->SetAtName(FX_BSTRC("Encoding"), FX_BSTRC("WinAnsiEncoding"));
- pFont = CPDF_Font::CreateFontF(NULL, pDict);
- pFontGlobals->Set(pDoc, font_id, pFont);
- return pFont;
-}
-const FX_BYTE ChineseFontNames[][5] = {
- {0xCB, 0xCE, 0xCC, 0xE5, 0x00},
- {0xBF, 0xAC, 0xCC, 0xE5, 0x00},
- {0xBA, 0xDA, 0xCC, 0xE5, 0x00},
- {0xB7, 0xC2, 0xCB, 0xCE, 0x00},
- {0xD0, 0xC2, 0xCB, 0xCE, 0x00}
-};
-CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict)
-{
- CFX_ByteString type = pFontDict->GetString(FX_BSTRC("Subtype"));
- CPDF_Font* pFont;
- if (type == FX_BSTRC("TrueType")) {
- {
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ || _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- CFX_ByteString basefont = pFontDict->GetString(FX_BSTRC("BaseFont"));
- CFX_ByteString tag = basefont.Left(4);
- int i;
- int count = sizeof(ChineseFontNames) / sizeof(ChineseFontNames[0]);
- for (i = 0; i < count; ++i) {
- if (tag == CFX_ByteString((FX_LPCSTR)ChineseFontNames[i])) {
- break;
- }
- }
- if (i < count) {
- CPDF_Dictionary* pFontDesc = pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
- if (pFontDesc == NULL || !pFontDesc->KeyExist(FX_BSTRC("FontFile2"))) {
- pFont = FX_NEW CPDF_CIDFont;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_CIDFONT;
- pFont->m_pFontDict = pFontDict;
- pFont->m_pDocument = pDoc;
- if (!pFont->Load()) {
- delete pFont;
- return NULL;
- }
- return pFont;
- }
- }
-#endif
- }
- pFont = FX_NEW CPDF_TrueTypeFont;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_TRUETYPE;
- } else if (type == FX_BSTRC("Type3")) {
- pFont = FX_NEW CPDF_Type3Font;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_TYPE3;
- } else if (type == FX_BSTRC("Type0")) {
- pFont = FX_NEW CPDF_CIDFont;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_CIDFONT;
- } else {
- pFont = FX_NEW CPDF_Type1Font;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_TYPE1;
- }
- pFont->m_pFontDict = pFontDict;
- pFont->m_pDocument = pDoc;
- if (!pFont->Load()) {
- delete pFont;
- return NULL;
- }
- return pFont;
-}
-FX_BOOL CPDF_Font::Load()
-{
- if (m_pFontDict == NULL) {
- return FALSE;
- }
- CFX_ByteString type = m_pFontDict->GetString(FX_BSTRC("Subtype"));
- m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont"));
- if (type == FX_BSTRC("MMType1")) {
- type = FX_BSTRC("Type1");
- }
- return _Load();
-}
-static CFX_WideString _FontMap_GetWideString(CFX_CharMap* pMap, const CFX_ByteString& bytestr)
-{
- return ((CPDF_FontCharMap*)pMap)->m_pFont->DecodeString(bytestr);
-}
-static CFX_ByteString _FontMap_GetByteString(CFX_CharMap* pMap, const CFX_WideString& widestr)
-{
- return ((CPDF_FontCharMap*)pMap)->m_pFont->EncodeString(widestr);
-}
-CPDF_FontCharMap::CPDF_FontCharMap(CPDF_Font* pFont)
-{
- m_GetByteString = _FontMap_GetByteString;
- m_GetWideString = _FontMap_GetWideString;
- m_pFont = pFont;
-}
-CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode)
-{
- FX_DWORD value;
- if (m_Map.Lookup(charcode, value)) {
- FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff);
- if (unicode != 0xffff) {
- return unicode;
- }
- FX_LPCWSTR buf = m_MultiCharBuf.GetBuffer();
- FX_DWORD buf_len = m_MultiCharBuf.GetLength();
- if (buf == NULL || buf_len == 0) {
- return CFX_WideString();
- }
- FX_DWORD index = value >> 16;
- if (index >= buf_len) {
- return CFX_WideString();
- }
- FX_DWORD len = buf[index];
- if (index + len < index || index + len >= buf_len) {
- return CFX_WideString();
- }
- return CFX_WideString(buf + index + 1, len);
- }
- if (m_pBaseMap) {
- return m_pBaseMap->UnicodeFromCID((FX_WORD)charcode);
- }
- return CFX_WideString();
-}
-FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode)
-{
- FX_POSITION pos = m_Map.GetStartPosition();
- while (pos) {
- FX_DWORD key, value;
- m_Map.GetNextAssoc(pos, key, value);
- if ((FX_WCHAR)value == unicode) {
- return key;
- }
- }
- return 0;
-}
-static FX_DWORD _StringToCode(FX_BSTR str)
-{
- FX_LPCSTR buf = str.GetCStr();
- int len = str.GetLength();
- if (len == 0) {
- return 0;
- }
- int result = 0;
- if (buf[0] == '<') {
- for (int i = 1; i < len; i ++) {
- int digit;
- if (buf[i] >= '0' && buf[i] <= '9') {
- digit = buf[i] - '0';
- } else if (buf[i] >= 'a' && buf[i] <= 'f') {
- digit = buf[i] - 'a' + 10;
- } else if (buf[i] >= 'A' && buf[i] <= 'F') {
- digit = buf[i] - 'A' + 10;
- } else {
- break;
- }
- result = result * 16 + digit;
- }
- return result;
- } else {
- for (int i = 0; i < len; i ++) {
- if (buf[i] < '0' || buf[i] > '9') {
- break;
- }
- result = result * 10 + buf[i] - '0';
- }
- }
- return result;
-}
-static CFX_WideString _StringDataAdd(CFX_WideString str)
-{
- CFX_WideString ret;
- int len = str.GetLength();
- FX_WCHAR value = 1;
- for (int i = len - 1; i >= 0 ; --i) {
- FX_WCHAR ch = str[i] + value;
- if (ch < str[i]) {
- ret.Insert(0, 0);
- } else {
- ret.Insert(0, ch);
- value = 0;
- }
- }
- if (value) {
- ret.Insert(0, value);
- }
- return ret;
-}
-static CFX_WideString _StringToWideString(FX_BSTR str)
-{
- FX_LPCSTR buf = str.GetCStr();
- int len = str.GetLength();
- if (len == 0) {
- return CFX_WideString();
- }
- CFX_WideString result;
- if (buf[0] == '<') {
- int byte_pos = 0;
- FX_WCHAR ch = 0;
- for (int i = 1; i < len; i ++) {
- int digit;
- if (buf[i] >= '0' && buf[i] <= '9') {
- digit = buf[i] - '0';
- } else if (buf[i] >= 'a' && buf[i] <= 'f') {
- digit = buf[i] - 'a' + 10;
- } else if (buf[i] >= 'A' && buf[i] <= 'F') {
- digit = buf[i] - 'A' + 10;
- } else {
- break;
- }
- ch = ch * 16 + digit;
- byte_pos ++;
- if (byte_pos == 4) {
- result += ch;
- byte_pos = 0;
- ch = 0;
- }
- }
- return result;
- }
- if (buf[0] == '(') {
- }
- return result;
-}
-void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream)
-{
- int CIDSet = 0;
- CPDF_StreamAcc stream;
- stream.LoadAllData(pStream, FALSE);
- CPDF_SimpleParser parser(stream.GetData(), stream.GetSize());
- m_Map.EstimateSize(stream.GetSize() / 8, 1024);
- while (1) {
- CFX_ByteStringC word = parser.GetWord();
- if (word.IsEmpty()) {
- break;
- }
- if (word == FX_BSTRC("beginbfchar")) {
- while (1) {
- word = parser.GetWord();
- if (word.IsEmpty() || word == FX_BSTRC("endbfchar")) {
- break;
- }
- FX_DWORD srccode = _StringToCode(word);
- word = parser.GetWord();
- CFX_WideString destcode = _StringToWideString(word);
- int len = destcode.GetLength();
- if (len == 0) {
- continue;
- }
- if (len == 1) {
- m_Map.SetAt(srccode, destcode.GetAt(0));
- } else {
- m_Map.SetAt(srccode, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff);
- m_MultiCharBuf.AppendChar(destcode.GetLength());
- m_MultiCharBuf << destcode;
- }
- }
- } else if (word == FX_BSTRC("beginbfrange")) {
- while (1) {
- CFX_ByteString low, high;
- low = parser.GetWord();
- if (low.IsEmpty() || low == FX_BSTRC("endbfrange")) {
- break;
- }
- high = parser.GetWord();
- FX_DWORD lowcode = _StringToCode(low);
- FX_DWORD highcode = (lowcode & 0xffffff00) | (_StringToCode(high) & 0xff);
- if (highcode == (FX_DWORD) - 1) {
- break;
- }
- CFX_ByteString start = parser.GetWord();
- if (start == FX_BSTRC("[")) {
- for (FX_DWORD code = lowcode; code <= highcode; code ++) {
- CFX_ByteString dest = parser.GetWord();
- CFX_WideString destcode = _StringToWideString(dest);
- int len = destcode.GetLength();
- if (len == 0) {
- continue;
- }
- if (len == 1) {
- m_Map.SetAt(code, destcode.GetAt(0));
- } else {
- m_Map.SetAt(code, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff);
- m_MultiCharBuf.AppendChar(destcode.GetLength());
- m_MultiCharBuf << destcode;
- }
- }
- parser.GetWord();
- } else {
- CFX_WideString destcode = _StringToWideString(start);
- int len = destcode.GetLength();
- FX_DWORD value = 0;
- if (len == 1) {
- value = _StringToCode(start);
- for (FX_DWORD code = lowcode; code <= highcode; code ++) {
- m_Map.SetAt(code, value++);
- }
- } else {
- for (FX_DWORD code = lowcode; code <= highcode; code ++) {
- CFX_WideString retcode;
- if (code == lowcode) {
- retcode = destcode;
- } else {
- retcode = _StringDataAdd(destcode);
- }
- m_Map.SetAt(code, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff);
- m_MultiCharBuf.AppendChar(retcode.GetLength());
- m_MultiCharBuf << retcode;
- destcode = retcode;
- }
- }
- }
- }
- } else if (word == FX_BSTRC("/Adobe-Korea1-UCS2")) {
- CIDSet = CIDSET_KOREA1;
- } else if (word == FX_BSTRC("/Adobe-Japan1-UCS2")) {
- CIDSet = CIDSET_JAPAN1;
- } else if (word == FX_BSTRC("/Adobe-CNS1-UCS2")) {
- CIDSet = CIDSET_CNS1;
- } else if (word == FX_BSTRC("/Adobe-GB1-UCS2")) {
- CIDSet = CIDSET_GB1;
- }
- }
- if (CIDSet) {
- m_pBaseMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetCID2UnicodeMap(CIDSet, FALSE);
- } else {
- m_pBaseMap = NULL;
- }
-}
-static FX_BOOL GetPredefinedEncoding(int& basemap, const CFX_ByteString& value)
-{
- if (value == FX_BSTRC("WinAnsiEncoding")) {
- basemap = PDFFONT_ENCODING_WINANSI;
- } else if (value == FX_BSTRC("MacRomanEncoding")) {
- basemap = PDFFONT_ENCODING_MACROMAN;
- } else if (value == FX_BSTRC("MacExpertEncoding")) {
- basemap = PDFFONT_ENCODING_MACEXPERT;
- } else if (value == FX_BSTRC("PDFDocEncoding")) {
- basemap = PDFFONT_ENCODING_PDFDOC;
- } else {
- return FALSE;
- }
- return TRUE;
-}
-void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, CFX_ByteString*& pCharNames,
- FX_BOOL bEmbedded, FX_BOOL bTrueType)
-{
- if (pEncoding == NULL) {
- if (m_BaseFont == FX_BSTRC("Symbol")) {
- iBaseEncoding = bTrueType ? PDFFONT_ENCODING_MS_SYMBOL : PDFFONT_ENCODING_ADOBE_SYMBOL;
- } else if (!bEmbedded && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) {
- iBaseEncoding = PDFFONT_ENCODING_WINANSI;
- }
- return;
- }
- if (pEncoding->GetType() == PDFOBJ_NAME) {
- if (iBaseEncoding == PDFFONT_ENCODING_ADOBE_SYMBOL || iBaseEncoding == PDFFONT_ENCODING_ZAPFDINGBATS) {
- return;
- }
- if ((m_Flags & PDFFONT_SYMBOLIC) && m_BaseFont == FX_BSTRC("Symbol")) {
- if (!bTrueType) {
- iBaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL;
- }
- return;
- }
- CFX_ByteString bsEncoding = pEncoding->GetString();
- if (bsEncoding.Compare(FX_BSTRC("MacExpertEncoding")) == 0) {
- bsEncoding = FX_BSTRC("WinAnsiEncoding");
- }
- GetPredefinedEncoding(iBaseEncoding, bsEncoding);
- return;
- }
- if (pEncoding->GetType() != PDFOBJ_DICTIONARY) {
- return;
- }
- CPDF_Dictionary* pDict = (CPDF_Dictionary*)pEncoding;
- if (iBaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && iBaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS) {
- CFX_ByteString bsEncoding = pDict->GetString(FX_BSTRC("BaseEncoding"));
- if (bsEncoding.Compare(FX_BSTRC("MacExpertEncoding")) == 0 && bTrueType) {
- bsEncoding = FX_BSTRC("WinAnsiEncoding");
- }
- GetPredefinedEncoding(iBaseEncoding, bsEncoding);
- }
- if ((!bEmbedded || bTrueType) && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) {
- iBaseEncoding = PDFFONT_ENCODING_STANDARD;
- }
- CPDF_Array* pDiffs = pDict->GetArray(FX_BSTRC("Differences"));
- if (pDiffs == NULL) {
- return;
- }
- FX_NEW_VECTOR(pCharNames, CFX_ByteString, 256);
- FX_DWORD cur_code = 0;
- for (FX_DWORD i = 0; i < pDiffs->GetCount(); i ++) {
- CPDF_Object* pElement = pDiffs->GetElementValue(i);
- if (pElement == NULL) {
- continue;
- }
- if (pElement->GetType() == PDFOBJ_NAME) {
- if (cur_code < 256) {
- pCharNames[cur_code] = ((CPDF_Name*)pElement)->GetString();
- }
- cur_code ++;
- } else {
- cur_code = pElement->GetInteger();
- }
- }
-}
-FX_BOOL CPDF_Font::IsStandardFont() const
-{
- if (m_FontType != PDFFONT_TYPE1) {
- return FALSE;
- }
- if (m_pFontFile != NULL) {
- return FALSE;
- }
- if (((CPDF_Type1Font*)this)->GetBase14Font() < 0) {
- return FALSE;
- }
- return TRUE;
-}
-extern FX_LPCSTR PDF_CharNameFromPredefinedCharSet(int encoding, FX_BYTE charcode);
-CPDF_SimpleFont::CPDF_SimpleFont()
-{
- FXSYS_memset8(m_CharBBox, 0xff, sizeof m_CharBBox);
- FXSYS_memset8(m_CharWidth, 0xff, sizeof m_CharWidth);
- FXSYS_memset8(m_GlyphIndex, 0xff, sizeof m_GlyphIndex);
- FXSYS_memset8(m_ExtGID, 0xff, sizeof m_ExtGID);
- m_pCharNames = NULL;
- m_BaseEncoding = PDFFONT_ENCODING_BUILTIN;
-}
-CPDF_SimpleFont::~CPDF_SimpleFont()
-{
- if (m_pCharNames) {
- FX_DELETE_VECTOR(m_pCharNames, CFX_ByteString, 256);
- }
-}
-int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph)
-{
- if (pVertGlyph) {
- *pVertGlyph = FALSE;
- }
- if (charcode > 0xff) {
- return -1;
- }
- int index = m_GlyphIndex[(FX_BYTE)charcode];
- if (index == 0xffff) {
- return -1;
- }
- return index;
-}
-void CPDF_SimpleFont::LoadCharMetrics(int charcode)
-{
- if (m_Font.m_Face == NULL) {
- return;
- }
- if (charcode < 0 || charcode > 0xff) {
- return;
- }
- int glyph_index = m_GlyphIndex[charcode];
- if (glyph_index == 0xffff) {
- if (m_pFontFile == NULL && charcode != 32) {
- LoadCharMetrics(32);
- m_CharBBox[charcode] = m_CharBBox[32];
- if (m_bUseFontWidth) {
- m_CharWidth[charcode] = m_CharWidth[32];
- }
- }
- return;
- }
- int err = FXFT_Load_Glyph(m_Font.m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
- if (err) {
- return;
- }
- m_CharBBox[charcode].Left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(m_Font.m_Face), m_Font.m_Face);
- m_CharBBox[charcode].Right = TT2PDF(FXFT_Get_Glyph_HoriBearingX(m_Font.m_Face) + FXFT_Get_Glyph_Width(m_Font.m_Face), m_Font.m_Face);
- m_CharBBox[charcode].Top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(m_Font.m_Face), m_Font.m_Face);
- m_CharBBox[charcode].Bottom = TT2PDF(FXFT_Get_Glyph_HoriBearingY(m_Font.m_Face) - FXFT_Get_Glyph_Height(m_Font.m_Face), m_Font.m_Face);
- if (m_bUseFontWidth) {
- int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(m_Font.m_Face), m_Font.m_Face);
- if (m_CharWidth[charcode] == 0xffff) {
- m_CharWidth[charcode] = TT_Width;
- } else if (TT_Width && !IsEmbedded()) {
- m_CharBBox[charcode].Right = m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width;
- m_CharBBox[charcode].Left = m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width;
- }
- }
-}
-int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level)
-{
- if (charcode > 0xff) {
- charcode = 0;
- }
- if (m_CharWidth[charcode] == 0xffff) {
- LoadCharMetrics(charcode);
- if (m_CharWidth[charcode] == 0xffff) {
- m_CharWidth[charcode] = 0;
- }
- }
- return (FX_INT16)m_CharWidth[charcode];
-}
-void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level)
-{
- if (charcode > 0xff) {
- charcode = 0;
- }
- if (m_CharBBox[charcode].Left == (FX_SHORT)0xffff) {
- LoadCharMetrics(charcode);
- }
- rect.left = m_CharBBox[charcode].Left;
- rect.right = m_CharBBox[charcode].Right;
- rect.bottom = m_CharBBox[charcode].Bottom;
- rect.top = m_CharBBox[charcode].Top;
-}
-FX_LPCSTR GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pCharNames, int charcode)
-{
- ASSERT(charcode >= 0 && charcode < 256);
- if (charcode < 0 || charcode >= 256) {
- return NULL;
- }
- FX_LPCSTR name = NULL;
- if (pCharNames) {
- name = pCharNames[charcode];
- }
- if ((name == NULL || name[0] == 0) && iBaseEncoding) {
- name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode);
- }
- if (name == NULL || name[0] == 0) {
- return NULL;
- }
- return name;
-}
-FX_BOOL CPDF_SimpleFont::LoadCommon()
-{
- CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
- if (pFontDesc) {
- LoadFontDescriptor(pFontDesc);
- }
- CPDF_Array* pWidthArray = m_pFontDict->GetArray(FX_BSTRC("Widths"));
- int width_start = 0, width_end = -1;
- m_bUseFontWidth = TRUE;
- if (pWidthArray) {
- m_bUseFontWidth = FALSE;
- if (pFontDesc && pFontDesc->KeyExist(FX_BSTRC("MissingWidth"))) {
- int MissingWidth = pFontDesc->GetInteger(FX_BSTRC("MissingWidth"));
- for (int i = 0; i < 256; i ++) {
- m_CharWidth[i] = MissingWidth;
- }
- }
- width_start = m_pFontDict->GetInteger(FX_BSTRC("FirstChar"), 0);
- width_end = m_pFontDict->GetInteger(FX_BSTRC("LastChar"), 0);
- if (width_start >= 0 && width_start <= 255) {
- if (width_end <= 0 || width_end >= width_start + (int)pWidthArray->GetCount()) {
- width_end = width_start + pWidthArray->GetCount() - 1;
- }
- if (width_end > 255) {
- width_end = 255;
- }
- for (int i = width_start; i <= width_end; i ++) {
- m_CharWidth[i] = pWidthArray->GetInteger(i - width_start);
- }
- }
- }
- if (m_pFontFile == NULL) {
- LoadSubstFont();
- } else {
- if (m_BaseFont.GetLength() > 8 && m_BaseFont[7] == '+') {
- m_BaseFont = m_BaseFont.Mid(8);
- }
- }
- if (!(m_Flags & PDFFONT_SYMBOLIC)) {
- m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
- }
- CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding"));
- LoadPDFEncoding(pEncoding, m_BaseEncoding, m_pCharNames, m_pFontFile != NULL, m_Font.IsTTFont());
- LoadGlyphMap();
- if (m_pCharNames) {
- FX_DELETE_VECTOR(m_pCharNames, CFX_ByteString, 256);
- m_pCharNames = NULL;
- }
- if (m_Font.m_Face == NULL) {
- return TRUE;
- }
- if (m_Flags & PDFFONT_ALLCAP) {
- unsigned char lowercases[] = {'a', 'z', 0xe0, 0xf6, 0xf8, 0xfd};
- for (int range = 0; range < sizeof lowercases / 2; range ++) {
- for (int i = lowercases[range * 2]; i <= lowercases[range * 2 + 1]; i ++) {
- if (m_GlyphIndex[i] != 0xffff && m_pFontFile != NULL) {
- continue;
- }
- m_GlyphIndex[i] = m_GlyphIndex[i - 32];
- if (m_CharWidth[i - 32]) {
- m_CharWidth[i] = m_CharWidth[i - 32];
- m_CharBBox[i] = m_CharBBox[i - 32];
- }
- }
- }
- }
- CheckFontMetrics();
- return TRUE;
-}
-void CPDF_SimpleFont::LoadSubstFont()
-{
- if (!m_bUseFontWidth && !(m_Flags & PDFFONT_FIXEDPITCH)) {
- int width = 0, i;
- for (i = 0; i < 256; i ++) {
- if (m_CharWidth[i] == 0 || m_CharWidth[i] == 0xffff) {
- continue;
- }
- if (width == 0) {
- width = m_CharWidth[i];
- } else if (width != m_CharWidth[i]) {
- break;
- }
- }
- if (i == 256 && width) {
- m_Flags |= PDFFONT_FIXEDPITCH;
- }
- }
- int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140);
- m_Font.LoadSubst(m_BaseFont, m_FontType == PDFFONT_TRUETYPE, m_Flags, weight, m_ItalicAngle, 0);
- if (m_Font.m_pSubstFont->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) {
- }
-}
-FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const
-{
- return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL &&
- m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS;
-}
-CPDF_Type1Font::CPDF_Type1Font()
-{
- m_Base14Font = -1;
-}
-FX_BOOL CPDF_Type1Font::_Load()
-{
- m_Base14Font = _PDF_GetStandardFontName(m_BaseFont);
- if (m_Base14Font >= 0) {
- CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
- if (pFontDesc && pFontDesc->KeyExist(FX_BSTRC("Flags"))) {
- m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags"));
- } else {
- m_Flags = m_Base14Font >= 12 ? PDFFONT_SYMBOLIC : PDFFONT_NONSYMBOLIC;
- }
- if (m_Base14Font < 4)
- for (int i = 0; i < 256; i ++) {
- m_CharWidth[i] = 600;
- }
- if (m_Base14Font == 12) {
- m_BaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL;
- } else if (m_Base14Font == 13) {
- m_BaseEncoding = PDFFONT_ENCODING_ZAPFDINGBATS;
- } else if (m_Flags & PDFFONT_NONSYMBOLIC) {
- m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
- }
- }
- return LoadCommon();
-}
-static FX_BOOL FT_UseType1Charmap(FXFT_Face face)
-{
- if (FXFT_Get_Face_CharmapCount(face) == 0) {
- return FALSE;
- }
- if (FXFT_Get_Face_CharmapCount(face) == 1 &&
- FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == FXFT_ENCODING_UNICODE) {
- return FALSE;
- }
- if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == FXFT_ENCODING_UNICODE) {
- FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[1]);
- } else {
- FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]);
- }
- return TRUE;
-}
-extern FX_WCHAR FT_UnicodeFromCharCode(int encoding, FX_DWORD charcode);
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
-#include "../../fxge/apple/apple_int.h"
-#endif
-int CPDF_Type1Font::GlyphFromCharCodeExt(FX_DWORD charcode)
-{
- if (charcode > 0xff) {
- return -1;
- }
- int index = m_ExtGID[(FX_BYTE)charcode];
- if (index == 0xffff) {
- return -1;
- }
- return index;
-}
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
-struct _GlyphNameMap {
- FX_LPCSTR m_pStrAdobe;
- FX_LPCSTR m_pStrUnicode;
-};
-static const _GlyphNameMap g_GlyphNameSubsts[] = {
- {"ff", "uniFB00"},
- {"fi", "uniFB01"},
- {"fl", "uniFB02"},
- {"ffi", "uniFB03"},
- {"ffl", "uniFB04"}
-};
-extern "C" {
- static int compareString(const void* key, const void* element)
- {
- return FXSYS_stricmp((FX_LPCSTR)key, ((_GlyphNameMap*)element)->m_pStrAdobe);
- }
-}
-static FX_LPCSTR _GlyphNameRemap(FX_LPCSTR pStrAdobe)
-{
- _GlyphNameMap* found = (_GlyphNameMap*)FXSYS_bsearch(pStrAdobe, g_GlyphNameSubsts,
- sizeof g_GlyphNameSubsts / sizeof(_GlyphNameMap), sizeof(_GlyphNameMap),
- compareString);
- if (found) {
- return found->m_pStrUnicode;
- }
- return NULL;
-}
-#endif
-void CPDF_Type1Font::LoadGlyphMap()
-{
- if (m_Font.m_Face == NULL) {
- return;
- }
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- FX_BOOL bCoreText = TRUE;
- CQuartz2D & quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatformData())->_quartz2d;
- if (!m_Font.m_pPlatformFont) {
- if (m_Font.GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) {
- bCoreText = FALSE;
- }
- m_Font.m_pPlatformFont = quartz2d.CreateFont(m_Font.m_pFontData, m_Font.m_dwSize);
- if (NULL == m_Font.m_pPlatformFont) {
- bCoreText = FALSE;
- }
- }
-#endif
- if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) {
- if (FT_UseTTCharmap(m_Font.m_Face, 3, 0)) {
- FX_BOOL bGotOne = FALSE;
- for (int charcode = 0; charcode < 256; charcode ++) {
- const FX_BYTE prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
- for (int j = 0; j < 4; j ++) {
- FX_WORD unicode = prefix[j] * 256 + charcode;
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
-#endif
- if (m_GlyphIndex[charcode]) {
- bGotOne = TRUE;
- break;
- }
- }
- }
- if (bGotOne) {
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- if (!bCoreText) {
- FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
- }
-#endif
- return;
- }
- }
- FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE);
- if (m_BaseEncoding == 0) {
- m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
- }
- for (int charcode = 0; charcode < 256; charcode ++) {
- FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- continue;
- }
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]);
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
-#endif
- if (m_GlyphIndex[charcode] == 0 && FXSYS_strcmp(name, ".notdef") == 0) {
- m_Encoding.m_Unicodes[charcode] = 0x20;
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, 0x20);
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
-#endif
- }
- }
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- if (!bCoreText) {
- FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
- }
-#endif
- return;
- }
- FT_UseType1Charmap(m_Font.m_Face);
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- if (bCoreText) {
- if (m_Flags & PDFFONT_SYMBOLIC) {
- for (int charcode = 0; charcode < 256; charcode ++) {
- FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name) {
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
- } else {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
- FX_WCHAR unicode = 0;
- if (m_GlyphIndex[charcode]) {
- unicode = FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
- }
- FX_CHAR name_glyph[256];
- FXSYS_memset32(name_glyph, 0, sizeof(name_glyph));
- FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
- name_glyph[255] = 0;
- if (unicode == 0 && name_glyph[0] != 0) {
- unicode = PDF_UnicodeFromAdobeName(name_glyph);
- }
- m_Encoding.m_Unicodes[charcode] = unicode;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
- }
- }
- return;
- }
- FX_BOOL bUnicode = FALSE;
- if (0 == FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE)) {
- bUnicode = TRUE;
- }
- for (int charcode = 0; charcode < 256; charcode ++) {
- FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- continue;
- }
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- FX_LPCSTR pStrUnicode = _GlyphNameRemap(name);
- if (pStrUnicode && 0 == FXFT_Get_Name_Index(m_Font.m_Face, (char*)name)) {
- name = pStrUnicode;
- }
- m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
- if (m_GlyphIndex[charcode] == 0) {
- if (FXSYS_strcmp(name, ".notdef") != 0 && FXSYS_strcmp(name, "space") != 0) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
- } else {
- m_Encoding.m_Unicodes[charcode] = 0x20;
- m_GlyphIndex[charcode] = bUnicode ? FXFT_Get_Char_Index(m_Font.m_Face, 0x20) : 0xffff;
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
- }
- }
- }
- return;
- }
-#endif
- if (m_Flags & PDFFONT_SYMBOLIC) {
- for (int charcode = 0; charcode < 256; charcode ++) {
- FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name) {
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
- } else {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
- if (m_GlyphIndex[charcode]) {
- FX_WCHAR unicode = FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
- if (unicode == 0) {
- FX_CHAR name_glyph[256];
- FXSYS_memset32(name_glyph, 0, sizeof(name_glyph));
- FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
- name_glyph[255] = 0;
- if (name_glyph[0] != 0) {
- unicode = PDF_UnicodeFromAdobeName(name_glyph);
- }
- }
- m_Encoding.m_Unicodes[charcode] = unicode;
- }
- }
- }
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- if (!bCoreText) {
- FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
- }
-#endif
- return;
- }
- FX_BOOL bUnicode = FALSE;
- if (0 == FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE)) {
- bUnicode = TRUE;
- }
- for (int charcode = 0; charcode < 256; charcode ++) {
- FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- continue;
- }
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
- if (m_GlyphIndex[charcode] == 0) {
- if (FXSYS_strcmp(name, ".notdef") != 0 && FXSYS_strcmp(name, "space") != 0) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
- } else {
- m_Encoding.m_Unicodes[charcode] = 0x20;
- m_GlyphIndex[charcode] = 0xffff;
- }
- }
- }
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- if (!bCoreText) {
- FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
- }
-#endif
-}
-CPDF_FontEncoding::CPDF_FontEncoding()
-{
- FXSYS_memset32(m_Unicodes, 0, sizeof(m_Unicodes));
-}
-int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const
-{
- for (int i = 0; i < 256; i ++)
- if (m_Unicodes[i] == unicode) {
- return i;
- }
- return -1;
-}
-CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding)
-{
- const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding);
- if (!pSrc) {
- FXSYS_memset32(m_Unicodes, 0, sizeof(m_Unicodes));
- } else
- for (int i = 0; i < 256; i++) {
- m_Unicodes[i] = pSrc[i];
- }
-}
-FX_BOOL CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const
-{
- return FXSYS_memcmp32(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) == 0;
-}
-CPDF_Object* CPDF_FontEncoding::Realize()
-{
- int predefined = 0;
- for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS; cs ++) {
- const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(cs);
- FX_BOOL match = TRUE;
- for (int i = 0; i < 256; ++i) {
- if (m_Unicodes[i] != pSrc[i]) {
- match = FALSE;
- break;
- }
- }
- if (match) {
- predefined = cs;
- break;
- }
- }
- if (predefined) {
- if (predefined == PDFFONT_ENCODING_WINANSI) {
- return CPDF_Name::Create("WinAnsiEncoding");
- }
- if (predefined == PDFFONT_ENCODING_MACROMAN) {
- return CPDF_Name::Create("MacRomanEncoding");
- }
- if (predefined == PDFFONT_ENCODING_MACEXPERT) {
- return CPDF_Name::Create("MacExpertEncoding");
- }
- return NULL;
- }
- CPDF_Dictionary* pDict = CPDF_Dictionary::Create();
- pDict->SetAtName(FX_BSTRC("BaseEncoding"), FX_BSTRC("WinAnsiEncoding"));
- const FX_WORD* pStandard = PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI);
- CPDF_Array* pDiff = CPDF_Array::Create();
- for (int i = 0; i < 256; i ++) {
- if (pStandard[i] == m_Unicodes[i]) {
- continue;
- }
- pDiff->Add(CPDF_Number::Create(i));
- pDiff->Add(CPDF_Name::Create(PDF_AdobeNameFromUnicode(m_Unicodes[i])));
- }
- pDict->SetAt(FX_BSTRC("Differences"), pDiff);
- return pDict;
-}
-CPDF_TrueTypeFont::CPDF_TrueTypeFont()
-{
-}
-FX_BOOL CPDF_TrueTypeFont::_Load()
-{
- return LoadCommon();
-}
-extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode);
-void CPDF_TrueTypeFont::LoadGlyphMap()
-{
- if (m_Font.m_Face == NULL) {
- return;
- }
- int baseEncoding = m_BaseEncoding;
- if (m_pFontFile && m_Font.m_Face->num_charmaps > 0
- && (baseEncoding == PDFFONT_ENCODING_MACROMAN || baseEncoding == PDFFONT_ENCODING_WINANSI)
- && (m_Flags & PDFFONT_SYMBOLIC)) {
- FX_BOOL bSupportWin = FALSE;
- FX_BOOL bSupportMac = FALSE;
- for (int i = 0; i < FXFT_Get_Face_CharmapCount(m_Font.m_Face); i++) {
- int platform_id = FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]);
- if (platform_id == 0 || platform_id == 3) {
- bSupportWin = TRUE;
- } else if (platform_id == 0 || platform_id == 1) {
- bSupportMac = TRUE;
- }
- }
- if (baseEncoding == PDFFONT_ENCODING_WINANSI && !bSupportWin) {
- baseEncoding = bSupportMac ? PDFFONT_ENCODING_MACROMAN : PDFFONT_ENCODING_BUILTIN;
- } else if (baseEncoding == PDFFONT_ENCODING_MACROMAN && !bSupportMac) {
- baseEncoding = bSupportWin ? PDFFONT_ENCODING_WINANSI : PDFFONT_ENCODING_BUILTIN;
- }
- }
- if (((baseEncoding == PDFFONT_ENCODING_MACROMAN || baseEncoding == PDFFONT_ENCODING_WINANSI)
- && m_pCharNames == NULL) || (m_Flags & PDFFONT_NONSYMBOLIC)) {
- if (!FXFT_Has_Glyph_Names(m_Font.m_Face) && (!m_Font.m_Face->num_charmaps || !m_Font.m_Face->charmaps)) {
- int nStartChar = m_pFontDict->GetInteger(FX_BSTRC("FirstChar"));
- int charcode = 0;
- for (; charcode < nStartChar; charcode ++) {
- m_GlyphIndex[charcode] = 0;
- }
- FX_WORD nGlyph = charcode - nStartChar + 3;
- for (; charcode < 256; charcode ++, nGlyph ++) {
- m_GlyphIndex[charcode] = nGlyph;
- }
- return;
- }
- FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1);
- FX_BOOL bMacRoman = FALSE, bMSSymbol = FALSE;
- if (!bMSUnicode) {
- if (m_Flags & PDFFONT_NONSYMBOLIC) {
- bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0);
- bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.m_Face, 3, 0);
- } else {
- bMSSymbol = FT_UseTTCharmap(m_Font.m_Face, 3, 0);
- bMacRoman = !bMSSymbol && FT_UseTTCharmap(m_Font.m_Face, 1, 0);
- }
- }
- FX_BOOL bToUnicode = m_pFontDict->KeyExist(FX_BSTRC("ToUnicode"));
- for (int charcode = 0; charcode < 256; charcode ++) {
- FX_LPCSTR name = GetAdobeCharName(baseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- m_GlyphIndex[charcode] = m_pFontFile ? FXFT_Get_Char_Index(m_Font.m_Face, charcode) : -1;
- continue;
- }
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- if (bMSSymbol) {
- const FX_BYTE prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
- for (int j = 0; j < 4; j ++) {
- FX_WORD unicode = prefix[j] * 256 + charcode;
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
- if (m_GlyphIndex[charcode]) {
- break;
- }
- }
- } else if (m_Encoding.m_Unicodes[charcode]) {
- if (bMSUnicode) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]);
- } else if (bMacRoman) {
- FX_DWORD maccode = FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, m_Encoding.m_Unicodes[charcode]);
- if (!maccode) {
- m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char *)name);
- } else {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, maccode);
- }
- }
- }
- if ((m_GlyphIndex[charcode] == 0 || m_GlyphIndex[charcode] == 0xffff) && name != NULL) {
- if (name[0] == '.' && FXSYS_strcmp(name, ".notdef") == 0) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, 32);
- } else {
- m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
- if (m_GlyphIndex[charcode] == 0) {
- if (bToUnicode) {
- CFX_WideString wsUnicode = UnicodeFromCharCode(charcode);
- if (!wsUnicode.IsEmpty()) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, wsUnicode[0]);
- m_Encoding.m_Unicodes[charcode] = wsUnicode[0];
- }
- }
- if (m_GlyphIndex[charcode] == 0) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
- }
- }
- }
- }
- }
- return;
- }
- if (FT_UseTTCharmap(m_Font.m_Face, 3, 0)) {
- const FX_BYTE prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
- FX_BOOL bGotOne = FALSE;
- for (int charcode = 0; charcode < 256; charcode ++) {
- for (int j = 0; j < 4; j ++) {
- FX_WORD unicode = prefix[j] * 256 + charcode;
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
- if (m_GlyphIndex[charcode]) {
- bGotOne = TRUE;
- break;
- }
- }
- }
- if (bGotOne) {
- if (baseEncoding != PDFFONT_ENCODING_BUILTIN) {
- for (int charcode = 0; charcode < 256; charcode ++) {
- FX_LPCSTR name = GetAdobeCharName(baseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- continue;
- }
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- }
- } else if (FT_UseTTCharmap(m_Font.m_Face, 1, 0)) {
- for (int charcode = 0; charcode < 256; charcode ++) {
- m_Encoding.m_Unicodes[charcode] = FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
- }
- }
- return;
- }
- }
- if (FT_UseTTCharmap(m_Font.m_Face, 1, 0)) {
- FX_BOOL bGotOne = FALSE;
- for (int charcode = 0; charcode < 256; charcode ++) {
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
- m_Encoding.m_Unicodes[charcode] = FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
- if (m_GlyphIndex[charcode]) {
- bGotOne = TRUE;
- }
- }
- if (m_pFontFile || bGotOne) {
- return;
- }
- }
- if (FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE) == 0) {
- FX_BOOL bGotOne = FALSE;
- const FX_WORD* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding);
- for (int charcode = 0; charcode < 256; charcode ++) {
- if (m_pFontFile == NULL) {
- FX_LPCSTR name = GetAdobeCharName(0, m_pCharNames, charcode);
- if (name != NULL) {
- m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
- } else if (pUnicodes) {
- m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode];
- }
- } else {
- m_Encoding.m_Unicodes[charcode] = charcode;
- }
- m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]);
- if (m_GlyphIndex[charcode]) {
- bGotOne = TRUE;
- }
- }
- if (bGotOne) {
- return;
- }
- }
- for (int charcode = 0; charcode < 256; charcode ++) {
- m_GlyphIndex[charcode] = charcode;
- }
-}
-CPDF_Type3Font::CPDF_Type3Font()
-{
- m_pPageResources = NULL;
- FXSYS_memset32(m_CharWidthL, 0, sizeof m_CharWidthL);
-}
-CPDF_Type3Font::~CPDF_Type3Font()
-{
- FX_POSITION pos = m_CacheMap.GetStartPosition();
- while (pos) {
- FX_LPVOID key, value;
- m_CacheMap.GetNextAssoc(pos, key, value);
- delete (CPDF_Type3Char*)value;
- }
- m_CacheMap.RemoveAll();
- pos = m_DeletedMap.GetStartPosition();
- while (pos) {
- FX_LPVOID key, value;
- m_DeletedMap.GetNextAssoc(pos, key, value);
- delete (CPDF_Type3Char*)key;
- }
-}
-FX_BOOL CPDF_Type3Font::_Load()
-{
- m_pFontResources = m_pFontDict->GetDict(FX_BSTRC("Resources"));
- CPDF_Array* pMatrix = m_pFontDict->GetArray(FX_BSTRC("FontMatrix"));
- FX_FLOAT xscale = 1.0f, yscale = 1.0f;
- if (pMatrix) {
- m_FontMatrix = pMatrix->GetMatrix();
- xscale = m_FontMatrix.a;
- yscale = m_FontMatrix.d;
- }
- CPDF_Array* pBBox = m_pFontDict->GetArray(FX_BSTRC("FontBBox"));
- if (pBBox) {
- m_FontBBox.left = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(0), xscale) * 1000);
- m_FontBBox.bottom = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(1), yscale) * 1000);
- m_FontBBox.right = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(2), xscale) * 1000);
- m_FontBBox.top = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(3), yscale) * 1000);
- }
- int StartChar = m_pFontDict->GetInteger(FX_BSTRC("FirstChar"));
- CPDF_Array* pWidthArray = m_pFontDict->GetArray(FX_BSTRC("Widths"));
- if (pWidthArray && (StartChar >= 0 && StartChar < 256)) {
- FX_DWORD count = pWidthArray->GetCount();
- if (count > 256) {
- count = 256;
- }
- if (StartChar + count > 256) {
- count = 256 - StartChar;
- }
- for (FX_DWORD i = 0; i < count; i ++) {
- m_CharWidthL[StartChar + i] = FXSYS_round(FXSYS_Mul(pWidthArray->GetNumber(i), xscale) * 1000);
- }
- }
- m_pCharProcs = m_pFontDict->GetDict(FX_BSTRC("CharProcs"));
- CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding"));
- if (pEncoding) {
- LoadPDFEncoding(pEncoding, m_BaseEncoding, m_pCharNames, FALSE, FALSE);
- if (m_pCharNames) {
- for (int i = 0; i < 256; i ++) {
- m_Encoding.m_Unicodes[i] = PDF_UnicodeFromAdobeName(m_pCharNames[i]);
- if (m_Encoding.m_Unicodes[i] == 0) {
- m_Encoding.m_Unicodes[i] = i;
- }
- }
- }
- }
- return TRUE;
-}
-void CPDF_Type3Font::CheckType3FontMetrics()
-{
- CheckFontMetrics();
-}
-CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level)
-{
- if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_) {
- return NULL;
- }
- CPDF_Type3Char* pChar = NULL;
- if (m_CacheMap.Lookup((FX_LPVOID)(FX_UINTPTR)charcode, (FX_LPVOID&)pChar)) {
- if (pChar->m_bPageRequired && m_pPageResources) {
- delete pChar;
- m_CacheMap.RemoveKey((FX_LPVOID)(FX_UINTPTR)charcode);
- return LoadChar(charcode, level + 1);
- }
- return pChar;
- }
- FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
- if (name == NULL) {
- return NULL;
- }
- CPDF_Stream* pStream = (CPDF_Stream*)m_pCharProcs->GetElementValue(name);
- if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) {
- return NULL;
- }
- pChar = FX_NEW CPDF_Type3Char;
- pChar->m_pForm = FX_NEW CPDF_Form(m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, pStream, NULL);
- pChar->m_pForm->ParseContent(NULL, NULL, pChar, NULL, level + 1);
- FX_FLOAT scale = m_FontMatrix.GetXUnit();
- pChar->m_Width = (FX_INT32)(pChar->m_Width * scale + 0.5f);
- FX_RECT &rcBBox = pChar->m_BBox;
- CFX_FloatRect char_rect((FX_FLOAT)rcBBox.left / 1000.0f, (FX_FLOAT)rcBBox.bottom / 1000.0f,
- (FX_FLOAT)rcBBox.right / 1000.0f, (FX_FLOAT)rcBBox.top / 1000.0f);
- if (rcBBox.right <= rcBBox.left || rcBBox.bottom >= rcBBox.top) {
- char_rect = pChar->m_pForm->CalcBoundingBox();
- }
- char_rect.Transform(&m_FontMatrix);
- rcBBox.left = FXSYS_round(char_rect.left * 1000);
- rcBBox.right = FXSYS_round(char_rect.right * 1000);
- rcBBox.top = FXSYS_round(char_rect.top * 1000);
- rcBBox.bottom = FXSYS_round(char_rect.bottom * 1000);
- m_CacheMap.SetAt((FX_LPVOID)(FX_UINTPTR)charcode, pChar);
- if (pChar->m_pForm->CountObjects() == 0) {
- delete pChar->m_pForm;
- pChar->m_pForm = NULL;
- }
- return pChar;
-}
-int CPDF_Type3Font::GetCharWidthF(FX_DWORD charcode, int level)
-{
- if (charcode > 0xff) {
- charcode = 0;
- }
- if (m_CharWidthL[charcode]) {
- return m_CharWidthL[charcode];
- }
- CPDF_Type3Char* pChar = LoadChar(charcode, level);
- if (pChar == NULL) {
- return 0;
- }
- return pChar->m_Width;
-}
-void CPDF_Type3Font::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level)
-{
- CPDF_Type3Char* pChar = LoadChar(charcode, level);
- if (pChar == NULL) {
- rect.left = rect.right = rect.top = rect.bottom = 0;
- return;
- }
- rect = pChar->m_BBox;
-}
-CPDF_Type3Char::CPDF_Type3Char()
-{
- m_pForm = NULL;
- m_pBitmap = NULL;
- m_bPageRequired = FALSE;
- m_bColored = FALSE;
-}
-CPDF_Type3Char::~CPDF_Type3Char()
-{
- if (m_pForm) {
- delete m_pForm;
- }
- if (m_pBitmap) {
- delete m_pBitmap;
- }
-}
+// 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
+
+#include "../../../include/fpdfapi/fpdf_page.h"
+#include "../../../include/fpdfapi/fpdf_module.h"
+#include "../../../include/fpdfapi/fpdf_pageobj.h"
+#include "font_int.h"
+#include "../fpdf_page/pageint.h"
+#include "../../../include/fxge/fx_freetype.h"
+FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id)
+{
+ for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i ++) {
+ if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == platform_id &&
+ FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == encoding_id) {
+ FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[i]);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+extern const FX_WORD* PDF_UnicodesForPredefinedCharSet(int);
+CPDF_FontGlobals::CPDF_FontGlobals()
+{
+ FXSYS_memset32(m_EmbeddedCharsets, 0, sizeof m_EmbeddedCharsets);
+ FXSYS_memset32(m_EmbeddedToUnicodes, 0, sizeof m_EmbeddedToUnicodes);
+ m_pContrastRamps = NULL;
+}
+CPDF_FontGlobals::~CPDF_FontGlobals()
+{
+ ClearAll();
+ if (m_pContrastRamps) {
+ FX_Free(m_pContrastRamps);
+ }
+}
+class CFX_StockFontArray : public CFX_Object
+{
+public:
+ CFX_StockFontArray()
+ {
+ FXSYS_memset32(m_pStockFonts, 0, sizeof(CPDF_Font*) * 14);
+ }
+ CPDF_Font* m_pStockFonts[14];
+};
+CPDF_Font* CPDF_FontGlobals::Find(void* key, int index)
+{
+ void* value = NULL;
+ if (!m_pStockMap.Lookup(key, value)) {
+ return NULL;
+ }
+ if (!value) {
+ return NULL;
+ }
+ return ((CFX_StockFontArray*)value)->m_pStockFonts[index];
+}
+void CPDF_FontGlobals::Set(void* key, int index, CPDF_Font* pFont)
+{
+ void* value = NULL;
+ if (m_pStockMap.Lookup(key, value)) {
+ ((CFX_StockFontArray*)value)->m_pStockFonts[index] = pFont;
+ return;
+ }
+ CFX_StockFontArray* pFonts = FX_NEW CFX_StockFontArray();
+ if (pFonts) {
+ pFonts->m_pStockFonts[index] = pFont;
+ }
+ m_pStockMap.SetAt(key, pFonts);
+}
+void CPDF_FontGlobals::Clear(void* key)
+{
+ void* value = NULL;
+ if (!m_pStockMap.Lookup(key, value)) {
+ return;
+ }
+ if (value) {
+ CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value;
+ for (int i = 0; i < 14; i ++) {
+ if (pStockFonts->m_pStockFonts[i]) {
+ pStockFonts->m_pStockFonts[i]->GetFontDict()->Release();
+ delete pStockFonts->m_pStockFonts[i];
+ }
+ }
+ delete pStockFonts;
+ }
+ m_pStockMap.RemoveKey(key);
+}
+void CPDF_FontGlobals::ClearAll()
+{
+ FX_POSITION pos = m_pStockMap.GetStartPosition();
+ while (pos) {
+ void *key = NULL;
+ void* value = NULL;
+ m_pStockMap.GetNextAssoc(pos, key, value);
+ if (value) {
+ CFX_StockFontArray* pStockFonts = (CFX_StockFontArray*)value;
+ for (int i = 0; i < 14; i ++) {
+ if (pStockFonts->m_pStockFonts[i]) {
+ pStockFonts->m_pStockFonts[i]->GetFontDict()->Release();
+ delete pStockFonts->m_pStockFonts[i];
+ }
+ }
+ delete pStockFonts;
+ }
+ m_pStockMap.RemoveKey(key);
+ }
+}
+CPDF_Font::CPDF_Font()
+{
+ m_FontType = 0;
+ m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0;
+ m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0;
+ m_pFontFile = NULL;
+ m_Flags = 0;
+ m_pToUnicodeMap = NULL;
+ m_bToUnicodeLoaded = FALSE;
+ m_pCharMap = NULL;
+}
+FX_BOOL CPDF_Font::Initialize()
+{
+ m_pCharMap = FX_NEW CPDF_FontCharMap(this);
+ return TRUE;
+}
+CPDF_Font::~CPDF_Font()
+{
+ if (m_pCharMap) {
+ FX_Free(m_pCharMap);
+ m_pCharMap = NULL;
+ }
+ if (m_pToUnicodeMap) {
+ delete m_pToUnicodeMap;
+ m_pToUnicodeMap = NULL;
+ }
+ if (m_pFontFile) {
+ m_pDocument->GetPageData()->ReleaseFontFileStreamAcc((CPDF_Stream*)m_pFontFile->GetStream());
+ }
+}
+FX_BOOL CPDF_Font::IsVertWriting() const
+{
+ FX_BOOL bVertWriting = FALSE;
+ CPDF_CIDFont* pCIDFont = GetCIDFont();
+ if (pCIDFont) {
+ bVertWriting = pCIDFont->IsVertWriting();
+ } else {
+ bVertWriting = m_Font.IsVertical();
+ }
+ return bVertWriting;
+}
+CFX_ByteString CPDF_Font::GetFontTypeName() const
+{
+ switch (m_FontType) {
+ case PDFFONT_TYPE1:
+ return FX_BSTRC("Type1");
+ case PDFFONT_TRUETYPE:
+ return FX_BSTRC("TrueType");
+ case PDFFONT_TYPE3:
+ return FX_BSTRC("Type3");
+ case PDFFONT_CIDFONT:
+ return FX_BSTRC("Type0");
+ }
+ return CFX_ByteString();
+}
+void CPDF_Font::AppendChar(CFX_ByteString& str, FX_DWORD charcode) const
+{
+ char buf[4];
+ int len = AppendChar(buf, charcode);
+ if (len == 1) {
+ str += buf[0];
+ } else {
+ str += CFX_ByteString(buf, len);
+ }
+}
+CFX_WideString CPDF_Font::UnicodeFromCharCode(FX_DWORD charcode) const
+{
+ if (!m_bToUnicodeLoaded) {
+ ((CPDF_Font*)this)->LoadUnicodeMap();
+ }
+ if (m_pToUnicodeMap) {
+ CFX_WideString wsRet = m_pToUnicodeMap->Lookup(charcode);
+ if (!wsRet.IsEmpty()) {
+ return wsRet;
+ }
+ }
+ FX_WCHAR unicode = _UnicodeFromCharCode(charcode);
+ if (unicode == 0) {
+ return CFX_WideString();
+ }
+ return unicode;
+}
+FX_DWORD CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const
+{
+ if (!m_bToUnicodeLoaded) {
+ ((CPDF_Font*)this)->LoadUnicodeMap();
+ }
+ if (m_pToUnicodeMap) {
+ FX_DWORD charcode = m_pToUnicodeMap->ReverseLookup(unicode);
+ if (charcode) {
+ return charcode;
+ }
+ }
+ return _CharCodeFromUnicode(unicode);
+}
+CFX_WideString CPDF_Font::DecodeString(const CFX_ByteString& str) const
+{
+ CFX_WideString result;
+ int src_len = str.GetLength();
+ result.Reserve(src_len);
+ FX_LPCSTR src_buf = str;
+ int src_pos = 0;
+ while (src_pos < src_len) {
+ FX_DWORD charcode = GetNextChar(src_buf, src_pos);
+ CFX_WideString unicode = UnicodeFromCharCode(charcode);
+ if (!unicode.IsEmpty()) {
+ result += unicode;
+ } else {
+ result += (FX_WCHAR)charcode;
+ }
+ }
+ return result;
+}
+CFX_ByteString CPDF_Font::EncodeString(const CFX_WideString& str) const
+{
+ CFX_ByteString result;
+ int src_len = str.GetLength();
+ FX_LPSTR dest_buf = result.GetBuffer(src_len * 2);
+ FX_LPCWSTR src_buf = str;
+ int dest_pos = 0;
+ for (int src_pos = 0; src_pos < src_len; src_pos ++) {
+ FX_DWORD charcode = CharCodeFromUnicode(src_buf[src_pos]);
+ dest_pos += AppendChar(dest_buf + dest_pos, charcode);
+ }
+ result.ReleaseBuffer(dest_pos);
+ return result;
+}
+void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc)
+{
+ m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags"), PDFFONT_NONSYMBOLIC);
+ int ItalicAngle = 0;
+ FX_BOOL bExistItalicAngle = FALSE;
+ if (pFontDesc->KeyExist(FX_BSTRC("ItalicAngle"))) {
+ ItalicAngle = pFontDesc->GetInteger(FX_BSTRC("ItalicAngle"));
+ bExistItalicAngle = TRUE;
+ }
+ if (ItalicAngle < 0) {
+ m_Flags |= PDFFONT_ITALIC;
+ m_ItalicAngle = ItalicAngle;
+ }
+ FX_BOOL bExistStemV = FALSE;
+ if (pFontDesc->KeyExist(FX_BSTRC("StemV"))) {
+ m_StemV = pFontDesc->GetInteger(FX_BSTRC("StemV"));
+ bExistStemV = TRUE;
+ }
+ FX_BOOL bExistAscent = FALSE;
+ if (pFontDesc->KeyExist(FX_BSTRC("Ascent"))) {
+ m_Ascent = pFontDesc->GetInteger(FX_BSTRC("Ascent"));
+ bExistAscent = TRUE;
+ }
+ FX_BOOL bExistDescent = FALSE;
+ if (pFontDesc->KeyExist(FX_BSTRC("Descent"))) {
+ m_Descent = pFontDesc->GetInteger(FX_BSTRC("Descent"));
+ bExistDescent = TRUE;
+ }
+ FX_BOOL bExistCapHeight = FALSE;
+ if (pFontDesc->KeyExist(FX_BSTRC("CapHeight"))) {
+ bExistCapHeight = TRUE;
+ }
+ if (bExistItalicAngle && bExistAscent && bExistCapHeight && bExistDescent && bExistStemV) {
+ m_Flags |= PDFFONT_USEEXTERNATTR;
+ }
+ if (m_Descent > 10) {
+ m_Descent = -m_Descent;
+ }
+ CPDF_Array* pBBox = pFontDesc->GetArray(FX_BSTRC("FontBBox"));
+ if (pBBox) {
+ m_FontBBox.left = pBBox->GetInteger(0);
+ m_FontBBox.bottom = pBBox->GetInteger(1);
+ m_FontBBox.right = pBBox->GetInteger(2);
+ m_FontBBox.top = pBBox->GetInteger(3);
+ }
+ CPDF_Stream* pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile"));
+ if (pFontFile == NULL) {
+ pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile2"));
+ }
+ if (pFontFile == NULL) {
+ pFontFile = pFontDesc->GetStream(FX_BSTRC("FontFile3"));
+ }
+ if (pFontFile) {
+ m_pFontFile = m_pDocument->LoadFontFile(pFontFile);
+ if (m_pFontFile == NULL) {
+ return;
+ }
+ FX_LPCBYTE pFontData = m_pFontFile->GetData();
+ FX_DWORD dwFontSize = m_pFontFile->GetSize();
+ m_Font.LoadEmbedded(pFontData, dwFontSize);
+ if (m_Font.m_Face == NULL) {
+ m_pFontFile = NULL;
+ }
+ }
+}
+short TT2PDF(int m, FXFT_Face face)
+{
+ int upm = FXFT_Get_Face_UnitsPerEM(face);
+ if (upm == 0) {
+ return (short)m;
+ }
+ return (m * 1000 + upm / 2) / upm;
+}
+void CPDF_Font::CheckFontMetrics()
+{
+ if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 && m_FontBBox.right == 0) {
+ if (m_Font.m_Face) {
+ m_FontBBox.left = TT2PDF(FXFT_Get_Face_xMin(m_Font.m_Face), m_Font.m_Face);
+ m_FontBBox.bottom = TT2PDF(FXFT_Get_Face_yMin(m_Font.m_Face), m_Font.m_Face);
+ m_FontBBox.right = TT2PDF(FXFT_Get_Face_xMax(m_Font.m_Face), m_Font.m_Face);
+ m_FontBBox.top = TT2PDF(FXFT_Get_Face_yMax(m_Font.m_Face), m_Font.m_Face);
+ m_Ascent = TT2PDF(FXFT_Get_Face_Ascender(m_Font.m_Face), m_Font.m_Face);
+ m_Descent = TT2PDF(FXFT_Get_Face_Descender(m_Font.m_Face), m_Font.m_Face);
+ } else {
+ FX_BOOL bFirst = TRUE;
+ for (int i = 0; i < 256; i ++) {
+ FX_RECT rect;
+ GetCharBBox(i, rect);
+ if (rect.left == rect.right) {
+ continue;
+ }
+ if (bFirst) {
+ m_FontBBox = rect;
+ bFirst = FALSE;
+ } else {
+ if (m_FontBBox.top < rect.top) {
+ m_FontBBox.top = rect.top;
+ }
+ if (m_FontBBox.right < rect.right) {
+ m_FontBBox.right = rect.right;
+ }
+ if (m_FontBBox.left > rect.left) {
+ m_FontBBox.left = rect.left;
+ }
+ if (m_FontBBox.bottom > rect.bottom) {
+ m_FontBBox.bottom = rect.bottom;
+ }
+ }
+ }
+ }
+ }
+ if (m_Ascent == 0 && m_Descent == 0) {
+ FX_RECT rect;
+ GetCharBBox('A', rect);
+ if (rect.bottom == rect.top) {
+ m_Ascent = m_FontBBox.top;
+ } else {
+ m_Ascent = rect.top;
+ }
+ GetCharBBox('g', rect);
+ if (rect.bottom == rect.top) {
+ m_Descent = m_FontBBox.bottom;
+ } else {
+ m_Descent = rect.bottom;
+ }
+ }
+}
+void CPDF_Font::LoadUnicodeMap()
+{
+ m_bToUnicodeLoaded = TRUE;
+ CPDF_Stream* pStream = m_pFontDict->GetStream(FX_BSTRC("ToUnicode"));
+ if (pStream == NULL) {
+ return;
+ }
+ m_pToUnicodeMap = FX_NEW CPDF_ToUnicodeMap;
+ m_pToUnicodeMap->Load(pStream);
+}
+int CPDF_Font::GetStringWidth(FX_LPCSTR pString, int size)
+{
+ int offset = 0;
+ int width = 0;
+ while (offset < size) {
+ FX_DWORD charcode = GetNextChar(pString, offset);
+ width += GetCharWidthF(charcode);
+ }
+ return width;
+}
+int CPDF_Font::GetCharTypeWidth(FX_DWORD charcode)
+{
+ if (m_Font.m_Face == NULL) {
+ return 0;
+ }
+ int glyph_index = GlyphFromCharCode(charcode);
+ if (glyph_index == 0xffff) {
+ return 0;
+ }
+ return m_Font.GetGlyphWidth(glyph_index);
+}
+int _PDF_GetStandardFontName(CFX_ByteString& name);
+CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, FX_BSTR name)
+{
+ CFX_ByteString fontname(name);
+ int font_id = _PDF_GetStandardFontName(fontname);
+ if (font_id < 0) {
+ return NULL;
+ }
+ CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
+ CPDF_Font* pFont = pFontGlobals->Find(pDoc, font_id);
+ if (pFont) {
+ return pFont;
+ }
+ CPDF_Dictionary* pDict = CPDF_Dictionary::Create();
+ pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("Font"));
+ pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Type1"));
+ pDict->SetAtName(FX_BSTRC("BaseFont"), fontname);
+ pDict->SetAtName(FX_BSTRC("Encoding"), FX_BSTRC("WinAnsiEncoding"));
+ pFont = CPDF_Font::CreateFontF(NULL, pDict);
+ pFontGlobals->Set(pDoc, font_id, pFont);
+ return pFont;
+}
+const FX_BYTE ChineseFontNames[][5] = {
+ {0xCB, 0xCE, 0xCC, 0xE5, 0x00},
+ {0xBF, 0xAC, 0xCC, 0xE5, 0x00},
+ {0xBA, 0xDA, 0xCC, 0xE5, 0x00},
+ {0xB7, 0xC2, 0xCB, 0xCE, 0x00},
+ {0xD0, 0xC2, 0xCB, 0xCE, 0x00}
+};
+CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict)
+{
+ CFX_ByteString type = pFontDict->GetString(FX_BSTRC("Subtype"));
+ CPDF_Font* pFont;
+ if (type == FX_BSTRC("TrueType")) {
+ {
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ || _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ CFX_ByteString basefont = pFontDict->GetString(FX_BSTRC("BaseFont"));
+ CFX_ByteString tag = basefont.Left(4);
+ int i;
+ int count = sizeof(ChineseFontNames) / sizeof(ChineseFontNames[0]);
+ for (i = 0; i < count; ++i) {
+ if (tag == CFX_ByteString((FX_LPCSTR)ChineseFontNames[i])) {
+ break;
+ }
+ }
+ if (i < count) {
+ CPDF_Dictionary* pFontDesc = pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
+ if (pFontDesc == NULL || !pFontDesc->KeyExist(FX_BSTRC("FontFile2"))) {
+ pFont = FX_NEW CPDF_CIDFont;
+ pFont->Initialize();
+ pFont->m_FontType = PDFFONT_CIDFONT;
+ pFont->m_pFontDict = pFontDict;
+ pFont->m_pDocument = pDoc;
+ if (!pFont->Load()) {
+ delete pFont;
+ return NULL;
+ }
+ return pFont;
+ }
+ }
+#endif
+ }
+ pFont = FX_NEW CPDF_TrueTypeFont;
+ pFont->Initialize();
+ pFont->m_FontType = PDFFONT_TRUETYPE;
+ } else if (type == FX_BSTRC("Type3")) {
+ pFont = FX_NEW CPDF_Type3Font;
+ pFont->Initialize();
+ pFont->m_FontType = PDFFONT_TYPE3;
+ } else if (type == FX_BSTRC("Type0")) {
+ pFont = FX_NEW CPDF_CIDFont;
+ pFont->Initialize();
+ pFont->m_FontType = PDFFONT_CIDFONT;
+ } else {
+ pFont = FX_NEW CPDF_Type1Font;
+ pFont->Initialize();
+ pFont->m_FontType = PDFFONT_TYPE1;
+ }
+ pFont->m_pFontDict = pFontDict;
+ pFont->m_pDocument = pDoc;
+ if (!pFont->Load()) {
+ delete pFont;
+ return NULL;
+ }
+ return pFont;
+}
+FX_BOOL CPDF_Font::Load()
+{
+ if (m_pFontDict == NULL) {
+ return FALSE;
+ }
+ CFX_ByteString type = m_pFontDict->GetString(FX_BSTRC("Subtype"));
+ m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont"));
+ if (type == FX_BSTRC("MMType1")) {
+ type = FX_BSTRC("Type1");
+ }
+ return _Load();
+}
+static CFX_WideString _FontMap_GetWideString(CFX_CharMap* pMap, const CFX_ByteString& bytestr)
+{
+ return ((CPDF_FontCharMap*)pMap)->m_pFont->DecodeString(bytestr);
+}
+static CFX_ByteString _FontMap_GetByteString(CFX_CharMap* pMap, const CFX_WideString& widestr)
+{
+ return ((CPDF_FontCharMap*)pMap)->m_pFont->EncodeString(widestr);
+}
+CPDF_FontCharMap::CPDF_FontCharMap(CPDF_Font* pFont)
+{
+ m_GetByteString = _FontMap_GetByteString;
+ m_GetWideString = _FontMap_GetWideString;
+ m_pFont = pFont;
+}
+CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode)
+{
+ FX_DWORD value;
+ if (m_Map.Lookup(charcode, value)) {
+ FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff);
+ if (unicode != 0xffff) {
+ return unicode;
+ }
+ FX_LPCWSTR buf = m_MultiCharBuf.GetBuffer();
+ FX_DWORD buf_len = m_MultiCharBuf.GetLength();
+ if (buf == NULL || buf_len == 0) {
+ return CFX_WideString();
+ }
+ FX_DWORD index = value >> 16;
+ if (index >= buf_len) {
+ return CFX_WideString();
+ }
+ FX_DWORD len = buf[index];
+ if (index + len < index || index + len >= buf_len) {
+ return CFX_WideString();
+ }
+ return CFX_WideString(buf + index + 1, len);
+ }
+ if (m_pBaseMap) {
+ return m_pBaseMap->UnicodeFromCID((FX_WORD)charcode);
+ }
+ return CFX_WideString();
+}
+FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode)
+{
+ FX_POSITION pos = m_Map.GetStartPosition();
+ while (pos) {
+ FX_DWORD key, value;
+ m_Map.GetNextAssoc(pos, key, value);
+ if ((FX_WCHAR)value == unicode) {
+ return key;
+ }
+ }
+ return 0;
+}
+static FX_DWORD _StringToCode(FX_BSTR str)
+{
+ FX_LPCSTR buf = str.GetCStr();
+ int len = str.GetLength();
+ if (len == 0) {
+ return 0;
+ }
+ int result = 0;
+ if (buf[0] == '<') {
+ for (int i = 1; i < len; i ++) {
+ int digit;
+ if (buf[i] >= '0' && buf[i] <= '9') {
+ digit = buf[i] - '0';
+ } else if (buf[i] >= 'a' && buf[i] <= 'f') {
+ digit = buf[i] - 'a' + 10;
+ } else if (buf[i] >= 'A' && buf[i] <= 'F') {
+ digit = buf[i] - 'A' + 10;
+ } else {
+ break;
+ }
+ result = result * 16 + digit;
+ }
+ return result;
+ } else {
+ for (int i = 0; i < len; i ++) {
+ if (buf[i] < '0' || buf[i] > '9') {
+ break;
+ }
+ result = result * 10 + buf[i] - '0';
+ }
+ }
+ return result;
+}
+static CFX_WideString _StringDataAdd(CFX_WideString str)
+{
+ CFX_WideString ret;
+ int len = str.GetLength();
+ FX_WCHAR value = 1;
+ for (int i = len - 1; i >= 0 ; --i) {
+ FX_WCHAR ch = str[i] + value;
+ if (ch < str[i]) {
+ ret.Insert(0, 0);
+ } else {
+ ret.Insert(0, ch);
+ value = 0;
+ }
+ }
+ if (value) {
+ ret.Insert(0, value);
+ }
+ return ret;
+}
+static CFX_WideString _StringToWideString(FX_BSTR str)
+{
+ FX_LPCSTR buf = str.GetCStr();
+ int len = str.GetLength();
+ if (len == 0) {
+ return CFX_WideString();
+ }
+ CFX_WideString result;
+ if (buf[0] == '<') {
+ int byte_pos = 0;
+ FX_WCHAR ch = 0;
+ for (int i = 1; i < len; i ++) {
+ int digit;
+ if (buf[i] >= '0' && buf[i] <= '9') {
+ digit = buf[i] - '0';
+ } else if (buf[i] >= 'a' && buf[i] <= 'f') {
+ digit = buf[i] - 'a' + 10;
+ } else if (buf[i] >= 'A' && buf[i] <= 'F') {
+ digit = buf[i] - 'A' + 10;
+ } else {
+ break;
+ }
+ ch = ch * 16 + digit;
+ byte_pos ++;
+ if (byte_pos == 4) {
+ result += ch;
+ byte_pos = 0;
+ ch = 0;
+ }
+ }
+ return result;
+ }
+ if (buf[0] == '(') {
+ }
+ return result;
+}
+void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream)
+{
+ int CIDSet = 0;
+ CPDF_StreamAcc stream;
+ stream.LoadAllData(pStream, FALSE);
+ CPDF_SimpleParser parser(stream.GetData(), stream.GetSize());
+ m_Map.EstimateSize(stream.GetSize() / 8, 1024);
+ while (1) {
+ CFX_ByteStringC word = parser.GetWord();
+ if (word.IsEmpty()) {
+ break;
+ }
+ if (word == FX_BSTRC("beginbfchar")) {
+ while (1) {
+ word = parser.GetWord();
+ if (word.IsEmpty() || word == FX_BSTRC("endbfchar")) {
+ break;
+ }
+ FX_DWORD srccode = _StringToCode(word);
+ word = parser.GetWord();
+ CFX_WideString destcode = _StringToWideString(word);
+ int len = destcode.GetLength();
+ if (len == 0) {
+ continue;
+ }
+ if (len == 1) {
+ m_Map.SetAt(srccode, destcode.GetAt(0));
+ } else {
+ m_Map.SetAt(srccode, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff);
+ m_MultiCharBuf.AppendChar(destcode.GetLength());
+ m_MultiCharBuf << destcode;
+ }
+ }
+ } else if (word == FX_BSTRC("beginbfrange")) {
+ while (1) {
+ CFX_ByteString low, high;
+ low = parser.GetWord();
+ if (low.IsEmpty() || low == FX_BSTRC("endbfrange")) {
+ break;
+ }
+ high = parser.GetWord();
+ FX_DWORD lowcode = _StringToCode(low);
+ FX_DWORD highcode = (lowcode & 0xffffff00) | (_StringToCode(high) & 0xff);
+ if (highcode == (FX_DWORD) - 1) {
+ break;
+ }
+ CFX_ByteString start = parser.GetWord();
+ if (start == FX_BSTRC("[")) {
+ for (FX_DWORD code = lowcode; code <= highcode; code ++) {
+ CFX_ByteString dest = parser.GetWord();
+ CFX_WideString destcode = _StringToWideString(dest);
+ int len = destcode.GetLength();
+ if (len == 0) {
+ continue;
+ }
+ if (len == 1) {
+ m_Map.SetAt(code, destcode.GetAt(0));
+ } else {
+ m_Map.SetAt(code, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff);
+ m_MultiCharBuf.AppendChar(destcode.GetLength());
+ m_MultiCharBuf << destcode;
+ }
+ }
+ parser.GetWord();
+ } else {
+ CFX_WideString destcode = _StringToWideString(start);
+ int len = destcode.GetLength();
+ FX_DWORD value = 0;
+ if (len == 1) {
+ value = _StringToCode(start);
+ for (FX_DWORD code = lowcode; code <= highcode; code ++) {
+ m_Map.SetAt(code, value++);
+ }
+ } else {
+ for (FX_DWORD code = lowcode; code <= highcode; code ++) {
+ CFX_WideString retcode;
+ if (code == lowcode) {
+ retcode = destcode;
+ } else {
+ retcode = _StringDataAdd(destcode);
+ }
+ m_Map.SetAt(code, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff);
+ m_MultiCharBuf.AppendChar(retcode.GetLength());
+ m_MultiCharBuf << retcode;
+ destcode = retcode;
+ }
+ }
+ }
+ }
+ } else if (word == FX_BSTRC("/Adobe-Korea1-UCS2")) {
+ CIDSet = CIDSET_KOREA1;
+ } else if (word == FX_BSTRC("/Adobe-Japan1-UCS2")) {
+ CIDSet = CIDSET_JAPAN1;
+ } else if (word == FX_BSTRC("/Adobe-CNS1-UCS2")) {
+ CIDSet = CIDSET_CNS1;
+ } else if (word == FX_BSTRC("/Adobe-GB1-UCS2")) {
+ CIDSet = CIDSET_GB1;
+ }
+ }
+ if (CIDSet) {
+ m_pBaseMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetCID2UnicodeMap(CIDSet, FALSE);
+ } else {
+ m_pBaseMap = NULL;
+ }
+}
+static FX_BOOL GetPredefinedEncoding(int& basemap, const CFX_ByteString& value)
+{
+ if (value == FX_BSTRC("WinAnsiEncoding")) {
+ basemap = PDFFONT_ENCODING_WINANSI;
+ } else if (value == FX_BSTRC("MacRomanEncoding")) {
+ basemap = PDFFONT_ENCODING_MACROMAN;
+ } else if (value == FX_BSTRC("MacExpertEncoding")) {
+ basemap = PDFFONT_ENCODING_MACEXPERT;
+ } else if (value == FX_BSTRC("PDFDocEncoding")) {
+ basemap = PDFFONT_ENCODING_PDFDOC;
+ } else {
+ return FALSE;
+ }
+ return TRUE;
+}
+void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, CFX_ByteString*& pCharNames,
+ FX_BOOL bEmbedded, FX_BOOL bTrueType)
+{
+ if (pEncoding == NULL) {
+ if (m_BaseFont == FX_BSTRC("Symbol")) {
+ iBaseEncoding = bTrueType ? PDFFONT_ENCODING_MS_SYMBOL : PDFFONT_ENCODING_ADOBE_SYMBOL;
+ } else if (!bEmbedded && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) {
+ iBaseEncoding = PDFFONT_ENCODING_WINANSI;
+ }
+ return;
+ }
+ if (pEncoding->GetType() == PDFOBJ_NAME) {
+ if (iBaseEncoding == PDFFONT_ENCODING_ADOBE_SYMBOL || iBaseEncoding == PDFFONT_ENCODING_ZAPFDINGBATS) {
+ return;
+ }
+ if ((m_Flags & PDFFONT_SYMBOLIC) && m_BaseFont == FX_BSTRC("Symbol")) {
+ if (!bTrueType) {
+ iBaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL;
+ }
+ return;
+ }
+ CFX_ByteString bsEncoding = pEncoding->GetString();
+ if (bsEncoding.Compare(FX_BSTRC("MacExpertEncoding")) == 0) {
+ bsEncoding = FX_BSTRC("WinAnsiEncoding");
+ }
+ GetPredefinedEncoding(iBaseEncoding, bsEncoding);
+ return;
+ }
+ if (pEncoding->GetType() != PDFOBJ_DICTIONARY) {
+ return;
+ }
+ CPDF_Dictionary* pDict = (CPDF_Dictionary*)pEncoding;
+ if (iBaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && iBaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS) {
+ CFX_ByteString bsEncoding = pDict->GetString(FX_BSTRC("BaseEncoding"));
+ if (bsEncoding.Compare(FX_BSTRC("MacExpertEncoding")) == 0 && bTrueType) {
+ bsEncoding = FX_BSTRC("WinAnsiEncoding");
+ }
+ GetPredefinedEncoding(iBaseEncoding, bsEncoding);
+ }
+ if ((!bEmbedded || bTrueType) && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) {
+ iBaseEncoding = PDFFONT_ENCODING_STANDARD;
+ }
+ CPDF_Array* pDiffs = pDict->GetArray(FX_BSTRC("Differences"));
+ if (pDiffs == NULL) {
+ return;
+ }
+ FX_NEW_VECTOR(pCharNames, CFX_ByteString, 256);
+ FX_DWORD cur_code = 0;
+ for (FX_DWORD i = 0; i < pDiffs->GetCount(); i ++) {
+ CPDF_Object* pElement = pDiffs->GetElementValue(i);
+ if (pElement == NULL) {
+ continue;
+ }
+ if (pElement->GetType() == PDFOBJ_NAME) {
+ if (cur_code < 256) {
+ pCharNames[cur_code] = ((CPDF_Name*)pElement)->GetString();
+ }
+ cur_code ++;
+ } else {
+ cur_code = pElement->GetInteger();
+ }
+ }
+}
+FX_BOOL CPDF_Font::IsStandardFont() const
+{
+ if (m_FontType != PDFFONT_TYPE1) {
+ return FALSE;
+ }
+ if (m_pFontFile != NULL) {
+ return FALSE;
+ }
+ if (((CPDF_Type1Font*)this)->GetBase14Font() < 0) {
+ return FALSE;
+ }
+ return TRUE;
+}
+extern FX_LPCSTR PDF_CharNameFromPredefinedCharSet(int encoding, FX_BYTE charcode);
+CPDF_SimpleFont::CPDF_SimpleFont()
+{
+ FXSYS_memset8(m_CharBBox, 0xff, sizeof m_CharBBox);
+ FXSYS_memset8(m_CharWidth, 0xff, sizeof m_CharWidth);
+ FXSYS_memset8(m_GlyphIndex, 0xff, sizeof m_GlyphIndex);
+ FXSYS_memset8(m_ExtGID, 0xff, sizeof m_ExtGID);
+ m_pCharNames = NULL;
+ m_BaseEncoding = PDFFONT_ENCODING_BUILTIN;
+}
+CPDF_SimpleFont::~CPDF_SimpleFont()
+{
+ if (m_pCharNames) {
+ FX_DELETE_VECTOR(m_pCharNames, CFX_ByteString, 256);
+ }
+}
+int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph)
+{
+ if (pVertGlyph) {
+ *pVertGlyph = FALSE;
+ }
+ if (charcode > 0xff) {
+ return -1;
+ }
+ int index = m_GlyphIndex[(FX_BYTE)charcode];
+ if (index == 0xffff) {
+ return -1;
+ }
+ return index;
+}
+void CPDF_SimpleFont::LoadCharMetrics(int charcode)
+{
+ if (m_Font.m_Face == NULL) {
+ return;
+ }
+ if (charcode < 0 || charcode > 0xff) {
+ return;
+ }
+ int glyph_index = m_GlyphIndex[charcode];
+ if (glyph_index == 0xffff) {
+ if (m_pFontFile == NULL && charcode != 32) {
+ LoadCharMetrics(32);
+ m_CharBBox[charcode] = m_CharBBox[32];
+ if (m_bUseFontWidth) {
+ m_CharWidth[charcode] = m_CharWidth[32];
+ }
+ }
+ return;
+ }
+ int err = FXFT_Load_Glyph(m_Font.m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+ if (err) {
+ return;
+ }
+ m_CharBBox[charcode].Left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(m_Font.m_Face), m_Font.m_Face);
+ m_CharBBox[charcode].Right = TT2PDF(FXFT_Get_Glyph_HoriBearingX(m_Font.m_Face) + FXFT_Get_Glyph_Width(m_Font.m_Face), m_Font.m_Face);
+ m_CharBBox[charcode].Top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(m_Font.m_Face), m_Font.m_Face);
+ m_CharBBox[charcode].Bottom = TT2PDF(FXFT_Get_Glyph_HoriBearingY(m_Font.m_Face) - FXFT_Get_Glyph_Height(m_Font.m_Face), m_Font.m_Face);
+ if (m_bUseFontWidth) {
+ int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(m_Font.m_Face), m_Font.m_Face);
+ if (m_CharWidth[charcode] == 0xffff) {
+ m_CharWidth[charcode] = TT_Width;
+ } else if (TT_Width && !IsEmbedded()) {
+ m_CharBBox[charcode].Right = m_CharBBox[charcode].Right * m_CharWidth[charcode] / TT_Width;
+ m_CharBBox[charcode].Left = m_CharBBox[charcode].Left * m_CharWidth[charcode] / TT_Width;
+ }
+ }
+}
+int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level)
+{
+ if (charcode > 0xff) {
+ charcode = 0;
+ }
+ if (m_CharWidth[charcode] == 0xffff) {
+ LoadCharMetrics(charcode);
+ if (m_CharWidth[charcode] == 0xffff) {
+ m_CharWidth[charcode] = 0;
+ }
+ }
+ return (FX_INT16)m_CharWidth[charcode];
+}
+void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level)
+{
+ if (charcode > 0xff) {
+ charcode = 0;
+ }
+ if (m_CharBBox[charcode].Left == (FX_SHORT)0xffff) {
+ LoadCharMetrics(charcode);
+ }
+ rect.left = m_CharBBox[charcode].Left;
+ rect.right = m_CharBBox[charcode].Right;
+ rect.bottom = m_CharBBox[charcode].Bottom;
+ rect.top = m_CharBBox[charcode].Top;
+}
+FX_LPCSTR GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pCharNames, int charcode)
+{
+ ASSERT(charcode >= 0 && charcode < 256);
+ if (charcode < 0 || charcode >= 256) {
+ return NULL;
+ }
+ FX_LPCSTR name = NULL;
+ if (pCharNames) {
+ name = pCharNames[charcode];
+ }
+ if ((name == NULL || name[0] == 0) && iBaseEncoding) {
+ name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode);
+ }
+ if (name == NULL || name[0] == 0) {
+ return NULL;
+ }
+ return name;
+}
+FX_BOOL CPDF_SimpleFont::LoadCommon()
+{
+ CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
+ if (pFontDesc) {
+ LoadFontDescriptor(pFontDesc);
+ }
+ CPDF_Array* pWidthArray = m_pFontDict->GetArray(FX_BSTRC("Widths"));
+ int width_start = 0, width_end = -1;
+ m_bUseFontWidth = TRUE;
+ if (pWidthArray) {
+ m_bUseFontWidth = FALSE;
+ if (pFontDesc && pFontDesc->KeyExist(FX_BSTRC("MissingWidth"))) {
+ int MissingWidth = pFontDesc->GetInteger(FX_BSTRC("MissingWidth"));
+ for (int i = 0; i < 256; i ++) {
+ m_CharWidth[i] = MissingWidth;
+ }
+ }
+ width_start = m_pFontDict->GetInteger(FX_BSTRC("FirstChar"), 0);
+ width_end = m_pFontDict->GetInteger(FX_BSTRC("LastChar"), 0);
+ if (width_start >= 0 && width_start <= 255) {
+ if (width_end <= 0 || width_end >= width_start + (int)pWidthArray->GetCount()) {
+ width_end = width_start + pWidthArray->GetCount() - 1;
+ }
+ if (width_end > 255) {
+ width_end = 255;
+ }
+ for (int i = width_start; i <= width_end; i ++) {
+ m_CharWidth[i] = pWidthArray->GetInteger(i - width_start);
+ }
+ }
+ }
+ if (m_pFontFile == NULL) {
+ LoadSubstFont();
+ } else {
+ if (m_BaseFont.GetLength() > 8 && m_BaseFont[7] == '+') {
+ m_BaseFont = m_BaseFont.Mid(8);
+ }
+ }
+ if (!(m_Flags & PDFFONT_SYMBOLIC)) {
+ m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
+ }
+ CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding"));
+ LoadPDFEncoding(pEncoding, m_BaseEncoding, m_pCharNames, m_pFontFile != NULL, m_Font.IsTTFont());
+ LoadGlyphMap();
+ if (m_pCharNames) {
+ FX_DELETE_VECTOR(m_pCharNames, CFX_ByteString, 256);
+ m_pCharNames = NULL;
+ }
+ if (m_Font.m_Face == NULL) {
+ return TRUE;
+ }
+ if (m_Flags & PDFFONT_ALLCAP) {
+ unsigned char lowercases[] = {'a', 'z', 0xe0, 0xf6, 0xf8, 0xfd};
+ for (int range = 0; range < sizeof lowercases / 2; range ++) {
+ for (int i = lowercases[range * 2]; i <= lowercases[range * 2 + 1]; i ++) {
+ if (m_GlyphIndex[i] != 0xffff && m_pFontFile != NULL) {
+ continue;
+ }
+ m_GlyphIndex[i] = m_GlyphIndex[i - 32];
+ if (m_CharWidth[i - 32]) {
+ m_CharWidth[i] = m_CharWidth[i - 32];
+ m_CharBBox[i] = m_CharBBox[i - 32];
+ }
+ }
+ }
+ }
+ CheckFontMetrics();
+ return TRUE;
+}
+void CPDF_SimpleFont::LoadSubstFont()
+{
+ if (!m_bUseFontWidth && !(m_Flags & PDFFONT_FIXEDPITCH)) {
+ int width = 0, i;
+ for (i = 0; i < 256; i ++) {
+ if (m_CharWidth[i] == 0 || m_CharWidth[i] == 0xffff) {
+ continue;
+ }
+ if (width == 0) {
+ width = m_CharWidth[i];
+ } else if (width != m_CharWidth[i]) {
+ break;
+ }
+ }
+ if (i == 256 && width) {
+ m_Flags |= PDFFONT_FIXEDPITCH;
+ }
+ }
+ int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140);
+ m_Font.LoadSubst(m_BaseFont, m_FontType == PDFFONT_TRUETYPE, m_Flags, weight, m_ItalicAngle, 0);
+ if (m_Font.m_pSubstFont->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) {
+ }
+}
+FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const
+{
+ return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL &&
+ m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS;
+}
+CPDF_Type1Font::CPDF_Type1Font()
+{
+ m_Base14Font = -1;
+}
+FX_BOOL CPDF_Type1Font::_Load()
+{
+ m_Base14Font = _PDF_GetStandardFontName(m_BaseFont);
+ if (m_Base14Font >= 0) {
+ CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
+ if (pFontDesc && pFontDesc->KeyExist(FX_BSTRC("Flags"))) {
+ m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags"));
+ } else {
+ m_Flags = m_Base14Font >= 12 ? PDFFONT_SYMBOLIC : PDFFONT_NONSYMBOLIC;
+ }
+ if (m_Base14Font < 4)
+ for (int i = 0; i < 256; i ++) {
+ m_CharWidth[i] = 600;
+ }
+ if (m_Base14Font == 12) {
+ m_BaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL;
+ } else if (m_Base14Font == 13) {
+ m_BaseEncoding = PDFFONT_ENCODING_ZAPFDINGBATS;
+ } else if (m_Flags & PDFFONT_NONSYMBOLIC) {
+ m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
+ }
+ }
+ return LoadCommon();
+}
+static FX_BOOL FT_UseType1Charmap(FXFT_Face face)
+{
+ if (FXFT_Get_Face_CharmapCount(face) == 0) {
+ return FALSE;
+ }
+ if (FXFT_Get_Face_CharmapCount(face) == 1 &&
+ FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == FXFT_ENCODING_UNICODE) {
+ return FALSE;
+ }
+ if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == FXFT_ENCODING_UNICODE) {
+ FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[1]);
+ } else {
+ FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]);
+ }
+ return TRUE;
+}
+extern FX_WCHAR FT_UnicodeFromCharCode(int encoding, FX_DWORD charcode);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+#include "../../fxge/apple/apple_int.h"
+#endif
+int CPDF_Type1Font::GlyphFromCharCodeExt(FX_DWORD charcode)
+{
+ if (charcode > 0xff) {
+ return -1;
+ }
+ int index = m_ExtGID[(FX_BYTE)charcode];
+ if (index == 0xffff) {
+ return -1;
+ }
+ return index;
+}
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+struct _GlyphNameMap {
+ FX_LPCSTR m_pStrAdobe;
+ FX_LPCSTR m_pStrUnicode;
+};
+static const _GlyphNameMap g_GlyphNameSubsts[] = {
+ {"ff", "uniFB00"},
+ {"fi", "uniFB01"},
+ {"fl", "uniFB02"},
+ {"ffi", "uniFB03"},
+ {"ffl", "uniFB04"}
+};
+extern "C" {
+ static int compareString(const void* key, const void* element)
+ {
+ return FXSYS_stricmp((FX_LPCSTR)key, ((_GlyphNameMap*)element)->m_pStrAdobe);
+ }
+}
+static FX_LPCSTR _GlyphNameRemap(FX_LPCSTR pStrAdobe)
+{
+ _GlyphNameMap* found = (_GlyphNameMap*)FXSYS_bsearch(pStrAdobe, g_GlyphNameSubsts,
+ sizeof g_GlyphNameSubsts / sizeof(_GlyphNameMap), sizeof(_GlyphNameMap),
+ compareString);
+ if (found) {
+ return found->m_pStrUnicode;
+ }
+ return NULL;
+}
+#endif
+void CPDF_Type1Font::LoadGlyphMap()
+{
+ if (m_Font.m_Face == NULL) {
+ return;
+ }
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ FX_BOOL bCoreText = TRUE;
+ CQuartz2D & quartz2d = ((CApplePlatform *) CFX_GEModule::Get()->GetPlatformData())->_quartz2d;
+ if (!m_Font.m_pPlatformFont) {
+ if (m_Font.GetPsName() == CFX_WideString::FromLocal("DFHeiStd-W5")) {
+ bCoreText = FALSE;
+ }
+ m_Font.m_pPlatformFont = quartz2d.CreateFont(m_Font.m_pFontData, m_Font.m_dwSize);
+ if (NULL == m_Font.m_pPlatformFont) {
+ bCoreText = FALSE;
+ }
+ }
+#endif
+ if (!IsEmbedded() && (m_Base14Font < 12) && m_Font.IsTTFont()) {
+ if (FT_UseTTCharmap(m_Font.m_Face, 3, 0)) {
+ FX_BOOL bGotOne = FALSE;
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ const FX_BYTE prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
+ for (int j = 0; j < 4; j ++) {
+ FX_WORD unicode = prefix[j] * 256 + charcode;
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ FX_CHAR name_glyph[256];
+ FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
+ name_glyph[255] = 0;
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+#endif
+ if (m_GlyphIndex[charcode]) {
+ bGotOne = TRUE;
+ break;
+ }
+ }
+ }
+ if (bGotOne) {
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (!bCoreText) {
+ FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
+ }
+#endif
+ return;
+ }
+ }
+ FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE);
+ if (m_BaseEncoding == 0) {
+ m_BaseEncoding = PDFFONT_ENCODING_STANDARD;
+ }
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
+ if (name == NULL) {
+ continue;
+ }
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ FX_CHAR name_glyph[256];
+ FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
+ name_glyph[255] = 0;
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+#endif
+ if (m_GlyphIndex[charcode] == 0 && FXSYS_strcmp(name, ".notdef") == 0) {
+ m_Encoding.m_Unicodes[charcode] = 0x20;
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, 0x20);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ FX_CHAR name_glyph[256];
+ FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
+ name_glyph[255] = 0;
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+#endif
+ }
+ }
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (!bCoreText) {
+ FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
+ }
+#endif
+ return;
+ }
+ FT_UseType1Charmap(m_Font.m_Face);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (bCoreText) {
+ if (m_Flags & PDFFONT_SYMBOLIC) {
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
+ if (name) {
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+ } else {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
+ FX_WCHAR unicode = 0;
+ if (m_GlyphIndex[charcode]) {
+ unicode = FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
+ }
+ FX_CHAR name_glyph[256];
+ FXSYS_memset32(name_glyph, 0, sizeof(name_glyph));
+ FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
+ name_glyph[255] = 0;
+ if (unicode == 0 && name_glyph[0] != 0) {
+ unicode = PDF_UnicodeFromAdobeName(name_glyph);
+ }
+ m_Encoding.m_Unicodes[charcode] = unicode;
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+ }
+ }
+ return;
+ }
+ FX_BOOL bUnicode = FALSE;
+ if (0 == FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE)) {
+ bUnicode = TRUE;
+ }
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
+ if (name == NULL) {
+ continue;
+ }
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ FX_LPCSTR pStrUnicode = _GlyphNameRemap(name);
+ if (pStrUnicode && 0 == FXFT_Get_Name_Index(m_Font.m_Face, (char*)name)) {
+ name = pStrUnicode;
+ }
+ m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+ if (m_GlyphIndex[charcode] == 0) {
+ if (FXSYS_strcmp(name, ".notdef") != 0 && FXSYS_strcmp(name, "space") != 0) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
+ FX_CHAR name_glyph[256];
+ FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
+ name_glyph[255] = 0;
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+ } else {
+ m_Encoding.m_Unicodes[charcode] = 0x20;
+ m_GlyphIndex[charcode] = bUnicode ? FXFT_Get_Char_Index(m_Font.m_Face, 0x20) : 0xffff;
+ FX_CHAR name_glyph[256];
+ FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
+ name_glyph[255] = 0;
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.m_pPlatformFont, name_ct);
+ if (name_ct) {
+ CFRelease(name_ct);
+ }
+ }
+ }
+ }
+ return;
+ }
+#endif
+ if (m_Flags & PDFFONT_SYMBOLIC) {
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
+ if (name) {
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
+ } else {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
+ if (m_GlyphIndex[charcode]) {
+ FX_WCHAR unicode = FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
+ if (unicode == 0) {
+ FX_CHAR name_glyph[256];
+ FXSYS_memset32(name_glyph, 0, sizeof(name_glyph));
+ FXFT_Get_Glyph_Name(m_Font.m_Face, m_GlyphIndex[charcode], name_glyph, 256);
+ name_glyph[255] = 0;
+ if (name_glyph[0] != 0) {
+ unicode = PDF_UnicodeFromAdobeName(name_glyph);
+ }
+ }
+ m_Encoding.m_Unicodes[charcode] = unicode;
+ }
+ }
+ }
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (!bCoreText) {
+ FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
+ }
+#endif
+ return;
+ }
+ FX_BOOL bUnicode = FALSE;
+ if (0 == FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE)) {
+ bUnicode = TRUE;
+ }
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
+ if (name == NULL) {
+ continue;
+ }
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
+ if (m_GlyphIndex[charcode] == 0) {
+ if (FXSYS_strcmp(name, ".notdef") != 0 && FXSYS_strcmp(name, "space") != 0) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
+ } else {
+ m_Encoding.m_Unicodes[charcode] = 0x20;
+ m_GlyphIndex[charcode] = 0xffff;
+ }
+ }
+ }
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (!bCoreText) {
+ FXSYS_memcpy32(m_ExtGID, m_GlyphIndex, 256);
+ }
+#endif
+}
+CPDF_FontEncoding::CPDF_FontEncoding()
+{
+ FXSYS_memset32(m_Unicodes, 0, sizeof(m_Unicodes));
+}
+int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const
+{
+ for (int i = 0; i < 256; i ++)
+ if (m_Unicodes[i] == unicode) {
+ return i;
+ }
+ return -1;
+}
+CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding)
+{
+ const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding);
+ if (!pSrc) {
+ FXSYS_memset32(m_Unicodes, 0, sizeof(m_Unicodes));
+ } else
+ for (int i = 0; i < 256; i++) {
+ m_Unicodes[i] = pSrc[i];
+ }
+}
+FX_BOOL CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const
+{
+ return FXSYS_memcmp32(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) == 0;
+}
+CPDF_Object* CPDF_FontEncoding::Realize()
+{
+ int predefined = 0;
+ for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS; cs ++) {
+ const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(cs);
+ FX_BOOL match = TRUE;
+ for (int i = 0; i < 256; ++i) {
+ if (m_Unicodes[i] != pSrc[i]) {
+ match = FALSE;
+ break;
+ }
+ }
+ if (match) {
+ predefined = cs;
+ break;
+ }
+ }
+ if (predefined) {
+ if (predefined == PDFFONT_ENCODING_WINANSI) {
+ return CPDF_Name::Create("WinAnsiEncoding");
+ }
+ if (predefined == PDFFONT_ENCODING_MACROMAN) {
+ return CPDF_Name::Create("MacRomanEncoding");
+ }
+ if (predefined == PDFFONT_ENCODING_MACEXPERT) {
+ return CPDF_Name::Create("MacExpertEncoding");
+ }
+ return NULL;
+ }
+ CPDF_Dictionary* pDict = CPDF_Dictionary::Create();
+ pDict->SetAtName(FX_BSTRC("BaseEncoding"), FX_BSTRC("WinAnsiEncoding"));
+ const FX_WORD* pStandard = PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI);
+ CPDF_Array* pDiff = CPDF_Array::Create();
+ for (int i = 0; i < 256; i ++) {
+ if (pStandard[i] == m_Unicodes[i]) {
+ continue;
+ }
+ pDiff->Add(CPDF_Number::Create(i));
+ pDiff->Add(CPDF_Name::Create(PDF_AdobeNameFromUnicode(m_Unicodes[i])));
+ }
+ pDict->SetAt(FX_BSTRC("Differences"), pDiff);
+ return pDict;
+}
+CPDF_TrueTypeFont::CPDF_TrueTypeFont()
+{
+}
+FX_BOOL CPDF_TrueTypeFont::_Load()
+{
+ return LoadCommon();
+}
+extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode);
+void CPDF_TrueTypeFont::LoadGlyphMap()
+{
+ if (m_Font.m_Face == NULL) {
+ return;
+ }
+ int baseEncoding = m_BaseEncoding;
+ if (m_pFontFile && m_Font.m_Face->num_charmaps > 0
+ && (baseEncoding == PDFFONT_ENCODING_MACROMAN || baseEncoding == PDFFONT_ENCODING_WINANSI)
+ && (m_Flags & PDFFONT_SYMBOLIC)) {
+ FX_BOOL bSupportWin = FALSE;
+ FX_BOOL bSupportMac = FALSE;
+ for (int i = 0; i < FXFT_Get_Face_CharmapCount(m_Font.m_Face); i++) {
+ int platform_id = FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]);
+ if (platform_id == 0 || platform_id == 3) {
+ bSupportWin = TRUE;
+ } else if (platform_id == 0 || platform_id == 1) {
+ bSupportMac = TRUE;
+ }
+ }
+ if (baseEncoding == PDFFONT_ENCODING_WINANSI && !bSupportWin) {
+ baseEncoding = bSupportMac ? PDFFONT_ENCODING_MACROMAN : PDFFONT_ENCODING_BUILTIN;
+ } else if (baseEncoding == PDFFONT_ENCODING_MACROMAN && !bSupportMac) {
+ baseEncoding = bSupportWin ? PDFFONT_ENCODING_WINANSI : PDFFONT_ENCODING_BUILTIN;
+ }
+ }
+ if (((baseEncoding == PDFFONT_ENCODING_MACROMAN || baseEncoding == PDFFONT_ENCODING_WINANSI)
+ && m_pCharNames == NULL) || (m_Flags & PDFFONT_NONSYMBOLIC)) {
+ if (!FXFT_Has_Glyph_Names(m_Font.m_Face) && (!m_Font.m_Face->num_charmaps || !m_Font.m_Face->charmaps)) {
+ int nStartChar = m_pFontDict->GetInteger(FX_BSTRC("FirstChar"));
+ int charcode = 0;
+ for (; charcode < nStartChar; charcode ++) {
+ m_GlyphIndex[charcode] = 0;
+ }
+ FX_WORD nGlyph = charcode - nStartChar + 3;
+ for (; charcode < 256; charcode ++, nGlyph ++) {
+ m_GlyphIndex[charcode] = nGlyph;
+ }
+ return;
+ }
+ FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1);
+ FX_BOOL bMacRoman = FALSE, bMSSymbol = FALSE;
+ if (!bMSUnicode) {
+ if (m_Flags & PDFFONT_NONSYMBOLIC) {
+ bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0);
+ bMSSymbol = !bMacRoman && FT_UseTTCharmap(m_Font.m_Face, 3, 0);
+ } else {
+ bMSSymbol = FT_UseTTCharmap(m_Font.m_Face, 3, 0);
+ bMacRoman = !bMSSymbol && FT_UseTTCharmap(m_Font.m_Face, 1, 0);
+ }
+ }
+ FX_BOOL bToUnicode = m_pFontDict->KeyExist(FX_BSTRC("ToUnicode"));
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ FX_LPCSTR name = GetAdobeCharName(baseEncoding, m_pCharNames, charcode);
+ if (name == NULL) {
+ m_GlyphIndex[charcode] = m_pFontFile ? FXFT_Get_Char_Index(m_Font.m_Face, charcode) : -1;
+ continue;
+ }
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ if (bMSSymbol) {
+ const FX_BYTE prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
+ for (int j = 0; j < 4; j ++) {
+ FX_WORD unicode = prefix[j] * 256 + charcode;
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
+ if (m_GlyphIndex[charcode]) {
+ break;
+ }
+ }
+ } else if (m_Encoding.m_Unicodes[charcode]) {
+ if (bMSUnicode) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]);
+ } else if (bMacRoman) {
+ FX_DWORD maccode = FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, m_Encoding.m_Unicodes[charcode]);
+ if (!maccode) {
+ m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char *)name);
+ } else {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, maccode);
+ }
+ }
+ }
+ if ((m_GlyphIndex[charcode] == 0 || m_GlyphIndex[charcode] == 0xffff) && name != NULL) {
+ if (name[0] == '.' && FXSYS_strcmp(name, ".notdef") == 0) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, 32);
+ } else {
+ m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.m_Face, (char*)name);
+ if (m_GlyphIndex[charcode] == 0) {
+ if (bToUnicode) {
+ CFX_WideString wsUnicode = UnicodeFromCharCode(charcode);
+ if (!wsUnicode.IsEmpty()) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, wsUnicode[0]);
+ m_Encoding.m_Unicodes[charcode] = wsUnicode[0];
+ }
+ }
+ if (m_GlyphIndex[charcode] == 0) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
+ }
+ }
+ }
+ }
+ }
+ return;
+ }
+ if (FT_UseTTCharmap(m_Font.m_Face, 3, 0)) {
+ const FX_BYTE prefix[4] = {0x00, 0xf0, 0xf1, 0xf2};
+ FX_BOOL bGotOne = FALSE;
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ for (int j = 0; j < 4; j ++) {
+ FX_WORD unicode = prefix[j] * 256 + charcode;
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
+ if (m_GlyphIndex[charcode]) {
+ bGotOne = TRUE;
+ break;
+ }
+ }
+ }
+ if (bGotOne) {
+ if (baseEncoding != PDFFONT_ENCODING_BUILTIN) {
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ FX_LPCSTR name = GetAdobeCharName(baseEncoding, m_pCharNames, charcode);
+ if (name == NULL) {
+ continue;
+ }
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ }
+ } else if (FT_UseTTCharmap(m_Font.m_Face, 1, 0)) {
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ m_Encoding.m_Unicodes[charcode] = FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
+ }
+ }
+ return;
+ }
+ }
+ if (FT_UseTTCharmap(m_Font.m_Face, 1, 0)) {
+ FX_BOOL bGotOne = FALSE;
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, charcode);
+ m_Encoding.m_Unicodes[charcode] = FT_UnicodeFromCharCode(FXFT_ENCODING_APPLE_ROMAN, charcode);
+ if (m_GlyphIndex[charcode]) {
+ bGotOne = TRUE;
+ }
+ }
+ if (m_pFontFile || bGotOne) {
+ return;
+ }
+ }
+ if (FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE) == 0) {
+ FX_BOOL bGotOne = FALSE;
+ const FX_WORD* pUnicodes = PDF_UnicodesForPredefinedCharSet(baseEncoding);
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ if (m_pFontFile == NULL) {
+ FX_LPCSTR name = GetAdobeCharName(0, m_pCharNames, charcode);
+ if (name != NULL) {
+ m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
+ } else if (pUnicodes) {
+ m_Encoding.m_Unicodes[charcode] = pUnicodes[charcode];
+ }
+ } else {
+ m_Encoding.m_Unicodes[charcode] = charcode;
+ }
+ m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.m_Face, m_Encoding.m_Unicodes[charcode]);
+ if (m_GlyphIndex[charcode]) {
+ bGotOne = TRUE;
+ }
+ }
+ if (bGotOne) {
+ return;
+ }
+ }
+ for (int charcode = 0; charcode < 256; charcode ++) {
+ m_GlyphIndex[charcode] = charcode;
+ }
+}
+CPDF_Type3Font::CPDF_Type3Font()
+{
+ m_pPageResources = NULL;
+ FXSYS_memset32(m_CharWidthL, 0, sizeof m_CharWidthL);
+}
+CPDF_Type3Font::~CPDF_Type3Font()
+{
+ FX_POSITION pos = m_CacheMap.GetStartPosition();
+ while (pos) {
+ FX_LPVOID key, value;
+ m_CacheMap.GetNextAssoc(pos, key, value);
+ delete (CPDF_Type3Char*)value;
+ }
+ m_CacheMap.RemoveAll();
+ pos = m_DeletedMap.GetStartPosition();
+ while (pos) {
+ FX_LPVOID key, value;
+ m_DeletedMap.GetNextAssoc(pos, key, value);
+ delete (CPDF_Type3Char*)key;
+ }
+}
+FX_BOOL CPDF_Type3Font::_Load()
+{
+ m_pFontResources = m_pFontDict->GetDict(FX_BSTRC("Resources"));
+ CPDF_Array* pMatrix = m_pFontDict->GetArray(FX_BSTRC("FontMatrix"));
+ FX_FLOAT xscale = 1.0f, yscale = 1.0f;
+ if (pMatrix) {
+ m_FontMatrix = pMatrix->GetMatrix();
+ xscale = m_FontMatrix.a;
+ yscale = m_FontMatrix.d;
+ }
+ CPDF_Array* pBBox = m_pFontDict->GetArray(FX_BSTRC("FontBBox"));
+ if (pBBox) {
+ m_FontBBox.left = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(0), xscale) * 1000);
+ m_FontBBox.bottom = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(1), yscale) * 1000);
+ m_FontBBox.right = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(2), xscale) * 1000);
+ m_FontBBox.top = (FX_INT32)(FXSYS_Mul(pBBox->GetNumber(3), yscale) * 1000);
+ }
+ int StartChar = m_pFontDict->GetInteger(FX_BSTRC("FirstChar"));
+ CPDF_Array* pWidthArray = m_pFontDict->GetArray(FX_BSTRC("Widths"));
+ if (pWidthArray && (StartChar >= 0 && StartChar < 256)) {
+ FX_DWORD count = pWidthArray->GetCount();
+ if (count > 256) {
+ count = 256;
+ }
+ if (StartChar + count > 256) {
+ count = 256 - StartChar;
+ }
+ for (FX_DWORD i = 0; i < count; i ++) {
+ m_CharWidthL[StartChar + i] = FXSYS_round(FXSYS_Mul(pWidthArray->GetNumber(i), xscale) * 1000);
+ }
+ }
+ m_pCharProcs = m_pFontDict->GetDict(FX_BSTRC("CharProcs"));
+ CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding"));
+ if (pEncoding) {
+ LoadPDFEncoding(pEncoding, m_BaseEncoding, m_pCharNames, FALSE, FALSE);
+ if (m_pCharNames) {
+ for (int i = 0; i < 256; i ++) {
+ m_Encoding.m_Unicodes[i] = PDF_UnicodeFromAdobeName(m_pCharNames[i]);
+ if (m_Encoding.m_Unicodes[i] == 0) {
+ m_Encoding.m_Unicodes[i] = i;
+ }
+ }
+ }
+ }
+ return TRUE;
+}
+void CPDF_Type3Font::CheckType3FontMetrics()
+{
+ CheckFontMetrics();
+}
+CPDF_Type3Char* CPDF_Type3Font::LoadChar(FX_DWORD charcode, int level)
+{
+ if (level >= _FPDF_MAX_TYPE3_FORM_LEVEL_) {
+ return NULL;
+ }
+ CPDF_Type3Char* pChar = NULL;
+ if (m_CacheMap.Lookup((FX_LPVOID)(FX_UINTPTR)charcode, (FX_LPVOID&)pChar)) {
+ if (pChar->m_bPageRequired && m_pPageResources) {
+ delete pChar;
+ m_CacheMap.RemoveKey((FX_LPVOID)(FX_UINTPTR)charcode);
+ return LoadChar(charcode, level + 1);
+ }
+ return pChar;
+ }
+ FX_LPCSTR name = GetAdobeCharName(m_BaseEncoding, m_pCharNames, charcode);
+ if (name == NULL) {
+ return NULL;
+ }
+ CPDF_Stream* pStream = (CPDF_Stream*)m_pCharProcs->GetElementValue(name);
+ if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM) {
+ return NULL;
+ }
+ pChar = FX_NEW CPDF_Type3Char;
+ pChar->m_pForm = FX_NEW CPDF_Form(m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, pStream, NULL);
+ pChar->m_pForm->ParseContent(NULL, NULL, pChar, NULL, level + 1);
+ FX_FLOAT scale = m_FontMatrix.GetXUnit();
+ pChar->m_Width = (FX_INT32)(pChar->m_Width * scale + 0.5f);
+ FX_RECT &rcBBox = pChar->m_BBox;
+ CFX_FloatRect char_rect((FX_FLOAT)rcBBox.left / 1000.0f, (FX_FLOAT)rcBBox.bottom / 1000.0f,
+ (FX_FLOAT)rcBBox.right / 1000.0f, (FX_FLOAT)rcBBox.top / 1000.0f);
+ if (rcBBox.right <= rcBBox.left || rcBBox.bottom >= rcBBox.top) {
+ char_rect = pChar->m_pForm->CalcBoundingBox();
+ }
+ char_rect.Transform(&m_FontMatrix);
+ rcBBox.left = FXSYS_round(char_rect.left * 1000);
+ rcBBox.right = FXSYS_round(char_rect.right * 1000);
+ rcBBox.top = FXSYS_round(char_rect.top * 1000);
+ rcBBox.bottom = FXSYS_round(char_rect.bottom * 1000);
+ m_CacheMap.SetAt((FX_LPVOID)(FX_UINTPTR)charcode, pChar);
+ if (pChar->m_pForm->CountObjects() == 0) {
+ delete pChar->m_pForm;
+ pChar->m_pForm = NULL;
+ }
+ return pChar;
+}
+int CPDF_Type3Font::GetCharWidthF(FX_DWORD charcode, int level)
+{
+ if (charcode > 0xff) {
+ charcode = 0;
+ }
+ if (m_CharWidthL[charcode]) {
+ return m_CharWidthL[charcode];
+ }
+ CPDF_Type3Char* pChar = LoadChar(charcode, level);
+ if (pChar == NULL) {
+ return 0;
+ }
+ return pChar->m_Width;
+}
+void CPDF_Type3Font::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level)
+{
+ CPDF_Type3Char* pChar = LoadChar(charcode, level);
+ if (pChar == NULL) {
+ rect.left = rect.right = rect.top = rect.bottom = 0;
+ return;
+ }
+ rect = pChar->m_BBox;
+}
+CPDF_Type3Char::CPDF_Type3Char()
+{
+ m_pForm = NULL;
+ m_pBitmap = NULL;
+ m_bPageRequired = FALSE;
+ m_bColored = FALSE;
+}
+CPDF_Type3Char::~CPDF_Type3Char()
+{
+ if (m_pForm) {
+ delete m_pForm;
+ }
+ if (m_pBitmap) {
+ delete m_pBitmap;
+ }
+}
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_charset.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_charset.cpp
index bd09cfc75d..981018b33a 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_charset.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_charset.cpp
@@ -1,625 +1,625 @@
-// 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
-
-#include "../../../include/fpdfapi/fpdf_page.h"
-#include "../../../include/fxge/fx_freetype.h"
-extern FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR*);
-const struct _UnicodeAlt {
- FX_WORD m_Unicode;
- const FX_CHAR* m_Alter;
-}
-UnicodeAlts[] = {
- {0x00a0, " "}, {0x00a1, "!"}, {0x00a2, "c"}, {0x00a3, "P"}, {0x00a4, "o"},
- {0x00a5, "Y"}, {0x00a6, "|"}, {0x00a7, "S"}, {0x00a9, "(C)"}, {0x00aa, "a"},
- {0x00ab, "<<"}, {0x00ac, "-|"}, {0x00ae, "(R)"}, {0x00af, "-"},
- {0x00b0, "o"}, {0x00b1, "+/-"}, {0x00b2, "^2"}, { 0x00b3, "^3"},
- {0x00b4, "'"}, {0x00b5, "u"}, {0x00b6, "P"}, {0x00b7, "."},
- {0x00b9, "^1"}, {0x00ba, "o"}, {0x00bb, ">>"}, {0x00bc, "1/4"},
- {0x00bd, "1/2"}, {0x00be, "3/4"}, {0x00bf, "?"}, {0x00c0, "A"},
- {0x00c1, "A"}, {0x00c2, "A"}, {0x00c3, "A"}, {0x00c4, "A"},
- {0x00c5, "A"}, {0x00c6, "AE"}, {0x00c7, "C"}, {0x00c8, "E"},
- {0x00c9, "E"}, {0x00ca, "E"}, {0x00cb, "E"}, {0x00cc, "I"},
- {0x00cd, "I"}, {0x00ce, "I"}, {0x00cf, "I"},
- {0x00d1, "N"}, {0x00d2, "O"}, {0x00d3, "O"}, {0x00d4, "O"},
- {0x00d5, "O"}, {0x00d6, "O"}, {0x00d7, "x"}, {0x00d8, "O"},
- {0x00d9, "U"}, {0x00da, "U"}, {0x00db, "U"}, {0x00dc, "U"},
- {0x00dd, "Y"}, {0x00df, "S"}, {0x00e0, "a"},
- {0x00e1, "a"}, {0x00e2, "a"}, {0x00e3, "a"}, {0x00e4, "a"},
- {0x00e5, "a"}, {0x00e6, "ae"}, {0x00e7, "c"}, {0x00e8, "e"},
- {0x00e9, "e"}, {0x00ea, "e"}, {0x00eb, "e"}, {0x00ec, "i"},
- {0x00ed, "i"}, {0x00ee, "i"}, {0x00ef, "i"},
- {0x00f1, "n"}, {0x00f2, "o"}, {0x00f3, "o"}, {0x00f4, "o"},
- {0x00f5, "o"}, {0x00f6, "o"}, {0x00f7, "/"}, {0x00f8, "o"},
- {0x00f9, "u"}, {0x00fa, "u"}, {0x00fb, "u"}, {0x00fc, "u"},
- {0x00fd, "y"}, {0x00ff, "y"},
- {0x02b0, "h"}, {0x02b2, "j"}, {0x02b3, "r"}, {0x02b7, "w"},
- {0x02b8, "y"}, {0x02b9, "'"}, {0x02ba, "\""}, {0x02bb, "'"},
- {0x02bc, "'"}, {0x02bd, "'"}, {0x02be, "'"}, {0x02bf, "'"},
- {0x02c2, "<"}, {0x02c3, ">"}, {0x02c4, "^"}, {0x02c5, "v"},
- {0x02c6, "^"}, {0x02c7, "v"}, {0x02c8, "'"}, {0x02c9, "-"},
- {0x02ca, "'"}, {0x02cb, "'"}, {0x02cc, "."}, {0x02cd, "_"},
- {0x2010, "-"}, {0x2012, "-"}, {0x2013, "-"}, {0x2014, "--"},
- {0x2015, "--"}, {0x2016, "|"}, {0x2017, "_"},
- {0x2018, "'"}, {0x2019, "'"}, {0x201a, ","}, {0x201b, "'"},
- {0x201c, "\""}, {0x201d, "\""}, {0x201e, ","}, {0x201f, "'"},
- {0x2020, "+"}, {0x2021, "+"}, {0x2022, "*"}, {0x2023, ">"},
- {0x2024, "."}, {0x2025, ".."}, {0x2027, "."}, {0x2032, "'"},
- {0x2033, "\""}, {0x2035, "'"}, {0x2036, "\""}, {0x2038, "^"},
- {0x2039, "<"}, {0x203a, ">"}, {0x203b, "*"}, {0x203c, "!!"},
- {0x203d, "?!"}, {0x203e, "-"}, {0x2044, "/"}, {0x2047, "??"},
- {0x2048, "?!"}, {0x2049, "!?"}, {0x204e, "*"}, {0x2052, "%"},
- {0x2122, "(TM)"},
- {0x2212, "-"}, {0x2215, "/"}, {0x2216, "\\"}, {0x2217, "*"},
- {0x2218, "*"}, {0x2219, "*"}, {0x2223, "|"}, {0x22c5, "."},
- {0x266f, "#"},
- {0XF6D9, "(C)"}, {0XF6DA, "(C)"}, {0XF6DB, "(TM)"},
- {0XF8E8, "(C)"}, {0xf8e9, "(C)"}, {0XF8EA, "(TM)"},
-
- {0xfb01, "fi"}, {0xfb02, "fl"}
-};
-const FX_CHAR* FCS_GetAltStr(FX_WCHAR unicode)
-{
- int begin = 0;
- int end = sizeof UnicodeAlts / sizeof(struct _UnicodeAlt) - 1;
- while (begin <= end) {
- int middle = (begin + end) / 2;
- FX_WORD middlecode = UnicodeAlts[middle].m_Unicode;
- if (middlecode > unicode) {
- end = middle - 1;
- } else if (middlecode < unicode) {
- begin = middle + 1;
- } else {
- return UnicodeAlts[middle].m_Alter;
- }
- }
- return NULL;
-}
-const FX_WORD StandardEncoding[256] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x2019,
- 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031,
- 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b,
- 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,
- 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
- 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
- 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x2018, 0x0061, 0x0062, 0x0063,
- 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d,
- 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
- 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x00a1, 0x00a2, 0x00a3, 0x2044, 0x00a5, 0x0192, 0x00a7, 0x00a4, 0x0027,
- 0x201c, 0x00ab, 0x2039, 0x203a, 0xfb01, 0xfb02, 0x0000, 0x2013, 0x2020, 0x2021,
- 0x00b7, 0x0000, 0x00b6, 0x2022, 0x201a, 0x201e, 0x201d, 0x00bb, 0x2026, 0x2030,
- 0x0000, 0x00bf, 0x0000, 0x0060, 0x00b4, 0x02c6, 0x02dc, 0x00af, 0x02d8, 0x02d9,
- 0x00a8, 0x0000, 0x02da, 0x00b8, 0x0000, 0x02dd, 0x02db, 0x02c7, 0x2014, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00c6, 0x0000, 0x00aa, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0141, 0x00d8, 0x0152, 0x00ba, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x00e6, 0x0000, 0x0000, 0x0000, 0x0131, 0x0000, 0x0000, 0x0142, 0x00f8,
- 0x0153, 0x00df, 0x0000, 0x0000, 0x0000, 0x0000
-};
-const FX_WORD MacRomanEncoding[256] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
- 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031,
- 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b,
- 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,
- 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
- 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
- 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, 0x0063,
- 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d,
- 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
- 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000, 0x00c4, 0x00c5,
- 0x00c7, 0x00c9, 0x00d1, 0x00d6, 0x00dc, 0x00e1, 0x00e0, 0x00e2, 0x00e4, 0x00e3,
- 0x00e5, 0x00e7, 0x00e9, 0x00e8, 0x00ea, 0x00eb, 0x00ed, 0x00ec, 0x00ee, 0x00ef,
- 0x00f1, 0x00f3, 0x00f2, 0x00f4, 0x00f6, 0x00f5, 0x00fa, 0x00f9, 0x00fb, 0x00fc,
- 0x2020, 0x00b0, 0x00a2, 0x00a3, 0x00a7, 0x2022, 0x00b6, 0x00df, 0x00ae, 0x00a9,
- 0x2122, 0x00b4, 0x00a8, 0x0000, 0x00c6, 0x00d8, 0x0000, 0x00b1, 0x0000, 0x0000,
- 0x00a5, 0x00b5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00aa, 0x00ba, 0x0000,
- 0x00e6, 0x00f8, 0x00bf, 0x00a3, 0x00ac, 0x0000, 0x0192, 0x0000, 0x0000, 0x00ab,
- 0x00bb, 0x2026, 0x0020, 0x00c0, 0x00c3, 0x00d5, 0x0152, 0x0153, 0x2013, 0x2014,
- 0x201c, 0x201d, 0x2018, 0x2019, 0x00f7, 0x0000, 0x00ff, 0x0178, 0x2044, 0x00a4,
- 0x2039, 0x203a, 0xfb01, 0xfb02, 0x2021, 0x00b7, 0x201a, 0x201e, 0x2030, 0x00c2,
- 0x00ca, 0x00c1, 0x00cb, 0x00c8, 0x00cd, 0x00ce, 0x00cf, 0x00cc, 0x00d3, 0x00d4,
- 0x0000, 0x00d2, 0x00da, 0x00db, 0x00d9, 0x0131, 0x02c6, 0x02dc, 0x00af, 0x02d8,
- 0x02d9, 0x02da, 0x00b8, 0x02dd, 0x02db, 0x02c7
-};
-const FX_WORD AdobeWinAnsiEncoding[256] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
- 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
- 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
- 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
- 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
- 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
- 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
- 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
- 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
- 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
- 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
- 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2022,
- 0x20ac, 0x2022, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021,
- 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x2022, 0x017d, 0x2022,
- 0x2022, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014,
- 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x2022, 0x017e, 0x0178,
- 0x0020, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
- 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x002d, 0x00ae, 0x00af,
- 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
- 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
- 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7,
- 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
- 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
- 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
- 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
- 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
- 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
- 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
-};
-extern const FX_WORD PDFDocEncoding[256];
-const FX_WORD MacExpertEncoding[256] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0020, 0xf721, 0xf6f8, 0xf7a2, 0xf724, 0xf6e4, 0xf726, 0xf7b4,
- 0x207d, 0x207e, 0x2025, 0x2024, 0x002c, 0x002d, 0x002e, 0x2044, 0xf730, 0xf731,
- 0xf732, 0xf733, 0xf734, 0xf735, 0xf736, 0xf737, 0xf738, 0xf739, 0x003a, 0x003b,
- 0x0000, 0xf6de, 0x0000, 0xf73f, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7f0, 0x0000,
- 0x0000, 0x00bc, 0x00bd, 0x00be, 0x215b, 0x215c, 0x215d, 0x215e, 0x2153, 0x2154,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfb00, 0xfb01, 0xfb02, 0xfb03,
- 0xfb04, 0x208d, 0x0000, 0x208e, 0xf6f6, 0xf6e5, 0xf760, 0xf761, 0xf762, 0xf763,
- 0xf764, 0xf765, 0xf766, 0xf767, 0xf768, 0xf769, 0xf76a, 0xf76b, 0xf76c, 0xf76d,
- 0xf76e, 0xf76f, 0xf770, 0xf771, 0xf772, 0xf773, 0xf774, 0xf775, 0xf776, 0xf777,
- 0xf778, 0xf779, 0xf77a, 0x20a1, 0xf6dc, 0xf6dd, 0xf6fe, 0x0000, 0x0000, 0xf6e9,
- 0xf6e0, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7e1, 0xf7e0, 0xf7e2, 0xf7e4, 0xf7e3,
- 0xf7e5, 0xf7e7, 0xf7e9, 0xf7e8, 0xf7ea, 0xf7eb, 0xf7ed, 0xf7ec, 0xf7ee, 0xf7ef,
- 0xf7f1, 0xf7f3, 0xf7f2, 0xf7f4, 0xf7f6, 0xf7f5, 0xf7fa, 0xf7f9, 0xf7fb, 0xf7fc,
- 0x0000, 0x2078, 0x2084, 0x2083, 0x2086, 0x2088, 0x2087, 0xf6fd, 0x0000, 0xf6df,
- 0x2082, 0x0000, 0xf7a8, 0x0000, 0xf6f5, 0xf6fd, 0x2085, 0x0000, 0xf6e1, 0xf6e7,
- 0xf7fd, 0x0000, 0xf6e3, 0x0000, 0x0000, 0xf7fe, 0x0000, 0x2089, 0x2080, 0xf6ff,
- 0xf7e6, 0xf7f8, 0xf7bf, 0x2081, 0xf6e9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0xf7b8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf6fa, 0x2012, 0xf6e6,
- 0x0000, 0x0000, 0x0000, 0x0000, 0xf7a1, 0x0000, 0xf7ff, 0x0000, 0x00b9, 0x00b2,
- 0x00b3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2079, 0x2070, 0x0000, 0xf6ec, 0xf6f1,
- 0x0000, 0x0000, 0x0000, 0xf6ed, 0xf6f2, 0xf6eb, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0xf6ee, 0xf6fb, 0xf6f4, 0xf7af, 0xf6ea, 0x207f, 0xf6ef, 0xf6e2, 0xf6e8,
- 0xf6f7, 0xf6fc, 0x0000, 0x0000, 0x0000, 0x0000
-};
-const FX_WORD AdobeSymbolEncoding[256] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220B,
- 0x0028, 0x0029, 0x2217, 0x002B, 0x002C, 0x2212, 0x002E, 0x002F,
- 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
- 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
- 0x2245, 0x0391, 0x0392, 0x03A7, 0x0394, 0x0395, 0x03A6, 0x0393,
- 0x0397, 0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F,
- 0x03A0, 0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03C2, 0x03A9,
- 0x039E, 0x03A8, 0x0396, 0x005B, 0x2234, 0x005D, 0x22A5, 0x005F,
- 0xF8E5, 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03C6, 0x03B3,
- 0x03B7, 0x03B9, 0x03D5, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF,
- 0x03C0, 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03C9,
- 0x03BE, 0x03C8, 0x03B6, 0x007B, 0x007C, 0x007D, 0x223C, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x20AC, 0x03D2, 0x2032, 0x2264, 0x2044, 0x221E, 0x0192, 0x2663,
- 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193,
- 0x00B0, 0x00B1, 0x2033, 0x2265, 0x00D7, 0x221D, 0x2202, 0x2022,
- 0x00F7, 0x2260, 0x2261, 0x2248, 0x2026, 0xF8E6, 0xF8E7, 0x21B5,
- 0x2135, 0x2111, 0x211C, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229,
- 0x222A, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209,
- 0x2220, 0x2207, 0xF6DA, 0xF6D9, 0xF6DB, 0x220F, 0x221A, 0x22C5,
- 0x00AC, 0x2227, 0x2228, 0x21D4, 0x21D0, 0x21D1, 0x21D2, 0x21D3,
- 0x25CA, 0x2329, 0xF8E8, 0xF8E9, 0xF8EA, 0x2211, 0xF8EB, 0xF8EC,
- 0xF8ED, 0xF8EE, 0xF8EF, 0xF8F0, 0xF8F1, 0xF8F2, 0xF8F3, 0xF8F4,
- 0x0000, 0x232A, 0x222B, 0x2320, 0xF8F5, 0x2321, 0xF8F6, 0xF8F7,
- 0xF8F8, 0xF8F9, 0xF8FA, 0xF8FB, 0xF8FC, 0xF8FD, 0xF8FE, 0x0000,
-};
-const FX_WORD ZapfEncoding[256] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0020, 0x2701, 0x2702, 0x2703, 0x2704, 0x260E, 0x2706, 0x2707,
- 0x2708, 0x2709, 0x261B, 0x261E, 0x270C, 0x270D, 0x270E, 0x270F,
- 0x2710, 0x2711, 0x2712, 0x2713, 0x2714, 0x2715, 0x2716, 0x2717,
- 0x2718, 0x2719, 0x271A, 0x271B, 0x271C, 0x271D, 0x271E, 0x271F,
- 0x2720, 0x2721, 0x2722, 0x2723, 0x2724, 0x2725, 0x2726, 0x2727,
- 0x2605, 0x2729, 0x272A, 0x272B, 0x272C, 0x272D, 0x272E, 0x272F,
- 0x2730, 0x2731, 0x2732, 0x2733, 0x2734, 0x2735, 0x2736, 0x2737,
- 0x2738, 0x2739, 0x273A, 0x273B, 0x273C, 0x273D, 0x273E, 0x273F,
- 0x2740, 0x2741, 0x2742, 0x2743, 0x2744, 0x2745, 0x2746, 0x2747,
- 0x2748, 0x2749, 0x274A, 0x274B, 0x25CF, 0x274D, 0x25A0, 0x274F,
- 0x2750, 0x2751, 0x2752, 0x25B2, 0x25BC, 0x25C6, 0x2756, 0x25D7,
- 0x2758, 0x2759, 0x275A, 0x275B, 0x275C, 0x275D, 0x275E, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x2761, 0x2762, 0x2763, 0x2764, 0x2765, 0x2766, 0x2767,
- 0x2663, 0x2666, 0x2665, 0x2660, 0x2460, 0x2461, 0x2462, 0x2463,
- 0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x2776, 0x2777,
- 0x2778, 0x2779, 0x277A, 0x277B, 0x277C, 0x277D, 0x277E, 0x277F,
- 0x2780, 0x2781, 0x2782, 0x2783, 0x2784, 0x2785, 0x2786, 0x2787,
- 0x2788, 0x2789, 0x278A, 0x278B, 0x278C, 0x278D, 0x278E, 0x278F,
- 0x2790, 0x2791, 0x2792, 0x2793, 0x2794, 0x2192, 0x2194, 0x2195,
- 0x2798, 0x2799, 0x279A, 0x279B, 0x279C, 0x279D, 0x279E, 0x279F,
- 0x27A0, 0x27A1, 0x27A2, 0x27A3, 0x27A4, 0x27A5, 0x27A6, 0x27A7,
- 0x27A8, 0x27A9, 0x27AA, 0x27AB, 0x27AC, 0x27AD, 0x27AE, 0x27AF,
- 0x0000, 0x27B1, 0x27B2, 0x27B3, 0x27B4, 0x27B5, 0x27B6, 0x27B7,
- 0x27B8, 0x27B9, 0x27BA, 0x27BB, 0x27BC, 0x27BD, 0x27BE, 0x0000,
-};
-const FX_LPCSTR StandardEncodingNames[224] = {
- "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright",
- "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
- "zero", "one", "two", "three", "four", "five", "six", "seven",
- "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
- "at", "A", "B", "C", "D", "E", "F", "G",
- "H", "I", "J", "K", "L", "M", "N", "O",
- "P", "Q", "R", "S", "T", "U", "V", "W",
- "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
- "quoteleft", "a", "b", "c", "d", "e", "f", "g",
- "h", "i", "j", "k", "l", "m", "n", "o",
- "p", "q", "r", "s", "t", "u", "v", "w",
- "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section",
- "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl",
- NULL, "endash", "dagger", "daggerdbl", "periodcentered", NULL, "paragraph", "bullet",
- "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", NULL, "questiondown",
- NULL, "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent",
- "dieresis", NULL, "ring", "cedilla", NULL, "hungarumlaut", "ogonek", "caron",
- "emdash", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, "AE", NULL, "ordfeminine", NULL, NULL, NULL, NULL,
- "Lslash", "Oslash", "OE", "ordmasculine", NULL, NULL, NULL, NULL,
- NULL, "ae", NULL, NULL, NULL, "dotlessi", NULL, NULL,
- "lslash", "oslash", "oe", "germandbls", NULL, NULL, NULL, NULL,
-};
-const FX_LPCSTR AdobeWinAnsiEncodingNames[224] = {
- "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle",
- "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
- "zero", "one", "two", "three", "four", "five", "six", "seven",
- "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
- "at", "A", "B", "C", "D", "E", "F", "G",
- "H", "I", "J", "K", "L", "M", "N", "O",
- "P", "Q", "R", "S", "T", "U", "V", "W",
- "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
- "grave", "a", "b", "c", "d", "e", "f", "g",
- "h", "i", "j", "k", "l", "m", "n", "o",
- "p", "q", "r", "s", "t", "u", "v", "w",
- "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "bullet",
- "Euro", "bullet", "quotesinglbase", "florin", "quotedblbase", "ellipsis", "dagger", "daggerdbl",
- "circumflex", "perthousand", "Scaron", "guilsinglleft", "OE", "bullet", "Zcaron", "bullet",
- "bullet", "quoteleft", "quoteright", "quotedblleft", "quotedblright", "bullet", "endash", "emdash",
- "tilde", "trademark", "scaron", "guilsinglright", "oe", "bullet", "zcaron", "Ydieresis",
- "space", "exclamdown", "cent", "sterling", "currency", "yen", "brokenbar", "section",
- "dieresis", "copyright", "ordfeminine", "guillemotleft", "logicalnot", "hyphen", "registered", "macron",
- "degree", "plusminus", "twosuperior", "threesuperior", "acute", "mu", "paragraph", "periodcentered",
- "cedilla", "onesuperior", "ordmasculine", "guillemotright", "onequarter", "onehalf", "threequarters", "questiondown",
- "Agrave", "Aacute", "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla",
- "Egrave", "Eacute", "Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex", "Idieresis",
- "Eth", "Ntilde", "Ograve", "Oacute", "Ocircumflex", "Otilde", "Odieresis", "multiply",
- "Oslash", "Ugrave", "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls",
- "agrave", "aacute", "acircumflex", "atilde", "adieresis", "aring", "ae", "ccedilla",
- "egrave", "eacute", "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex", "idieresis",
- "eth", "ntilde", "ograve", "oacute", "ocircumflex", "otilde", "odieresis", "divide",
- "oslash", "ugrave", "uacute", "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis",
-};
-const FX_LPCSTR MacRomanEncodingNames[224] = {
- "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle",
- "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
- "zero", "one", "two", "three", "four", "five", "six", "seven",
- "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
- "at", "A", "B", "C", "D", "E", "F", "G",
- "H", "I", "J", "K", "L", "M", "N", "O",
- "P", "Q", "R", "S", "T", "U", "V", "W",
- "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
- "grave", "a", "b", "c", "d", "e", "f", "g",
- "h", "i", "j", "k", "l", "m", "n", "o",
- "p", "q", "r", "s", "t", "u", "v", "w",
- "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", NULL,
- "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute",
- "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave",
- "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute",
- "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis",
- "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls",
- "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash",
- "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff", "summation",
- "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash",
- "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft",
- "guillemotright", "ellipsis", "space", "Agrave", "Atilde", "Otilde", "OE", "oe",
- "endash", "emdash", "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge",
- "ydieresis", "Ydieresis", "fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl",
- "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", "Ecircumflex", "Aacute",
- "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
- "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde",
- "macron", "breve", "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron",
-};
-const FX_LPCSTR MacExpertEncodingNames[224] = {
- "space", "exclamsmall", "Hungarumlautsmall", "centoldstyle", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall",
- "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction",
- "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle",
- "eightoldstyle", "nineoldstyle", "colon", "semicolon", NULL, "threequartersemdash", NULL, "questionsmall",
- NULL, NULL, NULL, NULL, "Ethsmall", NULL, NULL, "onequarter",
- "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds",
- NULL, NULL, NULL, NULL, NULL, NULL, "ff", "fi",
- "fl", "ffi", "ffl", "parenleftinferior", NULL, "parenrightinferior", "Circumflexsmall", "hypheninferior",
- "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall",
- "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall",
- "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall",
- "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", NULL,
- NULL, "asuperior", "centsuperior", NULL, NULL, NULL, NULL, "Aacutesmall",
- "Agravesmall", "Acircumflexsmall", "Adieresissmall", "Atildesmall", "Aringsmall", "Ccedillasmall", "Eacutesmall", "Egravesmall",
- "Ecircumflexsmall", "Edieresissmall", "Iacutesmall", "Igravesmall", "Icircumflexsmall", "Idieresissmall", "Ntildesmall", "Oacutesmall",
- "Ogravesmall", "Ocircumflexsmall", "Odieresissmall", "Otildesmall", "Uacutesmall", "Ugravesmall", "Ucircumflexsmall", "Udieresissmall",
- NULL, "eightsuperior", "fourinferior", "threeinferior", "sixinferior", "eightinferior", "seveninferior", "Scaronsmall",
- NULL, "centinferior", "twoinferior", NULL, "Dieresissmall", NULL, "Caronsmall", "Scaronsmall",
- "fiveinferior", NULL, "commainferior", "periodinferior", "Yacutesmall", NULL, "dollarinferior", NULL,
- NULL, "Thornsmall", NULL, "nineinferior", "zeroinferior", "Zcaronsmall", "AEsmall", "Oslashsmall",
- "questiondownsmall", "oneinferior", "asuperior", NULL, NULL, NULL, NULL, NULL,
- NULL, "Cedillasmall", NULL, NULL, NULL, NULL, NULL, "OEsmall",
- "figuredash", "hyphensuperior", NULL, NULL, NULL, NULL, "exclamdownsmall", NULL,
- "Ydieresissmall", NULL, "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior",
- "sevensuperior", "ninesuperior", "zerosuperior", NULL, "esuperior", "rsuperior", NULL, NULL,
- NULL, "isuperior", "ssuperior", "dsuperior", NULL, NULL, NULL, NULL,
- NULL, "lsuperior", "Ogoneksmall", "Brevesmall", "Macronsmall", "bsuperior", "nsuperior", "msuperior",
- "commasuperior", "periodsuperior", "Dotaccentsmall", "Ringsmall", NULL, NULL, NULL, NULL,
-};
-const FX_LPCSTR PDFDocEncodingNames[232] = {
- "breve", "caron", "circumflex", "dotaccent", "hungarumlaut", "ogonek", "ring", "tilde",
- "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle",
- "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
- "zero", "one", "two", "three", "four", "five", "six", "seven",
- "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
- "at", "A", "B", "C", "D", "E", "F", "G",
- "H", "I", "J", "K", "L", "M", "N", "O",
- "P", "Q", "R", "S", "T", "U", "V", "W",
- "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
- "grave", "a", "b", "c", "d", "e", "f", "g",
- "h", "i", "j", "k", "l", "m", "n", "o",
- "p", "q", "r", "s", "t", "u", "v", "w",
- "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", NULL,
- "bullet3", "dagger", "daggerdbl", "ellipsis", "emdash", "endash", "florin", "fraction",
- "guilsinglleft", "guilsinglright", "minus", "perthousand", "quotedblbase", "quotedblleft", "quotedblright", "quoteleft",
- "quoteright", "quotesinglbase", "trademark", "fi", "fl", "Lslash", "OE", "Scaron",
- "Ydieresis", "Zcaron2", "dotlessi", "lslash", "oe", "scaron", "zcaron2", NULL,
- "Euro", "exclamdown", "cent", "sterling", "currency", "yen", "brokenbar", "section",
- "dieresis", "copyright", "ordfeminine", "guillemotleft4", "logicalnot", NULL, "registered", "macron",
- "degree", "plusminus", "twosuperior", "threesuperior", "acute", "mu", "paragraph", "periodcentered",
- "cedilla", "onesuperior", "ordmasculine", "guillemotright4", "onequarter", "onehalf", "threequarters", "questiondown",
- "Agrave", "Aacute", "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla",
- "Egrave", "Eacute", "Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex", "Idieresis",
- "Eth", "Ntilde", "Ograve", "Oacute", "Ocircumflex", "Otilde", "Odieresis", "multiply",
- "Oslash", "Ugrave", "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls",
- "agrave", "aacute", "acircumflex", "atilde", "adieresis", "aring", "ae", "ccedilla",
- "egrave", "eacute", "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex", "idieresis",
- "eth", "ntilde", "ograve", "oacute", "ocircumflex", "otilde", "odieresis", "divide",
- "oslash", "ugrave", "uacute", "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis",
-};
-const FX_LPCSTR AdobeSymbolEncodingNames[224] = {
- "space", "exclam", "universal", "numbersign", "existential", "percent", "ampersand", "suchthat",
- "parenleft", "parenright", "asteriskmath", "plus", "comma", "minus", "period", "slash",
- "zero", "one", "two", "three", "four", "five", "six", "seven",
- "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
- "congruent", "Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi", "Gamma",
- "Eta", "Iota", "theta1", "Kappa", "Lambda", "Mu", "Nu", "Omicron",
- "Pi", "Theta", "Rho", "Sigma", "Tau", "Upsilon", "sigma1", "Omega",
- "Xi", "Psi", "Zeta", "bracketleft", "therefore", "bracketright", "perpendicular", "underscore",
- "radicalex", "alpha", "beta", "chi", "delta", "epsilon", "phi", "gamma",
- "eta", "iota", "phi1", "kappa", "lambda", "mu", "nu", "omicron",
- "pi", "theta", "rho", "sigma", "tau", "upsilon", "omega1", "omega",
- "xi", "psi", "zeta", "braceleft", "bar", "braceright", "similar", NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- "Euro", "Upsilon1", "minute", "lessequal", "fraction", "infinity", "florin", "club",
- "diamond", "heart", "spade", "arrowboth", "arrowleft", "arrowup", "arrowright", "arrowdown",
- "degree", "plusminus", "second", "greaterequal", "multiply", "proportional", "partialdiff", "bullet",
- "divide", "notequal", "equivalence", "approxequal", "ellipsis", "arrowvertex", "arrowhorizex", "carriagereturn",
- "aleph", "Ifraktur", "Rfraktur", "weierstrass", "circlemultiply", "circleplus", "emptyset", "intersection",
- "union", "propersuperset", "reflexsuperset", "notsubset", "propersubset", "reflexsubset", "element", "notelement",
- "angle", "gradient", "registerserif", "copyrightserif", "trademarkserif", "product", "radical", "dotmath",
- "logicalnot", "logicaland", "logicalor", "arrowdblboth", "arrowdblleft", "arrowdblup", "arrowdblright", "arrowdbldown",
- "lozenge", "angleleft", "registersans", "copyrightsans", "trademarksans", "summation", "parenlefttp", "parenleftex",
- "parenleftbt", "bracketlefttp", "bracketleftex", "bracketleftbt", "bracelefttp", "braceleftmid", "braceleftbt", "braceex",
- NULL, "angleright", "integral", "integraltp", "integralex", "integralbt", "parenrighttp", "parenrightex",
- "parenrightbt", "bracketrighttp", "bracketrightex", "bracketrightbt", "bracerighttp", "bracerightmid", "bracerightbt", NULL,
-};
-const FX_LPCSTR ZapfEncodingNames[224] = {
- "space", "a1", "a2", "a202", "a3", "a4", "a5", "a119",
- "a118", "a117", "a11", "a12", "a13", "a14", "a15", "a16",
- "a105", "a17", "a18", "a19", "a20", "a21", "a22", "a23",
- "a24", "a25", "a26", "a27", "a28", "a6", "a7", "a8",
- "a9", "a10", "a29", "a30", "a31", "a32", "a33", "a34",
- "a35", "a36", "a37", "a38", "a39", "a40", "a41", "a42",
- "a43", "a44", "a45", "a46", "a47", "a48", "a49", "a50",
- "a51", "a52", "a53", "a54", "a55", "a56", "a57", "a58",
- "a59", "a60", "a61", "a62", "a63", "a64", "a65", "a66",
- "a67", "a68", "a69", "a70", "a71", "a72", "a73", "a74",
- "a203", "a75", "a204", "a76", "a77", "a78", "a79", "a81",
- "a82", "a83", "a84", "a97", "a98", "a99", "a100", NULL,
- "a89", "a90", "a93", "a94", "a91", "a92", "a205", "a85",
- "a206", "a86", "a87", "a88", "a95", "a96", NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, "a101", "a102", "a103", "a104", "a106", "a107", "a108",
- "a112", "a111", "a110", "a109", "a120", "a121", "a122", "a123",
- "a124", "a125", "a126", "a127", "a128", "a129", "a130", "a131",
- "a132", "a133", "a134", "a135", "a136", "a137", "a138", "a139",
- "a140", "a141", "a142", "a143", "a144", "a145", "a146", "a147",
- "a148", "a149", "a150", "a151", "a152", "a153", "a154", "a155",
- "a156", "a157", "a158", "a159", "a160", "a161", "a163", "a164",
- "a196", "a165", "a192", "a166", "a167", "a168", "a169", "a170",
- "a171", "a172", "a173", "a162", "a174", "a175", "a176", "a177",
- "a178", "a179", "a193", "a180", "a199", "a181", "a200", "a182",
- NULL, "a201", "a183", "a184", "a197", "a185", "a194", "a198",
- "a186", "a195", "a187", "a188", "a189", "a190", "a191", NULL
-};
-const FX_CHAR* PDF_CharNameFromPredefinedCharSet(int encoding, FX_BYTE charcode)
-{
- if (encoding == PDFFONT_ENCODING_PDFDOC) {
- if (charcode < 24) {
- return NULL;
- }
- charcode -= 24;
- } else {
- if (charcode < 32) {
- return NULL;
- }
- charcode -= 32;
- }
- switch (encoding) {
- case PDFFONT_ENCODING_WINANSI:
- return AdobeWinAnsiEncodingNames[charcode];
- case PDFFONT_ENCODING_MACROMAN:
- return MacRomanEncodingNames[charcode];
- case PDFFONT_ENCODING_MACEXPERT:
- return MacExpertEncodingNames[charcode];
- case PDFFONT_ENCODING_STANDARD:
- return StandardEncodingNames[charcode];
- case PDFFONT_ENCODING_ADOBE_SYMBOL:
- return AdobeSymbolEncodingNames[charcode];
- case PDFFONT_ENCODING_ZAPFDINGBATS:
- return ZapfEncodingNames[charcode];
- case PDFFONT_ENCODING_PDFDOC:
- return PDFDocEncodingNames[charcode];
- }
- return NULL;
-}
-FX_WCHAR FT_UnicodeFromCharCode(int encoding, FX_DWORD charcode)
-{
- switch (encoding) {
- case FXFT_ENCODING_UNICODE:
- return (FX_WORD)charcode;
- case FXFT_ENCODING_ADOBE_STANDARD:
- return StandardEncoding[(FX_BYTE)charcode];
- case FXFT_ENCODING_ADOBE_EXPERT:
- return MacExpertEncoding[(FX_BYTE)charcode];
- case FXFT_ENCODING_ADOBE_LATIN_1:
- return AdobeWinAnsiEncoding[(FX_BYTE)charcode];
- case FXFT_ENCODING_APPLE_ROMAN:
- return MacRomanEncoding[(FX_BYTE)charcode];
- case PDFFONT_ENCODING_PDFDOC:
- return PDFDocEncoding[(FX_BYTE)charcode];
- }
- return 0;
-}
-static FX_DWORD PDF_FindCode(const FX_WORD* pCodes, FX_WORD unicode)
-{
- for (FX_DWORD i = 0; i < 256; i ++)
- if (pCodes[i] == unicode) {
- return i;
- }
- return 0;
-}
-const FX_WORD MSSymbolEncoding[256] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 32, 33, 8704, 35, 8707, 37, 38, 8715,
- 40, 41, 8727, 43, 44, 8722, 46, 47, 48, 49,
- 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 60, 61, 62, 63, 8773, 913, 914, 935, 916, 917,
- 934, 915, 919, 921, 977, 922, 923, 924, 925, 927,
- 928, 920, 929, 931, 932, 933, 962, 937, 926, 936,
- 918, 91, 8756, 93, 8869, 95, 8254, 945, 946, 967,
- 948, 949, 966, 947, 951, 953, 981, 954, 955, 956,
- 957, 959, 960, 952, 961, 963, 964, 965, 982, 969,
- 958, 968, 950, 123, 124, 125, 8764, 0, 0, 0,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 978, 8242, 8804, 8725, 8734, 402, 9827, 9830, 9828,
- 9824, 8596, 8592, 8593, 8594, 8595, 176, 177, 8243, 8805,
- 215, 8733, 8706, 8729, 247, 8800, 8801, 8776, 8943, 0,
- 0, 8629, 0, 8465, 8476, 8472, 8855, 8853, 8709, 8745,
- 8746, 8835, 8839, 8836, 8834, 8838, 8712, 8713, 8736, 8711,
- 174, 169, 8482, 8719, 8730, 8901, 172, 8743, 8744, 8660,
- 8656, 8657, 8658, 8659, 9674, 9001, 0, 0, 0, 8721,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0x0000, 9002, 8747, 8992, 0, 8993, 0, 0, 0, 0,
- 0, 0, 0x0000, 0x0000, 0x0000, 0x0000
-};
-FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode)
-{
- switch (encoding) {
- case FXFT_ENCODING_UNICODE:
- return unicode;
- case FXFT_ENCODING_ADOBE_STANDARD:
- return PDF_FindCode(StandardEncoding, unicode);
- case FXFT_ENCODING_ADOBE_EXPERT:
- return PDF_FindCode(MacExpertEncoding, unicode);
- case FXFT_ENCODING_ADOBE_LATIN_1:
- return PDF_FindCode(AdobeWinAnsiEncoding, unicode);
- case FXFT_ENCODING_APPLE_ROMAN:
- return PDF_FindCode(MacRomanEncoding, unicode);
- case FXFT_ENCODING_ADOBE_CUSTOM:
- return PDF_FindCode(PDFDocEncoding, unicode);
- case FXFT_ENCODING_MS_SYMBOL:
- return PDF_FindCode(MSSymbolEncoding, unicode);
- }
- return 0;
-}
-const FX_WORD* PDF_UnicodesForPredefinedCharSet(int encoding)
-{
- switch (encoding) {
- case PDFFONT_ENCODING_WINANSI:
- return AdobeWinAnsiEncoding;
- case PDFFONT_ENCODING_MACROMAN:
- return MacRomanEncoding;
- case PDFFONT_ENCODING_MACEXPERT:
- return MacExpertEncoding;
- case PDFFONT_ENCODING_STANDARD:
- return StandardEncoding;
- case PDFFONT_ENCODING_ADOBE_SYMBOL:
- return AdobeSymbolEncoding;
- case PDFFONT_ENCODING_ZAPFDINGBATS:
- return ZapfEncoding;
- case PDFFONT_ENCODING_PDFDOC:
- return PDFDocEncoding;
- case PDFFONT_ENCODING_MS_SYMBOL:
- return MSSymbolEncoding;
- }
- return NULL;
-}
-FX_DWORD PDF_PredefinedCharCodeFromUnicode(int encoding, FX_WCHAR unicode)
-{
- return PDF_FindCode(PDF_UnicodesForPredefinedCharSet(encoding), unicode);
-}
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern int FXFT_unicode_from_adobe_name(const char* name);
-#ifdef __cplusplus
-}
-#endif
-FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR* name)
-{
- return (FX_WCHAR)(FXFT_unicode_from_adobe_name(name) & 0x7FFFFFFF);
-}
-CFX_ByteString PDF_AdobeNameFromUnicode(FX_WCHAR unicode)
-{
- char glyph_name[64];
- FXFT_adobe_name_from_unicode(glyph_name, unicode);
- return CFX_ByteString(glyph_name, -1);
-}
+// 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
+
+#include "../../../include/fpdfapi/fpdf_page.h"
+#include "../../../include/fxge/fx_freetype.h"
+extern FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR*);
+const struct _UnicodeAlt {
+ FX_WORD m_Unicode;
+ const FX_CHAR* m_Alter;
+}
+UnicodeAlts[] = {
+ {0x00a0, " "}, {0x00a1, "!"}, {0x00a2, "c"}, {0x00a3, "P"}, {0x00a4, "o"},
+ {0x00a5, "Y"}, {0x00a6, "|"}, {0x00a7, "S"}, {0x00a9, "(C)"}, {0x00aa, "a"},
+ {0x00ab, "<<"}, {0x00ac, "-|"}, {0x00ae, "(R)"}, {0x00af, "-"},
+ {0x00b0, "o"}, {0x00b1, "+/-"}, {0x00b2, "^2"}, { 0x00b3, "^3"},
+ {0x00b4, "'"}, {0x00b5, "u"}, {0x00b6, "P"}, {0x00b7, "."},
+ {0x00b9, "^1"}, {0x00ba, "o"}, {0x00bb, ">>"}, {0x00bc, "1/4"},
+ {0x00bd, "1/2"}, {0x00be, "3/4"}, {0x00bf, "?"}, {0x00c0, "A"},
+ {0x00c1, "A"}, {0x00c2, "A"}, {0x00c3, "A"}, {0x00c4, "A"},
+ {0x00c5, "A"}, {0x00c6, "AE"}, {0x00c7, "C"}, {0x00c8, "E"},
+ {0x00c9, "E"}, {0x00ca, "E"}, {0x00cb, "E"}, {0x00cc, "I"},
+ {0x00cd, "I"}, {0x00ce, "I"}, {0x00cf, "I"},
+ {0x00d1, "N"}, {0x00d2, "O"}, {0x00d3, "O"}, {0x00d4, "O"},
+ {0x00d5, "O"}, {0x00d6, "O"}, {0x00d7, "x"}, {0x00d8, "O"},
+ {0x00d9, "U"}, {0x00da, "U"}, {0x00db, "U"}, {0x00dc, "U"},
+ {0x00dd, "Y"}, {0x00df, "S"}, {0x00e0, "a"},
+ {0x00e1, "a"}, {0x00e2, "a"}, {0x00e3, "a"}, {0x00e4, "a"},
+ {0x00e5, "a"}, {0x00e6, "ae"}, {0x00e7, "c"}, {0x00e8, "e"},
+ {0x00e9, "e"}, {0x00ea, "e"}, {0x00eb, "e"}, {0x00ec, "i"},
+ {0x00ed, "i"}, {0x00ee, "i"}, {0x00ef, "i"},
+ {0x00f1, "n"}, {0x00f2, "o"}, {0x00f3, "o"}, {0x00f4, "o"},
+ {0x00f5, "o"}, {0x00f6, "o"}, {0x00f7, "/"}, {0x00f8, "o"},
+ {0x00f9, "u"}, {0x00fa, "u"}, {0x00fb, "u"}, {0x00fc, "u"},
+ {0x00fd, "y"}, {0x00ff, "y"},
+ {0x02b0, "h"}, {0x02b2, "j"}, {0x02b3, "r"}, {0x02b7, "w"},
+ {0x02b8, "y"}, {0x02b9, "'"}, {0x02ba, "\""}, {0x02bb, "'"},
+ {0x02bc, "'"}, {0x02bd, "'"}, {0x02be, "'"}, {0x02bf, "'"},
+ {0x02c2, "<"}, {0x02c3, ">"}, {0x02c4, "^"}, {0x02c5, "v"},
+ {0x02c6, "^"}, {0x02c7, "v"}, {0x02c8, "'"}, {0x02c9, "-"},
+ {0x02ca, "'"}, {0x02cb, "'"}, {0x02cc, "."}, {0x02cd, "_"},
+ {0x2010, "-"}, {0x2012, "-"}, {0x2013, "-"}, {0x2014, "--"},
+ {0x2015, "--"}, {0x2016, "|"}, {0x2017, "_"},
+ {0x2018, "'"}, {0x2019, "'"}, {0x201a, ","}, {0x201b, "'"},
+ {0x201c, "\""}, {0x201d, "\""}, {0x201e, ","}, {0x201f, "'"},
+ {0x2020, "+"}, {0x2021, "+"}, {0x2022, "*"}, {0x2023, ">"},
+ {0x2024, "."}, {0x2025, ".."}, {0x2027, "."}, {0x2032, "'"},
+ {0x2033, "\""}, {0x2035, "'"}, {0x2036, "\""}, {0x2038, "^"},
+ {0x2039, "<"}, {0x203a, ">"}, {0x203b, "*"}, {0x203c, "!!"},
+ {0x203d, "?!"}, {0x203e, "-"}, {0x2044, "/"}, {0x2047, "??"},
+ {0x2048, "?!"}, {0x2049, "!?"}, {0x204e, "*"}, {0x2052, "%"},
+ {0x2122, "(TM)"},
+ {0x2212, "-"}, {0x2215, "/"}, {0x2216, "\\"}, {0x2217, "*"},
+ {0x2218, "*"}, {0x2219, "*"}, {0x2223, "|"}, {0x22c5, "."},
+ {0x266f, "#"},
+ {0XF6D9, "(C)"}, {0XF6DA, "(C)"}, {0XF6DB, "(TM)"},
+ {0XF8E8, "(C)"}, {0xf8e9, "(C)"}, {0XF8EA, "(TM)"},
+
+ {0xfb01, "fi"}, {0xfb02, "fl"}
+};
+const FX_CHAR* FCS_GetAltStr(FX_WCHAR unicode)
+{
+ int begin = 0;
+ int end = sizeof UnicodeAlts / sizeof(struct _UnicodeAlt) - 1;
+ while (begin <= end) {
+ int middle = (begin + end) / 2;
+ FX_WORD middlecode = UnicodeAlts[middle].m_Unicode;
+ if (middlecode > unicode) {
+ end = middle - 1;
+ } else if (middlecode < unicode) {
+ begin = middle + 1;
+ } else {
+ return UnicodeAlts[middle].m_Alter;
+ }
+ }
+ return NULL;
+}
+const FX_WORD StandardEncoding[256] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x2019,
+ 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031,
+ 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b,
+ 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,
+ 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
+ 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x2018, 0x0061, 0x0062, 0x0063,
+ 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d,
+ 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
+ 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x00a1, 0x00a2, 0x00a3, 0x2044, 0x00a5, 0x0192, 0x00a7, 0x00a4, 0x0027,
+ 0x201c, 0x00ab, 0x2039, 0x203a, 0xfb01, 0xfb02, 0x0000, 0x2013, 0x2020, 0x2021,
+ 0x00b7, 0x0000, 0x00b6, 0x2022, 0x201a, 0x201e, 0x201d, 0x00bb, 0x2026, 0x2030,
+ 0x0000, 0x00bf, 0x0000, 0x0060, 0x00b4, 0x02c6, 0x02dc, 0x00af, 0x02d8, 0x02d9,
+ 0x00a8, 0x0000, 0x02da, 0x00b8, 0x0000, 0x02dd, 0x02db, 0x02c7, 0x2014, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00c6, 0x0000, 0x00aa, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0141, 0x00d8, 0x0152, 0x00ba, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x00e6, 0x0000, 0x0000, 0x0000, 0x0131, 0x0000, 0x0000, 0x0142, 0x00f8,
+ 0x0153, 0x00df, 0x0000, 0x0000, 0x0000, 0x0000
+};
+const FX_WORD MacRomanEncoding[256] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
+ 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031,
+ 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b,
+ 0x003c, 0x003d, 0x003e, 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045,
+ 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
+ 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, 0x0060, 0x0061, 0x0062, 0x0063,
+ 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d,
+ 0x006e, 0x006f, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
+ 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x0000, 0x00c4, 0x00c5,
+ 0x00c7, 0x00c9, 0x00d1, 0x00d6, 0x00dc, 0x00e1, 0x00e0, 0x00e2, 0x00e4, 0x00e3,
+ 0x00e5, 0x00e7, 0x00e9, 0x00e8, 0x00ea, 0x00eb, 0x00ed, 0x00ec, 0x00ee, 0x00ef,
+ 0x00f1, 0x00f3, 0x00f2, 0x00f4, 0x00f6, 0x00f5, 0x00fa, 0x00f9, 0x00fb, 0x00fc,
+ 0x2020, 0x00b0, 0x00a2, 0x00a3, 0x00a7, 0x2022, 0x00b6, 0x00df, 0x00ae, 0x00a9,
+ 0x2122, 0x00b4, 0x00a8, 0x0000, 0x00c6, 0x00d8, 0x0000, 0x00b1, 0x0000, 0x0000,
+ 0x00a5, 0x00b5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00aa, 0x00ba, 0x0000,
+ 0x00e6, 0x00f8, 0x00bf, 0x00a3, 0x00ac, 0x0000, 0x0192, 0x0000, 0x0000, 0x00ab,
+ 0x00bb, 0x2026, 0x0020, 0x00c0, 0x00c3, 0x00d5, 0x0152, 0x0153, 0x2013, 0x2014,
+ 0x201c, 0x201d, 0x2018, 0x2019, 0x00f7, 0x0000, 0x00ff, 0x0178, 0x2044, 0x00a4,
+ 0x2039, 0x203a, 0xfb01, 0xfb02, 0x2021, 0x00b7, 0x201a, 0x201e, 0x2030, 0x00c2,
+ 0x00ca, 0x00c1, 0x00cb, 0x00c8, 0x00cd, 0x00ce, 0x00cf, 0x00cc, 0x00d3, 0x00d4,
+ 0x0000, 0x00d2, 0x00da, 0x00db, 0x00d9, 0x0131, 0x02c6, 0x02dc, 0x00af, 0x02d8,
+ 0x02d9, 0x02da, 0x00b8, 0x02dd, 0x02db, 0x02c7
+};
+const FX_WORD AdobeWinAnsiEncoding[256] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
+ 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
+ 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
+ 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
+ 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
+ 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2022,
+ 0x20ac, 0x2022, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021,
+ 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x2022, 0x017d, 0x2022,
+ 0x2022, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014,
+ 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x2022, 0x017e, 0x0178,
+ 0x0020, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
+ 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x002d, 0x00ae, 0x00af,
+ 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
+ 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
+ 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7,
+ 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
+ 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
+ 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
+ 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
+ 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
+ 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
+ 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
+};
+extern const FX_WORD PDFDocEncoding[256];
+const FX_WORD MacExpertEncoding[256] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0020, 0xf721, 0xf6f8, 0xf7a2, 0xf724, 0xf6e4, 0xf726, 0xf7b4,
+ 0x207d, 0x207e, 0x2025, 0x2024, 0x002c, 0x002d, 0x002e, 0x2044, 0xf730, 0xf731,
+ 0xf732, 0xf733, 0xf734, 0xf735, 0xf736, 0xf737, 0xf738, 0xf739, 0x003a, 0x003b,
+ 0x0000, 0xf6de, 0x0000, 0xf73f, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7f0, 0x0000,
+ 0x0000, 0x00bc, 0x00bd, 0x00be, 0x215b, 0x215c, 0x215d, 0x215e, 0x2153, 0x2154,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xfb00, 0xfb01, 0xfb02, 0xfb03,
+ 0xfb04, 0x208d, 0x0000, 0x208e, 0xf6f6, 0xf6e5, 0xf760, 0xf761, 0xf762, 0xf763,
+ 0xf764, 0xf765, 0xf766, 0xf767, 0xf768, 0xf769, 0xf76a, 0xf76b, 0xf76c, 0xf76d,
+ 0xf76e, 0xf76f, 0xf770, 0xf771, 0xf772, 0xf773, 0xf774, 0xf775, 0xf776, 0xf777,
+ 0xf778, 0xf779, 0xf77a, 0x20a1, 0xf6dc, 0xf6dd, 0xf6fe, 0x0000, 0x0000, 0xf6e9,
+ 0xf6e0, 0x0000, 0x0000, 0x0000, 0x0000, 0xf7e1, 0xf7e0, 0xf7e2, 0xf7e4, 0xf7e3,
+ 0xf7e5, 0xf7e7, 0xf7e9, 0xf7e8, 0xf7ea, 0xf7eb, 0xf7ed, 0xf7ec, 0xf7ee, 0xf7ef,
+ 0xf7f1, 0xf7f3, 0xf7f2, 0xf7f4, 0xf7f6, 0xf7f5, 0xf7fa, 0xf7f9, 0xf7fb, 0xf7fc,
+ 0x0000, 0x2078, 0x2084, 0x2083, 0x2086, 0x2088, 0x2087, 0xf6fd, 0x0000, 0xf6df,
+ 0x2082, 0x0000, 0xf7a8, 0x0000, 0xf6f5, 0xf6fd, 0x2085, 0x0000, 0xf6e1, 0xf6e7,
+ 0xf7fd, 0x0000, 0xf6e3, 0x0000, 0x0000, 0xf7fe, 0x0000, 0x2089, 0x2080, 0xf6ff,
+ 0xf7e6, 0xf7f8, 0xf7bf, 0x2081, 0xf6e9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0xf7b8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf6fa, 0x2012, 0xf6e6,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0xf7a1, 0x0000, 0xf7ff, 0x0000, 0x00b9, 0x00b2,
+ 0x00b3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2079, 0x2070, 0x0000, 0xf6ec, 0xf6f1,
+ 0x0000, 0x0000, 0x0000, 0xf6ed, 0xf6f2, 0xf6eb, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0xf6ee, 0xf6fb, 0xf6f4, 0xf7af, 0xf6ea, 0x207f, 0xf6ef, 0xf6e2, 0xf6e8,
+ 0xf6f7, 0xf6fc, 0x0000, 0x0000, 0x0000, 0x0000
+};
+const FX_WORD AdobeSymbolEncoding[256] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220B,
+ 0x0028, 0x0029, 0x2217, 0x002B, 0x002C, 0x2212, 0x002E, 0x002F,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
+ 0x2245, 0x0391, 0x0392, 0x03A7, 0x0394, 0x0395, 0x03A6, 0x0393,
+ 0x0397, 0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F,
+ 0x03A0, 0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03C2, 0x03A9,
+ 0x039E, 0x03A8, 0x0396, 0x005B, 0x2234, 0x005D, 0x22A5, 0x005F,
+ 0xF8E5, 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03C6, 0x03B3,
+ 0x03B7, 0x03B9, 0x03D5, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF,
+ 0x03C0, 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03C9,
+ 0x03BE, 0x03C8, 0x03B6, 0x007B, 0x007C, 0x007D, 0x223C, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x20AC, 0x03D2, 0x2032, 0x2264, 0x2044, 0x221E, 0x0192, 0x2663,
+ 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193,
+ 0x00B0, 0x00B1, 0x2033, 0x2265, 0x00D7, 0x221D, 0x2202, 0x2022,
+ 0x00F7, 0x2260, 0x2261, 0x2248, 0x2026, 0xF8E6, 0xF8E7, 0x21B5,
+ 0x2135, 0x2111, 0x211C, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229,
+ 0x222A, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209,
+ 0x2220, 0x2207, 0xF6DA, 0xF6D9, 0xF6DB, 0x220F, 0x221A, 0x22C5,
+ 0x00AC, 0x2227, 0x2228, 0x21D4, 0x21D0, 0x21D1, 0x21D2, 0x21D3,
+ 0x25CA, 0x2329, 0xF8E8, 0xF8E9, 0xF8EA, 0x2211, 0xF8EB, 0xF8EC,
+ 0xF8ED, 0xF8EE, 0xF8EF, 0xF8F0, 0xF8F1, 0xF8F2, 0xF8F3, 0xF8F4,
+ 0x0000, 0x232A, 0x222B, 0x2320, 0xF8F5, 0x2321, 0xF8F6, 0xF8F7,
+ 0xF8F8, 0xF8F9, 0xF8FA, 0xF8FB, 0xF8FC, 0xF8FD, 0xF8FE, 0x0000,
+};
+const FX_WORD ZapfEncoding[256] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0020, 0x2701, 0x2702, 0x2703, 0x2704, 0x260E, 0x2706, 0x2707,
+ 0x2708, 0x2709, 0x261B, 0x261E, 0x270C, 0x270D, 0x270E, 0x270F,
+ 0x2710, 0x2711, 0x2712, 0x2713, 0x2714, 0x2715, 0x2716, 0x2717,
+ 0x2718, 0x2719, 0x271A, 0x271B, 0x271C, 0x271D, 0x271E, 0x271F,
+ 0x2720, 0x2721, 0x2722, 0x2723, 0x2724, 0x2725, 0x2726, 0x2727,
+ 0x2605, 0x2729, 0x272A, 0x272B, 0x272C, 0x272D, 0x272E, 0x272F,
+ 0x2730, 0x2731, 0x2732, 0x2733, 0x2734, 0x2735, 0x2736, 0x2737,
+ 0x2738, 0x2739, 0x273A, 0x273B, 0x273C, 0x273D, 0x273E, 0x273F,
+ 0x2740, 0x2741, 0x2742, 0x2743, 0x2744, 0x2745, 0x2746, 0x2747,
+ 0x2748, 0x2749, 0x274A, 0x274B, 0x25CF, 0x274D, 0x25A0, 0x274F,
+ 0x2750, 0x2751, 0x2752, 0x25B2, 0x25BC, 0x25C6, 0x2756, 0x25D7,
+ 0x2758, 0x2759, 0x275A, 0x275B, 0x275C, 0x275D, 0x275E, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x2761, 0x2762, 0x2763, 0x2764, 0x2765, 0x2766, 0x2767,
+ 0x2663, 0x2666, 0x2665, 0x2660, 0x2460, 0x2461, 0x2462, 0x2463,
+ 0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x2776, 0x2777,
+ 0x2778, 0x2779, 0x277A, 0x277B, 0x277C, 0x277D, 0x277E, 0x277F,
+ 0x2780, 0x2781, 0x2782, 0x2783, 0x2784, 0x2785, 0x2786, 0x2787,
+ 0x2788, 0x2789, 0x278A, 0x278B, 0x278C, 0x278D, 0x278E, 0x278F,
+ 0x2790, 0x2791, 0x2792, 0x2793, 0x2794, 0x2192, 0x2194, 0x2195,
+ 0x2798, 0x2799, 0x279A, 0x279B, 0x279C, 0x279D, 0x279E, 0x279F,
+ 0x27A0, 0x27A1, 0x27A2, 0x27A3, 0x27A4, 0x27A5, 0x27A6, 0x27A7,
+ 0x27A8, 0x27A9, 0x27AA, 0x27AB, 0x27AC, 0x27AD, 0x27AE, 0x27AF,
+ 0x0000, 0x27B1, 0x27B2, 0x27B3, 0x27B4, 0x27B5, 0x27B6, 0x27B7,
+ 0x27B8, 0x27B9, 0x27BA, 0x27BB, 0x27BC, 0x27BD, 0x27BE, 0x0000,
+};
+const FX_LPCSTR StandardEncodingNames[224] = {
+ "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright",
+ "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
+ "zero", "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "at", "A", "B", "C", "D", "E", "F", "G",
+ "H", "I", "J", "K", "L", "M", "N", "O",
+ "P", "Q", "R", "S", "T", "U", "V", "W",
+ "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
+ "quoteleft", "a", "b", "c", "d", "e", "f", "g",
+ "h", "i", "j", "k", "l", "m", "n", "o",
+ "p", "q", "r", "s", "t", "u", "v", "w",
+ "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section",
+ "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl",
+ NULL, "endash", "dagger", "daggerdbl", "periodcentered", NULL, "paragraph", "bullet",
+ "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", NULL, "questiondown",
+ NULL, "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent",
+ "dieresis", NULL, "ring", "cedilla", NULL, "hungarumlaut", "ogonek", "caron",
+ "emdash", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, "AE", NULL, "ordfeminine", NULL, NULL, NULL, NULL,
+ "Lslash", "Oslash", "OE", "ordmasculine", NULL, NULL, NULL, NULL,
+ NULL, "ae", NULL, NULL, NULL, "dotlessi", NULL, NULL,
+ "lslash", "oslash", "oe", "germandbls", NULL, NULL, NULL, NULL,
+};
+const FX_LPCSTR AdobeWinAnsiEncodingNames[224] = {
+ "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle",
+ "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
+ "zero", "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "at", "A", "B", "C", "D", "E", "F", "G",
+ "H", "I", "J", "K", "L", "M", "N", "O",
+ "P", "Q", "R", "S", "T", "U", "V", "W",
+ "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
+ "grave", "a", "b", "c", "d", "e", "f", "g",
+ "h", "i", "j", "k", "l", "m", "n", "o",
+ "p", "q", "r", "s", "t", "u", "v", "w",
+ "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "bullet",
+ "Euro", "bullet", "quotesinglbase", "florin", "quotedblbase", "ellipsis", "dagger", "daggerdbl",
+ "circumflex", "perthousand", "Scaron", "guilsinglleft", "OE", "bullet", "Zcaron", "bullet",
+ "bullet", "quoteleft", "quoteright", "quotedblleft", "quotedblright", "bullet", "endash", "emdash",
+ "tilde", "trademark", "scaron", "guilsinglright", "oe", "bullet", "zcaron", "Ydieresis",
+ "space", "exclamdown", "cent", "sterling", "currency", "yen", "brokenbar", "section",
+ "dieresis", "copyright", "ordfeminine", "guillemotleft", "logicalnot", "hyphen", "registered", "macron",
+ "degree", "plusminus", "twosuperior", "threesuperior", "acute", "mu", "paragraph", "periodcentered",
+ "cedilla", "onesuperior", "ordmasculine", "guillemotright", "onequarter", "onehalf", "threequarters", "questiondown",
+ "Agrave", "Aacute", "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla",
+ "Egrave", "Eacute", "Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex", "Idieresis",
+ "Eth", "Ntilde", "Ograve", "Oacute", "Ocircumflex", "Otilde", "Odieresis", "multiply",
+ "Oslash", "Ugrave", "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls",
+ "agrave", "aacute", "acircumflex", "atilde", "adieresis", "aring", "ae", "ccedilla",
+ "egrave", "eacute", "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex", "idieresis",
+ "eth", "ntilde", "ograve", "oacute", "ocircumflex", "otilde", "odieresis", "divide",
+ "oslash", "ugrave", "uacute", "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis",
+};
+const FX_LPCSTR MacRomanEncodingNames[224] = {
+ "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle",
+ "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
+ "zero", "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "at", "A", "B", "C", "D", "E", "F", "G",
+ "H", "I", "J", "K", "L", "M", "N", "O",
+ "P", "Q", "R", "S", "T", "U", "V", "W",
+ "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
+ "grave", "a", "b", "c", "d", "e", "f", "g",
+ "h", "i", "j", "k", "l", "m", "n", "o",
+ "p", "q", "r", "s", "t", "u", "v", "w",
+ "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", NULL,
+ "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute",
+ "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave",
+ "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute",
+ "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis",
+ "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls",
+ "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash",
+ "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff", "summation",
+ "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash",
+ "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft",
+ "guillemotright", "ellipsis", "space", "Agrave", "Atilde", "Otilde", "OE", "oe",
+ "endash", "emdash", "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge",
+ "ydieresis", "Ydieresis", "fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl",
+ "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", "Ecircumflex", "Aacute",
+ "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
+ "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde",
+ "macron", "breve", "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron",
+};
+const FX_LPCSTR MacExpertEncodingNames[224] = {
+ "space", "exclamsmall", "Hungarumlautsmall", "centoldstyle", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall",
+ "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction",
+ "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle",
+ "eightoldstyle", "nineoldstyle", "colon", "semicolon", NULL, "threequartersemdash", NULL, "questionsmall",
+ NULL, NULL, NULL, NULL, "Ethsmall", NULL, NULL, "onequarter",
+ "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds",
+ NULL, NULL, NULL, NULL, NULL, NULL, "ff", "fi",
+ "fl", "ffi", "ffl", "parenleftinferior", NULL, "parenrightinferior", "Circumflexsmall", "hypheninferior",
+ "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall",
+ "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall",
+ "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall",
+ "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", NULL,
+ NULL, "asuperior", "centsuperior", NULL, NULL, NULL, NULL, "Aacutesmall",
+ "Agravesmall", "Acircumflexsmall", "Adieresissmall", "Atildesmall", "Aringsmall", "Ccedillasmall", "Eacutesmall", "Egravesmall",
+ "Ecircumflexsmall", "Edieresissmall", "Iacutesmall", "Igravesmall", "Icircumflexsmall", "Idieresissmall", "Ntildesmall", "Oacutesmall",
+ "Ogravesmall", "Ocircumflexsmall", "Odieresissmall", "Otildesmall", "Uacutesmall", "Ugravesmall", "Ucircumflexsmall", "Udieresissmall",
+ NULL, "eightsuperior", "fourinferior", "threeinferior", "sixinferior", "eightinferior", "seveninferior", "Scaronsmall",
+ NULL, "centinferior", "twoinferior", NULL, "Dieresissmall", NULL, "Caronsmall", "Scaronsmall",
+ "fiveinferior", NULL, "commainferior", "periodinferior", "Yacutesmall", NULL, "dollarinferior", NULL,
+ NULL, "Thornsmall", NULL, "nineinferior", "zeroinferior", "Zcaronsmall", "AEsmall", "Oslashsmall",
+ "questiondownsmall", "oneinferior", "asuperior", NULL, NULL, NULL, NULL, NULL,
+ NULL, "Cedillasmall", NULL, NULL, NULL, NULL, NULL, "OEsmall",
+ "figuredash", "hyphensuperior", NULL, NULL, NULL, NULL, "exclamdownsmall", NULL,
+ "Ydieresissmall", NULL, "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior",
+ "sevensuperior", "ninesuperior", "zerosuperior", NULL, "esuperior", "rsuperior", NULL, NULL,
+ NULL, "isuperior", "ssuperior", "dsuperior", NULL, NULL, NULL, NULL,
+ NULL, "lsuperior", "Ogoneksmall", "Brevesmall", "Macronsmall", "bsuperior", "nsuperior", "msuperior",
+ "commasuperior", "periodsuperior", "Dotaccentsmall", "Ringsmall", NULL, NULL, NULL, NULL,
+};
+const FX_LPCSTR PDFDocEncodingNames[232] = {
+ "breve", "caron", "circumflex", "dotaccent", "hungarumlaut", "ogonek", "ring", "tilde",
+ "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle",
+ "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
+ "zero", "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "at", "A", "B", "C", "D", "E", "F", "G",
+ "H", "I", "J", "K", "L", "M", "N", "O",
+ "P", "Q", "R", "S", "T", "U", "V", "W",
+ "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
+ "grave", "a", "b", "c", "d", "e", "f", "g",
+ "h", "i", "j", "k", "l", "m", "n", "o",
+ "p", "q", "r", "s", "t", "u", "v", "w",
+ "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", NULL,
+ "bullet3", "dagger", "daggerdbl", "ellipsis", "emdash", "endash", "florin", "fraction",
+ "guilsinglleft", "guilsinglright", "minus", "perthousand", "quotedblbase", "quotedblleft", "quotedblright", "quoteleft",
+ "quoteright", "quotesinglbase", "trademark", "fi", "fl", "Lslash", "OE", "Scaron",
+ "Ydieresis", "Zcaron2", "dotlessi", "lslash", "oe", "scaron", "zcaron2", NULL,
+ "Euro", "exclamdown", "cent", "sterling", "currency", "yen", "brokenbar", "section",
+ "dieresis", "copyright", "ordfeminine", "guillemotleft4", "logicalnot", NULL, "registered", "macron",
+ "degree", "plusminus", "twosuperior", "threesuperior", "acute", "mu", "paragraph", "periodcentered",
+ "cedilla", "onesuperior", "ordmasculine", "guillemotright4", "onequarter", "onehalf", "threequarters", "questiondown",
+ "Agrave", "Aacute", "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla",
+ "Egrave", "Eacute", "Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex", "Idieresis",
+ "Eth", "Ntilde", "Ograve", "Oacute", "Ocircumflex", "Otilde", "Odieresis", "multiply",
+ "Oslash", "Ugrave", "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls",
+ "agrave", "aacute", "acircumflex", "atilde", "adieresis", "aring", "ae", "ccedilla",
+ "egrave", "eacute", "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex", "idieresis",
+ "eth", "ntilde", "ograve", "oacute", "ocircumflex", "otilde", "odieresis", "divide",
+ "oslash", "ugrave", "uacute", "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis",
+};
+const FX_LPCSTR AdobeSymbolEncodingNames[224] = {
+ "space", "exclam", "universal", "numbersign", "existential", "percent", "ampersand", "suchthat",
+ "parenleft", "parenright", "asteriskmath", "plus", "comma", "minus", "period", "slash",
+ "zero", "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "congruent", "Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi", "Gamma",
+ "Eta", "Iota", "theta1", "Kappa", "Lambda", "Mu", "Nu", "Omicron",
+ "Pi", "Theta", "Rho", "Sigma", "Tau", "Upsilon", "sigma1", "Omega",
+ "Xi", "Psi", "Zeta", "bracketleft", "therefore", "bracketright", "perpendicular", "underscore",
+ "radicalex", "alpha", "beta", "chi", "delta", "epsilon", "phi", "gamma",
+ "eta", "iota", "phi1", "kappa", "lambda", "mu", "nu", "omicron",
+ "pi", "theta", "rho", "sigma", "tau", "upsilon", "omega1", "omega",
+ "xi", "psi", "zeta", "braceleft", "bar", "braceright", "similar", NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ "Euro", "Upsilon1", "minute", "lessequal", "fraction", "infinity", "florin", "club",
+ "diamond", "heart", "spade", "arrowboth", "arrowleft", "arrowup", "arrowright", "arrowdown",
+ "degree", "plusminus", "second", "greaterequal", "multiply", "proportional", "partialdiff", "bullet",
+ "divide", "notequal", "equivalence", "approxequal", "ellipsis", "arrowvertex", "arrowhorizex", "carriagereturn",
+ "aleph", "Ifraktur", "Rfraktur", "weierstrass", "circlemultiply", "circleplus", "emptyset", "intersection",
+ "union", "propersuperset", "reflexsuperset", "notsubset", "propersubset", "reflexsubset", "element", "notelement",
+ "angle", "gradient", "registerserif", "copyrightserif", "trademarkserif", "product", "radical", "dotmath",
+ "logicalnot", "logicaland", "logicalor", "arrowdblboth", "arrowdblleft", "arrowdblup", "arrowdblright", "arrowdbldown",
+ "lozenge", "angleleft", "registersans", "copyrightsans", "trademarksans", "summation", "parenlefttp", "parenleftex",
+ "parenleftbt", "bracketlefttp", "bracketleftex", "bracketleftbt", "bracelefttp", "braceleftmid", "braceleftbt", "braceex",
+ NULL, "angleright", "integral", "integraltp", "integralex", "integralbt", "parenrighttp", "parenrightex",
+ "parenrightbt", "bracketrighttp", "bracketrightex", "bracketrightbt", "bracerighttp", "bracerightmid", "bracerightbt", NULL,
+};
+const FX_LPCSTR ZapfEncodingNames[224] = {
+ "space", "a1", "a2", "a202", "a3", "a4", "a5", "a119",
+ "a118", "a117", "a11", "a12", "a13", "a14", "a15", "a16",
+ "a105", "a17", "a18", "a19", "a20", "a21", "a22", "a23",
+ "a24", "a25", "a26", "a27", "a28", "a6", "a7", "a8",
+ "a9", "a10", "a29", "a30", "a31", "a32", "a33", "a34",
+ "a35", "a36", "a37", "a38", "a39", "a40", "a41", "a42",
+ "a43", "a44", "a45", "a46", "a47", "a48", "a49", "a50",
+ "a51", "a52", "a53", "a54", "a55", "a56", "a57", "a58",
+ "a59", "a60", "a61", "a62", "a63", "a64", "a65", "a66",
+ "a67", "a68", "a69", "a70", "a71", "a72", "a73", "a74",
+ "a203", "a75", "a204", "a76", "a77", "a78", "a79", "a81",
+ "a82", "a83", "a84", "a97", "a98", "a99", "a100", NULL,
+ "a89", "a90", "a93", "a94", "a91", "a92", "a205", "a85",
+ "a206", "a86", "a87", "a88", "a95", "a96", NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, "a101", "a102", "a103", "a104", "a106", "a107", "a108",
+ "a112", "a111", "a110", "a109", "a120", "a121", "a122", "a123",
+ "a124", "a125", "a126", "a127", "a128", "a129", "a130", "a131",
+ "a132", "a133", "a134", "a135", "a136", "a137", "a138", "a139",
+ "a140", "a141", "a142", "a143", "a144", "a145", "a146", "a147",
+ "a148", "a149", "a150", "a151", "a152", "a153", "a154", "a155",
+ "a156", "a157", "a158", "a159", "a160", "a161", "a163", "a164",
+ "a196", "a165", "a192", "a166", "a167", "a168", "a169", "a170",
+ "a171", "a172", "a173", "a162", "a174", "a175", "a176", "a177",
+ "a178", "a179", "a193", "a180", "a199", "a181", "a200", "a182",
+ NULL, "a201", "a183", "a184", "a197", "a185", "a194", "a198",
+ "a186", "a195", "a187", "a188", "a189", "a190", "a191", NULL
+};
+const FX_CHAR* PDF_CharNameFromPredefinedCharSet(int encoding, FX_BYTE charcode)
+{
+ if (encoding == PDFFONT_ENCODING_PDFDOC) {
+ if (charcode < 24) {
+ return NULL;
+ }
+ charcode -= 24;
+ } else {
+ if (charcode < 32) {
+ return NULL;
+ }
+ charcode -= 32;
+ }
+ switch (encoding) {
+ case PDFFONT_ENCODING_WINANSI:
+ return AdobeWinAnsiEncodingNames[charcode];
+ case PDFFONT_ENCODING_MACROMAN:
+ return MacRomanEncodingNames[charcode];
+ case PDFFONT_ENCODING_MACEXPERT:
+ return MacExpertEncodingNames[charcode];
+ case PDFFONT_ENCODING_STANDARD:
+ return StandardEncodingNames[charcode];
+ case PDFFONT_ENCODING_ADOBE_SYMBOL:
+ return AdobeSymbolEncodingNames[charcode];
+ case PDFFONT_ENCODING_ZAPFDINGBATS:
+ return ZapfEncodingNames[charcode];
+ case PDFFONT_ENCODING_PDFDOC:
+ return PDFDocEncodingNames[charcode];
+ }
+ return NULL;
+}
+FX_WCHAR FT_UnicodeFromCharCode(int encoding, FX_DWORD charcode)
+{
+ switch (encoding) {
+ case FXFT_ENCODING_UNICODE:
+ return (FX_WORD)charcode;
+ case FXFT_ENCODING_ADOBE_STANDARD:
+ return StandardEncoding[(FX_BYTE)charcode];
+ case FXFT_ENCODING_ADOBE_EXPERT:
+ return MacExpertEncoding[(FX_BYTE)charcode];
+ case FXFT_ENCODING_ADOBE_LATIN_1:
+ return AdobeWinAnsiEncoding[(FX_BYTE)charcode];
+ case FXFT_ENCODING_APPLE_ROMAN:
+ return MacRomanEncoding[(FX_BYTE)charcode];
+ case PDFFONT_ENCODING_PDFDOC:
+ return PDFDocEncoding[(FX_BYTE)charcode];
+ }
+ return 0;
+}
+static FX_DWORD PDF_FindCode(const FX_WORD* pCodes, FX_WORD unicode)
+{
+ for (FX_DWORD i = 0; i < 256; i ++)
+ if (pCodes[i] == unicode) {
+ return i;
+ }
+ return 0;
+}
+const FX_WORD MSSymbolEncoding[256] = {
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 32, 33, 8704, 35, 8707, 37, 38, 8715,
+ 40, 41, 8727, 43, 44, 8722, 46, 47, 48, 49,
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, 62, 63, 8773, 913, 914, 935, 916, 917,
+ 934, 915, 919, 921, 977, 922, 923, 924, 925, 927,
+ 928, 920, 929, 931, 932, 933, 962, 937, 926, 936,
+ 918, 91, 8756, 93, 8869, 95, 8254, 945, 946, 967,
+ 948, 949, 966, 947, 951, 953, 981, 954, 955, 956,
+ 957, 959, 960, 952, 961, 963, 964, 965, 982, 969,
+ 958, 968, 950, 123, 124, 125, 8764, 0, 0, 0,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 978, 8242, 8804, 8725, 8734, 402, 9827, 9830, 9828,
+ 9824, 8596, 8592, 8593, 8594, 8595, 176, 177, 8243, 8805,
+ 215, 8733, 8706, 8729, 247, 8800, 8801, 8776, 8943, 0,
+ 0, 8629, 0, 8465, 8476, 8472, 8855, 8853, 8709, 8745,
+ 8746, 8835, 8839, 8836, 8834, 8838, 8712, 8713, 8736, 8711,
+ 174, 169, 8482, 8719, 8730, 8901, 172, 8743, 8744, 8660,
+ 8656, 8657, 8658, 8659, 9674, 9001, 0, 0, 0, 8721,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0x0000, 9002, 8747, 8992, 0, 8993, 0, 0, 0, 0,
+ 0, 0, 0x0000, 0x0000, 0x0000, 0x0000
+};
+FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode)
+{
+ switch (encoding) {
+ case FXFT_ENCODING_UNICODE:
+ return unicode;
+ case FXFT_ENCODING_ADOBE_STANDARD:
+ return PDF_FindCode(StandardEncoding, unicode);
+ case FXFT_ENCODING_ADOBE_EXPERT:
+ return PDF_FindCode(MacExpertEncoding, unicode);
+ case FXFT_ENCODING_ADOBE_LATIN_1:
+ return PDF_FindCode(AdobeWinAnsiEncoding, unicode);
+ case FXFT_ENCODING_APPLE_ROMAN:
+ return PDF_FindCode(MacRomanEncoding, unicode);
+ case FXFT_ENCODING_ADOBE_CUSTOM:
+ return PDF_FindCode(PDFDocEncoding, unicode);
+ case FXFT_ENCODING_MS_SYMBOL:
+ return PDF_FindCode(MSSymbolEncoding, unicode);
+ }
+ return 0;
+}
+const FX_WORD* PDF_UnicodesForPredefinedCharSet(int encoding)
+{
+ switch (encoding) {
+ case PDFFONT_ENCODING_WINANSI:
+ return AdobeWinAnsiEncoding;
+ case PDFFONT_ENCODING_MACROMAN:
+ return MacRomanEncoding;
+ case PDFFONT_ENCODING_MACEXPERT:
+ return MacExpertEncoding;
+ case PDFFONT_ENCODING_STANDARD:
+ return StandardEncoding;
+ case PDFFONT_ENCODING_ADOBE_SYMBOL:
+ return AdobeSymbolEncoding;
+ case PDFFONT_ENCODING_ZAPFDINGBATS:
+ return ZapfEncoding;
+ case PDFFONT_ENCODING_PDFDOC:
+ return PDFDocEncoding;
+ case PDFFONT_ENCODING_MS_SYMBOL:
+ return MSSymbolEncoding;
+ }
+ return NULL;
+}
+FX_DWORD PDF_PredefinedCharCodeFromUnicode(int encoding, FX_WCHAR unicode)
+{
+ return PDF_FindCode(PDF_UnicodesForPredefinedCharSet(encoding), unicode);
+}
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int FXFT_unicode_from_adobe_name(const char* name);
+#ifdef __cplusplus
+}
+#endif
+FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR* name)
+{
+ return (FX_WCHAR)(FXFT_unicode_from_adobe_name(name) & 0x7FFFFFFF);
+}
+CFX_ByteString PDF_AdobeNameFromUnicode(FX_WCHAR unicode)
+{
+ char glyph_name[64];
+ FXFT_adobe_name_from_unicode(glyph_name, unicode);
+ return CFX_ByteString(glyph_name, -1);
+}
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 891d82fa1a..23bbc4aab9 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -1,1716 +1,1716 @@
-// 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
-
-#include "../../../include/fpdfapi/fpdf_module.h"
-#include "../../../include/fpdfapi/fpdf_page.h"
-#include "font_int.h"
-#include "../fpdf_cmaps/cmap_int.h"
-#include "../../../include/fxge/fx_ge.h"
-#include "../../../include/fxge/fx_freetype.h"
-extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode);
-extern FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name);
-extern FX_BOOL FXFC_LoadFile(FX_LPVOID pPackage, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD& size);
-extern void FXFC_ClosePackage(FX_LPVOID pPackage);
-extern short TT2PDF(int m, FXFT_Face face);
-extern FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id);
-extern FX_LPCSTR GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pCharNames, int charcode);
-CPDF_CMapManager::CPDF_CMapManager()
-{
-#ifndef _FPDFAPI_MINI_
- m_bPrompted = FALSE;
- m_pPackage = NULL;
-#endif
- FXSYS_memset32(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps);
-}
-CPDF_CMapManager::~CPDF_CMapManager()
-{
- DropAll(FALSE);
-#ifndef _FPDFAPI_MINI_
- if (m_pPackage) {
- FXFC_ClosePackage(m_pPackage);
- }
-#endif
-}
-#ifndef _FPDFAPI_MINI_
-FX_LPVOID CPDF_CMapManager::GetPackage(FX_BOOL bPrompt)
-{
-#ifndef FOXIT_CHROME_BUILD
- if (m_pPackage == NULL) {
- CFX_ByteString filename = CPDF_ModuleMgr::Get()->GetModuleFilePath(ADDIN_NAME_CJK, "FPDFCJK.BIN");
- m_pPackage = FXFC_LoadPackage(filename);
- if (bPrompt && m_pPackage == NULL && !m_bPrompted) {
- m_bPrompted = TRUE;
- if (!CPDF_ModuleMgr::Get()->DownloadModule(ADDIN_NAME_CJK)) {
- return NULL;
- }
- m_pPackage = FXFC_LoadPackage(filename);
- }
- }
-#endif
- return m_pPackage;
-}
-#endif
-CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPromptCJK)
-{
- CPDF_CMap* pCMap;
- if (m_CMaps.Lookup(name, (FX_LPVOID&)pCMap)) {
- return pCMap;
- }
- pCMap = LoadPredefinedCMap(name, bPromptCJK);
- if (name.IsEmpty()) {
- return pCMap;
- }
- m_CMaps.SetAt(name, pCMap);
- return pCMap;
-}
-CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPromptCJK)
-{
- CPDF_CMap* pCMap = FX_NEW CPDF_CMap;
- FX_LPCSTR pname = name;
- if (*pname == '/') {
- pname ++;
- }
- pCMap->LoadPredefined(this, pname, bPromptCJK);
- return pCMap;
-}
-const FX_LPCSTR g_CharsetNames[] = {NULL, "GB1", "CNS1", "Japan1", "Korea1", "UCS", NULL};
-const int g_CharsetCPs[] = {0, 936, 950, 932, 949, 1200, 0};
-int _CharsetFromOrdering(const CFX_ByteString& Ordering)
-{
- int charset = 1;
- while (g_CharsetNames[charset] && Ordering != CFX_ByteStringC(g_CharsetNames[charset])) {
- charset ++;
- }
- if (g_CharsetNames[charset] == NULL) {
- return CIDSET_UNKNOWN;
- }
- return charset;
-}
-void CPDF_CMapManager::ReloadAll()
-{
- DropAll(TRUE);
-}
-void CPDF_CMapManager::DropAll(FX_BOOL bReload)
-{
- FX_POSITION pos = m_CMaps.GetStartPosition();
- while (pos) {
- CFX_ByteString name;
- CPDF_CMap* pCMap;
- m_CMaps.GetNextAssoc(pos, name, (FX_LPVOID&)pCMap);
- if (pCMap == NULL) {
- continue;
- }
- if (bReload) {
- pCMap->LoadPredefined(this, name, FALSE);
- } else {
- delete pCMap;
- }
- }
- for (int i = 0; i < sizeof m_CID2UnicodeMaps / sizeof(CPDF_CID2UnicodeMap*); i ++) {
- CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i];
- if (pMap == NULL) {
- continue;
- }
- if (bReload) {
- pMap->Load(this, i, FALSE);
- } else {
- delete pMap;
- }
- }
-}
-CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(int charset, FX_BOOL bPromptCJK)
-{
- if (m_CID2UnicodeMaps[charset] == NULL) {
- m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
- }
- return m_CID2UnicodeMaps[charset];
-}
-CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(int charset, FX_BOOL bPromptCJK)
-{
- CPDF_CID2UnicodeMap* pMap = FX_NEW CPDF_CID2UnicodeMap();
- if (!pMap->Initialize()) {
- delete pMap;
- return NULL;
- }
- pMap->Load(this, charset, bPromptCJK);
- return pMap;
-}
-CPDF_CMapParser::CPDF_CMapParser()
-{
- m_pCMap = NULL;
- m_Status = 0;
- m_CodeSeq = 0;
-}
-FX_BOOL CPDF_CMapParser::Initialize(CPDF_CMap* pCMap)
-{
- m_pCMap = pCMap;
- m_Status = 0;
- m_CodeSeq = 0;
- m_AddMaps.EstimateSize(0, 10240);
- return TRUE;
-}
-static FX_DWORD CMap_GetCode(FX_BSTR word)
-{
- int num = 0;
- if (word.GetAt(0) == '<') {
- for (int i = 1; i < word.GetLength(); i ++) {
- FX_BYTE digit = word.GetAt(i);
- if (digit >= '0' && digit <= '9') {
- digit = digit - '0';
- } else if (digit >= 'a' && digit <= 'f') {
- digit = digit - 'a' + 10;
- } else if (digit >= 'A' && digit <= 'F') {
- digit = digit - 'A' + 10;
- } else {
- return num;
- }
- num = num * 16 + digit;
- }
- } else {
- for (int i = 0; i < word.GetLength(); i ++) {
- if (word.GetAt(i) < '0' || word.GetAt(i) > '9') {
- return num;
- }
- num = num * 10 + word.GetAt(i) - '0';
- }
- }
- return num;
-}
-static FX_BOOL _CMap_GetCodeRange(_CMap_CodeRange& range, FX_BSTR first, FX_BSTR second)
-{
- if (first.GetLength() == 0 || first.GetAt(0) != '<') {
- return FALSE;
- }
- int num = 0;
- int i;
- for (i = 1; i < first.GetLength(); i ++)
- if (first.GetAt(i) == '>') {
- break;
- }
- range.m_CharSize = (i - 1) / 2;
- if (range.m_CharSize > 4) {
- return FALSE;
- }
- for (i = 0; i < range.m_CharSize; i ++) {
- FX_BYTE digit1 = first.GetAt(i * 2 + 1);
- FX_BYTE digit2 = first.GetAt(i * 2 + 2);
- FX_BYTE byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((digit1 & 0xdf) - 'A' + 10);
- byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') : ((digit2 & 0xdf) - 'A' + 10));
- range.m_Lower[i] = byte;
- }
- FX_DWORD size = second.GetLength();
- for (i = 0; i < range.m_CharSize; i ++) {
- FX_BYTE digit1 = ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0;
- FX_BYTE digit2 = ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0;
- FX_BYTE byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((digit1 & 0xdf) - 'A' + 10);
- byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') : ((digit2 & 0xdf) - 'A' + 10));
- range.m_Upper[i] = byte;
- }
- return TRUE;
-}
-static CFX_ByteString CMap_GetString(FX_BSTR word)
-{
- return word.Mid(1, word.GetLength() - 2);
-}
-void CPDF_CMapParser::ParseWord(FX_BSTR word)
-{
- if (word.IsEmpty()) {
- return;
- }
- if (word == FX_BSTRC("begincidchar")) {
- m_Status = 1;
- m_CodeSeq = 0;
- } else if (word == FX_BSTRC("begincidrange")) {
- m_Status = 2;
- m_CodeSeq = 0;
- } else if (word == FX_BSTRC("endcidrange") || word == FX_BSTRC("endcidchar")) {
- m_Status = 0;
- } else if (word == FX_BSTRC("/WMode")) {
- m_Status = 6;
- } else if (word == FX_BSTRC("/Registry")) {
- m_Status = 3;
- } else if (word == FX_BSTRC("/Ordering")) {
- m_Status = 4;
- } else if (word == FX_BSTRC("/Supplement")) {
- m_Status = 5;
- } else if (word == FX_BSTRC("begincodespacerange")) {
- m_Status = 7;
- m_CodeSeq = 0;
- } else if (word == FX_BSTRC("usecmap")) {
- } else if (m_Status == 1 || m_Status == 2) {
- m_CodePoints[m_CodeSeq] = CMap_GetCode(word);
- m_CodeSeq ++;
- FX_DWORD StartCode, EndCode;
- FX_WORD StartCID;
- if (m_Status == 1) {
- if (m_CodeSeq < 2) {
- return;
- }
- EndCode = StartCode = m_CodePoints[0];
- StartCID = (FX_WORD)m_CodePoints[1];
- } else {
- if (m_CodeSeq < 3) {
- return;
- }
- StartCode = m_CodePoints[0];
- EndCode = m_CodePoints[1];
- StartCID = (FX_WORD)m_CodePoints[2];
- }
- if (EndCode < 0x10000) {
- for (FX_DWORD code = StartCode; code <= EndCode; code ++) {
- m_pCMap->m_pMapping[code] = (FX_WORD)(StartCID + code - StartCode);
- }
- } else {
- FX_DWORD buf[2];
- buf[0] = StartCode;
- buf[1] = ((EndCode - StartCode) << 16) + StartCID;
- m_AddMaps.AppendBlock(buf, sizeof buf);
- }
- m_CodeSeq = 0;
- } else if (m_Status == 3) {
- CMap_GetString(word);
- m_Status = 0;
- } else if (m_Status == 4) {
- m_pCMap->m_Charset = _CharsetFromOrdering(CMap_GetString(word));
- m_Status = 0;
- } else if (m_Status == 5) {
- CMap_GetCode(word);
- m_Status = 0;
- } else if (m_Status == 6) {
- m_pCMap->m_bVertical = CMap_GetCode(word);
- m_Status = 0;
- } else if (m_Status == 7) {
- if (word == FX_BSTRC("endcodespacerange")) {
- int nSegs = m_CodeRanges.GetSize();
- if (nSegs > 1) {
- m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes;
- m_pCMap->m_nCodeRanges = nSegs;
- m_pCMap->m_pLeadingBytes = FX_Alloc(FX_BYTE, nSegs * sizeof(_CMap_CodeRange));
- FXSYS_memcpy32(m_pCMap->m_pLeadingBytes, m_CodeRanges.GetData(), nSegs * sizeof(_CMap_CodeRange));
- } else if (nSegs == 1) {
- m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2) ? CPDF_CMap::TwoBytes : CPDF_CMap::OneByte;
- }
- m_Status = 0;
- } else {
- if (word.GetLength() == 0 || word.GetAt(0) != '<') {
- return;
- }
- if (m_CodeSeq % 2) {
- _CMap_CodeRange range;
- if (_CMap_GetCodeRange(range, m_LastWord, word)) {
- m_CodeRanges.Add(range);
- }
- }
- m_CodeSeq ++;
- }
- }
- m_LastWord = word;
-}
-CPDF_CMap::CPDF_CMap()
-{
- m_Charset = CIDSET_UNKNOWN;
- m_Coding = CIDCODING_UNKNOWN;
- m_CodingScheme = TwoBytes;
- m_bVertical = 0;
- m_bLoaded = FALSE;
- m_pMapping = NULL;
- m_pLeadingBytes = NULL;
- m_pAddMapping = NULL;
- m_pEmbedMap = NULL;
- m_pUseMap = NULL;
- m_nCodeRanges = 0;
-}
-CPDF_CMap::~CPDF_CMap()
-{
- if (m_pMapping) {
- FX_Free(m_pMapping);
- }
- if (m_pAddMapping) {
- FX_Free(m_pAddMapping);
- }
- if (m_pLeadingBytes) {
- FX_Free(m_pLeadingBytes);
- }
- if (m_pUseMap) {
- delete m_pUseMap;
- }
-}
-void CPDF_CMap::Release()
-{
- if (m_PredefinedCMap.IsEmpty()) {
- delete this;
- }
-}
-const CPDF_PredefinedCMap g_PredefinedCMaps[] = {
- { "GB-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
- { "GBpc-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfc} },
- { "GBK-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
- { "GBKp-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
- { "GBK2K-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
- { "GBK2K", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
- { "UniGB-UCS2", CIDSET_GB1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
- { "UniGB-UTF16", CIDSET_GB1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
- { "B5pc", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfc} },
- { "HKscs-B5", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0x88, 0xfe} },
- { "ETen-B5", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
- { "ETenms-B5", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
- { "UniCNS-UCS2", CIDSET_CNS1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
- { "UniCNS-UTF16", CIDSET_CNS1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
- { "83pv-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
- { "90ms-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
- { "90msp-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
- { "90pv-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
- { "Add-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
- { "EUC", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x8e, 0x8e, 0xa1, 0xfe} },
- { "H", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::TwoBytes, 1, {0x21, 0x7e} },
- { "V", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::TwoBytes, 1, {0x21, 0x7e} },
- { "Ext-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
- { "UniJIS-UCS2", CIDSET_JAPAN1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
- { "UniJIS-UCS2-HW", CIDSET_JAPAN1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
- { "UniJIS-UTF16", CIDSET_JAPAN1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
- { "KSC-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
- { "KSCms-UHC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
- { "KSCms-UHC-HW", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
- { "KSCpc-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfd} },
- { "UniKS-UCS2", CIDSET_KOREA1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
- { "UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
- { NULL, 0, 0 }
-};
-extern void FPDFAPI_FindEmbeddedCMap(const char* name, int charset, int coding, const FXCMAP_CMap*& pMap);
-extern FX_WORD FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, FX_DWORD charcode);
-FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, FX_LPCSTR pName, FX_BOOL bPromptCJK)
-{
- m_PredefinedCMap = pName;
- if (m_PredefinedCMap == FX_BSTRC("Identity-H") || m_PredefinedCMap == FX_BSTRC("Identity-V")) {
- m_Coding = CIDCODING_CID;
- m_bVertical = pName[9] == 'V';
- m_bLoaded = TRUE;
- return TRUE;
- }
- CFX_ByteString cmapid = m_PredefinedCMap;
- m_bVertical = cmapid.Right(1) == FX_BSTRC("V");
- if (cmapid.GetLength() > 2) {
- cmapid = cmapid.Left(cmapid.GetLength() - 2);
- }
- int index = 0;
- while (1) {
- if (g_PredefinedCMaps[index].m_pName == NULL) {
- return FALSE;
- }
- if (cmapid == CFX_ByteStringC(g_PredefinedCMaps[index].m_pName)) {
- break;
- }
- index ++;
- }
- const CPDF_PredefinedCMap& map = g_PredefinedCMaps[index];
- m_Charset = map.m_Charset;
- m_Coding = map.m_Coding;
- m_CodingScheme = map.m_CodingScheme;
- if (m_CodingScheme == MixedTwoBytes) {
- m_pLeadingBytes = FX_Alloc(FX_BYTE, 256);
- FXSYS_memset32(m_pLeadingBytes, 0, 256);
- for (FX_DWORD i = 0; i < map.m_LeadingSegCount; i ++) {
- for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2 + 1]; b ++) {
- m_pLeadingBytes[b] = 1;
- }
- }
- }
- FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap);
- if (m_pEmbedMap) {
- m_bLoaded = TRUE;
- return TRUE;
- }
-#ifndef _FPDFAPI_MINI_
- FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK);
- FX_LPBYTE pBuffer;
- FX_DWORD size;
- if (pPackage == NULL || !FXFC_LoadFile(pPackage, m_PredefinedCMap, pBuffer, size)) {
- return FALSE;
- }
- m_pMapping = FX_Alloc(FX_WORD, 65536);
- FXSYS_memset32(m_pMapping, 0, 65536 * sizeof(FX_WORD));
- FX_DWORD dwRecodeEndPos = 0;
- if (pBuffer[5] == 0) {
- FX_DWORD dwStartIndex = *(FX_DWORD*)(pBuffer + 8);
- FX_DWORD dwRecordCount = *(FX_DWORD*)(pBuffer + 16);
- FX_DWORD dwDataOffset = *(FX_DWORD*)(pBuffer + 20);
- if (dwRecordCount * 2 + dwStartIndex * 2 < 65536) {
- FXSYS_memcpy32(m_pMapping + dwStartIndex * 2, pBuffer + dwDataOffset, dwRecordCount * 2);
- }
- dwRecodeEndPos = dwDataOffset + dwRecordCount * 2;
- } else if (pBuffer[5] == 2) {
- FX_DWORD nSegments = *(FX_DWORD*)(pBuffer + 16);
- FX_DWORD dwDataOffset = *(FX_DWORD*)(pBuffer + 20);
- dwRecodeEndPos = dwDataOffset + 6 * nSegments;
- for (FX_DWORD i = 0; i < nSegments; i ++) {
- FX_LPBYTE pRecord = pBuffer + dwDataOffset + i * 6;
- FX_WORD IndexStart = *(FX_WORD*)pRecord;
- FX_WORD IndexCount = *(FX_WORD*)(pRecord + 2);
- FX_WORD CodeStart = *(FX_WORD*)(pRecord + 4);
- if (IndexStart + IndexCount < 65536)
- for (FX_DWORD j = 0; j < IndexCount; j ++) {
- m_pMapping[IndexStart + j ] = (FX_WORD)(CodeStart + j);
- }
- }
- }
- if (dwRecodeEndPos < size) {
- FX_DWORD dwMapLen = *(FX_DWORD*)(pBuffer + dwRecodeEndPos);
- if (dwMapLen) {
- m_pUseMap = FX_NEW CPDF_CMap;
- CFX_ByteString bsName(pBuffer + dwRecodeEndPos + 4 , dwMapLen);
- if (m_pUseMap) {
- m_pUseMap->LoadPredefined(pMgr, bsName, bPromptCJK);
- }
- }
- }
- FX_Free(pBuffer);
- m_bLoaded = TRUE;
-#endif
- return TRUE;
-}
-extern "C" {
- static int compare_dword(const void* data1, const void* data2)
- {
- return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2);
- }
-};
-FX_BOOL CPDF_CMap::LoadEmbedded(FX_LPCBYTE pData, FX_DWORD size)
-{
- m_pMapping = FX_Alloc(FX_WORD, 65536);
- FXSYS_memset32(m_pMapping, 0, 65536 * sizeof(FX_WORD));
- CPDF_CMapParser parser;
- parser.Initialize(this);
- CPDF_SimpleParser syntax(pData, size);
- while (1) {
- CFX_ByteStringC word = syntax.GetWord();
- if (word.IsEmpty()) {
- break;
- }
- parser.ParseWord(word);
- }
- if (m_CodingScheme == MixedFourBytes && parser.m_AddMaps.GetSize()) {
- m_pAddMapping = FX_Alloc(FX_BYTE, parser.m_AddMaps.GetSize() + 4);
- *(FX_DWORD*)m_pAddMapping = parser.m_AddMaps.GetSize() / 8;
- FXSYS_memcpy32(m_pAddMapping + 4, parser.m_AddMaps.GetBuffer(), parser.m_AddMaps.GetSize());
- FXSYS_qsort(m_pAddMapping + 4, parser.m_AddMaps.GetSize() / 8, 8, compare_dword);
- }
- return TRUE;
-}
-extern "C" {
- static int compareCID(const void* key, const void* element)
- {
- if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) {
- return -1;
- }
- if ((*(FX_DWORD*)key) > (*(FX_DWORD*)element) + ((FX_DWORD*)element)[1] / 65536) {
- return 1;
- }
- return 0;
- }
-};
-FX_WORD CPDF_CMap::CIDFromCharCode(FX_DWORD charcode) const
-{
- if (m_Coding == CIDCODING_CID) {
- return (FX_WORD)charcode;
- }
- if (m_pEmbedMap) {
- return FPDFAPI_CIDFromCharCode(m_pEmbedMap, charcode);
- }
- if (m_pMapping == NULL) {
- return (FX_WORD)charcode;
- }
- if (charcode >> 16) {
- if (m_pAddMapping) {
- void* found = FXSYS_bsearch(&charcode, m_pAddMapping + 4, *(FX_DWORD*)m_pAddMapping, 8, compareCID);
- if (found == NULL) {
- if (m_pUseMap) {
- return m_pUseMap->CIDFromCharCode(charcode);
- }
- return 0;
- }
- return (FX_WORD)(((FX_DWORD*)found)[1] % 65536 + charcode - * (FX_DWORD*)found);
- }
- if (m_pUseMap) {
- return m_pUseMap->CIDFromCharCode(charcode);
- }
- return 0;
- }
- FX_DWORD CID = m_pMapping[charcode];
- if (!CID && m_pUseMap) {
- return m_pUseMap->CIDFromCharCode(charcode);
- }
- return (FX_WORD)CID;
-}
-static int _CheckCodeRange(FX_LPBYTE codes, int size, _CMap_CodeRange* pRanges, int nRanges)
-{
- int iSeg = nRanges - 1;
- while (iSeg >= 0) {
- if (pRanges[iSeg].m_CharSize < size) {
- iSeg --;
- continue;
- }
- int iChar = 0;
- while (iChar < size) {
- if (codes[iChar] < pRanges[iSeg].m_Lower[iChar] ||
- codes[iChar] > pRanges[iSeg].m_Upper[iChar]) {
- break;
- }
- iChar ++;
- }
- if (iChar == pRanges[iSeg].m_CharSize) {
- return 2;
- }
- if (iChar) {
- if (size == pRanges[iSeg].m_CharSize) {
- return 2;
- }
- return 1;
- }
- iSeg --;
- }
- return 0;
-}
-FX_DWORD CPDF_CMap::GetNextChar(FX_LPCSTR pString, int& offset) const
-{
- switch (m_CodingScheme) {
- case OneByte:
- return ((FX_LPBYTE)pString)[offset++];
- case TwoBytes:
- offset += 2;
- return ((FX_LPBYTE)pString)[offset - 2] * 256 + ((FX_LPBYTE)pString)[offset - 1];
- case MixedTwoBytes: {
- FX_BYTE byte1 = ((FX_LPBYTE)pString)[offset++];
- if (!m_pLeadingBytes[byte1]) {
- return byte1;
- }
- FX_BYTE byte2 = ((FX_LPBYTE)pString)[offset++];
- return byte1 * 256 + byte2;
- }
- case MixedFourBytes: {
- FX_BYTE codes[4];
- int char_size = 1;
- codes[0] = ((FX_LPBYTE)pString)[offset++];
- _CMap_CodeRange* pRanges = (_CMap_CodeRange*)m_pLeadingBytes;
- while (1) {
- int ret = _CheckCodeRange(codes, char_size, pRanges, m_nCodeRanges);
- if (ret == 0) {
- return 0;
- }
- if (ret == 2) {
- FX_DWORD charcode = 0;
- for (int i = 0; i < char_size; i ++) {
- charcode = (charcode << 8) + codes[i];
- }
- return charcode;
- }
- if (char_size == 4) {
- return 0;
- }
- codes[char_size ++] = ((FX_LPBYTE)pString)[offset++];
- }
- break;
- }
- }
- return 0;
-}
-int CPDF_CMap::GetCharSize(FX_DWORD charcode) const
-{
- switch (m_CodingScheme) {
- case OneByte:
- return 1;
- case TwoBytes:
- return 2;
- case MixedTwoBytes:
- case MixedFourBytes:
- if (charcode < 0x100) {
- return 1;
- }
- if (charcode < 0x10000) {
- return 2;
- }
- if (charcode < 0x1000000) {
- return 3;
- }
- return 4;
- }
- return 1;
-}
-int CPDF_CMap::CountChar(FX_LPCSTR pString, int size) const
-{
- switch (m_CodingScheme) {
- case OneByte:
- return size;
- case TwoBytes:
- return (size + 1) / 2;
- case MixedTwoBytes: {
- int count = 0;
- for (int i = 0; i < size; i ++) {
- count ++;
- if (m_pLeadingBytes[((FX_LPBYTE)pString)[i]]) {
- i ++;
- }
- }
- return count;
- }
- case MixedFourBytes: {
- int count = 0, offset = 0;
- while (offset < size) {
- GetNextChar(pString, offset);
- count ++;
- }
- return count;
- }
- }
- return size;
-}
-int _GetCharSize(FX_DWORD charcode, _CMap_CodeRange* pRanges, int iRangesSize)
-{
- if (!iRangesSize) {
- return 1;
- }
- FX_BYTE codes[4];
- codes[0] = codes[1] = 0x00;
- codes[2] = (FX_BYTE)(charcode >> 8 & 0xFF);
- codes[3] = (FX_BYTE)charcode;
- int offset = 0, size = 4;
- for (int i = 0; i < 4; ++i) {
- int iSeg = iRangesSize - 1;
- while (iSeg >= 0) {
- if (pRanges[iSeg].m_CharSize < size) {
- iSeg --;
- continue;
- }
- int iChar = 0;
- while (iChar < size) {
- if (codes[offset + iChar] < pRanges[iSeg].m_Lower[iChar] ||
- codes[offset + iChar] > pRanges[iSeg].m_Upper[iChar]) {
- break;
- }
- iChar ++;
- }
- if (iChar == pRanges[iSeg].m_CharSize) {
- return size;
- }
- iSeg --;
- }
- size --;
- offset ++;
- }
- return 1;
-}
-int CPDF_CMap::AppendChar(FX_LPSTR str, FX_DWORD charcode) const
-{
- switch (m_CodingScheme) {
- case OneByte:
- str[0] = (FX_BYTE)charcode;
- return 1;
- case TwoBytes:
- str[0] = (FX_BYTE)(charcode / 256);
- str[1] = (FX_BYTE)(charcode % 256);
- return 2;
- case MixedTwoBytes:
- case MixedFourBytes:
- if (charcode < 0x100) {
- _CMap_CodeRange* pRanges = (_CMap_CodeRange*)m_pLeadingBytes;
- int iSize = _GetCharSize(charcode, pRanges, m_nCodeRanges);
- if (iSize == 0) {
- iSize = 1;
- }
- if (iSize > 1) {
- FXSYS_memset32(str, 0, sizeof(FX_BYTE) * iSize);
- }
- str[iSize - 1] = (FX_BYTE)charcode;
- return iSize;
- } else if (charcode < 0x10000) {
- str[0] = (FX_BYTE)(charcode >> 8);
- str[1] = (FX_BYTE)charcode;
- return 2;
- } else if (charcode < 0x1000000) {
- str[0] = (FX_BYTE)(charcode >> 16);
- str[1] = (FX_BYTE)(charcode >> 8);
- str[2] = (FX_BYTE)charcode;
- return 3;
- } else {
- str[0] = (FX_BYTE)(charcode >> 24);
- str[1] = (FX_BYTE)(charcode >> 16);
- str[2] = (FX_BYTE)(charcode >> 8);
- str[3] = (FX_BYTE)charcode;
- return 4;
- }
- }
- return 0;
-}
-CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap()
-{
- m_EmbeddedCount = 0;
-#ifndef _FPDFAPI_MINI_
- m_pExternalMap = NULL;
-#endif
-}
-CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap()
-{
-#ifndef _FPDFAPI_MINI_
- if (m_pExternalMap) {
- delete m_pExternalMap;
- }
-#endif
-}
-FX_BOOL CPDF_CID2UnicodeMap::Initialize()
-{
-#ifndef _FPDFAPI_MINI_
- m_pExternalMap = FX_NEW CPDF_FXMP;
-#endif
- return TRUE;
-}
-FX_BOOL CPDF_CID2UnicodeMap::IsLoaded()
-{
-#ifdef _FPDFAPI_MINI_
- return m_EmbeddedCount != 0;
-#else
- return m_EmbeddedCount != 0 || (m_pExternalMap != NULL && m_pExternalMap->IsLoaded());
-#endif
-}
-FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID)
-{
- if (m_Charset == CIDSET_UNICODE) {
- return CID;
- }
- if (CID < m_EmbeddedCount) {
- return m_pEmbeddedMap[CID];
- }
-#ifdef _FPDFAPI_MINI_
- return 0;
-#else
- FX_LPCBYTE record = m_pExternalMap->GetRecord(CID);
- if (record == NULL) {
- return 0;
- }
- return *(FX_WORD*)record;
-#endif
-}
-void FPDFAPI_LoadCID2UnicodeMap(int charset, const FX_WORD*& pMap, FX_DWORD& count);
-void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPromptCJK)
-{
- m_Charset = charset;
- FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount);
- if (m_EmbeddedCount) {
- return;
- }
-#ifndef _FPDFAPI_MINI_
- FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK);
- if (pPackage == NULL) {
- return;
- }
- m_pExternalMap->LoadFile(pPackage, FX_BSTRC("CIDInfo_") + g_CharsetNames[charset]);
-#endif
-}
-#include "ttgsubtable.h"
-CPDF_CIDFont::CPDF_CIDFont()
-{
- m_pCMap = NULL;
- m_pAllocatedCMap = NULL;
- m_pCID2UnicodeMap = NULL;
- m_pAnsiWidths = NULL;
- m_pCIDToGIDMap = NULL;
- m_bCIDIsGID = FALSE;
- m_bAdobeCourierStd = FALSE;
- m_pTTGSUBTable = NULL;
- FXSYS_memset8(m_CharBBox, 0xff, 256 * sizeof(FX_SMALL_RECT));
-}
-CPDF_CIDFont::~CPDF_CIDFont()
-{
- if (m_pAnsiWidths) {
- FX_Free(m_pAnsiWidths);
- }
- if (m_pAllocatedCMap) {
- delete m_pAllocatedCMap;
- }
- if (m_pCIDToGIDMap) {
- delete m_pCIDToGIDMap;
- }
- if (m_pTTGSUBTable) {
- delete m_pTTGSUBTable;
- }
-}
-FX_WORD CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const
-{
- if (m_pCMap == NULL) {
- return (FX_WORD)charcode;
- }
- return m_pCMap->CIDFromCharCode(charcode);
-}
-FX_BOOL CPDF_CIDFont::IsVertWriting() const
-{
- return m_pCMap ? m_pCMap->IsVertWriting() : FALSE;
-}
-extern FX_DWORD FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, FX_WORD cid);
-static FX_DWORD _EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap, int charset, FX_WCHAR unicode)
-{
- if (charset <= 0 || charset > 4) {
- return 0;
- }
- CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
- if (pCodes == NULL) {
- return 0;
- }
- int nCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
- for (int i = 0; i < nCodes; i++) {
- if (pCodes[i] == unicode) {
- FX_DWORD CharCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i);
- if (CharCode == 0) {
- continue;
- }
- return CharCode;
- }
- }
- return 0;
-}
-static FX_WCHAR _EmbeddedUnicodeFromCharcode(const FXCMAP_CMap* pEmbedMap, int charset, FX_DWORD charcode)
-{
- if (charset <= 0 || charset > 4) {
- return 0;
- }
- FX_WORD cid = FPDFAPI_CIDFromCharCode(pEmbedMap, charcode);
- if (cid == 0) {
- return 0;
- }
- CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
- if (pCodes == NULL) {
- return 0;
- }
- if (cid < pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count) {
- return pCodes[cid];
- }
- return 0;
-}
-FX_WCHAR CPDF_CIDFont::_UnicodeFromCharCode(FX_DWORD charcode) const
-{
- switch (m_pCMap->m_Coding) {
- case CIDCODING_UCS2:
- case CIDCODING_UTF16:
- return (FX_WCHAR)charcode;
- case CIDCODING_CID:
- if (m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
- return 0;
- }
- return m_pCID2UnicodeMap->UnicodeFromCID((FX_WORD)charcode);
- }
- if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
- FX_WCHAR unicode;
- int charsize = 1;
- if (charcode > 255) {
- charcode = (charcode % 256) * 256 + (charcode / 256);
- charsize = 2;
- }
- int ret = FXSYS_MultiByteToWideChar(g_CharsetCPs[m_pCMap->m_Coding], 0, (FX_LPCSTR)&charcode, charsize, &unicode, 1);
- if (ret != 1) {
- return 0;
- }
- return unicode;
-#endif
- if (m_pCMap->m_pEmbedMap) {
- return _EmbeddedUnicodeFromCharcode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset, charcode);
- } else {
- return 0;
- }
- }
- return m_pCID2UnicodeMap->UnicodeFromCID(CIDFromCharCode(charcode));
-}
-FX_DWORD CPDF_CIDFont::_CharCodeFromUnicode(FX_WCHAR unicode) const
-{
- switch (m_pCMap->m_Coding) {
- case CIDCODING_UNKNOWN:
- return 0;
- case CIDCODING_UCS2:
- case CIDCODING_UTF16:
- return unicode;
- case CIDCODING_CID: {
- if (m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
- return 0;
- }
- FX_DWORD CID = 0;
- while (CID < 65536) {
- FX_WCHAR this_unicode = m_pCID2UnicodeMap->UnicodeFromCID((FX_WORD)CID);
- if (this_unicode == unicode) {
- return CID;
- }
- CID ++;
- }
- break;
- }
- }
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
- FX_BYTE buffer[32];
- int ret = FXSYS_WideCharToMultiByte(g_CharsetCPs[m_pCMap->m_Coding], 0, &unicode, 1, (char*)buffer, 4, NULL, NULL);
- if (ret == 1) {
- return buffer[0];
- } else if (ret == 2) {
- return buffer[0] * 256 + buffer[1];
- }
- return 0;
-#endif
- if (unicode < 0x80) {
- return (FX_DWORD)unicode;
- } else {
- if (m_pCMap->m_pEmbedMap) {
- return _EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset, unicode);
- } else {
- return 0;
- }
- }
-}
-static void FT_UseCIDCharmap(FXFT_Face face, int coding)
-{
- int encoding;
- switch (coding) {
- case CIDCODING_GB:
- encoding = FXFT_ENCODING_GB2312;
- break;
- case CIDCODING_BIG5:
- encoding = FXFT_ENCODING_BIG5;
- break;
- case CIDCODING_JIS:
- encoding = FXFT_ENCODING_SJIS;
- break;
- case CIDCODING_KOREA:
- encoding = FXFT_ENCODING_JOHAB;
- break;
- default:
- encoding = FXFT_ENCODING_UNICODE;
- }
- int err = FXFT_Select_Charmap(face, encoding);
- if (err) {
- err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
- }
- if (err && FXFT_Get_Face_Charmaps(face)) {
- FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face));
- }
-}
-FX_BOOL CPDF_CIDFont::_Load()
-{
- if (m_pFontDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("TrueType")) {
- return LoadGB2312();
- }
- CPDF_Array* pFonts = m_pFontDict->GetArray(FX_BSTRC("DescendantFonts"));
- if (pFonts == NULL) {
- return FALSE;
- }
- if (pFonts->GetCount() != 1) {
- return FALSE;
- }
- CPDF_Dictionary* pCIDFontDict = pFonts->GetDict(0);
- if (pCIDFontDict == NULL) {
- return FALSE;
- }
- m_BaseFont = pCIDFontDict->GetString(FX_BSTRC("BaseFont"));
- if ((m_BaseFont.Compare("CourierStd") == 0 || m_BaseFont.Compare("CourierStd-Bold") == 0
- || m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || m_BaseFont.Compare("CourierStd-Oblique") == 0)
- && !IsEmbedded()) {
- m_bAdobeCourierStd = TRUE;
- }
- CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDict(FX_BSTRC("FontDescriptor"));
- if (pFontDesc) {
- LoadFontDescriptor(pFontDesc);
- }
- CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding"));
- if (pEncoding == NULL) {
- return FALSE;
- }
- CFX_ByteString subtype = pCIDFontDict->GetString(FX_BSTRC("Subtype"));
- m_bType1 = FALSE;
- if (subtype == FX_BSTRC("CIDFontType0")) {
- m_bType1 = TRUE;
- }
- if (pEncoding->GetType() == PDFOBJ_NAME) {
- CFX_ByteString cmap = pEncoding->GetString();
- m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetPredefinedCMap(cmap,
- m_pFontFile && m_bType1);
- } else if (pEncoding->GetType() == PDFOBJ_STREAM) {
- m_pAllocatedCMap = m_pCMap = FX_NEW CPDF_CMap;
- CPDF_Stream* pStream = (CPDF_Stream*)pEncoding;
- CPDF_StreamAcc acc;
- acc.LoadAllData(pStream, FALSE);
- m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
- } else {
- return FALSE;
- }
- if (m_pCMap == NULL) {
- return FALSE;
- }
- m_Charset = m_pCMap->m_Charset;
- if (m_Charset == CIDSET_UNKNOWN) {
- CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDict(FX_BSTRC("CIDSystemInfo"));
- if (pCIDInfo) {
- m_Charset = _CharsetFromOrdering(pCIDInfo->GetString(FX_BSTRC("Ordering")));
- }
- }
- if (m_Charset != CIDSET_UNKNOWN)
- m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetCID2UnicodeMap(m_Charset,
- m_pFontFile == NULL && (m_pCMap->m_Coding == CIDCODING_CID || pCIDFontDict->KeyExist(FX_BSTRC("W"))));
- if (m_Font.GetFace()) {
- if (m_bType1) {
- FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE);
- } else {
- FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding);
- }
- }
- m_DefaultWidth = pCIDFontDict->GetInteger(FX_BSTRC("DW"), 1000);
- CPDF_Array* pWidthArray = pCIDFontDict->GetArray(FX_BSTRC("W"));
- if (pWidthArray) {
- LoadMetricsArray(pWidthArray, m_WidthList, 1);
- }
- if (!IsEmbedded()) {
- LoadSubstFont();
- }
- if (1) {
- if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) {
- CPDF_Object* pmap = pCIDFontDict->GetElementValue(FX_BSTRC("CIDToGIDMap"));
- if (pmap) {
- if (pmap->GetType() == PDFOBJ_STREAM) {
- m_pCIDToGIDMap = FX_NEW CPDF_StreamAcc;
- m_pCIDToGIDMap->LoadAllData((CPDF_Stream*)pmap, FALSE);
- } else if (pmap->GetString() == FX_BSTRC("Identity")) {
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- if (m_pFontFile) {
- m_bCIDIsGID = TRUE;
- }
-#else
- m_bCIDIsGID = TRUE;
-#endif
- }
- }
- }
- }
- CheckFontMetrics();
- if (IsVertWriting()) {
- pWidthArray = pCIDFontDict->GetArray(FX_BSTRC("W2"));
- if (pWidthArray) {
- LoadMetricsArray(pWidthArray, m_VertMetrics, 3);
- }
- CPDF_Array* pDefaultArray = pCIDFontDict->GetArray(FX_BSTRC("DW2"));
- if (pDefaultArray) {
- m_DefaultVY = pDefaultArray->GetInteger(0);
- m_DefaultW1 = pDefaultArray->GetInteger(1);
- } else {
- m_DefaultVY = 880;
- m_DefaultW1 = -1000;
- }
- }
- return TRUE;
-}
-FX_FLOAT _CIDTransformToFloat(FX_BYTE ch)
-{
- if (ch < 128) {
- return ch * 1.0f / 127;
- }
- return (-255 + ch) * 1.0f / 127;
-}
-void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level)
-{
- if (charcode < 256 && m_CharBBox[charcode].Right != -1) {
- rect.bottom = m_CharBBox[charcode].Bottom;
- rect.left = m_CharBBox[charcode].Left;
- rect.right = m_CharBBox[charcode].Right;
- rect.top = m_CharBBox[charcode].Top;
- return;
- }
- FX_BOOL bVert = FALSE;
- int glyph_index = GlyphFromCharCode(charcode, &bVert);
- if (m_Font.m_Face == NULL) {
- rect = FX_RECT(0, 0, 0, 0);
- } else {
- rect.left = rect.bottom = rect.right = rect.top = 0;
- FXFT_Face face = m_Font.m_Face;
- if (FXFT_Is_Face_Tricky(face)) {
- int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
- if (!err) {
- FXFT_BBox cbox;
- FXFT_Glyph glyph;
- err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph);
- if (!err) {
- FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
- int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem;
- int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem;
- if (pixel_size_x == 0 || pixel_size_y == 0) {
- rect.left = cbox.xMin;
- rect.right = cbox.xMax;
- rect.top = cbox.yMax;
- rect.bottom = cbox.yMin;
- } else {
- rect.left = cbox.xMin * 1000 / pixel_size_x;
- rect.right = cbox.xMax * 1000 / pixel_size_x;
- rect.top = cbox.yMax * 1000 / pixel_size_y;
- rect.bottom = cbox.yMin * 1000 / pixel_size_y;
- }
- if (rect.top > FXFT_Get_Face_Ascender(face)) {
- rect.top = FXFT_Get_Face_Ascender(face);
- }
- if (rect.bottom < FXFT_Get_Face_Descender(face)) {
- rect.bottom = FXFT_Get_Face_Descender(face);
- }
- FXFT_Done_Glyph(glyph);
- }
- }
- } else {
- int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_SCALE);
- if (err == 0) {
- rect.left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face);
- rect.right = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), face);
- rect.top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face);
- rect.top += rect.top / 64;
- rect.bottom = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), face);
- }
- }
- }
- if (m_pFontFile == NULL && m_Charset == CIDSET_JAPAN1) {
- FX_WORD CID = CIDFromCharCode(charcode);
- FX_LPCBYTE pTransform = GetCIDTransform(CID);
- if (pTransform && !bVert) {
- CFX_AffineMatrix matrix(_CIDTransformToFloat(pTransform[0]), _CIDTransformToFloat(pTransform[1]),
- _CIDTransformToFloat(pTransform[2]), _CIDTransformToFloat(pTransform[3]),
- _CIDTransformToFloat(pTransform[4]) * 1000 , _CIDTransformToFloat(pTransform[5]) * 1000);
- CFX_FloatRect rect_f(rect);
- rect_f.Transform(&matrix);
- rect = rect_f.GetOutterRect();
- }
- }
- if (charcode < 256) {
- m_CharBBox[charcode].Bottom = (short)rect.bottom;
- m_CharBBox[charcode].Left = (short)rect.left;
- m_CharBBox[charcode].Right = (short)rect.right;
- m_CharBBox[charcode].Top = (short)rect.top;
- }
-}
-int CPDF_CIDFont::GetCharWidthF(FX_DWORD charcode, int level)
-{
- if (m_pAnsiWidths && charcode < 0x80) {
- return m_pAnsiWidths[charcode];
- }
- FX_WORD cid = CIDFromCharCode(charcode);
- int size = m_WidthList.GetSize();
- FX_DWORD* list = m_WidthList.GetData();
- for (int i = 0; i < size; i += 3) {
- if (cid >= list[i] && cid <= list[i + 1]) {
- return (int)list[i + 2];
- }
- }
- return m_DefaultWidth;
-}
-short CPDF_CIDFont::GetVertWidth(FX_WORD CID) const
-{
- FX_DWORD vertsize = m_VertMetrics.GetSize() / 5;
- if (vertsize == 0) {
- return m_DefaultW1;
- }
- const FX_DWORD* pTable = m_VertMetrics.GetData();
- for (FX_DWORD i = 0; i < vertsize; i ++)
- if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
- return (short)(int)pTable[i * 5 + 2];
- }
- return m_DefaultW1;
-}
-void CPDF_CIDFont::GetVertOrigin(FX_WORD CID, short& vx, short &vy) const
-{
- FX_DWORD vertsize = m_VertMetrics.GetSize() / 5;
- if (vertsize) {
- const FX_DWORD* pTable = m_VertMetrics.GetData();
- for (FX_DWORD i = 0; i < vertsize; i ++)
- if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
- vx = (short)(int)pTable[i * 5 + 3];
- vy = (short)(int)pTable[i * 5 + 4];
- return;
- }
- }
- FX_DWORD dwWidth = m_DefaultWidth;
- int size = m_WidthList.GetSize();
- const FX_DWORD* list = m_WidthList.GetData();
- for (int i = 0; i < size; i += 3) {
- if (CID >= list[i] && CID <= list[i + 1]) {
- dwWidth = (FX_WORD)list[i + 2];
- break;
- }
- }
- vx = (short)dwWidth / 2;
- vy = (short)m_DefaultVY;
-}
-int CPDF_CIDFont::GetGlyphIndex(FX_DWORD unicode, FX_BOOL *pVertGlyph)
-{
- if (pVertGlyph) {
- *pVertGlyph = FALSE;
- }
- int index = FXFT_Get_Char_Index(m_Font.m_Face, unicode );
- if (unicode == 0x2502) {
- return index;
- }
- if (index && IsVertWriting()) {
- if (m_pTTGSUBTable) {
- TT_uint32_t vindex = 0;
- m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
- if (vindex) {
- index = vindex;
- if (pVertGlyph) {
- *pVertGlyph = TRUE;
- }
- }
- return index;
- }
- if (NULL == m_Font.m_pGsubData) {
- unsigned long length = 0;
- int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length);
- if (!error) {
- m_Font.m_pGsubData = (unsigned char*)FX_Alloc(FX_BYTE, length);
- }
- }
- int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, m_Font.m_pGsubData, NULL);
- if (!error && m_Font.m_pGsubData) {
- m_pTTGSUBTable = FX_NEW CFX_CTTGSUBTable;
- m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.m_pGsubData);
- TT_uint32_t vindex = 0;
- m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
- if (vindex) {
- index = vindex;
- if (pVertGlyph) {
- *pVertGlyph = TRUE;
- }
- }
- }
- return index;
- }
- if (pVertGlyph) {
- *pVertGlyph = FALSE;
- }
- return index;
-}
-int CPDF_CIDFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph)
-{
- if (pVertGlyph) {
- *pVertGlyph = FALSE;
- }
- if (m_pFontFile == NULL && m_pCIDToGIDMap == NULL) {
- FX_WORD cid = CIDFromCharCode(charcode);
- FX_WCHAR unicode = 0;
- if (m_bCIDIsGID) {
-#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
- return cid;
-#else
- if (m_Flags & PDFFONT_SYMBOLIC) {
- return cid;
- }
- CFX_WideString uni_str = UnicodeFromCharCode(charcode);
- if (uni_str.IsEmpty()) {
- return cid;
- }
- unicode = uni_str.GetAt(0);
-#endif
- } else {
- if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded()) {
- unicode = m_pCID2UnicodeMap->UnicodeFromCID(cid);
- }
- if (unicode == 0) {
- unicode = _UnicodeFromCharCode(charcode);
- }
- if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) {
- unicode = UnicodeFromCharCode(charcode).GetAt(0);
- }
- }
- if (unicode == 0) {
- if (!m_bAdobeCourierStd) {
- return charcode == 0 ? -1 : (int)charcode;
- }
- charcode += 31;
- int index = 0, iBaseEncoding;
- FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1);
- FX_BOOL bMacRoman = FALSE;
- if (!bMSUnicode) {
- bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0);
- }
- iBaseEncoding = PDFFONT_ENCODING_STANDARD;
- if (bMSUnicode) {
- iBaseEncoding = PDFFONT_ENCODING_WINANSI;
- } else if (bMacRoman) {
- iBaseEncoding = PDFFONT_ENCODING_MACROMAN;
- }
- FX_LPCSTR name = GetAdobeCharName(iBaseEncoding, NULL, charcode);
- if (name == NULL) {
- return charcode == 0 ? -1 : (int)charcode;
- }
- FX_WORD unicode = PDF_UnicodeFromAdobeName(name);
- if (unicode) {
- if (bMSUnicode) {
- index = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
- } else if (bMacRoman) {
- FX_DWORD maccode = FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, unicode);
- index = !maccode ? FXFT_Get_Name_Index(m_Font.m_Face, (char *)name) : FXFT_Get_Char_Index(m_Font.m_Face, maccode);
- } else {
- return FXFT_Get_Char_Index(m_Font.m_Face, unicode);
- }
- } else {
- return charcode == 0 ? -1 : (int)charcode;
- }
- if (index == 0 || index == 0xffff) {
- return charcode == 0 ? -1 : (int)charcode;
- } else {
- return index;
- }
- }
- if (m_Charset == CIDSET_JAPAN1) {
- if (unicode == '\\') {
- unicode = '/';
- }
-#if !defined(_FPDFAPI_MINI_) && _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
- else if (unicode == 0xa5) {
- unicode = 0x5c;
- }
-#endif
- }
- if (m_Font.m_Face == NULL) {
- return unicode;
- }
- int err = FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE);
- if (err != 0) {
- int i;
- for (i = 0; i < FXFT_Get_Face_CharmapCount(m_Font.m_Face); i ++) {
- FX_DWORD ret = FT_CharCodeFromUnicode(FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]), (FX_WCHAR)charcode);
- if (ret == 0) {
- continue;
- }
- FXFT_Set_Charmap(m_Font.m_Face, FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]);
- unicode = (FX_WCHAR)ret;
- break;
- }
- if (i == FXFT_Get_Face_CharmapCount(m_Font.m_Face) && i) {
- FXFT_Set_Charmap(m_Font.m_Face, FXFT_Get_Face_Charmaps(m_Font.m_Face)[0]);
- unicode = (FX_WCHAR)charcode;
- }
- }
- if (FXFT_Get_Face_Charmap(m_Font.m_Face)) {
- int index = GetGlyphIndex(unicode, pVertGlyph);
- if (index == 0) {
- return -1;
- }
- return index;
- }
- return unicode ;
- }
- if (m_Font.m_Face == NULL) {
- return -1;
- }
- FX_WORD cid = CIDFromCharCode(charcode);
- if (m_bType1) {
- if (NULL == m_pCIDToGIDMap) {
- return cid;
- }
- } else {
- if (m_pCIDToGIDMap == NULL) {
- if (m_pFontFile && m_pCMap->m_pMapping == NULL) {
- return cid;
- }
- if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || FXFT_Get_Face_Charmap(m_Font.m_Face) == NULL) {
- return cid;
- }
- if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.m_Face)) == FXFT_ENCODING_UNICODE) {
- CFX_WideString unicode_str = UnicodeFromCharCode(charcode);
- if (unicode_str.IsEmpty()) {
- return -1;
- }
- charcode = unicode_str.GetAt(0);
- }
- return GetGlyphIndex(charcode, pVertGlyph);
- }
- }
- FX_DWORD byte_pos = cid * 2;
- if (byte_pos + 2 > m_pCIDToGIDMap->GetSize()) {
- return -1;
- }
- FX_LPCBYTE pdata = m_pCIDToGIDMap->GetData() + byte_pos;
- return pdata[0] * 256 + pdata[1];
-}
-FX_DWORD CPDF_CIDFont::GetNextChar(FX_LPCSTR pString, int& offset) const
-{
- return m_pCMap->GetNextChar(pString, offset);
-}
-int CPDF_CIDFont::GetCharSize(FX_DWORD charcode) const
-{
- return m_pCMap->GetCharSize(charcode);
-}
-int CPDF_CIDFont::CountChar(FX_LPCSTR pString, int size) const
-{
- return m_pCMap->CountChar(pString, size);
-}
-int CPDF_CIDFont::AppendChar(FX_LPSTR str, FX_DWORD charcode) const
-{
- return m_pCMap->AppendChar(str, charcode);
-}
-FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const
-{
- if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
- return m_pCMap->m_Coding != CIDCODING_UNKNOWN;
- }
- return TRUE;
-}
-FX_BOOL CPDF_CIDFont::IsFontStyleFromCharCode(FX_DWORD charcode) const
-{
- return TRUE;
-}
-void CPDF_CIDFont::LoadSubstFont()
-{
- m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, m_StemV * 5, m_ItalicAngle, g_CharsetCPs[m_Charset], IsVertWriting());
-}
-void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result, int nElements)
-{
- int width_status = 0;
- int iCurElement = 0;
- int first_code = 0, last_code;
- FX_DWORD count = pArray->GetCount();
- for (FX_DWORD i = 0; i < count; i ++) {
- CPDF_Object* pObj = pArray->GetElementValue(i);
- if (pObj == NULL) {
- continue;
- }
- if (pObj->GetType() == PDFOBJ_ARRAY) {
- if (width_status != 1) {
- return;
- }
- CPDF_Array* pArray = (CPDF_Array*)pObj;
- FX_DWORD count = pArray->GetCount();
- for (FX_DWORD j = 0; j < count; j += nElements) {
- result.Add(first_code);
- result.Add(first_code);
- for (int k = 0; k < nElements; k ++) {
- result.Add(pArray->GetInteger(j + k));
- }
- first_code ++;
- }
- width_status = 0;
- } else {
- if (width_status == 0) {
- first_code = pObj->GetInteger();
- width_status = 1;
- } else if (width_status == 1) {
- last_code = pObj->GetInteger();
- width_status = 2;
- iCurElement = 0;
- } else {
- if (!iCurElement) {
- result.Add(first_code);
- result.Add(last_code);
- }
- result.Add(pObj->GetInteger());
- iCurElement ++;
- if (iCurElement == nElements) {
- width_status = 0;
- }
- }
- }
- }
-}
-FX_BOOL CPDF_CIDFont::LoadGB2312()
-{
- m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont"));
- CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
- if (pFontDesc) {
- LoadFontDescriptor(pFontDesc);
- }
- m_Charset = CIDSET_GB1;
- m_bType1 = FALSE;
- m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetPredefinedCMap(
- FX_BSTRC("GBK-EUC-H"), FALSE);
- m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE);
- if (!IsEmbedded()) {
- LoadSubstFont();
- }
- CheckFontMetrics();
- m_DefaultWidth = 1000;
- m_pAnsiWidths = FX_Alloc(FX_WORD, 128);
- FXSYS_memset32(m_pAnsiWidths, 0, 128 * sizeof(FX_WORD));
- for (int i = 32; i < 127; i ++) {
- m_pAnsiWidths[i] = 500;
- }
- return TRUE;
-}
-const struct _CIDTransform {
- FX_WORD CID;
- FX_BYTE a, b, c, d, e, f;
-}
-Japan1_VertCIDs[] = {
- {97, 129, 0, 0, 127, 55, 0},
- {7887, 127, 0, 0, 127, 76, 89},
- {7888, 127, 0, 0, 127, 79, 94},
- {7889, 0, 129, 127, 0, 17, 127},
- {7890, 0, 129, 127, 0, 17, 127},
- {7891, 0, 129, 127, 0, 17, 127},
- {7892, 0, 129, 127, 0, 17, 127},
- {7893, 0, 129, 127, 0, 17, 127},
- {7894, 0, 129, 127, 0, 17, 127},
- {7895, 0, 129, 127, 0, 17, 127},
- {7896, 0, 129, 127, 0, 17, 127},
- {7897, 0, 129, 127, 0, 17, 127},
- {7898, 0, 129, 127, 0, 17, 127},
- {7899, 0, 129, 127, 0, 17, 104},
- {7900, 0, 129, 127, 0, 17, 127},
- {7901, 0, 129, 127, 0, 17, 104},
- {7902, 0, 129, 127, 0, 17, 127},
- {7903, 0, 129, 127, 0, 17, 127},
- {7904, 0, 129, 127, 0, 17, 127},
- {7905, 0, 129, 127, 0, 17, 114},
- {7906, 0, 129, 127, 0, 17, 127},
- {7907, 0, 129, 127, 0, 17, 127},
- {7908, 0, 129, 127, 0, 17, 127},
- {7909, 0, 129, 127, 0, 17, 127},
- {7910, 0, 129, 127, 0, 17, 127},
- {7911, 0, 129, 127, 0, 17, 127},
- {7912, 0, 129, 127, 0, 17, 127},
- {7913, 0, 129, 127, 0, 17, 127},
- {7914, 0, 129, 127, 0, 17, 127},
- {7915, 0, 129, 127, 0, 17, 114},
- {7916, 0, 129, 127, 0, 17, 127},
- {7917, 0, 129, 127, 0, 17, 127},
- {7918, 127, 0, 0, 127, 18, 25},
- {7919, 127, 0, 0, 127, 18, 25},
- {7920, 127, 0, 0, 127, 18, 25},
- {7921, 127, 0, 0, 127, 18, 25},
- {7922, 127, 0, 0, 127, 18, 25},
- {7923, 127, 0, 0, 127, 18, 25},
- {7924, 127, 0, 0, 127, 18, 25},
- {7925, 127, 0, 0, 127, 18, 25},
- {7926, 127, 0, 0, 127, 18, 25},
- {7927, 127, 0, 0, 127, 18, 25},
- {7928, 127, 0, 0, 127, 18, 25},
- {7929, 127, 0, 0, 127, 18, 25},
- {7930, 127, 0, 0, 127, 18, 25},
- {7931, 127, 0, 0, 127, 18, 25},
- {7932, 127, 0, 0, 127, 18, 25},
- {7933, 127, 0, 0, 127, 18, 25},
- {7934, 127, 0, 0, 127, 18, 25},
- {7935, 127, 0, 0, 127, 18, 25},
- {7936, 127, 0, 0, 127, 18, 25},
- {7937, 127, 0, 0, 127, 18, 25},
- {7938, 127, 0, 0, 127, 18, 25},
- {7939, 127, 0, 0, 127, 18, 25},
- {8720, 0, 129, 127, 0, 19, 102},
- {8721, 0, 129, 127, 0, 13, 127},
- {8722, 0, 129, 127, 0, 19, 108},
- {8723, 0, 129, 127, 0, 19, 102},
- {8724, 0, 129, 127, 0, 19, 102},
- {8725, 0, 129, 127, 0, 19, 102},
- {8726, 0, 129, 127, 0, 19, 102},
- {8727, 0, 129, 127, 0, 19, 102},
- {8728, 0, 129, 127, 0, 19, 114},
- {8729, 0, 129, 127, 0, 19, 114},
- {8730, 0, 129, 127, 0, 38, 108},
- {8731, 0, 129, 127, 0, 13, 108},
- {8732, 0, 129, 127, 0, 19, 108},
- {8733, 0, 129, 127, 0, 19, 108},
- {8734, 0, 129, 127, 0, 19, 108},
- {8735, 0, 129, 127, 0, 19, 108},
- {8736, 0, 129, 127, 0, 19, 102},
- {8737, 0, 129, 127, 0, 19, 102},
- {8738, 0, 129, 127, 0, 19, 102},
- {8739, 0, 129, 127, 0, 19, 102},
- {8740, 0, 129, 127, 0, 19, 102},
- {8741, 0, 129, 127, 0, 19, 102},
- {8742, 0, 129, 127, 0, 19, 102},
- {8743, 0, 129, 127, 0, 19, 102},
- {8744, 0, 129, 127, 0, 19, 102},
- {8745, 0, 129, 127, 0, 19, 102},
- {8746, 0, 129, 127, 0, 19, 114},
- {8747, 0, 129, 127, 0, 19, 114},
- {8748, 0, 129, 127, 0, 19, 102},
- {8749, 0, 129, 127, 0, 19, 102},
- {8750, 0, 129, 127, 0, 19, 102},
- {8751, 0, 129, 127, 0, 19, 102},
- {8752, 0, 129, 127, 0, 19, 102},
- {8753, 0, 129, 127, 0, 19, 102},
- {8754, 0, 129, 127, 0, 19, 102},
- {8755, 0, 129, 127, 0, 19, 102},
- {8756, 0, 129, 127, 0, 19, 102},
- {8757, 0, 129, 127, 0, 19, 102},
- {8758, 0, 129, 127, 0, 19, 102},
- {8759, 0, 129, 127, 0, 19, 102},
- {8760, 0, 129, 127, 0, 19, 102},
- {8761, 0, 129, 127, 0, 19, 102},
- {8762, 0, 129, 127, 0, 19, 102},
- {8763, 0, 129, 127, 0, 19, 102},
- {8764, 0, 129, 127, 0, 19, 102},
- {8765, 0, 129, 127, 0, 19, 102},
- {8766, 0, 129, 127, 0, 19, 102},
- {8767, 0, 129, 127, 0, 19, 102},
- {8768, 0, 129, 127, 0, 19, 102},
- {8769, 0, 129, 127, 0, 19, 102},
- {8770, 0, 129, 127, 0, 19, 102},
- {8771, 0, 129, 127, 0, 19, 102},
- {8772, 0, 129, 127, 0, 19, 102},
- {8773, 0, 129, 127, 0, 19, 102},
- {8774, 0, 129, 127, 0, 19, 102},
- {8775, 0, 129, 127, 0, 19, 102},
- {8776, 0, 129, 127, 0, 19, 102},
- {8777, 0, 129, 127, 0, 19, 102},
- {8778, 0, 129, 127, 0, 19, 102},
- {8779, 0, 129, 127, 0, 19, 114},
- {8780, 0, 129, 127, 0, 19, 108},
- {8781, 0, 129, 127, 0, 19, 114},
- {8782, 0, 129, 127, 0, 13, 114},
- {8783, 0, 129, 127, 0, 19, 108},
- {8784, 0, 129, 127, 0, 13, 114},
- {8785, 0, 129, 127, 0, 19, 108},
- {8786, 0, 129, 127, 0, 19, 108},
- {8787, 0, 129, 127, 0, 19, 108},
- {8788, 0, 129, 127, 0, 19, 108},
- {8789, 0, 129, 127, 0, 19, 108},
- {8790, 0, 129, 127, 0, 19, 108},
- {8791, 0, 129, 127, 0, 19, 108},
- {8792, 0, 129, 127, 0, 19, 108},
- {8793, 0, 129, 127, 0, 19, 108},
- {8794, 0, 129, 127, 0, 19, 108},
- {8795, 0, 129, 127, 0, 19, 108},
- {8796, 0, 129, 127, 0, 19, 108},
- {8797, 0, 129, 127, 0, 19, 108},
- {8798, 0, 129, 127, 0, 19, 108},
- {8799, 0, 129, 127, 0, 19, 108},
- {8800, 0, 129, 127, 0, 19, 108},
- {8801, 0, 129, 127, 0, 19, 108},
- {8802, 0, 129, 127, 0, 19, 108},
- {8803, 0, 129, 127, 0, 19, 108},
- {8804, 0, 129, 127, 0, 19, 108},
- {8805, 0, 129, 127, 0, 19, 108},
- {8806, 0, 129, 127, 0, 19, 108},
- {8807, 0, 129, 127, 0, 19, 108},
- {8808, 0, 129, 127, 0, 19, 108},
- {8809, 0, 129, 127, 0, 19, 108},
- {8810, 0, 129, 127, 0, 19, 108},
- {8811, 0, 129, 127, 0, 19, 114},
- {8812, 0, 129, 127, 0, 19, 102},
- {8813, 0, 129, 127, 0, 19, 114},
- {8814, 0, 129, 127, 0, 76, 102},
- {8815, 0, 129, 127, 0, 13, 121},
- {8816, 0, 129, 127, 0, 19, 114},
- {8817, 0, 129, 127, 0, 19, 127},
- {8818, 0, 129, 127, 0, 19, 114},
- {8819, 0, 129, 127, 0, 218, 108},
-};
-FX_LPCBYTE CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const
-{
- if (m_Charset != CIDSET_JAPAN1 || m_pFontFile != NULL) {
- return NULL;
- }
- int begin = 0;
- int end = sizeof Japan1_VertCIDs / sizeof(struct _CIDTransform) - 1;
- while (begin <= end) {
- int middle = (begin + end) / 2;
- FX_WORD middlecode = Japan1_VertCIDs[middle].CID;
- if (middlecode > CID) {
- end = middle - 1;
- } else if (middlecode < CID) {
- begin = middle + 1;
- } else {
- return &Japan1_VertCIDs[middle].a;
- }
- }
- return NULL;
-}
+// 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
+
+#include "../../../include/fpdfapi/fpdf_module.h"
+#include "../../../include/fpdfapi/fpdf_page.h"
+#include "font_int.h"
+#include "../fpdf_cmaps/cmap_int.h"
+#include "../../../include/fxge/fx_ge.h"
+#include "../../../include/fxge/fx_freetype.h"
+extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode);
+extern FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name);
+extern FX_BOOL FXFC_LoadFile(FX_LPVOID pPackage, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD& size);
+extern void FXFC_ClosePackage(FX_LPVOID pPackage);
+extern short TT2PDF(int m, FXFT_Face face);
+extern FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id);
+extern FX_LPCSTR GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pCharNames, int charcode);
+CPDF_CMapManager::CPDF_CMapManager()
+{
+#ifndef _FPDFAPI_MINI_
+ m_bPrompted = FALSE;
+ m_pPackage = NULL;
+#endif
+ FXSYS_memset32(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps);
+}
+CPDF_CMapManager::~CPDF_CMapManager()
+{
+ DropAll(FALSE);
+#ifndef _FPDFAPI_MINI_
+ if (m_pPackage) {
+ FXFC_ClosePackage(m_pPackage);
+ }
+#endif
+}
+#ifndef _FPDFAPI_MINI_
+FX_LPVOID CPDF_CMapManager::GetPackage(FX_BOOL bPrompt)
+{
+#ifndef FOXIT_CHROME_BUILD
+ if (m_pPackage == NULL) {
+ CFX_ByteString filename = CPDF_ModuleMgr::Get()->GetModuleFilePath(ADDIN_NAME_CJK, "FPDFCJK.BIN");
+ m_pPackage = FXFC_LoadPackage(filename);
+ if (bPrompt && m_pPackage == NULL && !m_bPrompted) {
+ m_bPrompted = TRUE;
+ if (!CPDF_ModuleMgr::Get()->DownloadModule(ADDIN_NAME_CJK)) {
+ return NULL;
+ }
+ m_pPackage = FXFC_LoadPackage(filename);
+ }
+ }
+#endif
+ return m_pPackage;
+}
+#endif
+CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPromptCJK)
+{
+ CPDF_CMap* pCMap;
+ if (m_CMaps.Lookup(name, (FX_LPVOID&)pCMap)) {
+ return pCMap;
+ }
+ pCMap = LoadPredefinedCMap(name, bPromptCJK);
+ if (name.IsEmpty()) {
+ return pCMap;
+ }
+ m_CMaps.SetAt(name, pCMap);
+ return pCMap;
+}
+CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPromptCJK)
+{
+ CPDF_CMap* pCMap = FX_NEW CPDF_CMap;
+ FX_LPCSTR pname = name;
+ if (*pname == '/') {
+ pname ++;
+ }
+ pCMap->LoadPredefined(this, pname, bPromptCJK);
+ return pCMap;
+}
+const FX_LPCSTR g_CharsetNames[] = {NULL, "GB1", "CNS1", "Japan1", "Korea1", "UCS", NULL};
+const int g_CharsetCPs[] = {0, 936, 950, 932, 949, 1200, 0};
+int _CharsetFromOrdering(const CFX_ByteString& Ordering)
+{
+ int charset = 1;
+ while (g_CharsetNames[charset] && Ordering != CFX_ByteStringC(g_CharsetNames[charset])) {
+ charset ++;
+ }
+ if (g_CharsetNames[charset] == NULL) {
+ return CIDSET_UNKNOWN;
+ }
+ return charset;
+}
+void CPDF_CMapManager::ReloadAll()
+{
+ DropAll(TRUE);
+}
+void CPDF_CMapManager::DropAll(FX_BOOL bReload)
+{
+ FX_POSITION pos = m_CMaps.GetStartPosition();
+ while (pos) {
+ CFX_ByteString name;
+ CPDF_CMap* pCMap;
+ m_CMaps.GetNextAssoc(pos, name, (FX_LPVOID&)pCMap);
+ if (pCMap == NULL) {
+ continue;
+ }
+ if (bReload) {
+ pCMap->LoadPredefined(this, name, FALSE);
+ } else {
+ delete pCMap;
+ }
+ }
+ for (int i = 0; i < sizeof m_CID2UnicodeMaps / sizeof(CPDF_CID2UnicodeMap*); i ++) {
+ CPDF_CID2UnicodeMap* pMap = m_CID2UnicodeMaps[i];
+ if (pMap == NULL) {
+ continue;
+ }
+ if (bReload) {
+ pMap->Load(this, i, FALSE);
+ } else {
+ delete pMap;
+ }
+ }
+}
+CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(int charset, FX_BOOL bPromptCJK)
+{
+ if (m_CID2UnicodeMaps[charset] == NULL) {
+ m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
+ }
+ return m_CID2UnicodeMaps[charset];
+}
+CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(int charset, FX_BOOL bPromptCJK)
+{
+ CPDF_CID2UnicodeMap* pMap = FX_NEW CPDF_CID2UnicodeMap();
+ if (!pMap->Initialize()) {
+ delete pMap;
+ return NULL;
+ }
+ pMap->Load(this, charset, bPromptCJK);
+ return pMap;
+}
+CPDF_CMapParser::CPDF_CMapParser()
+{
+ m_pCMap = NULL;
+ m_Status = 0;
+ m_CodeSeq = 0;
+}
+FX_BOOL CPDF_CMapParser::Initialize(CPDF_CMap* pCMap)
+{
+ m_pCMap = pCMap;
+ m_Status = 0;
+ m_CodeSeq = 0;
+ m_AddMaps.EstimateSize(0, 10240);
+ return TRUE;
+}
+static FX_DWORD CMap_GetCode(FX_BSTR word)
+{
+ int num = 0;
+ if (word.GetAt(0) == '<') {
+ for (int i = 1; i < word.GetLength(); i ++) {
+ FX_BYTE digit = word.GetAt(i);
+ if (digit >= '0' && digit <= '9') {
+ digit = digit - '0';
+ } else if (digit >= 'a' && digit <= 'f') {
+ digit = digit - 'a' + 10;
+ } else if (digit >= 'A' && digit <= 'F') {
+ digit = digit - 'A' + 10;
+ } else {
+ return num;
+ }
+ num = num * 16 + digit;
+ }
+ } else {
+ for (int i = 0; i < word.GetLength(); i ++) {
+ if (word.GetAt(i) < '0' || word.GetAt(i) > '9') {
+ return num;
+ }
+ num = num * 10 + word.GetAt(i) - '0';
+ }
+ }
+ return num;
+}
+static FX_BOOL _CMap_GetCodeRange(_CMap_CodeRange& range, FX_BSTR first, FX_BSTR second)
+{
+ if (first.GetLength() == 0 || first.GetAt(0) != '<') {
+ return FALSE;
+ }
+ int num = 0;
+ int i;
+ for (i = 1; i < first.GetLength(); i ++)
+ if (first.GetAt(i) == '>') {
+ break;
+ }
+ range.m_CharSize = (i - 1) / 2;
+ if (range.m_CharSize > 4) {
+ return FALSE;
+ }
+ for (i = 0; i < range.m_CharSize; i ++) {
+ FX_BYTE digit1 = first.GetAt(i * 2 + 1);
+ FX_BYTE digit2 = first.GetAt(i * 2 + 2);
+ FX_BYTE byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((digit1 & 0xdf) - 'A' + 10);
+ byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') : ((digit2 & 0xdf) - 'A' + 10));
+ range.m_Lower[i] = byte;
+ }
+ FX_DWORD size = second.GetLength();
+ for (i = 0; i < range.m_CharSize; i ++) {
+ FX_BYTE digit1 = ((FX_DWORD)i * 2 + 1 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 1) : 0;
+ FX_BYTE digit2 = ((FX_DWORD)i * 2 + 2 < size) ? second.GetAt((FX_STRSIZE)i * 2 + 2) : 0;
+ FX_BYTE byte = (digit1 >= '0' && digit1 <= '9') ? (digit1 - '0') : ((digit1 & 0xdf) - 'A' + 10);
+ byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') ? (digit2 - '0') : ((digit2 & 0xdf) - 'A' + 10));
+ range.m_Upper[i] = byte;
+ }
+ return TRUE;
+}
+static CFX_ByteString CMap_GetString(FX_BSTR word)
+{
+ return word.Mid(1, word.GetLength() - 2);
+}
+void CPDF_CMapParser::ParseWord(FX_BSTR word)
+{
+ if (word.IsEmpty()) {
+ return;
+ }
+ if (word == FX_BSTRC("begincidchar")) {
+ m_Status = 1;
+ m_CodeSeq = 0;
+ } else if (word == FX_BSTRC("begincidrange")) {
+ m_Status = 2;
+ m_CodeSeq = 0;
+ } else if (word == FX_BSTRC("endcidrange") || word == FX_BSTRC("endcidchar")) {
+ m_Status = 0;
+ } else if (word == FX_BSTRC("/WMode")) {
+ m_Status = 6;
+ } else if (word == FX_BSTRC("/Registry")) {
+ m_Status = 3;
+ } else if (word == FX_BSTRC("/Ordering")) {
+ m_Status = 4;
+ } else if (word == FX_BSTRC("/Supplement")) {
+ m_Status = 5;
+ } else if (word == FX_BSTRC("begincodespacerange")) {
+ m_Status = 7;
+ m_CodeSeq = 0;
+ } else if (word == FX_BSTRC("usecmap")) {
+ } else if (m_Status == 1 || m_Status == 2) {
+ m_CodePoints[m_CodeSeq] = CMap_GetCode(word);
+ m_CodeSeq ++;
+ FX_DWORD StartCode, EndCode;
+ FX_WORD StartCID;
+ if (m_Status == 1) {
+ if (m_CodeSeq < 2) {
+ return;
+ }
+ EndCode = StartCode = m_CodePoints[0];
+ StartCID = (FX_WORD)m_CodePoints[1];
+ } else {
+ if (m_CodeSeq < 3) {
+ return;
+ }
+ StartCode = m_CodePoints[0];
+ EndCode = m_CodePoints[1];
+ StartCID = (FX_WORD)m_CodePoints[2];
+ }
+ if (EndCode < 0x10000) {
+ for (FX_DWORD code = StartCode; code <= EndCode; code ++) {
+ m_pCMap->m_pMapping[code] = (FX_WORD)(StartCID + code - StartCode);
+ }
+ } else {
+ FX_DWORD buf[2];
+ buf[0] = StartCode;
+ buf[1] = ((EndCode - StartCode) << 16) + StartCID;
+ m_AddMaps.AppendBlock(buf, sizeof buf);
+ }
+ m_CodeSeq = 0;
+ } else if (m_Status == 3) {
+ CMap_GetString(word);
+ m_Status = 0;
+ } else if (m_Status == 4) {
+ m_pCMap->m_Charset = _CharsetFromOrdering(CMap_GetString(word));
+ m_Status = 0;
+ } else if (m_Status == 5) {
+ CMap_GetCode(word);
+ m_Status = 0;
+ } else if (m_Status == 6) {
+ m_pCMap->m_bVertical = CMap_GetCode(word);
+ m_Status = 0;
+ } else if (m_Status == 7) {
+ if (word == FX_BSTRC("endcodespacerange")) {
+ int nSegs = m_CodeRanges.GetSize();
+ if (nSegs > 1) {
+ m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes;
+ m_pCMap->m_nCodeRanges = nSegs;
+ m_pCMap->m_pLeadingBytes = FX_Alloc(FX_BYTE, nSegs * sizeof(_CMap_CodeRange));
+ FXSYS_memcpy32(m_pCMap->m_pLeadingBytes, m_CodeRanges.GetData(), nSegs * sizeof(_CMap_CodeRange));
+ } else if (nSegs == 1) {
+ m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2) ? CPDF_CMap::TwoBytes : CPDF_CMap::OneByte;
+ }
+ m_Status = 0;
+ } else {
+ if (word.GetLength() == 0 || word.GetAt(0) != '<') {
+ return;
+ }
+ if (m_CodeSeq % 2) {
+ _CMap_CodeRange range;
+ if (_CMap_GetCodeRange(range, m_LastWord, word)) {
+ m_CodeRanges.Add(range);
+ }
+ }
+ m_CodeSeq ++;
+ }
+ }
+ m_LastWord = word;
+}
+CPDF_CMap::CPDF_CMap()
+{
+ m_Charset = CIDSET_UNKNOWN;
+ m_Coding = CIDCODING_UNKNOWN;
+ m_CodingScheme = TwoBytes;
+ m_bVertical = 0;
+ m_bLoaded = FALSE;
+ m_pMapping = NULL;
+ m_pLeadingBytes = NULL;
+ m_pAddMapping = NULL;
+ m_pEmbedMap = NULL;
+ m_pUseMap = NULL;
+ m_nCodeRanges = 0;
+}
+CPDF_CMap::~CPDF_CMap()
+{
+ if (m_pMapping) {
+ FX_Free(m_pMapping);
+ }
+ if (m_pAddMapping) {
+ FX_Free(m_pAddMapping);
+ }
+ if (m_pLeadingBytes) {
+ FX_Free(m_pLeadingBytes);
+ }
+ if (m_pUseMap) {
+ delete m_pUseMap;
+ }
+}
+void CPDF_CMap::Release()
+{
+ if (m_PredefinedCMap.IsEmpty()) {
+ delete this;
+ }
+}
+const CPDF_PredefinedCMap g_PredefinedCMaps[] = {
+ { "GB-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
+ { "GBpc-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfc} },
+ { "GBK-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
+ { "GBKp-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
+ { "GBK2K-EUC", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
+ { "GBK2K", CIDSET_GB1, CIDCODING_GB, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
+ { "UniGB-UCS2", CIDSET_GB1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
+ { "UniGB-UTF16", CIDSET_GB1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
+ { "B5pc", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfc} },
+ { "HKscs-B5", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0x88, 0xfe} },
+ { "ETen-B5", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
+ { "ETenms-B5", CIDSET_CNS1, CIDCODING_BIG5, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
+ { "UniCNS-UCS2", CIDSET_CNS1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
+ { "UniCNS-UTF16", CIDSET_CNS1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
+ { "83pv-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
+ { "90ms-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
+ { "90msp-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
+ { "90pv-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
+ { "Add-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
+ { "EUC", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x8e, 0x8e, 0xa1, 0xfe} },
+ { "H", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::TwoBytes, 1, {0x21, 0x7e} },
+ { "V", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::TwoBytes, 1, {0x21, 0x7e} },
+ { "Ext-RKSJ", CIDSET_JAPAN1, CIDCODING_JIS, CPDF_CMap::MixedTwoBytes, 2, {0x81, 0x9f, 0xe0, 0xfc} },
+ { "UniJIS-UCS2", CIDSET_JAPAN1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
+ { "UniJIS-UCS2-HW", CIDSET_JAPAN1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
+ { "UniJIS-UTF16", CIDSET_JAPAN1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
+ { "KSC-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfe} },
+ { "KSCms-UHC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
+ { "KSCms-UHC-HW", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0x81, 0xfe} },
+ { "KSCpc-EUC", CIDSET_KOREA1, CIDCODING_KOREA, CPDF_CMap::MixedTwoBytes, 1, {0xa1, 0xfd} },
+ { "UniKS-UCS2", CIDSET_KOREA1, CIDCODING_UCS2, CPDF_CMap::TwoBytes },
+ { "UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes },
+ { NULL, 0, 0 }
+};
+extern void FPDFAPI_FindEmbeddedCMap(const char* name, int charset, int coding, const FXCMAP_CMap*& pMap);
+extern FX_WORD FPDFAPI_CIDFromCharCode(const FXCMAP_CMap* pMap, FX_DWORD charcode);
+FX_BOOL CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, FX_LPCSTR pName, FX_BOOL bPromptCJK)
+{
+ m_PredefinedCMap = pName;
+ if (m_PredefinedCMap == FX_BSTRC("Identity-H") || m_PredefinedCMap == FX_BSTRC("Identity-V")) {
+ m_Coding = CIDCODING_CID;
+ m_bVertical = pName[9] == 'V';
+ m_bLoaded = TRUE;
+ return TRUE;
+ }
+ CFX_ByteString cmapid = m_PredefinedCMap;
+ m_bVertical = cmapid.Right(1) == FX_BSTRC("V");
+ if (cmapid.GetLength() > 2) {
+ cmapid = cmapid.Left(cmapid.GetLength() - 2);
+ }
+ int index = 0;
+ while (1) {
+ if (g_PredefinedCMaps[index].m_pName == NULL) {
+ return FALSE;
+ }
+ if (cmapid == CFX_ByteStringC(g_PredefinedCMaps[index].m_pName)) {
+ break;
+ }
+ index ++;
+ }
+ const CPDF_PredefinedCMap& map = g_PredefinedCMaps[index];
+ m_Charset = map.m_Charset;
+ m_Coding = map.m_Coding;
+ m_CodingScheme = map.m_CodingScheme;
+ if (m_CodingScheme == MixedTwoBytes) {
+ m_pLeadingBytes = FX_Alloc(FX_BYTE, 256);
+ FXSYS_memset32(m_pLeadingBytes, 0, 256);
+ for (FX_DWORD i = 0; i < map.m_LeadingSegCount; i ++) {
+ for (int b = map.m_LeadingSegs[i * 2]; b <= map.m_LeadingSegs[i * 2 + 1]; b ++) {
+ m_pLeadingBytes[b] = 1;
+ }
+ }
+ }
+ FPDFAPI_FindEmbeddedCMap(pName, m_Charset, m_Coding, m_pEmbedMap);
+ if (m_pEmbedMap) {
+ m_bLoaded = TRUE;
+ return TRUE;
+ }
+#ifndef _FPDFAPI_MINI_
+ FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK);
+ FX_LPBYTE pBuffer;
+ FX_DWORD size;
+ if (pPackage == NULL || !FXFC_LoadFile(pPackage, m_PredefinedCMap, pBuffer, size)) {
+ return FALSE;
+ }
+ m_pMapping = FX_Alloc(FX_WORD, 65536);
+ FXSYS_memset32(m_pMapping, 0, 65536 * sizeof(FX_WORD));
+ FX_DWORD dwRecodeEndPos = 0;
+ if (pBuffer[5] == 0) {
+ FX_DWORD dwStartIndex = *(FX_DWORD*)(pBuffer + 8);
+ FX_DWORD dwRecordCount = *(FX_DWORD*)(pBuffer + 16);
+ FX_DWORD dwDataOffset = *(FX_DWORD*)(pBuffer + 20);
+ if (dwRecordCount * 2 + dwStartIndex * 2 < 65536) {
+ FXSYS_memcpy32(m_pMapping + dwStartIndex * 2, pBuffer + dwDataOffset, dwRecordCount * 2);
+ }
+ dwRecodeEndPos = dwDataOffset + dwRecordCount * 2;
+ } else if (pBuffer[5] == 2) {
+ FX_DWORD nSegments = *(FX_DWORD*)(pBuffer + 16);
+ FX_DWORD dwDataOffset = *(FX_DWORD*)(pBuffer + 20);
+ dwRecodeEndPos = dwDataOffset + 6 * nSegments;
+ for (FX_DWORD i = 0; i < nSegments; i ++) {
+ FX_LPBYTE pRecord = pBuffer + dwDataOffset + i * 6;
+ FX_WORD IndexStart = *(FX_WORD*)pRecord;
+ FX_WORD IndexCount = *(FX_WORD*)(pRecord + 2);
+ FX_WORD CodeStart = *(FX_WORD*)(pRecord + 4);
+ if (IndexStart + IndexCount < 65536)
+ for (FX_DWORD j = 0; j < IndexCount; j ++) {
+ m_pMapping[IndexStart + j ] = (FX_WORD)(CodeStart + j);
+ }
+ }
+ }
+ if (dwRecodeEndPos < size) {
+ FX_DWORD dwMapLen = *(FX_DWORD*)(pBuffer + dwRecodeEndPos);
+ if (dwMapLen) {
+ m_pUseMap = FX_NEW CPDF_CMap;
+ CFX_ByteString bsName(pBuffer + dwRecodeEndPos + 4 , dwMapLen);
+ if (m_pUseMap) {
+ m_pUseMap->LoadPredefined(pMgr, bsName, bPromptCJK);
+ }
+ }
+ }
+ FX_Free(pBuffer);
+ m_bLoaded = TRUE;
+#endif
+ return TRUE;
+}
+extern "C" {
+ static int compare_dword(const void* data1, const void* data2)
+ {
+ return (*(FX_DWORD*)data1) - (*(FX_DWORD*)data2);
+ }
+};
+FX_BOOL CPDF_CMap::LoadEmbedded(FX_LPCBYTE pData, FX_DWORD size)
+{
+ m_pMapping = FX_Alloc(FX_WORD, 65536);
+ FXSYS_memset32(m_pMapping, 0, 65536 * sizeof(FX_WORD));
+ CPDF_CMapParser parser;
+ parser.Initialize(this);
+ CPDF_SimpleParser syntax(pData, size);
+ while (1) {
+ CFX_ByteStringC word = syntax.GetWord();
+ if (word.IsEmpty()) {
+ break;
+ }
+ parser.ParseWord(word);
+ }
+ if (m_CodingScheme == MixedFourBytes && parser.m_AddMaps.GetSize()) {
+ m_pAddMapping = FX_Alloc(FX_BYTE, parser.m_AddMaps.GetSize() + 4);
+ *(FX_DWORD*)m_pAddMapping = parser.m_AddMaps.GetSize() / 8;
+ FXSYS_memcpy32(m_pAddMapping + 4, parser.m_AddMaps.GetBuffer(), parser.m_AddMaps.GetSize());
+ FXSYS_qsort(m_pAddMapping + 4, parser.m_AddMaps.GetSize() / 8, 8, compare_dword);
+ }
+ return TRUE;
+}
+extern "C" {
+ static int compareCID(const void* key, const void* element)
+ {
+ if ((*(FX_DWORD*)key) < (*(FX_DWORD*)element)) {
+ return -1;
+ }
+ if ((*(FX_DWORD*)key) > (*(FX_DWORD*)element) + ((FX_DWORD*)element)[1] / 65536) {
+ return 1;
+ }
+ return 0;
+ }
+};
+FX_WORD CPDF_CMap::CIDFromCharCode(FX_DWORD charcode) const
+{
+ if (m_Coding == CIDCODING_CID) {
+ return (FX_WORD)charcode;
+ }
+ if (m_pEmbedMap) {
+ return FPDFAPI_CIDFromCharCode(m_pEmbedMap, charcode);
+ }
+ if (m_pMapping == NULL) {
+ return (FX_WORD)charcode;
+ }
+ if (charcode >> 16) {
+ if (m_pAddMapping) {
+ void* found = FXSYS_bsearch(&charcode, m_pAddMapping + 4, *(FX_DWORD*)m_pAddMapping, 8, compareCID);
+ if (found == NULL) {
+ if (m_pUseMap) {
+ return m_pUseMap->CIDFromCharCode(charcode);
+ }
+ return 0;
+ }
+ return (FX_WORD)(((FX_DWORD*)found)[1] % 65536 + charcode - * (FX_DWORD*)found);
+ }
+ if (m_pUseMap) {
+ return m_pUseMap->CIDFromCharCode(charcode);
+ }
+ return 0;
+ }
+ FX_DWORD CID = m_pMapping[charcode];
+ if (!CID && m_pUseMap) {
+ return m_pUseMap->CIDFromCharCode(charcode);
+ }
+ return (FX_WORD)CID;
+}
+static int _CheckCodeRange(FX_LPBYTE codes, int size, _CMap_CodeRange* pRanges, int nRanges)
+{
+ int iSeg = nRanges - 1;
+ while (iSeg >= 0) {
+ if (pRanges[iSeg].m_CharSize < size) {
+ iSeg --;
+ continue;
+ }
+ int iChar = 0;
+ while (iChar < size) {
+ if (codes[iChar] < pRanges[iSeg].m_Lower[iChar] ||
+ codes[iChar] > pRanges[iSeg].m_Upper[iChar]) {
+ break;
+ }
+ iChar ++;
+ }
+ if (iChar == pRanges[iSeg].m_CharSize) {
+ return 2;
+ }
+ if (iChar) {
+ if (size == pRanges[iSeg].m_CharSize) {
+ return 2;
+ }
+ return 1;
+ }
+ iSeg --;
+ }
+ return 0;
+}
+FX_DWORD CPDF_CMap::GetNextChar(FX_LPCSTR pString, int& offset) const
+{
+ switch (m_CodingScheme) {
+ case OneByte:
+ return ((FX_LPBYTE)pString)[offset++];
+ case TwoBytes:
+ offset += 2;
+ return ((FX_LPBYTE)pString)[offset - 2] * 256 + ((FX_LPBYTE)pString)[offset - 1];
+ case MixedTwoBytes: {
+ FX_BYTE byte1 = ((FX_LPBYTE)pString)[offset++];
+ if (!m_pLeadingBytes[byte1]) {
+ return byte1;
+ }
+ FX_BYTE byte2 = ((FX_LPBYTE)pString)[offset++];
+ return byte1 * 256 + byte2;
+ }
+ case MixedFourBytes: {
+ FX_BYTE codes[4];
+ int char_size = 1;
+ codes[0] = ((FX_LPBYTE)pString)[offset++];
+ _CMap_CodeRange* pRanges = (_CMap_CodeRange*)m_pLeadingBytes;
+ while (1) {
+ int ret = _CheckCodeRange(codes, char_size, pRanges, m_nCodeRanges);
+ if (ret == 0) {
+ return 0;
+ }
+ if (ret == 2) {
+ FX_DWORD charcode = 0;
+ for (int i = 0; i < char_size; i ++) {
+ charcode = (charcode << 8) + codes[i];
+ }
+ return charcode;
+ }
+ if (char_size == 4) {
+ return 0;
+ }
+ codes[char_size ++] = ((FX_LPBYTE)pString)[offset++];
+ }
+ break;
+ }
+ }
+ return 0;
+}
+int CPDF_CMap::GetCharSize(FX_DWORD charcode) const
+{
+ switch (m_CodingScheme) {
+ case OneByte:
+ return 1;
+ case TwoBytes:
+ return 2;
+ case MixedTwoBytes:
+ case MixedFourBytes:
+ if (charcode < 0x100) {
+ return 1;
+ }
+ if (charcode < 0x10000) {
+ return 2;
+ }
+ if (charcode < 0x1000000) {
+ return 3;
+ }
+ return 4;
+ }
+ return 1;
+}
+int CPDF_CMap::CountChar(FX_LPCSTR pString, int size) const
+{
+ switch (m_CodingScheme) {
+ case OneByte:
+ return size;
+ case TwoBytes:
+ return (size + 1) / 2;
+ case MixedTwoBytes: {
+ int count = 0;
+ for (int i = 0; i < size; i ++) {
+ count ++;
+ if (m_pLeadingBytes[((FX_LPBYTE)pString)[i]]) {
+ i ++;
+ }
+ }
+ return count;
+ }
+ case MixedFourBytes: {
+ int count = 0, offset = 0;
+ while (offset < size) {
+ GetNextChar(pString, offset);
+ count ++;
+ }
+ return count;
+ }
+ }
+ return size;
+}
+int _GetCharSize(FX_DWORD charcode, _CMap_CodeRange* pRanges, int iRangesSize)
+{
+ if (!iRangesSize) {
+ return 1;
+ }
+ FX_BYTE codes[4];
+ codes[0] = codes[1] = 0x00;
+ codes[2] = (FX_BYTE)(charcode >> 8 & 0xFF);
+ codes[3] = (FX_BYTE)charcode;
+ int offset = 0, size = 4;
+ for (int i = 0; i < 4; ++i) {
+ int iSeg = iRangesSize - 1;
+ while (iSeg >= 0) {
+ if (pRanges[iSeg].m_CharSize < size) {
+ iSeg --;
+ continue;
+ }
+ int iChar = 0;
+ while (iChar < size) {
+ if (codes[offset + iChar] < pRanges[iSeg].m_Lower[iChar] ||
+ codes[offset + iChar] > pRanges[iSeg].m_Upper[iChar]) {
+ break;
+ }
+ iChar ++;
+ }
+ if (iChar == pRanges[iSeg].m_CharSize) {
+ return size;
+ }
+ iSeg --;
+ }
+ size --;
+ offset ++;
+ }
+ return 1;
+}
+int CPDF_CMap::AppendChar(FX_LPSTR str, FX_DWORD charcode) const
+{
+ switch (m_CodingScheme) {
+ case OneByte:
+ str[0] = (FX_BYTE)charcode;
+ return 1;
+ case TwoBytes:
+ str[0] = (FX_BYTE)(charcode / 256);
+ str[1] = (FX_BYTE)(charcode % 256);
+ return 2;
+ case MixedTwoBytes:
+ case MixedFourBytes:
+ if (charcode < 0x100) {
+ _CMap_CodeRange* pRanges = (_CMap_CodeRange*)m_pLeadingBytes;
+ int iSize = _GetCharSize(charcode, pRanges, m_nCodeRanges);
+ if (iSize == 0) {
+ iSize = 1;
+ }
+ if (iSize > 1) {
+ FXSYS_memset32(str, 0, sizeof(FX_BYTE) * iSize);
+ }
+ str[iSize - 1] = (FX_BYTE)charcode;
+ return iSize;
+ } else if (charcode < 0x10000) {
+ str[0] = (FX_BYTE)(charcode >> 8);
+ str[1] = (FX_BYTE)charcode;
+ return 2;
+ } else if (charcode < 0x1000000) {
+ str[0] = (FX_BYTE)(charcode >> 16);
+ str[1] = (FX_BYTE)(charcode >> 8);
+ str[2] = (FX_BYTE)charcode;
+ return 3;
+ } else {
+ str[0] = (FX_BYTE)(charcode >> 24);
+ str[1] = (FX_BYTE)(charcode >> 16);
+ str[2] = (FX_BYTE)(charcode >> 8);
+ str[3] = (FX_BYTE)charcode;
+ return 4;
+ }
+ }
+ return 0;
+}
+CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap()
+{
+ m_EmbeddedCount = 0;
+#ifndef _FPDFAPI_MINI_
+ m_pExternalMap = NULL;
+#endif
+}
+CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap()
+{
+#ifndef _FPDFAPI_MINI_
+ if (m_pExternalMap) {
+ delete m_pExternalMap;
+ }
+#endif
+}
+FX_BOOL CPDF_CID2UnicodeMap::Initialize()
+{
+#ifndef _FPDFAPI_MINI_
+ m_pExternalMap = FX_NEW CPDF_FXMP;
+#endif
+ return TRUE;
+}
+FX_BOOL CPDF_CID2UnicodeMap::IsLoaded()
+{
+#ifdef _FPDFAPI_MINI_
+ return m_EmbeddedCount != 0;
+#else
+ return m_EmbeddedCount != 0 || (m_pExternalMap != NULL && m_pExternalMap->IsLoaded());
+#endif
+}
+FX_WCHAR CPDF_CID2UnicodeMap::UnicodeFromCID(FX_WORD CID)
+{
+ if (m_Charset == CIDSET_UNICODE) {
+ return CID;
+ }
+ if (CID < m_EmbeddedCount) {
+ return m_pEmbeddedMap[CID];
+ }
+#ifdef _FPDFAPI_MINI_
+ return 0;
+#else
+ FX_LPCBYTE record = m_pExternalMap->GetRecord(CID);
+ if (record == NULL) {
+ return 0;
+ }
+ return *(FX_WORD*)record;
+#endif
+}
+void FPDFAPI_LoadCID2UnicodeMap(int charset, const FX_WORD*& pMap, FX_DWORD& count);
+void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPromptCJK)
+{
+ m_Charset = charset;
+ FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount);
+ if (m_EmbeddedCount) {
+ return;
+ }
+#ifndef _FPDFAPI_MINI_
+ FX_LPVOID pPackage = pMgr->GetPackage(bPromptCJK);
+ if (pPackage == NULL) {
+ return;
+ }
+ m_pExternalMap->LoadFile(pPackage, FX_BSTRC("CIDInfo_") + g_CharsetNames[charset]);
+#endif
+}
+#include "ttgsubtable.h"
+CPDF_CIDFont::CPDF_CIDFont()
+{
+ m_pCMap = NULL;
+ m_pAllocatedCMap = NULL;
+ m_pCID2UnicodeMap = NULL;
+ m_pAnsiWidths = NULL;
+ m_pCIDToGIDMap = NULL;
+ m_bCIDIsGID = FALSE;
+ m_bAdobeCourierStd = FALSE;
+ m_pTTGSUBTable = NULL;
+ FXSYS_memset8(m_CharBBox, 0xff, 256 * sizeof(FX_SMALL_RECT));
+}
+CPDF_CIDFont::~CPDF_CIDFont()
+{
+ if (m_pAnsiWidths) {
+ FX_Free(m_pAnsiWidths);
+ }
+ if (m_pAllocatedCMap) {
+ delete m_pAllocatedCMap;
+ }
+ if (m_pCIDToGIDMap) {
+ delete m_pCIDToGIDMap;
+ }
+ if (m_pTTGSUBTable) {
+ delete m_pTTGSUBTable;
+ }
+}
+FX_WORD CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const
+{
+ if (m_pCMap == NULL) {
+ return (FX_WORD)charcode;
+ }
+ return m_pCMap->CIDFromCharCode(charcode);
+}
+FX_BOOL CPDF_CIDFont::IsVertWriting() const
+{
+ return m_pCMap ? m_pCMap->IsVertWriting() : FALSE;
+}
+extern FX_DWORD FPDFAPI_CharCodeFromCID(const FXCMAP_CMap* pMap, FX_WORD cid);
+static FX_DWORD _EmbeddedCharcodeFromUnicode(const FXCMAP_CMap* pEmbedMap, int charset, FX_WCHAR unicode)
+{
+ if (charset <= 0 || charset > 4) {
+ return 0;
+ }
+ CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
+ const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
+ if (pCodes == NULL) {
+ return 0;
+ }
+ int nCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
+ for (int i = 0; i < nCodes; i++) {
+ if (pCodes[i] == unicode) {
+ FX_DWORD CharCode = FPDFAPI_CharCodeFromCID(pEmbedMap, i);
+ if (CharCode == 0) {
+ continue;
+ }
+ return CharCode;
+ }
+ }
+ return 0;
+}
+static FX_WCHAR _EmbeddedUnicodeFromCharcode(const FXCMAP_CMap* pEmbedMap, int charset, FX_DWORD charcode)
+{
+ if (charset <= 0 || charset > 4) {
+ return 0;
+ }
+ FX_WORD cid = FPDFAPI_CIDFromCharCode(pEmbedMap, charcode);
+ if (cid == 0) {
+ return 0;
+ }
+ CPDF_FontGlobals* pFontGlobals = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
+ const FX_WORD* pCodes = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
+ if (pCodes == NULL) {
+ return 0;
+ }
+ if (cid < pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count) {
+ return pCodes[cid];
+ }
+ return 0;
+}
+FX_WCHAR CPDF_CIDFont::_UnicodeFromCharCode(FX_DWORD charcode) const
+{
+ switch (m_pCMap->m_Coding) {
+ case CIDCODING_UCS2:
+ case CIDCODING_UTF16:
+ return (FX_WCHAR)charcode;
+ case CIDCODING_CID:
+ if (m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
+ return 0;
+ }
+ return m_pCID2UnicodeMap->UnicodeFromCID((FX_WORD)charcode);
+ }
+ if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+ FX_WCHAR unicode;
+ int charsize = 1;
+ if (charcode > 255) {
+ charcode = (charcode % 256) * 256 + (charcode / 256);
+ charsize = 2;
+ }
+ int ret = FXSYS_MultiByteToWideChar(g_CharsetCPs[m_pCMap->m_Coding], 0, (FX_LPCSTR)&charcode, charsize, &unicode, 1);
+ if (ret != 1) {
+ return 0;
+ }
+ return unicode;
+#endif
+ if (m_pCMap->m_pEmbedMap) {
+ return _EmbeddedUnicodeFromCharcode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset, charcode);
+ } else {
+ return 0;
+ }
+ }
+ return m_pCID2UnicodeMap->UnicodeFromCID(CIDFromCharCode(charcode));
+}
+FX_DWORD CPDF_CIDFont::_CharCodeFromUnicode(FX_WCHAR unicode) const
+{
+ switch (m_pCMap->m_Coding) {
+ case CIDCODING_UNKNOWN:
+ return 0;
+ case CIDCODING_UCS2:
+ case CIDCODING_UTF16:
+ return unicode;
+ case CIDCODING_CID: {
+ if (m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
+ return 0;
+ }
+ FX_DWORD CID = 0;
+ while (CID < 65536) {
+ FX_WCHAR this_unicode = m_pCID2UnicodeMap->UnicodeFromCID((FX_WORD)CID);
+ if (this_unicode == unicode) {
+ return CID;
+ }
+ CID ++;
+ }
+ break;
+ }
+ }
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+ FX_BYTE buffer[32];
+ int ret = FXSYS_WideCharToMultiByte(g_CharsetCPs[m_pCMap->m_Coding], 0, &unicode, 1, (char*)buffer, 4, NULL, NULL);
+ if (ret == 1) {
+ return buffer[0];
+ } else if (ret == 2) {
+ return buffer[0] * 256 + buffer[1];
+ }
+ return 0;
+#endif
+ if (unicode < 0x80) {
+ return (FX_DWORD)unicode;
+ } else {
+ if (m_pCMap->m_pEmbedMap) {
+ return _EmbeddedCharcodeFromUnicode(m_pCMap->m_pEmbedMap, m_pCMap->m_Charset, unicode);
+ } else {
+ return 0;
+ }
+ }
+}
+static void FT_UseCIDCharmap(FXFT_Face face, int coding)
+{
+ int encoding;
+ switch (coding) {
+ case CIDCODING_GB:
+ encoding = FXFT_ENCODING_GB2312;
+ break;
+ case CIDCODING_BIG5:
+ encoding = FXFT_ENCODING_BIG5;
+ break;
+ case CIDCODING_JIS:
+ encoding = FXFT_ENCODING_SJIS;
+ break;
+ case CIDCODING_KOREA:
+ encoding = FXFT_ENCODING_JOHAB;
+ break;
+ default:
+ encoding = FXFT_ENCODING_UNICODE;
+ }
+ int err = FXFT_Select_Charmap(face, encoding);
+ if (err) {
+ err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE);
+ }
+ if (err && FXFT_Get_Face_Charmaps(face)) {
+ FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face));
+ }
+}
+FX_BOOL CPDF_CIDFont::_Load()
+{
+ if (m_pFontDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("TrueType")) {
+ return LoadGB2312();
+ }
+ CPDF_Array* pFonts = m_pFontDict->GetArray(FX_BSTRC("DescendantFonts"));
+ if (pFonts == NULL) {
+ return FALSE;
+ }
+ if (pFonts->GetCount() != 1) {
+ return FALSE;
+ }
+ CPDF_Dictionary* pCIDFontDict = pFonts->GetDict(0);
+ if (pCIDFontDict == NULL) {
+ return FALSE;
+ }
+ m_BaseFont = pCIDFontDict->GetString(FX_BSTRC("BaseFont"));
+ if ((m_BaseFont.Compare("CourierStd") == 0 || m_BaseFont.Compare("CourierStd-Bold") == 0
+ || m_BaseFont.Compare("CourierStd-BoldOblique") == 0 || m_BaseFont.Compare("CourierStd-Oblique") == 0)
+ && !IsEmbedded()) {
+ m_bAdobeCourierStd = TRUE;
+ }
+ CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDict(FX_BSTRC("FontDescriptor"));
+ if (pFontDesc) {
+ LoadFontDescriptor(pFontDesc);
+ }
+ CPDF_Object* pEncoding = m_pFontDict->GetElementValue(FX_BSTRC("Encoding"));
+ if (pEncoding == NULL) {
+ return FALSE;
+ }
+ CFX_ByteString subtype = pCIDFontDict->GetString(FX_BSTRC("Subtype"));
+ m_bType1 = FALSE;
+ if (subtype == FX_BSTRC("CIDFontType0")) {
+ m_bType1 = TRUE;
+ }
+ if (pEncoding->GetType() == PDFOBJ_NAME) {
+ CFX_ByteString cmap = pEncoding->GetString();
+ m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetPredefinedCMap(cmap,
+ m_pFontFile && m_bType1);
+ } else if (pEncoding->GetType() == PDFOBJ_STREAM) {
+ m_pAllocatedCMap = m_pCMap = FX_NEW CPDF_CMap;
+ CPDF_Stream* pStream = (CPDF_Stream*)pEncoding;
+ CPDF_StreamAcc acc;
+ acc.LoadAllData(pStream, FALSE);
+ m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
+ } else {
+ return FALSE;
+ }
+ if (m_pCMap == NULL) {
+ return FALSE;
+ }
+ m_Charset = m_pCMap->m_Charset;
+ if (m_Charset == CIDSET_UNKNOWN) {
+ CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDict(FX_BSTRC("CIDSystemInfo"));
+ if (pCIDInfo) {
+ m_Charset = _CharsetFromOrdering(pCIDInfo->GetString(FX_BSTRC("Ordering")));
+ }
+ }
+ if (m_Charset != CIDSET_UNKNOWN)
+ m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetCID2UnicodeMap(m_Charset,
+ m_pFontFile == NULL && (m_pCMap->m_Coding == CIDCODING_CID || pCIDFontDict->KeyExist(FX_BSTRC("W"))));
+ if (m_Font.GetFace()) {
+ if (m_bType1) {
+ FXFT_Select_Charmap(m_Font.GetFace(), FXFT_ENCODING_UNICODE);
+ } else {
+ FT_UseCIDCharmap(m_Font.GetFace(), m_pCMap->m_Coding);
+ }
+ }
+ m_DefaultWidth = pCIDFontDict->GetInteger(FX_BSTRC("DW"), 1000);
+ CPDF_Array* pWidthArray = pCIDFontDict->GetArray(FX_BSTRC("W"));
+ if (pWidthArray) {
+ LoadMetricsArray(pWidthArray, m_WidthList, 1);
+ }
+ if (!IsEmbedded()) {
+ LoadSubstFont();
+ }
+ if (1) {
+ if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) {
+ CPDF_Object* pmap = pCIDFontDict->GetElementValue(FX_BSTRC("CIDToGIDMap"));
+ if (pmap) {
+ if (pmap->GetType() == PDFOBJ_STREAM) {
+ m_pCIDToGIDMap = FX_NEW CPDF_StreamAcc;
+ m_pCIDToGIDMap->LoadAllData((CPDF_Stream*)pmap, FALSE);
+ } else if (pmap->GetString() == FX_BSTRC("Identity")) {
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ if (m_pFontFile) {
+ m_bCIDIsGID = TRUE;
+ }
+#else
+ m_bCIDIsGID = TRUE;
+#endif
+ }
+ }
+ }
+ }
+ CheckFontMetrics();
+ if (IsVertWriting()) {
+ pWidthArray = pCIDFontDict->GetArray(FX_BSTRC("W2"));
+ if (pWidthArray) {
+ LoadMetricsArray(pWidthArray, m_VertMetrics, 3);
+ }
+ CPDF_Array* pDefaultArray = pCIDFontDict->GetArray(FX_BSTRC("DW2"));
+ if (pDefaultArray) {
+ m_DefaultVY = pDefaultArray->GetInteger(0);
+ m_DefaultW1 = pDefaultArray->GetInteger(1);
+ } else {
+ m_DefaultVY = 880;
+ m_DefaultW1 = -1000;
+ }
+ }
+ return TRUE;
+}
+FX_FLOAT _CIDTransformToFloat(FX_BYTE ch)
+{
+ if (ch < 128) {
+ return ch * 1.0f / 127;
+ }
+ return (-255 + ch) * 1.0f / 127;
+}
+void CPDF_CIDFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level)
+{
+ if (charcode < 256 && m_CharBBox[charcode].Right != -1) {
+ rect.bottom = m_CharBBox[charcode].Bottom;
+ rect.left = m_CharBBox[charcode].Left;
+ rect.right = m_CharBBox[charcode].Right;
+ rect.top = m_CharBBox[charcode].Top;
+ return;
+ }
+ FX_BOOL bVert = FALSE;
+ int glyph_index = GlyphFromCharCode(charcode, &bVert);
+ if (m_Font.m_Face == NULL) {
+ rect = FX_RECT(0, 0, 0, 0);
+ } else {
+ rect.left = rect.bottom = rect.right = rect.top = 0;
+ FXFT_Face face = m_Font.m_Face;
+ if (FXFT_Is_Face_Tricky(face)) {
+ int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+ if (!err) {
+ FXFT_BBox cbox;
+ FXFT_Glyph glyph;
+ err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph);
+ if (!err) {
+ FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
+ int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem;
+ int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem;
+ if (pixel_size_x == 0 || pixel_size_y == 0) {
+ rect.left = cbox.xMin;
+ rect.right = cbox.xMax;
+ rect.top = cbox.yMax;
+ rect.bottom = cbox.yMin;
+ } else {
+ rect.left = cbox.xMin * 1000 / pixel_size_x;
+ rect.right = cbox.xMax * 1000 / pixel_size_x;
+ rect.top = cbox.yMax * 1000 / pixel_size_y;
+ rect.bottom = cbox.yMin * 1000 / pixel_size_y;
+ }
+ if (rect.top > FXFT_Get_Face_Ascender(face)) {
+ rect.top = FXFT_Get_Face_Ascender(face);
+ }
+ if (rect.bottom < FXFT_Get_Face_Descender(face)) {
+ rect.bottom = FXFT_Get_Face_Descender(face);
+ }
+ FXFT_Done_Glyph(glyph);
+ }
+ }
+ } else {
+ int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_SCALE);
+ if (err == 0) {
+ rect.left = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face);
+ rect.right = TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), face);
+ rect.top = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face);
+ rect.top += rect.top / 64;
+ rect.bottom = TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), face);
+ }
+ }
+ }
+ if (m_pFontFile == NULL && m_Charset == CIDSET_JAPAN1) {
+ FX_WORD CID = CIDFromCharCode(charcode);
+ FX_LPCBYTE pTransform = GetCIDTransform(CID);
+ if (pTransform && !bVert) {
+ CFX_AffineMatrix matrix(_CIDTransformToFloat(pTransform[0]), _CIDTransformToFloat(pTransform[1]),
+ _CIDTransformToFloat(pTransform[2]), _CIDTransformToFloat(pTransform[3]),
+ _CIDTransformToFloat(pTransform[4]) * 1000 , _CIDTransformToFloat(pTransform[5]) * 1000);
+ CFX_FloatRect rect_f(rect);
+ rect_f.Transform(&matrix);
+ rect = rect_f.GetOutterRect();
+ }
+ }
+ if (charcode < 256) {
+ m_CharBBox[charcode].Bottom = (short)rect.bottom;
+ m_CharBBox[charcode].Left = (short)rect.left;
+ m_CharBBox[charcode].Right = (short)rect.right;
+ m_CharBBox[charcode].Top = (short)rect.top;
+ }
+}
+int CPDF_CIDFont::GetCharWidthF(FX_DWORD charcode, int level)
+{
+ if (m_pAnsiWidths && charcode < 0x80) {
+ return m_pAnsiWidths[charcode];
+ }
+ FX_WORD cid = CIDFromCharCode(charcode);
+ int size = m_WidthList.GetSize();
+ FX_DWORD* list = m_WidthList.GetData();
+ for (int i = 0; i < size; i += 3) {
+ if (cid >= list[i] && cid <= list[i + 1]) {
+ return (int)list[i + 2];
+ }
+ }
+ return m_DefaultWidth;
+}
+short CPDF_CIDFont::GetVertWidth(FX_WORD CID) const
+{
+ FX_DWORD vertsize = m_VertMetrics.GetSize() / 5;
+ if (vertsize == 0) {
+ return m_DefaultW1;
+ }
+ const FX_DWORD* pTable = m_VertMetrics.GetData();
+ for (FX_DWORD i = 0; i < vertsize; i ++)
+ if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
+ return (short)(int)pTable[i * 5 + 2];
+ }
+ return m_DefaultW1;
+}
+void CPDF_CIDFont::GetVertOrigin(FX_WORD CID, short& vx, short &vy) const
+{
+ FX_DWORD vertsize = m_VertMetrics.GetSize() / 5;
+ if (vertsize) {
+ const FX_DWORD* pTable = m_VertMetrics.GetData();
+ for (FX_DWORD i = 0; i < vertsize; i ++)
+ if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
+ vx = (short)(int)pTable[i * 5 + 3];
+ vy = (short)(int)pTable[i * 5 + 4];
+ return;
+ }
+ }
+ FX_DWORD dwWidth = m_DefaultWidth;
+ int size = m_WidthList.GetSize();
+ const FX_DWORD* list = m_WidthList.GetData();
+ for (int i = 0; i < size; i += 3) {
+ if (CID >= list[i] && CID <= list[i + 1]) {
+ dwWidth = (FX_WORD)list[i + 2];
+ break;
+ }
+ }
+ vx = (short)dwWidth / 2;
+ vy = (short)m_DefaultVY;
+}
+int CPDF_CIDFont::GetGlyphIndex(FX_DWORD unicode, FX_BOOL *pVertGlyph)
+{
+ if (pVertGlyph) {
+ *pVertGlyph = FALSE;
+ }
+ int index = FXFT_Get_Char_Index(m_Font.m_Face, unicode );
+ if (unicode == 0x2502) {
+ return index;
+ }
+ if (index && IsVertWriting()) {
+ if (m_pTTGSUBTable) {
+ TT_uint32_t vindex = 0;
+ m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
+ if (vindex) {
+ index = vindex;
+ if (pVertGlyph) {
+ *pVertGlyph = TRUE;
+ }
+ }
+ return index;
+ }
+ if (NULL == m_Font.m_pGsubData) {
+ unsigned long length = 0;
+ int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length);
+ if (!error) {
+ m_Font.m_pGsubData = (unsigned char*)FX_Alloc(FX_BYTE, length);
+ }
+ }
+ int error = FXFT_Load_Sfnt_Table( m_Font.m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, m_Font.m_pGsubData, NULL);
+ if (!error && m_Font.m_pGsubData) {
+ m_pTTGSUBTable = FX_NEW CFX_CTTGSUBTable;
+ m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.m_pGsubData);
+ TT_uint32_t vindex = 0;
+ m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
+ if (vindex) {
+ index = vindex;
+ if (pVertGlyph) {
+ *pVertGlyph = TRUE;
+ }
+ }
+ }
+ return index;
+ }
+ if (pVertGlyph) {
+ *pVertGlyph = FALSE;
+ }
+ return index;
+}
+int CPDF_CIDFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph)
+{
+ if (pVertGlyph) {
+ *pVertGlyph = FALSE;
+ }
+ if (m_pFontFile == NULL && m_pCIDToGIDMap == NULL) {
+ FX_WORD cid = CIDFromCharCode(charcode);
+ FX_WCHAR unicode = 0;
+ if (m_bCIDIsGID) {
+#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
+ return cid;
+#else
+ if (m_Flags & PDFFONT_SYMBOLIC) {
+ return cid;
+ }
+ CFX_WideString uni_str = UnicodeFromCharCode(charcode);
+ if (uni_str.IsEmpty()) {
+ return cid;
+ }
+ unicode = uni_str.GetAt(0);
+#endif
+ } else {
+ if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded()) {
+ unicode = m_pCID2UnicodeMap->UnicodeFromCID(cid);
+ }
+ if (unicode == 0) {
+ unicode = _UnicodeFromCharCode(charcode);
+ }
+ if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) {
+ unicode = UnicodeFromCharCode(charcode).GetAt(0);
+ }
+ }
+ if (unicode == 0) {
+ if (!m_bAdobeCourierStd) {
+ return charcode == 0 ? -1 : (int)charcode;
+ }
+ charcode += 31;
+ int index = 0, iBaseEncoding;
+ FX_BOOL bMSUnicode = FT_UseTTCharmap(m_Font.m_Face, 3, 1);
+ FX_BOOL bMacRoman = FALSE;
+ if (!bMSUnicode) {
+ bMacRoman = FT_UseTTCharmap(m_Font.m_Face, 1, 0);
+ }
+ iBaseEncoding = PDFFONT_ENCODING_STANDARD;
+ if (bMSUnicode) {
+ iBaseEncoding = PDFFONT_ENCODING_WINANSI;
+ } else if (bMacRoman) {
+ iBaseEncoding = PDFFONT_ENCODING_MACROMAN;
+ }
+ FX_LPCSTR name = GetAdobeCharName(iBaseEncoding, NULL, charcode);
+ if (name == NULL) {
+ return charcode == 0 ? -1 : (int)charcode;
+ }
+ FX_WORD unicode = PDF_UnicodeFromAdobeName(name);
+ if (unicode) {
+ if (bMSUnicode) {
+ index = FXFT_Get_Char_Index(m_Font.m_Face, unicode);
+ } else if (bMacRoman) {
+ FX_DWORD maccode = FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, unicode);
+ index = !maccode ? FXFT_Get_Name_Index(m_Font.m_Face, (char *)name) : FXFT_Get_Char_Index(m_Font.m_Face, maccode);
+ } else {
+ return FXFT_Get_Char_Index(m_Font.m_Face, unicode);
+ }
+ } else {
+ return charcode == 0 ? -1 : (int)charcode;
+ }
+ if (index == 0 || index == 0xffff) {
+ return charcode == 0 ? -1 : (int)charcode;
+ } else {
+ return index;
+ }
+ }
+ if (m_Charset == CIDSET_JAPAN1) {
+ if (unicode == '\\') {
+ unicode = '/';
+ }
+#if !defined(_FPDFAPI_MINI_) && _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
+ else if (unicode == 0xa5) {
+ unicode = 0x5c;
+ }
+#endif
+ }
+ if (m_Font.m_Face == NULL) {
+ return unicode;
+ }
+ int err = FXFT_Select_Charmap(m_Font.m_Face, FXFT_ENCODING_UNICODE);
+ if (err != 0) {
+ int i;
+ for (i = 0; i < FXFT_Get_Face_CharmapCount(m_Font.m_Face); i ++) {
+ FX_DWORD ret = FT_CharCodeFromUnicode(FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]), (FX_WCHAR)charcode);
+ if (ret == 0) {
+ continue;
+ }
+ FXFT_Set_Charmap(m_Font.m_Face, FXFT_Get_Face_Charmaps(m_Font.m_Face)[i]);
+ unicode = (FX_WCHAR)ret;
+ break;
+ }
+ if (i == FXFT_Get_Face_CharmapCount(m_Font.m_Face) && i) {
+ FXFT_Set_Charmap(m_Font.m_Face, FXFT_Get_Face_Charmaps(m_Font.m_Face)[0]);
+ unicode = (FX_WCHAR)charcode;
+ }
+ }
+ if (FXFT_Get_Face_Charmap(m_Font.m_Face)) {
+ int index = GetGlyphIndex(unicode, pVertGlyph);
+ if (index == 0) {
+ return -1;
+ }
+ return index;
+ }
+ return unicode ;
+ }
+ if (m_Font.m_Face == NULL) {
+ return -1;
+ }
+ FX_WORD cid = CIDFromCharCode(charcode);
+ if (m_bType1) {
+ if (NULL == m_pCIDToGIDMap) {
+ return cid;
+ }
+ } else {
+ if (m_pCIDToGIDMap == NULL) {
+ if (m_pFontFile && m_pCMap->m_pMapping == NULL) {
+ return cid;
+ }
+ if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || FXFT_Get_Face_Charmap(m_Font.m_Face) == NULL) {
+ return cid;
+ }
+ if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.m_Face)) == FXFT_ENCODING_UNICODE) {
+ CFX_WideString unicode_str = UnicodeFromCharCode(charcode);
+ if (unicode_str.IsEmpty()) {
+ return -1;
+ }
+ charcode = unicode_str.GetAt(0);
+ }
+ return GetGlyphIndex(charcode, pVertGlyph);
+ }
+ }
+ FX_DWORD byte_pos = cid * 2;
+ if (byte_pos + 2 > m_pCIDToGIDMap->GetSize()) {
+ return -1;
+ }
+ FX_LPCBYTE pdata = m_pCIDToGIDMap->GetData() + byte_pos;
+ return pdata[0] * 256 + pdata[1];
+}
+FX_DWORD CPDF_CIDFont::GetNextChar(FX_LPCSTR pString, int& offset) const
+{
+ return m_pCMap->GetNextChar(pString, offset);
+}
+int CPDF_CIDFont::GetCharSize(FX_DWORD charcode) const
+{
+ return m_pCMap->GetCharSize(charcode);
+}
+int CPDF_CIDFont::CountChar(FX_LPCSTR pString, int size) const
+{
+ return m_pCMap->CountChar(pString, size);
+}
+int CPDF_CIDFont::AppendChar(FX_LPSTR str, FX_DWORD charcode) const
+{
+ return m_pCMap->AppendChar(str, charcode);
+}
+FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const
+{
+ if (!m_pCMap->IsLoaded() || m_pCID2UnicodeMap == NULL || !m_pCID2UnicodeMap->IsLoaded()) {
+ return m_pCMap->m_Coding != CIDCODING_UNKNOWN;
+ }
+ return TRUE;
+}
+FX_BOOL CPDF_CIDFont::IsFontStyleFromCharCode(FX_DWORD charcode) const
+{
+ return TRUE;
+}
+void CPDF_CIDFont::LoadSubstFont()
+{
+ m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, m_StemV * 5, m_ItalicAngle, g_CharsetCPs[m_Charset], IsVertWriting());
+}
+void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result, int nElements)
+{
+ int width_status = 0;
+ int iCurElement = 0;
+ int first_code = 0, last_code;
+ FX_DWORD count = pArray->GetCount();
+ for (FX_DWORD i = 0; i < count; i ++) {
+ CPDF_Object* pObj = pArray->GetElementValue(i);
+ if (pObj == NULL) {
+ continue;
+ }
+ if (pObj->GetType() == PDFOBJ_ARRAY) {
+ if (width_status != 1) {
+ return;
+ }
+ CPDF_Array* pArray = (CPDF_Array*)pObj;
+ FX_DWORD count = pArray->GetCount();
+ for (FX_DWORD j = 0; j < count; j += nElements) {
+ result.Add(first_code);
+ result.Add(first_code);
+ for (int k = 0; k < nElements; k ++) {
+ result.Add(pArray->GetInteger(j + k));
+ }
+ first_code ++;
+ }
+ width_status = 0;
+ } else {
+ if (width_status == 0) {
+ first_code = pObj->GetInteger();
+ width_status = 1;
+ } else if (width_status == 1) {
+ last_code = pObj->GetInteger();
+ width_status = 2;
+ iCurElement = 0;
+ } else {
+ if (!iCurElement) {
+ result.Add(first_code);
+ result.Add(last_code);
+ }
+ result.Add(pObj->GetInteger());
+ iCurElement ++;
+ if (iCurElement == nElements) {
+ width_status = 0;
+ }
+ }
+ }
+ }
+}
+FX_BOOL CPDF_CIDFont::LoadGB2312()
+{
+ m_BaseFont = m_pFontDict->GetString(FX_BSTRC("BaseFont"));
+ CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
+ if (pFontDesc) {
+ LoadFontDescriptor(pFontDesc);
+ }
+ m_Charset = CIDSET_GB1;
+ m_bType1 = FALSE;
+ m_pCMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetPredefinedCMap(
+ FX_BSTRC("GBK-EUC-H"), FALSE);
+ m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals()->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE);
+ if (!IsEmbedded()) {
+ LoadSubstFont();
+ }
+ CheckFontMetrics();
+ m_DefaultWidth = 1000;
+ m_pAnsiWidths = FX_Alloc(FX_WORD, 128);
+ FXSYS_memset32(m_pAnsiWidths, 0, 128 * sizeof(FX_WORD));
+ for (int i = 32; i < 127; i ++) {
+ m_pAnsiWidths[i] = 500;
+ }
+ return TRUE;
+}
+const struct _CIDTransform {
+ FX_WORD CID;
+ FX_BYTE a, b, c, d, e, f;
+}
+Japan1_VertCIDs[] = {
+ {97, 129, 0, 0, 127, 55, 0},
+ {7887, 127, 0, 0, 127, 76, 89},
+ {7888, 127, 0, 0, 127, 79, 94},
+ {7889, 0, 129, 127, 0, 17, 127},
+ {7890, 0, 129, 127, 0, 17, 127},
+ {7891, 0, 129, 127, 0, 17, 127},
+ {7892, 0, 129, 127, 0, 17, 127},
+ {7893, 0, 129, 127, 0, 17, 127},
+ {7894, 0, 129, 127, 0, 17, 127},
+ {7895, 0, 129, 127, 0, 17, 127},
+ {7896, 0, 129, 127, 0, 17, 127},
+ {7897, 0, 129, 127, 0, 17, 127},
+ {7898, 0, 129, 127, 0, 17, 127},
+ {7899, 0, 129, 127, 0, 17, 104},
+ {7900, 0, 129, 127, 0, 17, 127},
+ {7901, 0, 129, 127, 0, 17, 104},
+ {7902, 0, 129, 127, 0, 17, 127},
+ {7903, 0, 129, 127, 0, 17, 127},
+ {7904, 0, 129, 127, 0, 17, 127},
+ {7905, 0, 129, 127, 0, 17, 114},
+ {7906, 0, 129, 127, 0, 17, 127},
+ {7907, 0, 129, 127, 0, 17, 127},
+ {7908, 0, 129, 127, 0, 17, 127},
+ {7909, 0, 129, 127, 0, 17, 127},
+ {7910, 0, 129, 127, 0, 17, 127},
+ {7911, 0, 129, 127, 0, 17, 127},
+ {7912, 0, 129, 127, 0, 17, 127},
+ {7913, 0, 129, 127, 0, 17, 127},
+ {7914, 0, 129, 127, 0, 17, 127},
+ {7915, 0, 129, 127, 0, 17, 114},
+ {7916, 0, 129, 127, 0, 17, 127},
+ {7917, 0, 129, 127, 0, 17, 127},
+ {7918, 127, 0, 0, 127, 18, 25},
+ {7919, 127, 0, 0, 127, 18, 25},
+ {7920, 127, 0, 0, 127, 18, 25},
+ {7921, 127, 0, 0, 127, 18, 25},
+ {7922, 127, 0, 0, 127, 18, 25},
+ {7923, 127, 0, 0, 127, 18, 25},
+ {7924, 127, 0, 0, 127, 18, 25},
+ {7925, 127, 0, 0, 127, 18, 25},
+ {7926, 127, 0, 0, 127, 18, 25},
+ {7927, 127, 0, 0, 127, 18, 25},
+ {7928, 127, 0, 0, 127, 18, 25},
+ {7929, 127, 0, 0, 127, 18, 25},
+ {7930, 127, 0, 0, 127, 18, 25},
+ {7931, 127, 0, 0, 127, 18, 25},
+ {7932, 127, 0, 0, 127, 18, 25},
+ {7933, 127, 0, 0, 127, 18, 25},
+ {7934, 127, 0, 0, 127, 18, 25},
+ {7935, 127, 0, 0, 127, 18, 25},
+ {7936, 127, 0, 0, 127, 18, 25},
+ {7937, 127, 0, 0, 127, 18, 25},
+ {7938, 127, 0, 0, 127, 18, 25},
+ {7939, 127, 0, 0, 127, 18, 25},
+ {8720, 0, 129, 127, 0, 19, 102},
+ {8721, 0, 129, 127, 0, 13, 127},
+ {8722, 0, 129, 127, 0, 19, 108},
+ {8723, 0, 129, 127, 0, 19, 102},
+ {8724, 0, 129, 127, 0, 19, 102},
+ {8725, 0, 129, 127, 0, 19, 102},
+ {8726, 0, 129, 127, 0, 19, 102},
+ {8727, 0, 129, 127, 0, 19, 102},
+ {8728, 0, 129, 127, 0, 19, 114},
+ {8729, 0, 129, 127, 0, 19, 114},
+ {8730, 0, 129, 127, 0, 38, 108},
+ {8731, 0, 129, 127, 0, 13, 108},
+ {8732, 0, 129, 127, 0, 19, 108},
+ {8733, 0, 129, 127, 0, 19, 108},
+ {8734, 0, 129, 127, 0, 19, 108},
+ {8735, 0, 129, 127, 0, 19, 108},
+ {8736, 0, 129, 127, 0, 19, 102},
+ {8737, 0, 129, 127, 0, 19, 102},
+ {8738, 0, 129, 127, 0, 19, 102},
+ {8739, 0, 129, 127, 0, 19, 102},
+ {8740, 0, 129, 127, 0, 19, 102},
+ {8741, 0, 129, 127, 0, 19, 102},
+ {8742, 0, 129, 127, 0, 19, 102},
+ {8743, 0, 129, 127, 0, 19, 102},
+ {8744, 0, 129, 127, 0, 19, 102},
+ {8745, 0, 129, 127, 0, 19, 102},
+ {8746, 0, 129, 127, 0, 19, 114},
+ {8747, 0, 129, 127, 0, 19, 114},
+ {8748, 0, 129, 127, 0, 19, 102},
+ {8749, 0, 129, 127, 0, 19, 102},
+ {8750, 0, 129, 127, 0, 19, 102},
+ {8751, 0, 129, 127, 0, 19, 102},
+ {8752, 0, 129, 127, 0, 19, 102},
+ {8753, 0, 129, 127, 0, 19, 102},
+ {8754, 0, 129, 127, 0, 19, 102},
+ {8755, 0, 129, 127, 0, 19, 102},
+ {8756, 0, 129, 127, 0, 19, 102},
+ {8757, 0, 129, 127, 0, 19, 102},
+ {8758, 0, 129, 127, 0, 19, 102},
+ {8759, 0, 129, 127, 0, 19, 102},
+ {8760, 0, 129, 127, 0, 19, 102},
+ {8761, 0, 129, 127, 0, 19, 102},
+ {8762, 0, 129, 127, 0, 19, 102},
+ {8763, 0, 129, 127, 0, 19, 102},
+ {8764, 0, 129, 127, 0, 19, 102},
+ {8765, 0, 129, 127, 0, 19, 102},
+ {8766, 0, 129, 127, 0, 19, 102},
+ {8767, 0, 129, 127, 0, 19, 102},
+ {8768, 0, 129, 127, 0, 19, 102},
+ {8769, 0, 129, 127, 0, 19, 102},
+ {8770, 0, 129, 127, 0, 19, 102},
+ {8771, 0, 129, 127, 0, 19, 102},
+ {8772, 0, 129, 127, 0, 19, 102},
+ {8773, 0, 129, 127, 0, 19, 102},
+ {8774, 0, 129, 127, 0, 19, 102},
+ {8775, 0, 129, 127, 0, 19, 102},
+ {8776, 0, 129, 127, 0, 19, 102},
+ {8777, 0, 129, 127, 0, 19, 102},
+ {8778, 0, 129, 127, 0, 19, 102},
+ {8779, 0, 129, 127, 0, 19, 114},
+ {8780, 0, 129, 127, 0, 19, 108},
+ {8781, 0, 129, 127, 0, 19, 114},
+ {8782, 0, 129, 127, 0, 13, 114},
+ {8783, 0, 129, 127, 0, 19, 108},
+ {8784, 0, 129, 127, 0, 13, 114},
+ {8785, 0, 129, 127, 0, 19, 108},
+ {8786, 0, 129, 127, 0, 19, 108},
+ {8787, 0, 129, 127, 0, 19, 108},
+ {8788, 0, 129, 127, 0, 19, 108},
+ {8789, 0, 129, 127, 0, 19, 108},
+ {8790, 0, 129, 127, 0, 19, 108},
+ {8791, 0, 129, 127, 0, 19, 108},
+ {8792, 0, 129, 127, 0, 19, 108},
+ {8793, 0, 129, 127, 0, 19, 108},
+ {8794, 0, 129, 127, 0, 19, 108},
+ {8795, 0, 129, 127, 0, 19, 108},
+ {8796, 0, 129, 127, 0, 19, 108},
+ {8797, 0, 129, 127, 0, 19, 108},
+ {8798, 0, 129, 127, 0, 19, 108},
+ {8799, 0, 129, 127, 0, 19, 108},
+ {8800, 0, 129, 127, 0, 19, 108},
+ {8801, 0, 129, 127, 0, 19, 108},
+ {8802, 0, 129, 127, 0, 19, 108},
+ {8803, 0, 129, 127, 0, 19, 108},
+ {8804, 0, 129, 127, 0, 19, 108},
+ {8805, 0, 129, 127, 0, 19, 108},
+ {8806, 0, 129, 127, 0, 19, 108},
+ {8807, 0, 129, 127, 0, 19, 108},
+ {8808, 0, 129, 127, 0, 19, 108},
+ {8809, 0, 129, 127, 0, 19, 108},
+ {8810, 0, 129, 127, 0, 19, 108},
+ {8811, 0, 129, 127, 0, 19, 114},
+ {8812, 0, 129, 127, 0, 19, 102},
+ {8813, 0, 129, 127, 0, 19, 114},
+ {8814, 0, 129, 127, 0, 76, 102},
+ {8815, 0, 129, 127, 0, 13, 121},
+ {8816, 0, 129, 127, 0, 19, 114},
+ {8817, 0, 129, 127, 0, 19, 127},
+ {8818, 0, 129, 127, 0, 19, 114},
+ {8819, 0, 129, 127, 0, 218, 108},
+};
+FX_LPCBYTE CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const
+{
+ if (m_Charset != CIDSET_JAPAN1 || m_pFontFile != NULL) {
+ return NULL;
+ }
+ int begin = 0;
+ int end = sizeof Japan1_VertCIDs / sizeof(struct _CIDTransform) - 1;
+ while (begin <= end) {
+ int middle = (begin + end) / 2;
+ FX_WORD middlecode = Japan1_VertCIDs[middle].CID;
+ if (middlecode > CID) {
+ end = middle - 1;
+ } else if (middlecode < CID) {
+ begin = middle + 1;
+ } else {
+ return &Japan1_VertCIDs[middle].a;
+ }
+ }
+ return NULL;
+}
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp
index 7810fe80a9..b10bff7ebe 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_utility.cpp
@@ -1,97 +1,97 @@
-// 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
-
-#include "../../../include/fpdfapi/fpdf_module.h"
-#include "../../../include/fpdfapi/fpdf_resource.h"
-#include "../../../include/fxcodec/fx_codec.h"
-#include "font_int.h"
-#ifndef _FPDFAPI_MINI_
-typedef struct {
- FXSYS_FILE* m_pFile;
- int m_nFiles;
- int m_IndexSize;
- int m_IndexOffset;
-} FXFC_PACKAGE;
-FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name)
-{
- FXSYS_FILE* file = FXSYS_fopen(name, (FX_LPCSTR)"rb");
- if (file == NULL) {
- return NULL;
- }
- FX_BYTE buf[256];
- size_t read = FXSYS_fread(buf, 1, 20, file);
- if (*(FX_DWORD*)buf != 0x43465846) {
- FXSYS_fclose(file);
- return NULL;
- }
- FXFC_PACKAGE* pPackage = FX_Alloc(FXFC_PACKAGE, 1);
- pPackage->m_pFile = file;
- pPackage->m_nFiles = *(int*)(buf + 8);
- pPackage->m_IndexSize = *(int*)(buf + 12);
- pPackage->m_IndexOffset = *(int*)(buf + 16);
- return pPackage;
-}
-void FXFC_ClosePackage(FX_LPVOID p)
-{
- FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p;
- FXSYS_fclose(pPackage->m_pFile);
- FX_Free(pPackage);
-}
-FX_BOOL FXFC_LoadFile(FX_LPVOID p, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD& size)
-{
- FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p;
- FXSYS_fseek(pPackage->m_pFile, pPackage->m_IndexOffset, FXSYS_SEEK_SET);
- FX_BYTE buf[128];
- size_t read = 0;
- for (int i = 0; i < pPackage->m_nFiles; i ++) {
- read = FXSYS_fread(buf, pPackage->m_IndexSize, 1, pPackage->m_pFile);
- if (FXSYS_stricmp((FX_LPCSTR)buf, name) == 0) {
- FX_DWORD offset = *(FX_DWORD*)&buf[64];
- size = *(FX_DWORD*)&buf[68];
- pBuffer = FX_Alloc(FX_BYTE, size);
- FXSYS_fseek(pPackage->m_pFile, offset, FXSYS_SEEK_SET);
- read = FXSYS_fread(pBuffer, size, 1, pPackage->m_pFile);
- if (buf[72]) {
- FX_DWORD orig_size;
- FX_LPBYTE comp_buf = pBuffer;
- CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(FALSE, comp_buf, size, FALSE,
- 0, 0, 0, 0, 0, pBuffer, orig_size);
- FX_Free(comp_buf);
- size = orig_size;
- }
- return TRUE;
- }
- }
- return FALSE;
-}
-FX_BOOL CPDF_FXMP::LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid)
-{
- if (m_pHeader) {
- FX_Free(m_pHeader);
- m_pHeader = NULL;
- }
- m_pTable = NULL;
- FX_DWORD size;
- if (!FXFC_LoadFile(pPackage, fileid, (FX_LPBYTE&)m_pHeader, size)) {
- return FALSE;
- }
- if (FXSYS_memcmp32(m_pHeader, "FXMP", 4)) {
- return FALSE;
- }
- m_pTable = (FX_LPBYTE)m_pHeader + m_pHeader->dwDataOffset;
- return TRUE;
-}
-FX_LPBYTE CPDF_FXMP::GetRecord(FX_DWORD index)
-{
- if (m_pTable == NULL) {
- return NULL;
- }
- if ((int)index < (int)m_pHeader->dwStartIndex || index > m_pHeader->dwEndIndex) {
- return NULL;
- }
- return m_pTable + (index - m_pHeader->dwStartIndex) * m_pHeader->dwRecordSize;
-}
-#endif
+// 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
+
+#include "../../../include/fpdfapi/fpdf_module.h"
+#include "../../../include/fpdfapi/fpdf_resource.h"
+#include "../../../include/fxcodec/fx_codec.h"
+#include "font_int.h"
+#ifndef _FPDFAPI_MINI_
+typedef struct {
+ FXSYS_FILE* m_pFile;
+ int m_nFiles;
+ int m_IndexSize;
+ int m_IndexOffset;
+} FXFC_PACKAGE;
+FX_LPVOID FXFC_LoadPackage(FX_LPCSTR name)
+{
+ FXSYS_FILE* file = FXSYS_fopen(name, (FX_LPCSTR)"rb");
+ if (file == NULL) {
+ return NULL;
+ }
+ FX_BYTE buf[256];
+ size_t read = FXSYS_fread(buf, 1, 20, file);
+ if (*(FX_DWORD*)buf != 0x43465846) {
+ FXSYS_fclose(file);
+ return NULL;
+ }
+ FXFC_PACKAGE* pPackage = FX_Alloc(FXFC_PACKAGE, 1);
+ pPackage->m_pFile = file;
+ pPackage->m_nFiles = *(int*)(buf + 8);
+ pPackage->m_IndexSize = *(int*)(buf + 12);
+ pPackage->m_IndexOffset = *(int*)(buf + 16);
+ return pPackage;
+}
+void FXFC_ClosePackage(FX_LPVOID p)
+{
+ FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p;
+ FXSYS_fclose(pPackage->m_pFile);
+ FX_Free(pPackage);
+}
+FX_BOOL FXFC_LoadFile(FX_LPVOID p, FX_LPCSTR name, FX_LPBYTE& pBuffer, FX_DWORD& size)
+{
+ FXFC_PACKAGE* pPackage = (FXFC_PACKAGE*)p;
+ FXSYS_fseek(pPackage->m_pFile, pPackage->m_IndexOffset, FXSYS_SEEK_SET);
+ FX_BYTE buf[128];
+ size_t read = 0;
+ for (int i = 0; i < pPackage->m_nFiles; i ++) {
+ read = FXSYS_fread(buf, pPackage->m_IndexSize, 1, pPackage->m_pFile);
+ if (FXSYS_stricmp((FX_LPCSTR)buf, name) == 0) {
+ FX_DWORD offset = *(FX_DWORD*)&buf[64];
+ size = *(FX_DWORD*)&buf[68];
+ pBuffer = FX_Alloc(FX_BYTE, size);
+ FXSYS_fseek(pPackage->m_pFile, offset, FXSYS_SEEK_SET);
+ read = FXSYS_fread(pBuffer, size, 1, pPackage->m_pFile);
+ if (buf[72]) {
+ FX_DWORD orig_size;
+ FX_LPBYTE comp_buf = pBuffer;
+ CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode(FALSE, comp_buf, size, FALSE,
+ 0, 0, 0, 0, 0, pBuffer, orig_size);
+ FX_Free(comp_buf);
+ size = orig_size;
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+FX_BOOL CPDF_FXMP::LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid)
+{
+ if (m_pHeader) {
+ FX_Free(m_pHeader);
+ m_pHeader = NULL;
+ }
+ m_pTable = NULL;
+ FX_DWORD size;
+ if (!FXFC_LoadFile(pPackage, fileid, (FX_LPBYTE&)m_pHeader, size)) {
+ return FALSE;
+ }
+ if (FXSYS_memcmp32(m_pHeader, "FXMP", 4)) {
+ return FALSE;
+ }
+ m_pTable = (FX_LPBYTE)m_pHeader + m_pHeader->dwDataOffset;
+ return TRUE;
+}
+FX_LPBYTE CPDF_FXMP::GetRecord(FX_DWORD index)
+{
+ if (m_pTable == NULL) {
+ return NULL;
+ }
+ if ((int)index < (int)m_pHeader->dwStartIndex || index > m_pHeader->dwEndIndex) {
+ return NULL;
+ }
+ return m_pTable + (index - m_pHeader->dwStartIndex) * m_pHeader->dwRecordSize;
+}
+#endif
diff --git a/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp b/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp
index b7a7864c2d..42f77de57b 100644
--- a/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp
+++ b/core/src/fpdfapi/fpdf_font/ttgsubtable.cpp
@@ -1,452 +1,452 @@
-// 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
-
-#include "../../../include/fxge/fx_ge.h"
-#include "../../../include/fxge/fx_freetype.h"
-#include "ttgsubtable.h"
-CFX_GlyphMap::CFX_GlyphMap()
-{
-}
-CFX_GlyphMap::~CFX_GlyphMap()
-{
-}
-extern "C" {
- static int _CompareInt(const void* p1, const void* p2)
- {
- return (*(FX_DWORD*)p1) - (*(FX_DWORD*)p2);
- }
-};
-struct _IntPair {
- FX_INT32 key;
- FX_INT32 value;
-};
-void CFX_GlyphMap::SetAt(int key, int value)
-{
- FX_DWORD count = m_Buffer.GetSize() / sizeof(_IntPair);
- _IntPair* buf = (_IntPair*)m_Buffer.GetBuffer();
- _IntPair pair = {key, value};
- if (count == 0 || key > buf[count - 1].key) {
- m_Buffer.AppendBlock(&pair, sizeof(_IntPair));
- return;
- }
- int low = 0, high = count - 1;
- while (low <= high) {
- int mid = (low + high) / 2;
- if (buf[mid].key < key) {
- low = mid + 1;
- } else if (buf[mid].key > key) {
- high = mid - 1;
- } else {
- buf[mid].value = value;
- return;
- }
- }
- m_Buffer.InsertBlock(low * sizeof(_IntPair), &pair, sizeof(_IntPair));
-}
-FX_BOOL CFX_GlyphMap::Lookup(int key, int &value)
-{
- FX_LPVOID pResult = FXSYS_bsearch(&key, m_Buffer.GetBuffer(), m_Buffer.GetSize() / sizeof(_IntPair),
- sizeof(_IntPair), _CompareInt);
- if (pResult == NULL) {
- return FALSE;
- }
- value = ((FX_DWORD*)pResult)[1];
- return TRUE;
-}
-bool CFX_CTTGSUBTable::LoadGSUBTable(FT_Bytes gsub)
-{
- header.Version = gsub[0] << 24 | gsub[1] << 16 | gsub[2] << 8 | gsub[3];
- if(header.Version != 0x00010000) {
- return false;
- }
- header.ScriptList = gsub[4] << 8 | gsub[5];
- header.FeatureList = gsub[6] << 8 | gsub[7];
- header.LookupList = gsub[8] << 8 | gsub[9];
- return Parse(
- &gsub[header.ScriptList],
- &gsub[header.FeatureList],
- &gsub[header.LookupList]);
-}
-bool CFX_CTTGSUBTable::GetVerticalGlyph(TT_uint32_t glyphnum, TT_uint32_t *vglyphnum)
-{
- TT_uint32_t tag[] = {
- (TT_uint8_t)'v' << 24 |
- (TT_uint8_t)'r' << 16 |
- (TT_uint8_t)'t' << 8 |
- (TT_uint8_t)'2',
- (TT_uint8_t)'v' << 24 |
- (TT_uint8_t)'e' << 16 |
- (TT_uint8_t)'r' << 8 |
- (TT_uint8_t)'t',
- };
- if (!m_bFeautureMapLoad) {
- for (int i = 0; i < ScriptList.ScriptCount; i++) {
- for (int j = 0; j < (ScriptList.ScriptRecord + i)->Script.LangSysCount; ++j) {
- for (int k = 0; k < ((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j)->LangSys.FeatureCount; ++k) {
- FX_DWORD index = *(((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j)->LangSys.FeatureIndex + k);
- if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] || FeatureList.FeatureRecord[index].FeatureTag == tag[1]) {
- FX_DWORD value;
- if (!m_featureMap.Lookup(index, value)) {
- m_featureMap.SetAt(index, index);
- }
- }
- }
- }
- }
- if (!m_featureMap.GetStartPosition()) {
- for (int i = 0; i < FeatureList.FeatureCount; i ++) {
- if (FeatureList.FeatureRecord[i].FeatureTag == tag[0] || FeatureList.FeatureRecord[i].FeatureTag == tag[1]) {
- FX_DWORD value;
- if (!m_featureMap.Lookup(i, value)) {
- m_featureMap.SetAt(i, i);
- }
- }
- }
- }
- m_bFeautureMapLoad = TRUE;
- }
- FX_POSITION pos = m_featureMap.GetStartPosition();
- while (pos) {
- FX_DWORD index, value;
- m_featureMap.GetNextAssoc(pos, index, value);
- if(GetVerticalGlyphSub(glyphnum, vglyphnum, &FeatureList.FeatureRecord[value].Feature)) {
- return true;
- }
- }
- return false;
-}
-bool CFX_CTTGSUBTable::GetVerticalGlyphSub(
- TT_uint32_t glyphnum,
- TT_uint32_t *vglyphnum,
- struct TFeature *Feature)
-{
- for(int i = 0; i < Feature->LookupCount; i++) {
- int index = Feature->LookupListIndex[i];
- if(index < 0 || LookupList.LookupCount < index) {
- continue;
- }
- if(LookupList.Lookup[index].LookupType == 1) {
- if(GetVerticalGlyphSub2(
- glyphnum,
- vglyphnum,
- &LookupList.Lookup[index])) {
- return true;
- }
- }
- }
- return false;
-}
-bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(
- TT_uint32_t glyphnum,
- TT_uint32_t *vglyphnum,
- struct TLookup *Lookup)
-{
- for(int i = 0; i < Lookup->SubTableCount; i++) {
- switch(Lookup->SubTable[i]->SubstFormat) {
- case 1: {
- TSingleSubstFormat1 *tbl1 = (TSingleSubstFormat1*)Lookup->SubTable[i];
- if(GetCoverageIndex(tbl1->Coverage, glyphnum) >= 0) {
- *vglyphnum = glyphnum + tbl1->DeltaGlyphID;
- return true;
- }
- break;
- }
- case 2: {
- TSingleSubstFormat2 *tbl2 = (TSingleSubstFormat2*)Lookup->SubTable[i];
- int index = -1;
- index = GetCoverageIndex(tbl2->Coverage, glyphnum);
- if(0 <= index && index < tbl2->GlyphCount) {
- *vglyphnum = tbl2->Substitute[index];
- return true;
- }
- break;
- }
- }
- }
- return false;
-}
-int CFX_CTTGSUBTable::GetCoverageIndex(struct TCoverageFormatBase *Coverage, TT_uint32_t g)
-{
- int i = 0;
- if(Coverage == NULL) {
- return -1;
- }
- switch(Coverage->CoverageFormat) {
- case 1: {
- TCoverageFormat1 *c1 = (TCoverageFormat1*)Coverage;
- for(i = 0; i < c1->GlyphCount; i++) {
- if((TT_uint32_t)c1->GlyphArray[i] == g) {
- return i;
- }
- }
- return -1;
- }
- case 2: {
- TCoverageFormat2 *c2 = (TCoverageFormat2*)Coverage;
- for(i = 0; i < c2->RangeCount; i++) {
- TT_uint32_t s = c2->RangeRecord[i].Start;
- TT_uint32_t e = c2->RangeRecord[i].End;
- TT_uint32_t si = c2->RangeRecord[i].StartCoverageIndex;
- if (s <= g && g <= e) {
- return si + g - s;
- }
- }
- return -1;
- }
- }
- return -1;
-}
-bool CFX_CTTGSUBTable::Parse(
- FT_Bytes scriptlist,
- FT_Bytes featurelist,
- FT_Bytes lookuplist)
-{
- ParseScriptList(scriptlist, &ScriptList);
- ParseFeatureList(featurelist, &FeatureList);
- ParseLookupList(lookuplist, &LookupList);
- return true;
-}
-void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList *rec)
-{
- int i;
- FT_Bytes sp = raw;
- rec->ScriptCount = GetUInt16(sp);
- if(rec->ScriptCount <= 0) {
- return;
- }
- rec->ScriptRecord = new struct TScriptRecord[rec->ScriptCount];
- for(i = 0; i < rec->ScriptCount; i++) {
- rec->ScriptRecord[i].ScriptTag = GetUInt32(sp);
- TT_uint16_t offset = GetUInt16(sp);
- ParseScript(
- &raw[offset],
- &rec->ScriptRecord[i].Script);
- }
-}
-void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript *rec)
-{
- int i;
- FT_Bytes sp = raw;
- rec->DefaultLangSys = GetUInt16(sp);
- rec->LangSysCount = GetUInt16(sp);
- if(rec->LangSysCount <= 0) {
- return;
- }
- rec->LangSysRecord = new struct TLangSysRecord[rec->LangSysCount];
- for(i = 0; i < rec->LangSysCount; i++) {
- rec->LangSysRecord[i].LangSysTag = GetUInt32(sp);
- TT_uint16_t offset = GetUInt16(sp);
- ParseLangSys(
- &raw[offset],
- &rec->LangSysRecord[i].LangSys);
- }
-}
-void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, struct TLangSys *rec)
-{
- FT_Bytes sp = raw;
- rec->LookupOrder = GetUInt16(sp);
- rec->ReqFeatureIndex = GetUInt16(sp);
- rec->FeatureCount = GetUInt16(sp);
- if(rec->FeatureCount <= 0) {
- return;
- }
- rec->FeatureIndex = new TT_uint16_t[rec->FeatureCount];
- FXSYS_memset32(rec->FeatureIndex, 0, sizeof(TT_uint16_t) * rec->FeatureCount);
- for (int i = 0; i < rec->FeatureCount; ++i) {
- rec->FeatureIndex[i] = GetUInt16(sp);
- }
-}
-void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList *rec)
-{
- int i;
- FT_Bytes sp = raw;
- rec->FeatureCount = GetUInt16(sp);
- if(rec->FeatureCount <= 0) {
- return;
- }
- rec->FeatureRecord = new struct TFeatureRecord[rec->FeatureCount];
- for(i = 0; i < rec->FeatureCount; i++) {
- rec->FeatureRecord[i].FeatureTag = GetUInt32(sp);
- TT_uint16_t offset = GetUInt16(sp);
- ParseFeature(
- &raw[offset],
- &rec->FeatureRecord[i].Feature);
- }
-}
-void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature *rec)
-{
- int i;
- FT_Bytes sp = raw;
- rec->FeatureParams = GetUInt16(sp);
- rec->LookupCount = GetUInt16(sp);
- if(rec->LookupCount <= 0) {
- return;
- }
- rec->LookupListIndex = new TT_uint16_t[rec->LookupCount];
- for(i = 0; i < rec->LookupCount; i++) {
- rec->LookupListIndex[i] = GetUInt16(sp);
- }
-}
-void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList *rec)
-{
- int i;
- FT_Bytes sp = raw;
- rec->LookupCount = GetUInt16(sp);
- if(rec->LookupCount <= 0) {
- return;
- }
- rec->Lookup = new struct TLookup[rec->LookupCount];
- for(i = 0; i < rec->LookupCount; i++) {
- TT_uint16_t offset = GetUInt16(sp);
- ParseLookup(
- &raw[offset],
- &rec->Lookup[i]);
- }
-}
-void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup *rec)
-{
- int i;
- FT_Bytes sp = raw;
- rec->LookupType = GetUInt16(sp);
- rec->LookupFlag = GetUInt16(sp);
- rec->SubTableCount = GetUInt16(sp);
- if(rec->SubTableCount <= 0) {
- return;
- }
- rec->SubTable = new struct TSubTableBase*[rec->SubTableCount];
- for(i = 0; i < rec->SubTableCount; i++) {
- rec->SubTable[i] = NULL;
- }
- if(rec->LookupType != 1) {
- return;
- }
- for(i = 0; i < rec->SubTableCount; i++) {
- TT_uint16_t offset = GetUInt16(sp);
- ParseSingleSubst(
- &raw[offset],
- &rec->SubTable[i]);
- }
-}
-void CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw, TCoverageFormatBase **rec)
-{
- FT_Bytes sp = raw;
- TT_uint16_t Format = GetUInt16(sp);
- switch(Format) {
- case 1:
- *rec = new TCoverageFormat1();
- ParseCoverageFormat1(raw, (TCoverageFormat1*)*rec);
- break;
- case 2:
- *rec = new TCoverageFormat2();
- ParseCoverageFormat2(raw, (TCoverageFormat2*)*rec);
- break;
- }
-}
-void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1 *rec)
-{
- int i;
- FT_Bytes sp = raw;
- GetUInt16(sp);
- rec->GlyphCount = GetUInt16(sp);
- if(rec->GlyphCount <= 0) {
- return;
- }
- rec->GlyphArray = new TT_uint16_t[rec->GlyphCount];
- for(i = 0; i < rec->GlyphCount; i++) {
- rec->GlyphArray[i] = GetUInt16(sp);
- }
-}
-void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2 *rec)
-{
- int i;
- FT_Bytes sp = raw;
- GetUInt16(sp);
- rec->RangeCount = GetUInt16(sp);
- if(rec->RangeCount <= 0) {
- return;
- }
- rec->RangeRecord = new TRangeRecord[rec->RangeCount];
- for(i = 0; i < rec->RangeCount; i++) {
- rec->RangeRecord[i].Start = GetUInt16(sp);
- rec->RangeRecord[i].End = GetUInt16(sp);
- rec->RangeRecord[i].StartCoverageIndex = GetUInt16(sp);
- }
-}
-void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw, TSubTableBase **rec)
-{
- FT_Bytes sp = raw;
- TT_uint16_t Format = GetUInt16(sp);
- switch(Format) {
- case 1:
- *rec = new TSingleSubstFormat1();
- ParseSingleSubstFormat1(raw, (TSingleSubstFormat1*)*rec);
- break;
- case 2:
- *rec = new TSingleSubstFormat2();
- ParseSingleSubstFormat2(raw, (TSingleSubstFormat2*)*rec);
- break;
- }
-}
-void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw, TSingleSubstFormat1 *rec)
-{
- FT_Bytes sp = raw;
- GetUInt16(sp);
- TT_uint16_t offset = GetUInt16(sp);
- ParseCoverage(
- &raw[offset],
- &rec->Coverage);
- rec->DeltaGlyphID = GetInt16(sp);
-}
-void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw, TSingleSubstFormat2 *rec)
-{
- int i;
- FT_Bytes sp = raw;
- GetUInt16(sp);
- TT_uint16_t offset = GetUInt16(sp);
- ParseCoverage(
- &raw[offset],
- &rec->Coverage);
- rec->GlyphCount = GetUInt16(sp);
- if(rec->GlyphCount <= 0) {
- return;
- }
- rec->Substitute = new TT_uint16_t[rec->GlyphCount];
- for(i = 0; i < rec->GlyphCount; i++) {
- rec->Substitute[i] = GetUInt16(sp);
- }
-}
-FX_BOOL CFX_GSUBTable::GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum)
-{
- return m_GsubImp.GetVerticalGlyph(glyphnum, vglyphnum);
-}
-IFX_GSUBTable* FXGE_CreateGSUBTable(CFX_Font* pFont)
-{
- if (!pFont) {
- return NULL;
- }
- if (NULL == pFont->m_pGsubData) {
- unsigned long length = 0;
- int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length);
- if (!error) {
- pFont->m_pGsubData = (unsigned char*)FX_Alloc(FX_BYTE, length);
- }
- if (!pFont->m_pGsubData) {
- return NULL;
- }
- }
- int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, pFont->m_pGsubData, NULL);
- if (!error && pFont->m_pGsubData) {
- CFX_GSUBTable* pGsubTable = FX_NEW CFX_GSUBTable;
- if (!pGsubTable) {
- return NULL;
- }
- if (pGsubTable->m_GsubImp.LoadGSUBTable((FT_Bytes)pFont->m_pGsubData)) {
- return pGsubTable;
- }
- delete pGsubTable;
- }
- return NULL;
-}
+// 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
+
+#include "../../../include/fxge/fx_ge.h"
+#include "../../../include/fxge/fx_freetype.h"
+#include "ttgsubtable.h"
+CFX_GlyphMap::CFX_GlyphMap()
+{
+}
+CFX_GlyphMap::~CFX_GlyphMap()
+{
+}
+extern "C" {
+ static int _CompareInt(const void* p1, const void* p2)
+ {
+ return (*(FX_DWORD*)p1) - (*(FX_DWORD*)p2);
+ }
+};
+struct _IntPair {
+ FX_INT32 key;
+ FX_INT32 value;
+};
+void CFX_GlyphMap::SetAt(int key, int value)
+{
+ FX_DWORD count = m_Buffer.GetSize() / sizeof(_IntPair);
+ _IntPair* buf = (_IntPair*)m_Buffer.GetBuffer();
+ _IntPair pair = {key, value};
+ if (count == 0 || key > buf[count - 1].key) {
+ m_Buffer.AppendBlock(&pair, sizeof(_IntPair));
+ return;
+ }
+ int low = 0, high = count - 1;
+ while (low <= high) {
+ int mid = (low + high) / 2;
+ if (buf[mid].key < key) {
+ low = mid + 1;
+ } else if (buf[mid].key > key) {
+ high = mid - 1;
+ } else {
+ buf[mid].value = value;
+ return;
+ }
+ }
+ m_Buffer.InsertBlock(low * sizeof(_IntPair), &pair, sizeof(_IntPair));
+}
+FX_BOOL CFX_GlyphMap::Lookup(int key, int &value)
+{
+ FX_LPVOID pResult = FXSYS_bsearch(&key, m_Buffer.GetBuffer(), m_Buffer.GetSize() / sizeof(_IntPair),
+ sizeof(_IntPair), _CompareInt);
+ if (pResult == NULL) {
+ return FALSE;
+ }
+ value = ((FX_DWORD*)pResult)[1];
+ return TRUE;
+}
+bool CFX_CTTGSUBTable::LoadGSUBTable(FT_Bytes gsub)
+{
+ header.Version = gsub[0] << 24 | gsub[1] << 16 | gsub[2] << 8 | gsub[3];
+ if(header.Version != 0x00010000) {
+ return false;
+ }
+ header.ScriptList = gsub[4] << 8 | gsub[5];
+ header.FeatureList = gsub[6] << 8 | gsub[7];
+ header.LookupList = gsub[8] << 8 | gsub[9];
+ return Parse(
+ &gsub[header.ScriptList],
+ &gsub[header.FeatureList],
+ &gsub[header.LookupList]);
+}
+bool CFX_CTTGSUBTable::GetVerticalGlyph(TT_uint32_t glyphnum, TT_uint32_t *vglyphnum)
+{
+ TT_uint32_t tag[] = {
+ (TT_uint8_t)'v' << 24 |
+ (TT_uint8_t)'r' << 16 |
+ (TT_uint8_t)'t' << 8 |
+ (TT_uint8_t)'2',
+ (TT_uint8_t)'v' << 24 |
+ (TT_uint8_t)'e' << 16 |
+ (TT_uint8_t)'r' << 8 |
+ (TT_uint8_t)'t',
+ };
+ if (!m_bFeautureMapLoad) {
+ for (int i = 0; i < ScriptList.ScriptCount; i++) {
+ for (int j = 0; j < (ScriptList.ScriptRecord + i)->Script.LangSysCount; ++j) {
+ for (int k = 0; k < ((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j)->LangSys.FeatureCount; ++k) {
+ FX_DWORD index = *(((ScriptList.ScriptRecord + i)->Script.LangSysRecord + j)->LangSys.FeatureIndex + k);
+ if (FeatureList.FeatureRecord[index].FeatureTag == tag[0] || FeatureList.FeatureRecord[index].FeatureTag == tag[1]) {
+ FX_DWORD value;
+ if (!m_featureMap.Lookup(index, value)) {
+ m_featureMap.SetAt(index, index);
+ }
+ }
+ }
+ }
+ }
+ if (!m_featureMap.GetStartPosition()) {
+ for (int i = 0; i < FeatureList.FeatureCount; i ++) {
+ if (FeatureList.FeatureRecord[i].FeatureTag == tag[0] || FeatureList.FeatureRecord[i].FeatureTag == tag[1]) {
+ FX_DWORD value;
+ if (!m_featureMap.Lookup(i, value)) {
+ m_featureMap.SetAt(i, i);
+ }
+ }
+ }
+ }
+ m_bFeautureMapLoad = TRUE;
+ }
+ FX_POSITION pos = m_featureMap.GetStartPosition();
+ while (pos) {
+ FX_DWORD index, value;
+ m_featureMap.GetNextAssoc(pos, index, value);
+ if(GetVerticalGlyphSub(glyphnum, vglyphnum, &FeatureList.FeatureRecord[value].Feature)) {
+ return true;
+ }
+ }
+ return false;
+}
+bool CFX_CTTGSUBTable::GetVerticalGlyphSub(
+ TT_uint32_t glyphnum,
+ TT_uint32_t *vglyphnum,
+ struct TFeature *Feature)
+{
+ for(int i = 0; i < Feature->LookupCount; i++) {
+ int index = Feature->LookupListIndex[i];
+ if(index < 0 || LookupList.LookupCount < index) {
+ continue;
+ }
+ if(LookupList.Lookup[index].LookupType == 1) {
+ if(GetVerticalGlyphSub2(
+ glyphnum,
+ vglyphnum,
+ &LookupList.Lookup[index])) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(
+ TT_uint32_t glyphnum,
+ TT_uint32_t *vglyphnum,
+ struct TLookup *Lookup)
+{
+ for(int i = 0; i < Lookup->SubTableCount; i++) {
+ switch(Lookup->SubTable[i]->SubstFormat) {
+ case 1: {
+ TSingleSubstFormat1 *tbl1 = (TSingleSubstFormat1*)Lookup->SubTable[i];
+ if(GetCoverageIndex(tbl1->Coverage, glyphnum) >= 0) {
+ *vglyphnum = glyphnum + tbl1->DeltaGlyphID;
+ return true;
+ }
+ break;
+ }
+ case 2: {
+ TSingleSubstFormat2 *tbl2 = (TSingleSubstFormat2*)Lookup->SubTable[i];
+ int index = -1;
+ index = GetCoverageIndex(tbl2->Coverage, glyphnum);
+ if(0 <= index && index < tbl2->GlyphCount) {
+ *vglyphnum = tbl2->Substitute[index];
+ return true;
+ }
+ break;
+ }
+ }
+ }
+ return false;
+}
+int CFX_CTTGSUBTable::GetCoverageIndex(struct TCoverageFormatBase *Coverage, TT_uint32_t g)
+{
+ int i = 0;
+ if(Coverage == NULL) {
+ return -1;
+ }
+ switch(Coverage->CoverageFormat) {
+ case 1: {
+ TCoverageFormat1 *c1 = (TCoverageFormat1*)Coverage;
+ for(i = 0; i < c1->GlyphCount; i++) {
+ if((TT_uint32_t)c1->GlyphArray[i] == g) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ case 2: {
+ TCoverageFormat2 *c2 = (TCoverageFormat2*)Coverage;
+ for(i = 0; i < c2->RangeCount; i++) {
+ TT_uint32_t s = c2->RangeRecord[i].Start;
+ TT_uint32_t e = c2->RangeRecord[i].End;
+ TT_uint32_t si = c2->RangeRecord[i].StartCoverageIndex;
+ if (s <= g && g <= e) {
+ return si + g - s;
+ }
+ }
+ return -1;
+ }
+ }
+ return -1;
+}
+bool CFX_CTTGSUBTable::Parse(
+ FT_Bytes scriptlist,
+ FT_Bytes featurelist,
+ FT_Bytes lookuplist)
+{
+ ParseScriptList(scriptlist, &ScriptList);
+ ParseFeatureList(featurelist, &FeatureList);
+ ParseLookupList(lookuplist, &LookupList);
+ return true;
+}
+void CFX_CTTGSUBTable::ParseScriptList(FT_Bytes raw, struct TScriptList *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ rec->ScriptCount = GetUInt16(sp);
+ if(rec->ScriptCount <= 0) {
+ return;
+ }
+ rec->ScriptRecord = new struct TScriptRecord[rec->ScriptCount];
+ for(i = 0; i < rec->ScriptCount; i++) {
+ rec->ScriptRecord[i].ScriptTag = GetUInt32(sp);
+ TT_uint16_t offset = GetUInt16(sp);
+ ParseScript(
+ &raw[offset],
+ &rec->ScriptRecord[i].Script);
+ }
+}
+void CFX_CTTGSUBTable::ParseScript(FT_Bytes raw, struct TScript *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ rec->DefaultLangSys = GetUInt16(sp);
+ rec->LangSysCount = GetUInt16(sp);
+ if(rec->LangSysCount <= 0) {
+ return;
+ }
+ rec->LangSysRecord = new struct TLangSysRecord[rec->LangSysCount];
+ for(i = 0; i < rec->LangSysCount; i++) {
+ rec->LangSysRecord[i].LangSysTag = GetUInt32(sp);
+ TT_uint16_t offset = GetUInt16(sp);
+ ParseLangSys(
+ &raw[offset],
+ &rec->LangSysRecord[i].LangSys);
+ }
+}
+void CFX_CTTGSUBTable::ParseLangSys(FT_Bytes raw, struct TLangSys *rec)
+{
+ FT_Bytes sp = raw;
+ rec->LookupOrder = GetUInt16(sp);
+ rec->ReqFeatureIndex = GetUInt16(sp);
+ rec->FeatureCount = GetUInt16(sp);
+ if(rec->FeatureCount <= 0) {
+ return;
+ }
+ rec->FeatureIndex = new TT_uint16_t[rec->FeatureCount];
+ FXSYS_memset32(rec->FeatureIndex, 0, sizeof(TT_uint16_t) * rec->FeatureCount);
+ for (int i = 0; i < rec->FeatureCount; ++i) {
+ rec->FeatureIndex[i] = GetUInt16(sp);
+ }
+}
+void CFX_CTTGSUBTable::ParseFeatureList(FT_Bytes raw, TFeatureList *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ rec->FeatureCount = GetUInt16(sp);
+ if(rec->FeatureCount <= 0) {
+ return;
+ }
+ rec->FeatureRecord = new struct TFeatureRecord[rec->FeatureCount];
+ for(i = 0; i < rec->FeatureCount; i++) {
+ rec->FeatureRecord[i].FeatureTag = GetUInt32(sp);
+ TT_uint16_t offset = GetUInt16(sp);
+ ParseFeature(
+ &raw[offset],
+ &rec->FeatureRecord[i].Feature);
+ }
+}
+void CFX_CTTGSUBTable::ParseFeature(FT_Bytes raw, TFeature *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ rec->FeatureParams = GetUInt16(sp);
+ rec->LookupCount = GetUInt16(sp);
+ if(rec->LookupCount <= 0) {
+ return;
+ }
+ rec->LookupListIndex = new TT_uint16_t[rec->LookupCount];
+ for(i = 0; i < rec->LookupCount; i++) {
+ rec->LookupListIndex[i] = GetUInt16(sp);
+ }
+}
+void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ rec->LookupCount = GetUInt16(sp);
+ if(rec->LookupCount <= 0) {
+ return;
+ }
+ rec->Lookup = new struct TLookup[rec->LookupCount];
+ for(i = 0; i < rec->LookupCount; i++) {
+ TT_uint16_t offset = GetUInt16(sp);
+ ParseLookup(
+ &raw[offset],
+ &rec->Lookup[i]);
+ }
+}
+void CFX_CTTGSUBTable::ParseLookup(FT_Bytes raw, TLookup *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ rec->LookupType = GetUInt16(sp);
+ rec->LookupFlag = GetUInt16(sp);
+ rec->SubTableCount = GetUInt16(sp);
+ if(rec->SubTableCount <= 0) {
+ return;
+ }
+ rec->SubTable = new struct TSubTableBase*[rec->SubTableCount];
+ for(i = 0; i < rec->SubTableCount; i++) {
+ rec->SubTable[i] = NULL;
+ }
+ if(rec->LookupType != 1) {
+ return;
+ }
+ for(i = 0; i < rec->SubTableCount; i++) {
+ TT_uint16_t offset = GetUInt16(sp);
+ ParseSingleSubst(
+ &raw[offset],
+ &rec->SubTable[i]);
+ }
+}
+void CFX_CTTGSUBTable::ParseCoverage(FT_Bytes raw, TCoverageFormatBase **rec)
+{
+ FT_Bytes sp = raw;
+ TT_uint16_t Format = GetUInt16(sp);
+ switch(Format) {
+ case 1:
+ *rec = new TCoverageFormat1();
+ ParseCoverageFormat1(raw, (TCoverageFormat1*)*rec);
+ break;
+ case 2:
+ *rec = new TCoverageFormat2();
+ ParseCoverageFormat2(raw, (TCoverageFormat2*)*rec);
+ break;
+ }
+}
+void CFX_CTTGSUBTable::ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1 *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ GetUInt16(sp);
+ rec->GlyphCount = GetUInt16(sp);
+ if(rec->GlyphCount <= 0) {
+ return;
+ }
+ rec->GlyphArray = new TT_uint16_t[rec->GlyphCount];
+ for(i = 0; i < rec->GlyphCount; i++) {
+ rec->GlyphArray[i] = GetUInt16(sp);
+ }
+}
+void CFX_CTTGSUBTable::ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2 *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ GetUInt16(sp);
+ rec->RangeCount = GetUInt16(sp);
+ if(rec->RangeCount <= 0) {
+ return;
+ }
+ rec->RangeRecord = new TRangeRecord[rec->RangeCount];
+ for(i = 0; i < rec->RangeCount; i++) {
+ rec->RangeRecord[i].Start = GetUInt16(sp);
+ rec->RangeRecord[i].End = GetUInt16(sp);
+ rec->RangeRecord[i].StartCoverageIndex = GetUInt16(sp);
+ }
+}
+void CFX_CTTGSUBTable::ParseSingleSubst(FT_Bytes raw, TSubTableBase **rec)
+{
+ FT_Bytes sp = raw;
+ TT_uint16_t Format = GetUInt16(sp);
+ switch(Format) {
+ case 1:
+ *rec = new TSingleSubstFormat1();
+ ParseSingleSubstFormat1(raw, (TSingleSubstFormat1*)*rec);
+ break;
+ case 2:
+ *rec = new TSingleSubstFormat2();
+ ParseSingleSubstFormat2(raw, (TSingleSubstFormat2*)*rec);
+ break;
+ }
+}
+void CFX_CTTGSUBTable::ParseSingleSubstFormat1(FT_Bytes raw, TSingleSubstFormat1 *rec)
+{
+ FT_Bytes sp = raw;
+ GetUInt16(sp);
+ TT_uint16_t offset = GetUInt16(sp);
+ ParseCoverage(
+ &raw[offset],
+ &rec->Coverage);
+ rec->DeltaGlyphID = GetInt16(sp);
+}
+void CFX_CTTGSUBTable::ParseSingleSubstFormat2(FT_Bytes raw, TSingleSubstFormat2 *rec)
+{
+ int i;
+ FT_Bytes sp = raw;
+ GetUInt16(sp);
+ TT_uint16_t offset = GetUInt16(sp);
+ ParseCoverage(
+ &raw[offset],
+ &rec->Coverage);
+ rec->GlyphCount = GetUInt16(sp);
+ if(rec->GlyphCount <= 0) {
+ return;
+ }
+ rec->Substitute = new TT_uint16_t[rec->GlyphCount];
+ for(i = 0; i < rec->GlyphCount; i++) {
+ rec->Substitute[i] = GetUInt16(sp);
+ }
+}
+FX_BOOL CFX_GSUBTable::GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum)
+{
+ return m_GsubImp.GetVerticalGlyph(glyphnum, vglyphnum);
+}
+IFX_GSUBTable* FXGE_CreateGSUBTable(CFX_Font* pFont)
+{
+ if (!pFont) {
+ return NULL;
+ }
+ if (NULL == pFont->m_pGsubData) {
+ unsigned long length = 0;
+ int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, NULL, &length);
+ if (!error) {
+ pFont->m_pGsubData = (unsigned char*)FX_Alloc(FX_BYTE, length);
+ }
+ if (!pFont->m_pGsubData) {
+ return NULL;
+ }
+ }
+ int error = FXFT_Load_Sfnt_Table(pFont->m_Face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, pFont->m_pGsubData, NULL);
+ if (!error && pFont->m_pGsubData) {
+ CFX_GSUBTable* pGsubTable = FX_NEW CFX_GSUBTable;
+ if (!pGsubTable) {
+ return NULL;
+ }
+ if (pGsubTable->m_GsubImp.LoadGSUBTable((FT_Bytes)pFont->m_pGsubData)) {
+ return pGsubTable;
+ }
+ delete pGsubTable;
+ }
+ return NULL;
+}
diff --git a/core/src/fpdfapi/fpdf_font/ttgsubtable.h b/core/src/fpdfapi/fpdf_font/ttgsubtable.h
index a1f0e8867a..bf9c7a4c42 100644
--- a/core/src/fpdfapi/fpdf_font/ttgsubtable.h
+++ b/core/src/fpdfapi/fpdf_font/ttgsubtable.h
@@ -1,419 +1,419 @@
-// 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 TTGSUBTable_H
-#define TTGSUBTable_H
-#include "../../fx_freetype.h"
-#include "../../../include/fxcrt/fx_basic.h"
-#include "common.h"
-class CFX_GlyphMap
-{
-public:
- CFX_GlyphMap();
- ~CFX_GlyphMap();
- void SetAt(int key, int value);
- FX_BOOL Lookup(int key, int &value);
-protected:
- CFX_BinaryBuf m_Buffer;
-};
-class CFX_CTTGSUBTable : public CFX_Object
-{
-public:
- CFX_CTTGSUBTable(void): loaded(false), m_bFeautureMapLoad(FALSE) {};
- CFX_CTTGSUBTable(FT_Bytes gsub): loaded(false), m_bFeautureMapLoad(FALSE)
- {
- LoadGSUBTable(gsub);
- }
- virtual ~CFX_CTTGSUBTable() {}
- bool IsOk(void) const
- {
- return loaded;
- }
- bool LoadGSUBTable(FT_Bytes gsub);
- bool GetVerticalGlyph(TT_uint32_t glyphnum, TT_uint32_t *vglyphnum);
-private:
- struct tt_gsub_header {
- TT_uint32_t Version;
- TT_uint16_t ScriptList;
- TT_uint16_t FeatureList;
- TT_uint16_t LookupList;
- };
- struct TLangSys {
- TT_uint16_t LookupOrder;
- TT_uint16_t ReqFeatureIndex;
- TT_uint16_t FeatureCount;
- TT_uint16_t *FeatureIndex;
- TLangSys(): LookupOrder(0), ReqFeatureIndex(0), FeatureCount(0), FeatureIndex(NULL) {}
- ~TLangSys()
- {
- if(FeatureIndex) {
- delete[] FeatureIndex;
- }
- }
- private:
- TLangSys(const TLangSys&);
- TLangSys& operator=(const TLangSys&);
- };
- struct TLangSysRecord {
- TT_uint32_t LangSysTag;
- struct TLangSys LangSys;
- TLangSysRecord(): LangSysTag(0) {}
- private:
- TLangSysRecord(const TLangSysRecord&);
- TLangSysRecord& operator=(const TLangSysRecord&);
- };
- struct TScript {
- TT_uint16_t DefaultLangSys;
- TT_uint16_t LangSysCount;
- struct TLangSysRecord *LangSysRecord;
- TScript(): DefaultLangSys(0), LangSysCount(0), LangSysRecord(NULL) {}
- ~TScript()
- {
- if(LangSysRecord) {
- delete[] LangSysRecord;
- }
- }
- private:
- TScript(const TScript&);
- TScript& operator=(const TScript&);
- };
- struct TScriptRecord {
- TT_uint32_t ScriptTag;
- struct TScript Script;
- TScriptRecord(): ScriptTag(0) {}
- private:
- TScriptRecord(const TScriptRecord&);
- TScriptRecord& operator=(const TScriptRecord&);
- };
- struct TScriptList {
- TT_uint16_t ScriptCount;
- struct TScriptRecord *ScriptRecord;
- TScriptList(): ScriptCount(0), ScriptRecord(NULL) {}
- ~TScriptList()
- {
- if(ScriptRecord) {
- delete[] ScriptRecord;
- }
- }
- private:
- TScriptList(const TScriptList&);
- TScriptList& operator=(const TScriptList&);
- };
- struct TFeature {
- TT_uint16_t FeatureParams;
- int LookupCount;
- TT_uint16_t *LookupListIndex;
- TFeature(): FeatureParams(0), LookupCount(0), LookupListIndex(NULL) {}
- ~TFeature()
- {
- if(LookupListIndex) {
- delete[] LookupListIndex;
- }
- }
- private:
- TFeature(const TFeature&);
- TFeature& operator=(const TFeature&);
- };
- struct TFeatureRecord {
- TT_uint32_t FeatureTag;
- struct TFeature Feature;
- TFeatureRecord(): FeatureTag(0) {}
- private:
- TFeatureRecord(const TFeatureRecord&);
- TFeatureRecord& operator=(const TFeatureRecord&);
- };
- struct TFeatureList {
- int FeatureCount;
- struct TFeatureRecord *FeatureRecord;
- TFeatureList(): FeatureCount(0), FeatureRecord(NULL) {}
- ~TFeatureList()
- {
- if(FeatureRecord) {
- delete[] FeatureRecord;
- }
- }
- private:
- TFeatureList(const TFeatureList&);
- TFeatureList& operator=(const TFeatureList&);
- };
- enum TLookupFlag {
- LOOKUPFLAG_RightToLeft = 0x0001,
- LOOKUPFLAG_IgnoreBaseGlyphs = 0x0002,
- LOOKUPFLAG_IgnoreLigatures = 0x0004,
- LOOKUPFLAG_IgnoreMarks = 0x0008,
- LOOKUPFLAG_Reserved = 0x00F0,
- LOOKUPFLAG_MarkAttachmentType = 0xFF00,
- };
- struct TCoverageFormatBase {
- TT_uint16_t CoverageFormat;
- CFX_GlyphMap m_glyphMap;
- TCoverageFormatBase(): CoverageFormat(0) {}
- virtual ~TCoverageFormatBase() {}
- private:
- TCoverageFormatBase(const TCoverageFormatBase&);
- TCoverageFormatBase& operator=(const TCoverageFormatBase&);
- };
- struct TCoverageFormat1: public TCoverageFormatBase {
- TT_uint16_t GlyphCount;
- TT_uint16_t *GlyphArray;
- TCoverageFormat1(): GlyphCount(0), GlyphArray(NULL)
- {
- CoverageFormat = 1;
- }
- ~TCoverageFormat1()
- {
- if(GlyphArray) {
- delete[] GlyphArray;
- }
- }
- private:
- TCoverageFormat1(const TCoverageFormat1&);
- TCoverageFormat1& operator=(const TCoverageFormat1&);
- };
- struct TRangeRecord {
- TT_uint16_t Start;
- TT_uint16_t End;
- TT_uint16_t StartCoverageIndex;
- TRangeRecord(): Start(0), End(0), StartCoverageIndex(0) {}
- friend bool operator > (const TRangeRecord &r1, const TRangeRecord &r2)
- {
- return r1.Start > r2.Start;
- }
- private:
- TRangeRecord(const TRangeRecord&);
- };
- struct TCoverageFormat2: public TCoverageFormatBase {
- TT_uint16_t RangeCount;
- struct TRangeRecord *RangeRecord;
- TCoverageFormat2(): RangeCount(0), RangeRecord(NULL)
- {
- CoverageFormat = 2;
- }
- ~TCoverageFormat2()
- {
- if(RangeRecord) {
- delete[] RangeRecord;
- }
- }
- private:
- TCoverageFormat2(const TCoverageFormat2&);
- TCoverageFormat2& operator=(const TCoverageFormat2&);
- };
- struct TClassDefFormatBase {
- TT_uint16_t ClassFormat;
- TClassDefFormatBase(): ClassFormat(0) {}
- virtual ~TClassDefFormatBase() {}
- private:
- TClassDefFormatBase(const TClassDefFormatBase&);
- TClassDefFormatBase& operator=(const TClassDefFormatBase&);
- };
- struct TClassDefFormat1: public TClassDefFormatBase {
- TT_uint16_t StartGlyph;
- TT_uint16_t GlyphCount;
- TT_uint16_t *ClassValueArray;
- TClassDefFormat1(): StartGlyph(0), GlyphCount(0), ClassValueArray(NULL)
- {
- ClassFormat = 1;
- }
- ~TClassDefFormat1()
- {
- if(ClassValueArray) {
- delete[] ClassValueArray;
- }
- }
- private:
- TClassDefFormat1(const TClassDefFormat1&);
- TClassDefFormat1& operator=(const TClassDefFormat1&);
- };
- struct TClassRangeRecord {
- TT_uint16_t Start;
- TT_uint16_t End;
- TT_uint16_t Class;
- TClassRangeRecord(): Start(0), End(0), Class(0) {}
- private:
- TClassRangeRecord(const TClassRangeRecord&);
- TClassRangeRecord& operator=(const TClassRangeRecord&);
- };
- struct TClassDefFormat2: public TClassDefFormatBase {
- TT_uint16_t ClassRangeCount;
- struct TClassRangeRecord *ClassRangeRecord;
- TClassDefFormat2(): ClassRangeCount(0), ClassRangeRecord(NULL)
- {
- ClassFormat = 2;
- }
- ~TClassDefFormat2()
- {
- if(ClassRangeRecord) {
- delete[] ClassRangeRecord;
- }
- }
- private:
- TClassDefFormat2(const TClassDefFormat2&);
- TClassDefFormat2& operator=(const TClassDefFormat2&);
- };
- struct TDevice {
- TT_uint16_t StartSize;
- TT_uint16_t EndSize;
- TT_uint16_t DeltaFormat;
- TDevice(): StartSize(0), EndSize(0), DeltaFormat(0) {}
- private:
- TDevice(const TDevice&);
- TDevice& operator=(const TDevice&);
- };
- struct TSubTableBase {
- TT_uint16_t SubstFormat;
- TSubTableBase(): SubstFormat(0) {}
- virtual ~TSubTableBase() {}
- private:
- TSubTableBase(const TSubTableBase&);
- TSubTableBase& operator=(const TSubTableBase&);
- };
- struct TSingleSubstFormat1: public TSubTableBase {
- TCoverageFormatBase *Coverage;
- TT_int16_t DeltaGlyphID;
- TSingleSubstFormat1(): DeltaGlyphID(0), Coverage(NULL)
- {
- SubstFormat = 1;
- }
- ~TSingleSubstFormat1()
- {
- if(Coverage) {
- delete Coverage;
- }
- }
- private:
- TSingleSubstFormat1(const TSingleSubstFormat1&);
- TSingleSubstFormat1& operator=(const TSingleSubstFormat1&);
- };
- struct TSingleSubstFormat2: public TSubTableBase {
- TCoverageFormatBase *Coverage;
- TT_uint16_t GlyphCount;
- TT_uint16_t *Substitute;
- TSingleSubstFormat2(): Coverage(NULL), GlyphCount(0), Substitute(NULL)
- {
- SubstFormat = 2;
- }
- ~TSingleSubstFormat2()
- {
- if(Coverage) {
- delete Coverage;
- }
- if(Substitute) {
- delete[] Substitute;
- }
- }
- private:
- TSingleSubstFormat2(const TSingleSubstFormat2&);
- TSingleSubstFormat2& operator=(const TSingleSubstFormat2&);
- };
- struct TLookup {
- TT_uint16_t LookupType;
- TT_uint16_t LookupFlag;
- TT_uint16_t SubTableCount;
- struct TSubTableBase **SubTable;
- TLookup(): LookupType(0), LookupFlag(0), SubTableCount(0), SubTable(NULL) {}
- ~TLookup()
- {
- if(SubTableCount > 0 && SubTable != NULL) {
- for(int i = 0; i < SubTableCount; i++) {
- delete SubTable[i];
- }
- delete[] SubTable;
- }
- }
- private:
- TLookup(const TLookup&);
- TLookup& operator=(const TLookup&);
- };
- struct TLookupList {
- int LookupCount;
- struct TLookup *Lookup;
- TLookupList(): LookupCount(0), Lookup(NULL) {}
- ~TLookupList()
- {
- if(Lookup) {
- delete[] Lookup;
- }
- }
- private:
- TLookupList(const TLookupList&);
- TLookupList& operator=(const TLookupList&);
- };
- bool Parse(
- FT_Bytes scriptlist,
- FT_Bytes featurelist,
- FT_Bytes lookuplist);
- void ParseScriptList(FT_Bytes raw, TScriptList *rec);
- void ParseScript(FT_Bytes raw, TScript *rec);
- void ParseLangSys(FT_Bytes raw, TLangSys *rec);
- void ParseFeatureList(FT_Bytes raw, TFeatureList *rec);
- void ParseFeature(FT_Bytes raw, TFeature *rec);
- void ParseLookupList(FT_Bytes raw, TLookupList *rec);
- void ParseLookup(FT_Bytes raw, TLookup *rec);
- void ParseCoverage(FT_Bytes raw, TCoverageFormatBase **rec);
- void ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1 *rec);
- void ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2 *rec);
- void ParseSingleSubst(FT_Bytes raw, TSubTableBase **rec);
- void ParseSingleSubstFormat1(FT_Bytes raw, TSingleSubstFormat1 *rec);
- void ParseSingleSubstFormat2(FT_Bytes raw, TSingleSubstFormat2 *rec);
- bool GetVerticalGlyphSub(
- TT_uint32_t glyphnum,
- TT_uint32_t *vglyphnum,
- struct TFeature *Feature);
- bool GetVerticalGlyphSub2(
- TT_uint32_t glyphnum,
- TT_uint32_t *vglyphnum,
- struct TLookup *Lookup);
- int GetCoverageIndex(struct TCoverageFormatBase *Coverage, TT_uint32_t g);
- TT_uint8_t GetUInt8(FT_Bytes& p) const
- {
- TT_uint8_t ret = p[0];
- p += 1;
- return ret;
- }
- TT_int16_t GetInt16(FT_Bytes& p) const
- {
- TT_uint16_t ret = p[0] << 8 | p[1];
- p += 2;
- return *(TT_int16_t*)&ret;
- }
- TT_uint16_t GetUInt16(FT_Bytes& p) const
- {
- TT_uint16_t ret = p[0] << 8 | p[1];
- p += 2;
- return ret;
- }
- TT_int32_t GetInt32(FT_Bytes& p) const
- {
- TT_uint32_t ret = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
- p += 4;
- return *(TT_int32_t*)&ret;
- }
- TT_uint32_t GetUInt32(FT_Bytes& p) const
- {
- TT_uint32_t ret = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
- p += 4;
- return ret;
- }
- CFX_CMapDWordToDWord m_featureMap;
- FX_BOOL m_bFeautureMapLoad;
- bool loaded;
- struct tt_gsub_header header;
- struct TScriptList ScriptList;
- struct TFeatureList FeatureList;
- struct TLookupList LookupList;
-};
-class CFX_GSUBTable : public IFX_GSUBTable, public CFX_Object
-{
-public:
- virtual void Release()
- {
- delete this;
- }
- virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum);
- CFX_CTTGSUBTable m_GsubImp;
-};
-#endif
+// 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 TTGSUBTable_H
+#define TTGSUBTable_H
+#include "../../fx_freetype.h"
+#include "../../../include/fxcrt/fx_basic.h"
+#include "common.h"
+class CFX_GlyphMap
+{
+public:
+ CFX_GlyphMap();
+ ~CFX_GlyphMap();
+ void SetAt(int key, int value);
+ FX_BOOL Lookup(int key, int &value);
+protected:
+ CFX_BinaryBuf m_Buffer;
+};
+class CFX_CTTGSUBTable : public CFX_Object
+{
+public:
+ CFX_CTTGSUBTable(void): loaded(false), m_bFeautureMapLoad(FALSE) {};
+ CFX_CTTGSUBTable(FT_Bytes gsub): loaded(false), m_bFeautureMapLoad(FALSE)
+ {
+ LoadGSUBTable(gsub);
+ }
+ virtual ~CFX_CTTGSUBTable() {}
+ bool IsOk(void) const
+ {
+ return loaded;
+ }
+ bool LoadGSUBTable(FT_Bytes gsub);
+ bool GetVerticalGlyph(TT_uint32_t glyphnum, TT_uint32_t *vglyphnum);
+private:
+ struct tt_gsub_header {
+ TT_uint32_t Version;
+ TT_uint16_t ScriptList;
+ TT_uint16_t FeatureList;
+ TT_uint16_t LookupList;
+ };
+ struct TLangSys {
+ TT_uint16_t LookupOrder;
+ TT_uint16_t ReqFeatureIndex;
+ TT_uint16_t FeatureCount;
+ TT_uint16_t *FeatureIndex;
+ TLangSys(): LookupOrder(0), ReqFeatureIndex(0), FeatureCount(0), FeatureIndex(NULL) {}
+ ~TLangSys()
+ {
+ if(FeatureIndex) {
+ delete[] FeatureIndex;
+ }
+ }
+ private:
+ TLangSys(const TLangSys&);
+ TLangSys& operator=(const TLangSys&);
+ };
+ struct TLangSysRecord {
+ TT_uint32_t LangSysTag;
+ struct TLangSys LangSys;
+ TLangSysRecord(): LangSysTag(0) {}
+ private:
+ TLangSysRecord(const TLangSysRecord&);
+ TLangSysRecord& operator=(const TLangSysRecord&);
+ };
+ struct TScript {
+ TT_uint16_t DefaultLangSys;
+ TT_uint16_t LangSysCount;
+ struct TLangSysRecord *LangSysRecord;
+ TScript(): DefaultLangSys(0), LangSysCount(0), LangSysRecord(NULL) {}
+ ~TScript()
+ {
+ if(LangSysRecord) {
+ delete[] LangSysRecord;
+ }
+ }
+ private:
+ TScript(const TScript&);
+ TScript& operator=(const TScript&);
+ };
+ struct TScriptRecord {
+ TT_uint32_t ScriptTag;
+ struct TScript Script;
+ TScriptRecord(): ScriptTag(0) {}
+ private:
+ TScriptRecord(const TScriptRecord&);
+ TScriptRecord& operator=(const TScriptRecord&);
+ };
+ struct TScriptList {
+ TT_uint16_t ScriptCount;
+ struct TScriptRecord *ScriptRecord;
+ TScriptList(): ScriptCount(0), ScriptRecord(NULL) {}
+ ~TScriptList()
+ {
+ if(ScriptRecord) {
+ delete[] ScriptRecord;
+ }
+ }
+ private:
+ TScriptList(const TScriptList&);
+ TScriptList& operator=(const TScriptList&);
+ };
+ struct TFeature {
+ TT_uint16_t FeatureParams;
+ int LookupCount;
+ TT_uint16_t *LookupListIndex;
+ TFeature(): FeatureParams(0), LookupCount(0), LookupListIndex(NULL) {}
+ ~TFeature()
+ {
+ if(LookupListIndex) {
+ delete[] LookupListIndex;
+ }
+ }
+ private:
+ TFeature(const TFeature&);
+ TFeature& operator=(const TFeature&);
+ };
+ struct TFeatureRecord {
+ TT_uint32_t FeatureTag;
+ struct TFeature Feature;
+ TFeatureRecord(): FeatureTag(0) {}
+ private:
+ TFeatureRecord(const TFeatureRecord&);
+ TFeatureRecord& operator=(const TFeatureRecord&);
+ };
+ struct TFeatureList {
+ int FeatureCount;
+ struct TFeatureRecord *FeatureRecord;
+ TFeatureList(): FeatureCount(0), FeatureRecord(NULL) {}
+ ~TFeatureList()
+ {
+ if(FeatureRecord) {
+ delete[] FeatureRecord;
+ }
+ }
+ private:
+ TFeatureList(const TFeatureList&);
+ TFeatureList& operator=(const TFeatureList&);
+ };
+ enum TLookupFlag {
+ LOOKUPFLAG_RightToLeft = 0x0001,
+ LOOKUPFLAG_IgnoreBaseGlyphs = 0x0002,
+ LOOKUPFLAG_IgnoreLigatures = 0x0004,
+ LOOKUPFLAG_IgnoreMarks = 0x0008,
+ LOOKUPFLAG_Reserved = 0x00F0,
+ LOOKUPFLAG_MarkAttachmentType = 0xFF00,
+ };
+ struct TCoverageFormatBase {
+ TT_uint16_t CoverageFormat;
+ CFX_GlyphMap m_glyphMap;
+ TCoverageFormatBase(): CoverageFormat(0) {}
+ virtual ~TCoverageFormatBase() {}
+ private:
+ TCoverageFormatBase(const TCoverageFormatBase&);
+ TCoverageFormatBase& operator=(const TCoverageFormatBase&);
+ };
+ struct TCoverageFormat1: public TCoverageFormatBase {
+ TT_uint16_t GlyphCount;
+ TT_uint16_t *GlyphArray;
+ TCoverageFormat1(): GlyphCount(0), GlyphArray(NULL)
+ {
+ CoverageFormat = 1;
+ }
+ ~TCoverageFormat1()
+ {
+ if(GlyphArray) {
+ delete[] GlyphArray;
+ }
+ }
+ private:
+ TCoverageFormat1(const TCoverageFormat1&);
+ TCoverageFormat1& operator=(const TCoverageFormat1&);
+ };
+ struct TRangeRecord {
+ TT_uint16_t Start;
+ TT_uint16_t End;
+ TT_uint16_t StartCoverageIndex;
+ TRangeRecord(): Start(0), End(0), StartCoverageIndex(0) {}
+ friend bool operator > (const TRangeRecord &r1, const TRangeRecord &r2)
+ {
+ return r1.Start > r2.Start;
+ }
+ private:
+ TRangeRecord(const TRangeRecord&);
+ };
+ struct TCoverageFormat2: public TCoverageFormatBase {
+ TT_uint16_t RangeCount;
+ struct TRangeRecord *RangeRecord;
+ TCoverageFormat2(): RangeCount(0), RangeRecord(NULL)
+ {
+ CoverageFormat = 2;
+ }
+ ~TCoverageFormat2()
+ {
+ if(RangeRecord) {
+ delete[] RangeRecord;
+ }
+ }
+ private:
+ TCoverageFormat2(const TCoverageFormat2&);
+ TCoverageFormat2& operator=(const TCoverageFormat2&);
+ };
+ struct TClassDefFormatBase {
+ TT_uint16_t ClassFormat;
+ TClassDefFormatBase(): ClassFormat(0) {}
+ virtual ~TClassDefFormatBase() {}
+ private:
+ TClassDefFormatBase(const TClassDefFormatBase&);
+ TClassDefFormatBase& operator=(const TClassDefFormatBase&);
+ };
+ struct TClassDefFormat1: public TClassDefFormatBase {
+ TT_uint16_t StartGlyph;
+ TT_uint16_t GlyphCount;
+ TT_uint16_t *ClassValueArray;
+ TClassDefFormat1(): StartGlyph(0), GlyphCount(0), ClassValueArray(NULL)
+ {
+ ClassFormat = 1;
+ }
+ ~TClassDefFormat1()
+ {
+ if(ClassValueArray) {
+ delete[] ClassValueArray;
+ }
+ }
+ private:
+ TClassDefFormat1(const TClassDefFormat1&);
+ TClassDefFormat1& operator=(const TClassDefFormat1&);
+ };
+ struct TClassRangeRecord {
+ TT_uint16_t Start;
+ TT_uint16_t End;
+ TT_uint16_t Class;
+ TClassRangeRecord(): Start(0), End(0), Class(0) {}
+ private:
+ TClassRangeRecord(const TClassRangeRecord&);
+ TClassRangeRecord& operator=(const TClassRangeRecord&);
+ };
+ struct TClassDefFormat2: public TClassDefFormatBase {
+ TT_uint16_t ClassRangeCount;
+ struct TClassRangeRecord *ClassRangeRecord;
+ TClassDefFormat2(): ClassRangeCount(0), ClassRangeRecord(NULL)
+ {
+ ClassFormat = 2;
+ }
+ ~TClassDefFormat2()
+ {
+ if(ClassRangeRecord) {
+ delete[] ClassRangeRecord;
+ }
+ }
+ private:
+ TClassDefFormat2(const TClassDefFormat2&);
+ TClassDefFormat2& operator=(const TClassDefFormat2&);
+ };
+ struct TDevice {
+ TT_uint16_t StartSize;
+ TT_uint16_t EndSize;
+ TT_uint16_t DeltaFormat;
+ TDevice(): StartSize(0), EndSize(0), DeltaFormat(0) {}
+ private:
+ TDevice(const TDevice&);
+ TDevice& operator=(const TDevice&);
+ };
+ struct TSubTableBase {
+ TT_uint16_t SubstFormat;
+ TSubTableBase(): SubstFormat(0) {}
+ virtual ~TSubTableBase() {}
+ private:
+ TSubTableBase(const TSubTableBase&);
+ TSubTableBase& operator=(const TSubTableBase&);
+ };
+ struct TSingleSubstFormat1: public TSubTableBase {
+ TCoverageFormatBase *Coverage;
+ TT_int16_t DeltaGlyphID;
+ TSingleSubstFormat1(): DeltaGlyphID(0), Coverage(NULL)
+ {
+ SubstFormat = 1;
+ }
+ ~TSingleSubstFormat1()
+ {
+ if(Coverage) {
+ delete Coverage;
+ }
+ }
+ private:
+ TSingleSubstFormat1(const TSingleSubstFormat1&);
+ TSingleSubstFormat1& operator=(const TSingleSubstFormat1&);
+ };
+ struct TSingleSubstFormat2: public TSubTableBase {
+ TCoverageFormatBase *Coverage;
+ TT_uint16_t GlyphCount;
+ TT_uint16_t *Substitute;
+ TSingleSubstFormat2(): Coverage(NULL), GlyphCount(0), Substitute(NULL)
+ {
+ SubstFormat = 2;
+ }
+ ~TSingleSubstFormat2()
+ {
+ if(Coverage) {
+ delete Coverage;
+ }
+ if(Substitute) {
+ delete[] Substitute;
+ }
+ }
+ private:
+ TSingleSubstFormat2(const TSingleSubstFormat2&);
+ TSingleSubstFormat2& operator=(const TSingleSubstFormat2&);
+ };
+ struct TLookup {
+ TT_uint16_t LookupType;
+ TT_uint16_t LookupFlag;
+ TT_uint16_t SubTableCount;
+ struct TSubTableBase **SubTable;
+ TLookup(): LookupType(0), LookupFlag(0), SubTableCount(0), SubTable(NULL) {}
+ ~TLookup()
+ {
+ if(SubTableCount > 0 && SubTable != NULL) {
+ for(int i = 0; i < SubTableCount; i++) {
+ delete SubTable[i];
+ }
+ delete[] SubTable;
+ }
+ }
+ private:
+ TLookup(const TLookup&);
+ TLookup& operator=(const TLookup&);
+ };
+ struct TLookupList {
+ int LookupCount;
+ struct TLookup *Lookup;
+ TLookupList(): LookupCount(0), Lookup(NULL) {}
+ ~TLookupList()
+ {
+ if(Lookup) {
+ delete[] Lookup;
+ }
+ }
+ private:
+ TLookupList(const TLookupList&);
+ TLookupList& operator=(const TLookupList&);
+ };
+ bool Parse(
+ FT_Bytes scriptlist,
+ FT_Bytes featurelist,
+ FT_Bytes lookuplist);
+ void ParseScriptList(FT_Bytes raw, TScriptList *rec);
+ void ParseScript(FT_Bytes raw, TScript *rec);
+ void ParseLangSys(FT_Bytes raw, TLangSys *rec);
+ void ParseFeatureList(FT_Bytes raw, TFeatureList *rec);
+ void ParseFeature(FT_Bytes raw, TFeature *rec);
+ void ParseLookupList(FT_Bytes raw, TLookupList *rec);
+ void ParseLookup(FT_Bytes raw, TLookup *rec);
+ void ParseCoverage(FT_Bytes raw, TCoverageFormatBase **rec);
+ void ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1 *rec);
+ void ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2 *rec);
+ void ParseSingleSubst(FT_Bytes raw, TSubTableBase **rec);
+ void ParseSingleSubstFormat1(FT_Bytes raw, TSingleSubstFormat1 *rec);
+ void ParseSingleSubstFormat2(FT_Bytes raw, TSingleSubstFormat2 *rec);
+ bool GetVerticalGlyphSub(
+ TT_uint32_t glyphnum,
+ TT_uint32_t *vglyphnum,
+ struct TFeature *Feature);
+ bool GetVerticalGlyphSub2(
+ TT_uint32_t glyphnum,
+ TT_uint32_t *vglyphnum,
+ struct TLookup *Lookup);
+ int GetCoverageIndex(struct TCoverageFormatBase *Coverage, TT_uint32_t g);
+ TT_uint8_t GetUInt8(FT_Bytes& p) const
+ {
+ TT_uint8_t ret = p[0];
+ p += 1;
+ return ret;
+ }
+ TT_int16_t GetInt16(FT_Bytes& p) const
+ {
+ TT_uint16_t ret = p[0] << 8 | p[1];
+ p += 2;
+ return *(TT_int16_t*)&ret;
+ }
+ TT_uint16_t GetUInt16(FT_Bytes& p) const
+ {
+ TT_uint16_t ret = p[0] << 8 | p[1];
+ p += 2;
+ return ret;
+ }
+ TT_int32_t GetInt32(FT_Bytes& p) const
+ {
+ TT_uint32_t ret = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+ p += 4;
+ return *(TT_int32_t*)&ret;
+ }
+ TT_uint32_t GetUInt32(FT_Bytes& p) const
+ {
+ TT_uint32_t ret = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+ p += 4;
+ return ret;
+ }
+ CFX_CMapDWordToDWord m_featureMap;
+ FX_BOOL m_bFeautureMapLoad;
+ bool loaded;
+ struct tt_gsub_header header;
+ struct TScriptList ScriptList;
+ struct TFeatureList FeatureList;
+ struct TLookupList LookupList;
+};
+class CFX_GSUBTable : public IFX_GSUBTable, public CFX_Object
+{
+public:
+ virtual void Release()
+ {
+ delete this;
+ }
+ virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum);
+ CFX_CTTGSUBTable m_GsubImp;
+};
+#endif