Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpvt_fontmap.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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 "core/fpdfdoc/cpvt_fontmap.h"
8
9#include <utility>
10
11#include "core/fpdfapi/font/cpdf_font.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_document.h"
14#include "core/fpdfapi/parser/cpdf_reference.h"
15#include "core/fpdfapi/parser/fpdf_parser_utility.h"
16#include "core/fpdfdoc/cpdf_interactiveform.h"
17#include "core/fxcrt/fx_codepage.h"
18#include "third_party/base/check.h"
19#include "third_party/base/notreached.h"
20
21CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc,
22 RetainPtr<CPDF_Dictionary> pResDict,
23 RetainPtr<CPDF_Font> pDefFont,
24 const ByteString& sDefFontAlias)
29
30CPVT_FontMap::~CPVT_FontMap() = default;
31
32void CPVT_FontMap::SetupAnnotSysPDFFont() {
33 if (!m_pDocument || !m_pResDict)
34 return;
35
36 RetainPtr<CPDF_Font> pPDFFont =
37 CPDF_InteractiveForm::AddNativeInteractiveFormFont(m_pDocument,
38 &m_sSysFontAlias);
39 if (!pPDFFont)
40 return;
41
42 RetainPtr<CPDF_Dictionary> pFontList = m_pResDict->GetMutableDictFor("Font");
43 if (ValidateFontResourceDict(pFontList.Get()) &&
44 !pFontList->KeyExist(m_sSysFontAlias)) {
45 pFontList->SetNewFor<CPDF_Reference>(m_sSysFontAlias, m_pDocument,
46 pPDFFont->GetFontDictObjNum());
47 }
48 m_pSysFont = std::move(pPDFFont);
49}
50
51RetainPtr<CPDF_Font> CPVT_FontMap::GetPDFFont(int32_t nFontIndex) {
52 switch (nFontIndex) {
53 case 0:
54 return m_pDefFont;
55 case 1:
56 if (!m_pSysFont)
57 SetupAnnotSysPDFFont();
58 return m_pSysFont;
59 default:
60 return nullptr;
61 }
62}
63
64ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
65 switch (nFontIndex) {
66 case 0:
67 return m_sDefFontAlias;
68 case 1:
69 if (!m_pSysFont)
70 SetupAnnotSysPDFFont();
71 return m_sSysFontAlias;
72 default:
73 return ByteString();
74 }
75}
76
77int32_t CPVT_FontMap::GetWordFontIndex(uint16_t word,
78 FX_Charset charset,
79 int32_t nFontIndex) {
80 NOTREACHED_NORETURN();
81}
82
83int32_t CPVT_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
84 NOTREACHED_NORETURN();
85}
86
87FX_Charset CPVT_FontMap::CharSetFromUnicode(uint16_t word,
88 FX_Charset nOldCharset) {
89 NOTREACHED_NORETURN();
90}
ByteString GetPDFFontAlias(int32_t nFontIndex) override
RetainPtr< CPDF_Font > GetPDFFont(int32_t nFontIndex) override
int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override
CPVT_FontMap(CPDF_Document *pDoc, RetainPtr< CPDF_Dictionary > pResDict, RetainPtr< CPDF_Font > pDefFont, const ByteString &sDefFontAlias)
int32_t GetWordFontIndex(uint16_t word, FX_Charset charset, int32_t nFontIndex) override
FX_Charset CharSetFromUnicode(uint16_t word, FX_Charset nOldCharset) override
~CPVT_FontMap() override
FX_Charset
Definition fx_codepage.h:70