TextDirection determineParagraphDirectionality(const TextRun& textRun, bool* hasStrongDirectionality = 0) { BidiResolver<TextRunIterator, BidiCharacterRun> resolver; resolver.setStatus(BidiStatus(LTR, false)); resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0)); return resolver.determineParagraphDirectionality(hasStrongDirectionality); }
TextDirection directionForRun(TextRun& run, bool& hasStrongDirectionality) { BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride())); bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); return bidiResolver.determineParagraphDirectionality(&hasStrongDirectionality); }
// Almost the same as determineDirectionality in core/html/HTMLElement.cpp, but // that one uses a "plain" TextRunIterator (which only checks for '\n'). static TextDirection determineDirectionality(const String& value, bool& hasStrongDirectionality) { TextRun run(value); BidiResolver<VTTTextRunIterator, BidiCharacterRun> bidiResolver; bidiResolver.setStatus(BidiStatus(LTR, false)); bidiResolver.setPositionIgnoringNestedIsolates(VTTTextRunIterator(&run, 0)); return bidiResolver.determineParagraphDirectionality(&hasStrongDirectionality); }
TEST(BidiResolver, Basic) { bool hasStrongDirectionality; String value("foo"); TextRun run(value); BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride())); bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); TextDirection direction = bidiResolver.determineParagraphDirectionality(&hasStrongDirectionality); EXPECT_TRUE(hasStrongDirectionality); EXPECT_EQ(LTR, direction); }
TextDirection directionForRun(TextRun& run, bool* hasStrongDirectionality) { if (!hasStrongDirectionality) { // 8bit is Latin-1 and therefore is always LTR. if (run.is8Bit()) return LTR; // length == 1 for more than 90% of cases of width() for CJK text. if (run.length() == 1 && U16_IS_SINGLE(run.characters16()[0])) return directionForCharacter(run.characters16()[0]); } BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride())); bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); return bidiResolver.determineParagraphDirectionality(hasStrongDirectionality); }