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