break.c 60.1 KB
Newer Older
Owen Taylor's avatar
Owen Taylor committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* Pango
 * break.c:
 *
 * Copyright (C) 1999 Red Hat Software
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

22
#include "config.h"
23

24
#include "pango-break.h"
25
#include "pango-script-private.h"
26
#include "pango-emoji-private.h"
27
#include "pango-attributes-private.h"
28
#include "pango-break-table.h"
29
#include "pango-impl-utils.h"
Elliot Lee's avatar
Elliot Lee committed
30
#include <string.h>
Owen Taylor's avatar
Owen Taylor committed
31

32 33
#define PARAGRAPH_SEPARATOR 0x2029
#define PARAGRAPH_SEPARATOR_STRING "\xE2\x80\xA9"
34

Havoc Pennington's avatar
Havoc Pennington committed
35 36 37 38 39 40 41 42 43
/* See http://www.unicode.org/unicode/reports/tr14/ if you hope
 * to understand the line breaking code.
 */

typedef enum
{
  BREAK_ALREADY_HANDLED,   /* didn't use the table */
  BREAK_PROHIBITED, /* no break, even if spaces intervene */
  BREAK_IF_SPACES,  /* "indirect break" (only if there are spaces) */
44
  BREAK_ALLOWED     /* "direct break" (can always break here) */
45
  /* TR 14 has two more break-opportunity classes,
46
   * "indirect break opportunity for combining marks following a space"
47
   * and "prohibited break for combining marks"
48 49
   * but we handle that inline in the code.
   */
Havoc Pennington's avatar
Havoc Pennington committed
50 51
} BreakOpportunity;

52
/* need to sync the break range to glib/gunicode.h . */
53
#define BREAK_TYPE_SAFE(btype)            \
54
	 ((btype) <= G_UNICODE_BREAK_ZERO_WIDTH_JOINER ? (btype) : G_UNICODE_BREAK_UNKNOWN)
Havoc Pennington's avatar
Havoc Pennington committed
55

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

/*
 * Hangul Conjoining Jamo handling.
 *
 * The way we implement it is just a bit different from TR14,
 * but produces the same results.
 * The same algorithm is also used in TR29 for cluster boundaries.
 *
 */


/* An enum that works as the states of the Hangul syllables system.
 **/
typedef enum
{
  JAMO_L,	/* G_UNICODE_BREAK_HANGUL_L_JAMO */
  JAMO_V,	/* G_UNICODE_BREAK_HANGUL_V_JAMO */
  JAMO_T,	/* G_UNICODE_BREAK_HANGUL_T_JAMO */
  JAMO_LV,	/* G_UNICODE_BREAK_HANGUL_LV_SYLLABLE */
  JAMO_LVT,	/* G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE */
  NO_JAMO	/* Other */
} JamoType;

/* There are Hangul syllables encoded as characters, that act like a
 * sequence of Jamos. For each character we define a JamoType
 * that the character starts with, and one that it ends with.  This
 * decomposes JAMO_LV and JAMO_LVT to simple other JAMOs.  So for
 * example, a character with LineBreak type
 * G_UNICODE_BREAK_HANGUL_LV_SYLLABLE has start=JAMO_L and end=JAMO_V.
 */
typedef struct _CharJamoProps
{
  JamoType start, end;
} CharJamoProps;

/* Map from JamoType to CharJamoProps that hold only simple
 * JamoTypes (no LV or LVT) or none.
 */
94
static const CharJamoProps HangulJamoProps[] = {
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  {JAMO_L, JAMO_L},	/* JAMO_L */
  {JAMO_V, JAMO_V},	/* JAMO_V */
  {JAMO_T, JAMO_T},	/* JAMO_T */
  {JAMO_L, JAMO_V},	/* JAMO_LV */
  {JAMO_L, JAMO_T},	/* JAMO_LVT */
  {NO_JAMO, NO_JAMO}	/* NO_JAMO */
};

/* A character forms a syllable with the previous character if and only if:
 * JamoType(this) is not NO_JAMO and:
 *
 * HangulJamoProps[JamoType(prev)].end and
 * HangulJamoProps[JamoType(this)].start are equal,
 * or the former is one less than the latter.
 */

#define IS_JAMO(btype)              \
	((btype >= G_UNICODE_BREAK_HANGUL_L_JAMO) && \
	 (btype <= G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE))
#define JAMO_TYPE(btype)      \
	(IS_JAMO(btype) ? (btype - G_UNICODE_BREAK_HANGUL_L_JAMO) : NO_JAMO)

Havoc Pennington's avatar
Havoc Pennington committed
117 118 119 120 121 122
/* Types of Japanese characters */
#define JAPANESE(wc) ((wc) >= 0x2F00 && (wc) <= 0x30FF)
#define KANJI(wc)    ((wc) >= 0x2F00 && (wc) <= 0x2FDF)
#define HIRAGANA(wc) ((wc) >= 0x3040 && (wc) <= 0x309F)
#define KATAKANA(wc) ((wc) >= 0x30A0 && (wc) <= 0x30FF)

123 124 125
#define LATIN(wc) (((wc) >= 0x0020 && (wc) <= 0x02AF) || ((wc) >= 0x1E00 && (wc) <= 0x1EFF))
#define CYRILLIC(wc) (((wc) >= 0x0400 && (wc) <= 0x052F))
#define GREEK(wc) (((wc) >= 0x0370 && (wc) <= 0x3FF) || ((wc) >= 0x1F00 && (wc) <= 0x1FFF))
126 127
#define KANA(wc) ((wc) >= 0x3040 && (wc) <= 0x30FF)
#define HANGUL(wc) ((wc) >= 0xAC00 && (wc) <= 0xD7A3)
128 129
#define EMOJI(wc) (_pango_Is_Emoji_Base_Character (wc))
#define BACKSPACE_DELETES_CHARACTER(wc) (!LATIN (wc) && !CYRILLIC (wc) && !GREEK (wc) && !KANA (wc) && !HANGUL (wc) && !EMOJI (wc))
130

131 132
/* Previously "123foo" was two words. But in UAX 29 of Unicode, 
 * we know don't break words between consecutive letters and numbers
Havoc Pennington's avatar
Havoc Pennington committed
133 134 135 136 137 138 139 140 141 142 143
 */
typedef enum
{
  WordNone,
  WordLetters,
  WordNumbers
} WordType;


