Class TextStyle

Class TextStyle

Namespace: Aspose.Note
Assembly: Aspose.Note.dll (25.3.0)

Specifies the text style.

public sealed class TextStyle : Style

Inheritance

objectStyleTextStyle

Inherited Members

Style.GetHashCode(), Style.IsBold, Style.IsItalic, Style.IsUnderline, Style.IsStrikethrough, Style.IsSuperscript, Style.IsSubscript, Style.FontName, Style.FontSize, Style.FontColor, Style.Highlight, Style.FontStyle, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

Let’s emphasize page’s titles among other headers by increasing font’s size.

string dataDir = RunExamples.GetDataDir_Text();

                                                                                       // Load the document into Aspose.Note.
                                                                                       Document document = new Document(dataDir + "Aspose.one");

                                                                                       // Iterate through page's titles.
                                                                                       foreach (var title in document.Select(e => e.Title.TitleText))
                                                                                       {
                                                                                           title.ParagraphStyle.FontSize = 24;
                                                                                           title.ParagraphStyle.IsBold = true;

                                                                                           foreach (var run in title.TextRuns)
                                                                                           {
                                                                                               run.Style.FontSize = 24;
                                                                                               run.Style.IsBold = true;
                                                                                           }
                                                                                       }

                                                                                       document.Save(Path.Combine(dataDir, "ChangePageTitleStyle.pdf"));

Let’s emphasize latest text’s changes by highlighting.

string dataDir = RunExamples.GetDataDir_Text();

                                                                 // Load the document into Aspose.Note.
                                                                 Document document = new Document(dataDir + "Aspose.one");

                                                                 // Get RichText nodes modified last week.
                                                                 var richTextNodes = document.GetChildNodes<richtext>().Where(e =&gt; e.LastModifiedTime &gt;= DateTime.Today.Subtract(TimeSpan.FromDays(7)));

                                                                 foreach (var node in richTextNodes)
                                                                 {
                                                                     // Set highlight color
                                                                     node.ParagraphStyle.Highlight = Color.DarkGreen;
                                                                     foreach (var run in node.TextRuns)
                                                                     {
                                                                         // Set highlight color
                                                                         run.Style.Highlight = Color.DarkSeaGreen;
                                                                     }
                                                                 }

                                                                 document.Save(Path.Combine(dataDir, "HighlightAllRecentChanges.pdf"));</richtext>

Set proofing language for a text.

var document = new Document();
                                            var page = new Page();
                                            var outline = new Outline();
                                            var outlineElem = new OutlineElement();

                                            var text = new RichText() { ParagraphStyle = ParagraphStyle.Default };
                                            text.Append("United States", new TextStyle() { Language = CultureInfo.GetCultureInfo("en-US") })
                                                .Append(" Germany", new TextStyle() { Language = CultureInfo.GetCultureInfo("de-DE") })
                                                .Append(" China", new TextStyle() { Language = CultureInfo.GetCultureInfo("zh-CN") });

                                            outlineElem.AppendChildLast(text);
                                            outline.AppendChildLast(outlineElem);
                                            page.AppendChildLast(outline);
                                            document.AppendChildLast(page);

                                            document.Save(Path.Combine(RunExamples.GetDataDir_Text(), "SetProofingLanguageForText.one"));

Manipulate by text format using paragraph style.

var document = new Document();
                                                           var page = new Page();
                                                           var outline = new Outline();
                                                           var outlineElem = new OutlineElement();

                                                           var text = new RichText() { ParagraphStyle = new ParagraphStyle() { FontName = "Courier New", FontSize = 20 } }
                                                                           .Append($"DefaultParagraphFontAndSize{Environment.NewLine}")
                                                                           .Append($"OnlyDefaultParagraphFont{Environment.NewLine}", new TextStyle() { FontSize = 14 })
                                                                           .Append("OnlyDefaultParagraphFontSize", new TextStyle() { FontName = "Verdana" });

                                                           outlineElem.AppendChildLast(text);
                                                           outline.AppendChildLast(outlineElem);
                                                           page.AppendChildLast(outline);
                                                           document.AppendChildLast(page);

                                                           document.Save(Path.Combine(RunExamples.GetDataDir_Text(), "SetDefaultParagraphStyle.one"));

