From d94c8c3672279f99b777d86689ef60ab2a486ce4 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 25 Mar 2017 16:49:54 -0400 Subject: [PATCH] got code wrapping working --- 4coder_lib/4coder_utf8.h | 4 +- 4coder_project_commands.cpp | 2 +- 4ed_file_view.cpp | 74 ++++++++++++++++++++++++------------- 4ed_translation.cpp | 9 ++++- 4 files changed, 59 insertions(+), 30 deletions(-) diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h index bff8d7d7..0cb1495f 100644 --- a/4coder_lib/4coder_utf8.h +++ b/4coder_lib/4coder_utf8.h @@ -90,7 +90,7 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){ *length_out = 4; } - if (result < cp_min_by_utf8_length[*length_out] || (result >= surrogate_min && result <= surrogate_max) || (result >= nonchar_min && result <= nonchar_max) || ((result & 0xFFFF) >= 0xFE)){ + if (result < cp_min_by_utf8_length[*length_out] || (result >= surrogate_min && result <= surrogate_max)){ result = 0; *length_out = 0; } @@ -167,7 +167,7 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){ }break; } - if (result < cp_min_by_utf8_length[length] || (result >= surrogate_min && result <= surrogate_max) || (result >= nonchar_min && result <= nonchar_max) || ((result & 0xFFFF) >= 0xFE)){ + if (result < cp_min_by_utf8_length[length] || (result >= surrogate_min && result <= surrogate_max)){ result = 0; length = 0; } diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index c9104821..8a7c2459 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -344,7 +344,7 @@ CUSTOM_COMMAND_SIG(load_project){ if (read_bool){ if (config_bool_var(array_item, 0, 0, dest_bool)){ - if (dest_bool){ + if (*dest_bool){ append(&msg, "true, "); } else{ diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index b0943d97..ee96d513 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1113,7 +1113,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ end = fixed_end_point; } - i = clamp_top(i, line_start); + i = clamp_bottom(i, line_start); if (i == line_start){ skipping_whitespace = true; @@ -1507,9 +1507,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, i32 potential_count = 0; i32 stage = 0; - Translation_State tran = {0}; - Translation_Emits emits = {0}; - do{ stop = buffer_measure_wrap_y(&state, params, current_line_shift, do_wrap, wrap_unit_end); @@ -1530,6 +1527,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } else{ + Translation_State tran = {0}; + Translation_Emits emits = {0}; Gap_Buffer_Stream stream = {0}; i32 word_stage = 0; @@ -1655,6 +1654,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, step.this_token = wrap_state.token_ptr; Gap_Buffer_Stream stream = {0}; + Translation_State tran = {0}; + Translation_Emits emits = {0}; Potential_Wrap_Indent_Pair potential_wrap = {0}; potential_wrap.wrap_position = i; @@ -1668,10 +1669,16 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, while(still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); + } - if (!char_is_whitespace(ch)){ - goto doublebreak_stage_vspace; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + if (!codepoint_is_whitespace(buffer_step.value)){ + goto doublebreak_stage_vspace; + } } } still_looping = buffer_stringify_next(&stream); @@ -1679,19 +1686,29 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, doublebreak_stage_vspace:; do{ + i32 pos_end_i = end_i; while (still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; - - if (char_is_whitespace(ch)){ - goto doublebreak_stage1; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); } - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - x += adv; - if (!first_word && x > current_width){ - emit_comment_position = 1; - goto doublebreak_stage1; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + if (codepoint_is_whitespace(buffer_step.value)){ + pos_end_i = buffer_step.i; + goto doublebreak_stage1; + } + + f32 adv = font_get_glyph_advance(params.system, params.font, buffer_step.value); + x += adv; + + if (!first_word && x > current_width){ + pos_end_i = buffer_step.i; + emit_comment_position = true; + goto doublebreak_stage1; + } } } still_looping = buffer_stringify_next(&stream); @@ -1700,28 +1717,35 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, first_word = 0; if (emit_comment_position){ - step.position_end = i; + step.position_end = pos_end_i; step.final_x = x; goto finished_comment_split; } while(still_looping){ for (; i < stream.end; ++i){ - u8 ch = stream.data[i]; - - if (!char_is_whitespace(ch)){ - goto doublebreak_stage2; + { + u8 ch = stream.data[i]; + translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits); } - f32 adv = font_get_glyph_advance(params.system, params.font, ch); - - x += adv; + for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){ + TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits); + + if (!codepoint_is_whitespace(buffer_step.value)){ + pos_end_i = buffer_step.i; + goto doublebreak_stage2; + } + + f32 adv = font_get_glyph_advance(params.system, params.font, buffer_step.value); + x += adv; + } } still_looping = buffer_stringify_next(&stream); } doublebreak_stage2:; - potential_wrap.wrap_position = i; + potential_wrap.wrap_position = pos_end_i; potential_wrap.wrap_x = x; }while(still_looping); } diff --git a/4ed_translation.cpp b/4ed_translation.cpp index c56b11aa..97a15980 100644 --- a/4ed_translation.cpp +++ b/4ed_translation.cpp @@ -143,10 +143,15 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo if (desc.prelim_emit_type == BufferModelUnit_Codepoint){ u32 cp = utf8_to_u32_length_unchecked(tran->fill_buffer, &type_out->codepoint_length); if (type_out->codepoint_length != 0){ - type_out->codepoint = cp; - if (!font_can_render(system, font, cp)){ + if ((cp >= nonchar_min && cp <= nonchar_max) || ((cp & 0xFFFF) >= 0xFE)){ type_out->emit_type = BufferModelUnit_Numbers; } + else{ + type_out->codepoint = cp; + if (!font_can_render(system, font, cp)){ + type_out->emit_type = BufferModelUnit_Numbers; + } + } } else{ type_out->emit_type = BufferModelUnit_Numbers;