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

Side by Side Diff: Source/core/platform/graphics/FontFastPath.cpp

Issue 25512005: Enable experimental support for sub-pixel font scaling (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years 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
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 10 matching lines...) Expand all
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/platform/graphics/Font.h" 24 #include "core/platform/graphics/Font.h"
25 25
26 #include "core/platform/graphics/FontCache.h" 26 #include "core/platform/graphics/FontCache.h"
27 #include "core/platform/graphics/FontFallbackList.h" 27 #include "core/platform/graphics/FontFallbackList.h"
28 #include "core/platform/graphics/GlyphPageTreeNode.h" 28 #include "core/platform/graphics/GlyphPageTreeNode.h"
29 #include "core/platform/graphics/SimpleFontData.h" 29 #include "core/platform/graphics/SimpleFontData.h"
30 #include "core/platform/graphics/WidthIterator.h" 30 #include "core/platform/graphics/WidthIterator.h"
31 #include "platform/LayoutUnit.h"
31 #include "platform/fonts/GlyphBuffer.h" 32 #include "platform/fonts/GlyphBuffer.h"
32 #include "platform/geometry/FloatRect.h" 33 #include "platform/geometry/FloatRect.h"
33 #include "platform/graphics/TextRun.h" 34 #include "platform/graphics/TextRun.h"
34 #include "wtf/MainThread.h" 35 #include "wtf/MainThread.h"
35 #include "wtf/MathExtras.h" 36 #include "wtf/MathExtras.h"
36 #include "wtf/unicode/CharacterNames.h" 37 #include "wtf/unicode/CharacterNames.h"
37 #include "wtf/unicode/Unicode.h" 38 #include "wtf/unicode/Unicode.h"
38 39
39 using namespace WTF; 40 using namespace WTF;
40 using namespace Unicode; 41 using namespace Unicode;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 550
550 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const 551 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const
551 { 552 {
552 GlyphBuffer glyphBuffer; 553 GlyphBuffer glyphBuffer;
553 WidthIterator it(this, run); 554 WidthIterator it(this, run);
554 it.advance(from, &glyphBuffer); 555 it.advance(from, &glyphBuffer);
555 float beforeWidth = it.m_runWidthSoFar; 556 float beforeWidth = it.m_runWidthSoFar;
556 it.advance(to, &glyphBuffer); 557 it.advance(to, &glyphBuffer);
557 float afterWidth = it.m_runWidthSoFar; 558 float afterWidth = it.m_runWidthSoFar;
558 559
559 // Using roundf() rather than ceilf() for the right edge as a compromise to ensure correct caret positioning. 560 // Using roundf() rather than ceilf() for the right edge as a compromise to
561 // ensure correct caret positioning.
562 // Use LayoutUnit::epsilon() to ensure that values that cannot be stored as
563 // an integer are floored to n and not n-1 due to floating point imprecision .
560 if (run.rtl()) { 564 if (run.rtl()) {
561 it.advance(run.length(), &glyphBuffer); 565 it.advance(run.length(), &glyphBuffer);
562 float totalWidth = it.m_runWidthSoFar; 566 float totalWidth = it.m_runWidthSoFar;
563 return FloatRect(floorf(point.x() + totalWidth - afterWidth), point.y(), roundf(point.x() + totalWidth - beforeWidth) - floorf(point.x() + totalWidth - afterWidth), h); 567 float pixelAlignedX = floorf(point.x() + totalWidth - afterWidth + Layou tUnit::epsilon());
568 return FloatRect(pixelAlignedX, point.y(),
569 roundf(point.x() + totalWidth - beforeWidth) - pixelAlignedX, h);
564 } 570 }
565 571
566 return FloatRect(floorf(point.x() + beforeWidth), point.y(), roundf(point.x( ) + afterWidth) - floorf(point.x() + beforeWidth), h); 572 float pixelAlignedX = floorf(point.x() + beforeWidth + LayoutUnit::epsilon() );
573 return FloatRect(pixelAlignedX, point.y(),
574 roundf(point.x() + afterWidth) - pixelAlignedX, h);
567 } 575 }
568 576
569 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const 577 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const
570 { 578 {
571 float delta = x; 579 float delta = x;
572 580
573 WidthIterator it(this, run); 581 WidthIterator it(this, run);
574 GlyphBuffer localGlyphBuffer; 582 GlyphBuffer localGlyphBuffer;
575 unsigned offset; 583 unsigned offset;
576 if (run.rtl()) { 584 if (run.rtl()) {
(...skipping 26 matching lines...) Expand all
603 if (delta <= 0) 611 if (delta <= 0)
604 break; 612 break;
605 } 613 }
606 } 614 }
607 } 615 }
608 616
609 return offset; 617 return offset;
610 } 618 }
611 619
612 } 620 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698