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 "fpdfsdk/include/fsdk_mgr.h" | 7 #include "fpdfsdk/include/fsdk_mgr.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "xfa/fxfa/include/xfa_rendercontext.h" | 26 #include "xfa/fxfa/include/xfa_rendercontext.h" |
27 #include "xfa/fxgraphics/include/cfx_graphics.h" | 27 #include "xfa/fxgraphics/include/cfx_graphics.h" |
28 #endif // PDF_ENABLE_XFA | 28 #endif // PDF_ENABLE_XFA |
29 | 29 |
30 #if _FX_OS_ == _FX_ANDROID_ | 30 #if _FX_OS_ == _FX_ANDROID_ |
31 #include "time.h" | 31 #include "time.h" |
32 #else | 32 #else |
33 #include <ctime> | 33 #include <ctime> |
34 #endif | 34 #endif |
35 | 35 |
36 namespace { | |
37 | |
38 int CharSet2CP(int charset) { | |
39 if (charset == 128) | |
40 return 932; | |
41 if (charset == 134) | |
42 return 936; | |
43 if (charset == 129) | |
44 return 949; | |
45 if (charset == 136) | |
46 return 950; | |
47 return 0; | |
48 } | |
49 | |
50 } // namespace | |
51 | |
52 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { | 36 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { |
53 return reinterpret_cast<FPDF_WIDESTRING>( | 37 return reinterpret_cast<FPDF_WIDESTRING>( |
54 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); | 38 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); |
55 } | 39 } |
56 | 40 |
57 class CFX_SystemHandler : public IFX_SystemHandler { | |
58 public: | |
59 explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) | |
60 : m_pEnv(pEnv), m_nCharSet(-1) {} | |
61 ~CFX_SystemHandler() override {} | |
62 | |
63 public: | |
64 // IFX_SystemHandler | |
65 void InvalidateRect(FX_HWND hWnd, FX_RECT rect) override; | |
66 void OutputSelectedRect(void* pFormFiller, CFX_FloatRect& rect) override; | |
67 FX_BOOL IsSelectionImplemented() override; | |
68 CFX_WideString GetClipboardText(FX_HWND hWnd) override { return L""; } | |
69 FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString str) override { | |
70 return FALSE; | |
71 } | |
72 void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) override {} | |
73 void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) override {} | |
74 void SetCursor(int32_t nCursorType) override; | |
75 FX_HMENU CreatePopupMenu() override { return NULL; } | |
76 FX_BOOL AppendMenuItem(FX_HMENU hMenu, | |
77 int32_t nIDNewItem, | |
78 CFX_WideString str) override { | |
79 return FALSE; | |
80 } | |
81 FX_BOOL EnableMenuItem(FX_HMENU hMenu, | |
82 int32_t nIDItem, | |
83 FX_BOOL bEnabled) override { | |
84 return FALSE; | |
85 } | |
86 int32_t TrackPopupMenu(FX_HMENU hMenu, | |
87 int32_t x, | |
88 int32_t y, | |
89 FX_HWND hParent) override { | |
90 return -1; | |
91 } | |
92 void DestroyMenu(FX_HMENU hMenu) override {} | |
93 CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset) override; | |
94 FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, | |
95 CFX_ByteString sFontFaceName) override; | |
96 CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, | |
97 CFX_ByteString sFontFaceName, | |
98 uint8_t nCharset) override; | |
99 int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) override; | |
100 void KillTimer(int32_t nID) override; | |
101 FX_BOOL IsSHIFTKeyDown(uint32_t nFlag) override { | |
102 return m_pEnv->FFI_IsSHIFTKeyDown(nFlag); | |
103 } | |
104 FX_BOOL IsCTRLKeyDown(uint32_t nFlag) override { | |
105 return m_pEnv->FFI_IsCTRLKeyDown(nFlag); | |
106 } | |
107 FX_BOOL IsALTKeyDown(uint32_t nFlag) override { | |
108 return m_pEnv->FFI_IsALTKeyDown(nFlag); | |
109 } | |
110 FX_BOOL IsINSERTKeyDown(uint32_t nFlag) override { | |
111 return m_pEnv->FFI_IsINSERTKeyDown(nFlag); | |
112 } | |
113 FX_SYSTEMTIME GetLocalTime() override; | |
114 int32_t GetCharSet() override { return m_nCharSet; } | |
115 void SetCharSet(int32_t nCharSet) override { m_nCharSet = nCharSet; } | |
116 | |
117 private: | |
118 CPDFDoc_Environment* m_pEnv; | |
119 int m_nCharSet; | |
120 }; | |
121 | |
122 void CFX_SystemHandler::SetCursor(int32_t nCursorType) { | |
123 m_pEnv->FFI_SetCursor(nCursorType); | |
124 } | |
125 | |
126 void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) { | |
127 CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; | |
128 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); | |
129 UnderlyingPageType* pPage = pSDKAnnot->GetUnderlyingPage(); | |
130 if (!pPage || !pPageView) | |
131 return; | |
132 CFX_Matrix page2device; | |
133 pPageView->GetCurrentMatrix(page2device); | |
134 CFX_Matrix device2page; | |
135 device2page.SetReverse(page2device); | |
136 FX_FLOAT left, top, right, bottom; | |
137 device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top); | |
138 device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, | |
139 bottom); | |
140 CFX_FloatRect rcPDF(left, bottom, right, top); | |
141 rcPDF.Normalize(); | |
142 | |
143 m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, | |
144 rcPDF.bottom); | |
145 } | |
146 void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, | |
147 CFX_FloatRect& rect) { | |
148 CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller; | |
149 if (pFFL) { | |
150 CFX_FloatPoint leftbottom = CFX_FloatPoint(rect.left, rect.bottom); | |
151 CFX_FloatPoint righttop = CFX_FloatPoint(rect.right, rect.top); | |
152 CFX_FloatPoint ptA = pFFL->PWLtoFFL(leftbottom); | |
153 CFX_FloatPoint ptB = pFFL->PWLtoFFL(righttop); | |
154 CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); | |
155 UnderlyingPageType* pPage = pAnnot->GetUnderlyingPage(); | |
156 ASSERT(pPage); | |
157 m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); | |
158 } | |
159 } | |
160 | |
161 FX_BOOL CFX_SystemHandler::IsSelectionImplemented() { | |
162 if (m_pEnv) { | |
163 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); | |
164 if (pInfo && pInfo->FFI_OutputSelectedRect) | |
165 return TRUE; | |
166 } | |
167 return FALSE; | |
168 } | |
169 | |
170 CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset) { | |
171 return ""; | |
172 } | |
173 | |
174 FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont( | |
175 int32_t nCharset, | |
176 CFX_ByteString sFontFaceName) { | |
177 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | |
178 if (!pFontMgr) | |
179 return FALSE; | |
180 | |
181 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | |
182 if (!pFontMapper) | |
183 return FALSE; | |
184 | |
185 if (pFontMapper->m_InstalledTTFonts.empty()) | |
186 pFontMapper->LoadInstalledFonts(); | |
187 | |
188 for (const auto& font : pFontMapper->m_InstalledTTFonts) { | |
189 if (font.Compare(sFontFaceName.AsStringC())) | |
190 return TRUE; | |
191 } | |
192 | |
193 return FALSE; | |
194 } | |
195 | |
196 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( | |
197 CPDF_Document* pDoc, | |
198 CFX_ByteString sFontFaceName, | |
199 uint8_t nCharset) { | |
200 if (pDoc) { | |
201 CFX_Font* pFXFont = new CFX_Font(); | |
202 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), | |
203 FALSE); | |
204 CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE); | |
205 delete pFXFont; | |
206 return pFont; | |
207 } | |
208 | |
209 return NULL; | |
210 } | |
211 | |
212 int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, | |
213 TimerCallback lpTimerFunc) { | |
214 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); | |
215 } | |
216 void CFX_SystemHandler::KillTimer(int32_t nID) { | |
217 m_pEnv->FFI_KillTimer(nID); | |
218 } | |
219 | |
220 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { | |
221 return m_pEnv->FFI_GetLocalTime(); | |
222 } | |
223 | |
224 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, | 41 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, |
225 FPDF_FORMFILLINFO* pFFinfo) | 42 FPDF_FORMFILLINFO* pFFinfo) |
226 : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pUnderlyingDoc(pDoc) { | 43 : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pUnderlyingDoc(pDoc) { |
227 m_pSysHandler.reset(new CFX_SystemHandler(this)); | 44 m_pSysHandler.reset(new CFX_SystemHandler(this)); |
228 } | 45 } |
229 | 46 |
230 CPDFDoc_Environment::~CPDFDoc_Environment() { | 47 CPDFDoc_Environment::~CPDFDoc_Environment() { |
231 #ifdef PDF_ENABLE_XFA | 48 #ifdef PDF_ENABLE_XFA |
232 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 49 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
233 if (pProvider->m_pEnvList.GetSize() == 0) | 50 if (pProvider->m_pEnvList.GetSize() == 0) |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); | 1015 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
1199 if (!pFocusAnnot) | 1016 if (!pFocusAnnot) |
1200 return nullptr; | 1017 return nullptr; |
1201 | 1018 |
1202 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 1019 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
1203 if (pAnnot == pFocusAnnot) | 1020 if (pAnnot == pFocusAnnot) |
1204 return pAnnot; | 1021 return pAnnot; |
1205 } | 1022 } |
1206 return nullptr; | 1023 return nullptr; |
1207 } | 1024 } |
OLD | NEW |