Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: fpdfsdk/src/fpdf_sysfontinfo.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../../public/fpdf_sysfontinfo.h" 7 #include "../../public/fpdf_sysfontinfo.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 #include "../include/pdfwindow/PWL_FontMap.h" 9 #include "../include/pdfwindow/PWL_FontMap.h"
10 10
11 class CFX_ExternalFontInfo final : public IFX_SystemFontInfo 11 class CFX_ExternalFontInfo final : public IFX_SystemFontInfo {
12 { 12 public:
13 public: 13 CFX_ExternalFontInfo(FPDF_SYSFONTINFO* pInfo) : m_pInfo(pInfo) {}
14 » CFX_ExternalFontInfo(FPDF_SYSFONTINFO* pInfo) : m_pInfo(pInfo) { }
15 14
16 » virtual void» » Release() override 15 virtual void Release() override {
17 » { 16 if (m_pInfo->Release)
18 » » if (m_pInfo->Release) 17 m_pInfo->Release(m_pInfo);
19 » » » m_pInfo->Release(m_pInfo); 18 delete this;
20 » » delete this; 19 }
21 » }
22 20
23 » virtual»FX_BOOL»» EnumFontList(CFX_FontMapper* pMapper) override 21 virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override {
24 » { 22 if (m_pInfo->EnumFonts) {
25 » » if (m_pInfo->EnumFonts) { 23 m_pInfo->EnumFonts(m_pInfo, pMapper);
26 » » » m_pInfo->EnumFonts(m_pInfo, pMapper); 24 return TRUE;
27 » » » return TRUE; 25 }
28 » » } 26 return FALSE;
29 » » return FALSE; 27 }
30 » }
31 28
32 » virtual void*» » MapFont(int weight, FX_BOOL bItalic, int charset , int pitch_family, const FX_CHAR* family, int& iExact) override 29 virtual void* MapFont(int weight,
33 » { 30 FX_BOOL bItalic,
34 » » if (m_pInfo->MapFont) 31 int charset,
35 » » » return m_pInfo->MapFont(m_pInfo, weight, bItalic, charse t, pitch_family, family, &iExact); 32 int pitch_family,
36 » » return NULL; 33 const FX_CHAR* family,
37 » } 34 int& iExact) override {
35 if (m_pInfo->MapFont)
36 return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family,
37 family, &iExact);
38 return NULL;
39 }
38 40
39 » virtual void*» » GetFont(const FX_CHAR* family) override 41 virtual void* GetFont(const FX_CHAR* family) override {
40 » { 42 if (m_pInfo->GetFont)
41 » » if (m_pInfo->GetFont) 43 return m_pInfo->GetFont(m_pInfo, family);
42 » » » return m_pInfo->GetFont(m_pInfo, family); 44 return NULL;
43 » » return NULL; 45 }
44 » }
45 46
46 » virtual FX_DWORD» GetFontData(void* hFont, FX_DWORD table, uint8_t * buffer, FX_DWORD size) override 47 virtual FX_DWORD GetFontData(void* hFont,
47 » { 48 FX_DWORD table,
48 » » if (m_pInfo->GetFontData) 49 uint8_t* buffer,
49 » » » return m_pInfo->GetFontData(m_pInfo, hFont, table, buffe r, size); 50 FX_DWORD size) override {
50 » » return 0; 51 if (m_pInfo->GetFontData)
51 » } 52 return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size);
53 return 0;
54 }
52 55
53 » virtual FX_BOOL»» GetFaceName(void* hFont, CFX_ByteString& name) override 56 virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override {
54 » { 57 if (m_pInfo->GetFaceName == NULL)
55 » » if (m_pInfo->GetFaceName == NULL) return FALSE; 58 return FALSE;
56 » » FX_DWORD size = m_pInfo->GetFaceName(m_pInfo, hFont, NULL, 0); 59 FX_DWORD size = m_pInfo->GetFaceName(m_pInfo, hFont, NULL, 0);
57 » » if (size == 0) return FALSE; 60 if (size == 0)
58 » » char* buffer = FX_Alloc(char, size); 61 return FALSE;
59 » » size = m_pInfo->GetFaceName(m_pInfo, hFont, buffer, size); 62 char* buffer = FX_Alloc(char, size);
60 » » name = CFX_ByteString(buffer, size); 63 size = m_pInfo->GetFaceName(m_pInfo, hFont, buffer, size);
61 » » FX_Free(buffer); 64 name = CFX_ByteString(buffer, size);
62 » » return TRUE; 65 FX_Free(buffer);
63 » } 66 return TRUE;
67 }
64 68
65 » virtual FX_BOOL»» GetFontCharset(void* hFont, int& charset) overr ide 69 virtual FX_BOOL GetFontCharset(void* hFont, int& charset) override {
66 » { 70 if (m_pInfo->GetFontCharset) {
67 » » if (m_pInfo->GetFontCharset) { 71 charset = m_pInfo->GetFontCharset(m_pInfo, hFont);
68 » » » charset = m_pInfo->GetFontCharset(m_pInfo, hFont); 72 return TRUE;
69 » » » return TRUE; 73 }
70 » » } 74 return FALSE;
71 » » return FALSE; 75 }
72 » }
73 76
74 » virtual void» » DeleteFont(void* hFont) override 77 virtual void DeleteFont(void* hFont) override {
75 » { 78 if (m_pInfo->DeleteFont)
76 » » if (m_pInfo->DeleteFont) 79 m_pInfo->DeleteFont(m_pInfo, hFont);
77 » » » m_pInfo->DeleteFont(m_pInfo, hFont); 80 }
78 » }
79 81
80 private: 82 private:
81 » ~CFX_ExternalFontInfo() { } 83 ~CFX_ExternalFontInfo() {}
82 84
83 » FPDF_SYSFONTINFO* const m_pInfo; 85 FPDF_SYSFONTINFO* const m_pInfo;
84 }; 86 };
85 87
86 DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper, const char* name, int charset) 88 DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper,
87 { 89 const char* name,
88 » ((CFX_FontMapper*)mapper)->AddInstalledFont(name, charset); 90 int charset) {
91 ((CFX_FontMapper*)mapper)->AddInstalledFont(name, charset);
89 } 92 }
90 93
91 DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) 94 DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) {
92 { 95 if (pFontInfoExt->version != 1)
93 » if (pFontInfoExt->version != 1) 96 return;
94 » » return;
95 97
96 » CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo( 98 CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(
97 » » new CFX_ExternalFontInfo(pFontInfoExt)); 99 new CFX_ExternalFontInfo(pFontInfoExt));
98 } 100 }
99 101
100 DLLEXPORT const FPDF_CharsetFontMap* STDCALL FPDF_GetDefaultTTFMap() 102 DLLEXPORT const FPDF_CharsetFontMap* STDCALL FPDF_GetDefaultTTFMap() {
101 { 103 return CPWL_FontMap::defaultTTFMap;
102 return CPWL_FontMap::defaultTTFMap;
103 } 104 }
104 105
105 struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO 106 struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO {
106 { 107 IFX_SystemFontInfo* m_pFontInfo;
107 » IFX_SystemFontInfo*» m_pFontInfo;
108 }; 108 };
109 109
110 static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) 110 static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) {
111 { 111 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->Release();
112 » ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->Release();
113 } 112 }
114 113
115 static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) 114 static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) {
116 { 115 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)
117 » ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->EnumFontList((CFX_FontM apper*)pMapper); 116 ->m_pFontInfo->EnumFontList((CFX_FontMapper*)pMapper);
118 } 117 }
119 118
120 static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, int weight, int bIt alic, int charset, int pitch_family, const char* family, int* bExact) 119 static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis,
121 { 120 int weight,
122 » return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->MapFont(weight, bItalic, charset, pitch_family, family, *bExact); 121 int bItalic,
122 int charset,
123 int pitch_family,
124 const char* family,
125 int* bExact) {
126 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)
127 ->m_pFontInfo->MapFont(weight, bItalic, charset, pitch_family, family,
128 *bExact);
123 } 129 }
124 130
125 void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) 131 void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) {
126 { 132 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFont(family);
127 » return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFont(family);
128 } 133 }
129 134
130 static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, void* h Font, 135 static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis,
131 » » » unsigned int table, unsigned char* buffer, unsigned long buf_size) 136 void* hFont,
132 { 137 unsigned int table,
133 » return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFontData(hFon t, table, buffer, buf_size); 138 unsigned char* buffer,
139 unsigned long buf_size) {
140 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)
141 ->m_pFontInfo->GetFontData(hFont, table, buffer, buf_size);
134 } 142 }
135 143
136 static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, void* h Font, char* buffer, unsigned long buf_size) 144 static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis,
137 { 145 void* hFont,
138 » CFX_ByteString name; 146 char* buffer,
139 » if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFaceName(hFont, name)) return 0; 147 unsigned long buf_size) {
140 » if (name.GetLength() >= (long)buf_size) return name.GetLength() + 1; 148 CFX_ByteString name;
141 » FXSYS_strcpy(buffer, name); 149 if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)
142 » return name.GetLength() + 1; 150 ->m_pFontInfo->GetFaceName(hFont, name))
151 return 0;
152 if (name.GetLength() >= (long)buf_size)
153 return name.GetLength() + 1;
154 FXSYS_strcpy(buffer, name);
155 return name.GetLength() + 1;
143 } 156 }
144 157
145 static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont) 158 static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont) {
146 { 159 int charset;
147 » int charset; 160 if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)
148 » if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFontCharset(hFo nt, charset)) return 0; 161 ->m_pFontInfo->GetFontCharset(hFont, charset))
149 » return charset; 162 return 0;
163 return charset;
150 } 164 }
151 165
152 static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) 166 static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) {
153 { 167 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->DeleteFont(hFont);
154 » ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->DeleteFont(hFont);
155 } 168 }
156 169
157 DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() 170 DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() {
158 { 171 IFX_SystemFontInfo* pFontInfo = IFX_SystemFontInfo::CreateDefault();
159 » IFX_SystemFontInfo* pFontInfo = IFX_SystemFontInfo::CreateDefault(); 172 if (pFontInfo == NULL)
160 » if (pFontInfo == NULL) return NULL; 173 return NULL;
161 174
162 » FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt = FX_Alloc(FPDF_SYSFONTINFO_DEFAU LT, 1); 175 FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt =
163 » pFontInfoExt->DeleteFont = DefaultDeleteFont; 176 FX_Alloc(FPDF_SYSFONTINFO_DEFAULT, 1);
164 » pFontInfoExt->EnumFonts = DefaultEnumFonts; 177 pFontInfoExt->DeleteFont = DefaultDeleteFont;
165 » pFontInfoExt->GetFaceName = DefaultGetFaceName; 178 pFontInfoExt->EnumFonts = DefaultEnumFonts;
166 » pFontInfoExt->GetFont = DefaultGetFont; 179 pFontInfoExt->GetFaceName = DefaultGetFaceName;
167 » pFontInfoExt->GetFontCharset = DefaultGetFontCharset; 180 pFontInfoExt->GetFont = DefaultGetFont;
168 » pFontInfoExt->GetFontData = DefaultGetFontData; 181 pFontInfoExt->GetFontCharset = DefaultGetFontCharset;
169 » pFontInfoExt->MapFont = DefaultMapFont; 182 pFontInfoExt->GetFontData = DefaultGetFontData;
170 » pFontInfoExt->Release = DefaultRelease; 183 pFontInfoExt->MapFont = DefaultMapFont;
171 » pFontInfoExt->version = 1; 184 pFontInfoExt->Release = DefaultRelease;
172 » pFontInfoExt->m_pFontInfo = pFontInfo; 185 pFontInfoExt->version = 1;
173 » return pFontInfoExt; 186 pFontInfoExt->m_pFontInfo = pFontInfo;
187 return pFontInfoExt;
174 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698