ReactOS 0.4.16-dev-2293-g4d8327b
CFontCache Class Reference

#include <CFontCache.hpp>

Collaboration diagram for CFontCache:

Public Member Functions

void Read ()
 
void SetFontDir (const LPCWSTR Path)
 
const CStringW & FontPath () const
 
CStringW GetFontFilePath (const PCWSTR Path) const
 
size_t Size ()
 
CStringW Name (size_t Index)
 
CStringW File (size_t Index)
 
CFontInfoFind (const FontPidlEntry *fontEntry)
 
BOOL IsMarkDeleted (size_t Index) const
 
void MarkDeleted (const FontPidlEntry *fontEntry)
 
CStringW Filename (CFontInfo *info, bool alwaysFullPath=false)
 

Protected Member Functions

 CFontCache ()
 
void Insert (CAtlList< CFontInfo > &fonts, const CStringW &KeyName, PCWSTR Value)
 

Private Attributes

CSimpleArray< CFontInfom_Fonts
 
CStringW m_FontFolderPath
 

Friends

class CFontExtModule
 

Detailed Description

Definition at line 39 of file CFontCache.hpp.

Constructor & Destructor Documentation

◆ CFontCache()

CFontCache::CFontCache ( )
protected

Definition at line 117 of file CFontCache.cpp.

118{
119}

Member Function Documentation

◆ File()

CStringW CFontCache::File ( size_t  Index)

Definition at line 146 of file CFontCache.cpp.

147{
148 if (m_Fonts.GetSize() == 0)
149 Read();
150
151 if ((INT)Index >= m_Fonts.GetSize())
152 return L"";
153
154 return m_Fonts[Index].File();
155}
CSimpleArray< CFontInfo > m_Fonts
Definition: CFontCache.hpp:42
void Read()
Definition: CFontCache.cpp:243
#define L(x)
Definition: resources.c:13
int32_t INT
Definition: typedefs.h:58
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by CEnumFonts::Next(), and CFontExt::ParseDisplayName().

◆ Filename()

CStringW CFontCache::Filename ( CFontInfo info,
bool  alwaysFullPath = false 
)

Definition at line 193 of file CFontCache.cpp.

194{
196 if (info)
197 {
198 File = info->File();
199
200 if (!File.IsEmpty() && alwaysFullPath)
201 {
202 // Ensure this is a full path
204 {
206 }
207 }
208 }
209
210 return File;
211}
CStringW m_FontFolderPath
Definition: CFontCache.hpp:43
Definition: File.h:16
BOOL WINAPI PathIsRelativeW(const WCHAR *path)
Definition: path.c:1030

Referenced by _CDataObject_CreateInstance(), and CFontInfo::ReadAttrs().

◆ Find()

CFontInfo * CFontCache::Find ( const FontPidlEntry fontEntry)

Definition at line 157 of file CFontCache.cpp.

158{
159 if (m_Fonts.GetSize() == 0)
160 Read();
161
162 for (INT i = 0; i < m_Fonts.GetSize(); ++i)
163 {
164 if (m_Fonts[i].Name().CompareNoCase(fontEntry->Name()) == 0)
165 {
166 return &m_Fonts[i];
167 }
168 }
169 return nullptr;
170}
LPWSTR Name
Definition: desk.c:124
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LPWSTR Name()
Definition: fontpidl.hpp:18

Referenced by _CDataObject_CreateInstance(), CFontExt::CompareIDs(), and CFontExt::GetDetailsOf().

◆ FontPath()

const CStringW & CFontCache::FontPath ( ) const
inline

Definition at line 54 of file CFontCache.hpp.

54{ return m_FontFolderPath; }

Referenced by InstallFontFiles().

◆ GetFontFilePath()

CStringW CFontCache::GetFontFilePath ( const PCWSTR  Path) const

Definition at line 236 of file CFontCache.cpp.

237{
239 return m_FontFolderPath + Path;
240 return Path;
241}
PRTL_UNICODE_STRING_BUFFER Path

Referenced by DeleteFontFiles(), CFontExt::GetDisplayNameOf(), CFontExt::GetUIObjectOf(), Insert(), CFontExt::ParseDisplayName(), and RunFontViewer().

◆ Insert()

void CFontCache::Insert ( CAtlList< CFontInfo > &  fonts,
const CStringW KeyName,
PCWSTR  Value 
)
protected

Definition at line 213 of file CFontCache.cpp.

214{
215 CFontInfo newInfo(KeyName, Value);
216
217 CStringW strFontFile = g_FontCache->GetFontFilePath(newInfo.File());
218 if (!PathFileExistsW(strFontFile))
219 return;
220
221 POSITION it = fonts.GetHeadPosition();
222 while (it != NULL)
223 {
224 POSITION lastit = it;
225 const CFontInfo& info = fonts.GetNext(it);
226 if (info.Name().CompareNoCase(KeyName) >= 0)
227 {
228 fonts.InsertBefore(lastit, newInfo);
229 return;
230 }
231 }
232
233 fonts.AddTail(newInfo);
234}
CFontCache * g_FontCache
Definition: CFontCache.cpp:12
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:629
POSITION GetHeadPosition() const
Definition: atlcoll.h:554
POSITION InsertBefore(_In_ POSITION pos, INARGTYPE element)
Definition: atlcoll.h:704
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:566
CStringW GetFontFilePath(const PCWSTR Path) const
Definition: CFontCache.cpp:236
#define NULL
Definition: types.h:112
BOOL WINAPI PathFileExistsW(const WCHAR *path)
Definition: path.c:2607
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by Read().

