Use One-Time Initialization for glyph run caching to avoid duplicate glyph run genera...
[gdipp.git] / gdipp_server / font_mgr.h
bloba23a6827425daadcddb49f594603dab649e93c8e
1 #pragma once
3 #include "gdipp_server/os2_metrics.h"
5 namespace gdipp
8 #define buf_family_name(metric_buf) (reinterpret_cast<const wchar_t *>(metric_buf + reinterpret_cast<const UINT>((reinterpret_cast<const OUTLINETEXTMETRICW *>(metric_buf)->otmpFamilyName))))
9 #define buf_face_name(metric_buf) (reinterpret_cast<const wchar_t *>(metric_buf + reinterpret_cast<const UINT>((reinterpret_cast<const OUTLINETEXTMETRICW *>(metric_buf)->otmpFaceName))))
10 #define buf_style_name(metric_buf) (reinterpret_cast<const wchar_t *>(metric_buf + reinterpret_cast<const UINT>((reinterpret_cast<const OUTLINETEXTMETRICW *>(metric_buf)->otmpStyleName))))
11 #define metric_family_name(outline_metric) (reinterpret_cast<const wchar_t *>(reinterpret_cast<const BYTE *>(outline_metric) + reinterpret_cast<const UINT>(outline_metric->otmpFamilyName)))
12 #define metric_face_name(outline_metric) (reinterpret_cast<const wchar_t *>(reinterpret_cast<const BYTE *>(outline_metric) + reinterpret_cast<const UINT>(outline_metric->otmpFaceName)))
13 #define metric_style_name(outline_metric) (reinterpret_cast<const wchar_t *>(reinterpret_cast<const BYTE *>(outline_metric) + reinterpret_cast<const UINT>(outline_metric->otmpStyleName)))
15 class font_mgr
17 public:
18 static DWORD get_font_size(HDC font_holder, DWORD *table_header);
19 static ULONG get_ttc_face_index(HDC font_holder, DWORD ttc_file_size);
21 font_mgr();
22 ~font_mgr();
24 void *register_font(HDC font_holder, const LOGFONTW *log_font, BYTE **outline_metrics_buf, unsigned long *outline_metrics_size);
25 HFONT select_font(void *font_id, HDC hdc) const;
27 ULONG lookup_face_index(void *font_id) const;
28 const os2_metrics *lookup_os2_metrics(void *font_id) const;
29 FT_Stream lookup_stream(void *font_id) const;
31 HDC get_thread_font_holder() const;
32 BOOL set_thread_font_holder(HDC font_holder) const;
34 private:
35 struct _font_entry
37 // all fields are font-specific and thread-safe invariants
39 HFONT font_handle;
40 os2_metrics os2;
41 FT_StreamRec stream;
43 // used to retrieve font data from GetFontData
44 DWORD face_index;
45 DWORD table_header;
48 static unsigned long get_dc_outline_metrics(HDC hdc, BYTE **outline_metrics_buf);
49 static unsigned long stream_io(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count);
50 static void stream_close(FT_Stream stream);
52 std::map<std::wstring, _font_entry> _font_registry;
53 DWORD _font_holder_tls_index;