2011-07-08 04:35:17 +02:00
|
|
|
/*
|
2012-08-12 00:34:13 +02:00
|
|
|
* Copyright © 2010,2012 Google, Inc.
|
2011-07-08 04:35:17 +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.
|
|
|
|
*
|
|
|
|
* Google Author(s): Behdad Esfahbod
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hb-ot-shape-complex-private.hh"
|
|
|
|
|
|
|
|
|
2012-04-10 16:52:07 +02:00
|
|
|
/* Thai / Lao shaper */
|
|
|
|
|
2012-07-31 03:08:51 +02:00
|
|
|
static void
|
2012-08-12 00:34:13 +02:00
|
|
|
preprocess_text_thai (const hb_ot_shape_plan_t *plan HB_UNUSED,
|
|
|
|
hb_buffer_t *buffer,
|
|
|
|
hb_font_t *font HB_UNUSED)
|
2012-04-10 16:52:07 +02:00
|
|
|
{
|
|
|
|
/* The following is NOT specified in the MS OT Thai spec, however, it seems
|
|
|
|
* to be what Uniscribe and other engines implement. According to Eric Muller:
|
|
|
|
*
|
2012-07-23 19:15:33 +02:00
|
|
|
* When you have a SARA AM, decompose it in NIKHAHIT + SARA AA, *and* move the
|
|
|
|
* NIKHAHIT backwards over any tone mark (0E48-0E4B).
|
2012-04-10 16:52:07 +02:00
|
|
|
*
|
|
|
|
* <0E14, 0E4B, 0E33> -> <0E14, 0E4D, 0E4B, 0E32>
|
|
|
|
*
|
2012-07-23 19:15:33 +02:00
|
|
|
* This reordering is legit only when the NIKHAHIT comes from a SARA AM, not
|
2012-04-10 16:52:07 +02:00
|
|
|
* when it's there to start with. The string <0E14, 0E4B, 0E4D> is probably
|
2012-07-23 19:15:33 +02:00
|
|
|
* not what a user wanted, but the rendering is nevertheless nikhahit above
|
2012-04-10 16:52:07 +02:00
|
|
|
* chattawa.
|
|
|
|
*
|
|
|
|
* Same for Lao.
|
2012-07-23 19:52:07 +02:00
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
*
|
2012-11-15 00:51:54 +01:00
|
|
|
* Uniscribe also does some below-marks reordering. Namely, it positions U+0E3A
|
2012-07-23 19:52:07 +02:00
|
|
|
* after U+0E38 and U+0E39. We do that by modifying the ccc for U+0E3A.
|
2012-08-01 23:13:10 +02:00
|
|
|
* See unicode->modified_combining_class (). Lao does NOT have a U+0E3A
|
2012-07-23 19:52:07 +02:00
|
|
|
* equivalent.
|
2012-04-10 16:52:07 +02:00
|
|
|
*/
|
|
|
|
|
2012-07-23 19:15:33 +02:00
|
|
|
|
2012-04-10 16:52:07 +02:00
|
|
|
/*
|
|
|
|
* Here are the characters of significance:
|
|
|
|
*
|
|
|
|
* Thai Lao
|
|
|
|
* SARA AM: U+0E33 U+0EB3
|
|
|
|
* SARA AA: U+0E32 U+0EB2
|
|
|
|
* Nikhahit: U+0E4D U+0ECD
|
|
|
|
*
|
2012-07-23 19:15:33 +02:00
|
|
|
* Testing shows that Uniscribe reorder the following marks:
|
2012-07-23 20:04:42 +02:00
|
|
|
* Thai: <0E31,0E34..0E37,0E47..0E4E>
|
|
|
|
* Lao: <0EB1,0EB4..0EB7,0EC7..0ECE>
|
2012-04-10 16:52:07 +02:00
|
|
|
*
|
|
|
|
* Note how the Lao versions are the same as Thai + 0x80.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* We only get one script at a time, so a script-agnostic implementation
|
|
|
|
* is adequate here. */
|
|
|
|
#define IS_SARA_AM(x) (((x) & ~0x0080) == 0x0E33)
|
|
|
|
#define NIKHAHIT_FROM_SARA_AM(x) ((x) - 0xE33 + 0xE4D)
|
|
|
|
#define SARA_AA_FROM_SARA_AM(x) ((x) - 1)
|
2012-07-23 20:04:42 +02:00
|
|
|
#define IS_TONE_MARK(x) (hb_in_ranges<hb_codepoint_t> ((x) & ~0x0080, 0x0E34, 0x0E37, 0x0E47, 0x0E4E, 0x0E31, 0x0E31))
|
2012-04-10 16:52:07 +02:00
|
|
|
|
|
|
|
buffer->clear_output ();
|
|
|
|
unsigned int count = buffer->len;
|
|
|
|
for (buffer->idx = 0; buffer->idx < count;)
|
|
|
|
{
|
2012-05-13 15:45:18 +02:00
|
|
|
hb_codepoint_t u = buffer->cur().codepoint;
|
2012-04-11 20:19:55 +02:00
|
|
|
if (likely (!IS_SARA_AM (u))) {
|
2012-04-10 16:52:07 +02:00
|
|
|
buffer->next_glyph ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is SARA AM. Decompose and reorder. */
|
2012-04-24 04:18:54 +02:00
|
|
|
hb_codepoint_t decomposed[2] = {hb_codepoint_t (NIKHAHIT_FROM_SARA_AM (u)),
|
|
|
|
hb_codepoint_t (SARA_AA_FROM_SARA_AM (u))};
|
2012-04-10 16:52:07 +02:00
|
|
|
buffer->replace_glyphs (1, 2, decomposed);
|
2012-04-10 23:20:05 +02:00
|
|
|
if (unlikely (buffer->in_error))
|
2012-04-10 16:52:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Ok, let's see... */
|
|
|
|
unsigned int end = buffer->out_len;
|
|
|
|
unsigned int start = end - 2;
|
|
|
|
while (start > 0 && IS_TONE_MARK (buffer->out_info[start - 1].codepoint))
|
|
|
|
start--;
|
|
|
|
|
2012-07-23 19:15:33 +02:00
|
|
|
if (start + 2 < end)
|
|
|
|
{
|
|
|
|
/* Move Nikhahit (end-2) to the beginning */
|
|
|
|
buffer->merge_out_clusters (start, end);
|
|
|
|
hb_glyph_info_t t = buffer->out_info[end - 2];
|
|
|
|
memmove (buffer->out_info + start + 1,
|
|
|
|
buffer->out_info + start,
|
|
|
|
sizeof (buffer->out_info[0]) * (end - start - 2));
|
|
|
|
buffer->out_info[start] = t;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Since we decomposed, and NIKHAHIT is combining, merge clusters with the
|
|
|
|
* previous cluster. */
|
|
|
|
if (start)
|
|
|
|
buffer->merge_out_clusters (start - 1, end);
|
|
|
|
}
|
2012-04-10 16:52:07 +02:00
|
|
|
}
|
|
|
|
buffer->swap_buffers ();
|
|
|
|
}
|
2012-07-31 03:08:51 +02:00
|
|
|
|
|
|
|
const hb_ot_complex_shaper_t _hb_ot_complex_shaper_thai =
|
|
|
|
{
|
|
|
|
"thai",
|
|
|
|
NULL, /* collect_features */
|
|
|
|
NULL, /* override_features */
|
2012-08-02 16:46:34 +02:00
|
|
|
NULL, /* data_create */
|
|
|
|
NULL, /* data_destroy */
|
2012-08-12 00:34:13 +02:00
|
|
|
preprocess_text_thai,
|
2012-07-31 03:08:51 +02:00
|
|
|
NULL, /* normalization_preference */
|
2012-11-13 21:35:35 +01:00
|
|
|
NULL, /* decompose */
|
|
|
|
NULL, /* compose */
|
2012-08-12 00:34:13 +02:00
|
|
|
NULL, /* setup_masks */
|
2012-08-01 05:41:06 +02:00
|
|
|
true, /* zero_width_attached_marks */
|
2012-11-14 22:48:26 +01:00
|
|
|
false,/* fallback_position */
|
2012-07-31 03:08:51 +02:00
|
|
|
};
|