2017-06-04 10:40:14 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
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);
|
|
|
|
}
|
|
|
|
|
2017-05-10 04:34:46 +08:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
return this.props.shape.version != nextProps.shape.version;
|
|
|
|
}
|
|
|
|
|
2016-06-15 04:01:11 +08:00
|
|
|
getCoordinates() {
|
2017-06-03 03:25:02 +08:00
|
|
|
const x = this.props.shape.x / 100 * this.props.slideWidth;
|
|
|
|
const y = this.props.shape.y / 100 * this.props.slideHeight;
|
|
|
|
const width = this.props.shape.textBoxWidth / 100 * this.props.slideWidth;
|
|
|
|
const height = this.props.shape.textBoxHeight / 100 * this.props.slideHeight;
|
|
|
|
const fontColor = ShapeHelpers.formatColor(this.props.shape.fontColor);
|
|
|
|
const fontSize = this.props.shape.fontSize;
|
|
|
|
const calcedFontSize = this.props.shape.calcedFontSize / 100 * this.props.slideHeight;
|
|
|
|
const text = this.props.shape.text;
|
2016-06-15 04:01:11 +08:00
|
|
|
|
|
|
|
return {
|
2017-06-03 03:25:02 +08:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
text,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
fontSize,
|
|
|
|
fontColor,
|
|
|
|
calcedFontSize,
|
2016-06-15 04:01:11 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getStyles(results) {
|
2017-06-03 03:25:02 +08:00
|
|
|
const 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;
|
|
|
|
}
|
|
|
|
|
2017-06-07 08:14:36 +08:00
|
|
|
renderViewerTextShape(results, styles) {
|
2016-05-31 06:07:02 +08:00
|
|
|
return (
|
2017-06-07 08:14:36 +08:00
|
|
|
<g>
|
2017-06-10 05:55:38 +08:00
|
|
|
<clipPath id={this.props.shape.id}>
|
2017-06-07 08:14:36 +08:00
|
|
|
<rect
|
|
|
|
x={results.x}
|
|
|
|
y={results.y}
|
|
|
|
width={results.width}
|
|
|
|
height={results.height}
|
|
|
|
fill="purple"
|
|
|
|
strokeWidth="2"
|
|
|
|
/>
|
|
|
|
</clipPath>
|
|
|
|
|
|
|
|
<foreignObject
|
2017-06-10 05:55:38 +08:00
|
|
|
clipPath={`url(#${this.props.shape.id})`}
|
2016-06-15 04:01:11 +08:00
|
|
|
x={results.x}
|
|
|
|
y={results.y}
|
|
|
|
width={results.width}
|
|
|
|
height={results.height}
|
2017-06-07 08:14:36 +08:00
|
|
|
>
|
|
|
|
<p style={styles}>
|
|
|
|
{results.text}
|
|
|
|
</p>
|
|
|
|
</foreignObject>
|
|
|
|
</g>
|
|
|
|
);
|
|
|
|
}
|
2016-05-31 06:07:02 +08:00
|
|
|
|
2017-06-07 08:14:36 +08:00
|
|
|
renderPresenterTextShape(results, styles) {
|
|
|
|
return (
|
|
|
|
<g></g>
|
2016-05-31 06:07:02 +08:00
|
|
|
);
|
|
|
|
}
|
2017-06-07 08:14:36 +08:00
|
|
|
|
|
|
|
render() {
|
|
|
|
let results = this.getCoordinates();
|
|
|
|
let styles = this.getStyles(results);
|
|
|
|
|
|
|
|
if(this.props.isPresenter && this.props.shape.status != "textPublished") {
|
|
|
|
return this.renderPresenterTextShape(results, styles);
|
|
|
|
} else {
|
|
|
|
return this.renderViewerTextShape(results, styles);
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 06:07:02 +08:00
|
|
|
}
|
2016-06-15 04:01:11 +08:00
|
|
|
|
|
|
|
TextDrawComponent.defaultProps = {
|
|
|
|
|
|
|
|
};
|