文本的样式。
如果相应的 TextRange
跨越多个文本运行,并且这些运行对于被调用的读取方法具有不同的值,则此类中的读取方法会返回 null
。为避免出现这种情况,请使用 TextRange.getRuns()
方法返回的 TextRange
查询文本样式。
如果您使用方法修改文本在形状中的调整方式,则应用于文本样式的所有自动调整设置会被停用。
方法
方法 | 返回类型 | 简介 |
---|---|---|
getBackgroundColor() | Color | 返回文本的背景颜色;如果文本有多种样式,则返回 null 。 |
getBaselineOffset() | TextBaselineOffset | 返回文本相对于其正常位置的垂直偏移量;如果文本有多种样式,则返回 null 。 |
getFontFamily() | String | 返回文本的字体系列,如果文本有多种样式,则返回 null 。 |
getFontSize() | Number | 返回文本的字体大小(以点为单位);如果文本有多种样式,则返回 null 。 |
getFontWeight() | Integer | 返回文本的字体粗细,如果文本有多种样式,则返回 null 。 |
getForegroundColor() | Color | 返回文本的前景颜色;如果文本有多种样式,则返回 null 。 |
getLink() | Link | 在文本上返回 Link ;如果没有链接、链接位于文本的一部分或有多个链接,则返回 null 。 |
hasLink() | Boolean | 如果文本上有链接,则返回 true ;如果文本中没有链接,则返回 false ;如果链接位于文本的一部分或有多个链接,则返回 null 。 |
isBackgroundTransparent() | Boolean | 如果文本背景是透明的,则返回 true ;如果文本背景不透明,则返回 false ;如果文本有多种样式,则返回 null 。 |
isBold() | Boolean | 如果文本呈现为粗体,则返回 true ;如果文本呈现为粗体,则返回 false ;如果文本有多种样式,则返回 null 。 |
isItalic() | Boolean | 如果文本设为斜体,则返回 true ;如果文本设为斜体,则返回 false ;如果文本有多种样式,则返回 null 。 |
isSmallCaps() | Boolean | 如果文本使用的是大写字母,则返回 true ;如果文本采用小写样式,则返回 false ;如果文本有多种样式,则返回 null 。 |
isStrikethrough() | Boolean | 如果文本带有删除线,则返回 true ;如果文本没有删除线,则返回 false ;如果文本有多种样式,则返回 null 。 |
isUnderline() | Boolean | 如果文本带有下划线,则返回 true ;如果文本没有下划线,则返回 false ;如果文本有多种样式,则返回 null 。 |
removeLink() | TextStyle | 移除 Link 。 |
setBackgroundColor(color) | TextStyle | 设置文本的背景颜色。 |
setBackgroundColor(red, green, blue) | TextStyle | 将文本的背景颜色设为指定的 RGB 值(0 到 255)。 |
setBackgroundColor(hexColor) | TextStyle | 将文本的背景颜色设为指定的十六进制颜色字符串。 |
setBackgroundColor(color) | TextStyle | 将文本的背景颜色设为指定的 ThemeColorType 。 |
setBackgroundColorTransparent() | TextStyle | 将文本的背景颜色设为透明。 |
setBaselineOffset(offset) | TextStyle | 设置文本相对于其正常位置的垂直偏移量。 |
setBold(bold) | TextStyle | 设置是否应将文本渲染为粗体。 |
setFontFamily(fontFamily) | TextStyle | 设置文本的字体系列。 |
setFontFamilyAndWeight(fontFamily, fontWeight) | TextStyle | 设置文本的字体系列和粗细。 |
setFontSize(fontSize) | TextStyle | 设置文本的字体大小(以点为单位)。 |
setForegroundColor(foregroundColor) | TextStyle | 设置文本的前景颜色。 |
setForegroundColor(red, green, blue) | TextStyle | 将文本的前景颜色设为指定的 RGB 值(0 到 255)。 |
setForegroundColor(hexColor) | TextStyle | 将文本的前景颜色设为指定的十六进制颜色字符串。 |
setForegroundColor(color) | TextStyle | 将文本的前景颜色设为指定的 ThemeColorType 。 |
setItalic(italic) | TextStyle | 设置文本是否设为斜体。 |
setLinkSlide(slideIndex) | TextStyle | 使用幻灯片索引(从零开始)将 Link 设为指定的 Slide 。 |
setLinkSlide(slide) | TextStyle | 将 Link 设为指定的 Slide ,链接由指定的幻灯片 ID 设置。 |
setLinkSlide(slidePosition) | TextStyle | 使用幻灯片的相对位置将 Link 设为指定的 Slide 。 |
setLinkUrl(url) | TextStyle | 将 Link 设置为指定的非空网址字符串。 |
setSmallCaps(smallCaps) | TextStyle | 设置文本是否以较小的大写字母呈现。 |
setStrikethrough(strikethrough) | TextStyle | 设置是否删除文本。 |
setUnderline(underline) | TextStyle | 设置文本是否加下划线。 |
详细文档
getBackgroundColor()
getBaselineOffset()
返回文本相对于其正常位置的垂直偏移量;如果文本有多种样式,则返回 null
。
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getFontFamily()
返回文本的字体系列,如果文本有多种样式,则返回 null
。
弃踢回攻
String
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getFontSize()
返回文本的字体大小(以点为单位);如果文本有多种样式,则返回 null
。
弃踢回攻
Number
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getFontWeight()
返回文本的字体粗细,如果文本有多种样式,则返回 null
。
权重是 100 到 900(含)之间的 100 的倍数。此范围对应于 CSS 2.1 规范第 15.6 节中描述的数值,不允许使用非数值。权重大于或等于 700 会被视为粗体,在这种情况下,isBold()
会返回 true
。默认值为 400(“normal”)。
弃踢回攻
Integer
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getForegroundColor()
getLink()
在文本上返回 Link
;如果没有链接、链接位于文本的一部分或有多个链接,则返回 null
。调用 hasLink()
以确定文本是否没有链接。
var textLink = shape.getText().getTextStyle().getLink(); if (textLink != null) { Logger.log('Shape text has a link of type: ' + textLink.getLinkType()); }
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
hasLink()
isBackgroundTransparent()
如果文本背景是透明的,则返回 true
;如果文本背景不透明,则返回 false
;如果文本有多种样式,则返回 null
。
弃踢回攻
Boolean
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isBold()
如果文本呈现为粗体,则返回 true
;如果文本呈现为粗体,则返回 false
;如果文本有多种样式,则返回 null
。
弃踢回攻
Boolean
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isItalic()
如果文本设为斜体,则返回 true
;如果文本设为斜体,则返回 false
;如果文本有多种样式,则返回 null
。
弃踢回攻
Boolean
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isSmallCaps()
如果文本使用的是大写字母,则返回 true
;如果文本采用小写样式,则返回 false
;如果文本有多种样式,则返回 null
。
弃踢回攻
Boolean
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isStrikethrough()
如果文本带有删除线,则返回 true
;如果文本没有删除线,则返回 false
;如果文本有多种样式,则返回 null
。
弃踢回攻
Boolean
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
isUnderline()
如果文本带有下划线,则返回 true
;如果文本没有下划线,则返回 false
;如果文本有多种样式,则返回 null
。
弃踢回攻
Boolean
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
removeLink()
setBackgroundColor(color)
setBackgroundColor(red, green, blue)
setBackgroundColor(hexColor)
setBackgroundColor(color)
将文本的背景颜色设为指定的 ThemeColorType
。
参数
名称 | 类型 | 说明 |
---|---|---|
color | ThemeColorType |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setBackgroundColorTransparent()
setBaselineOffset(offset)
设置文本相对于其正常位置的垂直偏移量。
参数
名称 | 类型 | 说明 |
---|---|---|
offset | TextBaselineOffset |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setBold(bold)
setFontFamily(fontFamily)
setFontFamilyAndWeight(fontFamily, fontWeight)
设置文本的字体系列和粗细。
权重是 100 到 900(含)之间的 100 的倍数。此范围对应于 CSS 2.1 规范第 15.6 节中描述的数值,不允许使用非数值。权重大于或等于 700 会被视为粗体,在这种情况下,isBold()
会返回 true
。默认值为 400(“normal”)。
参数
名称 | 类型 | 说明 |
---|---|---|
fontFamily | String | |
fontWeight | Integer |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setFontSize(fontSize)
setForegroundColor(foregroundColor)
setForegroundColor(red, green, blue)
setForegroundColor(hexColor)
setForegroundColor(color)
将文本的前景颜色设为指定的 ThemeColorType
。
参数
名称 | 类型 | 说明 |
---|---|---|
color | ThemeColorType |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setItalic(italic)
setLinkSlide(slideIndex)
使用幻灯片的索引(从零开始)将 Link
设为指定的 Slide
。
设置链接会更改要添加下划线的文本样式,并将前景颜色设置为 ThemeColorType.HYPERLINK
。这可以通过 setForegroundColor(hexColor)
和 setUnderline(underline)
进行更改。
由于无法针对换行符设置链接,因此 TextRange
中的换行符会被忽略。
// Set a link to the first slide of the presentation. text.getTextStyle().setLinkSlide(0);
参数
名称 | 类型 | 说明 |
---|---|---|
slideIndex | Integer | 幻灯片的索引(从零开始)。 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setLinkSlide(slide)
将 Link
设为指定的 Slide
,链接由指定的幻灯片 ID 设置。
设置链接会更改要添加下划线的文本样式,并将前景颜色设置为 ThemeColorType.HYPERLINK
。这可以通过 setForegroundColor(hexColor)
和 setUnderline(underline)
进行更改。
由于无法针对换行符设置链接,因此 TextRange
中的换行符会被忽略。
// Set a link to the first slide of the presentation. var slide = presentation.getSlides()[0]; text.getTextStyle().setLinkSlide(slide);
参数
名称 | 类型 | 说明 |
---|---|---|
slide | Slide | 要关联的 Slide 。 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setLinkSlide(slidePosition)
设置链接会更改要添加下划线的文本样式,并将前景颜色设置为 ThemeColorType.HYPERLINK
。这可以通过 setForegroundColor(hexColor)
和 setUnderline(underline)
进行更改。
由于无法针对换行符设置链接,因此 TextRange
中的换行符会被忽略。
// Set a link to the first slide of the presentation. text.getTextStyle().setLinkSlide(SlidesApp.SlidePosition.FIRST_SLIDE);
参数
名称 | 类型 | 说明 |
---|---|---|
slidePosition | SlidePosition | 相对 SlidePosition 。 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setLinkUrl(url)
将 Link
设置为指定的非空网址字符串。
设置链接会更改要添加下划线的文本样式,并将前景颜色设置为 ThemeColorType.HYPERLINK
。这可以通过 setForegroundColor(hexColor)
和 setUnderline(underline)
进行更改。
由于无法针对换行符设置链接,因此 TextRange
中的换行符会被忽略。
// Set a link to the URL. text.getTextStyle().setLinkUrl("https://slides.google.com");
参数
名称 | 类型 | 说明 |
---|---|---|
url | String | 网址字符串。 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations