usermanual-utilities.xml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?xml version="1.0"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
  4. <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
  5. <!ENTITY version SYSTEM "version.xml">
  6. ]>
  7. <chapter id="utilities">
  8. <title>Utilities</title>
  9. <para>
  10. HarfBuzz includes several auxiliary components in addition to the
  11. main APIs. These include a set of command-line tools, a set of
  12. lower-level APIs for common data types that may be of interest to
  13. client programs.
  14. </para>
  15. <section id="utilities-command-line-tools">
  16. <title>Command-line tools</title>
  17. <para>
  18. HarfBuzz include three command-line tools:
  19. <command>hb-shape</command>, <command>hb-view</command>, and
  20. <command>hb-subset</command>. They can be used to examine
  21. HarfBuzz's functionality, debug font binaries, or explore the
  22. various shaping models and features from a terminal.
  23. </para>
  24. <section id="utilities-command-line-hbshape">
  25. <title>hb-shape</title>
  26. <para>
  27. <emphasis><command>hb-shape</command></emphasis> allows you to run HarfBuzz's
  28. <function>hb_shape()</function> function on an input string and
  29. to examine the outcome, in human-readable form, as terminal
  30. output. <command>hb-shape</command> does
  31. <emphasis>not</emphasis> render the results of the shaping call
  32. into rendered text (you can use <command>hb-view</command>, below, for
  33. that). Instead, it prints out the final glyph indices and
  34. positions, taking all shaping operations into account, as if the
  35. input string were a HarfBuzz input buffer.
  36. </para>
  37. <para>
  38. You can specify the font to be used for shaping and, with
  39. command-line options, you can add various aspects of the
  40. internal state to the output that is sent to the terminal. The
  41. general format is
  42. </para>
  43. <programlisting>
  44. <command>hb-shape</command> <optional>[OPTIONS]</optional>
  45. <parameter>path/to/font/file.ttf</parameter>
  46. <parameter>yourinputtext</parameter>
  47. </programlisting>
  48. <para>
  49. The default output format is plain text (although JSON output
  50. can be selected instead by specifying the option
  51. <optional>--output-format=json</optional>). The default output
  52. syntax reports each glyph name (or glyph index if there is no
  53. name) followed by its cluster value, its horizontal and vertical
  54. position displacement, and its horizontal and vertical advances.
  55. </para>
  56. <para>
  57. Output options exist to skip any of these elements in the
  58. output, and to include additional data, such as Unicode
  59. code-point values, glyph extents, glyph flags, or interim
  60. shaping results.
  61. </para>
  62. <para>
  63. Output can also be redirected to a file, or input read from a
  64. file. Additional options enable you to enable or disable
  65. specific font features, to set variation-font axis values, to
  66. alter the language, script, direction, and clustering settings
  67. used, to enable sanity checks, or to change which shaping engine is used.
  68. </para>
  69. <para>
  70. For a complete explanation of the options available, run
  71. </para>
  72. <programlisting>
  73. <command>hb-shape</command> <parameter>--help</parameter>
  74. </programlisting>
  75. </section>
  76. <section id="utilities-command-line-hbview">
  77. <title>hb-view</title>
  78. <para>
  79. <emphasis><command>hb-view</command></emphasis> allows you to
  80. see the shaped output of an input string in rendered
  81. form. Like <command>hb-shape</command>,
  82. <command>hb-view</command> takes a font file and a text string
  83. as its arguments:
  84. </para>
  85. <programlisting>
  86. <command>hb-view</command> <optional>[OPTIONS]</optional>
  87. <parameter>path/to/font/file.ttf</parameter>
  88. <parameter>yourinputtext</parameter>
  89. </programlisting>
  90. <para>
  91. By default, <command>hb-view</command> renders the shaped
  92. text in ASCII block-character images as terminal output. By
  93. appending the
  94. <command>--output-file=<optional>filename</optional></command>
  95. switch, you can write the output to a PNG, SVG, or PDF file
  96. (among other formats).
  97. </para>
  98. <para>
  99. As with <command>hb-shape</command>, a lengthy set of options
  100. is available, with which you can enable or disable
  101. specific font features, set variation-font axis values,
  102. alter the language, script, direction, and clustering settings
  103. used, enable sanity checks, or change which shaping engine is
  104. used.
  105. </para>
  106. <para>
  107. You can also set the foreground and background colors used for
  108. the output, independently control the width of all four
  109. margins, alter the line spacing, and annotate the output image
  110. with
  111. </para>
  112. <para>
  113. In general, <command>hb-view</command> is a quick way to
  114. verify that the output of HarfBuzz's shaping operation looks
  115. correct for a given text-and-font combination, but you may
  116. want to use <command>hb-shape</command> to figure out exactly
  117. why something does not appear as expected.
  118. </para>
  119. </section>
  120. <section id="utilities-command-line-hbsubset">
  121. <title>hb-subset</title>
  122. <para>
  123. <emphasis><command>hb-subset</command></emphasis> allows you
  124. to generate a subset of a given font, with a limited set of
  125. supported characters, features, and variation settings.
  126. </para>
  127. <para>
  128. By default, you provide an input font and an input text string
  129. as the arguments to <command>hb-subset</command>, and it will
  130. generate a font that covers the input text exactly like the
  131. input font does, but includes no other characters or features.
  132. </para>
  133. <programlisting>
  134. <command>hb-subset</command> <optional>[OPTIONS]</optional>
  135. <parameter>path/to/font/file.ttf</parameter>
  136. <parameter>yourinputtext</parameter>
  137. </programlisting>
  138. <para>
  139. For example, to create a subset of Noto Serif that just includes the
  140. numerals and the lowercase Latin alphabet, you could run
  141. </para>
  142. <programlisting>
  143. <command>hb-subset</command> <optional>[OPTIONS]</optional>
  144. <parameter>NotoSerif-Regular.ttf</parameter>
  145. <parameter>0123456789abcdefghijklmnopqrstuvwxyz</parameter>
  146. </programlisting>
  147. <para>
  148. There are options available to remove hinting from the
  149. subsetted font and to specify a list of variation-axis settings.
  150. </para>
  151. </section>
  152. </section>
  153. <section id="utilities-common-types-apis">
  154. <title>Common data types and APIs</title>
  155. <para>
  156. HarfBuzz includes several APIs for working with general-purpose
  157. data that you may find convenient to leverage in your own
  158. software. They include set operations and integer-to-integer
  159. mapping operations.
  160. </para>
  161. <para>
  162. HarfBuzz uses set operations for internal bookkeeping, such as
  163. when it collects all of the glyph IDs covered by a particular
  164. font feature. You can also use the set API to build sets, add
  165. and remove elements, test whether or not sets contain particular
  166. elements, or compute the unions, intersections, or differences
  167. between sets.
  168. </para>
  169. <para>
  170. All set elements are integers (specifically,
  171. <type>hb_codepoint_t</type> 32-bit unsigned ints), and there are
  172. functions for fetching the minimum and maximum element from a
  173. set. The set API also includes some functions that might not
  174. be part of a generic set facility, such as the ability to add a
  175. contiguous range of integer elements to a set in bulk, and the
  176. ability to fetch the next-smallest or next-largest element.
  177. </para>
  178. <para>
  179. The HarfBuzz set API includes some conveniences as well. All
  180. sets are lifecycle-managed, just like other HarfBuzz
  181. objects. You increase the reference count on a set with
  182. <function>hb_set_reference()</function> and decrease it with
  183. <function>hb_set_destroy()</function>. You can also attach
  184. user data to a set, just like you can to blobs, buffers, faces,
  185. fonts, and other objects, and set destroy callbacks.
  186. </para>
  187. <para>
  188. HarfBuzz also provides an API for keeping track of
  189. integer-to-integer mappings. As with the set API, each integer is
  190. stored as an unsigned 32-bit <type>hb_codepoint_t</type>
  191. element. Maps, like other objects, are reference counted with
  192. reference and destroy functions, and you can attach user data to
  193. them. The mapping operations include adding and deleting
  194. integer-to-integer key:value pairs to the map, testing for the
  195. presence of a key, fetching the population of the map, and so on.
  196. </para>
  197. <para>
  198. There are several other internal HarfBuzz facilities that are
  199. exposed publicly and which you may want to take advantage of
  200. while processing text. HarfBuzz uses a common
  201. <type>hb_tag_t</type> for a variety of OpenType tag identifiers (for
  202. scripts, languages, font features, table names, variation-axis
  203. names, and more), and provides functions for converting strings
  204. to tags and vice-versa.
  205. </para>
  206. <para>
  207. Finally, HarfBuzz also includes data type for Booleans, bit
  208. masks, and other simple types.
  209. </para>
  210. </section>
  211. </chapter>