创建每个屏幕对应的信息条窗口
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
set(LIB_RENDERER "zswm-renderer")
|
||||
set(LIB_RENDERER_NAME ${LIB_RENDERER} PARENT_SCOPE)
|
||||
|
||||
add_library(${LIB_RENDERER} STATIC image.c)
|
||||
add_library(${LIB_RENDERER} STATIC image.c text.c)
|
||||
target_include_directories(${LIB_RENDERER} SYSTEM
|
||||
PRIVATE ${RENDERER_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
35
src/renderer/text.c
Normal file
35
src/renderer/text.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <pango/pango-attributes.h>
|
||||
#include <pango/pango-context.h>
|
||||
#include <pango/pango-font.h>
|
||||
#include <pango/pango-fontmap.h>
|
||||
#include <pango/pango-layout.h>
|
||||
#include <pango/pango-types.h>
|
||||
#include <pango/pangocairo.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
static PangoContext *context = NULL;
|
||||
|
||||
uint32_t get_font_height(const char *font_family, const uint32_t font_size,
|
||||
const uint32_t dpi) {
|
||||
PangoFontMap *fontmap = pango_cairo_font_map_new();
|
||||
context = pango_font_map_create_context(fontmap);
|
||||
pango_cairo_context_set_resolution(context, dpi);
|
||||
PangoLanguage *lang = pango_context_get_language(context);
|
||||
PangoAttrList *attr_list = pango_attr_list_new();
|
||||
|
||||
PangoFontDescription *desc = pango_font_description_from_string(font_family);
|
||||
pango_font_description_set_size(desc, font_size * PANGO_SCALE);
|
||||
PangoAttribute *attr = pango_attr_font_desc_new(desc);
|
||||
pango_attr_list_insert(attr_list, attr);
|
||||
|
||||
PangoFontMetrics *metrics = pango_context_get_metrics(context, desc, lang);
|
||||
int height = PANGO_PIXELS(pango_font_metrics_get_height(metrics));
|
||||
int ascent = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics));
|
||||
int descent = PANGO_PIXELS(pango_font_metrics_get_descent(metrics));
|
||||
printf("height: %d, ad: %d\n", height, ascent + descent);
|
||||
|
||||
return MIN(height, ascent + descent);
|
||||
}
|
||||
Reference in New Issue
Block a user