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

Side by Side Diff: cc/font_atlas.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaseagain Created 8 years, 1 month 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
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 "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
11 #include "base/string_split.h" 11 #include "base/string_split.h"
12 #include "cc/proxy.h" 12 #include "cc/proxy.h"
13 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "ui/gfx/point.h"
15 #include "ui/gfx/size.h"
16 14
17 namespace cc { 15 namespace cc {
18 16
19 FontAtlas::FontAtlas(SkBitmap bitmap, IntRect asciiToRectTable[128], int fontHei ght) 17 FontAtlas::FontAtlas(SkBitmap bitmap, gfx::Rect asciiToRectTable[128], int fontH eight)
20 : m_atlas(bitmap) 18 : m_atlas(bitmap)
21 , m_fontHeight(fontHeight) 19 , m_fontHeight(fontHeight)
22 { 20 {
23 for (size_t i = 0; i < 128; ++i) 21 for (size_t i = 0; i < 128; ++i)
24 m_asciiToRectTable[i] = asciiToRectTable[i]; 22 m_asciiToRectTable[i] = asciiToRectTable[i];
25 } 23 }
26 24
27 FontAtlas::~FontAtlas() 25 FontAtlas::~FontAtlas()
28 { 26 {
29 } 27 }
(...skipping 15 matching lines...) Expand all
45 } 43 }
46 44
47 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
48 { 46 {
49 DCHECK(Proxy::isImplThread()); 47 DCHECK(Proxy::isImplThread());
50 48
51 gfx::Point position = destPosition; 49 gfx::Point position = destPosition;
52 for (unsigned i = 0; i < textLine.length(); ++i) { 50 for (unsigned i = 0; i < textLine.length(); ++i) {
53 // 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.
54 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0; 52 int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0;
55 IntRect glyphBounds = m_asciiToRectTable[asciiIndex]; 53 gfx::Rect glyphBounds = m_asciiToRectTable[asciiIndex];
56 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());
57 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);
58 position.set_x(position.x() + glyphBounds.width()); 56 position.set_x(position.x() + glyphBounds.width());
59 } 57 }
60 } 58 }
61 59
62 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition) const 60 void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition) const
63 { 61 {
64 DCHECK(Proxy::isImplThread()); 62 DCHECK(Proxy::isImplThread());
65 63
66 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); 64 SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height());
67 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height())); 65 canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height()));
68 } 66 }
69 67
70 } // namespace cc 68 } // namespace cc
OLDNEW
« cc/font_atlas.h ('K') | « cc/font_atlas.h ('k') | cc/geometry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698