1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../include/fsdk_define.h"
8 #include "../include/fpdf_sysfontinfo.h"
10 class CSysFontInfo_Ext FX_FINAL : public IFX_SystemFontInfo
13 FPDF_SYSFONTINFO* m_pInfo;
15 virtual void Release() FX_OVERRIDE
18 m_pInfo->Release(m_pInfo);
22 virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) FX_OVERRIDE
24 if (m_pInfo->EnumFonts) {
25 m_pInfo->EnumFonts(m_pInfo, pMapper);
31 virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact) FX_OVERRIDE
34 return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family, family, &bExact);
38 virtual void* GetFont(FX_LPCSTR family) FX_OVERRIDE
41 return m_pInfo->GetFont(m_pInfo, family);
45 virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size) FX_OVERRIDE
47 if (m_pInfo->GetFontData)
48 return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size);
52 virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) FX_OVERRIDE
54 if (m_pInfo->GetFaceName == NULL) return FALSE;
55 FX_DWORD size = m_pInfo->GetFaceName(m_pInfo, hFont, NULL, 0);
56 if (size == 0) return FALSE;
57 char* buffer = FX_Alloc(char, size);
58 size = m_pInfo->GetFaceName(m_pInfo, hFont, buffer, size);
59 name = CFX_ByteString(buffer, size);
64 virtual FX_BOOL GetFontCharset(void* hFont, int& charset) FX_OVERRIDE
66 if (m_pInfo->GetFontCharset) {
67 charset = m_pInfo->GetFontCharset(m_pInfo, hFont);
73 virtual void DeleteFont(void* hFont) FX_OVERRIDE
75 if (m_pInfo->DeleteFont)
76 m_pInfo->DeleteFont(m_pInfo, hFont);
80 DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper, const char* name, int charset)
82 ((CFX_FontMapper*)mapper)->AddInstalledFont(name, charset);
85 DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt)
87 if (pFontInfoExt->version != 1) return;
89 CSysFontInfo_Ext* pFontInfo = FX_NEW CSysFontInfo_Ext;
90 pFontInfo->m_pInfo = pFontInfoExt;
91 CFX_GEModule::Get()->GetFontMgr()->SetSystemFontInfo(pFontInfo);
94 struct FPDF_SYSFONTINFO_DEFAULT : public FPDF_SYSFONTINFO
96 IFX_SystemFontInfo* m_pFontInfo;
99 static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis)
101 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->Release();
104 static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper)
106 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->EnumFontList((CFX_FontMapper*)pMapper);
109 static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, int weight, int bItalic, int charset, int pitch_family, const char* family, int* bExact)
111 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->MapFont(weight, bItalic, charset, pitch_family, family, *bExact);
114 void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family)
116 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFont(family);
119 static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, void* hFont,
120 unsigned int table, unsigned char* buffer, unsigned long buf_size)
122 return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFontData(hFont, table, buffer, buf_size);
125 static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, void* hFont, char* buffer, unsigned long buf_size)
128 if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFaceName(hFont, name)) return 0;
129 if (name.GetLength() >= (long)buf_size) return name.GetLength() + 1;
130 FXSYS_strcpy(buffer, name);
131 return name.GetLength() + 1;
134 static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont)
137 if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFontCharset(hFont, charset)) return 0;
141 static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont)
143 ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->DeleteFont(hFont);
146 DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo()
148 IFX_SystemFontInfo* pFontInfo = IFX_SystemFontInfo::CreateDefault();
149 if (pFontInfo == NULL) return NULL;
151 FPDF_SYSFONTINFO_DEFAULT* pFontInfoExt = FX_Alloc(FPDF_SYSFONTINFO_DEFAULT, 1);
152 pFontInfoExt->DeleteFont = DefaultDeleteFont;
153 pFontInfoExt->EnumFonts = DefaultEnumFonts;
154 pFontInfoExt->GetFaceName = DefaultGetFaceName;
155 pFontInfoExt->GetFont = DefaultGetFont;
156 pFontInfoExt->GetFontCharset = DefaultGetFontCharset;
157 pFontInfoExt->GetFontData = DefaultGetFontData;
158 pFontInfoExt->MapFont = DefaultMapFont;
159 pFontInfoExt->Release = DefaultRelease;
160 pFontInfoExt->version = 1;
161 pFontInfoExt->m_pFontInfo = pFontInfo;