mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
Update textlayer style cache processing
This commit is contained in:
@@ -63,10 +63,14 @@ typedef struct LCUI_TextStyleRec_ {
|
||||
/** 初始化字体样式数据 */
|
||||
LCUI_API void TextStyle_Init( LCUI_TextStyle data );
|
||||
|
||||
LCUI_API int TextStyle_CopyFamily( LCUI_TextStyle dst, LCUI_TextStyle src );
|
||||
|
||||
LCUI_API int TextStyle_Copy( LCUI_TextStyle dst, LCUI_TextStyle src );
|
||||
|
||||
LCUI_API void TextStyle_Destroy( LCUI_TextStyle data );
|
||||
|
||||
LCUI_API void TextStyle_Merge( LCUI_TextStyle base, LCUI_TextStyle target );
|
||||
|
||||
/* 设置字体粗细程度 */
|
||||
LCUI_API int TextStyle_SetWeight( LCUI_TextStyle ts, LCUI_FontWeight weight );
|
||||
|
||||
|
||||
+11
-14
@@ -1168,23 +1168,20 @@ void TextLayer_SetUsingStyleTags( LCUI_TextLayer layer, LCUI_BOOL is_true )
|
||||
layer->is_using_style_tags = is_true;
|
||||
}
|
||||
|
||||
static void TextLayer_UpdateTextStyleCache( LCUI_TextLayer layer )
|
||||
{
|
||||
LinkedListNode *node;
|
||||
/* 替换缺省字体,确保能够正确应用字体设置 */
|
||||
for( LinkedList_Each( node, &layer->style_cache ) ) {
|
||||
TextStyle_Merge( node->data, &layer->text_style );
|
||||
}
|
||||
}
|
||||
|
||||
/** 重新载入各个文字的字体位图 */
|
||||
void TextLayer_ReloadCharBitmap( LCUI_TextLayer layer )
|
||||
{
|
||||
LinkedListNode *node;
|
||||
int row, col, *font_ids;
|
||||
/* 替换缺省字体,确保能够正确应用字体粗细程度设置 */
|
||||
for( LinkedList_Each( node, &layer->style_cache ) ) {
|
||||
LCUI_TextStyle style = node->data;
|
||||
if( style->has_family || !style->has_weight ) {
|
||||
continue;
|
||||
}
|
||||
if( LCUIFont_UpdateWeight( layer->text_style.font_ids,
|
||||
style->weight, &font_ids ) > 0 ) {
|
||||
style->has_family = TRUE;
|
||||
style->font_ids = font_ids;
|
||||
}
|
||||
}
|
||||
int row, col;
|
||||
TextLayer_UpdateTextStyleCache( layer );
|
||||
for( row = 0; row < layer->text_rows.length; ++row ) {
|
||||
TextRow txtrow = layer->text_rows.rows[row];
|
||||
for( col = 0; col < txtrow->length; ++col ) {
|
||||
|
||||
+46
-5
@@ -75,23 +75,33 @@ void TextStyle_Init( LCUI_TextStyle data )
|
||||
data->pixel_size = 13;
|
||||
}
|
||||
|
||||
int TextStyle_Copy( LCUI_TextStyle dst, LCUI_TextStyle src )
|
||||
int TextStyle_CopyFamily( LCUI_TextStyle dst, LCUI_TextStyle src )
|
||||
{
|
||||
int len;
|
||||
*dst = *src;
|
||||
if( !dst->has_family ) {
|
||||
size_t len;
|
||||
if( !src->has_family ) {
|
||||
return 0;
|
||||
}
|
||||
for( len = 0; dst->font_ids[len] != -1; ++len );
|
||||
for( len = 0; src->font_ids[len] != -1; ++len );
|
||||
len += 1;
|
||||
if( dst->font_ids ) {
|
||||
free( dst->font_ids );
|
||||
}
|
||||
dst->font_ids = malloc( len * sizeof( int ) );
|
||||
if( !dst->font_ids ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
dst->has_family = TRUE;
|
||||
memcpy( dst->font_ids, src->font_ids, len * sizeof( int ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TextStyle_Copy( LCUI_TextStyle dst, LCUI_TextStyle src )
|
||||
{
|
||||
*dst = *src;
|
||||
dst->font_ids = NULL;
|
||||
return TextStyle_CopyFamily( dst, src );
|
||||
}
|
||||
|
||||
void TextStyle_Destroy( LCUI_TextStyle data )
|
||||
{
|
||||
if( data->font_ids ) {
|
||||
@@ -100,6 +110,37 @@ void TextStyle_Destroy( LCUI_TextStyle data )
|
||||
data->font_ids = NULL;
|
||||
}
|
||||
|
||||
void TextStyle_Merge( LCUI_TextStyle base, LCUI_TextStyle target )
|
||||
{
|
||||
int *font_ids = NULL;
|
||||
if( !base->has_family && target->has_family ) {
|
||||
base->has_family = TRUE;
|
||||
TextStyle_CopyFamily( base, target );
|
||||
}
|
||||
if( target->has_style && !base->has_style &&
|
||||
target->style != FONT_STYLE_NORMAL ) {
|
||||
base->has_style = TRUE;
|
||||
base->style = target->style;
|
||||
if( LCUIFont_UpdateStyle( base->font_ids,
|
||||
base->style,
|
||||
&font_ids ) > 0 ) {
|
||||
free( base->font_ids );
|
||||
base->font_ids = font_ids;
|
||||
}
|
||||
}
|
||||
if( target->has_weight && !base->has_weight &&
|
||||
target->weight != FONT_WEIGHT_NORMAL ) {
|
||||
base->has_weight = TRUE;
|
||||
base->weight = target->weight;
|
||||
if( LCUIFont_UpdateWeight( base->font_ids,
|
||||
base->weight,
|
||||
&font_ids ) > 0 ) {
|
||||
free( base->font_ids );
|
||||
base->font_ids = font_ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int TextStyle_SetWeight( LCUI_TextStyle ts, LCUI_FontWeight weight )
|
||||
{
|
||||
int *font_ids;
|
||||
|
||||
Reference in New Issue
Block a user