OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/font_atlas.h" | 7 #include "cc/font_atlas.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 for (size_t i = 0; i < 128; ++i) | 21 for (size_t i = 0; i < 128; ++i) |
22 m_asciiToRectTable[i] = asciiToRectTable[i]; | 22 m_asciiToRectTable[i] = asciiToRectTable[i]; |
23 } | 23 } |
24 | 24 |
25 FontAtlas::~FontAtlas() | 25 FontAtlas::~FontAtlas() |
26 { | 26 { |
27 } | 27 } |
28 | 28 |
29 void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::stri
ng& text, const gfx::Point& destPosition, const gfx::Size& clip) const | 29 void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::stri
ng& text, const gfx::Point& destPosition, const gfx::Size& clip) const |
30 { | 30 { |
31 DCHECK(Proxy::isImplThread()); | 31 DCHECK(m_threadChecker.CalledOnValidThread()); |
32 | 32 |
33 std::vector<std::string> lines; | 33 std::vector<std::string> lines; |
34 base::SplitString(text, '\n', &lines); | 34 base::SplitString(text, '\n', &lines); |
35 | 35 |
36 gfx::Point position = destPosition; | 36 gfx::Point position = destPosition; |
37 for (size_t i = 0; i < lines.size(); ++i) { | 37 for (size_t i = 0; i < lines.size(); ++i) { |
38 drawOneLineOfTextInternal(canvas, paint, lines[i], position); | 38 drawOneLineOfTextInternal(canvas, paint, lines[i], position); |
39 position.set_y(position.y() + m_fontHeight); | 39 position.set_y(position.y() + m_fontHeight); |
40 if (position.y() > clip.height()) | 40 if (position.y() > clip.height()) |
41 return; | 41 return; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint
, const std::string& textLine, const gfx::Point& destPosition) const | 45 void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint
, const std::string& textLine, const gfx::Point& destPosition) const |
46 { | 46 { |
47 DCHECK(Proxy::isImplThread()); | 47 DCHECK(m_threadChecker.CalledOnValidThread()); |
48 | 48 |
49 gfx::Point position = destPosition; | 49 gfx::Point position = destPosition; |
50 for (unsigned i = 0; i < textLine.length(); ++i) { | 50 for (unsigned i = 0; i < textLine.length(); ++i) { |
51 // If the ASCII code is out of bounds, then index 0 is used, which is ju
st a plain rectangle glyph. | 51 // If the ASCII code is out of bounds, then index 0 is used, which is ju
st a plain rectangle glyph. |
52 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; | 52 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; |
53 gfx::Rect glyphBounds = m_asciiToRectTable[asciiIndex]; | 53 gfx::Rect glyphBounds = m_asciiToRectTable[asciiIndex]; |
54 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly
phBounds.width(), glyphBounds.height()); | 54 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly
phBounds.width(), glyphBounds.height()); |
55 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(),
position.y(), glyphBounds.width(), glyphBounds.height()), &paint); | 55 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(),
position.y(), glyphBounds.width(), glyphBounds.height()), &paint); |
56 position.set_x(position.x() + glyphBounds.width()); | 56 position.set_x(position.x() + glyphBounds.width()); |
57 } | 57 } |
(...skipping 13 matching lines...) Expand all Loading... |
71 } | 71 } |
72 if (lineWidth > maxWidth) | 72 if (lineWidth > maxWidth) |
73 maxWidth = lineWidth; | 73 maxWidth = lineWidth; |
74 } | 74 } |
75 | 75 |
76 return gfx::Size(maxWidth, m_fontHeight * lines.size()); | 76 return gfx::Size(maxWidth, m_fontHeight * lines.size()); |
77 } | 77 } |
78 | 78 |
79 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const | 79 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const |
80 { | 80 { |
81 DCHECK(Proxy::isImplThread()); | 81 DCHECK(m_threadChecker.CalledOnValidThread()); |
82 | 82 |
83 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); | 83 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); |
84 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(),
destPosition.y(), m_atlas.width(), m_atlas.height())); | 84 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(),
destPosition.y(), m_atlas.width(), m_atlas.height())); |
85 } | 85 } |
86 | 86 |
87 } // namespace cc | 87 } // namespace cc |
OLD | NEW |