Class TextStyle

TextStyle

The style of text.

Read methods in this class return null if the corresponding TextRange spans multiple text runs, and those runs have different values for the read method being called. To avoid this, query for text styles using the TextRanges returned by the TextRange.getRuns() method.

Methods

MethodReturn typeBrief description
getBackgroundColor()ColorReturns the background color of the text, or null if there are multiple styles on the text.
getBaselineOffset()TextBaselineOffsetReturns the vertical offset of text from its normal position, or null if there are multiple styles on the text.
getFontFamily()StringReturns the font family of the text, or null if there are multiple styles on the text.
getFontSize()NumberReturns the font size of the text in points, or null if there are multiple styles on the text.
getFontWeight()IntegerReturns the font weight of the text, or null if there are multiple styles on the text.
getForegroundColor()ColorReturns the foreground color of the text, or null if there are multiple styles on the text.
getLink()LinkReturns the Link on the text, or null if there is no link or if the link is on part of the text or if there are multiple links.
hasLink()BooleanReturns true if there is link on the text, false if not, or null if the link is on part of the text or there are multiple links.
isBackgroundTransparent()BooleanReturns true if the background of the text is transparent, false if not, or null if there are multiple styles on the text.
isBold()BooleanReturns true if the text is rendered as bold, false if not, or null if there are multiple styles on the text.
isItalic()BooleanReturns true if the text is italicized, false if not, or null if there are multiple styles on the text.
isSmallCaps()BooleanReturns true if the text is in small capital letters, false if not, or null if there are multiple styles on the text.
isStrikethrough()BooleanReturns true if the text is struck through, false if not, or null if there are multiple styles on the text.
isUnderline()BooleanReturns true if the text is underlined, false if not, or null if there are multiple styles on the text.
removeLink()TextStyleRemoves a Link.
setBackgroundColor(color)TextStyleSets the background color of the text.
setBackgroundColor(red, green, blue)TextStyleSets the background color of the text to the given RGB values from 0 to 255.
setBackgroundColor(hexColor)TextStyleSets the background color of the text to the given hex color string.
setBackgroundColor(color)TextStyleSets the background color of the text to the given ThemeColorType.
setBackgroundColorTransparent()TextStyleSets the background color of the text to transparent.
setBaselineOffset(offset)TextStyleSets the vertical offset of the text relative to its normal position.
setBold(bold)TextStyleSets whether the text should be rendered as bold.
setFontFamily(fontFamily)TextStyleSets the font family of the text .
setFontFamilyAndWeight(fontFamily, fontWeight)TextStyleSets the font family and weight of the text.
setFontSize(fontSize)TextStyleSets the font size of the text, in points.
setForegroundColor(foregroundColor)TextStyleSets the foreground color of the text.
setForegroundColor(red, green, blue)TextStyleSets the foreground color of the text to the given RGB values from 0 to 255.
setForegroundColor(hexColor)TextStyleSets the foreground color of the text to the given hex color string.
setForegroundColor(color)TextStyleSets the foreground color of the text to the given ThemeColorType.
setItalic(italic)TextStyleSets the whether the text is italicized.
setLinkSlide(slideIndex)TextStyleSets a Link to the given Slide using the zero-based index of the slide.
setLinkSlide(slide)TextStyleSets a Link to the given Slide, the link is set by the given slide ID.
setLinkSlide(slidePosition)TextStyleSets a Link to the given Slide using the relative position of the slide.
setLinkUrl(url)TextStyleSets a Link to the given non-empty URL string.
setSmallCaps(smallCaps)TextStyleSets whether the text is rendered in small capital letters.
setStrikethrough(strikethrough)TextStyleSets whether the text is struck through.
setUnderline(underline)TextStyleSets whether the text is underlined.

Detailed documentation

getBackgroundColor()

Returns the background color of the text, or null if there are multiple styles on the text.

Return

Color


getBaselineOffset()

Returns the vertical offset of text from its normal position, or null if there are multiple styles on the text.

Return

