Back to index

texmacs  1.0.7.15
tm_cairo.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tm_cairo.cpp
00004 * DESCRIPTION: Interface with Cairo
00005 * COPYRIGHT  : (C) 2008 Massimiliano Gubinelli
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "dyn_link.hpp"
00013 #include "tm_cairo.hpp"
00014 
00015 #ifdef USE_CAIRO
00016 
00017 static bool tm_cairo_initialized= false;
00018 static bool tm_cairo_error      = true;
00019 
00020  void (*tm_cairo_move_to) (cairo_t *cr, double x, double y);
00021  void (*tm_cairo_show_glyphs) (cairo_t *cr, const cairo_glyph_t *glyphs, int num_glyphs);
00022  cairo_status_t (*tm_cairo_font_face_status) (cairo_font_face_t *font_face);
00023  void (*tm_cairo_set_source_surface) (cairo_t *cr, cairo_surface_t *surface, double x, double y);
00024  void (*tm_cairo_new_path) (cairo_t *cr);
00025  void (*tm_cairo_stroke) (cairo_t *cr);
00026  cairo_status_t (*tm_cairo_font_face_set_user_data) (cairo_font_face_t *font_face, const cairo_user_data_key_t *key, void *user_data, cairo_destroy_func_t destroy);
00027  void (*tm_cairo_set_antialias) (cairo_t *cr, cairo_antialias_t antialias);
00028  void (*tm_cairo_set_font_size) (cairo_t *cr, double size);
00029  void (*tm_cairo_fill) (cairo_t *cr);
00030  void (*tm_cairo_set_source_rgba) (cairo_t *cr, double red, double green, double blue, double alpha);
00031  const char * (*tm_cairo_status_to_string) (cairo_status_t status);
00032  void (*tm_cairo_set_source_rgb) (cairo_t *cr, double red, double green, double blue);
00033  void (*tm_cairo_close_path) (cairo_t *cr);
00034  void (*tm_cairo_restore) (cairo_t *cr);
00035  void (*tm_cairo_translate) (cairo_t *cr, double tx, double ty);
00036  void (*tm_cairo_set_font_face) (cairo_t *cr, cairo_font_face_t *font_face);
00037  void (*tm_cairo_font_face_destroy) (cairo_font_face_t *font_face);
00038  void (*tm_cairo_set_line_width) (cairo_t *cr, double width);
00039  cairo_surface_t * (*tm_cairo_image_surface_create_from_png) (const char *filename);
00040  int (*tm_cairo_image_surface_get_width) (cairo_surface_t *surface);
00041  void (*tm_cairo_scale) (cairo_t *cr, double sx, double sy);
00042  void (*tm_cairo_mask) (cairo_t *cr, cairo_pattern_t *pattern);
00043  void (*tm_cairo_set_operator) (cairo_t *cr, cairo_operator_t op);
00044  cairo_surface_t * (*tm_cairo_image_surface_create) (cairo_format_t format, int width, int height);
00045  void (*tm_cairo_paint) (cairo_t *cr);
00046  void (*tm_cairo_rectangle) (cairo_t *cr, double x, double y, double width, double height);
00047  void (*tm_cairo_set_line_cap) (cairo_t *cr, cairo_line_cap_t line_cap);
00048  void (*tm_cairo_set_line_join) (cairo_t *cr, cairo_line_join_t line_join);
00049  cairo_surface_t * (*tm_cairo_surface_reference) (cairo_surface_t *surface);
00050  void (*tm_cairo_line_to) (cairo_t *cr, double x, double y);
00051  cairo_status_t (*tm_cairo_status) (cairo_t *cr);
00052  void (*tm_cairo_show_page) (cairo_t *cr);
00053  cairo_t * (*tm_cairo_reference) (cairo_t *cr);
00054  cairo_t * (*tm_cairo_create) (cairo_surface_t *target);
00055  void (*tm_cairo_surface_destroy) (cairo_surface_t *surface);
00056  void (*tm_cairo_set_fill_rule) (cairo_t *cr, cairo_fill_rule_t fill_rule);
00057  void (*tm_cairo_destroy) (cairo_t *cr);
00058  void (*tm_cairo_save) (cairo_t *cr);
00059  void (*tm_cairo_set_source) (cairo_t *cr, cairo_pattern_t *source);
00060  int (*tm_cairo_image_surface_get_height) (cairo_surface_t *surface);
00061  void (*tm_cairo_mask_surface) (cairo_t *cr, cairo_surface_t *surface, double surface_x, double surface_y);
00062 
00063 
00064 #ifdef CAIRO_HAS_FT_FONT
00065   cairo_font_face_t * (*tm_cairo_ft_font_face_create_for_ft_face) (FT_Face face, int load_flags);
00066 #endif
00067 
00068 #ifdef CAIRO_HAS_PS_SURFACE
00069   cairo_surface_t * (*tm_cairo_ps_surface_create) (const char *filename, double width_in_points, double height_in_points);
00070 #endif
00071 
00072 #ifdef CAIRO_HAS_XLIB_SURFACE
00073  cairo_surface_t * (*tm_cairo_xlib_surface_create) (Display *dpy, Drawable   drawable, Visual *visual, int width, int height);
00074 #endif
00075 
00076 #ifdef CAIRO_HAS_QUARTZ_SURFACE
00077   cairo_surface_t * (*tm_cairo_quartz_surface_create_for_cg_context) (CGContextRef cgContext, unsigned int width, unsigned int height);
00078 #endif
00079 
00080 bool
00081 tm_cairo_initialize () {
00082   if (tm_cairo_initialized) return tm_cairo_error;
00083   tm_cairo_initialized= true;
00084 
00085 #ifdef LINKED_CAIRO
00086 #define CAIRO_LINK(a,b) b = a
00087 #else
00088 #define CAIRO_LINK(LIBFUNC,LOCALFUNC) \
00089   (void) symbol_install ("/usr/lib/cairo.so", #LIBFUNC , (pointer&) LOCALFUNC); \
00090   if (LOCALFUNC == NULL) return true; 
00091   
00092   int status= debug_off ();
00093 #endif
00094   
00095   CAIRO_LINK(cairo_move_to, tm_cairo_move_to);
00096   CAIRO_LINK(cairo_show_glyphs, tm_cairo_show_glyphs);
00097   CAIRO_LINK(cairo_font_face_status, tm_cairo_font_face_status);
00098   CAIRO_LINK(cairo_set_source_surface, tm_cairo_set_source_surface);
00099   CAIRO_LINK(cairo_new_path, tm_cairo_new_path);
00100   CAIRO_LINK(cairo_stroke, tm_cairo_stroke);
00101   CAIRO_LINK(cairo_font_face_set_user_data, tm_cairo_font_face_set_user_data);
00102   CAIRO_LINK(cairo_set_antialias, tm_cairo_set_antialias);
00103   CAIRO_LINK(cairo_set_font_size, tm_cairo_set_font_size);
00104   CAIRO_LINK(cairo_fill, tm_cairo_fill);
00105   CAIRO_LINK(cairo_set_source_rgba, tm_cairo_set_source_rgba);
00106   CAIRO_LINK(cairo_status_to_string, tm_cairo_status_to_string);
00107   CAIRO_LINK(cairo_set_source_rgb, tm_cairo_set_source_rgb);
00108   CAIRO_LINK(cairo_close_path, tm_cairo_close_path);
00109   CAIRO_LINK(cairo_restore, tm_cairo_restore);
00110   CAIRO_LINK(cairo_translate, tm_cairo_translate);
00111   CAIRO_LINK(cairo_set_font_face, tm_cairo_set_font_face);
00112   CAIRO_LINK(cairo_font_face_destroy, tm_cairo_font_face_destroy);
00113   CAIRO_LINK(cairo_set_line_width, tm_cairo_set_line_width);
00114   CAIRO_LINK(cairo_image_surface_create_from_png, tm_cairo_image_surface_create_from_png);
00115   CAIRO_LINK(cairo_image_surface_get_width, tm_cairo_image_surface_get_width);
00116   CAIRO_LINK(cairo_scale, tm_cairo_scale);
00117   CAIRO_LINK(cairo_mask, tm_cairo_mask);
00118   CAIRO_LINK(cairo_set_operator, tm_cairo_set_operator);
00119   CAIRO_LINK(cairo_image_surface_create, tm_cairo_image_surface_create);
00120   CAIRO_LINK(cairo_paint, tm_cairo_paint);
00121   CAIRO_LINK(cairo_rectangle, tm_cairo_rectangle);
00122   CAIRO_LINK(cairo_set_line_cap, tm_cairo_set_line_cap);
00123   CAIRO_LINK(cairo_set_line_join, tm_cairo_set_line_join);
00124   CAIRO_LINK(cairo_surface_reference, tm_cairo_surface_reference);
00125   CAIRO_LINK(cairo_line_to, tm_cairo_line_to);
00126   CAIRO_LINK(cairo_status, tm_cairo_status);
00127   CAIRO_LINK(cairo_show_page, tm_cairo_show_page);
00128   CAIRO_LINK(cairo_reference, tm_cairo_reference);
00129   CAIRO_LINK(cairo_create, tm_cairo_create);
00130   CAIRO_LINK(cairo_surface_destroy, tm_cairo_surface_destroy);
00131   CAIRO_LINK(cairo_set_fill_rule, tm_cairo_set_fill_rule);
00132   CAIRO_LINK(cairo_destroy, tm_cairo_destroy);
00133   CAIRO_LINK(cairo_save, tm_cairo_save);
00134   CAIRO_LINK(cairo_set_source, tm_cairo_set_source);
00135   CAIRO_LINK(cairo_image_surface_get_height, tm_cairo_image_surface_get_height);
00136   CAIRO_LINK(cairo_mask_surface, tm_cairo_mask_surface);
00137 
00138 #ifdef CAIRO_HAS_FT_FONT
00139   CAIRO_LINK(cairo_ft_font_face_create_for_ft_face, tm_cairo_ft_font_face_create_for_ft_face);
00140 #endif
00141 #ifdef CAIRO_HAS_PS_SURFACE
00142   CAIRO_LINK(cairo_ps_surface_create, tm_cairo_ps_surface_create);
00143 #endif
00144 #ifdef CAIRO_HAS_XLIB_SURFACE
00145   CAIRO_LINK(cairo_xlib_surface_create, tm_cairo_xlib_surface_create);
00146 #endif  
00147 #ifdef CAIRO_HAS_QUARTZ_SURFACE
00148   CAIRO_LINK(cairo_quartz_surface_create_for_cg_context, tm_cairo_quartz_surface_create_for_cg_context) ;
00149 #endif
00150   
00151     
00152 #undef CAIRO_LINK
00153 #ifdef LINKED_CAIRO
00154   if (DEBUG_AUTO) cout << "TeXmacs] With linked Cairo support\n";
00155 #else
00156   if (DEBUG_AUTO) cout << "TeXmacs] Installed Cairo support\n";
00157   debug_on (status);
00158 #endif
00159   
00160   
00161   tm_cairo_error= false;
00162   return false;
00163 }
00164 
00165 bool
00166 tm_cairo_present () {
00167   return !tm_cairo_initialize ();
00168 }
00169 
00170 #else
00171 
00172 bool tm_cairo_initialize () { return true; }
00173 bool tm_cairo_present () { return false; }
00174 
00175 #endif