summaryrefslogtreecommitdiff
path: root/xfa/fgas
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fgas')
-rw-r--r--xfa/fgas/font/fgas_gefont.cpp48
-rw-r--r--xfa/fgas/font/fgas_gefont.h2
-rw-r--r--xfa/fgas/font/fgas_stdfontmgr.cpp50
-rw-r--r--xfa/fgas/font/fgas_stdfontmgr.h4
4 files changed, 37 insertions, 67 deletions
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;