Text codepoints management functions.
This commit is contained in:
64
API.md
64
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
|
||||
|
||||
---
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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. */
|
||||
|
||||
136
src/text.c
136
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user