2 * Copyright © 2017 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
27 #include "hb-open-type-private.hh"
29 #include "hb-ot-layout-private.hh"
30 #include "hb-ot-layout-gsubgpos-private.hh"
32 #include "hb-aat-layout-private.hh"
33 #include "hb-aat-layout-ankr-table.hh"
34 #include "hb-aat-layout-kerx-table.hh"
35 #include "hb-aat-layout-morx-table.hh"
36 #include "hb-aat-layout-trak-table.hh"
42 static inline const AAT::ankr&
43 _get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr)
45 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
48 *blob = hb_blob_get_empty ();
49 return OT::Null(AAT::ankr);
51 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
52 const AAT::ankr& ankr = *(layout->ankr.get ());
54 *blob = layout->ankr.blob;
58 static inline const AAT::kerx&
59 _get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr)
61 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
64 *blob = hb_blob_get_empty ();
65 return OT::Null(AAT::kerx);
67 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
68 /* XXX this doesn't call set_num_glyphs on sanitizer. */
69 const AAT::kerx& kerx = *(layout->kerx.get ());
71 *blob = layout->kerx.blob;
75 static inline const AAT::morx&
76 _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr)
78 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
81 *blob = hb_blob_get_empty ();
82 return OT::Null(AAT::morx);
84 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
85 /* XXX this doesn't call set_num_glyphs on sanitizer. */
86 const AAT::morx& morx = *(layout->morx.get ());
88 *blob = layout->morx.blob;
92 static inline const AAT::trak&
93 _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr)
95 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
98 *blob = hb_blob_get_empty ();
99 return OT::Null(AAT::trak);
101 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
102 const AAT::trak& trak = *(layout->trak.get ());
104 *blob = layout->trak.blob;
108 // static inline void
109 // _hb_aat_layout_create (hb_face_t *face)
111 // OT::Sanitizer<AAT::morx> sanitizer;
112 // sanitizer.set_num_glyphs (face->get_num_glyphs ());
113 // hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_MORX));
114 // OT::Sanitizer<AAT::morx>::lock_instance (morx_blob);
118 // OT::Sanitizer<AAT::Lookup<OT::GlyphID> >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ());
123 hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer)
126 const AAT::morx& morx = _get_morx (font->face, &blob);
128 AAT::hb_aat_apply_context_t c (font, buffer, blob);
133 hb_aat_layout_position (hb_font_t *font, hb_buffer_t *buffer)
136 const AAT::ankr& ankr = _get_ankr (font->face, &blob);
137 const AAT::kerx& kerx = _get_kerx (font->face, &blob);
138 const AAT::trak& trak = _get_trak (font->face, &blob);
140 AAT::hb_aat_apply_context_t c (font, buffer, blob);
141 kerx.apply (&c, &ankr);