2013-11-25 12:49:55 +01:00
# include "stdafx.h"
2014-06-02 19:27:24 +02:00
# include "Emu/Memory/Memory.h"
# include "Emu/SysCalls/Modules.h"
2014-08-23 22:40:04 +02:00
# include "stblib/stb_truetype.h"
2014-06-02 19:27:24 +02:00
# include "Emu/FS/vfsFile.h"
2013-12-09 17:56:04 +01:00
# include "cellFont.h"
2014-01-02 02:13:08 +01:00
2014-05-02 08:30:32 +02:00
//void cellFont_init();
//void cellFont_load();
//void cellFont_unload();
//Module cellFont(0x0019, cellFont_init, cellFont_load, cellFont_unload);
Module * cellFont = nullptr ;
2013-11-25 12:49:55 +01:00
2014-04-15 16:12:15 +02:00
CCellFontInternal * s_fontInternalInstance = nullptr ;
2013-12-09 17:56:04 +01:00
// Functions
int cellFontInitializeWithRevision ( u64 revisionFlags , mem_ptr_t < CellFontConfig > config )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontInitializeWithRevision(revisionFlags=0x%llx, config=0x%x) " , revisionFlags , config . GetAddr ( ) ) ;
2013-12-09 17:56:04 +01:00
if ( s_fontInternalInstance - > m_bInitialized )
return CELL_FONT_ERROR_ALREADY_INITIALIZED ;
if ( config - > FileCache . size < 24 )
return CELL_FONT_ERROR_INVALID_PARAMETER ;
if ( config - > flags ! = 0 )
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontInitializeWithRevision: Unknown flags (0x%x) " , config - > flags ) ;
2013-12-09 17:56:04 +01:00
s_fontInternalInstance - > m_buffer_addr = config - > FileCache . buffer_addr ;
s_fontInternalInstance - > m_buffer_size = config - > FileCache . size ;
s_fontInternalInstance - > m_userFontEntrys_addr = config - > userFontEntrys_addr ;
s_fontInternalInstance - > m_userFontEntryMax = config - > userFontEntryMax ;
s_fontInternalInstance - > m_bInitialized = true ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontGetRevisionFlags ( mem64_t revisionFlags )
2013-11-25 12:49:55 +01:00
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontInit ( mem_ptr_t < CellFontConfig > config )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontInit(config=0x%x) " , config . GetAddr ( ) ) ;
2013-12-09 17:56:04 +01:00
2014-07-31 18:08:02 +02:00
vm : : var < u64 > revisionFlags ;
revisionFlags . value ( ) = 0 ;
cellFontGetRevisionFlags ( revisionFlags . addr ( ) ) ;
2013-12-09 17:56:04 +01:00
return cellFontInitializeWithRevision ( revisionFlags , config . GetAddr ( ) ) ;
2013-11-25 12:49:55 +01:00
}
2013-12-09 17:56:04 +01:00
int cellFontEnd ( )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontEnd() " ) ;
2013-12-09 17:56:04 +01:00
if ( ! s_fontInternalInstance - > m_bInitialized )
return CELL_FONT_ERROR_UNINITIALIZED ;
s_fontInternalInstance - > m_bInitialized = false ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
s32 cellFontSetFontsetOpenMode ( u32 openMode )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontSetFontsetOpenMode(openMode=0x%x) " , openMode ) ;
2013-11-25 12:49:55 +01:00
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2014-01-02 02:13:08 +01:00
int cellFontOpenFontMemory ( mem_ptr_t < CellFontLibrary > library , u32 fontAddr , u32 fontSize , u32 subNum , u32 uniqueId , mem_ptr_t < CellFont > font )
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontOpenFontMemory(library_addr=0x%x, fontAddr=0x%x, fontSize=%d, subNum=%d, uniqueId=%d, font_addr=0x%x) " ,
2014-01-02 02:13:08 +01:00
library . GetAddr ( ) , fontAddr , fontSize , subNum , uniqueId , font . GetAddr ( ) ) ;
if ( ! s_fontInternalInstance - > m_bInitialized )
return CELL_FONT_ERROR_UNINITIALIZED ;
2014-08-23 22:40:04 +02:00
font - > stbfont = ( stbtt_fontinfo * ) ( ( u8 * ) & ( font - > stbfont ) + sizeof ( void * ) ) ; // hack: use next bytes of the struct
if ( ! stbtt_InitFont ( font - > stbfont , ( unsigned char * ) Memory . VirtualToRealAddr ( fontAddr ) , 0 ) )
2014-02-09 12:07:50 +01:00
return CELL_FONT_ERROR_FONT_OPEN_FAILED ;
2014-01-02 02:13:08 +01:00
2014-04-28 05:34:33 +02:00
font - > renderer_addr = 0 ;
2014-02-09 12:07:50 +01:00
font - > fontdata_addr = fontAddr ;
font - > origin = CELL_FONT_OPEN_MEMORY ;
2014-01-02 02:13:08 +01:00
return CELL_FONT_OK ;
}
2014-08-31 17:01:48 +02:00
int cellFontOpenFontFile ( mem_ptr_t < CellFontLibrary > library , vm : : ptr < const char > fontPath , u32 subNum , s32 uniqueId , mem_ptr_t < CellFont > font )
2014-01-02 02:13:08 +01:00
{
2014-08-31 17:01:48 +02:00
std : : string fp ( fontPath . get_ptr ( ) ) ;
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontOpenFontFile(library_addr=0x%x, fontPath= \" %s \" , subNum=%d, uniqueId=%d, font_addr=0x%x) " ,
2014-04-01 02:33:55 +02:00
library . GetAddr ( ) , fp . c_str ( ) , subNum , uniqueId , font . GetAddr ( ) ) ;
2014-01-02 02:13:08 +01:00
2014-02-13 17:59:13 +01:00
vfsFile f ( fp ) ;
2014-01-02 02:13:08 +01:00
if ( ! f . IsOpened ( ) )
return CELL_FONT_ERROR_FONT_OPEN_FAILED ;
2014-08-30 22:41:01 +02:00
u32 fileSize = ( u32 ) f . GetSize ( ) ;
u32 bufferAddr = ( u32 ) Memory . Alloc ( fileSize , 1 ) ; // Freed in cellFontCloseFont
2014-02-09 12:07:50 +01:00
f . Read ( Memory . VirtualToRealAddr ( bufferAddr ) , fileSize ) ;
int ret = cellFontOpenFontMemory ( library . GetAddr ( ) , bufferAddr , fileSize , subNum , uniqueId , font . GetAddr ( ) ) ;
font - > origin = CELL_FONT_OPEN_FONT_FILE ;
return ret ;
2014-01-02 02:13:08 +01:00
}
2013-12-09 17:56:04 +01:00
int cellFontOpenFontset ( mem_ptr_t < CellFontLibrary > library , mem_ptr_t < CellFontType > fontType , mem_ptr_t < CellFont > font )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontOpenFontset(library_addr=0x%x, fontType_addr=0x%x, font_addr=0x%x) " ,
2013-12-09 17:56:04 +01:00
library . GetAddr ( ) , fontType . GetAddr ( ) , font . GetAddr ( ) ) ;
if ( ! s_fontInternalInstance - > m_bInitialized )
return CELL_FONT_ERROR_UNINITIALIZED ;
if ( fontType - > map ! = CELL_FONT_MAP_UNICODE )
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontOpenFontset: Only Unicode is supported " ) ;
2013-12-09 17:56:04 +01:00
2014-01-02 02:13:08 +01:00
std : : string file ;
2014-04-25 18:57:00 +02:00
switch ( ( u32 ) fontType - > type )
2014-01-02 02:13:08 +01:00
{
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN : file = " /dev_flash/data/font/SCE-PS3-RD-R-LATIN.TTF " ; break ;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN : file = " /dev_flash/data/font/SCE-PS3-RD-L-LATIN.TTF " ; break ;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN : file = " /dev_flash/data/font/SCE-PS3-RD-B-LATIN.TTF " ; break ;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN2 : file = " /dev_flash/data/font/SCE-PS3-RD-R-LATIN2.TTF " ; break ;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN2 : file = " /dev_flash/data/font/SCE-PS3-RD-L-LATIN2.TTF " ; break ;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN2 : file = " /dev_flash/data/font/SCE-PS3-RD-B-LATIN2.TTF " ; break ;
case CELL_FONT_TYPE_MATISSE_SERIF_LATIN : file = " /dev_flash/data/font/SCE-PS3-MT-R-LATIN.TTF " ; break ;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_JAPANESE : file = " /dev_flash/data/font/SCE-PS3-NR-R-JPN.TTF " ; break ;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_LIGHT_JAPANESE : file = " /dev_flash/data/font/SCE-PS3-NR-L-JPN.TTF " ; break ;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_BOLD_JAPANESE : file = " /dev_flash/data/font/SCE-PS3-NR-B-JPN.TTF " ; break ;
case CELL_FONT_TYPE_YD_GOTHIC_KOREAN : file = " /dev_flash/data/font/SCE-PS3-YG-R-KOR.TTF " ; break ;
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN : file = " /dev_flash/data/font/SCE-PS3-SR-R-LATIN.TTF " ; break ;
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN2 : file = " /dev_flash/data/font/SCE-PS3-SR-R-LATIN2.TTF " ; break ;
case CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND : file = " /dev_flash/data/font/SCE-PS3-VR-R-LATIN.TTF " ; break ;
case CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND_LATIN2 : file = " /dev_flash/data/font/SCE-PS3-VR-R-LATIN2.TTF " ; break ;
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_JAPANESE : file = " /dev_flash/data/font/SCE-PS3-SR-R-JPN.TTF " ; break ;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_JP_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_LATIN_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN2_SET :
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_TCH_SET :
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_TCH_SET :
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_TCH_SET :
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_SCH_SET :
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_SCH_SET :
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_SCH_SET :
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS_SET :
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET :
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_JP_SET :
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS_SET :
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET :
case CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET :
case CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_LIGHT_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_LIGHT_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_LIGHT_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_LIGHT_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_LIGHT_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_BOLD_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_BOLD_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_BOLD_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_BOLD_SET :
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_BOLD_SET :
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS2_SET :
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS2_SET :
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET :
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET :
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_VAGR2_SET :
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_VAGR2_SET :
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontOpenFontset: fontType->type = %d not supported yet. RD-R-LATIN.TTF will be used instead. " , fontType - > type ) ;
2014-01-02 02:13:08 +01:00
file = " /dev_flash/data/font/SCE-PS3-RD-R-LATIN.TTF " ;
break ;
default :
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontOpenFontset: fontType->type = %d not supported. " , fontType - > type ) ;
2014-01-02 02:13:08 +01:00
return CELL_FONT_ERROR_NO_SUPPORT_FONTSET ;
}
2013-12-09 17:56:04 +01:00
2014-08-31 17:01:48 +02:00
vm : : var < const char > f ( ( u32 ) file . length ( ) + 1 , 1 ) ;
Memory . WriteString ( f . addr ( ) , file ) ;
int ret = cellFontOpenFontFile ( library . GetAddr ( ) , vm : : ptr < const char > : : make ( f . addr ( ) ) , 0 , 0 , font . GetAddr ( ) ) ; //TODO: Find the correct values of subNum, uniqueId
2014-02-09 12:07:50 +01:00
font - > origin = CELL_FONT_OPEN_FONTSET ;
2014-01-02 02:13:08 +01:00
return ret ;
2013-11-25 12:49:55 +01:00
}
2013-12-09 17:56:04 +01:00
int cellFontOpenFontInstance ( mem_ptr_t < CellFont > openedFont , mem_ptr_t < CellFont > font )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontOpenFontInstance(openedFont=0x%x, font=0x%x) " , openedFont . GetAddr ( ) , font . GetAddr ( ) ) ;
2014-02-09 12:07:50 +01:00
font - > renderer_addr = openedFont - > renderer_addr ;
font - > scale_x = openedFont - > scale_x ;
font - > scale_y = openedFont - > scale_y ;
font - > slant = openedFont - > slant ;
font - > stbfont = openedFont - > stbfont ;
font - > origin = CELL_FONT_OPEN_FONT_INSTANCE ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
s32 cellFontSetFontOpenMode ( u32 openMode )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontSetFontOpenMode(openMode=0x%x) " , openMode ) ;
2013-11-25 12:49:55 +01:00
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontCreateRenderer ( mem_ptr_t < CellFontLibrary > library , mem_ptr_t < CellFontRendererConfig > config , mem_ptr_t < CellFontRenderer > Renderer )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontCreateRenderer(library_addr=0x%x, config_addr=0x%x, Renderer_addr=0x%x) " ,
2013-12-09 17:56:04 +01:00
library . GetAddr ( ) , config . GetAddr ( ) , Renderer . GetAddr ( ) ) ;
if ( ! s_fontInternalInstance - > m_bInitialized )
return CELL_FONT_ERROR_UNINITIALIZED ;
//Write data in Renderer
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
void cellFontRenderSurfaceInit ( mem_ptr_t < CellFontRenderSurface > surface , u32 buffer_addr , s32 bufferWidthByte , s32 pixelSizeByte , s32 w , s32 h )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontRenderSurfaceInit(surface_addr=0x%x, buffer_addr=0x%x, bufferWidthByte=%d, pixelSizeByte=%d, w=%d, h=%d) " ,
2013-12-09 17:56:04 +01:00
surface . GetAddr ( ) , buffer_addr , bufferWidthByte , pixelSizeByte , w , h ) ;
surface - > buffer_addr = buffer_addr ;
surface - > widthByte = bufferWidthByte ;
surface - > pixelSizeByte = pixelSizeByte ;
surface - > width = w ;
surface - > height = h ;
2014-03-18 17:45:26 +01:00
if ( ! buffer_addr )
2014-08-30 22:41:01 +02:00
surface - > buffer_addr = ( u32 ) Memory . Alloc ( bufferWidthByte * h , 1 ) ; // TODO: Huge memory leak
2013-12-09 17:56:04 +01:00
}
void cellFontRenderSurfaceSetScissor ( mem_ptr_t < CellFontRenderSurface > surface , s32 x0 , s32 y0 , s32 w , s32 h )
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontRenderSurfaceSetScissor(surface_addr=0x%x, x0=%d, y0=%d, w=%d, h=%d) " ,
2013-12-09 17:56:04 +01:00
surface . GetAddr ( ) , x0 , y0 , w , h ) ;
surface - > Scissor . x0 = x0 ;
surface - > Scissor . y0 = y0 ;
surface - > Scissor . x1 = w ;
surface - > Scissor . y1 = h ;
}
int cellFontSetScalePixel ( mem_ptr_t < CellFont > font , float w , float h )
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontSetScalePixel(font_addr=0x%x, w=%f, h=%f) " , font . GetAddr ( ) , w , h ) ;
2013-12-09 17:56:04 +01:00
font - > scale_x = w ;
font - > scale_y = h ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontGetHorizontalLayout ( mem_ptr_t < CellFont > font , mem_ptr_t < CellFontHorizontalLayout > layout )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontGetHorizontalLayout(font_addr=0x%x, layout_addr=0x%x) " ,
2013-12-09 17:56:04 +01:00
font . GetAddr ( ) , layout . GetAddr ( ) ) ;
2014-02-09 12:07:50 +01:00
int ascent , descent , lineGap ;
2014-08-23 22:40:04 +02:00
float scale = stbtt_ScaleForPixelHeight ( font - > stbfont , font - > scale_y ) ;
stbtt_GetFontVMetrics ( font - > stbfont , & ascent , & descent , & lineGap ) ;
2014-02-09 12:07:50 +01:00
layout - > baseLineY = ascent * scale ;
layout - > lineHeight = ( ascent - descent + lineGap ) * scale ;
layout - > effectHeight = lineGap * scale ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontBindRenderer ( mem_ptr_t < CellFont > font , mem_ptr_t < CellFontRenderer > renderer )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontBindRenderer(font_addr=0x%x, renderer_addr=0x%x) " ,
2013-12-09 17:56:04 +01:00
font . GetAddr ( ) , renderer . GetAddr ( ) ) ;
2014-08-05 12:18:22 +02:00
2013-12-09 17:56:04 +01:00
if ( font - > renderer_addr )
return CELL_FONT_ERROR_RENDERER_ALREADY_BIND ;
font - > renderer_addr = renderer . GetAddr ( ) ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontUnbindRenderer ( mem_ptr_t < CellFont > font )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontBindRenderer(font_addr=0x%x) " , font . GetAddr ( ) ) ;
2013-12-09 17:56:04 +01:00
if ( ! font - > renderer_addr )
return CELL_FONT_ERROR_RENDERER_UNBIND ;
2014-04-28 05:34:33 +02:00
font - > renderer_addr = 0 ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontDestroyRenderer ( )
2013-11-25 12:49:55 +01:00
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2014-02-09 12:07:50 +01:00
int cellFontSetupRenderScalePixel ( mem_ptr_t < CellFont > font , float w , float h )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontSetupRenderScalePixel(font_addr=0x%x, w=%f, h=%f) " , font . GetAddr ( ) , w , h ) ;
2014-02-09 12:07:50 +01:00
if ( ! font - > renderer_addr )
return CELL_FONT_ERROR_RENDERER_UNBIND ;
// TODO: ?
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2014-02-09 12:07:50 +01:00
int cellFontGetRenderCharGlyphMetrics ( mem_ptr_t < CellFont > font , u32 code , mem_ptr_t < CellFontGlyphMetrics > metrics )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontGetRenderCharGlyphMetrics(font_addr=0x%x, code=0x%x, metrics_addr=0x%x) " ,
2014-02-09 12:07:50 +01:00
font . GetAddr ( ) , code , metrics . GetAddr ( ) ) ;
if ( ! font - > renderer_addr )
return CELL_FONT_ERROR_RENDERER_UNBIND ;
// TODO: ?
return CELL_FONT_OK ;
}
int cellFontRenderCharGlyphImage ( mem_ptr_t < CellFont > font , u32 code , mem_ptr_t < CellFontRenderSurface > surface , float x , float y , mem_ptr_t < CellFontGlyphMetrics > metrics , mem_ptr_t < CellFontImageTransInfo > transInfo )
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontRenderCharGlyphImage(font_addr=0x%x, code=0x%x, surface_addr=0x%x, x=%f, y=%f, metrics_addr=0x%x, trans_addr=0x%x) " ,
2014-02-09 12:07:50 +01:00
font . GetAddr ( ) , code , surface . GetAddr ( ) , x , y , metrics . GetAddr ( ) , transInfo . GetAddr ( ) ) ;
if ( ! font - > renderer_addr )
return CELL_FONT_ERROR_RENDERER_UNBIND ;
// Render the character
int width , height , xoff , yoff ;
2014-08-23 22:40:04 +02:00
float scale = stbtt_ScaleForPixelHeight ( font - > stbfont , font - > scale_y ) ;
unsigned char * box = stbtt_GetCodepointBitmap ( font - > stbfont , scale , scale , code , & width , & height , & xoff , & yoff ) ;
2014-02-09 12:07:50 +01:00
if ( ! box ) return CELL_OK ;
// Get the baseLineY value
int baseLineY ;
int ascent , descent , lineGap ;
2014-08-23 22:40:04 +02:00
stbtt_GetFontVMetrics ( font - > stbfont , & ascent , & descent , & lineGap ) ;
2014-08-30 22:41:01 +02:00
baseLineY = ( int ) ( ( float ) ascent * scale ) ; // ???
2014-02-09 12:07:50 +01:00
// Move the rendered character to the surface
unsigned char * buffer = ( unsigned char * ) Memory . VirtualToRealAddr ( surface - > buffer_addr ) ;
2014-02-14 01:30:15 +01:00
for ( u32 ypos = 0 ; ypos < ( u32 ) height ; ypos + + ) {
2014-02-09 12:07:50 +01:00
if ( ( u32 ) y + ypos + yoff + baseLineY > = surface - > height )
break ;
2014-02-14 01:30:15 +01:00
for ( u32 xpos = 0 ; xpos < ( u32 ) width ; xpos + + ) {
2014-02-09 12:07:50 +01:00
if ( ( u32 ) x + xpos > = surface - > width )
break ;
// TODO: There are some oddities in the position of the character in the final buffer
buffer [ ( ( int ) y + ypos + yoff + baseLineY ) * surface - > width + ( int ) x + xpos ] = box [ ypos * width + xpos ] ;
}
}
stbtt_FreeBitmap ( box , 0 ) ;
2013-12-09 17:56:04 +01:00
return CELL_FONT_OK ;
2013-11-25 12:49:55 +01:00
}
2013-12-09 17:56:04 +01:00
int cellFontEndLibrary ( )
2013-11-25 12:49:55 +01:00
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontSetEffectSlant ( mem_ptr_t < CellFont > font , float slantParam )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontSetEffectSlant(font_addr=0x%x, slantParam=%f) " , font . GetAddr ( ) , slantParam ) ;
2013-12-09 17:56:04 +01:00
2014-08-05 12:18:22 +02:00
if ( slantParam < - 1.0 | | slantParam > 1.0 )
2013-12-09 17:56:04 +01:00
return CELL_FONT_ERROR_INVALID_PARAMETER ;
font - > slant = slantParam ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2014-08-30 22:41:01 +02:00
int cellFontGetEffectSlant ( mem_ptr_t < CellFont > font , mem_ptr_t < be_t < float > > slantParam )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontSetEffectSlant(font_addr=0x%x, slantParam_addr=0x%x) " , font . GetAddr ( ) , slantParam . GetAddr ( ) ) ;
2013-12-09 17:56:04 +01:00
2014-08-30 22:41:01 +02:00
* slantParam = font - > slant ;
2013-12-09 17:56:04 +01:00
return CELL_FONT_OK ;
2013-11-25 12:49:55 +01:00
}
2013-12-09 17:56:04 +01:00
int cellFontGetFontIdCode ( mem_ptr_t < CellFont > font , u32 code , mem32_t fontId , mem32_t fontCode )
2013-11-25 12:49:55 +01:00
{
2014-08-05 12:18:22 +02:00
cellFont - > Todo ( " cellFontGetFontIdCode(font_addr=0x%x, code=0x%x, fontId_addr=0x%x, fontCode_addr=0x%x " ,
2013-12-09 17:56:04 +01:00
font . GetAddr ( ) , code , fontId . GetAddr ( ) , fontCode . GetAddr ( ) ) ;
2014-02-09 12:07:50 +01:00
// TODO: ?
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2014-02-09 12:07:50 +01:00
int cellFontCloseFont ( mem_ptr_t < CellFont > font )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontCloseFont(font_addr=0x%x) " , font . GetAddr ( ) ) ;
2014-02-09 12:07:50 +01:00
if ( font - > origin = = CELL_FONT_OPEN_FONTSET | |
font - > origin = = CELL_FONT_OPEN_FONT_FILE | |
font - > origin = = CELL_FONT_OPEN_MEMORY )
Memory . Free ( font - > fontdata_addr ) ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontGetCharGlyphMetrics ( mem_ptr_t < CellFont > font , u32 code , mem_ptr_t < CellFontGlyphMetrics > metrics )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Log ( " cellFontGetCharGlyphMetrics(font_addr=0x%x, code=0x%x, metrics_addr=0x%x " ,
2013-12-09 17:56:04 +01:00
font . GetAddr ( ) , code , metrics . GetAddr ( ) ) ;
2014-02-09 12:07:50 +01:00
int x0 , y0 , x1 , y1 ;
int advanceWidth , leftSideBearing ;
2014-08-23 22:40:04 +02:00
float scale = stbtt_ScaleForPixelHeight ( font - > stbfont , font - > scale_y ) ;
stbtt_GetCodepointBox ( font - > stbfont , code , & x0 , & y0 , & x1 , & y1 ) ;
stbtt_GetCodepointHMetrics ( font - > stbfont , code , & advanceWidth , & leftSideBearing ) ;
2014-02-09 12:07:50 +01:00
// TODO: Add the rest of the information
metrics - > width = ( x1 - x0 ) * scale ;
metrics - > height = ( y1 - y0 ) * scale ;
metrics - > Horizontal . bearingX = ( float ) leftSideBearing * scale ;
2013-12-09 17:56:04 +01:00
metrics - > Horizontal . bearingY = 0 ;
2014-02-09 12:07:50 +01:00
metrics - > Horizontal . advance = ( float ) advanceWidth * scale ;
2013-12-09 17:56:04 +01:00
metrics - > Vertical . bearingX = 0 ;
metrics - > Vertical . bearingY = 0 ;
metrics - > Vertical . advance = 0 ;
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
int cellFontGraphicsSetFontRGBA ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
int cellFontOpenFontsetOnMemory ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
int cellFontGraphicsSetScalePixel ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
int cellFontGraphicsGetScalePixel ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
int cellFontSetEffectWeight ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
int cellFontGlyphSetupVertexesGlyph ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
int cellFontGetVerticalLayout ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
int cellFontGetRenderCharGlyphMetricsVertical ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontSetScalePoint ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontSetupRenderEffectSlant ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontGraphicsSetLineRGBA ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontGraphicsSetDrawType ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontEndGraphics ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontGraphicsSetupDrawContext ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontSetupRenderEffectWeight ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontGlyphGetOutlineControlDistance ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontGlyphGetVertexesGlyphSize ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontGenerateCharGlyph ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontDeleteGlyph ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
int cellFontExtend ( u32 a1 , u32 a2 , u32 a3 )
2013-11-25 12:49:55 +01:00
{
2014-05-02 08:30:32 +02:00
cellFont - > Warning ( " cellFontExtend(a1=0x%x, a2=0x%x, a3=0x%x) " , a1 , a2 , a3 ) ;
2013-12-09 17:56:04 +01:00
//In a test I did: a1=0xcfe00000, a2=0x0, a3=(pointer to something)
if ( a1 = = 0xcfe00000 )
{
if ( a2 ! = 0 | | a3 = = 0 )
{
//Something happens
}
if ( Memory . Read32 ( a3 ) = = 0 )
{
//Something happens
}
//Something happens
}
//Something happens?
2013-11-25 12:49:55 +01:00
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontRenderCharGlyphImageVertical ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontSetResolutionDpi ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
2013-12-09 17:56:04 +01:00
2013-11-25 12:49:55 +01:00
int cellFontGetCharGlyphMetricsVertical ( )
{
UNIMPLEMENTED_FUNC ( cellFont ) ;
return CELL_FONT_OK ;
}
void cellFont_init ( )
{
2014-05-02 08:30:32 +02:00
cellFont - > AddFunc ( 0x25c107e6 , cellFontInit ) ;
cellFont - > AddFunc ( 0x6bf6f832 , cellFontSetFontsetOpenMode ) ;
cellFont - > AddFunc ( 0x6cfada83 , cellFontSetFontOpenMode ) ;
cellFont - > AddFunc ( 0x042e74e3 , cellFontCreateRenderer ) ;
cellFont - > AddFunc ( 0x1387c45c , cellFontGetHorizontalLayout ) ;
cellFont - > AddFunc ( 0x21ebb248 , cellFontDestroyRenderer ) ;
cellFont - > AddFunc ( 0x227e1e3c , cellFontSetupRenderScalePixel ) ;
cellFont - > AddFunc ( 0x29329541 , cellFontOpenFontInstance ) ;
cellFont - > AddFunc ( 0x297f0e93 , cellFontSetScalePixel ) ;
cellFont - > AddFunc ( 0x2da9fd9d , cellFontGetRenderCharGlyphMetrics ) ;
cellFont - > AddFunc ( 0x40d40544 , cellFontEndLibrary ) ;
cellFont - > AddFunc ( 0x66a23100 , cellFontBindRenderer ) ;
cellFont - > AddFunc ( 0x7ab47f7e , cellFontEnd ) ;
cellFont - > AddFunc ( 0x8657c8f5 , cellFontSetEffectSlant ) ;
cellFont - > AddFunc ( 0xe16e679a , cellFontGetEffectSlant ) ;
cellFont - > AddFunc ( 0x88be4799 , cellFontRenderCharGlyphImage ) ;
cellFont - > AddFunc ( 0x90b9465e , cellFontRenderSurfaceInit ) ;
cellFont - > AddFunc ( 0x98ac5524 , cellFontGetFontIdCode ) ;
cellFont - > AddFunc ( 0xa885cc9b , cellFontOpenFontset ) ;
cellFont - > AddFunc ( 0xb276f1f6 , cellFontCloseFont ) ;
cellFont - > AddFunc ( 0xb422b005 , cellFontRenderSurfaceSetScissor ) ;
cellFont - > AddFunc ( 0xd8eaee9f , cellFontGetCharGlyphMetrics ) ;
cellFont - > AddFunc ( 0xf03dcc29 , cellFontInitializeWithRevision ) ;
cellFont - > AddFunc ( 0x061049ad , cellFontGraphicsSetFontRGBA ) ;
cellFont - > AddFunc ( 0x073fa321 , cellFontOpenFontsetOnMemory ) ;
cellFont - > AddFunc ( 0x0a7306a4 , cellFontOpenFontFile ) ;
cellFont - > AddFunc ( 0x16322df1 , cellFontGraphicsSetScalePixel ) ;
cellFont - > AddFunc ( 0x2388186c , cellFontGraphicsGetScalePixel ) ;
cellFont - > AddFunc ( 0x25253fe4 , cellFontSetEffectWeight ) ;
cellFont - > AddFunc ( 0x53f529fe , cellFontGlyphSetupVertexesGlyph ) ;
cellFont - > AddFunc ( 0x698897f8 , cellFontGetVerticalLayout ) ;
cellFont - > AddFunc ( 0x700e6223 , cellFontGetRenderCharGlyphMetricsVertical ) ;
cellFont - > AddFunc ( 0x70f3e728 , cellFontSetScalePoint ) ;
cellFont - > AddFunc ( 0x78d05e08 , cellFontSetupRenderEffectSlant ) ;
cellFont - > AddFunc ( 0x7c83bc15 , cellFontGraphicsSetLineRGBA ) ;
cellFont - > AddFunc ( 0x87bd650f , cellFontGraphicsSetDrawType ) ;
cellFont - > AddFunc ( 0x8a35c887 , cellFontEndGraphics ) ;
cellFont - > AddFunc ( 0x970d4c22 , cellFontGraphicsSetupDrawContext ) ;
cellFont - > AddFunc ( 0x9e19072b , cellFontOpenFontMemory ) ;
cellFont - > AddFunc ( 0xa6dc25d1 , cellFontSetupRenderEffectWeight ) ;
cellFont - > AddFunc ( 0xa8fae920 , cellFontGlyphGetOutlineControlDistance ) ;
cellFont - > AddFunc ( 0xb4d112af , cellFontGlyphGetVertexesGlyphSize ) ;
cellFont - > AddFunc ( 0xc17259de , cellFontGenerateCharGlyph ) ;
cellFont - > AddFunc ( 0xd62f5d76 , cellFontDeleteGlyph ) ;
cellFont - > AddFunc ( 0xdee0836c , cellFontExtend ) ;
cellFont - > AddFunc ( 0xe857a0ca , cellFontRenderCharGlyphImageVertical ) ;
cellFont - > AddFunc ( 0xfb3341ba , cellFontSetResolutionDpi ) ;
cellFont - > AddFunc ( 0xfe9a6dd7 , cellFontGetCharGlyphMetricsVertical ) ;
cellFont - > AddFunc ( 0xf16379fa , cellFontUnbindRenderer ) ;
cellFont - > AddFunc ( 0xb015a84e , cellFontGetRevisionFlags ) ;
2013-12-09 17:56:04 +01:00
}
2014-04-15 16:12:15 +02:00
void cellFont_load ( )
{
s_fontInternalInstance = new CCellFontInternal ( ) ;
}
2013-12-09 17:56:04 +01:00
void cellFont_unload ( )
{
2014-04-15 16:12:15 +02:00
// s_fontInternalInstance->m_bInitialized = false;
// s_fontInternalInstance->m_bFontGcmInitialized = false;
delete s_fontInternalInstance ;
2014-04-25 18:57:00 +02:00
}