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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 if (startInFragment < fragmentOffset) | 231 if (startInFragment < fragmentOffset) |
232 break; | 232 break; |
233 ++metrics; | 233 ++metrics; |
234 } | 234 } |
235 ASSERT(metrics <= metricsList.end()); | 235 ASSERT(metrics <= metricsList.end()); |
236 return metrics; | 236 return metrics; |
237 } | 237 } |
238 | 238 |
239 static float calculateGlyphRange(const QueryData* queryData, const SVGTextFragme
nt& fragment, unsigned start, unsigned end) | 239 static float calculateGlyphRange(const QueryData* queryData, const SVGTextFragme
nt& fragment, unsigned start, unsigned end) |
240 { | 240 { |
241 const MetricsList& metricsList = queryData->textLineLayout.layoutAttributes(
)->textMetricsValues(); | 241 const MetricsList& metricsList = queryData->textLineLayout.metricsList(); |
242 auto metrics = findMetricsForCharacter(metricsList, fragment, start); | 242 auto metrics = findMetricsForCharacter(metricsList, fragment, start); |
243 auto endMetrics = findMetricsForCharacter(metricsList, fragment, end); | 243 auto endMetrics = findMetricsForCharacter(metricsList, fragment, end); |
244 float glyphRange = 0; | 244 float glyphRange = 0; |
245 for (; metrics != endMetrics; ++metrics) | 245 for (; metrics != endMetrics; ++metrics) |
246 glyphRange += queryData->isVerticalText ? metrics->height() : metrics->w
idth(); | 246 glyphRange += queryData->isVerticalText ? metrics->height() : metrics->w
idth(); |
247 return glyphRange; | 247 return glyphRange; |
248 } | 248 } |
249 | 249 |
250 // subStringLength() implementation | 250 // subStringLength() implementation |
251 struct SubStringLengthData : QueryData { | 251 struct SubStringLengthData : QueryData { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 { | 443 { |
444 const float scalingFactor = queryData->textLineLayout.scalingFactor(); | 444 const float scalingFactor = queryData->textLineLayout.scalingFactor(); |
445 ASSERT(scalingFactor); | 445 ASSERT(scalingFactor); |
446 const float baseline = queryData->textLineLayout.scaledFont().getFontMetrics
().floatAscent() / scalingFactor; | 446 const float baseline = queryData->textLineLayout.scaledFont().getFontMetrics
().floatAscent() / scalingFactor; |
447 | 447 |
448 float glyphOffsetInDirection = calculateGlyphRange(queryData, fragment, 0, s
tartPosition); | 448 float glyphOffsetInDirection = calculateGlyphRange(queryData, fragment, 0, s
tartPosition); |
449 FloatPoint glyphPosition = logicalGlyphPositionToPhysical(queryData, fragmen
t, glyphOffsetInDirection); | 449 FloatPoint glyphPosition = logicalGlyphPositionToPhysical(queryData, fragmen
t, glyphOffsetInDirection); |
450 glyphPosition.move(0, -baseline); | 450 glyphPosition.move(0, -baseline); |
451 | 451 |
452 // Use the SVGTextMetrics computed by SVGTextMetricsBuilder. | 452 // Use the SVGTextMetrics computed by SVGTextMetricsBuilder. |
453 const MetricsList& metricsList = queryData->textLineLayout.layoutAttributes(
)->textMetricsValues(); | 453 const MetricsList& metricsList = queryData->textLineLayout.metricsList(); |
454 auto metrics = findMetricsForCharacter(metricsList, fragment, startPosition)
; | 454 auto metrics = findMetricsForCharacter(metricsList, fragment, startPosition)
; |
455 | 455 |
456 FloatRect extent = physicalGlyphExtents(queryData, *metrics, glyphPosition); | 456 FloatRect extent = physicalGlyphExtents(queryData, *metrics, glyphPosition); |
457 if (fragment.isTransformed()) { | 457 if (fragment.isTransformed()) { |
458 AffineTransform fragmentTransform = fragment.buildFragmentTransform(SVGT
extFragment::TransformIgnoringTextLength); | 458 AffineTransform fragmentTransform = fragment.buildFragmentTransform(SVGT
extFragment::TransformIgnoringTextLength); |
459 extent = fragmentTransform.mapRect(extent); | 459 extent = fragmentTransform.mapRect(extent); |
460 } | 460 } |
461 return extent; | 461 return extent; |
462 } | 462 } |
463 | 463 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 544 |
545 // Test the query point against the bounds of the entire fragment first. | 545 // Test the query point against the bounds of the entire fragment first. |
546 if (!fragment.boundingBox(baseline).contains(data->position)) | 546 if (!fragment.boundingBox(baseline).contains(data->position)) |
547 return false; | 547 return false; |
548 | 548 |
549 AffineTransform fragmentTransform = fragment.buildFragmentTransform(SVGTextF
ragment::TransformIgnoringTextLength); | 549 AffineTransform fragmentTransform = fragment.buildFragmentTransform(SVGTextF
ragment::TransformIgnoringTextLength); |
550 | 550 |
551 // Iterate through the glyphs in this fragment, and check if their extents | 551 // Iterate through the glyphs in this fragment, and check if their extents |
552 // contain the query point. | 552 // contain the query point. |
553 MetricsList::const_iterator metrics = | 553 MetricsList::const_iterator metrics = |
554 data->textLineLayout.layoutAttributes()->textMetricsValues().begin() + f
ragment.metricsListOffset; | 554 data->textLineLayout.metricsList().begin() + fragment.metricsListOffset; |
555 unsigned fragmentOffset = 0; | 555 unsigned fragmentOffset = 0; |
556 float glyphOffset = 0; | 556 float glyphOffset = 0; |
557 while (fragmentOffset < fragment.length) { | 557 while (fragmentOffset < fragment.length) { |
558 FloatPoint glyphPosition = logicalGlyphPositionToPhysical(data, fragment
, glyphOffset); | 558 FloatPoint glyphPosition = logicalGlyphPositionToPhysical(data, fragment
, glyphOffset); |
559 glyphPosition.move(0, -baseline); | 559 glyphPosition.move(0, -baseline); |
560 | 560 |
561 FloatRect extent = fragmentTransform.mapRect(physicalGlyphExtents(data,
*metrics, glyphPosition)); | 561 FloatRect extent = fragmentTransform.mapRect(physicalGlyphExtents(data,
*metrics, glyphPosition)); |
562 if (extent.contains(data->position)) { | 562 if (extent.contains(data->position)) { |
563 // Compute the character offset of the glyph within the text node. | 563 // Compute the character offset of the glyph within the text node. |
564 unsigned offsetInBox = fragment.characterOffset - queryData->textBox
->start() + fragmentOffset; | 564 unsigned offsetInBox = fragment.characterOffset - queryData->textBox
->start() + fragmentOffset; |
565 data->offsetInTextNode = logicalOffsetInTextNode(queryData->textLine
Layout, queryData->textBox, offsetInBox); | 565 data->offsetInTextNode = logicalOffsetInTextNode(queryData->textLine
Layout, queryData->textBox, offsetInBox); |
566 data->hitLayoutItem = LineLayoutItem(data->textLineLayout); | 566 data->hitLayoutItem = LineLayoutItem(data->textLineLayout); |
567 return true; | 567 return true; |
568 } | 568 } |
569 fragmentOffset += metrics->length(); | 569 fragmentOffset += metrics->length(); |
570 glyphOffset += data->isVerticalText ? metrics->height() : metrics->width
(); | 570 glyphOffset += data->isVerticalText ? metrics->height() : metrics->width
(); |
571 ++metrics; | 571 ++metrics; |
572 } | 572 } |
573 return false; | 573 return false; |
574 } | 574 } |
575 | 575 |
576 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const | 576 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const |
577 { | 577 { |
578 CharacterNumberAtPositionData data(position); | 578 CharacterNumberAtPositionData data(position); |
579 spatialQuery(m_queryRootLayoutObject, &data, characterNumberAtPositionCallba
ck); | 579 spatialQuery(m_queryRootLayoutObject, &data, characterNumberAtPositionCallba
ck); |
580 return data.characterNumberWithin(m_queryRootLayoutObject); | 580 return data.characterNumberWithin(m_queryRootLayoutObject); |
581 } | 581 } |
582 | 582 |
583 } // namespace blink | 583 } // namespace blink |
OLD | NEW |