2011-05-16 15:15:47 +02:00
|
|
|
/*
|
2013-01-28 18:03:27 -08:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-05-16 15:15:47 +02:00
|
|
|
* http://paperjs.org/
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2013-01-28 18:03:27 -08:00
|
|
|
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
2011-05-16 15:15:47 +02:00
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-07-01 12:17:45 +02:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-05-16 15:15:47 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-06-22 23:56:05 +01:00
|
|
|
/**
|
|
|
|
* @name CharacterStyle
|
|
|
|
*
|
|
|
|
* @class The CharacterStyle object represents the character style of a text
|
|
|
|
* item ({@link TextItem#characterStyle})
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-22 23:56:05 +01:00
|
|
|
* @extends PathStyle
|
|
|
|
*
|
|
|
|
* @classexample
|
|
|
|
* var text = new PointText(new Point(50, 50));
|
|
|
|
* text.content = 'Hello world.';
|
|
|
|
* text.characterStyle = {
|
|
|
|
* fontSize: 50,
|
|
|
|
* fillColor: 'black',
|
|
|
|
* };
|
|
|
|
*/
|
2011-12-19 22:26:09 +01:00
|
|
|
// Note that CharacterStyle extends PathStyle and thus injects the same
|
2011-12-19 22:03:36 +01:00
|
|
|
// accessors into its _owner TextItem, overriding those previously defined by
|
2011-12-19 22:26:09 +01:00
|
|
|
// PathStyle for Item. It is also returned from TextItem#getStyle instead of
|
|
|
|
// PathStyle. TextItem#characterStyle is now simply a pointer to #style.
|
2011-06-22 23:56:05 +01:00
|
|
|
var CharacterStyle = this.CharacterStyle = PathStyle.extend(/** @lends CharacterStyle# */{
|
2011-12-20 22:36:24 +01:00
|
|
|
_owner: TextItem,
|
|
|
|
_style: 'style',
|
2011-06-20 20:25:02 +01:00
|
|
|
_defaults: Base.merge(PathStyle.prototype._defaults, {
|
|
|
|
// Override default fillColor of CharacterStyle
|
|
|
|
fillColor: 'black',
|
2011-12-18 16:56:31 +01:00
|
|
|
fontSize: 12,
|
2011-11-23 18:12:41 +01:00
|
|
|
leading: null,
|
2011-06-20 14:10:37 +01:00
|
|
|
font: 'sans-serif'
|
2011-12-20 22:37:46 +01:00
|
|
|
}),
|
|
|
|
_flags: {
|
2012-11-05 18:11:44 -08:00
|
|
|
fontSize: /*#=*/ Change.GEOMETRY,
|
|
|
|
leading: /*#=*/ Change.GEOMETRY,
|
|
|
|
font: /*#=*/ Change.GEOMETRY
|
2011-12-20 22:37:46 +01:00
|
|
|
}
|
2011-06-20 14:10:37 +01:00
|
|
|
|
2011-05-23 19:28:55 +02:00
|
|
|
/**
|
|
|
|
* CharacterStyle objects don't need to be created directly. Just pass an
|
|
|
|
* object to {@link TextItem#characterStyle}, it will be converted to a
|
|
|
|
* CharacterStyle object internally.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-22 23:56:05 +01:00
|
|
|
* @name CharacterStyle#initialize
|
2011-05-23 19:28:55 +02:00
|
|
|
* @param {object} style
|
|
|
|
*/
|
2011-05-17 13:14:04 +01:00
|
|
|
|
2011-05-23 19:28:55 +02:00
|
|
|
/**
|
|
|
|
* The font of the character style.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-23 19:28:55 +02:00
|
|
|
* @name CharacterStyle#font
|
|
|
|
* @default 'sans-serif'
|
2011-05-27 20:15:15 +02:00
|
|
|
* @type String
|
2011-05-23 19:28:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The font size of the character style in points.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-23 19:28:55 +02:00
|
|
|
* @name CharacterStyle#fontSize
|
|
|
|
* @default 10
|
2011-05-27 20:15:15 +02:00
|
|
|
* @type Number
|
2011-05-23 19:28:55 +02:00
|
|
|
*/
|
2011-11-23 18:12:41 +01:00
|
|
|
}, {
|
|
|
|
getLeading: function() {
|
|
|
|
// Override leading to return fontSize * 1.2 by default, when undefined
|
|
|
|
var leading = this.base();
|
|
|
|
return leading != null ? leading : this.getFontSize() * 1.2;
|
2011-12-19 23:05:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getFontStyle: function() {
|
|
|
|
return this._fontSize + 'px ' + this._font;
|
2011-11-23 18:12:41 +01:00
|
|
|
}
|
2011-05-16 15:15:47 +02:00
|
|
|
});
|