soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SFontPool.h
Go to the documentation of this file.
1/**
2 * @file SFontPool.h
3 * @brief SOUI Font Management Module
4 * @version v1.0
5 * @author SOUI group
6 * @date 2014/08/02
7 *
8 * @details This module manages and retrieves font resources.
9 */
10
11#ifndef __SFONTPOOL__H__
12#define __SFONTPOOL__H__
13
14#include <core/SSingletonMap.h>
15#include <interface/SRender-i.h>
16#include <res.mgr/SFontInfo.h>
17#include <helper/obj-ref-impl.hpp>
18
19#define FF_DEFAULTFONT L""
20
21SNSBEGIN
22
23/**
24 * @class FontKey
25 * @brief Key for a FONT
26 *
27 * @details Used to implement a font map, uniquely identifying a font.
28 */
29typedef FontInfo FontKey;
30
31/**
32 * @class CElementTraits<FontInfo>
33 * @brief Hash and comparison template for FontInfo
34 *
35 * @details Used to implement a font map, providing hash and comparison functions.
36 */
37template <>
38class CElementTraits<FontInfo> : public CElementTraitsBase<FontInfo> {
39 public:
40 /**
41 * @brief Calculate the hash value of a FontInfo object
42 * @param fontKey FontInfo object
43 * @return Hash value
44 */
45 static ULONG Hash(INARGTYPE fontKey)
46 {
47 ULONG uRet = SNS::CElementTraits<SStringW>::Hash(fontKey.strFaceName);
48 uRet = (uRet << 5) + SNS::CElementTraits<SStringW>::Hash(fontKey.strPropEx);
49 uRet = (uRet << 5) + (UINT)fontKey.style.syle + 1 + fontKey.scale;
50 return uRet;
51 }
52
53 /**
54 * @brief Compare two FontInfo objects for equality
55 * @param element1 First FontInfo object
56 * @param element2 Second FontInfo object
57 * @return True if equal, false otherwise
58 */
59 static bool CompareElements(INARGTYPE element1, INARGTYPE element2)
60 {
61 return element1.strFaceName == element2.strFaceName && element1.strPropEx == element2.strPropEx && element1.style.syle == element2.style.syle && element1.scale == element2.scale;
62 }
63
64 /**
65 * @brief Compare two FontInfo objects in order
66 * @param element1 First FontInfo object
67 * @param element2 Second FontInfo object
68 * @return Comparison result, 0 if equal, negative if element1 < element2, positive if element1 > element2
69 */
70 static int CompareElementsOrdered(INARGTYPE element1, INARGTYPE element2)
71 {
72 int nRet = element1.strFaceName.Compare(element2.strFaceName);
73 if (nRet == 0)
74 nRet = element1.strPropEx.Compare(element2.strPropEx);
75 if (nRet == 0)
76 nRet = (int)(element1.style.syle - element2.style.syle);
77 if (nRet == 0)
78 nRet = (int)(element1.scale - element2.scale);
79
80 return nRet;
81 }
82};
83
84typedef IFontS *IFontPtr;
85typedef BOOL (*FunFontCheck)(const SStringW &strFontName);
86
87/**
88 * @class SFontPool
89 * @brief Font pool management class
90 *
91 * @details Manages and retrieves font resources, supporting font caching and reuse.
92 */
93class SOUI_EXP SFontPool : public SCmnMap<IFontPtr, FontInfo> {
94 public:
95 /**
96 * @brief Set the callback function for checking fonts
97 * @param fontCheck Callback function for checking fonts
98 */
99 static void SetFontChecker(FunFontCheck fontCheck);
100
101 /**
102 * @brief Check if a font is valid
103 * @param strFontName Font name
104 * @return TRUE if valid, FALSE if invalid
105 */
106 static BOOL CheckFont(const SStringW &strFontName);
107
108 /**
109 * @brief Convert font description to FontInfo
110 * @param strFontInfo Font description string
111 * @param defFontInfo Default FontInfo
112 * @return FontInfo object
113 */
114 static FontInfo FontInfoFromString(const SStringW &strFontInfo, const FontInfo &defFontInfo);
115
116 /**
117 * @brief Convert FontInfo to font description
118 * @param fi FontInfo object
119 * @return Font description string
120 */
121 static SStringW FontInfoToString(const FontInfo &fi);
122
123 /**
124 * @brief Get IFontPtr corresponding to the specified description string
125 * @param strFont Font description string
126 * @param scale Scale factor
127 * @return IFontPtr Font object pointer
128 *
129 * @details Description string format: face:宋体,bold:0,italic:1,underline:1,strike:1,adding:10
130 */
131 static IFontPtr GetFont(const SStringW &strFont, int scale);
132
133 /**
134 * @brief Set default font
135 * @param strFontInfo Default font description string
136 */
137 static void SetDefFontInfo(const SStringW &strFontInfo);
138
139 /**
140 * @brief Get default font information
141 * @return FontInfo Default font information
142 */
143 static FontInfo GetDefFontInfo();
144
145 protected:
146 /**
147 * @brief Callback function when FontInfo is removed
148 * @param obj Removed IFontPtr object
149 */
150 static void OnKeyRemoved(const IFontPtr &obj);
151
152 protected:
153 /**
154 * @brief Constructor
155 * @param fac Render factory object pointer
156 */
158
159 protected:
160 /**
161 * @brief Get constant reference to default font information
162 * @return FontInfo Constant reference to default font information
163 */
164 const FontInfo &_GetDefFontInfo() const;
165
166 /**
167 * @brief Set render factory object
168 * @param fac Render factory object pointer
169 */
171
172 /**
173 * @brief Get IFontPtr corresponding to the specified description string
174 * @param strFont Font description string
175 * @param scale Scale factor
176 * @return IFontPtr Font object pointer
177 */
178 IFontPtr _GetFont(const SStringW &strFont, int scale);
179
180 /**
181 * @brief Set default font description string
182 * @param strFontInfo Default font description string
183 */
184 void _SetDefFontInfo(const SStringW &strFontInfo);
185
186 /**
187 * @brief Create font object corresponding to FontInfo
188 * @param fontInfo FontInfo object
189 * @return IFontPtr Font object pointer
190 */
191 IFontPtr _CreateFont(const FontInfo &fontInfo);
192
193 /**
194 * @brief Set default font information
195 * @param fontInfo FontInfo object
196 */
197 void _SetDefFontInfo(const FontInfo &fontInfo);
198
199 SAutoRefPtr<IRenderFactory> m_RenderFactory; /**< Render factory object pointer */
200 FontInfo m_defFontInfo; /**< Default font information */
201
202 static FunFontCheck s_funFontCheck; /**< Font check callback function */
203};
204
205SNSEND
206
207#endif // __SFONTPOOL__H__
static bool CompareElements(INARGTYPE element1, INARGTYPE element2)
Compare two FontInfo objects for equality.
Definition SFontPool.h:59
static ULONG Hash(INARGTYPE fontKey)
Calculate the hash value of a FontInfo object.
Definition SFontPool.h:45
static int CompareElementsOrdered(INARGTYPE element1, INARGTYPE element2)
Compare two FontInfo objects in order.
Definition SFontPool.h:70
Key for a FONT.
Smart pointer class for managing COM-style reference-counted objects.
SCmnMap(void(*funOnKeyRemoved)(const IFontPtr &)=NULL)
Definition SCmnMap.h:28
static FunFontCheck s_funFontCheck
Definition SFontPool.h:202
const FontInfo & _GetDefFontInfo() const
Get constant reference to default font information.
FontInfo m_defFontInfo
Definition SFontPool.h:200
static FontInfo FontInfoFromString(const SStringW &strFontInfo, const FontInfo &defFontInfo)
Convert font description to FontInfo.
static void OnKeyRemoved(const IFontPtr &obj)
Callback function when FontInfo is removed.
Definition SFontPool.cpp:54
static void SetFontChecker(FunFontCheck fontCheck)
Set the callback function for checking fonts.
Definition SFontPool.cpp:31
SAutoRefPtr< IRenderFactory > m_RenderFactory
Definition SFontPool.h:199
SFontPool(IRenderFactory *fac)
Constructor.
Definition SFontPool.cpp:41
void SetRenderFactory(IRenderFactory *fac)
Set render factory object.
Definition SFontPool.cpp:49
static BOOL CheckFont(const SStringW &strFontName)
Check if a font is valid.
Definition SFontPool.cpp:36
static IFontPtr GetFont(const SStringW &strFont, int scale)
Get IFontPtr corresponding to the specified description string.
IFontPtr _GetFont(const SStringW &strFont, int scale)
Get IFontPtr corresponding to the specified description string.
Definition SFontPool.cpp:74
void _SetDefFontInfo(const SStringW &strFontInfo)
Set default font description string.
static SStringW FontInfoToString(const FontInfo &fi)
Convert FontInfo to font description.
IFontPtr _CreateFont(const FontInfo &fontInfo)
Create font object corresponding to FontInfo.
Definition SFontPool.cpp:92
static void SetDefFontInfo(const SStringW &strFontInfo)
Set default font.
static FontInfo GetDefFontInfo()
Get default font information.
A class representing an ASCII string.
Definition sstringw.h:96
Font information structure.
Definition SFontInfo.h:51
Font object interface.
Definition SRender-i.h:650
RenderFactory object.
Definition SRender-i.h:2018