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 
79  Font( Canvas &canvas, Sprite &sprite, const std::string &glyph_list, int spacelen, bool monospace, const FontMetrics &metrics);
80 
82 
85 public:
91  static Resource<Font> resource(Canvas &canvas, const FontDescription &desc, const ResourceManager &resources);
92 
93 
95 
96 
99 public:
100 
104  bool is_null() const;
105 
109 
110 public:
111 
121  void draw_text(Canvas &canvas, int x, int y, const std::string &text, const Colorf &color = Colorf::white);
122 
132  void draw_text(Canvas &canvas, float x, float y, const std::string &text, const Colorf &color = Colorf::white);
133 
142  void draw_text(Canvas &canvas, const Pointf &position, const std::string &text, const Colorf &color = Colorf::white);
143 
154  void draw_text_ellipsis(Canvas &canvas, int x, int y, Rect content_box, const std::string &text, const Colorf &color = Colorf::white);
155 
166  void draw_text_ellipsis(Canvas &canvas, float x, float y, Rectf content_box, const std::string &text, const Colorf &color = Colorf::white);
167 
177  void draw_text_ellipsis(Canvas &canvas, const Pointf &position, Rectf content_box, const std::string &text, const Colorf &color = Colorf::white);
178 
187  Size get_text_size(Canvas &canvas, const std::string &text);
188 
195  Size get_glyph_size(Canvas &canvas, unsigned int glyph);
196 
198  FontMetrics get_font_metrics();
199 
208  int get_character_index(Canvas &canvas, const std::string &text, const Point &point);
209 
213 
214 private:
215  std::shared_ptr<Font_Impl> impl;
217 };
218 
219 }
220 
222 
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
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