OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
8 #include "../include/fpdf_sysfontinfo.h" | 8 #include "../include/fpdf_sysfontinfo.h" |
9 | 9 |
10 class CSysFontInfo_Ext FX_FINAL : public IFX_SystemFontInfo | 10 class CSysFontInfo_Ext FX_FINAL : public IFX_SystemFontInfo { |
11 { | 11 public: |
12 public: | 12 FPDF_SYSFONTINFO* m_pInfo; |
13 » FPDF_SYSFONTINFO*» m_pInfo; | |
14 | 13 |
15 » virtual void» » Release() | 14 virtual void Release() { |
16 » { | 15 if (m_pInfo->Release) |
17 » » if (m_pInfo->Release) | 16 m_pInfo->Release(m_pInfo); |
18 » » » m_pInfo->Release(m_pInfo); | 17 delete this; |
19 » » delete this; | 18 } |
20 » } | |
21 | 19 |
22 » virtual»FX_BOOL»» EnumFontList(CFX_FontMapper* pMapper) | 20 virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) { |
23 » { | 21 if (m_pInfo->EnumFonts) { |
24 » » if (m_pInfo->EnumFonts) { | 22 m_pInfo->EnumFonts(m_pInfo, pMapper); |
25 » » » m_pInfo->EnumFonts(m_pInfo, pMapper); | 23 return TRUE; |
26 » » » return TRUE; | 24 } |
27 » » } | 25 return FALSE; |
28 » » return FALSE; | 26 } |
29 » } | |
30 | 27 |
31 » virtual void*» » MapFont(int weight, FX_BOOL bItalic, int charset
, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact) | 28 virtual void* MapFont(int weight, |
32 » { | 29 FX_BOOL bItalic, |
33 » » if (m_pInfo->MapFont) | 30 int charset, |
34 » » » return m_pInfo->MapFont(m_pInfo, weight, bItalic, charse
t, pitch_family, family, &bExact); | 31 int pitch_family, |
35 » » return NULL; | 32 FX_LPCSTR family, |
36 » } | 33 FX_BOOL& bExact) { |
| 34 if (m_pInfo->MapFont) |
| 35 return m_pInfo->MapFont( |
| 36 m_pInfo, weight, bItalic, charset, pitch_family, family, &bExact); |
| 37 return NULL; |
| 38 } |
37 | 39 |
38 » virtual void*» » GetFont(FX_LPCSTR family) | 40 virtual void* GetFont(FX_LPCSTR family) { |
39 » { | 41 if (m_pInfo->GetFont) |
40 » » if (m_pInfo->GetFont) | 42 return m_pInfo->GetFont(m_pInfo, family); |
41 » » » return m_pInfo->GetFont(m_pInfo, family); | 43 return NULL; |
42 » » return NULL; | 44 } |
43 » } | |
44 | 45 |
45 » virtual FX_DWORD» GetFontData(void* hFont, FX_DWORD table, FX_LPBY
TE buffer, FX_DWORD size) | 46 virtual FX_DWORD GetFontData(void* hFont, |
46 » { | 47 FX_DWORD table, |
47 » » if (m_pInfo->GetFontData) | 48 FX_LPBYTE buffer, |
48 » » » return m_pInfo->GetFontData(m_pInfo, hFont, table, buffe
r, size); | 49 FX_DWORD size) { |
49 » » return 0; | 50 if (m_pInfo->GetFontData) |
50 » } | 51 return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size); |
| 52 return 0; |
| 53 } |
51 | 54 |
52 » virtual FX_BOOL»» GetFaceName(void* hFont, CFX_ByteString& name) | 55 virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) { |
53 » { | 56 if (m_pInfo->GetFaceName == NULL) |
54 » » if (m_pInfo->GetFaceName == NULL) return FALSE; | 57 return FALSE; |
55 » » FX_DWORD size = m_pInfo->GetFaceName(m_pInfo, hFont, NULL, 0); | 58 FX_DWORD size = m_pInfo->GetFaceName(m_pInfo, hFont, NULL, 0); |
56 » » if (size == 0) return FALSE; | 59 if (size == 0) |
57 » » char* buffer = FX_Alloc(char, size); | 60 return FALSE; |
58 » » size = m_pInfo->GetFaceName(m_pInfo, hFont, buffer, size); | 61 char* buffer = FX_Alloc(char, size); |
59 » » name = CFX_ByteString(buffer, size); | 62 size = m_pInfo->GetFaceName(m_pInfo, hFont, buffer, size); |
60 » » FX_Free(buffer); | 63 name = CFX_ByteString(buffer, size); |
61 » » return TRUE; | 64 FX_Free(buffer); |
62 » } | 65 return TRUE; |
| 66 } |
63 | 67 |
64 » virtual FX_BOOL»» GetFontCharset(void* hFont, int& charset) | 68 virtual FX_BOOL GetFontCharset(void* hFont, int& charset) { |
65 » { | 69 if (m_pInfo->GetFontCharset) { |
66 » » if (m_pInfo->GetFontCharset) { | 70 charset = m_pInfo->GetFontCharset(m_pInfo, hFont); |
67 » » » charset = m_pInfo->GetFontCharset(m_pInfo, hFont); | 71 return TRUE; |
68 » » » return TRUE; | 72 } |
69 » » } | 73 return FALSE; |
70 » » return FALSE; | 74 } |
71 » } | |
72 | 75 |
73 » virtual void» » DeleteFont(void* hFont) | 76 virtual void DeleteFont(void* hFont) { |
74 » { | 77 if (m_pInfo->DeleteFont) |
75 » » if (m_pInfo->DeleteFont) | 78 m_pInfo->DeleteFont(m_pInfo, hFont); |
76 » » » m_pInfo->DeleteFont(m_pInfo, hFont); | 79 } |
77 » } | |
78 }; | 80 }; |
79 | 81 |
80 DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper, const char* name, int
charset) | 82 DLLEXPORT void STDCALL |
81 { | 83 FPDF_AddInstalledFont(void* mapper, const char* name, int charset) { |
82 » ((CFX_FontMapper*)mapper)->AddInstalledFont(name, charset); | 84 ((CFX_FontMapper*)mapper)->AddInstalledFont(name, charset); |
83 } | 85 } |
84 | 86 |
85 DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) | 87 DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) { |
86 { | 88 if (pFontInfoExt->version != 1) |
87 » if (pFontInfoExt->version != 1) return; | 89 return; |
88 | 90 |
89 » CSysFontInfo_Ext* pFontInfo = FX_NEW CSysFontInfo_Ext; | 91 CSysFontInfo_Ext* pFontInfo = FX_NEW CSysFontInfo_Ext; |
90 » pFontInfo->m_pInfo = pFontInfoExt; | 92 pFontInfo->m_pInfo = pFontInfoExt; |
91 » CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(pFontInfo); | 93 CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(pFontInfo); |
92 } | 94 } |
93 | 95 |
94 struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO | 96 struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO { |
95 { | 97 IFX_SystemFontInfo* m_pFontInfo; |
96 » IFX_SystemFontInfo*» m_pFontInfo; | |
97 }; | 98 }; |
98 | 99 |
99 static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) | 100 static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) { |
100 { | 101 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->Release(); |
101 » ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->Release(); | |
102 } | 102 } |
103 | 103 |
104 static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) | 104 static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) { |
105 { | 105 ((FPDF_SYSFONTINFO_DEFAULT*)pThis) |
106 » ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->EnumFontList((CFX_FontM
apper*)pMapper); | 106 ->m_pFontInfo->EnumFontList((CFX_FontMapper*)pMapper); |
107 } | 107 } |
108 | 108 |
109 static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, int weight, int bIt
alic, int charset, int pitch_family, const char* family, int* bExact) | 109 static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, |
110 { | 110 int weight, |
111 » return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->MapFont(weight,
bItalic, charset, pitch_family, family, *bExact); | 111 int bItalic, |
| 112 int charset, |
| 113 int pitch_family, |
| 114 const char* family, |
| 115 int* bExact) { |
| 116 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->MapFont( |
| 117 weight, bItalic, charset, pitch_family, family, *bExact); |
112 } | 118 } |
113 | 119 |
114 void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) | 120 void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) { |
115 { | 121 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFont(family); |
116 » return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFont(family); | |
117 } | 122 } |
118 | 123 |
119 static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, void* h
Font, | 124 static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, |
120 » » » unsigned int table, unsigned char* buffer, unsigned long
buf_size) | 125 void* hFont, |
121 { | 126 unsigned int table, |
122 » return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFontData(hFon
t, table, buffer, buf_size); | 127 unsigned char* buffer, |
| 128 unsigned long buf_size) { |
| 129 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis) |
| 130 ->m_pFontInfo->GetFontData(hFont, table, buffer, buf_size); |
123 } | 131 } |
124 | 132 |
125 static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, void* h
Font, char* buffer, unsigned long buf_size) | 133 static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, |
126 { | 134 void* hFont, |
127 » CFX_ByteString name; | 135 char* buffer, |
128 » if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFaceName(hFont,
name)) return 0; | 136 unsigned long buf_size) { |
129 » if (name.GetLength() >= (long)buf_size) return name.GetLength() + 1; | 137 CFX_ByteString name; |
130 » FXSYS_strcpy(buffer, name); | 138 if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis) |
131 » return name.GetLength() + 1; | 139 ->m_pFontInfo->GetFaceName(hFont, name)) |
| 140 return 0; |
| 141 if (name.GetLength() >= (long)buf_size) |
| 142 return name.GetLength() + 1; |
| 143 FXSYS_strcpy(buffer, name); |
| 144 return name.GetLength() + 1; |
132 } | 145 } |
133 | 146 |
134 static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont) | 147 static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont) { |
135 { | 148 int charset; |
136 » int charset; | 149 if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis) |
137 » if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFontCharset(hFo
nt, charset)) return 0; | 150 ->m_pFontInfo->GetFontCharset(hFont, charset)) |
138 » return charset; | 151 return 0; |
| 152 return charset; |
139 } | 153 } |
140 | 154 |
141 static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) | 155 static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) { |
142 { | 156 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->DeleteFont(hFont); |
143 » ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->DeleteFont(hFont); | |
144 } | 157 } |
145 | 158 |
146 DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() | 159 DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() { |
147 { | 160 IFX_SystemFontInfo* pFontInfo = IFX_SystemFontInfo::CreateDefault(); |
148 » IFX_SystemFontInfo* pFontInfo = IFX_SystemFontInfo::CreateDefault(); | 161 if (pFontInfo == NULL) |
149 » if (pFontInfo == NULL) return NULL; | 162 return NULL; |
150 | 163 |
151 » FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt = FX_Alloc(FPDF_SYSFONTINFO_DEFAU
LT, 1); | 164 FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt = |
152 » pFontInfoExt->DeleteFont = DefaultDeleteFont; | 165 FX_Alloc(FPDF_SYSFONTINFO_DEFAULT, 1); |
153 » pFontInfoExt->EnumFonts = DefaultEnumFonts; | 166 pFontInfoExt->DeleteFont = DefaultDeleteFont; |
154 » pFontInfoExt->GetFaceName = DefaultGetFaceName; | 167 pFontInfoExt->EnumFonts = DefaultEnumFonts; |
155 » pFontInfoExt->GetFont = DefaultGetFont; | 168 pFontInfoExt->GetFaceName = DefaultGetFaceName; |
156 » pFontInfoExt->GetFontCharset = DefaultGetFontCharset; | 169 pFontInfoExt->GetFont = DefaultGetFont; |
157 » pFontInfoExt->GetFontData = DefaultGetFontData; | 170 pFontInfoExt->GetFontCharset = DefaultGetFontCharset; |
158 » pFontInfoExt->MapFont = DefaultMapFont; | 171 pFontInfoExt->GetFontData = DefaultGetFontData; |
159 » pFontInfoExt->Release = DefaultRelease; | 172 pFontInfoExt->MapFont = DefaultMapFont; |
160 » pFontInfoExt->version = 1; | 173 pFontInfoExt->Release = DefaultRelease; |
161 » pFontInfoExt->m_pFontInfo = pFontInfo; | 174 pFontInfoExt->version = 1; |
162 » return pFontInfoExt; | 175 pFontInfoExt->m_pFontInfo = pFontInfo; |
| 176 return pFontInfoExt; |
163 } | 177 } |
OLD | NEW |