html-customization-plugin-webfont.dita 8.2 KB

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