font-measure
Advanced tools
+4
-2
@@ -19,3 +19,5 @@ 'use strict' | ||
| var fs = o.size || o.fontSize || o.em || 48 | ||
| var font = fs + 'px ' + family | ||
| var weight = o.weight || o.fontWeight || '' | ||
| var style = o.style || o.fontStyle || '' | ||
| var font = [style, weight, fs].join(' ') + 'px ' + family | ||
| var origin = o.origin || 'top' | ||
@@ -26,3 +28,3 @@ | ||
| if (fs <= measure.cache[family].em) { | ||
| return origin === 'top' ? measure.cache[family] : applyOrigin(measure.cache[family], origin) | ||
| return applyOrigin(measure.cache[family], origin) | ||
| } | ||
@@ -29,0 +31,0 @@ } |
+2
-2
| { | ||
| "name": "font-measure", | ||
| "version": "1.1.1", | ||
| "version": "1.2.0", | ||
| "description": "Calculate metrics of a font", | ||
@@ -38,4 +38,4 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "object-assign": "^4.1.1" | ||
| "css-font": "^1.2.0" | ||
| } | ||
| } |
+5
-3
@@ -38,5 +38,5 @@ # font-measure [](http://github.com/badges/stability-badges) | ||
| ### `let metrics = measure(font, options?)` | ||
| ### `let metrics = measure(family, options?)` | ||
| Get metrics data for a font, possibly with custom options. Font can be a string or an array with fonts. | ||
| Get metrics data for a font family or [CSS font string](), possibly with custom options. Font can be a string or an array with fonts. | ||
@@ -53,3 +53,5 @@ #### `metrics`: | ||
| `origin` | `top` | Origin for metrics. Can be changed to `baseline` or any other metric. | ||
| `size` | `64` | Font-size to use for calculations. Larger size gives higher precision with slower performance. | ||
| `fontSize` | `64` | Font-size to use for calculations. Larger size gives higher precision with slower performance. | ||
| `fontWeight` | `normal` | Font weight to use for calculations, eg. `bold`, `700` etc. | ||
| `fontStyle` | `normal` | Font style to use for calculations, eg. `italic`, `oblique`. | ||
| `canvas` | `measure.canvas` | Canvas to use for measurements. | ||
@@ -56,0 +58,0 @@ `tittle` | `i` | Character to detect tittle. `null` disables calculation. |
+2
-0
@@ -6,2 +6,3 @@ 'use strict' | ||
| let fix = { | ||
@@ -28,2 +29,3 @@ alphabetic: 1.03125, | ||
| a.deepEqual(m('Roboto', {fontSize: 64}), fix) | ||
| a.deepEqual(m('Roboto', {fontSize: 64, fontWeight: '700', fontStyle: 'italic'}), fix) | ||
| a.equal(m('Roboto', {fontSize: 64, origin: 'baseline'}).baseline, 0) |
10239
3.72%228
1.33%79
2.6%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed