OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/paint/SVGInlineTextBoxPainter.h" | 5 #include "core/paint/SVGInlineTextBoxPainter.h" |
6 | 6 |
7 #include "core/editing/Editor.h" | 7 #include "core/editing/Editor.h" |
8 #include "core/editing/markers/DocumentMarkerController.h" | 8 #include "core/editing/markers/DocumentMarkerController.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/layout/LayoutTheme.h" | 10 #include "core/layout/LayoutTheme.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 state_saver.Save(); | 173 state_saver.Save(); |
174 paint_info.context.ConcatCTM(fragment.BuildFragmentTransform()); | 174 paint_info.context.ConcatCTM(fragment.BuildFragmentTransform()); |
175 } | 175 } |
176 | 176 |
177 // Spec: All text decorations except line-through should be drawn before the | 177 // Spec: All text decorations except line-through should be drawn before the |
178 // text is filled and stroked; thus, the text is rendered on top of these | 178 // text is filled and stroked; thus, the text is rendered on top of these |
179 // decorations. | 179 // decorations. |
180 const Vector<AppliedTextDecoration>& decorations = | 180 const Vector<AppliedTextDecoration>& decorations = |
181 style.AppliedTextDecorations(); | 181 style.AppliedTextDecorations(); |
182 for (const AppliedTextDecoration& decoration : decorations) { | 182 for (const AppliedTextDecoration& decoration : decorations) { |
183 if (decoration.Lines() & kTextDecorationUnderline) | 183 if (EnumHasFlags(decoration.Lines(), TextDecoration::kUnderline)) |
184 PaintDecoration(paint_info, kTextDecorationUnderline, fragment); | 184 PaintDecoration(paint_info, TextDecoration::kUnderline, fragment); |
185 if (decoration.Lines() & kTextDecorationOverline) | 185 if (EnumHasFlags(decoration.Lines(), TextDecoration::kOverline)) |
186 PaintDecoration(paint_info, kTextDecorationOverline, fragment); | 186 PaintDecoration(paint_info, TextDecoration::kOverline, fragment); |
187 } | 187 } |
188 | 188 |
189 for (int i = 0; i < 3; i++) { | 189 for (int i = 0; i < 3; i++) { |
190 switch (svg_style.PaintOrderType(i)) { | 190 switch (svg_style.PaintOrderType(i)) { |
191 case PT_FILL: | 191 case PT_FILL: |
192 if (has_fill) | 192 if (has_fill) |
193 PaintText(paint_info, style, *selection_style, fragment, | 193 PaintText(paint_info, style, *selection_style, fragment, |
194 kApplyToFillMode, should_paint_selection); | 194 kApplyToFillMode, should_paint_selection); |
195 break; | 195 break; |
196 case PT_STROKE: | 196 case PT_STROKE: |
197 if (has_visible_stroke) | 197 if (has_visible_stroke) |
198 PaintText(paint_info, style, *selection_style, fragment, | 198 PaintText(paint_info, style, *selection_style, fragment, |
199 kApplyToStrokeMode, should_paint_selection); | 199 kApplyToStrokeMode, should_paint_selection); |
200 break; | 200 break; |
201 case PT_MARKERS: | 201 case PT_MARKERS: |
202 // Markers don't apply to text | 202 // Markers don't apply to text |
203 break; | 203 break; |
204 default: | 204 default: |
205 NOTREACHED(); | 205 NOTREACHED(); |
206 break; | 206 break; |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 // Spec: Line-through should be drawn after the text is filled and stroked; | 210 // Spec: Line-through should be drawn after the text is filled and stroked; |
211 // thus, the line-through is rendered on top of the text. | 211 // thus, the line-through is rendered on top of the text. |
212 for (const AppliedTextDecoration& decoration : decorations) { | 212 for (const AppliedTextDecoration& decoration : decorations) { |
213 if (decoration.Lines() & kTextDecorationLineThrough) | 213 if (EnumHasFlags(decoration.Lines(), TextDecoration::kLineThrough)) |
214 PaintDecoration(paint_info, kTextDecorationLineThrough, fragment); | 214 PaintDecoration(paint_info, TextDecoration::kLineThrough, fragment); |
215 } | 215 } |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 void SVGInlineTextBoxPainter::PaintSelectionBackground( | 219 void SVGInlineTextBoxPainter::PaintSelectionBackground( |
220 const PaintInfo& paint_info) { | 220 const PaintInfo& paint_info) { |
221 if (svg_inline_text_box_.GetLineLayoutItem().Style()->Visibility() != | 221 if (svg_inline_text_box_.GetLineLayoutItem().Style()->Visibility() != |
222 EVisibility::kVisible) | 222 EVisibility::kVisible) |
223 return; | 223 return; |
224 | 224 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 static inline LayoutObject* FindLayoutObjectDefininingTextDecoration( | 264 static inline LayoutObject* FindLayoutObjectDefininingTextDecoration( |
265 InlineFlowBox* parent_box) { | 265 InlineFlowBox* parent_box) { |
266 // Lookup first layout object in parent hierarchy which has text-decoration | 266 // Lookup first layout object in parent hierarchy which has text-decoration |
267 // set. | 267 // set. |
268 LayoutObject* layout_object = nullptr; | 268 LayoutObject* layout_object = nullptr; |
269 while (parent_box) { | 269 while (parent_box) { |
270 layout_object = | 270 layout_object = |
271 LineLayoutAPIShim::LayoutObjectFrom(parent_box->GetLineLayoutItem()); | 271 LineLayoutAPIShim::LayoutObjectFrom(parent_box->GetLineLayoutItem()); |
272 | 272 |
273 if (layout_object->Style() && | 273 if (layout_object->Style() && |
274 layout_object->Style()->GetTextDecoration() != kTextDecorationNone) | 274 layout_object->Style()->GetTextDecoration() != TextDecoration::kNone) |
275 break; | 275 break; |
276 | 276 |
277 parent_box = parent_box->Parent(); | 277 parent_box = parent_box->Parent(); |
278 } | 278 } |
279 | 279 |
280 DCHECK(layout_object); | 280 DCHECK(layout_object); |
281 return layout_object; | 281 return layout_object; |
282 } | 282 } |
283 | 283 |
284 // Offset from the baseline for |decoration|. Positive offsets are above the | 284 // Offset from the baseline for |decoration|. Positive offsets are above the |
285 // baseline. | 285 // baseline. |
286 static inline float BaselineOffsetForDecoration(TextDecoration decoration, | 286 static inline float BaselineOffsetForDecoration(TextDecoration decoration, |
287 const FontMetrics& font_metrics, | 287 const FontMetrics& font_metrics, |
288 float thickness) { | 288 float thickness) { |
289 // FIXME: For SVG Fonts we need to use the attributes defined in the | 289 // FIXME: For SVG Fonts we need to use the attributes defined in the |
290 // <font-face> if specified. | 290 // <font-face> if specified. |
291 // Compatible with Batik/Presto. | 291 // Compatible with Batik/Presto. |
292 if (decoration == kTextDecorationUnderline) | 292 if (decoration == TextDecoration::kUnderline) |
293 return -thickness * 1.5f; | 293 return -thickness * 1.5f; |
294 if (decoration == kTextDecorationOverline) | 294 if (decoration == TextDecoration::kOverline) |
295 return font_metrics.FloatAscent() - thickness; | 295 return font_metrics.FloatAscent() - thickness; |
296 if (decoration == kTextDecorationLineThrough) | 296 if (decoration == TextDecoration::kLineThrough) |
297 return font_metrics.FloatAscent() * 3 / 8.0f; | 297 return font_metrics.FloatAscent() * 3 / 8.0f; |
298 | 298 |
299 NOTREACHED(); | 299 NOTREACHED(); |
300 return 0.0f; | 300 return 0.0f; |
301 } | 301 } |
302 | 302 |
303 static inline float ThicknessForDecoration(TextDecoration, const Font& font) { | 303 static inline float ThicknessForDecoration(TextDecoration, const Font& font) { |
304 // FIXME: For SVG Fonts we need to use the attributes defined in the | 304 // FIXME: For SVG Fonts we need to use the attributes defined in the |
305 // <font-face> if specified. | 305 // <font-face> if specified. |
306 // Compatible with Batik/Presto | 306 // Compatible with Batik/Presto |
307 return font.GetFontDescription().ComputedSize() / 20.0f; | 307 return font.GetFontDescription().ComputedSize() / 20.0f; |
308 } | 308 } |
309 | 309 |
310 void SVGInlineTextBoxPainter::PaintDecoration(const PaintInfo& paint_info, | 310 void SVGInlineTextBoxPainter::PaintDecoration(const PaintInfo& paint_info, |
311 TextDecoration decoration, | 311 TextDecoration decoration, |
312 const SVGTextFragment& fragment) { | 312 const SVGTextFragment& fragment) { |
313 if (svg_inline_text_box_.GetLineLayoutItem() | 313 if (svg_inline_text_box_.GetLineLayoutItem() |
314 .Style() | 314 .Style() |
315 ->TextDecorationsInEffect() == kTextDecorationNone) | 315 ->TextDecorationsInEffect() == TextDecoration::kNone) |
316 return; | 316 return; |
317 | 317 |
318 if (fragment.width <= 0) | 318 if (fragment.width <= 0) |
319 return; | 319 return; |
320 | 320 |
321 // Find out which style defined the text-decoration, as its fill/stroke | 321 // Find out which style defined the text-decoration, as its fill/stroke |
322 // properties have to be used for drawing instead of ours. | 322 // properties have to be used for drawing instead of ours. |
323 LayoutObject* decoration_layout_object = | 323 LayoutObject* decoration_layout_object = |
324 FindLayoutObjectDefininingTextDecoration(svg_inline_text_box_.Parent()); | 324 FindLayoutObjectDefininingTextDecoration(svg_inline_text_box_.Parent()); |
325 const ComputedStyle& decoration_style = decoration_layout_object->StyleRef(); | 325 const ComputedStyle& decoration_style = decoration_layout_object->StyleRef(); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 } | 654 } |
655 FloatRect fragment_rect = svg_inline_text_box_.SelectionRectForTextFragment( | 655 FloatRect fragment_rect = svg_inline_text_box_.SelectionRectForTextFragment( |
656 fragment, text_match_info.start_position, text_match_info.end_position, | 656 fragment, text_match_info.start_position, text_match_info.end_position, |
657 style); | 657 style); |
658 paint_info.context.SetFillColor(color); | 658 paint_info.context.SetFillColor(color); |
659 paint_info.context.FillRect(fragment_rect); | 659 paint_info.context.FillRect(fragment_rect); |
660 } | 660 } |
661 } | 661 } |
662 | 662 |
663 } // namespace blink | 663 } // namespace blink |
OLD | NEW |