summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_font
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/fpdf_font')
-rw-r--r--core/fpdfapi/fpdf_font/cpdf_font.cpp24
-rw-r--r--core/fpdfapi/fpdf_font/include/cpdf_font.h3
2 files changed, 27 insertions, 0 deletions
diff --git a/core/fpdfapi/fpdf_font/cpdf_font.cpp b/core/fpdfapi/fpdf_font/cpdf_font.cpp
index 8101bd49a6..4747093ac4 100644
--- a/core/fpdfapi/fpdf_font/cpdf_font.cpp
+++ b/core/fpdfapi/fpdf_font/cpdf_font.cpp
@@ -22,7 +22,9 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
#include "core/fpdfapi/include/cpdf_modulemgr.h"
+#include "core/fxcrt/include/fx_memory.h"
#include "core/fxge/include/fx_freetype.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -451,3 +453,25 @@ const FX_CHAR* CPDF_Font::GetAdobeCharName(
name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode);
return name && name[0] ? name : nullptr;
}
+
+uint32_t CPDF_Font::FallbackFontFromCharcode(uint32_t charcode) {
+ if (m_FontFallbacks.empty()) {
+ m_FontFallbacks.push_back(WrapUnique(new CFX_Font()));
+ m_FontFallbacks[0]->LoadSubst("Arial", IsTrueTypeFont(), m_Flags,
+ m_StemV * 5, m_ItalicAngle, 0,
+ IsVertWriting());
+ }
+ return 0;
+}
+
+int CPDF_Font::FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode) {
+ if (fallbackFont < 0 ||
+ fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) {
+ return -1;
+ }
+ int glyph =
+ FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode);
+ if (glyph == 0 || glyph == 0xffff)
+ return -1;
+ return glyph;
+}
diff --git a/core/fpdfapi/fpdf_font/include/cpdf_font.h b/core/fpdfapi/fpdf_font/include/cpdf_font.h
index a76a6a2573..a47d8655c2 100644
--- a/core/fpdfapi/fpdf_font/include/cpdf_font.h
+++ b/core/fpdfapi/fpdf_font/include/cpdf_font.h
@@ -88,12 +88,15 @@ class CPDF_Font {
int GetItalicAngle() const { return m_ItalicAngle; }
int GetStemV() const { return m_StemV; }
int GetStringWidth(const FX_CHAR* pString, int size);
+ uint32_t FallbackFontFromCharcode(uint32_t charcode);
+ int FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode);
virtual int GetCharWidthF(uint32_t charcode, int level = 0) = 0;
virtual FX_RECT GetCharBBox(uint32_t charcode, int level = 0) = 0;
CPDF_Document* m_pDocument;
CFX_Font m_Font;
+ std::vector<std::unique_ptr<CFX_Font>> m_FontFallbacks;
protected:
CPDF_Font();