1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/paint/ng/ng_text_painter.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/ng_unpositioned_float.h"
#include "third_party/blink/renderer/core/paint/box_painter.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/core/paint/paint_timing_detector.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/shadow_list.h"
#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context_state_saver.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_controller.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
namespace blink {
void NGTextPainter::Paint(unsigned start_offset,
unsigned end_offset,
unsigned length,
const TextPaintStyle& text_style,
DOMNodeId node_id) {
GraphicsContextStateSaver state_saver(graphics_context_, false);
UpdateGraphicsContext(text_style, state_saver);
// TODO(layout-dev): Handle combine text here or elsewhere.
PaintInternal<kPaintText>(start_offset, end_offset, length, node_id);
if (!emphasis_mark_.IsEmpty()) {
if (text_style.emphasis_mark_color != text_style.fill_color)
graphics_context_.SetFillColor(text_style.emphasis_mark_color);
PaintInternal<kPaintEmphasisMark>(start_offset, end_offset, length,
node_id);
}
}
template <NGTextPainter::PaintInternalStep step>
void NGTextPainter::PaintInternalFragment(
unsigned from,
unsigned to,
DOMNodeId node_id) {
DCHECK(from <= fragment_paint_info_.text.length());
DCHECK(to <= fragment_paint_info_.text.length());
fragment_paint_info_.from = from;
fragment_paint_info_.to = to;
if (step == kPaintEmphasisMark) {
graphics_context_.DrawEmphasisMarks(
font_, fragment_paint_info_, emphasis_mark_,
FloatPoint(text_origin_) + IntSize(0, emphasis_mark_offset_));
} else {
DCHECK(step == kPaintText);
graphics_context_.DrawText(font_, fragment_paint_info_,
FloatPoint(text_origin_), node_id);
// TODO(npm): Check that there are non-whitespace characters. See
// crbug.com/788444.
graphics_context_.GetPaintController().SetTextPainted();
if (!font_.ShouldSkipDrawing())
PaintTimingDetector::NotifyTextPaint(visual_rect_);
}
}
template <NGTextPainter::PaintInternalStep Step>
void NGTextPainter::PaintInternal(unsigned start_offset,
unsigned end_offset,
unsigned truncation_point,
DOMNodeId node_id) {
// TODO(layout-dev): We shouldn't be creating text fragments without text.
if (!fragment_paint_info_.shape_result)
return;
if (start_offset <= end_offset) {
PaintInternalFragment<Step>(start_offset, end_offset, node_id);
} else {
if (end_offset > 0) {
PaintInternalFragment<Step>(ellipsis_offset_, end_offset, node_id);
}
if (start_offset < truncation_point) {
PaintInternalFragment<Step>(start_offset, truncation_point, node_id);
}
}
}
void NGTextPainter::ClipDecorationsStripe(float upper,
float stripe_width,
float dilation) {
if (fragment_paint_info_.from >= fragment_paint_info_.to ||
!fragment_paint_info_.shape_result)
return;
Vector<Font::TextIntercept> text_intercepts;
font_.GetTextIntercepts(
fragment_paint_info_, graphics_context_.DeviceScaleFactor(),
graphics_context_.FillFlags(),
std::make_tuple(upper, upper + stripe_width), text_intercepts);
DecorationsStripeIntercepts(upper, stripe_width, dilation, text_intercepts);
}
void NGTextPainter::PaintEmphasisMarkForCombinedText() {}
} // namespace blink
|