LibMB 1.12
mbexp.h
1/* libmb
2 * Copyright (C) 2002 Matthew Allum
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20/*
21 * XXXXXXXXX WARNING XXXXXXXXXXXX
22 *
23 * mbexp contains experimetal unstable code that is subject to
24 * constant change and therefore USE AT YOUR OWN RISK.
25 *
26 * XXXXXXXXX WARNING XXXXXXXXXXXX
27 */
28
29#ifndef _MB_EXP_H_
30#define _MB_EXP_H_
31
32#include <libmb/mbconfig.h>
33#include <libmb/mbpixbuf.h>
34#include <libmb/mbdotdesktop.h>
35
36#ifdef USE_XFT
37#include <X11/Xft/Xft.h>
38#include <locale.h>
39#include <langinfo.h>
40#endif
41
42#ifdef USE_PANGO
43#include <pango/pango.h>
44#include <pango/pangoxft.h>
45#endif
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
68typedef struct MBColor
69{
70 MBPixbuf *pb;
71
72 unsigned char r;
73 unsigned char g;
74 unsigned char b;
75 unsigned char a;
76
77 XColor xcol;
78#if defined (USE_XFT) || defined (USE_PANGO)
79 XftColor xftcol;
80#endif
81 int ref_cnt;
82
84
92typedef struct MBFont
93{
94 Display *dpy;
95 char *family;
96 int weight;
97 int slant;
98 int pt_size;
99 Bool have_shadow; /* A *little* hakkie */
100
101 MBColor *col;
102
103#ifdef USE_PANGO
104 PangoContext *pgo_context;
105 PangoFontMap *pgo_fontmap;
106 PangoFontDescription *fontdes;
107 PangoFont *font;
108 PangoFontMetrics *metrics;
109#elif defined (USE_XFT)
110 XftFont *font;
111#else
112 GC gc;
113 XFontStruct *font;
114#endif
115
116 Bool _have_fresh_font_object;
117 int ref_cnt;
118
120
126typedef enum {
127
128 MB_ENCODING_LATIN,
129 MB_ENCODING_UTF8
130
131} MBEncoding;
132
138typedef enum {
139
140 MB_NORMAL = 0,
141 MB_LIGHT,
142 MB_MEDIUM,
143 MB_DEMIBOLD,
144 MB_BOLD,
145 MB_BLACK,
146 MB_N_WEIGHTS
147
149
155typedef enum {
156
157 MB_ROMAN = 0,
158 MB_ITALIC,
159 MB_OBLIQUE,
160
161 MB_N_SLANTS
162
164
170typedef enum {
171
172 MB_FONT_RENDER_OPTS_NONE = 0,
173 MB_FONT_RENDER_OPTS_CLIP_TRAIL = (1<<1),
174 MB_FONT_RENDER_ALIGN_CENTER = (1<<2),
175 MB_FONT_RENDER_ALIGN_RIGHT = (1<<3),
176 MB_FONT_RENDER_EFFECT_SHADOW = (1<<4),
177 MB_FONT_RENDER_VALIGN_MIDDLE = (1<<5)
178
180
189typedef struct MBDrawable
190{
191 MBPixbuf *pb;
192 Pixmap xpixmap;
193 Bool have_ext_pxm;
194#if defined (USE_XFT) || defined (USE_PANGO)
195 XftDraw *xftdraw;
196#endif
197
198 int width, height;
200
208typedef struct MBLayout
209{
210 int x;
211 int y;
212 int width;
213 int height;
214 int line_spacing;
215
216 unsigned char *txt;
217 MBEncoding txt_encoding;
218 MBFont *font;
219
220 Bool _have_autocalc_size;
221
223
224/* Color */
225
236MBColor*
237mb_col_new_from_spec (MBPixbuf *pb, char *spec);
238
239
250Bool
251mb_col_set (MBColor *col, char *spec);
252
263void
264mb_col_set_rgba (MBColor *col,
265 unsigned char red,
266 unsigned char green,
267 unsigned char blue,
268 unsigned char alpha);
269
280void
281mb_col_get_rgba (MBColor *col,
282 unsigned char *red,
283 unsigned char *green,
284 unsigned char *blue,
285 unsigned char *alpha);
286
287
288#define mb_col_red(col) (col)->r
289#define mb_col_green(col) (col)->g
290#define mb_col_blue(col) (col)->b
291#define mb_col_alpha(col) (col)->a
292#define mb_col_xpixel(col) (col)->xcol.pixel
293
294
295/* FIXME: need mb_col_ref func */
296
302void
303mb_col_unref (MBColor *col);
304
305/* Fonts */
306
314MBFont*
315mb_font_new (Display *dpy,
316 char *family);
317
323void
324mb_font_ref(MBFont* font);
325
331void
332mb_font_unref(MBFont* font);
333
342MBFont*
343mb_font_new_from_string(Display *dpy, char *spec) ;
344
353MBFont*
354mb_font_set_from_string(MBFont *font, char *spec) ;
355
362void
363mb_font_set_family (MBFont *font, const char *family);
364
371char*
372mb_font_get_family (MBFont *font);
373
374/* FIXME: what is this ? */
375char*
376mb_font_get (MBFont *font);
377
384void
385mb_font_set_weight (MBFont *font, MBFontWeight weight);
386
394mb_font_get_weight (MBFont *font);
395
402void
403mb_font_set_slant (MBFont *font, MBFontSlant slant);
404
405
406/* FIXME: need mb_font_get_slant() */
407
414void
415mb_font_set_point_size (MBFont *font, int points);
416
423int
425
434int
435mb_font_set_size_to_pixels (MBFont *font, int max_pixels, int *points_to_try);
436
445void
446mb_font_set_color (MBFont *font, MBColor *col);
447
454MBColor *
455mb_font_get_color (MBFont *font);
456
457/* FIXME: encoding param should be enum */
458int
459mb_font_get_txt_width (MBFont *font,
460 unsigned char *txt,
461 int byte_len,
462 int encoding);
463
470int
471mb_font_get_height (MBFont *font);
472
479int
480mb_font_get_ascent(MBFont *font);
481
488int
490
491
505int
507 MBDrawable *drw,
508 int x,
509 int y,
510 int width,
511 unsigned char *text,
512 int encoding,
513 MBFontRenderOpts opts);
514
526int
528 int width,
529 unsigned char *text,
530 int encoding,
531 MBFontRenderOpts opts );
532
533
534/* Layout stuff
535 *
536 * XXX: This stuff is experimental, subject to change and shouldn't
537 * really be used as yet unless you really know what you doing.
538 *
539 */
540
541MBLayout *
542mb_layout_new (void);
543
544void
545mb_layout_unref (MBLayout *layout);
546
547void
548mb_layout_set_font(MBLayout *layout, MBFont *font);
549
550
551/* If layout not set size is autocalculated */
552void
553mb_layout_set_geometry(MBLayout *layout,
554 int width, int height);
555
556void
557mb_layout_get_geometry(MBLayout *layout,
558 int *width, int *height);
559
560/* call set text, then get geometry for the space it takes up */
561void
562mb_layout_set_text(MBLayout *layout,
563 unsigned char *text,
564 MBEncoding encoding); /* XXX plus text len ? */
565
566void
567mb_layout_destroy (MBLayout *layout);
568
569void
570mb_layout_set_multiline (MBLayout *layout, Bool want_multiline);
571
572void
573mb_layout_set_align (MBLayout *layout, int horizontal, int vertical);
574
575void /* dots, word, letter, none */
576mb_layout_set_clip_style (MBLayout *layout, int clip_stype);
577
578void
579mb_layout_render (MBLayout *layout,
580 MBDrawable *drw,
581 int x,
582 int y,
583 MBFontRenderOpts opts);
584
585#define mb_layout_width(l) (l)->width
586#define mb_layout_height(l) (l)->height
587
588
589/* Drawables */
590
601mb_drawable_new (MBPixbuf *pixbuf, int width, int height);
602
613mb_drawable_new_from_pixmap (MBPixbuf *pixbuf, Pixmap pxm);
614
621void
622mb_drawable_unref (MBDrawable* drw);
623
629#define mb_drawable_pixmap(drw) (drw)->xpixmap
630
631/* FIXME: document */
632int
633mb_util_next_utf8_char (unsigned char **string);
634
637#ifdef __cplusplus
638}
639#endif
640
641#endif
int mb_font_get_descent(MBFont *font)
Gets the fonts descent in pixels.
MBColor * mb_col_new_from_spec(MBPixbuf *pb, char *spec)
Constructs a new MBColor from a string specification.
MBFont * mb_font_new(Display *dpy, char *family)
Constructs a new MBFont instance.
char * mb_font_get_family(MBFont *font)
Gets the fonts family.
MBFontWeight
enumerated types for font weights.
Definition mbexp.h:138
int mb_font_render_simple_get_width(MBFont *font, int width, unsigned char *text, int encoding, MBFontRenderOpts opts)
Returns the width in pixels of any text rendered with mb_font_render_simple, taking into account any ...
MBFont * mb_font_set_from_string(MBFont *font, char *spec)
Sets the font propertys from a textual description.
void mb_font_set_color(MBFont *font, MBColor *col)
Sets the fonts color.
void mb_font_set_slant(MBFont *font, MBFontSlant slant)
Sets the fonts slant.
void mb_font_unref(MBFont *font)
Unrefs ( frees ) a created MBColor object.
MBFontSlant
enumerated types for font slant styles
Definition mbexp.h:155
struct MBColor MBColor
Its not recommended you touch structure internals directly.
void mb_col_unref(MBColor *col)
Unrefs ( frees ) a created MBColor object.
int mb_font_get_ascent(MBFont *font)
Gets the fonts ascent in pixels.
MBFontRenderOpts
Option flags for text rendering.
Definition mbexp.h:170
void mb_col_get_rgba(MBColor *col, unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *alpha)
Gets an r,g,b,a values from an existing MBColor.
MBFont * mb_font_new_from_string(Display *dpy, char *spec)
Constructs a new MBFont instance.
struct MBDrawable MBDrawable
Type for representing an mbdrawable.
int mb_font_get_height(MBFont *font)
Gets the fonts height in pixels.
void mb_font_set_family(MBFont *font, const char *family)
Sets the fonts family.
void mb_font_set_weight(MBFont *font, MBFontWeight weight)
Sets the fonts weight.
MBEncoding
enumerated types for text encodings
Definition mbexp.h:126
int mb_font_render_simple(MBFont *font, MBDrawable *drw, int x, int y, int width, unsigned char *text, int encoding, MBFontRenderOpts opts)
Renders a line of text onto a MBDrawable.
struct MBLayout MBLayout
Experimental and therefore not as yet documented.
int mb_font_get_point_size(MBFont *font)
Gets the fonts point size.
MBDrawable * mb_drawable_new_from_pixmap(MBPixbuf *pixbuf, Pixmap pxm)
Creates a new MBDrawable instance from a pre-existing pixmap.
int mb_font_set_size_to_pixels(MBFont *font, int max_pixels, int *points_to_try)
Attempts to fit the point size to a pixel size.
MBFontWeight mb_font_get_weight(MBFont *font)
Gets the fonts weight.
void mb_font_set_point_size(MBFont *font, int points)
Sets the fonts size.
struct MBFont MBFont
Its not recommended you touch structure internals directly.
void mb_drawable_unref(MBDrawable *drw)
Unrefs ( frees ) a drawable.
MBColor * mb_font_get_color(MBFont *font)
Gets the fonts point size.
MBDrawable * mb_drawable_new(MBPixbuf *pixbuf, int width, int height)
Creates a new MBDrawable instance.
void mb_col_set_rgba(MBColor *col, unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
Sets an existing MBColor from r,g,b,a values.
Bool mb_col_set(MBColor *col, char *spec)
Sets an existing MBColor from a string specification.
void mb_font_ref(MBFont *font)
Refs a created MBFont object.
struct MBPixbuf MBPixbuf
Opaque structure used for all operations.