/**
 * pango_default_break:
144
 * @text: text to break. Must be valid UTF-8
145
 * @length: length of text in bytes (may be -1 if @text is nul-terminated)
146
 * @analysis: (nullable): a `PangoAnalysis` structure for the @text
Havoc Pennington's avatar
Havoc Pennington committed
147
 * @attrs: logical attributes to fill in
148
 * @attrs_len: size of the array passed as @attrs
Havoc Pennington's avatar
Havoc Pennington committed
149
 *
150 151
 * This is the default break algorithm.
 *
152 153 154
 * It applies Unicode rules without language-specific
 * tailoring, therefore the @analyis argument is unused
 * and can be %NULL.
Matthias Clasen's avatar
Matthias Clasen committed
155
 *
156 157
 * See [func@Pango.tailor_break] for language-specific breaks.
 */
Havoc Pennington's avatar
Havoc Pennington committed
158 159
void
pango_default_break (const gchar   *text,
160
		     gint           length,
Behdad Esfahbod's avatar
Behdad Esfahbod committed
161
		     PangoAnalysis *analysis G_GNUC_UNUSED,
162
		     PangoLogAttr  *attrs,
Behdad Esfahbod's avatar
Behdad Esfahbod committed
163
		     int            attrs_len G_GNUC_UNUSED)
