summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-28 00:31:52 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-28 00:31:52 +0000
commit9c5cf9b51fc657345d60f0e240024ce830906bee (patch)
treecd43b4791d0c1fd4206dfa0196d04cd3add96d21 /ppapi/tests
parent8321f97faea7ebcfe6c25aab0539e8fb24599820 (diff)
downloadchromium_src-9c5cf9b51fc657345d60f0e240024ce830906bee.zip
chromium_src-9c5cf9b51fc657345d60f0e240024ce830906bee.tar.gz
chromium_src-9c5cf9b51fc657345d60f0e240024ce830906bee.tar.bz2
Implement right-to-left text rendering in Pepper.
TEST=included BUG=http://crbug.com/134394 Review URL: https://chromiumcodereview.appspot.com/10658037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144623 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_browser_font.cc90
-rw-r--r--ppapi/tests/test_browser_font.h2
2 files changed, 90 insertions, 2 deletions
diff --git a/ppapi/tests/test_browser_font.cc b/ppapi/tests/test_browser_font.cc
index 9f3a2e0..8fc4104 100644
--- a/ppapi/tests/test_browser_font.cc
+++ b/ppapi/tests/test_browser_font.cc
@@ -4,8 +4,6 @@
#include "ppapi/tests/test_browser_font.h"
-#include <stdio.h>// ERASEME
-
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
#include "ppapi/cpp/image_data.h"
@@ -20,7 +18,11 @@ bool TestBrowserFont::Init() {
void TestBrowserFont::RunTests(const std::string& filter) {
RUN_TEST(FontFamilies, filter);
RUN_TEST(Measure, filter);
+ RUN_TEST(MeasureRTL, filter);
RUN_TEST(CharPos, filter);
+ // This test is disabled. It doesn't currently pass. See the
+ // CharacterOffsetForPixel API.
+ //RUN_TEST(CharPosRTL, filter);
RUN_TEST(Draw, filter);
}
@@ -54,6 +56,48 @@ std::string TestBrowserFont::TestMeasure() {
PASS();
}
+std::string TestBrowserFont::TestMeasureRTL() {
+ pp::BrowserFontDescription desc;
+ pp::BrowserFont_Trusted font(instance_, desc);
+
+ // Mixed string, two chars of LTR, two of RTL, then two of LTR.
+ // Note this is in UTF-8 so has more than 6 bytes.
+ std::string mixed("AB\xd7\x94\xd7\x97ZZ");
+ const int kNumChars = 6;
+ pp::BrowserFontTextRun run(mixed);
+
+ // Note that since this is UTF-8, the two RTL chars are two bytes each.
+ int32_t len[kNumChars];
+ len[0] = font.PixelOffsetForCharacter(run, 0);
+ len[1] = font.PixelOffsetForCharacter(run, 1);
+ len[2] = font.PixelOffsetForCharacter(run, 2);
+ len[3] = font.PixelOffsetForCharacter(run, 3);
+ len[4] = font.PixelOffsetForCharacter(run, 4);
+ len[5] = font.PixelOffsetForCharacter(run, 5);
+
+ // First three chars should be increasing.
+ ASSERT_TRUE(len[0] >= 0);
+ ASSERT_TRUE(len[1] > len[0]);
+ ASSERT_TRUE(len[3] > len[1]);
+ ASSERT_TRUE(len[2] > len[3]);
+ ASSERT_TRUE(len[4] > len[2]);
+ ASSERT_TRUE(len[5] > len[4]);
+
+ // Test the same sequence with force LTR. The offsets should appear in
+ // sequence.
+ pp::BrowserFontTextRun forced_run(mixed, false, true);
+ len[0] = font.PixelOffsetForCharacter(forced_run, 0);
+ len[1] = font.PixelOffsetForCharacter(forced_run, 1);
+ len[2] = font.PixelOffsetForCharacter(forced_run, 2);
+ len[3] = font.PixelOffsetForCharacter(forced_run, 3);
+ len[4] = font.PixelOffsetForCharacter(forced_run, 4);
+ len[5] = font.PixelOffsetForCharacter(forced_run, 5);
+ for (int i = 1; i < kNumChars; i++)
+ ASSERT_TRUE(len[i] > len[i - 1]);
+
+ PASS();
+}
+
// Tests that the character/pixel offset functions correctly round-trip.
std::string TestBrowserFont::TestCharPos() {
pp::BrowserFontDescription desc;
@@ -71,6 +115,48 @@ std::string TestBrowserFont::TestCharPos() {
PASS();
}
+// Tests that we can get character positions in a mixed LTR/RTL run.
+std::string TestBrowserFont::TestCharPosRTL() {
+ pp::BrowserFontDescription desc;
+ pp::BrowserFont_Trusted font(instance_, desc);
+
+ // Mixed string, two chars of LTR, two of RTL, than two of LTR.
+ // Note this is in UTF-8 so has more than 6 bytes.
+ std::string mixed("AB\xd7\x94\xd7\x97ZZ");
+
+ pp::BrowserFontTextRun run(mixed);
+ static const int kNumChars = 6;
+ int expected_char_sequence[kNumChars] = { 0, 1, 3, 2, 4, 5 };
+
+ // Check that the characters appear in the order we expect.
+ int pixel_width = font.MeasureText(pp::BrowserFontTextRun(mixed));
+ int last_sequence = 0; // Index into expected_char_sequence.
+ for (int x = 0; x < pixel_width; x++) {
+ int cur_char = font.CharacterOffsetForPixel(run, x);
+ if (cur_char != expected_char_sequence[last_sequence]) {
+ // This pixel has a different character. It should be the next one in
+ // the sequence for it to be correct.
+ last_sequence++;
+ ASSERT_TRUE(last_sequence < kNumChars);
+ ASSERT_TRUE(cur_char == expected_char_sequence[last_sequence]);
+ }
+ }
+
+ // Try the same string with force LTR. The characters should all appear in
+ // sequence.
+ pp::BrowserFontTextRun forced_run(mixed, false, true);
+ int last_forced_char = 0; // Char index into the forced sequence.
+ for (int x = 0; x < pixel_width; x++) {
+ int cur_char = font.CharacterOffsetForPixel(forced_run, x);
+ if (cur_char != last_forced_char) {
+ last_forced_char++;
+ ASSERT_TRUE(cur_char == last_forced_char);
+ }
+ }
+
+ PASS();
+}
+
// Tests that drawing some text produces "some" output.
std::string TestBrowserFont::TestDraw() {
pp::BrowserFontDescription desc;
diff --git a/ppapi/tests/test_browser_font.h b/ppapi/tests/test_browser_font.h
index eba1c7e..c166212 100644
--- a/ppapi/tests/test_browser_font.h
+++ b/ppapi/tests/test_browser_font.h
@@ -18,7 +18,9 @@ class TestBrowserFont : public TestCase {
private:
std::string TestFontFamilies();
std::string TestMeasure();
+ std::string TestMeasureRTL();
std::string TestCharPos();
+ std::string TestCharPosRTL();
std::string TestDraw();
};