Shows how to bind a hyperlink to a text.

// The path to the documents directory.
                                                   string dataDir = RunExamples.GetDataDir_Tasks();

                                                   // Create an object of the Document class
                                                   Document doc = new Document();

                                                   RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");

                                                   Outline outline = new Outline()
                                                                         {
                                                                             MaxWidth = 200,
                                                                             MaxHeight = 200,
                                                                             VerticalOffset = 100,
                                                                             HorizontalOffset = 100
                                                                         };

                                                   TextStyle textStyleRed = new TextStyle
                                                                                {
                                                                                    FontColor = Color.Red,
                                                                                    FontName = "Arial",
                                                                                    FontSize = 10,
                                                                                };

                                                   TextStyle textStyleHyperlink = new TextStyle
                                                                                      {
                                                                                          IsHyperlink = true,
                                                                                          HyperlinkAddress = "www.google.com"
                                                                                      };

                                                   RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
                                                                       .Append("This is ", textStyleRed)
                                                                       .Append("hyperlink", textStyleHyperlink)
                                                                       .Append(". This text is not a hyperlink.", TextStyle.Default);

                                                   OutlineElement outlineElem = new OutlineElement();
                                                   outlineElem.AppendChildLast(text);

                                                   // Add outline elements
                                                   outline.AppendChildLast(outlineElem);

                                                   // Initialize Title class object
                                                   Title title = new Title() { TitleText = titleText };

                                                   // Initialize Page class object
                                                   Page page = new Note.Page() { Title = title };

                                                   // Add Outline node
                                                   page.AppendChildLast(outline);

                                                   // Add Page node
                                                   doc.AppendChildLast(page);

                                                   // Save OneNote document
                                                   dataDir = dataDir + "AddHyperlink_out.one";
                                                   doc.Save(dataDir);

Constructors

TextStyle()

public TextStyle()

Properties

Default

Gets the style with “en-US” culture.

public static TextStyle Default { get; }

Property Value

TextStyle

DefaultMsOneNoteTitleDateStyle

Gets default style for title date in MS OneNote.

public static TextStyle DefaultMsOneNoteTitleDateStyle { get; }

Property Value

TextStyle

DefaultMsOneNoteTitleTextStyle

Gets default style for title text in MS OneNote.

public static TextStyle DefaultMsOneNoteTitleTextStyle { get; }

Property Value

TextStyle

DefaultMsOneNoteTitleTimeStyle

Gets default style for title time in MS OneNote.

public static TextStyle DefaultMsOneNoteTitleTimeStyle { get; }

Property Value

TextStyle

HyperlinkAddress

Gets or sets the hyperlink address. Must be set if the value of the Aspose.Note.TextStyle.IsHyperlink property is true.

public string HyperlinkAddress { get; set; }

Property Value

string

Examples

Shows how to bind a hyperlink to a text.

// The path to the documents directory.
                                                   string dataDir = RunExamples.GetDataDir_Tasks();

                                                   // Create an object of the Document class
                                                   Document doc = new Document();

                                                   RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");

                                                   Outline outline = new Outline()
                                                                         {
                                                                             MaxWidth = 200,
                                                                             MaxHeight = 200,
                                                                             VerticalOffset = 100,
                                                                             HorizontalOffset = 100
                                                                         };

                                                   TextStyle textStyleRed = new TextStyle
                                                                                {
                                                                                    FontColor = Color.Red,
                                                                                    FontName = "Arial",
                                                                                    FontSize = 10,
                                                                                };

                                                   TextStyle textStyleHyperlink = new TextStyle
                                                                                      {
                                                                                          IsHyperlink = true,
                                                                                          HyperlinkAddress = "www.google.com"
                                                                                      };

                                                   RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
                                                                       .Append("This is ", textStyleRed)
                                                                       .Append("hyperlink", textStyleHyperlink)
                                                                       .Append(". This text is not a hyperlink.", TextStyle.Default);

                                                   OutlineElement outlineElem = new OutlineElement();
                                                   outlineElem.AppendChildLast(text);

                                                   // Add outline elements
                                                   outline.AppendChildLast(outlineElem);

                                                   // Initialize Title class object
                                                   Title title = new Title() { TitleText = titleText };

                                                   // Initialize Page class object
                                                   Page page = new Note.Page() { Title = title };

                                                   // Add Outline node
                                                   page.AppendChildLast(outline);

                                                   // Add Page node
                                                   doc.AppendChildLast(page);

                                                   // Save OneNote document
                                                   dataDir = dataDir + "AddHyperlink_out.one";
                                                   doc.Save(dataDir);

