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

Side by Side Diff: sky/engine/core/rendering/InlineTextBox.cpp

Issue 1189403005: Make wavy underlines go all the way to the end of the inline. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix the math so it doesn't crash Created 5 years, 6 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
« 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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
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 23 matching lines...) Expand all
34 #include "sky/engine/core/editing/InputMethodController.h" 34 #include "sky/engine/core/editing/InputMethodController.h"
35 #include "sky/engine/core/frame/LocalFrame.h" 35 #include "sky/engine/core/frame/LocalFrame.h"
36 #include "sky/engine/core/frame/Settings.h" 36 #include "sky/engine/core/frame/Settings.h"
37 #include "sky/engine/core/page/Page.h" 37 #include "sky/engine/core/page/Page.h"
38 #include "sky/engine/core/rendering/EllipsisBox.h" 38 #include "sky/engine/core/rendering/EllipsisBox.h"
39 #include "sky/engine/core/rendering/HitTestResult.h" 39 #include "sky/engine/core/rendering/HitTestResult.h"
40 #include "sky/engine/core/rendering/PaintInfo.h" 40 #include "sky/engine/core/rendering/PaintInfo.h"
41 #include "sky/engine/core/rendering/RenderBlock.h" 41 #include "sky/engine/core/rendering/RenderBlock.h"
42 #include "sky/engine/core/rendering/RenderTheme.h" 42 #include "sky/engine/core/rendering/RenderTheme.h"
43 #include "sky/engine/core/rendering/style/ShadowList.h" 43 #include "sky/engine/core/rendering/style/ShadowList.h"
44 #include "sky/engine/platform/animation/UnitBezier.h"
44 #include "sky/engine/platform/fonts/FontCache.h" 45 #include "sky/engine/platform/fonts/FontCache.h"
45 #include "sky/engine/platform/fonts/GlyphBuffer.h" 46 #include "sky/engine/platform/fonts/GlyphBuffer.h"
46 #include "sky/engine/platform/fonts/WidthIterator.h" 47 #include "sky/engine/platform/fonts/WidthIterator.h"
47 #include "sky/engine/platform/graphics/GraphicsContextStateSaver.h" 48 #include "sky/engine/platform/graphics/GraphicsContextStateSaver.h"
48 #include "sky/engine/wtf/Vector.h" 49 #include "sky/engine/wtf/Vector.h"
49 #include "sky/engine/wtf/text/CString.h" 50 #include "sky/engine/wtf/text/CString.h"
50 #include "sky/engine/wtf/text/StringBuilder.h" 51 #include "sky/engine/wtf/text/StringBuilder.h"
51 52
52 #include <algorithm> 53 #include <algorithm>
53 54
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 if (offset > 0) 772 if (offset > 0)
772 return inlineTextBox->logicalHeight() + gap + offset; 773 return inlineTextBox->logicalHeight() + gap + offset;
773 return inlineTextBox->logicalHeight() + gap; 774 return inlineTextBox->logicalHeight() + gap;
774 } 775 }
775 } 776 }
776 777
777 ASSERT_NOT_REACHED(); 778 ASSERT_NOT_REACHED();
778 return fontMetrics.ascent() + gap; 779 return fontMetrics.ascent() + gap;
779 } 780 }
780 781
781 static void adjustStepToDecorationLength(float& step, float& controlPointDistanc e, float length)
782 {
783 ASSERT(step > 0);
784
785 if (length <= 0)
786 return;
787
788 unsigned stepCount = static_cast<unsigned>(length / step);
789
790 // Each Bezier curve starts at the same pixel that the previous one
791 // ended. We need to subtract (stepCount - 1) pixels when calculating the
792 // length covered to account for that.
793 float uncoveredLength = length - (stepCount * step - (stepCount - 1));
794 float adjustment = uncoveredLength / stepCount;
795 step += adjustment;
796 controlPointDistance += adjustment;
797 }
798
799 struct CurveAlongX { 782 struct CurveAlongX {
800 static inline float x(const FloatPoint& p) { return p.x(); } 783 static inline float x(const FloatPoint& p) { return p.x(); }
801 static inline float y(const FloatPoint& p) { return p.y(); } 784 static inline float y(const FloatPoint& p) { return p.y(); }
802 static inline FloatPoint p(float x, float y) { return FloatPoint(x, y); } 785 static inline FloatPoint p(float x, float y) { return FloatPoint(x, y); }
803 static inline void setX(FloatPoint& p, double x) { p.setX(x); } 786 static inline void setX(FloatPoint& p, double x) { p.setX(x); }
804 }; 787 };
805 788
806 struct CurveAlongY { 789 struct CurveAlongY {
807 static inline float x(const FloatPoint& p) { return p.y(); } 790 static inline float x(const FloatPoint& p) { return p.y(); }
808 static inline float y(const FloatPoint& p) { return p.x(); } 791 static inline float y(const FloatPoint& p) { return p.x(); }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 float x2; 845 float x2;
863 846
864 if (Curve::x(p1) < Curve::x(p2)) { 847 if (Curve::x(p1) < Curve::x(p2)) {
865 x1 = Curve::x(p1); 848 x1 = Curve::x(p1);
866 x2 = Curve::x(p2); 849 x2 = Curve::x(p2);
867 } else { 850 } else {
868 x1 = Curve::x(p2); 851 x1 = Curve::x(p2);
869 x2 = Curve::x(p1); 852 x2 = Curve::x(p1);
870 } 853 }
871 854
872 adjustStepToDecorationLength(step, controlPointDistance, x2 - x1);
873
874 FloatPoint controlPoint1 = Curve::p(0, yAxis + controlPointDistance); 855 FloatPoint controlPoint1 = Curve::p(0, yAxis + controlPointDistance);
875 FloatPoint controlPoint2 = Curve::p(0, yAxis - controlPointDistance); 856 FloatPoint controlPoint2 = Curve::p(0, yAxis - controlPointDistance);
876 857
877 for (float x = x1; x + 2 * step <= x2;) { 858 float x;
859 for (x = x1; x + 2 * step <= x2;) {
878 Curve::setX(controlPoint1, x + step); 860 Curve::setX(controlPoint1, x + step);
879 Curve::setX(controlPoint2, x + step); 861 Curve::setX(controlPoint2, x + step);
880 x += 2 * step; 862 x += 2 * step;
881 path.addBezierCurveTo(controlPoint1, controlPoint2, Curve::p(x, yAxis)); 863 path.addBezierCurveTo(controlPoint1, controlPoint2, Curve::p(x, yAxis));
882 } 864 }
883 865
866 if (x < x2) {
867 Curve::setX(controlPoint1, x + step);
868 Curve::setX(controlPoint2, x + step);
869 float xScale = 1.0 / (2 * step);
870 float yScale = 1.0 / (2 * controlPointDistance);
871 OwnPtr<UnitBezier> bezier = adoptPtr(new UnitBezier((Curve::x(controlPoint 1) - x) * xScale,
eseidel 2015/06/22 22:10:02 How hot is this? Do we care that you're mallocing
872 (Curve::y(controlPoint 1) - yAxis) * yScale,
873 (Curve::x(controlPoint 2) - x) * xScale,
874 (Curve::y(controlPoint 2) - yAxis) * yScale));
875 float t = bezier->solveCurveX((x2 - x) / (2.0 * step), std::numeric_limits <double>::epsilon());
876 // following math based on http://stackoverflow.com/a/879213
877 float u1 = 1.0 - t;
878 float qxb = x*u1*u1 + Curve::x(controlPoint1)*2*t*u1 + Curve::x(controlPo int2)*t*t;
eseidel 2015/06/22 22:10:02 Spaces?
879 float qxd = Curve::x(controlPoint1)*u1*u1 + Curve::x(controlPoint2)*2*t*u1 + (x+step)*t*t;
880 float qyb = yAxis*u1*u1 + Curve::y(controlPoint1)*2*t*u1 + Curve::y(contr olPoint2)*t*t;
881 float qyd = Curve::y(controlPoint1)*u1*u1 + Curve::y(controlPoint2)*2*t*u1 + yAxis*t*t;
882 float xb = x*u1 + Curve::x(controlPoint1)*t;
883 float yb = yAxis*u1 + Curve::y(controlPoint1)*t;
884 float xc = qxb;
885 float xd = qxb*u1 + qxd*t;
886 float yc = qyb;
887 float yd = qyb*u1 + qyd*t;
888 path.addBezierCurveTo(Curve::p(xb, yb), Curve::p(xc, yc), Curve::p(xd, yd) );
889 }
890
884 context->setShouldAntialias(true); 891 context->setShouldAntialias(true);
885 context->strokePath(path); 892 context->strokePath(path);
886 } 893 }
887 894
888 static void strokeWavyTextDecoration(GraphicsContext* context, FloatPoint p1, Fl oatPoint p2, float strokeThickness) 895 static void strokeWavyTextDecoration(GraphicsContext* context, FloatPoint p1, Fl oatPoint p2, float strokeThickness)
889 { 896 {
890 if (p1.y() == p2.y()) // horizontal line 897 if (p1.y() == p2.y()) // horizontal line
891 strokeWavyTextDecorationInternal<CurveAlongX>(context, p1, p2, strokeThick ness); 898 strokeWavyTextDecorationInternal<CurveAlongX>(context, p1, p2, strokeThick ness);
892 else // vertical line 899 else // vertical line
893 strokeWavyTextDecorationInternal<CurveAlongY>(context, p1, p2, strokeThick ness); 900 strokeWavyTextDecorationInternal<CurveAlongY>(context, p1, p2, strokeThick ness);
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); 1335 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj);
1329 const int rendererCharacterOffset = 24; 1336 const int rendererCharacterOffset = 24;
1330 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) 1337 for (; printedCharacters < rendererCharacterOffset; printedCharacters++)
1331 fputc(' ', stderr); 1338 fputc(' ', stderr);
1332 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 1339 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
1333 } 1340 }
1334 1341
1335 #endif 1342 #endif
1336 1343
1337 } // namespace blink 1344 } // namespace blink
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