Skip to content

Commit 3fcfa99

Browse files
committed
feat(textview): refresh all textview after loading new font
1 parent 3c62a6b commit 3fcfa99

File tree

5 files changed

+115
-65
lines changed

5 files changed

+115
-65
lines changed

include/LCUI/gui/widget/textview.h

+4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ LCUI_API void TextView_SetAutoWrap(LCUI_Widget w, LCUI_BOOL enable);
4646

4747
LCUI_API void TextView_SetMulitiline(LCUI_Widget w, LCUI_BOOL enable);
4848

49+
LCUI_API size_t LCUIWidget_RefreshTextView(void);
50+
4951
LCUI_API void LCUIWidget_AddTextView(void);
5052

53+
LCUI_API void LCUIWidget_FreeTextView(void);
54+
5155
LCUI_END_HEADER
5256

5357
#endif

src/font/textlayer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static void TextChar_UpdateBitmap(LCUI_TextChar ch, LCUI_TextStyle style)
263263
size = ch->style->pixel_size;
264264
}
265265
}
266-
while (font_ids && font_ids[i] >= 0) {
266+
while (font_ids && font_ids[i] > 0) {
267267
int ret = LCUIFont_GetBitmap(ch->code, font_ids[i],
268268
size, &ch->bitmap);
269269
if (ret == 0) {

src/gui/css_parser.c

+61-53
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,39 @@
2828
* POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31-
3231
#include <errno.h>
3332
#include <stdio.h>
3433
#include <stdlib.h>
3534
#include <string.h>
3635
#include <LCUI_Build.h>
3736
#include <LCUI/LCUI.h>
3837
#include <LCUI/thread.h>
38+
#include <LCUI/gui/widget.h>
39+
#include <LCUI/gui/widget/textview.h>
3940
#include <LCUI/gui/css_library.h>
4041
#include <LCUI/gui/css_parser.h>
4142
#include <LCUI/font.h>
4243

43-
#define SPLIT_NUMBER 1
44-
#define SPLIT_COLOR (1<<1)
45-
#define SPLIT_STYLE (1<<2)
44+
#define SPLIT_NUMBER 1
45+
#define SPLIT_COLOR (1 << 1)
46+
#define SPLIT_STYLE (1 << 2)
4647

47-
#define LEN(A) sizeof( A ) / sizeof( *A )
48+
#define LEN(A) sizeof(A) / sizeof(*A)
4849

4950
static struct CSSParserModule {
5051
int count;
51-
DictType dicttype; /**< 解析器表的字典类型数据 */
52-
Dict *parsers; /**< 解析器表,以名称进行索引 */
52+
DictType dicttype; /**< 解析器表的字典类型数据 */
53+
Dict *parsers; /**< 解析器表,以名称进行索引 */
5354
} self;
5455

55-
static int SplitValues(const char *str, LCUI_Style slist,
56-
int max_len, int mode)
56+
static int SplitValues(const char *str, LCUI_Style slist, int max_len, int mode)
5757
{
5858
char **values;
5959
const char *p;
6060
int val, vi = 0, vj = 0, n_quotes = 0;
6161

62-
values = (char**)calloc(max_len, sizeof(char*));
63-
values[0] = (char*)malloc(sizeof(char) * 64);
62+
values = (char **)calloc(max_len, sizeof(char *));
63+
values[0] = (char *)malloc(sizeof(char) * 64);
6464
for (p = str; *p; ++p) {
6565
if (*p == '(') {
6666
n_quotes += 1;
@@ -81,7 +81,7 @@ static int SplitValues(const char *str, LCUI_Style slist,
8181
if (vi >= max_len) {
8282
goto clean;
8383
}
84-
values[vi] = (char*)malloc(sizeof(char) * 64);
84+
values[vi] = (char *)malloc(sizeof(char) * 64);
8585
}
8686
}
8787
values[vi][vj] = 0;
@@ -195,8 +195,7 @@ static int OnParseImage(LCUI_CSSParserStyleContext ctx, const char *str)
195195
return -1;
196196
}
197197

198-
static int OnParseStyleOption(LCUI_CSSParserStyleContext ctx,
199-
const char *str)
198+
static int OnParseStyleOption(LCUI_CSSParserStyleContext ctx, const char *str)
200199
{
201200
LCUI_Style s = &ctx->sheet->sheet[ctx->parser->key];
202201
int v = LCUI_GetStyleValue(str);
@@ -209,11 +208,10 @@ static int OnParseStyleOption(LCUI_CSSParserStyleContext ctx,
209208
return 0;
210209
}
211210

212-
static int OnParseBorder(LCUI_CSSParserStyleContext ctx,
213-
const char *str)
211+
static int OnParseBorder(LCUI_CSSParserStyleContext ctx, const char *str)
214212
{
215213
LCUI_StyleSheet ss = ctx->sheet;
216-
LCUI_StyleRec slist[3] = { { 0 }, { 0 }, { 0 } };
214+
LCUI_StyleRec slist[3] = { 0 };
217215
int i, mode = SPLIT_COLOR | SPLIT_NUMBER | SPLIT_STYLE;
218216
if (SplitValues(str, slist, 3, mode) < 1) {
219217
return -1;
@@ -242,14 +240,14 @@ static int OnParseBorder(LCUI_CSSParserStyleContext ctx,
242240
ss->sheet[key_border_bottom_style] = slist[i];
243241
ss->sheet[key_border_left_style] = slist[i];
244242
break;
245-
default: return -1;
243+
default:
244+
return -1;
246245
}
247246
}
248247
return 0;
249248
}
250249

251-
static int OnParseBorderRadius(LCUI_CSSParserStyleContext ctx,
252-
const char *str)
250+
static int OnParseBorderRadius(LCUI_CSSParserStyleContext ctx, const char *str)
253251
{
254252
LCUI_StyleRec s;
255253
LCUI_StyleSheet ss = ctx->sheet;
@@ -263,11 +261,10 @@ static int OnParseBorderRadius(LCUI_CSSParserStyleContext ctx,
263261
return 0;
264262
}
265263

266-
static int OnParseBorderLeft(LCUI_CSSParserStyleContext ctx,
267-
const char *str)
264+
static int OnParseBorderLeft(LCUI_CSSParserStyleContext ctx, const char *str)
268265
{
269-
LCUI_StyleRec slist[3];
270266
LCUI_StyleSheet ss = ctx->sheet;
267+
LCUI_StyleRec slist[3] = { 0 };
271268
int i, mode = SPLIT_COLOR | SPLIT_NUMBER | SPLIT_STYLE;
272269
if (SplitValues(str, slist, 3, mode) < 1) {
273270
return -1;
@@ -284,17 +281,17 @@ static int OnParseBorderLeft(LCUI_CSSParserStyleContext ctx,
284281
case LCUI_STYPE_style:
285282
ss->sheet[key_border_left_style] = slist[i];
286283
break;
287-
default: return -1;
284+
default:
285+
return -1;
288286
}
289287
}
290288
return 0;
291289
}
292290

293-
static int OnParseBorderTop(LCUI_CSSParserStyleContext ctx,
294-
const char *str)
291+
static int OnParseBorderTop(LCUI_CSSParserStyleContext ctx, const char *str)
295292
{
296-
LCUI_StyleRec slist[3];
297293
LCUI_StyleSheet ss = ctx->sheet;
294+
LCUI_StyleRec slist[3] = { 0 };
298295
int i, mode = SPLIT_COLOR | SPLIT_NUMBER | SPLIT_STYLE;
299296
if (SplitValues(str, slist, 3, mode) < 1) {
300297
return -1;
@@ -311,17 +308,17 @@ static int OnParseBorderTop(LCUI_CSSParserStyleContext ctx,
311308
case LCUI_STYPE_style:
312309
ss->sheet[key_border_top_style] = slist[i];
313310
break;
314-
default: return -1;
311+
default:
312+
return -1;
315313
}
316314
}
317315
return 0;
318316
}
319317

320-
static int OnParseBorderRight(LCUI_CSSParserStyleContext ctx,
321-
const char *str)
318+
static int OnParseBorderRight(LCUI_CSSParserStyleContext ctx, const char *str)
322319
{
323-
LCUI_StyleRec slist[3];
324320
LCUI_StyleSheet ss = ctx->sheet;
321+
LCUI_StyleRec slist[3] = { 0 };
325322
int i, mode = SPLIT_COLOR | SPLIT_NUMBER | SPLIT_STYLE;
326323
if (SplitValues(str, slist, 3, mode) < 1) {
327324
return -1;
@@ -338,17 +335,17 @@ static int OnParseBorderRight(LCUI_CSSParserStyleContext ctx,
338335
case LCUI_STYPE_style:
339336
ss->sheet[key_border_right_style] = slist[i];
340337
break;
341-
default: return -1;
338+
default:
339+
return -1;
342340
}
343341
}
344342
return 0;
345343
}
346344

347-
static int OnParseBorderBottom(LCUI_CSSParserStyleContext ctx,
348-
const char *str)
345+
static int OnParseBorderBottom(LCUI_CSSParserStyleContext ctx, const char *str)
349346
{
350-
LCUI_StyleRec slist[3];
351347
LCUI_StyleSheet ss = ctx->sheet;
348+
LCUI_StyleRec slist[3] = { 0 };
352349
int i, mode = SPLIT_COLOR | SPLIT_NUMBER | SPLIT_STYLE;
353350
if (SplitValues(str, slist, 3, mode) < 1) {
354351
return -1;
@@ -365,7 +362,8 @@ static int OnParseBorderBottom(LCUI_CSSParserStyleContext ctx,
365362
case LCUI_STYPE_style:
366363
ss->sheet[key_border_bottom_style] = slist[i];
367364
break;
368-
default: return -1;
365+
default:
366+
return -1;
369367
}
370368
}
371369
return 0;
@@ -418,7 +416,7 @@ static int OnParseBorderStyle(LCUI_CSSParserStyleContext ctx, const char *str)
418416

419417
static int OnParsePadding(LCUI_CSSParserStyleContext ctx, const char *str)
420418
{
421-
LCUI_StyleRec s[4];
419+
LCUI_StyleRec s[4] = { 0 };
422420
LCUI_StyleSheet ss = ctx->sheet;
423421
switch (SplitValues(str, s, 4, SPLIT_NUMBER)) {
424422
case 1:
@@ -444,14 +442,15 @@ static int OnParsePadding(LCUI_CSSParserStyleContext ctx, const char *str)
444442
ss->sheet[key_padding_right] = s[1];
445443
ss->sheet[key_padding_bottom] = s[2];
446444
ss->sheet[key_padding_left] = s[3];
447-
default: break;
445+
default:
446+
break;
448447
}
449448
return 0;
450449
}
451450

452451
static int OnParseMargin(LCUI_CSSParserStyleContext ctx, const char *str)
453452
{
454-
LCUI_StyleRec s[4];
453+
LCUI_StyleRec s[4] = { 0 };
455454
LCUI_StyleSheet ss = ctx->sheet;
456455
switch (SplitValues(str, s, 4, SPLIT_NUMBER)) {
457456
case 1:
@@ -477,14 +476,15 @@ static int OnParseMargin(LCUI_CSSParserStyleContext ctx, const char *str)
477476
ss->sheet[key_margin_right] = s[1];
478477
ss->sheet[key_margin_bottom] = s[2];
479478
ss->sheet[key_margin_left] = s[3];
480-
default: break;
479+
default:
480+
break;
481481
}
482482
return 0;
483483
}
484484

485485
static int OnParseBoxShadow(LCUI_CSSParserStyleContext ctx, const char *str)
486486
{
487-
LCUI_StyleRec s[5];
487+
LCUI_StyleRec s[5] = { 0 };
488488
LCUI_StyleSheet ss = ctx->sheet;
489489
if (strcasecmp(str, "none") == 0) {
490490
SetStyle(ss, key_box_shadow_x, 0, none);
@@ -508,7 +508,8 @@ static int OnParseBoxShadow(LCUI_CSSParserStyleContext ctx, const char *str)
508508
ss->sheet[key_box_shadow_blur] = s[2];
509509
ss->sheet[key_box_shadow_color] = s[3];
510510
break;
511-
default: return -1;
511+
default:
512+
return -1;
512513
}
513514
return 0;
514515
}
@@ -518,9 +519,10 @@ static int OnParseBackground(LCUI_CSSParserStyleContext ctx, const char *str)
518519
return 0;
519520
}
520521

521-
static int OnParseBackgroundPosition(LCUI_CSSParserStyleContext ctx, const char *str)
522+
static int OnParseBackgroundPosition(LCUI_CSSParserStyleContext ctx,
523+
const char *str)
522524
{
523-
LCUI_StyleRec slist[2];
525+
LCUI_StyleRec slist[2] = { 0 };
524526
int ret = OnParseStyleOption(ctx, str);
525527
if (ret == 0) {
526528
return 0;
@@ -533,9 +535,10 @@ static int OnParseBackgroundPosition(LCUI_CSSParserStyleContext ctx, const char
533535
return -2;
534536
}
535537

536-
static int OnParseBackgroundSize(LCUI_CSSParserStyleContext ctx, const char *str)
538+
static int OnParseBackgroundSize(LCUI_CSSParserStyleContext ctx,
539+
const char *str)
537540
{
538-
LCUI_StyleRec slist[2];
541+
LCUI_StyleRec slist[2] = { 0 };
539542
int ret = OnParseStyleOption(ctx, str);
540543
if (ret == 0) {
541544
SetStyle(ctx->sheet, key_background_size_width, 0, 0);
@@ -552,7 +555,8 @@ static int OnParseBackgroundSize(LCUI_CSSParserStyleContext ctx, const char *str
552555
return 0;
553556
}
554557

555-
static int OnParseBackgroundRepeat(LCUI_CSSParserStyleContext ctx, const char *str)
558+
static int OnParseBackgroundRepeat(LCUI_CSSParserStyleContext ctx,
559+
const char *str)
556560
{
557561
return 0;
558562
}
@@ -645,8 +649,12 @@ static int CSSParser_ParseComment(LCUI_CSSParserContext ctx)
645649
int CSSParser_BeginParseComment(LCUI_CSSParserContext ctx)
646650
{
647651
switch (*(ctx->cur + 1)) {
648-
case '/': ctx->comment.is_line_comment = TRUE; break;
649-
case '*': ctx->comment.is_line_comment = FALSE; break;
652+
case '/':
653+
ctx->comment.is_line_comment = TRUE;
654+
break;
655+
case '*':
656+
ctx->comment.is_line_comment = FALSE;
657+
break;
650658
default:
651659
CSSParser_GetChar(ctx);
652660
return -1;
@@ -694,8 +702,7 @@ static int CSSParser_ParseSelector(LCUI_CSSParserContext ctx)
694702
return 0;
695703
}
696704

697-
static int CSSParser_SetRuleParser(LCUI_CSSParserContext ctx,
698-
const char *name)
705+
static int CSSParser_SetRuleParser(LCUI_CSSParserContext ctx, const char *name)
699706
{
700707
LCUI_CSSRule rule;
701708
LCUI_CSSRuleParser parser;
@@ -754,8 +761,8 @@ static int CSSParser_ParseStyleName(LCUI_CSSParserContext ctx)
754761
ctx->target = CSS_TARGET_VALUE;
755762
CSSParser_EndBuffer(ctx);
756763
CSSParser_SetStyleParser(ctx, ctx->buffer);
757-
DEBUG_MSG("select style: %s, parser: %p\n",
758-
ctx->buffer, ctx->style_parser);
764+
DEBUG_MSG("select style: %s, parser: %p\n", ctx->buffer,
765+
ctx->style_parser);
759766
break;
760767
case '}':
761768
ctx->target = CSS_TARGET_NONE;
@@ -833,6 +840,7 @@ void CSSParser_EndParseRuleData(LCUI_CSSParserContext ctx)
833840
static void LoadFontFile(void *arg1, void *arg2)
834841
{
835842
LCUIFont_LoadFile(arg1);
843+
LCUIWidget_RefreshTextView();
836844
}
837845

838846
static void OnParsedFontFace(LCUI_CSSFontFace face)

src/gui/widget.c

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void LCUI_InitWidget(void)
6060

6161
void LCUI_FreeWidget(void)
6262
{
63+
LCUIWidget_FreeTextView();
6364
LCUIWidget_FreeTasks();
6465
LCUIWidget_FreeRoot();
6566
LCUIWidget_FreeEvent();

0 commit comments

Comments
 (0)