使用cairo和freetype进行字体布局和渲染
使用cairo和freetype进行字体布局和渲染 |
https://qa.1r1g.com/sf/ask/2568859961/#
以下示例将输入字符串转换为字形,检索其范围并进行渲染:
const char* text = "Hello world";
int fontSize = 14;
cairo_font_face_t* fontFace = ...;// get the scaled font object
cairo_set_font_face(cr, fontFace);
cairo_set_font_size(cr, fontSize);
auto scaled_face = cairo_get_scaled_font(cr);// get glyphs for the text
cairo_glyph_t* glyphs = NULL;
int glyph_count;
cairo_text_cluster_t* clusters = NULL;
int cluster_count;
cairo_text_cluster_flags_t clusterflags;auto stat = cairo_scaled_font_text_to_glyphs(scaled_face, 0, 0, text, strlen(text), &glyphs, &glyph_count, &clusters, &cluster_count,&clusterflags);// check if conversion was successful
if (stat == CAIRO_STATUS_SUCCESS) {// text paints on bottom linecairo_translate(cr, 0, fontSize);// draw each clusterint glyph_index = 0;int byte_index = 0;for (int i = 0; i < cluster_count; i++) {cairo_text_cluster_t* cluster = &clusters[i];cairo_glyph_t* clusterglyphs = &glyphs[glyph_index];// get extents for the glyphs in the clustercairo_text_extents_t extents;cairo_scaled_font_glyph_extents(scaled_face, clusterglyphs, cluster->num_glyphs, &extents);// ... for later use// put paths for current cluster to contextcairo_glyph_path(cr, clusterglyphs, cluster->num_glyphs);// draw black text with green strokecairo_set_source_rgba(cr, 0.2, 0.2, 0.2, 1.0);cairo_fill_preserve(cr);cairo_set_source_rgba(cr, 0, 1, 0, 1.0);cairo_set_line_width(cr, 0.5);cairo_stroke(cr);// glyph/byte positionglyph_index += cluster->num_glyphs;byte_index += cluster->num_bytes;}
}
另外一篇文章:
Cairo 图形指南 (10) —— 文本 - Emerging World
使用cairo和freetype进行字体布局和渲染相关推荐
- 基于嵌入式linux的freetype矢量字体简单显示的实现
一.freetype简介 FreeType库是一个完全免费(开源)的.高质量的且可移植的字体引擎,它提供统一的接口来访问多种字体格式文件,可以非常方便我们开发字体显示相关的程序功能.它支持单色位图.反 ...
- FreeType矢量字体对颜色的显示(妙用)
在网上发现FreeType矢量字体对颜色的显示这类文章较少,这里就给出一个示例代码: show_lines.c #include <sys/mman.h> #include <sys ...
- 用freetype开源字体库,实现在图片上字体大小
掌握truetype字体原理,利用freetype开源字体库,实现在图片上书写一行字体大小变化的诗句(比如首字体增大). 首先,在树莓派上安装freetype: 下载好: 传输文件,并且安装好: 解压 ...
- 使用FreeType绘制字体
不带缓存的FreeType使用 1. 初始化库 FT_Init_FreeType( FT_Library *alibrary ); 2. 通过创建一个新的 face 对象来打开一个字体文件 FT_N ...
- 通过skia/freetype 解析字体获取fontfamily fontstyle name 支持多语言翻译
前言 我们的项目是基于google skia的渲染引擎 然后skia关于文字处理这块 是用的 freetype + harfbuzz 不太清楚的可以先了解下这些库的背景,这里就不说了 怎么解析字体文件 ...
- vue动态加载在线字体,及渲染
字体为后台接口返回,主要参数为字体code,及包地址,添加到头部 /*** @description: 获取字体列表* @param {*}* @return: {*}* @author: */con ...
- Three.js初识:渲染立方体、3d字体、修改渲染背景颜色
用场景对three.js进行渲染:场景.相机.渲染器 const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCame ...
- 深度学习中的遥感影像数据集~持续更新
收集网络上公开的遥感数据集,欢迎补充 以下数据集均为网上开源数据集,若有遗误或不慎涉及侵权,烦请评论或留言联系 目前本项目共整理 场景分类数据集27个(整理完结): 目标检测数据集31+个(整理完结) ...
- FreeType解析矢量字体存在的问题以及优化技巧
目录 一.前言 二.FreeType 存在的问题 三.针对 FreeType 存在问题的优化技巧 3.1 提高 FreeType 解析字体的精度 3.2 关闭 auto\_hint 四.总结 一.前言 ...
最新文章
- c#初学-索引器get和set的使用(泛型类)
- Javascript网页滚动方法
- 百度PARL再度夺冠NeurIPS仿生人挑战赛:强化学习控制的流畅行走
- JMeter中3种参数值的传递
- 闯过这 54 关,点亮你的 Git 技能树 (五) - 完结篇
- python内置类型方法_python基础(一)内置类型及方法
- 仿大众点评下拉菜单实现
- 【长期更新】Linux学习笔记
- 如何在VS中统计项目代码量
- 自制硬盘空间整数计算器,打发时间的无聊之作
- 二进制转十进制python程序_二进制转换(使用Python实现十进制转换器)
- 教你如何卷积操作进行边缘检测,基础必备
- SPEA将出席MWS China 2022
- Excel VBA之类模块 实例
- ESP8266串口wifi模块 NodeMCU Lua V3物联网开发板 CH340上传程序不显示
- 基于C语言实现的多种可视化排序算法演示程序
- qt 之 生成pdf
- jwt生成token与解析token
- Severance:BoD[官方英文版][资源收集分享]
- [Python] openpyxl读存大数据 Exception: String longer than 32767 characters
热门文章
- 【计算机科学】【2019.05】城市街道交叉口三维点云和照片模型的精度分析
- nvme固态硬盘开机慢_解决nvme固态开机慢
- 如何给Word重新排页码
- 贤鱼的刷题日常【c++动态规划】4978:宠物小精灵之收服
- 论文阅读——Segment Medical Image Using U-Net Combining Recurrent Residuals and Attention
- 室内定位:基于NB/LTE Cat.1蜂窝网络的穿戴设备定位 BLE-4
- 细粒度图像分类(FGVC)--- 综述
- 使用python爬取猎聘网的职位信息
- 运行 skimage 报错ImportError: DLL load failed:找不到指定模块
- 每个程序员书柜必备的编程书籍