Use SCHEME_HTTP for HTTPS proxies on Android.
[chromium-blink-merge.git] / cc / font_atlas.h
blobd18483fba081a44ad82bf43d8b5781a2c31f68ec
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
3 // found in the LICENSE file.
5 #ifndef CC_FONT_ATLAS_H_
6 #define CC_FONT_ATLAS_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/cc_export.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/rect.h"
16 class SkCanvas;
18 namespace gfx {
19 class Point;
20 class Size;
23 namespace cc {
25 // This class provides basic ability to draw text onto the heads-up display.
26 class CC_EXPORT FontAtlas {
27 public:
28 static scoped_ptr<FontAtlas> create(SkBitmap bitmap, gfx::Rect asciiToRectTable[128], int fontHeight)
30 return make_scoped_ptr(new FontAtlas(bitmap, asciiToRectTable, fontHeight));
32 ~FontAtlas();
34 // Current font height.
35 int fontHeight() const { return m_fontHeight; }
37 // Draws multiple lines of text where each line of text is separated by '\n'.
38 // - Correct glyphs will be drawn for ASCII codes in the range 32-127; any characters
39 // outside that range will be displayed as a default rectangle glyph.
40 // - gfx::Size clip is used to avoid wasting time drawing things that are outside the
41 // target canvas bounds.
42 // - Should only be called only on the impl thread.
43 void drawText(SkCanvas*, const SkPaint&, const std::string& text, const gfx::Point& destPosition, const gfx::Size& clip) const;
45 // Gives a text's width and height on the canvas.
46 gfx::Size textSize(const std::string& text);
48 // Draws the entire atlas at the specified position, just for debugging purposes.
49 void drawDebugAtlas(SkCanvas*, const gfx::Point& destPosition) const;
51 private:
52 FontAtlas(SkBitmap, gfx::Rect asciiToRectTable[128], int fontHeight);
54 void drawOneLineOfTextInternal(SkCanvas*, const SkPaint&, const std::string&, const gfx::Point& destPosition) const;
56 // The actual texture atlas containing all the pre-rendered glyphs.
57 SkBitmap m_atlas;
59 // The look-up tables mapping ascii characters to their gfx::Rect locations on the atlas.
60 gfx::Rect m_asciiToRectTable[128];
62 int m_fontHeight;
64 DISALLOW_COPY_AND_ASSIGN(FontAtlas);
67 } // namespace cc
69 #endif // CC_FONT_ATLAS_H_