mbexp.h
/* libmb
* Copyright (C) 2002 Matthew Allum
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* XXXXXXXXX WARNING XXXXXXXXXXXX
*
* mbexp contains experimetal unstable code that is subject to
* constant change and therefore USE AT YOUR OWN RISK.
*
* XXXXXXXXX WARNING XXXXXXXXXXXX
*/
#ifndef _MB_EXP_H_
#define _MB_EXP_H_
#include "libmb/mbconfig.h"
#include "mbpixbuf.h"
#include "mbdotdesktop.h"
#ifdef USE_XFT
#include <X11/Xft/Xft.h>
#include <locale.h>
#include <langinfo.h>
#endif
#ifdef USE_PANGO
#include <pango/pango.h>
#include <pango/pangoxft.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct MBColor
{
MBPixbuf *pb;
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
XColor xcol;
#if defined (USE_XFT) || defined (USE_PANGO)
XftColor xftcol;
#endif
int ref_cnt;
} MBColor;
typedef struct MBFont
{
Display *dpy;
char *family;
int weight;
int slant;
int pt_size;
Bool have_shadow; /* A *little* hakkie */
MBColor *col;
#ifdef USE_PANGO
PangoContext *pgo_context;
PangoFontMap *pgo_fontmap;
PangoFontDescription *fontdes;
PangoFont *font;
PangoFontMetrics *metrics;
#elif defined (USE_XFT)
XftFont *font;
#else
GC gc;
XFontStruct *font;
#endif
Bool _have_fresh_font_object;
int ref_cnt;
} MBFont;
typedef enum {
MB_ENCODING_LATIN,
MB_ENCODING_UTF8
} MBEncoding;
typedef enum {
MB_NORMAL = 0,
MB_LIGHT,
MB_MEDIUM,
MB_DEMIBOLD,
MB_BOLD,
MB_BLACK,
MB_N_WEIGHTS
} MBFontWeight;
typedef enum {
MB_ROMAN = 0,
MB_ITALIC,
MB_OBLIQUE,
MB_N_SLANTS
} MBFontSlant;
typedef enum {
MB_FONT_RENDER_OPTS_NONE = 0,
MB_FONT_RENDER_OPTS_CLIP_TRAIL = (1<<1),
MB_FONT_RENDER_ALIGN_CENTER = (1<<2),
MB_FONT_RENDER_ALIGN_RIGHT = (1<<3),
MB_FONT_RENDER_EFFECT_SHADOW = (1<<4),
MB_FONT_RENDER_VALIGN_MIDDLE = (1<<5)
} MBFontRenderOpts;
typedef struct MBDrawable
{
MBPixbuf *pb;
Pixmap xpixmap;
Bool have_ext_pxm;
#if defined (USE_XFT) || defined (USE_PANGO)
XftDraw *xftdraw;
#endif
int width, height;
} MBDrawable;
typedef struct MBLayout
{
int x;
int y;
int width;
int height;
int line_spacing;
unsigned char *txt;
MBEncoding txt_encoding;
MBFont *font;
Bool _have_autocalc_size;
} MBLayout;
/* Color */
MBColor*
mb_col_new_from_spec (MBPixbuf *pb, char *spec);
Bool
mb_col_set (MBColor *col, char *spec);
void
mb_col_set_rgba (MBColor *col,
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha);
void
mb_col_get_rgba (MBColor *col,
unsigned char *red,
unsigned char *green,
unsigned char *blue,
unsigned char *alpha);
#define mb_col_red(col) (col)->r
#define mb_col_green(col) (col)->g
#define mb_col_blue(col) (col)->b
#define mb_col_alpha(col) (col)->a
#define mb_col_xpixel(col) (col)->xcol.pixel
/* FIXME: need mb_col_ref func */
void
mb_col_unref (MBColor *col);
/* Fonts */
MBFont*
mb_font_new (Display *dpy,
char *family);
void
mb_font_ref(MBFont* font);
void
mb_font_unref(MBFont* font);
MBFont*
mb_font_new_from_string(Display *dpy, char *spec) ;
MBFont*
mb_font_set_from_string(MBFont *font, char *spec) ;
void
mb_font_set_family (MBFont *font, const char *family);
char*
mb_font_get_family (MBFont *font);
/* FIXME: what is this ? */
char*
mb_font_get (MBFont *font);
void
mb_font_set_weight (MBFont *font, MBFontWeight weight);
MBFontWeight
mb_font_get_weight (MBFont *font);
void
mb_font_set_slant (MBFont *font, MBFontSlant slant);
/* FIXME: need mb_font_get_slant() */
void
mb_font_set_point_size (MBFont *font, int points);
int
mb_font_get_point_size (MBFont *font);
int
mb_font_set_size_to_pixels (MBFont *font, int max_pixels, int *points_to_try);
void
mb_font_set_color (MBFont *font, MBColor *col);
MBColor *
mb_font_get_color (MBFont *font);
/* FIXME: encoding param should be enum */
int
mb_font_get_txt_width (MBFont *font,
unsigned char *txt,
int byte_len,
int encoding);
int
mb_font_get_height (MBFont *font);
int
mb_font_get_ascent(MBFont *font);
int
mb_font_get_descent(MBFont *font);
int
mb_font_render_simple (MBFont *font,
MBDrawable *drw,
int x,
int y,
int width,
unsigned char *text,
int encoding,
MBFontRenderOpts opts);
int
mb_font_render_simple_get_width (MBFont *font,
int width,
unsigned char *text,
int encoding,
MBFontRenderOpts opts );
/* Layout stuff
*
* XXX: This stuff is experimental, subject to change and shouldn't
* really be used as yet unless you really know what you doing.
*
*/
MBLayout *
mb_layout_new (void);
void
mb_layout_unref (MBLayout *layout);
void
mb_layout_set_font(MBLayout *layout, MBFont *font);
/* If layout not set size is autocalculated */
void
mb_layout_set_geometry(MBLayout *layout,
int width, int height);
void
mb_layout_get_geometry(MBLayout *layout,
int *width, int *height);
/* call set text, then get geometry for the space it takes up */
void
mb_layout_set_text(MBLayout *layout,
unsigned char *text,
MBEncoding encoding); /* XXX plus text len ? */
void
mb_layout_destroy (MBLayout *layout);
void
mb_layout_set_multiline (MBLayout *layout, Bool want_multiline);
void
mb_layout_set_align (MBLayout *layout, int horizontal, int vertical);
void /* dots, word, letter, none */
mb_layout_set_clip_style (MBLayout *layout, int clip_stype);
void
mb_layout_render (MBLayout *layout,
MBDrawable *drw,
int x,
int y,
MBFontRenderOpts opts);
#define mb_layout_width(l) (l)->width
#define mb_layout_height(l) (l)->height
/* Drawables */
MBDrawable*
mb_drawable_new (MBPixbuf *pixbuf, int width, int height);
MBDrawable*
mb_drawable_new_from_pixmap (MBPixbuf *pixbuf, Pixmap pxm);
void
mb_drawable_unref (MBDrawable* drw);
#define mb_drawable_pixmap(drw) (drw)->xpixmap
/* FIXME: document */
int
mb_util_next_utf8_char (unsigned char **string);
#ifdef __cplusplus
}
#endif
#endif
mb_font_set_from_string
MBFont * mb_font_set_from_string(MBFont *font, char *spec)
Sets the font propertys from a textual description.
MBFontRenderOpts
MBFontRenderOpts
Option flags for text rendering.
Definition: mbexp.h:170
mb_col_new_from_spec
MBColor * mb_col_new_from_spec(MBPixbuf *pb, char *spec)
Constructs a new MBColor from a string specification.
mb_font_ref
void mb_font_ref(MBFont *font)
Refs a created MBFont object.
mb_font_set_family
void mb_font_set_family(MBFont *font, const char *family)
Sets the fonts family.
mb_font_get_weight
MBFontWeight mb_font_get_weight(MBFont *font)
Gets the fonts weight.
mb_font_get_family
char * mb_font_get_family(MBFont *font)
Gets the fonts family.
mb_drawable_unref
void mb_drawable_unref(MBDrawable *drw)
Unrefs ( frees ) a drawable.
mb_font_set_slant
void mb_font_set_slant(MBFont *font, MBFontSlant slant)
Sets the fonts slant.
mb_font_get_descent
int mb_font_get_descent(MBFont *font)
Gets the fonts descent in pixels.
mb_font_render_simple
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.
mb_font_set_color
void mb_font_set_color(MBFont *font, MBColor *col)
Sets the fonts color.
mb_col_set
Bool mb_col_set(MBColor *col, char *spec)
Sets an existing MBColor from a string specification.
mb_font_get_height
int mb_font_get_height(MBFont *font)
Gets the fonts height in pixels.
MBColor
struct MBColor MBColor
Its not recommended you touch structure internals directly.
mb_font_get_ascent
int mb_font_get_ascent(MBFont *font)
Gets the fonts ascent in pixels.
mb_font_unref
void mb_font_unref(MBFont *font)
Unrefs ( frees ) a created MBColor object.
mb_font_set_weight
void mb_font_set_weight(MBFont *font, MBFontWeight weight)
Sets the fonts weight.
mb_drawable_new_from_pixmap
MBDrawable * mb_drawable_new_from_pixmap(MBPixbuf *pixbuf, Pixmap pxm)
Creates a new MBDrawable instance from a pre-existing pixmap.
MBDrawable
struct MBDrawable MBDrawable
Type for representing an mbdrawable.
mb_font_set_size_to_pixels
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.
mb_font_set_point_size
void mb_font_set_point_size(MBFont *font, int points)
Sets the fonts size.
MBFontSlant
MBFontSlant
enumerated types for font slant styles
Definition: mbexp.h:155
MBFontWeight
MBFontWeight
enumerated types for font weights.
Definition: mbexp.h:138
mb_drawable_new
MBDrawable * mb_drawable_new(MBPixbuf *pixbuf, int width, int height)
Creates a new MBDrawable instance.
MBFont
struct MBFont MBFont
Its not recommended you touch structure internals directly.
mb_font_get_point_size
int mb_font_get_point_size(MBFont *font)
Gets the fonts point size.
mb_col_unref
void mb_col_unref(MBColor *col)
Unrefs ( frees ) a created MBColor object.
mb_font_new_from_string
MBFont * mb_font_new_from_string(Display *dpy, char *spec)
Constructs a new MBFont instance.
MBPixbuf
struct MBPixbuf MBPixbuf
Opaque structure used for all operations.
mb_font_new
MBFont * mb_font_new(Display *dpy, char *family)
Constructs a new MBFont instance.
mb_font_get_color
MBColor * mb_font_get_color(MBFont *font)
Gets the fonts point size.
MBLayout
struct MBLayout MBLayout
Experimental and therefore not as yet documented.
mb_col_set_rgba
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.
mb_font_render_simple_get_width
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 ...
mb_col_get_rgba
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.
MBEncoding
MBEncoding
enumerated types for text encodings
Definition: mbexp.h:126