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

Side by Side Diff: Source/platform/text/BidiResolver.h

Issue 83443002: Handle surrogates in BidiResolver::determineParagraphDirectionality (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix scoping of String in unittest; rebase Created 7 years 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 | « no previous file | Source/platform/text/BidiResolverTest.cpp » ('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 (C) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008 Apple Inc. All right reserved. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008 Apple Inc. All right reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 template <class Iterator, class Run> 541 template <class Iterator, class Run>
542 TextDirection BidiResolver<Iterator, Run>::determineParagraphDirectionality(bool * hasStrongDirectionality) 542 TextDirection BidiResolver<Iterator, Run>::determineParagraphDirectionality(bool * hasStrongDirectionality)
543 { 543 {
544 while (!m_current.atEnd()) { 544 while (!m_current.atEnd()) {
545 if (inIsolate()) { 545 if (inIsolate()) {
546 increment(); 546 increment();
547 continue; 547 continue;
548 } 548 }
549 if (m_current.atParagraphSeparator()) 549 if (m_current.atParagraphSeparator())
550 break; 550 break;
551 if (UChar current = m_current.current()) { 551 UChar32 current = m_current.current();
552 WTF::Unicode::Direction charDirection = WTF::Unicode::direction(curr ent); 552 if (UNLIKELY(U16_IS_SURROGATE(current))) {
553 if (charDirection == WTF::Unicode::LeftToRight) { 553 increment();
554 if (hasStrongDirectionality) 554 // If this not the high part of the surrogate pair, then drop it and move to the next.
555 *hasStrongDirectionality = true; 555 if (!U16_IS_SURROGATE_LEAD(current))
556 return LTR; 556 continue;
557 } 557 UChar high = static_cast<UChar>(current);
558 if (charDirection == WTF::Unicode::RightToLeft || charDirection == W TF::Unicode::RightToLeftArabic) { 558 if (m_current.atEnd())
559 if (hasStrongDirectionality) 559 continue;
560 *hasStrongDirectionality = true; 560 UChar low = m_current.current();
561 return RTL; 561 // Verify the low part. If invalid, then assume an invalid surrogate pair and retry.
562 } 562 if (!U16_IS_TRAIL(low))
563 continue;
564 current = U16_GET_SUPPLEMENTARY(high, low);
565 }
566 WTF::Unicode::Direction charDirection = WTF::Unicode::direction(current) ;
567 if (charDirection == WTF::Unicode::LeftToRight) {
568 if (hasStrongDirectionality)
569 *hasStrongDirectionality = true;
570 return LTR;
571 }
572 if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF:: Unicode::RightToLeftArabic) {
573 if (hasStrongDirectionality)
574 *hasStrongDirectionality = true;
575 return RTL;
563 } 576 }
564 increment(); 577 increment();
565 } 578 }
566 if (hasStrongDirectionality) 579 if (hasStrongDirectionality)
567 *hasStrongDirectionality = false; 580 *hasStrongDirectionality = false;
568 return LTR; 581 return LTR;
569 } 582 }
570 583
571 template <class Iterator, class Run> 584 template <class Iterator, class Run>
572 void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, Vis ualDirectionOverride override, bool hardLineBreak) 585 void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, Vis ualDirectionOverride override, bool hardLineBreak)
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 template<class Iterator, class Run> 994 template<class Iterator, class Run>
982 MidpointState<Iterator> BidiResolver<Iterator, Run>::midpointStateForIsolatedRun (Run* run) 995 MidpointState<Iterator> BidiResolver<Iterator, Run>::midpointStateForIsolatedRun (Run* run)
983 { 996 {
984 return m_midpointStateForIsolatedRun.take(run); 997 return m_midpointStateForIsolatedRun.take(run);
985 } 998 }
986 999
987 1000
988 } // namespace WebCore 1001 } // namespace WebCore
989 1002
990 #endif // BidiResolver_h 1003 #endif // BidiResolver_h
OLDNEW
« no previous file with comments | « no previous file | Source/platform/text/BidiResolverTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698