Class TextStyle

TextStyle

テキストのスタイル。

対応する TextRange が複数のテキスト実行にまたがっており、それらの実行が呼び出される読み取りメソッドに異なる値を持つ場合、このクラスの読み取りメソッドは null を返します。これを回避するには、TextRange.getRuns() メソッドから返された TextRange を使用してテキスト スタイルをクエリします。

シェイプ内のテキストの配置を編集する方法を使用すると、テキスト スタイルに適用されている自動調整設定はすべて無効になります。

Methods

メソッド戻り値の型概要
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()TextStyleLink を削除します。
setBackgroundColor(color)TextStyleテキストの背景色を設定します。
setBackgroundColor(red, green, blue)TextStyleテキストの背景色を 0 ~ 255 の指定された RGB 値に設定します。
setBackgroundColor(hexColor)TextStyleテキストの背景色を、指定した 16 進数色文字列に設定します。
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テキストの前景の色を、指定された 16 進数色文字列に設定します。
setForegroundColor(color)TextStyleテキストのフォアグラウンドの色を、指定した ThemeColorType に設定します。
setItalic(italic)TextStyleテキストが斜体にするかどうかを設定します。
setLinkSlide(slideIndex)TextStyleスライドのゼロから始まるインデックスを使用して、Link を指定された Slide に設定します。
setLinkSlide(slide)TextStyleLink を指定された Slide に設定します。リンクは指定されたスライド ID によって設定されます。
setLinkSlide(slidePosition)TextStyleスライドの相対位置を使用して、Link を指定された Slide に設定します。
setLinkUrl(url)TextStyleLink を指定された空でない URL 文字列に設定します。
setSmallCaps(smallCaps)TextStyleテキストを小さい大文字でレンダリングするかどうかを設定します。
setStrikethrough(strikethrough)TextStyleテキストに取り消し線を引くかどうかを設定します。
setUnderline(underline)TextStyleテキストに下線を引くかどうかを設定します。

詳細なドキュメント

getBackgroundColor()

テキストの背景色、またはテキストに複数のスタイルがある場合は null を返します。

リターン

Color

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getBaselineOffset()

テキストの通常の位置からの垂直オフセットを返します。テキストに複数のスタイルがある場合は null を返します。

リターン

TextBaselineOffset

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getFontFamily()

テキストのフォント ファミリーを返します。テキストに複数のスタイルがある場合は null を返します。

リターン

String

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getFontSize()

テキストのフォントサイズをポイント単位で返します。テキストに複数のスタイルがある場合は null を返します。

リターン

Number

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • 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(「標準」)です。

リターン

Integer

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

getForegroundColor()

テキストのフォアグラウンドの色を返します。テキストに複数のスタイルがある場合は null を返します。

リターン

Color

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

テキストの Link を返します。リンクがない場合、リンクがテキストの一部か複数のリンクがある場合は null を返します。hasLink() を呼び出して、テキストにリンクがないかどうかを確認します。

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

リターン

Link

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

テキストにリンクがある場合は true、存在しない場合は false、リンクがテキストの一部または複数のリンクがある場合は null を返します。

リンクを改行文字に設定することはできません。したがって、TextRange に改行文字が含まれている場合、このメソッドは常に null または false を返します。

リターン

Boolean

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

isBackgroundTransparent()

テキストの背景が透明の場合は true、そうでない場合は false、テキストに複数のスタイルがある場合は null を返します。

リターン

Boolean

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

isBold()

テキストが太字でレンダリングされる場合は true、そうでない場合は false、テキストに複数のスタイルがある場合は null を返します。

リターン

Boolean

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

isItalic()

テキストが斜体の場合は true、そうでない場合は false、テキストに複数のスタイルがある場合は null を返します。

リターン

Boolean

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

isSmallCaps()

テキストが小さい大文字の場合は true、そうでない場合は false、テキストに複数のスタイルがある場合は null を返します。

リターン

Boolean

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

isStrikethrough()

テキストに取り消し線がある場合は true、そうでない場合は false、テキストに複数のスタイルがある場合は null を返します。

リターン

Boolean

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

isUnderline()

テキストに下線が引かれた場合は true、そうでない場合は false、テキストに複数のスタイルがある場合は null を返します。

リターン

Boolean

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

Link を削除します。

リンクを削除すると、テキストのハイパーリンクの前景の色と下線のスタイルが削除されます。可能な場合、これらのスタイルは、リンクの前のテキストに合わせて適用されます。

text.getTextStyle().removeLink();

リターン

TextStyle


setBackgroundColor(color)

テキストの背景色を設定します。

パラメータ

名前説明
colorColor

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColor(red, green, blue)

