fixed unicode rendering rule in string render routine
This commit is contained in:
parent
6bbc2f76c0
commit
3edcf0a5b3
|
@ -35,13 +35,14 @@
|
|||
|
||||
#include "4ed_rendering.h"
|
||||
#include "4ed.h"
|
||||
#include "4ed_buffer_model.h"
|
||||
|
||||
#define FCPP_FORBID_MALLOC
|
||||
#include "4cpp/4cpp_lexer.h"
|
||||
|
||||
#include "4ed_doubly_linked_list.cpp"
|
||||
|
||||
#include "4ed_font_set.cpp"
|
||||
#include "4ed_translation.cpp"
|
||||
#include "4ed_rendering_helper.cpp"
|
||||
|
||||
#include "4ed_style.h"
|
||||
|
|
|
@ -186,6 +186,8 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count,
|
|||
return(shift_amount);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
internal i32
|
||||
eol_convert_in(char *dest, char *src, i32 size){
|
||||
i32 i = 0, j = 0, k = 0;
|
||||
|
@ -271,6 +273,8 @@ eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){
|
|||
return(result);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
// TODO(allen): ditch this shit yo
|
||||
inline i32
|
||||
is_whitespace(char c){
|
||||
|
@ -333,26 +337,7 @@ is_match_insensitive(char *a, char *b, i32 len){
|
|||
return(result);
|
||||
}
|
||||
|
||||
struct Buffer_Model_Step{
|
||||
u32 type;
|
||||
u32 value;
|
||||
i32 i;
|
||||
u32 byte_length;
|
||||
};
|
||||
|
||||
struct Buffer_Model_Behavior{
|
||||
b32 do_newline;
|
||||
b32 do_codepoint_advance;
|
||||
b32 do_number_advance;
|
||||
};
|
||||
|
||||
enum{
|
||||
BufferModelUnit_None,
|
||||
BufferModelUnit_Codepoint,
|
||||
BufferModelUnit_Numbers,
|
||||
};
|
||||
|
||||
#include "4ed_translation.cpp"
|
||||
//////////////////////////////////////
|
||||
|
||||
//
|
||||
// Implementation of the gap buffer
|
||||
|
@ -417,31 +402,30 @@ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){
|
|||
buffer->max = page_size;
|
||||
}
|
||||
|
||||
internal i32
|
||||
internal b32
|
||||
buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){
|
||||
Gap_Buffer *buffer = init->buffer;
|
||||
i32 osize1 = 0, size1 = 0, size2 = 0, size = init->size;
|
||||
i32 result = 0;
|
||||
b32 result = false;
|
||||
|
||||
if (buffer->data){
|
||||
if (buffer->max >= init->size){
|
||||
size2 = size >> 1;
|
||||
size1 = osize1 = size - size2;
|
||||
|
||||
if (size1 > 0){
|
||||
size1 = eol_convert_in(buffer->data, init->data, size1);
|
||||
if (size2 > 0){
|
||||
size2 = eol_convert_in(buffer->data + size1, init->data + osize1, size2);
|
||||
}
|
||||
if (buffer->data && buffer->max >= init->size){
|
||||
i32 size = init->size;
|
||||
i32 size2 = size >> 1;
|
||||
i32 osize1 = size - size2;
|
||||
i32 size1 = osize1;
|
||||
|
||||
if (size1 > 0){
|
||||
size1 = eol_convert_in(buffer->data, init->data, size1);
|
||||
if (size2 > 0){
|
||||
size2 = eol_convert_in(buffer->data + size1, init->data + osize1, size2);
|
||||
}
|
||||
|
||||
buffer->size1 = size1;
|
||||
buffer->size2 = size2;
|
||||
buffer->gap_size = buffer->max - size1 - size2;
|
||||
memmove(buffer->data + size1 + buffer->gap_size, buffer->data + size1, size2);
|
||||
|
||||
result = 1;
|
||||
}
|
||||
|
||||
buffer->size1 = size1;
|
||||
buffer->size2 = size2;
|
||||
buffer->gap_size = buffer->max - size1 - size2;
|
||||
memmove(buffer->data + size1 + buffer->gap_size, buffer->data + size1, size2);
|
||||
|
||||
result = true;
|
||||
}
|
||||
|
||||
return(result);
|
||||
|
@ -779,7 +763,7 @@ buffer_measure_character_starts(System_Functions *system, Render_Font *font, Gap
|
|||
|
||||
translating_fully_process_byte(system, font, &tran, ch, i, size, &emits);
|
||||
|
||||
for (TRANSLATION_DECL_OUTPUT(J, emits)){
|
||||
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
|
||||
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
|
||||
|
||||
if (behavior.do_newline){
|
||||
|
@ -906,7 +890,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
|
|||
translating_fully_process_byte(params.system, params.font, &S.tran, ch, S.i, S.size, &S.emits);
|
||||
}
|
||||
|
||||
for (TRANSLATION_OUTPUT(S.J, S.emits)){
|
||||
for (TRANSLATION_EMIT_LOOP(S.J, S.emits)){
|
||||
TRANSLATION_GET_STEP(S.step, S.behavior, S.J, S.emits);
|
||||
|
||||
if (S.behavior.do_newline){
|
||||
|
@ -1115,7 +1099,7 @@ buffer_remeasure_character_starts(System_Functions *system, Render_Font *font, G
|
|||
u8 ch = (u8)stream.data[char_i];
|
||||
translating_fully_process_byte(system, font, &tran, ch, char_i, size, &emits);
|
||||
|
||||
for (TRANSLATION_DECL_OUTPUT(J, emits)){
|
||||
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
|
||||
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
|
||||
|
||||
if (behavior.do_newline){
|
||||
|
@ -1590,7 +1574,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
|
|||
translating_fully_process_byte(params.system, params.font, &S.tran, ch, S.i, S.size, &S.emits);
|
||||
}
|
||||
|
||||
for (TRANSLATION_OUTPUT(S.J, S.emits)){
|
||||
for (TRANSLATION_EMIT_LOOP(S.J, S.emits)){
|
||||
TRANSLATION_GET_STEP(S.step, S.behavior, S.J, S.emits);
|
||||
|
||||
S.prev_cursor = S.this_cursor;
|
||||
|
@ -1953,7 +1937,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
|
|||
translating_fully_process_byte(params.system, params.font, &S.tran, ch, S.i, S.size, &S.emits);
|
||||
}
|
||||
|
||||
for (TRANSLATION_OUTPUT(S.J, S.emits)){
|
||||
for (TRANSLATION_EMIT_LOOP(S.J, S.emits)){
|
||||
TRANSLATION_GET_STEP(S.step, S.behavior, S.J, S.emits);
|
||||
|
||||
if (!S.behavior.do_newline && S.step.i >= S.wrap_unit_end){
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 18.03.2017
|
||||
*
|
||||
* Abstract model for the describing the characters of a buffer.
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
#if !defined(FRED_BUFFER_MODEL_H)
|
||||
#define FRED_BUFFER_MODEL_H
|
||||
|
||||
struct Buffer_Model_Step{
|
||||
u32 type;
|
||||
u32 value;
|
||||
i32 i;
|
||||
u32 byte_length;
|
||||
};
|
||||
|
||||
struct Buffer_Model_Behavior{
|
||||
b32 do_newline;
|
||||
b32 do_codepoint_advance;
|
||||
b32 do_number_advance;
|
||||
};
|
||||
|
||||
enum{
|
||||
BufferModelUnit_None,
|
||||
BufferModelUnit_Codepoint,
|
||||
BufferModelUnit_Numbers,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -1132,7 +1132,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
|
|||
u8 ch = (u8)state->stream.data[i];
|
||||
translating_fully_process_byte(system, font, &state->tran, ch, i, state->size, &state->emits);
|
||||
|
||||
for (TRANSLATION_OUTPUT(state->J, state->emits)){
|
||||
for (TRANSLATION_EMIT_LOOP(state->J, state->emits)){
|
||||
TRANSLATION_GET_STEP(state->step, state->behavior, state->J, state->emits);
|
||||
|
||||
if (state->behavior.do_newline){
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 18.12.2015
|
||||
*
|
||||
* Font set for 4coder
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -139,10 +139,46 @@ draw_string_base(System_Functions *system, Render_Target *target, Font_ID font_i
|
|||
x = (f32)x_;
|
||||
|
||||
f32 byte_advance = font_get_byte_advance(font);
|
||||
f32 *sub_advances = font_get_byte_sub_advances(font);
|
||||
|
||||
u8 *str = (u8*)str_.str;
|
||||
u8 *str_end = str + str_.size;
|
||||
|
||||
Translation_State tran = {0};
|
||||
Translation_Emits emits = {0};
|
||||
|
||||
for (u32 i = 0; str < str_end; ++str, ++i){
|
||||
translating_fully_process_byte(system, font, &tran, *str, i, str_.size, &emits);
|
||||
|
||||
for (TRANSLATION_DECL_EMIT_LOOP(j, emits)){
|
||||
TRANSLATION_DECL_GET_STEP(step, behavior, j, emits);
|
||||
|
||||
if (behavior.do_codepoint_advance){
|
||||
u32 codepoint = step.value;
|
||||
if (color != 0){
|
||||
font_draw_glyph(target, font_id, type, codepoint, x, y, color);
|
||||
}
|
||||
x += font_get_glyph_advance(system, font, codepoint);
|
||||
}
|
||||
else if (behavior.do_number_advance){
|
||||
u8 n = (u8)(step.value);
|
||||
if (color != 0){
|
||||
u8 cs[3];
|
||||
cs[0] = '\\';
|
||||
byte_to_ascii(n, cs+1);
|
||||
|
||||
f32 xx = x;
|
||||
for (u32 j = 0; j < 3; ++j){
|
||||
font_draw_glyph(target, font_id, type, cs[j], xx, y, color);
|
||||
xx += sub_advances[j];
|
||||
}
|
||||
}
|
||||
x += byte_advance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
for (;str < str_end;){
|
||||
u8 *byte = str;
|
||||
u32 codepoint = utf8_to_u32(&str, str_end);
|
||||
|
@ -188,6 +224,7 @@ draw_string_base(System_Functions *system, Render_Target *target, Font_ID font_i
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return(x);
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
// TOP
|
||||
|
||||
#include "4ed_buffer_model.h"
|
||||
|
||||
struct Translation_State{
|
||||
u8 fill_buffer[4];
|
||||
u32 fill_start_i;
|
||||
|
@ -196,17 +198,6 @@ translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_r
|
|||
skip_all:;
|
||||
}
|
||||
|
||||
#if 0
|
||||
internal void
|
||||
translating_fully_process_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){
|
||||
Translation_Byte_Description description = {0};
|
||||
translating_consume_byte(tran, ch, i, size, &description);
|
||||
Translation_Emit_Rule emit_rule = {0};
|
||||
translating_select_emit_rule_ASCII(tran, description, &emit_rule);
|
||||
translating_generate_emits(tran, emit_rule, ch, i, emits_out);
|
||||
}
|
||||
#endif
|
||||
|
||||
internal void
|
||||
translating_fully_process_byte(System_Functions *system, Render_Font *font, Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){
|
||||
Translation_Byte_Description description = {0};
|
||||
|
@ -238,12 +229,12 @@ translation_step_read(Buffer_Model_Step step, Buffer_Model_Behavior *behavior_ou
|
|||
}
|
||||
}
|
||||
|
||||
#define TRANSLATION_DECL_OUTPUT(_j,_emit) u32 _j = 0; _j < (_emit).step_count; ++_j
|
||||
#define TRANSLATION_DECL_EMIT_LOOP(_j,_emit) u32 _j = 0; _j < (_emit).step_count; ++_j
|
||||
#define TRANSLATION_DECL_GET_STEP(_step,_behav,_j,_emit) \
|
||||
Buffer_Model_Step _step = _emit.steps[_j]; Buffer_Model_Behavior _behav; \
|
||||
translation_step_read(_step, &_behav)
|
||||
|
||||
#define TRANSLATION_OUTPUT(_j,_emit) _j = 0; _j < (_emit).step_count; ++_j
|
||||
#define TRANSLATION_EMIT_LOOP(_j,_emit) _j = 0; _j < (_emit).step_count; ++_j
|
||||
#define TRANSLATION_GET_STEP(_step,_behav,_j,_emit)\
|
||||
(_step) = _emit.steps[_j]; translation_step_read((_step), &(_behav))
|
||||
|
||||
|
|
Loading…
Reference in New Issue