| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 459 } |
| 460 return glyphExtents; | 460 return glyphExtents; |
| 461 } | 461 } |
| 462 | 462 |
| 463 static inline FloatRect calculateGlyphBoundaries( | 463 static inline FloatRect calculateGlyphBoundaries( |
| 464 const QueryData* queryData, | 464 const QueryData* queryData, |
| 465 const SVGTextFragment& fragment, | 465 const SVGTextFragment& fragment, |
| 466 int startPosition) { | 466 int startPosition) { |
| 467 const float scalingFactor = queryData->textLineLayout.scalingFactor(); | 467 const float scalingFactor = queryData->textLineLayout.scalingFactor(); |
| 468 ASSERT(scalingFactor); | 468 ASSERT(scalingFactor); |
| 469 const SimpleFontData* fontData = |
| 470 queryData->textLineLayout.scaledFont().primaryFont(); |
| 471 DCHECK(fontData); |
| 472 if (!fontData) |
| 473 return FloatRect(); |
| 474 |
| 469 const float baseline = | 475 const float baseline = |
| 470 queryData->textLineLayout.scaledFont().getFontMetrics().floatAscent() / | 476 fontData->getFontMetrics().floatAscent() / scalingFactor; |
| 471 scalingFactor; | |
| 472 | |
| 473 float glyphOffsetInDirection = | 477 float glyphOffsetInDirection = |
| 474 calculateGlyphRange(queryData, fragment, 0, startPosition); | 478 calculateGlyphRange(queryData, fragment, 0, startPosition); |
| 475 FloatPoint glyphPosition = logicalGlyphPositionToPhysical( | 479 FloatPoint glyphPosition = logicalGlyphPositionToPhysical( |
| 476 queryData, fragment, glyphOffsetInDirection); | 480 queryData, fragment, glyphOffsetInDirection); |
| 477 glyphPosition.move(0, -baseline); | 481 glyphPosition.move(0, -baseline); |
| 478 | 482 |
| 479 // Use the SVGTextMetrics computed by SVGTextMetricsBuilder. | 483 // Use the SVGTextMetrics computed by SVGTextMetricsBuilder. |
| 480 const MetricsList& metricsList = queryData->textLineLayout.metricsList(); | 484 const MetricsList& metricsList = queryData->textLineLayout.metricsList(); |
| 481 auto metrics = findMetricsForCharacter(metricsList, fragment, startPosition); | 485 auto metrics = findMetricsForCharacter(metricsList, fragment, startPosition); |
| 482 | 486 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 return offset; | 563 return offset; |
| 560 } | 564 } |
| 561 | 565 |
| 562 static bool characterNumberAtPositionCallback(QueryData* queryData, | 566 static bool characterNumberAtPositionCallback(QueryData* queryData, |
| 563 const SVGTextFragment& fragment) { | 567 const SVGTextFragment& fragment) { |
| 564 CharacterNumberAtPositionData* data = | 568 CharacterNumberAtPositionData* data = |
| 565 static_cast<CharacterNumberAtPositionData*>(queryData); | 569 static_cast<CharacterNumberAtPositionData*>(queryData); |
| 566 | 570 |
| 567 const float scalingFactor = data->textLineLayout.scalingFactor(); | 571 const float scalingFactor = data->textLineLayout.scalingFactor(); |
| 568 ASSERT(scalingFactor); | 572 ASSERT(scalingFactor); |
| 573 |
| 574 const SimpleFontData* fontData = |
| 575 data->textLineLayout.scaledFont().primaryFont(); |
| 576 DCHECK(fontData); |
| 577 if (!fontData) |
| 578 return false; |
| 579 |
| 569 const float baseline = | 580 const float baseline = |
| 570 data->textLineLayout.scaledFont().getFontMetrics().floatAscent() / | 581 fontData->getFontMetrics().floatAscent() / scalingFactor; |
| 571 scalingFactor; | |
| 572 | 582 |
| 573 // Test the query point against the bounds of the entire fragment first. | 583 // Test the query point against the bounds of the entire fragment first. |
| 574 if (!fragment.boundingBox(baseline).contains(data->position)) | 584 if (!fragment.boundingBox(baseline).contains(data->position)) |
| 575 return false; | 585 return false; |
| 576 | 586 |
| 577 AffineTransform fragmentTransform = fragment.buildFragmentTransform( | 587 AffineTransform fragmentTransform = fragment.buildFragmentTransform( |
| 578 SVGTextFragment::TransformIgnoringTextLength); | 588 SVGTextFragment::TransformIgnoringTextLength); |
| 579 | 589 |
| 580 // Iterate through the glyphs in this fragment, and check if their extents | 590 // Iterate through the glyphs in this fragment, and check if their extents |
| 581 // contain the query point. | 591 // contain the query point. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 607 } | 617 } |
| 608 | 618 |
| 609 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const { | 619 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const { |
| 610 CharacterNumberAtPositionData data(position); | 620 CharacterNumberAtPositionData data(position); |
| 611 spatialQuery(m_queryRootLayoutObject, &data, | 621 spatialQuery(m_queryRootLayoutObject, &data, |
| 612 characterNumberAtPositionCallback); | 622 characterNumberAtPositionCallback); |
| 613 return data.characterNumberWithin(m_queryRootLayoutObject); | 623 return data.characterNumberWithin(m_queryRootLayoutObject); |
| 614 } | 624 } |
| 615 | 625 |
| 616 } // namespace blink | 626 } // namespace blink |
| OLD | NEW |