7#include "helper/SplitString.h"
8#include "layout/SLayoutSize.h"
9#include "helper/SHostMgr.h"
13int CALLBACK DefFontsEnumProc(CONST LOGFONT *lplf,
14 CONST TEXTMETRIC *lptm,
19 BOOL *pbValidFont = (BOOL *)lpData;
24static BOOL DefFontCheck(
const SStringW &strFontName)
26 return HasFont(S_CW2T(strFontName));
59static const WCHAR KFontPropSeprator = L
',';
60static const WCHAR KPropSeprator = L
':';
61static const WCHAR kExPropKey[] = L
"exprop";
62static const WCHAR KFontFace[] = L
"face";
63static const WCHAR KFontBold[] = L
"bold";
64static const WCHAR KFontUnderline[] = L
"underline";
65static const WCHAR KFontItalic[] = L
"italic";
66static const WCHAR KFontStrike[] = L
"strike";
67static const WCHAR KFontAdding[] = L
"adding";
68static const WCHAR KFontSize[] = L
"size";
69static const WCHAR KFontCharset[] = L
"charset";
70static const WCHAR KFontWeight[] = L
"weight";
71static const WCHAR KFontEscapement[] = L
"escapement";
72const static WCHAR KDefFontFace[] = L
"宋体";
76 SStringW strFontDesc = GETUIDEF->GetFontDesc(strFont);
79 IFontPtr hftRet = NULL;
94 LOGFONT lfNew = { 0 };
100 if (lfNew.lfWeight == 0)
101 lfNew.lfWeight = (fontInfo.
style.attr.
fBold ? FW_BOLD : FW_NORMAL);
103 lfNew.lfItalic = (FALSE != fontInfo.
style.attr.
fItalic);
104 lfNew.lfStrikeOut = (FALSE != fontInfo.
style.attr.
fStrike);
118 lfNew.lfQuality = CLEARTYPE_QUALITY;
120 _tcscpy_s(lfNew.lfFaceName, _countof(lfNew.lfFaceName), S_CW2T(fontInfo.
strFaceName));
152 emptyDefFont.
scale = 100;
171 nodeExp = xmlExProp.
root().
child(kExPropKey);
174 SArray<SStringW> strLst;
175 size_t nSeg = SplitString(fontDesc2, KFontPropSeprator, strLst);
176 for (
size_t i = 0; i < nSeg; i++)
179 size_t n = SplitString(strLst[i], KPropSeprator, kv);
183 if (kv[0] == KFontFace)
185 if (kv[1][0] == L
'\'' || kv[1][0] == L
'\"')
190 else if (kv[0] == KFontSize)
194 fi.
style.attr.
nSize = (short)abs(layoutSize.fSize);
198 else if (kv[0] == KFontAdding)
202 fi.
style.attr.
nSize = (short)layoutSize.fSize;
206 else if (kv[0] == KFontCharset)
210 else if (kv[0] == KFontWeight)
214 else if (kv[0] == KFontBold)
218 else if (kv[0] == KFontItalic)
222 else if (kv[0] == KFontStrike)
226 else if (kv[0] == KFontUnderline)
230 else if (kv[0] == KFontEscapement)
232 int fescapement = (int)(_wtof(kv[1]) * 10);
257 s << KFontSize << KPropSeprator << (short)fi.
style.attr.
nSize <<
",";
258 s << KFontCharset << KPropSeprator << fi.
style.attr.
byCharset <<
",";
259 s << KFontWeight << KPropSeprator << fi.
style.attr.
byWeight * 4 <<
",";
260 s << KFontBold << KPropSeprator << (fi.
style.attr.
fBold ?
"1" :
"0") <<
",";
261 s << KFontItalic << KPropSeprator << (fi.
style.attr.
fItalic ?
"1" :
"0") <<
",";
262 s << KFontStrike << KPropSeprator << (fi.
style.attr.
fStrike ?
"1" :
"0") <<
",";
263 s << KFontUnderline << KPropSeprator << (fi.
style.attr.
fUnderline ?
"1" :
"0");
266 return S_CA2W(szBuf);
271 return GETUIDEF->GetFont(strFont, scale);
276 return GETUIDEF->SetDefFontInfo(strFontInfo);
281 return GETUIDEF->GetDefFontInfo();
SOUI Font Management Module.
bool GetKeyObject(const FontInfo &key, IFontPtr &obj) const
bool AddKeyObject(const FontInfo &key, const IFontPtr &obj)
bool HasKey(const FontInfo &key) const
void(* m_pFunOnKeyRemoved)(const IFontPtr &obj)
static FunFontCheck s_funFontCheck
const FontInfo & _GetDefFontInfo() const
Get constant reference to default font information.
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.
static void SetFontChecker(FunFontCheck fontCheck)
Set the callback function for checking fonts.
SAutoRefPtr< IRenderFactory > m_RenderFactory
SFontPool(IRenderFactory *fac)
Constructor.
void SetRenderFactory(IRenderFactory *fac)
Set render factory object.
static BOOL CheckFont(const SStringW &strFontName)
Check if a font is valid.
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.
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.
static void SetDefFontInfo(const SStringW &strFontInfo)
Set default font.
static FontInfo GetDefFontInfo()
Get default font information.
void DispatchMessage(UINT uMsg, WPARAM wp=0, LPARAM lp=0)
分发消息到宿主窗口
void parseString(const SStringW &strSize)
从字符串解析大小
int toPixelSize(int scale) const
将大小转换为像素值
static SHostMgr * getSingletonPtr(void)
A class representing an ASCII string.
const wchar_t * c_str() SCONST
Retrieves a C-style string representation of the string.
BOOL IsEmpty() SCONST
Checks if the string is empty.
SStringW Mid(int nFirst) const
Extracts a substring from the string.
bool set_value(const wchar_t *rhs)
Sets the attribute value.
Implementation of IXmlDoc.
SXmlNode root() const
Retrieves the root node of the document.
bool load_string(const wchar_t *contents, unsigned int options=xml_parse_default)
Loads the document from a zero-terminated string.
Class representing an XML node.
SXmlAttr first_attribute() const
Gets the first attribute of the node.
void ToString(IStringW *out) SCONST OVERRIDE
Converts the node to a string representation.
SXmlAttr append_attribute(const wchar_t *name)
Adds an attribute with the specified name.
SXmlNode child(const wchar_t *name, bool bCaseSensitive=false) const
Gets the child node, attribute, or next/previous sibling with the specified name.
SXmlNode append_child(XmlNodeType type=node_element)
Adds a child node with the specified type.
Font information structure.
void SetProp(IXmlNode *pXmlNode) PURE
Sets properties from an XML node.
long Release() PURE
Decrements the reference count for the object.