Chromium Code Reviews| 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 "CCFontAtlas.h" | 7 #include "CCFontAtlas.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 for (unsigned i = 0; i < textLine.length(); ++i) { | 53 for (unsigned i = 0; i < textLine.length(); ++i) { |
| 54 // If the ASCII code is out of bounds, then index 0 is used, which is ju st a plain rectangle glyph. | 54 // If the ASCII code is out of bounds, then index 0 is used, which is ju st a plain rectangle glyph. |
| 55 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; | 55 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; |
| 56 IntRect glyphBounds = m_asciiToRectTable[asciiIndex]; | 56 IntRect glyphBounds = m_asciiToRectTable[asciiIndex]; |
| 57 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly phBounds.width(), glyphBounds.height()); | 57 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly phBounds.width(), glyphBounds.height()); |
| 58 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(), position.y(), glyphBounds.width(), glyphBounds.height()), &paint); | 58 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(), position.y(), glyphBounds.width(), glyphBounds.height()), &paint); |
| 59 position.set_x(position.x() + glyphBounds.width()); | 59 position.set_x(position.x() + glyphBounds.width()); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 IntSize FontAtlas::textSize(const std::string& text) | |
|
egraether
2012/10/26 00:06:52
This new method calculates the screen text size of
| |
| 64 { | |
| 65 int maxWidth = 0; | |
| 66 std::vector<std::string> lines; | |
| 67 base::SplitString(text, '\n', &lines); | |
| 68 | |
| 69 for (size_t i = 0; i < lines.size(); ++i) { | |
| 70 int lineWidth = 0; | |
| 71 for (size_t j = 0; j < lines[i].size(); ++j) { | |
| 72 int asciiIndex = (lines[i][j] < 128) ? lines[i][j] : 0; | |
| 73 lineWidth += m_asciiToRectTable[asciiIndex].width(); | |
| 74 } | |
| 75 if (lineWidth > maxWidth) | |
| 76 maxWidth = lineWidth; | |
| 77 } | |
| 78 | |
| 79 return IntSize(maxWidth, m_fontHeight * lines.size()); | |
| 80 } | |
| 81 | |
| 63 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition) const | 82 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition) const |
| 64 { | 83 { |
| 65 DCHECK(Proxy::isImplThread()); | 84 DCHECK(Proxy::isImplThread()); |
| 66 | 85 |
| 67 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); | 86 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); |
| 68 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height())); | 87 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height())); |
| 69 } | 88 } |
| 70 | 89 |
| 71 } // namespace cc | 90 } // namespace cc |
| OLD | NEW |