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