Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Release 0.0.3

  • Loading branch information...
commit 102b8aaaee6b73aabaa477dc357f226a337b50d5 1 parent 358f86b
@tj tj authored
Showing with 22 additions and 11 deletions.
  1. +8 −0 History.md
  2. +13 −10 build/texty.js
  3. +1 −1  build/texty.min.js
View
8 History.md
@@ -1,4 +1,12 @@
+0.0.3 / 2011-09-02
+==================
+
+ * Added text resizing to example
+ * Fixed default line-height of null (aka .size)
+ * Fixed line-height support
+ * Fixed caret sizing
+
0.0.2 / 2011-07-29
==================
View
23 build/texty.js
@@ -382,7 +382,7 @@ Text.prototype.clearCSS = function(){
.font('Helvetica')
.color('#000')
.selectionBackground('#DFF3FC')
- .lineHeight(this._size);
+ .lineHeight(null);
};
/**
@@ -889,6 +889,7 @@ Text.prototype.drawSelection = function(ctx, x, y, size, text){
, last = before[beforeLen - 1]
, selected = text.slice(from, to).split('\n')
, selectionLen = selected.length
+ , lineHeight = this.lineHeight()
, px = size / 2
, ox = x
, oy = y
@@ -898,21 +899,21 @@ Text.prototype.drawSelection = function(ctx, x, y, size, text){
ctx.fillStyle = this._selectionBackgroundColor;
// first
- y += (beforeLen - 1) * size;
+ y += (beforeLen - 1) * lineHeight;
width = ctx.measureText(selected[0]).width;
last = ctx.measureText(last).width;
ctx.fillRect(x + last, y - px, width, size);
// mid
for (var i = 1, len = selectionLen - 1; i < len; ++i) {
- y += size;
+ y += lineHeight;
width = ctx.measureText(selected[i]).width;
ctx.fillRect(x, y - px, width, size);
}
// last
if (selectionLen < 2) return;
- y += size;
+ y += lineHeight;
last = selected[selectionLen - 1];
width = ctx.measureText(last).width;
ctx.fillRect(x, y - px, width, size);
@@ -955,14 +956,13 @@ Text.prototype.drawCaret = function(ctx, x, y, size, text){
Text.prototype.drawText = function(ctx, x, y, size, text){
var lines = text.split('\n')
+ , lineHeight = this.lineHeight()
, ox = x;
ctx.fillStyle = this._textColor;
- ctx.textBaseline = 'middle';
- ctx.font = this._size + 'px ' + this._families;
for (var i = 0, len = lines.length; i < len; ++i) {
ctx.fillText(lines[i], x, y);
x = ox;
- y += size;
+ y += lineHeight;
}
};
@@ -974,6 +974,7 @@ Text.prototype.drawText = function(ctx, x, y, size, text){
Text.prototype.drawLineDecoration = function(ctx, x, y, size, text, c){
var len = text.split('\n').length
+ , lineHeight = this.lineHeight()
, em = this.em(ctx);
ctx.save();
@@ -983,7 +984,7 @@ Text.prototype.drawLineDecoration = function(ctx, x, y, size, text, c){
ctx.fillText('function' == typeof c
? c(i)
: c, x, y);
- y += size;
+ y += lineHeight;
}
ctx.restore();
};
@@ -999,7 +1000,7 @@ Text.prototype.drawLineDecoration = function(ctx, x, y, size, text, c){
Text.prototype.bounds = function(ctx){
var text = this._text
, lines = text.split('\n')
- , size = this.lineHeight()
+ , size = Math.max(this._size, this.lineHeight())
, height = size * lines.length
, width = 0
, x = this.x
@@ -1044,11 +1045,13 @@ Text.prototype.drawBounds = function(ctx){
Text.prototype.draw = function(ctx){
if (!this.visible) return this;
var text = this._text
- , size = this.lineHeight()
+ , size = this._size
, x = this.x
, y = this.y;
this._width = ctx.measureText(text).width;
+ ctx.textBaseline = 'middle';
+ ctx.font = size + 'px ' + this._families;
if (this.selected) this.drawSelection(ctx, x, y, size, text);
this.drawCaret(ctx, x, y, size, text);
this.drawText(ctx, x, y, size, text);
View
2  build/texty.min.js
@@ -1 +1 @@
--function(){Caret=function Caret(text){this.text=text,this.pos=0,this.color("#888"),this.softLeft=/([A-Z][a-z0-9]*|[a-z0-9]+|_+| +)$/,this.softRight=/^([A-Z][a-z0-9]*|[a-z0-9]+|_+| +)/,this.hardLeft=/(\w+| +)$/,this.hardRight=/^(\w+| +)/,this.show()},Caret.prototype.show=function(){this.visible=!0;return this},Caret.prototype.hide=function(){this.visible=!1;return this},Caret.prototype.color=function(color){if(!color)return this;this._color=color;return this},Caret.prototype.move=function(n){var len=this.text._text.length;this.pos+=n,this.pos<0?this.pos=0:this.pos>len&&(this.pos=len);return this},Caret.prototype.moveLeft=function(n){return this.move(-(n||1))},Caret.prototype.moveRight=function(n){return this.move(n||1)},Caret.prototype.moveUp=function(){var lines=this.text._text.slice(0,this.pos).split("\n"),curr=lines.pop(),prev=lines.pop()||"",n=prev.slice(curr.length).length;return this.moveLeft(curr.length+n+1)},Caret.prototype.moveDown=function(){var lines=this.text._text.slice(this.pos).split("\n"),curr=lines.shift(),next=lines.shift()||"",n=next.slice(curr.length).length;return this.moveRight(curr.length+n+1)},Caret.prototype.moveTo=function(x,y){2==arguments.length?this.moveTo(this.text.indexOf(x,y)):this.pos=x;return this},Caret.prototype.moveWithPattern=function(regexp,direction){var text=this.text._text,captures,n=1;-1==direction?text=text.slice(0,this.pos):text=text.slice(this.pos);if(captures=regexp.exec(text))n=captures[1].length;this.move(-1==direction?-n:n);return n},Caret.prototype.moveLeftSoft=function(){return this.moveWithPattern(this.softLeft,-1)},Caret.prototype.moveRightSoft=function(){return this.moveWithPattern(this.softRight,1)},Caret.prototype.moveLeftHard=function(){return this.moveWithPattern(this.hardLeft,-1)},Caret.prototype.moveRightHard=function(){return this.moveWithPattern(this.hardRight,1)}}(),-function(){function toArray(args){var ret=[];for(var i=0,len=args.length;i<len;++i)ret.push(args[i]);return ret}EventEmitter=function EventEmitter(){this.callbacks={}},EventEmitter.prototype.on=function(event,fn){(this.callbacks[event]=this.callbacks[event]||[]).push(fn);return this},EventEmitter.prototype.emit=function(event){var args=toArray(arguments).slice(1),callbacks=this.callbacks[event];if(callbacks)for(var i=0,len=callbacks.length;i<len;++i)callbacks[i].apply(this,args);return this}}(),-function(){selectorStyle=function style(selector,prop){var cache=style.cache=style.cache||{},cid=selector+":"+prop;if(cache[cid])return cache[cid];var parts=selector.split(/ +/),len=parts.length,parent=root=document.createElement("div"),child,part;for(var i=0;i<len;++i)part=parts[i],child=document.createElement("div"),parent.appendChild(child),parent=child,"#"==part[0]?child.setAttribute("id",part.substr(1)):"."==part[0]&&child.setAttribute("class",part.substr(1));document.body.appendChild(root);var ret=getComputedStyle(child)[prop];document.body.removeChild(root);return cache[cid]=ret}}(),-function(){Text=function Text(str){this.caret=new Caret(this),this.hide().text(str||""),this.clearCSS()},Text.prototype.clearCSS=function(){this.caret.color("#888"),this.listStyle("none").size(20).font("Helvetica").color("#000").selectionBackground("#DFF3FC").lineHeight(this._size)},Text.prototype.inheritCSS=function(){var s=selectorStyle;this.size(parseInt(s(".text","font-size"),10)).font(s(".text","font-family")).color(s(".text","color")).selectionBackground(s(".text .selection","background-color")),this.listStyle(s(".text .line","list-style-type")).lineHeight(parseInt(s(".text .line","line-height"),10)),this.caret.color(s(".text .caret","color"))},Text.prototype.lineHeight=function(n){if(0==arguments.length)return this._lineHeight||this._size;this._lineHeight=n;return this},Text.prototype.toString=function(){return this.text()},Text.prototype.listStyle=function(style){if(0==arguments.length)return this._listStyle;if(!style)return this;this._listStyle=style;return this},Text.prototype.text=function(str){if(arguments.length){this._text=str;return this}return this._text},Text.prototype.color=function(color){if(!color)return this;this._textColor=color;return this},Text.prototype.selectionBackground=function(color){if(!color)return this;this._selectionBackgroundColor=color;return this},Text.prototype.remove=function(n){return this.removeAt(n,this.caret.pos)},Text.prototype.removeAt=function(n,pos){this._text=this._text.substr(0,pos-n)+this._text.substr(pos);return this.caret.move(-n)},Text.prototype.removeRange=function(from,to){this._text=this._text.substr(0,from)+this._text.substr(to);return this.deselect().caret.moveTo(from)},Text.prototype.selection=function(){if(!!this.selected){var from=this.selected.from,to=this.selected.to;return{string:this._text.slice(from,to),from:from,to:to}}},Text.prototype.removeSelection=function(){if(!this.selected)throw new Error("no selection is made");var from=this.selected.from,to=this.selected.to;return this.removeRange(from,to)},Text.prototype.clear=function(){return this.text("")},Text.prototype.insert=function(str){return this.insertAt(str,this.caret.pos)},Text.prototype.insertAt=function(str,pos){this._text=this._text.substr(0,pos)+str+this._text.substr(pos);return this.caret.move(str.length)},Text.prototype.em=function(ctx){return ctx.measureText("M").width},Text.prototype.indexOf=function(x,y){var text=this.text(),width=this._width,size=this.lineHeight(),lines=text.split("\n"),height=lines.length*size,charWidth=width/text.length,len=lines.length,x=x-this.x,y=y-this.y,pad=10;if(x<-pad||x>width+pad)return 0;if(y<-pad||y>height+pad)return 0;y<size&&(y=size),y=Math.ceil(y/size),y>len&&(y=len);var preceding=lines.slice(0,y-1).join("\n").length;y&&++preceding;var i=Math.round(preceding+x/charWidth);return i},Text.prototype.select=function(x,y,x2,y2){var from=this.indexOf(x,y),to=this.indexOf(x2,y2);return this.selectRange(from,to).caret.moveTo(x2,y2).text},Text.prototype.selectWordAt=function(x,y){var i=this.indexOf(x,y);this.caret.moveTo(i);var left=this.caret.moveLeftHard();this.selectLeft(left),this.caret.moveTo(i);var right=this.caret.moveRightHard();this.selectRight(right),this.caret.moveTo(i);return this},Text.prototype.selectLeft=function(n){var pos=this.caret.pos,n=n||1,selection;(selection=this.selection())?this.selectRange(selection.from-n,selection.to):this.selectRange(pos,pos+n);return this},Text.prototype.selectRight=function(n){var pos=this.caret.pos,n=n||1,selection;(selection=this.selection())?this.selectRange(selection.from,selection.to+n):this.selectRange(pos-n,pos);return this},Text.prototype.selectAll=function(){return this.selectRange(0,this._text.length)},Text.prototype.selectRange=function(from,to){var len=this._text.length,tmp;from>to&&(tmp=from,from=to,to=tmp),this.selected={from:from>0?from:0,to:to<len?to:len};return this},Text.prototype.deselect=function(){this.selected=null;return this},Text.prototype.moveTo=function(x,y){this.x=x,this.y=y;return this},Text.prototype.hide=function(){this.visible=!1;return this},Text.prototype.show=function(){this.visible=!0;return this},Text.prototype.font=function(families){if(0==arguments.length)return this._families;if(!families)return this;this._families=families;return this},Text.prototype.size=function(n){if(0==arguments.length)return this._size;if(!n)return this;this._size=n;return this},Text.prototype.drawSelection=function(ctx,x,y,size,text){var selection=this.selection(),from=selection.from,to=selection.to,before=text.slice(0,from).split("\n"),beforeLen=before.length,last=before[beforeLen-1],selected=text.slice(from,to).split("\n"),selectionLen=selected.length,px=size/2,ox=x,oy=y,width,line;ctx.fillStyle=this._selectionBackgroundColor,y+=(beforeLen-1)*size,width=ctx.measureText(selected[0]).width,last=ctx.measureText(last).width,ctx.fillRect(x+last,y-px,width,size);for(var i=1,len=selectionLen-1;i<len;++i)y+=size,width=ctx.measureText(selected[i]).width,ctx.fillRect(x,y-px,width,size);selectionLen<2||(y+=size,last=selected[selectionLen-1],width=ctx.measureText(last).width,ctx.fillRect(x,y-px,width,size))},Text.prototype.drawCaret=function(ctx,x,y,size,text){if(!!this.caret.visible){var lines=text.substr(0,this.caret.pos).split("\n"),len=lines.length,line=lines[len-1],px=size/2,caret=ctx.measureText(line).width+2,y=y+ --len*size;ctx.strokeStyle=this.caret._color,ctx.beginPath(),ctx.moveTo(x+caret,y-px-2),ctx.lineTo(x+caret,y+px+2),ctx.stroke()}},Text.prototype.drawText=function(ctx,x,y,size,text){var lines=text.split("\n"),ox=x;ctx.fillStyle=this._textColor,ctx.textBaseline="middle",ctx.font=this._size+"px "+this._families;for(var i=0,len=lines.length;i<len;++i)ctx.fillText(lines[i],x,y),x=ox,y+=size},Text.prototype.drawLineDecoration=function(ctx,x,y,size,text,c){var len=text.split("\n").length,em=this.em(ctx);ctx.save(),ctx.font=this._size*.65+"px "+this._families,x-=em;for(var i=0;i<len;++i)ctx.fillText("function"==typeof c?c(i):c,x,y),y+=size;ctx.restore()},Text.prototype.bounds=function(ctx){var text=this._text,lines=text.split("\n"),size=this.lineHeight(),height=size*lines.length,width=0,x=this.x,y=this.y;for(var i=0,len=lines.length;i<len;++i)width=Math.max(width,ctx.measureText(lines[i]).width);return{x:x,y:y-size/2,width:width,height:height}},Text.prototype.drawBounds=function(ctx){if(!this.visible)return this;var bounds=this.bounds(ctx);ctx.strokeStyle="rgba(255,0,0,.5)",ctx.strokeRect(bounds.x,bounds.y,bounds.width,bounds.height);return this},Text.prototype.draw=function(ctx){if(!this.visible)return this;var text=this._text,size=this.lineHeight(),x=this.x,y=this.y;this._width=ctx.measureText(text).width,this.selected&&this.drawSelection(ctx,x,y,size,text),this.drawCaret(ctx,x,y,size,text),this.drawText(ctx,x,y,size,text);var decoration;switch(this._listStyle){case"decimal":decoration=function(i){return++i+"."};break;case"square":decoration="■";break;case"circle":decoration="○";break;case"disc":decoration="●"}decoration&&this.drawLineDecoration(ctx,x,y,size,text,decoration);return this}}()
+-function(){Caret=function Caret(text){this.text=text,this.pos=0,this.color("#888"),this.softLeft=/([A-Z][a-z0-9]*|[a-z0-9]+|_+| +)$/,this.softRight=/^([A-Z][a-z0-9]*|[a-z0-9]+|_+| +)/,this.hardLeft=/(\w+| +)$/,this.hardRight=/^(\w+| +)/,this.show()},Caret.prototype.show=function(){this.visible=!0;return this},Caret.prototype.hide=function(){this.visible=!1;return this},Caret.prototype.color=function(color){if(!color)return this;this._color=color;return this},Caret.prototype.move=function(n){var len=this.text._text.length;this.pos+=n,this.pos<0?this.pos=0:this.pos>len&&(this.pos=len);return this},Caret.prototype.moveLeft=function(n){return this.move(-(n||1))},Caret.prototype.moveRight=function(n){return this.move(n||1)},Caret.prototype.moveUp=function(){var lines=this.text._text.slice(0,this.pos).split("\n"),curr=lines.pop(),prev=lines.pop()||"",n=prev.slice(curr.length).length;return this.moveLeft(curr.length+n+1)},Caret.prototype.moveDown=function(){var lines=this.text._text.slice(this.pos).split("\n"),curr=lines.shift(),next=lines.shift()||"",n=next.slice(curr.length).length;return this.moveRight(curr.length+n+1)},Caret.prototype.moveTo=function(x,y){2==arguments.length?this.moveTo(this.text.indexOf(x,y)):this.pos=x;return this},Caret.prototype.moveWithPattern=function(regexp,direction){var text=this.text._text,captures,n=1;-1==direction?text=text.slice(0,this.pos):text=text.slice(this.pos);if(captures=regexp.exec(text))n=captures[1].length;this.move(-1==direction?-n:n);return n},Caret.prototype.moveLeftSoft=function(){return this.moveWithPattern(this.softLeft,-1)},Caret.prototype.moveRightSoft=function(){return this.moveWithPattern(this.softRight,1)},Caret.prototype.moveLeftHard=function(){return this.moveWithPattern(this.hardLeft,-1)},Caret.prototype.moveRightHard=function(){return this.moveWithPattern(this.hardRight,1)}}(),-function(){function toArray(args){var ret=[];for(var i=0,len=args.length;i<len;++i)ret.push(args[i]);return ret}EventEmitter=function EventEmitter(){this.callbacks={}},EventEmitter.prototype.on=function(event,fn){(this.callbacks[event]=this.callbacks[event]||[]).push(fn);return this},EventEmitter.prototype.emit=function(event){var args=toArray(arguments).slice(1),callbacks=this.callbacks[event];if(callbacks)for(var i=0,len=callbacks.length;i<len;++i)callbacks[i].apply(this,args);return this}}(),-function(){selectorStyle=function style(selector,prop){var cache=style.cache=style.cache||{},cid=selector+":"+prop;if(cache[cid])return cache[cid];var parts=selector.split(/ +/),len=parts.length,parent=root=document.createElement("div"),child,part;for(var i=0;i<len;++i)part=parts[i],child=document.createElement("div"),parent.appendChild(child),parent=child,"#"==part[0]?child.setAttribute("id",part.substr(1)):"."==part[0]&&child.setAttribute("class",part.substr(1));document.body.appendChild(root);var ret=getComputedStyle(child)[prop];document.body.removeChild(root);return cache[cid]=ret}}(),-function(){Text=function Text(str){this.caret=new Caret(this),this.hide().text(str||""),this.clearCSS()},Text.prototype.clearCSS=function(){this.caret.color("#888"),this.listStyle("none").size(20).font("Helvetica").color("#000").selectionBackground("#DFF3FC").lineHeight(null)},Text.prototype.inheritCSS=function(){var s=selectorStyle;this.size(parseInt(s(".text","font-size"),10)).font(s(".text","font-family")).color(s(".text","color")).selectionBackground(s(".text .selection","background-color")),this.listStyle(s(".text .line","list-style-type")).lineHeight(parseInt(s(".text .line","line-height"),10)),this.caret.color(s(".text .caret","color"))},Text.prototype.lineHeight=function(n){if(0==arguments.length)return this._lineHeight||this._size;this._lineHeight=n;return this},Text.prototype.toString=function(){return this.text()},Text.prototype.listStyle=function(style){if(0==arguments.length)return this._listStyle;if(!style)return this;this._listStyle=style;return this},Text.prototype.text=function(str){if(arguments.length){this._text=str;return this}return this._text},Text.prototype.color=function(color){if(!color)return this;this._textColor=color;return this},Text.prototype.selectionBackground=function(color){if(!color)return this;this._selectionBackgroundColor=color;return this},Text.prototype.remove=function(n){return this.removeAt(n,this.caret.pos)},Text.prototype.removeAt=function(n,pos){this._text=this._text.substr(0,pos-n)+this._text.substr(pos);return this.caret.move(-n)},Text.prototype.removeRange=function(from,to){this._text=this._text.substr(0,from)+this._text.substr(to);return this.deselect().caret.moveTo(from)},Text.prototype.selection=function(){if(!!this.selected){var from=this.selected.from,to=this.selected.to;return{string:this._text.slice(from,to),from:from,to:to}}},Text.prototype.removeSelection=function(){if(!this.selected)throw new Error("no selection is made");var from=this.selected.from,to=this.selected.to;return this.removeRange(from,to)},Text.prototype.clear=function(){return this.text("")},Text.prototype.insert=function(str){return this.insertAt(str,this.caret.pos)},Text.prototype.insertAt=function(str,pos){this._text=this._text.substr(0,pos)+str+this._text.substr(pos);return this.caret.move(str.length)},Text.prototype.em=function(ctx){return ctx.measureText("M").width},Text.prototype.indexOf=function(x,y){var text=this.text(),width=this._width,size=this.lineHeight(),lines=text.split("\n"),height=lines.length*size,charWidth=width/text.length,len=lines.length,x=x-this.x,y=y-this.y,pad=10;if(x<-pad||x>width+pad)return 0;if(y<-pad||y>height+pad)return 0;y<size&&(y=size),y=Math.ceil(y/size),y>len&&(y=len);var preceding=lines.slice(0,y-1).join("\n").length;y&&++preceding;var i=Math.round(preceding+x/charWidth);return i},Text.prototype.select=function(x,y,x2,y2){var from=this.indexOf(x,y),to=this.indexOf(x2,y2);return this.selectRange(from,to).caret.moveTo(x2,y2).text},Text.prototype.selectWordAt=function(x,y){var i=this.indexOf(x,y);this.caret.moveTo(i);var left=this.caret.moveLeftHard();this.selectLeft(left),this.caret.moveTo(i);var right=this.caret.moveRightHard();this.selectRight(right),this.caret.moveTo(i);return this},Text.prototype.selectLeft=function(n){var pos=this.caret.pos,n=n||1,selection;(selection=this.selection())?this.selectRange(selection.from-n,selection.to):this.selectRange(pos,pos+n);return this},Text.prototype.selectRight=function(n){var pos=this.caret.pos,n=n||1,selection;(selection=this.selection())?this.selectRange(selection.from,selection.to+n):this.selectRange(pos-n,pos);return this},Text.prototype.selectAll=function(){return this.selectRange(0,this._text.length)},Text.prototype.selectRange=function(from,to){var len=this._text.length,tmp;from>to&&(tmp=from,from=to,to=tmp),this.selected={from:from>0?from:0,to:to<len?to:len};return this},Text.prototype.deselect=function(){this.selected=null;return this},Text.prototype.moveTo=function(x,y){this.x=x,this.y=y;return this},Text.prototype.hide=function(){this.visible=!1;return this},Text.prototype.show=function(){this.visible=!0;return this},Text.prototype.font=function(families){if(0==arguments.length)return this._families;if(!families)return this;this._families=families;return this},Text.prototype.size=function(n){if(0==arguments.length)return this._size;if(!n)return this;this._size=n;return this},Text.prototype.drawSelection=function(ctx,x,y,size,text){var selection=this.selection(),from=selection.from,to=selection.to,before=text.slice(0,from).split("\n"),beforeLen=before.length,last=before[beforeLen-1],selected=text.slice(from,to).split("\n"),selectionLen=selected.length,lineHeight=this.lineHeight(),px=size/2,ox=x,oy=y,width,line;ctx.fillStyle=this._selectionBackgroundColor,y+=(beforeLen-1)*lineHeight,width=ctx.measureText(selected[0]).width,last=ctx.measureText(last).width,ctx.fillRect(x+last,y-px,width,size);for(var i=1,len=selectionLen-1;i<len;++i)y+=lineHeight,width=ctx.measureText(selected[i]).width,ctx.fillRect(x,y-px,width,size);selectionLen<2||(y+=lineHeight,last=selected[selectionLen-1],width=ctx.measureText(last).width,ctx.fillRect(x,y-px,width,size))},Text.prototype.drawCaret=function(ctx,x,y,size,text){if(!!this.caret.visible){var lines=text.substr(0,this.caret.pos).split("\n"),len=lines.length,line=lines[len-1],px=size/2,caret=ctx.measureText(line).width+2,y=y+ --len*size;ctx.strokeStyle=this.caret._color,ctx.beginPath(),ctx.moveTo(x+caret,y-px-2),ctx.lineTo(x+caret,y+px+2),ctx.stroke()}},Text.prototype.drawText=function(ctx,x,y,size,text){var lines=text.split("\n"),lineHeight=this.lineHeight(),ox=x;ctx.fillStyle=this._textColor;for(var i=0,len=lines.length;i<len;++i)ctx.fillText(lines[i],x,y),x=ox,y+=lineHeight},Text.prototype.drawLineDecoration=function(ctx,x,y,size,text,c){var len=text.split("\n").length,lineHeight=this.lineHeight(),em=this.em(ctx);ctx.save(),ctx.font=this._size*.65+"px "+this._families,x-=em;for(var i=0;i<len;++i)ctx.fillText("function"==typeof c?c(i):c,x,y),y+=lineHeight;ctx.restore()},Text.prototype.bounds=function(ctx){var text=this._text,lines=text.split("\n"),size=Math.max(this._size,this.lineHeight()),height=size*lines.length,width=0,x=this.x,y=this.y;for(var i=0,len=lines.length;i<len;++i)width=Math.max(width,ctx.measureText(lines[i]).width);return{x:x,y:y-size/2,width:width,height:height}},Text.prototype.drawBounds=function(ctx){if(!this.visible)return this;var bounds=this.bounds(ctx);ctx.strokeStyle="rgba(255,0,0,.5)",ctx.strokeRect(bounds.x,bounds.y,bounds.width,bounds.height);return this},Text.prototype.draw=function(ctx){if(!this.visible)return this;var text=this._text,size=this._size,x=this.x,y=this.y;this._width=ctx.measureText(text).width,ctx.textBaseline="middle",ctx.font=size+"px "+this._families,this.selected&&this.drawSelection(ctx,x,y,size,text),this.drawCaret(ctx,x,y,size,text),this.drawText(ctx,x,y,size,text);var decoration;switch(this._listStyle){case"decimal":decoration=function(i){return++i+"."};break;case"square":decoration="■";break;case"circle":decoration="○";break;case"disc":decoration="●"}decoration&&this.drawLineDecoration(ctx,x,y,size,text,decoration);return this}}()
Please sign in to comment.
Something went wrong with that request. Please try again.