summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.cpp26
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h3
-rw-r--r--xfa/fgas/font/cfgas_gefont.cpp31
-rw-r--r--xfa/fgas/font/cfgas_gefont.h8
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.cpp4
-rw-r--r--xfa/fgas/layout/fgas_textbreak.cpp8
6 files changed, 38 insertions, 42 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 1849441a16..9d3954fb1e 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -575,14 +575,6 @@ CFGAS_FontMgr::CFGAS_FontMgr(CFX_FontSourceEnum_File* pFontEnum)
CFGAS_FontMgr::~CFGAS_FontMgr() {
for (int32_t i = 0; i < m_InstalledFonts.GetSize(); i++)
delete m_InstalledFonts[i];
- FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
- while (pos) {
- uint32_t dwHash;
- CFX_FontDescriptorInfos* pDescs;
- m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
- delete pDescs;
- }
- m_Hash2Fonts.clear();
}
bool CFGAS_FontMgr::EnumFontsFromFontMapper() {
@@ -645,12 +637,13 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByCodePage(
if (!pFontArray->empty())
return (*pFontArray)[0];
- CFX_FontDescriptorInfos* sortedFonts = nullptr;
- if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) {
- sortedFonts = new CFX_FontDescriptorInfos;
+ CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash].get();
+ if (!sortedFonts) {
+ auto pNewFonts = pdfium::MakeUnique<CFX_FontDescriptorInfos>();
+ sortedFonts = pNewFonts.get();
MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
CFX_WideString(pszFontFamily), 0);
- m_Hash2CandidateList.SetAt(dwHash, sortedFonts);
+ m_Hash2CandidateList[dwHash] = std::move(pNewFonts);
}
if (sortedFonts->GetSize() == 0)
return nullptr;
@@ -688,12 +681,13 @@ CFX_RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::GetFontByUnicode(
if (VerifyUnicode((*pFonts)[i], wUnicode))
return (*pFonts)[i];
}
- CFX_FontDescriptorInfos* sortedFonts = nullptr;
- if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) {
- sortedFonts = new CFX_FontDescriptorInfos;
+ CFX_FontDescriptorInfos* sortedFonts = m_Hash2CandidateList[dwHash].get();
+ if (!sortedFonts) {
+ auto pNewFonts = pdfium::MakeUnique<CFX_FontDescriptorInfos>();
+ sortedFonts = pNewFonts.get();
MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
CFX_WideString(pszFontFamily), wUnicode);
- m_Hash2CandidateList.SetAt(dwHash, sortedFonts);
+ m_Hash2CandidateList[dwHash] = std::move(pNewFonts);
}
for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) {
CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont;
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index c4030e76ee..20efa3296b 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -249,7 +249,8 @@ class CFGAS_FontMgr {
const CFX_ByteString& bsFaceName);
CFX_FontDescriptors m_InstalledFonts;
- CFX_MapPtrTemplate<uint32_t, CFX_FontDescriptorInfos*> m_Hash2CandidateList;
+ std::map<uint32_t, std::unique_ptr<CFX_FontDescriptorInfos>>
+ m_Hash2CandidateList;
std::map<uint32_t, std::vector<CFX_RetainPtr<CFGAS_GEFont>>> m_Hash2Fonts;
std::map<CFX_RetainPtr<CFGAS_GEFont>, CFX_RetainPtr<IFX_SeekableReadStream>>
m_IFXFont2FileRead;
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp
index fc202f6bc3..49639c2005 100644
--- a/xfa/fgas/font/cfgas_gefont.cpp
+++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -214,6 +214,7 @@ bool CFGAS_GEFont::LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont) {
bool CFGAS_GEFont::InitFont() {
if (!m_pFont)
return false;
+
if (!m_pFontEncoding) {
m_pFontEncoding.reset(FX_CreateFontEncodingEx(m_pFont));
if (!m_pFontEncoding)
@@ -225,9 +226,6 @@ bool CFGAS_GEFont::InitFont() {
}
if (!m_pRectArray)
m_pRectArray = pdfium::MakeUnique<CFX_MassArrayTemplate<CFX_Rect>>(16);
- if (!m_pBBoxMap)
- m_pBBoxMap = pdfium::MakeUnique<CFX_MapPtrToPtr>(16);
-
return true;
}
@@ -312,19 +310,19 @@ bool CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode,
}
bool CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode,
- CFX_Rect& bbox,
+ CFX_Rect* bbox,
bool bCharCode) {
return GetCharBBoxInternal(wUnicode, bbox, true, bCharCode);
}
bool CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
- CFX_Rect& bbox,
+ CFX_Rect* bbox,
bool bRecursive,
bool bCharCode) {
ASSERT(m_pRectArray);
- ASSERT(m_pBBoxMap);
- void* pRect = nullptr;
- if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) {
+ CFX_Rect* pRect = nullptr;
+ auto it = m_BBoxMap.find(wUnicode);
+ if (it == m_BBoxMap.end()) {
CFX_RetainPtr<CFGAS_GEFont> pFont;
int32_t iGlyph = GetGlyphIndex(wUnicode, true, &pFont, bCharCode);
if (iGlyph != 0xFFFF && pFont) {
@@ -335,28 +333,31 @@ bool CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
rt.Set(rtBBox.left, rtBBox.top, rtBBox.Width(), rtBBox.Height());
int32_t index = m_pRectArray->Add(rt);
pRect = m_pRectArray->GetPtrAt(index);
- m_pBBoxMap->SetAt((void*)(uintptr_t)wUnicode, pRect);
+ m_BBoxMap[wUnicode] = pRect;
}
} else if (pFont->GetCharBBoxInternal(wUnicode, bbox, false, bCharCode)) {
return true;
}
}
+ } else {
+ pRect = it->second;
}
if (!pRect)
return false;
- bbox = *static_cast<const CFX_Rect*>(pRect);
+ *bbox = *pRect;
return true;
}
-bool CFGAS_GEFont::GetBBox(CFX_Rect& bbox) {
+bool CFGAS_GEFont::GetBBox(CFX_Rect* bbox) {
FX_RECT rt(0, 0, 0, 0);
if (!m_pFont->GetBBox(rt))
return false;
- bbox.left = rt.left;
- bbox.width = rt.Width();
- bbox.top = rt.bottom;
- bbox.height = -rt.Height();
+
+ bbox->left = rt.left;
+ bbox->width = rt.Width();
+ bbox->top = rt.bottom;
+ bbox->height = -rt.Height();
return true;
}
diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h
index 962b93fbb5..de4f9639e0 100644
--- a/xfa/fgas/font/cfgas_gefont.h
+++ b/xfa/fgas/font/cfgas_gefont.h
@@ -55,8 +55,8 @@ class CFGAS_GEFont : public CFX_Retainable {
int32_t GetGlyphIndex(FX_WCHAR wUnicode, bool bCharCode = false);
int32_t GetAscent() const;
int32_t GetDescent() const;
- bool GetCharBBox(FX_WCHAR wUnicode, CFX_Rect& bbox, bool bCharCode = false);
- bool GetBBox(CFX_Rect& bbox);
+ bool GetCharBBox(FX_WCHAR wUnicode, CFX_Rect* bbox, bool bCharCode = false);
+ bool GetBBox(CFX_Rect* bbox);
CFX_RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex) const;
CFX_Font* GetDevFont() const { return m_pFont; }
void SetFontProvider(CXFA_PDFFontMgr* pProvider) { m_pProvider = pProvider; }
@@ -83,7 +83,7 @@ class CFGAS_GEFont : public CFX_Retainable {
bool LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont);
bool InitFont();
bool GetCharBBoxInternal(FX_WCHAR wUnicode,
- CFX_Rect& bbox,
+ CFX_Rect* bbox,
bool bRecursive,
bool bCharCode = false);
bool GetCharWidthInternal(FX_WCHAR wUnicode,
@@ -109,7 +109,7 @@ class CFGAS_GEFont : public CFX_Retainable {
std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding;
std::unique_ptr<CFX_DiscreteArrayTemplate<uint16_t>> m_pCharWidthMap;
std::unique_ptr<CFX_MassArrayTemplate<CFX_Rect>> m_pRectArray;
- std::unique_ptr<CFX_MapPtrToPtr> m_pBBoxMap;
+ std::map<FX_WCHAR, CFX_Rect*> m_BBoxMap; // Rect owned by m_pRectArray.
CXFA_PDFFontMgr* m_pProvider; // not owned.
std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_SubstFonts;
std::map<FX_WCHAR, CFX_RetainPtr<CFGAS_GEFont>> m_FontMapper;
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp
index cacb77fcf8..f7ba0e72b9 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.cpp
+++ b/xfa/fgas/layout/fgas_rtfbreak.cpp
@@ -1319,7 +1319,7 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
if (!bAdjusted && bVerticalChar && (dwProps & 0x00010000) != 0) {
CFX_Rect rtBBox;
rtBBox.Reset();
- if (pFont->GetCharBBox(wForm, rtBBox, bMBCSCode)) {
+ if (pFont->GetCharBBox(wForm, &rtBBox, bMBCSCode)) {
ptOffset.x = fFontSize * (850 - rtBBox.right()) / 1000.0f;
ptOffset.y = fFontSize * (1000 - rtBBox.height) / 2000.0f;
}
@@ -1436,7 +1436,7 @@ int32_t CFX_RTFBreak::GetCharRects(const FX_RTFTEXTOBJ* pText,
CFX_Rect bbox;
bbox.Set(0, 0, 0, 0);
if (bCharBBox)
- bCharBBox = pFont->GetBBox(bbox);
+ bCharBBox = pFont->GetBBox(&bbox);
FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale);
FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale);
diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp
index a9d35a3cd7..35984f5017 100644
--- a/xfa/fgas/layout/fgas_textbreak.cpp
+++ b/xfa/fgas/layout/fgas_textbreak.cpp
@@ -1468,7 +1468,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
if (chartype == FX_CHARTYPE_Combination) {
CFX_Rect rtBBox;
rtBBox.Reset();
- if (pFont->GetCharBBox(wForm, rtBBox, false)) {
+ if (pFont->GetCharBBox(wForm, &rtBBox, false)) {
pCharPos->m_OriginY =
fYBase + fFontSize -
fFontSize * (FX_FLOAT)rtBBox.height / (FX_FLOAT)iMaxHeight;
@@ -1479,7 +1479,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
FX_CHARTYPE_Combination) {
CFX_Rect rtBox;
rtBox.Reset();
- if (pFont->GetCharBBox(wLast, rtBox, false)) {
+ if (pFont->GetCharBBox(wLast, &rtBox, false)) {
pCharPos->m_OriginY -= fFontSize * rtBox.height / iMaxHeight;
}
}
@@ -1494,7 +1494,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
if (!bAdjusted && bVerticalChar && (dwProps & 0x00010000) != 0) {
CFX_Rect rtBBox;
rtBBox.Reset();
- if (pFont->GetCharBBox(wForm, rtBBox, false)) {
+ if (pFont->GetCharBBox(wForm, &rtBBox, false)) {
ptOffset.x = fFontSize * (850 - rtBBox.right()) / iMaxHeight;
ptOffset.y = fFontSize * (iAscent - rtBBox.top - 150) / iMaxHeight;
}
@@ -1610,7 +1610,7 @@ int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun,
CFX_Rect bbox;
bbox.Set(0, 0, 0, 0);
if (bCharBBox)
- bCharBBox = pFont->GetBBox(bbox);
+ bCharBBox = pFont->GetBBox(&bbox);
FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale);
FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale);