PowerPoint.ShapeFont class

Representa os atributos de fonte, como nome da fonte, tamanho da fonte e cor, para o objeto TextRange de uma forma.

Extends

Comentários

Conjunto de APIs: PowerPointApi 1.4

Usada por

Exemplos

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Gets navigational (complex) properties of the selected text range.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.load("font,paragraphFormat/bulletFormat,paragraphFormat/horizontalAlignment");

  const parentTextFrame: PowerPoint.TextFrame = textRange.getParentTextFrame();
  const parentShape: PowerPoint.Shape = parentTextFrame.getParentShape();
  const parentSlide: PowerPoint.Slide = parentShape.getParentSlide();
  parentShape.load("id");
  parentSlide.load("id");
  await context.sync();

  console.log(`Selected text range found in parent shape with ID ${parentShape.id} on parentSlide with ID ${parentSlide.id}`);

  console.log("Font properties of selected text range:");
  console.log(`\tallCaps: ${textRange.font.allCaps}`);
  console.log(`\tbold: ${textRange.font.bold}`);
  console.log(`\tcolor: ${textRange.font.color}`);
  console.log(`\tdoubleStrikethrough: ${textRange.font.doubleStrikethrough}`);
  console.log(`\titalic: ${textRange.font.italic}`);
  console.log(`\tname: ${textRange.font.name}`);
  console.log(`\tsize: ${textRange.font.size}`);
  console.log(`\tsmallCaps: ${textRange.font.smallCaps}`);
  console.log(`\tstrikethrough: ${textRange.font.strikethrough}`);
  console.log(`\tsubscript: ${textRange.font.subscript}`);
  console.log(`\tsuperscript: ${textRange.font.superscript}`);
  console.log(`\tunderline: ${textRange.font.underline}`);

  console.log("Paragraph format properties of selected text range:");
  console.log(`\tbulletFormat.visible: ${textRange.paragraphFormat.bulletFormat.visible}`);
  console.log(`\thorizontalAlignment: ${textRange.paragraphFormat.horizontalAlignment}`);
});

Propriedades

bold

Especifica se o texto no TextRange está definido como negrito. Os valores possíveis são os seguintes:

  • true : todo o texto está em negrito.

  • false : Nenhum texto está em negrito.

  • null : retornado se parte do texto, mas não todo, estiver em negrito.

color

Especifica a representação do código de cores HTML da cor do texto (por exemplo, "#FF0000" representa vermelho). Retorna null se contém TextRange fragmentos de texto com cores diferentes.

context

O contexto de solicitação associado ao objeto. Isso conecta o processo do suplemento ao processo do aplicativo host do Office.

italic

Especifica se o TextRange texto no está definido como itálico. Os valores possíveis são os seguintes:

  • true : todo o texto está em itálico.

  • false : Nenhum texto está em itálico.

  • null : retornado se parte do texto, mas não todo, estiver em itálico.

name

Especifica o nome da fonte (por exemplo, "Calibri"). Se o texto for um Complex Script ou um idioma do Leste Asiático, este será o nome da fonte correspondente; caso contrário, é o nome da fonte latina. Retorna null se contiver TextRange fragmentos de texto com nomes de fonte diferentes.

size

Especifica o tamanho da fonte em pontos (por exemplo, 11). Retorna null se contiver TextRange fragmentos de texto com tamanhos de fonte diferentes.

underline

Especifica o tipo de sublinhado aplicado à fonte. Retorna null se contém TextRange fragmentos de texto com estilos de sublinhado diferentes. Confira PowerPoint.ShapeFontUnderlineStyle para obter detalhes.

Métodos

load(options)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

load(propertyNames)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

load(propertyNamesAndPaths)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

toJSON()

Substitui o método JavaScript toJSON() para fornecer uma saída mais útil quando um objeto de API é passado para JSON.stringify(). (JSON.stringify, por sua vez, chama o toJSON método do objeto que é passado para ele.) Enquanto o objeto original PowerPoint.ShapeFont é um objeto de API, o toJSON método retorna um objeto JavaScript simples (digitado como PowerPoint.Interfaces.ShapeFontData) que contém cópias superficiais de todas as propriedades filho carregadas do objeto original.

Detalhes da propriedade

bold

Especifica se o texto no TextRange está definido como negrito. Os valores possíveis são os seguintes:

  • true : todo o texto está em negrito.

  • false : Nenhum texto está em negrito.

  • null : retornado se parte do texto, mas não todo, estiver em negrito.

bold: boolean | null;

Valor da propriedade

boolean | null

Comentários

Conjunto de APIs: PowerPointApi 1.4

color

Especifica a representação do código de cores HTML da cor do texto (por exemplo, "#FF0000" representa vermelho). Retorna null se contém TextRange fragmentos de texto com cores diferentes.

color: string | null;

Valor da propriedade

string | null

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Sets the color of the selected text range to green.
await PowerPoint.run(async (context) => {
  const textRange: PowerPoint.TextRange = context.presentation.getSelectedTextRange();
  textRange.font.color = "green";
  await context.sync();
});

context

O contexto de solicitação associado ao objeto. Isso conecta o processo do suplemento ao processo do aplicativo host do Office.

context: RequestContext;

Valor da propriedade

italic

Especifica se o TextRange texto no está definido como itálico. Os valores possíveis são os seguintes:

  • true : todo o texto está em itálico.

  • false : Nenhum texto está em itálico.

  • null : retornado se parte do texto, mas não todo, estiver em itálico.

italic: boolean | null;

Valor da propriedade

boolean | null

Comentários

Conjunto de APIs: PowerPointApi 1.4

name

Especifica o nome da fonte (por exemplo, "Calibri"). Se o texto for um Complex Script ou um idioma do Leste Asiático, este será o nome da fonte correspondente; caso contrário, é o nome da fonte latina. Retorna null se contiver TextRange fragmentos de texto com nomes de fonte diferentes.

name: string | null;

Valor da propriedade

string | null

Comentários

Conjunto de APIs: PowerPointApi 1.4

size

Especifica o tamanho da fonte em pontos (por exemplo, 11). Retorna null se contiver TextRange fragmentos de texto com tamanhos de fonte diferentes.

size: number | null;

Valor da propriedade

number | null

Comentários

Conjunto de APIs: PowerPointApi 1.4

underline

Especifica o tipo de sublinhado aplicado à fonte. Retorna null se contém TextRange fragmentos de texto com estilos de sublinhado diferentes. Confira PowerPoint.ShapeFontUnderlineStyle para obter detalhes.

underline: PowerPoint.ShapeFontUnderlineStyle | "None" | "Single" | "Double" | "Heavy" | "Dotted" | "DottedHeavy" | "Dash" | "DashHeavy" | "DashLong" | "DashLongHeavy" | "DotDash" | "DotDashHeavy" | "DotDotDash" | "DotDotDashHeavy" | "Wavy" | "WavyHeavy" | "WavyDouble" | null;

Valor da propriedade

PowerPoint.ShapeFontUnderlineStyle | "None" | "Single" | "Double" | "Heavy" | "Dotted" | "DottedHeavy" | "Dash" | "DashHeavy" | "DashLong" | "DashLongHeavy" | "DotDash" | "DotDashHeavy" | "DotDotDash" | "DotDotDashHeavy" | "Wavy" | "WavyHeavy" | "WavyDouble" | null

Comentários

Conjunto de APIs: PowerPointApi 1.4

Exemplos

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/shapes.yaml

// This function gets the collection of shapes on the first slide,
// and adds a brace pair, {}, to the collection, while specifying its
// location and size. Then it names the shape, sets its text and font
// color, and centers it inside the braces.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
  const braces: PowerPoint.Shape = shapes.addGeometricShape(PowerPoint.GeometricShapeType.bracePair, {
    left: 100,
    top: 400,
    height: 50,
    width: 150,
  });
  braces.name = "Braces";
  braces.textFrame.textRange.text = "Shape text";
  braces.textFrame.textRange.font.color = "purple";
  braces.textFrame.textRange.font.underline = PowerPoint.ShapeFontUnderlineStyle.heavy;
  braces.textFrame.verticalAlignment = PowerPoint.TextVerticalAlignment.middleCentered;
  braces.textFrame.autoSizeSetting = PowerPoint.ShapeAutoSize.autoSizeShapeToFitText;

  return context.sync();
});

Detalhes do método

load(options)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

load(options?: PowerPoint.Interfaces.ShapeFontLoadOptions): PowerPoint.ShapeFont;

Parâmetros

options
PowerPoint.Interfaces.ShapeFontLoadOptions

Fornece opções para quais propriedades do objeto devem ser carregadas.

Retornos

load(propertyNames)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

load(propertyNames?: string | string[]): PowerPoint.ShapeFont;

Parâmetros

propertyNames

string | string[]

Uma cadeia de caracteres delimitada por vírgula ou uma matriz de cadeias de caracteres que especifica as propriedades a serem carregadas.

Retornos

load(propertyNamesAndPaths)

Coloca um comando na fila para carregar as propriedades especificadas do objeto. Você deve chamar context.sync() antes de ler as propriedades.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.ShapeFont;

Parâmetros

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select é uma cadeia de caracteres delimitada por vírgula que especifica as propriedades a serem carregadas e propertyNamesAndPaths.expand é uma cadeia de caracteres delimitada por vírgula que especifica as propriedades de navegação a serem carregadas.

Retornos

toJSON()

Substitui o método JavaScript toJSON() para fornecer uma saída mais útil quando um objeto de API é passado para JSON.stringify(). (JSON.stringify, por sua vez, chama o toJSON método do objeto que é passado para ele.) Enquanto o objeto original PowerPoint.ShapeFont é um objeto de API, o toJSON método retorna um objeto JavaScript simples (digitado como PowerPoint.Interfaces.ShapeFontData) que contém cópias superficiais de todas as propriedades filho carregadas do objeto original.

toJSON(): PowerPoint.Interfaces.ShapeFontData;

Retornos