且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法更改粗体文字颜色,仍保留“黑色边框"

更新时间:2023-10-31 23:12:16

字体程序包含绘制一组字形所需的所有路径构造运算符.当您使用字体中的字形时,这些绘制指令将与路径绘制运算符一起执行.默认情况下,路径绘制运算符是填充"运算符.没有绘制边框,仅使用当前的填充颜色填充形状.这称为默认的渲染模式.

A font program contains all the path construction operators that are needed to draw a set of glyphs. When you use a glyph from a font, these drawing instructions are executed along with a path painting operator. By default, the path painting operator is a "fill" operator. No borders are drawn, the shape is just filled using the current fill color. This is called the default render mode.

其他渲染模式例如是笔触",它使用当前笔触颜色绘制字形的轮廓,但不填充它.或填充和笔触"使用默认的笔触颜色绘制轮廓,并使用默认的填充色填充路径.还有一种渲染模式不可见",在这种情况下,不会触碰任何东西,也不会填充任何东西.

Other rendermodes are for instance "stroke" which draws the outlines of the glyph using the current stroke color, but doesn't fill it. Or "fill and stroke" which draws the outlines using the default stroke color and fills the path using the default fill color. There's also a render mode "invisible" in which case nothing is stroked, nothing is filled.

查看您的图像,似乎使用的渲染模式将字形填充为灰色,并使用黑色对其进行描边(并且线宽似乎很粗).如果我不得不猜测,我会说您正在尝试模仿粗体".以粗体显示文本的***方法是从常规字体(例如arial.ttf)切换为粗体(例如arialbd.ttf).不幸的是,并非每种字体都有粗体(例如,有arialuni.ttf,但没有arialunibd.ttf).在这种情况下,通过将渲染模式更改为填充和描边"来模仿粗体,并更改线宽以使字形具有粗体外观.这可能就是您的情况.

Looking at your image, it seems like the render mode that is used fills the glyph in gray and strokes it using black (and the line width seems to be quite thick). If I had to guess, I'd say that you're trying to mimic "bold". The best way to draw text in bold, is to switch from a regular font (e.g. arial.ttf) to a bold font (e.g. arialbd.ttf). Unfortunately, not every font has a bold counterpart (e.g. there's arialuni.ttf, but no arialunibd.ttf). In that case, bold is mimicked by changing the render mode to "fill and stroke" and the line width is changed to give the glyphs a bold appearance. This could be what is happening in your case.

检查您的HTML:您有没有机会谈论粗体字?如果是这样,也许您应该更改字体以及颜色.这样,您将使用 true 粗体字体而不是 pseudo 假字体.

Check your HTML: are you by any chance talking about text that is in bold? If so, maybe you should change the font along with the color. That way, you'll use a true bold font instead of a pseudo false font.

免责声明::我不知道飞碟,也不想知道.飞碟正在使用iText生成PDF. iText是我编写的一个库,但是Flying Saucer在使用它时并未与我经营的iText Group NV建立业务关系.因此,飞碟的创建者有责任支持他们的软件.

DISCLAIMER: I don't know Flying Saucer and I don't want to know it. Flying Saucer is using iText for PDF generation. iText is a library I wrote, but Flying Saucer is using it without having established a business relationship with iText Group NV, which is a company I run. Hence it's the responsibility of the creators of Flying Saucer to support their software.