diff options
author | Igor Viarheichyk <viarheichyk@google.com> | 2017-07-06 15:23:51 -0700 |
---|---|---|
committer | Igor Viarheichyk <viarheichyk@google.com> | 2017-07-06 15:41:47 -0700 |
commit | 4fb6516a55604bfbae2e8b1411e1bdd27df1866f (patch) | |
tree | 674a09589c4a845ca4bea340335e8eb683a3ee65 /tools/aapt2/compile/Pseudolocalizer.cpp | |
parent | f02beb06daf49a2113881484579a36249f5a19a1 (diff) |
Improved word break for BiDi pseudolocalizer.
Characted sequences \n and \t are now treated as word separators
by BiDi pseudolocalizer. This solves issues when text rendering
engine breaks a line in the middle of a text chunk marked with
RLM+RLO and PDF+RLM sequences.
Bug:34064580
Change-Id: I52e6018785fae25479fa167440f24c534b0e3253
Fixes:34064580
Test: make aapt2_tests
Test: Run aapt2_tests binary
Diffstat (limited to 'tools/aapt2/compile/Pseudolocalizer.cpp')
-rw-r--r-- | tools/aapt2/compile/Pseudolocalizer.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tools/aapt2/compile/Pseudolocalizer.cpp b/tools/aapt2/compile/Pseudolocalizer.cpp index 15a3d8c289e2..3a515fad3202 100644 --- a/tools/aapt2/compile/Pseudolocalizer.cpp +++ b/tools/aapt2/compile/Pseudolocalizer.cpp @@ -445,9 +445,15 @@ std::string PseudoMethodBidi::Text(const StringPiece& source) { std::string result; bool lastspace = true; bool space = true; + bool escape = false; + const char ESCAPE_CHAR = '\\'; for (size_t i = 0; i < source.size(); i++) { char c = s[i]; - space = isspace(c); + if (!escape && c == ESCAPE_CHAR) { + escape = true; + continue; + } + space = (!escape && isspace(c)) || (escape && (c == 'n' || c == 't')); if (lastspace && !space) { // Word start result += kRlm + kRlo; @@ -456,6 +462,10 @@ std::string PseudoMethodBidi::Text(const StringPiece& source) { result += kPdf + kRlm; } lastspace = space; + if (escape) { + result.append(&ESCAPE_CHAR, 1); + escape=false; + } result.append(&c, 1); } if (!lastspace) { |