OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "fpdfsdk/cfx_systemhandler.h" | 7 #include "fpdfsdk/cfx_systemhandler.h" |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "core/fxge/include/fx_ge.h" | 11 #include "core/fxge/include/fx_ge.h" |
10 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 12 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
11 #include "fpdfsdk/include/fsdk_mgr.h" | 13 #include "fpdfsdk/include/fsdk_mgr.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 int CharSet2CP(int charset) { | 17 int CharSet2CP(int charset) { |
16 if (charset == 128) | 18 if (charset == FXFONT_SHIFTJIS_CHARSET) |
17 return 932; | 19 return 932; |
18 if (charset == 134) | 20 if (charset == FXFONT_GB2312_CHARSET) |
19 return 936; | 21 return 936; |
20 if (charset == 129) | 22 if (charset == FXFONT_HANGEUL_CHARSET) |
21 return 949; | 23 return 949; |
22 if (charset == 136) | 24 if (charset == FXFONT_CHINESEBIG5_CHARSET) |
23 return 950; | 25 return 950; |
24 return 0; | 26 return 0; |
25 } | 27 } |
26 | 28 |
27 } // namespace | 29 } // namespace |
28 | 30 |
29 void CFX_SystemHandler::SetCursor(int32_t nCursorType) { | 31 void CFX_SystemHandler::SetCursor(int32_t nCursorType) { |
30 m_pEnv->FFI_SetCursor(nCursorType); | 32 m_pEnv->FFI_SetCursor(nCursorType); |
31 } | 33 } |
32 | 34 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 73 |
72 bool CFX_SystemHandler::IsSelectionImplemented() const { | 74 bool CFX_SystemHandler::IsSelectionImplemented() const { |
73 if (m_pEnv) { | 75 if (m_pEnv) { |
74 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); | 76 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); |
75 if (pInfo && pInfo->FFI_OutputSelectedRect) | 77 if (pInfo && pInfo->FFI_OutputSelectedRect) |
76 return true; | 78 return true; |
77 } | 79 } |
78 return false; | 80 return false; |
79 } | 81 } |
80 | 82 |
81 bool CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, | 83 bool CFX_SystemHandler::FindNativeTrueTypeFont(CFX_ByteString sFontFaceName) { |
82 CFX_ByteString sFontFaceName) { | |
83 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 84 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
84 if (!pFontMgr) | 85 if (!pFontMgr) |
85 return false; | 86 return false; |
86 | 87 |
87 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 88 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
88 if (!pFontMapper) | 89 if (!pFontMapper) |
89 return false; | 90 return false; |
90 | 91 |
91 if (pFontMapper->m_InstalledTTFonts.empty()) | 92 if (pFontMapper->m_InstalledTTFonts.empty()) |
92 pFontMapper->LoadInstalledFonts(); | 93 pFontMapper->LoadInstalledFonts(); |
93 | 94 |
94 for (const auto& font : pFontMapper->m_InstalledTTFonts) { | 95 for (const auto& font : pFontMapper->m_InstalledTTFonts) { |
95 if (font.Compare(sFontFaceName.AsStringC())) | 96 if (font.Compare(sFontFaceName.AsStringC())) |
96 return true; | 97 return true; |
97 } | 98 } |
98 | 99 |
99 return false; | 100 return false; |
100 } | 101 } |
101 | 102 |
102 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( | 103 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( |
103 CPDF_Document* pDoc, | 104 CPDF_Document* pDoc, |
104 CFX_ByteString sFontFaceName, | 105 CFX_ByteString sFontFaceName, |
105 uint8_t nCharset) { | 106 uint8_t nCharset) { |
106 if (!pDoc) | 107 if (!pDoc) |
107 return nullptr; | 108 return nullptr; |
108 | 109 |
109 CFX_Font* pFXFont = new CFX_Font(); | 110 std::unique_ptr<CFX_Font> pFXFont(new CFX_Font); |
110 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), FALSE); | 111 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), FALSE); |
111 CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE); | 112 return pDoc->AddFont(pFXFont.get(), nCharset, FALSE); |
112 delete pFXFont; | |
113 return pFont; | |
114 } | 113 } |
115 | 114 |
116 int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, | 115 int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, |
117 TimerCallback lpTimerFunc) { | 116 TimerCallback lpTimerFunc) { |
118 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); | 117 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); |
119 } | 118 } |
120 | 119 |
121 void CFX_SystemHandler::KillTimer(int32_t nID) { | 120 void CFX_SystemHandler::KillTimer(int32_t nID) { |
122 m_pEnv->FFI_KillTimer(nID); | 121 m_pEnv->FFI_KillTimer(nID); |
123 } | 122 } |
124 | 123 |
125 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { | 124 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { |
126 return m_pEnv->FFI_GetLocalTime(); | 125 return m_pEnv->FFI_GetLocalTime(); |
127 } | 126 } |
128 | 127 |
129 bool CFX_SystemHandler::IsSHIFTKeyDown(uint32_t nFlag) const { | 128 bool CFX_SystemHandler::IsSHIFTKeyDown(uint32_t nFlag) const { |
130 return !!m_pEnv->FFI_IsSHIFTKeyDown(nFlag); | 129 return !!m_pEnv->FFI_IsSHIFTKeyDown(nFlag); |
131 } | 130 } |
132 | 131 |
133 bool CFX_SystemHandler::IsCTRLKeyDown(uint32_t nFlag) const { | 132 bool CFX_SystemHandler::IsCTRLKeyDown(uint32_t nFlag) const { |
134 return !!m_pEnv->FFI_IsCTRLKeyDown(nFlag); | 133 return !!m_pEnv->FFI_IsCTRLKeyDown(nFlag); |
135 } | 134 } |
136 | 135 |
137 bool CFX_SystemHandler::IsALTKeyDown(uint32_t nFlag) const { | 136 bool CFX_SystemHandler::IsALTKeyDown(uint32_t nFlag) const { |
138 return !!m_pEnv->FFI_IsALTKeyDown(nFlag); | 137 return !!m_pEnv->FFI_IsALTKeyDown(nFlag); |
139 } | 138 } |
OLD | NEW |