font.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 
30 #pragma once
31 
32 #include "../api_display.h"
33 #include <memory>
34 #include "../Render/graphic_context.h"
35 #include "../Image/pixel_buffer.h"
36 #include "../2D/sprite.h"
37 #include "../../Core/Signals/callback_2.h"
38 #include "font_description.h"
39 
40 namespace clan
41 {
44 
45 class FontProvider;
46 class Canvas;
47 class Font_Impl;
48 
52 class CL_API_DISPLAY Font
53 {
56 
57 public:
59  Font();
60 
64  Font( Canvas &canvas, const std::string &typeface_name, int height);
65 
66  // \brief Constructs standard font
67  Font( Canvas &canvas, const FontDescription &desc);
68 
69  // \brief Constructs standard font
70  Font( Canvas &canvas, const FontDescription &desc, const std::string &ttf_filename);
71 
72  // \brief Constructs standard font
73  Font( Canvas &canvas, const FontDescription &desc, const std::string &ttf_filename, FileSystem fs);
74 
82  Font( Canvas &canvas, Sprite &sprite, const std::string &glyph_list, int spacelen, bool monospace, const FontMetrics &metrics);
83 
85 
88 public:
94  static Resource<Font> resource(Canvas &canvas, const FontDescription &desc, const ResourceManager &resources);
95 
96 
98 
99 
102 public:
103 
107  bool is_null() const;
108 
112 
113 public:
114 
124  void draw_text(Canvas &canvas, int x, int y, const std::string &text, const Colorf &color = Colorf::white);
125 
135  void draw_text(Canvas &canvas, float x, float y, const std::string &text, const Colorf &color = Colorf::white);
136 
145  void draw_text(Canvas &canvas, const Pointf &position, const std::string &text, const Colorf &color = Colorf::white);
146 
157  void draw_text_ellipsis(Canvas &canvas, int x, int y, Rect content_box, const std::string &text, const Colorf &color = Colorf::white);
158 
169  void draw_text_ellipsis(Canvas &canvas, float x, float y, Rectf content_box, const std::string &text, const Colorf &color = Colorf::white);
170 
180  void draw_text_ellipsis(Canvas &canvas, const Pointf &position, Rectf content_box, const std::string &text, const Colorf &color = Colorf::white);
181 
190  Size get_text_size(Canvas &canvas, const std::string &text);
191 
198  Size get_glyph_size(Canvas &canvas, unsigned int glyph);
199 
201  FontMetrics get_font_metrics();
202 
211  int get_character_index(Canvas &canvas, const std::string &text, const Point &point);
212 
216 
217 private:
218  std::shared_ptr<Font_Impl> impl;
220 };
221 
222 }
223 
225 
Floating point color description class (for float).
Definition: color.h:661
Font description class.
Definition: font_description.h:47
Resource proxy of a specific type.
Definition: resource.h:59
static Colorf white
Definition: color.h:1245
2D Graphics Canvas
Definition: canvas.h:70
Sprite class.
Definition: sprite.h:57
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:453
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:467
Virtual File System (VFS).
Definition: file_system.h:48
Resource manager.
Definition: resource_manager.h:45
2D (x,y) point structure - Integer
Definition: point.h:63
Font class.
Definition: font.h:52
2D (width,height) size structure - Integer
Definition: size.h:157
2D (x,y) point structure - Float
Definition: point.h:73
Font metrics class.
Definition: font_metrics.h:47