テキストの背景色を 0 ~ 255 の指定された RGB 値に設定します。

パラメータ

名前説明
redInteger
greenInteger
blueInteger

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColor(hexColor)

テキストの背景色を、指定した 16 進数色文字列に設定します。

16 進数文字列は、「#RRGGBB」の形式である必要があります。たとえば、ピンクは「#FFC0CB」になります。

パラメータ

名前説明
hexColorString

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColor(color)

テキストの背景色を指定された ThemeColorType に設定します。

パラメータ

名前説明
colorThemeColorType

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBackgroundColorTransparent()

テキストの背景色を透明に設定します。

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBaselineOffset(offset)

通常の位置に対するテキストの垂直オフセットを設定します。

パラメータ

名前説明
offsetTextBaselineOffset

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setBold(bold)

テキストを太字でレンダリングするかどうかを設定します。

テキストの太字を変更すると、テキストのレンダリングに使用するフォントの太さが更新されます。

パラメータ

名前説明
boldBoolean

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setFontFamily(fontFamily)

テキストのフォント ファミリーを設定します。

パラメータ

名前説明
fontFamilyString

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setFontFamilyAndWeight(fontFamily, fontWeight)

テキストのフォント ファミリーと太さを設定します。

重みは、100 以上 900 以下の 100 の倍数です。この範囲は CSS 2.1 仕様のセクション 15.6 に記載されている数値に対応していますが、数値以外の値は使用できません。700 以上の重みは太字とみなされ、isBold()true を返します。デフォルト値は 400(「標準」)です。

パラメータ

名前説明
fontFamilyString
fontWeightInteger

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setFontSize(fontSize)

テキストのフォントサイズをポイント単位で設定します。

パラメータ

名前説明
fontSizeNumber

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(foregroundColor)

テキストのフォアグラウンドの色を設定します。

パラメータ

名前説明
foregroundColorColor

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(red, green, blue)

テキストのフォアグラウンドの色を、指定された RGB 値(0 ~ 255)に設定します。

パラメータ

名前説明
redInteger
greenInteger
blueInteger

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(hexColor)

テキストの前景の色を、指定された 16 進数色文字列に設定します。

16 進数文字列は、「#RRGGBB」の形式である必要があります。たとえば、ピンクは「#FFC0CB」になります。

パラメータ

名前説明
hexColorString

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setForegroundColor(color)

テキストのフォアグラウンドの色を、指定した ThemeColorType に設定します。

パラメータ

名前説明
colorThemeColorType

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setItalic(italic)

テキストが斜体にするかどうかを設定します。

パラメータ

名前説明
italicBoolean

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setLinkSlide(slideIndex)

スライドのゼロから始まるインデックスを使用して、指定された SlideLink を設定します。

リンクを設定すると、下線が引かれるテキストのスタイルと、前景の色が ThemeColorType.HYPERLINK に変わります。これは setForegroundColor(hexColor)setUnderline(underline) で変更できます。

改行文字にはリンクを設定できないため、TextRange 内の改行文字は無視されます。

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

パラメータ

名前説明
slideIndexIntegerスライドのゼロから始まるインデックス。

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

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

パラメータ

名前説明
slideSlideリンクする Slide

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setLinkSlide(slidePosition)

スライドの相対位置を使用して、Link を指定された Slide に設定します。

リンクを設定すると、下線が引かれるテキストのスタイルと、前景の色が ThemeColorType.HYPERLINK に変わります。これは setForegroundColor(hexColor)setUnderline(underline) で変更できます。

改行文字にはリンクを設定できないため、TextRange 内の改行文字は無視されます。

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

パラメータ

名前説明
slidePositionSlidePosition相対 SlidePosition

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setLinkUrl(url)

Link を指定された空でない URL 文字列に設定します。

リンクを設定すると、下線が引かれるテキストのスタイルと、前景の色が ThemeColorType.HYPERLINK に変わります。これは setForegroundColor(hexColor)setUnderline(underline) で変更できます。

改行文字にはリンクを設定できないため、TextRange 内の改行文字は無視されます。

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

パラメータ

名前説明
urlStringURL 文字列。

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setSmallCaps(smallCaps)

テキストを小さい大文字でレンダリングするかどうかを設定します。

パラメータ

名前説明
smallCapsBoolean

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setStrikethrough(strikethrough)

テキストに取り消し線を引くかどうかを設定します。

パラメータ

名前説明
strikethroughBoolean

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations

setUnderline(underline)

テキストに下線を引くかどうかを設定します。

パラメータ

名前説明
underlineBoolean

リターン

TextStyle

承認

この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。

  • https://www.googleapis.com/auth/presentations.currentonly
  • https://www.googleapis.com/auth/presentations