Class TextStyle

TextStyle class

Specifica lo stile del testo.

public sealed class TextStyle : Style

Costruttori

NomeDescrizione
TextStyle()Default_Costruttore

Proprietà

NomeDescrizione
static Default { get; }Ottiene lo stile con la cultura “en-US”.
static DefaultMsOneNoteTitleDateStyle { get; }Ottiene lo stile predefinito per la data del titolo in MS OneNote.
static DefaultMsOneNoteTitleTextStyle { get; }Ottiene lo stile predefinito per il testo del titolo in MS OneNote.
static DefaultMsOneNoteTitleTimeStyle { get; }Ottiene lo stile predefinito per l’ora del titolo in MS OneNote.
FontColor { get; set; }Ottiene o imposta il colore del carattere.
FontName { get; set; }Ottiene o imposta il nome del font.
FontSize { get; set; }Ottiene o imposta la dimensione del carattere.
FontStyle { get; }Ottiene lo stile del carattere.
Highlight { get; set; }Ottiene o imposta il colore di evidenziazione.
HyperlinkAddress { get; set; }Ottiene o imposta l’indirizzo del collegamento ipertestuale. Deve essere impostato se il valore diIsHyperlink proprietà è true.
IsBold { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è in grassetto.
IsHidden { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è nascosto.
IsHyperlink { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è collegamento ipertestuale.
IsItalic { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è corsivo.
IsMathFormatting { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è di formattazione matematica.
IsStrikethrough { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è barrato.
IsSubscript { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è pedice.
IsSuperscript { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è apice.
IsUnderline { get; set; }Ottiene o imposta un valore che indica se lo stile del testo è sottolineato.
Language { get; set; }Ottiene o imposta la lingua del testo.

Metodi

NomeDescrizione
override Equals(object)Determina se l’oggetto specificato è uguale all’oggetto corrente.
Equals(TextStyle)Determina se l’oggetto specificato è uguale all’oggetto corrente.
override GetHashCode()Funge da funzione hash per il tipo.

Esempi

Mettiamo in risalto i titoli delle pagine tra le altre intestazioni aumentando la dimensione del carattere.

string dataDir = RunExamples.GetDataDir_Text();

// Carica il documento in Aspose.Note.
Document document = new Document(dataDir + "Aspose.one");

// Itera attraverso i titoli della pagina.
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"));

Sottolineiamo le ultime modifiche al testo evidenziando.

string dataDir = RunExamples.GetDataDir_Text();

// Carica il documento in Aspose.Note.
Document document = new Document(dataDir + "Aspose.one");

// Ottieni i nodi RichText modificati la scorsa settimana.
var richTextNodes = document.GetChildNodes<RichText>().Where(e => e.LastModifiedTime >= DateTime.Today.Subtract(TimeSpan.FromDays(7)));

foreach (var node in richTextNodes)
{
    // Imposta il colore di evidenziazione
    node.ParagraphStyle.Highlight = Color.DarkGreen;
    foreach (var run in node.TextRuns)
    {
        // Imposta il colore di evidenziazione
        run.Style.Highlight = Color.DarkSeaGreen;
    }
}

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

Imposta la lingua di correzione per un testo.

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"));

Manipolare in base al formato del testo utilizzando lo stile di paragrafo.

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"));

Mostra come associare un collegamento ipertestuale a un testo.

// Il percorso della directory dei documenti.
string dataDir = RunExamples.GetDataDir_Tasks();

// Crea un oggetto della classe Document
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);

// Aggiungi elementi di contorno
outline.AppendChildLast(outlineElem);

// Inizializza l'oggetto della classe Title
Title title = new Title() { TitleText = titleText };

// Inizializza l'oggetto della classe Page
Page page = new Note.Page() { Title = title };

// Aggiungi nodo Struttura
page.AppendChildLast(outline);

// Aggiungi nodo Pagina
doc.AppendChildLast(page);

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

Guarda anche