blob: c5f53341e18161a50424200d40ac529602c49696 [file] [log] [blame]
dsinclairb9590102016-04-27 06:38:59 -07001// Copyright 2016 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.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fpdfsdk/cfx_systemhandler.h"
8
9#include "fpdfsdk/formfiller/cffl_formfiller.h"
10#include "fpdfsdk/include/fsdk_mgr.h"
11
12namespace {
13
14int CharSet2CP(int charset) {
15 if (charset == 128)
16 return 932;
17 if (charset == 134)
18 return 936;
19 if (charset == 129)
20 return 949;
21 if (charset == 136)
22 return 950;
23 return 0;
24}
25
26} // namespace
27
28void CFX_SystemHandler::SetCursor(int32_t nCursorType) {
29 m_pEnv->FFI_SetCursor(nCursorType);
30}
31
32void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) {
33 CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;
34 CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
35 UnderlyingPageType* pPage = pSDKAnnot->GetUnderlyingPage();
36 if (!pPage || !pPageView)
37 return;
38
39 CFX_Matrix page2device;
40 pPageView->GetCurrentMatrix(page2device);
41 CFX_Matrix device2page;
42 device2page.SetReverse(page2device);
43 FX_FLOAT left, top, right, bottom;
44 device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top);
45 device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right,
46 bottom);
47 CFX_FloatRect rcPDF(left, bottom, right, top);
48 rcPDF.Normalize();
49
50 m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right,
51 rcPDF.bottom);
52}
53
54void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller,
55 CFX_FloatRect& rect) {
56 CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller;
57 if (!pFFL)
58 return;
59
60 CFX_FloatPoint leftbottom = CFX_FloatPoint(rect.left, rect.bottom);
61 CFX_FloatPoint righttop = CFX_FloatPoint(rect.right, rect.top);
62 CFX_FloatPoint ptA = pFFL->PWLtoFFL(leftbottom);
63 CFX_FloatPoint ptB = pFFL->PWLtoFFL(righttop);
64 CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot();
65 UnderlyingPageType* pPage = pAnnot->GetUnderlyingPage();
66 ASSERT(pPage);
67
68 m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);
69}
70
71bool CFX_SystemHandler::IsSelectionImplemented() const {
72 if (m_pEnv) {
73 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo();
74 if (pInfo && pInfo->FFI_OutputSelectedRect)
75 return true;
76 }
77 return false;
78}
79
80bool CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset,
81 CFX_ByteString sFontFaceName) {
82 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
83 if (!pFontMgr)
84 return false;
85
86 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
87 if (!pFontMapper)
88 return false;
89
90 if (pFontMapper->m_InstalledTTFonts.empty())
91 pFontMapper->LoadInstalledFonts();
92
93 for (const auto& font : pFontMapper->m_InstalledTTFonts) {
94 if (font.Compare(sFontFaceName.AsStringC()))
95 return true;
96 }
97
98 return false;
99}
100
101CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(
102 CPDF_Document* pDoc,
103 CFX_ByteString sFontFaceName,
104 uint8_t nCharset) {
105 if (!pDoc)
106 return nullptr;
107
108 CFX_Font* pFXFont = new CFX_Font();
109 pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), FALSE);
110 CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE);
111 delete pFXFont;
112 return pFont;
113}
114
115int32_t CFX_SystemHandler::SetTimer(int32_t uElapse,
116 TimerCallback lpTimerFunc) {
117 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
118}
119
120void CFX_SystemHandler::KillTimer(int32_t nID) {
121 m_pEnv->FFI_KillTimer(nID);
122}
123
124FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() {
125 return m_pEnv->FFI_GetLocalTime();
126}
127
128bool CFX_SystemHandler::IsSHIFTKeyDown(uint32_t nFlag) const {
dsinclair224bc5a2016-04-28 11:04:51 -0700129 return !!m_pEnv->FFI_IsSHIFTKeyDown(nFlag);
dsinclairb9590102016-04-27 06:38:59 -0700130}
131
132bool CFX_SystemHandler::IsCTRLKeyDown(uint32_t nFlag) const {
dsinclair224bc5a2016-04-28 11:04:51 -0700133 return !!m_pEnv->FFI_IsCTRLKeyDown(nFlag);
dsinclairb9590102016-04-27 06:38:59 -0700134}
135
136bool CFX_SystemHandler::IsALTKeyDown(uint32_t nFlag) const {
dsinclair224bc5a2016-04-28 11:04:51 -0700137 return !!m_pEnv->FFI_IsALTKeyDown(nFlag);
dsinclairb9590102016-04-27 06:38:59 -0700138}