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 TextItem
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-22 23:56:05 +01:00
|
|
|
* @class The TextItem type allows you to create typography. Its
|
|
|
|
* functionality is inherited by different text item types such as
|
|
|
|
* {@link PointText}, and {@link AreaText} (coming soon). They each add a
|
|
|
|
* layer of functionality that is unique to their type, but share the
|
|
|
|
* underlying properties and functions that they inherit from TextItem.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-22 23:56:05 +01:00
|
|
|
* @extends Item
|
|
|
|
*/
|
2013-05-27 12:48:58 -07:00
|
|
|
var TextItem = Item.extend(/** @lends TextItem# */{
|
2013-06-23 20:18:32 -07:00
|
|
|
_class: 'TextItem',
|
2013-02-24 15:53:37 -08:00
|
|
|
_boundsSelected: true,
|
2013-02-11 17:08:39 -08:00
|
|
|
_serializeFields: {
|
|
|
|
content: null
|
|
|
|
},
|
2011-11-24 15:44:26 +01:00
|
|
|
// TextItem doesn't make the distinction between the different bounds,
|
2011-11-24 16:03:05 +01:00
|
|
|
// so use the same name for all of them
|
2012-12-15 08:19:10 -08:00
|
|
|
_boundsGetter: 'getBounds',
|
2011-11-24 15:44:26 +01:00
|
|
|
|
2013-05-27 12:48:58 -07:00
|
|
|
initialize: function TextItem(arg) {
|
2012-12-25 22:12:25 +01:00
|
|
|
// Support two forms of item initialization: Passing one object literal
|
|
|
|
// describing all the different properties to be set, or a point where
|
|
|
|
// it should be placed (arg).
|
|
|
|
// See if a point is passed, and if so, pass it on to base(). If not, it
|
|
|
|
// might be a properties object literal for #setPropeties() at the end.
|
2013-04-07 17:36:09 -07:00
|
|
|
var hasProperties = arg && Base.isPlainObject(arg)
|
2013-02-11 17:08:39 -08:00
|
|
|
&& arg.x === undefined && arg.y === undefined;
|
2013-05-27 09:11:50 -07:00
|
|
|
Item.call(this, hasProperties ? null : Point.read(arguments));
|
2011-06-19 23:28:41 +01:00
|
|
|
this._content = '';
|
2011-11-23 18:12:41 +01:00
|
|
|
this._lines = [];
|
2013-04-07 17:36:09 -07:00
|
|
|
if (hasProperties)
|
2013-02-15 18:28:49 -08:00
|
|
|
this._set(arg);
|
2011-05-16 15:15:47 +02:00
|
|
|
},
|
|
|
|
|
2011-05-23 18:52:54 +02:00
|
|
|
/**
|
|
|
|
* The text contents of the text item.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-23 18:52:54 +02:00
|
|
|
* @name TextItem#content
|
2011-05-27 20:15:15 +02:00
|
|
|
* @type String
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 14:05:58 +02:00
|
|
|
* @example {@paperscript}
|
|
|
|
* // Setting the content of a PointText item:
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 14:05:58 +02:00
|
|
|
* // Create a point-text item at {x: 30, y: 30}:
|
|
|
|
* var text = new PointText(new Point(30, 30));
|
2011-06-22 23:56:05 +01:00
|
|
|
* text.fillColor = 'black';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 14:05:58 +02:00
|
|
|
* // Set the content of the text item:
|
|
|
|
* text.content = 'Hello world';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 14:05:58 +02:00
|
|
|
* @example {@paperscript}
|
|
|
|
* // Interactive example, move your mouse over the view below:
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 14:05:58 +02:00
|
|
|
* // Create a point-text item at {x: 30, y: 30}:
|
|
|
|
* var text = new PointText(new Point(30, 30));
|
2011-06-22 23:56:05 +01:00
|
|
|
* text.fillColor = 'black';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 14:05:58 +02:00
|
|
|
* text.content = 'Move your mouse over the view, to see its position';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 14:05:58 +02:00
|
|
|
* function onMouseMove(event) {
|
|
|
|
* // Each time the mouse is moved, set the content of
|
|
|
|
* // the point text to describe the position of the mouse:
|
|
|
|
* text.content = 'Your position is: ' + event.point.toString();
|
|
|
|
* }
|
2011-05-23 18:52:54 +02:00
|
|
|
*/
|
|
|
|
|
2013-05-27 10:04:05 -07:00
|
|
|
_clone: function _clone(copy) {
|
2011-11-23 18:12:41 +01:00
|
|
|
copy.setContent(this._content);
|
2013-05-27 10:04:05 -07:00
|
|
|
return _clone.base.call(this, copy);
|
2011-05-20 21:33:25 +02:00
|
|
|
},
|
|
|
|
|
2011-06-19 23:28:41 +01:00
|
|
|
getContent: function() {
|
|
|
|
return this._content;
|
|
|
|
},
|
|
|
|
|
|
|
|
setContent: function(content) {
|
2011-06-30 09:12:14 -04:00
|
|
|
this._content = '' + content;
|
2011-11-23 18:12:41 +01:00
|
|
|
this._lines = this._content.split(/\r\n|\n|\r/mg);
|
2012-11-05 18:11:44 -08:00
|
|
|
this._changed(/*#=*/ Change.CONTENT);
|
2011-06-19 23:28:41 +01:00
|
|
|
},
|
|
|
|
|
2012-10-10 20:11:11 -07:00
|
|
|
isEmpty: function() {
|
2012-12-18 05:29:03 +01:00
|
|
|
return !this._content;
|
2012-10-10 20:11:11 -07:00
|
|
|
},
|
|
|
|
|
2011-05-23 18:52:54 +02:00
|
|
|
/**
|
2013-04-09 16:46:20 -07:00
|
|
|
* @private
|
|
|
|
* @deprecated use {@link #getStyle()} instead.
|
2011-05-23 18:52:54 +02:00
|
|
|
*/
|
2013-05-06 21:01:04 -07:00
|
|
|
getCharacterStyle: '#getStyle',
|
|
|
|
setCharacterStyle: '#setStyle',
|
2011-12-19 22:26:09 +01:00
|
|
|
|
2011-05-23 18:52:54 +02:00
|
|
|
/**
|
2013-04-09 16:46:20 -07:00
|
|
|
* @private
|
|
|
|
* @deprecated use {@link #getStyle()} instead.
|
2011-05-23 18:52:54 +02:00
|
|
|
*/
|
2013-05-06 21:01:04 -07:00
|
|
|
getParagraphStyle: '#getStyle',
|
|
|
|
setParagraphStyle: '#setStyle'
|
2011-05-16 15:15:47 +02:00
|
|
|
});
|