diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-12-21 15:21:32 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-12-21 15:21:32 +0000 |
commit | 419f43348ab6c9226b82490d41c736230ae3bf41 (patch) | |
tree | 4a1180085a719d69a1efa03b74e647ee2fefbefb | |
parent | ef279d36ca176d3669b1623aa4692f469ec52a58 (diff) |
add SkUnichar_IsVariationSelector()
git-svn-id: http://skia.googlecode.com/svn/trunk@2915 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gyp/tests.gyp | 1 | ||||
-rw-r--r-- | include/core/SkUtils.h | 15 | ||||
-rw-r--r-- | tests/UnicodeTest.cpp | 45 |
3 files changed, 61 insertions, 0 deletions
diff --git a/gyp/tests.gyp b/gyp/tests.gyp index acec8231ec..e47bec6936 100644 --- a/gyp/tests.gyp +++ b/gyp/tests.gyp @@ -64,6 +64,7 @@ '../tests/Test.h', '../tests/TestSize.cpp', '../tests/ToUnicode.cpp', + '../tests/UnicodeTest.cpp', '../tests/UtilsTest.cpp', '../tests/WArrayTest.cpp', '../tests/WritePixelsTest.cpp', diff --git a/include/core/SkUtils.h b/include/core/SkUtils.h index 2e2010733f..84528b205b 100644 --- a/include/core/SkUtils.h +++ b/include/core/SkUtils.h @@ -91,6 +91,21 @@ size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL); size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues, char utf8[] = NULL); +static bool SkUnichar_IsVariationSelector(SkUnichar uni) { +/* The 'true' ranges are: + * 0x180B <= uni <= 0x180D + * 0xFE00 <= uni <= 0xFE0F + * 0xE0100 <= uni <= 0xE01EF + */ + if (uni < 0x180B || uni > 0xE01EF) { + return false; + } + if ((uni > 0x180D && uni < 0xFE00) || (uni > 0xFE0F && uni < 0xE0100)) { + return false; + } + return true; +} + /////////////////////////////////////////////////////////////////////////////// class SkAutoTrace { diff --git a/tests/UnicodeTest.cpp b/tests/UnicodeTest.cpp new file mode 100644 index 0000000000..602ff81431 --- /dev/null +++ b/tests/UnicodeTest.cpp @@ -0,0 +1,45 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "Test.h" +#include "SkUtils.h" + +// Unicode Variation Selector ranges: inclusive +#define UVS_MIN0 0x180B +#define UVS_MAX0 0x180D +#define UVS_MIN1 0xFE00 +#define UVS_MAX1 0xFE0F +#define UVS_MIN2 0xE0100 +#define UVS_MAX2 0xE01EF + +static bool isUVS(SkUnichar uni) { + return (uni >= UVS_MIN0 && uni <= UVS_MAX0) || + (uni >= UVS_MIN1 && uni <= UVS_MAX1) || + (uni >= UVS_MIN2 && uni <= UVS_MAX2); +} + +static void test_uvs(skiatest::Reporter* reporter) { + // [min, max], [min, max] ... inclusive + static const SkUnichar gRanges[] = { + UVS_MIN0, UVS_MAX0, UVS_MIN1, UVS_MAX1, UVS_MIN2, UVS_MAX2 + }; + + for (size_t i = 0; i < SK_ARRAY_COUNT(gRanges); i += 2) { + for (SkUnichar uni = gRanges[i] - 8; uni <= gRanges[i+1] + 8; ++uni) { + bool uvs0 = isUVS(uni); + bool uvs1 = SkUnichar_IsVariationSelector(uni); + REPORTER_ASSERT(reporter, uvs0 == uvs1); + } + } +} + +static void TestUnicode(skiatest::Reporter* reporter) { + test_uvs(reporter); +} + +#include "TestClassDef.h" +DEFINE_TESTCLASS("Unicode", TestUnicodeClass, TestUnicode) |