29 #include "ascension/context.h" |
29 #include "ascension/context.h" |
30 #include "ascension/filesystem.h" |
30 #include "ascension/filesystem.h" |
31 #include "ascension/ui/font.h" |
31 #include "ascension/ui/font.h" |
32 |
32 |
33 #include <assert.h> |
33 #include <assert.h> |
|
34 #include <math.h> |
34 #include <cx/array_list.h> |
35 #include <cx/array_list.h> |
35 |
36 |
36 void asc_font(enum AscFontStyle style, int size) { |
37 void asc_font(enum AscFontStyle style, int size) { |
37 asc_context.active_font.style = style; |
38 asc_context.active_font.style = style; |
38 asc_context.active_font.size = size; |
39 asc_context.active_font.size = size; |
78 assert(asc_font_cache != NULL); |
79 assert(asc_font_cache != NULL); |
79 cxListFree(asc_font_cache); |
80 cxListFree(asc_font_cache); |
80 } |
81 } |
81 |
82 |
82 TTF_Font *asc_font_load(AscFont font) { |
83 TTF_Font *asc_font_load(AscFont font) { |
|
84 // apply the UI scaling factor first to get the actual font size |
|
85 if (asc_context.ui_scale != 1.f) { |
|
86 font.size = (int) roundf((float) font.size * asc_context.ui_scale); |
|
87 } |
|
88 |
83 CxIterator iter = cxListIterator(asc_font_cache); |
89 CxIterator iter = cxListIterator(asc_font_cache); |
84 cx_foreach(struct asc_font_cache_entry*, cache, iter) { |
90 cx_foreach(struct asc_font_cache_entry*, cache, iter) { |
85 if (cache->font.style == font.style && cache->font.size == font.size) { |
91 if (cache->font.style == font.style && cache->font.size == font.size) { |
86 return cache->ttf; |
92 return cache->ttf; |
87 } |
93 } |