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> | 9 #include <memory> |
10 | 10 |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 #include "core/fxge/include/cfx_fontmapper.h" | 12 #include "core/fxge/include/cfx_fontmapper.h" |
13 #include "core/fxge/include/cfx_fontmgr.h" | 13 #include "core/fxge/include/cfx_fontmgr.h" |
14 #include "core/fxge/include/cfx_gemodule.h" | 14 #include "core/fxge/include/cfx_gemodule.h" |
15 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 15 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
16 #include "fpdfsdk/include/cpdfsdk_annot.h" | 16 #include "fpdfsdk/include/cpdfsdk_annot.h" |
17 #include "fpdfsdk/include/cpdfsdk_document.h" | 17 #include "fpdfsdk/include/cpdfsdk_document.h" |
18 #include "fpdfsdk/include/cpdfsdk_environment.h" | 18 #include "fpdfsdk/include/cpdfsdk_environment.h" |
19 #include "fpdfsdk/include/cpdfsdk_pageview.h" | 19 #include "fpdfsdk/include/cpdfsdk_pageview.h" |
| 20 #include "fpdfsdk/include/cpdfsdk_widget.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 int CharSet2CP(int charset) { | 24 int CharSet2CP(int charset) { |
24 if (charset == FXFONT_SHIFTJIS_CHARSET) | 25 if (charset == FXFONT_SHIFTJIS_CHARSET) |
25 return 932; | 26 return 932; |
26 if (charset == FXFONT_GB2312_CHARSET) | 27 if (charset == FXFONT_GB2312_CHARSET) |
27 return 936; | 28 return 936; |
28 if (charset == FXFONT_HANGEUL_CHARSET) | 29 if (charset == FXFONT_HANGEUL_CHARSET) |
29 return 949; | 30 return 949; |
30 if (charset == FXFONT_CHINESEBIG5_CHARSET) | 31 if (charset == FXFONT_CHINESEBIG5_CHARSET) |
31 return 950; | 32 return 950; |
32 return 0; | 33 return 0; |
33 } | 34 } |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
37 void CFX_SystemHandler::SetCursor(int32_t nCursorType) { | 38 void CFX_SystemHandler::InvalidateRect(CPDFSDK_Widget* widget, FX_RECT rect) { |
38 m_pEnv->SetCursor(nCursorType); | 39 CPDFSDK_PageView* pPageView = widget->GetPageView(); |
39 } | 40 UnderlyingPageType* pPage = widget->GetUnderlyingPage(); |
40 | |
41 void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) { | |
42 CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; | |
43 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); | |
44 UnderlyingPageType* pPage = pSDKAnnot->GetUnderlyingPage(); | |
45 if (!pPage || !pPageView) | 41 if (!pPage || !pPageView) |
46 return; | 42 return; |
47 | 43 |
48 CFX_Matrix page2device; | 44 CFX_Matrix page2device; |
49 pPageView->GetCurrentMatrix(page2device); | 45 pPageView->GetCurrentMatrix(page2device); |
| 46 |
50 CFX_Matrix device2page; | 47 CFX_Matrix device2page; |
51 device2page.SetReverse(page2device); | 48 device2page.SetReverse(page2device); |
52 FX_FLOAT left, top, right, bottom; | 49 |
53 device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top); | 50 FX_FLOAT left; |
54 device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, | 51 FX_FLOAT top; |
55 bottom); | 52 FX_FLOAT right; |
| 53 FX_FLOAT bottom; |
| 54 device2page.Transform(static_cast<FX_FLOAT>(rect.left), |
| 55 static_cast<FX_FLOAT>(rect.top), left, top); |
| 56 device2page.Transform(static_cast<FX_FLOAT>(rect.right), |
| 57 static_cast<FX_FLOAT>(rect.bottom), right, bottom); |
56 CFX_FloatRect rcPDF(left, bottom, right, top); | 58 CFX_FloatRect rcPDF(left, bottom, right, top); |
57 rcPDF.Normalize(); | 59 rcPDF.Normalize(); |
58 | 60 |
59 m_pEnv->Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom); | 61 m_pEnv->Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom); |
60 } | 62 } |
61 | 63 |
62 void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, | 64 void CFX_SystemHandler::OutputSelectedRect(CFFL_FormFiller* pFormFiller, |
63 CFX_FloatRect& rect) { | 65 CFX_FloatRect& rect) { |
64 CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller; | 66 if (!pFormFiller) |
65 if (!pFFL) | |
66 return; | 67 return; |
67 | 68 |
68 CFX_FloatPoint leftbottom = CFX_FloatPoint(rect.left, rect.bottom); | 69 CFX_FloatPoint leftbottom = CFX_FloatPoint(rect.left, rect.bottom); |
69 CFX_FloatPoint righttop = CFX_FloatPoint(rect.right, rect.top); | 70 CFX_FloatPoint righttop = CFX_FloatPoint(rect.right, rect.top); |
70 CFX_FloatPoint ptA = pFFL->PWLtoFFL(leftbottom); | 71 CFX_FloatPoint ptA = pFormFiller->PWLtoFFL(leftbottom); |
71 CFX_FloatPoint ptB = pFFL->PWLtoFFL(righttop); | 72 CFX_FloatPoint ptB = pFormFiller->PWLtoFFL(righttop); |
72 CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); | 73 |
| 74 CPDFSDK_Annot* pAnnot = pFormFiller->GetSDKAnnot(); |
73 UnderlyingPageType* pPage = pAnnot->GetUnderlyingPage(); | 75 UnderlyingPageType* pPage = pAnnot->GetUnderlyingPage(); |
74 ASSERT(pPage); | 76 ASSERT(pPage); |
75 | 77 |
76 m_pEnv->OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); | 78 m_pEnv->OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); |
77 } | 79 } |
78 | 80 |
79 bool CFX_SystemHandler::IsSelectionImplemented() const { | 81 bool CFX_SystemHandler::IsSelectionImplemented() const { |
80 if (m_pEnv) { | 82 if (!m_pEnv) |
81 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); | 83 return false; |
82 if (pInfo && pInfo->FFI_OutputSelectedRect) | 84 |
83 return true; | 85 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); |
84 } | 86 return pInfo && pInfo->FFI_OutputSelectedRect; |
85 return false; | 87 } |
| 88 |
| 89 void CFX_SystemHandler::SetCursor(int32_t nCursorType) { |
| 90 m_pEnv->SetCursor(nCursorType); |
86 } | 91 } |
87 | 92 |
88 bool CFX_SystemHandler::FindNativeTrueTypeFont(CFX_ByteString sFontFaceName) { | 93 bool CFX_SystemHandler::FindNativeTrueTypeFont(CFX_ByteString sFontFaceName) { |
89 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 94 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
90 if (!pFontMgr) | 95 if (!pFontMgr) |
91 return false; | 96 return false; |
92 | 97 |
93 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); | 98 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); |
94 if (!pFontMapper) | 99 if (!pFontMapper) |
95 return false; | 100 return false; |
96 | 101 |
97 if (pFontMapper->m_InstalledTTFonts.empty()) | 102 if (pFontMapper->m_InstalledTTFonts.empty()) |
98 pFontMapper->LoadInstalledFonts(); | 103 pFontMapper->LoadInstalledFonts(); |
99 | 104 |
100 for (const auto& font : pFontMapper->m_InstalledTTFonts) { | 105 for (const auto& font : pFontMapper->m_InstalledTTFonts) { |
101 if (font.Compare(sFontFaceName.AsStringC())) | 106 if (font.Compare(sFontFaceName.AsStringC())) |
102 return true; | 107 return true; |
103 } | 108 } |
104 | |
105 return false; | 109 return false; |
106 } | 110 } |
107 | 111 |
108 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( | 112 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( |
109 CPDF_Document* pDoc, | 113 CPDF_Document* pDoc, |
110 CFX_ByteString sFontFaceName, | 114 CFX_ByteString sFontFaceName, |
111 uint8_t nCharset) { | 115 uint8_t nCharset) { |
112 if (!pDoc) | 116 if (!pDoc) |
113 return nullptr; | 117 return nullptr; |
114 | 118 |
115 std::unique_ptr<CFX_Font> pFXFont(new CFX_Font); | 119 std::unique_ptr<CFX_Font> pFXFont(new CFX_Font); |
116 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), FALSE); | 120 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), FALSE); |
117 return pDoc->AddFont(pFXFont.get(), nCharset, FALSE); | 121 return pDoc->AddFont(pFXFont.get(), nCharset, FALSE); |
118 } | 122 } |
119 | 123 |
120 int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, | 124 int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, |
121 TimerCallback lpTimerFunc) { | 125 TimerCallback lpTimerFunc) { |
122 return m_pEnv->SetTimer(uElapse, lpTimerFunc); | 126 return m_pEnv->SetTimer(uElapse, lpTimerFunc); |
123 } | 127 } |
124 | 128 |
125 void CFX_SystemHandler::KillTimer(int32_t nID) { | 129 void CFX_SystemHandler::KillTimer(int32_t nID) { |
126 m_pEnv->KillTimer(nID); | 130 m_pEnv->KillTimer(nID); |
127 } | 131 } |
128 | 132 |
129 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { | |
130 return m_pEnv->GetLocalTime(); | |
131 } | |
132 | |
133 bool CFX_SystemHandler::IsSHIFTKeyDown(uint32_t nFlag) const { | 133 bool CFX_SystemHandler::IsSHIFTKeyDown(uint32_t nFlag) const { |
134 return !!m_pEnv->IsSHIFTKeyDown(nFlag); | 134 return !!m_pEnv->IsSHIFTKeyDown(nFlag); |
135 } | 135 } |
136 | 136 |
137 bool CFX_SystemHandler::IsCTRLKeyDown(uint32_t nFlag) const { | 137 bool CFX_SystemHandler::IsCTRLKeyDown(uint32_t nFlag) const { |
138 return !!m_pEnv->IsCTRLKeyDown(nFlag); | 138 return !!m_pEnv->IsCTRLKeyDown(nFlag); |
139 } | 139 } |
140 | 140 |
141 bool CFX_SystemHandler::IsALTKeyDown(uint32_t nFlag) const { | 141 bool CFX_SystemHandler::IsALTKeyDown(uint32_t nFlag) const { |
142 return !!m_pEnv->IsALTKeyDown(nFlag); | 142 return !!m_pEnv->IsALTKeyDown(nFlag); |
143 } | 143 } |
OLD | NEW |