Imported Upstream version 1.7.6
[platform/upstream/harfbuzz.git] / src / hb-aat-layout.cc
1 /*
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"
28
29 #include "hb-ot-layout-private.hh"
30 #include "hb-ot-layout-gsubgpos-private.hh"
31
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"
37
38 /*
39  * morx/kerx/trak
40  */
41
42 static inline const AAT::ankr&
43 _get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr)
44 {
45   if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
46   {
47     if (blob)
48       *blob = hb_blob_get_empty ();
49     return OT::Null(AAT::ankr);
50   }
51   hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
52   const AAT::ankr& ankr = *(layout->ankr.get ());
53   if (blob)
54     *blob = layout->ankr.blob;
55   return ankr;
56 }
57
58 static inline const AAT::kerx&
59 _get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr)
60 {
61   if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
62   {
63     if (blob)
64       *blob = hb_blob_get_empty ();
65     return OT::Null(AAT::kerx);
66   }
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 ());
70   if (blob)
71     *blob = layout->kerx.blob;
72   return kerx;
73 }
74
75 static inline const AAT::morx&
76 _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr)
77 {
78   if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
79   {
80     if (blob)
81       *blob = hb_blob_get_empty ();
82     return OT::Null(AAT::morx);
83   }
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 ());
87   if (blob)
88     *blob = layout->morx.blob;
89   return morx;
90 }
91
92 static inline const AAT::trak&
93 _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr)
94 {
95   if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
96   {
97     if (blob)
98       *blob = hb_blob_get_empty ();
99     return OT::Null(AAT::trak);
100   }
101   hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
102   const AAT::trak& trak = *(layout->trak.get ());
103   if (blob)
104     *blob = layout->trak.blob;
105   return trak;
106 }
107
108 // static inline void
109 // _hb_aat_layout_create (hb_face_t *face)
110 // {
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);
115
116 //   if (0)
117 //   {
118 //     OT::Sanitizer<AAT::Lookup<OT::GlyphID> >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ());
119 //   }
120 // }
121
122 void
123 hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer)
124 {
125   hb_blob_t *blob;
126   const AAT::morx& morx = _get_morx (font->face, &blob);
127
128   AAT::hb_aat_apply_context_t c (font, buffer, blob);
129   morx.apply (&c);
130 }
131
132 void
133 hb_aat_layout_position (hb_font_t *font, hb_buffer_t *buffer)
134 {
135   hb_blob_t *blob;
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);
139
140   AAT::hb_aat_apply_context_t c (font, buffer, blob);
141   kerx.apply (&c, &ankr);
142   trak.apply (&c);
143 }