164
{
165 166 167
  /* The rationale for all this is in section 5.15 of the Unicode 3.0 book,
   * the line breaking stuff is also in TR14 on unicode.org
   */
Havoc Pennington's avatar
Havoc Pennington committed
168 169 170 171 172 173

  /* This is a default break implementation that should work for nearly all
   * languages. Language engines can override it optionally.
   */

  /* FIXME one cheesy optimization here would be to memset attrs to 0
174
   * before we start, and then never assign %FALSE to anything
Havoc Pennington's avatar
Havoc Pennington committed
175 176
   */

177
  const gchar *next;
178
  gint i;
179

Havoc Pennington's avatar
Havoc Pennington committed
180 181
  gunichar prev_wc;
  gunichar next_wc;
182 183 184

  JamoType prev_jamo;

185
  GUnicodeBreakType next_break_type;
186 187
  GUnicodeBreakType prev_break_type;
  GUnicodeBreakType prev_prev_break_type;
188

189 190 191 192 193 194
  /* See Grapheme_Cluster_Break Property Values table of UAX#29 */
  typedef enum
  {
    GB_Other,
    GB_ControlCRLF,
    GB_Extend,
195
    GB_ZWJ,
196 197 198
    GB_Prepend,
    GB_SpacingMark,
    GB_InHangulSyllable, /* Handles all of L, V, T, LV, LVT rules */
199 200 201 202
    /* Use state machine to handle emoji sequence */
    /* Rule GB12 and GB13 */
    GB_RI_Odd, /* Meets odd number of RI */
    GB_RI_Even, /* Meets even number of RI */
203 204
  } GraphemeBreakType;
  GraphemeBreakType prev_GB_type = GB_Other;
205
  gboolean met_Extended_Pictographic = FALSE;
206

207 208 209 210 211 212 213
  /* See Word_Break Property Values table of UAX#29 */
  typedef enum
  {
    WB_Other,
    WB_NewlineCRLF,
    WB_ExtendFormat,
    WB_Katakana,
214
    WB_Hebrew_Letter,
215 216 217 218 219 220
    WB_ALetter,
    WB_MidNumLet,
    WB_MidLetter,
    WB_MidNum,
    WB_Numeric,
    WB_ExtendNumLet,
221 222
    WB_RI_Odd,
    WB_RI_Even,
Peng Wu's avatar
Peng Wu committed
223
    WB_WSegSpace,
224 225 226 227
  } WordBreakType;
  WordBreakType prev_prev_WB_type = WB_Other, prev_WB_type = WB_Other;
  gint prev_WB_i = -1;

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
  /* See Sentence_Break Property Values table of UAX#29 */
  typedef enum
  {
    SB_Other,
    SB_ExtendFormat,
    SB_ParaSep,
    SB_Sp,
    SB_Lower,
    SB_Upper,
    SB_OLetter,
    SB_Numeric,
    SB_ATerm,
    SB_SContinue,
    SB_STerm,
    SB_Close,
    /* Rules SB8 and SB8a */
    SB_ATerm_Close_Sp,
    SB_STerm_Close_Sp,
  } SentenceBreakType;
  SentenceBreakType prev_prev_SB_type = SB_Other, prev_SB_type = SB_Other;
  gint prev_SB_i = -1;

250 251 252 253 254 255 256 257 258 259 260
  /* Rule LB25 with Example 7 of Customization */
  typedef enum
  {
    LB_Other,
    LB_Numeric,
    LB_Numeric_Close,
    LB_RI_Odd,
    LB_RI_Even,
  } LineBreakType;
  LineBreakType prev_LB_type = LB_Other;

Havoc Pennington's avatar
Havoc Pennington committed
261 262
  WordType current_word_type = WordNone;
  gunichar last_word_letter = 0;
263
  gunichar base_character = 0;
264

265
  gint last_sentence_start = -1;
266
  gint last_non_space = -1;
267

268 269
  gboolean almost_done = FALSE;
  gboolean done = FALSE;
Havoc Pennington's avatar
Havoc Pennington committed
270

271
  g_return_if_fail (length == 0 || text != NULL);
Havoc Pennington's avatar
Havoc Pennington committed
272
  g_return_if_fail (attrs != NULL);
273 274

  next = text;
275

Havoc Pennington's avatar
Havoc Pennington committed
276
  prev_break_type = G_UNICODE_BREAK_UNKNOWN;
277
  prev_prev_break_type = G_UNICODE_BREAK_UNKNOWN;
Havoc Pennington's avatar
Havoc Pennington committed
278
  prev_wc = 0;
279
  prev_jamo = NO_JAMO;
Havoc Pennington's avatar
Havoc Pennington committed
280

281
  if (length == 0 || *text == '\0')
282 283 284 285
    {
      next_wc = PARAGRAPH_SEPARATOR;
      almost_done = TRUE;
    }
286
  else
287
    next_wc = g_utf8_get_char (next);
Havoc Pennington's avatar
Havoc Pennington committed
288

289
  next_break_type = g_unichar_break_type (next_wc);
290
  next_break_type = BREAK_TYPE_SAFE (next_break_type);
291

292
  for (i = 0; !done ; i++)
Havoc Pennington's avatar
Havoc Pennington committed
293 294 295 296
    {
      GUnicodeType type;
      gunichar wc;
      GUnicodeBreakType break_type;
297
      GUnicodeBreakType row_break_type;
Havoc Pennington's avatar
Havoc Pennington committed
298
      BreakOpportunity break_op;
299 300
      JamoType jamo;
      gboolean makes_hangul_syllable;
Havoc Pennington's avatar
Havoc Pennington committed
301

302 303 304
      /* UAX#29 boundaries */
      gboolean is_grapheme_boundary;
      gboolean is_word_boundary;
305
      gboolean is_sentence_boundary;
306

307 308 309
      /* Emoji extended pictographics */
      gboolean is_Extended_Pictographic;

Havoc Pennington's avatar
Havoc Pennington committed
310
      wc = next_wc;
311
      break_type = next_break_type;
Havoc Pennington's avatar
Havoc Pennington committed
312

313
      if (almost_done)
314 315 316 317 318 319
	{
	  /*
	   * If we have already reached the end of @text g_utf8_next_char()
	   * may not increment next
	   */
	  next_wc = 0;
320
	  next_break_type = G_UNICODE_BREAK_UNKNOWN;
321
	  done = TRUE;
322
	}
Havoc Pennington's avatar
Havoc Pennington committed
323
      else
324 325
	{
	  next = g_utf8_next_char (next);
326

327
	  if ((length >= 0 && next >= text + length) || *next == '\0')
328 329 330
	    {
	      /* This is how we fill in the last element (end position) of the
	       * attr array - assume there's a paragraph separators off the end
331
	       * of @text.
332
	       */
333
	      next_wc = PARAGRAPH_SEPARATOR;
334
	      almost_done = TRUE;
335 336
	    }
	  else
337
	    next_wc = g_utf8_get_char (next);
338

339
	  next_break_type = g_unichar_break_type (next_wc);
340 341
	  next_break_type = BREAK_TYPE_SAFE (next_break_type);
	}
Havoc Pennington's avatar
Havoc Pennington committed
342 343

      type = g_unichar_type (wc);
344 345 346 347
      jamo = JAMO_TYPE (break_type);

      /* Determine wheter this forms a Hangul syllable with prev. */
      if (jamo == NO_JAMO)
348
	makes_hangul_syllable = FALSE;
349 350 351 352
      else
	{
	  JamoType prev_end   = HangulJamoProps[prev_jamo].end  ;
	  JamoType this_start = HangulJamoProps[     jamo].start;
353

354 355 356
	  /* See comments before IS_JAMO */
	  makes_hangul_syllable = (prev_end == this_start) || (prev_end + 1 == this_start);
	}
Havoc Pennington's avatar
Havoc Pennington committed
357

358 359 360 361 362 363 364
      switch (type)
        {
        case G_UNICODE_SPACE_SEPARATOR:
        case G_UNICODE_LINE_SEPARATOR:
        case G_UNICODE_PARAGRAPH_SEPARATOR:
          attrs[i].is_white = TRUE;
          break;
365
        case G_UNICODE_CONTROL:
366 367 368 369 370
          if (wc == '\t' || wc == '\n' || wc == '\r' || wc == '\f')
            attrs[i].is_white = TRUE;
          else
            attrs[i].is_white = FALSE;
          break;
371 372 373
        default:
          attrs[i].is_white = FALSE;
          break;
374
        }
Havoc Pennington's avatar
Havoc Pennington committed
375

376 377 378
      /* Just few spaces have variable width. So explicitly mark them.
       */
      attrs[i].is_expandable_space = (0x0020 == wc || 0x00A0 == wc);
379
      is_Extended_Pictographic =
380 381
	_pango_Is_Emoji_Extended_Pictographic (wc);

Havoc Pennington's avatar
Havoc Pennington committed
382

383
      /* ---- UAX#29 Grapheme Boundaries ---- */
384
      {
Behdad Esfahbod's avatar
Behdad Esfahbod committed
385
	GraphemeBreakType GB_type;
386

387
        /* Find the GraphemeBreakType of wc */
Behdad Esfahbod's avatar
Behdad Esfahbod committed
388
	GB_type = GB_Other;
Behdad Esfahbod's avatar
Behdad Esfahbod committed
389
	switch ((int) type)
390 391
	  {
	  case G_UNICODE_FORMAT:
392
	    if (G_UNLIKELY (wc == 0x200C))
393
	      {
394 395 396 397 398 399
		GB_type = GB_Extend;
		break;
	      }
	    if (G_UNLIKELY (wc == 0x200D))
	      {
		GB_type = GB_ZWJ;
400 401
		break;
	      }
402 403 404 405 406
            if (G_UNLIKELY((wc >= 0x600 && wc <= 0x605) ||
                            wc == 0x6DD ||
                            wc == 0x70F ||
                            wc == 0x8E2 ||
                            wc == 0x110BD ||
407
                            wc == 0x110CD))
408 409 410 411
              {
                GB_type = GB_Prepend;
                break;
              }
412
            G_GNUC_FALLTHROUGH;
413
	  case G_UNICODE_CONTROL:
414 415
	  case G_UNICODE_LINE_SEPARATOR:
	  case G_UNICODE_PARAGRAPH_SEPARATOR:
416
	  case G_UNICODE_SURROGATE:
417
	    GB_type = GB_ControlCRLF;
418 419
	    break;

420 421 422 423 424 425 426 427
	  case G_UNICODE_UNASSIGNED:
	    /* Unassigned default ignorables */
	    if ((wc >= 0xFFF0 && wc <= 0xFFF8) ||
		(wc >= 0xE0000 && wc <= 0xE0FFF))
	      {
		GB_type = GB_ControlCRLF;
		break;
	      }
428
            G_GNUC_FALLTHROUGH;
429

430 431 432
	  case G_UNICODE_OTHER_LETTER:
	    if (makes_hangul_syllable)
	      GB_type = GB_InHangulSyllable;
433 434 435 436

	    if (_pango_is_Consonant_Preceding_Repha (wc) ||
		_pango_is_Consonant_Prefixed (wc))
	      GB_type = GB_Prepend;
437 438 439 440 441 442 443
	    break;

	  case G_UNICODE_MODIFIER_LETTER:
	    if (wc >= 0xFF9E && wc <= 0xFF9F)
	      GB_type = GB_Extend; /* Other_Grapheme_Extend */
	    break;

444
	  case G_UNICODE_SPACING_MARK:
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
	    GB_type = GB_SpacingMark; /* SpacingMark */
	    if (wc >= 0x0900)
	      {
		if (wc == 0x09BE || wc == 0x09D7 ||
		    wc == 0x0B3E || wc == 0x0B57 || wc == 0x0BBE || wc == 0x0BD7 ||
		    wc == 0x0CC2 || wc == 0x0CD5 || wc == 0x0CD6 ||
		    wc == 0x0D3E || wc == 0x0D57 || wc == 0x0DCF || wc == 0x0DDF ||
		    wc == 0x1D165 || (wc >= 0x1D16E && wc <= 0x1D172))
		  GB_type = GB_Extend; /* Other_Grapheme_Extend */
	      }
	    break;

	  case G_UNICODE_ENCLOSING_MARK:
	  case G_UNICODE_NON_SPACING_MARK:
	    GB_type = GB_Extend; /* Grapheme_Extend */
	    break;
461

462 463 464 465 466 467 468 469 470
          case G_UNICODE_OTHER_SYMBOL:
            if (G_UNLIKELY(wc >=0x1F1E6 && wc <=0x1F1FF))
              {
                if (prev_GB_type == GB_RI_Odd)
                  GB_type = GB_RI_Even;
                else if (prev_GB_type == GB_RI_Even)
                  GB_type = GB_RI_Odd;
                else
                  GB_type = GB_RI_Odd;
471
                break;
472 473 474 475 476
              }
            break;

          case G_UNICODE_MODIFIER_SYMBOL:
            if (wc >= 0x1F3FB && wc <= 0x1F3FF)
477
              GB_type = GB_Extend;
478
            break;
479 480
	  }

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
	/* Rule GB11 */
	if (met_Extended_Pictographic)
	  {
	    if (GB_type == GB_Extend)
	      met_Extended_Pictographic = TRUE;
	    else if (_pango_Is_Emoji_Extended_Pictographic (prev_wc) &&
		     GB_type == GB_ZWJ)
	      met_Extended_Pictographic = TRUE;
	    else if (prev_GB_type == GB_Extend && GB_type == GB_ZWJ)
	      met_Extended_Pictographic = TRUE;
	    else if (prev_GB_type == GB_ZWJ && is_Extended_Pictographic)
	      met_Extended_Pictographic = TRUE;
	    else
	      met_Extended_Pictographic = FALSE;
	  }

497
	/* Grapheme Cluster Boundary Rules */
498
	is_grapheme_boundary = TRUE; /* Rule GB999 */
499

500 501
	/* We apply Rules GB1 and GB2 at the end of the function */
	if (wc == '\n' && prev_wc == '\r')
502
          is_grapheme_boundary = FALSE; /* Rule GB3 */
503
	else if (prev_GB_type == GB_ControlCRLF || GB_type == GB_ControlCRLF)
Behdad Esfahbod's avatar
Behdad Esfahbod committed
504
	  is_grapheme_boundary = TRUE; /* Rules GB4 and GB5 */
505
	else if (GB_type == GB_InHangulSyllable)
Behdad Esfahbod's avatar
Behdad Esfahbod committed
506
	  is_grapheme_boundary = FALSE; /* Rules GB6, GB7, GB8 */
507
	else if (GB_type == GB_Extend)
Matthias Clasen's avatar
Matthias Clasen committed
508
	  is_grapheme_boundary = FALSE; /* Rule GB9 */
509 510
        else if (GB_type == GB_ZWJ)
	  is_grapheme_boundary = FALSE; /* Rule GB9 */
511
	else if (GB_type == GB_SpacingMark)
Behdad Esfahbod's avatar
Behdad Esfahbod committed
512
	  is_grapheme_boundary = FALSE; /* Rule GB9a */
513
	else if (prev_GB_type == GB_Prepend)
Behdad Esfahbod's avatar
Behdad Esfahbod committed
514
	  is_grapheme_boundary = FALSE; /* Rule GB9b */
515 516 517 518 519
	else if (is_Extended_Pictographic)
	  { /* Rule GB11 */
	    if (prev_GB_type == GB_ZWJ && met_Extended_Pictographic)
	      is_grapheme_boundary = FALSE;
	  }
520 521
	else if (prev_GB_type == GB_RI_Odd && GB_type == GB_RI_Even)
	  is_grapheme_boundary = FALSE; /* Rule GB12 and GB13 */
522 523 524

	if (is_Extended_Pictographic)
	  met_Extended_Pictographic = TRUE;
525

Behdad Esfahbod's avatar
Behdad Esfahbod committed
526
	attrs[i].is_cursor_position = is_grapheme_boundary;
527 528 529
	/* If this is a grapheme boundary, we have to decide if backspace
	 * deletes a character or the whole grapheme cluster */
	if (is_grapheme_boundary)
530
          {
531
	    attrs[i].backspace_deletes_character = BACKSPACE_DELETES_CHARACTER (base_character);
532 533 534 535 536

	    /* Dependent Vowels for Indic language */
	    if (_pango_is_Virama (prev_wc) ||
		_pango_is_Vowel_Dependent (prev_wc))
	      attrs[i].backspace_deletes_character = TRUE;
537
          }
538 539
	else
	  attrs[i].backspace_deletes_character = FALSE;
540 541

	prev_GB_type = GB_type;
542 543 544 545 546
      }

      /* ---- UAX#29 Word Boundaries ---- */
      {
	is_word_boundary = FALSE;
547 548
	if (is_grapheme_boundary ||
	    G_UNLIKELY(wc >=0x1F1E6 && wc <=0x1F1FF)) /* Rules WB3 and WB4 */
549 550 551 552
	  {
	    PangoScript script;
	    WordBreakType WB_type;

Matthias Clasen's avatar
Matthias Clasen committed
553
	    script = (PangoScript)g_unichar_get_script (wc);
554 555 556 557 558 559 560

	    /* Find the WordBreakType of wc */
	    WB_type = WB_Other;

	    if (script == PANGO_SCRIPT_KATAKANA)
	      WB_type = WB_Katakana;

561 562 563
	    if (script == PANGO_SCRIPT_HEBREW && type == G_UNICODE_OTHER_LETTER)
	      WB_type = WB_Hebrew_Letter;

564 565 566 567 568 569 570 571 572 573 574
	    if (WB_type == WB_Other)
	      switch (wc >> 8)
	        {
		case 0x30:
		  if (wc == 0x3031 || wc == 0x3032 || wc == 0x3033 || wc == 0x3034 || wc == 0x3035 ||
		      wc == 0x309b || wc == 0x309c || wc == 0x30a0 || wc == 0x30fc)
		    WB_type = WB_Katakana; /* Katakana exceptions */
		  break;
		case 0xFF:
		  if (wc == 0xFF70)
		    WB_type = WB_Katakana; /* Katakana exceptions */
575
		  else if (wc >= 0xFF9E && wc <= 0xFF9F)
576 577 578
		    WB_type = WB_ExtendFormat; /* Other_Grapheme_Extend */
		  break;
		case 0x05:
579
		  if (wc == 0x058A)
580 581 582 583 584
		    WB_type = WB_ALetter; /* ALetter exceptions */
		  break;
		}

	    if (WB_type == WB_Other)
Behdad Esfahbod's avatar
Behdad Esfahbod committed
585
	      switch ((int) break_type)
586 587 588 589 590 591 592 593 594 595 596 597
	        {
		case G_UNICODE_BREAK_NUMERIC:
		  if (wc != 0x066C)
		    WB_type = WB_Numeric; /* Numeric */
		  break;
		case G_UNICODE_BREAK_INFIX_SEPARATOR:
		  if (wc != 0x003A && wc != 0xFE13 && wc != 0x002E)
		    WB_type = WB_MidNum; /* MidNum */
		  break;
		}

	    if (WB_type == WB_Other)
Behdad Esfahbod's avatar
Behdad Esfahbod committed
598
	      switch ((int) type)
599 600 601 602
		{
		case G_UNICODE_CONTROL:
		  if (wc != 0x000D && wc != 0x000A && wc != 0x000B && wc != 0x000C && wc != 0x0085)
		    break;
603
                  G_GNUC_FALLTHROUGH;
604 605 606 607 608 609
		case G_UNICODE_LINE_SEPARATOR:
		case G_UNICODE_PARAGRAPH_SEPARATOR:
		  WB_type = WB_NewlineCRLF; /* CR, LF, Newline */
		  break;

		case G_UNICODE_FORMAT:
610
		case G_UNICODE_SPACING_MARK:
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
		case G_UNICODE_ENCLOSING_MARK:
		case G_UNICODE_NON_SPACING_MARK:
		  WB_type = WB_ExtendFormat; /* Extend, Format */
		  break;

		case G_UNICODE_CONNECT_PUNCTUATION:
		  WB_type = WB_ExtendNumLet; /* ExtendNumLet */
		  break;

		case G_UNICODE_INITIAL_PUNCTUATION:
		case G_UNICODE_FINAL_PUNCTUATION:
		  if (wc == 0x2018 || wc == 0x2019)
		    WB_type = WB_MidNumLet; /* MidNumLet */
		  break;
		case G_UNICODE_OTHER_PUNCTUATION:
626 627 628 629
		  if ((wc >= 0x055a && wc <= 0x055c) ||
		      wc == 0x055e || wc == 0x05f3)
		    WB_type = WB_ALetter; /* ALetter */
		  else if (wc == 0x0027 || wc == 0x002e || wc == 0x2024 ||
630 631
		      wc == 0xfe52 || wc == 0xff07 || wc == 0xff0e)
		    WB_type = WB_MidNumLet; /* MidNumLet */
632 633
		  else if (wc == 0x00b7 || wc == 0x05f4 || wc == 0x2027 ||
			   wc == 0x003a || wc == 0x0387 || wc == 0x055f ||
634
			   wc == 0xfe13 || wc == 0xfe55 || wc == 0xff1a)
635
		    WB_type = WB_MidLetter; /* MidLetter */
636 637 638 639 640 641 642 643
		  else if (wc == 0x066c ||
			   wc == 0xfe50 || wc == 0xfe54 || wc == 0xff0c || wc == 0xff1b)
		    WB_type = WB_MidNum; /* MidNum */
		  break;

		case G_UNICODE_OTHER_SYMBOL:
		  if (wc >= 0x24B6 && wc <= 0x24E9) /* Other_Alphabetic */
		    goto Alphabetic;
644

Matthias Clasen's avatar
Matthias Clasen committed
645
		  if (G_UNLIKELY(wc >= 0x1F1E6 && wc <= 0x1F1FF))
646
		    {
Matthias Clasen's avatar
Matthias Clasen committed
647 648 649 650
                      if (prev_WB_type == WB_RI_Odd)
                        WB_type = WB_RI_Even;
                      else
                        WB_type = WB_RI_Odd;
651 652
		    }

653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
		  break;

		case G_UNICODE_OTHER_LETTER:
		case G_UNICODE_LETTER_NUMBER:
		  if (wc == 0x3006 || wc == 0x3007 ||
		      (wc >= 0x3021 && wc <= 0x3029) ||
		      (wc >= 0x3038 && wc <= 0x303A) ||
		      (wc >= 0x3400 && wc <= 0x4DB5) ||
		      (wc >= 0x4E00 && wc <= 0x9FC3) ||
		      (wc >= 0xF900 && wc <= 0xFA2D) ||
		      (wc >= 0xFA30 && wc <= 0xFA6A) ||
		      (wc >= 0xFA70 && wc <= 0xFAD9) ||
		      (wc >= 0x20000 && wc <= 0x2A6D6) ||
		      (wc >= 0x2F800 && wc <= 0x2FA1D))
		    break; /* ALetter exceptions: Ideographic */
		  goto Alphabetic;

		case G_UNICODE_LOWERCASE_LETTER:
		case G_UNICODE_MODIFIER_LETTER:
		case G_UNICODE_TITLECASE_LETTER:
		case G_UNICODE_UPPERCASE_LETTER:
		Alphabetic:
		  if (break_type != G_UNICODE_BREAK_COMPLEX_CONTEXT && script != PANGO_SCRIPT_HIRAGANA)
		    WB_type = WB_ALetter; /* ALetter */
		  break;
		}

Peng Wu's avatar
Peng Wu committed
680 681 682 683 684 685 686 687
	    if (WB_type == WB_Other)
	      {
		if (type == G_UNICODE_SPACE_SEPARATOR &&
		    break_type != G_UNICODE_BREAK_NON_BREAKING_GLUE)
		  WB_type = WB_WSegSpace;
	      }

	    /* Word Cluster Boundary Rules */
688 689 690 691

	    /* We apply Rules WB1 and WB2 at the end of the function */

	    if (prev_wc == 0x3031 && wc == 0x41)
692
	      g_debug ("Y %d %d", prev_WB_type, WB_type);
693 694 695 696 697 698 699 700 701 702
	    if (prev_WB_type == WB_NewlineCRLF && prev_WB_i + 1 == i)
	      {
	        /* The extra check for prev_WB_i is to correctly handle sequences like
		 * Newline ÷ Extend × Extend
		 * since we have not skipped ExtendFormat yet.
		 */
	        is_word_boundary = TRUE; /* Rule WB3a */
	      }
	    else if (WB_type == WB_NewlineCRLF)
	      is_word_boundary = TRUE; /* Rule WB3b */
Peng Wu's avatar
Peng Wu committed
703 704 705 706 707
	    else if (prev_wc == 0x200D && is_Extended_Pictographic)
	      is_word_boundary = FALSE; /* Rule WB3c */
	    else if (prev_WB_type == WB_WSegSpace &&
		     WB_type == WB_WSegSpace && prev_WB_i + 1 == i)
	      is_word_boundary = FALSE; /* Rule WB3d */
708 709 710
	    else if (WB_type == WB_ExtendFormat)
	      is_word_boundary = FALSE; /* Rules WB4? */
	    else if ((prev_WB_type == WB_ALetter  ||
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
                  prev_WB_type == WB_Hebrew_Letter ||
                  prev_WB_type == WB_Numeric) &&
                 (WB_type == WB_ALetter  ||
                  WB_type == WB_Hebrew_Letter ||
                  WB_type == WB_Numeric))
	      is_word_boundary = FALSE; /* Rules WB5, WB8, WB9, WB10 */
	    else if (prev_WB_type == WB_Katakana && WB_type == WB_Katakana)
	      is_word_boundary = FALSE; /* Rule WB13 */
	    else if ((prev_WB_type == WB_ALetter ||
                  prev_WB_type == WB_Hebrew_Letter ||
                  prev_WB_type == WB_Numeric ||
                  prev_WB_type == WB_Katakana ||
                  prev_WB_type == WB_ExtendNumLet) &&
                 WB_type == WB_ExtendNumLet)
	      is_word_boundary = FALSE; /* Rule WB13a */
	    else if (prev_WB_type == WB_ExtendNumLet &&
                 (WB_type == WB_ALetter ||
                  WB_type == WB_Hebrew_Letter ||
                  WB_type == WB_Numeric ||
                  WB_type == WB_Katakana))
	      is_word_boundary = FALSE; /* Rule WB13b */
	    else if (((prev_prev_WB_type == WB_ALetter ||
                   prev_prev_WB_type == WB_Hebrew_Letter) &&
                  (WB_type == WB_ALetter ||
                   WB_type == WB_Hebrew_Letter)) &&
		     (prev_WB_type == WB_MidLetter ||
              prev_WB_type == WB_MidNumLet ||
              prev_wc == 0x0027))
739 740 741 742
	      {
		attrs[prev_WB_i].is_word_boundary = FALSE; /* Rule WB6 */
		is_word_boundary = FALSE; /* Rule WB7 */
	      }
743 744 745 746 747 748 749
	    else if (prev_WB_type == WB_Hebrew_Letter && wc == 0x0027)
          is_word_boundary = FALSE; /* Rule WB7a */
	    else if (prev_prev_WB_type == WB_Hebrew_Letter && prev_wc == 0x0022 &&
                 WB_type == WB_Hebrew_Letter) {
          attrs[prev_WB_i].is_word_boundary = FALSE; /* Rule WB7b */
          is_word_boundary = FALSE; /* Rule WB7c */
        }
750
	    else if ((prev_prev_WB_type == WB_Numeric && WB_type == WB_Numeric) &&
751 752
                 (prev_WB_type == WB_MidNum || prev_WB_type == WB_MidNumLet ||
                  prev_wc == 0x0027))
753 754 755 756
	      {
		is_word_boundary = FALSE; /* Rule WB11 */
		attrs[prev_WB_i].is_word_boundary = FALSE; /* Rule WB12 */
	      }
757 758
	    else if (prev_WB_type == WB_RI_Odd && WB_type == WB_RI_Even)
	      is_word_boundary = FALSE; /* Rule WB15 and WB16 */
759
	    else
760
	      is_word_boundary = TRUE; /* Rule WB999 */
761 762 763 764 765 766 767 768 769 770

	    if (WB_type != WB_ExtendFormat)
	      {
		prev_prev_WB_type = prev_WB_type;
		prev_WB_type = WB_type;
		prev_WB_i = i;
	      }
	  }

	attrs[i].is_word_boundary = is_word_boundary;
771
      }
772

773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
      /* ---- UAX#29 Sentence Boundaries ---- */
      {
	is_sentence_boundary = FALSE;
	if (is_word_boundary ||
	    wc == '\r' || wc == '\n') /* Rules SB3 and SB5 */
	  {
	    SentenceBreakType SB_type;

	    /* Find the SentenceBreakType of wc */
	    SB_type = SB_Other;

	    if (break_type == G_UNICODE_BREAK_NUMERIC)
	      SB_type = SB_Numeric; /* Numeric */

	    if (SB_type == SB_Other)
	      switch ((int) type)
		{
		case G_UNICODE_CONTROL:
		  if (wc == '\r' || wc == '\n')
		    SB_type = SB_ParaSep;
		  else if (wc == 0x0009 || wc == 0x000B || wc == 0x000C)
		    SB_type = SB_Sp;
		  else if (wc == 0x0085)
		    SB_type = SB_ParaSep;
		  break;

		case G_UNICODE_SPACE_SEPARATOR:
		  if (wc == 0x0020 || wc == 0x00A0 || wc == 0x1680 ||
		      (wc >= 0x2000 && wc <= 0x200A) ||
		      wc == 0x202F || wc == 0x205F || wc == 0x3000)
		    SB_type = SB_Sp;
		  break;

		case G_UNICODE_LINE_SEPARATOR:
		case G_UNICODE_PARAGRAPH_SEPARATOR:
		  SB_type = SB_ParaSep;
		  break;

		case G_UNICODE_FORMAT:
		case G_UNICODE_SPACING_MARK:
		case G_UNICODE_ENCLOSING_MARK:
		case G_UNICODE_NON_SPACING_MARK:
		  SB_type = SB_ExtendFormat; /* Extend, Format */
		  break;

		case G_UNICODE_MODIFIER_LETTER:
		  if (wc >= 0xFF9E && wc <= 0xFF9F)
		    SB_type = SB_ExtendFormat; /* Other_Grapheme_Extend */
		  break;

		case G_UNICODE_TITLECASE_LETTER:
		  SB_type = SB_Upper;
		  break;

		case G_UNICODE_DASH_PUNCTUATION:
		  if (wc == 0x002D ||
		      (wc >= 0x2013 && wc <= 0x2014) ||
		      (wc >= 0xFE31 && wc <= 0xFE32) ||
		      wc == 0xFE58 ||
		      wc == 0xFE63 ||
		      wc == 0xFF0D)
		    SB_type = SB_SContinue;
		  break;

		case G_UNICODE_OTHER_PUNCTUATION:
		  if (wc == 0x05F3)
		    SB_type = SB_OLetter;
		  else if (wc == 0x002E || wc == 0x2024 ||
		      wc == 0xFE52 || wc == 0xFF0E)
		    SB_type = SB_ATerm;

		  if (wc == 0x002C ||
		      wc == 0x003A ||
		      wc == 0x055D ||
		      (wc >= 0x060C && wc <= 0x060D) ||
		      wc == 0x07F8 ||
		      wc == 0x1802 ||
		      wc == 0x1808 ||
		      wc == 0x3001 ||
		      (wc >= 0xFE10 && wc <= 0xFE11) ||
		      wc == 0xFE13 ||
		      (wc >= 0xFE50 && wc <= 0xFE51) ||
		      wc == 0xFE55 ||
		      wc == 0xFF0C ||
		      wc == 0xFF1A ||
		      wc == 0xFF64)
		    SB_type = SB_SContinue;

861
		  if (_pango_is_STerm(wc))
862 863 864 865 866 867 868
		    SB_type = SB_STerm;

		  break;
		}

	    if (SB_type == SB_Other)
	      {
869
                if (type == G_UNICODE_LOWERCASE_LETTER)
870
		  SB_type = SB_Lower;
871
                else if (type == G_UNICODE_UPPERCASE_LETTER)
872
		  SB_type = SB_Upper;
873 874 875
                else if (type == G_UNICODE_TITLECASE_LETTER ||
                         type == G_UNICODE_MODIFIER_LETTER ||
                         type == G_UNICODE_OTHER_LETTER)
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
		  SB_type = SB_OLetter;

		if (type == G_UNICODE_OPEN_PUNCTUATION ||
		    type == G_UNICODE_CLOSE_PUNCTUATION ||
		    break_type == G_UNICODE_BREAK_QUOTATION)
		  SB_type = SB_Close;
	      }

	    /* Sentence Boundary Rules */

	    /* We apply Rules SB1 and SB2 at the end of the function */

#define IS_OTHER_TERM(SB_type)						\
	    /* not in (OLetter | Upper | Lower | ParaSep | SATerm) */	\
	      !(SB_type == SB_OLetter ||				\
		SB_type == SB_Upper || SB_type == SB_Lower ||		\
		SB_type == SB_ParaSep ||				\
		SB_type == SB_ATerm || SB_type == SB_STerm ||		\
		SB_type == SB_ATerm_Close_Sp ||				\
		SB_type == SB_STerm_Close_Sp)


	    if (wc == '\n' && prev_wc == '\r')
	      is_sentence_boundary = FALSE; /* Rule SB3 */
	    else if (prev_SB_type == SB_ParaSep && prev_SB_i + 1 == i)
	      {
		/* The extra check for prev_SB_i is to correctly handle sequences like
		 * ParaSep ÷ Extend × Extend
		 * since we have not skipped ExtendFormat yet.
		 */

		is_sentence_boundary = TRUE; /* Rule SB4 */
	      }
	    else if (SB_type == SB_ExtendFormat)
	      is_sentence_boundary = FALSE; /* Rule SB5? */
	    else if (prev_SB_type == SB_ATerm && SB_type == SB_Numeric)
	      is_sentence_boundary = FALSE; /* Rule SB6 */
	    else if ((prev_prev_SB_type == SB_Upper ||
		      prev_prev_SB_type == SB_Lower) &&
		     prev_SB_type == SB_ATerm &&
		     SB_type == SB_Upper)
	      is_sentence_boundary = FALSE; /* Rule SB7 */
	    else if (prev_SB_type == SB_ATerm && SB_type == SB_Close)
		SB_type = SB_ATerm;
	    else if (prev_SB_type == SB_STerm && SB_type == SB_Close)
	      SB_type = SB_STerm;
	    else if (prev_SB_type == SB_ATerm && SB_type == SB_Sp)
	      SB_type = SB_ATerm_Close_Sp;
	    else if (prev_SB_type == SB_STerm && SB_type == SB_Sp)
	      SB_type = SB_STerm_Close_Sp;
	    /* Rule SB8 */
	    else if ((prev_SB_type == SB_ATerm ||
		      prev_SB_type == SB_ATerm_Close_Sp) &&
		     SB_type == SB_Lower)
	      is_sentence_boundary = FALSE;
	    else if ((prev_prev_SB_type == SB_ATerm ||
		      prev_prev_SB_type == SB_ATerm_Close_Sp) &&
		     IS_OTHER_TERM(prev_SB_type) &&
		     SB_type == SB_Lower)
935 936 937 938 939 940 941 942 943 944 945 946 947 948
              {
	        attrs[prev_SB_i].is_sentence_boundary = FALSE;
	        attrs[prev_SB_i].is_sentence_start = FALSE;
	        attrs[prev_SB_i].is_sentence_end = FALSE;
                last_sentence_start = -1;
                for (int j = prev_SB_i - 1; j >= 0; j--)
                  {
                    if (attrs[j].is_sentence_boundary)
                      {
                        last_sentence_start = j;
                        break;
                      }
                  }
              }
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
	    else if ((prev_SB_type == SB_ATerm ||
		      prev_SB_type == SB_ATerm_Close_Sp ||
		      prev_SB_type == SB_STerm ||
		      prev_SB_type == SB_STerm_Close_Sp) &&
		     (SB_type == SB_SContinue ||
		      SB_type == SB_ATerm || SB_type == SB_STerm))
	      is_sentence_boundary = FALSE; /* Rule SB8a */
	    else if ((prev_SB_type == SB_ATerm ||
		      prev_SB_type == SB_STerm) &&
		     (SB_type == SB_Close || SB_type == SB_Sp ||
		      SB_type == SB_ParaSep))
	      is_sentence_boundary = FALSE; /* Rule SB9 */
	    else if ((prev_SB_type == SB_ATerm ||
		      prev_SB_type == SB_ATerm_Close_Sp ||
		      prev_SB_type == SB_STerm ||
		      prev_SB_type == SB_STerm_Close_Sp) &&
		     (SB_type == SB_Sp || SB_type == SB_ParaSep))
	      is_sentence_boundary = FALSE; /* Rule SB10 */
	    else if ((prev_SB_type == SB_ATerm ||
		      prev_SB_type == SB_ATerm_Close_Sp ||
		      prev_SB_type == SB_STerm ||
		      prev_SB_type == SB_STerm_Close_Sp) &&
		     SB_type != SB_ParaSep)
	      is_sentence_boundary = TRUE; /* Rule SB11 */
	    else
	      is_sentence_boundary = FALSE; /* Rule SB998 */

	    if (SB_type != SB_ExtendFormat &&
		!((prev_prev_SB_type == SB_ATerm ||
		   prev_prev_SB_type == SB_ATerm_Close_Sp) &&
		  IS_OTHER_TERM(prev_SB_type) &&
		  IS_OTHER_TERM(SB_type)))
              {
                prev_prev_SB_type = prev_SB_type;
                prev_SB_type = SB_type;
                prev_SB_i = i;
              }

#undef IS_OTHER_TERM

	  }

	if (i == 0 || done)
	  is_sentence_boundary = TRUE; /* Rules SB1 and SB2 */

	attrs[i].is_sentence_boundary = is_sentence_boundary;
      }
996

Havoc Pennington's avatar
Havoc Pennington committed
997 998 999 1000
      /* ---- Line breaking ---- */

      break_op = BREAK_ALREADY_HANDLED;

1001 1002 1003
      row_break_type = prev_break_type == G_UNICODE_BREAK_SPACE ?
	prev_prev_break_type : prev_break_type;
      g_assert (row_break_type != G_UNICODE_BREAK_SPACE);
Havoc Pennington's avatar
Havoc Pennington committed
1004

Matthias Clasen's avatar
Matthias Clasen committed
1005
      attrs[i].is_char_break = FALSE;
1006
      attrs[i].is_line_break = FALSE;
Havoc Pennington's avatar
Havoc Pennington committed
1007
      attrs[i].is_mandatory_break = FALSE;
1008

1009 1010
      /* Rule LB1:
	 assign a line breaking class to each code point of the input. */
Peng Wu's avatar
Peng Wu committed
1011
      switch (break_type)
1012
	{
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
	case G_UNICODE_BREAK_AMBIGUOUS:
	case G_UNICODE_BREAK_SURROGATE:
	case G_UNICODE_BREAK_UNKNOWN:
	  break_type = G_UNICODE_BREAK_ALPHABETIC;
	  break;

	case G_UNICODE_BREAK_COMPLEX_CONTEXT:
	  if (type == G_UNICODE_NON_SPACING_MARK ||
	      type == G_UNICODE_SPACING_MARK)
	    break_type = G_UNICODE_BREAK_COMBINING_MARK;
	  else
	    break_type = G_UNICODE_BREAK_ALPHABETIC;
	  break;
1026

1027 1028 1029
	case G_UNICODE_BREAK_CONDITIONAL_JAPANESE_STARTER:
	  break_type = G_UNICODE_BREAK_NON_STARTER;
	  break;
1030

1031 1032 1033
	default:
	  ;
	}
1034

1035 1036 1037 1038 1039 1040 1041 1042 1043
      /* If it's not a grapheme boundary, it's not a line break either */
      if (attrs[i].is_cursor_position ||
	  break_type == G_UNICODE_BREAK_COMBINING_MARK ||
	  break_type == G_UNICODE_BREAK_ZERO_WIDTH_JOINER ||
	  break_type == G_UNICODE_BREAK_HANGUL_L_JAMO ||
	  break_type == G_UNICODE_BREAK_HANGUL_V_JAMO ||
	  break_type == G_UNICODE_BREAK_HANGUL_T_JAMO ||
	  break_type == G_UNICODE_BREAK_HANGUL_LV_SYLLABLE ||
	  break_type == G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE ||
Peng Wu's avatar
Peng Wu committed
1044
	  break_type == G_UNICODE_BREAK_EMOJI_MODIFIER ||
1045 1046 1047
	  break_type == G_UNICODE_BREAK_REGIONAL_INDICATOR)
	{
	  LineBreakType LB_type;
1048

1049 1050
	  /* Find the LineBreakType of wc */
	  LB_type = LB_Other;
1051

1052 1053
	  if (break_type == G_UNICODE_BREAK_NUMERIC)
	    LB_type = LB_Numeric;
1054

1055 1056 1057 1058 1059 1060
	  if (break_type == G_UNICODE_BREAK_SYMBOL ||
	      break_type == G_UNICODE_BREAK_INFIX_SEPARATOR)
	    {
	      if (!(prev_LB_type == LB_Numeric))
		LB_type = LB_Other;
	    }
1061

1062 1063 1064 1065 1066 1067 1068 1069
	  if (break_type == G_UNICODE_BREAK_CLOSE_PUNCTUATION ||
	      break_type == G_UNICODE_BREAK_CLOSE_PARANTHESIS)
	    {
	      if (prev_LB_type == LB_Numeric)
		LB_type = LB_Numeric_Close;
	      else
		LB_type = LB_Other;
	    }
1070

1071 1072 1073 1074 1075 1076 1077 1078 1079
	  if (break_type == G_UNICODE_BREAK_REGIONAL_INDICATOR)
	    {
	      if (prev_LB_type == LB_RI_Odd)
		LB_type = LB_RI_Even;
	      else if (prev_LB_type == LB_RI_Even)
		LB_type = LB_RI_Odd;
	      else
		LB_type = LB_RI_Odd;
	    }
1080

1081
	  attrs[i].is_line_break = TRUE; /* Rule LB31 */
1082 1083 1084 1085
	  /* Unicode doesn't specify char wrap;
	     we wrap around all chars currently. */
	  if (attrs[i].is_cursor_position)
	    attrs[i].is_char_break = TRUE;
1086

1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
	  /* Make any necessary replacements first */
	  if (row_break_type == G_UNICODE_BREAK_UNKNOWN)
	    row_break_type = G_UNICODE_BREAK_ALPHABETIC;

	  /* add the line break rules in reverse order to override
	     the lower priority rules. */

	  /* Rule LB30 */
	  if ((prev_break_type == G_UNICODE_BREAK_ALPHABETIC ||
	       prev_break_type == G_UNICODE_BREAK_HEBREW_LETTER ||
	       prev_break_type == G_UNICODE_BREAK_NUMERIC) &&
Peng Wu's avatar
Peng Wu committed
1098 1099
	      break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
	      !_pango_is_EastAsianWide (wc))
1100 1101 1102
	    break_op = BREAK_PROHIBITED;

	  if (prev_break_type == G_UNICODE_BREAK_CLOSE_PARANTHESIS &&
Peng Wu's avatar
Peng Wu committed
1103
	      !_pango_is_EastAsianWide (prev_wc)&&
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197