Font: Allow setting dpi internally
This fixes some unexpected changes in text rendering for OpenFL which rely on a private function in Lime. Previously we defaulted at 72 dpi, which apparently is expected to layout the text properly. Most displays are 96 dpi or higher today, so we should probably look into this. For RenderGlyph, which was previously broken over several versions, we will now use a dpi of 96 for now. In the next version of lime, we absolutely should alter the function signature to allow for renderGlyph to accept a dpi argument.
This commit is contained in:
@@ -59,7 +59,7 @@ namespace lime {
|
||||
int GetUnitsPerEM ();
|
||||
int RenderGlyph (int index, Bytes *bytes, int offset = 0);
|
||||
int RenderGlyphs (value indices, Bytes *bytes);
|
||||
void SetSize (size_t size);
|
||||
void SetSize (size_t size, size_t dpi);
|
||||
|
||||
void* library;
|
||||
void* face;
|
||||
|
||||
@@ -1602,21 +1602,21 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void lime_font_set_size (value fontHandle, int fontSize) {
|
||||
void lime_font_set_size (value fontHandle, int fontSize, int dpi) {
|
||||
|
||||
#ifdef LIME_FREETYPE
|
||||
Font *font = (Font*)val_data (fontHandle);
|
||||
font->SetSize (fontSize);
|
||||
font->SetSize (fontSize, dpi);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM void HL_NAME(hl_font_set_size) (HL_CFFIPointer* fontHandle, int fontSize) {
|
||||
HL_PRIM void HL_NAME(hl_font_set_size) (HL_CFFIPointer* fontHandle, int fontSize, int dpi) {
|
||||
|
||||
#ifdef LIME_FREETYPE
|
||||
Font *font = (Font*)fontHandle->ptr;
|
||||
font->SetSize (fontSize);
|
||||
font->SetSize (fontSize, dpi);
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -4153,7 +4153,7 @@ namespace lime {
|
||||
DEFINE_HL_PRIM (_DYN, hl_font_outline_decompose, _TCFFIPOINTER _I32);
|
||||
DEFINE_HL_PRIM (_TBYTES, hl_font_render_glyph, _TCFFIPOINTER _I32 _TBYTES);
|
||||
DEFINE_HL_PRIM (_TBYTES, hl_font_render_glyphs, _TCFFIPOINTER _ARR _TBYTES);
|
||||
DEFINE_HL_PRIM (_VOID, hl_font_set_size, _TCFFIPOINTER _I32);
|
||||
DEFINE_HL_PRIM (_VOID, hl_font_set_size, _TCFFIPOINTER _I32 _I32);
|
||||
DEFINE_HL_PRIM (_VOID, hl_gamepad_add_mappings, _ARR);
|
||||
DEFINE_HL_PRIM (_VOID, hl_gamepad_event_manager_register, _FUN(_VOID, _NO_ARG) _TGAMEPAD_EVENT);
|
||||
DEFINE_HL_PRIM (_BYTES, hl_gamepad_get_device_guid, _I32);
|
||||
|
||||
@@ -1039,14 +1039,22 @@ namespace lime {
|
||||
return totalOffset;
|
||||
|
||||
}
|
||||
|
||||
void Font::SetSize(size_t size, size_t dpi)
|
||||
{
|
||||
//We changed the function signature to include a dpi argument which changes this from
|
||||
//the default value of 72 for dpi. Any public api that uses this should probably be changed
|
||||
//to allow setting the dpi in an appropriate future release.
|
||||
size_t hdpi = dpi;
|
||||
size_t vdpi = dpi;
|
||||
|
||||
|
||||
void Font::SetSize (size_t size) {
|
||||
|
||||
size_t hdpi = 72;
|
||||
size_t vdpi = 72;
|
||||
|
||||
FT_Set_Char_Size ((FT_Face)face, (int)(size*64), (int)(size*64), hdpi, vdpi);
|
||||
FT_Set_Char_Size(
|
||||
(FT_Face)face, //Handle to the target face object
|
||||
0, //Char width in 1/64th of points (0 means same as height)
|
||||
static_cast<int>(size * 64), //Char height in 1/64th of points
|
||||
hdpi, //Horizontal DPI
|
||||
vdpi //Vertical DPI
|
||||
);
|
||||
mSize = size;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user