| 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 #ifndef CC_FONT_ATLAS_H_ | 5 #ifndef CC_FONT_ATLAS_H_ |
| 6 #define CC_FONT_ATLAS_H_ | 6 #define CC_FONT_ATLAS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // This class provides basic ability to draw text onto the heads-up display. | 25 // This class provides basic ability to draw text onto the heads-up display. |
| 26 class CC_EXPORT FontAtlas { | 26 class CC_EXPORT FontAtlas { |
| 27 public: | 27 public: |
| 28 static scoped_ptr<FontAtlas> create(SkBitmap bitmap, gfx::Rect asciiToRectTa
ble[128], int fontHeight) | 28 static scoped_ptr<FontAtlas> create(SkBitmap bitmap, gfx::Rect asciiToRectTa
ble[128], int fontHeight) |
| 29 { | 29 { |
| 30 return make_scoped_ptr(new FontAtlas(bitmap, asciiToRectTable, fontHeigh
t)); | 30 return make_scoped_ptr(new FontAtlas(bitmap, asciiToRectTable, fontHeigh
t)); |
| 31 } | 31 } |
| 32 ~FontAtlas(); | 32 ~FontAtlas(); |
| 33 | 33 |
| 34 // Current font height. |
| 35 int fontHeight() const { return m_fontHeight; } |
| 36 |
| 34 // Draws multiple lines of text where each line of text is separated by '\n'
. | 37 // Draws multiple lines of text where each line of text is separated by '\n'
. |
| 35 // - Correct glyphs will be drawn for ASCII codes in the range 32-127; any c
haracters | 38 // - Correct glyphs will be drawn for ASCII codes in the range 32-127; any c
haracters |
| 36 // outside that range will be displayed as a default rectangle glyph. | 39 // outside that range will be displayed as a default rectangle glyph. |
| 37 // - gfx::Size clip is used to avoid wasting time drawing things that are ou
tside the | 40 // - gfx::Size clip is used to avoid wasting time drawing things that are ou
tside the |
| 38 // target canvas bounds. | 41 // target canvas bounds. |
| 39 // - Should only be called only on the impl thread. | 42 // - Should only be called only on the impl thread. |
| 40 void drawText(SkCanvas*, const SkPaint&, const std::string& text, const gfx:
:Point& destPosition, const gfx::Size& clip) const; | 43 void drawText(SkCanvas*, const SkPaint&, const std::string& text, const gfx:
:Point& destPosition, const gfx::Size& clip) const; |
| 41 | 44 |
| 45 // Gives a text's width and height on the canvas. |
| 46 gfx::Size textSize(const std::string& text); |
| 47 |
| 42 // Draws the entire atlas at the specified position, just for debugging purp
oses. | 48 // Draws the entire atlas at the specified position, just for debugging purp
oses. |
| 43 void drawDebugAtlas(SkCanvas*, const gfx::Point& destPosition) const; | 49 void drawDebugAtlas(SkCanvas*, const gfx::Point& destPosition) const; |
| 44 | 50 |
| 45 private: | 51 private: |
| 46 FontAtlas(SkBitmap, gfx::Rect asciiToRectTable[128], int fontHeight); | 52 FontAtlas(SkBitmap, gfx::Rect asciiToRectTable[128], int fontHeight); |
| 47 | 53 |
| 48 void drawOneLineOfTextInternal(SkCanvas*, const SkPaint&, const std::string&
, const gfx::Point& destPosition) const; | 54 void drawOneLineOfTextInternal(SkCanvas*, const SkPaint&, const std::string&
, const gfx::Point& destPosition) const; |
| 49 | 55 |
| 50 // The actual texture atlas containing all the pre-rendered glyphs. | 56 // The actual texture atlas containing all the pre-rendered glyphs. |
| 51 SkBitmap m_atlas; | 57 SkBitmap m_atlas; |
| 52 | 58 |
| 53 // The look-up tables mapping ascii characters to their gfx::Rect locations
on the atlas. | 59 // The look-up tables mapping ascii characters to their gfx::Rect locations
on the atlas. |
| 54 gfx::Rect m_asciiToRectTable[128]; | 60 gfx::Rect m_asciiToRectTable[128]; |
| 55 | 61 |
| 56 int m_fontHeight; | 62 int m_fontHeight; |
| 57 | 63 |
| 58 DISALLOW_COPY_AND_ASSIGN(FontAtlas); | 64 DISALLOW_COPY_AND_ASSIGN(FontAtlas); |
| 59 }; | 65 }; |
| 60 | 66 |
| 61 } // namespace cc | 67 } // namespace cc |
| 62 | 68 |
| 63 #endif // CC_FONT_ATLAS_H_ | 69 #endif // CC_FONT_ATLAS_H_ |
| OLD | NEW |