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 "platform/fonts/shaping/HarfBuzzShaper.h" | 5 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
6 | 6 |
7 #include "platform/fonts/Font.h" | 7 #include "platform/fonts/Font.h" |
8 #include "platform/fonts/FontCache.h" | 8 #include "platform/fonts/FontCache.h" |
9 #include "platform/fonts/shaping/ShapeResultTestInfo.h" | 9 #include "platform/fonts/shaping/ShapeResultTestInfo.h" |
10 #include "platform/text/TextRun.h" | 10 #include "platform/text/TextRun.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 RefPtr<ShapeResult> combined = shaper.shape(&font, TextDirection::kRtl); | 258 RefPtr<ShapeResult> combined = shaper.shape(&font, TextDirection::kRtl); |
259 | 259 |
260 RefPtr<ShapeResult> first = shaper.shape(&font, TextDirection::kRtl, 0, 1); | 260 RefPtr<ShapeResult> first = shaper.shape(&font, TextDirection::kRtl, 0, 1); |
261 RefPtr<ShapeResult> second = shaper.shape(&font, TextDirection::kRtl, 1, 2); | 261 RefPtr<ShapeResult> second = shaper.shape(&font, TextDirection::kRtl, 1, 2); |
262 | 262 |
263 // Combined width should be the same when shaping the two characters | 263 // Combined width should be the same when shaping the two characters |
264 // separately as when shaping them combined. | 264 // separately as when shaping them combined. |
265 ASSERT_NEAR(combined->width(), first->width() + second->width(), 0.1); | 265 ASSERT_NEAR(combined->width(), first->width() + second->width(), 0.1); |
266 } | 266 } |
267 | 267 |
| 268 TEST_F(HarfBuzzShaperTest, PositionForOffsetLatin) { |
| 269 String string = to16Bit("Hello World!", 12); |
| 270 TextDirection direction = TextDirection::kLtr; |
| 271 |
| 272 HarfBuzzShaper shaper(string.characters16(), 12); |
| 273 RefPtr<ShapeResult> result = shaper.shape(&font, direction); |
| 274 RefPtr<ShapeResult> first = shaper.shape(&font, direction, 0, 5); // Hello |
| 275 RefPtr<ShapeResult> second = shaper.shape(&font, direction, 6, 11); // World |
| 276 |
| 277 ASSERT_EQ(0.0f, result->positionForOffset(0)); |
| 278 ASSERT_NEAR(first->width(), result->positionForOffset(5), 1); |
| 279 ASSERT_NEAR(second->width(), |
| 280 result->positionForOffset(11) - result->positionForOffset(6), 1); |
| 281 ASSERT_NEAR(result->width(), result->positionForOffset(12), 0.1); |
| 282 } |
| 283 |
| 284 TEST_F(HarfBuzzShaperTest, PositionForOffsetArabic) { |
| 285 UChar arabicString[] = {0x628, 0x64A, 0x629}; |
| 286 TextDirection direction = TextDirection::kRtl; |
| 287 |
| 288 HarfBuzzShaper shaper(arabicString, 3); |
| 289 RefPtr<ShapeResult> result = shaper.shape(&font, direction); |
| 290 |
| 291 ASSERT_EQ(0.0f, result->positionForOffset(3)); |
| 292 ASSERT_NEAR(result->width(), result->positionForOffset(0), 0.1); |
| 293 } |
| 294 |
| 295 TEST_F(HarfBuzzShaperTest, OffsetForPositionMatchesPositionForOffsetLatin) { |
| 296 String string = to16Bit("Hello World!", 12); |
| 297 TextDirection direction = TextDirection::kLtr; |
| 298 |
| 299 HarfBuzzShaper shaper(string.characters16(), 12); |
| 300 RefPtr<ShapeResult> result = shaper.shape(&font, direction); |
| 301 |
| 302 // Last argument is includePartialGlyphs |
| 303 ASSERT_EQ(0u, result->offsetForPosition(result->positionForOffset(0), true)); |
| 304 ASSERT_EQ(1u, result->offsetForPosition(result->positionForOffset(1), true)); |
| 305 ASSERT_EQ(2u, result->offsetForPosition(result->positionForOffset(2), true)); |
| 306 ASSERT_EQ(3u, result->offsetForPosition(result->positionForOffset(3), true)); |
| 307 ASSERT_EQ(4u, result->offsetForPosition(result->positionForOffset(4), true)); |
| 308 ASSERT_EQ(5u, result->offsetForPosition(result->positionForOffset(5), true)); |
| 309 ASSERT_EQ(6u, result->offsetForPosition(result->positionForOffset(6), true)); |
| 310 ASSERT_EQ(7u, result->offsetForPosition(result->positionForOffset(7), true)); |
| 311 ASSERT_EQ(8u, result->offsetForPosition(result->positionForOffset(8), true)); |
| 312 ASSERT_EQ(9u, result->offsetForPosition(result->positionForOffset(9), true)); |
| 313 ASSERT_EQ(10u, |
| 314 result->offsetForPosition(result->positionForOffset(10), true)); |
| 315 ASSERT_EQ(11u, |
| 316 result->offsetForPosition(result->positionForOffset(11), true)); |
| 317 ASSERT_EQ(12u, |
| 318 result->offsetForPosition(result->positionForOffset(12), true)); |
| 319 } |
| 320 |
| 321 TEST_F(HarfBuzzShaperTest, OffsetForPositionMatchesPositionForOffsetArabic) { |
| 322 UChar arabicString[] = {0x628, 0x64A, 0x629}; |
| 323 TextDirection direction = TextDirection::kRtl; |
| 324 |
| 325 HarfBuzzShaper shaper(arabicString, 3); |
| 326 RefPtr<ShapeResult> result = shaper.shape(&font, direction); |
| 327 |
| 328 // Last argument is includePartialGlyphs |
| 329 ASSERT_EQ(0u, result->offsetForPosition(result->positionForOffset(0), true)); |
| 330 ASSERT_EQ(1u, result->offsetForPosition(result->positionForOffset(1), true)); |
| 331 ASSERT_EQ(2u, result->offsetForPosition(result->positionForOffset(2), true)); |
| 332 ASSERT_EQ(3u, result->offsetForPosition(result->positionForOffset(3), true)); |
| 333 } |
| 334 |
| 335 TEST_F(HarfBuzzShaperTest, OffsetForPositionMatchesPositionForOffsetMixed) { |
| 336 UChar mixedString[] = {0x628, 0x64A, 0x629, 0xE20, 0x65E5, 0x62}; |
| 337 HarfBuzzShaper shaper(mixedString, 6); |
| 338 RefPtr<ShapeResult> result = shaper.shape(&font, TextDirection::kLtr); |
| 339 |
| 340 // Last argument is includePartialGlyphs |
| 341 ASSERT_EQ(0u, result->offsetForPosition(result->positionForOffset(0), true)); |
| 342 ASSERT_EQ(1u, result->offsetForPosition(result->positionForOffset(1), true)); |
| 343 ASSERT_EQ(2u, result->offsetForPosition(result->positionForOffset(2), true)); |
| 344 ASSERT_EQ(3u, result->offsetForPosition(result->positionForOffset(3), true)); |
| 345 ASSERT_EQ(4u, result->offsetForPosition(result->positionForOffset(4), true)); |
| 346 ASSERT_EQ(5u, result->offsetForPosition(result->positionForOffset(5), true)); |
| 347 ASSERT_EQ(6u, result->offsetForPosition(result->positionForOffset(6), true)); |
| 348 } |
| 349 |
268 } // namespace blink | 350 } // namespace blink |
OLD | NEW |