| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "platform/fonts/Font.h" | 36 #include "platform/fonts/Font.h" |
| 37 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" | 37 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" |
| 38 #include "platform/fonts/shaping/ShapeResultSpacing.h" | 38 #include "platform/fonts/shaping/ShapeResultSpacing.h" |
| 39 #include "platform/wtf/PtrUtil.h" | 39 #include "platform/wtf/PtrUtil.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 float ShapeResult::RunInfo::xPositionForVisualOffset( | 43 float ShapeResult::RunInfo::xPositionForVisualOffset( |
| 44 unsigned offset, | 44 unsigned offset, |
| 45 AdjustMidCluster adjustMidCluster) const { | 45 AdjustMidCluster adjustMidCluster) const { |
| 46 ASSERT(offset < m_numCharacters); | 46 DCHECK_LT(offset, m_numCharacters); |
| 47 if (rtl()) | 47 if (rtl()) |
| 48 offset = m_numCharacters - offset - 1; | 48 offset = m_numCharacters - offset - 1; |
| 49 return xPositionForOffset(offset, adjustMidCluster); | 49 return xPositionForOffset(offset, adjustMidCluster); |
| 50 } | 50 } |
| 51 | 51 |
| 52 float ShapeResult::RunInfo::xPositionForOffset( | 52 float ShapeResult::RunInfo::xPositionForOffset( |
| 53 unsigned offset, | 53 unsigned offset, |
| 54 AdjustMidCluster adjustMidCluster) const { | 54 AdjustMidCluster adjustMidCluster) const { |
| 55 ASSERT(offset <= m_numCharacters); | 55 DCHECK_LE(offset, m_numCharacters); |
| 56 const unsigned numGlyphs = m_glyphData.size(); | 56 const unsigned numGlyphs = m_glyphData.size(); |
| 57 unsigned glyphIndex = 0; | 57 unsigned glyphIndex = 0; |
| 58 float position = 0; | 58 float position = 0; |
| 59 if (rtl()) { | 59 if (rtl()) { |
| 60 while (glyphIndex < numGlyphs && | 60 while (glyphIndex < numGlyphs && |
| 61 m_glyphData[glyphIndex].characterIndex > offset) { | 61 m_glyphData[glyphIndex].characterIndex > offset) { |
| 62 position += m_glyphData[glyphIndex].advance; | 62 position += m_glyphData[glyphIndex].advance; |
| 63 ++glyphIndex; | 63 ++glyphIndex; |
| 64 } | 64 } |
| 65 // Adjust offset if it's not on the cluster boundary. In RTL, this means | 65 // Adjust offset if it's not on the cluster boundary. In RTL, this means |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 259 |
| 260 // The position in question might be just after the text. | 260 // The position in question might be just after the text. |
| 261 if (!offsetX && absoluteOffset == numCharacters()) | 261 if (!offsetX && absoluteOffset == numCharacters()) |
| 262 return rtl() ? 0 : m_width; | 262 return rtl() ? 0 : m_width; |
| 263 | 263 |
| 264 return offsetX; | 264 return offsetX; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void ShapeResult::fallbackFonts( | 267 void ShapeResult::fallbackFonts( |
| 268 HashSet<const SimpleFontData*>* fallback) const { | 268 HashSet<const SimpleFontData*>* fallback) const { |
| 269 ASSERT(fallback); | 269 DCHECK(fallback); |
| 270 ASSERT(m_primaryFont); | 270 DCHECK(m_primaryFont); |
| 271 for (unsigned i = 0; i < m_runs.size(); ++i) { | 271 for (unsigned i = 0; i < m_runs.size(); ++i) { |
| 272 if (m_runs[i] && m_runs[i]->m_fontData && | 272 if (m_runs[i] && m_runs[i]->m_fontData && |
| 273 m_runs[i]->m_fontData != m_primaryFont && | 273 m_runs[i]->m_fontData != m_primaryFont && |
| 274 !m_runs[i]->m_fontData->isTextOrientationFallbackOf( | 274 !m_runs[i]->m_fontData->isTextOrientationFallbackOf( |
| 275 m_primaryFont.get())) { | 275 m_primaryFont.get())) { |
| 276 fallback->insert(m_runs[i]->m_fontData.get()); | 276 fallback->insert(m_runs[i]->m_fontData.get()); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 332 } |
| 333 | 333 |
| 334 static inline float harfBuzzPositionToFloat(hb_position_t value) { | 334 static inline float harfBuzzPositionToFloat(hb_position_t value) { |
| 335 return static_cast<float>(value) / (1 << 16); | 335 return static_cast<float>(value) / (1 << 16); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void ShapeResult::insertRun(std::unique_ptr<ShapeResult::RunInfo> runToInsert, | 338 void ShapeResult::insertRun(std::unique_ptr<ShapeResult::RunInfo> runToInsert, |
| 339 unsigned startGlyph, | 339 unsigned startGlyph, |
| 340 unsigned numGlyphs, | 340 unsigned numGlyphs, |
| 341 hb_buffer_t* harfBuzzBuffer) { | 341 hb_buffer_t* harfBuzzBuffer) { |
| 342 ASSERT(numGlyphs > 0); | 342 DCHECK_GT(numGlyphs, 0u); |
| 343 std::unique_ptr<ShapeResult::RunInfo> run(std::move(runToInsert)); | 343 std::unique_ptr<ShapeResult::RunInfo> run(std::move(runToInsert)); |
| 344 ASSERT(numGlyphs == run->m_glyphData.size()); | 344 DCHECK_EQ(numGlyphs, run->m_glyphData.size()); |
| 345 | 345 |
| 346 const SimpleFontData* currentFontData = run->m_fontData.get(); | 346 const SimpleFontData* currentFontData = run->m_fontData.get(); |
| 347 const hb_glyph_info_t* glyphInfos = | 347 const hb_glyph_info_t* glyphInfos = |
| 348 hb_buffer_get_glyph_infos(harfBuzzBuffer, 0); | 348 hb_buffer_get_glyph_infos(harfBuzzBuffer, 0); |
| 349 const hb_glyph_position_t* glyphPositions = | 349 const hb_glyph_position_t* glyphPositions = |
| 350 hb_buffer_get_glyph_positions(harfBuzzBuffer, 0); | 350 hb_buffer_get_glyph_positions(harfBuzzBuffer, 0); |
| 351 const unsigned startCluster = | 351 const unsigned startCluster = |
| 352 HB_DIRECTION_IS_FORWARD(hb_buffer_get_direction(harfBuzzBuffer)) | 352 HB_DIRECTION_IS_FORWARD(hb_buffer_get_direction(harfBuzzBuffer)) |
| 353 ? glyphInfos[startGlyph].cluster | 353 ? glyphInfos[startGlyph].cluster |
| 354 : glyphInfos[startGlyph + numGlyphs - 1].cluster; | 354 : glyphInfos[startGlyph + numGlyphs - 1].cluster; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 383 | 383 |
| 384 FloatRect glyphBounds = currentFontData->boundsForGlyph(glyph); | 384 FloatRect glyphBounds = currentFontData->boundsForGlyph(glyph); |
| 385 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); | 385 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); |
| 386 m_glyphBoundingBox.unite(glyphBounds); | 386 m_glyphBoundingBox.unite(glyphBounds); |
| 387 glyphOrigin += FloatSize(advance + offsetX, offsetY); | 387 glyphOrigin += FloatSize(advance + offsetX, offsetY); |
| 388 } | 388 } |
| 389 | 389 |
| 390 run->m_width = std::max(0.0f, totalAdvance); | 390 run->m_width = std::max(0.0f, totalAdvance); |
| 391 m_width += run->m_width; | 391 m_width += run->m_width; |
| 392 m_numGlyphs += numGlyphs; | 392 m_numGlyphs += numGlyphs; |
| 393 ASSERT(m_numGlyphs >= numGlyphs); | 393 DCHECK_GE(m_numGlyphs, numGlyphs); |
| 394 m_hasVerticalOffsets |= hasVerticalOffsets; | 394 m_hasVerticalOffsets |= hasVerticalOffsets; |
| 395 | 395 |
| 396 // The runs are stored in result->m_runs in visual order. For LTR, we place | 396 // The runs are stored in result->m_runs in visual order. For LTR, we place |
| 397 // the run to be inserted before the next run with a bigger character | 397 // the run to be inserted before the next run with a bigger character |
| 398 // start index. For RTL, we place the run before the next run with a lower | 398 // start index. For RTL, we place the run before the next run with a lower |
| 399 // character index. Otherwise, for both directions, at the end. | 399 // character index. Otherwise, for both directions, at the end. |
| 400 if (HB_DIRECTION_IS_FORWARD(run->m_direction)) { | 400 if (HB_DIRECTION_IS_FORWARD(run->m_direction)) { |
| 401 for (size_t pos = 0; pos < m_runs.size(); ++pos) { | 401 for (size_t pos = 0; pos < m_runs.size(); ++pos) { |
| 402 if (m_runs.at(pos)->m_startIndex > run->m_startIndex) { | 402 if (m_runs.at(pos)->m_startIndex > run->m_startIndex) { |
| 403 m_runs.insert(pos, std::move(run)); | 403 m_runs.insert(pos, std::move(run)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 result->m_width = run->m_width; | 468 result->m_width = run->m_width; |
| 469 result->m_numGlyphs = count; | 469 result->m_numGlyphs = count; |
| 470 DCHECK_EQ(result->m_numGlyphs, count); // no overflow | 470 DCHECK_EQ(result->m_numGlyphs, count); // no overflow |
| 471 result->m_hasVerticalOffsets = | 471 result->m_hasVerticalOffsets = |
| 472 fontData->platformData().isVerticalAnyUpright(); | 472 fontData->platformData().isVerticalAnyUpright(); |
| 473 result->m_runs.push_back(std::move(run)); | 473 result->m_runs.push_back(std::move(run)); |
| 474 return result.release(); | 474 return result.release(); |
| 475 } | 475 } |
| 476 | 476 |
| 477 } // namespace blink | 477 } // namespace blink |
| OLD | NEW |