/** * Created by TonyJiang on 16/8/25. */ import * as React from "react"; import {observer} from "mobx-react/index"; import Editor from "../Editor"; import {Font} from "../../../../items/properties/classes/Font"; import {FontFamilyEditor} from "./FontFamilyEditor"; import {FontSizeEditor} from "./FontSizeEditor"; import {autobind} from "core-decorators"; import {Unit} from "../../../../drawing/Unit"; @observer export class FontEditor extends Editor{ constructor(props, context){ super(props, context); } propertyDefaultValue = { 'fontColor': 'rgba(0,0,0,1)', 'fontFamily': 'Arial', 'fontSize': Unit.pixel(12) }; getValue(){ const {items} = this.props; const defaultFont = new Font(); const fonts: Array = items.map(item => item.getPropertyValue(this.props.property)); const calFont = fonts[0].clone(); const fields = Font.getFields(); for(var font of fonts){ for(var field of fields){ if(field.type == 'Unit'){ if((font[field.name] as Unit).toPixel() != (calFont[field.name] as Unit).toPixel()){ calFont[field.name] = (defaultFont[field.name] as Unit).clone(); } }else{ if(font[field.name] != calFont[field.name]){ console.log('font field not match', field.name); calFont[field.name] = defaultFont[field.name]; } } } } return calFont; } renderValueEditor(){ const font:Font = this.getValue(); const {fontFamily, fontSize, isBold, isItalic, isUnderline, isStrikeThrough} = font; const boldClass = "editor-icon-font-bold " + (isBold ? " editor-icon-selected" : ""); const italicClass = "editor-icon-font-italic" + (isItalic ? " editor-icon-selected" : ""); const underlineClass = "editor-icon-font-underline" + (isUnderline ? " editor-icon-selected" : ""); const strikeThroughClass = "editor-icon-font-strike" + (isStrikeThrough ? " editor-icon-selected" : ""); return (
); } @autobind onFontFamilyChange(value){ const font:Font = this.getValue(); const newFont:Font = font ? font.clone() : new Font(); newFont.fontFamily = value; this.setValue(newFont); } @autobind onFontSizeChange(value){ const font:Font = this.getValue(); const newFont:Font = font ? font.clone() : new Font(); newFont.fontSize = value; this.setValue(newFont); } @autobind onFontBoldChange(){ const font:Font = this.getValue(); const newFont:Font = font ? font.clone() : new Font(); newFont.isBold = !newFont.isBold; this.setValue(newFont); } @autobind onFontItalicChange(){ const font:Font = this.getValue(); const newFont:Font = font ? font.clone() : new Font(); newFont.isItalic = !newFont.isItalic; this.setValue(newFont); } @autobind onFontUnderlineChange(){ const font:Font = this.getValue(); const newFont:Font = font ? font.clone() : new Font(); newFont.isUnderline = !newFont.isUnderline; this.setValue(newFont); } @autobind onFontStrikeThroughChange(){ const font:Font = this.getValue(); const newFont:Font = font ? font.clone() : new Font(); newFont.isStrikeThrough = !newFont.isStrikeThrough; this.setValue(newFont); } }