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

Side by Side Diff: Source/core/rendering/InlineTextBox.cpp

Issue 197633002: Fix dashed/dotted regression caused by multi-style text decoration patch. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 * . . | 977 * . . |
978 * . . | controlPointDistance 978 * . . | controlPointDistance
979 * | 979 * |
980 * | 980 * |
981 * + - 981 * + -
982 * controlPoint2 982 * controlPoint2
983 * 983 *
984 * |-----------| 984 * |-----------|
985 * step 985 * step
986 */ 986 */
987 static void strokeWavyTextDecoration(GraphicsContext* context, FloatPoint& p1, F loatPoint& p2, float strokeThickness) 987 static void strokeWavyTextDecoration(GraphicsContext* context, FloatPoint p1, Fl oatPoint p2, float strokeThickness)
988 { 988 {
989 context->adjustLineToPixelBoundaries(p1, p2, strokeThickness, context->strok eStyle()); 989 context->adjustLineToPixelBoundaries(p1, p2, strokeThickness, context->strok eStyle());
990 990
991 Path path; 991 Path path;
992 path.moveTo(p1); 992 path.moveTo(p1);
993 993
994 // Distance between decoration's axis and Bezier curve's control points. 994 // Distance between decoration's axis and Bezier curve's control points.
995 // The height of the curve is based on this distance. Use a minimum of 6 pix els distance since 995 // The height of the curve is based on this distance. Use a minimum of 6 pix els distance since
996 // the actual curve passes approximately at half of that distance, that is 3 pixels. 996 // the actual curve passes approximately at half of that distance, that is 3 pixels.
997 // The minimum height of the curve is also approximately 3 pixels. Increases the curve's height 997 // The minimum height of the curve is also approximately 3 pixels. Increases the curve's height
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 static bool shouldSetDecorationAntialias(TextDecorationStyle decorationStyle) 1064 static bool shouldSetDecorationAntialias(TextDecorationStyle decorationStyle)
1065 { 1065 {
1066 return decorationStyle == TextDecorationStyleDotted || decorationStyle == Te xtDecorationStyleDashed; 1066 return decorationStyle == TextDecorationStyleDotted || decorationStyle == Te xtDecorationStyleDashed;
1067 } 1067 }
1068 1068
1069 static bool shouldSetDecorationAntialias(TextDecorationStyle underline, TextDeco rationStyle overline, TextDecorationStyle linethrough) 1069 static bool shouldSetDecorationAntialias(TextDecorationStyle underline, TextDeco rationStyle overline, TextDecorationStyle linethrough)
1070 { 1070 {
1071 return shouldSetDecorationAntialias(underline) || shouldSetDecorationAntiali as(overline) || shouldSetDecorationAntialias(linethrough); 1071 return shouldSetDecorationAntialias(underline) || shouldSetDecorationAntiali as(overline) || shouldSetDecorationAntialias(linethrough);
1072 } 1072 }
1073 1073
1074 static void paintAppliedDecoration(GraphicsContext* context, FloatPoint start, f loat width, float doubleOffset, int wavyOffsetFactor,
1075 RenderObject::AppliedTextDecoration decoration, float thickness, bool antial iasDecoration, bool isPrinting)
1076 {
1077 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decoration.style));
1078 context->setStrokeColor(decoration.color);
1079
1080 switch (decoration.style) {
1081 case TextDecorationStyleWavy:
1082 strokeWavyTextDecoration(context, start + FloatPoint(0, doubleOffset * w avyOffsetFactor), start + FloatPoint(width, doubleOffset * wavyOffsetFactor), th ickness);
1083 break;
1084 case TextDecorationStyleDotted:
1085 case TextDecorationStyleDashed:
1086 context->setShouldAntialias(antialiasDecoration);
1087 // Fall through
1088 default:
1089 context->drawLineForText(start, width, isPrinting);
1090
1091 if (decoration.style == TextDecorationStyleDouble)
1092 context->drawLineForText(start + FloatPoint(0, doubleOffset), width, isPrinting);
1093 }
1094 }
1095
1074 void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco, const ShadowList* shadowList) 1096 void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco, const ShadowList* shadowList)
1075 { 1097 {
1076 GraphicsContextStateSaver stateSaver(*context); 1098 GraphicsContextStateSaver stateSaver(*context);
1077 1099
1078 if (m_truncation == cFullTruncation) 1100 if (m_truncation == cFullTruncation)
1079 return; 1101 return;
1080 1102
1081 FloatPoint localOrigin = boxOrigin; 1103 FloatPoint localOrigin = boxOrigin;
1082 1104
1083 float width = m_logicalWidth; 1105 float width = m_logicalWidth;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 const ShadowData& shadow = shadowList->shadows()[i]; 1168 const ShadowData& shadow = shadowList->shadows()[i];
1147 float shadowX = isHorizontal() ? shadow.x() : shadow.y(); 1169 float shadowX = isHorizontal() ? shadow.x() : shadow.y();
1148 float shadowY = isHorizontal() ? shadow.y() : -shadow.x(); 1170 float shadowY = isHorizontal() ? shadow.y() : -shadow.x();
1149 context->setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow .blur(), shadow.color()); 1171 context->setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow .blur(), shadow.color());
1150 } 1172 }
1151 1173
1152 // Offset between lines - always non-zero, so lines never cross each oth er. 1174 // Offset between lines - always non-zero, so lines never cross each oth er.
1153 float doubleOffset = textDecorationThickness + 1.f; 1175 float doubleOffset = textDecorationThickness + 1.f;
1154 1176
1155 if (deco & TextDecorationUnderline) { 1177 if (deco & TextDecorationUnderline) {
1156 context->setStrokeStyle(textDecorationStyleToStrokeStyle(underline.s tyle));
1157 context->setStrokeColor(underline.color);
1158 const int underlineOffset = computeUnderlineOffset(styleToUse->textU nderlinePosition(), styleToUse->fontMetrics(), this, textDecorationThickness); 1178 const int underlineOffset = computeUnderlineOffset(styleToUse->textU nderlinePosition(), styleToUse->fontMetrics(), this, textDecorationThickness);
1159 switch (underline.style) { 1179 paintAppliedDecoration(context, localOrigin + FloatPoint(0, underlin eOffset), width, doubleOffset, 1, underline, textDecorationThickness, antialiasD ecoration, isPrinting);
1160 case TextDecorationStyleWavy: {
1161 FloatPoint start(localOrigin.x(), localOrigin.y() + underlineOff set + doubleOffset);
1162 FloatPoint end(localOrigin.x() + width, localOrigin.y() + underl ineOffset + doubleOffset);
1163 strokeWavyTextDecoration(context, start, end, textDecorationThic kness);
1164 break;
1165 }
1166 case TextDecorationStyleDotted:
1167 case TextDecorationStyleDashed:
1168 context->setShouldAntialias(antialiasDecoration);
1169 // Fall through
1170 case TextDecorationStyleDouble:
1171 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + underlineOffset + doubleOffset), width, isPrinting);
1172 // Fall through
1173 default:
1174 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + underlineOffset), width, isPrinting);
1175 }
1176 } 1180 }
1177 if (deco & TextDecorationOverline) { 1181 if (deco & TextDecorationOverline) {
1178 context->setStrokeStyle(textDecorationStyleToStrokeStyle(overline.st yle)); 1182 paintAppliedDecoration(context, localOrigin, width, -doubleOffset, 1 , overline, textDecorationThickness, antialiasDecoration, isPrinting);
1179 context->setStrokeColor(overline.color);
1180 switch (overline.style) {
1181 case TextDecorationStyleWavy: {
1182 FloatPoint start(localOrigin.x(), localOrigin.y() - doubleOffset );
1183 FloatPoint end(localOrigin.x() + width, localOrigin.y() - double Offset);
1184 strokeWavyTextDecoration(context, start, end, textDecorationThic kness);
1185 break;
1186 }
1187 case TextDecorationStyleDotted:
1188 case TextDecorationStyleDashed:
1189 context->setShouldAntialias(antialiasDecoration);
1190 // Fall through
1191 case TextDecorationStyleDouble:
1192 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() - doubleOffset), width, isPrinting);
1193 // Fall through
1194 default:
1195 context->drawLineForText(localOrigin, width, isPrinting);
1196 }
1197 } 1183 }
1198 if (deco & TextDecorationLineThrough) { 1184 if (deco & TextDecorationLineThrough) {
1199 context->setStrokeStyle(textDecorationStyleToStrokeStyle(linethrough .style)); 1185 const float lineThroughOffset = 2 * baseline / 3;
1200 context->setStrokeColor(linethrough.color); 1186 paintAppliedDecoration(context, localOrigin + FloatPoint(0, lineThro ughOffset), width, doubleOffset, 0, linethrough, textDecorationThickness, antial iasDecoration, isPrinting);
1201 switch (linethrough.style) {
1202 case TextDecorationStyleWavy: {
1203 FloatPoint start(localOrigin.x(), localOrigin.y() + 2 * baseline / 3);
1204 FloatPoint end(localOrigin.x() + width, localOrigin.y() + 2 * ba seline / 3);
1205 strokeWavyTextDecoration(context, start, end, textDecorationThic kness);
1206 break;
1207 }
1208 case TextDecorationStyleDotted:
1209 case TextDecorationStyleDashed:
1210 context->setShouldAntialias(antialiasDecoration);
1211 // Fall through
1212 case TextDecorationStyleDouble:
1213 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + doubleOffset + 2 * baseline / 3), width, isPrinting);
1214 // Fall through
1215 default:
1216 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + 2 * baseline / 3), width, isPrinting);
1217 }
1218 } 1187 }
1219 } 1188 }
1220 } 1189 }
1221 1190
1222 static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentM arker::MarkerType markerType) 1191 static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentM arker::MarkerType markerType)
1223 { 1192 {
1224 switch (markerType) { 1193 switch (markerType) {
1225 case DocumentMarker::Spelling: 1194 case DocumentMarker::Spelling:
1226 return GraphicsContext::DocumentMarkerSpellingLineStyle; 1195 return GraphicsContext::DocumentMarkerSpellingLineStyle;
1227 case DocumentMarker::Grammar: 1196 case DocumentMarker::Grammar:
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); 1565 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj);
1597 const int rendererCharacterOffset = 24; 1566 const int rendererCharacterOffset = 24;
1598 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) 1567 for (; printedCharacters < rendererCharacterOffset; printedCharacters++)
1599 fputc(' ', stderr); 1568 fputc(' ', stderr);
1600 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 1569 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
1601 } 1570 }
1602 1571
1603 #endif 1572 #endif
1604 1573
1605 } // namespace WebCore 1574 } // namespace WebCore
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