Got unicode text files working, need to revist code wrapping

This commit is contained in:
Allen Webster 2017-03-24 19:41:10 -04:00
parent 4d46aa8e97
commit fbe5c3ff4f
8 changed files with 118 additions and 60 deletions

View File

@ -53,16 +53,16 @@ static u32_4tech
utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){
u32_4tech result = 0;
if (buffer[0] <= 0x7F){
if (buffer[0] < 0x80){
result = (u32_4tech)buffer[0];
*length_out = 1;
}
else if (buffer[0] <= 0xE0){
else if (buffer[0] < 0xE0){
result = ((u32_4tech)((buffer[0])&0x1F)) << 6;
result |= ((u32_4tech)((buffer[1])&0x3F));
*length_out = 2;
}
else if (buffer[0] <= 0xF0){
else if (buffer[0] < 0xF0){
result = ((u32_4tech)((buffer[0])&0x0F)) << 12;
result |= ((u32_4tech)((buffer[1])&0x3F)) << 6;
result |= ((u32_4tech)((buffer[2])&0x3F));
@ -198,11 +198,11 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *
u32_4tech codepoint = 0;
u32_4tech utf8_size = 0;
if (s[0] <= 0x7F){
if (s[0] < 0x80){
codepoint = (u32_4tech)s[0];
utf8_size = 1;
}
else if (s[0] <= 0xE0){
else if (s[0] < 0xE0){
if (limit <= 1){
*error = true;
break;
@ -212,7 +212,7 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *
codepoint |= ((u32_4tech)((s[1])&0x3F));
utf8_size = 2;
}
else if (s[0] <= 0xF0){
else if (s[0] < 0xF0){
if (limit <= 2){
*error = true;
break;

View File

@ -858,11 +858,11 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
}
S.did_wrap = false;
if (S.i >= S.wrap_unit_end){
if (S.step.i >= S.wrap_unit_end){
S_stop.status = BLStatus_NeedWrapDetermination;
S_stop.line_index = S.line_index - 1;
S_stop.wrap_line_index = S.current_wrap_index;
S_stop.pos = S.i;
S_stop.pos = S.step.i;
S_stop.x = S.x;
DrYield(4, S_stop);
@ -876,7 +876,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
S_stop.status = BLStatus_NeedWrapLineShift;
S_stop.line_index = S.line_index - 1;
S_stop.wrap_line_index = S.current_wrap_index;
S_stop.pos = S.i;
S_stop.pos = S.step.i;
DrYield(3, S_stop);
}
@ -1403,7 +1403,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
// Build the cursor hint
S.next_cursor.pos = params.buffer->line_starts[safe_line_index];
S.next_cursor.character_pos = params.character_starts[safe_line_index];
S.next_cursor.line = line_index + 1;
S.next_cursor.line = safe_line_index + 1;
S.next_cursor.character = 1;
S.next_cursor.wrap_line = params.wrap_line_index[safe_line_index] + 1;
S.next_cursor.unwrapped_y = (f32)(safe_line_index * S.font_height);

View File

@ -1476,9 +1476,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
Buffer_Layout_Stop stop = {0};
f32 edge_tolerance = 50.f;
if (edge_tolerance > width){
edge_tolerance = width;
}
edge_tolerance = clamp_top(edge_tolerance, 50.f);
f32 current_line_shift = 0.f;
b32 do_wrap = 0;
@ -1509,6 +1507,9 @@ 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);
@ -1535,35 +1536,46 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
i32 i = stop.pos;
f32 x = stop.x;
f32 self_x = 0;
i32 wrap_end_result = size;
if (buffer_stringify_loop(&stream, params.buffer, i, size)){
b32 still_looping = 0;
do{
for (; i < stream.end; ++i){
u8 ch = stream.data[i];
{
u8 ch = stream.data[i];
translating_fully_process_byte(system, font, &tran, ch, i, size, &emits);
}
switch (word_stage){
case 0:
{
if (char_is_whitespace(ch)){
word_stage = 1;
}
else{
f32 adv = font_get_glyph_advance(params.system, params.font, ch);
x += adv;
self_x += adv;
if (self_x > width){
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
u32 codepoint = step.value;
switch (word_stage){
case 0:
{
if (codepoint_is_whitespace(codepoint)){
word_stage = 1;
}
else{
f32 adv = font_get_glyph_advance(params.system, params.font, codepoint);
x += adv;
self_x += adv;
if (self_x > width){
wrap_end_result = step.i;
goto doublebreak;
}
}
}break;
case 1:
{
if (!codepoint_is_whitespace(codepoint)){
wrap_end_result = step.i;
goto doublebreak;
}
}
}break;
case 1:
{
if (!char_is_whitespace(ch)){
goto doublebreak;
}
}break;
}break;
}
}
}
still_looping = buffer_stringify_next(&stream);
@ -1571,7 +1583,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
}
doublebreak:;
wrap_unit_end = i;
wrap_unit_end = wrap_end_result;
if (x > width){
do_wrap = 1;
file_allocate_wrap_positions_as_needed(general, file, wrap_position_index);
@ -1608,7 +1620,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
Wrap_Current_Shift current_shift = get_current_shift(&wrap_state, next_line_start);
if (current_shift.adjust_top_to_this){
wrap_state_set_top(&wrap_state, current_shift.shift);
}
@ -1702,7 +1713,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
goto doublebreak_stage2;
}
f32 adv = font_get_glyph_advance(params.system, params.font, ch);
x += adv;

View File

@ -8,6 +8,7 @@ Created 21.01.2017 (dd.mm.yyyy)
#if !defined(FTECH_DEFINES)
#define FTECH_DEFINES
#include <stdint.h>
typedef int8_t i8;
@ -23,7 +24,6 @@ typedef uint64_t u64;
typedef i8 b8;
typedef i32 b32;
// TODO(allen): Find a real way to detect 32 bit ness.
#if defined(FTECH_32_BIT)
typedef u32 umem;
typedef i32 imem;

View File

@ -164,6 +164,10 @@ build_cl(u32 flags, char *code_path, char *code_file, char *out_path, char *out_
build_ap(line, CL_OPTS);
}
if (flags & X86){
build_ap(line, "/DFTECH_32_BIT");
}
if (flags & INCLUDES){
build_ap(line, CL_INCLUDES);
}

View File

@ -1,5 +1,5 @@
1
0
68
69

Binary file not shown.

View File

@ -16,7 +16,7 @@
struct Win32_Fonts{
Partition part;
Render_Font fonts[5];
Render_Font fonts[32];
u32 font_count;
};
@ -87,6 +87,9 @@ Sys_Font_Free_Sig(system_font_free){
internal
Sys_Font_Init_Sig(system_font_init){
Partition *scratch = &shared_vars.scratch;
Temp_Memory temp = begin_temp_memory(scratch);
font->get_count = system_font_get_count;
font->get_ids_by_index = system_font_get_ids_by_index;
font->get_name_by_index = system_font_get_name_by_index;
@ -98,36 +101,77 @@ Sys_Font_Init_Sig(system_font_init){
font_size = clamp_bottom(8, font_size);
struct Font_Setup{
struct TEST_DATA{
char *c_filename;
i32 filename_len;
char *c_name;
i32 name_len;
u32 pt_size;
};
Font_Setup font_setup[] = {
{literal("LiberationSans-Regular.ttf"), literal("Liberation Sans"), font_size},
{literal("liberation-mono.ttf"), literal("Liberation Mono"), font_size},
{literal("Hack-Regular.ttf"), literal("Hack"), font_size},
{literal("CutiveMono-Regular.ttf"), literal("Cutive Mono"), font_size},
{literal("Inconsolata-Regular.ttf"), literal("Inconsolata"), font_size},
TEST_DATA TEST_SETUP[] = {
{literal("fonts/LiberationSans-Regular.ttf"), literal("Liberation Sans"), },
{literal("fonts/liberation-mono.ttf"), literal("Liberation Mono"), },
{literal("fonts/Hack-Regular.ttf"), literal("Hack"), },
{literal("fonts/CutiveMono-Regular.ttf"), literal("Cutive Mono"), },
{literal("fonts/Inconsolata-Regular.ttf"), literal("Inconsolata"), },
};
u32 font_count = Min(ArrayCount(win32_fonts.fonts), ArrayCount(font_setup));
for (u32 i = 0; i < font_count; ++i){
String filename = make_string(font_setup[i].c_filename, font_setup[i].filename_len);
String name = make_string(font_setup[i].c_name, font_setup[i].name_len);
u32 pt_size = font_setup[i].pt_size;
Render_Font *render_font = &win32_fonts.fonts[i];
struct Font_Setup{
Font_Setup *next_font;
char *c_filename;
char *c_name;
i32 filename_len;
i32 name_len;
};
Font_Setup *first_setup = 0;
Font_Setup *head_setup = 0;
u32 TEST_COUNT = ArrayCount(TEST_SETUP);
for (u32 i = 0; i < TEST_COUNT; ++i){
if (first_setup == 0){
head_setup = push_struct(scratch, Font_Setup);
first_setup = head_setup;
}
else{
head_setup->next_font = push_struct(scratch, Font_Setup);
head_setup = head_setup->next_font;
}
char full_filename_space[256];
String full_filename = make_fixed_width_string(full_filename_space);
sysshared_to_binary_path(&full_filename, filename.str);
TEST_DATA *TEST = &TEST_SETUP[i];
system_set_font(&win32vars.system, &win32_fonts.part, render_font, full_filename, name, pt_size, use_hinting);
head_setup->c_filename = push_array(scratch, char, TEST->filename_len+1);
memcpy(head_setup->c_filename, TEST->c_filename, TEST->filename_len+1);
head_setup->filename_len = TEST->filename_len;
head_setup->c_name = push_array(scratch, char, TEST->name_len+1);
memcpy(head_setup->c_name, TEST->c_name, TEST->name_len+1);
head_setup->name_len = TEST->name_len;
partition_align(scratch, 8);
}
win32_fonts.font_count = font_count;
u32 font_count_max = ArrayCount(win32_fonts.fonts);
u32 font_count = 0;
u32 i = 0;
for (Font_Setup *ptr = first_setup; ptr != 0; ptr = ptr->next_font, ++i){
if (i < font_count_max){
String filename = make_string(ptr->c_filename, ptr->filename_len);
String name = make_string(ptr->c_name, ptr->name_len);
Render_Font *render_font = &win32_fonts.fonts[i];
char full_filename_space[256];
String full_filename = make_fixed_width_string(full_filename_space);
sysshared_to_binary_path(&full_filename, filename.str);
system_set_font(&win32vars.system, &win32_fonts.part, render_font, full_filename, name, font_size, use_hinting);
}
++font_count;
}
win32_fonts.font_count = clamp_top(font_count, font_count_max);
end_temp_memory(temp);
}
// BOTTOM