OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. |
6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. | 6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 265 } |
266 | 266 |
267 float Font::Width(const TextRun& run, | 267 float Font::Width(const TextRun& run, |
268 HashSet<const SimpleFontData*>* fallback_fonts, | 268 HashSet<const SimpleFontData*>* fallback_fonts, |
269 FloatRect* glyph_bounds) const { | 269 FloatRect* glyph_bounds) const { |
270 FontCachePurgePreventer purge_preventer; | 270 FontCachePurgePreventer purge_preventer; |
271 CachingWordShaper shaper(*this); | 271 CachingWordShaper shaper(*this); |
272 return shaper.Width(run, fallback_fonts, glyph_bounds); | 272 return shaper.Width(run, fallback_fonts, glyph_bounds); |
273 } | 273 } |
274 | 274 |
275 static int GetInterceptsFromBlobs( | 275 namespace { // anonymous namespace |
276 const ShapeResultBloberizer::BlobBuffer& blobs, | 276 |
277 const SkPaint& paint, | 277 unsigned InterceptsFromBlobs(const ShapeResultBloberizer::BlobBuffer& blobs, |
278 const std::tuple<float, float>& bounds, | 278 const SkPaint& paint, |
279 SkScalar* intercepts_buffer) { | 279 const std::tuple<float, float>& bounds, |
| 280 SkScalar* intercepts_buffer) { |
280 SkScalar bounds_array[2] = {std::get<0>(bounds), std::get<1>(bounds)}; | 281 SkScalar bounds_array[2] = {std::get<0>(bounds), std::get<1>(bounds)}; |
281 | 282 |
282 int num_intervals = 0; | 283 unsigned num_intervals = 0; |
283 for (const auto& blob_info : blobs) { | 284 for (const auto& blob_info : blobs) { |
284 DCHECK(blob_info.blob); | 285 DCHECK(blob_info.blob); |
285 | 286 |
286 // ShapeResultBloberizer splits for a new blob rotation, but does not split | 287 // ShapeResultBloberizer splits for a new blob rotation, but does not split |
287 // for a change in font. A TextBlob can contain runs with differing fonts | 288 // for a change in font. A TextBlob can contain runs with differing fonts |
288 // and the getTextBlobIntercepts method handles multiple fonts for us. For | 289 // and the getTextBlobIntercepts method handles multiple fonts for us. For |
289 // upright in vertical blobs we currently have to bail, see crbug.com/655154 | 290 // upright in vertical blobs we currently have to bail, see crbug.com/655154 |
290 if (blob_info.rotation == ShapeResultBloberizer::BlobRotation::kCCWRotation) | 291 if (blob_info.rotation == ShapeResultBloberizer::BlobRotation::kCCWRotation) |
291 continue; | 292 continue; |
292 | 293 |
293 SkScalar* offset_intercepts_buffer = nullptr; | 294 SkScalar* offset_intercepts_buffer = nullptr; |
294 if (intercepts_buffer) | 295 if (intercepts_buffer) |
295 offset_intercepts_buffer = &intercepts_buffer[num_intervals]; | 296 offset_intercepts_buffer = &intercepts_buffer[num_intervals]; |
296 num_intervals += paint.getTextBlobIntercepts( | 297 num_intervals += paint.getTextBlobIntercepts( |
297 blob_info.blob.get(), bounds_array, offset_intercepts_buffer); | 298 blob_info.blob.get(), bounds_array, offset_intercepts_buffer); |
298 } | 299 } |
299 return num_intervals; | 300 return num_intervals; |
300 } | 301 } |
301 | 302 |
| 303 void GetTextInterceptsInternal(const ShapeResultBloberizer::BlobBuffer& blobs, |
| 304 const PaintFlags& flags, |
| 305 const std::tuple<float, float>& bounds, |
| 306 Vector<Font::TextIntercept>& intercepts) { |
| 307 // Get the number of intervals, without copying the actual values by |
| 308 // specifying nullptr for the buffer, following the Skia allocation model for |
| 309 // retrieving text intercepts. |
| 310 SkPaint paint(ToSkPaint(flags)); |
| 311 unsigned num_intervals = InterceptsFromBlobs(blobs, paint, bounds, nullptr); |
| 312 if (!num_intervals) |
| 313 return; |
| 314 DCHECK_EQ(num_intervals % 2, 0u); |
| 315 intercepts.resize(num_intervals / 2u); |
| 316 |
| 317 InterceptsFromBlobs(blobs, paint, bounds, |
| 318 reinterpret_cast<SkScalar*>(intercepts.data())); |
| 319 } |
| 320 |
| 321 } // anonymous namespace |
| 322 |
302 void Font::GetTextIntercepts(const TextRunPaintInfo& run_info, | 323 void Font::GetTextIntercepts(const TextRunPaintInfo& run_info, |
303 float device_scale_factor, | 324 float device_scale_factor, |
304 const PaintFlags& flags, | 325 const PaintFlags& flags, |
305 const std::tuple<float, float>& bounds, | 326 const std::tuple<float, float>& bounds, |
306 Vector<TextIntercept>& intercepts) const { | 327 Vector<TextIntercept>& intercepts) const { |
307 if (ShouldSkipDrawing()) | 328 if (ShouldSkipDrawing()) |
308 return; | 329 return; |
309 | 330 |
310 ShapeResultBloberizer bloberizer( | 331 ShapeResultBloberizer bloberizer( |
311 *this, device_scale_factor, ShapeResultBloberizer::Type::kTextIntercepts); | 332 *this, device_scale_factor, ShapeResultBloberizer::Type::kTextIntercepts); |
312 | |
313 CachingWordShaper word_shaper(*this); | 333 CachingWordShaper word_shaper(*this); |
314 ShapeResultBuffer buffer; | 334 ShapeResultBuffer buffer; |
315 word_shaper.FillResultBuffer(run_info, &buffer); | 335 word_shaper.FillResultBuffer(run_info, &buffer); |
316 bloberizer.FillGlyphs(run_info, buffer); | 336 bloberizer.FillGlyphs(run_info, buffer); |
317 | 337 |
318 const auto& blobs = bloberizer.Blobs(); | 338 GetTextInterceptsInternal(bloberizer.Blobs(), flags, bounds, intercepts); |
| 339 } |
319 | 340 |
320 // Get the number of intervals, without copying the actual values by | 341 void Font::GetTextIntercepts(const TextFragmentPaintInfo& text_info, |
321 // specifying nullptr for the buffer, following the Skia allocation model for | 342 float device_scale_factor, |
322 // retrieving text intercepts. | 343 const PaintFlags& flags, |
323 SkPaint paint(ToSkPaint(flags)); | 344 const std::tuple<float, float>& bounds, |
324 int num_intervals = GetInterceptsFromBlobs(blobs, paint, bounds, nullptr); | 345 Vector<TextIntercept>& intercepts) const { |
325 if (!num_intervals) | 346 if (ShouldSkipDrawing()) |
326 return; | 347 return; |
327 DCHECK_EQ(num_intervals % 2, 0); | |
328 intercepts.resize(num_intervals / 2); | |
329 | 348 |
330 GetInterceptsFromBlobs(blobs, paint, bounds, | 349 ShapeResultBloberizer bloberizer( |
331 reinterpret_cast<SkScalar*>(intercepts.data())); | 350 *this, device_scale_factor, ShapeResultBloberizer::Type::kTextIntercepts); |
| 351 bloberizer.FillGlyphs(text_info.text, text_info.from, text_info.to, |
| 352 text_info.shape_result); |
| 353 |
| 354 GetTextInterceptsInternal(bloberizer.Blobs(), flags, bounds, intercepts); |
332 } | 355 } |
333 | 356 |
334 static inline FloatRect PixelSnappedSelectionRect(FloatRect rect) { | 357 static inline FloatRect PixelSnappedSelectionRect(FloatRect rect) { |
335 // Using roundf() rather than ceilf() for the right edge as a compromise to | 358 // Using roundf() rather than ceilf() for the right edge as a compromise to |
336 // ensure correct caret positioning. | 359 // ensure correct caret positioning. |
337 float rounded_x = roundf(rect.X()); | 360 float rounded_x = roundf(rect.X()); |
338 return FloatRect(rounded_x, rect.Y(), roundf(rect.MaxX() - rounded_x), | 361 return FloatRect(rounded_x, rect.Y(), roundf(rect.MaxX() - rounded_x), |
339 rect.Height()); | 362 rect.Height()); |
340 } | 363 } |
341 | 364 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 489 |
467 bool Font::LoadingCustomFonts() const { | 490 bool Font::LoadingCustomFonts() const { |
468 return font_fallback_list_ && font_fallback_list_->LoadingCustomFonts(); | 491 return font_fallback_list_ && font_fallback_list_->LoadingCustomFonts(); |
469 } | 492 } |
470 | 493 |
471 bool Font::IsFallbackValid() const { | 494 bool Font::IsFallbackValid() const { |
472 return !font_fallback_list_ || font_fallback_list_->IsValid(); | 495 return !font_fallback_list_ || font_fallback_list_->IsValid(); |
473 } | 496 } |
474 | 497 |
475 } // namespace blink | 498 } // namespace blink |
OLD | NEW |