2
0

add-fonts.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1">
  6. <title>Add Fonts :: jMonkeyEngine Docs</title>
  7. <link rel="canonical" href="https://wiki.jmonkeyengine.org/wiki-ui/add-fonts.html">
  8. <link rel="prev" href="stylesheets.html">
  9. <link rel="next" href="style-guide.html">
  10. <meta name="generator" content="Antora 3.0.1">
  11. <link rel="stylesheet" href="../_/css/site.css">
  12. <meta property="og:image" content="https://wiki.jmonkeyengine.org/_/img/iconx128.png">
  13. <meta property="og:description" content="Add Fonts">
  14. <meta property="og:title" content="jMonkeyEngine Docs">
  15. <link rel="stylesheet" href="../_/css/site-extra.css">
  16. <link rel="stylesheet" href="../_/css/vendor/docsearch.min.css">
  17. <!-- fetched from https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css -->
  18. <link rel="icon" href="../_/img/favicon.ico" type="image/x-icon">
  19. </head>
  20. <body class="article">
  21. <header class="header">
  22. <nav class="navbar">
  23. <div class="navbar-brand">
  24. <a class="navbar-item" href="https://wiki.jmonkeyengine.org">
  25. <img alt="" src="../_/img/jme-logo.png" height="32" type="image/x-icon">
  26. </a>
  27. <div class="navbar-item hide-for-print">
  28. <input id="search-input" type="text" placeholder="Search docs">
  29. </div>
  30. <button class="navbar-burger" data-target="topbar-nav">
  31. <span></span>
  32. <span></span>
  33. <span></span>
  34. </button>
  35. </div>
  36. <div id="topbar-nav" class="navbar-menu">
  37. <div class="navbar-end">
  38. <div class="navbar-item theme-switch-wrapper">
  39. <label class="theme-switch" for="checkbox">
  40. <input type="checkbox" id="checkbox" />
  41. <div class="slider round"></div>
  42. </label>
  43. </div>
  44. <a class="navbar-item" href="https://github.com/jmonkeyengine/wiki">Github</a>
  45. </div>
  46. </div>
  47. </nav>
  48. </header>
  49. <div class="body">
  50. <div class="nav-container" data-component="wiki-ui" data-version="master">
  51. <aside class="nav">
  52. <div class="panels">
  53. <div class="nav-panel-menu is-active" data-panel="menu">
  54. <nav class="nav-menu">
  55. <h3 class="title"><a href="index.html">Wiki UI</a></h3>
  56. <ul class="nav-list">
  57. <li class="nav-item" data-depth="0">
  58. <ul class="nav-list">
  59. <li class="nav-item" data-depth="1">
  60. <a class="nav-link" href="prerequisites.html">UI Development Prerequisites</a>
  61. </li>
  62. <li class="nav-item" data-depth="1">
  63. <a class="nav-link" href="set-up-project.html">Set up a UI Project</a>
  64. </li>
  65. <li class="nav-item" data-depth="1">
  66. <a class="nav-link" href="build-preview-ui.html">Build and Preview the UI</a>
  67. </li>
  68. <li class="nav-item" data-depth="1">
  69. <a class="nav-link" href="development-workflow.html">UI Development Workflow</a>
  70. </li>
  71. <li class="nav-item" data-depth="1">
  72. <a class="nav-link" href="templates.html">Work with the Handlebars Templates</a>
  73. </li>
  74. <li class="nav-item" data-depth="1">
  75. <button class="nav-item-toggle"></button>
  76. <a class="nav-link" href="stylesheets.html">Work with the CSS Stylesheets</a>
  77. <ul class="nav-list">
  78. <li class="nav-item is-current-page" data-depth="2">
  79. <a class="nav-link" href="add-fonts.html">Add Fonts</a>
  80. </li>
  81. </ul>
  82. </li>
  83. <li class="nav-item" data-depth="1">
  84. <button class="nav-item-toggle"></button>
  85. <a class="nav-link" href="style-guide.html">UI Element Styles</a>
  86. <ul class="nav-list">
  87. <li class="nav-item" data-depth="2">
  88. <a class="nav-link" href="inline-text-styles.html">Inline Text</a>
  89. </li>
  90. <li class="nav-item" data-depth="2">
  91. <a class="nav-link" href="admonition-styles.html">Admonitions</a>
  92. </li>
  93. <li class="nav-item" data-depth="2">
  94. <a class="nav-link" href="list-styles.html">Lists</a>
  95. </li>
  96. <li class="nav-item" data-depth="2">
  97. <a class="nav-link" href="sidebar-styles.html">Sidebars</a>
  98. </li>
  99. <li class="nav-item" data-depth="2">
  100. <a class="nav-link" href="ui-macro-styles.html">UI Macros</a>
  101. </li>
  102. </ul>
  103. </li>
  104. </ul>
  105. </li>
  106. </ul>
  107. </nav>
  108. </div>
  109. <div class="nav-panel-explore" data-panel="explore">
  110. <div class="context">
  111. <span class="title">Wiki UI</span>
  112. <span class="version">master</span>
  113. </div>
  114. <ul class="components">
  115. <li class="component">
  116. <span class="title">JME</span>
  117. <ul class="versions">
  118. <li class="version">
  119. <a href="../docs/3.8/documentation.html">3.8</a>
  120. </li>
  121. <li class="version">
  122. <a href="../docs/3.4/documentation.html">3.4</a>
  123. </li>
  124. <li class="version">
  125. <a href="../docs/3.3/documentation.html">3.3</a>
  126. </li>
  127. <li class="version">
  128. <a href="../docs/3.2/documentation.html">3.2</a>
  129. </li>
  130. </ul>
  131. </li>
  132. <li class="component">
  133. <span class="title">Wiki Contribution</span>
  134. <ul class="versions">
  135. <li class="version">
  136. <a href="../docs-wiki/3.8/wiki_contributor.html">3.8</a>
  137. </li>
  138. </ul>
  139. </li>
  140. <li class="component is-current">
  141. <span class="title">Wiki UI</span>
  142. <ul class="versions">
  143. <li class="version is-current">
  144. <a href="index.html">master</a>
  145. </li>
  146. </ul>
  147. </li>
  148. </ul>
  149. </div>
  150. </div>
  151. </aside>
  152. </div>
  153. <main class="article">
  154. <div class="toolbar" role="navigation">
  155. <button class="nav-toggle"></button>
  156. <nav class="breadcrumbs" aria-label="breadcrumbs">
  157. <ul>
  158. <li><a href="index.html">Wiki UI</a></li>
  159. <li><a href="stylesheets.html">Work with the CSS Stylesheets</a></li>
  160. <li><a href="add-fonts.html">Add Fonts</a></li>
  161. </ul>
  162. </nav>
  163. <div class="edit-this-page"><a href="https://github.com/jMonkeyEngine/wiki-ui/edit/master/docs/modules/ROOT/pages/add-fonts.adoc">Edit this Page</a></div>
  164. </div>
  165. <div class="content">
  166. <article class="doc">
  167. <h1 class="page">Add Fonts</h1>
  168. <div id="preamble">
  169. <div class="sectionbody">
  170. <div class="paragraph">
  171. <p>This page explains how to add new fonts to your UI.
  172. These instructions assume you&#8217;ve forked the default UI and are able to customize it.</p>
  173. </div>
  174. <div class="paragraph">
  175. <p>There are three steps involved:</p>
  176. </div>
  177. <div class="olist arabic">
  178. <ol class="arabic">
  179. <li>
  180. <p>Add the font to your UI project</p>
  181. </li>
  182. <li>
  183. <p>Add a font-face declaration to your stylesheet</p>
  184. </li>
  185. <li>
  186. <p>Use the new font in your stylesheet</p>
  187. </li>
  188. </ol>
  189. </div>
  190. <div class="paragraph">
  191. <p>How you reference the font file in the font-face declaration depends on how you decide to manage it.
  192. You can manage the font with npm or download it manually and add it directly to your UI project.
  193. The following sections describe each approach in turn.</p>
  194. </div>
  195. </div>
  196. </div>
  197. <div class="sect1">
  198. <h2 id="npm-managed"><a class="anchor" href="#npm-managed"></a>npm managed</h2>
  199. <div class="sectionbody">
  200. <div class="paragraph">
  201. <p>You can use npm (or Yarn) to manage the font.
  202. This approach saves you from having to store the font file directly in your UI project.
  203. Here are the steps involved.</p>
  204. </div>
  205. <div class="olist arabic">
  206. <ol class="arabic">
  207. <li>
  208. <p>Use npm (or Yarn) to install the font files from a package (e.g., <a href="https://www.npmjs.com/package/typeface-open-sans">typeface-open-sans</a>)</p>
  209. <div class="literalblock">
  210. <div class="content">
  211. <pre>$ npm install --save typeface-open-sans</pre>
  212. </div>
  213. </div>
  214. </li>
  215. <li>
  216. <p>In <em class="path">src/css</em>, add a corresponding CSS file (e.g., <em class="path">typeface-open-sans.css</em>)</p>
  217. </li>
  218. <li>
  219. <p>In that file, declare the font face:</p>
  220. <div class="listingblock">
  221. <div class="content">
  222. <pre class="highlightjs highlight"><code class="language-css hljs" data-lang="css">@font-face {
  223. font-family: "Open Sans";
  224. font-style: normal;
  225. font-weight: 400;
  226. src:
  227. local("Open Sans"),
  228. local("Open Sans-Regular"),
  229. url(~typeface-open-sans/files/open-sans-latin-400.woff) format("woff")
  230. }</code></pre>
  231. </div>
  232. </div>
  233. <div class="paragraph">
  234. <p>The Gulp build recognizes the <code>~</code> URL prefix and copies the font from the npm package to the build folder (and hence bundle).</p>
  235. </div>
  236. <div class="paragraph">
  237. <p>You must define one @font-face for each font weight and style combination (e.g., <code>font-weight: 500</code> + <code>font-style: italic</code>) from the font that you want to use in your stylesheet.</p>
  238. </div>
  239. </li>
  240. <li>
  241. <p>Import the typeface CSS file you just created into the main stylesheet, <em class="path">src/css/site.css</em> (adjacent to the other typeface imports):</p>
  242. <div class="listingblock">
  243. <div class="content">
  244. <pre class="highlightjs highlight"><code class="language-css hljs" data-lang="css">@import "typeface-open-sans.css";</code></pre>
  245. </div>
  246. </div>
  247. </li>
  248. <li>
  249. <p>Repeat the previous steps for each font style and weight you want to use from that package.</p>
  250. </li>
  251. <li>
  252. <p>Change the CSS to use your newly imported font:</p>
  253. <div class="listingblock">
  254. <div class="content">
  255. <pre class="highlightjs highlight"><code class="language-css hljs" data-lang="css">html {
  256. font-family: "Open Sans", sans;
  257. }</code></pre>
  258. </div>
  259. </div>
  260. <div class="admonitionblock tip">
  261. <table>
  262. <tr>
  263. <td class="icon">
  264. <i class="fa icon-tip" title="Tip"></i>
  265. </td>
  266. <td class="content">
  267. If you&#8217;re building on the default UI, you may instead want to define or update the font family using a variable defined in <em class="path">src/css/vars.css</em>.
  268. </td>
  269. </tr>
  270. </table>
  271. </div>
  272. </li>
  273. <li>
  274. <p>Test the new font by previewing your UI:</p>
  275. <div class="literalblock">
  276. <div class="content">
  277. <pre>$ gulp preview</pre>
  278. </div>
  279. </div>
  280. </li>
  281. </ol>
  282. </div>
  283. <div class="paragraph">
  284. <p>If you see the new font, you&#8217;ve now successfully added it to your UI.
  285. If you aren&#8217;t sure, look for the <a href="https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Edit_fonts">All fonts on page</a> section in your browser&#8217;s developer tools to see whether the font was loaded.</p>
  286. </div>
  287. </div>
  288. </div>
  289. <div class="sect1">
  290. <h2 id="manual"><a class="anchor" href="#manual"></a>Manual</h2>
  291. <div class="sectionbody">
  292. <div class="paragraph">
  293. <p>A simpler approach to adding fonts is to store them directly in your project.
  294. Here are the steps involved.</p>
  295. </div>
  296. <div class="olist arabic">
  297. <ol class="arabic">
  298. <li>
  299. <p>Download the font files and add them to the <em class="path">src/font</em> folder.
  300. Create this folder if it does not exist.</p>
  301. </li>
  302. <li>
  303. <p>In <em class="path">src/css</em>, add a corresponding CSS file (e.g., <em class="path">typeface-open-sans.css</em>)</p>
  304. </li>
  305. <li>
  306. <p>In that file, declare the font face:</p>
  307. <div class="listingblock">
  308. <div class="content">
  309. <pre class="highlightjs highlight"><code class="language-css hljs" data-lang="css">@font-face {
  310. font-family: "Open Sans";
  311. font-style: normal;
  312. font-weight: 400;
  313. src:
  314. local("Open Sans"),
  315. local("Open Sans-Regular"),
  316. url(../font/open-sans-latin-400.woff) format("woff")
  317. }</code></pre>
  318. </div>
  319. </div>
  320. <div class="paragraph">
  321. <p>Note that the path is a relative path starting from the <em class="path">src/css</em> folder to the <em class="path">src/font</em> folder.</p>
  322. </div>
  323. <div class="paragraph">
  324. <p>You must define one @font-face for each font weight and style combination (e.g., <code>font-weight: 500</code> + <code>font-style: italic</code>) from the font that you want to use in your stylesheet.</p>
  325. </div>
  326. </li>
  327. <li>
  328. <p>Import the typeface CSS file you just created into the main stylesheet, <em class="path">src/css/site.css</em> (adjacent to the other typeface imports):</p>
  329. <div class="listingblock">
  330. <div class="content">
  331. <pre class="highlightjs highlight"><code class="language-css hljs" data-lang="css">@import "typeface-open-sans.css";</code></pre>
  332. </div>
  333. </div>
  334. </li>
  335. <li>
  336. <p>Repeat the previous steps for each font style and weight you want to use.</p>
  337. </li>
  338. <li>
  339. <p>Change the CSS to use your newly imported font:</p>
  340. <div class="listingblock">
  341. <div class="content">
  342. <pre class="highlightjs highlight"><code class="language-css hljs" data-lang="css">html {
  343. font-family: "Open Sans", sans;
  344. }</code></pre>
  345. </div>
  346. </div>
  347. <div class="admonitionblock tip">
  348. <table>
  349. <tr>
  350. <td class="icon">
  351. <i class="fa icon-tip" title="Tip"></i>
  352. </td>
  353. <td class="content">
  354. If you&#8217;re building on the default UI, you may instead want to define or update the font family using a variable defined in <em class="path">src/css/vars.css</em>.
  355. </td>
  356. </tr>
  357. </table>
  358. </div>
  359. </li>
  360. <li>
  361. <p>Test the new font by previewing your UI:</p>
  362. <div class="literalblock">
  363. <div class="content">
  364. <pre>$ gulp preview</pre>
  365. </div>
  366. </div>
  367. </li>
  368. </ol>
  369. </div>
  370. <div class="paragraph">
  371. <p>If you see the new font, you&#8217;ve now successfully added it to your UI.
  372. If you aren&#8217;t sure, look for the <a href="https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Edit_fonts">All fonts on page</a> section in your browser&#8217;s developer tools to see whether the font was loaded.</p>
  373. </div>
  374. </div>
  375. </div>
  376. <nav class="pagination">
  377. <span class="prev"><a href="stylesheets.html">Work with the CSS Stylesheets</a></span>
  378. <span class="next"><a href="style-guide.html">UI Element Styles</a></span>
  379. </nav>
  380. </article>
  381. <aside class="toc sidebar" data-title="Contents" data-levels="2">
  382. <div class="toc-menu"></div>
  383. </aside>
  384. </div>
  385. </main>
  386. </div>
  387. <footer class="footer">
  388. <p>Copyright 2020 jMonkeyEngine Wiki Contributors. Licensed BSD-3.</p>
  389. </footer>
  390. <script src="../_/js/vendor/docsearch.min.js"></script>
  391. <!-- fetched from https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js -->
  392. <script>
  393. var search = docsearch({
  394. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  395. indexName: 'jmonkeyengine',
  396. inputSelector: '#search-input',
  397. autocompleteOptions: { hint: false, keyboardShortcuts: ['s'] },
  398. algoliaOptions: { hitsPerPage: 10 }
  399. }).autocomplete
  400. search.on('autocomplete:closed', function () { search.autocomplete.setVal() })
  401. function focusSearchInput () { document.querySelector('#search-input').focus() }
  402. if (document.querySelector('.home-link.is-current')) window.addEventListener('load', focusSearchInput)
  403. </script>
  404. <script src="../_/js/site.js"></script>
  405. <script async src="../_/js/vendor/highlight.js"></script>
  406. </body>
  407. </html>