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

Side by Side Diff: Source/core/rendering/svg/SVGTextQuery.cpp

Issue 355173002: Add per-fragment early-out for getCharNumAtPosition (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 501
502 SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->te xtRenderer, fragment.characterOffset + startPosition, 1); 502 SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->te xtRenderer, fragment.characterOffset + startPosition, 1);
503 extent.setSize(FloatSize(metrics.width(), metrics.height())); 503 extent.setSize(FloatSize(metrics.width(), metrics.height()));
504 504
505 AffineTransform fragmentTransform; 505 AffineTransform fragmentTransform;
506 fragment.buildFragmentTransform(fragmentTransform, SVGTextFragment::Transfor mIgnoringTextLength); 506 fragment.buildFragmentTransform(fragmentTransform, SVGTextFragment::Transfor mIgnoringTextLength);
507 507
508 extent = fragmentTransform.mapRect(extent); 508 extent = fragmentTransform.mapRect(extent);
509 } 509 }
510 510
511 static inline FloatRect calculateFragmentBoundaries(const RenderSVGInlineText& t extRenderer, const SVGTextFragment& fragment)
512 {
513 float scalingFactor = textRenderer.scalingFactor();
514 ASSERT(scalingFactor);
515 float baseline = textRenderer.scaledFont().fontMetrics().floatAscent() / sca lingFactor;
516
517 AffineTransform fragmentTransform;
518 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fr agment.height);
519 fragment.buildFragmentTransform(fragmentTransform);
520 return fragmentTransform.mapRect(fragmentRect);
fs 2014/06/27 14:16:04 (Pondered putting these last four lines in a metho
521 }
522
511 bool SVGTextQuery::extentOfCharacterCallback(Data* queryData, const SVGTextFragm ent& fragment) const 523 bool SVGTextQuery::extentOfCharacterCallback(Data* queryData, const SVGTextFragm ent& fragment) const
512 { 524 {
513 ExtentOfCharacterData* data = static_cast<ExtentOfCharacterData*>(queryData) ; 525 ExtentOfCharacterData* data = static_cast<ExtentOfCharacterData*>(queryData) ;
514 526
515 int startPosition = data->position; 527 int startPosition = data->position;
516 int endPosition = startPosition + 1; 528 int endPosition = startPosition + 1;
517 if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startP osition, endPosition)) 529 if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startP osition, endPosition))
518 return false; 530 return false;
519 531
520 calculateGlyphBoundaries(queryData, fragment, startPosition, data->extent); 532 calculateGlyphBoundaries(queryData, fragment, startPosition, data->extent);
(...skipping 17 matching lines...) Expand all
538 { 550 {
539 } 551 }
540 552
541 FloatPoint position; 553 FloatPoint position;
542 }; 554 };
543 555
544 bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT extFragment& fragment) const 556 bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT extFragment& fragment) const
545 { 557 {
546 CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionD ata*>(queryData); 558 CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionD ata*>(queryData);
547 559
560 // Test the query point against the bounds of the entire fragment first.
561 FloatRect fragmentExtents = calculateFragmentBoundaries(*queryData->textRend erer, fragment);
562 if (!fragmentExtents.contains(data->position))
563 return false;
564
548 // Iterate through the glyphs in this fragment, and check if their extents 565 // Iterate through the glyphs in this fragment, and check if their extents
549 // contain the query point. 566 // contain the query point.
550 FloatRect extent; 567 FloatRect extent;
551 const Vector<SVGTextMetrics>& textMetrics = queryData->textRenderer->layoutA ttributes()->textMetricsValues(); 568 const Vector<SVGTextMetrics>& textMetrics = queryData->textRenderer->layoutA ttributes()->textMetricsValues();
552 unsigned textMetricsOffset = fragment.metricsListOffset; 569 unsigned textMetricsOffset = fragment.metricsListOffset;
553 unsigned fragmentOffset = 0; 570 unsigned fragmentOffset = 0;
554 while (fragmentOffset < fragment.length) { 571 while (fragmentOffset < fragment.length) {
555 calculateGlyphBoundaries(queryData, fragment, fragmentOffset, extent); 572 calculateGlyphBoundaries(queryData, fragment, fragmentOffset, extent);
556 if (extent.contains(data->position)) { 573 if (extent.contains(data->position)) {
557 // Compute the character offset of the glyph within the text box 574 // Compute the character offset of the glyph within the text box
(...skipping 14 matching lines...) Expand all
572 return -1; 589 return -1;
573 590
574 CharacterNumberAtPositionData data(position); 591 CharacterNumberAtPositionData data(position);
575 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) 592 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback))
576 return -1; 593 return -1;
577 594
578 return data.processedCharacters; 595 return data.processedCharacters;
579 } 596 }
580 597
581 } 598 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698