author | prr |
Thu, 21 Jun 2018 12:54:30 -0700 | |
changeset 50826 | f5b95be8b6e2 |
parent 50352 | 25db2c8f3cf8 |
child 54232 | 7c11a7cc7c1d |
permissions | -rw-r--r-- |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
1 |
/* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
2 |
* Copyright © 2011,2014 Google, Inc. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
3 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
4 |
* This is part of HarfBuzz, a text shaping library. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
5 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
6 |
* Permission is hereby granted, without written agreement and without |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
7 |
* license or royalty fees, to use, copy, modify, and distribute this |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
8 |
* software and its documentation for any purpose, provided that the |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
9 |
* above copyright notice and the following two paragraphs appear in |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
10 |
* all copies of this software. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
11 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
12 |
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
13 |
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
14 |
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
15 |
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
16 |
* DAMAGE. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
17 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
18 |
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
19 |
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
20 |
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
21 |
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
22 |
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
23 |
* |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
24 |
* Google Author(s): Behdad Esfahbod, Roozbeh Pournader |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
25 |
*/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
26 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
27 |
#include "hb-private.hh" |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
28 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
29 |
#include "hb-ot.h" |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
30 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
31 |
#include "hb-font-private.hh" |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
32 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
33 |
#include "hb-ot-cmap-table.hh" |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
34 |
#include "hb-ot-glyf-table.hh" |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
35 |
#include "hb-ot-hmtx-table.hh" |
48274 | 36 |
#include "hb-ot-kern-table.hh" |
37 |
#include "hb-ot-post-table.hh" |
|
43232 | 38 |
|
50352 | 39 |
#include "hb-ot-color-cbdt-table.hh" |
40435 | 40 |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
41 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
42 |
struct hb_ot_font_t |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
43 |
{ |
50352 | 44 |
OT::cmap::accelerator_t cmap; |
45 |
OT::hmtx::accelerator_t h_metrics; |
|
46 |
OT::vmtx::accelerator_t v_metrics; |
|
47 |
OT::hb_lazy_loader_t<OT::glyf::accelerator_t> glyf; |
|
48 |
OT::hb_lazy_loader_t<OT::CBDT::accelerator_t> cbdt; |
|
49 |
OT::hb_lazy_loader_t<OT::post::accelerator_t> post; |
|
50 |
OT::hb_lazy_loader_t<OT::kern::accelerator_t> kern; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
51 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
52 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
53 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
54 |
static hb_ot_font_t * |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
55 |
_hb_ot_font_create (hb_face_t *face) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
56 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
57 |
hb_ot_font_t *ot_font = (hb_ot_font_t *) calloc (1, sizeof (hb_ot_font_t)); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
58 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
59 |
if (unlikely (!ot_font)) |
48274 | 60 |
return nullptr; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
61 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
62 |
ot_font->cmap.init (face); |
50352 | 63 |
ot_font->h_metrics.init (face); |
64 |
ot_font->v_metrics.init (face, ot_font->h_metrics.ascender - ot_font->h_metrics.descender); /* TODO Can we do this lazily? */ |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
65 |
ot_font->glyf.init (face); |
43232 | 66 |
ot_font->cbdt.init (face); |
48274 | 67 |
ot_font->post.init (face); |
68 |
ot_font->kern.init (face); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
69 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
70 |
return ot_font; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
71 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
72 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
73 |
static void |
48274 | 74 |
_hb_ot_font_destroy (void *data) |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
75 |
{ |
48274 | 76 |
hb_ot_font_t *ot_font = (hb_ot_font_t *) data; |
77 |
||
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
78 |
ot_font->cmap.fini (); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
79 |
ot_font->h_metrics.fini (); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
80 |
ot_font->v_metrics.fini (); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
81 |
ot_font->glyf.fini (); |
43232 | 82 |
ot_font->cbdt.fini (); |
48274 | 83 |
ot_font->post.fini (); |
84 |
ot_font->kern.fini (); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
85 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
86 |
free (ot_font); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
87 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
88 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
89 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
90 |
static hb_bool_t |
40435 | 91 |
hb_ot_get_nominal_glyph (hb_font_t *font HB_UNUSED, |
92 |
void *font_data, |
|
93 |
hb_codepoint_t unicode, |
|
94 |
hb_codepoint_t *glyph, |
|
95 |
void *user_data HB_UNUSED) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
96 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
97 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
98 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
40435 | 99 |
return ot_font->cmap.get_nominal_glyph (unicode, glyph); |
100 |
} |
|
101 |
||
102 |
static hb_bool_t |
|
103 |
hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED, |
|
104 |
void *font_data, |
|
105 |
hb_codepoint_t unicode, |
|
106 |
hb_codepoint_t variation_selector, |
|
107 |
hb_codepoint_t *glyph, |
|
108 |
void *user_data HB_UNUSED) |
|
109 |
{ |
|
110 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
|
111 |
return ot_font->cmap.get_variation_glyph (unicode, variation_selector, glyph); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
112 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
113 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
114 |
static hb_position_t |
48274 | 115 |
hb_ot_get_glyph_h_advance (hb_font_t *font, |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
116 |
void *font_data, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
117 |
hb_codepoint_t glyph, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
118 |
void *user_data HB_UNUSED) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
119 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
120 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
48274 | 121 |
return font->em_scale_x (ot_font->h_metrics.get_advance (glyph, font)); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
122 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
123 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
124 |
static hb_position_t |
48274 | 125 |
hb_ot_get_glyph_v_advance (hb_font_t *font, |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
126 |
void *font_data, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
127 |
hb_codepoint_t glyph, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
128 |
void *user_data HB_UNUSED) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
129 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
130 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
48274 | 131 |
return font->em_scale_y (-(int) ot_font->v_metrics.get_advance (glyph, font)); |
132 |
} |
|
133 |
||
134 |
static hb_position_t |
|
135 |
hb_ot_get_glyph_h_kerning (hb_font_t *font, |
|
136 |
void *font_data, |
|
137 |
hb_codepoint_t left_glyph, |
|
138 |
hb_codepoint_t right_glyph, |
|
139 |
void *user_data HB_UNUSED) |
|
140 |
{ |
|
141 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
|
142 |
return font->em_scale_x (ot_font->kern->get_h_kerning (left_glyph, right_glyph)); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
143 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
144 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
145 |
static hb_bool_t |
50826 | 146 |
hb_ot_get_glyph_extents (hb_font_t *font, |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
147 |
void *font_data, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
148 |
hb_codepoint_t glyph, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
149 |
hb_glyph_extents_t *extents, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
150 |
void *user_data HB_UNUSED) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
151 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
152 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
40435 | 153 |
bool ret = ot_font->glyf->get_extents (glyph, extents); |
43232 | 154 |
if (!ret) |
155 |
ret = ot_font->cbdt->get_extents (glyph, extents); |
|
48274 | 156 |
// TODO Hook up side-bearings variations. |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
157 |
extents->x_bearing = font->em_scale_x (extents->x_bearing); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
158 |
extents->y_bearing = font->em_scale_y (extents->y_bearing); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
159 |
extents->width = font->em_scale_x (extents->width); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
160 |
extents->height = font->em_scale_y (extents->height); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
161 |
return ret; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
162 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
163 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
164 |
static hb_bool_t |
48274 | 165 |
hb_ot_get_glyph_name (hb_font_t *font HB_UNUSED, |
166 |
void *font_data, |
|
167 |
hb_codepoint_t glyph, |
|
168 |
char *name, unsigned int size, |
|
169 |
void *user_data HB_UNUSED) |
|
170 |
{ |
|
171 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
|
172 |
return ot_font->post->get_glyph_name (glyph, name, size); |
|
173 |
} |
|
174 |
||
175 |
static hb_bool_t |
|
176 |
hb_ot_get_glyph_from_name (hb_font_t *font HB_UNUSED, |
|
177 |
void *font_data, |
|
178 |
const char *name, int len, |
|
179 |
hb_codepoint_t *glyph, |
|
180 |
void *user_data HB_UNUSED) |
|
181 |
{ |
|
182 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
|
183 |
return ot_font->post->get_glyph_from_name (name, len, glyph); |
|
184 |
} |
|
185 |
||
186 |
static hb_bool_t |
|
50826 | 187 |
hb_ot_get_font_h_extents (hb_font_t *font, |
40435 | 188 |
void *font_data, |
189 |
hb_font_extents_t *metrics, |
|
190 |
void *user_data HB_UNUSED) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
191 |
{ |
40435 | 192 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
193 |
metrics->ascender = font->em_scale_y (ot_font->h_metrics.ascender); |
|
194 |
metrics->descender = font->em_scale_y (ot_font->h_metrics.descender); |
|
195 |
metrics->line_gap = font->em_scale_y (ot_font->h_metrics.line_gap); |
|
48274 | 196 |
// TODO Hook up variations. |
43232 | 197 |
return ot_font->h_metrics.has_font_extents; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
198 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
199 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
200 |
static hb_bool_t |
50826 | 201 |
hb_ot_get_font_v_extents (hb_font_t *font, |
40435 | 202 |
void *font_data, |
203 |
hb_font_extents_t *metrics, |
|
204 |
void *user_data HB_UNUSED) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
205 |
{ |
40435 | 206 |
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; |
207 |
metrics->ascender = font->em_scale_x (ot_font->v_metrics.ascender); |
|
208 |
metrics->descender = font->em_scale_x (ot_font->v_metrics.descender); |
|
209 |
metrics->line_gap = font->em_scale_x (ot_font->v_metrics.line_gap); |
|
48274 | 210 |
// TODO Hook up variations. |
43232 | 211 |
return ot_font->v_metrics.has_font_extents; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
212 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
213 |
|
48274 | 214 |
static hb_font_funcs_t *static_ot_funcs = nullptr; |
40435 | 215 |
|
216 |
#ifdef HB_USE_ATEXIT |
|
217 |
static |
|
218 |
void free_static_ot_funcs (void) |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
219 |
{ |
50826 | 220 |
retry: |
221 |
hb_font_funcs_t *ot_funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ot_funcs); |
|
222 |
if (!hb_atomic_ptr_cmpexch (&static_ot_funcs, ot_funcs, nullptr)) |
|
223 |
goto retry; |
|
224 |
||
225 |
hb_font_funcs_destroy (ot_funcs); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
226 |
} |
40435 | 227 |
#endif |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
228 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
229 |
static hb_font_funcs_t * |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
230 |
_hb_ot_get_font_funcs (void) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
231 |
{ |
40435 | 232 |
retry: |
233 |
hb_font_funcs_t *funcs = (hb_font_funcs_t *) hb_atomic_ptr_get (&static_ot_funcs); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
234 |
|
40435 | 235 |
if (unlikely (!funcs)) |
236 |
{ |
|
237 |
funcs = hb_font_funcs_create (); |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
238 |
|
48274 | 239 |
hb_font_funcs_set_font_h_extents_func (funcs, hb_ot_get_font_h_extents, nullptr, nullptr); |
240 |
hb_font_funcs_set_font_v_extents_func (funcs, hb_ot_get_font_v_extents, nullptr, nullptr); |
|
241 |
hb_font_funcs_set_nominal_glyph_func (funcs, hb_ot_get_nominal_glyph, nullptr, nullptr); |
|
242 |
hb_font_funcs_set_variation_glyph_func (funcs, hb_ot_get_variation_glyph, nullptr, nullptr); |
|
243 |
hb_font_funcs_set_glyph_h_advance_func (funcs, hb_ot_get_glyph_h_advance, nullptr, nullptr); |
|
244 |
hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ot_get_glyph_v_advance, nullptr, nullptr); |
|
245 |
//hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ot_get_glyph_h_origin, nullptr, nullptr); |
|
246 |
//hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ot_get_glyph_v_origin, nullptr, nullptr); |
|
247 |
hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ot_get_glyph_h_kerning, nullptr, nullptr); |
|
248 |
//hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ot_get_glyph_v_kerning, nullptr, nullptr); |
|
249 |
hb_font_funcs_set_glyph_extents_func (funcs, hb_ot_get_glyph_extents, nullptr, nullptr); |
|
50352 | 250 |
//hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ot_get_glyph_contour_point, nullptr, nullptr); |
48274 | 251 |
hb_font_funcs_set_glyph_name_func (funcs, hb_ot_get_glyph_name, nullptr, nullptr); |
252 |
hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr); |
|
40435 | 253 |
|
254 |
hb_font_funcs_make_immutable (funcs); |
|
255 |
||
48274 | 256 |
if (!hb_atomic_ptr_cmpexch (&static_ot_funcs, nullptr, funcs)) { |
40435 | 257 |
hb_font_funcs_destroy (funcs); |
258 |
goto retry; |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
259 |
} |
40435 | 260 |
|
261 |
#ifdef HB_USE_ATEXIT |
|
262 |
atexit (free_static_ot_funcs); /* First person registers atexit() callback. */ |
|
263 |
#endif |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
264 |
}; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
265 |
|
40435 | 266 |
return funcs; |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
267 |
} |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
268 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
269 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
270 |
/** |
40435 | 271 |
* hb_ot_font_set_funcs: |
272 |
* |
|
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
273 |
* Since: 0.9.28 |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
274 |
**/ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
275 |
void |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
276 |
hb_ot_font_set_funcs (hb_font_t *font) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
277 |
{ |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
278 |
hb_ot_font_t *ot_font = _hb_ot_font_create (font->face); |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
279 |
if (unlikely (!ot_font)) |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
280 |
return; |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
281 |
|
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
282 |
hb_font_set_funcs (font, |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
283 |
_hb_ot_get_font_funcs (), |
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
284 |
ot_font, |
48274 | 285 |
_hb_ot_font_destroy); |
34414
e496a8d8fc8a
8143177: Integrate harfbuzz opentype layout engine per JEP 258
prr
parents:
diff
changeset
|
286 |
} |