2011-05-16 09:15:47 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-16 09:15:47 -04:00
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-16 09:15:47 -04:00
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-07-01 06:17:45 -04:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-05-16 09:15:47 -04:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-06-22 18:56:05 -04:00
|
|
|
/**
|
|
|
|
* @name TextItem
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-22 18:56:05 -04: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 18:56:05 -04:00
|
|
|
* @extends Item
|
|
|
|
*/
|
|
|
|
var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
2011-11-24 09:44:26 -05:00
|
|
|
// TextItem doesn't make the distinction between the different bounds,
|
2011-11-24 10:03:05 -05:00
|
|
|
// so use the same name for all of them
|
|
|
|
_boundsType: 'bounds',
|
2011-11-24 09:44:26 -05:00
|
|
|
|
2011-12-20 17:33:53 -05:00
|
|
|
initialize: function(pointOrMatrix) {
|
2011-12-19 16:26:09 -05:00
|
|
|
// Note that internally #characterStyle is the same as #style, but
|
|
|
|
// defined as an instance of CharacterStyle. We need to define it before
|
|
|
|
// calling this.base(), to override the default PathStyle instance.
|
|
|
|
this._style = CharacterStyle.create(this);
|
|
|
|
this._paragraphStyle = ParagraphStyle.create(this);
|
2011-12-20 17:33:53 -05:00
|
|
|
this.base(pointOrMatrix);
|
2011-12-19 17:07:14 -05:00
|
|
|
// No need to call setStyle(), since base() handles this already.
|
2011-12-19 16:26:09 -05:00
|
|
|
// Call with no parameter to initalize defaults now.
|
|
|
|
this.setParagraphStyle();
|
2011-06-19 18:28:41 -04:00
|
|
|
this._content = '';
|
2011-11-23 12:12:41 -05:00
|
|
|
this._lines = [];
|
2011-05-16 09:15:47 -04:00
|
|
|
},
|
|
|
|
|
2011-05-23 12:52:54 -04:00
|
|
|
/**
|
|
|
|
* The text contents of the text item.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-23 12:52:54 -04:00
|
|
|
* @name TextItem#content
|
2011-05-27 14:15:15 -04:00
|
|
|
* @type String
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 08:05:58 -04:00
|
|
|
* @example {@paperscript}
|
|
|
|
* // Setting the content of a PointText item:
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 08:05:58 -04:00
|
|
|
* // Create a point-text item at {x: 30, y: 30}:
|
|
|
|
* var text = new PointText(new Point(30, 30));
|
2011-06-22 18:56:05 -04:00
|
|
|
* text.fillColor = 'black';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 08:05:58 -04:00
|
|
|
* // Set the content of the text item:
|
|
|
|
* text.content = 'Hello world';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 08:05:58 -04:00
|
|
|
* @example {@paperscript}
|
|
|
|
* // Interactive example, move your mouse over the view below:
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 08:05:58 -04:00
|
|
|
* // Create a point-text item at {x: 30, y: 30}:
|
|
|
|
* var text = new PointText(new Point(30, 30));
|
2011-06-22 18:56:05 -04:00
|
|
|
* text.fillColor = 'black';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 08:05:58 -04:00
|
|
|
* text.content = 'Move your mouse over the view, to see its position';
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-10 08:05:58 -04: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 12:52:54 -04:00
|
|
|
*/
|
|
|
|
|
2011-05-20 15:33:25 -04:00
|
|
|
_clone: function(copy) {
|
2011-11-23 12:12:41 -05:00
|
|
|
copy.setContent(this._content);
|
2011-05-20 15:33:25 -04:00
|
|
|
copy.setParagraphStyle(this._paragraphStyle);
|
|
|
|
return this.base(copy);
|
|
|
|
},
|
|
|
|
|
2011-06-19 18:28:41 -04:00
|
|
|
getContent: function() {
|
|
|
|
return this._content;
|
|
|
|
},
|
|
|
|
|
|
|
|
setContent: function(content) {
|
2011-06-30 09:12:14 -04:00
|
|
|
this._content = '' + content;
|
2011-11-23 12:12:41 -05:00
|
|
|
this._lines = this._content.split(/\r\n|\n|\r/mg);
|
|
|
|
this._changed(Change.CONTENT);
|
2011-06-19 18:28:41 -04:00
|
|
|
},
|
|
|
|
|
2011-05-23 12:52:54 -04:00
|
|
|
/**
|
2011-06-22 18:56:05 -04:00
|
|
|
* {@grouptitle Style Properties}
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-23 12:52:54 -04:00
|
|
|
* The character style of the text item.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-23 12:52:54 -04:00
|
|
|
* @type CharacterStyle
|
|
|
|
* @bean
|
|
|
|
*/
|
|
|
|
|
2011-12-19 16:26:09 -05:00
|
|
|
// As explained in CharacterStyle, this is internally the same as #style.
|
|
|
|
getCharacterStyle: function() {
|
|
|
|
return this.getStyle();
|
|
|
|
},
|
|
|
|
|
|
|
|
setCharacterStyle: function(style) {
|
|
|
|
this.setStyle(style);
|
2012-04-09 03:28:09 -04:00
|
|
|
}
|
2011-12-19 16:26:09 -05:00
|
|
|
|
2011-05-23 12:52:54 -04:00
|
|
|
/**
|
|
|
|
* The paragraph style of the text item.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-12-19 16:14:10 -05:00
|
|
|
* @name TextItem#getParagraphStyle
|
2011-05-23 12:52:54 -04:00
|
|
|
* @type ParagraphStyle
|
|
|
|
* @bean
|
|
|
|
*/
|
2011-05-16 09:15:47 -04:00
|
|
|
});
|