LibMB
1.9
|
00001 /* libmb 00002 * Copyright (C) 2002 Matthew Allum 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the 00016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /* 00021 * XXXXXXXXX WARNING XXXXXXXXXXXX 00022 * 00023 * mbexp contains experimetal unstable code that is subject to 00024 * constant change and therefore USE AT YOUR OWN RISK. 00025 * 00026 * XXXXXXXXX WARNING XXXXXXXXXXXX 00027 */ 00028 00029 #ifndef _MB_EXP_H_ 00030 #define _MB_EXP_H_ 00031 00032 #include "libmb/mbconfig.h" 00033 #include "mbpixbuf.h" 00034 #include "mbdotdesktop.h" 00035 00036 #ifdef USE_XFT 00037 #include <X11/Xft/Xft.h> 00038 #include <locale.h> 00039 #include <langinfo.h> 00040 #endif 00041 00042 #ifdef USE_PANGO 00043 #include <pango/pango.h> 00044 #include <pango/pangoxft.h> 00045 #endif 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00068 typedef struct MBColor 00069 { 00070 MBPixbuf *pb; 00071 00072 unsigned char r; 00073 unsigned char g; 00074 unsigned char b; 00075 unsigned char a; 00076 00077 XColor xcol; 00078 #if defined (USE_XFT) || defined (USE_PANGO) 00079 XftColor xftcol; 00080 #endif 00081 int ref_cnt; 00082 00083 } MBColor; 00084 00092 typedef struct MBFont 00093 { 00094 Display *dpy; 00095 char *family; 00096 int weight; 00097 int slant; 00098 int pt_size; 00099 Bool have_shadow; /* A *little* hakkie */ 00100 00101 MBColor *col; 00102 00103 #ifdef USE_PANGO 00104 PangoContext *pgo_context; 00105 PangoFontMap *pgo_fontmap; 00106 PangoFontDescription *fontdes; 00107 PangoFont *font; 00108 PangoFontMetrics *metrics; 00109 #elif defined (USE_XFT) 00110 XftFont *font; 00111 #else 00112 GC gc; 00113 XFontStruct *font; 00114 #endif 00115 00116 Bool _have_fresh_font_object; 00117 int ref_cnt; 00118 00119 } MBFont; 00120 00126 typedef enum { 00127 00128 MB_ENCODING_LATIN, 00129 MB_ENCODING_UTF8 00130 00131 } MBEncoding; 00132 00138 typedef enum { 00139 00140 MB_NORMAL = 0, 00141 MB_LIGHT, 00142 MB_MEDIUM, 00143 MB_DEMIBOLD, 00144 MB_BOLD, 00145 MB_BLACK, 00146 MB_N_WEIGHTS 00147 00148 } MBFontWeight; 00149 00155 typedef enum { 00156 00157 MB_ROMAN = 0, 00158 MB_ITALIC, 00159 MB_OBLIQUE, 00160 00161 MB_N_SLANTS 00162 00163 } MBFontSlant; 00164 00170 typedef enum { 00171 00172 MB_FONT_RENDER_OPTS_NONE = 0, 00173 MB_FONT_RENDER_OPTS_CLIP_TRAIL = (1<<1), 00174 MB_FONT_RENDER_ALIGN_CENTER = (1<<2), 00175 MB_FONT_RENDER_ALIGN_RIGHT = (1<<3), 00176 MB_FONT_RENDER_EFFECT_SHADOW = (1<<4), 00177 MB_FONT_RENDER_VALIGN_MIDDLE = (1<<5) 00178 00179 } MBFontRenderOpts; 00180 00189 typedef struct MBDrawable 00190 { 00191 MBPixbuf *pb; 00192 Pixmap xpixmap; 00193 Bool have_ext_pxm; 00194 #if defined (USE_XFT) || defined (USE_PANGO) 00195 XftDraw *xftdraw; 00196 #endif 00197 00198 int width, height; 00199 } MBDrawable; 00200 00208 typedef struct MBLayout 00209 { 00210 int x; 00211 int y; 00212 int width; 00213 int height; 00214 int line_spacing; 00215 00216 unsigned char *txt; 00217 MBEncoding txt_encoding; 00218 MBFont *font; 00219 00220 Bool _have_autocalc_size; 00221 00222 } MBLayout; 00223 00224 /* Color */ 00225 00236 MBColor* 00237 mb_col_new_from_spec (MBPixbuf *pb, char *spec); 00238 00239 00250 Bool 00251 mb_col_set (MBColor *col, char *spec); 00252 00263 void 00264 mb_col_set_rgba (MBColor *col, 00265 unsigned char red, 00266 unsigned char green, 00267 unsigned char blue, 00268 unsigned char alpha); 00269 00280 void 00281 mb_col_get_rgba (MBColor *col, 00282 unsigned char *red, 00283 unsigned char *green, 00284 unsigned char *blue, 00285 unsigned char *alpha); 00286 00287 00288 #define mb_col_red(col) (col)->r 00289 #define mb_col_green(col) (col)->g 00290 #define mb_col_blue(col) (col)->b 00291 #define mb_col_alpha(col) (col)->a 00292 #define mb_col_xpixel(col) (col)->xcol.pixel 00293 00294 00295 /* FIXME: need mb_col_ref func */ 00296 00302 void 00303 mb_col_unref (MBColor *col); 00304 00305 /* Fonts */ 00306 00314 MBFont* 00315 mb_font_new (Display *dpy, 00316 char *family); 00317 00323 void 00324 mb_font_ref(MBFont* font); 00325 00331 void 00332 mb_font_unref(MBFont* font); 00333 00342 MBFont* 00343 mb_font_new_from_string(Display *dpy, char *spec) ; 00344 00353 MBFont* 00354 mb_font_set_from_string(MBFont *font, char *spec) ; 00355 00362 void 00363 mb_font_set_family (MBFont *font, const char *family); 00364 00371 char* 00372 mb_font_get_family (MBFont *font); 00373 00374 /* FIXME: what is this ? */ 00375 char* 00376 mb_font_get (MBFont *font); 00377 00384 void 00385 mb_font_set_weight (MBFont *font, MBFontWeight weight); 00386 00393 MBFontWeight 00394 mb_font_get_weight (MBFont *font); 00395 00402 void 00403 mb_font_set_slant (MBFont *font, MBFontSlant slant); 00404 00405 00406 /* FIXME: need mb_font_get_slant() */ 00407 00414 void 00415 mb_font_set_point_size (MBFont *font, int points); 00416 00423 int 00424 mb_font_get_point_size (MBFont *font); 00425 00434 int 00435 mb_font_set_size_to_pixels (MBFont *font, int max_pixels, int *points_to_try); 00436 00445 void 00446 mb_font_set_color (MBFont *font, MBColor *col); 00447 00454 MBColor * 00455 mb_font_get_color (MBFont *font); 00456 00457 /* FIXME: encoding param should be enum */ 00458 int 00459 mb_font_get_txt_width (MBFont *font, 00460 unsigned char *txt, 00461 int byte_len, 00462 int encoding); 00463 00470 int 00471 mb_font_get_height (MBFont *font); 00472 00479 int 00480 mb_font_get_ascent(MBFont *font); 00481 00488 int 00489 mb_font_get_descent(MBFont *font); 00490 00491 00505 int 00506 mb_font_render_simple (MBFont *font, 00507 MBDrawable *drw, 00508 int x, 00509 int y, 00510 int width, 00511 unsigned char *text, 00512 int encoding, 00513 MBFontRenderOpts opts); 00514 00526 int 00527 mb_font_render_simple_get_width (MBFont *font, 00528 int width, 00529 unsigned char *text, 00530 int encoding, 00531 MBFontRenderOpts opts ); 00532 00533 00534 /* Layout stuff 00535 * 00536 * XXX: This stuff is experimental, subject to change and shouldn't 00537 * really be used as yet unless you really know what you doing. 00538 * 00539 */ 00540 00541 MBLayout * 00542 mb_layout_new (void); 00543 00544 void 00545 mb_layout_unref (MBLayout *layout); 00546 00547 void 00548 mb_layout_set_font(MBLayout *layout, MBFont *font); 00549 00550 00551 /* If layout not set size is autocalculated */ 00552 void 00553 mb_layout_set_geometry(MBLayout *layout, 00554 int width, int height); 00555 00556 void 00557 mb_layout_get_geometry(MBLayout *layout, 00558 int *width, int *height); 00559 00560 /* call set text, then get geometry for the space it takes up */ 00561 void 00562 mb_layout_set_text(MBLayout *layout, 00563 unsigned char *text, 00564 MBEncoding encoding); /* XXX plus text len ? */ 00565 00566 void 00567 mb_layout_destroy (MBLayout *layout); 00568 00569 void 00570 mb_layout_set_multiline (MBLayout *layout, Bool want_multiline); 00571 00572 void 00573 mb_layout_set_align (MBLayout *layout, int horizontal, int vertical); 00574 00575 void /* dots, word, letter, none */ 00576 mb_layout_set_clip_style (MBLayout *layout, int clip_stype); 00577 00578 void 00579 mb_layout_render (MBLayout *layout, 00580 MBDrawable *drw, 00581 int x, 00582 int y, 00583 MBFontRenderOpts opts); 00584 00585 #define mb_layout_width(l) (l)->width 00586 #define mb_layout_height(l) (l)->height 00587 00588 00589 /* Drawables */ 00590 00600 MBDrawable* 00601 mb_drawable_new (MBPixbuf *pixbuf, int width, int height); 00602 00612 MBDrawable* 00613 mb_drawable_new_from_pixmap (MBPixbuf *pixbuf, Pixmap pxm); 00614 00621 void 00622 mb_drawable_unref (MBDrawable* drw); 00623 00629 #define mb_drawable_pixmap(drw) (drw)->xpixmap 00630 00631 /* FIXME: document */ 00632 int 00633 mb_util_next_utf8_char (unsigned char **string); 00634 00637 #ifdef __cplusplus 00638 } 00639 #endif 00640 00641 #endif