2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#ifndef __CAIRO_DOCK_OPENGL_FONT__
22
#define __CAIRO_DOCK_OPENGL_FONT__
26
#include <gdk/x11/gdkglx.h>
27
#include <gtk/gtkgl.h>
30
#include "cairo-dock-struct.h"
35
*@file cairo-dock-opengl-font.h This class provides different ways to draw text directly in OpenGL.
36
* \ref cairo_dock_create_texture_from_text_simple lets you draw any text in any font, by creating a texture from a Pango font description. This is a convenient function but not very fast.
37
* For a more efficient way, you load a font into a CairoDockGLFont with either :
38
* \ref cairo_dock_load_bitmap_font to load a subset of any font into bitmaps (bitmaps are not influenced by the transformation matrix)
39
* \ref cairo_dock_load_textured_font to load a subset of a Mono font into textures.
40
* You then use \ref cairo_dock_draw_gl_text_at_position to draw the text.
43
/** Create a texture from a text. The text is drawn in white, so that you can later colorize it with a mere glColor.
44
*@param cText the text
45
*@param cFontDescription a description of the font, for instance "Monospace Bold 12"
46
*@param pSourceContext a cairo context, not altered by the function.
47
*@param iWidth a pointer that will be filled with the width of the texture.
48
*@param iHeight a pointer that will be filled with the height of the texture.
49
*@return a newly allocated texture.
51
GLuint cairo_dock_create_texture_from_text_simple (const gchar *cText, const gchar *cFontDescription, cairo_t* pSourceContext, int *iWidth, int *iHeight);
53
/// Structure used to load a font for OpenGL text rendering.
54
struct _CairoDockGLFont {
65
/** Load a font into bitmaps. You can load any characters of font with this function. The drawback is that each character is a bitmap, that is to say you can't zoom them.
66
*@param cFontDescription a description of the font, for instance "Monospace Bold 12"
67
*@param first first character to load.
68
*@param count number of characters to load.
69
*@return a newly allocated opengl font.
71
CairoDockGLFont *cairo_dock_load_bitmap_font (const gchar *cFontDescription, int first, int count);
73
/** Load a font into textures. You can then render your text like a normal texture (zoom, etc). The drawback is that only a mono font can be used with this function.
74
*@param cFontDescription a description of the font, for instance "Monospace Bold 12"
75
*@param first first character to load.
76
*@param count number of characters to load.
77
*@return a newly allocated opengl font.
79
CairoDockGLFont *cairo_dock_load_textured_font (const gchar *cFontDescription, int first, int count);
81
/** Like the previous function, but loads the characters from an image. The image must be squared and contain the 256 extended ASCII characters in the alphabetic order.
82
*@param cImagePath path to the image.
83
*@return a newly allocated opengl font.
85
CairoDockGLFont *cairo_dock_load_textured_font_from_image (const gchar *cImagePath);
87
/** Free an opengl font.
88
*@param pFont the font.
90
void cairo_dock_free_gl_font (CairoDockGLFont *pFont);
92
/** Compute the size a text will take for a given font.
93
*@param cText the text
94
*@param pFont the font.
95
*@param iWidth a pointer that will be filled with the width of the text.
96
*@param iHeight a pointer that will be filled with the height of the text.
98
void cairo_dock_get_gl_text_extent (const gchar *cText, CairoDockGLFont *pFont, int *iWidth, int *iHeight);
100
/** Render a text for a given font. In the case of a bitmap font, the current raster position is used. In the case of a texture font, the current model view is used.
101
*@param cText the text
102
*@param pFont the font.
104
void cairo_dock_draw_gl_text (const guchar *cText, CairoDockGLFont *pFont);
106
/** Like /ref cairo_dock_draw_gl_text but at a given position.
107
*@param cText the text
108
*@param pFont the font.
109
*@param x x position of the left bottom corner of the text.
110
*@param y y position of the left bottom corner of the text.
112
void cairo_dock_draw_gl_text_at_position (const guchar *cText, CairoDockGLFont *pFont, int x, int y);
114
/** Like /ref cairo_dock_draw_gl_text but resize the text so that it fits into a given area. Only works for a texture font.
115
*@param cText the text
116
*@param pFont the font.
117
*@param iWidth iWidth of the area.
118
*@param iHeight iHeight of the area
119
*@param bCentered whether the text is centered on the current position or not.
121
void cairo_dock_draw_gl_text_in_area (const guchar *cText, CairoDockGLFont *pFont, int iWidth, int iHeight, gboolean bCentered);
123
/** Like /ref cairo_dock_draw_gl_text_in_area and /ref cairo_dock_draw_gl_text_at_position.
124
*@param cText the text
125
*@param pFont the font.
126
*@param x x position of the left bottom corner of the text.
127
*@param y y position of the left bottom corner of the text.
128
*@param iWidth iWidth of the area.
129
*@param iHeight iHeight of the area
130
*@param bCentered whether the text is centered on the given position or not.
132
void cairo_dock_draw_gl_text_at_position_in_area (const guchar *cText, CairoDockGLFont *pFont, int x, int y, int iWidth, int iHeight, gboolean bCentered);