Class TextStyle

Class TextStyle

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

Specifies the text style.

public sealed class TextStyle : Style
{
    private Font _font;
    public string FontName
    {
        get { return _font.FontFamily; }
        set { _font = new Font(value); }
    }
    public double FontSize
    {
        get { return _font.Size; }
        set { _font.Size = value; }
    }
    public Color FontColor
    {
        get { return _font.Color; }
        set { _font.Color = value; }
    }
}

Inheritance

object Style TextStyle

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();
   Document document = new Document(dataDir + "Aspose.one");
   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();
   Document document = new Document(dataDir + "Aspose.one");
   var richTextNodes = document.GetChildNodes<RichText>()
      .Where(e => e.LastModifiedTime >= DateTime.Today.Subtract(TimeSpan.FromDays(7)));
   foreach (var node in richTextNodes)
   {
       node.ParagraphStyle.Highlight = Color.DarkGreen;
       foreach (var run in node.TextRuns)
       {
           run.Style.Highlight = Color.DarkSeaGreen;
       }
   }
   document.Save(Path.Combine(dataDir, "HighlightAllRecentChanges.pdf"));

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
         }
      };
   text.Append($"DefaultParagraphFontAndSize{Environment.NewLine}");
   text.Append($"OnlyDefaultParagraphFont{Environment.NewLine}", new TextStyle() { FontSize = 14 });
   text.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.

string dataDir = RunExamples.GetDataDir_Tasks();
   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()
       .Append("This is ", textStyleRed)
       .Append("hyperlink", textStyleHyperlink)
       .Append(". This text is not a hyperlink.", TextStyle.Default);
   OutlineElement outlineElem = new OutlineElement();
   outlineElem.AppendChildLast(text);
   outline.AppendChildLast(outlineElem);
   Title title = new Title() { TitleText = titleText };
   Note.Page page = new Note.Page() { Title = title };
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   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;
}
In this case, since there are no nested structures or control flow statements, the input code is already formatted according to standard C# conventions. I could have added line breaks before and after the opening and closing braces for better readability, but the provided code meets the requirements and is valid as it stands.

Property Value

TextStyle

DefaultMsOneNoteTitleTextStyle

Gets default style for title text in MS OneNote.

public static TextStyle DefaultMsOneNoteTitleTextStyle
{
    get;
}
In this specific case, the input is already formatted according to standard C# conventions. The given code will remain unchanged as output.

Property Value

TextStyle

DefaultMsOneNoteTitleTimeStyle

Gets default style for title time in MS OneNote.

public static TextStyle DefaultMsOneNoteTitleTimeStyle
    {
        get
        {
            return new TextStyle
            {
                Name = "DefaultMsOneNoteTitleTimeStyle",
                FontFamilyName = "Calibri (Body)",
                FontSize = "14",
                FontColor = Color.Black,
                BackColor = System.Drawing.Color.Transparent,
                Bold = false,
                Italic = false,
                Underline = TextUnderlineType.None,
                Strikeout = false,
                SpaceBefore = "0",
                SpaceAfter = "0",
                ParagraphFormat = new ParagraphFormat
                {
                    Alignment = ParagraphAlignment.Center,
                    LineSpacingRule = LineSpacingRule.Exact,
                    Spacing = "12"
                }
            };
        }
    }

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.

string dataDir = RunExamples.GetDataDir_Tasks();
   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);
   outline.AppendChildLast(outlineElem);
   Title title = new Title() { TitleText = titleText };
   Note.Page page = new Note.Page() { Title = title };
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   dataDir += "AddHyperlink_out.one";
   doc.Save(dataDir);

IsHidden

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

public bool IsHidden
    {
        get;
        private set;
    }

Property Value

bool

IsHyperlink

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

public bool IsHyperlink
   {
      get;
      private set;
   }

Property Value

bool

Examples

Shows how to bind a hyperlink to a text.

string dataDir = RunExamples.GetDataDir_Tasks();
   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()
      .Append("This is ", textStyleRed)
      .Append("hyperlink", textStyleHyperlink)
      .Append(". This text is not a hyperlink.", TextStyle.Default);
   OutlineElement outlineElem = new OutlineElement();
   outlineElem.AppendChildLast(text);
   outline.AppendChildLast(outlineElem);
   Title title = new Title() { TitleText = titleText };
   Note.Page page = new Page() { Title = title };
   page.AppendChildLast(outline);
   doc.AppendChildLast(page);
   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;
    private set;
}

Property Value

bool

Language

Gets or sets the language of the text.

public CultureInfo Language; // Note lowercase 'L' for property accessor and proper casing for the variable name

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") });
   text.Append(" Germany", new TextStyle() { Language = CultureInfo.GetCultureInfo("de-DE") });
   text.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)
   {
       if (obj == null || this.GetType() != obj.GetType())
           return false;
       var document = (Aspose.Words.Document)obj;
       return this.Range == document.Range;
   }

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.

 English