diff --git a/4ed_rendering.cpp b/4ed_rendering.cpp index d75d947f..45705544 100644 --- a/4ed_rendering.cpp +++ b/4ed_rendering.cpp @@ -305,6 +305,9 @@ launch_rendering(Render_Target *target){ #undef ExtractStruct +// TODO(allen): Put the burden of translation outside +// of this function (and other functions implementing +// the same interface). internal i32 draw_font_load(Partition *part, Render_Font *font_out, diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 35fa94cd..4a96ceb2 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -1166,6 +1166,18 @@ Font_Load_Sig(system_draw_font_load){ #endif for (b32 success = 0; success == 0;){ +#if USE_WIN32_FONTS + + success = win32_draw_font_load(&win32vars.font_part, + font_out, + filename, + pt_size, + tab_width, + oversample, + store_texture); + +#else + success = draw_font_load(&win32vars.font_part, font_out, filename, @@ -1174,6 +1186,8 @@ Font_Load_Sig(system_draw_font_load){ oversample, store_texture); +#endif + // TODO(allen): Make the growable partition something // that can just be passed directly to font load and // let it be grown there. diff --git a/win32_font.cpp b/win32_font.cpp index 901214ef..97ef97b6 100644 --- a/win32_font.cpp +++ b/win32_font.cpp @@ -15,8 +15,55 @@ win32_draw_font_load(Partition *part, char *filename_untranslated, i32 pt_size, i32 tab_width, - i32 oversample){ - i32 result = 1; + i32 oversample, + b32 store_texture){ + + char space_[1024]; + String filename = make_fixed_width_string(space_); + b32 translate_success = sysshared_to_binary_path(&filename, filename_untranslated); + if (!translate_success) return 0; + + i32 result = 0; + + AddFontResourceEx(filename.str, FR_PRIVATE, 0); + + HFONT font_handle = + CreateFontA(pt_size, 0, 0, 0, + FW_NORMAL, // WEIGHT + FALSE, // ITALICS + FALSE, // UNDERLINE + FALSE, // STRIKE-OUT + ANSI_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + ANTIALIASED_QUALITY, + DEFAULT_PITCH|FF_DONTCARE, + filename.str); + + if (font_handle){ + HDC dc = CreateCompatibleDC(0); + + if (dc){ + // TODO(allen): Have to get metrics + + result = 1; + + if (store_texture){ + i32 tex_width = pt_size*16*oversample; + i32 tex_height = pt_size*16*oversample; + + HBITAMP bitmap = CreateCompatibleBitmap(dc, tex_width, tex_height); + + // TODO(allen): pack each glyph into a texture + // and generate the equivalent data output by stb + // in the stbtt_packedchar array. + + } + } + + DeleteObject(font_handle); + } + return(result); }