| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 #include "platform/text/BidiResolver.h" | 33 #include "platform/text/BidiResolver.h" |
| 34 #include "platform/text/TextRunIterator.h" | 34 #include "platform/text/TextRunIterator.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 TextDirection directionForRun(TextRun& run, bool* hasStrongDirectionality) { | 38 TextDirection directionForRun(TextRun& run, bool* hasStrongDirectionality) { |
| 39 if (!hasStrongDirectionality) { | 39 if (!hasStrongDirectionality) { |
| 40 // 8bit is Latin-1 and therefore is always LTR. | 40 // 8bit is Latin-1 and therefore is always LTR. |
| 41 if (run.is8Bit()) | 41 if (run.is8Bit()) |
| 42 return LTR; | 42 return TextDirection::Ltr; |
| 43 | 43 |
| 44 // length == 1 for more than 90% of cases of width() for CJK text. | 44 // length == 1 for more than 90% of cases of width() for CJK text. |
| 45 if (run.length() == 1 && U16_IS_SINGLE(run.characters16()[0])) | 45 if (run.length() == 1 && U16_IS_SINGLE(run.characters16()[0])) |
| 46 return directionForCharacter(run.characters16()[0]); | 46 return directionForCharacter(run.characters16()[0]); |
| 47 } | 47 } |
| 48 | 48 |
| 49 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; | 49 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; |
| 50 bidiResolver.setStatus( | 50 bidiResolver.setStatus( |
| 51 BidiStatus(run.direction(), run.directionalOverride())); | 51 BidiStatus(run.direction(), run.directionalOverride())); |
| 52 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); | 52 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); |
| 53 return bidiResolver.determineDirectionality(hasStrongDirectionality); | 53 return bidiResolver.determineDirectionality(hasStrongDirectionality); |
| 54 } | 54 } |
| 55 | 55 |
| 56 TextDirection determineDirectionality(const String& value, | 56 TextDirection determineDirectionality(const String& value, |
| 57 bool* hasStrongDirectionality) { | 57 bool* hasStrongDirectionality) { |
| 58 TextRun run(value); | 58 TextRun run(value); |
| 59 return directionForRun(run, hasStrongDirectionality); | 59 return directionForRun(run, hasStrongDirectionality); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TextRun textRunWithDirectionality(const String& value, | 62 TextRun textRunWithDirectionality(const String& value, |
| 63 bool* hasStrongDirectionality) { | 63 bool* hasStrongDirectionality) { |
| 64 TextRun run(value); | 64 TextRun run(value); |
| 65 TextDirection direction = directionForRun(run, hasStrongDirectionality); | 65 TextDirection direction = directionForRun(run, hasStrongDirectionality); |
| 66 if (hasStrongDirectionality) | 66 if (hasStrongDirectionality) |
| 67 run.setDirection(direction); | 67 run.setDirection(direction); |
| 68 return run; | 68 return run; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |