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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
58 } | 58 } |
59 | 59 |
| 60 gfx::Size FontAtlas::textSize(const std::string& text) |
| 61 { |
| 62 int maxWidth = 0; |
| 63 std::vector<std::string> lines; |
| 64 base::SplitString(text, '\n', &lines); |
| 65 |
| 66 for (size_t i = 0; i < lines.size(); ++i) { |
| 67 int lineWidth = 0; |
| 68 for (size_t j = 0; j < lines[i].size(); ++j) { |
| 69 int asciiIndex = (lines[i][j] < 128) ? lines[i][j] : 0; |
| 70 lineWidth += m_asciiToRectTable[asciiIndex].width(); |
| 71 } |
| 72 if (lineWidth > maxWidth) |
| 73 maxWidth = lineWidth; |
| 74 } |
| 75 |
| 76 return gfx::Size(maxWidth, m_fontHeight * lines.size()); |
| 77 } |
| 78 |
60 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const | 79 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const |
61 { | 80 { |
62 DCHECK(Proxy::isImplThread()); | 81 DCHECK(Proxy::isImplThread()); |
63 | 82 |
64 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); | 83 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); |
65 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())); |
66 } | 85 } |
67 | 86 |
68 } // namespace cc | 87 } // namespace cc |
OLD | NEW |