diff options
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_cidfont.cpp | 83 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_cidfont.h | 8 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_simplefont.cpp | 32 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_simplefont.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/font_int.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_font/fpdf_font.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/include/fx_coordinates.h | 33 |
7 files changed, 77 insertions, 89 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; } diff --git a/core/fxcrt/include/fx_coordinates.h b/core/fxcrt/include/fx_coordinates.h index e9c05ec644..49f6a19859 100644 --- a/core/fxcrt/include/fx_coordinates.h +++ b/core/fxcrt/include/fx_coordinates.h @@ -124,28 +124,11 @@ typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; // TODO(tsepez): Consolidate all these different rectangle classes. // LTRB rectangles (y-axis runs downwards). -struct FX_SMALL_RECT { - FX_SMALL_RECT() : FX_SMALL_RECT(kInvalid, kInvalid, kInvalid, kInvalid) {} - - FX_SMALL_RECT(int16_t l, int16_t t, int16_t r, int16_t b) - : left(l), top(t), right(r), bottom(b) {} - - static const int16_t kInvalid = -1; - - int16_t left; - int16_t top; - int16_t right; - int16_t bottom; -}; - struct FX_RECT { FX_RECT() : left(0), top(0), right(0), bottom(0) {} FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {} - explicit FX_RECT(const FX_SMALL_RECT& other) - : FX_RECT(other.left, other.top, other.right, other.bottom) {} - int Width() const { return right - left; } int Height() const { return bottom - top; } bool IsEmpty() const { return right <= left || bottom <= top; } @@ -178,21 +161,15 @@ struct FX_RECT { bottom == src.bottom; } - FX_BOOL Contains(const FX_RECT& other_rect) const { + bool Contains(const FX_RECT& other_rect) const { return other_rect.left >= left && other_rect.right <= right && other_rect.top >= top && other_rect.bottom <= bottom; } - FX_BOOL Contains(int x, int y) const { + bool Contains(int x, int y) const { return x >= left && x < right && y >= top && y < bottom; } - FX_SMALL_RECT ToSmallRect() const { - return FX_SMALL_RECT( - static_cast<uint16_t>(left), static_cast<uint16_t>(top), - static_cast<uint16_t>(right), static_cast<uint16_t>(bottom)); - } - int32_t left; int32_t top; int32_t right; @@ -433,11 +410,11 @@ class CFX_RTemplate { return width <= fEpsilon || height <= fEpsilon; } void Empty() { width = height = 0; } - FX_BOOL Contains(baseType x, baseType y) const { + bool Contains(baseType x, baseType y) const { return x >= left && x < left + width && y >= top && y < top + height; } - FX_BOOL Contains(const FXT_POINT& p) const { return Contains(p.x, p.y); } - FX_BOOL Contains(const FXT_RECT& rt) const { + bool Contains(const FXT_POINT& p) const { return Contains(p.x, p.y); } + bool Contains(const FXT_RECT& rt) const { return rt.left >= left && rt.right() <= right() && rt.top >= top && rt.bottom() <= bottom(); } |