1*2d1272b8SAndroid Build Coastguard Worker<?xml version="1.0"?> 2*2d1272b8SAndroid Build Coastguard Worker<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" 3*2d1272b8SAndroid Build Coastguard Worker "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [ 4*2d1272b8SAndroid Build Coastguard Worker <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'"> 5*2d1272b8SAndroid Build Coastguard Worker <!ENTITY version SYSTEM "version.xml"> 6*2d1272b8SAndroid Build Coastguard Worker]> 7*2d1272b8SAndroid Build Coastguard Worker<chapter id="integration"> 8*2d1272b8SAndroid Build Coastguard Worker <title>Platform Integration Guide</title> 9*2d1272b8SAndroid Build Coastguard Worker <para> 10*2d1272b8SAndroid Build Coastguard Worker HarfBuzz was first developed for use with the GNOME and GTK 11*2d1272b8SAndroid Build Coastguard Worker software stack commonly found in desktop Linux 12*2d1272b8SAndroid Build Coastguard Worker distributions. Nevertheless, it can be used on other operating 13*2d1272b8SAndroid Build Coastguard Worker systems and platforms, from iOS and macOS to Windows. It can also 14*2d1272b8SAndroid Build Coastguard Worker be used with other application frameworks and components, such as 15*2d1272b8SAndroid Build Coastguard Worker Android, Qt, or application-specific widget libraries. 16*2d1272b8SAndroid Build Coastguard Worker </para> 17*2d1272b8SAndroid Build Coastguard Worker <para> 18*2d1272b8SAndroid Build Coastguard Worker This chapter will look at how HarfBuzz fits into a typical 19*2d1272b8SAndroid Build Coastguard Worker text-rendering pipeline, and will discuss the APIs available to 20*2d1272b8SAndroid Build Coastguard Worker integrate HarfBuzz with contemporary Linux, Mac, and Windows 21*2d1272b8SAndroid Build Coastguard Worker software. It will also show how HarfBuzz integrates with popular 22*2d1272b8SAndroid Build Coastguard Worker external libraries like FreeType and International Components for 23*2d1272b8SAndroid Build Coastguard Worker Unicode (ICU) and describe the HarfBuzz language bindings for 24*2d1272b8SAndroid Build Coastguard Worker Python. 25*2d1272b8SAndroid Build Coastguard Worker </para> 26*2d1272b8SAndroid Build Coastguard Worker <para> 27*2d1272b8SAndroid Build Coastguard Worker On a GNOME system, HarfBuzz is designed to tie in with several 28*2d1272b8SAndroid Build Coastguard Worker other common system libraries. The most common architecture uses 29*2d1272b8SAndroid Build Coastguard Worker Pango at the layer directly "above" HarfBuzz; Pango is responsible 30*2d1272b8SAndroid Build Coastguard Worker for text segmentation and for ensuring that each input 31*2d1272b8SAndroid Build Coastguard Worker <type>hb_buffer_t</type> passed to HarfBuzz for shaping contains 32*2d1272b8SAndroid Build Coastguard Worker Unicode code points that share the same segment properties 33*2d1272b8SAndroid Build Coastguard Worker (namely, direction, language, and script, but also higher-level 34*2d1272b8SAndroid Build Coastguard Worker properties like the active font, font style, and so on). 35*2d1272b8SAndroid Build Coastguard Worker </para> 36*2d1272b8SAndroid Build Coastguard Worker <para> 37*2d1272b8SAndroid Build Coastguard Worker The layer directly "below" HarfBuzz is typically FreeType, which 38*2d1272b8SAndroid Build Coastguard Worker is used to rasterize glyph outlines at the necessary optical size, 39*2d1272b8SAndroid Build Coastguard Worker hinting settings, and pixel resolution. FreeType provides APIs for 40*2d1272b8SAndroid Build Coastguard Worker accessing font and face information, so HarfBuzz includes 41*2d1272b8SAndroid Build Coastguard Worker functions to create <type>hb_face_t</type> and 42*2d1272b8SAndroid Build Coastguard Worker <type>hb_font_t</type> objects directly from FreeType 43*2d1272b8SAndroid Build Coastguard Worker objects. HarfBuzz can use FreeType's built-in functions for 44*2d1272b8SAndroid Build Coastguard Worker <structfield>font_funcs</structfield> vtable in an <type>hb_font_t</type>. 45*2d1272b8SAndroid Build Coastguard Worker </para> 46*2d1272b8SAndroid Build Coastguard Worker <para> 47*2d1272b8SAndroid Build Coastguard Worker FreeType's output is bitmaps of the rasterized glyphs; on a 48*2d1272b8SAndroid Build Coastguard Worker typical Linux system these will then be drawn by a graphics 49*2d1272b8SAndroid Build Coastguard Worker library like Cairo, but those details are beyond HarfBuzz's 50*2d1272b8SAndroid Build Coastguard Worker control. On the other hand, at the top end of the stack, Pango is 51*2d1272b8SAndroid Build Coastguard Worker part of the larger GNOME framework, and HarfBuzz does include APIs 52*2d1272b8SAndroid Build Coastguard Worker for working with key components of GNOME's higher-level libraries 53*2d1272b8SAndroid Build Coastguard Worker — most notably GLib. 54*2d1272b8SAndroid Build Coastguard Worker </para> 55*2d1272b8SAndroid Build Coastguard Worker <para> 56*2d1272b8SAndroid Build Coastguard Worker For other operating systems or application frameworks, the 57*2d1272b8SAndroid Build Coastguard Worker critical integration points are where HarfBuzz gets font and face 58*2d1272b8SAndroid Build Coastguard Worker information about the font used for shaping and where HarfBuzz 59*2d1272b8SAndroid Build Coastguard Worker gets Unicode data about the input-buffer code points. 60*2d1272b8SAndroid Build Coastguard Worker </para> 61*2d1272b8SAndroid Build Coastguard Worker <para> 62*2d1272b8SAndroid Build Coastguard Worker The font and face information is necessary for text shaping 63*2d1272b8SAndroid Build Coastguard Worker because HarfBuzz needs to retrieve the glyph indices for 64*2d1272b8SAndroid Build Coastguard Worker particular code points, and to know the extents and advances of 65*2d1272b8SAndroid Build Coastguard Worker glyphs. Note that, in an OpenType variable font, both of those 66*2d1272b8SAndroid Build Coastguard Worker types of information can change with different variation-axis 67*2d1272b8SAndroid Build Coastguard Worker settings. 68*2d1272b8SAndroid Build Coastguard Worker </para> 69*2d1272b8SAndroid Build Coastguard Worker <para> 70*2d1272b8SAndroid Build Coastguard Worker The Unicode information is necessary for shaping because the 71*2d1272b8SAndroid Build Coastguard Worker properties of a code point (such as its General Category (gc), 72*2d1272b8SAndroid Build Coastguard Worker Canonical Combining Class (ccc), and decomposition) can directly 73*2d1272b8SAndroid Build Coastguard Worker impact the shaping moves that HarfBuzz performs. 74*2d1272b8SAndroid Build Coastguard Worker </para> 75*2d1272b8SAndroid Build Coastguard Worker 76*2d1272b8SAndroid Build Coastguard Worker <section id="integration-glib"> 77*2d1272b8SAndroid Build Coastguard Worker <title>GNOME integration, GLib, and GObject</title> 78*2d1272b8SAndroid Build Coastguard Worker <para> 79*2d1272b8SAndroid Build Coastguard Worker As mentioned in the preceding section, HarfBuzz offers 80*2d1272b8SAndroid Build Coastguard Worker integration APIs to help client programs using the 81*2d1272b8SAndroid Build Coastguard Worker GNOME and GTK framework commonly found in desktop Linux 82*2d1272b8SAndroid Build Coastguard Worker distributions. 83*2d1272b8SAndroid Build Coastguard Worker </para> 84*2d1272b8SAndroid Build Coastguard Worker <para> 85*2d1272b8SAndroid Build Coastguard Worker GLib is the main utility library for GNOME applications. It 86*2d1272b8SAndroid Build Coastguard Worker provides basic data types and conversions, file abstractions, 87*2d1272b8SAndroid Build Coastguard Worker string manipulation, and macros, as well as facilities like 88*2d1272b8SAndroid Build Coastguard Worker memory allocation and the main event loop. 89*2d1272b8SAndroid Build Coastguard Worker </para> 90*2d1272b8SAndroid Build Coastguard Worker <para> 91*2d1272b8SAndroid Build Coastguard Worker Where text shaping is concerned, GLib provides several utilities 92*2d1272b8SAndroid Build Coastguard Worker that HarfBuzz can take advantage of, including a set of 93*2d1272b8SAndroid Build Coastguard Worker Unicode-data functions and a data type for script 94*2d1272b8SAndroid Build Coastguard Worker information. Both are useful when working with HarfBuzz 95*2d1272b8SAndroid Build Coastguard Worker buffers. To make use of them, you will need to include the 96*2d1272b8SAndroid Build Coastguard Worker <filename>hb-glib.h</filename> header file. 97*2d1272b8SAndroid Build Coastguard Worker </para> 98*2d1272b8SAndroid Build Coastguard Worker <para> 99*2d1272b8SAndroid Build Coastguard Worker GLib's <ulink 100*2d1272b8SAndroid Build Coastguard Worker url="https://developer.gnome.org/glib/stable/glib-Unicode-Manipulation.html">Unicode 101*2d1272b8SAndroid Build Coastguard Worker manipulation API</ulink> includes all the functionality 102*2d1272b8SAndroid Build Coastguard Worker necessary to retrieve Unicode data for the 103*2d1272b8SAndroid Build Coastguard Worker <structfield>unicode_funcs</structfield> structure of a HarfBuzz 104*2d1272b8SAndroid Build Coastguard Worker <type>hb_buffer_t</type>. 105*2d1272b8SAndroid Build Coastguard Worker </para> 106*2d1272b8SAndroid Build Coastguard Worker <para> 107*2d1272b8SAndroid Build Coastguard Worker The function <function>hb_glib_get_unicode_funcs()</function> 108*2d1272b8SAndroid Build Coastguard Worker sets up a <type>hb_unicode_funcs_t</type> structure configured 109*2d1272b8SAndroid Build Coastguard Worker with the GLib Unicode functions and returns a pointer to it. 110*2d1272b8SAndroid Build Coastguard Worker </para> 111*2d1272b8SAndroid Build Coastguard Worker <para> 112*2d1272b8SAndroid Build Coastguard Worker You can attach this Unicode-functions structure to your buffer, 113*2d1272b8SAndroid Build Coastguard Worker and it will be ready for use with GLib: 114*2d1272b8SAndroid Build Coastguard Worker </para> 115*2d1272b8SAndroid Build Coastguard Worker <programlisting language="C"> 116*2d1272b8SAndroid Build Coastguard Worker #include <hb-glib.h> 117*2d1272b8SAndroid Build Coastguard Worker ... 118*2d1272b8SAndroid Build Coastguard Worker hb_unicode_funcs_t *glibufunctions; 119*2d1272b8SAndroid Build Coastguard Worker glibufunctions = hb_glib_get_unicode_funcs(); 120*2d1272b8SAndroid Build Coastguard Worker hb_buffer_set_unicode_funcs(buf, glibufunctions); 121*2d1272b8SAndroid Build Coastguard Worker </programlisting> 122*2d1272b8SAndroid Build Coastguard Worker <para> 123*2d1272b8SAndroid Build Coastguard Worker For script information, GLib uses the 124*2d1272b8SAndroid Build Coastguard Worker <type>GUnicodeScript</type> type. Like HarfBuzz's own 125*2d1272b8SAndroid Build Coastguard Worker <type>hb_script_t</type>, this data type is an enumeration 126*2d1272b8SAndroid Build Coastguard Worker of Unicode scripts, but text segments passed in from GLib code 127*2d1272b8SAndroid Build Coastguard Worker will be tagged with a <type>GUnicodeScript</type>. Therefore, 128*2d1272b8SAndroid Build Coastguard Worker when setting the script property on a <type>hb_buffer_t</type>, 129*2d1272b8SAndroid Build Coastguard Worker you will need to convert between the <type>GUnicodeScript</type> 130*2d1272b8SAndroid Build Coastguard Worker of the input provided by GLib and HarfBuzz's 131*2d1272b8SAndroid Build Coastguard Worker <type>hb_script_t</type> type. 132*2d1272b8SAndroid Build Coastguard Worker </para> 133*2d1272b8SAndroid Build Coastguard Worker <para> 134*2d1272b8SAndroid Build Coastguard Worker The <function>hb_glib_script_to_script()</function> function 135*2d1272b8SAndroid Build Coastguard Worker takes an <type>GUnicodeScript</type> script identifier as its 136*2d1272b8SAndroid Build Coastguard Worker sole argument and returns the corresponding <type>hb_script_t</type>. 137*2d1272b8SAndroid Build Coastguard Worker The <function>hb_glib_script_from_script()</function> does the 138*2d1272b8SAndroid Build Coastguard Worker reverse, taking an <type>hb_script_t</type> and returning the 139*2d1272b8SAndroid Build Coastguard Worker <type>GUnicodeScript</type> identifier for GLib. 140*2d1272b8SAndroid Build Coastguard Worker </para> 141*2d1272b8SAndroid Build Coastguard Worker <para> 142*2d1272b8SAndroid Build Coastguard Worker Finally, GLib also provides a reference-counted object type called <ulink 143*2d1272b8SAndroid Build Coastguard Worker url="https://developer.gnome.org/glib/stable/glib-Byte-Arrays.html#GBytes"><type>GBytes</type></ulink> 144*2d1272b8SAndroid Build Coastguard Worker that is used for accessing raw memory segments with the benefits 145*2d1272b8SAndroid Build Coastguard Worker of GLib's lifecycle management. HarfBuzz provides a 146*2d1272b8SAndroid Build Coastguard Worker <function>hb_glib_blob_create()</function> function that lets 147*2d1272b8SAndroid Build Coastguard Worker you create an <type>hb_blob_t</type> directly from a 148*2d1272b8SAndroid Build Coastguard Worker <type>GBytes</type> object. This function takes only the 149*2d1272b8SAndroid Build Coastguard Worker <type>GBytes</type> object as its input; HarfBuzz registers the 150*2d1272b8SAndroid Build Coastguard Worker GLib <function>destroy</function> callback automatically. 151*2d1272b8SAndroid Build Coastguard Worker </para> 152*2d1272b8SAndroid Build Coastguard Worker <para> 153*2d1272b8SAndroid Build Coastguard Worker The GNOME platform also features an object system called 154*2d1272b8SAndroid Build Coastguard Worker GObject. For HarfBuzz, the main advantage of GObject is a 155*2d1272b8SAndroid Build Coastguard Worker feature called <ulink 156*2d1272b8SAndroid Build Coastguard Worker url="https://gi.readthedocs.io/en/latest/">GObject 157*2d1272b8SAndroid Build Coastguard Worker Introspection</ulink>. This is a middleware facility that can be 158*2d1272b8SAndroid Build Coastguard Worker used to generate language bindings for C libraries. HarfBuzz uses it 159*2d1272b8SAndroid Build Coastguard Worker to build its Python bindings, which we will look at in a separate section. 160*2d1272b8SAndroid Build Coastguard Worker </para> 161*2d1272b8SAndroid Build Coastguard Worker </section> 162*2d1272b8SAndroid Build Coastguard Worker 163*2d1272b8SAndroid Build Coastguard Worker <section id="integration-freetype"> 164*2d1272b8SAndroid Build Coastguard Worker <title>FreeType integration</title> 165*2d1272b8SAndroid Build Coastguard Worker <para> 166*2d1272b8SAndroid Build Coastguard Worker FreeType is the free-software font-rendering engine included in 167*2d1272b8SAndroid Build Coastguard Worker desktop Linux distributions, Android, ChromeOS, iOS, and multiple Unix 168*2d1272b8SAndroid Build Coastguard Worker operating systems, and used by cross-platform programs like 169*2d1272b8SAndroid Build Coastguard Worker Chrome, Java, and GhostScript. Used together, HarfBuzz can 170*2d1272b8SAndroid Build Coastguard Worker perform shaping on Unicode text segments, outputting the glyph 171*2d1272b8SAndroid Build Coastguard Worker IDs that FreeType should rasterize from the active font as well 172*2d1272b8SAndroid Build Coastguard Worker as the positions at which those glyphs should be drawn. 173*2d1272b8SAndroid Build Coastguard Worker </para> 174*2d1272b8SAndroid Build Coastguard Worker <para> 175*2d1272b8SAndroid Build Coastguard Worker HarfBuzz provides integration points with FreeType at the 176*2d1272b8SAndroid Build Coastguard Worker face-object and font-object level and for the font-functions 177*2d1272b8SAndroid Build Coastguard Worker virtual-method structure of a font object. These functions 178*2d1272b8SAndroid Build Coastguard Worker make it easy for clients that use FreeType for rasterization 179*2d1272b8SAndroid Build Coastguard Worker or font-loading, to use HarfBuzz for shaping. To use the 180*2d1272b8SAndroid Build Coastguard Worker FreeType-integration API, include the 181*2d1272b8SAndroid Build Coastguard Worker <filename>hb-ft.h</filename> header. 182*2d1272b8SAndroid Build Coastguard Worker </para> 183*2d1272b8SAndroid Build Coastguard Worker <para> 184*2d1272b8SAndroid Build Coastguard Worker In a typical client program, you will create your 185*2d1272b8SAndroid Build Coastguard Worker <type>hb_face_t</type> face object and <type>hb_font_t</type> 186*2d1272b8SAndroid Build Coastguard Worker font object from a FreeType <type>FT_Face</type>. HarfBuzz 187*2d1272b8SAndroid Build Coastguard Worker provides a suite of functions for doing this. 188*2d1272b8SAndroid Build Coastguard Worker </para> 189*2d1272b8SAndroid Build Coastguard Worker <para> 190*2d1272b8SAndroid Build Coastguard Worker In the most common case, you will want to use 191*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_font_create_referenced()</function>, which 192*2d1272b8SAndroid Build Coastguard Worker creates both an <type>hb_face_t</type> face object and 193*2d1272b8SAndroid Build Coastguard Worker <type>hb_font_t</type> font object (linked to that face object), 194*2d1272b8SAndroid Build Coastguard Worker and provides lifecycle management. 195*2d1272b8SAndroid Build Coastguard Worker </para> 196*2d1272b8SAndroid Build Coastguard Worker <para> 197*2d1272b8SAndroid Build Coastguard Worker It is important to note, 198*2d1272b8SAndroid Build Coastguard Worker though, that while HarfBuzz makes a distinction between its face and 199*2d1272b8SAndroid Build Coastguard Worker font objects, FreeType's <type>FT_Face</type> does not. After 200*2d1272b8SAndroid Build Coastguard Worker you create your <type>FT_Face</type>, you must set its size 201*2d1272b8SAndroid Build Coastguard Worker parameter using <function>FT_Set_Char_Size()</function>, because 202*2d1272b8SAndroid Build Coastguard Worker an <type>hb_font_t</type> is defined as an instance of an 203*2d1272b8SAndroid Build Coastguard Worker <type>hb_face_t</type> with size specified. 204*2d1272b8SAndroid Build Coastguard Worker </para> 205*2d1272b8SAndroid Build Coastguard Worker <programlisting language="C"> 206*2d1272b8SAndroid Build Coastguard Worker #include <hb-ft.h> 207*2d1272b8SAndroid Build Coastguard Worker ... 208*2d1272b8SAndroid Build Coastguard Worker FT_New_Face(ft_library, font_path, index, &face); 209*2d1272b8SAndroid Build Coastguard Worker FT_Set_Char_Size(face, 0, 1000, 0, 0); 210*2d1272b8SAndroid Build Coastguard Worker hb_font_t *font = hb_ft_font_create(face); 211*2d1272b8SAndroid Build Coastguard Worker </programlisting> 212*2d1272b8SAndroid Build Coastguard Worker <para> 213*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_font_create_referenced()</function> is 214*2d1272b8SAndroid Build Coastguard Worker the recommended function for creating an <type>hb_face_t</type> face 215*2d1272b8SAndroid Build Coastguard Worker object. This function calls <function>FT_Reference_Face()</function> 216*2d1272b8SAndroid Build Coastguard Worker before using the <type>FT_Face</type> and calls 217*2d1272b8SAndroid Build Coastguard Worker <function>FT_Done_Face()</function> when it is finished using the 218*2d1272b8SAndroid Build Coastguard Worker <type>FT_Face</type>. Consequently, your client program does not need 219*2d1272b8SAndroid Build Coastguard Worker to worry about destroying the <type>FT_Face</type> while HarfBuzz 220*2d1272b8SAndroid Build Coastguard Worker is still using it. 221*2d1272b8SAndroid Build Coastguard Worker </para> 222*2d1272b8SAndroid Build Coastguard Worker <para> 223*2d1272b8SAndroid Build Coastguard Worker Although <function>hb_ft_font_create_referenced()</function> is 224*2d1272b8SAndroid Build Coastguard Worker the recommended function, there is another variant for client code 225*2d1272b8SAndroid Build Coastguard Worker where special circumstances make it necessary. The simpler 226*2d1272b8SAndroid Build Coastguard Worker version of the function is <function>hb_ft_font_create()</function>, 227*2d1272b8SAndroid Build Coastguard Worker which takes an <type>FT_Face</type> and an optional destroy callback 228*2d1272b8SAndroid Build Coastguard Worker as its arguments. Because <function>hb_ft_font_create()</function> 229*2d1272b8SAndroid Build Coastguard Worker does not offer lifecycle management, however, your client code will 230*2d1272b8SAndroid Build Coastguard Worker be responsible for tracking references to the <type>FT_Face</type> 231*2d1272b8SAndroid Build Coastguard Worker objects and destroying them when they are no longer needed. If you 232*2d1272b8SAndroid Build Coastguard Worker do not have a valid reason for doing this, use 233*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_font_create_referenced()</function>. 234*2d1272b8SAndroid Build Coastguard Worker </para> 235*2d1272b8SAndroid Build Coastguard Worker <para> 236*2d1272b8SAndroid Build Coastguard Worker After you have created your font object from your 237*2d1272b8SAndroid Build Coastguard Worker <type>FT_Face</type>, you can set or retrieve the 238*2d1272b8SAndroid Build Coastguard Worker <structfield>load_flags</structfield> of the 239*2d1272b8SAndroid Build Coastguard Worker <type>FT_Face</type> through the <type>hb_font_t</type> 240*2d1272b8SAndroid Build Coastguard Worker object. HarfBuzz provides 241*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_font_set_load_flags()</function> and 242*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_font_get_load_flags()</function> for this 243*2d1272b8SAndroid Build Coastguard Worker purpose. The ability to set the 244*2d1272b8SAndroid Build Coastguard Worker <structfield>load_flags</structfield> through the font object 245*2d1272b8SAndroid Build Coastguard Worker could be useful for enabling or disabling hinting, for example, 246*2d1272b8SAndroid Build Coastguard Worker or to activate vertical layout. 247*2d1272b8SAndroid Build Coastguard Worker </para> 248*2d1272b8SAndroid Build Coastguard Worker <para> 249*2d1272b8SAndroid Build Coastguard Worker HarfBuzz also provides a utility function called 250*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_font_changed()</function> that you should 251*2d1272b8SAndroid Build Coastguard Worker call whenever you have altered the properties of your underlying 252*2d1272b8SAndroid Build Coastguard Worker <type>FT_Face</type>, as well as a 253*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_get_face()</function> that you can call on an 254*2d1272b8SAndroid Build Coastguard Worker <type>hb_font_t</type> font object to fetch its underlying <type>FT_Face</type>. 255*2d1272b8SAndroid Build Coastguard Worker </para> 256*2d1272b8SAndroid Build Coastguard Worker <para> 257*2d1272b8SAndroid Build Coastguard Worker With an <type>hb_face_t</type> and <type>hb_font_t</type> both linked 258*2d1272b8SAndroid Build Coastguard Worker to your <type>FT_Face</type>, you will typically also want to 259*2d1272b8SAndroid Build Coastguard Worker use FreeType for the <structfield>font_funcs</structfield> 260*2d1272b8SAndroid Build Coastguard Worker vtable of your <type>hb_font_t</type>. As a reminder, this 261*2d1272b8SAndroid Build Coastguard Worker font-functions structure is the set of methods that HarfBuzz 262*2d1272b8SAndroid Build Coastguard Worker will use to fetch important information from the font, such as 263*2d1272b8SAndroid Build Coastguard Worker the advances and extents of individual glyphs. 264*2d1272b8SAndroid Build Coastguard Worker </para> 265*2d1272b8SAndroid Build Coastguard Worker <para> 266*2d1272b8SAndroid Build Coastguard Worker All you need to do is call 267*2d1272b8SAndroid Build Coastguard Worker </para> 268*2d1272b8SAndroid Build Coastguard Worker <programlisting language="C"> 269*2d1272b8SAndroid Build Coastguard Worker hb_ft_font_set_funcs(font); 270*2d1272b8SAndroid Build Coastguard Worker </programlisting> 271*2d1272b8SAndroid Build Coastguard Worker <para> 272*2d1272b8SAndroid Build Coastguard Worker and HarfBuzz will use FreeType for the font-functions in 273*2d1272b8SAndroid Build Coastguard Worker <literal>font</literal>. 274*2d1272b8SAndroid Build Coastguard Worker </para> 275*2d1272b8SAndroid Build Coastguard Worker <para> 276*2d1272b8SAndroid Build Coastguard Worker As we noted above, an <type>hb_font_t</type> is derived from an 277*2d1272b8SAndroid Build Coastguard Worker <type>hb_face_t</type> with size (and, perhaps, other 278*2d1272b8SAndroid Build Coastguard Worker parameters, such as variation-axis coordinates) 279*2d1272b8SAndroid Build Coastguard Worker specified. Consequently, you can reuse an <type>hb_face_t</type> 280*2d1272b8SAndroid Build Coastguard Worker with several <type>hb_font_t</type> objects, and HarfBuzz 281*2d1272b8SAndroid Build Coastguard Worker provides functions to simplify this. 282*2d1272b8SAndroid Build Coastguard Worker </para> 283*2d1272b8SAndroid Build Coastguard Worker <para> 284*2d1272b8SAndroid Build Coastguard Worker The <function>hb_ft_face_create_referenced()</function> 285*2d1272b8SAndroid Build Coastguard Worker function creates just an <type>hb_face_t</type> from a FreeType 286*2d1272b8SAndroid Build Coastguard Worker <type>FT_Face</type> and, as with 287*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_font_create_referenced()</function> above, 288*2d1272b8SAndroid Build Coastguard Worker provides lifecycle management for the <type>FT_Face</type>. 289*2d1272b8SAndroid Build Coastguard Worker </para> 290*2d1272b8SAndroid Build Coastguard Worker <para> 291*2d1272b8SAndroid Build Coastguard Worker Similarly, there is an <function>hb_ft_face_create()</function> 292*2d1272b8SAndroid Build Coastguard Worker function variant that does not provide the lifecycle-management 293*2d1272b8SAndroid Build Coastguard Worker feature. As with the font-object case, if you use this version 294*2d1272b8SAndroid Build Coastguard Worker of the function, it will be your client code's respsonsibility 295*2d1272b8SAndroid Build Coastguard Worker to track usage of the <type>FT_Face</type> objects. 296*2d1272b8SAndroid Build Coastguard Worker </para> 297*2d1272b8SAndroid Build Coastguard Worker <para> 298*2d1272b8SAndroid Build Coastguard Worker A third variant of this function is 299*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_face_create_cached()</function>, which is the 300*2d1272b8SAndroid Build Coastguard Worker same as <function>hb_ft_face_create()</function> except that it 301*2d1272b8SAndroid Build Coastguard Worker also uses the <structfield>generic</structfield> field of the 302*2d1272b8SAndroid Build Coastguard Worker <type>FT_Face</type> structure to save a pointer to the newly 303*2d1272b8SAndroid Build Coastguard Worker created <type>hb_face_t</type>. Subsequently, function calls 304*2d1272b8SAndroid Build Coastguard Worker that pass the same <type>FT_Face</type> will get the same 305*2d1272b8SAndroid Build Coastguard Worker <type>hb_face_t</type> returned — and the 306*2d1272b8SAndroid Build Coastguard Worker <type>hb_face_t</type> will be correctly reference 307*2d1272b8SAndroid Build Coastguard Worker counted. Still, as with 308*2d1272b8SAndroid Build Coastguard Worker <function>hb_ft_face_create()</function>, your client code must 309*2d1272b8SAndroid Build Coastguard Worker track references to the <type>FT_Face</type> itself, and destroy 310*2d1272b8SAndroid Build Coastguard Worker it when it is unneeded. 311*2d1272b8SAndroid Build Coastguard Worker </para> 312*2d1272b8SAndroid Build Coastguard Worker </section> 313*2d1272b8SAndroid Build Coastguard Worker 314*2d1272b8SAndroid Build Coastguard Worker <section id="integration-cairo"> 315*2d1272b8SAndroid Build Coastguard Worker <title>Cairo integration</title> 316*2d1272b8SAndroid Build Coastguard Worker 317*2d1272b8SAndroid Build Coastguard Worker <para> 318*2d1272b8SAndroid Build Coastguard Worker Cairo is a 2D graphics library that is frequently used together 319*2d1272b8SAndroid Build Coastguard Worker with GTK and Pango. Cairo supports rendering text using FreeType, or 320*2d1272b8SAndroid Build Coastguard Worker by using callback-based 'user fonts'. 321*2d1272b8SAndroid Build Coastguard Worker </para> 322*2d1272b8SAndroid Build Coastguard Worker <para> 323*2d1272b8SAndroid Build Coastguard Worker HarfBuzz provides integration points with cairo for fonts as well as 324*2d1272b8SAndroid Build Coastguard Worker for buffers. To use the Cairo-integration API, link against libharfbuzz-cairo, 325*2d1272b8SAndroid Build Coastguard Worker and include the <filename>hb-cairo.h</filename> header. For easy buildsystem 326*2d1272b8SAndroid Build Coastguard Worker integration, HarfBuzz comes with a <filename>harfbuzz-cairo.pc</filename> 327*2d1272b8SAndroid Build Coastguard Worker pkg-config file. 328*2d1272b8SAndroid Build Coastguard Worker </para> 329*2d1272b8SAndroid Build Coastguard Worker <para> 330*2d1272b8SAndroid Build Coastguard Worker To create a <type>cairo_scaled_font_t</type> font from a HarfBuzz 331*2d1272b8SAndroid Build Coastguard Worker <type>hb_font_t</type>, you can use <function>hb_cairo_font_face_create_for_font()</function> 332*2d1272b8SAndroid Build Coastguard Worker or <function>hb_cairo_font_face_create_for_face()</function>. The former API 333*2d1272b8SAndroid Build Coastguard Worker applies variations and synthetic slant from the <type>hb_font_t</type> when 334*2d1272b8SAndroid Build Coastguard Worker rendering, the latter takes them from the <type>cairo_font_options_t</type> 335*2d1272b8SAndroid Build Coastguard Worker that were passed when creating the <type>cairo_scaled_font_t</type>. 336*2d1272b8SAndroid Build Coastguard Worker </para> 337*2d1272b8SAndroid Build Coastguard Worker <para> 338*2d1272b8SAndroid Build Coastguard Worker The Cairo fonts created in this way make use of Cairo's user-font facilities. 339*2d1272b8SAndroid Build Coastguard Worker They can be used to render on any Cairo context, and provide full support for 340*2d1272b8SAndroid Build Coastguard Worker font rendering features, including color. One current limitation of the 341*2d1272b8SAndroid Build Coastguard Worker implementation is that it does not support hinting for glyph outlines. 342*2d1272b8SAndroid Build Coastguard Worker </para> 343*2d1272b8SAndroid Build Coastguard Worker <para> 344*2d1272b8SAndroid Build Coastguard Worker When using color fonts with this API, the color palette index is taken from 345*2d1272b8SAndroid Build Coastguard Worker the <type>cairo_font_options_t</type> (with new enough Cairo), and the foreground 346*2d1272b8SAndroid Build Coastguard Worker color is extracted from the source of the Cairo context. 347*2d1272b8SAndroid Build Coastguard Worker </para> 348*2d1272b8SAndroid Build Coastguard Worker <para> 349*2d1272b8SAndroid Build Coastguard Worker To render the results of shaping a piece of text, use 350*2d1272b8SAndroid Build Coastguard Worker <function>hb_cairo_glyphs_from_buffer()</function> to obtain the glyphs in 351*2d1272b8SAndroid Build Coastguard Worker a form that can be passed to <function>cairo_show_text_glyphs()</function> or 352*2d1272b8SAndroid Build Coastguard Worker <function>cairo_show_glyphs()</function>. 353*2d1272b8SAndroid Build Coastguard Worker </para> 354*2d1272b8SAndroid Build Coastguard Worker </section> 355*2d1272b8SAndroid Build Coastguard Worker 356*2d1272b8SAndroid Build Coastguard Worker <section id="integration-uniscribe"> 357*2d1272b8SAndroid Build Coastguard Worker <title>Uniscribe integration</title> 358*2d1272b8SAndroid Build Coastguard Worker <para> 359*2d1272b8SAndroid Build Coastguard Worker If your client program is running on Windows, HarfBuzz offers 360*2d1272b8SAndroid Build Coastguard Worker an additional API that can help integrate with Microsoft's 361*2d1272b8SAndroid Build Coastguard Worker Uniscribe engine and the Windows GDI. 362*2d1272b8SAndroid Build Coastguard Worker </para> 363*2d1272b8SAndroid Build Coastguard Worker <para> 364*2d1272b8SAndroid Build Coastguard Worker Overall, the Uniscribe API covers a broader set of typographic 365*2d1272b8SAndroid Build Coastguard Worker layout functions than HarfBuzz implements, but HarfBuzz's 366*2d1272b8SAndroid Build Coastguard Worker shaping API can serve as a drop-in replacement for Uniscribe's shaping 367*2d1272b8SAndroid Build Coastguard Worker functionality. In fact, one of HarfBuzz's design goals is to 368*2d1272b8SAndroid Build Coastguard Worker accurately reproduce the same output for shaping a given text 369*2d1272b8SAndroid Build Coastguard Worker segment that Uniscribe produces — even to the point of 370*2d1272b8SAndroid Build Coastguard Worker duplicating known shaping bugs or deviations from the 371*2d1272b8SAndroid Build Coastguard Worker specification — so you can be confident that your users' 372*2d1272b8SAndroid Build Coastguard Worker documents with their existing fonts will not be affected adversely by 373*2d1272b8SAndroid Build Coastguard Worker switching to HarfBuzz. 374*2d1272b8SAndroid Build Coastguard Worker </para> 375*2d1272b8SAndroid Build Coastguard Worker <para> 376*2d1272b8SAndroid Build Coastguard Worker At a basic level, HarfBuzz's <function>hb_shape()</function> 377*2d1272b8SAndroid Build Coastguard Worker function replaces both the <ulink url=""><function>ScriptShape()</function></ulink> 378*2d1272b8SAndroid Build Coastguard Worker and <ulink 379*2d1272b8SAndroid Build Coastguard Worker url="https://docs.microsoft.com/en-us/windows/desktop/api/Usp10/nf-usp10-scriptplace"><function>ScriptPlace()</function></ulink> 380*2d1272b8SAndroid Build Coastguard Worker functions from Uniscribe. 381*2d1272b8SAndroid Build Coastguard Worker </para> 382*2d1272b8SAndroid Build Coastguard Worker <para> 383*2d1272b8SAndroid Build Coastguard Worker However, whereas <function>ScriptShape()</function> returns the 384*2d1272b8SAndroid Build Coastguard Worker glyphs and clusters for a shaped sequence and 385*2d1272b8SAndroid Build Coastguard Worker <function>ScriptPlace()</function> returns the advances and 386*2d1272b8SAndroid Build Coastguard Worker offsets for those glyphs, <function>hb_shape()</function> 387*2d1272b8SAndroid Build Coastguard Worker handles both. After <function>hb_shape()</function> shapes a 388*2d1272b8SAndroid Build Coastguard Worker buffer, the output glyph IDs and cluster IDs are returned as 389*2d1272b8SAndroid Build Coastguard Worker an array of <structname>hb_glyph_info_t</structname> structures, and the 390*2d1272b8SAndroid Build Coastguard Worker glyph advances and offsets are returned as an array of 391*2d1272b8SAndroid Build Coastguard Worker <structname>hb_glyph_position_t</structname> structures. 392*2d1272b8SAndroid Build Coastguard Worker </para> 393*2d1272b8SAndroid Build Coastguard Worker <para> 394*2d1272b8SAndroid Build Coastguard Worker Your client program only needs to ensure that it converts 395*2d1272b8SAndroid Build Coastguard Worker correctly between HarfBuzz's low-level data types (such as 396*2d1272b8SAndroid Build Coastguard Worker <type>hb_position_t</type>) and Windows's corresponding types 397*2d1272b8SAndroid Build Coastguard Worker (such as <type>GOFFSET</type> and <type>ABC</type>). Be sure you 398*2d1272b8SAndroid Build Coastguard Worker read the <xref linkend="buffers-language-script-and-direction" 399*2d1272b8SAndroid Build Coastguard Worker /> 400*2d1272b8SAndroid Build Coastguard Worker chapter for a full explanation of how HarfBuzz input buffers are 401*2d1272b8SAndroid Build Coastguard Worker used, and see <xref linkend="shaping-buffer-output" /> for the 402*2d1272b8SAndroid Build Coastguard Worker details of what <function>hb_shape()</function> returns in the 403*2d1272b8SAndroid Build Coastguard Worker output buffer when shaping is complete. 404*2d1272b8SAndroid Build Coastguard Worker </para> 405*2d1272b8SAndroid Build Coastguard Worker <para> 406*2d1272b8SAndroid Build Coastguard Worker Although <function>hb_shape()</function> itself is functionally 407*2d1272b8SAndroid Build Coastguard Worker equivalent to Uniscribe's shaping routines, there are two 408*2d1272b8SAndroid Build Coastguard Worker additional HarfBuzz functions you may want to use to integrate 409*2d1272b8SAndroid Build Coastguard Worker the libraries in your code. Both are used to link HarfBuzz font 410*2d1272b8SAndroid Build Coastguard Worker objects to the equivalent Windows structures. 411*2d1272b8SAndroid Build Coastguard Worker </para> 412*2d1272b8SAndroid Build Coastguard Worker <para> 413*2d1272b8SAndroid Build Coastguard Worker The <function>hb_uniscribe_font_get_logfontw()</function> 414*2d1272b8SAndroid Build Coastguard Worker function takes a <type>hb_font_t</type> font object and returns 415*2d1272b8SAndroid Build Coastguard Worker a pointer to the <ulink 416*2d1272b8SAndroid Build Coastguard Worker url="https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-logfontw"><type>LOGFONTW</type></ulink> 417*2d1272b8SAndroid Build Coastguard Worker "logical font" that corresponds to it. A <type>LOGFONTW</type> 418*2d1272b8SAndroid Build Coastguard Worker structure holds font-wide attributes, including metrics, size, 419*2d1272b8SAndroid Build Coastguard Worker and style information. 420*2d1272b8SAndroid Build Coastguard Worker </para> 421*2d1272b8SAndroid Build Coastguard Worker<!-- 422*2d1272b8SAndroid Build Coastguard Worker <para> 423*2d1272b8SAndroid Build Coastguard Worker In Uniscribe's model, the <type>SCRIPT_CACHE</type> holds the 424*2d1272b8SAndroid Build Coastguard Worker device context, including the logical font that the shaping 425*2d1272b8SAndroid Build Coastguard Worker functions apply. 426*2d1272b8SAndroid Build Coastguard Worker https://docs.microsoft.com/en-us/windows/desktop/Intl/script-cache 427*2d1272b8SAndroid Build Coastguard Worker </para> 428*2d1272b8SAndroid Build Coastguard Worker--> 429*2d1272b8SAndroid Build Coastguard Worker <para> 430*2d1272b8SAndroid Build Coastguard Worker The <function>hb_uniscribe_font_get_hfont()</function> function 431*2d1272b8SAndroid Build Coastguard Worker also takes a <type>hb_font_t</type> font object, but it returns 432*2d1272b8SAndroid Build Coastguard Worker an <type>HFONT</type> — a handle to the underlying logical 433*2d1272b8SAndroid Build Coastguard Worker font — instead. 434*2d1272b8SAndroid Build Coastguard Worker </para> 435*2d1272b8SAndroid Build Coastguard Worker <para> 436*2d1272b8SAndroid Build Coastguard Worker <type>LOGFONTW</type>s and <type>HFONT</type>s are both needed 437*2d1272b8SAndroid Build Coastguard Worker by other Uniscribe functions. 438*2d1272b8SAndroid Build Coastguard Worker </para> 439*2d1272b8SAndroid Build Coastguard Worker <para> 440*2d1272b8SAndroid Build Coastguard Worker As a final note, you may notice a reference to an optional 441*2d1272b8SAndroid Build Coastguard Worker <literal>uniscribe</literal> shaper back-end in the <xref 442*2d1272b8SAndroid Build Coastguard Worker linkend="configuration" /> section of the HarfBuzz manual. This 443*2d1272b8SAndroid Build Coastguard Worker option is not a Uniscribe-integration facility. 444*2d1272b8SAndroid Build Coastguard Worker </para> 445*2d1272b8SAndroid Build Coastguard Worker <para> 446*2d1272b8SAndroid Build Coastguard Worker Instead, it is a internal code path used in the 447*2d1272b8SAndroid Build Coastguard Worker <command>hb-shape</command> command-line utility, which hands 448*2d1272b8SAndroid Build Coastguard Worker shaping functionality over to Uniscribe entirely, when run on a 449*2d1272b8SAndroid Build Coastguard Worker Windows system. That allows testing HarfBuzz's native output 450*2d1272b8SAndroid Build Coastguard Worker against the Uniscribe engine, for tracking compatibility and 451*2d1272b8SAndroid Build Coastguard Worker debugging. 452*2d1272b8SAndroid Build Coastguard Worker </para> 453*2d1272b8SAndroid Build Coastguard Worker <para> 454*2d1272b8SAndroid Build Coastguard Worker Because this back-end is only used when testing HarfBuzz 455*2d1272b8SAndroid Build Coastguard Worker functionality, it is disabled by default when building the 456*2d1272b8SAndroid Build Coastguard Worker HarfBuzz binaries. 457*2d1272b8SAndroid Build Coastguard Worker </para> 458*2d1272b8SAndroid Build Coastguard Worker </section> 459*2d1272b8SAndroid Build Coastguard Worker 460*2d1272b8SAndroid Build Coastguard Worker <section id="integration-coretext"> 461*2d1272b8SAndroid Build Coastguard Worker <title>Core Text integration</title> 462*2d1272b8SAndroid Build Coastguard Worker <para> 463*2d1272b8SAndroid Build Coastguard Worker If your client program is running on macOS or iOS, HarfBuzz offers 464*2d1272b8SAndroid Build Coastguard Worker an additional API that can help integrate with Apple's 465*2d1272b8SAndroid Build Coastguard Worker Core Text engine and the underlying Core Graphics 466*2d1272b8SAndroid Build Coastguard Worker framework. HarfBuzz does not attempt to offer the same 467*2d1272b8SAndroid Build Coastguard Worker drop-in-replacement functionality for Core Text that it strives 468*2d1272b8SAndroid Build Coastguard Worker for with Uniscribe on Windows, but you can still use HarfBuzz 469*2d1272b8SAndroid Build Coastguard Worker to perform text shaping in native macOS and iOS applications. 470*2d1272b8SAndroid Build Coastguard Worker </para> 471*2d1272b8SAndroid Build Coastguard Worker <para> 472*2d1272b8SAndroid Build Coastguard Worker Note, though, that if your interest is just in using fonts that 473*2d1272b8SAndroid Build Coastguard Worker contain Apple Advanced Typography (AAT) features, then you do 474*2d1272b8SAndroid Build Coastguard Worker not need to add Core Text integration. HarfBuzz natively 475*2d1272b8SAndroid Build Coastguard Worker supports AAT features and will shape AAT fonts (on any platform) 476*2d1272b8SAndroid Build Coastguard Worker automatically, without requiring additional work on your 477*2d1272b8SAndroid Build Coastguard Worker part. This includes support for AAT-specific TrueType tables 478*2d1272b8SAndroid Build Coastguard Worker such as <literal>mort</literal>, <literal>morx</literal>, and 479*2d1272b8SAndroid Build Coastguard Worker <literal>kerx</literal>, which AAT fonts use instead of 480*2d1272b8SAndroid Build Coastguard Worker <literal>GSUB</literal> and <literal>GPOS</literal>. 481*2d1272b8SAndroid Build Coastguard Worker </para> 482*2d1272b8SAndroid Build Coastguard Worker <para> 483*2d1272b8SAndroid Build Coastguard Worker On a macOS or iOS system, the primary integration points offered 484*2d1272b8SAndroid Build Coastguard Worker by HarfBuzz are for face objects and font objects. 485*2d1272b8SAndroid Build Coastguard Worker </para> 486*2d1272b8SAndroid Build Coastguard Worker <para> 487*2d1272b8SAndroid Build Coastguard Worker The Apple APIs offer a pair of data structures that map well to 488*2d1272b8SAndroid Build Coastguard Worker HarfBuzz's face and font objects. The Core Graphics API, which 489*2d1272b8SAndroid Build Coastguard Worker is slightly lower-level than Core Text, provides 490*2d1272b8SAndroid Build Coastguard Worker <ulink url="https://developer.apple.com/documentation/coregraphics/cgfontref"><type>CGFontRef</type></ulink>, which enables access to typeface 491*2d1272b8SAndroid Build Coastguard Worker properties, but does not include size information. Core Text's 492*2d1272b8SAndroid Build Coastguard Worker <ulink url="https://developer.apple.com/documentation/coretext/ctfont-q6r"><type>CTFontRef</type></ulink> is analogous to a HarfBuzz font object, 493*2d1272b8SAndroid Build Coastguard Worker with all of the properties required to render text at a specific 494*2d1272b8SAndroid Build Coastguard Worker size and configuration. 495*2d1272b8SAndroid Build Coastguard Worker Consequently, a HarfBuzz <type>hb_font_t</type> font object can 496*2d1272b8SAndroid Build Coastguard Worker be hooked up to a Core Text <type>CTFontRef</type>, and a HarfBuzz 497*2d1272b8SAndroid Build Coastguard Worker <type>hb_face_t</type> face object can be hooked up to a 498*2d1272b8SAndroid Build Coastguard Worker <type>CGFontRef</type>. 499*2d1272b8SAndroid Build Coastguard Worker </para> 500*2d1272b8SAndroid Build Coastguard Worker <para> 501*2d1272b8SAndroid Build Coastguard Worker You can create a <type>hb_face_t</type> from a 502*2d1272b8SAndroid Build Coastguard Worker <type>CGFontRef</type> by using the 503*2d1272b8SAndroid Build Coastguard Worker <function>hb_coretext_face_create()</function>. Subsequently, 504*2d1272b8SAndroid Build Coastguard Worker you can retrieve the <type>CGFontRef</type> from a 505*2d1272b8SAndroid Build Coastguard Worker <type>hb_face_t</type> with <function>hb_coretext_face_get_cg_font()</function>. 506*2d1272b8SAndroid Build Coastguard Worker </para> 507*2d1272b8SAndroid Build Coastguard Worker <para> 508*2d1272b8SAndroid Build Coastguard Worker Likewise, you create a <type>hb_font_t</type> from a 509*2d1272b8SAndroid Build Coastguard Worker <type>CTFontRef</type> by calling 510*2d1272b8SAndroid Build Coastguard Worker <function>hb_coretext_font_create()</function>, and you can 511*2d1272b8SAndroid Build Coastguard Worker fetch the associated <type>CTFontRef</type> from a 512*2d1272b8SAndroid Build Coastguard Worker <type>hb_font_t</type> font object with 513*2d1272b8SAndroid Build Coastguard Worker <function>hb_coretext_face_get_ct_font()</function>. 514*2d1272b8SAndroid Build Coastguard Worker </para> 515*2d1272b8SAndroid Build Coastguard Worker <para> 516*2d1272b8SAndroid Build Coastguard Worker HarfBuzz also offers a <function>hb_font_set_ptem()</function> 517*2d1272b8SAndroid Build Coastguard Worker that you an use to set the nominal point size on any 518*2d1272b8SAndroid Build Coastguard Worker <type>hb_font_t</type> font object. Core Text uses this value to 519*2d1272b8SAndroid Build Coastguard Worker implement optical scaling. 520*2d1272b8SAndroid Build Coastguard Worker </para> 521*2d1272b8SAndroid Build Coastguard Worker <para> 522*2d1272b8SAndroid Build Coastguard Worker When integrating your client code with Core Text, it is 523*2d1272b8SAndroid Build Coastguard Worker important to recognize that Core Text <literal>points</literal> 524*2d1272b8SAndroid Build Coastguard Worker are not typographic points (standardized at 72 per inch) as the 525*2d1272b8SAndroid Build Coastguard Worker term is used elsewhere in OpenType. Instead, Core Text points 526*2d1272b8SAndroid Build Coastguard Worker are CSS points, which are standardized at 96 per inch. 527*2d1272b8SAndroid Build Coastguard Worker </para> 528*2d1272b8SAndroid Build Coastguard Worker <para> 529*2d1272b8SAndroid Build Coastguard Worker HarfBuzz's font functions take this distinction into account, 530*2d1272b8SAndroid Build Coastguard Worker but it can be an easy detail to miss in cross-platform 531*2d1272b8SAndroid Build Coastguard Worker code. 532*2d1272b8SAndroid Build Coastguard Worker </para> 533*2d1272b8SAndroid Build Coastguard Worker <para> 534*2d1272b8SAndroid Build Coastguard Worker As a final note, you may notice a reference to an optional 535*2d1272b8SAndroid Build Coastguard Worker <literal>coretext</literal> shaper back-end in the <xref 536*2d1272b8SAndroid Build Coastguard Worker linkend="configuration" /> section of the HarfBuzz manual. This 537*2d1272b8SAndroid Build Coastguard Worker option is not a Core Text-integration facility. 538*2d1272b8SAndroid Build Coastguard Worker </para> 539*2d1272b8SAndroid Build Coastguard Worker <para> 540*2d1272b8SAndroid Build Coastguard Worker Instead, it is a internal code path used in the 541*2d1272b8SAndroid Build Coastguard Worker <command>hb-shape</command> command-line utility, which hands 542*2d1272b8SAndroid Build Coastguard Worker shaping functionality over to Core Text entirely, when run on a 543*2d1272b8SAndroid Build Coastguard Worker macOS system. That allows testing HarfBuzz's native output 544*2d1272b8SAndroid Build Coastguard Worker against the Core Text engine, for tracking compatibility and debugging. 545*2d1272b8SAndroid Build Coastguard Worker </para> 546*2d1272b8SAndroid Build Coastguard Worker <para> 547*2d1272b8SAndroid Build Coastguard Worker Because this back-end is only used when testing HarfBuzz 548*2d1272b8SAndroid Build Coastguard Worker functionality, it is disabled by default when building the 549*2d1272b8SAndroid Build Coastguard Worker HarfBuzz binaries. 550*2d1272b8SAndroid Build Coastguard Worker </para> 551*2d1272b8SAndroid Build Coastguard Worker </section> 552*2d1272b8SAndroid Build Coastguard Worker 553*2d1272b8SAndroid Build Coastguard Worker <section id="integration-icu"> 554*2d1272b8SAndroid Build Coastguard Worker <title>ICU integration</title> 555*2d1272b8SAndroid Build Coastguard Worker <para> 556*2d1272b8SAndroid Build Coastguard Worker Although HarfBuzz includes its own Unicode-data functions, it 557*2d1272b8SAndroid Build Coastguard Worker also provides integration APIs for using the International 558*2d1272b8SAndroid Build Coastguard Worker Components for Unicode (ICU) library as a source of Unicode data 559*2d1272b8SAndroid Build Coastguard Worker on any supported platform. 560*2d1272b8SAndroid Build Coastguard Worker </para> 561*2d1272b8SAndroid Build Coastguard Worker <para> 562*2d1272b8SAndroid Build Coastguard Worker The principal integration point with ICU is the 563*2d1272b8SAndroid Build Coastguard Worker <type>hb_unicode_funcs_t</type> Unicode-functions structure 564*2d1272b8SAndroid Build Coastguard Worker attached to a buffer. This structure holds the virtual methods 565*2d1272b8SAndroid Build Coastguard Worker used for retrieving Unicode character properties, such as 566*2d1272b8SAndroid Build Coastguard Worker General Category, Script, Combining Class, decomposition 567*2d1272b8SAndroid Build Coastguard Worker mappings, and mirroring information. 568*2d1272b8SAndroid Build Coastguard Worker </para> 569*2d1272b8SAndroid Build Coastguard Worker <para> 570*2d1272b8SAndroid Build Coastguard Worker To use ICU in your client program, you need to call 571*2d1272b8SAndroid Build Coastguard Worker <function>hb_icu_get_unicode_funcs()</function>, which creates a 572*2d1272b8SAndroid Build Coastguard Worker Unicode-functions structure populated with the ICU function for 573*2d1272b8SAndroid Build Coastguard Worker each included method. Subsequently, you can attach the 574*2d1272b8SAndroid Build Coastguard Worker Unicode-functions structure to your buffer: 575*2d1272b8SAndroid Build Coastguard Worker </para> 576*2d1272b8SAndroid Build Coastguard Worker <programlisting language="C"> 577*2d1272b8SAndroid Build Coastguard Worker hb_unicode_funcs_t *icufunctions; 578*2d1272b8SAndroid Build Coastguard Worker icufunctions = hb_icu_get_unicode_funcs(); 579*2d1272b8SAndroid Build Coastguard Worker hb_buffer_set_unicode_funcs(buf, icufunctions); 580*2d1272b8SAndroid Build Coastguard Worker </programlisting> 581*2d1272b8SAndroid Build Coastguard Worker <para> 582*2d1272b8SAndroid Build Coastguard Worker and ICU will be used for Unicode-data access. 583*2d1272b8SAndroid Build Coastguard Worker </para> 584*2d1272b8SAndroid Build Coastguard Worker <para> 585*2d1272b8SAndroid Build Coastguard Worker HarfBuzz also supplies a pair of functions 586*2d1272b8SAndroid Build Coastguard Worker (<function>hb_icu_script_from_script()</function> and 587*2d1272b8SAndroid Build Coastguard Worker <function>hb_icu_script_to_script()</function>) for converting 588*2d1272b8SAndroid Build Coastguard Worker between ICU's and HarfBuzz's internal enumerations of Unicode 589*2d1272b8SAndroid Build Coastguard Worker scripts. The <function>hb_icu_script_from_script()</function> 590*2d1272b8SAndroid Build Coastguard Worker function converts from a HarfBuzz <type>hb_script_t</type> to an 591*2d1272b8SAndroid Build Coastguard Worker ICU <type>UScriptCode</type>. The 592*2d1272b8SAndroid Build Coastguard Worker <function>hb_icu_script_to_script()</function> function does the 593*2d1272b8SAndroid Build Coastguard Worker reverse: converting from a <type>UScriptCode</type> identifier 594*2d1272b8SAndroid Build Coastguard Worker to a <type>hb_script_t</type>. 595*2d1272b8SAndroid Build Coastguard Worker </para> 596*2d1272b8SAndroid Build Coastguard Worker <para> 597*2d1272b8SAndroid Build Coastguard Worker By default, HarfBuzz's ICU support is built as a separate shared 598*2d1272b8SAndroid Build Coastguard Worker library (<filename class="libraryfile">libharfbuzz-icu.so</filename>) 599*2d1272b8SAndroid Build Coastguard Worker when compiling HarfBuzz from source. This allows client programs 600*2d1272b8SAndroid Build Coastguard Worker that do not need ICU to link against HarfBuzz without unnecessarily 601*2d1272b8SAndroid Build Coastguard Worker adding ICU as a dependency. You can also build HarfBuzz with ICU 602*2d1272b8SAndroid Build Coastguard Worker support built directly into the main HarfBuzz shared library 603*2d1272b8SAndroid Build Coastguard Worker (<filename class="libraryfile">libharfbuzz.so</filename>), 604*2d1272b8SAndroid Build Coastguard Worker by specifying the <literal>--with-icu=builtin</literal> 605*2d1272b8SAndroid Build Coastguard Worker compile-time option. 606*2d1272b8SAndroid Build Coastguard Worker </para> 607*2d1272b8SAndroid Build Coastguard Worker 608*2d1272b8SAndroid Build Coastguard Worker </section> 609*2d1272b8SAndroid Build Coastguard Worker 610*2d1272b8SAndroid Build Coastguard Worker <section id="integration-python"> 611*2d1272b8SAndroid Build Coastguard Worker <title>Python bindings</title> 612*2d1272b8SAndroid Build Coastguard Worker <para> 613*2d1272b8SAndroid Build Coastguard Worker As noted in the <xref linkend="integration-glib" /> section, 614*2d1272b8SAndroid Build Coastguard Worker HarfBuzz uses a feature called <ulink 615*2d1272b8SAndroid Build Coastguard Worker url="https://wiki.gnome.org/Projects/GObjectIntrospection">GObject 616*2d1272b8SAndroid Build Coastguard Worker Introspection</ulink> (GI) to provide bindings for Python. 617*2d1272b8SAndroid Build Coastguard Worker </para> 618*2d1272b8SAndroid Build Coastguard Worker <para> 619*2d1272b8SAndroid Build Coastguard Worker At compile time, the GI scanner analyzes the HarfBuzz C source 620*2d1272b8SAndroid Build Coastguard Worker and builds metadata objects connecting the language bindings to 621*2d1272b8SAndroid Build Coastguard Worker the C library. Your Python code can then use the HarfBuzz binary 622*2d1272b8SAndroid Build Coastguard Worker through its Python interface. 623*2d1272b8SAndroid Build Coastguard Worker </para> 624*2d1272b8SAndroid Build Coastguard Worker <para> 625*2d1272b8SAndroid Build Coastguard Worker HarfBuzz's Python bindings support Python 2 and Python 3. To use 626*2d1272b8SAndroid Build Coastguard Worker them, you will need to have the <literal>pygobject</literal> 627*2d1272b8SAndroid Build Coastguard Worker package installed. Then you should import 628*2d1272b8SAndroid Build Coastguard Worker <literal>HarfBuzz</literal> from 629*2d1272b8SAndroid Build Coastguard Worker <literal>gi.repository</literal>: 630*2d1272b8SAndroid Build Coastguard Worker </para> 631*2d1272b8SAndroid Build Coastguard Worker <programlisting language="Python"> 632*2d1272b8SAndroid Build Coastguard Worker from gi.repository import HarfBuzz 633*2d1272b8SAndroid Build Coastguard Worker </programlisting> 634*2d1272b8SAndroid Build Coastguard Worker <para> 635*2d1272b8SAndroid Build Coastguard Worker and you can call HarfBuzz functions from Python. Sample code can 636*2d1272b8SAndroid Build Coastguard Worker be found in the <filename>sample.py</filename> script in the 637*2d1272b8SAndroid Build Coastguard Worker HarfBuzz <filename>src</filename> directory. 638*2d1272b8SAndroid Build Coastguard Worker </para> 639*2d1272b8SAndroid Build Coastguard Worker <para> 640*2d1272b8SAndroid Build Coastguard Worker Do note, however, that the Python API is subject to change 641*2d1272b8SAndroid Build Coastguard Worker without advance notice. GI allows the bindings to be 642*2d1272b8SAndroid Build Coastguard Worker automatically updated, which is one of its advantages, but you 643*2d1272b8SAndroid Build Coastguard Worker may need to update your Python code. 644*2d1272b8SAndroid Build Coastguard Worker </para> 645*2d1272b8SAndroid Build Coastguard Worker </section> 646*2d1272b8SAndroid Build Coastguard Worker 647*2d1272b8SAndroid Build Coastguard Worker</chapter> 648