Skip to content

Commit

Permalink
0.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ted Patrick committed Nov 23, 2014
1 parent dff50ff commit b202e30
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 14 deletions.
35 changes: 30 additions & 5 deletions dist/txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ var txt;
if (lastLineWord != undefined && lastLineWord.hasSpace) {
currentLine.measuredWidth -= lastLineWord.spaceOffset;
}
currentLine.measuredHeight = vPosition;
if (firstLine == false && this.lineHeight != null) {
currentLine.measuredHeight = this.lineHeight;
}
else {
currentLine.measuredHeight = vPosition;
}
firstLine = false;
currentLine = new txt.Line();
this.lines.push(currentLine);
Expand All @@ -265,11 +270,21 @@ var txt;
this.block.addChild(currentLine);
var swapWord = this.words[i];
currentLine.addChild(swapWord);
currentLine.measuredHeight = swapWord.measuredHeight;
if (this.lineHeight != null) {
currentLine.measuredHeight = this.lineHeight;
}
else {
currentLine.measuredHeight = swapWord.measuredHeight;
}
currentLine.measuredWidth = swapWord.measuredWidth;
currentLine = new txt.Line();
this.lines.push(currentLine);
currentLine.y = lastHeight + vPosition;
if (this.lineHeight != null) {
currentLine.y = lastHeight + this.lineHeight;
}
else {
currentLine.y = lastHeight + vPosition;
}
this.block.addChild(currentLine);
if (i < len - 1) {
vPosition = 0;
Expand All @@ -288,7 +303,12 @@ var txt;
if (lastLineWord != undefined && lastLineWord.hasSpace) {
currentLine.measuredWidth -= lastLineWord.spaceOffset;
}
currentLine.measuredHeight = vPosition;
if (firstLine == false && this.lineHeight != null) {
currentLine.measuredHeight = this.lineHeight;
}
else {
currentLine.measuredHeight = vPosition;
}
firstLine = false;
currentLine = new txt.Line();
this.lines.push(currentLine);
Expand All @@ -308,7 +328,12 @@ var txt;
lastHeight = currentLine.y + vPosition;
}
currentLine.measuredWidth = hPosition + currentWord.measuredWidth;
currentLine.measuredHeight = vPosition;
if (firstLine == false && this.lineHeight != null) {
currentLine.measuredHeight = this.lineHeight;
}
else {
currentLine.measuredHeight = vPosition;
}
currentLine.addChild(this.words[i]);
firstLine = false;
currentLine = new txt.Line();
Expand Down
69 changes: 69 additions & 0 deletions examples/CharacterText/wordwrap_natural_lineheight.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>
<head>
<title>txt: CharacterText + Alignment Wordwrap Natural and LineHeight</title>

<script type="text/javascript" src="../../dist/easeljs-NEXT.min.js"></script>
<script type="text/javascript" src="../../dist/txt.js"></script>

<script type="text/javascript">
var canvas;
var stage;

var PIXEL_RATIO = (function () {
var ctx = document.createElement("canvas").getContext("2d"),
dpr = window.devicePixelRatio || 1,
bsr = ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;
return dpr / bsr;
})();

createHiDPICanvas = function(w, h, ratio) {
if (!ratio) { ratio = PIXEL_RATIO; }
var can = document.createElement("canvas");
can.width = w * ratio;
can.height = h * ratio;
can.style.width = w + "px";
can.style.height = h + "px";
can.getContext("2d").setTransform(ratio, 0, 0, ratio, 0, 0);
return can;
}


function init() {

canvas = createHiDPICanvas( 1000 , 1000 , 2 );
document.body.appendChild( canvas );
stage = new createjs.Stage(canvas);

var text = new txt.CharacterText( {
text:'123 444 555\n6',
font:'lato',
align:4,
tracking:0,
lineHeight:38.4,
ligatures:false,
width:123.86006745195687,
height:146.61010452961662,
size:32,
debug:true,
x:10,
y:10
} );
text.scaleX = text.scaleY = 10;

stage.addChild( text );

stage.update();

}

</script>

</head>
<body onload="init()">
</body>
</html>
69 changes: 69 additions & 0 deletions examples/Text/wordwrap_natural_lineheight.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>
<head>
<title>txt: Text + Alignment Wordwrap Natural and LineHeight</title>

<script type="text/javascript" src="../../dist/easeljs-NEXT.min.js"></script>
<script type="text/javascript" src="../../dist/txt.js"></script>

<script type="text/javascript">
var canvas;
var stage;

var PIXEL_RATIO = (function () {
var ctx = document.createElement("canvas").getContext("2d"),
dpr = window.devicePixelRatio || 1,
bsr = ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;
return dpr / bsr;
})();

