Created
October 21, 2010 02:16
-
-
Save mnickel/637796 to your computer and use it in GitHub Desktop.
Learning exercise about "this" scoping and real javascript OO. Pay particular attention to this.bbox and it's use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| this.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