Put CFWL_FontManager into its own .cpp/.h files
It doesn't belong in cfwl_widgettp.h, even if they are both used in
similar places.
-- forward declare where possible.
Change-Id: If49ce616abdb4bb0979869398b91cb4c1d1bcd8a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/74951
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/BUILD.gn b/xfa/fwl/BUILD.gn
index 12e07b1..58a3b3c 100644
--- a/xfa/fwl/BUILD.gn
+++ b/xfa/fwl/BUILD.gn
@@ -90,6 +90,8 @@
"theme/cfwl_datetimepickertp.h",
"theme/cfwl_edittp.cpp",
"theme/cfwl_edittp.h",
+ "theme/cfwl_fontmanager.cpp",
+ "theme/cfwl_fontmanager.h",
"theme/cfwl_listboxtp.cpp",
"theme/cfwl_listboxtp.h",
"theme/cfwl_monthcalendartp.cpp",
diff --git a/xfa/fwl/theme/cfwl_checkboxtp.h b/xfa/fwl/theme/cfwl_checkboxtp.h
index e79a693..0877b1e 100644
--- a/xfa/fwl/theme/cfwl_checkboxtp.h
+++ b/xfa/fwl/theme/cfwl_checkboxtp.h
@@ -12,6 +12,7 @@
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_Widget;
+class CXFA_GEPath;
class CFWL_CheckBoxTP final : public CFWL_WidgetTP {
public:
diff --git a/xfa/fwl/theme/cfwl_fontmanager.cpp b/xfa/fwl/theme/cfwl_fontmanager.cpp
new file mode 100644
index 0000000..30ece54
--- /dev/null
+++ b/xfa/fwl/theme/cfwl_fontmanager.cpp
@@ -0,0 +1,77 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fwl/theme/cfwl_fontmanager.h"
+
+#include <utility>
+
+#include "xfa/fgas/font/cfgas_gefont.h"
+
+namespace {
+
+CFWL_FontManager* g_FontManager = nullptr;
+
+} // namespace
+
+// static
+CFWL_FontManager* CFWL_FontManager::GetInstance() {
+ if (!g_FontManager)
+ g_FontManager = new CFWL_FontManager;
+ return g_FontManager;
+}
+
+// static
+void CFWL_FontManager::DestroyInstance() {
+ delete g_FontManager;
+ g_FontManager = nullptr;
+}
+
+CFWL_FontManager::CFWL_FontManager() = default;
+
+CFWL_FontManager::~CFWL_FontManager() = default;
+
+RetainPtr<CFGAS_GEFont> CFWL_FontManager::FindFont(WideStringView wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t wCodePage) {
+ for (const auto& pData : m_FontsArray) {
+ if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage))
+ return pData->GetFont();
+ }
+ auto pFontData = std::make_unique<FontData>();
+ if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage))
+ return nullptr;
+
+ m_FontsArray.push_back(std::move(pFontData));
+ return m_FontsArray.back()->GetFont();
+}
+
+CFWL_FontManager::FontData::FontData() = default;
+
+CFWL_FontManager::FontData::~FontData() = default;
+
+bool CFWL_FontManager::FontData::Equal(WideStringView wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t wCodePage) {
+ return m_wsFamily == wsFontFamily && m_dwStyles == dwFontStyles &&
+ m_dwCodePage == wCodePage;
+}
+
+bool CFWL_FontManager::FontData::LoadFont(WideStringView wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t dwCodePage) {
+ m_wsFamily = wsFontFamily;
+ m_dwStyles = dwFontStyles;
+ m_dwCodePage = dwCodePage;
+
+ // TODO(tsepez): check usage of c_str() below.
+ m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.unterminated_c_str(),
+ dwFontStyles, dwCodePage);
+ return !!m_pFont;
+}
+
+RetainPtr<CFGAS_GEFont> CFWL_FontManager::FontData::GetFont() const {
+ return m_pFont;
+}
diff --git a/xfa/fwl/theme/cfwl_fontmanager.h b/xfa/fwl/theme/cfwl_fontmanager.h
new file mode 100644
index 0000000..6a80ea8
--- /dev/null
+++ b/xfa/fwl/theme/cfwl_fontmanager.h
@@ -0,0 +1,55 @@
+// Copyright 2020 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef XFA_FWL_THEME_CFWL_FONTMANAGER_H_
+#define XFA_FWL_THEME_CFWL_FONTMANAGER_H_
+
+#include <memory>
+#include <vector>
+
+#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/retain_ptr.h"
+
+class CFGAS_GEFont;
+
+class CFWL_FontManager final {
+ public:
+ static CFWL_FontManager* GetInstance();
+ static void DestroyInstance();
+
+ RetainPtr<CFGAS_GEFont> FindFont(WideStringView wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t dwCodePage);
+
+ private:
+ class FontData final {
+ public:
+ FontData();
+ ~FontData();
+
+ bool Equal(WideStringView wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t wCodePage);
+ bool LoadFont(WideStringView wsFontFamily,
+ uint32_t dwFontStyles,
+ uint16_t wCodePage);
+ RetainPtr<CFGAS_GEFont> GetFont() const;
+
+ private:
+ WideString m_wsFamily;
+ uint32_t m_dwStyles = 0;
+ uint32_t m_dwCodePage = 0;
+ RetainPtr<CFGAS_GEFont> m_pFont;
+ };
+
+ CFWL_FontManager();
+ ~CFWL_FontManager();
+
+ std::vector<std::unique_ptr<FontData>> m_FontsArray;
+};
+
+#endif // XFA_FWL_THEME_CFWL_FONTMANAGER_H_
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp
index 6082027..2c3be42 100644
--- a/xfa/fwl/theme/cfwl_widgettp.cpp
+++ b/xfa/fwl/theme/cfwl_widgettp.cpp
@@ -10,7 +10,6 @@
#include <utility>
#include "xfa/fde/cfde_textout.h"
-#include "xfa/fgas/font/cfgas_fontmgr.h"
#include "xfa/fgas/font/cfgas_gefont.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_themepart.h"
@@ -18,15 +17,9 @@
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fwl/cfwl_widgetmgr.h"
#include "xfa/fwl/ifwl_themeprovider.h"
+#include "xfa/fwl/theme/cfwl_fontmanager.h"
#include "xfa/fxgraphics/cxfa_gecolor.h"
#include "xfa/fxgraphics/cxfa_gepath.h"
-#include "xfa/fxgraphics/cxfa_geshading.h"
-
-namespace {
-
-CFWL_FontManager* g_FontManager = nullptr;
-
-} // namespace
CFWL_WidgetTP::CFWL_WidgetTP() = default;
@@ -220,61 +213,3 @@
InitializeArrowColorData();
DrawArrow(pGraphics, rect, eDict, m_pColorData->clrSign[eState - 1], matrix);
}
-
-CFWL_FontManager::FontData::FontData() = default;
-
-CFWL_FontManager::FontData::~FontData() = default;
-
-bool CFWL_FontManager::FontData::Equal(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage) {
- return m_wsFamily == wsFontFamily && m_dwStyles == dwFontStyles &&
- m_dwCodePage == wCodePage;
-}
-
-bool CFWL_FontManager::FontData::LoadFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t dwCodePage) {
- m_wsFamily = wsFontFamily;
- m_dwStyles = dwFontStyles;
- m_dwCodePage = dwCodePage;
-
- // TODO(tsepez): check usage of c_str() below.
- m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.unterminated_c_str(),
- dwFontStyles, dwCodePage);
- return !!m_pFont;
-}
-
-RetainPtr<CFGAS_GEFont> CFWL_FontManager::FontData::GetFont() const {
- return m_pFont;
-}
-
-CFWL_FontManager* CFWL_FontManager::GetInstance() {
- if (!g_FontManager)
- g_FontManager = new CFWL_FontManager;
- return g_FontManager;
-}
-
-void CFWL_FontManager::DestroyInstance() {
- delete g_FontManager;
- g_FontManager = nullptr;
-}
-
-CFWL_FontManager::CFWL_FontManager() = default;
-
-CFWL_FontManager::~CFWL_FontManager() = default;
-
-RetainPtr<CFGAS_GEFont> CFWL_FontManager::FindFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage) {
- for (const auto& pData : m_FontsArray) {
- if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage))
- return pData->GetFont();
- }
- auto pFontData = std::make_unique<FontData>();
- if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage))
- return nullptr;
-
- m_FontsArray.push_back(std::move(pFontData));
- return m_FontsArray.back()->GetFont();
-}
diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h
index 88aaaf7..00b0a27 100644
--- a/xfa/fwl/theme/cfwl_widgettp.h
+++ b/xfa/fwl/theme/cfwl_widgettp.h
@@ -8,18 +8,18 @@
#define XFA_FWL_THEME_CFWL_WIDGETTP_H_
#include <memory>
-#include <vector>
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/retain_ptr.h"
+#include "core/fxge/fx_dib.h"
#include "xfa/fwl/theme/cfwl_utils.h"
-#include "xfa/fxgraphics/cxfa_graphics.h"
class CFDE_TextOut;
class CFGAS_GEFont;
class CFWL_ThemeBackground;
class CFWL_ThemeText;
+class CXFA_Graphics;
class CFWL_WidgetTP {
public:
@@ -76,40 +76,4 @@
std::unique_ptr<CColorData> m_pColorData;
};
-class CFWL_FontManager final {
- public:
- static CFWL_FontManager* GetInstance();
- static void DestroyInstance();
-
- RetainPtr<CFGAS_GEFont> FindFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t dwCodePage);
-
- private:
- class FontData final {
- public:
- FontData();
- ~FontData();
-
- bool Equal(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage);
- bool LoadFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage);
- RetainPtr<CFGAS_GEFont> GetFont() const;
-
- private:
- WideString m_wsFamily;
- uint32_t m_dwStyles = 0;
- uint32_t m_dwCodePage = 0;
- RetainPtr<CFGAS_GEFont> m_pFont;
- };
-
- CFWL_FontManager();
- ~CFWL_FontManager();
-
- std::vector<std::unique_ptr<FontData>> m_FontsArray;
-};
-
#endif // XFA_FWL_THEME_CFWL_WIDGETTP_H_
diff --git a/xfa/fxfa/cxfa_fwltheme.cpp b/xfa/fxfa/cxfa_fwltheme.cpp
index d286213..a5a863c 100644
--- a/xfa/fxfa/cxfa_fwltheme.cpp
+++ b/xfa/fxfa/cxfa_fwltheme.cpp
@@ -25,6 +25,7 @@
#include "xfa/fwl/cfwl_scrollbar.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_themetext.h"
+#include "xfa/fwl/theme/cfwl_fontmanager.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
#include "xfa/fxfa/cxfa_ffapp.h"
#include "xfa/fxfa/cxfa_ffwidget.h"