Basic FreeType renderer implementation.
[gdipp.git] / gdipp_server / os2_metrics.cpp
blob0fd62e9428881b2da7e18a862a36fa0edd501221
1 #include "stdafx.h"
2 #include "os2_metrics.h"
3 #include "gdipp_lib/helper.h"
4 #include "gdipp_rpc/gdipp_rpc.h"
5 #include "gdipp_server/global.h"
7 namespace gdipp
10 #define OS2_TABLE_TAG mmioFOURCC('O', 'S', '/', '2')
12 // little-endian <-> big-endian
13 #define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
14 #define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
16 bool os2_metrics::init(HDC hdc)
18 // retrieve needed fields from the OS/2 table
20 DWORD font_data_size;
22 font_data_size = GetFontData(hdc, OS2_TABLE_TAG, offsetof(TT_OS2, xAvgCharWidth), &_xAvgCharWidth, sizeof(_xAvgCharWidth));
23 if (font_data_size == GDI_ERROR)
24 return false;
26 font_data_size = GetFontData(hdc, OS2_TABLE_TAG, offsetof(TT_OS2, usWeightClass), &_usWeightClass, sizeof(_usWeightClass));
27 if (font_data_size == GDI_ERROR)
28 return false;
30 font_data_size = GetFontData(hdc, OS2_TABLE_TAG, offsetof(TT_OS2, usWidthClass), &_usWidthClass, sizeof(_usWidthClass));
31 if (font_data_size == GDI_ERROR)
32 return false;
34 font_data_size = GetFontData(hdc, OS2_TABLE_TAG, offsetof(TT_OS2, fsSelection), &_fsSelection, sizeof(_fsSelection));
35 if (font_data_size == GDI_ERROR)
36 return false;
38 _xAvgCharWidth = SWAPWORD(_xAvgCharWidth);
39 _usWeightClass = SWAPWORD(_usWeightClass);
40 _usWidthClass = SWAPWORD(_usWidthClass);
41 _fsSelection = SWAPWORD(_fsSelection);
43 return true;
46 bool os2_metrics::init(void *font_id)
48 // retrieve needed fields from the OS/2 table
50 DWORD font_data_size;
52 HDC font_holder = dc_pool_instance.claim();
54 font_data_size = font_mgr_instance.lookup_font_data(font_id, OS2_TABLE_TAG, offsetof(TT_OS2, xAvgCharWidth), reinterpret_cast<byte *>(&_xAvgCharWidth), sizeof(_xAvgCharWidth), font_holder);
55 if (font_data_size == GDI_ERROR)
56 goto failed_init_os2_metrics;
58 font_data_size = font_mgr_instance.lookup_font_data(font_id, OS2_TABLE_TAG, offsetof(TT_OS2, usWeightClass), reinterpret_cast<byte *>(&_usWeightClass), sizeof(_usWeightClass), font_holder);
59 if (font_data_size == GDI_ERROR)
60 goto failed_init_os2_metrics;
62 font_data_size = font_mgr_instance.lookup_font_data(font_id, OS2_TABLE_TAG, offsetof(TT_OS2, usWidthClass), reinterpret_cast<byte *>(&_usWidthClass), sizeof(_usWidthClass), font_holder);
63 if (font_data_size == GDI_ERROR)
64 goto failed_init_os2_metrics;
66 font_data_size = font_mgr_instance.lookup_font_data(font_id, OS2_TABLE_TAG, offsetof(TT_OS2, fsSelection), reinterpret_cast<byte *>(&_fsSelection), sizeof(_fsSelection), font_holder);
67 if (font_data_size == GDI_ERROR)
68 goto failed_init_os2_metrics;
70 _xAvgCharWidth = SWAPWORD(_xAvgCharWidth);
71 _usWeightClass = SWAPWORD(_usWeightClass);
72 _usWidthClass = SWAPWORD(_usWidthClass);
73 _fsSelection = SWAPWORD(_fsSelection);
75 return true;
77 failed_init_os2_metrics:
78 dc_pool_instance.free(font_holder);
79 return false;
82 FT_Short os2_metrics::get_xAvgCharWidth() const
84 return _xAvgCharWidth;
87 char os2_metrics::get_weight_class() const
89 return get_gdi_weight_class(_usWeightClass);
92 FT_UShort os2_metrics::get_usWidthClass() const
94 return _usWidthClass;
97 bool os2_metrics::is_italic() const
99 return (_fsSelection & 1);