Basic FreeType renderer implementation.
[gdipp.git] / gdipp_server / font_mgr.h
blob58628507438361ed4df5bd3328f5ea37be143c5a
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 void *register_font(const LOGFONTW *log_font, BYTE **outline_metrics_buf, unsigned long *outline_metrics_size, HDC hdc = NULL);
22 HFONT select_font(void *font_id, HDC hdc) const;
24 ULONG lookup_face_index(void *font_id) const;
25 DWORD lookup_font_data(void *font_id, DWORD table, DWORD offset, LPVOID data_buf, DWORD buf_size, HDC hdc = NULL) const;
26 DWORD lookup_glyph_indices(void *font_id, const wchar_t *str, int count, unsigned short *gi, HDC hdc = NULL) const;
27 const os2_metrics *lookup_os2_metrics(void *font_id) const;
28 FT_Stream lookup_stream(void *font_id) const;
30 private:
31 struct font_entry
33 // all fields are font-specific invariants
35 HFONT font_handle;
36 os2_metrics os2;
37 FT_StreamRec stream;
39 // used to retrieve font data from GetFontData
40 DWORD face_index;
41 DWORD table_header;
44 static unsigned long get_dc_outline_metrics(HDC hdc, BYTE **outline_metrics_buf);
45 static unsigned long stream_io(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count);
46 static void stream_close(FT_Stream stream);
48 std::map<std::wstring, font_entry> _font_registry;