Skip to content

Commit

Permalink
feat: font alias
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Jan 5, 2025
1 parent 3b658cd commit 9b85ed3
Show file tree
Hide file tree
Showing 6 changed files with 691 additions and 630 deletions.
10 changes: 5 additions & 5 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

- [目录](#%E7%9B%AE%E5%BD%95)
- [介绍](#%E4%BB%8B%E7%BB%8D)
- [主要特性](#%E4%B8%BB%E8%A6%81%E7%89%B9%E6%80%A7)
- [一图速览](#%E4%B8%80%E5%9B%BE%E9%80%9F%E8%A7%88)
- [架构](#%E6%9E%B6%E6%9E%84)
- [主要特性](#%E4%B8%BB%E8%A6%81%E7%89%B9%E6%80%A7)
- [开发体验预览](#%E5%BC%80%E5%8F%91%E4%BD%93%E9%AA%8C%E9%A2%84%E8%A7%88)
- [架构](#%E6%9E%B6%E6%9E%84)
- [快速体验](#%E5%BF%AB%E9%80%9F%E4%BD%93%E9%AA%8C)
- [文档](#%E6%96%87%E6%A1%A3)
- [教程](#%E6%95%99%E7%A8%8B)
- [参考资料](#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99)
- [教程](#%E6%95%99%E7%A8%8B)
- [参考资料](#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99)
- [路线图](#%E8%B7%AF%E7%BA%BF%E5%9B%BE)
- [贡献](#%E8%B4%A1%E7%8C%AE)
- [常见问题](#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)
Expand Down
13 changes: 13 additions & 0 deletions include/LCUI/fonts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#ifndef LCUI_INCLUDE_LCUI_FONTS_H
#define LCUI_INCLUDE_LCUI_FONTS_H

#include "common.h"

LCUI_BEGIN_HEADER

LCUI_API bool lcui_fonts_set_default(const char *family_name);

#define lcui_set_default_font lcui_fonts_set_default

#endif
104 changes: 54 additions & 50 deletions lib/pandagl/include/pandagl/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,65 @@
#include "common.h"

typedef enum pd_font_style_t {
PD_FONT_STYLE_NORMAL,
PD_FONT_STYLE_ITALIC,
PD_FONT_STYLE_OBLIQUE,
PD_FONT_STYLE_TOTAL_NUM
PD_FONT_STYLE_NORMAL,
PD_FONT_STYLE_ITALIC,
PD_FONT_STYLE_OBLIQUE,
PD_FONT_STYLE_TOTAL_NUM
} pd_font_style_t;

typedef enum pd_font_weight_t {
PD_FONT_WEIGHT_NONE,
PD_FONT_WEIGHT_THIN,
PD_FONT_WEIGHT_EXTRA_LIGHT,
PD_FONT_WEIGHT_LIGHT,
PD_FONT_WEIGHT_NORMAL,
PD_FONT_WEIGHT_MEDIUM,
PD_FONT_WEIGHT_SEMI_BOLD,
PD_FONT_WEIGHT_BOLD,
PD_FONT_WEIGHT_EXTRA_BOLD,
PD_FONT_WEIGHT_BLACK,
PD_FONT_WEIGHT_TOTAL_NUM
PD_FONT_WEIGHT_NONE,
PD_FONT_WEIGHT_THIN,
PD_FONT_WEIGHT_EXTRA_LIGHT,
PD_FONT_WEIGHT_LIGHT,
PD_FONT_WEIGHT_NORMAL,
PD_FONT_WEIGHT_MEDIUM,
PD_FONT_WEIGHT_SEMI_BOLD,
PD_FONT_WEIGHT_BOLD,
PD_FONT_WEIGHT_EXTRA_BOLD,
PD_FONT_WEIGHT_BLACK,
PD_FONT_WEIGHT_TOTAL_NUM
} pd_font_weight_t;

typedef struct pd_font_bitmap {
int top; /**< 与顶边框的距离 */
int left; /**< 与左边框的距离 */
int width; /**< 位图宽度 */
int rows; /**< 位图行数 */
int pitch;
uint8_t *buffer; /**< 字体位图数据 */
struct {
int hori_advance, vert_advance;
int bbox_width, bbox_height;
int ascender;
} metrics;
int top; /**< 与顶边框的距离 */
int left; /**< 与左边框的距离 */
int width; /**< 位图宽度 */
int rows; /**< 位图行数 */
int pitch;
uint8_t *buffer; /**< 字体位图数据 */
struct {
int hori_advance, vert_advance;
int bbox_width, bbox_height;
int ascender;
} metrics;
} pd_font_bitmap_t;

typedef struct font_engine font_engine_t;

typedef struct pd_font {
int id; /**< 字体信息ID */
char *style_name; /**< 样式名称 */
char *family_name; /**< 字族名称 */
void *data; /**< 相关数据 */
pd_font_style_t style; /**< 风格 */
pd_font_weight_t weight; /**< 粗细程度 */
font_engine_t *engine; /**< 所属的字体引擎 */
int id; /**< 字体信息ID */
char *style_name; /**< 样式名称 */
char *family_name; /**< 字族名称 */
void *data; /**< 相关数据 */
pd_font_style_t style; /**< 风格 */
pd_font_weight_t weight; /**< 粗细程度 */
font_engine_t *engine; /**< 所属的字体引擎 */
} pd_font_t;

struct font_engine {
char name[64];
int (*open)(const char *, pd_font_t ***);
int (*render)(pd_font_bitmap_t *, unsigned, int, pd_font_t *);
void (*close)(void *);
char name[64];
int (*open)(const char *, pd_font_t ***);
int (*render)(pd_font_bitmap_t *, unsigned, int, pd_font_t *);
void (*close)(void *);
};

PD_BEGIN_DECLS

/** 将字体位图绘制到目标图像上 */
PD_PUBLIC int pd_canvas_mix_font_bitmap(pd_canvas_t *graph, pd_pos_t pos,
const pd_font_bitmap_t *bmp,
pd_color_t color);
const pd_font_bitmap_t *bmp,
pd_color_t color);

PD_PUBLIC char *pd_font_library_get_font_path(const char *name);

Expand All @@ -91,7 +91,7 @@ PD_PUBLIC pd_font_style_t pd_font_library_detect_style(const char *str);

/** 载入字体位图 */
PD_PUBLIC int pd_font_library_render_bitmap(pd_font_bitmap_t *buff, unsigned ch,
int font_id, int pixel_size);
int font_id, int pixel_size);

/** 添加字体族,并返回该字族的ID */
PD_PUBLIC int pd_font_library_add_font(pd_font_t *font);
Expand All @@ -103,8 +103,8 @@ PD_PUBLIC int pd_font_library_add_font(pd_font_t *font);
* @param[in] weight 字体粗细程度,若为值 0,则默认为 PD_FONT_WEIGHT_NORMAL
*/
PD_PUBLIC int pd_font_library_get_font_id(const char *family_name,
pd_font_style_t style,
pd_font_weight_t weight);
pd_font_style_t style,
pd_font_weight_t weight);

/**
* 更新当前字体的粗细程度
Expand All @@ -113,8 +113,8 @@ PD_PUBLIC int pd_font_library_get_font_id(const char *family_name,
* @params[out] new_font_ids 更新字体粗细程度后的字体 id 列表
*/
PD_PUBLIC size_t pd_font_library_update_font_weight(const int *font_ids,
pd_font_weight_t weight,
int **new_font_ids);
pd_font_weight_t weight,
int **new_font_ids);

/**
* 更新当前字体的风格
Expand All @@ -123,8 +123,8 @@ PD_PUBLIC size_t pd_font_library_update_font_weight(const int *font_ids,
* @params[out] new_font_ids 更新字体粗细程度后的字体 id 列表
*/
PD_PUBLIC size_t pd_font_library_update_font_style(const int *font_ids,
pd_font_style_t style,
int **new_font_ids);
pd_font_style_t style,
int **new_font_ids);

/**
* 根据字族名称获取对应的字体 ID 列表
Expand All @@ -135,18 +135,22 @@ PD_PUBLIC size_t pd_font_library_update_font_style(const int *font_ids,
* @return 获取到的字体 ID 的数量
*/
PD_PUBLIC unsigned pd_font_library_query(int **font_ids, pd_font_style_t style,
pd_font_weight_t weight,
const char *const *names);
pd_font_weight_t weight,
const char *const *names);

/** 获取指定字体ID的字体信息 */
PD_PUBLIC pd_font_t *pd_font_library_get_font(int id);

/** 获取默认的字体ID */
PD_PUBLIC int pd_font_library_get_default_font(void);

/** 设定默认的字体 */
/** 设置默认的字体 */
PD_PUBLIC void pd_font_library_set_default_font(int id);

/** 设置字体族的别名 */
PD_PUBLIC bool pd_font_library_set_font_family_alias(const char *alias,
const char *family_name);

/**
* 向字体缓存中添加字体位图
* @param[in] ch 字符码
Expand All @@ -169,7 +173,7 @@ PD_PUBLIC pd_font_bitmap_t *pd_font_library_add_bitmap(
* 空间存储字体位图的拷贝。
*/
PD_PUBLIC int pd_font_library_get_bitmap(unsigned ch, int font_id, int size,
const pd_font_bitmap_t **bmp);
const pd_font_bitmap_t **bmp);

/** 载入字体至数据库中 */
PD_PUBLIC int pd_font_library_load_file(const char *filepath);
Expand Down
Loading

0 comments on commit 9b85ed3

Please sign in to comment.