LibMB  1.9
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 "mbpixbuf.h"
34 #include "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
48 extern "C" {
49 #endif
50 
68 typedef 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 
83 } MBColor;
84 
92 typedef 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 
119 } MBFont;
120 
126 typedef enum {
127 
128  MB_ENCODING_LATIN,
129  MB_ENCODING_UTF8
130 
131 } MBEncoding;
132 
138 typedef 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 
148 } MBFontWeight;
149 
155 typedef enum {
156 
157  MB_ROMAN = 0,
158  MB_ITALIC,
159  MB_OBLIQUE,
160 
161  MB_N_SLANTS
162 
163 } MBFontSlant;
164 
170 typedef 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 
189 typedef 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;
199 } MBDrawable;
200 
208 typedef 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 
222 } MBLayout;
223 
224 /* Color */
225 
236 MBColor*
237 mb_col_new_from_spec (MBPixbuf *pb, char *spec);
238 
239 
250 Bool
251 mb_col_set (MBColor *col, char *spec);
252 
263 void
264 mb_col_set_rgba (MBColor *col,
265  unsigned char red,
266  unsigned char green,
267  unsigned char blue,
268  unsigned char alpha);
269 
280 void
281 mb_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 
302 void
303 mb_col_unref (MBColor *col);
304 
305 /* Fonts */
306 
314 MBFont*
315 mb_font_new (Display *dpy,
316  char *family);
317 
323 void
324 mb_font_ref(MBFont* font);
325 
331 void
332 mb_font_unref(MBFont* font);
333 
342 MBFont*
343 mb_font_new_from_string(Display *dpy, char *spec) ;
344 
353 MBFont*
354 mb_font_set_from_string(MBFont *font, char *spec) ;
355 
362 void
363 mb_font_set_family (MBFont *font, const char *family);
364 
371 char*
372 mb_font_get_family (MBFont *font);
373 
374 /* FIXME: what is this ? */
375 char*
376 mb_font_get (MBFont *font);
377 
384 void
385 mb_font_set_weight (MBFont *font, MBFontWeight weight);
386 
394 mb_font_get_weight (MBFont *font);
395 
402 void
403 mb_font_set_slant (MBFont *font, MBFontSlant slant);
404 
405 
406 /* FIXME: need mb_font_get_slant() */
407 
414 void
415 mb_font_set_point_size (MBFont *font, int points);
416 
423 int
425 
434 int
435 mb_font_set_size_to_pixels (MBFont *font, int max_pixels, int *points_to_try);
436 
445 void
446 mb_font_set_color (MBFont *font, MBColor *col);
447 
454 MBColor *
455 mb_font_get_color (MBFont *font);
456 
457 /* FIXME: encoding param should be enum */
458 int
459 mb_font_get_txt_width (MBFont *font,
460  unsigned char *txt,
461  int byte_len,
462  int encoding);
463 
470 int
471 mb_font_get_height (MBFont *font);
472 
479 int
481 
488 int
490 
491 
505 int
507  MBDrawable *drw,
508  int x,
509  int y,
510  int width,
511  unsigned char *text,
512  int encoding,
513  MBFontRenderOpts opts);
514 
526 int
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 
541 MBLayout *
542 mb_layout_new (void);
543 
544 void
545 mb_layout_unref (MBLayout *layout);
546 
547 void
548 mb_layout_set_font(MBLayout *layout, MBFont *font);
549 
550 
551 /* If layout not set size is autocalculated */
552 void
553 mb_layout_set_geometry(MBLayout *layout,
554  int width, int height);
555 
556 void
557 mb_layout_get_geometry(MBLayout *layout,
558  int *width, int *height);
559 
560 /* call set text, then get geometry for the space it takes up */
561 void
562 mb_layout_set_text(MBLayout *layout,
563  unsigned char *text,
564  MBEncoding encoding); /* XXX plus text len ? */
565 
566 void
567 mb_layout_destroy (MBLayout *layout);
568 
569 void
570 mb_layout_set_multiline (MBLayout *layout, Bool want_multiline);
571 
572 void
573 mb_layout_set_align (MBLayout *layout, int horizontal, int vertical);
574 
575 void /* dots, word, letter, none */
576 mb_layout_set_clip_style (MBLayout *layout, int clip_stype);
577 
578 void
579 mb_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 
600 MBDrawable*
601 mb_drawable_new (MBPixbuf *pixbuf, int width, int height);
602 
612 MBDrawable*
613 mb_drawable_new_from_pixmap (MBPixbuf *pixbuf, Pixmap pxm);
614 
621 void
623 
629 #define mb_drawable_pixmap(drw) (drw)->xpixmap
630 
631 /* FIXME: document */
632 int
633 mb_util_next_utf8_char (unsigned char **string);
634 
637 #ifdef __cplusplus
638 }
639 #endif
640 
641 #endif