TextBaselineOffset


getFontFamily()

Returns the font family of the text, or null if there are multiple styles on the text.

Return

String


getFontSize()

Returns the font size of the text in points, or null if there are multiple styles on the text.

Return

Number


getFontWeight()

Returns the font weight of the text, or null if there are multiple styles on the text.

The weight is a multiple of 100 between 100 and 900, inclusive. This range corresponds to the numerical values described in the CSS 2.1 Specification, section 15.6, with non-numerical values disallowed. Weights greater than or equal to 700 are considered bold, in which case isBold() returns true. The default value is 400 ("normal").

Return

Integer


getForegroundColor()

Returns the foreground color of the text, or null if there are multiple styles on the text.

Return

Color


getLink()

Returns the Link on the text, or null if there is no link or if the link is on part of the text or if there are multiple links. Call hasLink() to determine whether the text has no link.


 var textLink = shape.getText().getTextStyle().getLink();
 if (textLink != null) {
   Logger.log('Shape text has a link of type: ' + textLink.getLinkType());
 }
 

Return

Link


hasLink()

Returns true if there is link on the text, false if not, or null if the link is on part of the text or there are multiple links.

Links cannot be set on newline characters. Therefore, if the TextRange contains a newline character, this method always returns either null or false.

Return

Boolean


isBackgroundTransparent()

Returns true if the background of the text is transparent, false if not, or null if there are multiple styles on the text.

Return

Boolean


isBold()

Returns true if the text is rendered as bold, false if not, or null if there are multiple styles on the text.

Return

Boolean


isItalic()

Returns true if the text is italicized, false if not, or null if there are multiple styles on the text.

Return

Boolean


isSmallCaps()

Returns true if the text is in small capital letters, false if not, or null if there are multiple styles on the text.

Return

Boolean


isStrikethrough()

Returns true if the text is struck through, false if not, or null if there are multiple styles on the text.

Return

Boolean


isUnderline()

Returns true if the text is underlined, false if not, or null if there are multiple styles on the text.

Return

Boolean


removeLink()

Removes a Link.

Removing a link removes the hyperlink foreground color and underline style on the text. If possible, these styles are applied to match the text preceding the link.

 text.getTextStyle().removeLink();
 

Return

TextStyle


setBackgroundColor(color)

Sets the background color of the text.

Parameters

NameTypeDescription
colorColor

Return

TextStyle


setBackgroundColor(red, green, blue)

Sets the background color of the text to the given RGB values from 0 to 255.

Parameters

NameTypeDescription
redInteger
greenInteger
blueInteger

Return

TextStyle


setBackgroundColor(hexColor)

Sets the background color of the text to the given hex color string.

The hex string must be in the format '#RRGGBB'. For example, pink would be represented as '#FFC0CB'.

Parameters

NameTypeDescription
hexColorString

Return

TextStyle


setBackgroundColor(color)

Sets the background color of the text to the given ThemeColorType.

Parameters

NameTypeDescription
colorThemeColorType

Return

TextStyle


setBackgroundColorTransparent()

Sets the background color of the text to transparent.

Return

TextStyle


setBaselineOffset(offset)

Sets the vertical offset of the text relative to its normal position.

Parameters

NameTypeDescription
offsetTextBaselineOffset

Return

TextStyle


setBold(bold)

Sets whether the text should be rendered as bold.

Changing the text's boldness updates the font weight used to render the text.

Parameters

NameTypeDescription
boldBoolean

Return

TextStyle


setFontFamily(fontFamily)

Sets the font family of the text .

Parameters

NameTypeDescription
fontFamilyString

Return

TextStyle


setFontFamilyAndWeight(fontFamily, fontWeight)

Sets the font family and weight of the text.

The weight is a multiple of 100 between 100 and 900, inclusive. This range corresponds to the numerical values described in the CSS 2.1 Specification, section 15.6, with non-numerical values disallowed. Weights greater than or equal to 700 are considered bold, in which case isBold() returns true. The default value is 400 ("normal").

