Created
December 3, 2012 17:37
-
-
Save MacDada/4196618 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Mierzy wysokość tekstu na podstawie specyfikacji css: font. | |
* Przykład: MMG.getTextHeight("italic bold 13em Arial"); | |
* | |
* @param string font CSSowa specyfikacja czcionki | |
* @return integer Wysokość linii tekstu w pikselach | |
*/ | |
MMG.getTextHeight = function(font) { | |
var text = $('<span style="font: ' + font + '">Hg</span>'); | |
var block = $('<div style="display: inline-block; width: 1px; height: 0px;"></div>'); | |
var div = $('<div></div>'); | |
div.append(text, block); | |
var body = $('body'); | |
body.append(div); | |
try { | |
var result = {}; | |
block.css({ verticalAlign: 'baseline' }); | |
result.ascent = block.offset().top - text.offset().top; | |
block.css({ verticalAlign: 'bottom' }); | |
result.height = block.offset().top - text.offset().top; | |
result.descent = result.height - result.height; | |
} finally { | |
div.remove(); | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment