| 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 "cc/font_atlas.h" | 5 #include "cc/font_atlas.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (position.y() > clip.height()) | 35 if (position.y() > clip.height()) |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint
, const std::string& textLine, const gfx::Point& destPosition) const | 40 void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint
, const std::string& textLine, const gfx::Point& destPosition) const |
| 41 { | 41 { |
| 42 gfx::Point position = destPosition; | 42 gfx::Point position = destPosition; |
| 43 for (unsigned i = 0; i < textLine.length(); ++i) { | 43 for (unsigned i = 0; i < textLine.length(); ++i) { |
| 44 // If the ASCII code is out of bounds, then index 0 is used, which is ju
st a plain rectangle glyph. | 44 // If the ASCII code is out of bounds, then index 0 is used, which is ju
st a plain rectangle glyph. |
| 45 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; | 45 unsigned asciiIndex = textLine[i]; |
| 46 if (asciiIndex >= 128) |
| 47 asciiIndex = 0; |
| 46 gfx::Rect glyphBounds = m_asciiToRectTable[asciiIndex]; | 48 gfx::Rect glyphBounds = m_asciiToRectTable[asciiIndex]; |
| 47 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly
phBounds.width(), glyphBounds.height()); | 49 SkIRect source = SkIRect::MakeXYWH(glyphBounds.x(), glyphBounds.y(), gly
phBounds.width(), glyphBounds.height()); |
| 48 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(),
position.y(), glyphBounds.width(), glyphBounds.height()), &paint); | 50 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(),
position.y(), glyphBounds.width(), glyphBounds.height()), &paint); |
| 49 position.set_x(position.x() + glyphBounds.width()); | 51 position.set_x(position.x() + glyphBounds.width()); |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 gfx::Size FontAtlas::textSize(const std::string& text) | 55 gfx::Size FontAtlas::textSize(const std::string& text) |
| 54 { | 56 { |
| 55 int maxWidth = 0; | 57 int maxWidth = 0; |
| 56 std::vector<std::string> lines; | 58 std::vector<std::string> lines; |
| 57 base::SplitString(text, '\n', &lines); | 59 base::SplitString(text, '\n', &lines); |
| 58 | 60 |
| 59 for (size_t i = 0; i < lines.size(); ++i) { | 61 for (size_t i = 0; i < lines.size(); ++i) { |
| 60 int lineWidth = 0; | 62 int lineWidth = 0; |
| 61 for (size_t j = 0; j < lines[i].size(); ++j) { | 63 for (size_t j = 0; j < lines[i].size(); ++j) { |
| 62 int asciiIndex = (lines[i][j] < 128) ? lines[i][j] : 0; | 64 unsigned asciiIndex = lines[i][j]; |
| 65 if (asciiIndex >= 128) |
| 66 asciiIndex = 0; |
| 63 lineWidth += m_asciiToRectTable[asciiIndex].width(); | 67 lineWidth += m_asciiToRectTable[asciiIndex].width(); |
| 64 } | 68 } |
| 65 if (lineWidth > maxWidth) | 69 if (lineWidth > maxWidth) |
| 66 maxWidth = lineWidth; | 70 maxWidth = lineWidth; |
| 67 } | 71 } |
| 68 | 72 |
| 69 return gfx::Size(maxWidth, m_fontHeight * lines.size()); | 73 return gfx::Size(maxWidth, m_fontHeight * lines.size()); |
| 70 } | 74 } |
| 71 | 75 |
| 72 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const | 76 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition)
const |
| 73 { | 77 { |
| 74 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); | 78 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); |
| 75 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(),
destPosition.y(), m_atlas.width(), m_atlas.height())); | 79 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(),
destPosition.y(), m_atlas.width(), m_atlas.height())); |
| 76 } | 80 } |
| 77 | 81 |
| 78 } // namespace cc | 82 } // namespace cc |
| OLD | NEW |