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

Side by Side Diff: Source/core/platform/graphics/Font.cpp

Issue 18949006: Optimize Font CodePath selection and more unit testing. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix test check macros. Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 10 matching lines...) Expand all
21 * 21 *
22 */ 22 */
23 23
24 #include "config.h" 24 #include "config.h"
25 #include "core/platform/graphics/Font.h" 25 #include "core/platform/graphics/Font.h"
26 26
27 #include "core/platform/graphics/FloatRect.h" 27 #include "core/platform/graphics/FloatRect.h"
28 #include "core/platform/graphics/TextRun.h" 28 #include "core/platform/graphics/TextRun.h"
29 #include "core/platform/graphics/WidthIterator.h" 29 #include "core/platform/graphics/WidthIterator.h"
30 #include "core/platform/text/transcoder/FontTranscoder.h" 30 #include "core/platform/text/transcoder/FontTranscoder.h"
31 #include <wtf/MainThread.h> 31 #include "wtf/MainThread.h"
32 #include <wtf/MathExtras.h> 32 #include "wtf/MathExtras.h"
33 #include <wtf/text/StringBuilder.h> 33 #include "wtf/StdLibExtras.h"
34 #include <wtf/UnusedParam.h> 34 #include "wtf/UnusedParam.h"
35 #include "wtf/text/StringBuilder.h"
35 36
36 using namespace WTF; 37 using namespace WTF;
37 using namespace Unicode; 38 using namespace Unicode;
38 39
39 namespace WTF { 40 namespace WTF {
40 41
41 // allow compilation of OwnPtr<TextLayout> in source files that don't have acces s to the TextLayout class definition 42 // allow compilation of OwnPtr<TextLayout> in source files that don't have acces s to the TextLayout class definition
42 template <> void deleteOwnedPtr<WebCore::TextLayout>(WebCore::TextLayout* ptr) 43 template <> void deleteOwnedPtr<WebCore::TextLayout>(WebCore::TextLayout* ptr)
43 { 44 {
44 WebCore::Font::deleteLayout(ptr); 45 WebCore::Font::deleteLayout(ptr);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (!run.characterScanForCodePath()) 347 if (!run.characterScanForCodePath())
347 return Simple; 348 return Simple;
348 349
349 if (run.is8Bit()) 350 if (run.is8Bit())
350 return Simple; 351 return Simple;
351 352
352 // Start from 0 since drawing and highlighting also measure the characters b efore run->from. 353 // Start from 0 since drawing and highlighting also measure the characters b efore run->from.
353 return characterRangeCodePath(run.characters16(), run.length()); 354 return characterRangeCodePath(run.characters16(), run.length());
354 } 355 }
355 356
357 static inline UChar keyExtractor(const UChar* value)
358 {
359 return *value;
360 }
361
356 Font::CodePath Font::characterRangeCodePath(const UChar* characters, unsigned le n) 362 Font::CodePath Font::characterRangeCodePath(const UChar* characters, unsigned le n)
357 { 363 {
358 // FIXME: Should use a UnicodeSet in ports where ICU is used. Note that we 364 static UChar complexCodePathRanges[] = {
359 // can't simply use UnicodeCharacter Property/class because some characters 365 // U+02E5 through U+02E9 (Modifier Letters : Tone letters)
360 // are not 'combining', but still need to go to the complex path. 366 0x2E5, 0x2E9,
361 // Alternatively, we may as well consider binary search over a sorted 367 // U+0300 through U+036F Combining diacritical marks
362 // list of ranges. 368 0x300, 0x36F,
369 // U+0591 through U+05CF excluding U+05BE Hebrew combining marks, ...
370 0x0591, 0x05BD,
371 // ... Hebrew punctuation Paseq, Sof Pasuq and Nun Hafukha
372 0x05BF, 0x05CF,
373 // U+0600 through U+109F Arabic, Syriac, Thaana, NKo, Samaritan, Mandaic ,
374 // Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannad a,
375 // Malayalam, Sinhala, Thai, Lao, Tibetan, Myanmar
376 0x0600, 0x109F,
377 // U+1100 through U+11FF Hangul Jamo (only Ancient Korean should be left
378 // here if you precompose; Modern Korean will be precomposed as a result of step A)
379 0x1100, 0x11FF,
380 // U+135D through U+135F Ethiopic combining marks
381 0x135D, 0x135F,
382 // U+1780 through U+18AF Tagalog, Hanunoo, Buhid, Taghanwa,Khmer, Mongol ian
383 0x1700, 0x18AF,
384 // U+1900 through U+194F Limbu (Unicode 4.0)
385 0x1900, 0x194F,
386 // U+1980 through U+19DF New Tai Lue
387 0x1980, 0x19DF,
388 // U+1A00 through U+1CFF Buginese, Tai Tham, Balinese, Batak, Lepcha, Ve dic
389 0x1A00, 0x1CFF,
390 // U+1DC0 through U+1DFF Comining diacritical mark supplement
391 0x1DC0, 0x1DFF,
392 // U+20D0 through U+20FF Combining marks for symbols
393 0x20D0, 0x20FF,
394 // U+2CEF through U+2CF1 Combining marks for Coptic
395 0x2CEF, 0x2CF1,
396 // U+302A through U+302F Ideographic and Hangul Tone marks
397 0x302A, 0x302F,
398 // U+A67C through U+A67D Combining marks for old Cyrillic
399 0xA67C, 0xA67D,
400 // U+A6F0 through U+A6F1 Combining mark for Bamum
401 0xA6F0, 0xA6F1,
402 // U+A800 through U+ABFF Nagri, Phags-pa, Saurashtra, Devanagari Extende d,
403 // Hangul Jamo Ext. A, Javanese, Myanmar Extended A, Tai Viet, Meetei Ma yek
404 0xA800, 0xABFF,
405 // U+D7B0 through U+D7FF Hangul Jamo Ext. B
406 0xD7B0, 0xD7FF,
407 // U+FE00 through U+FE0F Unicode variation selectors
408 0xFE00, 0xFE0F,
409 // U+FE20 through U+FE2F Combining half marks
410 0xFE20, 0xFE2F,
411 };
412 static size_t complexCodePathRangesCount = WTF_ARRAY_LENGTH(complexCodePathR anges);
413
363 CodePath result = Simple; 414 CodePath result = Simple;
364 for (unsigned i = 0; i < len; i++) { 415 for (unsigned i = 0; i < len; i++) {
365 const UChar c = characters[i]; 416 const UChar c = characters[i];
366 if (c < 0x2E5) // U+02E5 through U+02E9 (Modifier Letters : Tone letters ) 417
418 // Shortcut for common case
419 if (c < 0x2E5)
367 continue; 420 continue;
368 if (c <= 0x2E9)
369 return Complex;
370
371 if (c < 0x300) // U+0300 through U+036F Combining diacritical marks
372 continue;
373 if (c <= 0x36F)
374 return Complex;
375
376 if (c < 0x0591 || c == 0x05BE) // U+0591 through U+05CF excluding U+05BE Hebrew combining marks, Hebrew punctuation Paseq, Sof Pasuq and Nun Hafukha
377 continue;
378 if (c <= 0x05CF)
379 return Complex;
380
381 // U+0600 through U+109F Arabic, Syriac, Thaana, NKo, Samaritan, Mandaic ,
382 // Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannad a,
383 // Malayalam, Sinhala, Thai, Lao, Tibetan, Myanmar
384 if (c < 0x0600)
385 continue;
386 if (c <= 0x109F)
387 return Complex;
388
389 // U+1100 through U+11FF Hangul Jamo (only Ancient Korean should be left here if you precompose;
390 // Modern Korean will be precomposed as a result of step A)
391 if (c < 0x1100)
392 continue;
393 if (c <= 0x11FF)
394 return Complex;
395
396 if (c < 0x135D) // U+135D through U+135F Ethiopic combining marks
397 continue;
398 if (c <= 0x135F)
399 return Complex;
400
401 if (c < 0x1700) // U+1780 through U+18AF Tagalog, Hanunoo, Buhid, Taghan wa,Khmer, Mongolian
402 continue;
403 if (c <= 0x18AF)
404 return Complex;
405
406 if (c < 0x1900) // U+1900 through U+194F Limbu (Unicode 4.0)
407 continue;
408 if (c <= 0x194F)
409 return Complex;
410
411 if (c < 0x1980) // U+1980 through U+19DF New Tai Lue
412 continue;
413 if (c <= 0x19DF)
414 return Complex;
415
416 if (c < 0x1A00) // U+1A00 through U+1CFF Buginese, Tai Tham, Balinese, B atak, Lepcha, Vedic
417 continue;
418 if (c <= 0x1CFF)
419 return Complex;
420
421 if (c < 0x1DC0) // U+1DC0 through U+1DFF Comining diacritical mark suppl ement
422 continue;
423 if (c <= 0x1DFF)
424 return Complex;
425 421
426 // U+1E00 through U+2000 characters with diacritics and stacked diacriti cs 422 // U+1E00 through U+2000 characters with diacritics and stacked diacriti cs
427 if (c <= 0x2000) { 423 if (c >= 0x1E00 && c <= 0x2000) {
428 result = SimpleWithGlyphOverflow; 424 result = SimpleWithGlyphOverflow;
429 continue; 425 continue;
430 } 426 }
431 427
432 if (c < 0x20D0) // U+20D0 through U+20FF Combining marks for symbols 428 // Surrogate pairs
433 continue; 429 if (c > 0xD7FF && c <= 0xDBFF) {
434 if (c <= 0x20FF)
435 return Complex;
436
437 if (c < 0x2CEF) // U+2CEF through U+2CF1 Combining marks for Coptic
438 continue;
439 if (c <= 0x2CF1)
440 return Complex;
441
442 if (c < 0x302A) // U+302A through U+302F Ideographic and Hangul Tone mar ks
443 continue;
444 if (c <= 0x302F)
445 return Complex;
446
447 if (c < 0xA67C) // U+A67C through U+A67D Combining marks for old Cyrilli c
448 continue;
449 if (c <= 0xA67D)
450 return Complex;
451
452 if (c < 0xA6F0) // U+A6F0 through U+A6F1 Combining mark for Bamum
453 continue;
454 if (c <= 0xA6F1)
455 return Complex;
456
457 // U+A800 through U+ABFF Nagri, Phags-pa, Saurashtra, Devanagari Extended ,
458 // Hangul Jamo Ext. A, Javanese, Myanmar Extended A, Tai Viet, Meetei May ek,
459 if (c < 0xA800)
460 continue;
461 if (c <= 0xABFF)
462 return Complex;
463
464 if (c < 0xD7B0) // U+D7B0 through U+D7FF Hangul Jamo Ext. B
465 continue;
466 if (c <= 0xD7FF)
467 return Complex;
468
469 if (c <= 0xDBFF) {
470 // High surrogate
471
472 if (i == len - 1) 430 if (i == len - 1)
473 continue; 431 continue;
474 432
475 UChar next = characters[++i]; 433 UChar next = characters[++i];
476 if (!U16_IS_TRAIL(next)) 434 if (!U16_IS_TRAIL(next))
477 continue; 435 continue;
478 436
479 UChar32 supplementaryCharacter = U16_GET_SUPPLEMENTARY(c, next); 437 UChar32 supplementaryCharacter = U16_GET_SUPPLEMENTARY(c, next);
480 438
481 if (supplementaryCharacter < 0x1F1E6) // U+1F1E6 through U+1F1FF Reg ional Indicator Symbols 439 if (supplementaryCharacter < 0x1F1E6) // U+1F1E6 through U+1F1FF Reg ional Indicator Symbols
482 continue; 440 continue;
483 if (supplementaryCharacter <= 0x1F1FF) 441 if (supplementaryCharacter <= 0x1F1FF)
484 return Complex; 442 return Complex;
485 443
486 if (supplementaryCharacter < 0xE0100) // U+E0100 through U+E01EF Uni code variation selectors. 444 if (supplementaryCharacter < 0xE0100) // U+E0100 through U+E01EF Uni code variation selectors.
487 continue; 445 continue;
488 if (supplementaryCharacter <= 0xE01EF) 446 if (supplementaryCharacter <= 0xE01EF)
489 return Complex; 447 return Complex;
490 448
491 // FIXME: Check for Brahmi (U+11000 block), Kaithi (U+11080 block) a nd other complex scripts 449 // FIXME: Check for Brahmi (U+11000 block), Kaithi (U+11080 block) a nd other complex scripts
492 // in plane 1 or higher. 450 // in plane 1 or higher.
493 451
494 continue; 452 continue;
495 } 453 }
496 454
497 if (c < 0xFE00) // U+FE00 through U+FE0F Unicode variation selectors 455 // Search for other Complex cases
456 UChar* boundingCharacter = approximateBinarySearch<UChar, UChar>(
457 (UChar*)complexCodePathRanges, complexCodePathRangesCount, c, keyExt ractor);
458 // Exact matches are complex
459 if (*boundingCharacter == c)
460 return Complex;
461 bool isEndOfRange = ((boundingCharacter - complexCodePathRanges) % 2);
462 if (*boundingCharacter < c) {
463 // Determine if we are in a range or out
464 if (!isEndOfRange)
465 return Complex;
498 continue; 466 continue;
499 if (c <= 0xFE0F) 467 }
500 return Complex; 468 ASSERT(*boundingCharacter > c);
501 469 // Determine if we are in a range or out - opposite condition to above
502 if (c < 0xFE20) // U+FE20 through U+FE2F Combining half marks 470 if (isEndOfRange)
503 continue;
504 if (c <= 0xFE2F)
505 return Complex; 471 return Complex;
506 } 472 }
473
507 return result; 474 return result;
508 } 475 }
509 476
510 bool Font::isCJKIdeograph(UChar32 c) 477 bool Font::isCJKIdeograph(UChar32 c)
511 { 478 {
512 // The basic CJK Unified Ideographs block. 479 // The basic CJK Unified Ideographs block.
513 if (c >= 0x4E00 && c <= 0x9FFF) 480 if (c >= 0x4E00 && c <= 0x9FFF)
514 return true; 481 return true;
515 482
516 // CJK Unified Ideographs Extension A. 483 // CJK Unified Ideographs Extension A.
517 if (c >= 0x3400 && c <= 0x4DBF) 484 if (c >= 0x3400 && c <= 0x4DBF)
518 return true; 485 return true;
519 486
520 // CJK Radicals Supplement. 487 // CJK Radicals Supplement and Kangxi Radicals.
521 if (c >= 0x2E80 && c <= 0x2EFF) 488 if (c >= 0x2E80 && c <= 0x2FDF)
522 return true;
523
524 // Kangxi Radicals.
525 if (c >= 0x2F00 && c <= 0x2FDF)
526 return true; 489 return true;
527 490
528 // CJK Strokes. 491 // CJK Strokes.
529 if (c >= 0x31C0 && c <= 0x31EF) 492 if (c >= 0x31C0 && c <= 0x31EF)
530 return true; 493 return true;
531 494
532 // CJK Compatibility Ideographs. 495 // CJK Compatibility Ideographs.
533 if (c >= 0xF900 && c <= 0xFAFF) 496 if (c >= 0xF900 && c <= 0xFAFF)
534 return true; 497 return true;
535 498
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 533
571 if (c >= 0x2156 && c <= 0x215A) 534 if (c >= 0x2156 && c <= 0x215A)
572 return true; 535 return true;
573 536
574 if (c >= 0x2160 && c <= 0x216B) 537 if (c >= 0x2160 && c <= 0x216B)
575 return true; 538 return true;
576 539
577 if (c >= 0x2170 && c <= 0x217B) 540 if (c >= 0x2170 && c <= 0x217B)
578 return true; 541 return true;
579 542
580 if ((c == 0x217F) || (c == 0x2189) || (c == 0x2307) || (c == 0x2312) || (c = = 0x23BE) || (c == 0x23BF)) 543 if ((c == 0x217F) || (c == 0x2189) || (c == 0x2307) || (c == 0x2312))
581 return true; 544 return true;
582 545
583 if (c >= 0x23C0 && c <= 0x23CC) 546 if (c >= 0x23BE && c <= 0x23CC)
584 return true; 547 return true;
585 548
586 if ((c == 0x23CE) || (c == 0x2423)) 549 if ((c == 0x23CE) || (c == 0x2423))
587 return true; 550 return true;
588 551
589 if (c >= 0x2460 && c <= 0x2492) 552 if (c >= 0x2460 && c <= 0x2492)
590 return true; 553 return true;
591 554
592 if (c >= 0x249C && c <= 0x24FF) 555 if (c >= 0x249C && c <= 0x24FF)
593 return true; 556 return true;
(...skipping 30 matching lines...) Expand all
624 587
625 if ((c == 0x26A0) || (c == 0x26BD) || (c == 0x26BE) || (c == 0x2713) || (c = = 0x271A) || (c == 0x273F) || (c == 0x2740) || (c == 0x2756)) 588 if ((c == 0x26A0) || (c == 0x26BD) || (c == 0x26BE) || (c == 0x2713) || (c = = 0x271A) || (c == 0x273F) || (c == 0x2740) || (c == 0x2756))
626 return true; 589 return true;
627 590
628 if (c >= 0x2776 && c <= 0x277F) 591 if (c >= 0x2776 && c <= 0x277F)
629 return true; 592 return true;
630 593
631 if (c == 0x2B1A) 594 if (c == 0x2B1A)
632 return true; 595 return true;
633 596
634 // Ideographic Description Characters. 597 // Ideographic Description Characters, with CJK Symbols and Punctuation, exc luding 0x3030.
635 if (c >= 0x2FF0 && c <= 0x2FFF) 598 // Then Hiragana 0x3040 .. 0x309F, Katakana 0x30A0 .. 0x30FF, Bopomofo 0x310 0 .. 0x312F
636 return true; 599 if (c >= 0x2FF0 && c < 0x3030)
637
638 // CJK Symbols and Punctuation, excluding 0x3030.
639 if (c >= 0x3000 && c < 0x3030)
640 return true; 600 return true;
641 601
642 if (c > 0x3030 && c <= 0x303F) 602 if (c > 0x3030 && c <= 0x312F)
643 return true; 603 return true;
644 604
645 // Hiragana 605 // More Bopomofo and Bopomofo Extended 0x31A0 .. 0x31BF
646 if (c >= 0x3040 && c <= 0x309F) 606 if (c >= 0x3190 && c <= 0x31BF)
647 return true;
648
649 // Katakana
650 if (c >= 0x30A0 && c <= 0x30FF)
651 return true;
652
653 // Bopomofo
654 if (c >= 0x3100 && c <= 0x312F)
655 return true;
656
657 if (c >= 0x3190 && c <= 0x319F)
658 return true;
659
660 // Bopomofo Extended
661 if (c >= 0x31A0 && c <= 0x31BF)
662 return true; 607 return true;
663 608
664 // Enclosed CJK Letters and Months. 609 // Enclosed CJK Letters and Months (0x3200 .. 0x32FF).
665 if (c >= 0x3200 && c <= 0x32FF) 610 // CJK Compatibility (0x3300 .. 0x33FF).
666 return true; 611 if (c >= 0x3200 && c <= 0x33FF)
667
668 // CJK Compatibility.
669 if (c >= 0x3300 && c <= 0x33FF)
670 return true; 612 return true;
671 613
672 if (c >= 0xF860 && c <= 0xF862) 614 if (c >= 0xF860 && c <= 0xF862)
673 return true; 615 return true;
674 616
675 // CJK Compatibility Forms. 617 // CJK Compatibility Forms.
676 if (c >= 0xFE30 && c <= 0xFE4F) 618 if (c >= 0xFE30 && c <= 0xFE4F)
677 return true; 619 return true;
678 620
679 if ((c == 0xFE10) || (c == 0xFE11) || (c == 0xFE12) || (c == 0xFE19)) 621 if ((c == 0xFE10) || (c == 0xFE11) || (c == 0xFE12) || (c == 0xFE19))
(...skipping 16 matching lines...) Expand all
696 638
697 if (c >= 0x1F130 && c <= 0x1F149) 639 if (c >= 0x1F130 && c <= 0x1F149)
698 return true; 640 return true;
699 641
700 if (c >= 0x1F150 && c <= 0x1F169) 642 if (c >= 0x1F150 && c <= 0x1F169)
701 return true; 643 return true;
702 644
703 if (c >= 0x1F170 && c <= 0x1F189) 645 if (c >= 0x1F170 && c <= 0x1F189)
704 return true; 646 return true;
705 647
706 if (c >= 0x1F200 && c <= 0x1F6F) 648 if (c >= 0x1F200 && c <= 0x1F6FF)
707 return true; 649 return true;
708 650
709 return isCJKIdeograph(c); 651 return isCJKIdeograph(c);
710 } 652 }
711 653
712 unsigned Font::expansionOpportunityCount(const LChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion) 654 unsigned Font::expansionOpportunityCount(const LChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion)
713 { 655 {
714 unsigned count = 0; 656 unsigned count = 0;
715 if (direction == LTR) { 657 if (direction == LTR) {
716 for (size_t i = 0; i < length; ++i) { 658 for (size_t i = 0; i < length; ++i) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 732
791 // Additional word-separator characters listed in CSS Text Level 3 Editor's Draft 3 November 2010. 733 // Additional word-separator characters listed in CSS Text Level 3 Editor's Draft 3 November 2010.
792 if (c == ethiopicWordspace || c == aegeanWordSeparatorLine || c == aegeanWor dSeparatorDot 734 if (c == ethiopicWordspace || c == aegeanWordSeparatorLine || c == aegeanWor dSeparatorDot
793 || c == ugariticWordDivider || c == tibetanMarkIntersyllabicTsheg || c = = tibetanMarkDelimiterTshegBstar) 735 || c == ugariticWordDivider || c == tibetanMarkIntersyllabicTsheg || c = = tibetanMarkDelimiterTshegBstar)
794 return false; 736 return false;
795 737
796 return true; 738 return true;
797 } 739 }
798 740
799 } 741 }
OLDNEW
« no previous file with comments | « no previous file | Source/core/platform/graphics/FontTest.cpp » ('j') | Source/core/platform/graphics/FontTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698