2011-08-24 01:29:25 +02:00
|
|
|
/*
|
2011-08-24 03:22:49 +02:00
|
|
|
* Copyright © 2011 Martin Hosken
|
|
|
|
* Copyright © 2011 SIL International
|
2012-08-07 04:25:39 +02:00
|
|
|
* Copyright © 2011,2012 Google, Inc.
|
2011-08-24 01:29:25 +02:00
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
2011-08-24 03:22:49 +02:00
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
2011-08-24 01:29:25 +02:00
|
|
|
*/
|
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
#define HB_SHAPER graphite2
|
|
|
|
#include "hb-shaper-impl-private.hh"
|
|
|
|
|
2011-08-24 01:47:25 +02:00
|
|
|
#include "hb-graphite2.h"
|
|
|
|
|
2013-09-14 02:36:43 +02:00
|
|
|
#include <graphite2/Segment.h>
|
|
|
|
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2017-02-04 01:43:25 +01:00
|
|
|
HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, face)
|
|
|
|
HB_SHAPER_DATA_ENSURE_DEFINE(graphite2, font)
|
2011-08-24 01:29:25 +02:00
|
|
|
|
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
/*
|
|
|
|
* shaper face data
|
|
|
|
*/
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
typedef struct hb_graphite2_tablelist_t {
|
|
|
|
struct hb_graphite2_tablelist_t *next;
|
2012-08-07 20:11:16 +02:00
|
|
|
hb_blob_t *blob;
|
2011-08-24 03:22:49 +02:00
|
|
|
unsigned int tag;
|
2012-08-07 04:25:39 +02:00
|
|
|
} hb_graphite2_tablelist_t;
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
struct hb_graphite2_shaper_face_data_t {
|
|
|
|
hb_face_t *face;
|
2011-08-24 03:22:49 +02:00
|
|
|
gr_face *grface;
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_graphite2_tablelist_t *tlist;
|
|
|
|
};
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2012-08-07 20:11:16 +02:00
|
|
|
static const void *hb_graphite2_get_table (const void *data, unsigned int tag, size_t *len)
|
2011-08-24 01:29:25 +02:00
|
|
|
{
|
2012-08-07 20:11:16 +02:00
|
|
|
hb_graphite2_shaper_face_data_t *face_data = (hb_graphite2_shaper_face_data_t *) data;
|
|
|
|
hb_graphite2_tablelist_t *tlist = face_data->tlist;
|
|
|
|
|
|
|
|
hb_blob_t *blob = NULL;
|
|
|
|
|
|
|
|
for (hb_graphite2_tablelist_t *p = tlist; p; p = p->next)
|
|
|
|
if (p->tag == tag) {
|
|
|
|
blob = p->blob;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely (!blob))
|
2011-08-24 03:22:49 +02:00
|
|
|
{
|
2012-08-08 23:44:19 +02:00
|
|
|
blob = face_data->face->reference_table (tag);
|
2012-08-07 20:11:16 +02:00
|
|
|
|
|
|
|
hb_graphite2_tablelist_t *p = (hb_graphite2_tablelist_t *) calloc (1, sizeof (hb_graphite2_tablelist_t));
|
|
|
|
if (unlikely (!p)) {
|
2011-08-26 09:33:06 +02:00
|
|
|
hb_blob_destroy (blob);
|
2011-08-24 03:22:49 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-08-07 20:11:16 +02:00
|
|
|
p->blob = blob;
|
|
|
|
p->tag = tag;
|
|
|
|
|
|
|
|
/* TODO Not thread-safe, but fairly harmless.
|
|
|
|
* We can do the double-chcked pointer cmpexch thing here. */
|
|
|
|
p->next = face_data->tlist;
|
|
|
|
face_data->tlist = p;
|
2011-08-24 03:22:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int tlen;
|
|
|
|
const char *d = hb_blob_get_data (blob, &tlen);
|
|
|
|
*len = tlen;
|
|
|
|
return d;
|
2011-08-24 01:29:25 +02:00
|
|
|
}
|
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_graphite2_shaper_face_data_t *
|
|
|
|
_hb_graphite2_shaper_face_data_create (hb_face_t *face)
|
2011-08-24 01:29:25 +02:00
|
|
|
{
|
2012-08-08 23:44:19 +02:00
|
|
|
hb_blob_t *silf_blob = face->reference_table (HB_GRAPHITE2_TAG_SILF);
|
2012-08-07 04:42:47 +02:00
|
|
|
/* Umm, we just reference the table to check whether it exists.
|
|
|
|
* Maybe add better API for this? */
|
2012-08-07 04:25:39 +02:00
|
|
|
if (!hb_blob_get_length (silf_blob))
|
|
|
|
{
|
|
|
|
hb_blob_destroy (silf_blob);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-08-07 04:42:47 +02:00
|
|
|
hb_blob_destroy (silf_blob);
|
|
|
|
|
|
|
|
hb_graphite2_shaper_face_data_t *data = (hb_graphite2_shaper_face_data_t *) calloc (1, sizeof (hb_graphite2_shaper_face_data_t));
|
|
|
|
if (unlikely (!data))
|
2014-01-28 17:16:01 +01:00
|
|
|
return NULL;
|
2012-08-07 04:25:39 +02:00
|
|
|
|
|
|
|
data->face = face;
|
2012-12-10 00:43:03 +01:00
|
|
|
data->grface = gr_make_face (data, &hb_graphite2_get_table, gr_face_preloadAll);
|
2012-08-07 04:25:39 +02:00
|
|
|
|
2012-08-07 04:42:47 +02:00
|
|
|
if (unlikely (!data->grface)) {
|
|
|
|
free (data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
return data;
|
2011-08-24 01:29:25 +02:00
|
|
|
}
|
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
void
|
|
|
|
_hb_graphite2_shaper_face_data_destroy (hb_graphite2_shaper_face_data_t *data)
|
2011-08-24 01:29:25 +02:00
|
|
|
{
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_graphite2_tablelist_t *tlist = data->tlist;
|
|
|
|
|
2011-08-24 03:22:49 +02:00
|
|
|
while (tlist)
|
|
|
|
{
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_graphite2_tablelist_t *old = tlist;
|
2011-08-24 03:22:49 +02:00
|
|
|
hb_blob_destroy (tlist->blob);
|
|
|
|
tlist = tlist->next;
|
2011-08-26 09:33:06 +02:00
|
|
|
free (old);
|
2011-08-24 03:22:49 +02:00
|
|
|
}
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
gr_face_destroy (data->grface);
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
free (data);
|
2011-08-24 01:29:25 +02:00
|
|
|
}
|
|
|
|
|
2015-09-03 13:23:22 +02:00
|
|
|
/*
|
|
|
|
* Since: 0.9.10
|
|
|
|
*/
|
2012-12-10 00:44:41 +01:00
|
|
|
gr_face *
|
|
|
|
hb_graphite2_face_get_gr_face (hb_face_t *face)
|
|
|
|
{
|
|
|
|
if (unlikely (!hb_graphite2_shaper_face_data_ensure (face))) return NULL;
|
|
|
|
return HB_SHAPER_DATA_GET (face)->grface;
|
|
|
|
}
|
|
|
|
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
/*
|
|
|
|
* shaper font data
|
|
|
|
*/
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2016-11-11 01:16:39 +01:00
|
|
|
struct hb_graphite2_shaper_font_data_t {};
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_graphite2_shaper_font_data_t *
|
2016-11-11 01:16:39 +01:00
|
|
|
_hb_graphite2_shaper_font_data_create (hb_font_t *font HB_UNUSED)
|
2012-08-07 04:25:39 +02:00
|
|
|
{
|
2016-11-11 01:16:39 +01:00
|
|
|
return (hb_graphite2_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
|
2011-08-24 01:29:25 +02:00
|
|
|
}
|
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
void
|
2016-11-11 01:16:39 +01:00
|
|
|
_hb_graphite2_shaper_font_data_destroy (hb_graphite2_shaper_font_data_t *data HB_UNUSED)
|
2011-08-24 01:29:25 +02:00
|
|
|
{
|
2012-08-07 04:25:39 +02:00
|
|
|
}
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2015-09-03 13:23:22 +02:00
|
|
|
/*
|
|
|
|
* Since: 0.9.10
|
|
|
|
*/
|
2012-12-10 00:44:41 +01:00
|
|
|
gr_font *
|
|
|
|
hb_graphite2_font_get_gr_font (hb_font_t *font)
|
|
|
|
{
|
2016-11-11 01:16:39 +01:00
|
|
|
return NULL;
|
2012-12-10 00:44:41 +01:00
|
|
|
}
|
|
|
|
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
/*
|
|
|
|
* shaper shape_plan data
|
|
|
|
*/
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
struct hb_graphite2_shaper_shape_plan_data_t {};
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_graphite2_shaper_shape_plan_data_t *
|
2012-08-14 15:33:18 +02:00
|
|
|
_hb_graphite2_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
|
|
|
|
const hb_feature_t *user_features HB_UNUSED,
|
2016-09-10 12:57:24 +02:00
|
|
|
unsigned int num_user_features HB_UNUSED,
|
|
|
|
const int *coords HB_UNUSED,
|
|
|
|
unsigned int num_coords HB_UNUSED)
|
2012-08-07 04:25:39 +02:00
|
|
|
{
|
|
|
|
return (hb_graphite2_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
|
|
|
|
}
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
void
|
2012-08-14 15:33:18 +02:00
|
|
|
_hb_graphite2_shaper_shape_plan_data_destroy (hb_graphite2_shaper_shape_plan_data_t *data HB_UNUSED)
|
2012-08-07 04:25:39 +02:00
|
|
|
{
|
|
|
|
}
|
2011-08-24 03:22:49 +02:00
|
|
|
|
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
/*
|
|
|
|
* shaper
|
|
|
|
*/
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2012-08-07 04:25:39 +02:00
|
|
|
struct hb_graphite2_cluster_t {
|
|
|
|
unsigned int base_char;
|
|
|
|
unsigned int num_chars;
|
|
|
|
unsigned int base_glyph;
|
|
|
|
unsigned int num_glyphs;
|
2014-05-30 23:38:14 +02:00
|
|
|
unsigned int cluster;
|
2016-01-17 00:24:00 +01:00
|
|
|
float advance;
|
2012-08-07 04:25:39 +02:00
|
|
|
};
|
2011-08-24 01:29:25 +02:00
|
|
|
|
2011-08-24 03:22:49 +02:00
|
|
|
hb_bool_t
|
2012-08-07 04:25:39 +02:00
|
|
|
_hb_graphite2_shape (hb_shape_plan_t *shape_plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
const hb_feature_t *features,
|
|
|
|
unsigned int num_features)
|
2011-08-24 01:29:25 +02:00
|
|
|
{
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_face_t *face = font->face;
|
|
|
|
gr_face *grface = HB_SHAPER_DATA_GET (face)->grface;
|
2011-08-24 03:22:49 +02:00
|
|
|
|
|
|
|
const char *lang = hb_language_to_string (hb_buffer_get_language (buffer));
|
2013-04-02 20:08:53 +02:00
|
|
|
const char *lang_end = lang ? strchr (lang, '-') : NULL;
|
2011-08-26 09:25:04 +02:00
|
|
|
int lang_len = lang_end ? lang_end - lang : -1;
|
2012-08-07 04:25:39 +02:00
|
|
|
gr_feature_val *feats = gr_face_featureval_for_lang (grface, lang ? hb_tag_from_string (lang, lang_len) : 0);
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2015-07-22 15:28:25 +02:00
|
|
|
for (unsigned int i = 0; i < num_features; i++)
|
2011-08-24 03:22:49 +02:00
|
|
|
{
|
2015-07-22 15:28:25 +02:00
|
|
|
const gr_feature_ref *fref = gr_face_find_fref (grface, features[i].tag);
|
2011-08-24 03:22:49 +02:00
|
|
|
if (fref)
|
2015-07-22 15:28:25 +02:00
|
|
|
gr_fref_set_feature_value (fref, features[i].value, feats);
|
2011-08-24 03:22:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gr_segment *seg = NULL;
|
|
|
|
const gr_slot *is;
|
|
|
|
unsigned int ci = 0, ic = 0;
|
|
|
|
float curradvx = 0., curradvy = 0.;
|
|
|
|
|
2012-08-24 06:41:51 +02:00
|
|
|
unsigned int scratch_size;
|
2013-11-13 20:44:01 +01:00
|
|
|
hb_buffer_t::scratch_buffer_t *scratch = buffer->get_scratch_buffer (&scratch_size);
|
2012-08-24 06:41:51 +02:00
|
|
|
|
2013-11-12 23:22:49 +01:00
|
|
|
uint32_t *chars = (uint32_t *) scratch;
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-24 06:41:51 +02:00
|
|
|
for (unsigned int i = 0; i < buffer->len; ++i)
|
|
|
|
chars[i] = buffer->info[i].codepoint;
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2015-07-22 15:28:25 +02:00
|
|
|
/* TODO ensure_native_direction. */
|
|
|
|
|
2011-08-24 03:22:49 +02:00
|
|
|
hb_tag_t script_tag[2];
|
2011-08-26 09:33:06 +02:00
|
|
|
hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script_tag[1]);
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2016-10-30 19:16:41 +01:00
|
|
|
seg = gr_make_seg (NULL, grface,
|
2011-08-24 03:22:49 +02:00
|
|
|
script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1],
|
|
|
|
feats,
|
2012-08-24 06:41:51 +02:00
|
|
|
gr_utf32, chars, buffer->len,
|
2011-08-26 09:33:06 +02:00
|
|
|
2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ? 1 : 0));
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-24 06:41:51 +02:00
|
|
|
if (unlikely (!seg)) {
|
|
|
|
if (feats) gr_featureval_destroy (feats);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int glyph_count = gr_seg_n_slots (seg);
|
|
|
|
if (unlikely (!glyph_count)) {
|
|
|
|
if (feats) gr_featureval_destroy (feats);
|
|
|
|
gr_seg_destroy (seg);
|
2015-07-22 15:28:25 +02:00
|
|
|
buffer->len = 0;
|
|
|
|
return true;
|
2012-08-24 06:41:51 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 15:28:25 +02:00
|
|
|
buffer->ensure (glyph_count);
|
2013-11-12 23:22:49 +01:00
|
|
|
scratch = buffer->get_scratch_buffer (&scratch_size);
|
|
|
|
while ((DIV_CEIL (sizeof (hb_graphite2_cluster_t) * buffer->len, sizeof (*scratch)) +
|
|
|
|
DIV_CEIL (sizeof (hb_codepoint_t) * glyph_count, sizeof (*scratch))) > scratch_size)
|
2012-08-24 06:41:51 +02:00
|
|
|
{
|
2014-08-11 19:42:42 +02:00
|
|
|
if (unlikely (!buffer->ensure (buffer->allocated * 2)))
|
|
|
|
{
|
2012-08-24 06:41:51 +02:00
|
|
|
if (feats) gr_featureval_destroy (feats);
|
|
|
|
gr_seg_destroy (seg);
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-12 23:22:49 +01:00
|
|
|
scratch = buffer->get_scratch_buffer (&scratch_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ALLOCATE_ARRAY(Type, name, len) \
|
|
|
|
Type *name = (Type *) scratch; \
|
|
|
|
{ \
|
|
|
|
unsigned int _consumed = DIV_CEIL ((len) * sizeof (Type), sizeof (*scratch)); \
|
|
|
|
assert (_consumed <= scratch_size); \
|
|
|
|
scratch += _consumed; \
|
|
|
|
scratch_size -= _consumed; \
|
2012-08-24 06:41:51 +02:00
|
|
|
}
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2012-08-24 06:41:51 +02:00
|
|
|
ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len);
|
|
|
|
ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count);
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2013-11-12 23:22:49 +01:00
|
|
|
#undef ALLOCATE_ARRAY
|
|
|
|
|
2012-08-24 06:41:51 +02:00
|
|
|
memset (clusters, 0, sizeof (clusters[0]) * buffer->len);
|
|
|
|
|
|
|
|
hb_codepoint_t *pg = gids;
|
2014-05-30 23:38:14 +02:00
|
|
|
clusters[0].cluster = buffer->info[0].cluster;
|
2017-04-20 20:13:22 +02:00
|
|
|
float curradv = 0.;
|
2016-01-17 00:24:00 +01:00
|
|
|
if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
|
|
|
|
{
|
|
|
|
curradv = gr_slot_origin_X(gr_seg_first_slot(seg));
|
|
|
|
clusters[0].advance = gr_seg_advance_X(seg) - curradv;
|
|
|
|
}
|
2011-08-24 03:22:49 +02:00
|
|
|
for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (is), ic++)
|
|
|
|
{
|
|
|
|
unsigned int before = gr_slot_before (is);
|
|
|
|
unsigned int after = gr_slot_after (is);
|
|
|
|
*pg = gr_slot_gid (is);
|
|
|
|
pg++;
|
|
|
|
while (clusters[ci].base_char > before && ci)
|
2011-08-24 01:29:25 +02:00
|
|
|
{
|
2011-08-24 03:22:49 +02:00
|
|
|
clusters[ci-1].num_chars += clusters[ci].num_chars;
|
|
|
|
clusters[ci-1].num_glyphs += clusters[ci].num_glyphs;
|
2016-01-17 00:24:00 +01:00
|
|
|
clusters[ci-1].advance += clusters[ci].advance;
|
2011-08-26 09:27:13 +02:00
|
|
|
ci--;
|
2011-08-24 01:29:25 +02:00
|
|
|
}
|
|
|
|
|
2011-08-24 03:22:49 +02:00
|
|
|
if (gr_slot_can_insert_before (is) && clusters[ci].num_chars && before >= clusters[ci].base_char + clusters[ci].num_chars)
|
2011-08-24 01:29:25 +02:00
|
|
|
{
|
2012-08-07 04:25:39 +02:00
|
|
|
hb_graphite2_cluster_t *c = clusters + ci + 1;
|
2011-08-24 03:22:49 +02:00
|
|
|
c->base_char = clusters[ci].base_char + clusters[ci].num_chars;
|
2014-05-30 23:38:14 +02:00
|
|
|
c->cluster = buffer->info[c->base_char].cluster;
|
2011-08-24 03:22:49 +02:00
|
|
|
c->num_chars = before - c->base_char;
|
|
|
|
c->base_glyph = ic;
|
|
|
|
c->num_glyphs = 0;
|
2016-01-17 00:24:00 +01:00
|
|
|
if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
|
2017-04-20 20:13:22 +02:00
|
|
|
c->advance = curradv - gr_slot_origin_X(is);
|
|
|
|
else
|
2016-01-17 00:24:00 +01:00
|
|
|
clusters[ci].advance = gr_slot_origin_X(is) - curradv;
|
2017-04-20 20:13:22 +02:00
|
|
|
ci++;
|
2016-01-17 00:24:00 +01:00
|
|
|
curradv = gr_slot_origin_X(is);
|
2011-08-24 01:29:25 +02:00
|
|
|
}
|
2011-08-26 09:27:13 +02:00
|
|
|
clusters[ci].num_glyphs++;
|
2011-08-24 03:22:49 +02:00
|
|
|
|
|
|
|
if (clusters[ci].base_char + clusters[ci].num_chars < after + 1)
|
|
|
|
clusters[ci].num_chars = after + 1 - clusters[ci].base_char;
|
|
|
|
}
|
2016-01-17 00:24:00 +01:00
|
|
|
|
2017-04-20 20:13:22 +02:00
|
|
|
if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
|
|
|
|
clusters[ci].advance += curradv;
|
|
|
|
else
|
2016-01-17 00:24:00 +01:00
|
|
|
clusters[ci].advance = gr_seg_advance_X(seg) - curradv;
|
2011-08-26 09:27:13 +02:00
|
|
|
ci++;
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2011-08-26 09:27:13 +02:00
|
|
|
for (unsigned int i = 0; i < ci; ++i)
|
2012-12-10 00:45:47 +01:00
|
|
|
{
|
|
|
|
for (unsigned int j = 0; j < clusters[i].num_glyphs; ++j)
|
|
|
|
{
|
|
|
|
hb_glyph_info_t *info = &buffer->info[clusters[i].base_glyph + j];
|
|
|
|
info->codepoint = gids[clusters[i].base_glyph + j];
|
2014-05-30 23:38:14 +02:00
|
|
|
info->cluster = clusters[i].cluster;
|
2016-01-17 00:24:00 +01:00
|
|
|
info->var1.i32 = clusters[i].advance; // all glyphs in the cluster get the same advance
|
2012-12-10 00:45:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
buffer->len = glyph_count;
|
2011-08-24 03:22:49 +02:00
|
|
|
|
2016-10-30 19:16:41 +01:00
|
|
|
unsigned int upem = hb_face_get_upem (face);
|
|
|
|
float xscale = (float) font->x_scale / upem;
|
|
|
|
float yscale = (float) font->y_scale / upem;
|
|
|
|
yscale *= yscale / xscale;
|
2015-07-22 15:28:25 +02:00
|
|
|
/* Positioning. */
|
2017-04-20 20:13:22 +02:00
|
|
|
int currclus = -1;
|
|
|
|
const hb_glyph_info_t *info = buffer->info;
|
|
|
|
hb_glyph_position_t *pPos = hb_buffer_get_glyph_positions (buffer, NULL);
|
2015-07-22 15:28:25 +02:00
|
|
|
if (!HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
|
2011-08-24 03:22:49 +02:00
|
|
|
{
|
2016-01-17 00:24:00 +01:00
|
|
|
curradvx = 0;
|
|
|
|
for (is = gr_seg_first_slot (seg); is; pPos++, ++info, is = gr_slot_next_in_segment (is))
|
2015-07-22 15:28:25 +02:00
|
|
|
{
|
2016-10-30 19:16:41 +01:00
|
|
|
pPos->x_offset = gr_slot_origin_X (is) * xscale - curradvx;
|
2015-11-23 04:03:56 +01:00
|
|
|
pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy;
|
2016-01-17 00:24:00 +01:00
|
|
|
if (info->cluster != currclus) {
|
2016-10-30 19:16:41 +01:00
|
|
|
pPos->x_advance = info->var1.i32 * xscale;
|
2016-01-17 00:24:00 +01:00
|
|
|
curradvx += pPos->x_advance;
|
|
|
|
currclus = info->cluster;
|
|
|
|
} else
|
|
|
|
pPos->x_advance = 0.;
|
|
|
|
|
2016-10-30 19:16:41 +01:00
|
|
|
pPos->y_advance = gr_slot_advance_Y (is, grface, NULL) * yscale;
|
2015-07-22 15:28:25 +02:00
|
|
|
curradvy += pPos->y_advance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-20 20:13:22 +02:00
|
|
|
curradvx = gr_seg_advance_X(seg);
|
2016-01-17 00:24:00 +01:00
|
|
|
for (is = gr_seg_first_slot (seg); is; pPos++, info++, is = gr_slot_next_in_segment (is))
|
2015-07-22 15:28:25 +02:00
|
|
|
{
|
|
|
|
if (info->cluster != currclus)
|
|
|
|
{
|
2016-10-30 19:16:41 +01:00
|
|
|
pPos->x_advance = info->var1.i32 * xscale;
|
2017-04-20 20:13:22 +02:00
|
|
|
curradvx -= pPos->x_advance;
|
2015-07-22 15:28:25 +02:00
|
|
|
currclus = info->cluster;
|
2016-01-17 00:24:00 +01:00
|
|
|
} else
|
2017-04-20 20:13:22 +02:00
|
|
|
pPos->x_advance = 0.;
|
2016-01-17 00:24:00 +01:00
|
|
|
|
2016-10-30 19:16:41 +01:00
|
|
|
pPos->y_advance = gr_slot_advance_Y (is, grface, NULL) * yscale;
|
2015-07-22 15:28:25 +02:00
|
|
|
curradvy -= pPos->y_advance;
|
2017-04-20 20:13:22 +02:00
|
|
|
pPos->x_offset = (gr_slot_origin_X (is) - info->var1.i32) * xscale - curradvx + pPos->x_advance;
|
2015-11-23 04:03:56 +01:00
|
|
|
pPos->y_offset = gr_slot_origin_Y (is) * yscale - curradvy;
|
2015-07-22 15:28:25 +02:00
|
|
|
}
|
2012-08-07 04:35:04 +02:00
|
|
|
hb_buffer_reverse_clusters (buffer);
|
2015-07-22 15:28:25 +02:00
|
|
|
}
|
2011-09-20 00:51:48 +02:00
|
|
|
|
2012-08-07 04:42:47 +02:00
|
|
|
if (feats) gr_featureval_destroy (feats);
|
2012-08-24 06:41:51 +02:00
|
|
|
gr_seg_destroy (seg);
|
|
|
|
|
|
|
|
return true;
|
2011-08-24 01:29:25 +02:00
|
|
|
}
|