Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "platform/fonts/shaping/CachingWordShaper.h" | 6 #include "platform/fonts/shaping/CachingWordShaper.h" |
| 7 | 7 |
| 8 #include "platform/fonts/FontCache.h" | 8 #include "platform/fonts/FontCache.h" |
| 9 #include "platform/fonts/GlyphBuffer.h" | 9 #include "platform/fonts/GlyphBuffer.h" |
| 10 #include "platform/fonts/shaping/CachingWordShapeIterator.h" | 10 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 ASSERT_GT(shaper.width(&font, textRun, nullptr, &glyphBounds), 0); | 173 ASSERT_GT(shaper.width(&font, textRun, nullptr, &glyphBounds), 0); |
| 174 | 174 |
| 175 GlyphBuffer glyphBuffer; | 175 GlyphBuffer glyphBuffer; |
| 176 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 8); | 176 shaper.fillGlyphBuffer(&font, textRun, fallbackFonts, &glyphBuffer, 0, 8); |
| 177 | 177 |
| 178 FloatPoint point; | 178 FloatPoint point; |
| 179 int height = 16; | 179 int height = 16; |
| 180 shaper.selectionRect(&font, textRun, point, height, 0, 8); | 180 shaper.selectionRect(&font, textRun, point, height, 0, 8); |
| 181 } | 181 } |
| 182 | 182 |
| 183 TEST_F(CachingWordShaperTest, SegmentCJKByCharacter) | |
| 184 { | |
| 185 const UChar str[] = { | |
| 186 0x56FD, 0x56FD, // CJK Unified Ideograph | |
| 187 'a', 'b', | |
| 188 0x56FD, // CJK Unified Ideograph | |
| 189 'x', 'y', 'z', | |
| 190 0x3042, // HIRAGANA LETTER A | |
| 191 0x56FD, // CJK Unified Ideograph | |
| 192 0x0 | |
| 193 }; | |
| 194 TextRun textRun(str, 10); | |
| 195 | |
| 196 RefPtr<ShapeResult> wordResult; | |
| 197 CachingWordShapeIterator iterator(cache.get(), textRun, &font); | |
| 198 | |
| 199 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 200 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 201 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 202 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 203 | |
| 204 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 205 EXPECT_EQ(2u, wordResult->numCharacters()); | |
| 206 | |
| 207 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 208 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 209 | |
| 210 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 211 EXPECT_EQ(3u, wordResult->numCharacters()); | |
| 212 | |
| 213 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 214 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 215 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 216 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 217 | |
| 218 ASSERT_FALSE(iterator.next(&wordResult)); | |
| 219 } | |
| 220 | |
| 221 TEST_F(CachingWordShaperTest, SegmentCJKAndCommon) | |
| 222 { | |
| 223 const UChar str[] = { | |
| 224 'a', 'b', | |
| 225 0xFF08, // FULLWIDTH LEFT PARENTHESIS (script=common) | |
| 226 0x56FD, // CJK Unified Ideograph | |
| 227 0x56FD, // CJK Unified Ideograph | |
| 228 0x56FD, // CJK Unified Ideograph | |
| 229 0x3002, // IDEOGRAPHIC FULL STOP (script=common) | |
| 230 0x0 | |
| 231 }; | |
| 232 TextRun textRun(str, 7); | |
| 233 | |
| 234 RefPtr<ShapeResult> wordResult; | |
| 235 CachingWordShapeIterator iterator(cache.get(), textRun, &font); | |
| 236 | |
| 237 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 238 EXPECT_EQ(2u, wordResult->numCharacters()); | |
| 239 | |
| 240 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 241 EXPECT_EQ(2u, wordResult->numCharacters()); | |
| 242 | |
| 243 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 244 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 245 | |
| 246 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 247 EXPECT_EQ(2u, wordResult->numCharacters()); | |
| 248 | |
| 249 ASSERT_FALSE(iterator.next(&wordResult)); | |
| 250 } | |
| 251 | |
| 252 TEST_F(CachingWordShaperTest, SegmentCJKAndInherit) | |
| 253 { | |
| 254 const UChar str[] = { | |
| 255 0x304B, // HIRAGANA LETTER KA | |
| 256 0x304B, // HIRAGANA LETTER KA | |
| 257 0x3009, // COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK | |
| 258 0x304B, // HIRAGANA LETTER KA | |
| 259 0x0 | |
| 260 }; | |
| 261 TextRun textRun(str, 4); | |
| 262 | |
| 263 RefPtr<ShapeResult> wordResult; | |
| 264 CachingWordShapeIterator iterator(cache.get(), textRun, &font); | |
| 265 | |
| 266 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 267 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 268 | |
| 269 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 270 EXPECT_EQ(2u, wordResult->numCharacters()); | |
| 271 | |
| 272 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 273 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 274 | |
| 275 ASSERT_FALSE(iterator.next(&wordResult)); | |
| 276 } | |
| 277 | |
| 278 TEST_F(CachingWordShaperTest, SegmentCJKAndNonCJKCommon) | |
| 279 { | |
| 280 const UChar str[] = { | |
| 281 0x56FD, // CJK Unified Ideograph | |
| 282 ' ', | |
| 283 0x0 | |
| 284 }; | |
| 285 TextRun textRun(str, 2); | |
| 286 | |
| 287 RefPtr<ShapeResult> wordResult; | |
| 288 CachingWordShapeIterator iterator(cache.get(), textRun, &font); | |
| 289 | |
| 290 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 291 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 292 | |
| 293 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 294 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 295 | |
| 296 ASSERT_FALSE(iterator.next(&wordResult)); | |
| 297 } | |
| 298 | |
| 299 TEST_F(CachingWordShaperTest, SegmentCJKCommonAndNonCJK) | |
|
drott
2015/12/21 14:57:41
Could you add one test with only COMMON, no actual
kojii
2015/12/21 15:34:53
Done.
| |
| 300 { | |
| 301 const UChar str[] = { | |
| 302 0xFF08, // FULLWIDTH LEFT PARENTHESIS (script=common) | |
| 303 'a', 'b', | |
| 304 0x0 | |
| 305 }; | |
| 306 TextRun textRun(str, 3); | |
| 307 | |
| 308 RefPtr<ShapeResult> wordResult; | |
| 309 CachingWordShapeIterator iterator(cache.get(), textRun, &font); | |
| 310 | |
| 311 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 312 EXPECT_EQ(1u, wordResult->numCharacters()); | |
| 313 | |
| 314 ASSERT_TRUE(iterator.next(&wordResult)); | |
| 315 EXPECT_EQ(2u, wordResult->numCharacters()); | |
| 316 | |
| 317 ASSERT_FALSE(iterator.next(&wordResult)); | |
| 318 } | |
| 319 | |
| 183 TEST_F(CachingWordShaperTest, TextOrientationFallbackShouldNotInFallbackList) | 320 TEST_F(CachingWordShaperTest, TextOrientationFallbackShouldNotInFallbackList) |
| 184 { | 321 { |
| 185 const UChar str[] = { | 322 const UChar str[] = { |
| 186 'A', // code point for verticalRightOrientationFontData() | 323 'A', // code point for verticalRightOrientationFontData() |
| 187 // Ideally we'd like to test uprightOrientationFontData() too | 324 // Ideally we'd like to test uprightOrientationFontData() too |
| 188 // using code point such as U+3042, but it'd fallback to system | 325 // using code point such as U+3042, but it'd fallback to system |
| 189 // fonts as the glyph is missing. | 326 // fonts as the glyph is missing. |
| 190 0x0 | 327 0x0 |
| 191 }; | 328 }; |
| 192 TextRun textRun(str, 1); | 329 TextRun textRun(str, 1); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 216 float periodsAndSpacesWidth = shaper.width(&font, periodsAndSpaces, nullptr, &periodsAndSpacesGlyphBounds); | 353 float periodsAndSpacesWidth = shaper.width(&font, periodsAndSpaces, nullptr, &periodsAndSpacesGlyphBounds); |
| 217 | 354 |
| 218 // The total width of periods and spaces should be longer than the width of periods alone. | 355 // The total width of periods and spaces should be longer than the width of periods alone. |
| 219 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); | 356 ASSERT_GT(periodsAndSpacesWidth, periodsWidth); |
| 220 | 357 |
| 221 // The glyph bounds of periods and spaces should be longer than the glyph bo unds of periods alone. | 358 // The glyph bounds of periods and spaces should be longer than the glyph bo unds of periods alone. |
| 222 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); | 359 ASSERT_GT(periodsAndSpacesGlyphBounds.width(), periodsGlyphBounds.width()); |
| 223 } | 360 } |
| 224 | 361 |
| 225 } // namespace blink | 362 } // namespace blink |
| OLD | NEW |