Class TextStyle

TextStyle class

Especifica el estilo del texto.

public sealed class TextStyle : Style

Constructores

NombreDescripción
TextStyle()Constructor predeterminado

Propiedades

NombreDescripción
static Default { get; }Obtiene el estilo con cultura “en-US”.
static DefaultMsOneNoteTitleDateStyle { get; }Obtiene el estilo predeterminado para la fecha del título en MS OneNote.
static DefaultMsOneNoteTitleTextStyle { get; }Obtiene el estilo predeterminado para el texto del título en MS OneNote.
static DefaultMsOneNoteTitleTimeStyle { get; }Obtiene el estilo predeterminado para la hora del título en MS OneNote.
FontColor { get; set; }Obtiene o establece el color de la fuente.
FontName { get; set; }Obtiene o establece el nombre de la fuente.
FontSize { get; set; }Obtiene o establece el tamaño de fuente.
FontStyle { get; }Obtiene el estilo de fuente.
Highlight { get; set; }Obtiene o establece el color de resaltado.
HyperlinkAddress { get; set; }Obtiene o establece la dirección del hipervínculo. Debe establecerse si el valor de laIsHyperlink la propiedad es verdadera.
IsBold { get; set; }Obtiene o establece un valor que indica si el estilo de texto está en negrita.
IsHidden { get; set; }Obtiene o establece un valor que indica si el estilo de texto está oculto.
IsHyperlink { get; set; }Obtiene o establece un valor que indica si el estilo de texto es hipervínculo.
IsItalic { get; set; }Obtiene o establece un valor que indica si el estilo del texto es cursiva.
IsMathFormatting { get; set; }Obtiene o establece un valor que indica si el estilo de texto tiene formato matemático.
IsStrikethrough { get; set; }Obtiene o establece un valor que indica si el estilo de texto es tachado.
IsSubscript { get; set; }Obtiene o establece un valor que indica si el estilo de texto es subíndice.
IsSuperscript { get; set; }Obtiene o establece un valor que indica si el estilo de texto es superíndice.
IsUnderline { get; set; }Obtiene o establece un valor que indica si el estilo de texto es subrayado.
Language { get; set; }Obtiene o establece el idioma del texto.

Métodos

NombreDescripción
override Equals(object)Determina si el objeto especificado es igual al objeto actual.
Equals(TextStyle)Determina si el objeto especificado es igual al objeto actual.
override GetHashCode()Sirve como función hash para el tipo.

Ejemplos

Destaquemos los títulos de las páginas entre otros encabezados aumentando el tamaño de la fuente.

string dataDir = RunExamples.GetDataDir_Text();

// Cargue el documento en Aspose.Note.
Document document = new Document(dataDir + "Aspose.one");

// Iterar a través de los títulos de la página.
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"));

Resaltemos los últimos cambios del texto resaltando.

string dataDir = RunExamples.GetDataDir_Text();

// Cargue el documento en Aspose.Note.
Document document = new Document(dataDir + "Aspose.one");

// Obtenga los nodos RichText modificados la semana pasada.
var richTextNodes = document.GetChildNodes<RichText>().Where(e => e.LastModifiedTime >= DateTime.Today.Subtract(TimeSpan.FromDays(7)));

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

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

Establecer el idioma de prueba para un texto.

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

Manipular por formato de texto usando estilo de párrafo.

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

Muestra cómo vincular un hipervínculo a un texto.

// La ruta al directorio de documentos.
string dataDir = RunExamples.GetDataDir_Tasks();

// Crear un objeto de la clase Documento
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);

// Agregar elementos de contorno
outline.AppendChildLast(outlineElem);

// Inicializa el objeto de la clase Título
Title title = new Title() { TitleText = titleText };

// Inicializar objeto de clase de página
Page page = new Note.Page() { Title = title };

// Añadir nodo Esquema
page.AppendChildLast(outline);

// Agregar nodo de página
doc.AppendChildLast(page);

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

Ver también