From ec51ac3e4dfa8ee1da3d581b40f0b35af4563c9e Mon Sep 17 00:00:00 2001 From: thestig Date: Mon, 20 Jun 2016 10:38:52 -0700 Subject: Another round of fx_ge cleanup. - Clean up CFX_GEModule. - Remove duplicate #defines in fx_ge.h - Remove IsFontStyleFromCharCode() that always returns true. - Mark a FXTEXT_CHARPOS field as Mac only. Review-Url: https://codereview.chromium.org/2075333002 --- core/fpdfapi/fpdf_font/cpdf_cidfont.cpp | 18 ++++---- core/fpdfapi/fpdf_font/cpdf_cidfont.h | 1 - core/fpdfapi/fpdf_render/fpdf_render_text.cpp | 2 +- core/fxge/ge/fx_ge.cpp | 59 +++++++++++++++------------ core/fxge/include/fx_ge.h | 47 ++++++++++----------- fpdfsdk/fpdfview.cpp | 4 +- xfa/fde/fde_gedevice.cpp | 2 +- xfa/fgas/layout/fgas_rtfbreak.cpp | 2 + xfa/fgas/layout/fgas_textbreak.cpp | 2 + 9 files changed, 73 insertions(+), 64 deletions(-) diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp index af4121da16..317e6ddb01 100644 --- a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp @@ -775,34 +775,36 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { const uint8_t* pdata = m_pStreamAcc->GetData() + byte_pos; return pdata[0] * 256 + pdata[1]; } + uint32_t CPDF_CIDFont::GetNextChar(const FX_CHAR* pString, int nStrLen, int& offset) const { return m_pCMap->GetNextChar(pString, nStrLen, offset); } + int CPDF_CIDFont::GetCharSize(uint32_t charcode) const { return m_pCMap->GetCharSize(charcode); } + int CPDF_CIDFont::CountChar(const FX_CHAR* pString, int size) const { return m_pCMap->CountChar(pString, size); } + int CPDF_CIDFont::AppendChar(FX_CHAR* str, uint32_t charcode) const { return m_pCMap->AppendChar(str, charcode); } + FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const { - if (!m_pCMap->IsLoaded() || !m_pCID2UnicodeMap || - !m_pCID2UnicodeMap->IsLoaded()) { - return m_pCMap->m_Coding != CIDCODING_UNKNOWN; - } - return TRUE; -} -FX_BOOL CPDF_CIDFont::IsFontStyleFromCharCode(uint32_t charcode) const { - return TRUE; + if (m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded() && m_pCMap->IsLoaded()) + return TRUE; + return m_pCMap->m_Coding != CIDCODING_UNKNOWN; } + void CPDF_CIDFont::LoadSubstFont() { m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, m_StemV * 5, m_ItalicAngle, g_CharsetCPs[m_Charset], IsVertWriting()); } + void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, CFX_ArrayTemplate& result, int nElements) { diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.h b/core/fpdfapi/fpdf_font/cpdf_cidfont.h index f1c72c65cf..5abb20f7aa 100644 --- a/core/fpdfapi/fpdf_font/cpdf_cidfont.h +++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.h @@ -61,7 +61,6 @@ class CPDF_CIDFont : public CPDF_Font { const uint8_t* GetCIDTransform(uint16_t CID) const; short GetVertWidth(uint16_t CID) const; void GetVertOrigin(uint16_t CID, short& vx, short& vy) const; - virtual FX_BOOL IsFontStyleFromCharCode(uint32_t charcode) const; protected: int GetGlyphIndex(uint32_t unicodeb, FX_BOOL* pVertGlyph); diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp index 5b0ad96aee..2da51b90d5 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -562,7 +562,7 @@ void CPDF_CharPosList::Load(int nChars, FX_BOOL bVert = FALSE; FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++]; if (pCIDFont) { - charpos.m_bFontStyle = pCIDFont->IsFontStyleFromCharCode(CharCode); + charpos.m_bFontStyle = true; } charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ diff --git a/core/fxge/ge/fx_ge.cpp b/core/fxge/ge/fx_ge.cpp index 360a4eb417..4ebf812f12 100644 --- a/core/fxge/ge/fx_ge.cpp +++ b/core/fxge/ge/fx_ge.cpp @@ -9,52 +9,57 @@ #include "core/fxge/ge/fx_text_int.h" static CFX_GEModule* g_pGEModule = nullptr; -CFX_GEModule::CFX_GEModule(const char** pUserFontPaths) { - m_pFontCache = nullptr; - m_pFontMgr = nullptr; - m_FTLibrary = nullptr; - m_pCodecModule = nullptr; - m_pPlatformData = nullptr; - m_pUserFontPaths = pUserFontPaths; + +CFX_GEModule::CFX_GEModule(const char** pUserFontPaths, + CCodec_ModuleMgr* pCodecModule) + : m_FTLibrary(nullptr), + m_pFontCache(nullptr), + m_pFontMgr(new CFX_FontMgr), + m_pCodecModule(pCodecModule), + m_pPlatformData(nullptr), + m_pUserFontPaths(pUserFontPaths) { + InitPlatform(); + SetTextGamma(2.2f); } + CFX_GEModule::~CFX_GEModule() { delete m_pFontCache; - m_pFontCache = nullptr; - delete m_pFontMgr; - m_pFontMgr = nullptr; DestroyPlatform(); } + +// static +void CFX_GEModule::Create(const char** userFontPaths, + CCodec_ModuleMgr* pCodecModule) { + ASSERT(!g_pGEModule); + g_pGEModule = new CFX_GEModule(userFontPaths, pCodecModule); +} + +// static CFX_GEModule* CFX_GEModule::Get() { return g_pGEModule; } -void CFX_GEModule::Create(const char** userFontPaths) { - g_pGEModule = new CFX_GEModule(userFontPaths); - g_pGEModule->m_pFontMgr = new CFX_FontMgr; - g_pGEModule->InitPlatform(); - g_pGEModule->SetTextGamma(2.2f); -} -void CFX_GEModule::Use(CFX_GEModule* pModule) { - g_pGEModule = pModule; -} + +// static void CFX_GEModule::Destroy() { + ASSERT(g_pGEModule); delete g_pGEModule; g_pGEModule = nullptr; } + CFX_FontCache* CFX_GEModule::GetFontCache() { - if (!m_pFontCache) { + if (!m_pFontCache) m_pFontCache = new CFX_FontCache(); - } return m_pFontCache; } + void CFX_GEModule::SetTextGamma(FX_FLOAT gammaValue) { gammaValue /= 2.2f; - int i = 0; - while (i < 256) { - m_GammaValue[i] = - (uint8_t)(FXSYS_pow((FX_FLOAT)i / 255, gammaValue) * 255.0f + 0.5f); - i++; + for (int i = 0; i < 256; ++i) { + m_GammaValue[i] = static_cast( + FXSYS_pow(static_cast(i) / 255, gammaValue) * 255.0f + 0.5f); } } -const uint8_t* CFX_GEModule::GetTextGammaTable() { + +const uint8_t* CFX_GEModule::GetTextGammaTable() const { return m_GammaValue; } diff --git a/core/fxge/include/fx_ge.h b/core/fxge/include/fx_ge.h index 9114b47008..538afdb581 100644 --- a/core/fxge/include/fx_ge.h +++ b/core/fxge/include/fx_ge.h @@ -7,6 +7,8 @@ #ifndef CORE_FXGE_INCLUDE_FX_GE_H_ #define CORE_FXGE_INCLUDE_FX_GE_H_ +#include + #include "core/fxge/include/fx_dib.h" #include "core/fxge/include/fx_font.h" @@ -16,42 +18,37 @@ class CFX_Font; class CFX_FontCache; class CFX_FontMgr; class CPDF_ShadingPattern; -class CPSFont; class IFX_RenderDeviceDriver; class SkPictureRecorder; class CFX_GEModule { public: - static void Create(const char** pUserFontPaths); - static void Use(CFX_GEModule* pMgr); + static void Create(const char** pUserFontPaths, + CCodec_ModuleMgr* pCodecModule); static CFX_GEModule* Get(); static void Destroy(); CFX_FontCache* GetFontCache(); - CFX_FontMgr* GetFontMgr() { return m_pFontMgr; } + CFX_FontMgr* GetFontMgr() { return m_pFontMgr.get(); } void SetTextGamma(FX_FLOAT gammaValue); - const uint8_t* GetTextGammaTable(); + const uint8_t* GetTextGammaTable() const; - void SetCodecModule(CCodec_ModuleMgr* pCodecModule) { - m_pCodecModule = pCodecModule; - } CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; } void* GetPlatformData() { return m_pPlatformData; } FXFT_Library m_FTLibrary; - protected: - explicit CFX_GEModule(const char** pUserFontPaths); + private: + CFX_GEModule(const char** pUserFontPaths, CCodec_ModuleMgr* pCodecModule); ~CFX_GEModule(); void InitPlatform(); void DestroyPlatform(); - private: uint8_t m_GammaValue[256]; CFX_FontCache* m_pFontCache; - CFX_FontMgr* m_pFontMgr; - CCodec_ModuleMgr* m_pCodecModule; + std::unique_ptr m_pFontMgr; + CCodec_ModuleMgr* const m_pCodecModule; void* m_pPlatformData; const char** m_pUserFontPaths; }; @@ -62,14 +59,6 @@ struct FX_PATHPOINT { int m_Flag; }; -#define FXPT_CLOSEFIGURE 0x01 -#define FXPT_LINETO 0x02 -#define FXPT_BEZIERTO 0x04 -#define FXPT_MOVETO 0x06 -#define FXPT_TYPE 0x06 -#define FXFILL_ALTERNATE 1 -#define FXFILL_WINDING 2 - class CFX_ClipRgn { public: enum ClipType { RectI, MaskF }; @@ -168,6 +157,13 @@ class CFX_GraphStateData { #define FXDC_RENDER_CAPS 7 #define FXDC_DISPLAY 1 #define FXDC_PRINTER 2 + +#define FXPT_CLOSEFIGURE 0x01 +#define FXPT_LINETO 0x02 +#define FXPT_BEZIERTO 0x04 +#define FXPT_MOVETO 0x06 +#define FXPT_TYPE 0x06 + #define FXRC_GET_BITS 0x01 #define FXRC_BIT_MASK 0x02 #define FXRC_ALPHA_MASK 0x04 @@ -182,6 +178,7 @@ class CFX_GraphStateData { #define FXRENDER_IMAGE_LOSSY 0x1000 #define FXRC_FILLSTROKE_PATH 0x2000 #define FXRC_SHADING 0x4000 + #define FXFILL_ALTERNATE 1 #define FXFILL_WINDING 2 #define FXFILL_FULLCOVER 4 @@ -192,6 +189,7 @@ class CFX_GraphStateData { #define FX_FILL_TEXT_MODE 128 #define FX_ZEROAREA_FILL 256 #define FXFILL_NOPATHSMOOTH 512 + #define FXTEXT_CLEARTYPE 0x01 #define FXTEXT_BGR_STRIPE 0x02 #define FXTEXT_PRINTGRAPHICTEXT 0x04 @@ -201,12 +199,15 @@ class CFX_GraphStateData { struct FXTEXT_CHARPOS { uint32_t m_GlyphIndex; - FX_FLOAT m_OriginX, m_OriginY; + FX_FLOAT m_OriginX; + FX_FLOAT m_OriginY; int m_FontCharWidth; FX_BOOL m_bGlyphAdjust; FX_FLOAT m_AdjustMatrix[4]; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ uint32_t m_ExtGID; - FX_BOOL m_bFontStyle; +#endif + bool m_bFontStyle; }; class CFX_RenderDevice { diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 43ca3183f9..6521eb854a 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -262,9 +262,7 @@ DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { g_pCodecModule = new CCodec_ModuleMgr(); - CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr); - CFX_GEModule::Get()->SetCodecModule(g_pCodecModule); - + CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr, g_pCodecModule); CPDF_ModuleMgr::Create(); CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); pModuleMgr->SetCodecModule(g_pCodecModule); diff --git a/xfa/fde/fde_gedevice.cpp b/xfa/fde/fde_gedevice.cpp index c7c5cfb970..98f2492b79 100644 --- a/xfa/fde/fde_gedevice.cpp +++ b/xfa/fde/fde_gedevice.cpp @@ -145,7 +145,7 @@ FX_BOOL CFDE_RenderDevice::DrawString(CFDE_Brush* pBrush, for (int32_t i = 0; i < iCount; ++i) { pSTFont = pFont->GetSubstFont((int32_t)pCP->m_GlyphIndex); pCP->m_GlyphIndex &= 0x00FFFFFF; - pCP->m_bFontStyle = FALSE; + pCP->m_bFontStyle = false; if (pCurFont != pSTFont) { if (pCurFont) { pFxFont = pCurFont->GetDevFont(); diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index 848f7f4e93..80591f1714 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -1285,7 +1285,9 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText, pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wch, bMBCSCode); } } +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ pCharPos->m_ExtGID = pCharPos->m_GlyphIndex; +#endif pCharPos->m_FontCharWidth = iCharWidth; if (pWSForms) { *pWSForms += wForm; diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index 8eebbed76a..a272d0cfc7 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -1395,7 +1395,9 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { pCharPos->m_GlyphIndex = bCharCode ? wch : pFont->GetGlyphIndex(wForm, FALSE); +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ pCharPos->m_ExtGID = pCharPos->m_GlyphIndex; +#endif pCharPos->m_FontCharWidth = iCharWidth; if (pWSForms) { *pWSForms += wForm; -- cgit v1.2.3