diff options
author | thestig <thestig@chromium.org> | 2016-06-21 14:38:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-21 14:38:28 -0700 |
commit | 907a5223ea5abd09878de20cc74c59ebd0d6c3c8 (patch) | |
tree | 7dba8b090eda4f65da57d1979bdb02cedd273055 /xfa | |
parent | 56a8b1944d555ed65dda97164b702a9a657485ca (diff) | |
download | pdfium-907a5223ea5abd09878de20cc74c59ebd0d6c3c8.tar.xz |
Use FXFONT defines in place of integers.
Fix nits along the way.
Review-Url: https://codereview.chromium.org/2083943003
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fde/fde_gedevice.cpp | 4 | ||||
-rw-r--r-- | xfa/fgas/font/fgas_gefont.cpp | 48 | ||||
-rw-r--r-- | xfa/fgas/font/fgas_gefont.h | 2 | ||||
-rw-r--r-- | xfa/fgas/font/fgas_stdfontmgr.cpp | 50 | ||||
-rw-r--r-- | xfa/fgas/font/fgas_stdfontmgr.h | 4 |
5 files changed, 39 insertions, 69 deletions
diff --git a/xfa/fde/fde_gedevice.cpp b/xfa/fde/fde_gedevice.cpp index 98f2492b79..ba72e7d014 100644 --- a/xfa/fde/fde_gedevice.cpp +++ b/xfa/fde/fde_gedevice.cpp @@ -137,9 +137,9 @@ FX_BOOL CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, CFX_SubstFont SubstFxFont; FxFont.SetSubstFont(&SubstFxFont); SubstFxFont.m_Weight = dwFontStyle & FX_FONTSTYLE_Bold ? 700 : 400; - SubstFxFont.m_WeightCJK = SubstFxFont.m_Weight; SubstFxFont.m_ItalicAngle = dwFontStyle & FX_FONTSTYLE_Italic ? -12 : 0; - SubstFxFont.m_bItlicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); + SubstFxFont.m_WeightCJK = SubstFxFont.m_Weight; + SubstFxFont.m_bItalicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ for (int32_t i = 0; i < iCount; ++i) { diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp index c07455556c..7863ef715b 100644 --- a/xfa/fgas/font/fgas_gefont.cpp +++ b/xfa/fgas/font/fgas_gefont.cpp @@ -83,8 +83,7 @@ CFGAS_GEFont::CFGAS_GEFont(IFGAS_FontMgr* pFontMgr) m_pCharWidthMap(NULL), m_pRectArray(NULL), m_pBBoxMap(NULL), - m_pProvider(NULL), - m_wCharSet(0xFFFF) { + m_pProvider(NULL) { } CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) @@ -103,8 +102,7 @@ CFGAS_GEFont::CFGAS_GEFont(const CFGAS_GEFont& src, uint32_t dwFontStyles) m_pCharWidthMap(NULL), m_pRectArray(NULL), m_pBBoxMap(NULL), - m_pProvider(NULL), - m_wCharSet(0xFFFF) { + m_pProvider(NULL) { ASSERT(src.m_pFont); m_pFont = new CFX_Font; m_pFont->LoadClone(src.m_pFont); @@ -189,11 +187,6 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily, } int32_t iWeight = (dwFontStyles & FX_FONTSTYLE_Bold) ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL; - uint16_t wCharSet = FX_GetCharsetFromCodePage(wCodePage); - if (wCharSet == 0xFFFF) { - wCharSet = FXSYS_GetACP(); - } - m_wCharSet = wCharSet; m_pFont = new CFX_Font; if ((dwFlags & FXFONT_ITALIC) && (dwFlags & FXFONT_BOLD)) { csFontFamily += ",BoldItalic"; @@ -203,24 +196,19 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(const FX_WCHAR* pszFontFamily, csFontFamily += ",Italic"; } m_pFont->LoadSubst(csFontFamily, TRUE, dwFlags, iWeight, 0, wCodePage); - FX_BOOL bRet = m_pFont->GetFace() != nullptr; - if (bRet) { - bRet = InitFont(); - } - return bRet; + if (!m_pFont->GetFace()) + return false; + return InitFont(); } FX_BOOL CFGAS_GEFont::LoadFontInternal(const uint8_t* pBuffer, int32_t length) { - if (m_pFont) { + if (m_pFont) return FALSE; - } + m_pFont = new CFX_Font; - FX_BOOL bRet = m_pFont->LoadEmbedded(pBuffer, length); - if (bRet) { - bRet = InitFont(); - } - m_wCharSet = 0xFFFF; - return bRet; + if (!m_pFont->LoadEmbedded(pBuffer, length)) + return FALSE; + return InitFont(); } FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, @@ -240,7 +228,6 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(IFX_Stream* pFontStream, m_pFileRead->Release(); m_pFileRead = nullptr; } - m_wCharSet = 0xFFFF; return bRet; } #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ @@ -251,7 +238,6 @@ FX_BOOL CFGAS_GEFont::LoadFontInternal(CFX_Font* pExtFont) { } m_pFont = pExtFont; m_bExtFont = TRUE; - m_wCharSet = 0xFFFF; return InitFont(); } @@ -272,21 +258,13 @@ FX_BOOL CFGAS_GEFont::InitFont() { return TRUE; } + CFGAS_GEFont* CFGAS_GEFont::Derive(uint32_t dwFontStyles, uint16_t wCodePage) { - if (GetFontStyles() == dwFontStyles) { + if (GetFontStyles() == dwFontStyles) return Retain(); - } return new CFGAS_GEFont(*this, dwFontStyles); } -uint8_t CFGAS_GEFont::GetCharSet() const { - if (m_wCharSet != 0xFFFF) { - return (uint8_t)m_wCharSet; - } - if (!m_pFont->GetSubstFont()) { - return FX_CHARSET_Default; - } - return m_pFont->GetSubstFont()->m_Charset; -} + void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const { if (!m_pFont->GetSubstFont() || m_pFont->GetSubstFont()->m_Family.GetLength() == 0) { diff --git a/xfa/fgas/font/fgas_gefont.h b/xfa/fgas/font/fgas_gefont.h index 30f1c99159..5d7b664cf9 100644 --- a/xfa/fgas/font/fgas_gefont.h +++ b/xfa/fgas/font/fgas_gefont.h @@ -39,7 +39,6 @@ class CFGAS_GEFont { CFGAS_GEFont* Derive(uint32_t dwFontStyles, uint16_t wCodePage = 0); void GetFamilyName(CFX_WideString& wsFamily) const; uint32_t GetFontStyles() const; - uint8_t GetCharSet() const; FX_BOOL GetCharWidth(FX_WCHAR wUnicode, int32_t& iWidth, FX_BOOL bCharCode = FALSE); @@ -103,7 +102,6 @@ class CFGAS_GEFont { CFX_MassArrayTemplate<CFX_Rect>* m_pRectArray; CFX_MapPtrToPtr* m_pBBoxMap; CXFA_PDFFontMgr* m_pProvider; - uint16_t m_wCharSet; CFX_ArrayTemplate<CFGAS_GEFont*> m_SubstFonts; std::map<FX_WCHAR, CFGAS_GEFont*> m_FontMapper; }; diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp index 00b1028a76..34f5078962 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.cpp +++ b/xfa/fgas/font/fgas_stdfontmgr.cpp @@ -1163,32 +1163,26 @@ void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, if ((pFace->face_flags & FT_FACE_FLAG_SCALABLE) == 0) return; - CFX_FontDescriptor* pFont = new CFX_FontDescriptor; + std::unique_ptr<CFX_FontDescriptor> pFont(new CFX_FontDescriptor); pFont->m_dwFontStyles |= FXFT_Is_Face_Bold(pFace) ? FX_FONTSTYLE_Bold : 0; pFont->m_dwFontStyles |= FXFT_Is_Face_Italic(pFace) ? FX_FONTSTYLE_Italic : 0; pFont->m_dwFontStyles |= GetFlags(pFace); - CFX_ArrayTemplate<uint16_t> Charsets; - GetCharsets(pFace, Charsets); + std::vector<uint16_t> charsets = GetCharsets(pFace); GetUSBCSB(pFace, pFont->m_dwUsb, pFont->m_dwCsb); FT_ULong dwTag; - uint8_t* pTable = nullptr; FT_ENC_TAG(dwTag, 'n', 'a', 'm', 'e'); + std::vector<uint8_t> table; unsigned long nLength = 0; unsigned int error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, nullptr, &nLength); if (error == 0 && nLength != 0) { - pTable = FX_Alloc(uint8_t, nLength); - error = FXFT_Load_Sfnt_Table(pFace, dwTag, 0, pTable, nullptr); - if (0 != error) { - FX_Free(pTable); - pTable = nullptr; - } + table.resize(nLength); + if (FXFT_Load_Sfnt_Table(pFace, dwTag, 0, table.data(), nullptr)) + table.clear(); } - GetNames(pTable, pFont->m_wsFamilyNames); - if (pTable) - FX_Free(pTable); + GetNames(table.empty() ? nullptr : table.data(), pFont->m_wsFamilyNames); pFont->m_wsFamilyNames.Add(CFX_ByteString(pFace->family_name).UTF8Decode()); pFont->m_wsFaceName = @@ -1196,7 +1190,7 @@ void CFGAS_FontMgrImp::RegisterFace(FXFT_Face pFace, : CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(pFace)); pFont->m_nFaceIndex = pFace->face_index; - Fonts.Add(pFont); + Fonts.Add(pFont.release()); } void CFGAS_FontMgrImp::RegisterFaces(IFX_FileRead* pFontStream, @@ -1346,30 +1340,28 @@ FX_BIT2CHARSET g_FX_Bit2Charset4[16] = { {1 << 14, FX_CHARSET_Default}, {1 << 15, FX_CHARSET_US}, }; -#define CODEPAGERANGE_IMPLEMENT(n) \ - for (int32_t i = 0; i < 16; i++) { \ - if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) { \ - Charsets.Add(g_FX_Bit2Charset##n[i].wCharset); \ - } \ +#define CODEPAGERANGE_IMPLEMENT(n) \ + for (int32_t i = 0; i < 16; i++) { \ + if ((a##n & g_FX_Bit2Charset##n[i].wBit) != 0) \ + charsets.push_back(g_FX_Bit2Charset##n[i].wCharset); \ } -void CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace, - CFX_ArrayTemplate<uint16_t>& Charsets) { - Charsets.RemoveAll(); +std::vector<uint16_t> CFGAS_FontMgrImp::GetCharsets(FXFT_Face pFace) const { + std::vector<uint16_t> charsets; TT_OS2* pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(pFace, ft_sfnt_os2); - if (NULL != pOS2) { - uint16_t a1, a2, a3, a4; - a1 = pOS2->ulCodePageRange1 & 0x0000ffff; + if (pOS2) { + uint16_t a1 = pOS2->ulCodePageRange1 & 0xffff; CODEPAGERANGE_IMPLEMENT(1); - a2 = (pOS2->ulCodePageRange1 >> 16) & 0x0000ffff; + uint16_t a2 = (pOS2->ulCodePageRange1 >> 16) & 0xffff; CODEPAGERANGE_IMPLEMENT(2); - a3 = pOS2->ulCodePageRange2 & 0x0000ffff; + uint16_t a3 = pOS2->ulCodePageRange2 & 0xffff; CODEPAGERANGE_IMPLEMENT(3); - a4 = (pOS2->ulCodePageRange2 >> 16) & 0x0000ffff; + uint16_t a4 = (pOS2->ulCodePageRange2 >> 16) & 0xffff; CODEPAGERANGE_IMPLEMENT(4); } else { - Charsets.Add(FX_CHARSET_Default); + charsets.push_back(FX_CHARSET_Default); } + return charsets; } #undef CODEPAGERANGE_IMPLEMENT diff --git a/xfa/fgas/font/fgas_stdfontmgr.h b/xfa/fgas/font/fgas_stdfontmgr.h index 66b1412d10..f66729e21b 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.h +++ b/xfa/fgas/font/fgas_stdfontmgr.h @@ -7,6 +7,8 @@ #ifndef XFA_FGAS_FONT_FGAS_STDFONTMGR_H_ #define XFA_FGAS_FONT_FGAS_STDFONTMGR_H_ +#include <vector> + #include "core/fxcrt/include/fx_ext.h" #include "core/fxge/include/fx_freetype.h" #include "third_party/freetype/include/freetype/fttypes.h" @@ -194,7 +196,7 @@ class CFGAS_FontMgrImp : public IFGAS_FontMgr { void RegisterFaces(IFX_FileRead* pFontStream, const CFX_WideString* pFaceName); void GetNames(const uint8_t* name_table, CFX_WideStringArray& Names); - void GetCharsets(FXFT_Face pFace, CFX_ArrayTemplate<uint16_t>& Charsets); + std::vector<uint16_t> GetCharsets(FXFT_Face pFace) const; void GetUSBCSB(FXFT_Face pFace, uint32_t* USB, uint32_t* CSB); uint32_t GetFlags(FXFT_Face pFace); CFX_FontDescriptors m_InstalledFonts; |