Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: third_party/harfbuzz-ng/src/hb-common.cc

Issue 1408003004: Roll harfbuzz-ng to 1.0.5 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2526
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-common.h ('k') | third_party/harfbuzz-ng/src/hb-coretext.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright © 2009,2010 Red Hat, Inc. 2 * Copyright © 2009,2010 Red Hat, Inc.
3 * Copyright © 2011,2012 Google, Inc. 3 * Copyright © 2011,2012 Google, Inc.
4 * 4 *
5 * This is part of HarfBuzz, a text shaping library. 5 * This is part of HarfBuzz, a text shaping library.
6 * 6 *
7 * Permission is hereby granted, without written agreement and without 7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this 8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the 9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in 10 * above copyright notice and the following two paragraphs appear in
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 /** 58 /**
59 * hb_tag_from_string: 59 * hb_tag_from_string:
60 * @str: (array length=len) (element-type uint8_t): 60 * @str: (array length=len) (element-type uint8_t):
61 * @len: 61 * @len:
62 * 62 *
63 * 63 *
64 * 64 *
65 * Return value: 65 * Return value:
66 * 66 *
67 * Since: 1.0 67 * Since: 0.9.2
68 **/ 68 **/
69 hb_tag_t 69 hb_tag_t
70 hb_tag_from_string (const char *str, int len) 70 hb_tag_from_string (const char *str, int len)
71 { 71 {
72 char tag[4]; 72 char tag[4];
73 unsigned int i; 73 unsigned int i;
74 74
75 if (!str || !len || !*str) 75 if (!str || !len || !*str)
76 return HB_TAG_NONE; 76 return HB_TAG_NONE;
77 77
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 /** 116 /**
117 * hb_direction_from_string: 117 * hb_direction_from_string:
118 * @str: (array length=len) (element-type uint8_t): 118 * @str: (array length=len) (element-type uint8_t):
119 * @len: 119 * @len:
120 * 120 *
121 * 121 *
122 * 122 *
123 * Return value: 123 * Return value:
124 * 124 *
125 * Since: 1.0 125 * Since: 0.9.2
126 **/ 126 **/
127 hb_direction_t 127 hb_direction_t
128 hb_direction_from_string (const char *str, int len) 128 hb_direction_from_string (const char *str, int len)
129 { 129 {
130 if (unlikely (!str || !len || !*str)) 130 if (unlikely (!str || !len || !*str))
131 return HB_DIRECTION_INVALID; 131 return HB_DIRECTION_INVALID;
132 132
133 /* Lets match loosely: just match the first letter, such that 133 /* Lets match loosely: just match the first letter, such that
134 * all of "ltr", "left-to-right", etc work! 134 * all of "ltr", "left-to-right", etc work!
135 */ 135 */
136 char c = TOLOWER (str[0]); 136 char c = TOLOWER (str[0]);
137 for (unsigned int i = 0; i < ARRAY_LENGTH (direction_strings); i++) 137 for (unsigned int i = 0; i < ARRAY_LENGTH (direction_strings); i++)
138 if (c == direction_strings[i][0]) 138 if (c == direction_strings[i][0])
139 return (hb_direction_t) (HB_DIRECTION_LTR + i); 139 return (hb_direction_t) (HB_DIRECTION_LTR + i);
140 140
141 return HB_DIRECTION_INVALID; 141 return HB_DIRECTION_INVALID;
142 } 142 }
143 143
144 /** 144 /**
145 * hb_direction_to_string: 145 * hb_direction_to_string:
146 * @direction: 146 * @direction:
147 * 147 *
148 * 148 *
149 * 149 *
150 * Return value: (transfer none): 150 * Return value: (transfer none):
151 * 151 *
152 * Since: 1.0 152 * Since: 0.9.2
153 **/ 153 **/
154 const char * 154 const char *
155 hb_direction_to_string (hb_direction_t direction) 155 hb_direction_to_string (hb_direction_t direction)
156 { 156 {
157 if (likely ((unsigned int) (direction - HB_DIRECTION_LTR) 157 if (likely ((unsigned int) (direction - HB_DIRECTION_LTR)
158 < ARRAY_LENGTH (direction_strings))) 158 < ARRAY_LENGTH (direction_strings)))
159 return direction_strings[direction - HB_DIRECTION_LTR]; 159 return direction_strings[direction - HB_DIRECTION_LTR];
160 160
161 return "invalid"; 161 return "invalid";
162 } 162 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 281
282 /** 282 /**
283 * hb_language_from_string: 283 * hb_language_from_string:
284 * @str: (array length=len) (element-type uint8_t): 284 * @str: (array length=len) (element-type uint8_t):
285 * @len: 285 * @len:
286 * 286 *
287 * 287 *
288 * 288 *
289 * Return value: (transfer none): 289 * Return value: (transfer none):
290 * 290 *
291 * Since: 1.0 291 * Since: 0.9.2
292 **/ 292 **/
293 hb_language_t 293 hb_language_t
294 hb_language_from_string (const char *str, int len) 294 hb_language_from_string (const char *str, int len)
295 { 295 {
296 char strbuf[64];
297
298 if (!str || !len || !*str) 296 if (!str || !len || !*str)
299 return HB_LANGUAGE_INVALID; 297 return HB_LANGUAGE_INVALID;
300 298
299 hb_language_item_t *item = NULL;
301 if (len >= 0) 300 if (len >= 0)
302 { 301 {
303 /* NUL-terminate it. */ 302 /* NUL-terminate it. */
303 char strbuf[64];
304 len = MIN (len, (int) sizeof (strbuf) - 1); 304 len = MIN (len, (int) sizeof (strbuf) - 1);
305 memcpy (strbuf, str, len); 305 memcpy (strbuf, str, len);
306 strbuf[len] = '\0'; 306 strbuf[len] = '\0';
307 str = strbuf; 307 item = lang_find_or_insert (strbuf);
308 } 308 }
309 309 else
310 hb_language_item_t *item = lang_find_or_insert (str); 310 item = lang_find_or_insert (str);
311 311
312 return likely (item) ? item->lang : HB_LANGUAGE_INVALID; 312 return likely (item) ? item->lang : HB_LANGUAGE_INVALID;
313 } 313 }
314 314
315 /** 315 /**
316 * hb_language_to_string: 316 * hb_language_to_string:
317 * @language: 317 * @language:
318 * 318 *
319 * 319 *
320 * 320 *
321 * Return value: (transfer none): 321 * Return value: (transfer none):
322 * 322 *
323 * Since: 1.0 323 * Since: 0.9.2
324 **/ 324 **/
325 const char * 325 const char *
326 hb_language_to_string (hb_language_t language) 326 hb_language_to_string (hb_language_t language)
327 { 327 {
328 /* This is actually NULL-safe! */ 328 /* This is actually NULL-safe! */
329 return language->s; 329 return language->s;
330 } 330 }
331 331
332 /** 332 /**
333 * hb_language_get_default: 333 * hb_language_get_default:
334 * 334 *
335 * 335 *
336 * 336 *
337 * Return value: (transfer none): 337 * Return value: (transfer none):
338 * 338 *
339 * Since: 1.0 339 * Since: 0.9.2
340 **/ 340 **/
341 hb_language_t 341 hb_language_t
342 hb_language_get_default (void) 342 hb_language_get_default (void)
343 { 343 {
344 static hb_language_t default_language = HB_LANGUAGE_INVALID; 344 static hb_language_t default_language = HB_LANGUAGE_INVALID;
345 345
346 hb_language_t language = (hb_language_t) hb_atomic_ptr_get (&default_language) ; 346 hb_language_t language = (hb_language_t) hb_atomic_ptr_get (&default_language) ;
347 if (unlikely (language == HB_LANGUAGE_INVALID)) { 347 if (unlikely (language == HB_LANGUAGE_INVALID)) {
348 language = hb_language_from_string (setlocale (LC_CTYPE, NULL), -1); 348 language = hb_language_from_string (setlocale (LC_CTYPE, NULL), -1);
349 (void) hb_atomic_ptr_cmpexch (&default_language, HB_LANGUAGE_INVALID, langua ge); 349 (void) hb_atomic_ptr_cmpexch (&default_language, HB_LANGUAGE_INVALID, langua ge);
350 } 350 }
351 351
352 return default_language; 352 return default_language;
353 } 353 }
354 354
355 355
356 /* hb_script_t */ 356 /* hb_script_t */
357 357
358 /** 358 /**
359 * hb_script_from_iso15924_tag: 359 * hb_script_from_iso15924_tag:
360 * @tag: 360 * @tag:
361 * 361 *
362 * 362 *
363 * 363 *
364 * Return value: 364 * Return value:
365 * 365 *
366 * Since: 1.0 366 * Since: 0.9.2
367 **/ 367 **/
368 hb_script_t 368 hb_script_t
369 hb_script_from_iso15924_tag (hb_tag_t tag) 369 hb_script_from_iso15924_tag (hb_tag_t tag)
370 { 370 {
371 if (unlikely (tag == HB_TAG_NONE)) 371 if (unlikely (tag == HB_TAG_NONE))
372 return HB_SCRIPT_INVALID; 372 return HB_SCRIPT_INVALID;
373 373
374 /* Be lenient, adjust case (one capital letter followed by three small letters ) */ 374 /* Be lenient, adjust case (one capital letter followed by three small letters ) */
375 tag = (tag & 0xDFDFDFDFu) | 0x00202020u; 375 tag = (tag & 0xDFDFDFDFu) | 0x00202020u;
376 376
(...skipping 24 matching lines...) Expand all
401 401
402 /** 402 /**
403 * hb_script_from_string: 403 * hb_script_from_string:
404 * @s: (array length=len) (element-type uint8_t): 404 * @s: (array length=len) (element-type uint8_t):
405 * @len: 405 * @len:
406 * 406 *
407 * 407 *
408 * 408 *
409 * Return value: 409 * Return value:
410 * 410 *
411 * Since: 1.0 411 * Since: 0.9.2
412 **/ 412 **/
413 hb_script_t 413 hb_script_t
414 hb_script_from_string (const char *s, int len) 414 hb_script_from_string (const char *s, int len)
415 { 415 {
416 return hb_script_from_iso15924_tag (hb_tag_from_string (s, len)); 416 return hb_script_from_iso15924_tag (hb_tag_from_string (s, len));
417 } 417 }
418 418
419 /** 419 /**
420 * hb_script_to_iso15924_tag: 420 * hb_script_to_iso15924_tag:
421 * @script: 421 * @script:
422 * 422 *
423 * 423 *
424 * 424 *
425 * Return value: 425 * Return value:
426 * 426 *
427 * Since: 1.0 427 * Since: 0.9.2
428 **/ 428 **/
429 hb_tag_t 429 hb_tag_t
430 hb_script_to_iso15924_tag (hb_script_t script) 430 hb_script_to_iso15924_tag (hb_script_t script)
431 { 431 {
432 return (hb_tag_t) script; 432 return (hb_tag_t) script;
433 } 433 }
434 434
435 /** 435 /**
436 * hb_script_get_horizontal_direction: 436 * hb_script_get_horizontal_direction:
437 * @script: 437 * @script:
438 * 438 *
439 * 439 *
440 * 440 *
441 * Return value: 441 * Return value:
442 * 442 *
443 * Since: 1.0 443 * Since: 0.9.2
444 **/ 444 **/
445 hb_direction_t 445 hb_direction_t
446 hb_script_get_horizontal_direction (hb_script_t script) 446 hb_script_get_horizontal_direction (hb_script_t script)
447 { 447 {
448 /* http://goo.gl/x9ilM */ 448 /* http://goo.gl/x9ilM */
449 switch ((hb_tag_t) script) 449 switch ((hb_tag_t) script)
450 { 450 {
451 /* Unicode-1.1 additions */ 451 /* Unicode-1.1 additions */
452 case HB_SCRIPT_ARABIC: 452 case HB_SCRIPT_ARABIC:
453 case HB_SCRIPT_HEBREW: 453 case HB_SCRIPT_HEBREW:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 /* hb_version */ 538 /* hb_version */
539 539
540 /** 540 /**
541 * hb_version: 541 * hb_version:
542 * @major: (out): Library major version component. 542 * @major: (out): Library major version component.
543 * @minor: (out): Library minor version component. 543 * @minor: (out): Library minor version component.
544 * @micro: (out): Library micro version component. 544 * @micro: (out): Library micro version component.
545 * 545 *
546 * Returns library version as three integer components. 546 * Returns library version as three integer components.
547 * 547 *
548 * Since: 1.0 548 * Since: 0.9.2
549 **/ 549 **/
550 void 550 void
551 hb_version (unsigned int *major, 551 hb_version (unsigned int *major,
552 unsigned int *minor, 552 unsigned int *minor,
553 unsigned int *micro) 553 unsigned int *micro)
554 { 554 {
555 *major = HB_VERSION_MAJOR; 555 *major = HB_VERSION_MAJOR;
556 *minor = HB_VERSION_MINOR; 556 *minor = HB_VERSION_MINOR;
557 *micro = HB_VERSION_MICRO; 557 *micro = HB_VERSION_MICRO;
558 } 558 }
559 559
560 /** 560 /**
561 * hb_version_string: 561 * hb_version_string:
562 * 562 *
563 * Returns library version as a string with three components. 563 * Returns library version as a string with three components.
564 * 564 *
565 * Return value: library version string. 565 * Return value: library version string.
566 * 566 *
567 * Since: 1.0 567 * Since: 0.9.2
568 **/ 568 **/
569 const char * 569 const char *
570 hb_version_string (void) 570 hb_version_string (void)
571 { 571 {
572 return HB_VERSION_STRING; 572 return HB_VERSION_STRING;
573 } 573 }
574 574
575 /** 575 /**
576 * hb_version_atleast: 576 * hb_version_atleast:
577 * @major: 577 * @major:
578 * @minor: 578 * @minor:
579 * @micro: 579 * @micro:
580 * 580 *
581 * 581 *
582 * 582 *
583 * Return value: 583 * Return value:
584 * 584 *
585 * Since: 0.9.30 585 * Since: 0.9.30
586 **/ 586 **/
587 hb_bool_t 587 hb_bool_t
588 hb_version_atleast (unsigned int major, 588 hb_version_atleast (unsigned int major,
589 unsigned int minor, 589 unsigned int minor,
590 unsigned int micro) 590 unsigned int micro)
591 { 591 {
592 return HB_VERSION_ATLEAST (major, minor, micro); 592 return HB_VERSION_ATLEAST (major, minor, micro);
593 } 593 }
OLDNEW
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-common.h ('k') | third_party/harfbuzz-ng/src/hb-coretext.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698