如何为文本添加文本轮廓效果

This article was translated from English: Does it need improvement?
Translated
View the article in English

文字轮廓效果可在文字字符周围添加一个可见的边框,形成一个明确的轮廓,增强可读性或视觉效果。这种效果可以根据设计偏好定制颜色、粗细和样式。它常用于图形、排版和数字设计中,使文字在背景中脱颖而出,或创造出风格化的外观。

适用于的C# NuGet库

安装使用 NuGet

Install-Package IronWord
适用于的C# NuGet库

安装使用 NuGet

Install-Package IronWord
Java PDF JAR

下载 DLL

下载DLL

手动安装到你的项目中

开始在您的项目中使用IronPDF,并立即获取免费试用。

第一步:
green arrow pointer

查看 IronWordNuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变。

适用于的C# NuGet库 nuget.org/packages/IronWord/
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")
VB   C#
添加文本轮廓效果

文本轮廓效果属性

文本轮廓效果提供多种可定制的属性,以满足任何设计需求。下面是这些属性及其说明:

  • 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")
VB   C#
自定义文字轮廓效果