font.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00031 
00032 #pragma once
00033 
00034 #include "../api_display.h"
00035 #include "../../Core/System/sharedptr.h"
00036 #include "../Render/graphic_context.h"
00037 #include "../Image/pixel_buffer.h"
00038 #include "font_description.h"
00039 
00040 class CL_FontProvider;
00041 class CL_Font_Impl;
00042 
00046 class CL_API_DISPLAY CL_Font
00047 {
00050 
00051 public:
00053         CL_Font();
00054 
00055         // \brief Constructs standard font - Currently this defaults to CL_Font_System
00056         CL_Font( CL_GraphicContext &context, const CL_StringRef &typeface_name, int height);
00057 
00058         // \brief Constructs standard font - Currently this defaults to CL_Font_System
00059         CL_Font( CL_GraphicContext &context, const CL_FontDescription &desc);
00060 
00064         CL_Font(CL_FontProvider *provider);
00065 
00069         CL_Font(const CL_Font &copy);
00070 
00071         virtual ~CL_Font();
00072 
00076 
00077 public:
00078 
00082         bool is_null() const;
00083 
00085         CL_FontProvider *get_provider() const;
00086 
00090 
00091 public:
00092 
00102         void draw_text(CL_GraphicContext &gc, int x, int y, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);
00103 
00113         void draw_text(CL_GraphicContext &gc, float x, float y, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);
00114 
00123         void draw_text(CL_GraphicContext &gc, const CL_Pointf &position, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);
00124 
00135         void draw_text_ellipsis(CL_GraphicContext &gc, int x, int y, CL_Rect content_box, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);
00136 
00147         void draw_text_ellipsis(CL_GraphicContext &gc, float x, float y, CL_Rectf content_box, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);
00148 
00158         void draw_text_ellipsis(CL_GraphicContext &gc, const CL_Pointf &position, CL_Rectf content_box, const CL_StringRef &text, const CL_Colorf &color = CL_Colorf::white);
00159 
00168         CL_Size get_text_size(CL_GraphicContext &gc, const CL_StringRef &text);
00169 
00176         CL_Size get_glyph_size(CL_GraphicContext &gc, unsigned int glyph);
00177 
00179         CL_FontMetrics get_font_metrics();
00180 
00189         int get_character_index(CL_GraphicContext &gc, const CL_String &text, const CL_Point &point);
00190 
00194 
00195 private:
00196         CL_SharedPtr<CL_Font_Impl> impl;
00198 };
00199 
00203 class CL_API_DISPLAY CL_FontPixelBuffer
00204 {
00205 public:
00206         CL_FontPixelBuffer() : glyph(0), empty_buffer(true), offset(0,0), increment(0,0) { };
00207 
00209         unsigned int glyph;
00210 
00212         bool empty_buffer;
00213 
00215         CL_PixelBuffer buffer;
00216 
00218         CL_Rect buffer_rect;
00219 
00221 
00224         CL_Point offset;
00225 
00227 
00230         CL_Point increment;
00231 };
00232 
00234