Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: cc/font_atlas.cc

Issue 11416239: Fix tautological compares in font_atlas.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698