2012-08-08 04:41:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2011,2012 Google, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
2019-06-26 22:21:03 +02:00
|
|
|
#include "hb.hh"
|
|
|
|
|
|
|
|
#ifndef HB_NO_OT_SHAPE
|
|
|
|
|
2018-08-26 07:36:36 +02:00
|
|
|
#include "hb-ot-shape-fallback.hh"
|
2018-11-07 19:35:06 +01:00
|
|
|
#include "hb-kern.hh"
|
2012-08-08 04:41:38 +02:00
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
static unsigned int
|
2012-09-02 01:20:41 +02:00
|
|
|
recategorize_combining_class (hb_codepoint_t u,
|
2012-09-02 02:06:26 +02:00
|
|
|
unsigned int klass)
|
2012-08-08 07:20:45 +02:00
|
|
|
{
|
2012-09-02 02:06:26 +02:00
|
|
|
if (klass >= 200)
|
|
|
|
return klass;
|
2012-08-08 07:20:45 +02:00
|
|
|
|
2012-09-02 02:06:26 +02:00
|
|
|
/* Thai / Lao need some per-character work. */
|
2014-07-11 20:54:42 +02:00
|
|
|
if ((u & ~0xFF) == 0x0E00u)
|
2012-09-02 02:06:26 +02:00
|
|
|
{
|
|
|
|
if (unlikely (klass == 0))
|
|
|
|
{
|
|
|
|
switch (u)
|
|
|
|
{
|
2014-07-11 20:54:42 +02:00
|
|
|
case 0x0E31u:
|
|
|
|
case 0x0E34u:
|
|
|
|
case 0x0E35u:
|
|
|
|
case 0x0E36u:
|
|
|
|
case 0x0E37u:
|
|
|
|
case 0x0E47u:
|
|
|
|
case 0x0E4Cu:
|
|
|
|
case 0x0E4Du:
|
|
|
|
case 0x0E4Eu:
|
2012-09-02 02:06:26 +02:00
|
|
|
klass = HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
|
|
|
|
break;
|
|
|
|
|
2014-07-11 20:54:42 +02:00
|
|
|
case 0x0EB1u:
|
|
|
|
case 0x0EB4u:
|
|
|
|
case 0x0EB5u:
|
|
|
|
case 0x0EB6u:
|
|
|
|
case 0x0EB7u:
|
|
|
|
case 0x0EBBu:
|
|
|
|
case 0x0ECCu:
|
|
|
|
case 0x0ECDu:
|
2012-09-02 02:06:26 +02:00
|
|
|
klass = HB_UNICODE_COMBINING_CLASS_ABOVE;
|
|
|
|
break;
|
|
|
|
|
2014-07-11 20:54:42 +02:00
|
|
|
case 0x0EBCu:
|
2012-09-02 02:06:26 +02:00
|
|
|
klass = HB_UNICODE_COMBINING_CLASS_BELOW;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Thai virama is below-right */
|
2014-07-11 20:54:42 +02:00
|
|
|
if (u == 0x0E3Au)
|
2012-09-02 02:06:26 +02:00
|
|
|
klass = HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (klass)
|
2012-08-08 07:20:45 +02:00
|
|
|
{
|
2012-08-10 03:12:30 +02:00
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
/* Hebrew */
|
2012-08-10 03:12:30 +02:00
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC10: /* sheva */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC11: /* hataf segol */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC12: /* hataf patah */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC13: /* hataf qamats */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC14: /* hiriq */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC15: /* tsere */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC16: /* segol */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC17: /* patah */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC18: /* qamats */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC20: /* qubuts */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC22: /* meteg */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_BELOW;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC23: /* rafe */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC24: /* shin dot */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC25: /* sin dot */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC19: /* holam */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC26: /* point varika */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_ABOVE;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC21: /* dagesh */
|
|
|
|
break;
|
|
|
|
|
2012-08-10 03:12:30 +02:00
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
/* Arabic and Syriac */
|
2012-08-10 03:12:30 +02:00
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC27: /* fathatan */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC28: /* dammatan */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC30: /* fatha */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC31: /* damma */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC33: /* shadda */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC34: /* sukun */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC35: /* superscript alef */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC36: /* superscript alaph */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_ABOVE;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC29: /* kasratan */
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC32: /* kasra */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_BELOW;
|
|
|
|
|
2012-08-10 03:12:30 +02:00
|
|
|
|
|
|
|
/* Thai */
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC103: /* sara u / sara uu */
|
2012-08-31 04:53:29 +02:00
|
|
|
return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT;
|
2012-08-10 03:12:30 +02:00
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC107: /* mai */
|
2012-08-31 04:53:29 +02:00
|
|
|
return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT;
|
2012-08-10 03:12:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Lao */
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC118: /* sign u / sign uu */
|
2012-11-14 23:09:46 +01:00
|
|
|
return HB_UNICODE_COMBINING_CLASS_BELOW;
|
2012-08-10 03:12:30 +02:00
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC122: /* mai */
|
2012-11-14 23:09:46 +01:00
|
|
|
return HB_UNICODE_COMBINING_CLASS_ABOVE;
|
2012-08-10 03:12:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Tibetan */
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC129: /* sign aa */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_BELOW;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC130: /* sign i*/
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_ABOVE;
|
|
|
|
|
|
|
|
case HB_MODIFIED_COMBINING_CLASS_CCC132: /* sign u */
|
|
|
|
return HB_UNICODE_COMBINING_CLASS_BELOW;
|
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
}
|
|
|
|
|
2012-09-02 02:06:26 +02:00
|
|
|
return klass;
|
2012-08-08 07:20:45 +02:00
|
|
|
}
|
|
|
|
|
2012-09-02 01:20:41 +02:00
|
|
|
void
|
2018-10-09 05:30:24 +02:00
|
|
|
_hb_ot_shape_fallback_mark_position_recategorize_marks (const hb_ot_shape_plan_t *plan HB_UNUSED,
|
|
|
|
hb_font_t *font HB_UNUSED,
|
|
|
|
hb_buffer_t *buffer)
|
2012-09-02 01:20:41 +02:00
|
|
|
{
|
2019-05-11 08:15:58 +02:00
|
|
|
#ifdef HB_NO_OT_SHAPE_FALLBACK
|
2019-04-12 16:12:11 +02:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2012-09-02 01:20:41 +02:00
|
|
|
unsigned int count = buffer->len;
|
2014-07-17 20:22:11 +02:00
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2012-09-02 01:20:41 +02:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2014-07-17 20:22:11 +02:00
|
|
|
if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) {
|
|
|
|
unsigned int combining_class = _hb_glyph_info_get_modified_combining_class (&info[i]);
|
|
|
|
combining_class = recategorize_combining_class (info[i].codepoint, combining_class);
|
|
|
|
_hb_glyph_info_set_modified_combining_class (&info[i], combining_class);
|
2012-09-02 01:20:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
zero_mark_advances (hb_buffer_t *buffer,
|
|
|
|
unsigned int start,
|
2019-01-24 12:08:23 +01:00
|
|
|
unsigned int end,
|
|
|
|
bool adjust_offsets_when_zeroing)
|
2012-09-02 01:20:41 +02:00
|
|
|
{
|
2014-07-17 20:22:11 +02:00
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2012-09-02 01:20:41 +02:00
|
|
|
for (unsigned int i = start; i < end; i++)
|
2014-07-17 20:22:11 +02:00
|
|
|
if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
|
2012-09-02 01:20:41 +02:00
|
|
|
{
|
2019-01-24 12:08:23 +01:00
|
|
|
if (adjust_offsets_when_zeroing)
|
|
|
|
{
|
|
|
|
buffer->pos[i].x_offset -= buffer->pos[i].x_advance;
|
|
|
|
buffer->pos[i].y_offset -= buffer->pos[i].y_advance;
|
|
|
|
}
|
2012-09-02 01:20:41 +02:00
|
|
|
buffer->pos[i].x_advance = 0;
|
|
|
|
buffer->pos[i].y_advance = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
static inline void
|
2018-10-27 06:01:11 +02:00
|
|
|
position_mark (const hb_ot_shape_plan_t *plan HB_UNUSED,
|
2012-08-08 07:20:45 +02:00
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
hb_glyph_extents_t &base_extents,
|
|
|
|
unsigned int i,
|
|
|
|
unsigned int combining_class)
|
|
|
|
{
|
|
|
|
hb_glyph_extents_t mark_extents;
|
2018-02-09 00:14:52 +01:00
|
|
|
if (!font->get_glyph_extents (buffer->info[i].codepoint, &mark_extents))
|
2012-08-08 07:20:45 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
hb_position_t y_gap = font->y_scale / 16;
|
|
|
|
|
|
|
|
hb_glyph_position_t &pos = buffer->pos[i];
|
|
|
|
pos.x_offset = pos.y_offset = 0;
|
|
|
|
|
|
|
|
|
2017-11-03 14:05:00 +01:00
|
|
|
/* We don't position LEFT and RIGHT marks. */
|
2012-08-08 07:20:45 +02:00
|
|
|
|
|
|
|
/* X positioning */
|
|
|
|
switch (combining_class)
|
|
|
|
{
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
|
2012-08-10 22:38:44 +02:00
|
|
|
if (buffer->props.direction == HB_DIRECTION_LTR) {
|
2017-11-21 04:43:22 +01:00
|
|
|
pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width / 2 - mark_extents.x_bearing;
|
2012-08-10 22:38:44 +02:00
|
|
|
break;
|
|
|
|
} else if (buffer->props.direction == HB_DIRECTION_RTL) {
|
2017-11-21 04:43:22 +01:00
|
|
|
pos.x_offset += base_extents.x_bearing - mark_extents.width / 2 - mark_extents.x_bearing;
|
2012-08-10 22:38:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-10-21 15:04:28 +02:00
|
|
|
HB_FALLTHROUGH;
|
2012-08-08 07:20:45 +02:00
|
|
|
|
2012-08-27 22:28:05 +02:00
|
|
|
default:
|
2012-08-08 07:20:45 +02:00
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_BELOW:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ABOVE:
|
|
|
|
/* Center align. */
|
|
|
|
pos.x_offset += base_extents.x_bearing + (base_extents.width - mark_extents.width) / 2 - mark_extents.x_bearing;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
|
|
|
|
/* Left align. */
|
|
|
|
pos.x_offset += base_extents.x_bearing - mark_extents.x_bearing;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
|
|
|
|
/* Right align. */
|
|
|
|
pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width - mark_extents.x_bearing;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Y positioning */
|
|
|
|
switch (combining_class)
|
|
|
|
{
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_BELOW:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT:
|
|
|
|
/* Add gap, fall-through. */
|
|
|
|
base_extents.height -= y_gap;
|
2015-10-21 15:04:28 +02:00
|
|
|
HB_FALLTHROUGH;
|
2012-08-08 07:20:45 +02:00
|
|
|
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW:
|
2013-10-18 15:50:29 +02:00
|
|
|
pos.y_offset = base_extents.y_bearing + base_extents.height - mark_extents.y_bearing;
|
2013-10-18 16:08:53 +02:00
|
|
|
/* Never shift up "below" marks. */
|
2013-10-18 15:57:36 +02:00
|
|
|
if ((y_gap > 0) == (pos.y_offset > 0))
|
|
|
|
{
|
|
|
|
base_extents.height -= pos.y_offset;
|
|
|
|
pos.y_offset = 0;
|
|
|
|
}
|
2012-08-08 07:20:45 +02:00
|
|
|
base_extents.height += mark_extents.height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ABOVE:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT:
|
|
|
|
/* Add gap, fall-through. */
|
|
|
|
base_extents.y_bearing += y_gap;
|
|
|
|
base_extents.height -= y_gap;
|
2015-10-21 15:04:28 +02:00
|
|
|
HB_FALLTHROUGH;
|
2012-08-08 07:20:45 +02:00
|
|
|
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE:
|
|
|
|
case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT:
|
2013-10-18 15:50:29 +02:00
|
|
|
pos.y_offset = base_extents.y_bearing - (mark_extents.y_bearing + mark_extents.height);
|
2013-10-18 16:08:53 +02:00
|
|
|
/* Don't shift down "above" marks too much. */
|
|
|
|
if ((y_gap > 0) != (pos.y_offset > 0))
|
|
|
|
{
|
|
|
|
unsigned int correction = -pos.y_offset / 2;
|
|
|
|
base_extents.y_bearing += correction;
|
|
|
|
base_extents.height -= correction;
|
|
|
|
pos.y_offset += correction;
|
|
|
|
}
|
2012-08-08 07:20:45 +02:00
|
|
|
base_extents.y_bearing -= mark_extents.height;
|
|
|
|
base_extents.height += mark_extents.height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
position_around_base (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
unsigned int base,
|
2019-01-24 12:08:23 +01:00
|
|
|
unsigned int end,
|
|
|
|
bool adjust_offsets_when_zeroing)
|
2012-08-08 07:20:45 +02:00
|
|
|
{
|
2012-09-06 23:22:31 +02:00
|
|
|
hb_direction_t horiz_dir = HB_DIRECTION_INVALID;
|
2017-08-11 05:16:15 +02:00
|
|
|
|
|
|
|
buffer->unsafe_to_break (base, end);
|
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
hb_glyph_extents_t base_extents;
|
2012-08-08 23:44:19 +02:00
|
|
|
if (!font->get_glyph_extents (buffer->info[base].codepoint,
|
|
|
|
&base_extents))
|
2012-08-08 07:20:45 +02:00
|
|
|
{
|
|
|
|
/* If extents don't work, zero marks and go home. */
|
2019-01-24 12:08:23 +01:00
|
|
|
zero_mark_advances (buffer, base + 1, end, adjust_offsets_when_zeroing);
|
2012-08-08 07:20:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
base_extents.y_bearing += buffer->pos[base].y_offset;
|
2019-01-24 12:08:23 +01:00
|
|
|
/* Use horizontal advance for horizontal positioning.
|
|
|
|
* Generally a better idea. Also works for zero-ink glyphs. See:
|
|
|
|
* https://github.com/harfbuzz/harfbuzz/issues/1532 */
|
|
|
|
base_extents.x_bearing = 0;
|
|
|
|
base_extents.width = font->get_glyph_h_advance (buffer->info[base].codepoint);
|
2012-08-08 07:20:45 +02:00
|
|
|
|
2013-10-18 00:02:43 +02:00
|
|
|
unsigned int lig_id = _hb_glyph_info_get_lig_id (&buffer->info[base]);
|
2018-02-09 00:14:52 +01:00
|
|
|
/* Use integer for num_lig_components such that it doesn't convert to unsigned
|
|
|
|
* when we divide or multiply by it. */
|
|
|
|
int num_lig_components = _hb_glyph_info_get_lig_num_comps (&buffer->info[base]);
|
2012-08-08 07:20:45 +02:00
|
|
|
|
|
|
|
hb_position_t x_offset = 0, y_offset = 0;
|
2012-08-10 22:34:04 +02:00
|
|
|
if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
|
|
|
|
x_offset -= buffer->pos[base].x_advance;
|
|
|
|
y_offset -= buffer->pos[base].y_advance;
|
|
|
|
}
|
2012-09-06 23:22:31 +02:00
|
|
|
|
|
|
|
hb_glyph_extents_t component_extents = base_extents;
|
2018-02-09 00:14:52 +01:00
|
|
|
int last_lig_component = -1;
|
2012-08-08 07:20:45 +02:00
|
|
|
unsigned int last_combining_class = 255;
|
2012-11-05 01:48:45 +01:00
|
|
|
hb_glyph_extents_t cluster_extents = base_extents; /* Initialization is just to shut gcc up. */
|
2014-07-17 20:22:11 +02:00
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2012-08-08 07:20:45 +02:00
|
|
|
for (unsigned int i = base + 1; i < end; i++)
|
2014-07-17 20:22:11 +02:00
|
|
|
if (_hb_glyph_info_get_modified_combining_class (&info[i]))
|
2012-08-08 07:20:45 +02:00
|
|
|
{
|
2012-09-06 23:22:31 +02:00
|
|
|
if (num_lig_components > 1) {
|
2014-07-17 20:22:11 +02:00
|
|
|
unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&info[i]);
|
2018-02-09 00:14:52 +01:00
|
|
|
int this_lig_component = _hb_glyph_info_get_lig_comp (&info[i]) - 1;
|
2012-09-06 23:22:31 +02:00
|
|
|
/* Conditions for attaching to the last component. */
|
|
|
|
if (!lig_id || lig_id != this_lig_id || this_lig_component >= num_lig_components)
|
|
|
|
this_lig_component = num_lig_components - 1;
|
|
|
|
if (last_lig_component != this_lig_component)
|
|
|
|
{
|
|
|
|
last_lig_component = this_lig_component;
|
|
|
|
last_combining_class = 255;
|
|
|
|
component_extents = base_extents;
|
|
|
|
if (unlikely (horiz_dir == HB_DIRECTION_INVALID)) {
|
|
|
|
if (HB_DIRECTION_IS_HORIZONTAL (plan->props.direction))
|
|
|
|
horiz_dir = plan->props.direction;
|
|
|
|
else
|
|
|
|
horiz_dir = hb_script_get_horizontal_direction (plan->props.script);
|
|
|
|
}
|
|
|
|
if (horiz_dir == HB_DIRECTION_LTR)
|
|
|
|
component_extents.x_bearing += (this_lig_component * component_extents.width) / num_lig_components;
|
|
|
|
else
|
|
|
|
component_extents.x_bearing += ((num_lig_components - 1 - this_lig_component) * component_extents.width) / num_lig_components;
|
|
|
|
component_extents.width /= num_lig_components;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 20:22:11 +02:00
|
|
|
unsigned int this_combining_class = _hb_glyph_info_get_modified_combining_class (&info[i]);
|
2012-09-06 23:22:31 +02:00
|
|
|
if (last_combining_class != this_combining_class)
|
|
|
|
{
|
|
|
|
last_combining_class = this_combining_class;
|
|
|
|
cluster_extents = component_extents;
|
|
|
|
}
|
2012-08-08 07:20:45 +02:00
|
|
|
|
2012-08-27 23:00:44 +02:00
|
|
|
position_mark (plan, font, buffer, cluster_extents, i, this_combining_class);
|
2012-08-08 07:20:45 +02:00
|
|
|
|
|
|
|
buffer->pos[i].x_advance = 0;
|
|
|
|
buffer->pos[i].y_advance = 0;
|
|
|
|
buffer->pos[i].x_offset += x_offset;
|
|
|
|
buffer->pos[i].y_offset += y_offset;
|
|
|
|
|
|
|
|
} else {
|
2012-08-10 22:34:04 +02:00
|
|
|
if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
|
|
|
|
x_offset -= buffer->pos[i].x_advance;
|
|
|
|
y_offset -= buffer->pos[i].y_advance;
|
|
|
|
} else {
|
|
|
|
x_offset += buffer->pos[i].x_advance;
|
|
|
|
y_offset += buffer->pos[i].y_advance;
|
|
|
|
}
|
2012-08-08 07:20:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
position_cluster (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
unsigned int start,
|
2019-01-24 12:08:23 +01:00
|
|
|
unsigned int end,
|
|
|
|
bool adjust_offsets_when_zeroing)
|
2012-08-08 07:20:45 +02:00
|
|
|
{
|
|
|
|
if (end - start < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Find the base glyph */
|
2014-07-17 20:22:11 +02:00
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2012-08-08 07:20:45 +02:00
|
|
|
for (unsigned int i = start; i < end; i++)
|
2014-07-17 20:22:11 +02:00
|
|
|
if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])))
|
2012-08-08 07:20:45 +02:00
|
|
|
{
|
2012-09-06 22:02:07 +02:00
|
|
|
/* Find mark glyphs */
|
|
|
|
unsigned int j;
|
|
|
|
for (j = i + 1; j < end; j++)
|
2014-07-17 20:22:11 +02:00
|
|
|
if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[j])))
|
2012-09-06 22:02:07 +02:00
|
|
|
break;
|
|
|
|
|
2019-01-24 12:08:23 +01:00
|
|
|
position_around_base (plan, font, buffer, i, j, adjust_offsets_when_zeroing);
|
2012-09-06 22:02:07 +02:00
|
|
|
|
|
|
|
i = j - 1;
|
2012-08-08 07:20:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-08 04:41:38 +02:00
|
|
|
void
|
2018-10-09 05:30:24 +02:00
|
|
|
_hb_ot_shape_fallback_mark_position (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
2019-01-24 12:08:23 +01:00
|
|
|
hb_buffer_t *buffer,
|
|
|
|
bool adjust_offsets_when_zeroing)
|
2012-08-08 04:41:38 +02:00
|
|
|
{
|
2019-05-11 08:15:58 +02:00
|
|
|
#ifdef HB_NO_OT_SHAPE_FALLBACK
|
2019-04-12 16:12:11 +02:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2014-08-02 23:18:46 +02:00
|
|
|
_hb_buffer_assert_gsubgpos_vars (buffer);
|
|
|
|
|
2012-08-08 07:20:45 +02:00
|
|
|
unsigned int start = 0;
|
|
|
|
unsigned int count = buffer->len;
|
2015-08-07 18:51:28 +02:00
|
|
|
hb_glyph_info_t *info = buffer->info;
|
2012-08-08 07:20:45 +02:00
|
|
|
for (unsigned int i = 1; i < count; i++)
|
2015-08-07 18:51:28 +02:00
|
|
|
if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])))) {
|
2019-01-24 12:08:23 +01:00
|
|
|
position_cluster (plan, font, buffer, start, i, adjust_offsets_when_zeroing);
|
2012-08-08 07:20:45 +02:00
|
|
|
start = i;
|
|
|
|
}
|
2019-01-24 12:08:23 +01:00
|
|
|
position_cluster (plan, font, buffer, start, count, adjust_offsets_when_zeroing);
|
2012-08-08 04:41:38 +02:00
|
|
|
}
|
2013-02-21 21:23:39 +01:00
|
|
|
|
|
|
|
|
2019-05-11 09:37:01 +02:00
|
|
|
#ifndef HB_DISABLE_DEPRECATED
|
2018-10-09 14:20:10 +02:00
|
|
|
struct hb_ot_shape_fallback_kern_driver_t
|
|
|
|
{
|
|
|
|
hb_ot_shape_fallback_kern_driver_t (hb_font_t *font_,
|
|
|
|
hb_buffer_t *buffer) :
|
|
|
|
font (font_), direction (buffer->props.direction) {}
|
|
|
|
|
|
|
|
hb_position_t get_kerning (hb_codepoint_t first, hb_codepoint_t second) const
|
|
|
|
{
|
|
|
|
hb_position_t kern = 0;
|
|
|
|
font->get_glyph_kerning_for_direction (first, second,
|
|
|
|
direction,
|
|
|
|
&kern, &kern);
|
|
|
|
return kern;
|
|
|
|
}
|
|
|
|
|
|
|
|
hb_font_t *font;
|
|
|
|
hb_direction_t direction;
|
|
|
|
};
|
2019-05-11 09:37:01 +02:00
|
|
|
#endif
|
2018-10-09 14:20:10 +02:00
|
|
|
|
2018-10-09 05:09:48 +02:00
|
|
|
/* Performs font-assisted kerning. */
|
2013-02-21 21:23:39 +01:00
|
|
|
void
|
|
|
|
_hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan,
|
|
|
|
hb_font_t *font,
|
2018-10-09 05:57:45 +02:00
|
|
|
hb_buffer_t *buffer)
|
2013-02-21 21:23:39 +01:00
|
|
|
{
|
2019-05-11 08:15:58 +02:00
|
|
|
#ifdef HB_NO_OT_SHAPE_FALLBACK
|
2019-04-12 16:12:11 +02:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2019-05-11 09:37:01 +02:00
|
|
|
#ifndef HB_DISABLE_DEPRECATED
|
2018-10-10 16:18:39 +02:00
|
|
|
if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction) ?
|
|
|
|
!font->has_glyph_h_kerning_func () :
|
|
|
|
!font->has_glyph_v_kerning_func ())
|
2018-10-10 16:04:05 +02:00
|
|
|
return;
|
2018-11-07 19:58:41 +01:00
|
|
|
|
|
|
|
bool reverse = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
buffer->reverse ();
|
|
|
|
|
2018-10-09 14:20:10 +02:00
|
|
|
hb_ot_shape_fallback_kern_driver_t driver (font, buffer);
|
2018-11-07 16:25:25 +01:00
|
|
|
OT::hb_kern_machine_t<hb_ot_shape_fallback_kern_driver_t> machine (driver);
|
2018-10-16 22:24:29 +02:00
|
|
|
machine.kern (font, buffer, plan->kern_mask, false);
|
2018-11-07 19:58:41 +01:00
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
buffer->reverse ();
|
2019-05-11 09:37:01 +02:00
|
|
|
#endif
|
2013-02-21 21:23:39 +01:00
|
|
|
}
|
2015-11-05 02:27:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Adjusts width of various spaces. */
|
|
|
|
void
|
2018-10-27 06:01:11 +02:00
|
|
|
_hb_ot_shape_fallback_spaces (const hb_ot_shape_plan_t *plan HB_UNUSED,
|
2015-11-05 02:27:07 +01:00
|
|
|
hb_font_t *font,
|
|
|
|
hb_buffer_t *buffer)
|
|
|
|
{
|
|
|
|
hb_glyph_info_t *info = buffer->info;
|
|
|
|
hb_glyph_position_t *pos = buffer->pos;
|
2018-11-01 02:21:48 +01:00
|
|
|
bool horizontal = HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction);
|
2015-11-05 02:27:07 +01:00
|
|
|
unsigned int count = buffer->len;
|
|
|
|
for (unsigned int i = 0; i < count; i++)
|
|
|
|
if (_hb_glyph_info_is_unicode_space (&info[i]) && !_hb_glyph_info_ligated (&info[i]))
|
|
|
|
{
|
|
|
|
hb_unicode_funcs_t::space_t space_type = _hb_glyph_info_get_unicode_space_fallback_type (&info[i]);
|
|
|
|
hb_codepoint_t glyph;
|
|
|
|
typedef hb_unicode_funcs_t t;
|
|
|
|
switch (space_type)
|
|
|
|
{
|
|
|
|
case t::NOT_SPACE: /* Shouldn't happen. */
|
|
|
|
case t::SPACE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case t::SPACE_EM:
|
|
|
|
case t::SPACE_EM_2:
|
|
|
|
case t::SPACE_EM_3:
|
|
|
|
case t::SPACE_EM_4:
|
|
|
|
case t::SPACE_EM_5:
|
|
|
|
case t::SPACE_EM_6:
|
|
|
|
case t::SPACE_EM_16:
|
2018-11-01 02:21:48 +01:00
|
|
|
if (horizontal)
|
2018-11-17 00:04:41 +01:00
|
|
|
pos[i].x_advance = +(font->x_scale + ((int) space_type)/2) / (int) space_type;
|
2018-11-01 02:21:48 +01:00
|
|
|
else
|
2018-11-17 00:04:41 +01:00
|
|
|
pos[i].y_advance = -(font->y_scale + ((int) space_type)/2) / (int) space_type;
|
2015-11-05 02:27:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case t::SPACE_4_EM_18:
|
2018-11-01 02:21:48 +01:00
|
|
|
if (horizontal)
|
2018-11-17 00:04:41 +01:00
|
|
|
pos[i].x_advance = (int64_t) +font->x_scale * 4 / 18;
|
2018-11-01 02:21:48 +01:00
|
|
|
else
|
2018-11-17 00:04:41 +01:00
|
|
|
pos[i].y_advance = (int64_t) -font->y_scale * 4 / 18;
|
2015-11-05 02:27:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case t::SPACE_FIGURE:
|
|
|
|
for (char u = '0'; u <= '9'; u++)
|
2016-02-24 11:05:23 +01:00
|
|
|
if (font->get_nominal_glyph (u, &glyph))
|
2015-11-05 02:27:07 +01:00
|
|
|
{
|
2018-11-01 02:21:48 +01:00
|
|
|
if (horizontal)
|
|
|
|
pos[i].x_advance = font->get_glyph_h_advance (glyph);
|
|
|
|
else
|
|
|
|
pos[i].y_advance = font->get_glyph_v_advance (glyph);
|
2015-11-05 02:27:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case t::SPACE_PUNCTUATION:
|
2018-11-01 02:21:48 +01:00
|
|
|
if (font->get_nominal_glyph ('.', &glyph) ||
|
|
|
|
font->get_nominal_glyph (',', &glyph))
|
|
|
|
{
|
|
|
|
if (horizontal)
|
|
|
|
pos[i].x_advance = font->get_glyph_h_advance (glyph);
|
|
|
|
else
|
|
|
|
pos[i].y_advance = font->get_glyph_v_advance (glyph);
|
|
|
|
}
|
2015-11-05 02:27:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case t::SPACE_NARROW:
|
|
|
|
/* Half-space?
|
2018-04-12 11:10:45 +02:00
|
|
|
* Unicode doc https://unicode.org/charts/PDF/U2000.pdf says ~1/4 or 1/5 of EM.
|
2015-11-05 02:27:07 +01:00
|
|
|
* However, in my testing, many fonts have their regular space being about that
|
|
|
|
* size. To me, a percentage of the space width makes more sense. Half is as
|
|
|
|
* good as any. */
|
2018-11-01 02:21:48 +01:00
|
|
|
if (horizontal)
|
|
|
|
pos[i].x_advance /= 2;
|
|
|
|
else
|
|
|
|
pos[i].y_advance /= 2;
|
2015-11-05 02:27:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 22:21:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|