2016-05-31 06:07:02 +08:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-06-15 04:01:11 +08:00
|
|
|
import ShapeHelpers from '../helpers.js';
|
2016-05-31 06:07:02 +08:00
|
|
|
|
|
|
|
export default class TextDrawComponent extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2016-06-15 04:01:11 +08:00
|
|
|
getCoordinates() {
|
2016-06-25 05:30:37 +08:00
|
|
|
let x = this.props.shape.x / 100 * this.props.slideWidth;
|
|
|
|
let y = this.props.shape.y / 100 * this.props.slideHeight;
|
|
|
|
let width = this.props.shape.textBoxWidth / 100 * this.props.slideWidth;
|
|
|
|
let height = this.props.shape.textBoxHeight / 100 * this.props.slideHeight;
|
|
|
|
let fontColor = ShapeHelpers.formatColor(this.props.shape.fontColor);
|
|
|
|
let fontSize = this.props.shape.fontSize;
|
|
|
|
let calcedFontSize = this.props.shape.calcedFontSize / 100 * this.props.slideHeight;
|
|
|
|
let text = this.props.shape.text;
|
2016-06-15 04:01:11 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
text: text,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
fontSize: fontSize,
|
|
|
|
fontColor: fontColor,
|
|
|
|
calcedFontSize: calcedFontSize,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getStyles(results) {
|
|
|
|
let styles = {
|
2016-05-31 06:07:02 +08:00
|
|
|
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
|
2016-06-15 04:01:11 +08:00
|
|
|
pointerEvents: 'none',
|
|
|
|
fontStyle: 'normal',
|
|
|
|
fontVariant: 'normal',
|
|
|
|
fontWeight: 'normal',
|
|
|
|
fontStretch: 'normal',
|
|
|
|
lineHeight: 'normal',
|
|
|
|
fontFamily: 'Arial',
|
2017-05-13 03:43:06 +08:00
|
|
|
whiteSpace: 'pre-wrap',
|
2016-06-15 04:01:11 +08:00
|
|
|
wordWrap: 'break-word',
|
|
|
|
wordBreak: 'normal',
|
|
|
|
textAlign: 'left',
|
2016-06-23 06:17:31 +08:00
|
|
|
margin: 0,
|
2016-06-15 04:01:11 +08:00
|
|
|
color: results.fontColor,
|
|
|
|
fontSize: results.calcedFontSize,
|
2016-05-31 06:07:02 +08:00
|
|
|
};
|
2016-06-15 04:01:11 +08:00
|
|
|
return styles;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let results = this.getCoordinates();
|
|
|
|
let styles = this.getStyles(results);
|
|
|
|
|
2016-05-31 06:07:02 +08:00
|
|
|
return (
|
2016-06-15 04:01:11 +08:00
|
|
|
<g>
|
|
|
|
<clipPath id="c1">
|
|
|
|
<rect
|
|
|
|
x={results.x}
|
|
|
|
y={results.y}
|
|
|
|
width={results.width}
|
|
|
|
height={results.height}
|
|
|
|
fill="purple"
|
|
|
|
strokeWidth="2"
|
|
|
|
/>
|
|
|
|
</clipPath>
|
2016-05-31 06:07:02 +08:00
|
|
|
|
2016-06-15 04:01:11 +08:00
|
|
|
<foreignObject
|
|
|
|
clipPath="url(#c1)"
|
|
|
|
x={results.x}
|
|
|
|
y={results.y}
|
|
|
|
width={results.width}
|
|
|
|
height={results.height}
|
2016-05-31 06:07:02 +08:00
|
|
|
>
|
2016-06-15 04:01:11 +08:00
|
|
|
<p style={styles}>
|
|
|
|
{results.text}
|
|
|
|
</p>
|
|
|
|
</foreignObject>
|
|
|
|
</g>
|
2016-05-31 06:07:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 04:01:11 +08:00
|
|
|
|
|
|
|
TextDrawComponent.defaultProps = {
|
|
|
|
|
|
|
|
};
|