From 12c8b920d264d8777a4b0016e6bedd1d78416802 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 13 Mar 2017 19:48:11 -0400 Subject: [PATCH] setup the page loading on request, setup the rendering with the new system, still fixing bugs --- 4coder_lib/4coder_string.h | 289 +++++++++++++++----------- 4ed.cpp | 68 ------ 4ed.h | 7 +- 4ed_app_models.h | 1 + 4ed_file_view.cpp | 156 ++++++-------- 4ed_math.h | 51 +---- 4ed_rendering_helper.cpp | 43 ++-- 4ed_system_shared.cpp | 116 +++++++---- file/4coder_buffer.cpp | 72 +++---- file/4coder_translation.cpp | 11 +- font/4coder_font_data.h | 6 +- font/4coder_font_interface.h | 13 +- font/4coder_font_interface_to_os.h | 24 +++ font/4coder_font_static_functions.cpp | 40 +++- linux_4ed.cpp | 17 +- string/4coder_string_build_num.txt | 2 +- string/_4coder_string.ctm | Bin 2580 -> 2724 bytes string/internal_4coder_string.cpp | 46 +++- win32_4ed.cpp | 39 ++-- win32_4ed_fonts.cpp | 97 ++++++++- win32_gl.h | 1 + 21 files changed, 585 insertions(+), 514 deletions(-) create mode 100644 font/4coder_font_interface_to_os.h diff --git a/4coder_lib/4coder_string.h b/4coder_lib/4coder_string.h index 38a8272c..c126ca17 100644 --- a/4coder_lib/4coder_string.h +++ b/4coder_lib/4coder_string.h @@ -1,5 +1,5 @@ /* -4coder_string.h - Version 1.0.59 +4coder_string.h - Version 1.0.66 no warranty implied; use at your own risk This software is in the public domain. Where that dedication is not @@ -142,8 +142,10 @@ FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String see FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src); FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src); FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src); +FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src); FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src); FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src); +FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src); FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src); FSTRING_INLINE void copy_ss(String *dest, String src); FSTRING_INLINE void copy_sc(String *dest, char *src); @@ -246,8 +248,10 @@ FSTRING_INLINE b32_4tech has_substr_insensitive(String s, String seek) FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} FSTRING_LINK b32_4tech copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} +FSTRING_LINK b32_4tech copy_checked(char *dest, i32_4tech dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} FSTRING_LINK b32_4tech copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} FSTRING_LINK b32_4tech copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} +FSTRING_LINK b32_4tech copy_partial(char *dest, i32_4tech dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} FSTRING_INLINE i32_4tech copy(char *dest, char *src){return(copy_cc(dest,src));} FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} @@ -281,7 +285,7 @@ FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech ite // #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_slash(char c) { return (c == '\\' || c == '/'); @@ -289,7 +293,7 @@ char_is_slash(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_upper(char c) { return (c >= 'A' && c <= 'Z'); @@ -297,7 +301,7 @@ char_is_upper(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_lower(char c) { return (c >= 'a' && c <= 'z'); @@ -305,7 +309,7 @@ char_is_lower(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE char + FSTRING_INLINE char char_to_upper(char c) { return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; @@ -313,7 +317,7 @@ char_to_upper(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE char + FSTRING_INLINE char char_to_lower(char c) { return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; @@ -321,7 +325,7 @@ char_to_lower(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_whitespace(char c) { return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); @@ -329,7 +333,7 @@ char_is_whitespace(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); @@ -337,7 +341,7 @@ char_is_alpha_numeric(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); @@ -345,7 +349,7 @@ char_is_alpha_numeric_true(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_alpha(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_'); @@ -353,7 +357,7 @@ char_is_alpha(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_alpha_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); @@ -361,7 +365,7 @@ char_is_alpha_true(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_hex(char c) { return (c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f'); @@ -369,7 +373,7 @@ char_is_hex(char c) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech char_is_numeric(char c) { return (c >= '0' && c <= '9'); @@ -383,7 +387,7 @@ char_is_numeric(char c) #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ String result; result.str = (char*)str; @@ -394,7 +398,7 @@ make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String make_string(void *str, i32_4tech size){ String result; result.str = (char*)str; @@ -405,7 +409,7 @@ make_string(void *str, i32_4tech size){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech str_size(char *str) { i32_4tech i = 0; @@ -415,7 +419,7 @@ str_size(char *str) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String make_string_slowly(void *str) { String result; @@ -428,7 +432,7 @@ make_string_slowly(void *str) #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String substr_tail(String str, i32_4tech start) { String result; @@ -440,7 +444,7 @@ substr_tail(String str, i32_4tech start) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size) { String result; @@ -455,7 +459,7 @@ substr(String str, i32_4tech start, i32_4tech size) #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String skip_whitespace(String str) { String result = {0}; @@ -468,7 +472,7 @@ skip_whitespace(String str) #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length) { String result = {0}; @@ -481,7 +485,7 @@ skip_whitespace_measure(String str, i32_4tech *skip_length) #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String chop_whitespace(String str) { String result = {0}; @@ -493,7 +497,7 @@ chop_whitespace(String str) #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String skip_chop_whitespace(String str) { str = skip_whitespace(str); @@ -504,7 +508,7 @@ skip_chop_whitespace(String str) #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length) { str = skip_whitespace_measure(str, skip_length); @@ -514,7 +518,7 @@ skip_chop_whitespace_measure(String str, i32_4tech *skip_length) #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String tailstr(String str) { String result; @@ -532,7 +536,7 @@ tailstr(String str) #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_cc(char *a, char *b){ for (i32_4tech i = 0;; ++i){ if (a[i] != b[i]){ @@ -547,7 +551,7 @@ match_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_sc(String a, char *b){ i32_4tech i = 0; for (; i < a.size; ++i){ @@ -564,7 +568,7 @@ match_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech match_cs(char *a, String b){ return(match_sc(b,a)); } @@ -572,7 +576,7 @@ match_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_ss(String a, String b){ if (a.size != b.size){ return 0; @@ -588,7 +592,7 @@ match_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len){ i32_4tech i; for (i = 0; b[i] != 0; ++i){ @@ -603,7 +607,7 @@ match_part_ccl(char *a, char *b, i32_4tech *len){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len){ i32_4tech i; for (i = 0; b[i] != 0; ++i){ @@ -618,7 +622,7 @@ match_part_scl(String a, char *b, i32_4tech *len){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b){ i32_4tech x; return match_part_ccl(a,b,&x); @@ -627,7 +631,7 @@ match_part_cc(char *a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech match_part_sc(String a, char *b){ i32_4tech x; return match_part_scl(a,b,&x); @@ -636,7 +640,7 @@ match_part_sc(String a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_cs(char *a, String b){ for (i32_4tech i = 0; i != b.size; ++i){ if (a[i] != b.str[i]){ @@ -649,7 +653,7 @@ match_part_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_ss(String a, String b){ if (a.size < b.size){ return 0; @@ -665,7 +669,7 @@ match_part_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b){ for (i32_4tech i = 0;; ++i){ if (char_to_upper(a[i]) != @@ -681,7 +685,7 @@ match_insensitive_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b){ i32_4tech i = 0; for (; i < a.size; ++i){ @@ -699,7 +703,7 @@ match_insensitive_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b){ return match_insensitive_sc(b,a); } @@ -707,7 +711,7 @@ match_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b){ if (a.size != b.size){ return 0; @@ -724,7 +728,7 @@ match_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ i32_4tech i; for (i = 0; b[i] != 0; ++i){ @@ -739,7 +743,7 @@ match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len){ i32_4tech i; for (i = 0; b[i] != 0; ++i){ @@ -755,7 +759,7 @@ match_part_insensitive_scl(String a, char *b, i32_4tech *len){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b){ i32_4tech x; return match_part_insensitive_ccl(a,b,&x); @@ -764,7 +768,7 @@ match_part_insensitive_cc(char *a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b){ i32_4tech x; return match_part_insensitive_scl(a,b,&x); @@ -773,7 +777,7 @@ match_part_insensitive_sc(String a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b){ for (i32_4tech i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ @@ -786,7 +790,7 @@ match_part_insensitive_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b){ if (a.size < b.size){ return(0); @@ -802,7 +806,7 @@ match_part_insensitive_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech compare_cc(char *a, char *b){ i32_4tech i = 0, r = 0; while (a[i] == b[i] && a[i] != 0){ @@ -815,7 +819,7 @@ compare_cc(char *a, char *b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech compare_sc(String a, char *b){ i32_4tech i = 0, r = 0; while (i < a.size && a.str[i] == b[i]){ @@ -838,7 +842,7 @@ compare_sc(String a, char *b){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE i32_4tech + FSTRING_INLINE i32_4tech compare_cs(char *a, String b){ i32_4tech r = -compare_sc(b,a); return(r); @@ -847,7 +851,7 @@ compare_cs(char *a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech compare_ss(String a, String b){ i32_4tech i = 0, r = 0; i32_4tech m = a.size; @@ -875,7 +879,7 @@ compare_ss(String a, String b){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character){ i32_4tech i = start; while (str[i] != character && str[i] != 0) ++i; @@ -885,7 +889,7 @@ find_c_char(char *str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character){ i32_4tech i = start; while (i < str.size && str.str[i] != character) ++i; @@ -895,7 +899,7 @@ find_s_char(String str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character){ i32_4tech i = start; while (i >= 0 && str.str[i] != character) --i; @@ -905,7 +909,7 @@ rfind_s_char(String str, i32_4tech start, char character){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters){ i32_4tech i = start, j; while (str[i] != 0){ @@ -922,7 +926,7 @@ find_c_chars(char *str, i32_4tech start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters){ i32_4tech i = start, j; while (i < str.size){ @@ -939,7 +943,7 @@ find_s_chars(String str, i32_4tech start, char *characters){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek){ i32_4tech i, j, k; b32_4tech hit; @@ -968,7 +972,7 @@ find_substr_c(char *str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek){ i32_4tech stop_at, i, j, k; b32_4tech hit; @@ -997,7 +1001,7 @@ find_substr_s(String str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek){ i32_4tech i, j, k; b32_4tech hit; @@ -1028,17 +1032,20 @@ rfind_substr_s(String str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek){ i32_4tech i, j, k; b32_4tech hit; char a_upper, b_upper; + char first_test_char; if (seek.size == 0){ return str_size(str); } + first_test_char = char_to_upper(seek.str[0]); for (i = start; str[i]; ++i){ - if (str[i] == seek.str[0]){ + a_upper = char_to_upper(str[i]); + if (a_upper == first_test_char){ hit = 1; for (j = 1, k = i+1; j < seek.size; ++j, ++k){ a_upper = char_to_upper(str[k]); @@ -1059,19 +1066,22 @@ find_substr_insensitive_c(char *str, i32_4tech start, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek){ i32_4tech i, j, k; i32_4tech stop_at; b32_4tech hit; char a_upper, b_upper; + char first_test_char; if (seek.size == 0){ return str.size; } stop_at = str.size - seek.size + 1; + first_test_char = char_to_upper(seek.str[0]); for (i = start; i < stop_at; ++i){ - if (str.str[i] == seek.str[0]){ + a_upper = char_to_upper(str.str[i]); + if (a_upper == first_test_char){ hit = 1; for (j = 1, k = i+1; j < seek.size; ++j, ++k){ a_upper = char_to_upper(str.str[k]); @@ -1092,7 +1102,7 @@ find_substr_insensitive_s(String str, i32_4tech start, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek){ return (s[find_substr_c(s, 0, seek)] != 0); } @@ -1100,7 +1110,7 @@ has_substr_c(char *s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech has_substr_s(String s, String seek){ return (find_substr_s(s, 0, seek) < s.size); } @@ -1108,7 +1118,7 @@ has_substr_s(String s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek){ return (s[find_substr_insensitive_c(s, 0, seek)] != 0); } @@ -1116,7 +1126,7 @@ has_substr_insensitive_c(char *s, String seek){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek){ return (find_substr_insensitive_s(s, 0, seek) < s.size); } @@ -1128,7 +1138,7 @@ has_substr_insensitive_s(String s, String seek){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src){ char *start = dest; while (*src != 0){ @@ -1142,7 +1152,7 @@ copy_fast_unsafe_cc(char *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src){ i32_4tech i = 0; while (i != src.size){ @@ -1155,7 +1165,7 @@ copy_fast_unsafe_cs(char *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src){ char *dest_str; i32_4tech i; @@ -1173,7 +1183,22 @@ copy_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech +copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ + i32_4tech i; + if (dest_cap < src.size){ + return 0; + } + for (i = 0; i < src.size; ++i){ + dest[i] = src.str[i]; + } + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src){ i32_4tech i = 0; i32_4tech memory_size = dest->memory_size; @@ -1192,7 +1217,7 @@ copy_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src){ char *dest_str = dest->str; i32_4tech memory_size = dest->memory_size; @@ -1205,13 +1230,31 @@ copy_partial_ss(String *dest, String src){ dest_str[i] = src.str[i]; } dest->size = memory_size; - return result; + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ + b32_4tech result = 0; + i32_4tech copy_size = dest_cap; + i32_4tech i; + if (dest_cap >= src.size){ + result = 1; + copy_size = src.size; + } + for (i = 0; i < copy_size; ++i){ + dest[i] = src.str[i]; + } + return(result); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE i32_4tech + FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src){ return copy_fast_unsafe_cc(dest, src); } @@ -1219,7 +1262,7 @@ copy_cc(char *dest, char *src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE void + FSTRING_INLINE void copy_ss(String *dest, String src){ copy_checked_ss(dest, src); } @@ -1227,7 +1270,7 @@ copy_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE void + FSTRING_INLINE void copy_sc(String *dest, char *src){ copy_partial_sc(dest, src); } @@ -1235,7 +1278,7 @@ copy_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src){ String end; end = tailstr(*dest); @@ -1249,7 +1292,7 @@ append_checked_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src){ String end = tailstr(*dest); b32_4tech result = copy_partial_sc(&end, src); @@ -1260,7 +1303,7 @@ append_partial_sc(String *dest, char *src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src){ String end = tailstr(*dest); b32_4tech result = copy_partial_ss(&end, src); @@ -1271,7 +1314,7 @@ append_partial_ss(String *dest, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_s_char(String *dest, char c){ b32_4tech result = 0; if (dest->size < dest->memory_size){ @@ -1284,7 +1327,7 @@ append_s_char(String *dest, char c){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech append_ss(String *dest, String src){ return append_partial_ss(dest, src); } @@ -1292,14 +1335,14 @@ append_ss(String *dest, String src){ #if !defined(FSTRING_GUARD) -FSTRING_INLINE b32_4tech + FSTRING_INLINE b32_4tech append_sc(String *dest, char *src){ return append_partial_sc(dest, src); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech terminate_with_null(String *str){ b32_4tech result = 0; if (str->size < str->memory_size){ @@ -1311,7 +1354,7 @@ terminate_with_null(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size){ b32_4tech result = 1; i32_4tech offset = target_size - dest->size; @@ -1334,7 +1377,7 @@ append_padding(String *dest, char c, i32_4tech target_size){ // #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void replace_char(String *str, char replace, char with){ char *s = str->str; i32_4tech i = 0; @@ -1346,7 +1389,7 @@ replace_char(String *str, char replace, char with){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_lower_cc(char *src, char *dst){ for (; *src != 0; ++src){ *dst++ = char_to_lower(*src); @@ -1357,7 +1400,7 @@ to_lower_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_lower_ss(String *dst, String src){ i32_4tech i = 0; i32_4tech size = src.size; @@ -1375,7 +1418,7 @@ to_lower_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_lower_s(String *str){ i32_4tech i = 0; i32_4tech size = str->size; @@ -1388,7 +1431,7 @@ to_lower_s(String *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_upper_cc(char *src, char *dst){ for (; *src != 0; ++src){ *dst++ = char_to_upper(*src); @@ -1399,7 +1442,7 @@ to_upper_cc(char *src, char *dst){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_upper_ss(String *dst, String src){ i32_4tech i = 0; i32_4tech size = src.size; @@ -1417,7 +1460,7 @@ to_upper_ss(String *dst, String src){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_upper_s(String *str){ i32_4tech i = 0; i32_4tech size = str->size; @@ -1430,7 +1473,7 @@ to_upper_s(String *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK void + FSTRING_LINK void to_camel_cc(char *src, char *dst){ char *c, ch; i32_4tech is_first = 1; @@ -1460,7 +1503,7 @@ to_camel_cc(char *src, char *dst){ // #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x){ i32_4tech size = 1; if (x < 0){ @@ -1476,7 +1519,7 @@ int_to_str_size(i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x){ b32_4tech result = 1; char *str = dest->str; @@ -1523,7 +1566,7 @@ int_to_str(String *dest, i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x){ String last_part = tailstr(*dest); b32_4tech result = int_to_str(&last_part, x); @@ -1535,7 +1578,7 @@ append_int_to_str(String *dest, i32_4tech x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x){ i32_4tech size; if (x < 0){ @@ -1554,7 +1597,7 @@ u64_to_str_size(uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x){ b32_4tech result = 1; char *str = dest->str; @@ -1593,7 +1636,7 @@ u64_to_str(String *dest, uint64_t x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x){ String last_part = tailstr(*dest); b32_4tech result = u64_to_str(&last_part, x); @@ -1628,7 +1671,7 @@ get_float_vars(float x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech float_to_str_size(float x){ Float_To_Str_Variables vars = get_float_vars(x); i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); @@ -1637,7 +1680,7 @@ float_to_str_size(float x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x){ b32_4tech result = 1; Float_To_Str_Variables vars = get_float_vars(x); @@ -1655,7 +1698,7 @@ append_float_to_str(String *dest, float x){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech float_to_str(String *dest, float x){ b32_4tech result = 1; dest->size = 0; @@ -1666,7 +1709,7 @@ float_to_str(String *dest, float x){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech str_is_int_c(char *str){ b32_4tech result = 1; for (; *str; ++str){ @@ -1681,7 +1724,7 @@ str_is_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech str_is_int_s(String str){ b32_4tech result = 1; for (i32_4tech i = 0; i < str.size; ++i){ @@ -1696,7 +1739,7 @@ str_is_int_s(String str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech str_to_int_c(char *str){ i32_4tech x = 0; for (; *str; ++str){ @@ -1715,7 +1758,7 @@ str_to_int_c(char *str){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech str_to_int_s(String str){ i32_4tech x, i; if (str.size == 0){ @@ -1733,7 +1776,7 @@ str_to_int_s(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech hexchar_to_int(char c){ i32_4tech x = 0; if (c >= '0' && c <= '9'){ @@ -1750,14 +1793,14 @@ hexchar_to_int(char c){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK char + FSTRING_LINK char int_to_hexchar(i32_4tech x){ return (x<10)?((char)x+'0'):((char)x+'a'-10); } #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK u32_4tech + FSTRING_LINK u32_4tech hexstr_to_int(String str){ u32_4tech x; i32_4tech i; @@ -1776,7 +1819,7 @@ hexstr_to_int(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color){ b32_4tech result = 0; i32_4tech i; @@ -1805,7 +1848,7 @@ color_to_hexstr(String *s, u32_4tech color){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out){ b32_4tech result = 0; u32_4tech color = 0; @@ -1830,7 +1873,7 @@ hexstr_to_color(String s, u32_4tech *out){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK i32_4tech + FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos){ i32_4tech i = str.size - 1 - pos; while (i >= 0 && !char_is_slash(str.str[i])){ @@ -1841,21 +1884,21 @@ reverse_seek_slash_pos(String str, i32_4tech pos){ #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE i32_4tech + FSTRING_INLINE i32_4tech reverse_seek_slash(String str){ return(reverse_seek_slash_pos(str, 0)); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String front_of_directory(String dir){ return substr_tail(dir, reverse_seek_slash(dir) + 1); } #endif #if !defined(FSTRING_GUARD) -FSTRING_INLINE String + FSTRING_INLINE String path_of_directory(String dir){ return substr(dir, 0, reverse_seek_slash(dir) + 1); } @@ -1863,7 +1906,7 @@ path_of_directory(String dir){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash){ b32_4tech result = 0; i32_4tech size = reverse_seek_slash(*dir) + 1; @@ -1882,7 +1925,7 @@ set_last_folder_sc(String *dir, char *folder_name, char slash){ #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash){ b32_4tech result = 0; i32_4tech size = reverse_seek_slash(*dir) + 1; @@ -1900,7 +1943,7 @@ set_last_folder_ss(String *dir, String folder_name, char slash){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String file_extension(String str){ i32_4tech i; for (i = str.size - 1; i >= 0; --i){ @@ -1912,7 +1955,7 @@ file_extension(String str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech remove_extension(String *str){ b32_4tech result = 0; i32_4tech i; @@ -1928,7 +1971,7 @@ remove_extension(String *str){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech remove_last_folder(String *str){ b32_4tech result = 0; i32_4tech end = reverse_seek_slash_pos(*str, 1); @@ -1943,7 +1986,7 @@ remove_last_folder(String *str){ // TODO(allen): Add hash-table extension to string sets. #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){ b32_4tech result = 0; i32_4tech i = 0; @@ -1960,7 +2003,7 @@ string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, Stri #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK b32_4tech + FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index){ b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index); return(result); @@ -1968,7 +2011,7 @@ string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String get_first_double_line(String source){ String line = {0}; i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); @@ -1982,7 +2025,7 @@ get_first_double_line(String source){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String get_next_double_line(String source, String line){ String next = {0}; i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size; @@ -2007,7 +2050,7 @@ get_next_double_line(String source, String line){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String get_next_word(String source, String prev_word){ String word = {0}; @@ -2038,7 +2081,7 @@ get_next_word(String source, String prev_word){ #endif #if defined(FSTRING_IMPLEMENTATION) -FSTRING_LINK String + FSTRING_LINK String get_first_word(String source){ String start_str = make_string(source.str, 0); String word = get_next_word(source, start_str); diff --git a/4ed.cpp b/4ed.cpp index 6bd4792a..acccbf6f 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -962,7 +962,6 @@ enum Command_Line_Action{ CLAct_WindowStreamMode, CLAct_FontSize, CLAct_FontStartHinting, - CLAct_FontCustom, CLAct_Count }; @@ -1010,8 +1009,6 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, case 'u': action = CLAct_UserFile; strict = 0; break; case 'U': action = CLAct_UserFile; strict = 1; break; - case 'c': action = CLAct_FontCustom; break; - case 'd': action = CLAct_CustomDLL; strict = 0; break; case 'D': action = CLAct_CustomDLL; strict = 1; break; @@ -1115,16 +1112,6 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings, action = CLAct_Nothing; }break; - case CLAct_FontCustom: - { - if ((i + 3) <= clparams.argc){ - settings->custom_font_file = clparams.argv[i++]; - settings->custom_font_name = clparams.argv[i++]; - settings->custom_font_size = str_to_int_c(clparams.argv[i]); - } - action = CLAct_Nothing; - }break; - case CLAct_FontStartHinting: { plat_settings->use_hinting = 1; @@ -1158,8 +1145,6 @@ app_setup_memory(System_Functions *system, Application_Memory *memory){ return(vars); } -static App_Settings null_app_settings = {0}; - App_Read_Command_Line_Sig(app_read_command_line){ i32 out_size = 0; App_Vars *vars = app_setup_memory(system, memory); @@ -1452,59 +1437,6 @@ App_Init_Sig(app_init){ setup_ui_commands(&models->map_ui, &models->mem.part, global_map); } -#if 0 - // NOTE(allen): font setup - { - models->font_set = &target->font_set; - - struct Font_Setup{ - char *c_file_name; - i32 file_name_len; - char *c_name; - i32 name_len; - i32 pt_size; - }; - - i32 font_size = models->settings.font_size; - - char *custom_font_file = models->settings.custom_font_file; - char *custom_font_name = models->settings.custom_font_name; - i32 custom_font_size = models->settings.custom_font_size; - b32 use_custom_font = true; - if (custom_font_file == 0){ - use_custom_font = false; - custom_font_file = ""; - custom_font_name = ""; - } - - font_size = clamp_bottom(8, font_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}, - {custom_font_file, str_size(custom_font_file), - custom_font_name, str_size(custom_font_name), - custom_font_size}, - }; - i32 font_count = ArrayCount(font_setup); - if (!use_custom_font){ - --font_count; - } - - font_set_init(models->font_set, partition, 16, 6); - - for (i32 i = 0; i < font_count; ++i){ - String file_name = make_string(font_setup[i].c_file_name, font_setup[i].file_name_len); - String name = make_string(font_setup[i].c_name, font_setup[i].name_len); - i32 pt_size = font_setup[i].pt_size; - font_set_add(models->font_set, file_name, name, pt_size); - } - } -#endif - // NOTE(allen): file setup working_set_init(&models->working_set, partition, &vars->models.mem.general); models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH; diff --git a/4ed.h b/4ed.h index 71a08546..ece63443 100644 --- a/4ed.h +++ b/4ed.h @@ -64,12 +64,7 @@ typedef struct Plat_Settings{ } Plat_Settings; #define App_Read_Command_Line_Sig(name) \ -i32 name(System_Functions *system, \ -Application_Memory *memory, \ -String current_directory, \ -Plat_Settings *plat_settings, \ -char ***files, i32 **file_count, \ -Command_Line_Parameters clparams) +i32 name(System_Functions *system, Application_Memory *memory, String current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, Command_Line_Parameters clparams) typedef App_Read_Command_Line_Sig(App_Read_Command_Line); diff --git a/4ed_app_models.h b/4ed_app_models.h index 5b83fe6b..d1b3ceda 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -29,6 +29,7 @@ struct App_Settings{ i32 custom_arg_start; i32 custom_arg_end; }; +global_const App_Settings null_app_settings = {0}; struct Debug_Input_Event{ Key_Code key; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index eecc6a4d..9a6a5181 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1015,7 +1015,7 @@ struct Code_Wrap_State{ }; internal void -wrap_state_init(Code_Wrap_State *state, Editing_File *file, Render_Font *font){ +wrap_state_init(System_Functions *system, Code_Wrap_State *state, Editing_File *file, Render_Font *font){ state->token_array = file->state.token_array; state->token_ptr = state->token_array.tokens; state->end_token = state->token_ptr + state->token_array.count; @@ -1031,10 +1031,7 @@ wrap_state_init(Code_Wrap_State *state, Editing_File *file, Render_Font *font){ state->font = font; -#if 0 - state->tab_indent_amount = get_codepoint_advance(font, '\t'); -#endif - state->tab_indent_amount = 2.f; + state->tab_indent_amount = font_get_glyph_advance(system, font, '\t'); state->byte_advance = font_get_byte_advance(font); state->tran = null_buffer_translating_state; @@ -1146,10 +1143,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_ u32 n = state->step.value; f32 adv = 0; if (state->behavior.do_codepoint_advance){ -#if 0 - adv = get_codepoint_advance(state->font, n); -#endif - adv = 2.f; + adv = font_get_glyph_advance(system, state->font, n); if (n != ' ' && n != '\t'){ skipping_whitespace = false; @@ -1406,14 +1400,12 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start, b32 *adjust_ if (wrap_state->wrap_x.paren_safe_top != 0 && prev_token.type == CPP_TOKEN_PARENTHESE_OPEN){ current_shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top-1] + wrap_state->tab_indent_amount; - *adjust_top_to_this = 1; } f32 statement_continuation_indent = 0.f; if (current_shift != 0.f && wrap_state->wrap_x.paren_safe_top == 0){ - if (!(prev_token.flags & CPP_TFLAG_PP_BODY) && !(prev_token.flags & CPP_TFLAG_PP_DIRECTIVE)){ - + if (!(prev_token.flags & (CPP_TFLAG_PP_DIRECTIVE|CPP_TFLAG_PP_BODY))){ switch (prev_token.type){ case CPP_TOKEN_BRACKET_OPEN: case CPP_TOKEN_BRACE_OPEN: @@ -1499,7 +1491,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, i32 max_wrap_indent_mark = 0; if (params.virtual_white && file->state.tokens_complete && !file->state.still_lexing){ - wrap_state_init(&wrap_state, file, font); + wrap_state_init(system, &wrap_state, file, font); use_tokens = 1; potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width)); @@ -1551,10 +1543,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, word_stage = 1; } else{ -#if 0 - f32 adv = get_codepoint_advance(params.font, ch); -#endif - f32 adv = 2.f; + f32 adv = font_get_glyph_advance(params.system, params.font, ch); x += adv; self_x += adv; @@ -1682,11 +1671,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, goto doublebreak_stage1; } -#if 0 - f32 adv = get_codepoint_advance(params.font, ch); -#endif - f32 adv = 2.f; - + f32 adv = font_get_glyph_advance(params.system, params.font, ch); x += adv; if (!first_word && x > current_width){ emit_comment_position = 1; @@ -1713,10 +1698,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } -#if 0 - f32 adv = get_codepoint_advance(params.font, ch); -#endif - f32 adv = 2.f; + f32 adv = font_get_glyph_advance(params.system, params.font, ch); x += adv; } @@ -1978,7 +1960,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File * Font_ID font_id = models->global_font_id; file->settings.font_id = font_id; - Render_Font *font = 0; + Render_Font *font = system->font.get_render_data_by_id(font_id); file_measure_starts(general, &file->state.buffer); @@ -3243,8 +3225,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file Assert(scratch_size > 0); i32 request_amount = 0; Assert(end <= buffer_size(&file->state.buffer)); - while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, - part->base + part->pos, scratch_size, &request_amount)){ + while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount, part->base + part->pos, scratch_size, &request_amount)){ void *new_data = 0; if (request_amount > 0){ new_data = general_memory_allocate(general, request_amount); @@ -3273,8 +3254,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len); i32 line_shift = new_line_count - replaced_line_count; - //Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; - Render_Font *font = 0; + Render_Font *font = system->font.get_render_data_by_id(file->settings.font_id); file_grow_starts_as_needed(general, buffer, line_shift); buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount); @@ -3396,8 +3376,7 @@ file_do_batch_edit(System_Functions *system, Models *models, Editing_File *file, Buffer_Measure_Starts measure_state = {}; buffer_measure_starts(&measure_state, &file->state.buffer); - //Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font; - Render_Font *font = 0; + Render_Font *font = system->font.get_render_data_by_id(file->settings.font_id); // TODO(allen): write the remeasurement version file_allocate_character_starts_as_needed(&models->mem.general, file); @@ -3682,9 +3661,7 @@ style_get_color(Style *style, Cpp_Token token){ internal void file_set_font(System_Functions *system, Models *models, Editing_File *file, Font_ID font_id){ file->settings.font_id = font_id; - //Font_Info *font_info = get_font_info(models->font_set, file->settings.font_id); - //Render_Font *font = font_info->font; - Render_Font *font = 0; + Render_Font *font = system->font.get_render_data_by_id(font_id); file_measure_wraps_and_fix_cursor(system, models, file, font); Editing_Layout *layout = &models->layout; @@ -4148,9 +4125,9 @@ struct File_Bar{ }; internal void -intbar_draw_string(Render_Target *target, File_Bar *bar, String str, u32 char_color){ - draw_string(target, bar->font_id, str, (i32)(bar->pos_x + bar->text_shift_x), (i32)(bar->pos_y + bar->text_shift_y), char_color); - bar->pos_x += font_string_width(target, bar->font_id, str); +intbar_draw_string(System_Functions *system, Render_Target *target, File_Bar *bar, String str, u32 char_color){ + draw_string(system, target, bar->font_id, str, (i32)(bar->pos_x + bar->text_shift_x), (i32)(bar->pos_y + bar->text_shift_y), char_color); + bar->pos_x += font_string_width(system, target, bar->font_id, str); } internal GUI_Scroll_Vars @@ -5938,8 +5915,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act Buffer_Render_Item *items = push_array(part, Buffer_Render_Item, max); Font_ID font_id = file->settings.font_id; - //Render_Font *font = get_font_info(models->font_set, font_id)->font; - Render_Font *font = 0; + Render_Font *font = system->font.get_render_data_by_id(font_id); f32 scroll_x = view->edit_pos->scroll.scroll_x; f32 scroll_y = view->edit_pos->scroll.scroll_y; @@ -6145,7 +6121,7 @@ draw_file_loaded(System_Functions *system, View *view, i32_Rect rect, b32 is_act } internal void -draw_text_field(Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String p, String t){ +draw_text_field(System_Functions *system, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String p, String t){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6158,13 +6134,13 @@ draw_text_field(Render_Target *target, View *view, Font_ID font_id, i32_Rect rec if (target){ draw_rectangle(target, rect, back_color); - x = ceil32(draw_string(target, font_id, p, x, y, text2_color)); - draw_string(target, font_id, t, x, y, text1_color); + x = ceil32(draw_string(system, target, font_id, p, x, y, text2_color)); + draw_string(system, target, font_id, t, x, y, text1_color); } } internal void -draw_text_with_cursor(Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String s, i32 pos){ +draw_text_with_cursor(System_Functions *system, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, String s, i32 pos){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6180,35 +6156,33 @@ draw_text_with_cursor(Render_Target *target, View *view, Font_ID font_id, i32_Re draw_rectangle(target, rect, back_color); if (pos >= 0 && pos < s.size){ - //Render_Font *font = get_font_info(models->font_set, font_id)->font; - Render_Font *font = 0; AllowLocal(font); + Render_Font *font = system->font.get_render_data_by_id(font_id); String part1 = substr(s, 0, pos); String part2 = substr(s, pos, 1); String part3 = substr(s, pos+1, s.size-pos-1); - x = draw_string(target, font_id, part1, floor32(x), y, text_color); + x = draw_string(system, target, font_id, part1, floor32(x), y, text_color); - //f32 adv = get_codepoint_advance(font, s.str[pos]); - f32 adv = 2.f; + f32 adv = font_get_glyph_advance(system, font, s.str[pos]); i32_Rect cursor_rect; cursor_rect.x0 = floor32(x); cursor_rect.x1 = floor32(x) + ceil32(adv); cursor_rect.y0 = y; cursor_rect.y1 = y + view->line_height; draw_rectangle(target, cursor_rect, cursor_color); - x = draw_string(target, font_id, part2, floor32(x), y, at_cursor_color); + x = draw_string(system, target, font_id, part2, floor32(x), y, at_cursor_color); - draw_string(target, font_id, part3, floor32(x), y, text_color); + draw_string(system, target, font_id, part3, floor32(x), y, text_color); } else{ - draw_string(target, font_id, s, floor32(x), y, text_color); + draw_string(system, target, font_id, s, floor32(x), y, text_color); } } } internal void -draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect rect){ +draw_file_bar(System_Functions *system, Render_Target *target, View *view, Editing_File *file, i32_Rect rect){ File_Bar bar; Models *models = view->persistent.models; Style *style = main_style(models); @@ -6232,11 +6206,11 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re Assert(file); - intbar_draw_string(target, &bar, file->name.live_name, base_color); - intbar_draw_string(target, &bar, make_lit_string(" -"), base_color); + intbar_draw_string(system, target, &bar, file->name.live_name, base_color); + intbar_draw_string(system, target, &bar, make_lit_string(" -"), base_color); if (file->is_loading){ - intbar_draw_string(target, &bar, make_lit_string(" loading"), base_color); + intbar_draw_string(system, target, &bar, make_lit_string(" loading"), base_color); } else{ char bar_space[526]; @@ -6255,11 +6229,11 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re append_ss(&bar_text, make_lit_string(" nix")); } - intbar_draw_string(target, &bar, bar_text, base_color); + intbar_draw_string(system, target, &bar, bar_text, base_color); if (file->state.still_lexing){ - intbar_draw_string(target, &bar, make_lit_string(" parsing"), pop1_color); + intbar_draw_string(system, target, &bar, make_lit_string(" parsing"), pop1_color); } if (!file->settings.unimportant){ @@ -6267,13 +6241,13 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re case DirtyState_UnloadedChanges: { local_persist String out_of_sync = make_lit_string(" !"); - intbar_draw_string(target, &bar, out_of_sync, pop2_color); + intbar_draw_string(system, target, &bar, out_of_sync, pop2_color); }break; case DirtyState_UnsavedChanges: { local_persist String out_of_sync = make_lit_string(" *"); - intbar_draw_string(target, &bar, out_of_sync, pop2_color); + intbar_draw_string(system, target, &bar, out_of_sync, pop2_color); }break; } } @@ -6303,7 +6277,7 @@ get_margin_color(i32 active_level, Style *style){ } internal void -draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, u32 fore, u32 back, String text){ +draw_color_button(System_Functions *system, GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, u32 fore, u32 back, String text){ i32 active_level = gui_active_level(gui_target, id); if (active_level > 0){ @@ -6311,11 +6285,11 @@ draw_color_button(GUI_Target *gui_target, Render_Target *target, View *view, Fon } draw_rectangle(target, rect, back); - draw_string(target, font_id, text, rect.x0, rect.y0 + 1, fore); + draw_string(system, target, font_id, text, rect.x0, rect.y0 + 1, fore); } internal void -draw_font_button(GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, Font_ID font_id, String text){ +draw_font_button(System_Functions *system, GUI_Target *gui_target, Render_Target *target, View *view, i32_Rect rect, GUI_id id, Font_ID font_id, String text){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6327,12 +6301,11 @@ draw_font_button(GUI_Target *gui_target, Render_Target *target, View *view, i32_ draw_rectangle(target, rect, back_color); draw_rectangle_outline(target, rect, margin_color); - draw_string(target, font_id, text, rect.x0, rect.y0 + 1, text_color); + draw_string(system, target, font_id, text, rect.x0, rect.y0 + 1, text_color); } internal void -draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, - String text, String pop, i8 checkbox = -1){ +draw_fat_option_block(System_Functions *system, GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, String text, String pop, i8 checkbox = -1){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6367,12 +6340,12 @@ draw_fat_option_block(GUI_Target *gui_target, Render_Target *target, View *view, x = checkbox_rect.x1 + 3; } - x = ceil32(draw_string(target, font_id, text, x, y, text_color)); - draw_string(target, font_id, pop, x, y, pop_color); + x = ceil32(draw_string(system, target, font_id, text, x, y, text_color)); + draw_string(system, target, font_id, pop, x, y, pop_color); } internal void -draw_button(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, String text){ +draw_button(System_Functions *system, GUI_Target *gui_target, Render_Target *target, View *view, Font_ID font_id, i32_Rect rect, GUI_id id, String text){ Models *models = view->persistent.models; Style *style = main_style(models); @@ -6387,13 +6360,13 @@ draw_button(GUI_Target *gui_target, Render_Target *target, View *view, Font_ID f i32 h = view->line_height; i32 y = inner.y0 + h/2 - 1; - i32 w = (i32)font_string_width(target, font_id, text); + i32 w = (i32)font_string_width(system, target, font_id, text); i32 x = (inner.x1 + inner.x0 - w)/2; draw_rectangle(target, inner, back); draw_rectangle_outline(target, inner, margin); - draw_string(target, font_id, text, x, y, text_color); + draw_string(system, target, font_id, text, x, y, text_color); } internal void @@ -6401,7 +6374,6 @@ draw_style_preview(System_Functions *system, GUI_Target *gui_target, Render_Targ Models *models = view->persistent.models; AllowLocal(models); i32 active_level = gui_active_level(gui_target, id); - //Font_Info *info = get_font_info(models->font_set, font_id); char font_name_space[256]; String font_name = make_fixed_width_string(font_name_space); font_name.size = system->font.get_name_by_id(font_id, font_name.str, font_name.memory_size); @@ -6421,26 +6393,26 @@ draw_style_preview(System_Functions *system, GUI_Target *gui_target, Render_Targ i32 y = inner.y0; i32 x = inner.x0; - x = ceil32(draw_string(target, font_id, style->name.str, x, y, text_color)); - i32 font_x = (i32)(inner.x1 - font_string_width(target, font_id, font_name)); + x = ceil32(draw_string(system, target, font_id, style->name.str, x, y, text_color)); + i32 font_x = (i32)(inner.x1 - font_string_width(system, target, font_id, font_name)); if (font_x > x + 10){ - draw_string(target, font_id, font_name, font_x, y, text_color); + draw_string(system, target, font_id, font_name, font_x, y, text_color); } i32 height = font_get_height(font); x = inner.x0; y += height; - x = ceil32(draw_string(target, font_id, "if", x, y, keyword_color)); - x = ceil32(draw_string(target, font_id, "(x < ", x, y, text_color)); - x = ceil32(draw_string(target, font_id, "0", x, y, int_constant_color)); - x = ceil32(draw_string(target, font_id, ") { x = ", x, y, text_color)); - x = ceil32(draw_string(target, font_id, "0", x, y, int_constant_color)); - x = ceil32(draw_string(target, font_id, "; } ", x, y, text_color)); - x = ceil32(draw_string(target, font_id, "// comment", x, y, comment_color)); + x = ceil32(draw_string(system, target, font_id, "if", x, y, keyword_color)); + x = ceil32(draw_string(system, target, font_id, "(x < ", x, y, text_color)); + x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color)); + x = ceil32(draw_string(system, target, font_id, ") { x = ", x, y, text_color)); + x = ceil32(draw_string(system, target, font_id, "0", x, y, int_constant_color)); + x = ceil32(draw_string(system, target, font_id, "; } ", x, y, text_color)); + x = ceil32(draw_string(system, target, font_id, "// comment", x, y, comment_color)); x = inner.x0; y += height; - draw_string(target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", x, y, text_color); + draw_string(system, target, font_id, "[] () {}; * -> +-/ <>= ! && || % ^", x, y, text_color); } internal i32 @@ -6483,7 +6455,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol switch (h->type){ case guicom_top_bar: { - draw_file_bar(target, view, file, gui_session.rect); + draw_file_bar(system, target, view, file, gui_session.rect); }break; case guicom_file: @@ -6498,7 +6470,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol void *ptr = (h+1); String p = gui_read_string(&ptr); String t = gui_read_string(&ptr); - draw_text_field(target, view, font_id, gui_session.rect, p, t); + draw_text_field(system, target, view, font_id, gui_session.rect, p, t); }break; case guicom_text_with_cursor: @@ -6507,7 +6479,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol String s = gui_read_string(&ptr); i32 pos = gui_read_integer(&ptr); - draw_text_with_cursor(target, view, font_id, gui_session.rect, s, pos); + draw_text_with_cursor(system, target, view, font_id, gui_session.rect, s, pos); }break; case guicom_color_button: @@ -6518,7 +6490,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol u32 back = (u32)gui_read_integer(&ptr); String t = gui_read_string(&ptr); - draw_color_button(gui_target, target, view, font_id, gui_session.rect, b->id, fore, back, t); + draw_color_button(system, gui_target, target, view, font_id, gui_session.rect, b->id, fore, back, t); }break; case guicom_font_button: @@ -6528,7 +6500,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol Font_ID font_id = (Font_ID)gui_read_integer(&ptr); String t = gui_read_string(&ptr); - draw_font_button(gui_target, target, view, gui_session.rect, b->id, font_id, t); + draw_font_button(system, gui_target, target, view, gui_session.rect, b->id, font_id, t); }break; case guicom_file_option: @@ -6543,7 +6515,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol append_s_char(&f, '/'); } - draw_fat_option_block(gui_target, target, view, font_id, gui_session.rect, b->id, f, m); + draw_fat_option_block(system, gui_target, target, view, font_id, gui_session.rect, b->id, f, m); }break; case guicom_style_preview: @@ -6568,7 +6540,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol status = (i8)gui_read_byte(&ptr); } - draw_fat_option_block(gui_target, target, view, font_id, gui_session.rect, b->id, f, m, status); + draw_fat_option_block(system, gui_target, target, view, font_id, gui_session.rect, b->id, f, m, status); }break; case guicom_button: @@ -6577,7 +6549,7 @@ do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scrol void *ptr = (b + 1); String t = gui_read_string(&ptr); - draw_button(gui_target, target, view, font_id, gui_session.rect, b->id, t); + draw_button(system, gui_target, target, view, font_id, gui_session.rect, b->id, t); }break; case guicom_scrollable_bar: diff --git a/4ed_math.h b/4ed_math.h index eedbcafc..e0ce58d2 100644 --- a/4ed_math.h +++ b/4ed_math.h @@ -431,18 +431,6 @@ unlerp(f32 a, f32 x, f32 b){ return(r); } -inline f32 -clamp_bottom(f32 a, f32 n){ - if (n < a) n = a; - return (n); -} - -inline f32 -clamp_top(f32 n, f32 z){ - if (n > z) n = z; - return (n); -} - inline f32 clamp(f32 a, f32 n, f32 z){ if (n < a) n = a; @@ -450,18 +438,6 @@ clamp(f32 a, f32 n, f32 z){ return (n); } -inline i32 -clamp_bottom(i32 a, i32 n){ - if (n < a) n = a; - return (n); -} - -inline i32 -clamp_top(i32 n, i32 z){ - if (n > z) n = z; - return (n); -} - inline i32 clamp(i32 a, i32 n, i32 z){ if (n < a) n = a; @@ -469,30 +445,6 @@ clamp(i32 a, i32 n, i32 z){ return (n); } -inline u32 -clamp_bottom(u32 a, u32 n){ - if (n < a) n = a; - return (n); -} - -inline u64 -clamp_bottom(u64 a, u64 n){ - if (n < a) n = a; - return (n); -} - -inline u32 -clamp_top(u32 n, u32 z){ - if (n > z) n = z; - return (n); -} - -inline u64 -clamp_top(u64 n, u64 z){ - if (n > z) n = z; - return (n); -} - inline u32 clamp(u32 a, u32 n, u32 z){ if (n < a) n = a; @@ -500,6 +452,9 @@ clamp(u32 a, u32 n, u32 z){ return (n); } +#define clamp_top(a,b) Min(a,b) +#define clamp_bottom(a,b) Max(a,b) + /* * Color */ diff --git a/4ed_rendering_helper.cpp b/4ed_rendering_helper.cpp index bec1b00c..8ed01103 100644 --- a/4ed_rendering_helper.cpp +++ b/4ed_rendering_helper.cpp @@ -130,19 +130,15 @@ font_draw_glyph(Render_Target *target, Font_ID font_id, u32 codepoint, f32 x, f3 } internal f32 -draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_, i32 x_, i32 y_, u32 color){ - +draw_string_base(System_Functions *system, Render_Target *target, Font_ID font_id, i32 type, String str_, i32 x_, i32 y_, u32 color){ f32 x = 0; -#if 0 - Font_Info *font_info = get_font_info(&target->font_set, font_id); - Render_Font *font = font_info->font; - - if (font){ + Render_Font *font = system->font.get_render_data_by_id(font_id); + if (font != 0){ f32 y = (f32)y_; x = (f32)x_; - f32 byte_advance = font->byte_advance; + f32 byte_advance = font_get_byte_advance(font); u8 *str = (u8*)str_.str; u8 *str_end = str + str_.size; @@ -169,7 +165,7 @@ draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_, if (color != 0){ font_draw_glyph(target, font_id, type, (u8)codepoint, x, y, color); } - x += get_codepoint_advance(font, codepoint); + x += font_get_glyph_advance(system, font, codepoint); } else if (do_numbers){ for (;byte < str; ++byte){ @@ -179,10 +175,12 @@ draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_, cs[0] = '\\'; byte_to_ascii(n, cs+1); + f32 *advances = font_get_byte_sub_advances(font); + f32 xx = x; for (u32 j = 0; j < 3; ++j){ font_draw_glyph(target, font_id, type, cs[j], xx, y, color); - xx += byte_advance; + xx += advances[j]; } } @@ -191,47 +189,46 @@ draw_string_base(Render_Target *target, Font_ID font_id, i32 type, String str_, } } } -#endif return(x); } internal f32 -draw_string(Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, u32 color){ - f32 w = draw_string_base(target, font_id, piece_type_glyph, str, x, y, color); +draw_string(System_Functions *system, Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, u32 color){ + f32 w = draw_string_base(system, target, font_id, piece_type_glyph, str, x, y, color); return(w); } internal f32 -draw_string(Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, u32 color){ +draw_string(System_Functions *system, Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, u32 color){ String string = make_string_slowly(str); - f32 w = draw_string_base(target, font_id, piece_type_glyph, string, x, y, color); + f32 w = draw_string_base(system, target, font_id, piece_type_glyph, string, x, y, color); return(w); } internal f32 -draw_string_mono(Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, f32 advance, u32 color){ - f32 w = draw_string_base(target, font_id, piece_type_mono_glyph, str, x, y, color); +draw_string_mono(System_Functions *system, Render_Target *target, Font_ID font_id, String str, i32 x, i32 y, f32 advance, u32 color){ + f32 w = draw_string_base(system, target, font_id, piece_type_mono_glyph, str, x, y, color); return(w); } internal f32 -draw_string_mono(Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, f32 advance, u32 color){ +draw_string_mono(System_Functions *system, Render_Target *target, Font_ID font_id, char *str, i32 x, i32 y, f32 advance, u32 color){ String string = make_string_slowly(str); - f32 w = draw_string_base(target, font_id, piece_type_mono_glyph, string, x, y, color); + f32 w = draw_string_base(system, target, font_id, piece_type_mono_glyph, string, x, y, color); return(w); } internal f32 -font_string_width(Render_Target *target, Font_ID font_id, String str){ - f32 w = draw_string_base(target, font_id, piece_type_glyph, str, 0, 0, 0); +font_string_width(System_Functions *system, Render_Target *target, Font_ID font_id, String str){ + f32 w = draw_string_base(system, target, font_id, piece_type_glyph, str, 0, 0, 0); return(w); } internal f32 -font_string_width(Render_Target *target, Font_ID font_id, char *str){ +font_string_width(System_Functions *system, Render_Target *target, Font_ID font_id, char *str){ String string = make_string_slowly(str); - f32 w = draw_string_base(target, font_id, piece_type_glyph, string, 0, 0, 0); + f32 w = draw_string_base(system, target, font_id, piece_type_glyph, string, 0, 0, 0); return(w); } diff --git a/4ed_system_shared.cpp b/4ed_system_shared.cpp index 2bcdfe2f..0aa088e8 100644 --- a/4ed_system_shared.cpp +++ b/4ed_system_shared.cpp @@ -424,10 +424,9 @@ get_exact_render_quad(Glyph_Bounds *b, i32 pw, i32 ph, float xpos, float ypos){ } inline void -private_draw_glyph(Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){ -#if 0 - Glyph_Data glyph = {0}; - if (get_codepoint_glyph_data(font, character, &glyph)){ +private_draw_glyph(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){ + Glyph_Data glyph = font_get_glyph(system, font, codepoint); + if (glyph.tex != 0){ Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y); draw_set_color(target, color); @@ -441,14 +440,12 @@ private_draw_glyph(Render_Target *target, Render_Font *font, u32 codepoint, f32 } glEnd(); } -#endif } inline void -private_draw_glyph_mono(Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){ -#if 0 - Glyph_Data glyph = {0}; - if (get_codepoint_glyph_data(font, character, &glyph)){ +private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){ + Glyph_Data glyph = font_get_glyph(system, font, codepoint); + if (glyph.tex != 0){ f32 left = glyph.bounds.x0; f32 right = glyph.bounds.x1; f32 width = (right - left); @@ -469,18 +466,16 @@ private_draw_glyph_mono(Render_Target *target, Render_Font *font, u32 codepoint, } glEnd(); } -#endif - } inline void -private_draw_glyph_mono(Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){ +private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){ f32 advance = (f32)font_get_advance(font); - private_draw_glyph_mono(target, font, character, x, y, advance, color); + private_draw_glyph_mono(system, target, font, character, x, y, advance, color); } internal void -launch_rendering(Render_Target *target){ +launch_rendering(System_Functions *system, Render_Target *target){ char *cursor = target->push_buffer; char *cursor_end = cursor + target->size; @@ -509,44 +504,34 @@ launch_rendering(Render_Target *target){ case piece_type_glyph: { -#if 0 Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); - Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; - if (font){ - private_draw_glyph(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); - } -#endif + Render_Font *font = system->font.get_render_data_by_id(glyph->font_id); + Assert(font != 0); + private_draw_glyph(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color); }break; case piece_type_mono_glyph: { -#if 0 Render_Piece_Glyph *glyph = ExtractStruct(Render_Piece_Glyph); - Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; - if (font){ - private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->color); - } -#endif + Render_Font *font = system->font.get_render_data_by_id(glyph->font_id); + Assert(font != 0); + private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color); }break; case piece_type_mono_glyph_advance: { -#if 0 Render_Piece_Glyph_Advance *glyph = ExtractStruct(Render_Piece_Glyph_Advance); - Render_Font *font = get_font_info(&target->font_set, glyph->font_id)->font; - if (font){ - private_draw_glyph_mono(target, font, glyph->character, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color); - } -#endif + Render_Font *font = system->font.get_render_data_by_id(glyph->font_id); + Assert(font != 0); + private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color); }break; case piece_type_change_clip: { - Render_Piece_Change_Clip *clip = - ExtractStruct(Render_Piece_Change_Clip); + Render_Piece_Change_Clip *clip = ExtractStruct(Render_Piece_Change_Clip); draw_set_clip(target, clip->box); }break; } @@ -684,7 +669,9 @@ font_load_page_inner(Partition *part, Render_Font *font, FT_Library ft, FT_Face } internal b32 -font_load_page(System_Functions *system, Partition *part, Render_Font *font, char *filename, i32 pt_size, i32 tab_width, b32 use_hinting, u32 page_number){ +font_load_page(System_Functions *system, Partition *part, Render_Font *font, Glyph_Page *page, u32 page_number, u32 pt_size, b32 use_hinting){ + + char *filename = font->filename; // TODO(allen): Stop redoing all this init for each call. FT_Library ft; @@ -694,8 +681,7 @@ font_load_page(System_Functions *system, Partition *part, Render_Font *font, cha FT_New_Face(ft, filename, 0, &face); // NOTE(allen): set texture and glyph data. - Glyph_Page *page = font_get_or_make_page(system, font, page_number); - font_load_page_inner(part, font, ft, face, use_hinting, page, page_number, tab_width); + font_load_page_inner(part, font, ft, face, use_hinting, page, page_number, 4); FT_Done_FreeType(ft); @@ -703,9 +689,9 @@ font_load_page(System_Functions *system, Partition *part, Render_Font *font, cha } internal b32 -font_load(System_Functions *system, Partition *part, Render_Font *font, char *filename, i32 pt_size, i32 tab_width, b32 use_hinting){ +font_load(System_Functions *system, Partition *part, Render_Font *font, i32 pt_size, b32 use_hinting){ - memset(font, 0, sizeof(*font)); + char *filename = font->filename; // TODO(allen): Stop redoing all this init for each call. FT_Library ft; @@ -731,7 +717,6 @@ font_load(System_Functions *system, Partition *part, Render_Font *font, char *fi // NOTE(allen): set texture and glyph data. Glyph_Page *page = font_get_or_make_page(system, font, 0); - font_load_page_inner(part, font, ft, face, use_hinting, page, 0, tab_width); // NOTE(allen): Setup some basic spacing stuff. f32 backslash_adv = page->advance['\\']; @@ -750,12 +735,63 @@ font_load(System_Functions *system, Partition *part, Render_Font *font, char *fi } font->byte_advance = backslash_adv + max_hex_advance*2; + font->byte_sub_advances[0] = backslash_adv; + font->byte_sub_advances[1] = max_hex_advance; + font->byte_sub_advances[2] = max_hex_advance; FT_Done_FreeType(ft); return(true); } +internal void +system_set_page(System_Functions *system, Partition *part, Render_Font *font, Glyph_Page *page, u32 page_number, u32 pt_size, b32 use_hinting){ + memset(page, 0, sizeof(*page)); + + if (part->base == 0){ + *part = sysshared_scratch_partition(MB(8)); + } + + b32 success = false; + for (u32 R = 0; R < 3; ++R){ + success = font_load_page(system, part, font, page, page_number, pt_size, use_hinting); + if (success){ + break; + } + else{ + sysshared_partition_double(part); + } + } +} + +internal void +system_set_font(System_Functions *system, Partition *part, Render_Font *font, String filename, String name, u32 pt_size, b32 use_hinting){ + memset(font, 0, sizeof(*font)); + + copy_partial_cs(font->filename, sizeof(font->filename)-1, filename); + font->filename_len = filename.size; + font->filename[font->filename_len] = 0; + copy_partial_cs(font->name, sizeof(font->name)-1, name); + font->name_len = name.size; + font->name[font->name_len] = 0; + + if (part->base == 0){ + *part = sysshared_scratch_partition(MB(8)); + } + + b32 success = false; + for (u32 R = 0; R < 3; ++R){ + success = font_load(system, part, font, pt_size, use_hinting); + if (success){ + break; + } + else{ + sysshared_partition_double(part); + } + } +} + + #endif // BOTTOM diff --git a/file/4coder_buffer.cpp b/file/4coder_buffer.cpp index 7bcc9a0b..8b255033 100644 --- a/file/4coder_buffer.cpp +++ b/file/4coder_buffer.cpp @@ -922,17 +922,12 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para } else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){ if (!S.skipping_whitespace){ - - S.current_adv = 2.f; - -#if 0 if (S.behavior.do_codepoint_advance){ - S.current_adv = get_codepoint_advance(params.font, S.tran.step_current.value); + S.current_adv = font_get_glyph_advance(params.system, params.font, S.step.value); } else{ - S.current_adv = params.font->byte_advance; + S.current_adv = font_get_byte_advance(params.font); } -#endif S.did_wrap = false; if (S.i >= S.wrap_unit_end){ @@ -1438,9 +1433,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa switch (params.seek.type){ case buffer_seek_pos: { - if (params.seek.pos > S.size){ - params.seek.pos = S.size; - } + params.seek.pos = clamp(0, params.seek.pos, S.size); line_index = buffer_get_line_index(params.buffer, params.seek.pos); }break; @@ -1449,34 +1442,21 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa { i32 line_count = params.buffer->line_count; i32 max_character = params.character_starts[line_count] - 1; - if (params.seek.pos > max_character){ - params.seek.pos = max_character; - } + params.seek.pos = clamp(0, params.seek.pos, max_character); - line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, - 0, params.buffer->line_count); + line_index = buffer_get_line_index_from_character_pos(params.character_starts, params.seek.pos, 0, params.buffer->line_count); }break; case buffer_seek_line_char: { line_index = params.seek.line - 1; - if (line_index >= params.buffer->line_count){ - line_index = params.buffer->line_count - 1; - } - if (line_index < 0){ - line_index = 0; - } + line_index = clamp_bottom(0, line_index); }break; case buffer_seek_unwrapped_xy: { line_index = (i32)(params.seek.y / S.font_height); - if (line_index >= params.buffer->line_count){ - line_index = params.buffer->line_count - 1; - } - if (line_index < 0){ - line_index = 0; - } + line_index = clamp_bottom(0, line_index); }break; case buffer_seek_wrapped_xy: @@ -1487,15 +1467,20 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa default: InvalidCodePath; } + i32 safe_line_index = line_index; + if (line_index >= params.buffer->line_count){ + safe_line_index = params.buffer->line_count-1; + } + // Build the cursor hint - S.next_cursor.pos = params.buffer->line_starts[line_index]; - S.next_cursor.character_pos = params.character_starts[line_index]; + 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.character = 1; - S.next_cursor.wrap_line = params.wrap_line_index[line_index] + 1; - S.next_cursor.unwrapped_y = (f32)(line_index * S.font_height); + 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); S.next_cursor.unwrapped_x = 0; - S.next_cursor.wrapped_y = (f32)(params.wrap_line_index[line_index] * S.font_height); + S.next_cursor.wrapped_y = (f32)(params.wrap_line_index[safe_line_index] * S.font_height); S.next_cursor.wrapped_x = 0; } @@ -1624,16 +1609,12 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa } else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){ - S.ch_width = 2.f; - -#if 0 - if (S.tran.do_codepoint_advance){ - S.ch_width = get_codepoint_advance(params.font, S.tran.step_current.value); + if (S.behavior.do_codepoint_advance){ + S.ch_width = font_get_glyph_advance(params.system, params.font, S.step.value); } else{ - S.ch_width = params.font->byte_advance; + S.ch_width = font_get_byte_advance(params.font); } -#endif if (S.step.i >= S.wrap_unit_end){ S_stop.status = BLStatus_NeedWrapDetermination; @@ -1821,6 +1802,7 @@ typedef struct Buffer_Render_Item{ typedef struct Render_Item_Write{ Buffer_Render_Item *item; f32 x, y; + System_Functions *system; Render_Font *font; i32 font_height; f32 x_min; @@ -1830,11 +1812,7 @@ typedef struct Render_Item_Write{ inline Render_Item_Write write_render_item(Render_Item_Write write, i32 index, u32 codepoint, u32 flags){ -#if 0 - f32 ch_width = get_codepoint_advance(write.font, codepoint); -#endif - - f32 ch_width = 2.f; + f32 ch_width = font_get_glyph_advance(write.system, write.font, codepoint); if (write.x <= write.x_max && write.x + ch_width >= write.x_min){ write.item->index = index; @@ -1945,6 +1923,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 S.write.item = params.items; S.write.x = S.shift_x + line_shift; S.write.y = S.shift_y; + S.write.system = params.system; S.write.font = params.font; S.write.font_height = font_get_height(params.font); S.write.x_min = params.port_x; @@ -2055,10 +2034,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 case '\t': { -#if 0 - S.ch_width = get_codepoint_advance(params.font, '\t'); -#endif - S.ch_width = 2.f; + S.ch_width = font_get_glyph_advance(params.system, params.font, '\t'); f32 new_x = S.write.x + S.ch_width; S.write = write_render_item(S.write, I, ' ', 0); diff --git a/file/4coder_translation.cpp b/file/4coder_translation.cpp index 83579f2a..a52b8eb7 100644 --- a/file/4coder_translation.cpp +++ b/file/4coder_translation.cpp @@ -18,6 +18,7 @@ struct Translation_State{ global_const Translation_State null_buffer_translating_state = {0}; enum{ + TranLBH_None, TranLBH_Rebuffer, TranLBH_EmitAsCP, }; @@ -41,6 +42,8 @@ struct Translation_Emits{ u32 step_count; }; +#define SINGLE_BYTE_ERROR_CLASS max_u8 + internal void translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Byte_Description *desc_out){ desc_out->byte_class = 0; @@ -48,7 +51,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl desc_out->byte_class = 1; } else if (ch < 0xC0){ - desc_out->byte_class = max_u8; + desc_out->byte_class = SINGLE_BYTE_ERROR_CLASS; } else if (ch < 0xE0){ desc_out->byte_class = 2; @@ -61,7 +64,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl } desc_out->prelim_emit_type = BufferModelUnit_None; - desc_out->last_byte_handler = 0; + desc_out->last_byte_handler = TranLBH_None; if (tran->fill_expected == 0){ tran->fill_buffer[0] = ch; tran->fill_start_i = i; @@ -70,7 +73,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl if (desc_out->byte_class == 1){ desc_out->prelim_emit_type = BufferModelUnit_Codepoint; } - else if (desc_out->byte_class == 0 || desc_out->byte_class == 1000){ + else if (desc_out->byte_class == 0 || desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ desc_out->prelim_emit_type = BufferModelUnit_Numbers; } else{ @@ -78,7 +81,7 @@ translating_consume_byte(Translation_State *tran, u8 ch, u32 i, u32 size, Transl } } else{ - if (desc_out->byte_class == 1000){ + if (desc_out->byte_class == SINGLE_BYTE_ERROR_CLASS){ tran->fill_buffer[tran->fill_i] = ch; ++tran->fill_i; diff --git a/font/4coder_font_data.h b/font/4coder_font_data.h index 6c28d7b0..07231146 100644 --- a/font/4coder_font_data.h +++ b/font/4coder_font_data.h @@ -38,12 +38,13 @@ struct Render_Font{ Glyph_Page **pages; u32 page_count, page_max; f32 byte_advance; + f32 byte_sub_advances[3]; i32 height, ascent, descent, line_skip, advance; - char filename[256]; - char name[256]; u32 filename_len; u32 name_len; + char filename[256]; + char name[256]; }; struct Glyph_Data{ @@ -56,4 +57,3 @@ struct Glyph_Data{ // BOTTOM - diff --git a/font/4coder_font_interface.h b/font/4coder_font_interface.h index 644381e7..d1f1eeb6 100644 --- a/font/4coder_font_interface.h +++ b/font/4coder_font_interface.h @@ -26,13 +26,16 @@ typedef Sys_Font_Get_IDs_By_Index_Sig(Font_Get_IDs_By_Index_Function); #define Sys_Font_Get_Name_By_Index_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap) typedef Sys_Font_Get_Name_By_Index_Sig(Font_Get_Name_By_Index_Function); -#define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(u32 font_index, char *str_out, u32 str_out_cap) +#define Sys_Font_Get_Name_By_ID_Sig(name_) u32 (name_)(u32 font_id, char *str_out, u32 str_out_cap) typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function); #define Sys_Font_Get_Render_Data_By_ID_Sig(name_) Render_Font* (name_)(u32 font_id) typedef Sys_Font_Get_Render_Data_By_ID_Sig(Font_Get_Render_Data_By_ID_Function); -#define Sys_Font_Allocate_Sig(name_) void* (name_)(umem size) +#define Sys_Font_Load_Page_Sig(name_) void (name_)(Render_Font *font, Glyph_Page *page, u32 page_number) +typedef Sys_Font_Load_Page_Sig(Font_Load_Page_Function); + +#define Sys_Font_Allocate_Sig(name_) void* (name_)(i32 size) typedef Sys_Font_Allocate_Sig(Font_Allocate_Function); #define Sys_Font_Free_Sig(name_) void (name_)(void *ptr) @@ -44,12 +47,14 @@ struct Font_Functions{ Font_Get_Name_By_Index_Function *get_name_by_index; Font_Get_Name_By_ID_Function *get_name_by_id; Font_Get_Render_Data_By_ID_Function *get_render_data_by_id; + Font_Load_Page_Function *load_page; Font_Allocate_Function *allocate; Font_Free_Function *free; }; internal f32 font_get_byte_advance(Render_Font *font); +internal f32*font_get_byte_sub_advances(Render_Font *font); internal i32 font_get_height(Render_Font *font); internal i32 font_get_ascent(Render_Font *font); internal i32 font_get_descent(Render_Font *font); @@ -57,6 +62,10 @@ internal i32 font_get_line_skip(Render_Font *font); internal i32 font_get_advance(Render_Font *font); internal b32 font_can_render(struct System_Functions *system, Render_Font *font, u32 codepoint); +internal f32 font_get_glyph_advance(struct System_Functions *system, Render_Font *font, u32 codepoint); + +struct Glyph_Data; +internal Glyph_Data font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint); internal Glyph_Page *font_get_or_make_page(struct System_Functions *system, Render_Font *font, u32 page_number); diff --git a/font/4coder_font_interface_to_os.h b/font/4coder_font_interface_to_os.h new file mode 100644 index 00000000..e93efb6c --- /dev/null +++ b/font/4coder_font_interface_to_os.h @@ -0,0 +1,24 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 13.03.2017 + * + * Font system interface to the OS layer. + * + */ + +// TOP + +#if !defined(FCODER_FONT_INTERFACE_TO_OS_H) +#define FCODER_FONT_INTERFACE_TO_OS_H + +#define Sys_Font_Init_Sig(name_) void (name_)(Font_Functions *font, void *memory, umem memory_size, u32 font_size, b32 use_hinting) +internal Sys_Font_Init_Sig(system_font_init); + + +#endif + +// BOTTOM + + + diff --git a/font/4coder_font_static_functions.cpp b/font/4coder_font_static_functions.cpp index c185ec93..32dfdc3a 100644 --- a/font/4coder_font_static_functions.cpp +++ b/font/4coder_font_static_functions.cpp @@ -16,6 +16,11 @@ font_get_byte_advance(Render_Font *font){ return(font->byte_advance); } +internal f32* +font_get_byte_sub_advances(Render_Font *font){ + return(font->byte_sub_advances); +} + internal i32 font_get_height(Render_Font *font){ return(font->height); @@ -46,12 +51,37 @@ font_can_render(System_Functions *system, Render_Font *font, u32 codepoint){ b32 result = false; u32 page_number = (codepoint >> 8); u32 glyph_index = codepoint & 0xFF; - Glyph_Page *page = font_get_or_make_page(system, font, page_number); if (page != 0 && page->advance[glyph_index] > 0.f){ result = true; } - + return(result); +} + +internal f32 +font_get_glyph_advance(System_Functions *system, Render_Font *font, u32 codepoint){ + f32 result = 0.f; + u32 page_number = (codepoint >> 8); + u32 glyph_index = codepoint & 0xFF; + Glyph_Page *page = font_get_or_make_page(system, font, page_number); + if (page != 0 && page->advance[glyph_index] > 0.f){ + result = page->advance[glyph_index]; + } + return(result); +} + +internal Glyph_Data +font_get_glyph(System_Functions *system, Render_Font *font, u32 codepoint){ + Glyph_Data result = {0}; + u32 page_number = (codepoint >> 8); + u32 glyph_index = codepoint & 0xFF; + Glyph_Page *page = font_get_or_make_page(system, font, page_number); + if (page != 0 && page->advance[glyph_index] > 0.f){ + result.bounds = page->glyphs[glyph_index]; + result.tex = page->tex; + result.tex_width = page->tex_width; + result.tex_height = page->tex_height; + } return(result); } @@ -153,14 +183,16 @@ font_get_or_make_page(System_Functions *system, Render_Font *font, u32 page_numb *dest = new_page; font->page_count += new_page_count; result = new_page; + system->font.load_page(font, new_page, page_number); } } } + else{ + result = *page_get_result; + } } return(result); } // BOTTOM - - diff --git a/linux_4ed.cpp b/linux_4ed.cpp index badee602..896a834e 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -2424,10 +2424,6 @@ LinuxGetXSettingsDPI(Display* dpy, int screen) internal b32 LinuxX11WindowInit(int argc, char** argv, int* WinWidth, int* WinHeight) { - // NOTE(allen): Here begins the linux screen setup stuff. - // Behold the true nature of this wonderful OS: - // (thanks again to Casey for providing this stuff) - #define BASE_W 800 #define BASE_H 600 @@ -2454,17 +2450,10 @@ LinuxX11WindowInit(int argc, char** argv, int* WinWidth, int* WinHeight) swa.backing_store = WhenMapped; swa.event_mask = StructureNotifyMask; swa.bit_gravity = NorthWestGravity; - swa.colormap = XCreateColormap(linuxvars.XDisplay, - RootWindow(linuxvars.XDisplay, Config.BestInfo.screen), - Config.BestInfo.visual, AllocNone); + swa.colormap = XCreateColormap(linuxvars.XDisplay, RootWindow(linuxvars.XDisplay, Config.BestInfo.screen), Config.BestInfo.visual, AllocNone); - linuxvars.XWindow = - XCreateWindow(linuxvars.XDisplay, - RootWindow(linuxvars.XDisplay, Config.BestInfo.screen), - 0, 0, *WinWidth, *WinHeight, - 0, Config.BestInfo.depth, InputOutput, - Config.BestInfo.visual, - CWBackingStore|CWBitGravity|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &swa); + linuxvars.XWindow = XCreateWindow(linuxvars.XDisplay, RootWindow(linuxvars.XDisplay, Config.BestInfo.screen), + 0, 0, *WinWidth, *WinHeight, 0, Config.BestInfo.depth, InputOutput, Config.BestInfo.visual, CWBackingStore|CWBitGravity|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &swa); if (!linuxvars.XWindow){ LinuxFatalErrorMsg("XCreateWindow failed. Make sure your display is set up correctly."); diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index 6d58b80b..3c4899bf 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -63 +68 diff --git a/string/_4coder_string.ctm b/string/_4coder_string.ctm index 108a7bd6b927e485e4b8166c9522a73dd51967ad..77f6a7439b2cd0374f3dd2bf75e5d201915439c8 100644 GIT binary patch delta 153 zcmbOtvP5))2v_~om+u~{&bh?M%)r3#iiv@Nx0SVXMN04e|gT8}B> delta 7 OcmZ1?Iz?oI2p0efcLFc~ diff --git a/string/internal_4coder_string.cpp b/string/internal_4coder_string.cpp index 0b7c9658..c2bc3a5b 100644 --- a/string/internal_4coder_string.cpp +++ b/string/internal_4coder_string.cpp @@ -970,6 +970,23 @@ This call returns non-zero on a successful copy.) */{ return 1; } +CPP_NAME(copy_checked) +API_EXPORT FSTRING_LINK b32_4tech +copy_checked_cs(char *dest, i32_4tech dest_cap, String src)/* +DOC(This call performs a copy from the src string to the dest string. +The value dest_cap is checked before any coppying is done. +This call returns non-zero on a successful copy.) +*/{ + i32_4tech i; + if (dest_cap < src.size){ + return 0; + } + for (i = 0; i < src.size; ++i){ + dest[i] = src.str[i]; + } + return 1; +} + CPP_NAME(copy_partial) API_EXPORT FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src)/* @@ -995,9 +1012,9 @@ CPP_NAME(copy_partial) API_EXPORT FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src)/* DOC(This call performs a copy from the src string to the dest string. -The memory_size of dest is checked if the entire copy cannot be performed, -as many bytes as possible are coppied to dest. This call returns non-zero -if the entire string is coppied to dest.) */{ +The memory_size of dest is checked. If the entire copy cannot be performed, +as many bytes as possible are coppied to dest. +This call returns non-zero if the entire string is coppied to dest.) */{ char *dest_str = dest->str; i32_4tech memory_size = dest->memory_size; b32_4tech result = 0; @@ -1009,7 +1026,28 @@ if the entire string is coppied to dest.) */{ dest_str[i] = src.str[i]; } dest->size = memory_size; - return result; + return(result); +} + +CPP_NAME(copy_partial) +API_EXPORT FSTRING_LINK b32_4tech +copy_partial_cs(char *dest, i32_4tech dest_cap, String src)/* +DOC(This call performs a copy from the src string to the dest string. +The value dest_cap is checked. If the entire copy cannot be performed, +as many bytes as possible are coppied to dest. +This call returns non-zero if the entire string is coppied to dest.) +*/{ + b32_4tech result = 0; + i32_4tech copy_size = dest_cap; + i32_4tech i; + if (dest_cap >= src.size){ + result = 1; + copy_size = src.size; + } + for (i = 0; i < copy_size; ++i){ + dest[i] = src.str[i]; + } + return(result); } CPP_NAME(copy) diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 86a78486..c56a7373 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -184,10 +184,8 @@ typedef struct Win32_Vars{ b32 next_clipboard_is_self; DWORD clipboard_sequence; - HWND window_handle; Render_Target target; - Partition font_part; #if SUPPORT_DPI i32 dpi_x, dpi_y; #endif @@ -332,9 +330,7 @@ Sys_Release_Lock_Sig(system_release_lock){ internal void system_wait_cv(i32 crit_id, i32 cv_id){ - SleepConditionVariableCS(win32vars.condition_vars + cv_id, - win32vars.locks + crit_id, - INFINITE); + SleepConditionVariableCS(win32vars.condition_vars + cv_id, win32vars.locks + crit_id, INFINITE); } internal void @@ -371,9 +367,7 @@ JobThreadProc(LPVOID lpParameter){ // wrapping by the queue wrap. That was super stupid what was that? // Now it just wraps by the queue wrap. u32 next_read_index = (read_index + 1) % QUEUE_WRAP; - u32 safe_read_index = - InterlockedCompareExchange(&queue->read_position, - next_read_index, read_index); + u32 safe_read_index = InterlockedCompareExchange(&queue->read_position, next_read_index, read_index); if (safe_read_index == read_index){ Full_Job_Data *full_job = queue->jobs + safe_read_index; @@ -381,16 +375,13 @@ JobThreadProc(LPVOID lpParameter){ // with the cancel job routine, which may try to cancel this job // at the same time that we try to run it - i32 safe_running_thread = - InterlockedCompareExchange(&full_job->running_thread, - thread->id, THREAD_NOT_ASSIGNED); + i32 safe_running_thread =InterlockedCompareExchange(&full_job->running_thread, thread->id, THREAD_NOT_ASSIGNED); if (safe_running_thread == THREAD_NOT_ASSIGNED){ thread->job_id = full_job->id; thread->running = 1; - full_job->job.callback(&win32vars.system, - thread, thread_memory, full_job->job.data); + full_job->job.callback(&win32vars.system, thread, thread_memory, full_job->job.data); PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0); //full_job->running_thread = 0; thread->running = 0; @@ -1391,6 +1382,8 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){ #include "4ed_system_shared.cpp" +#include "win32_4ed_fonts.cpp" + // // Linkage to Custom and Application // @@ -1458,7 +1451,6 @@ Win32LoadSystemCode(){ win32vars.system.is_fullscreen = system_is_fullscreen;win32vars.system.show_mouse_cursor = system_show_mouse_cursor; win32vars.system.send_exit_signal = system_send_exit_signal; - #if FRED_INTERNAL win32vars.system.internal_get_thread_states = INTERNAL_get_thread_states; #endif @@ -1469,11 +1461,6 @@ Win32LoadRenderCode(){ win32vars.target.push_clip = draw_push_clip; win32vars.target.pop_clip = draw_pop_clip; win32vars.target.push_piece = draw_push_piece; - -#if 0 - win32vars.target.font_set.font_load = font_load; - win32vars.target.font_set.release_font = draw_release_font; -#endif } // @@ -1518,7 +1505,7 @@ Win32KeycodeInit(){ internal void Win32RedrawScreen(HDC hdc){ - launch_rendering(&win32vars.target); + launch_rendering(&win32vars.system, &win32vars.target); glFlush(); SwapBuffers(hdc); } @@ -2034,11 +2021,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32vars.target.max = MB(1); win32vars.target.push_buffer = (char*)system_get_memory(win32vars.target.max); - if (!memory_vars.vars_memory || !memory_vars.target_memory || !memory_vars.user_memory || !win32vars.target.push_buffer){ + if (memory_vars.vars_memory == 0 || memory_vars.target_memory == 0 || memory_vars.user_memory == 0 || win32vars.target.push_buffer == 0){ exit(1); } - // // System and Application Layer Linkage // @@ -2048,17 +2034,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } Win32LoadSystemCode(); - Win32LoadRenderCode(); - // // Shared Systems Init // init_shared_vars(); - // // Read Command Line // @@ -2082,7 +2065,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS sysshared_filter_real_files(files, file_count); - // // Custom Layer Linkage // @@ -2192,6 +2174,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS Win32InitGL(); Win32Resize(window_rect.right - window_rect.left, window_rect.bottom - window_rect.top); + // + // Font System Init + // + + system_font_init(&win32vars.system.font, 0, 0, 16, true); // // Misc System Initializations diff --git a/win32_4ed_fonts.cpp b/win32_4ed_fonts.cpp index 6464e609..47f23787 100644 --- a/win32_4ed_fonts.cpp +++ b/win32_4ed_fonts.cpp @@ -11,43 +11,124 @@ #include "4ed_system_shared.cpp" #include "font/4coder_font_interface.h" +#include "font/4coder_font_interface_to_os.h" +#include "font/4coder_font_data.h" + +struct Win32_Fonts{ + Partition part; + Render_Font fonts[5]; + u32 font_count; +}; + +global Win32_Fonts win32_fonts = {0}; internal Sys_Font_Get_Count_Sig(system_font_get_count){ - + return(5); } internal Sys_Font_Get_IDs_By_Index_Sig(system_font_get_ids_by_index){ - + b32 result = false; + u32 stop_index = first_index + index_count; + if (stop_index < win32_fonts.font_count){ + result = true; + for (u32 i = first_index; i < stop_index; ++i){ + id_out[i] = i; + } + } + return(result); } internal Sys_Font_Get_Name_By_Index_Sig(system_font_get_name_by_index){ - + u32 length = 0; + if (font_index < win32_fonts.font_count){ + Render_Font *font = &win32_fonts.fonts[font_index]; + char *name = font->name; + u32 name_len = font->name_len; + copy_partial_cs(str_out, str_out_cap, make_string(name, name_len)); + } + return(length); } internal Sys_Font_Get_Name_By_ID_Sig(system_font_get_name_by_id){ - + u32 font_index = font_id; + u32 result = system_font_get_name_by_index(font_index, str_out, str_out_cap); + return(result); } internal Sys_Font_Get_Render_Data_By_ID_Sig(system_font_get_render_data_by_id){ - + Render_Font *result = 0; + u32 font_index = font_id; + if (font_index < win32_fonts.font_count){ + result = &win32_fonts.fonts[font_index]; + } + return(result); +} + +internal +Sys_Font_Load_Page_Sig(system_font_load_page){ + system_set_page(&win32vars.system, &win32_fonts.part, font, page, page_number, 16, true); } internal Sys_Font_Allocate_Sig(system_font_allocate){ - + void *result = system_memory_allocate(size); + return(result); } internal Sys_Font_Free_Sig(system_font_free){ + system_memory_free(ptr, 0); +} + +internal +Sys_Font_Init_Sig(system_font_init){ + 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; + font->get_name_by_id = system_font_get_name_by_id; + font->get_render_data_by_id = system_font_get_render_data_by_id; + font->load_page = system_font_load_page; + font->allocate = system_font_allocate; + font->free = system_font_free; + font_size = clamp_bottom(8, font_size); + + struct Font_Setup{ + 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}, + }; + + 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]; + + 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, pt_size, use_hinting); + } + + win32_fonts.font_count = font_count; } // BOTTOM - - diff --git a/win32_gl.h b/win32_gl.h index 7cc6248b..2ba985ed 100644 --- a/win32_gl.h +++ b/win32_gl.h @@ -79,6 +79,7 @@ wglGetExtensionsStringARB_Function(HDC hdc); typedef void CALL_CONVENTION GLDEBUGPROC_TYPE(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char * message, const GLvoid * userParam); +// TODO(allen): these don't belong here, but the organizational stuff is not fully in place yet. typedef GLDEBUGPROC_TYPE * GLDEBUGPROC; typedef void CALL_CONVENTION glDebugMessageControl_type(GLenum source, GLenum type, GLenum severity, GLsizei count, GLuint * ids, GLboolean enabled);