◆ IsMarkDeleted()

BOOL CFontCache::IsMarkDeleted ( size_t  Index) const

Definition at line 172 of file CFontCache.cpp.

173{
174 if ((INT)Index >= m_Fonts.GetSize())
175 return FALSE;
176 return m_Fonts[Index].IsMarkDeleted();
177}
#define FALSE
Definition: types.h:117

Referenced by CEnumFonts::Next(), and CEnumFonts::Skip().

◆ MarkDeleted()

void CFontCache::MarkDeleted ( const FontPidlEntry fontEntry)

Definition at line 181 of file CFontCache.cpp.

182{
183 for (INT i = 0; i < m_Fonts.GetSize(); ++i)
184 {
185 if (m_Fonts[i].Name().CompareNoCase(fontEntry->Name()) == 0)
186 {
187 m_Fonts[i].MarkDeleted();
188 break;
189 }
190 }
191}

Referenced by DeleteFontFiles().

◆ Name()

CStringW CFontCache::Name ( size_t  Index)

Definition at line 135 of file CFontCache.cpp.

136{
137 if (m_Fonts.GetSize() == 0)
138 Read();
139
140 if ((INT)Index >= m_Fonts.GetSize())
141 return L"";
142
143 return m_Fonts[Index].Name();
144}

Referenced by CEnumFonts::Next(), and CFontExt::ParseDisplayName().

◆ Read()

void CFontCache::Read ( )

Definition at line 243 of file CFontCache.cpp.

244{
245 CRegKey key;
247 if (error != ERROR_SUCCESS)
248 {
249 ERR("Can't open registry: %ld\n", error);
250 return;
251 }
252
254 DWORD cchName = MAX_PATH, cchValue = MAX_PATH;
255 if (!Name.Allocate(cchName) || !Value.Allocate(cchValue))
256 {
257 ERR("Out of memory\n");
258 return;
259 }
260
261 // Enumerate all registered font names
263 for (DWORD iItem = 0;; ++iItem)
264 {
265 DWORD cchName2 = cchName, cbValue = cchValue * sizeof(WCHAR);
266 error = RegEnumValueW(key, iItem, Name, &cchName2, NULL, NULL,
267 (PBYTE)(PWSTR)Value, &cbValue);
268 if (error == ERROR_MORE_DATA)
269 {
270 cchName += 128;
271 cchValue += 128;
272 if (!Name.Reallocate(cchName) || !Value.Reallocate(cchValue))
273 {
274 ERR("Out of memory\n");
275 break;
276 }
277 --iItem;
278 continue;
279 }
280
281 if (error != ERROR_SUCCESS)
282 break;
283
284 if (Name[0] && Value[0])
285 {
286 // Insert will create an ordered list (sorted)
287 Insert(fonts, (PCWSTR)Name, (PCWSTR)Value);
288 }
289 }
290
291 // Move the fonts from a list to an array (for easy indexing)
292 m_Fonts.RemoveAll();
293 POSITION it = fonts.GetHeadPosition();
294 while (it != NULL)
295 m_Fonts.Add(fonts.GetNext(it));
296}
#define ERR(fmt,...)
Definition: precomp.h:57
void Insert(CAtlList< CFontInfo > &fonts, const CStringW &KeyName, PCWSTR Value)
Definition: CFontCache.cpp:213
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define FONT_HIVE
Definition: precomp.h:50
#define FONT_KEY
Definition: precomp.h:51
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
#define error(str)
Definition: mkdosfs.c:1605
#define KEY_READ
Definition: nt_native.h:1026
BYTE * PBYTE
Definition: pedump.c:66
Definition: copy.c:22
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName
Definition: winbase.h:2521
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CFontExt::Drop(), File(), CFontFolderViewCB::FilterEvent(), Find(), Name(), CFontExt::ParseDisplayName(), and Size().

◆ SetFontDir()

void CFontCache::SetFontDir ( const LPCWSTR  Path)

Definition at line 121 of file CFontCache.cpp.

122{
125}
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394

Referenced by CFontExt::Initialize().

◆ Size()

size_t CFontCache::Size ( )

Definition at line 127 of file CFontCache.cpp.

128{
129 if (m_Fonts.GetSize() == 0)
130 Read();
131
132 return m_Fonts.GetSize();
133}

Referenced by CEnumFonts::Next(), CFontExt::ParseDisplayName(), and CEnumFonts::Skip().

Friends And Related Function Documentation

◆ CFontExtModule

friend class CFontExtModule
friend

Definition at line 66 of file CFontCache.hpp.

Member Data Documentation

◆ m_FontFolderPath

CStringW CFontCache::m_FontFolderPath
private

Definition at line 43 of file CFontCache.hpp.

Referenced by Filename(), FontPath(), GetFontFilePath(), and SetFontDir().

◆ m_Fonts

CSimpleArray<CFontInfo> CFontCache::m_Fonts
private

Definition at line 42 of file CFontCache.hpp.

Referenced by File(), Find(), IsMarkDeleted(), MarkDeleted(), Name(), Read(), and Size().


The documentation for this class was generated from the following files: