Use bold for CSD titles
This commit is contained in:
parent
55dc354e68
commit
c5b3e43b6c
@ -77,9 +77,12 @@ cleanup(RenderCtx *ctx) {
|
|||||||
void
|
void
|
||||||
set_main_face_family(FreeTypeRenderCtx ctx_, const char *family, bool bold, bool italic) {
|
set_main_face_family(FreeTypeRenderCtx ctx_, const char *family, bool bold, bool italic) {
|
||||||
RenderCtx *ctx = (RenderCtx*)ctx_;
|
RenderCtx *ctx = (RenderCtx*)ctx_;
|
||||||
if (family == main_face_family.name || (main_face_family.name && strcmp(family, main_face_family.name) == 0)) return;
|
if (
|
||||||
|
(family == main_face_family.name || (main_face_family.name && strcmp(family, main_face_family.name) == 0)) &&
|
||||||
|
main_face_family.bold == bold && main_face_family.italic == italic
|
||||||
|
) return;
|
||||||
cleanup(ctx);
|
cleanup(ctx);
|
||||||
main_face_family.name = strdup(family);
|
main_face_family.name = family ? strdup(family) : NULL;
|
||||||
main_face_family.bold = bold; main_face_family.italic = italic;
|
main_face_family.bold = bold; main_face_family.italic = italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,18 +107,6 @@ load_font(FontConfigFace *info, Face *ans) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
|
||||||
ensure_state(RenderCtx *ctx) {
|
|
||||||
if (main_face.freetype && main_face.hb) return true;
|
|
||||||
if (!information_for_font_family(main_face_family.name, main_face_family.bold, main_face_family.italic, &main_face_information)) return false;
|
|
||||||
if (!load_font(&main_face_information, &main_face)) return false;
|
|
||||||
hb_buffer = hb_buffer_create();
|
|
||||||
if (!hb_buffer) { PyErr_NoMemory(); return false; }
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
font_units_to_pixels_y(FT_Face face, int x) {
|
font_units_to_pixels_y(FT_Face face, int x) {
|
||||||
return (int)ceil((double)FT_MulFix(x, face->size->metrics.y_scale) / 64.0);
|
return (int)ceil((double)FT_MulFix(x, face->size->metrics.y_scale) / 64.0);
|
||||||
@ -375,9 +366,14 @@ end:
|
|||||||
}
|
}
|
||||||
|
|
||||||
FreeTypeRenderCtx
|
FreeTypeRenderCtx
|
||||||
create_freetype_render_context(void) {
|
create_freetype_render_context(const char *family, bool bold, bool italic) {
|
||||||
RenderCtx *ctx = calloc(1, sizeof(RenderCtx));
|
RenderCtx *ctx = calloc(1, sizeof(RenderCtx));
|
||||||
if (!ensure_state(ctx)) { free(ctx); return NULL; }
|
main_face_family.name = family ? strdup(family) : NULL;
|
||||||
|
main_face_family.bold = bold; main_face_family.italic = italic;
|
||||||
|
if (!information_for_font_family(main_face_family.name, main_face_family.bold, main_face_family.italic, &main_face_information)) return false;
|
||||||
|
if (!load_font(&main_face_information, &main_face)) return false;
|
||||||
|
hb_buffer = hb_buffer_create();
|
||||||
|
if (!hb_buffer) { PyErr_NoMemory(); return false; }
|
||||||
ctx->created = true;
|
ctx->created = true;
|
||||||
return (FreeTypeRenderCtx)ctx;
|
return (FreeTypeRenderCtx)ctx;
|
||||||
}
|
}
|
||||||
@ -399,9 +395,8 @@ render_line(PyObject *self UNUSED, PyObject *args, PyObject *kw) {
|
|||||||
PyObject *ans = PyBytes_FromStringAndSize(NULL, width * height * 4);
|
PyObject *ans = PyBytes_FromStringAndSize(NULL, width * height * 4);
|
||||||
if (!ans) return NULL;
|
if (!ans) return NULL;
|
||||||
uint8_t *buffer = (u_int8_t*) PyBytes_AS_STRING(ans);
|
uint8_t *buffer = (u_int8_t*) PyBytes_AS_STRING(ans);
|
||||||
RenderCtx *ctx = (RenderCtx*)create_freetype_render_context();
|
RenderCtx *ctx = (RenderCtx*)create_freetype_render_context(family, bold, italic);
|
||||||
if (!ctx) return NULL;
|
if (!ctx) return NULL;
|
||||||
if (family) set_main_face_family((FreeTypeRenderCtx)ctx, family, bold, italic);
|
|
||||||
if (!render_single_line((FreeTypeRenderCtx)ctx, text, 3 * height / 4, 0, 0xffffffff, buffer, width, height, x_offset, y_offset)) {
|
if (!render_single_line((FreeTypeRenderCtx)ctx, text, 3 * height / 4, 0, 0xffffffff, buffer, width, height, x_offset, y_offset)) {
|
||||||
Py_CLEAR(ans);
|
Py_CLEAR(ans);
|
||||||
if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError, "Unknown error while rendering text");
|
if (!PyErr_Occurred()) PyErr_SetString(PyExc_RuntimeError, "Unknown error while rendering text");
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
typedef struct {bool created;} *FreeTypeRenderCtx;
|
typedef struct {bool created;} *FreeTypeRenderCtx;
|
||||||
|
|
||||||
FreeTypeRenderCtx create_freetype_render_context(void);
|
FreeTypeRenderCtx create_freetype_render_context(const char *family, bool bold, bool italic);
|
||||||
void set_main_face_family(FreeTypeRenderCtx ctx, const char *family, bool bold, bool italic);
|
void set_main_face_family(FreeTypeRenderCtx ctx, const char *family, bool bold, bool italic);
|
||||||
bool render_single_line(FreeTypeRenderCtx ctx, const char *text, unsigned sz_px, uint32_t fg, uint32_t bg, uint8_t *output_buf, size_t width, size_t height, float x_offset, float y_offset);
|
bool render_single_line(FreeTypeRenderCtx ctx, const char *text, unsigned sz_px, uint32_t fg, uint32_t bg, uint8_t *output_buf, size_t width, size_t height, float x_offset, float y_offset);
|
||||||
void release_freetype_render_context(FreeTypeRenderCtx ctx);
|
void release_freetype_render_context(FreeTypeRenderCtx ctx);
|
||||||
|
|||||||
@ -401,7 +401,7 @@ static bool
|
|||||||
draw_text_callback(GLFWwindow *window, const char *text, uint32_t fg, uint32_t bg, uint8_t *output_buf, size_t width, size_t height, float x_offset, float y_offset) {
|
draw_text_callback(GLFWwindow *window, const char *text, uint32_t fg, uint32_t bg, uint8_t *output_buf, size_t width, size_t height, float x_offset, float y_offset) {
|
||||||
if (!set_callback_window(window)) return false;
|
if (!set_callback_window(window)) return false;
|
||||||
if (!csd_title_render_ctx) {
|
if (!csd_title_render_ctx) {
|
||||||
csd_title_render_ctx = create_freetype_render_context();
|
csd_title_render_ctx = create_freetype_render_context(NULL, true, false);
|
||||||
if (!csd_title_render_ctx) {
|
if (!csd_title_render_ctx) {
|
||||||
if (PyErr_Occurred()) PyErr_Print();
|
if (PyErr_Occurred()) PyErr_Print();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user