Skip to content

Instantly share code, notes, and snippets.

@ryedin
Forked from mnickel/CharacterElement.js
Created October 21, 2010 15:05
Show Gist options
  • Select an option

  • Save ryedin/638631 to your computer and use it in GitHub Desktop.

Select an option

Save ryedin/638631 to your computer and use it in GitHub Desktop.
var CharacterElement = function(locChar) {
this.x = null;
this.y = null;
this.width = null;
this.dy = null;
this.value = (locChar !== null) ? locChar : "";
this.se_newline = "";
this.characterAttribute = null;
this.bbox = null;
};
CharacterElement.prototype = {
setBBox: function( charAttr ) {
// precompute the bounding box coordinates for the
// character
this.bbox = {
ul: {
x: this.x,
y: this.y + (charAttr.attr.font_size * charAttr.attr.leading) + (charAttr.attr.font_size * charAttr.attr.ascent)
},
ur: {
x: this.x + this.width,
y: this.y + (charAttr.attr.font_size * charAttr.attr.ascent)
},
ll: {
x: this.x,
y: this.y - (charAttr.attr.font_size * charAttr.attr.descent)
},
lr: {
x: this.x + this.width,
y: this.y - (charAttr.attr.font_size * charAttr.attr.descent)
}
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment