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_
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"
25 // This class provides basic ability to draw text onto the heads-up display.
26 class CC_EXPORT FontAtlas
{
28 static scoped_ptr
<FontAtlas
> create(SkBitmap bitmap
, gfx::Rect asciiToRectTable
[128], int fontHeight
)
30 return make_scoped_ptr(new FontAtlas(bitmap
, asciiToRectTable
, fontHeight
));
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;
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.
59 // The look-up tables mapping ascii characters to their gfx::Rect locations on the atlas.
60 gfx::Rect m_asciiToRectTable
[128];
64 DISALLOW_COPY_AND_ASSIGN(FontAtlas
);
69 #endif // CC_FONT_ATLAS_H_