Sha256: 554093eb5e5b7421ef3a8d98823b9a3f118ac506efc7a29d3ceaa63063ceb292
Contents?: true
Size: 1.99 KB
Versions: 1
Compression:
Stored size: 1.99 KB
Contents
goog.provide('webfont.FontRuler'); goog.require('webfont.CssFontFamilyName'); goog.require('webfont.FontVariationDescription'); /** * An element that can be used to measure the metrics * of a given font and string. * @constructor * @param {webfont.DomHelper} domHelper * @param {string} fontTestString */ webfont.FontRuler = function(domHelper, fontTestString) { this.domHelper_ = domHelper; this.fontTestString_ = fontTestString; this.nameHelper_ = new webfont.CssFontFamilyName(); this.fvd_ = new webfont.FontVariationDescription(); this.el_ = this.domHelper_.createElement('span', {}, this.fontTestString_); }; goog.scope(function () { var FontRuler = webfont.FontRuler; /** * @param {string} fontFamily * @param {string=} opt_fontDescription */ FontRuler.prototype.setFont = function(fontFamily, opt_fontDescription) { var styleString = this.computeStyleString_(fontFamily, opt_fontDescription); this.domHelper_.setStyle(this.el_, styleString); }; /** * Inserts the ruler into the DOM. */ FontRuler.prototype.insert = function() { this.domHelper_.insertInto('body', this.el_); }; /** * @private * @param {string} fontFamily * @param {string=} opt_fontDescription * @return {string} */ FontRuler.prototype.computeStyleString_ = function(fontFamily, opt_fontDescription) { var variationCss = opt_fontDescription ? this.fvd_.expand(opt_fontDescription) : ''; var styleString = "position:absolute;top:-999px;left:-999px;" + "font-size:300px;width:auto;height:auto;line-height:normal;margin:0;" + "padding:0;font-variant:normal;white-space:nowrap;font-family:" + this.nameHelper_.quote(fontFamily) + ";" + variationCss; return styleString; }; /** * @return {number} */ FontRuler.prototype.getWidth = function() { return this.el_.offsetWidth; }; /** * Removes the ruler element from the DOM. */ FontRuler.prototype.remove = function() { this.domHelper_.removeElement(this.el_); }; });
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
webfontloader-1.4.0 | src/core/fontruler.js |