如何为文本添加文本轮廓效果
文字轮廓效果可在文字字符周围添加一个可见的边框,形成一个明确的轮廓,增强可读性或视觉效果。这种效果可以根据设计偏好定制颜色、粗细和样式。它常用于图形、排版和数字设计中,使文字在背景中脱颖而出,或创造出风格化的外观。
如何为文本添加文本轮廓效果
- 下载一个 C# 库,为文本添加文字轮廓
- 将文字效果应用于新创建或现有文字
- 的静态命名实例,应用预设的文字轮廓效果。 文本轮廓效果 类
- 配置 文本轮廓效果 属性来实现自定义文本轮廓
- 将编辑过的 Word 文档导出为新文件
安装使用 NuGet
Install-Package IronWord
开始在您的项目中使用IronPDF,并立即获取免费试用。
查看 IronWord 上 Nuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变。
Install-Package IronWord
添加文本轮廓效果
要为文本指定文本轮廓效果,请创建TextStyle对象,并在 TextOutlineEffect 属性中填入一个TextOutlineEffect对象。最后,通过将 TextStyle 对象赋值给 TextEffect 属性,添加具有该样式的新文本。
:path=/static-assets/word/content-code-examples/how-to/text-effect-text-outline-effect.cs
using IronWord;
using IronWord.Models;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
TextOutlineEffect = TextOutlineEffect.DefaultEffect,
};
// Add text with style
doc.AddText("Hello World").Style = textStyle;
// Export new Word document
doc.SaveAs("textOutlineEffect.docx");
Imports IronWord
Imports IronWord.Models
' Create new Word document
Private doc As New WordDocument()
' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {.TextOutlineEffect = TextOutlineEffect.DefaultEffect}
' Add text with style
doc.AddText("Hello World").Style = textStyle
' Export new Word document
doc.SaveAs("textOutlineEffect.docx")
文本轮廓效果属性
文本轮廓效果提供多种可定制的属性,以满足任何设计需求。下面是这些属性及其说明:
- PenAlignment:获取或设置用于轮廓效果的笔的对齐方式。
- LineCapType:获取或设置用于轮廓效果的线帽类型。
- LineWidth:获取或设置轮廓效果线的宽度。 (备注宽度以点为单位 (1/72 英寸).)
- 复合线类型:获取或设置用于轮廓效果的复合线类型。
- LineJoin:获取或设置轮廓效果所使用的线条连接样式。
**颜色***:获取或设置轮廓效果的实心填充颜色。
- presetLineDash:获取或设置轮廓效果的预设破折号线样式。
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-text-outline-effect.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Create new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
TextOutlineEffect = new TextOutlineEffect()
{
Color = IronWord.Models.Color.Red,
CompoundLineType = CompoundLineValues.Double,
LineCapType = LineCapValues.Round,
LineJoin = StrokeJoinStyleValues.Bevel,
LineWidth = 0.3,
PenAlignment = PenAlignmentValues.Center,
presetLineDash = PresetLineDashValues.Solid
},
};
// Add text with style
doc.AddText("Customized text outline").Style = textStyle;
// Export new Word document
doc.SaveAs("customizedTextOutlineEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Create new Word document
Private doc As New WordDocument()
' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
.TextOutlineEffect = New TextOutlineEffect() With {
.Color = IronWord.Models.Color.Red,
.CompoundLineType = CompoundLineValues.Double,
.LineCapType = LineCapValues.Round,
.LineJoin = StrokeJoinStyleValues.Bevel,
.LineWidth = 0.3,
.PenAlignment = PenAlignmentValues.Center,
.presetLineDash = PresetLineDashValues.Solid
}
}
' Add text with style
doc.AddText("Customized text outline").Style = textStyle
' Export new Word document
doc.SaveAs("customizedTextOutlineEffect.docx")