import { defaultValue } from '../util'
import Zondy from './Zondy'
/**
* 字体样式,参考示例:<a href='#new-Font'>[字体样式]</a>
* @class Font
* @param {Object} options 构造参数
* @param {String} [options.family = '宋体'] 字体名
* @param {Number} [options.size = 9] 字体大小,单位像素
* @param {String} [options.style = 'normal'] 字体样式, 可选"normal"|"italic"|"oblique"
* @param {String} [options.weight = 'normal'] 字体粗细, 可选"normal"|"bold"|"bolder"|"lighter"
*
* @summary <h5>支持如下方法:</h5>
* <a href='#toJSON'>[1、转换为json对象]</a><br/>
* <a href='#clone'>[2、克隆并返回一个新的LabelClass对象]</a><br/>
* <a href='#fromJSON'>[3、将JSON里的数据导入,并返回一个新的LabelClass对象]</a><br/>
*
* @example <caption><h7 id='new-Font'>创建字体样式</h7></caption>
* const font = new Zondy.Font({
* // 字体
* family: "微软雅黑",
* // 文字大小,单位像素
* size: 30,
* // 文字是否为斜体,正常模式
* style: "normal",
* // 文字粗细
* weight: "normal"
* })
*/
class Font {
constructor(options) {
options = defaultValue(options, {})
/**
* 字体名
* @default 微软雅黑
* @member {String} Font.prototype.family
*/
this.family = defaultValue(options.family, '微软雅黑')
/**
* 字体大小
* @default 12
* @member {Number} Font.prototype.size
*/
this.size = defaultValue(options.size, 12)
/**
* 字体样式
* @default normal
* @member {String} Font.prototype.style
*/
this.style = defaultValue(options.style, 'normal')
/**
* 字体粗细
* @default normal
* @member {String} Font.prototype.weight
*/
this.weight = defaultValue(options.weight, 'normal')
}
/**
* 将JSON里的数据导入,并返回一个新的Font对象<a id='fromJSON'></a>
* @param {Object} [json] 新的Font对象
* @return {Font} 新的Font对象
*/
static fromJSON(json) {
json = defaultValue(json, {})
return new Font(json)
}
/**
* 转换为json对象<a id='toJSON'></a>
* @returns {Font} Font对象
*/
toJSON() {
const json = {}
json.family = this.family
json.size = this.size
json.style = this.style
json.weight = this.weight
return json
}
/**
* 克隆并返回一个新的Font对象<a id='clone'></a>
* @returns {Font} Font对象
*/
clone() {
return new Font(this.toJSON())
}
}
Zondy.Font = Font
export default Font