html-customization-plugin-webfont.dita 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <task id="custom-html-plugin-webfont">
  5. <title>Embedding web fonts in HTML output</title>
  6. <titlealts>
  7. <navtitle>Embedding web fonts</navtitle>
  8. </titlealts>
  9. <shortdesc>A custom plug-in can be created to generate HTML output that uses custom fonts for enhanced typographic
  10. features, extended character sets or a unique corporate identity.</shortdesc>
  11. <prolog>
  12. <metadata>
  13. <keywords>
  14. <indexterm><xmlelement>require</xmlelement></indexterm>
  15. <indexterm><xmlelement>link</xmlelement></indexterm>
  16. <indexterm><xmlelement>head</xmlelement></indexterm>
  17. <indexterm>HTML<indexterm>custom plug-in</indexterm></indexterm>
  18. <indexterm>HTML<indexterm>fonts</indexterm></indexterm>
  19. <indexterm>CSS<indexterm>web fonts</indexterm></indexterm>
  20. <indexterm>fonts<indexterm>HTML</indexterm></indexterm>
  21. <indexterm>web fonts<index-see>fonts</index-see></indexterm>
  22. <indexterm>custom.css</indexterm>
  23. <indexterm>build_html5-webfont.xml</indexterm>
  24. <indexterm>plugin.xml</indexterm>
  25. <indexterm>org.dita.html5</indexterm>
  26. </keywords>
  27. </metadata>
  28. </prolog>
  29. <taskbody>
  30. <context>
  31. <p>This scenario walks through the process of creating a very simple plug-in
  32. (<codeph>com.example.html5-webfont</codeph>) that creates a new transformation type:
  33. <option>html5-webfont</option>. </p>
  34. <p>The <option>html5-webfont</option> transformation includes a custom CSS file and sets five parameters to
  35. integrate font links and a custom stylesheet in the generated HTML5 output. These parameter settings make the
  36. following changes:</p>
  37. <ul>
  38. <li>
  39. <p>Specify a file that links to the font from the document head with <parmname>args.hdf</parmname>.</p></li>
  40. <li>
  41. <p>Specify the <filepath>css</filepath> subfolder of the plug-in as the source directory for custom CSS with
  42. <parmname>args.cssroot</parmname>.</p></li>
  43. <li>
  44. <p>Specify the name of the custom CSS file with <parmname>args.css</parmname>.</p>
  45. <p>The value of this parameter tells DITA-OT to use the <filepath>custom.css</filepath> file provided by the
  46. plug-in.</p></li>
  47. <li>
  48. <p>Ensure that the CSS file is copied to the output directory by setting <parmname>args.copycss</parmname> to
  49. <option>yes</option>.</p></li>
  50. <li>
  51. <p>Set the destination path for CSS files in the output folder with <parmname>args.csspath</parmname>.</p>
  52. <p>CSS files are copied to the root level of the output folder by default. Setting this parameter places CSS
  53. files in a dedicated <filepath>css</filepath> subfolder.</p></li>
  54. </ul>
  55. <p>All five parameters are set in the Ant script (<filepath>build_html5-webfont.xml</filepath>).</p>
  56. </context>
  57. <steps>
  58. <step>
  59. <cmd>In the <filepath>plugins</filepath> directory, create a directory named
  60. <filepath>com.example.html5-webfont</filepath>.</cmd>
  61. </step>
  62. <step>
  63. <cmd>In the new <filepath>com.example.html5-webfont</filepath> directory, create a plug-in configuration file
  64. (<filepath>plugin.xml</filepath>) that declares the new <option>html5-webfont</option> transformation and
  65. its dependencies.</cmd>
  66. <stepxmp>
  67. <fig>
  68. <title>Sample <filepath>plugin.xml</filepath> file</title>
  69. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.html5-webfont/plugin.xml"/></codeblock>
  70. </fig>
  71. <note>This plug-in will extend the default HTML5 transformation, so the <xmlelement>require</xmlelement>
  72. element explicitly defines <filepath>org.dita.html5</filepath> as a dependency.</note>
  73. </stepxmp>
  74. </step>
  75. <step>
  76. <cmd>In the <filepath>com.example.html5-webfont</filepath> directory, create a subdirectory named
  77. <filepath>include</filepath>.</cmd>
  78. </step>
  79. <step>
  80. <cmd>In the new <filepath>include</filepath> subdirectory, create a file named
  81. <filepath>webfont.hdf.xml</filepath> with your custom font links.</cmd>
  82. <stepxmp>
  83. <fig>
  84. <title>Sample <filepath>webfont.hdf.xml</filepath> file</title>
  85. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.html5-webfont/include/webfont.hdf.xml"/></codeblock>
  86. </fig>
  87. <p>This example uses the <xref keyref="noto-sans-font"/> font. You can use multiple fonts by creating
  88. additional <xmlelement>link</xmlelement> references in this file. The division wrapper will be discarded
  89. when generating HTML files, and the contents will be inserted into the <xmlelement>head</xmlelement> element
  90. of each page.</p>
  91. </stepxmp>
  92. </step>
  93. <step>
  94. <cmd>In the <filepath>com.example.html5-webfont</filepath> directory, create a subdirectory named
  95. <filepath>css</filepath>.</cmd>
  96. </step>
  97. <step>
  98. <cmd>In the new <filepath>css</filepath> subdirectory, create a file named <filepath>custom.css</filepath> with
  99. the stylesheet rules that apply the custom <codeph>font-family</codeph> to the desired elements.</cmd>
  100. <stepxmp>
  101. <fig>
  102. <title>Sample <filepath>custom.css</filepath> file</title>
  103. <codeblock outputclass="language-css normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.html5-webfont/css/custom.css"/></codeblock>
  104. </fig>
  105. <p>This example uses <xref keyref="noto-sans-font"/> for all body content. In practice, you would normally use
  106. different fonts for headings, body content, tables, etc. by creating additional rules in your CSS file.</p>
  107. </stepxmp>
  108. </step>
  109. <step>
  110. <cmd>In the <filepath>com.example.html5-webfont</filepath> root directory, add an Ant script
  111. (<filepath>build_html5-webfont.xml</filepath>) to define the transformation type.</cmd>
  112. <stepxmp>
  113. <fig>
  114. <title>Sample build file: <filepath>build_html5-webfont.xml</filepath></title>
  115. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.html5-webfont/build_html5-webfont.xml"/></codeblock>
  116. </fig>
  117. </stepxmp>
  118. </step>
  119. </steps>
  120. <result>
  121. <note type="tip">The files for this sample plug-in are included in the DITA-OT installation directory under
  122. <filepath>docsrc/samples/plugins/com.example.html5-webfont/</filepath> and on <xref
  123. href="https://github.com/dita-ot/docs/tree/develop/samples/plugins/com.example.html5-webfont" format="html"
  124. scope="external">GitHub</xref>.</note>
  125. <p>The plug-in directory has the following layout and files:</p>
  126. <codeblock>com.example.html5-webfont
  127. ├── build_html5-webfont.xml
  128. ├── css
  129. │   └── custom.css
  130. ├── include
  131. │   └── webfont.hdf.xml
  132. └── plugin.xml</codeblock>
  133. </result>
  134. <postreq>
  135. <ol>
  136. <li>Run <filepath conref="../resources/conref-task.dita#ID/dita-cmd"/>
  137. <parmname>--install</parmname> to install the plug-in and make the <option>html5-webfont</option>
  138. transformation available.</li>
  139. <li>Build output with the new transformation type to verify that the plug-in works as intended.
  140. <codeblock><filepath conref="../resources/conref-task.dita#ID/dita-cmd"/> <parmname>--input</parmname>=<varname>my.ditamap</varname> <parmname>--format</parmname>=<option>html5-webfont</option></codeblock>
  141. </li>
  142. <li>Refine the styles in your <filepath>custom.css</filepath> file to adjust the font usage as necessary.</li>
  143. </ol>
  144. </postreq>
  145. </taskbody>
  146. </task>