summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/fpdf_font/cpdf_cidfont.cpp83
-rw-r--r--core/fpdfapi/fpdf_font/cpdf_cidfont.h8
-rw-r--r--core/fpdfapi/fpdf_font/cpdf_simplefont.cpp32
-rw-r--r--core/fpdfapi/fpdf_font/cpdf_simplefont.h4
-rw-r--r--core/fpdfapi/fpdf_font/font_int.h2
-rw-r--r--core/fpdfapi/fpdf_font/fpdf_font.cpp4
6 files changed, 72 insertions, 61 deletions
diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp
index 0dcbf48be2..491bd6d0c7 100644
--- a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp
@@ -189,14 +189,21 @@ void FT_UseCIDCharmap(FXFT_Face face, int coding) {
FXFT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face));
}
+bool IsMetricForCID(const uint32_t* pEntry, uint16_t CID) {
+ return pEntry[0] <= CID && pEntry[1] >= CID;
+}
+
} // namespace
CPDF_CIDFont::CPDF_CIDFont()
: m_pCMap(nullptr),
m_pCID2UnicodeMap(nullptr),
- m_bCIDIsGID(FALSE),
+ m_bCIDIsGID(false),
m_bAnsiWidthsFixed(false),
- m_bAdobeCourierStd(FALSE) {}
+ m_bAdobeCourierStd(false) {
+ for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i)
+ m_CharBBox[i] = FX_RECT(-1, -1, -1, -1);
+}
CPDF_CIDFont::~CPDF_CIDFont() {}
@@ -213,14 +220,12 @@ CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() {
}
uint16_t CPDF_CIDFont::CIDFromCharCode(uint32_t charcode) const {
- if (!m_pCMap) {
- return (uint16_t)charcode;
- }
- return m_pCMap->CIDFromCharCode(charcode);
+ return m_pCMap ? m_pCMap->CIDFromCharCode(charcode)
+ : static_cast<uint16_t>(charcode);
}
FX_BOOL CPDF_CIDFont::IsVertWriting() const {
- return m_pCMap ? m_pCMap->IsVertWriting() : FALSE;
+ return m_pCMap && m_pCMap->IsVertWriting();
}
CFX_WideString CPDF_CIDFont::UnicodeFromCharCode(uint32_t charcode) const {
@@ -336,7 +341,7 @@ FX_BOOL CPDF_CIDFont::Load() {
m_BaseFont.Compare("CourierStd-BoldOblique") == 0 ||
m_BaseFont.Compare("CourierStd-Oblique") == 0) &&
!IsEmbedded()) {
- m_bAdobeCourierStd = TRUE;
+ m_bAdobeCourierStd = true;
}
CPDF_Dictionary* pFontDesc = pCIDFontDict->GetDictBy("FontDescriptor");
if (pFontDesc)
@@ -354,6 +359,8 @@ FX_BOOL CPDF_CIDFont::Load() {
CFX_ByteString cmap = pEncoding->GetString();
bool bPromptCJK = m_pFontFile && m_bType1;
m_pCMap = manager.GetPredefinedCMap(cmap, bPromptCJK);
+ if (!m_pCMap)
+ return FALSE;
} else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
m_pCMap = new CPDF_CMap;
m_pAllocatedCMap.reset(m_pCMap);
@@ -363,8 +370,6 @@ FX_BOOL CPDF_CIDFont::Load() {
} else {
return FALSE;
}
- if (!m_pCMap)
- return FALSE;
m_Charset = m_pCMap->m_Charset;
if (m_Charset == CIDSET_UNKNOWN) {
@@ -401,10 +406,10 @@ FX_BOOL CPDF_CIDFont::Load() {
} else if (pmap->GetString() == "Identity") {
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
if (m_pFontFile) {
- m_bCIDIsGID = TRUE;
+ m_bCIDIsGID = true;
}
#else
- m_bCIDIsGID = TRUE;
+ m_bCIDIsGID = true;
#endif
}
}
@@ -429,8 +434,8 @@ FX_BOOL CPDF_CIDFont::Load() {
}
FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode, int level) {
- if (charcode < 256 && m_CharBBox[charcode].right != FX_SMALL_RECT::kInvalid)
- return FX_RECT(m_CharBBox[charcode]);
+ if (charcode < 256 && m_CharBBox[charcode].right != -1)
+ return m_CharBBox[charcode];
FX_RECT rect;
bool bVert = false;
@@ -496,58 +501,64 @@ FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode, int level) {
}
}
if (charcode < 256)
- m_CharBBox[charcode] = rect.ToSmallRect();
+ m_CharBBox[charcode] = rect;
return rect;
}
+
int CPDF_CIDFont::GetCharWidthF(uint32_t charcode, int level) {
if (charcode < 0x80 && m_bAnsiWidthsFixed)
return charcode >= 32 && charcode < 127 ? 500 : 0;
uint16_t cid = CIDFromCharCode(charcode);
int size = m_WidthList.GetSize();
- uint32_t* list = m_WidthList.GetData();
+ const uint32_t* pList = m_WidthList.GetData();
for (int i = 0; i < size; i += 3) {
- if (cid >= list[i] && cid <= list[i + 1]) {
- return (int)list[i + 2];
- }
+ const uint32_t* pEntry = pList + i;
+ if (IsMetricForCID(pEntry, cid))
+ return static_cast<int>(pEntry[2]);
}
return m_DefaultWidth;
}
+
short CPDF_CIDFont::GetVertWidth(uint16_t CID) const {
uint32_t vertsize = m_VertMetrics.GetSize() / 5;
- if (vertsize == 0) {
- return m_DefaultW1;
- }
- const uint32_t* pTable = m_VertMetrics.GetData();
- for (uint32_t i = 0; i < vertsize; i++)
- if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
- return (short)(int)pTable[i * 5 + 2];
+ if (vertsize) {
+ const uint32_t* pTable = m_VertMetrics.GetData();
+ for (uint32_t i = 0; i < vertsize; i++) {
+ const uint32_t* pEntry = pTable + (i * 5);
+ if (IsMetricForCID(pEntry, CID))
+ return static_cast<short>(pEntry[2]);
}
+ }
return m_DefaultW1;
}
+
void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const {
uint32_t vertsize = m_VertMetrics.GetSize() / 5;
if (vertsize) {
const uint32_t* pTable = m_VertMetrics.GetData();
- for (uint32_t i = 0; i < vertsize; i++)
- if (pTable[i * 5] <= CID && pTable[i * 5 + 1] >= CID) {
- vx = (short)(int)pTable[i * 5 + 3];
- vy = (short)(int)pTable[i * 5 + 4];
+ for (uint32_t i = 0; i < vertsize; i++) {
+ const uint32_t* pEntry = pTable + (i * 5);
+ if (IsMetricForCID(pEntry, CID)) {
+ vx = static_cast<short>(pEntry[3]);
+ vy = static_cast<short>(pEntry[4]);
return;
}
+ }
}
uint32_t dwWidth = m_DefaultWidth;
int size = m_WidthList.GetSize();
- const uint32_t* list = m_WidthList.GetData();
+ const uint32_t* pList = m_WidthList.GetData();
for (int i = 0; i < size; i += 3) {
- if (CID >= list[i] && CID <= list[i + 1]) {
- dwWidth = (uint16_t)list[i + 2];
+ const uint32_t* pEntry = pList + i;
+ if (IsMetricForCID(pEntry, CID)) {
+ dwWidth = pEntry[2];
break;
}
}
- vx = (short)dwWidth / 2;
- vy = (short)m_DefaultVY;
+ vx = static_cast<short>(dwWidth) / 2;
+ vy = m_DefaultVY;
}
int CPDF_CIDFont::GetGlyphIndex(uint32_t unicode, bool* pVertGlyph) {
@@ -820,7 +831,7 @@ void CPDF_CIDFont::LoadGB2312() {
LoadFontDescriptor(pFontDesc);
m_Charset = CIDSET_GB1;
- m_bType1 = FALSE;
+ m_bType1 = false;
CPDF_CMapManager& manager = GetFontGlobals()->m_CMapManager;
m_pCMap = manager.GetPredefinedCMap("GBK-EUC-H", FALSE);
m_pCID2UnicodeMap = manager.GetCID2UnicodeMap(m_Charset, FALSE);
diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.h b/core/fpdfapi/fpdf_font/cpdf_cidfont.h
index 567598bc4e..1a5ce07cf0 100644
--- a/core/fpdfapi/fpdf_font/cpdf_cidfont.h
+++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.h
@@ -74,17 +74,17 @@ class CPDF_CIDFont : public CPDF_Font {
std::unique_ptr<CPDF_CMap> m_pAllocatedCMap;
CPDF_CID2UnicodeMap* m_pCID2UnicodeMap;
CIDSet m_Charset;
- FX_BOOL m_bType1;
- FX_BOOL m_bCIDIsGID;
+ bool m_bType1;
+ bool m_bCIDIsGID;
uint16_t m_DefaultWidth;
std::unique_ptr<CPDF_StreamAcc> m_pStreamAcc;
bool m_bAnsiWidthsFixed;
- FX_SMALL_RECT m_CharBBox[256];
+ FX_RECT m_CharBBox[256];
CFX_ArrayTemplate<uint32_t> m_WidthList;
short m_DefaultVY;
short m_DefaultW1;
CFX_ArrayTemplate<uint32_t> m_VertMetrics;
- FX_BOOL m_bAdobeCourierStd;
+ bool m_bAdobeCourierStd;
std::unique_ptr<CFX_CTTGSUBTable> m_pTTGSUBTable;
};
diff --git a/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp b/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp
index 65f4a5a235..62d6959062 100644
--- a/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/fpdf_font/cpdf_simplefont.cpp
@@ -15,6 +15,8 @@ CPDF_SimpleFont::CPDF_SimpleFont() : m_BaseEncoding(PDFFONT_ENCODING_BUILTIN) {
FXSYS_memset(m_CharWidth, 0xff, sizeof(m_CharWidth));
FXSYS_memset(m_GlyphIndex, 0xff, sizeof(m_GlyphIndex));
FXSYS_memset(m_ExtGID, 0xff, sizeof(m_ExtGID));
+ for (size_t i = 0; i < FX_ArraySize(m_CharBBox); ++i)
+ m_CharBBox[i] = FX_RECT(-1, -1, -1, -1);
}
CPDF_SimpleFont::~CPDF_SimpleFont() {}
@@ -52,16 +54,15 @@ void CPDF_SimpleFont::LoadCharMetrics(int charcode) {
int err = FXFT_Load_Glyph(
face, glyph_index,
FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
- if (err) {
+ if (err)
return;
- }
- m_CharBBox[charcode] = FX_SMALL_RECT(
- TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face),
- TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face),
- TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face),
- face),
- TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face),
- face));
+
+ int iHoriBearingX = FXFT_Get_Glyph_HoriBearingX(face);
+ int iHoriBearingY = FXFT_Get_Glyph_HoriBearingY(face);
+ m_CharBBox[charcode] =
+ FX_RECT(TT2PDF(iHoriBearingX, face), TT2PDF(iHoriBearingY, face),
+ TT2PDF(iHoriBearingX + FXFT_Get_Glyph_Width(face), face),
+ TT2PDF(iHoriBearingY - FXFT_Get_Glyph_Height(face), face));
if (m_bUseFontWidth) {
int TT_Width = TT2PDF(FXFT_Get_Glyph_HoriAdvance(face), face);
@@ -77,26 +78,26 @@ void CPDF_SimpleFont::LoadCharMetrics(int charcode) {
}
int CPDF_SimpleFont::GetCharWidthF(uint32_t charcode, int level) {
- if (charcode > 0xff) {
+ if (charcode > 0xff)
charcode = 0;
- }
+
if (m_CharWidth[charcode] == 0xffff) {
LoadCharMetrics(charcode);
if (m_CharWidth[charcode] == 0xffff) {
m_CharWidth[charcode] = 0;
}
}
- return (int16_t)m_CharWidth[charcode];
+ return m_CharWidth[charcode];
}
FX_RECT CPDF_SimpleFont::GetCharBBox(uint32_t charcode, int level) {
if (charcode > 0xff)
charcode = 0;
- if (m_CharBBox[charcode].left == FX_SMALL_RECT::kInvalid)
+ if (m_CharBBox[charcode].left == -1)
LoadCharMetrics(charcode);
- return FX_RECT(m_CharBBox[charcode]);
+ return m_CharBBox[charcode];
}
FX_BOOL CPDF_SimpleFont::LoadCommon() {
@@ -105,9 +106,8 @@ FX_BOOL CPDF_SimpleFont::LoadCommon() {
LoadFontDescriptor(pFontDesc);
}
CPDF_Array* pWidthArray = m_pFontDict->GetArrayBy("Widths");
- m_bUseFontWidth = TRUE;
+ m_bUseFontWidth = !pWidthArray;
if (pWidthArray) {
- m_bUseFontWidth = FALSE;
if (pFontDesc && pFontDesc->KeyExist("MissingWidth")) {
int MissingWidth = pFontDesc->GetIntegerBy("MissingWidth");
for (int i = 0; i < 256; i++) {
diff --git a/core/fpdfapi/fpdf_font/cpdf_simplefont.h b/core/fpdfapi/fpdf_font/cpdf_simplefont.h
index 9000850ca3..59eb9be012 100644
--- a/core/fpdfapi/fpdf_font/cpdf_simplefont.h
+++ b/core/fpdfapi/fpdf_font/cpdf_simplefont.h
@@ -42,8 +42,8 @@ class CPDF_SimpleFont : public CPDF_Font {
std::vector<CFX_ByteString> m_CharNames;
int m_BaseEncoding;
uint16_t m_CharWidth[256];
- FX_SMALL_RECT m_CharBBox[256];
- FX_BOOL m_bUseFontWidth;
+ FX_RECT m_CharBBox[256];
+ bool m_bUseFontWidth;
};
#endif // CORE_FPDFAPI_FPDF_FONT_CPDF_SIMPLEFONT_H_
diff --git a/core/fpdfapi/fpdf_font/font_int.h b/core/fpdfapi/fpdf_font/font_int.h
index 9854797e67..c1e2f75599 100644
--- a/core/fpdfapi/fpdf_font/font_int.h
+++ b/core/fpdfapi/fpdf_font/font_int.h
@@ -20,7 +20,7 @@ class CPDF_Stream;
using FXFT_Library = void*;
-int16_t TT2PDF(int m, FXFT_Face face);
+int TT2PDF(int m, FXFT_Face face);
bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id);
CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering);
diff --git a/core/fpdfapi/fpdf_font/fpdf_font.cpp b/core/fpdfapi/fpdf_font/fpdf_font.cpp
index cb410b8d68..fefe936543 100644
--- a/core/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -21,10 +21,10 @@
#include "core/fxge/include/fx_freetype.h"
#include "third_party/base/stl_util.h"
-int16_t TT2PDF(int m, FXFT_Face face) {
+int TT2PDF(int m, FXFT_Face face) {
int upm = FXFT_Get_Face_UnitsPerEM(face);
if (upm == 0)
- return static_cast<int16_t>(m);
+ return m;
return (m * 1000 + upm / 2) / upm;
}