scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
1,103 lines (723 loc) • 79.5 kB
HTML
<!DOCTYPE html>
<html>
<head>
<title>FontAttributes factory</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="../../docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="../core/animationloop.html">
./source/core/animationloop.js
</a>
<a class="source" href="../core/document.html">
./source/core/document.js
</a>
<a class="source" href="../core/events.html">
./source/core/events.js
</a>
<a class="source" href="../core/init.html">
./source/core/init.js
</a>
<a class="source" href="../core/library.html">
./source/core/library.js
</a>
<a class="source" href="../core/random-seed.html">
./source/core/random-seed.js
</a>
<a class="source" href="../core/snippets.html">
./source/core/snippets.js
</a>
<a class="source" href="../core/userInteraction.html">
./source/core/userInteraction.js
</a>
<a class="source" href="../core/utilities.html">
./source/core/utilities.js
</a>
<a class="source" href="action.html">
./source/factory/action.js
</a>
<a class="source" href="anchor.html">
./source/factory/anchor.js
</a>
<a class="source" href="animation.html">
./source/factory/animation.js
</a>
<a class="source" href="bezier.html">
./source/factory/bezier.js
</a>
<a class="source" href="block.html">
./source/factory/block.js
</a>
<a class="source" href="canvas.html">
./source/factory/canvas.js
</a>
<a class="source" href="cell.html">
./source/factory/cell.js
</a>
<a class="source" href="cog.html">
./source/factory/cog.js
</a>
<a class="source" href="color.html">
./source/factory/color.js
</a>
<a class="source" href="conicGradient.html">
./source/factory/conicGradient.js
</a>
<a class="source" href="coordinate.html">
./source/factory/coordinate.js
</a>
<a class="source" href="crescent.html">
./source/factory/crescent.js
</a>
<a class="source" href="element.html">
./source/factory/element.js
</a>
<a class="source" href="emitter.html">
./source/factory/emitter.js
</a>
<a class="source" href="filter.html">
./source/factory/filter.js
</a>
<a class="source" href="filterEngine-bluenoiseData.html">
./source/factory/filterEngine-bluenoiseData.js
</a>
<a class="source" href="filterEngine.html">
./source/factory/filterEngine.js
</a>
<a class="source" href="fontAttributes.html">
./source/factory/fontAttributes.js
</a>
<a class="source" href="gradient.html">
./source/factory/gradient.js
</a>
<a class="source" href="grid.html">
./source/factory/grid.js
</a>
<a class="source" href="group.html">
./source/factory/group.js
</a>
<a class="source" href="imageAsset.html">
./source/factory/imageAsset.js
</a>
<a class="source" href="line.html">
./source/factory/line.js
</a>
<a class="source" href="lineSpiral.html">
./source/factory/lineSpiral.js
</a>
<a class="source" href="loom.html">
./source/factory/loom.js
</a>
<a class="source" href="mesh.html">
./source/factory/mesh.js
</a>
<a class="source" href="net.html">
./source/factory/net.js
</a>
<a class="source" href="noiseAsset.html">
./source/factory/noiseAsset.js
</a>
<a class="source" href="oval.html">
./source/factory/oval.js
</a>
<a class="source" href="palette.html">
./source/factory/palette.js
</a>
<a class="source" href="particle.html">
./source/factory/particle.js
</a>
<a class="source" href="particleForce.html">
./source/factory/particleForce.js
</a>
<a class="source" href="particleHistory.html">
./source/factory/particleHistory.js
</a>
<a class="source" href="particleSpring.html">
./source/factory/particleSpring.js
</a>
<a class="source" href="particleWorld.html">
./source/factory/particleWorld.js
</a>
<a class="source" href="pattern.html">
./source/factory/pattern.js
</a>
<a class="source" href="phrase.html">
./source/factory/phrase.js
</a>
<a class="source" href="picture.html">
./source/factory/picture.js
</a>
<a class="source" href="polygon.html">
./source/factory/polygon.js
</a>
<a class="source" href="polyline.html">
./source/factory/polyline.js
</a>
<a class="source" href="quadratic.html">
./source/factory/quadratic.js
</a>
<a class="source" href="quaternion.html">
./source/factory/quaternion.js
</a>
<a class="source" href="radialGradient.html">
./source/factory/radialGradient.js
</a>
<a class="source" href="rawAsset.html">
./source/factory/rawAsset.js
</a>
<a class="source" href="rdAsset.html">
./source/factory/rdAsset.js
</a>
<a class="source" href="rectangle.html">
./source/factory/rectangle.js
</a>
<a class="source" href="renderAnimation.html">
./source/factory/renderAnimation.js
</a>
<a class="source" href="shape.html">
./source/factory/shape.js
</a>
<a class="source" href="spiral.html">
./source/factory/spiral.js
</a>
<a class="source" href="spriteAsset.html">
./source/factory/spriteAsset.js
</a>
<a class="source" href="stack.html">
./source/factory/stack.js
</a>
<a class="source" href="star.html">
./source/factory/star.js
</a>
<a class="source" href="state.html">
./source/factory/state.js
</a>
<a class="source" href="tetragon.html">
./source/factory/tetragon.js
</a>
<a class="source" href="ticker.html">
./source/factory/ticker.js
</a>
<a class="source" href="tracer.html">
./source/factory/tracer.js
</a>
<a class="source" href="tween.html">
./source/factory/tween.js
</a>
<a class="source" href="unstackedElement.html">
./source/factory/unstackedElement.js
</a>
<a class="source" href="vector.html">
./source/factory/vector.js
</a>
<a class="source" href="videoAsset.html">
./source/factory/videoAsset.js
</a>
<a class="source" href="wheel.html">
./source/factory/wheel.js
</a>
<a class="source" href="../mixin/anchor.html">
./source/mixin/anchor.js
</a>
<a class="source" href="../mixin/asset.html">
./source/mixin/asset.js
</a>
<a class="source" href="../mixin/assetAdvancedFunctionality.html">
./source/mixin/assetAdvancedFunctionality.js
</a>
<a class="source" href="../mixin/assetConsumer.html">
./source/mixin/assetConsumer.js
</a>
<a class="source" href="../mixin/base.html">
./source/mixin/base.js
</a>
<a class="source" href="../mixin/cascade.html">
./source/mixin/cascade.js
</a>
<a class="source" href="../mixin/delta.html">
./source/mixin/delta.js
</a>
<a class="source" href="../mixin/displayShape.html">
./source/mixin/displayShape.js
</a>
<a class="source" href="../mixin/dom.html">
./source/mixin/dom.js
</a>
<a class="source" href="../mixin/entity.html">
./source/mixin/entity.js
</a>
<a class="source" href="../mixin/filter.html">
./source/mixin/filter.js
</a>
<a class="source" href="../mixin/mimic.html">
./source/mixin/mimic.js
</a>
<a class="source" href="../mixin/path.html">
./source/mixin/path.js
</a>
<a class="source" href="../mixin/pattern.html">
./source/mixin/pattern.js
</a>
<a class="source" href="../mixin/pivot.html">
./source/mixin/pivot.js
</a>
<a class="source" href="../mixin/position.html">
./source/mixin/position.js
</a>
<a class="source" href="../mixin/shapeBasic.html">
./source/mixin/shapeBasic.js
</a>
<a class="source" href="../mixin/shapeCurve.html">
./source/mixin/shapeCurve.js
</a>
<a class="source" href="../mixin/shapePathCalculation.html">
./source/mixin/shapePathCalculation.js
</a>
<a class="source" href="../mixin/styles.html">
./source/mixin/styles.js
</a>
<a class="source" href="../mixin/tween.html">
./source/mixin/tween.js
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="section-1">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-1">§</a>
</div>
<h1 id="fontattributes-factory">FontAttributes factory</h1>
<p>FontAttribute objects are used exclusively by <a href="./phrase.html">Phrase</a> entitys. They hold data about the Phrase entity’s current font</p>
<ul>
<li>The constructor uses naming functionality (from the <a href="../mixin/base.html">base</a> mixin), but doesn’t actually store FontAttribute instances in the <a href="../core/library.html">library</a></li>
<li>Instead they are referenced directly from each Phrase instance.</li>
<li>FontAttribute instances get cloned as part of the Phrase stamp functionality (because of subsequent ‘update’ invocations on them). </li>
<li>If we stored FA instances in the library we’d risk running out of memory, or slowing up code speed, as the cloned instances are pretty temporary and get thrown away whenever a new Phrase.set invocation (involving font attributes) happens.</li>
</ul>
<p>The Phrase entity includes functionality to allow the getting and setting of FontAttribute attributes directly on the entity instance.</p>
<p>Note that <canvas> context engines will attempt to display <a href="https://web.dev/variable-fonts/">variable fonts</a>, but the added functionality of those fonts is, for the most part, ignored. Scrawl-canvas makes no overt attempts to overcome this limitation.</p>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-2">§</a>
</div>
<h4 id="demos">Demos:</h4>
<ul>
<li>All Phrase-related demos use FontAttribute objects in the background. Developers should never need to deal with them directly</li>
</ul>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-3">§</a>
</div>
<h4 id="imports">Imports</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { constructors } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/library.js'</span>;
<span class="hljs-keyword">import</span> { mergeOver, pushUnique, xt, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/utilities.js'</span>;
<span class="hljs-keyword">import</span> { requestCell, releaseCell } <span class="hljs-keyword">from</span> <span class="hljs-string">'./cell.js'</span>;
<span class="hljs-keyword">import</span> baseMix <span class="hljs-keyword">from</span> <span class="hljs-string">'../mixin/base.js'</span>;</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-4">§</a>
</div>
<h4 id="fontattributes-constructor">FontAttributes constructor</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">FontAttributes</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items = Ωempty</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">makeName</span>(items.<span class="hljs-property">name</span>);
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>);
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(items);
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-5">§</a>
</div>
<h4 id="fontattributes-prototype">FontAttributes prototype</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> P = <span class="hljs-title class_">FontAttributes</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span> = <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">create</span>(<span class="hljs-title class_">Object</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>);
P.<span class="hljs-property">type</span> = <span class="hljs-string">'FontAttributes'</span>;
P.<span class="hljs-property">lib</span> = <span class="hljs-string">'fontattribute'</span>;</pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-6">§</a>
</div>
<h4 id="mixins">Mixins</h4>
</div>
<div class="content"><div class='highlight'><pre>P = <span class="hljs-title function_">baseMix</span>(P);</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-7">§</a>
</div>
<h4 id="fontattributes-attributes">FontAttributes attributes</h4>
<ul>
<li>Attributes defined in the <a href="../mixin/base.html">base mixin</a>: <strong>name</strong>.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> defaultAttributes = {</pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-8">§</a>
</div>
<p><strong>font</strong> - pseudo-attribute String which gets broken down into its component parts.</p>
<ul>
<li>Once the breakdown completes the font string gets reassembled and then passed through a <canvas> element’s context engine to determine the actual font String that will be used by the engine. This value gets stored in the <strong>temperedFontString</strong> attribute.</li>
</ul>
</div>
</li>
<li id="section-9">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-9">§</a>
</div>
<p><em>font-style</em> - saved in the <strong>style</strong> String attribute - acceptable values are: <code>normal</code>, <code>italic</code> and <code>oblique</code>. Note that browser handling of oblique (sloped rather than explicitly italic) fonts by their respective canvas context engines is, at best, idiosyncratic.</p>
<ul>
<li>To explicitly use an oblique font design (often called ‘slanted’ or ‘sloped’), reference the font face directly in the <code>family</code> or font strings.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">style</span>: <span class="hljs-string">'normal'</span>,</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-10">§</a>
</div>
<p><em>font-variant</em> - saved in the <strong>variant</strong> String attribute - the standard indicates that canvas context engine should only recognise <code>normal</code> and <code>small-caps</code> values. Do not use other possibilities (<em>font-variant-caps, font-variant-numeric, font-variant-ligatures, font-variant-east-asian, font-variant-alternates</em>) in font strings; scrawl-canvas will remove and/or ignore them when it parses the font string.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">variant</span>: <span class="hljs-string">'normal'</span>,</pre></div></div>
</li>
<li id="section-11">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-11">§</a>
</div>
<p><em>font-weight</em> - saved in the <strong>weight</strong> String attribute - acceptable values are: <code>normal</code>, <code>bold</code>, <code>lighter</code>, <code>bolder</code>; or a number (100. 200, 300, … 900). Bold is generally the equivalent of 700, and normal is 400; lighter/bolder are values relative to the <canvas> element’s computed font weight. Note that browser handling of font weight requirements by their respective canvas context engines is not entirely standards compliant - for instance Safari browsers will generally ignore weight assertions in font strings.</p>
<ul>
<li>To explicitly use a light, bold or heavy font design, reference the font face directly in the <code>family</code> or font strings.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">weight</span>: <span class="hljs-string">'normal'</span>,</pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-12">§</a>
</div>
<p><strong>font-stretch</strong> - saved in the <strong>stretch</strong> String attribute acceptable values are: <code>normal</code>, <code>semi-condensed</code>, <code>condensed</code>, <code>extra-condensed</code>, <code>ultra-condensed</code>, <code>semi-expanded</code>, <code>expanded</code>, <code>extra-expanded</code>, <code>ultra-expanded</code>. Browser support for these values by the <canvas> element’s context engine is, for the most part, non-existant.</p>
<ul>
<li>To explicitly use a condensed or stretched font design, reference the font face directly in the <code>family</code> or font strings.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">stretch</span>: <span class="hljs-string">'normal'</span>,</pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-13">§</a>
</div>
<p><em>font-size</em> - broken into two parts and saved in the <strong>sizeValue</strong> Number and <strong>sizeMetric</strong> String, each of which can be set separately. The W3C HTML Canvas 2D Context Recommendation states: <em>“with the ‘font-size’ component converted to CSS pixels”</em>. However, Scrawl-canvas makes every effort to respect and interpret non-px-based font-size requests.</p>
<ul>
<li>Note that these pixel values are representative of the <canvas> element’s intrinsic drawing area dimensions, not of any such measure modified by CSS dimension rules (width, height, scale, skew, etc) applied to the canvas.</li>
</ul>
<p>Length values relative to some intrinsic propertly of the font - Scrawl-canvas will not attempt to interpret the following, instead treating them as some fixed proportion of the <canvas> element’s computed font size:</p>
<ul>
<li><code>1em</code> is the <canvas> element’s computed font size</li>
<li><code>1rem</code> is the document root (<html>) element’s computed font size</li>
<li><code>1lh</code> is the <canvas> element’s computed font size multiplied by the entity’s line height value</li>
<li><code>1rlh</code> is the document root (<html>) element’s computed font size multiplied by the entity’s line height value</li>
<li><code>1ex</code> is ≈ ‘0.5em’</li>
<li><code>1cap</code>, <code>1ch</code>, <code>1ic</code> are all ≈ ‘1em’</li>
</ul>
<p>Length percentage values, with calculation based on the <canvas> element’s computed font size: </p>
<ul>
<li><code>120%</code> = ‘1.2em’</li>
</ul>
<p>Non-numerical values (in the Fonts standards, ‘absolute-size’ and ‘relative-size’ keywords) will calculate a size based on the <canvas> element’s computed font size: </p>
<ul>
<li><code>xx-small</code> = 60% of the computed font size</li>
<li><code>x-small</code> = 75% of the computed font size</li>
<li><code>small</code> = 89% of the computed font size</li>
<li><code>medium</code> = 100% of the computed font size</li>
<li><code>large</code> = 120% of the computed font size</li>
<li><code>x-large</code> = 150% of the computed font size</li>
<li><code>xx-large</code> = 200% of the computed font size</li>
<li><code>xxx-large</code> = 300% of the computed font size</li>
<li><code>smaller</code> = 80% of the computed font size</li>
<li><code>larger</code> = 130% of the computed font size</li>
</ul>
<p>Length values relative to the browser’s viewport (window) dimensions:</p>
<ul>
<li><code>1vw</code> and <code>1vh</code> represent 1% of the viewport’s width and height, respectively</li>
<li><code>1vmax</code> - is 1% of the larger viewport dimension</li>
<li><code>1vmin</code> - is 1% of the smaller viewport dimension</li>
<li>Scrawl-canvas treats <code>1vi</code> as ≈ 1vw, and <code>1vb</code> as ≈ 1vh</li>
</ul>
<p>Absolute length values convert as follow:</p>
<ul>
<li><code>1in</code> (inch) = 96px</li>
<li><code>1cm</code> (centimeter) = 37.80px</li>
<li><code>1mm</code> (millimeter) = 3.78px</li>
<li><code>1Q</code> (quarter mm) = 0.95px </li>
<li><code>1pc</code> (pica) = 16px</li>
<li><code>1pt</code> (point) = 1.33px</li>
<li><code>1px</code> (pixel) = 1px</li>
</ul>
<p>Note: we break down the <code>size</code> attribute into two components: <strong>sizeValue</strong> and <strong>sizeMetric</strong>. Line height values are ignored and, when present in a font string, may break the code!</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">sizeValue</span>: <span class="hljs-number">12</span>,
<span class="hljs-attr">sizeMetric</span>: <span class="hljs-string">'px'</span>,</pre></div></div>
</li>
<li id="section-14">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-14">§</a>
</div>
<p><strong>font-family</strong> - any part of the font string that comes after the above declarations.</p>
<ul>
<li>It is generally a good idea to include one of the preset defaults - <code>serif</code>, <code>sans-serif</code>, <code>monospace</code>, <code>cursive</code>, <code>fantasy</code>, <code>system-ui</code>, <code>math</code>, <code>emoji</code>, <code>fangsong</code> - at the end of the font or family string, to act as a fallback default as other fonts load.</li>
<li>Scrawl-canvas will attempt to redraw the display when fonts complete their (asynchronous) upload, but this may fail and need to be triggered manually.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">family</span>: <span class="hljs-string">'sans-serif'</span>,
};
P.<span class="hljs-property">defs</span> = <span class="hljs-title function_">mergeOver</span>(P.<span class="hljs-property">defs</span>, defaultAttributes);</pre></div></div>
</li>
<li id="section-15">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-15">§</a>
</div>
<h4 id="packet-management">Packet management</h4>
<p>No additional clone functionality required
P.packetExclusions = pushUnique(P.packetExclusions, [‘font’]);</p>
</div>
</li>
<li id="section-16">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-16">§</a>
</div>
<h4 id="clone-management">Clone management</h4>
<p>No additional clone functionality required</p>
</div>
</li>
<li id="section-17">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-17">§</a>
</div>
<h4 id="kill-management">Kill management</h4>
<p>No additional kill functionality required</p>
</div>
</li>
<li id="section-18">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-18">§</a>
</div>
<h4 id="get-set-deltaset">Get, Set, deltaSet</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">let</span> G = P.<span class="hljs-property">getters</span>,
S = P.<span class="hljs-property">setters</span>,
D = P.<span class="hljs-property">deltaSetters</span>;</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-19">§</a>
</div>
<p><strong>size</strong> - pseudo-attribute </p>
<ul>
<li>getter returns a CSS fontSize String</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>G.<span class="hljs-property">size</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">return</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeValue</span>) ? <span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-variable language_">this</span>.sizeValue}</span><span class="hljs-subst">${<span class="hljs-variable language_">this</span>.sizeMetric}</span>`</span> : <span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeMetric</span>;
};</pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-20">§</a>
</div>
<ul>
<li>setter breaks the fontSize String into <strong>sizeValue</strong> and <strong>sizeMetric</strong> values</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">size</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item)) {
<span class="hljs-keyword">let</span> res,
size = <span class="hljs-number">0</span>,
metric = <span class="hljs-string">'medium'</span>;
<span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'xx-small'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'xx-small'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'x-small'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'x-small'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'smaller'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'smaller'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'small'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'small'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'medium'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'medium'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'xxx-large'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'xxx-large'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'xx-large'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'xx-large'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'x-large'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'x-large'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'larger'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'larger'</span>;
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'large'</span>) >= <span class="hljs-number">0</span>) metric = <span class="hljs-string">'large'</span>;
<span class="hljs-keyword">else</span> {
size = <span class="hljs-number">12</span>;
metric = <span class="hljs-string">'px'</span>
}
<span class="hljs-keyword">let</span> full, val, suffix;
<span class="hljs-keyword">let</span> r = item.<span class="hljs-title function_">match</span>(<span class="hljs-regexp">/(\d+\.\d+|\d+|\.\d+)(rem|em|rlh|lh|ex|cap|ch|ic|%|vw|vh|vmax|vmin|vi|vb|in|cm|mm|Q|pc|pt|px)?/i</span>);
<span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(r)) {
[full, val, suffix] = r;
<span class="hljs-keyword">if</span> (val && suffix && val != <span class="hljs-string">'.'</span>) {
size = val;
metric = suffix;
}
}
<span class="hljs-keyword">else</span> {
r = item.<span class="hljs-title function_">match</span>(<span class="hljs-regexp">/\/(\d+\.\d+|\d+|\.\d+)(rem|em|rlh|lh|ex|cap|ch|ic|%|vw|vh|vmax|vmin|vi|vb|in|cm|mm|Q|pc|pt|px)?/i</span>);
<span class="hljs-keyword">if</span> (<span class="hljs-title class_">Array</span>.<span class="hljs-title function_">isArray</span>(r)) {
[full, val, suffix] = r;
<span class="hljs-keyword">if</span> (val && suffix && val != <span class="hljs-string">'.'</span>) {
size = val;
metric = suffix;
}
}
}
<span class="hljs-keyword">if</span> (size !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeValue</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeValue</span> = size;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFont</span> = <span class="hljs-literal">true</span>;
}
<span class="hljs-keyword">if</span> (metric !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeMetric</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeMetric</span> = metric;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFont</span> = <span class="hljs-literal">true</span>;
}
}
};
S.<span class="hljs-property">sizeValue</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item) && item !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeValue</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeValue</span> = item;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFont</span> = <span class="hljs-literal">true</span>;
}
}
S.<span class="hljs-property">sizeMetric</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item) && item !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeMetric</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">sizeMetric</span> = item;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFont</span> = <span class="hljs-literal">true</span>;
}
}</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-21">§</a>
</div>
<p><strong>font</strong> - pseudo-attribute which calls various functions to break down the font String into its constituent parts</p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">font</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item)) {
S.<span class="hljs-property">style</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, item);
S.<span class="hljs-property">variant</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, item);
S.<span class="hljs-property">weight</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, item);
S.<span class="hljs-property">stretch</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, item);
S.<span class="hljs-property">size</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, item);
S.<span class="hljs-property">family</span>.<span class="hljs-title function_">call</span>(<span class="hljs-variable language_">this</span>, item);
}
};</pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-22">§</a>
</div>
<p><strong>style</strong></p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">style</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item)) {
<span class="hljs-keyword">let</span> v = <span class="hljs-string">'normal'</span>;
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'italic'</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'italic'</span> : v;
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'oblique'</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'oblique'</span> : v;
<span class="hljs-keyword">if</span> (v !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">style</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">style</span> = v;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFont</span> = <span class="hljs-literal">true</span>;
}
}
};</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-23">§</a>
</div>
<p><strong>variant</strong></p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">variant</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item)) {
<span class="hljs-keyword">let</span> v = <span class="hljs-string">'normal'</span>;
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'small-caps'</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'small-caps'</span> : v;
<span class="hljs-keyword">if</span> (v !== <span class="hljs-variable language_">this</span>.<span class="hljs-property">variant</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">variant</span> = v;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">dirtyFont</span> = <span class="hljs-literal">true</span>;
}
}
};</pre></div></div>
</li>
<li id="section-24">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-24">§</a>
</div>
<p><strong>weight</strong></p>
</div>
<div class="content"><div class='highlight'><pre>S.<span class="hljs-property">weight</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-title function_">xt</span>(item)) {
<span class="hljs-keyword">let</span> v = <span class="hljs-string">'normal'</span>;</pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-25">§</a>
</div>
<p>Handling direct entry of numbers</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (item.<span class="hljs-property">toFixed</span>) v = item;
<span class="hljs-keyword">else</span> {
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'bold'</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'bold'</span> : v;
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'lighter'</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'lighter'</span> : v;
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">'bolder'</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'bolder'</span> : v;</pre></div></div>
</li>
<li id="section-26">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-26">§</a>
</div>
<p>Putting spaces around the number should help identify it as a Weight value within the font string the string</p>
</div>
<div class="content"><div class='highlight'><pre> v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">' 100 '</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'100'</span> : v;
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">' 200 '</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'200'</span> : v;
v = (item.<span class="hljs-title function_">indexOf</span>(<span class="hljs-string">' 300 '</span>) >= <span class="hljs-number">0</span>) ? <span class="hljs-string">'300'</span> : v;
v = (ite