Behdad Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 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" |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 28 | |
Behdad Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 29 | #include "hb-ot-layout-private.hh" |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 30 | #include "hb-ot-layout-gsubgpos-private.hh" |
Behdad Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 31 | |
Behdad Esfahbod | a0175e7 | 2017-08-17 16:55:54 -0700 | [diff] [blame] | 32 | #include "hb-aat-layout-private.hh" |
Ebrahim Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 33 | #include "hb-aat-layout-ankr-table.hh" |
Ebrahim Byagowi | a64eacd | 2018-02-19 23:27:08 +0330 | [diff] [blame] | 34 | #include "hb-aat-layout-kerx-table.hh" |
Ebrahim Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 35 | #include "hb-aat-layout-morx-table.hh" |
Ebrahim Byagowi | a64eacd | 2018-02-19 23:27:08 +0330 | [diff] [blame] | 36 | #include "hb-aat-layout-trak-table.hh" |
Ebrahim Byagowi | aa53cb5 | 2018-03-26 13:28:26 +0430 | [diff] [blame] | 37 | #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 Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 39 | |
| 40 | /* |
Ebrahim Byagowi | bb82f01 | 2018-02-25 12:30:33 +0330 | [diff] [blame] | 41 | * morx/kerx/trak |
Behdad Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 42 | */ |
| 43 | |
Ebrahim Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 44 | static inline const AAT::ankr& |
| 45 | _get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr) |
Behdad Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 46 | { |
Behdad Esfahbod | e6263c7 | 2018-01-15 15:37:55 -0500 | [diff] [blame] | 47 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) |
| 48 | { |
Behdad Esfahbod | f07ce66 | 2018-01-19 16:52:01 -0800 | [diff] [blame] | 49 | if (blob) |
| 50 | *blob = hb_blob_get_empty (); |
Ebrahim Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 51 | return OT::Null(AAT::ankr); |
Behdad Esfahbod | e6263c7 | 2018-01-15 15:37:55 -0500 | [diff] [blame] | 52 | } |
Behdad Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 53 | hb_ot_layout_t * layout = hb_ot_layout_from_face (face); |
Ebrahim Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 54 | const AAT::ankr& ankr = *(layout->ankr.get ()); |
Behdad Esfahbod | f07ce66 | 2018-01-19 16:52:01 -0800 | [diff] [blame] | 55 | if (blob) |
Ebrahim Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 56 | *blob = layout->ankr.blob; |
| 57 | return ankr; |
Behdad Esfahbod | c71b55a | 2017-08-14 17:24:36 -0700 | [diff] [blame] | 58 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 59 | |
Ebrahim Byagowi | 1ab16f4 | 2018-02-24 12:49:42 +0330 | [diff] [blame] | 60 | static 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 Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 77 | static 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 Byagowi | 1ab16f4 | 2018-02-24 12:49:42 +0330 | [diff] [blame] | 94 | static 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 Byagowi | 1ab16f4 | 2018-02-24 12:49:42 +0330 | [diff] [blame] | 104 | const AAT::trak& trak = *(layout->trak.get ()); |
| 105 | if (blob) |
| 106 | *blob = layout->trak.blob; |
| 107 | return trak; |
| 108 | } |
| 109 | |
Ebrahim Byagowi | cd28eb9 | 2018-02-24 14:17:54 +0330 | [diff] [blame] | 110 | // 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 Byagowi | 158f281 | 2018-03-26 12:04:30 +0430 | [diff] [blame] | 115 | // hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx)); |
Ebrahim Byagowi | cd28eb9 | 2018-02-24 14:17:54 +0330 | [diff] [blame] | 116 | // OT::Sanitizer<AAT::morx>::lock_instance (morx_blob); |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 117 | |
Ebrahim Byagowi | cd28eb9 | 2018-02-24 14:17:54 +0330 | [diff] [blame] | 118 | // if (0) |
| 119 | // { |
| 120 | // OT::Sanitizer<AAT::Lookup<OT::GlyphID> >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ()); |
| 121 | // } |
| 122 | // } |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 123 | |
| 124 | void |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 125 | hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 126 | { |
Behdad Esfahbod | f07ce66 | 2018-01-19 16:52:01 -0800 | [diff] [blame] | 127 | hb_blob_t *blob; |
| 128 | const AAT::morx& morx = _get_morx (font->face, &blob); |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 129 | |
Behdad Esfahbod | f07ce66 | 2018-01-19 16:52:01 -0800 | [diff] [blame] | 130 | AAT::hb_aat_apply_context_t c (font, buffer, blob); |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 131 | morx.apply (&c); |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 132 | } |
Ebrahim Byagowi | 1ab16f4 | 2018-02-24 12:49:42 +0330 | [diff] [blame] | 133 | |
| 134 | void |
| 135 | hb_aat_layout_position (hb_font_t *font, hb_buffer_t *buffer) |
| 136 | { |
| 137 | hb_blob_t *blob; |
Ebrahim Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 138 | const AAT::ankr& ankr = _get_ankr (font->face, &blob); |
Ebrahim Byagowi | 1ab16f4 | 2018-02-24 12:49:42 +0330 | [diff] [blame] | 139 | 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 Byagowi | ae14dd0 | 2018-02-26 00:31:09 +0330 | [diff] [blame] | 143 | kerx.apply (&c, &ankr); |
Ebrahim Byagowi | 1ab16f4 | 2018-02-24 12:49:42 +0330 | [diff] [blame] | 144 | trak.apply (&c); |
| 145 | } |