OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "public/platform/WebFont.h" | 5 #include "public/platform/WebFont.h" |
6 | 6 |
7 #include "platform/fonts/Font.h" | 7 #include "platform/fonts/Font.h" |
8 #include "platform/fonts/FontCache.h" | 8 #include "platform/fonts/FontCache.h" |
9 #include "platform/fonts/FontDescription.h" | 9 #include "platform/fonts/FontDescription.h" |
10 #include "platform/graphics/GraphicsContext.h" | 10 #include "platform/graphics/GraphicsContext.h" |
11 #include "platform/graphics/paint/DisplayItemClient.h" | |
12 #include "platform/graphics/paint/DrawingRecorder.h" | 11 #include "platform/graphics/paint/DrawingRecorder.h" |
13 #include "platform/graphics/paint/SkPictureBuilder.h" | 12 #include "platform/graphics/paint/SkPictureBuilder.h" |
14 #include "platform/text/TextRun.h" | 13 #include "platform/text/TextRun.h" |
15 #include "public/platform/WebFloatPoint.h" | 14 #include "public/platform/WebFloatPoint.h" |
16 #include "public/platform/WebFloatRect.h" | 15 #include "public/platform/WebFloatRect.h" |
17 #include "public/platform/WebFontDescription.h" | 16 #include "public/platform/WebFontDescription.h" |
18 #include "public/platform/WebRect.h" | 17 #include "public/platform/WebRect.h" |
19 #include "public/platform/WebTextRun.h" | 18 #include "public/platform/WebTextRun.h" |
20 | 19 |
21 namespace blink { | 20 namespace blink { |
22 | 21 |
23 WebFont* WebFont::create(const WebFontDescription& description) | 22 WebFont* WebFont::create(const WebFontDescription& description) |
24 { | 23 { |
25 return new WebFont(description); | 24 return new WebFont(description); |
26 } | 25 } |
27 | 26 |
28 class WebFont::Impl final : public DisplayItemClient { | 27 class WebFont::Impl final { |
29 public: | 28 public: |
30 explicit Impl(const WebFontDescription& description) | 29 explicit Impl(const WebFontDescription& description) |
31 : m_font(description) | 30 : m_font(description) |
32 { | 31 { |
33 m_font.update(nullptr); | 32 m_font.update(nullptr); |
34 } | 33 } |
35 | 34 |
36 const Font& getFont() const { return m_font; } | 35 const Font& getFont() const { return m_font; } |
37 String debugName() const final { return "WebFont::Impl"; } | |
38 LayoutRect visualRect() const final | |
39 { | |
40 // TODO(chrishtr): fix this. | |
41 return LayoutRect(); | |
42 } | |
43 | 36 |
44 private: | 37 private: |
45 Font m_font; | 38 Font m_font; |
46 }; | 39 }; |
47 | 40 |
48 WebFont::WebFont(const WebFontDescription& description) | 41 WebFont::WebFont(const WebFontDescription& description) |
49 : m_private(new Impl(description)) | 42 : m_private(new Impl(description)) |
50 { | 43 { |
51 } | 44 } |
52 | 45 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 FontCachePurgePreventer fontCachePurgePreventer; | 84 FontCachePurgePreventer fontCachePurgePreventer; |
92 FloatRect textClipRect(clip); | 85 FloatRect textClipRect(clip); |
93 TextRun textRun(run); | 86 TextRun textRun(run); |
94 TextRunPaintInfo runInfo(textRun); | 87 TextRunPaintInfo runInfo(textRun); |
95 runInfo.bounds = textClipRect; | 88 runInfo.bounds = textClipRect; |
96 | 89 |
97 IntRect intRect(clip); | 90 IntRect intRect(clip); |
98 SkPictureBuilder pictureBuilder(intRect); | 91 SkPictureBuilder pictureBuilder(intRect); |
99 GraphicsContext& context = pictureBuilder.context(); | 92 GraphicsContext& context = pictureBuilder.context(); |
100 | 93 |
101 ASSERT(!DrawingRecorder::useCachedDrawingIfPossible(context, *m_private, Dis
playItem::WebFont)); | |
102 { | 94 { |
103 DrawingRecorder drawingRecorder(context, *m_private, DisplayItem::WebFon
t, intRect); | 95 DrawingRecorder drawingRecorder(context, pictureBuilder, DisplayItem::We
bFont, intRect); |
104 context.save(); | 96 context.save(); |
105 context.setFillColor(color); | 97 context.setFillColor(color); |
106 context.clip(textClipRect); | 98 context.clip(textClipRect); |
107 context.drawText(m_private->getFont(), runInfo, leftBaseline); | 99 context.drawText(m_private->getFont(), runInfo, leftBaseline); |
108 context.restore(); | 100 context.restore(); |
109 } | 101 } |
110 | 102 |
111 pictureBuilder.endRecording()->playback(canvas); | 103 pictureBuilder.endRecording()->playback(canvas); |
112 } | 104 } |
113 | 105 |
114 int WebFont::calculateWidth(const WebTextRun& run) const | 106 int WebFont::calculateWidth(const WebTextRun& run) const |
115 { | 107 { |
116 return m_private->getFont().width(run, 0); | 108 return m_private->getFont().width(run, 0); |
117 } | 109 } |
118 | 110 |
119 int WebFont::offsetForPosition(const WebTextRun& run, float position) const | 111 int WebFont::offsetForPosition(const WebTextRun& run, float position) const |
120 { | 112 { |
121 return m_private->getFont().offsetForPosition(run, position, true); | 113 return m_private->getFont().offsetForPosition(run, position, true); |
122 } | 114 } |
123 | 115 |
124 WebFloatRect WebFont::selectionRectForText(const WebTextRun& run, const WebFloat
Point& leftBaseline, int height, int from, int to) const | 116 WebFloatRect WebFont::selectionRectForText(const WebTextRun& run, const WebFloat
Point& leftBaseline, int height, int from, int to) const |
125 { | 117 { |
126 return m_private->getFont().selectionRectForText(run, leftBaseline, height,
from, to); | 118 return m_private->getFont().selectionRectForText(run, leftBaseline, height,
from, to); |
127 } | 119 } |
128 | 120 |
129 } // namespace blink | 121 } // namespace blink |
OLD | NEW |