2 #include "os2_metrics.h"
3 #include "gdipp_lib/helper.h"
4 #include "gdipp_rpc/gdipp_rpc.h"
5 #include "gdipp_server/global.h"
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
22 font_data_size
= GetFontData(hdc
, OS2_TABLE_TAG
, offsetof(TT_OS2
, xAvgCharWidth
), &_xAvgCharWidth
, sizeof(_xAvgCharWidth
));
23 if (font_data_size
== GDI_ERROR
)
26 font_data_size
= GetFontData(hdc
, OS2_TABLE_TAG
, offsetof(TT_OS2
, usWeightClass
), &_usWeightClass
, sizeof(_usWeightClass
));
27 if (font_data_size
== GDI_ERROR
)
30 font_data_size
= GetFontData(hdc
, OS2_TABLE_TAG
, offsetof(TT_OS2
, usWidthClass
), &_usWidthClass
, sizeof(_usWidthClass
));
31 if (font_data_size
== GDI_ERROR
)
34 font_data_size
= GetFontData(hdc
, OS2_TABLE_TAG
, offsetof(TT_OS2
, fsSelection
), &_fsSelection
, sizeof(_fsSelection
));
35 if (font_data_size
== GDI_ERROR
)
38 _xAvgCharWidth
= SWAPWORD(_xAvgCharWidth
);
39 _usWeightClass
= SWAPWORD(_usWeightClass
);
40 _usWidthClass
= SWAPWORD(_usWidthClass
);
41 _fsSelection
= SWAPWORD(_fsSelection
);
46 bool os2_metrics::init(void *font_id
)
48 // retrieve needed fields from the OS/2 table
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
);
77 failed_init_os2_metrics
:
78 dc_pool_instance
.free(font_holder
);
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
97 bool os2_metrics::is_italic() const
99 return (_fsSelection
& 1);