OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "sky/engine/web/WebFontImpl.h" | |
32 | |
33 #include "skia/ext/platform_canvas.h" | |
34 #include "sky/engine/platform/fonts/FontCache.h" | |
35 #include "sky/engine/platform/fonts/FontDescription.h" | |
36 #include "sky/engine/platform/graphics/GraphicsContext.h" | |
37 #include "sky/engine/platform/text/TextRun.h" | |
38 #include "sky/engine/public/platform/WebFloatPoint.h" | |
39 #include "sky/engine/public/platform/WebFloatRect.h" | |
40 #include "sky/engine/public/platform/WebRect.h" | |
41 #include "sky/engine/public/web/WebFontDescription.h" | |
42 #include "sky/engine/public/web/WebTextRun.h" | |
43 | |
44 namespace blink { | |
45 | |
46 WebFont* WebFont::create(const WebFontDescription& desc) | |
47 { | |
48 return new WebFontImpl(desc); | |
49 } | |
50 | |
51 WebFontImpl::WebFontImpl(const FontDescription& desc) | |
52 : m_font(desc) | |
53 { | |
54 m_font.update(nullptr); | |
55 } | |
56 | |
57 WebFontDescription WebFontImpl::fontDescription() const | |
58 { | |
59 return WebFontDescription(m_font.fontDescription()); | |
60 } | |
61 | |
62 int WebFontImpl::ascent() const | |
63 { | |
64 return m_font.fontMetrics().ascent(); | |
65 } | |
66 | |
67 int WebFontImpl::descent() const | |
68 { | |
69 return m_font.fontMetrics().descent(); | |
70 } | |
71 | |
72 int WebFontImpl::height() const | |
73 { | |
74 return m_font.fontMetrics().height(); | |
75 } | |
76 | |
77 int WebFontImpl::lineSpacing() const | |
78 { | |
79 return m_font.fontMetrics().lineSpacing(); | |
80 } | |
81 | |
82 float WebFontImpl::xHeight() const | |
83 { | |
84 return m_font.fontMetrics().xHeight(); | |
85 } | |
86 | |
87 void WebFontImpl::drawText(WebCanvas* canvas, const WebTextRun& run, const WebFl
oatPoint& leftBaseline, | |
88 WebColor color, const WebRect& clip, bool canvasIsOpa
que, | |
89 int from, int to) const | |
90 { | |
91 FontCachePurgePreventer fontCachePurgePreventer; | |
92 FloatRect textClipRect(clip); | |
93 TextRun textRun(run); | |
94 TextRunPaintInfo runInfo(textRun); | |
95 runInfo.from = from; | |
96 runInfo.to = to == -1 ? textRun.length() : to; | |
97 runInfo.bounds = textClipRect; | |
98 GraphicsContext gc(canvas); | |
99 | |
100 gc.save(); | |
101 gc.setCertainlyOpaque(canvasIsOpaque); | |
102 gc.setFillColor(color); | |
103 gc.clip(textClipRect); | |
104 m_font.drawText(&gc, runInfo, leftBaseline); | |
105 gc.restore(); | |
106 } | |
107 | |
108 int WebFontImpl::calculateWidth(const WebTextRun& run) const | |
109 { | |
110 FontCachePurgePreventer fontCachePurgePreventer; | |
111 return m_font.width(run, 0); | |
112 } | |
113 | |
114 int WebFontImpl::offsetForPosition(const WebTextRun& run, float position) const | |
115 { | |
116 FontCachePurgePreventer fontCachePurgePreventer; | |
117 return m_font.offsetForPosition(run, position, true); | |
118 } | |
119 | |
120 WebFloatRect WebFontImpl::selectionRectForText(const WebTextRun& run, const WebF
loatPoint& leftBaseline, int height, int from, int to) const | |
121 { | |
122 FontCachePurgePreventer fontCachePurgePreventer; | |
123 return m_font.selectionRectForText(run, leftBaseline, height, from, to); | |
124 } | |
125 | |
126 } // namespace blink | |
OLD | NEW |