blob: a9b4328d65a416a7f6e97ee3b89cac829ff81b41 [file] [log] [blame]
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -07001/*
2 * Copyright © 2017 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
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.
11 *
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
16 * DAMAGE.
17 *
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.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
27#include "hb-open-type-private.hh"
Behdad Esfahbod748b9892018-01-09 17:55:17 +010028
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -070029#include "hb-ot-layout-private.hh"
Behdad Esfahbod748b9892018-01-09 17:55:17 +010030#include "hb-ot-layout-gsubgpos-private.hh"
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -070031
Behdad Esfahboda0175e72017-08-17 16:55:54 -070032#include "hb-aat-layout-private.hh"
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +033033#include "hb-aat-layout-ankr-table.hh"
Ebrahim Byagowia64eacd2018-02-19 23:27:08 +033034#include "hb-aat-layout-kerx-table.hh"
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +033035#include "hb-aat-layout-morx-table.hh"
Ebrahim Byagowia64eacd2018-02-19 23:27:08 +033036#include "hb-aat-layout-trak-table.hh"
Ebrahim Byagowiaa53cb52018-03-26 13:28:26 +043037#include "hb-aat-fmtx-table.hh" // Just so we compile it; unused otherwise
38#include "hb-aat-ltag-table.hh" // Just so we compile it; unused otherwise.
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -070039
40/*
Ebrahim Byagowibb82f012018-02-25 12:30:33 +033041 * morx/kerx/trak
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -070042 */
43
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +033044static inline const AAT::ankr&
45_get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr)
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -070046{
Behdad Esfahbode6263c72018-01-15 15:37:55 -050047 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
48 {
Behdad Esfahbodf07ce662018-01-19 16:52:01 -080049 if (blob)
50 *blob = hb_blob_get_empty ();
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +033051 return OT::Null(AAT::ankr);
Behdad Esfahbode6263c72018-01-15 15:37:55 -050052 }
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -070053 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +033054 const AAT::ankr& ankr = *(layout->ankr.get ());
Behdad Esfahbodf07ce662018-01-19 16:52:01 -080055 if (blob)
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +033056 *blob = layout->ankr.blob;
57 return ankr;
Behdad Esfahbodc71b55a2017-08-14 17:24:36 -070058}
Behdad Esfahbod470fe5b2018-01-09 15:48:51 +010059
Ebrahim Byagowi1ab16f42018-02-24 12:49:42 +033060static inline const AAT::kerx&
61_get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr)
62{
63 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
64 {
65 if (blob)
66 *blob = hb_blob_get_empty ();
67 return OT::Null(AAT::kerx);
68 }
69 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
70 /* XXX this doesn't call set_num_glyphs on sanitizer. */
71 const AAT::kerx& kerx = *(layout->kerx.get ());
72 if (blob)
73 *blob = layout->kerx.blob;
74 return kerx;
75}
76
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +033077static inline const AAT::morx&
78_get_morx (hb_face_t *face, hb_blob_t **blob = nullptr)
79{
80 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
81 {
82 if (blob)
83 *blob = hb_blob_get_empty ();
84 return OT::Null(AAT::morx);
85 }
86 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
87 /* XXX this doesn't call set_num_glyphs on sanitizer. */
88 const AAT::morx& morx = *(layout->morx.get ());
89 if (blob)
90 *blob = layout->morx.blob;
91 return morx;
92}
93
Ebrahim Byagowi1ab16f42018-02-24 12:49:42 +033094static inline const AAT::trak&
95_get_trak (hb_face_t *face, hb_blob_t **blob = nullptr)
96{
97 if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
98 {
99 if (blob)
100 *blob = hb_blob_get_empty ();
101 return OT::Null(AAT::trak);
102 }
103 hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
Ebrahim Byagowi1ab16f42018-02-24 12:49:42 +0330104 const AAT::trak& trak = *(layout->trak.get ());
105 if (blob)
106 *blob = layout->trak.blob;
107 return trak;
108}
109
Ebrahim Byagowicd28eb92018-02-24 14:17:54 +0330110// static inline void
111// _hb_aat_layout_create (hb_face_t *face)
112// {
113// OT::Sanitizer<AAT::morx> sanitizer;
114// sanitizer.set_num_glyphs (face->get_num_glyphs ());
Ebrahim Byagowi158f2812018-03-26 12:04:30 +0430115// hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx));
Ebrahim Byagowicd28eb92018-02-24 14:17:54 +0330116// OT::Sanitizer<AAT::morx>::lock_instance (morx_blob);
Behdad Esfahbod470fe5b2018-01-09 15:48:51 +0100117
Ebrahim Byagowicd28eb92018-02-24 14:17:54 +0330118// if (0)
119// {
120// OT::Sanitizer<AAT::Lookup<OT::GlyphID> >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ());
121// }
122// }
Behdad Esfahbod748b9892018-01-09 17:55:17 +0100123
124void
Behdad Esfahbod046690a2018-01-17 16:59:55 -0800125hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer)
Behdad Esfahbod748b9892018-01-09 17:55:17 +0100126{
Behdad Esfahbodf07ce662018-01-19 16:52:01 -0800127 hb_blob_t *blob;
128 const AAT::morx& morx = _get_morx (font->face, &blob);
Behdad Esfahbod046690a2018-01-17 16:59:55 -0800129
Behdad Esfahbodf07ce662018-01-19 16:52:01 -0800130 AAT::hb_aat_apply_context_t c (font, buffer, blob);
Behdad Esfahbod046690a2018-01-17 16:59:55 -0800131 morx.apply (&c);
Behdad Esfahbod748b9892018-01-09 17:55:17 +0100132}
Ebrahim Byagowi1ab16f42018-02-24 12:49:42 +0330133
134void
135hb_aat_layout_position (hb_font_t *font, hb_buffer_t *buffer)
136{
137 hb_blob_t *blob;
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +0330138 const AAT::ankr& ankr = _get_ankr (font->face, &blob);
Ebrahim Byagowi1ab16f42018-02-24 12:49:42 +0330139 const AAT::kerx& kerx = _get_kerx (font->face, &blob);
140 const AAT::trak& trak = _get_trak (font->face, &blob);
141
142 AAT::hb_aat_apply_context_t c (font, buffer, blob);
Ebrahim Byagowiae14dd02018-02-26 00:31:09 +0330143 kerx.apply (&c, &ankr);
Ebrahim Byagowi1ab16f42018-02-24 12:49:42 +0330144 trak.apply (&c);
145}