IsHidden

Gets or sets a value indicating whether the text style is hidden.

public bool IsHidden { get; set; }

Property Value

bool

IsHyperlink

Gets or sets a value indicating whether the text style is hyperlink.

public bool IsHyperlink { get; set; }

Property Value

bool

Examples

Shows how to bind a hyperlink to a text.

// The path to the documents directory.
                                                   string dataDir = RunExamples.GetDataDir_Tasks();

                                                   // Create an object of the Document class
                                                   Document doc = new Document();

                                                   RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");

                                                   Outline outline = new Outline()
                                                                         {
                                                                             MaxWidth = 200,
                                                                             MaxHeight = 200,
                                                                             VerticalOffset = 100,
                                                                             HorizontalOffset = 100
                                                                         };

                                                   TextStyle textStyleRed = new TextStyle
                                                                                {
                                                                                    FontColor = Color.Red,
                                                                                    FontName = "Arial",
                                                                                    FontSize = 10,
                                                                                };

                                                   TextStyle textStyleHyperlink = new TextStyle
                                                                                      {
                                                                                          IsHyperlink = true,
                                                                                          HyperlinkAddress = "www.google.com"
                                                                                      };

                                                   RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
                                                                       .Append("This is ", textStyleRed)
                                                                       .Append("hyperlink", textStyleHyperlink)
                                                                       .Append(". This text is not a hyperlink.", TextStyle.Default);

                                                   OutlineElement outlineElem = new OutlineElement();
                                                   outlineElem.AppendChildLast(text);

                                                   // Add outline elements
                                                   outline.AppendChildLast(outlineElem);

                                                   // Initialize Title class object
                                                   Title title = new Title() { TitleText = titleText };

                                                   // Initialize Page class object
                                                   Page page = new Note.Page() { Title = title };

                                                   // Add Outline node
                                                   page.AppendChildLast(outline);

                                                   // Add Page node
                                                   doc.AppendChildLast(page);

                                                   // Save OneNote document
                                                   dataDir = dataDir + "AddHyperlink_out.one";
                                                   doc.Save(dataDir);

IsMathFormatting

Gets or sets a value indicating whether the text style is math-formatting.

public bool IsMathFormatting { get; set; }

Property Value

bool

Language

Gets or sets the language of the text.

public CultureInfo Language { get; set; }

Property Value

CultureInfo

Examples

Set proofing language for a text.

var document = new Document();
                                            var page = new Page();
                                            var outline = new Outline();
                                            var outlineElem = new OutlineElement();

                                            var text = new RichText() { ParagraphStyle = ParagraphStyle.Default };
                                            text.Append("United States", new TextStyle() { Language = CultureInfo.GetCultureInfo("en-US") })
                                                .Append(" Germany", new TextStyle() { Language = CultureInfo.GetCultureInfo("de-DE") })
                                                .Append(" China", new TextStyle() { Language = CultureInfo.GetCultureInfo("zh-CN") });

                                            outlineElem.AppendChildLast(text);
                                            outline.AppendChildLast(outlineElem);
                                            page.AppendChildLast(outline);
                                            document.AppendChildLast(page);

                                            document.Save(Path.Combine(RunExamples.GetDataDir_Text(), "SetProofingLanguageForText.one"));

Remarks

Returns System.Globalization.CultureInfo.InvariantCulture if the property is not set.

Methods

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The object.

Returns

bool

The System.Boolean.

Equals(TextStyle)

Determines whether the specified object is equal to the current object.

public bool Equals(TextStyle other)

Parameters

other TextStyle

The object.

Returns

bool

The System.Boolean.

GetHashCode()

Serves as a hash function for the type.

public override int GetHashCode()

Returns

int

The System.Int32.