如何使字形粗体使用freetype库
How to make glyph bold using freetype library?
我一直在使用字形,我知道要使一些字体加粗,你必须加载该字体的加粗版本。但我想要实现的是使常规字体加粗使用自由类型。我已经使用FT_TRANSFORM实现了斜体样式,现在我想把它变成粗体。什么好主意吗?这可能吗?我已经阅读了FreeType API参考指南,但没有找到幸运!关于
为了模拟粗体,您可以将相同的字形打印两次,偏移1 px。虽然我不认为你会得到完美的结果,但至少有些东西。
我知道这是一个很老的问题。
SFML代码显示了如何做到这一点:https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/Font.cpp L558
重要的位似乎是FT_Outline_Embolden和FT_Bitmap_Embolden函数
我以前写过。在这里我添加了一行用于二次打印,使字母像@c-smile提到的那样加粗。我不推荐这样的把戏。如果有一个标准的方法,那就更好了。
void DrawFTGlyph(FT_Bitmap* pBitmap, int x, int y)
{
int i, j, p, q;
int xMax = x + pBitmap->width;
int yMax = y + pBitmap->rows;
D3DXCOLOR color = D3DCOLOR_RGBA(255, 255, 255, 1);
for (i = x, p = 0; i < xMax; i++, p++)
{
for (j = y, q = 0; j < yMax; j++, q++)
{
if (i < 0 || j < 0 ||
i >= texture.Size().Width() ||
j >= texture.Size().Height())
{
continue;
}
BYTE intensity = pBitmap->buffer[q * pBitmap->pitch + p];
D3DXCOLOR pixel(color.r * intensity, color.g * intensity, color.b * intensity, color.a * intensity);
texture.SetPixel(i, j, pixel);
texture.SetPixel(i + 2, j + 2, pixel); // Second print
}
}
}
相关文章:
- 如何在 C 中正确使用 libiconv 使其不会报告"Arg list too long"?
- std::vector的包装器,使数组的结构看起来像结构的数组
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 如何在全屏模式下(在OpenGL中)使背景透明
- 找到两对数字,使它们的乘积的绝对差最小化
- C++:如何使函数只返回作为列表一部分的字符串
- Python中的for循环与C++有何不同
- c++使用foreach使数组为null
- 使外部项目可用于find_package CMake
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 是否可以在C++中使变量真正只读
- 有可能使shared_ptr协变吗
- 使lambda不可复制/不可移动
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 如何使用OpenMP使这个循环并行
- 根据变量使Qt UI中的复选框为已选中/未选中
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- 如何编译Freetype(2)和Harfbuzz(带有Visual studio)使它们协同工作?
- 如何使字形粗体使用freetype库
- C++11编译器何时会使RVO和NRVO优于移动语义和常量引用绑定