got code wrapping working

This commit is contained in:
Allen Webster 2017-03-25 16:49:54 -04:00
parent 8f8919fd08
commit d94c8c3672
4 changed files with 59 additions and 30 deletions

View File

@ -90,7 +90,7 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){
*length_out = 4; *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; result = 0;
*length_out = 0; *length_out = 0;
} }
@ -167,7 +167,7 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){
}break; }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; result = 0;
length = 0; length = 0;
} }

View File

@ -344,7 +344,7 @@ CUSTOM_COMMAND_SIG(load_project){
if (read_bool){ if (read_bool){
if (config_bool_var(array_item, 0, 0, dest_bool)){ if (config_bool_var(array_item, 0, 0, dest_bool)){
if (dest_bool){ if (*dest_bool){
append(&msg, "true, "); append(&msg, "true, ");
} }
else{ else{

View File

@ -1113,7 +1113,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
end = fixed_end_point; end = fixed_end_point;
} }
i = clamp_top(i, line_start); i = clamp_bottom(i, line_start);
if (i == line_start){ if (i == line_start){
skipping_whitespace = true; skipping_whitespace = true;
@ -1507,9 +1507,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
i32 potential_count = 0; i32 potential_count = 0;
i32 stage = 0; i32 stage = 0;
Translation_State tran = {0};
Translation_Emits emits = {0};
do{ do{
stop = buffer_measure_wrap_y(&state, params, current_line_shift, do_wrap, wrap_unit_end); 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{ else{
Translation_State tran = {0};
Translation_Emits emits = {0};
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
i32 word_stage = 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; step.this_token = wrap_state.token_ptr;
Gap_Buffer_Stream stream = {0}; Gap_Buffer_Stream stream = {0};
Translation_State tran = {0};
Translation_Emits emits = {0};
Potential_Wrap_Indent_Pair potential_wrap = {0}; Potential_Wrap_Indent_Pair potential_wrap = {0};
potential_wrap.wrap_position = i; potential_wrap.wrap_position = i;
@ -1668,10 +1669,16 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
while(still_looping){ while(still_looping){
for (; i < stream.end; ++i){ 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)){ for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
goto doublebreak_stage_vspace; 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); still_looping = buffer_stringify_next(&stream);
@ -1679,19 +1686,29 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
doublebreak_stage_vspace:; doublebreak_stage_vspace:;
do{ do{
i32 pos_end_i = end_i;
while (still_looping){ while (still_looping){
for (; i < stream.end; ++i){ for (; i < stream.end; ++i){
u8 ch = stream.data[i]; {
u8 ch = stream.data[i];
if (char_is_whitespace(ch)){ translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits);
goto doublebreak_stage1;
} }
f32 adv = font_get_glyph_advance(params.system, params.font, ch); for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
x += adv; TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits);
if (!first_word && x > current_width){ if (codepoint_is_whitespace(buffer_step.value)){
emit_comment_position = 1; pos_end_i = buffer_step.i;
goto doublebreak_stage1; 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); still_looping = buffer_stringify_next(&stream);
@ -1700,28 +1717,35 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
first_word = 0; first_word = 0;
if (emit_comment_position){ if (emit_comment_position){
step.position_end = i; step.position_end = pos_end_i;
step.final_x = x; step.final_x = x;
goto finished_comment_split; goto finished_comment_split;
} }
while(still_looping){ while(still_looping){
for (; i < stream.end; ++i){ for (; i < stream.end; ++i){
u8 ch = stream.data[i]; {
u8 ch = stream.data[i];
if (!char_is_whitespace(ch)){ translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits);
goto doublebreak_stage2;
} }
f32 adv = font_get_glyph_advance(params.system, params.font, ch); for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
TRANSLATION_DECL_GET_STEP(buffer_step, behav, J, emits);
x += adv;
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); still_looping = buffer_stringify_next(&stream);
} }
doublebreak_stage2:; doublebreak_stage2:;
potential_wrap.wrap_position = i; potential_wrap.wrap_position = pos_end_i;
potential_wrap.wrap_x = x; potential_wrap.wrap_x = x;
}while(still_looping); }while(still_looping);
} }

View File

@ -143,10 +143,15 @@ translating_select_emit_rule_with_font(System_Functions *system, Render_Font *fo
if (desc.prelim_emit_type == BufferModelUnit_Codepoint){ if (desc.prelim_emit_type == BufferModelUnit_Codepoint){
u32 cp = utf8_to_u32_length_unchecked(tran->fill_buffer, &type_out->codepoint_length); u32 cp = utf8_to_u32_length_unchecked(tran->fill_buffer, &type_out->codepoint_length);
if (type_out->codepoint_length != 0){ if (type_out->codepoint_length != 0){
type_out->codepoint = cp; if ((cp >= nonchar_min && cp <= nonchar_max) || ((cp & 0xFFFF) >= 0xFE)){
if (!font_can_render(system, font, cp)){
type_out->emit_type = BufferModelUnit_Numbers; 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{ else{
type_out->emit_type = BufferModelUnit_Numbers; type_out->emit_type = BufferModelUnit_Numbers;