Parameters

NameTypeDescription
fontFamilyString
fontWeightInteger

Return

TextStyle


setFontSize(fontSize)

Sets the font size of the text, in points.

Parameters

NameTypeDescription
fontSizeNumber

Return

TextStyle


setForegroundColor(foregroundColor)

Sets the foreground color of the text.

Parameters

NameTypeDescription
foregroundColorColor

Return

TextStyle


setForegroundColor(red, green, blue)

Sets the foreground color of the text to the given RGB values from 0 to 255.

Parameters

NameTypeDescription
redInteger
greenInteger
blueInteger

Return

TextStyle


setForegroundColor(hexColor)

Sets the foreground color of the text to the given hex color string.

The hex string must be in the format '#RRGGBB'. For example, pink would be represented as '#FFC0CB'.

Parameters

NameTypeDescription
hexColorString

Return

TextStyle


setForegroundColor(color)

Sets the foreground color of the text to the given ThemeColorType.

Parameters

NameTypeDescription
colorThemeColorType

Return

TextStyle


setItalic(italic)

Sets the whether the text is italicized.

Parameters

NameTypeDescription
italicBoolean

Return

TextStyle


setLinkSlide(slideIndex)

Sets a Link to the given Slide using the zero-based index of the slide.

Setting a link changes the style of the text to be underlined and to have a ThemeColorType.HYPERLINK foreground color. This can be changed via setForegroundColor(hexColor) and setUnderline(underline).

Since links cannot be set on newline characters, newline characters in the TextRange are ignored.

 // Set a link to the first slide of the presentation.
 text.getTextStyle().setLinkSlide(0);
 

Parameters

NameTypeDescription
slideIndexIntegerThe zero-based index to the slide.

Return

TextStyle


setLinkSlide(slide)

Sets a Link to the given Slide, the link is set by the given slide ID.

Setting a link changes the style of the text to be underlined and to have a ThemeColorType.HYPERLINK foreground color. This can be changed via setForegroundColor(hexColor) and setUnderline(underline).

Since links cannot be set on newline characters, newline characters in the TextRange are ignored.

 // Set a link to the first slide of the presentation.
 var slide = presentation.getSlides()[0];
 text.getTextStyle().setLinkSlide(slide);
 

Parameters

NameTypeDescription
slideSlideThe Slide to be linked.

Return

TextStyle


setLinkSlide(slidePosition)

Sets a Link to the given Slide using the relative position of the slide.

Setting a link changes the style of the text to be underlined and to have a ThemeColorType.HYPERLINK foreground color. This can be changed via setForegroundColor(hexColor) and setUnderline(underline).

Since links cannot be set on newline characters, newline characters in the TextRange are ignored.

 // Set a link to the first slide of the presentation.
 text.getTextStyle().setLinkSlide(SlidesApp.SlidePosition.FIRST_SLIDE);
 

Parameters

NameTypeDescription
slidePositionSlidePositionThe relative SlidePosition.

Return

TextStyle


setLinkUrl(url)

Sets a Link to the given non-empty URL string.

Setting a link changes the style of the text to be underlined and to have a ThemeColorType.HYPERLINK foreground color. This can be changed via setForegroundColor(hexColor) and setUnderline(underline).

Since links cannot be set on newline characters, newline characters in the TextRange are ignored.

 // Set a link to the URL.
 text.getTextStyle().setLinkUrl("https://slides.google.com");
 

Parameters

NameTypeDescription
urlStringThe URL string.

Return

TextStyle


setSmallCaps(smallCaps)

Sets whether the text is rendered in small capital letters.

Parameters

NameTypeDescription
smallCapsBoolean

Return

TextStyle


setStrikethrough(strikethrough)

Sets whether the text is struck through.

Parameters

NameTypeDescription
strikethroughBoolean

Return

TextStyle


setUnderline(underline)

Sets whether the text is underlined.

Parameters

NameTypeDescription
underlineBoolean

Return

TextStyle

Send feedback about...

Apps Script
Apps Script