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