createHiDPICanvas = function(w, h, ratio) {
if (!ratio) { ratio = PIXEL_RATIO; }
var can = document.createElement("canvas");
can.width = w * ratio;
can.height = h * ratio;
can.style.width = w + "px";
can.style.height = h + "px";
can.getContext("2d").setTransform(ratio, 0, 0, ratio, 0, 0);
return can;
}


function init() {

canvas = createHiDPICanvas( 1000 , 1000 , 2 );
document.body.appendChild( canvas );
stage = new createjs.Stage(canvas);

var text = new txt.Text( {
text:'123 444 555\n6',
font:'lato',
align:4,
tracking:0,
lineHeight:38.4,
ligatures:false,
width:123.86006745195687,
height:146.61010452961662,
size:32,
debug:true,
x:10,
y:10
} );
text.scaleX = text.scaleY = 10;

stage.addChild( text );

stage.update();

}

</script>

</head>
<body onload="init()">
</body>
</html>
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ <h2 class="content-subhead" id="text">Text</h2>
</li>
<li>
<a href="/examples/Text/wordwrap_natural_newline.html">Alignment - Wordwrap natural and newlines</a>
</li>
<li>
<a href="/examples/Text/wordwrap_natural_lineHeight.html">Alignment - Wordwrap natural and lineHeight</a>
</li>
<li>
<a href="/examples/Text/complete.html">Event - complete</a>
Expand Down Expand Up @@ -193,6 +196,9 @@ <h2 class="content-subhead" id="charactertext">CharacterText</h2>
</li>
<li>
<a href="/examples/CharacterText/wordwrap_natural_newline.html">Alignment - Wordwrap natural and newlines</a>
</li>
<li>
<a href="/examples/CharacterText/wordwrap_natural_lineHeight.html">Alignment - Wordwrap natural and lineHeight</a>
</li>
<li>
<a href="/examples/CharacterText/complete.html">Event - complete</a>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "txtjs",
"version": "0.8.3",
"version": "0.8.4",
"description": "A <canvas> font and typesetting engine for @CreateJS",
"author": "Ted Patrick (http://tedpatrick.com)",
"license": "BSD",
Expand All @@ -12,4 +12,4 @@
"typescript": "^1.1.0-1"
},
"repository": "diverted247/txtjs"
}
}
34 changes: 27 additions & 7 deletions src/txt/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ module txt {
if( lastLineWord != undefined && lastLineWord.hasSpace ){
currentLine.measuredWidth -= lastLineWord.spaceOffset;
}
currentLine.measuredHeight = vPosition;
if( firstLine == false && this.lineHeight != null ){
currentLine.measuredHeight = this.lineHeight;
}else{
currentLine.measuredHeight = vPosition;
}


firstLine = false;
currentLine = new txt.Line();
Expand All @@ -338,13 +343,21 @@ module txt {
//add word
var swapWord = this.words[ i ];
currentLine.addChild( swapWord );
currentLine.measuredHeight = swapWord.measuredHeight;
if( this.lineHeight != null ){
currentLine.measuredHeight = this.lineHeight;
}else{
currentLine.measuredHeight = swapWord.measuredHeight;
}
currentLine.measuredWidth = swapWord.measuredWidth;

//add new line
currentLine = new txt.Line();
this.lines.push( currentLine );
currentLine.y = lastHeight + vPosition;
if( this.lineHeight != null ){
currentLine.y = lastHeight + this.lineHeight;
}else{
currentLine.y = lastHeight + vPosition;
}
this.block.addChild( currentLine );
if( i < len - 1 ){
vPosition = 0;
Expand All @@ -365,7 +378,12 @@ module txt {
if( lastLineWord != undefined && lastLineWord.hasSpace ){
currentLine.measuredWidth -= lastLineWord.spaceOffset;
}
currentLine.measuredHeight = vPosition;
if( firstLine == false && this.lineHeight != null ){
currentLine.measuredHeight = this.lineHeight;
}else{
currentLine.measuredHeight = vPosition;
}


firstLine = false;
currentLine = new txt.Line();
Expand All @@ -387,8 +405,11 @@ module txt {
lastHeight = currentLine.y + vPosition;
}
currentLine.measuredWidth = hPosition + currentWord.measuredWidth;

currentLine.measuredHeight = vPosition;
if( firstLine == false && this.lineHeight != null ){
currentLine.measuredHeight = this.lineHeight;
}else{
currentLine.measuredHeight = vPosition;
}
currentLine.addChild( this.words[ i ] );

firstLine = false;
Expand Down Expand Up @@ -445,7 +466,6 @@ module txt {
}

measuredHeight += line.measuredHeight;

if( this.align === a.TOP_CENTER ){
//move to center
line.x = ( this.width - line.measuredWidth ) / 2;
Expand Down

0 comments on commit b202e30

Please sign in to comment.