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

Side by Side Diff: Source/platform/fonts/FontFastPath.cpp

Issue 141433026: Font metrics, version 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adding Layout tests. Should work for simple text. Created 6 years, 10 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
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Holger Hans Peter Freyther 3 * Copyright (C) 2008 Holger Hans Peter Freyther
4 * Copyright (C) 2009 Torch Mobile, Inc. 4 * Copyright (C) 2009 Torch Mobile, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 if (glyphOverflow) { 543 if (glyphOverflow) {
544 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent())); 544 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent()));
545 glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(it.maxGlyp hBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().descent())) ; 545 glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(it.maxGlyp hBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().descent())) ;
546 glyphOverflow->left = ceilf(it.firstGlyphOverflow()); 546 glyphOverflow->left = ceilf(it.firstGlyphOverflow());
547 glyphOverflow->right = ceilf(it.lastGlyphOverflow()); 547 glyphOverflow->right = ceilf(it.lastGlyphOverflow());
548 } 548 }
549 549
550 return it.m_runWidthSoFar; 550 return it.m_runWidthSoFar;
551 } 551 }
552 552
553 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const 553 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
554 { 554 {
555 GlyphBuffer glyphBuffer; 555 GlyphBuffer glyphBuffer;
556 WidthIterator it(this, run); 556 WidthIterator it(this, run, 0, accountForGlyphBounds);
557 it.advance(from, &glyphBuffer); 557 it.advance(from, &glyphBuffer);
558 float beforeWidth = it.m_runWidthSoFar; 558 float beforeWidth = it.m_runWidthSoFar;
559 it.advance(to, &glyphBuffer); 559 it.advance(to, &glyphBuffer);
560 float afterWidth = it.m_runWidthSoFar; 560 float afterWidth = it.m_runWidthSoFar;
561 561
562 // Using roundf() rather than ceilf() for the right edge as a compromise to 562 // Using roundf() rather than ceilf() for the right edge as a compromise to
563 // ensure correct caret positioning. 563 // ensure correct caret positioning.
564 // Use LayoutUnit::epsilon() to ensure that values that cannot be stored as 564 // Use LayoutUnit::epsilon() to ensure that values that cannot be stored as
565 // an integer are floored to n and not n-1 due to floating point imprecision . 565 // an integer are floored to n and not n-1 due to floating point imprecision .
566 if (run.rtl()) { 566 if (run.rtl()) {
567 it.advance(run.length(), &glyphBuffer); 567 it.advance(run.length(), &glyphBuffer);
568 float totalWidth = it.m_runWidthSoFar; 568 float totalWidth = it.m_runWidthSoFar;
569 float pixelAlignedX = floorf(point.x() + totalWidth - afterWidth + Layou tUnit::epsilon()); 569 float pixelAlignedX = floorf(point.x() + totalWidth - afterWidth + Layou tUnit::epsilon());
570 return FloatRect(pixelAlignedX, point.y(), 570 return FloatRect(pixelAlignedX, point.y() + accountForGlyphBounds ? it.m inGlyphBoundingBoxY() : 0,
571 roundf(point.x() + totalWidth - beforeWidth) - pixelAlignedX, h); 571 roundf(point.x() + totalWidth - beforeWidth) - pixelAlignedX,
572 accountForGlyphBounds ? it.maxGlyphBoundingBoxY() - it.minGlyphBound ingBoxY() : h);
572 } 573 }
573 574
574 float pixelAlignedX = floorf(point.x() + beforeWidth + LayoutUnit::epsilon() ); 575 float pixelAlignedX = floorf(point.x() + beforeWidth + LayoutUnit::epsilon() );
575 return FloatRect(pixelAlignedX, point.y(), 576 return FloatRect(pixelAlignedX, point.y() + accountForGlyphBounds ? it.minGl yphBoundingBoxY() : 0,
576 roundf(point.x() + afterWidth) - pixelAlignedX, h); 577 roundf(point.x() + afterWidth) - pixelAlignedX,
578 accountForGlyphBounds ? it.maxGlyphBoundingBoxY() - it.minGlyphBoundingB oxY() : h);
577 } 579 }
578 580
579 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const 581 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const
580 { 582 {
581 float delta = x; 583 float delta = x;
582 584
583 WidthIterator it(this, run); 585 WidthIterator it(this, run);
584 GlyphBuffer localGlyphBuffer; 586 GlyphBuffer localGlyphBuffer;
585 unsigned offset; 587 unsigned offset;
586 if (run.rtl()) { 588 if (run.rtl()) {
(...skipping 26 matching lines...) Expand all
613 if (delta <= 0) 615 if (delta <= 0)
614 break; 616 break;
615 } 617 }
616 } 618 }
617 } 619 }
618 620
619 return offset; 621 return offset;
620 } 622 }
621 623
622 } 624 }
OLDNEW
« Source/core/html/canvas/CanvasRenderingContext2D.cpp ('K') | « Source/platform/fonts/Font.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698