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

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

Issue 1045793002: Determine the right SVGTextMetrics using the correct approach (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add test. Created 5 years, 8 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 | « LayoutTests/svg/text/getextentofchar-nonbmp-expected.txt ('k') | 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 struct ExtentOfCharacterData : SVGTextQuery::Data { 413 struct ExtentOfCharacterData : SVGTextQuery::Data {
414 ExtentOfCharacterData(unsigned queryPosition) 414 ExtentOfCharacterData(unsigned queryPosition)
415 : position(queryPosition) 415 : position(queryPosition)
416 { 416 {
417 } 417 }
418 418
419 unsigned position; 419 unsigned position;
420 FloatRect extent; 420 FloatRect extent;
421 }; 421 };
422 422
423 const SVGTextMetrics& findMetricsForCharacter(const Vector<SVGTextMetrics>& text MetricsValues, const SVGTextFragment& fragment, unsigned startInFragment)
424 {
425 // Find the text metrics cell that start at or contain the character at |sta rtInFragment|.
426 unsigned textMetricsOffset = fragment.metricsListOffset;
427 unsigned fragmentOffset = 0;
428 while (fragmentOffset < fragment.length) {
429 const SVGTextMetrics& metrics = textMetricsValues[textMetricsOffset++];
430 unsigned glyphEnd = fragmentOffset + metrics.length();
431 if (startInFragment < glyphEnd)
432 break;
433 fragmentOffset = glyphEnd;
434 }
435 return textMetricsValues[textMetricsOffset - 1];
436 }
437
423 static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent) 438 static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent)
424 { 439 {
425 float scalingFactor = queryData->textLayoutObject->scalingFactor(); 440 float scalingFactor = queryData->textLayoutObject->scalingFactor();
426 ASSERT(scalingFactor); 441 ASSERT(scalingFactor);
427 442
428 FloatPoint glyphPosition = calculateGlyphPositionWithoutTransform(queryData, fragment, startPosition); 443 FloatPoint glyphPosition = calculateGlyphPositionWithoutTransform(queryData, fragment, startPosition);
429 glyphPosition.move(0, -queryData->textLayoutObject->scaledFont().fontMetrics ().floatAscent() / scalingFactor); 444 glyphPosition.move(0, -queryData->textLayoutObject->scaledFont().fontMetrics ().floatAscent() / scalingFactor);
430 extent.setLocation(glyphPosition); 445 extent.setLocation(glyphPosition);
431 446
432 // Use the SVGTextMetrics computed by SVGTextMetricsBuilder (which spends 447 // Use the SVGTextMetrics computed by SVGTextMetricsBuilder (which spends
433 // time attempting to compute more correct glyph bounds already, handling 448 // time attempting to compute more correct glyph bounds already, handling
434 // cursive scripts to some degree.) 449 // cursive scripts to some degree.)
435 Vector<SVGTextMetrics>& textMetricsValues = queryData->textLayoutObject->lay outAttributes()->textMetricsValues(); 450 const Vector<SVGTextMetrics>& textMetricsValues = queryData->textLayoutObjec t->layoutAttributes()->textMetricsValues();
436 const SVGTextMetrics& metrics = textMetricsValues[fragment.characterOffset + startPosition]; 451 const SVGTextMetrics& metrics = findMetricsForCharacter(textMetricsValues, f ragment, startPosition);
437 452
438 // TODO(fs): Negative glyph extents seems kind of weird to have, but 453 // TODO(fs): Negative glyph extents seems kind of weird to have, but
439 // presently it can occur in some cases (like Arabic.) 454 // presently it can occur in some cases (like Arabic.)
440 FloatSize glyphSize(std::max<float>(metrics.width(), 0), std::max<float>(met rics.height(), 0)); 455 FloatSize glyphSize(std::max<float>(metrics.width(), 0), std::max<float>(met rics.height(), 0));
441 extent.setSize(glyphSize); 456 extent.setSize(glyphSize);
442 457
443 // If RTL, adjust the starting point to align with the LHS of the glyph boun ding box. 458 // If RTL, adjust the starting point to align with the LHS of the glyph boun ding box.
444 if (!queryData->textBox->isLeftToRightDirection()) { 459 if (!queryData->textBox->isLeftToRightDirection()) {
445 if (queryData->isVerticalText) 460 if (queryData->isVerticalText)
446 extent.move(0, -glyphSize.height()); 461 extent.move(0, -glyphSize.height());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const 544 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const
530 { 545 {
531 CharacterNumberAtPositionData data(position); 546 CharacterNumberAtPositionData data(position);
532 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) 547 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback))
533 return -1; 548 return -1;
534 549
535 return data.processedCharacters; 550 return data.processedCharacters;
536 } 551 }
537 552
538 } 553 }
OLDNEW
« no previous file with comments | « LayoutTests/svg/text/getextentofchar-nonbmp-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698