Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp

Issue 2869893005: Clamp RunInfo::num_characters when shaping ranges with context (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <unicode/uscript.h> 7 #include <unicode/uscript.h>
8 #include "platform/fonts/Font.h" 8 #include "platform/fonts/Font.h"
9 #include "platform/fonts/FontCache.h" 9 #include "platform/fonts/FontCache.h"
10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" 10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h"
(...skipping 12 matching lines...) Expand all
23 font = Font(font_description); 23 font = Font(font_description);
24 font.Update(nullptr); 24 font.Update(nullptr);
25 } 25 }
26 26
27 void TearDown() override {} 27 void TearDown() override {}
28 28
29 FontCachePurgePreventer font_cache_purge_preventer; 29 FontCachePurgePreventer font_cache_purge_preventer;
30 FontDescription font_description; 30 FontDescription font_description;
31 Font font; 31 Font font;
32 unsigned start_index = 0; 32 unsigned start_index = 0;
33 unsigned num_characters = 0;
33 unsigned num_glyphs = 0; 34 unsigned num_glyphs = 0;
34 hb_script_t script = HB_SCRIPT_INVALID; 35 hb_script_t script = HB_SCRIPT_INVALID;
35 }; 36 };
36 37
37 static inline ShapeResultTestInfo* TestInfo(RefPtr<ShapeResult>& result) { 38 static inline ShapeResultTestInfo* TestInfo(RefPtr<ShapeResult>& result) {
38 return static_cast<ShapeResultTestInfo*>(result.Get()); 39 return static_cast<ShapeResultTestInfo*>(result.Get());
39 } 40 }
40 41
41 static inline String To16Bit(const char* text, unsigned length) { 42 static inline String To16Bit(const char* text, unsigned length) {
42 return String::Make16BitFrom8BitSource(reinterpret_cast<const LChar*>(text), 43 return String::Make16BitFrom8BitSource(reinterpret_cast<const LChar*>(text),
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 TEST_F(HarfBuzzShaperTest, ShapeLatinSegment) { 219 TEST_F(HarfBuzzShaperTest, ShapeLatinSegment) {
219 String string = To16Bit("Hello World!", 12); 220 String string = To16Bit("Hello World!", 12);
220 TextDirection direction = TextDirection::kLtr; 221 TextDirection direction = TextDirection::kLtr;
221 222
222 HarfBuzzShaper shaper(string.Characters16(), 12); 223 HarfBuzzShaper shaper(string.Characters16(), 12);
223 RefPtr<ShapeResult> combined = shaper.Shape(&font, direction); 224 RefPtr<ShapeResult> combined = shaper.Shape(&font, direction);
224 RefPtr<ShapeResult> first = shaper.Shape(&font, direction, 0, 6); 225 RefPtr<ShapeResult> first = shaper.Shape(&font, direction, 0, 6);
225 RefPtr<ShapeResult> second = shaper.Shape(&font, direction, 6, 11); 226 RefPtr<ShapeResult> second = shaper.Shape(&font, direction, 6, 11);
226 RefPtr<ShapeResult> third = shaper.Shape(&font, direction, 11, 12); 227 RefPtr<ShapeResult> third = shaper.Shape(&font, direction, 11, 12);
227 228
229 ASSERT_TRUE(TestInfo(first)->RunInfoForTesting(0, start_index, num_characters,
230 num_glyphs, script));
231 EXPECT_EQ(0u, start_index);
232 EXPECT_EQ(6u, num_characters);
233 ASSERT_TRUE(TestInfo(second)->RunInfoForTesting(
234 0, start_index, num_characters, num_glyphs, script));
235 EXPECT_EQ(6u, start_index);
236 EXPECT_EQ(5u, num_characters);
237 ASSERT_TRUE(TestInfo(third)->RunInfoForTesting(0, start_index, num_characters,
238 num_glyphs, script));
239 EXPECT_EQ(11u, start_index);
240 EXPECT_EQ(1u, num_characters);
241
228 HarfBuzzShaper shaper2(string.Characters16(), 6); 242 HarfBuzzShaper shaper2(string.Characters16(), 6);
229 RefPtr<ShapeResult> first_reference = shaper2.Shape(&font, direction); 243 RefPtr<ShapeResult> first_reference = shaper2.Shape(&font, direction);
230 244
231 HarfBuzzShaper shaper3(string.Characters16() + 6, 5); 245 HarfBuzzShaper shaper3(string.Characters16() + 6, 5);
232 RefPtr<ShapeResult> second_reference = shaper3.Shape(&font, direction); 246 RefPtr<ShapeResult> second_reference = shaper3.Shape(&font, direction);
233 247
234 HarfBuzzShaper shaper4(string.Characters16() + 11, 1); 248 HarfBuzzShaper shaper4(string.Characters16() + 11, 1);
235 RefPtr<ShapeResult> third_reference = shaper4.Shape(&font, direction); 249 RefPtr<ShapeResult> third_reference = shaper4.Shape(&font, direction);
236 250
237 // Width of each segment should be the same when shaped using start and end 251 // Width of each segment should be the same when shaped using start and end
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 composite_result->SnappedStartPositionForOffset(5)); 418 composite_result->SnappedStartPositionForOffset(5));
405 EXPECT_EQ(result->SnappedStartPositionForOffset(6), 419 EXPECT_EQ(result->SnappedStartPositionForOffset(6),
406 composite_result->SnappedStartPositionForOffset(6)); 420 composite_result->SnappedStartPositionForOffset(6));
407 EXPECT_EQ(result->SnappedStartPositionForOffset(7), 421 EXPECT_EQ(result->SnappedStartPositionForOffset(7),
408 composite_result->SnappedStartPositionForOffset(7)); 422 composite_result->SnappedStartPositionForOffset(7));
409 EXPECT_EQ(result->SnappedStartPositionForOffset(8), 423 EXPECT_EQ(result->SnappedStartPositionForOffset(8),
410 composite_result->SnappedStartPositionForOffset(8)); 424 composite_result->SnappedStartPositionForOffset(8));
411 } 425 }
412 426
413 } // namespace blink 427 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698