diff --git a/project/include/system/DisplayMode.h b/project/include/system/DisplayMode.h index b798fd20d..3271cdc76 100644 --- a/project/include/system/DisplayMode.h +++ b/project/include/system/DisplayMode.h @@ -9,36 +9,22 @@ namespace lime { - struct HL_DisplayMode { - - hl_type* t; - int height; - PixelFormat pixelFormat; - int refreshRate; - int width; - - }; - - class DisplayMode { public: - DisplayMode (); - DisplayMode (value DisplayMode); - DisplayMode (HL_DisplayMode* DisplayMode); - DisplayMode (int width, int height, PixelFormat pixelFormat, int refreshRate); - - void* Value (); - + hl_type* t; int height; PixelFormat pixelFormat; int refreshRate; int width; - private: + DisplayMode (); + DisplayMode (value DisplayMode); + DisplayMode (int width, int height, PixelFormat pixelFormat, int refreshRate); - HL_DisplayMode* _mode; + void CopyFrom (DisplayMode* other); + void* Value (); }; diff --git a/project/include/system/System.h b/project/include/system/System.h index 79a5a3f11..62a1063fc 100644 --- a/project/include/system/System.h +++ b/project/include/system/System.h @@ -32,7 +32,7 @@ namespace lime { static std::wstring* GetDeviceModel (); static std::wstring* GetDeviceVendor (); static std::wstring* GetDirectory (SystemDirectory type, const char* company, const char* title); - static value GetDisplay (int id); + static void* GetDisplay (bool useCFFIValue, int id); #ifdef IPHONE static std::wstring* GetIOSDirectory (SystemDirectory type); static bool GetIOSTablet (); diff --git a/project/include/text/Font.h b/project/include/text/Font.h index 21d4d11db..6523207db 100644 --- a/project/include/text/Font.h +++ b/project/include/text/Font.h @@ -45,13 +45,13 @@ namespace lime { Font (Resource *resource, int faceIndex = 0); ~Font (); - value Decompose (int em); + void* Decompose (bool useCFFIValue, int em); int GetAscender (); int GetDescender (); wchar_t *GetFamilyName (); int GetGlyphIndex (char* character); - value GetGlyphIndices (char* characters); - value GetGlyphMetrics (int index); + void* GetGlyphIndices (bool useCFFIValue, char* characters); + void* GetGlyphMetrics (bool useCFFIValue, int index); int GetHeight (); int GetNumGlyphs (); int GetUnderlinePosition (); diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index a2439863e..c1e254d6c 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -1141,7 +1141,7 @@ namespace lime { #ifdef LIME_FREETYPE Font *font = (Font*)val_data (fontHandle); - return font->GetGlyphIndices ((char*)characters.c_str ()); + return (value)font->GetGlyphIndices (true, (char*)characters.c_str ()); #else return alloc_null (); #endif @@ -1151,12 +1151,12 @@ namespace lime { HL_PRIM hl_varray* hl_lime_font_get_glyph_indices (HL_CFFIPointer* fontHandle, hl_vstring* characters) { - // #ifdef LIME_FREETYPE - // Font *font = (Font*)fontHandle->ptr; - // return font->GetGlyphIndices (characters ? (char*)hl_to_utf8 ((const uchar*)characters->bytes) : NULL); - // #else + #ifdef LIME_FREETYPE + Font *font = (Font*)fontHandle->ptr; + return (hl_varray*)font->GetGlyphIndices (false, characters ? (char*)hl_to_utf8 ((const uchar*)characters->bytes) : NULL); + #else return 0; - // #endif + #endif } @@ -1165,7 +1165,7 @@ namespace lime { #ifdef LIME_FREETYPE Font *font = (Font*)val_data (fontHandle); - return font->GetGlyphMetrics (index); + return (value)font->GetGlyphMetrics (true, index); #else return alloc_null (); #endif @@ -1175,12 +1175,12 @@ namespace lime { HL_PRIM vdynamic* hl_lime_font_get_glyph_metrics (HL_CFFIPointer* fontHandle, int index) { - // #ifdef LIME_FREETYPE - // Font *font = (Font*)fontHandle->ptr; - // return font->GetGlyphMetrics (index); - // #else + #ifdef LIME_FREETYPE + Font *font = (Font*)fontHandle->ptr; + return (vdynamic*)font->GetGlyphMetrics (false, index); + #else return 0; - // #endif + #endif } @@ -1436,7 +1436,7 @@ namespace lime { #ifdef LIME_FREETYPE Font *font = (Font*)val_data (fontHandle); - return font->Decompose (size); + return (value)font->Decompose (true, size); #else return alloc_null (); #endif @@ -1446,12 +1446,12 @@ namespace lime { HL_PRIM vdynamic* hl_lime_font_outline_decompose (HL_CFFIPointer* fontHandle, int size) { - // #ifdef LIME_FREETYPE - // Font *font = (Font*)fontHandle->ptr; - // return font->Decompose (size); - // #else + #ifdef LIME_FREETYPE + Font *font = (Font*)fontHandle->ptr; + return (vdynamic*)font->Decompose (false, size); + #else return 0; - // #endif + #endif } @@ -2765,15 +2765,14 @@ namespace lime { value lime_system_get_display (int id) { - return System::GetDisplay (id); + return (value)System::GetDisplay (true, id); } HL_PRIM vdynamic* hl_lime_system_get_display (int id) { - return 0; - //return System::GetDisplay (id); + return (vdynamic*)System::GetDisplay (false, id); } @@ -3278,12 +3277,12 @@ namespace lime { } - HL_PRIM HL_DisplayMode* hl_lime_window_get_display_mode (HL_CFFIPointer* window, HL_DisplayMode* displayMode) { + HL_PRIM void hl_lime_window_get_display_mode (HL_CFFIPointer* window, DisplayMode* result) { Window* targetWindow = (Window*)window->ptr; - DisplayMode _displayMode = DisplayMode (displayMode); - targetWindow->GetDisplayMode (&_displayMode); - return (HL_DisplayMode*)_displayMode.Value (); + DisplayMode displayMode; + targetWindow->GetDisplayMode (&displayMode); + result->CopyFrom(&displayMode); } @@ -3531,13 +3530,12 @@ namespace lime { } - HL_PRIM HL_DisplayMode* hl_lime_window_set_display_mode (HL_CFFIPointer* window, HL_DisplayMode* displayMode) { + HL_PRIM void hl_lime_window_set_display_mode (HL_CFFIPointer* window, DisplayMode* displayMode, DisplayMode* result) { Window* targetWindow = (Window*)window->ptr; - DisplayMode _displayMode (displayMode); - targetWindow->SetDisplayMode (&_displayMode); - targetWindow->GetDisplayMode (&_displayMode); - return (HL_DisplayMode*)_displayMode.Value (); + targetWindow->SetDisplayMode (displayMode); + targetWindow->GetDisplayMode (displayMode); + result->CopyFrom(displayMode); } @@ -4079,7 +4077,7 @@ namespace lime { DEFINE_HL_PRIM (_F64, lime_window_get_context, _TCFFIPOINTER); DEFINE_HL_PRIM (_BYTES, lime_window_get_context_type, _TCFFIPOINTER); DEFINE_HL_PRIM (_I32, lime_window_get_display, _TCFFIPOINTER); - DEFINE_HL_PRIM (_DYN, lime_window_get_display_mode, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_window_get_display_mode, _TCFFIPOINTER _TDISPLAYMODE); DEFINE_HL_PRIM (_I32, lime_window_get_height, _TCFFIPOINTER); DEFINE_HL_PRIM (_I32, lime_window_get_id, _TCFFIPOINTER); DEFINE_HL_PRIM (_BOOL, lime_window_get_mouse_lock, _TCFFIPOINTER); @@ -4093,7 +4091,7 @@ namespace lime { DEFINE_HL_PRIM (_VOID, lime_window_resize, _TCFFIPOINTER _I32 _I32); DEFINE_HL_PRIM (_BOOL, lime_window_set_borderless, _TCFFIPOINTER _BOOL); DEFINE_HL_PRIM (_VOID, lime_window_set_cursor, _TCFFIPOINTER _I32); - DEFINE_HL_PRIM (_TDISPLAYMODE, lime_window_set_display_mode, _TCFFIPOINTER _TDISPLAYMODE); + DEFINE_HL_PRIM (_VOID, lime_window_set_display_mode, _TCFFIPOINTER _TDISPLAYMODE _TDISPLAYMODE); DEFINE_HL_PRIM (_BOOL, lime_window_set_fullscreen, _TCFFIPOINTER _BOOL); DEFINE_HL_PRIM (_VOID, lime_window_set_icon, _TCFFIPOINTER _TIMAGEBUFFER); DEFINE_HL_PRIM (_BOOL, lime_window_set_maximized, _TCFFIPOINTER _BOOL); diff --git a/project/src/backend/sdl/SDLSystem.cpp b/project/src/backend/sdl/SDLSystem.cpp index bed050e85..9bcef4e36 100644 --- a/project/src/backend/sdl/SDLSystem.cpp +++ b/project/src/backend/sdl/SDLSystem.cpp @@ -291,81 +291,50 @@ namespace lime { } - value System::GetDisplay (int id) { + void* System::GetDisplay (bool useCFFIValue, int id) { - if (!init) { + if (useCFFIValue) { - id_bounds = val_id ("bounds"); - id_currentMode = val_id ("currentMode"); - id_dpi = val_id ("dpi"); - id_height = val_id ("height"); - id_name = val_id ("name"); - id_pixelFormat = val_id ("pixelFormat"); - id_refreshRate = val_id ("refreshRate"); - id_supportedModes = val_id ("supportedModes"); - id_width = val_id ("width"); - init = true; + if (!init) { - } + id_bounds = val_id ("bounds"); + id_currentMode = val_id ("currentMode"); + id_dpi = val_id ("dpi"); + id_height = val_id ("height"); + id_name = val_id ("name"); + id_pixelFormat = val_id ("pixelFormat"); + id_refreshRate = val_id ("refreshRate"); + id_supportedModes = val_id ("supportedModes"); + id_width = val_id ("width"); + init = true; - int numDisplays = GetNumDisplays (); + } - if (id < 0 || id >= numDisplays) { + int numDisplays = GetNumDisplays (); - return alloc_null (); + if (id < 0 || id >= numDisplays) { - } + return alloc_null (); - value display = alloc_empty_object (); - alloc_field (display, id_name, alloc_string (SDL_GetDisplayName (id))); + } - SDL_Rect bounds = { 0, 0, 0, 0 }; - SDL_GetDisplayBounds (id, &bounds); - alloc_field (display, id_bounds, Rectangle (bounds.x, bounds.y, bounds.w, bounds.h).Value ()); + value display = alloc_empty_object (); + alloc_field (display, id_name, alloc_string (SDL_GetDisplayName (id))); - float dpi = 72.0; - #ifndef EMSCRIPTEN - SDL_GetDisplayDPI (id, &dpi, NULL, NULL); - #endif - alloc_field (display, id_dpi, alloc_float (dpi)); + SDL_Rect bounds = { 0, 0, 0, 0 }; + SDL_GetDisplayBounds (id, &bounds); + alloc_field (display, id_bounds, Rectangle (bounds.x, bounds.y, bounds.w, bounds.h).Value ()); - SDL_DisplayMode displayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; - DisplayMode mode; + float dpi = 72.0; + #ifndef EMSCRIPTEN + SDL_GetDisplayDPI (id, &dpi, NULL, NULL); + #endif + alloc_field (display, id_dpi, alloc_float (dpi)); - SDL_GetDesktopDisplayMode (id, &displayMode); + SDL_DisplayMode displayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; + DisplayMode mode; - mode.height = displayMode.h; - - switch (displayMode.format) { - - case SDL_PIXELFORMAT_ARGB8888: - - mode.pixelFormat = ARGB32; - break; - - case SDL_PIXELFORMAT_BGRA8888: - case SDL_PIXELFORMAT_BGRX8888: - - mode.pixelFormat = BGRA32; - break; - - default: - - mode.pixelFormat = RGBA32; - - } - - mode.refreshRate = displayMode.refresh_rate; - mode.width = displayMode.w; - - alloc_field (display, id_currentMode, (value)mode.Value ()); - - int numDisplayModes = SDL_GetNumDisplayModes (id); - value supportedModes = alloc_array (numDisplayModes); - - for (int i = 0; i < numDisplayModes; i++) { - - SDL_GetDisplayMode (id, i, &displayMode); + SDL_GetDesktopDisplayMode (id, &displayMode); mode.height = displayMode.h; @@ -391,13 +360,176 @@ namespace lime { mode.refreshRate = displayMode.refresh_rate; mode.width = displayMode.w; - val_array_set_i (supportedModes, i, (value)mode.Value ()); + alloc_field (display, id_currentMode, (value)mode.Value ()); + + int numDisplayModes = SDL_GetNumDisplayModes (id); + value supportedModes = alloc_array (numDisplayModes); + + for (int i = 0; i < numDisplayModes; i++) { + + SDL_GetDisplayMode (id, i, &displayMode); + + mode.height = displayMode.h; + + switch (displayMode.format) { + + case SDL_PIXELFORMAT_ARGB8888: + + mode.pixelFormat = ARGB32; + break; + + case SDL_PIXELFORMAT_BGRA8888: + case SDL_PIXELFORMAT_BGRX8888: + + mode.pixelFormat = BGRA32; + break; + + default: + + mode.pixelFormat = RGBA32; + + } + + mode.refreshRate = displayMode.refresh_rate; + mode.width = displayMode.w; + + val_array_set_i (supportedModes, i, (value)mode.Value ()); + + } + + alloc_field (display, id_supportedModes, supportedModes); + return display; + + } else { + + const int id_bounds = hl_hash_utf8 ("bounds"); + const int id_currentMode = hl_hash_utf8 ("currentMode"); + const int id_dpi = hl_hash_utf8 ("dpi"); + const int id_height = hl_hash_utf8 ("height"); + const int id_name = hl_hash_utf8 ("name"); + const int id_pixelFormat = hl_hash_utf8 ("pixelFormat"); + const int id_refreshRate = hl_hash_utf8 ("refreshRate"); + const int id_supportedModes = hl_hash_utf8 ("supportedModes"); + const int id_width = hl_hash_utf8 ("width"); + const int id_x = hl_hash_utf8 ("x"); + const int id_y = hl_hash_utf8 ("y"); + + int numDisplays = GetNumDisplays (); + + if (id < 0 || id >= numDisplays) { + + return 0; + + } + + vdynamic* display = (vdynamic*)hl_alloc_dynobj (); + + const char* displayName = SDL_GetDisplayName (id); + char* _displayName = (char*)malloc(strlen(displayName) + 1); + strcpy (_displayName, displayName); + hl_dyn_setp (display, id_name, &hlt_bytes, _displayName); + + SDL_Rect bounds = { 0, 0, 0, 0 }; + SDL_GetDisplayBounds (id, &bounds); + + vdynamic* _bounds = (vdynamic*)hl_alloc_dynobj (); + hl_dyn_seti (_bounds, id_x, &hlt_i32, bounds.x); + hl_dyn_seti (_bounds, id_y, &hlt_i32, bounds.y); + hl_dyn_seti (_bounds, id_width, &hlt_i32, bounds.w); + hl_dyn_seti (_bounds, id_height, &hlt_i32, bounds.h); + + hl_dyn_setp (display, id_bounds, &hlt_dynobj, _bounds); + + float dpi = 72.0; + #ifndef EMSCRIPTEN + SDL_GetDisplayDPI (id, &dpi, NULL, NULL); + #endif + hl_dyn_setf (display, id_dpi, dpi); + + SDL_DisplayMode displayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; + DisplayMode mode; + + SDL_GetDesktopDisplayMode (id, &displayMode); + + mode.height = displayMode.h; + + switch (displayMode.format) { + + case SDL_PIXELFORMAT_ARGB8888: + + mode.pixelFormat = ARGB32; + break; + + case SDL_PIXELFORMAT_BGRA8888: + case SDL_PIXELFORMAT_BGRX8888: + + mode.pixelFormat = BGRA32; + break; + + default: + + mode.pixelFormat = RGBA32; + + } + + mode.refreshRate = displayMode.refresh_rate; + mode.width = displayMode.w; + + vdynamic* _displayMode = (vdynamic*)hl_alloc_dynobj (); + hl_dyn_seti (_displayMode, id_height, &hlt_i32, mode.height); + hl_dyn_seti (_displayMode, id_pixelFormat, &hlt_i32, mode.pixelFormat); + hl_dyn_seti (_displayMode, id_refreshRate, &hlt_i32, mode.refreshRate); + hl_dyn_seti (_displayMode, id_width, &hlt_i32, mode.width); + hl_dyn_setp (display, id_currentMode, &hlt_dynobj, _displayMode); + + int numDisplayModes = SDL_GetNumDisplayModes (id); + + hl_varray* supportedModes = (hl_varray*)hl_alloc_array (&hlt_dynobj, numDisplayModes); + vdynamic** supportedModesData = hl_aptr (supportedModes, vdynamic*); + + for (int i = 0; i < numDisplayModes; i++) { + + SDL_GetDisplayMode (id, i, &displayMode); + + mode.height = displayMode.h; + + switch (displayMode.format) { + + case SDL_PIXELFORMAT_ARGB8888: + + mode.pixelFormat = ARGB32; + break; + + case SDL_PIXELFORMAT_BGRA8888: + case SDL_PIXELFORMAT_BGRX8888: + + mode.pixelFormat = BGRA32; + break; + + default: + + mode.pixelFormat = RGBA32; + + } + + mode.refreshRate = displayMode.refresh_rate; + mode.width = displayMode.w; + + vdynamic* _displayMode = (vdynamic*)hl_alloc_dynobj (); + hl_dyn_seti (_displayMode, id_height, &hlt_i32, mode.height); + hl_dyn_seti (_displayMode, id_pixelFormat, &hlt_i32, mode.pixelFormat); + hl_dyn_seti (_displayMode, id_refreshRate, &hlt_i32, mode.refreshRate); + hl_dyn_seti (_displayMode, id_width, &hlt_i32, mode.width); + + *supportedModesData++ = _displayMode; + + } + + hl_dyn_setp (display, id_supportedModes, &hlt_array, supportedModes); + return display; } - alloc_field (display, id_supportedModes, supportedModes); - return display; - } diff --git a/project/src/system/DisplayMode.cpp b/project/src/system/DisplayMode.cpp index a18cc69a6..d7c84d6c4 100644 --- a/project/src/system/DisplayMode.cpp +++ b/project/src/system/DisplayMode.cpp @@ -31,16 +31,6 @@ namespace lime { } - DisplayMode::DisplayMode (HL_DisplayMode* displayMode) { - - width = displayMode->width; - height = displayMode->height; - pixelFormat = displayMode->pixelFormat; - refreshRate = displayMode->refreshRate; - - } - - DisplayMode::DisplayMode (int _width, int _height, PixelFormat _pixelFormat, int _refreshRate) { width = _width; @@ -51,6 +41,16 @@ namespace lime { } + void DisplayMode::CopyFrom (DisplayMode* other) { + + height = other->height; + pixelFormat = other->pixelFormat; + refreshRate = other->refreshRate; + width = other->width; + + } + + void* DisplayMode::Value () { // if (_mode) { diff --git a/project/src/text/Font.cpp b/project/src/text/Font.cpp index ed6e95592..5ba96e72f 100644 --- a/project/src/text/Font.cpp +++ b/project/src/text/Font.cpp @@ -449,7 +449,7 @@ namespace lime { } - value Font::Decompose (int em) { + void* Font::Decompose (bool useCFFIValue, int em) { int result, i, j; @@ -535,81 +535,169 @@ namespace lime { wchar_t* family_name = GetFamilyName (); - value ret = alloc_empty_object (); - alloc_field (ret, val_id ("has_kerning"), alloc_bool (FT_HAS_KERNING (((FT_Face)face)))); - alloc_field (ret, val_id ("is_fixed_width"), alloc_bool (FT_IS_FIXED_WIDTH (((FT_Face)face)))); - alloc_field (ret, val_id ("has_glyph_names"), alloc_bool (FT_HAS_GLYPH_NAMES (((FT_Face)face)))); - alloc_field (ret, val_id ("is_italic"), alloc_bool (((FT_Face)face)->style_flags & FT_STYLE_FLAG_ITALIC)); - alloc_field (ret, val_id ("is_bold"), alloc_bool (((FT_Face)face)->style_flags & FT_STYLE_FLAG_BOLD)); - alloc_field (ret, val_id ("num_glyphs"), alloc_int (num_glyphs)); - alloc_field (ret, val_id ("family_name"), family_name == NULL ? alloc_string (((FT_Face)face)->family_name) : alloc_wstring (family_name)); - alloc_field (ret, val_id ("style_name"), alloc_string (((FT_Face)face)->style_name)); - alloc_field (ret, val_id ("em_size"), alloc_int (((FT_Face)face)->units_per_EM)); - alloc_field (ret, val_id ("ascend"), alloc_int (((FT_Face)face)->ascender)); - alloc_field (ret, val_id ("descend"), alloc_int (((FT_Face)face)->descender)); - alloc_field (ret, val_id ("height"), alloc_int (((FT_Face)face)->height)); + if (useCFFIValue) { - delete family_name; + value ret = alloc_empty_object (); + alloc_field (ret, val_id ("has_kerning"), alloc_bool (FT_HAS_KERNING (((FT_Face)face)))); + alloc_field (ret, val_id ("is_fixed_width"), alloc_bool (FT_IS_FIXED_WIDTH (((FT_Face)face)))); + alloc_field (ret, val_id ("has_glyph_names"), alloc_bool (FT_HAS_GLYPH_NAMES (((FT_Face)face)))); + alloc_field (ret, val_id ("is_italic"), alloc_bool (((FT_Face)face)->style_flags & FT_STYLE_FLAG_ITALIC)); + alloc_field (ret, val_id ("is_bold"), alloc_bool (((FT_Face)face)->style_flags & FT_STYLE_FLAG_BOLD)); + alloc_field (ret, val_id ("num_glyphs"), alloc_int (num_glyphs)); + alloc_field (ret, val_id ("family_name"), family_name == NULL ? alloc_string (((FT_Face)face)->family_name) : alloc_wstring (family_name)); + alloc_field (ret, val_id ("style_name"), alloc_string (((FT_Face)face)->style_name)); + alloc_field (ret, val_id ("em_size"), alloc_int (((FT_Face)face)->units_per_EM)); + alloc_field (ret, val_id ("ascend"), alloc_int (((FT_Face)face)->ascender)); + alloc_field (ret, val_id ("descend"), alloc_int (((FT_Face)face)->descender)); + alloc_field (ret, val_id ("height"), alloc_int (((FT_Face)face)->height)); - // 'glyphs' field - value neko_glyphs = alloc_array (num_glyphs); - for (i = 0; i < glyphs.size (); i++) { + delete family_name; - glyph *g = glyphs[i]; - int num_points = g->pts.size (); + // 'glyphs' field + value neko_glyphs = alloc_array (num_glyphs); + for (i = 0; i < glyphs.size (); i++) { - value points = alloc_array (num_points); + glyph *g = glyphs[i]; + int num_points = g->pts.size (); - for (j = 0; j < num_points; j++) { + value points = alloc_array (num_points); - val_array_set_i (points, j, alloc_int (g->pts[j])); + for (j = 0; j < num_points; j++) { + + val_array_set_i (points, j, alloc_int (g->pts[j])); + + } + + value item = alloc_empty_object (); + val_array_set_i (neko_glyphs, i, item); + alloc_field (item, val_id ("char_code"), alloc_int (g->char_code)); + alloc_field (item, val_id ("advance"), alloc_int (g->metrics.horiAdvance)); + alloc_field (item, val_id ("min_x"), alloc_int (g->metrics.horiBearingX)); + alloc_field (item, val_id ("max_x"), alloc_int (g->metrics.horiBearingX + g->metrics.width)); + alloc_field (item, val_id ("min_y"), alloc_int (g->metrics.horiBearingY - g->metrics.height)); + alloc_field (item, val_id ("max_y"), alloc_int (g->metrics.horiBearingY)); + alloc_field (item, val_id ("points"), points); + + delete g; } - value item = alloc_empty_object (); - val_array_set_i (neko_glyphs, i, item); - alloc_field (item, val_id ("char_code"), alloc_int (g->char_code)); - alloc_field (item, val_id ("advance"), alloc_int (g->metrics.horiAdvance)); - alloc_field (item, val_id ("min_x"), alloc_int (g->metrics.horiBearingX)); - alloc_field (item, val_id ("max_x"), alloc_int (g->metrics.horiBearingX + g->metrics.width)); - alloc_field (item, val_id ("min_y"), alloc_int (g->metrics.horiBearingY - g->metrics.height)); - alloc_field (item, val_id ("max_y"), alloc_int (g->metrics.horiBearingY)); - alloc_field (item, val_id ("points"), points); + alloc_field (ret, val_id ("glyphs"), neko_glyphs); - delete g; + // 'kerning' field + if (FT_HAS_KERNING (((FT_Face)face))) { - } + value neko_kerning = alloc_array (kern.size ()); - alloc_field (ret, val_id ("glyphs"), neko_glyphs); + for (i = 0; i < kern.size(); i++) { - // 'kerning' field - if (FT_HAS_KERNING (((FT_Face)face))) { + kerning *k = &kern[i]; - value neko_kerning = alloc_array (kern.size ()); + value item = alloc_empty_object(); + val_array_set_i (neko_kerning,i,item); + alloc_field (item, val_id ("left_glyph"), alloc_int (k->l_glyph)); + alloc_field (item, val_id ("right_glyph"), alloc_int (k->r_glyph)); + alloc_field (item, val_id ("x"), alloc_int (k->x)); + alloc_field (item, val_id ("y"), alloc_int (k->y)); - for (i = 0; i < kern.size(); i++) { + } - kerning *k = &kern[i]; + alloc_field (ret, val_id ("kerning"), neko_kerning); - value item = alloc_empty_object(); - val_array_set_i (neko_kerning,i,item); - alloc_field (item, val_id ("left_glyph"), alloc_int (k->l_glyph)); - alloc_field (item, val_id ("right_glyph"), alloc_int (k->r_glyph)); - alloc_field (item, val_id ("x"), alloc_int (k->x)); - alloc_field (item, val_id ("y"), alloc_int (k->y)); + } else { + + alloc_field (ret, val_id ("kerning"), alloc_null ()); } - alloc_field (ret, val_id ("kerning"), neko_kerning); + return ret; } else { - alloc_field (ret, val_id ("kerning"), alloc_null ()); + vdynamic* ret = (vdynamic*)hl_alloc_dynobj (); + hl_dyn_seti (ret, hl_hash_utf8 ("has_kerning"), &hlt_bool, FT_HAS_KERNING (((FT_Face)face))); + hl_dyn_seti (ret, hl_hash_utf8 ("is_fixed_width"), &hlt_bool, FT_IS_FIXED_WIDTH (((FT_Face)face))); + hl_dyn_seti (ret, hl_hash_utf8 ("has_glyph_names"), &hlt_bool, FT_HAS_GLYPH_NAMES (((FT_Face)face))); + hl_dyn_seti (ret, hl_hash_utf8 ("is_italic"), &hlt_bool, ((FT_Face)face)->style_flags & FT_STYLE_FLAG_ITALIC); + hl_dyn_seti (ret, hl_hash_utf8 ("is_bold"), &hlt_bool, ((FT_Face)face)->style_flags & FT_STYLE_FLAG_BOLD); + hl_dyn_seti (ret, hl_hash_utf8 ("num_glyphs"), &hlt_i32, num_glyphs); + + // TODO: if family_name is null, convert to wide string + char* style_name = (char*)malloc(strlen(((FT_Face)face)->style_name) + 1); + strcpy(style_name, ((FT_Face)face)->style_name); + + hl_dyn_setp (ret, hl_hash_utf8 ("family_name"), &hlt_bytes, family_name); + hl_dyn_setp (ret, hl_hash_utf8 ("style_name"), &hlt_bytes, style_name); + hl_dyn_seti (ret, hl_hash_utf8 ("em_size"), &hlt_i32, ((FT_Face)face)->units_per_EM); + hl_dyn_seti (ret, hl_hash_utf8 ("ascend"), &hlt_i32, ((FT_Face)face)->ascender); + hl_dyn_seti (ret, hl_hash_utf8 ("descend"), &hlt_i32, ((FT_Face)face)->descender); + hl_dyn_seti (ret, hl_hash_utf8 ("height"), &hlt_i32, ((FT_Face)face)->height); + + // 'glyphs' field + hl_varray* _glyphs = (hl_varray*)hl_alloc_array (&hlt_dynobj, num_glyphs); + vdynamic** _glyphsData = hl_aptr (_glyphs, vdynamic*); + + for (i = 0; i < glyphs.size (); i++) { + + glyph *g = glyphs[i]; + int num_points = g->pts.size (); + + hl_varray* points = (hl_varray*)hl_alloc_array (&hlt_i32, num_points); + int* pointsData = hl_aptr (points, int); + + for (j = 0; j < num_points; j++) { + + *pointsData++ = g->pts[j]; + + } + + vdynamic* item = (vdynamic*)hl_alloc_dynobj (); + *_glyphsData++ = item; + hl_dyn_seti (item, hl_hash_utf8 ("char_code"), &hlt_i32, g->char_code); + hl_dyn_seti (item, hl_hash_utf8 ("advance"), &hlt_i32, g->metrics.horiAdvance); + hl_dyn_seti (item, hl_hash_utf8 ("min_x"), &hlt_i32, g->metrics.horiBearingX); + hl_dyn_seti (item, hl_hash_utf8 ("max_x"), &hlt_i32, g->metrics.horiBearingX + g->metrics.width); + hl_dyn_seti (item, hl_hash_utf8 ("min_y"), &hlt_i32, g->metrics.horiBearingY - g->metrics.height); + hl_dyn_seti (item, hl_hash_utf8 ("max_y"), &hlt_i32, g->metrics.horiBearingY); + hl_dyn_setp (item, hl_hash_utf8 ("points"), &hlt_array, points); + + delete g; + + } + + hl_dyn_setp (ret, hl_hash_utf8 ("glyphs"), &hlt_array, _glyphs); + + // 'kerning' field + if (FT_HAS_KERNING (((FT_Face)face))) { + + hl_varray* _kerning = (hl_varray*)hl_alloc_array (&hlt_i32, kern.size ()); + vdynamic** _kerningData = hl_aptr (_kerning, vdynamic*); + + for (i = 0; i < kern.size(); i++) { + + kerning *k = &kern[i]; + + vdynamic* item = (vdynamic*)hl_alloc_dynobj (); + *_kerningData++ = item; + hl_dyn_seti (item, hl_hash_utf8 ("left_glyph"), &hlt_i32, k->l_glyph); + hl_dyn_seti (item, hl_hash_utf8 ("right_glyph"), &hlt_i32, k->r_glyph); + hl_dyn_seti (item, hl_hash_utf8 ("x"), &hlt_i32, k->x); + hl_dyn_seti (item, hl_hash_utf8 ("y"), &hlt_i32, k->y); + + } + + hl_dyn_setp (ret, hl_hash_utf8 ("kerning"), &hlt_array, _kerning); + + } else { + + hl_dyn_setp (ret, hl_hash_utf8 ("kerning"), &hlt_array, 0); + + } + + return ret; } - return ret; - } @@ -696,47 +784,110 @@ namespace lime { } - value Font::GetGlyphIndices (char* characters) { + void* Font::GetGlyphIndices (bool useCFFIValue, char* characters) { - value indices = alloc_array (0); - unsigned long character; - int index; + if (useCFFIValue) { - while (*characters != 0) { + value indices = alloc_array (0); + unsigned long character; + int index; - character = readNextChar (characters); - index = FT_Get_Char_Index ((FT_Face)face, character); - val_array_push (indices, alloc_int (index)); + while (*characters != 0) { + + character = readNextChar (characters); + index = FT_Get_Char_Index ((FT_Face)face, character); + val_array_push (indices, alloc_int (index)); + + } + + return indices; + + } else { + + unsigned long character; + int index; + int count = 0; + + // TODO: Determine array size first + + while (*characters != 0) { + + character = readNextChar (characters); + count++; + + } + + hl_varray* indices = (hl_varray*)hl_alloc_array (&hlt_i32, count); + int* indicesData = hl_aptr (indices, int); + + while (*characters != 0) { + + character = readNextChar (characters); + *indicesData++ = FT_Get_Char_Index ((FT_Face)face, character); + + } + + return indices; } - return indices; - } - value Font::GetGlyphMetrics (int index) { + void* Font::GetGlyphMetrics (bool useCFFIValue, int index) { - initialize (); + if (useCFFIValue) { - if (FT_Load_Glyph ((FT_Face)face, index, FT_LOAD_NO_BITMAP | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_DEFAULT) == 0) { + initialize (); - value metrics = alloc_empty_object (); + if (FT_Load_Glyph ((FT_Face)face, index, FT_LOAD_NO_BITMAP | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_DEFAULT) == 0) { - alloc_field (metrics, id_height, alloc_int (((FT_Face)face)->glyph->metrics.height)); - alloc_field (metrics, id_horizontalBearingX, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingX)); - alloc_field (metrics, id_horizontalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingY)); - alloc_field (metrics, id_horizontalAdvance, alloc_int (((FT_Face)face)->glyph->metrics.horiAdvance)); - alloc_field (metrics, id_verticalBearingX, alloc_int (((FT_Face)face)->glyph->metrics.vertBearingX)); - alloc_field (metrics, id_verticalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.vertBearingY)); - alloc_field (metrics, id_verticalAdvance, alloc_int (((FT_Face)face)->glyph->metrics.vertAdvance)); + value metrics = alloc_empty_object (); - return metrics; + alloc_field (metrics, id_height, alloc_int (((FT_Face)face)->glyph->metrics.height)); + alloc_field (metrics, id_horizontalBearingX, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingX)); + alloc_field (metrics, id_horizontalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.horiBearingY)); + alloc_field (metrics, id_horizontalAdvance, alloc_int (((FT_Face)face)->glyph->metrics.horiAdvance)); + alloc_field (metrics, id_verticalBearingX, alloc_int (((FT_Face)face)->glyph->metrics.vertBearingX)); + alloc_field (metrics, id_verticalBearingY, alloc_int (((FT_Face)face)->glyph->metrics.vertBearingY)); + alloc_field (metrics, id_verticalAdvance, alloc_int (((FT_Face)face)->glyph->metrics.vertAdvance)); + + return metrics; + + } + + return alloc_null (); + + } else { + + if (FT_Load_Glyph ((FT_Face)face, index, FT_LOAD_NO_BITMAP | FT_LOAD_FORCE_AUTOHINT | FT_LOAD_DEFAULT) == 0) { + + const int id_height = hl_hash_utf8 ("height"); + const int id_horizontalBearingX = hl_hash_utf8 ("horizontalBearingX"); + const int id_horizontalBearingY = hl_hash_utf8 ("horizontalBearingY"); + const int id_horizontalAdvance = hl_hash_utf8 ("horizontalAdvance"); + const int id_verticalBearingX = hl_hash_utf8 ("verticalBearingX"); + const int id_verticalBearingY = hl_hash_utf8 ("verticalBearingY"); + const int id_verticalAdvance = hl_hash_utf8 ("verticalAdvance"); + + vdynamic* metrics = (vdynamic*)hl_alloc_dynobj (); + + hl_dyn_seti (metrics, id_height, &hlt_i32, ((FT_Face)face)->glyph->metrics.height); + hl_dyn_seti (metrics, id_horizontalBearingX, &hlt_i32, ((FT_Face)face)->glyph->metrics.horiBearingX); + hl_dyn_seti (metrics, id_horizontalBearingY, &hlt_i32, ((FT_Face)face)->glyph->metrics.horiBearingY); + hl_dyn_seti (metrics, id_horizontalAdvance, &hlt_i32, ((FT_Face)face)->glyph->metrics.horiAdvance); + hl_dyn_seti (metrics, id_verticalBearingX, &hlt_i32, ((FT_Face)face)->glyph->metrics.vertBearingX); + hl_dyn_seti (metrics, id_verticalBearingY, &hlt_i32, ((FT_Face)face)->glyph->metrics.vertBearingY); + hl_dyn_seti (metrics, id_verticalAdvance, &hlt_i32, ((FT_Face)face)->glyph->metrics.vertAdvance); + + return metrics; + + } + + return 0; } - return alloc_null (); - } diff --git a/src/lime/_internal/backend/native/NativeCFFI.hx b/src/lime/_internal/backend/native/NativeCFFI.hx index 62c220332..4f5a25de5 100644 --- a/src/lime/_internal/backend/native/NativeCFFI.hx +++ b/src/lime/_internal/backend/native/NativeCFFI.hx @@ -1249,10 +1249,7 @@ class NativeCFFI return 0; } - @:hlNative("lime", "lime_window_get_display_mode") private static function lime_window_get_display_mode(handle:CFFIPointer):Dynamic - { - return null; - } + @:hlNative("lime", "lime_window_get_display_mode") private static function lime_window_get_display_mode(handle:CFFIPointer, result:DisplayMode):Void {} @:hlNative("lime", "lime_window_get_height") private static function lime_window_get_height(handle:CFFIPointer):Int { @@ -1312,10 +1309,7 @@ class NativeCFFI @:hlNative("lime", "lime_window_set_cursor") private static function lime_window_set_cursor(handle:CFFIPointer, cursor:Int):Void {} @:hlNative("lime", "lime_window_set_display_mode") private static function lime_window_set_display_mode(handle:CFFIPointer, - displayMode:DisplayMode):DisplayMode - { - return null; - } + displayMode:DisplayMode, result:DisplayMode):Void {} @:hlNative("lime", "lime_window_set_fullscreen") private static function lime_window_set_fullscreen(handle:CFFIPointer, fullscreen:Bool):Bool { diff --git a/src/lime/_internal/backend/native/NativeWindow.hx b/src/lime/_internal/backend/native/NativeWindow.hx index b646619a7..732d51232 100644 --- a/src/lime/_internal/backend/native/NativeWindow.hx +++ b/src/lime/_internal/backend/native/NativeWindow.hx @@ -267,12 +267,16 @@ class NativeWindow if (handle != null) { #if (!macro && lime_cffi) + #if hl + NativeCFFI.lime_window_get_display_mode(handle, displayMode); + #else var data:Dynamic = NativeCFFI.lime_window_get_display_mode(handle); displayMode.width = data.width; displayMode.height = data.height; displayMode.pixelFormat = data.pixelFormat; displayMode.refreshRate = data.refreshRate; #end + #end } return displayMode; @@ -501,12 +505,16 @@ class NativeWindow if (handle != null) { #if (!macro && lime_cffi) + #if hl + NativeCFFI.lime_window_set_display_mode(handle, value, displayMode); + #else var data:Dynamic = NativeCFFI.lime_window_set_display_mode(handle, value); displayMode.width = data.width; displayMode.height = data.height; displayMode.pixelFormat = data.pixelFormat; displayMode.refreshRate = data.refreshRate; #end + #end } return displayMode; diff --git a/src/lime/system/System.hx b/src/lime/system/System.hx index 0f581f355..600ec3e02 100644 --- a/src/lime/system/System.hx +++ b/src/lime/system/System.hx @@ -170,7 +170,11 @@ class System { var display = new Display(); display.id = id; + #if hl + display.name = @:privateAccess String.fromUTF8(displayInfo.name); + #else display.name = displayInfo.name; + #end display.bounds = new Rectangle(displayInfo.bounds.x, displayInfo.bounds.y, displayInfo.bounds.width, displayInfo.bounds.height); #if ios @@ -195,7 +199,12 @@ class System var displayMode; - for (mode in cast(displayInfo.supportedModes, Array)) + #if hl + var supportedModes:hl.NativeArray = displayInfo.supportedModes; + #else + var supportedModes:Array = displayInfo.supportedModes; + #end + for (mode in supportedModes) { displayMode = new DisplayMode(mode.width, mode.height, mode.refreshRate, mode.pixelFormat); display.supportedModes.push(displayMode); diff --git a/src/lime/text/Font.hx b/src/lime/text/Font.hx index eb760a203..1729e1453 100644 --- a/src/lime/text/Font.hx +++ b/src/lime/text/Font.hx @@ -104,6 +104,12 @@ class Font #if (lime_cffi && !macro) if (src == null) throw "Uninitialized font handle."; var data:Dynamic = NativeCFFI.lime_font_outline_decompose(src, 1024 * 20); + #if hl + if (data != null) { + data.family_name = @:privateAccess String.fromUCS2(data.family_name); + data.style_name = @:privateAccess String.fromUTF8(data.style_name); + } + #end return data; #else return null;