+
+
+
+
+
+
+
+
+
+
+
+
;
+ }
+
+ setColor(color, colorName) {
+ this.setState({color, colorName});
+ this.textInput.current.focus();
+ }
+
+ onClickConfirm(e) {
+ // Exit if user doesn't enter any text
+ if (!this.textInput.current.textContent) {
+ if (this.props.cancelTextHandler) {
+ this.props.cancelTextHandler();
+ }
+ sendEvent("cancel-text", "text-toolbar");
+ return;
+ }
+ const styles = window.getComputedStyle(this.textInput.current);
+ const FONT_SIZE = parseInt(styles["font-size"], 10);
+ const x = this.state.left + parseFloat(styles["padding-left"]);
+ const y = this.state.top + TEXT_INPUT_PADDING + parseFloat(styles["line-height"]) / 2;
+
+ const textCanvas = document.createElement("canvas");
+ textCanvas.width = this.props.baseCanvas.width;
+ textCanvas.height = this.props.baseCanvas.height;
+ const drawingContext = textCanvas.getContext("2d");
+
+ drawingContext.scale(this.props.canvasPixelRatio, this.props.canvasPixelRatio);
+ drawingContext.textBaseline = "middle";
+ drawingContext.fillStyle = styles.backgroundColor;
+ drawingContext.fillRect(this.state.left,
+ this.state.top,
+ this.textInput.current.clientWidth,
+ this.textInput.current.clientHeight);
+ drawingContext.fillStyle = styles.color;
+ drawingContext.font = `${FONT_WEIGHT} ${FONT_SIZE}px ${FONT_STYLE}`;
+ drawingContext.fillText(this.textInput.current.textContent, x, y);
+
+ const textSelection = new Selection(this.state.left,
+ this.state.top,
+ this.state.left + this.textInput.current.clientWidth,
+ this.state.top + this.textInput.current.clientHeight);
+
+ if (this.props.confirmTextHandler) {
+ this.props.confirmTextHandler(textSelection, textCanvas);
+ }
+ sendEvent("confirm-text", "text-toolbar");
+ }
+
+ onClickCancel(e) {
+ if (this.props.cancelTextHandler) {
+ this.props.cancelTextHandler();
+ }
+ sendEvent("cancel-text", "text-toolbar");
+ }
+
+ onKeyDown(e) {
+ this.adjustX(e);
+ }
+
+ onKeyUp(e) {
+ // Fix to remove