mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-30 19:08:12 +03:00
parts: clean up text layout logic
This commit is contained in:
+2
-8
@@ -163,21 +163,15 @@ float gfx_render_textf(Texture *dst, float x, int y, char *msg, struct text_styl
|
||||
void gfx_render_dash_text(Texture *dst, struct text_style *ts);
|
||||
void gfx_draw_text_to_amap(Texture *dst, int x, int y, char *text);
|
||||
void gfx_draw_text_to_pmap(Texture *dst, int x, int y, char *text);
|
||||
float gfx_size_char_unstyled(struct text_style *ts, const char *ch);
|
||||
float gfx_size_char(struct text_style *ts, const char *ch);
|
||||
float gfx_size_char_kerning(struct text_style *ts, uint32_t code, uint32_t code_next);
|
||||
float gfx_size_text(struct text_style *ts, const char *text);
|
||||
float gfx_get_actual_font_size(unsigned face, float size);
|
||||
float gfx_get_actual_font_size_round_down(unsigned face, float size);
|
||||
|
||||
static inline float text_style_width(struct text_style *ts, const char *ch)
|
||||
{
|
||||
return (gfx_size_char(ts, ch) + (ts->bold_width * 2) + ts->edge_left + ts->edge_right)
|
||||
* ts->scale_x;
|
||||
}
|
||||
|
||||
static inline float text_style_height(struct text_style *ts)
|
||||
{
|
||||
return ts->size + (ts->bold_width * 2) + ts->edge_up + ts->edge_down;
|
||||
return ts->size + ceilf(ts->bold_width)*2 + ts->edge_up + ts->edge_down;
|
||||
}
|
||||
|
||||
#endif /* SYSTEM4_FONT_H */
|
||||
|
||||
@@ -176,7 +176,7 @@ static void charsprite_render(struct charsprite *cs)
|
||||
ch[2] = 0;
|
||||
}
|
||||
|
||||
int w = ceilf(text_style_width(&cs->ts, ch));
|
||||
int w = ceilf(gfx_size_char(&cs->ts, ch));
|
||||
int h = cs->ts.size + cs->ts.size/2;
|
||||
sprite_init_color(&cs->sp, w, h, 0, 0, 0, 0);
|
||||
sprite_get_texture(&cs->sp); // XXX: force initialization of texture
|
||||
|
||||
@@ -113,7 +113,7 @@ bool StoatSpriteEngine_SP_SetTextSprite(int sp_no, struct string *text)
|
||||
|
||||
char s[3];
|
||||
extract_sjis_char(text->text, s);
|
||||
int w = ceilf(text_style_width(&text_sprite_ts, s));
|
||||
int w = ceilf(gfx_size_char(&text_sprite_ts, s));
|
||||
int h = text_sprite_ts.size;
|
||||
// XXX: System40.exe lies about the height of half-width characters.
|
||||
// E.g. a size 64 letter "H" is reported as 32 pixels tall.
|
||||
|
||||
@@ -82,7 +82,7 @@ struct sound_motion {
|
||||
struct parts_text_char {
|
||||
Texture t;
|
||||
char ch[4];
|
||||
float advance;
|
||||
int advance;
|
||||
Point off;
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -135,7 +135,7 @@ static void parts_render_text(struct parts *parts, struct parts_text *t)
|
||||
Rectangle r = { 0, 0, ch->t.w, ch->t.h };
|
||||
parts_render_texture(&ch->t, mw_transform, &r, blend_rate, add_color,
|
||||
multiply_color, 0, parts->alpha_clipper_parts_no);
|
||||
x += ceilf(ch->advance);
|
||||
x += ch->advance;
|
||||
}
|
||||
x = parts->global.pos.x + t->common.origin_offset.x;
|
||||
y += line->height + t->line_space;
|
||||
|
||||
+3
-4
@@ -84,13 +84,12 @@ static const char *parts_text_append_char(struct parts_text *t, const char *str)
|
||||
|
||||
ch->off = text_style_offset(&t->ts);
|
||||
int len = extract_sjis_char(str, ch->ch);
|
||||
int width = ceilf(text_style_width(&t->ts, ch->ch));
|
||||
int width = gfx_size_char(&t->ts, ch->ch);
|
||||
int height = text_style_height(&t->ts);
|
||||
gfx_init_texture_rgba(&ch->t, width, height, (SDL_Color){0,0,0,0});
|
||||
ch->advance = gfx_render_textf(&ch->t, 0, 0, ch->ch, &t->ts, false);
|
||||
|
||||
ch->advance = ceilf(gfx_render_textf(&ch->t, 0, 0, ch->ch, &t->ts, false));
|
||||
line->width += ch->advance;
|
||||
line->height = max(line->height, height + ceilf(t->ts.bold_width)*2);
|
||||
line->height = max(line->height, height);
|
||||
return str + len;
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -158,16 +158,18 @@ static uint32_t char_to_code(const char *ch, enum charmap charmap)
|
||||
return c;
|
||||
}
|
||||
|
||||
float gfx_size_char(struct text_style *ts, const char *ch)
|
||||
float gfx_size_char_unstyled(struct text_style *ts, const char *ch)
|
||||
{
|
||||
struct font_size *size = text_style_font_size(ts);
|
||||
return font_size_char(size, char_to_code(ch, size->font->charmap));
|
||||
}
|
||||
|
||||
float gfx_size_char_kerning(struct text_style *ts, uint32_t code, uint32_t code_next)
|
||||
float gfx_size_char(struct text_style *ts, const char *ch)
|
||||
{
|
||||
struct font_size *size = text_style_font_size(ts);
|
||||
return size->font->size_char_kerning(size, code, code_next);
|
||||
float w = gfx_size_char_unstyled(ts, ch);
|
||||
if (gfx_text_advance_edges)
|
||||
w += ts->edge_left + ts->edge_right + ceilf(ts->bold_width)*2;
|
||||
return w * ts->scale_x;
|
||||
}
|
||||
|
||||
float gfx_size_text(struct text_style *ts, const char *text)
|
||||
@@ -182,7 +184,7 @@ float gfx_size_text(struct text_style *ts, const char *text)
|
||||
x += edge_advance;
|
||||
text = sjis_skip_char(text);
|
||||
}
|
||||
return x;
|
||||
return x * ts->scale_x;;
|
||||
}
|
||||
|
||||
float gfx_get_actual_font_size(unsigned face, float size)
|
||||
|
||||
Reference in New Issue
Block a user