# 도형과 텍스트

- Human documentation: [https://docs.univer.ai/ko-KR/guides/slides/features/core/shapes-and-text](https://docs.univer.ai/ko-KR/guides/slides/features/core/shapes-and-text)

- Agent Markdown: [https://docs.univer.ai/ko-KR/guides/slides/features/core/shapes-and-text.md](https://docs.univer.ai/ko-KR/guides/slides/features/core/shapes-and-text.md)

- Requested language: `ko-KR`

- Content language: `ko-KR`

- Documentation version: `1.0.4`

- Source: [slides/features/core/shapes-and-text.ko-KR.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/slides/features/core/shapes-and-text.ko-KR.mdx)

---

Slides는 공유 Shape 엔진으로 편집 가능한 도형, 연결선, 도형 텍스트를 제공합니다. `FSlide.insertShape()`는 Slides 명령 파이프라인에 연결된 도형 Facade를 반환합니다.

## 도형 삽입

```ts
const slide = univerAPI.getActivePresentation()?.getActiveSlide()

if (!slide) {
  throw new Error('No active slide')
}

const shape = slide.insertShape({
  shapeType: univerAPI.Enum.ShapeTypeEnum.RoundRect,
  transform: { left: 80, top: 64, width: 320, height: 120 },
  visible: true,
  selectable: true,
  shapeData: {
    fill: {
      fillType: univerAPI.Enum.ShapeFillEnum.SolidFill,
      color: '#dbeafe',
    },
  },
})
```

Shape 호스트 어댑터를 사용할 수 없거나 입력을 만들 수 없으면 `insertShape()`가 `null`을 반환할 수 있습니다. 도형을 삽입하기 전에 Slides 구성에 필요한 Shape 의존성을 등록하세요.

## 서식 있는 텍스트 추가

```ts
if (shape) {
  const richText = univerAPI.newRichText()
    .text('Quarterly ')
    .bold('review')

  shape.getText()
    .setRichText(richText)
    .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER)
    .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)
}
```

`slide.getShape(id)` 또는 `slide.getShapes()`로 도형을 가져옵니다. 공통 요소 메서드로 위치, 크기, 표시 여부, 이름, 설명을 바꾸고 `slide.deleteElement(shape)`로 삭제할 수 있습니다.

## 도형 텍스트 편집

아래 또는 앞의 예제에서 `insertShape()`가 반환한 도형을 사용합니다. `getText()`는 실시간 [FShapeText](https://docs.univer.ai/ko-KR/reference/facade/shape-text.md) 객체를 반환합니다. `getPlainText()`로 텍스트를 읽고, `setText()`로 전체 텍스트를 바꾸며 글꼴, 색상, 정렬을 설정할 수 있습니다.

```ts
if (!shape) throw new Error('Shape is not available')
const shapeText = shape.getText()
console.log(shapeText.getPlainText())
shapeText
  .setText('Quarterly review')
  .setFontSize(18)
  .setColor('#2563eb')
  .setBold(true)
  .setHorizontalAlign(univerAPI.Enum.HorizontalAlign.CENTER)
  .setVerticalAlign(univerAPI.Enum.VerticalAlign.MIDDLE)
```

`setText()`는 기존 텍스트를 대체합니다. 여러 서식을 사용하려면 `setRichText()`를 사용하세요. 기존 서식 있는 텍스트를 편집하려면 `getRichText()?.copy()`로 빌더를 얻고 수정한 뒤 `setRichText()`에 전달합니다. 빌더를 수정하는 것만으로는 반영되지 않습니다. [텍스트 스타일](https://docs.univer.ai/ko-KR/reference/facade/shape-text.md#settextstyle)과 [텍스트 상자 여백 및 레이아웃](https://docs.univer.ai/ko-KR/reference/facade/shape-text.md#settextboxoptions)도 참고하세요.

```ts
const richText = univerAPI.newRichText()
  .text('Quarterly ')
  .bold('review')
shapeText.setRichText(richText)
```

## 도형 서식 복사

원본 도형을 선택하고 서식 복사를 활성화한 뒤 대상 도형을 선택하세요. 채우기, 선, 효과 및 지원되는 텍스트 서식을 복사하고 대상 ID, 기하 정보, 텍스트 내용 및 수식 연결은 유지합니다. 서식 지우기는 삽입 기본값을 복원합니다. SmartArt는 제외되며 해당 도형 UI 플러그인이 기능을 자동 등록합니다.
