-
Notifications
You must be signed in to change notification settings - Fork 9
/
text_area.ts
29 lines (20 loc) · 863 Bytes
/
text_area.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Frame, getFrameChecked } from '../core/frame';
import { Color } from '../core/types';
/**
* @category Items
*/
export function textArea(text: string, w: number) {
const frame = getFrameChecked();
const painter = frame.getPainter();
const style = Frame.getStyle();
const selector = frame.buildStyleSelector('text-area');
const font = style.getPropertyAs<number>(selector, 'font-family');
const scale = style.getPropertyAs<number>(selector, 'font-size');
const lc = painter.getTextLineCount(text, font, scale, w);
const h = lc === 0 ? 0 : lc === 1 ? style.item.height : GetRenderedCharacterHeight(scale, font) * (lc + 1);
frame.beginItem(w, h);
painter.setColor(style.getPropertyAs<Color>(selector, 'color'));
if (lc === 1) painter.move(0, style.item.textOffset);
painter.drawMultilineText(text, font, scale, w);
frame.endItem();
}