summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-07-16 15:49:34 -0400
committerpommicket <pommicket@gmail.com>2023-07-16 15:49:34 -0400
commita7b5a9a5584a971f3602fadf2a1a007c4c5c261f (patch)
tree78844fd8af527e2ed92900fb193becf0b1b5ee67
parent3f734cf1eb86fef82c7390df003124565b8a84c6 (diff)
variable width fonts seem to be working
-rw-r--r--main.c9
-rw-r--r--ted.c3
-rw-r--r--text.c8
3 files changed, 11 insertions, 9 deletions
diff --git a/main.c b/main.c
index 4b16e88..371ddee 100644
--- a/main.c
+++ b/main.c
@@ -607,6 +607,15 @@ int main(int argc, char **argv) {
ted_update_window_dimensions(ted);
+
+ {
+ Settings *active_settings = ted_active_settings(ted);
+ // we don't properly handle variable-width fonts
+ text_font_set_force_monospace(ted->font, active_settings->force_monospace);
+ text_font_set_force_monospace(ted->font_bold, active_settings->force_monospace);
+ }
+
+
SDL_Event event;
while (SDL_PollEvent(&event)) {
TextBuffer *buffer = ted->active_buffer;
diff --git a/ted.c b/ted.c
index 865e9fe..f526947 100644
--- a/ted.c
+++ b/ted.c
@@ -294,9 +294,6 @@ static void ted_load_font(Ted *ted, const char *filename, Font **out) {
if (ted_get_file(ted, filename, font_filename, sizeof font_filename)) {
Font *font = text_font_load(font_filename, ted_active_settings(ted)->text_size);
if (font) {
- // we don't properly handle variable-width fonts
- text_font_set_force_monospace(font, true);
-
if (*out) {
text_font_free(*out);
}
diff --git a/text.c b/text.c
index 093c5ec..c869a5e 100644
--- a/text.c
+++ b/text.c
@@ -195,12 +195,8 @@ Font *text_font_load(const char *ttf_filename, float font_size) {
font->char_height = font_size;
font->ttf_data = file_data;
if (text_load_char_page(font, 0)) { // load page with Latin text, etc.
- // calculate width of the character 'a'
- stbtt_aligned_quad q = {0};
- float x = 0, y = 0;
- stbtt_GetBakedQuad(font->char_pages[0], font->tex_widths[0], font->tex_heights[0],
- 'a', &x, &y, &q, 1);
- font->space_width = x;
+ // calculate width of the character ' '
+ font->space_width = font->char_pages[0][' '].xadvance;
}
} else {
text_set_err("Couldn't read font file.");