1- /*! p5.js v0.3.6 September 11 , 2014 */
1+ /*! p5.js v0.3.6 September 14 , 2014 */
22var shim = function ( require ) {
33 window . requestDraw = function ( ) {
44 return window . requestAnimationFrame || window . webkitRequestAnimationFrame || window . mozRequestAnimationFrame || window . oRequestAnimationFrame || window . msRequestAnimationFrame || function ( callback , element ) {
@@ -4520,14 +4520,13 @@ var typographyattributes = function (require, core, constants) {
45204520 p5 . prototype . _textFont = 'sans-serif' ;
45214521 p5 . prototype . _textSize = 12 ;
45224522 p5 . prototype . _textStyle = constants . NORMAL ;
4523+ p5 . prototype . _textAscent = null ;
4524+ p5 . prototype . _textDescent = null ;
45234525 p5 . prototype . textAlign = function ( a ) {
45244526 if ( a === constants . LEFT || a === constants . RIGHT || a === constants . CENTER ) {
45254527 this . drawingContext . textAlign = a ;
45264528 }
45274529 } ;
4528- p5 . prototype . textHeight = function ( s ) {
4529- return this . drawingContext . measureText ( s ) . height ;
4530- } ;
45314530 p5 . prototype . textLeading = function ( l ) {
45324531 this . _setProperty ( '_textLeading' , l ) ;
45334532 } ;
@@ -4544,10 +4543,68 @@ var typographyattributes = function (require, core, constants) {
45444543 p5 . prototype . textWidth = function ( s ) {
45454544 return this . drawingContext . measureText ( s ) . width ;
45464545 } ;
4546+ p5 . prototype . textAscent = function ( ) {
4547+ if ( this . _textAscent == null ) {
4548+ this . _updateTextMetrics ( ) ;
4549+ }
4550+ return this . _textAscent ;
4551+ } ;
4552+ p5 . prototype . textDescent = function ( ) {
4553+ if ( this . _textDescent == null ) {
4554+ this . _updateTextMetrics ( ) ;
4555+ }
4556+ return this . _textDescent ;
4557+ } ;
45474558 p5 . prototype . _applyTextProperties = function ( ) {
4559+ this . _setProperty ( '_textAscent' , null ) ;
4560+ this . _setProperty ( '_textDescent' , null ) ;
45484561 var str = this . _textStyle + ' ' + this . _textSize + 'px ' + this . _textFont ;
45494562 this . drawingContext . font = str ;
45504563 } ;
4564+ p5 . prototype . _updateTextMetrics = function ( ) {
4565+ var text = document . createElement ( 'span' ) ;
4566+ text . style . fontFamily = this . _textFont ;
4567+ text . style . fontSize = this . _textSize + 'px' ;
4568+ text . innerHTML = 'ABCjgq|' ;
4569+ var block = document . createElement ( 'div' ) ;
4570+ block . style . display = 'inline-block' ;
4571+ block . style . width = '1px' ;
4572+ block . style . height = '0px' ;
4573+ var container = document . createElement ( 'div' ) ;
4574+ container . appendChild ( text ) ;
4575+ container . appendChild ( block ) ;
4576+ container . style . height = '0px' ;
4577+ container . style . overflow = 'hidden' ;
4578+ document . body . appendChild ( container ) ;
4579+ block . style . verticalAlign = 'baseline' ;
4580+ var blockOffset = this . _calculateOffset ( block ) ;
4581+ var textOffset = this . _calculateOffset ( text ) ;
4582+ var ascent = blockOffset [ 1 ] - textOffset [ 1 ] ;
4583+ block . style . verticalAlign = 'bottom' ;
4584+ blockOffset = this . _calculateOffset ( block ) ;
4585+ textOffset = this . _calculateOffset ( text ) ;
4586+ var height = blockOffset [ 1 ] - textOffset [ 1 ] ;
4587+ var descent = height - ascent ;
4588+ document . body . removeChild ( container ) ;
4589+ this . _setProperty ( '_textAscent' , ascent ) ;
4590+ this . _setProperty ( '_textDescent' , descent ) ;
4591+ } ;
4592+ p5 . prototype . _calculateOffset = function ( object ) {
4593+ var currentLeft = 0 , currentTop = 0 ;
4594+ if ( object . offsetParent ) {
4595+ do {
4596+ currentLeft += object . offsetLeft ;
4597+ currentTop += object . offsetTop ;
4598+ } while ( object = object . offsetParent ) ;
4599+ } else {
4600+ currentLeft += object . offsetLeft ;
4601+ currentTop += object . offsetTop ;
4602+ }
4603+ return [
4604+ currentLeft ,
4605+ currentTop
4606+ ] ;
4607+ } ;
45514608 return p5 ;
45524609 } ( { } , core , constants ) ;
45534610var typographyloading_displaying = function ( require , core , canvas ) {
0 commit comments