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-bsln-table.hh" // Just so we compile it; unused otherwise.
35 #include "hb-aat-layout-feat-table.hh" // Just so we compile it; unused otherwise.
36 #include "hb-aat-layout-kerx-table.hh"
37 #include "hb-aat-layout-morx-table.hh"
38 #include "hb-aat-layout-trak-table.hh"
39 #include "hb-aat-fmtx-table.hh" // Just so we compile it; unused otherwise.
40 #include "hb-aat-gcid-table.hh" // Just so we compile it; unused otherwise.
41 #include "hb-aat-ltag-table.hh" // Just so we compile it; unused otherwise.
48 static inline const AAT::ankr&
49 _get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr)
51 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
54 *blob = hb_blob_get_empty ();
55 return Null(AAT::ankr);
57 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
58 const AAT::ankr& ankr = *(layout->ankr.get ());
60 *blob = layout->ankr.blob;
64 static inline const AAT::kerx&
65 _get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr)
67 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
70 *blob = hb_blob_get_empty ();
71 return Null(AAT::kerx);
73 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
74 /* XXX this doesn't call set_num_glyphs on sanitizer. */
75 const AAT::kerx& kerx = *(layout->kerx.get ());
77 *blob = layout->kerx.blob;
81 static inline const AAT::morx&
82 _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr)
84 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
87 *blob = hb_blob_get_empty ();
88 return Null(AAT::morx);
90 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
91 /* XXX this doesn't call set_num_glyphs on sanitizer. */
92 const AAT::morx& morx = *(layout->morx.get ());
94 *blob = layout->morx.blob;
98 static inline const AAT::trak&
99 _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr)
101 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
104 *blob = hb_blob_get_empty ();
105 return Null(AAT::trak);
107 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
108 const AAT::trak& trak = *(layout->trak.get ());
110 *blob = layout->trak.blob;
115 // static inline void
116 // _hb_aat_layout_create (hb_face_t *face)
118 // OT::Sanitizer<AAT::morx> sanitizer;
119 // sanitizer.set_num_glyphs (face->get_num_glyphs ());
120 // hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx));
121 // morx_blob->as<AAT::morx> ();
125 // morx_blob->as<AAT::Lookup<OT::GlyphID> > ()->get_value (1, face->get_num_glyphs ());
130 hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer)
134 const AAT::morx& morx = _get_morx (font->face, &blob);
136 AAT::hb_aat_apply_context_t c (font, buffer, blob);
142 hb_aat_layout_position (hb_font_t *font, hb_buffer_t *buffer)
146 const AAT::ankr& ankr = _get_ankr (font->face, &blob);
147 const AAT::kerx& kerx = _get_kerx (font->face, &blob);
148 const AAT::trak& trak = _get_trak (font->face, &blob);
150 AAT::hb_aat_apply_context_t c (font, buffer, blob);
151 kerx.apply (&c, &ankr);