summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2024-01-28 13:10:18 +0200
committerjussi2024-01-28 13:10:18 +0200
commit71cc89c3033365746e5dcdb933c460c8e0da7fb0 (patch)
tree4b08b5c379991894bb4aae974f22150841aa5204
parent3b3d0ad32e24c2ff0a13daf3e865054f63afaf86 (diff)
downloadreilua-enhanced-71cc89c3033365746e5dcdb933c460c8e0da7fb0.tar.gz
reilua-enhanced-71cc89c3033365746e5dcdb933c460c8e0da7fb0.tar.bz2
reilua-enhanced-71cc89c3033365746e5dcdb933c460c8e0da7fb0.zip
Text codepoints management functions.
-rw-r--r--API.md64
-rw-r--r--ReiLua_API.lua52
-rw-r--r--changelog2
-rw-r--r--include/text.h8
-rw-r--r--src/lua_core.c8
-rw-r--r--src/text.c136
6 files changed, 262 insertions, 8 deletions
diff --git a/API.md b/API.md
index a05e0ae..d003c37 100644
--- a/API.md
+++ b/API.md
@@ -6470,7 +6470,7 @@ Get glyph index position in font for a codepoint (unicode character), fallback t
> glyphInfo = RL.GetGlyphInfo( Font font, int codepoint )
-Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
+Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found. Return as lightuserdata
- Success return GlyphInfo
@@ -6478,7 +6478,7 @@ Get glyph font info data for a codepoint (unicode character), fallback to '?' if
> glyphInfo = RL.GetGlyphInfoByIndex( Font font, int index )
-Get glyph font info data by index
+Get glyph font info data by index. Return as lightuserdata
- Failure return nil
- Success return GlyphInfo
@@ -6608,6 +6608,66 @@ Get glyphInfo character image data. Return as lightuserdata
---
+## Text - Text codepoints management functions (unicode characters)
+
+---
+
+> string = RL.LoadUTF8( int{} codepoints )
+
+Load UTF-8 text encoded from codepoints array
+
+- Success return string
+
+---
+
+> codepoints = RL.LoadCodepoints( string text )
+
+Load all codepoints from a UTF-8 text string
+
+- Success return int{}
+
+---
+
+> count = RL.GetCodepointCount( string text )
+
+Get total number of codepoints in a UTF-8 encoded string
+
+- Success return int
+
+---
+
+> codepoint, codepointSize = RL.GetCodepoint( string text )
+
+Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+
+- Success return int, int
+
+---
+
+> codepoint, codepointSize = RL.GetCodepointNext( string text )
+
+Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+
+- Success return int, int
+
+---
+
+> codepoint, codepointSize = RL.GetCodepointPrevious( string text )
+
+Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+
+- Success return int, int
+
+---
+
+> string, utf8Size = RL.CodepointToUTF8( int codepoint )
+
+Encode one codepoint into UTF-8 byte array
+
+- Success return string, int
+
+---
+
## Models - Basic geometric 3D shapes drawing functions
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 09f0bb3..fb11af6 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -3836,14 +3836,14 @@ function RL.MeasureText( font, text, fontSize, spacing ) end
---@return any index
function RL.GetGlyphIndex( font, codepoint ) end
----Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
+---Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found. Return as lightuserdata
---- Success return GlyphInfo
---@param font any
---@param codepoint integer
---@return any glyphInfo
function RL.GetGlyphInfo( font, codepoint ) end
----Get glyph font info data by index
+---Get glyph font info data by index. Return as lightuserdata
---- Failure return nil
---- Success return GlyphInfo
---@param font any
@@ -3951,6 +3951,54 @@ function RL.GetGlyphInfoAdvanceX( glyphInfo ) end
---@return any image
function RL.GetGlyphInfoImage( glyphInfo ) end
+-- Text - Text codepoints management functions (unicode characters)
+
+---Load UTF-8 text encoded from codepoints array
+---- Success return string
+---@param codepoints table
+---@return any string
+function RL.LoadUTF8( codepoints ) end
+
+---Load all codepoints from a UTF-8 text string
+---- Success return int{}
+---@param text string
+---@return any codepoints
+function RL.LoadCodepoints( text ) end
+
+---Get total number of codepoints in a UTF-8 encoded string
+---- Success return int
+---@param text string
+---@return any count
+function RL.GetCodepointCount( text ) end
+
+---Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+---- Success return int, int
+---@param text string
+---@return any codepoint
+---@return any codepointSize
+function RL.GetCodepoint( text ) end
+
+---Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+---- Success return int, int
+---@param text string
+---@return any codepoint
+---@return any codepointSize
+function RL.GetCodepointNext( text ) end
+
+---Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+---- Success return int, int
+---@param text string
+---@return any codepoint
+---@return any codepointSize
+function RL.GetCodepointPrevious( text ) end
+
+---Encode one codepoint into UTF-8 byte array
+---- Success return string, int
+---@param codepoint integer
+---@return any string
+---@return any utf8Size
+function RL.CodepointToUTF8( codepoint ) end
+
-- Models - Basic geometric 3D shapes drawing functions
---Draw a line in 3D world space
diff --git a/changelog b/changelog
index cfe7dfd..f94e786 100644
--- a/changelog
+++ b/changelog
@@ -33,6 +33,7 @@ KEY CHANGES:
- CHANGE: GuiTabBar works differently to raygui implementation.
- CHANGE: Raygui lib refactoring.
- ADDED: Raygui lib extensions property list.
+ - ADDED: Text codepoints management functions.
DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
@@ -63,6 +64,7 @@ DETAILED CHANGES:
- CHANGE: Raygui.h returns textBounds for some controls.
- CHANGE: Raygui lib changed term element to control to correspond raylib naming.
- ADDED: LoadBufferFromString, LoadWaveFromMemory and LoadMusicStreamFromMemory.
+ - CHANGE: GetGlyphInfo and GetGlyphInfoByIndex return glyphInfo as lightuserdata.
------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5
diff --git a/include/text.h b/include/text.h
index 96c9b82..bbfe1ba 100644
--- a/include/text.h
+++ b/include/text.h
@@ -45,3 +45,11 @@ int ltextGetGlyphInfoValue( lua_State *L );
int ltextGetGlyphInfoOffset( lua_State *L );
int ltextGetGlyphInfoAdvanceX( lua_State *L );
int ltextGetGlyphInfoImage( lua_State *L );
+/* Text codepoints management functions (unicode characters). */
+int ltextLoadUTF8( lua_State *L );
+int ltextLoadCodepoints( lua_State *L );
+int ltextGetCodepointCount( lua_State *L );
+int ltextGetCodepoint( lua_State *L );
+int ltextGetCodepointNext( lua_State *L );
+int ltextGetCodepointPrevious( lua_State *L );
+int ltextCodepointToUTF8( lua_State *L );
diff --git a/src/lua_core.c b/src/lua_core.c
index 3465fce..a7c9f57 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -1757,6 +1757,14 @@ void luaRegister() {
assingGlobalFunction( "GetGlyphInfoOffset", ltextGetGlyphInfoOffset );
assingGlobalFunction( "GetGlyphInfoAdvanceX", ltextGetGlyphInfoAdvanceX );
assingGlobalFunction( "GetGlyphInfoImage", ltextGetGlyphInfoImage );
+ /* Text codepoints management functions (unicode characters). */
+ assingGlobalFunction( "LoadUTF8", ltextLoadUTF8 );
+ assingGlobalFunction( "LoadCodepoints", ltextLoadCodepoints );
+ assingGlobalFunction( "GetCodepointCount", ltextGetCodepointCount );
+ assingGlobalFunction( "GetCodepoint", ltextGetCodepoint );
+ assingGlobalFunction( "GetCodepointNext", ltextGetCodepointNext );
+ assingGlobalFunction( "GetCodepointPrevious", ltextGetCodepointPrevious );
+ assingGlobalFunction( "CodepointToUTF8", ltextCodepointToUTF8 );
/* Audio. */
/* Audio device management functions. */
diff --git a/src/text.c b/src/text.c
index d93f240..b09eb96 100644
--- a/src/text.c
+++ b/src/text.c
@@ -698,7 +698,7 @@ int ltextGetGlyphIndex( lua_State *L ) {
/*
> glyphInfo = RL.GetGlyphInfo( Font font, int codepoint )
-Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
+Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found. Return as lightuserdata
- Success return GlyphInfo
*/
@@ -707,7 +707,7 @@ int ltextGetGlyphInfo( lua_State *L ) {
int codepoint = luaL_checkinteger( L, 2 );
int id = GetGlyphIndex( *font, codepoint );
- uluaPushGlyphInfo( L, font->glyphs[id] );
+ lua_pushlightuserdata( L, &font->glyphs[id] );
return 1;
}
@@ -715,7 +715,7 @@ int ltextGetGlyphInfo( lua_State *L ) {
/*
> glyphInfo = RL.GetGlyphInfoByIndex( Font font, int index )
-Get glyph font info data by index
+Get glyph font info data by index. Return as lightuserdata
- Failure return nil
- Success return GlyphInfo
@@ -725,7 +725,7 @@ int ltextGetGlyphInfoByIndex( lua_State *L ) {
int index = luaL_checkinteger( L, 2 );
if ( 0 <= index && index < font->glyphCount ) {
- uluaPushGlyphInfo( L, font->glyphs[ index ] );
+ lua_pushlightuserdata( L, &font->glyphs[ index ] );
}
else {
TraceLog( state->logLevelInvalid, "Glyph index %d out of bounds", index );
@@ -1005,3 +1005,131 @@ int ltextGetGlyphInfoImage( lua_State *L ) {
return 1;
}
+
+/*
+## Text - Text codepoints management functions (unicode characters)
+*/
+
+/*
+> string = RL.LoadUTF8( int{} codepoints )
+
+Load UTF-8 text encoded from codepoints array
+
+- Success return string
+*/
+int ltextLoadUTF8( lua_State *L ) {
+ int codepointCount = uluaGetTableLen( L, 1 );
+ int codepoints[ codepointCount ];
+ getCodepoints( L, codepoints, 1 );
+
+ char* string = LoadUTF8( codepoints, codepointCount );
+ lua_pushstring( L, string );
+ UnloadUTF8( string );
+
+ return 1;
+}
+
+/*
+> codepoints = RL.LoadCodepoints( string text )
+
+Load all codepoints from a UTF-8 text string
+
+- Success return int{}
+*/
+int ltextLoadCodepoints( lua_State *L ) {
+ const char* text = luaL_checkstring( L, 1 );
+
+ int count = 0;
+ int* codepoints = LoadCodepoints( text, &count );
+
+ for ( int i = 0; i < count; i++ ) {
+ lua_pushinteger( L, codepoints[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+ UnloadCodepoints( codepoints );
+
+ return 1;
+}
+
+/*
+> count = RL.GetCodepointCount( string text )
+
+Get total number of codepoints in a UTF-8 encoded string
+
+- Success return int
+*/
+int ltextGetCodepointCount( lua_State *L ) {
+ const char* text = luaL_checkstring( L, 1 );
+
+ lua_pushinteger( L, GetCodepointCount( text ) );
+
+ return 1;
+}
+
+/*
+> codepoint, codepointSize = RL.GetCodepoint( string text )
+
+Get codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+
+- Success return int, int
+*/
+int ltextGetCodepoint( lua_State *L ) {
+ const char* text = luaL_checkstring( L, 1 );
+
+ int codepointSize = 0;
+ lua_pushinteger( L, GetCodepoint( text, &codepointSize ) );
+ lua_pushinteger( L, codepointSize );
+
+ return 2;
+}
+
+/*
+> codepoint, codepointSize = RL.GetCodepointNext( string text )
+
+Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+
+- Success return int, int
+*/
+int ltextGetCodepointNext( lua_State *L ) {
+ const char* text = luaL_checkstring( L, 1 );
+
+ int codepointSize = 0;
+ lua_pushinteger( L, GetCodepointNext( text, &codepointSize ) );
+ lua_pushinteger( L, codepointSize );
+
+ return 2;
+}
+
+/*
+> codepoint, codepointSize = RL.GetCodepointPrevious( string text )
+
+Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure
+
+- Success return int, int
+*/
+int ltextGetCodepointPrevious( lua_State *L ) {
+ const char* text = luaL_checkstring( L, 1 );
+
+ int codepointSize = 0;
+ lua_pushinteger( L, GetCodepointPrevious( text, &codepointSize ) );
+ lua_pushinteger( L, codepointSize );
+
+ return 2;
+}
+
+/*
+> string, utf8Size = RL.CodepointToUTF8( int codepoint )
+
+Encode one codepoint into UTF-8 byte array
+
+- Success return string, int
+*/
+int ltextCodepointToUTF8( lua_State *L ) {
+ int codepoint = luaL_checkinteger( L, 1 );
+
+ int utf8Size = 0;
+ lua_pushstring( L, CodepointToUTF8( codepoint, &utf8Size ) );
+ lua_pushinteger( L, utf8Size );
+
+ return 2;
+}