changeset 465:d8181696b689 Android_Skia

Move functions into graphic engine layers. Cairo and Skia have their own header files and C/C++ files. Some functions are refactoried and move into graphic engine layer to make reset of MadButterfly independently from graphic engines.
author Thinker K.F. Li <thinker@branda.to>
date Thu, 12 Nov 2009 21:22:30 +0800
parents 271212f325b4
children cd6f57b9b104
files configure.ac include/Makefile.am include/mb_graph_engine.h include/mb_graph_engine_cairo.h include/mb_graph_engine_skia.h src/Makefile.am src/graph_engine_cairo.c src/shape_stext.c src/shape_text.c
diffstat 9 files changed, 522 insertions(+), 289 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Thu Nov 12 21:16:13 2009 +0800
+++ b/configure.ac	Thu Nov 12 21:22:30 2009 +0800
@@ -4,7 +4,7 @@
 AC_PREREQ(2.61)
 AC_INIT([MadButterfly],[0.0],[http://www.assembla.com/spaces/MadButterfly])
 AC_CONFIG_SRCDIR([README.h])
-AC_CONFIG_HEADER([config.h])
+AC_CONFIG_HEADER([include/mb_config.h])
 AM_INIT_AUTOMAKE([foreign])
 
 # Checks for programs.
--- a/include/Makefile.am	Thu Nov 12 21:16:13 2009 +0800
+++ b/include/Makefile.am	Thu Nov 12 21:22:30 2009 +0800
@@ -1,4 +1,5 @@
 include_HEADERS = 	\
+	mb_config.h	\
 	mb_animate.h 	\
 	mb.h	 	\
 	mb_timer.h 	\
--- a/include/mb_graph_engine.h	Thu Nov 12 21:16:13 2009 +0800
+++ b/include/mb_graph_engine.h	Thu Nov 12 21:22:30 2009 +0800
@@ -1,187 +1,13 @@
 #ifndef __MBE_H_
 #define __MBE_H_
-
-#include <stdio.h>
-#include <cairo.h>
-#include <cairo-xlib.h>
-#include "mb_img_ldr.h"
-
-/*! \defgroup mb_graph_engine MadButterfly Graphic Engine
- * @{
- */
-#define MBE_OPERATOR_CLEAR CAIRO_OPERATOR_CLEAR
-#define MBE_OPERATOR_SOURCE CAIRO_OPERATOR_SOURCE
-#define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS
-
-#define mbe_ft_font_face_create_for_pattern cairo_ft_font_face_create_for_pattern
-#define mbe_image_surface_create_from_png cairo_image_surface_create_from_png
-#define mbe_pattern_add_color_stop_rgba cairo_pattern_add_color_stop_rgba
-#define mbe_pattern_create_for_surface cairo_pattern_create_for_surface
-#define mbe_scaled_font_text_extents cairo_scaled_font_text_extents
-#define mbe_image_surface_get_stride cairo_image_surface_get_stride
-#define mbe_image_surface_get_height cairo_image_surface_get_height
-#define mbe_image_surface_get_width cairo_image_surface_get_width
-#define mbe_image_surface_get_data cairo_image_surface_get_data
-#define mbe_scaled_font_reference cairo_scaled_font_reference
-#define mbe_pattern_create_radial cairo_pattern_create_radial
-#define mbe_pattern_create_linear cairo_pattern_create_linear
-#define mbe_xlib_surface_create cairo_xlib_surface_create
-#define mbe_scaled_font_destroy cairo_scaled_font_destroy
-#define mbe_font_options_create cairo_font_options_create
-#define mbe_font_face_reference cairo_font_face_reference
-#define mbe_set_source_surface cairo_set_source_surface
-#define mbe_scaled_font_status cairo_scaled_font_status
-#define mbe_scaled_font_create cairo_scaled_font_create
-#define mbe_pattern_set_matrix cairo_pattern_set_matrix
-#define mbe_font_face_destroy cairo_font_face_destroy
-#define mbe_paint_with_alpha cairo_paint_with_alpha
-#define mbe_font_face_status cairo_font_face_status
-#define mbe_surface_destroy cairo_surface_destroy
-#define mbe_set_source_rgba cairo_set_source_rgba
-#define mbe_set_scaled_font cairo_set_scaled_font
-#define mbe_pattern_destroy cairo_pattern_destroy
-#define mbe_get_scaled_font cairo_get_scaled_font
-#define mbe_set_source_rgb cairo_set_source_rgb
-#define mbe_set_line_width cairo_set_line_width
-#define mbe_get_font_face cairo_get_font_face
-#define mbe_fill_preserve cairo_fill_preserve
-#define mbe_set_operator cairo_set_operator
-#define mbe_get_operator cairo_get_operator
-#define mbe_set_source cairo_set_source
-#define mbe_reset_clip cairo_reset_clip
-#define mbe_get_target cairo_get_target
-#define mbe_close_path cairo_close_path
-#define mbe_text_path cairo_text_path
-#define mbe_show_text cairo_show_text
-#define mbe_rectangle cairo_rectangle
-#define mbe_in_stroke cairo_in_stroke
-#define mbe_new_path cairo_new_path
-#define mbe_curve_to cairo_curve_to
-#define mbe_restore cairo_restore
-#define mbe_move_to cairo_move_to
-#define mbe_line_to cairo_line_to
-#define mbe_in_fill cairo_in_fill
-#define mbe_destroy cairo_destroy
-#define mbe_stroke cairo_stroke
-#define mbe_create cairo_create
-#define mbe_paint cairo_paint
-#define mbe_save cairo_save
-#define mbe_fill cairo_fill
-#define mbe_clip cairo_clip
-
-typedef cairo_text_extents_t mbe_text_extents_t;
-typedef cairo_font_options_t mbe_font_options_t;
-typedef cairo_scaled_font_t mbe_scaled_font_t;
-typedef cairo_font_face_t mbe_font_face_t;
-typedef cairo_operator_t mbe_operator_t;
-typedef cairo_surface_t mbe_surface_t;
-typedef cairo_pattern_t mbe_pattern_t;
-typedef cairo_status_t mbe_status_t;
-typedef cairo_matrix_t mbe_matrix_t;
-typedef cairo_t mbe_t;
-typedef float co_aix;
+#include <mb_config.h>
 
-static mbe_surface_t *
-mbe_image_surface_create_for_data(unsigned char *data,
-				  mb_img_fmt_t fmt,
-				  int width, int height,
-				  int stride) {
-    cairo_format_t _fmt;
-    
-    switch(fmt) {
-    case MB_IFMT_ARGB32:
-	_fmt = CAIRO_FORMAT_ARGB32;
-	break;
-    case MB_IFMT_RGB24:
-	_fmt = CAIRO_FORMAT_RGB24;
-	break;
-    case MB_IFMT_A8:
-	_fmt = CAIRO_FORMAT_A8;
-	break;
-    case MB_IFMT_A1:
-	_fmt = CAIRO_FORMAT_A1;
-	break;
-    default:
-	return NULL;
-    }
-    return cairo_image_surface_create_for_data(data, _fmt,
-					       width, height, stride);
-}
-
-static mb_img_fmt_t
-mbe_image_surface_get_format(mbe_surface_t *surface) {
-    cairo_format_t _fmt;
-    mb_img_fmt_t fmt;
-
-    _fmt = cairo_image_surface_get_format(surface);
-    switch(_fmt) {
-    case CAIRO_FORMAT_ARGB32:
-	fmt = MB_IFMT_ARGB32;
-	break;
-    case CAIRO_FORMAT_RGB24:
-	fmt = MB_IFMT_RGB24;
-	break;
-    case CAIRO_FORMAT_A8:
-	fmt = MB_IFMT_A8;
-	break;
-    case CAIRO_FORMAT_A1:
-	fmt = MB_IFMT_A1;
-	break;
-    default:
-	fmt = MB_IFMT_DUMMY;
-	break;
-    }
+#ifdef CAIRO_BACKEND
+#include <mb_graph_engine_cairo.h>
+#endif
 
-    return fmt;
-}
-
-static mbe_surface_t *
-mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) {
-    cairo_format_t _fmt;
-    
-    switch(fmt) {
-    case MB_IFMT_ARGB32:
-	_fmt = CAIRO_FORMAT_ARGB32;
-	break;
-    case MB_IFMT_RGB24:
-	_fmt = CAIRO_FORMAT_RGB24;
-	break;
-    case MB_IFMT_A8:
-	_fmt = CAIRO_FORMAT_A8;
-	break;
-    case MB_IFMT_A1:
-	_fmt = CAIRO_FORMAT_A1;
-	break;
-    default:
-	return NULL;
-    }
-    
-    return cairo_image_surface_create(_fmt, width, height);
-}
-
-static void
-mbe_transform(mbe_t *mbe, const co_aix matrix[6]) {
-    cairo_matrix_t cmtx;
-
-    cmtx.xx = matrix[0];
-    cmtx.xy = matrix[1];
-    cmtx.x0 = matrix[2];
-    cmtx.yx = matrix[3];
-    cmtx.yy = matrix[4];
-    cmtx.y0 = matrix[5];
-
-    cairo_transform(mbe, &cmtx);
-}
-
-static void
-mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius,
-	co_aix angle_start, co_aix angle_stop) {
-    if(angle_start <= angle_stop)
-	cairo_arc(mbe, x, y, radius, angle_start, angle_stop);
-    else
-	cairo_arc_negative(mbe, x, y, radius, angle_start, angle_stop);
-}
-
-/* @} */
+#ifdef SKAI_BACKEND
+#include <mb_graph_engine_skia.h>
+#endif
 
 #endif /* __MBE_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/mb_graph_engine_cairo.h	Thu Nov 12 21:22:30 2009 +0800
@@ -0,0 +1,206 @@
+#ifndef __MB_GE_CAIRO_H_
+#define __MB_GE_CAIRO_H_
+
+#include <stdio.h>
+#include <cairo.h>
+#include <cairo-xlib.h>
+#include "mb_img_ldr.h"
+
+/*! \defgroup mb_ge_cairo MadButterfly Graphic Engine with Cairo
+ * @{
+ */
+#define MBE_OPERATOR_CLEAR CAIRO_OPERATOR_CLEAR
+#define MBE_OPERATOR_SOURCE CAIRO_OPERATOR_SOURCE
+#define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS
+
+#define mbe_ft_font_face_create_for_pattern cairo_ft_font_face_create_for_pattern
+#define mbe_image_surface_create_from_png cairo_image_surface_create_from_png
+#define mbe_pattern_add_color_stop_rgba cairo_pattern_add_color_stop_rgba
+#define mbe_pattern_create_for_surface cairo_pattern_create_for_surface
+#define mbe_scaled_font_text_extents cairo_scaled_font_text_extents
+#define mbe_image_surface_get_stride cairo_image_surface_get_stride
+#define mbe_image_surface_get_height cairo_image_surface_get_height
+#define mbe_image_surface_get_width cairo_image_surface_get_width
+#define mbe_image_surface_get_data cairo_image_surface_get_data
+#define mbe_scaled_font_reference cairo_scaled_font_reference
+#define mbe_pattern_create_radial cairo_pattern_create_radial
+#define mbe_pattern_create_linear cairo_pattern_create_linear
+#define mbe_xlib_surface_create cairo_xlib_surface_create
+#define mbe_scaled_font_destroy cairo_scaled_font_destroy
+#define mbe_font_face_reference cairo_font_face_reference
+#define mbe_set_source_surface cairo_set_source_surface
+#define mbe_scaled_font_status cairo_scaled_font_status
+#define mbe_pattern_set_matrix cairo_pattern_set_matrix
+#define mbe_font_face_destroy cairo_font_face_destroy
+#define mbe_paint_with_alpha cairo_paint_with_alpha
+#define mbe_font_face_status cairo_font_face_status
+#define mbe_surface_destroy cairo_surface_destroy
+#define mbe_set_source_rgba cairo_set_source_rgba
+#define mbe_set_scaled_font cairo_set_scaled_font
+#define mbe_pattern_destroy cairo_pattern_destroy
+#define mbe_get_scaled_font cairo_get_scaled_font
+#define mbe_set_source_rgb cairo_set_source_rgb
+#define mbe_set_line_width cairo_set_line_width
+#define mbe_get_font_face cairo_get_font_face
+#define mbe_fill_preserve cairo_fill_preserve
+#define mbe_set_operator cairo_set_operator
+#define mbe_get_operator cairo_get_operator
+#define mbe_set_source cairo_set_source
+#define mbe_reset_clip cairo_reset_clip
+#define mbe_get_target cairo_get_target
+#define mbe_close_path cairo_close_path
+#define mbe_text_path cairo_text_path
+#define mbe_show_text cairo_show_text
+#define mbe_rectangle cairo_rectangle
+#define mbe_in_stroke cairo_in_stroke
+#define mbe_new_path cairo_new_path
+#define mbe_curve_to cairo_curve_to
+#define mbe_restore cairo_restore
+#define mbe_move_to cairo_move_to
+#define mbe_line_to cairo_line_to
+#define mbe_in_fill cairo_in_fill
+#define mbe_destroy cairo_destroy
+#define mbe_stroke cairo_stroke
+#define mbe_create cairo_create
+#define mbe_paint cairo_paint
+#define mbe_save cairo_save
+#define mbe_fill cairo_fill
+#define mbe_clip cairo_clip
+
+typedef cairo_text_extents_t mbe_text_extents_t;
+typedef cairo_scaled_font_t mbe_scaled_font_t;
+typedef cairo_font_face_t mbe_font_face_t;
+typedef cairo_operator_t mbe_operator_t;
+typedef cairo_surface_t mbe_surface_t;
+typedef cairo_pattern_t mbe_pattern_t;
+typedef cairo_status_t mbe_status_t;
+typedef cairo_matrix_t mbe_matrix_t;
+typedef cairo_t mbe_t;
+typedef float co_aix;
+
+
+extern mbe_font_face_t * mbe_query_font_face(const char *family,
+					     int slant, int weight);
+extern void mbe_free_font_face(mbe_font_face_t *face);
+
+
+static mbe_scaled_font_t *
+mbe_scaled_font_create(mbe_font_face_t *face, mbe_matrix_t *fnt_mtx,
+		       mbe_matrix_t *ctm) {
+    cairo_font_options_t *options;
+    mbe_scaled_font_t *scaled;
+
+    options = cairo_font_options_create();
+    if(options == NULL)
+	return NULL;
+    
+    scaled = cairo_scaled_font_create(face, fnt_mtx, ctm, options);
+
+    cairo_font_options_destroy(options);
+    
+    return scaled;
+}
+
+static mbe_surface_t *
+mbe_image_surface_create_for_data(unsigned char *data,
+				  mb_img_fmt_t fmt,
+				  int width, int height,
+				  int stride) {
+    cairo_format_t _fmt;
+    
+    switch(fmt) {
+    case MB_IFMT_ARGB32:
+	_fmt = CAIRO_FORMAT_ARGB32;
+	break;
+    case MB_IFMT_RGB24:
+	_fmt = CAIRO_FORMAT_RGB24;
+	break;
+    case MB_IFMT_A8:
+	_fmt = CAIRO_FORMAT_A8;
+	break;
+    case MB_IFMT_A1:
+	_fmt = CAIRO_FORMAT_A1;
+	break;
+    default:
+	return NULL;
+    }
+    return cairo_image_surface_create_for_data(data, _fmt,
+					       width, height, stride);
+}
+
+static mb_img_fmt_t
+mbe_image_surface_get_format(mbe_surface_t *surface) {
+    cairo_format_t _fmt;
+    mb_img_fmt_t fmt;
+
+    _fmt = cairo_image_surface_get_format(surface);
+    switch(_fmt) {
+    case CAIRO_FORMAT_ARGB32:
+	fmt = MB_IFMT_ARGB32;
+	break;
+    case CAIRO_FORMAT_RGB24:
+	fmt = MB_IFMT_RGB24;
+	break;
+    case CAIRO_FORMAT_A8:
+	fmt = MB_IFMT_A8;
+	break;
+    case CAIRO_FORMAT_A1:
+	fmt = MB_IFMT_A1;
+	break;
+    default:
+	fmt = MB_IFMT_DUMMY;
+	break;
+    }
+
+    return fmt;
+}
+
+static mbe_surface_t *
+mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) {
+    cairo_format_t _fmt;
+    
+    switch(fmt) {
+    case MB_IFMT_ARGB32:
+	_fmt = CAIRO_FORMAT_ARGB32;
+	break;
+    case MB_IFMT_RGB24:
+	_fmt = CAIRO_FORMAT_RGB24;
+	break;
+    case MB_IFMT_A8:
+	_fmt = CAIRO_FORMAT_A8;
+	break;
+    case MB_IFMT_A1:
+	_fmt = CAIRO_FORMAT_A1;
+	break;
+    default:
+	return NULL;
+    }
+    
+    return cairo_image_surface_create(_fmt, width, height);
+}
+
+static void
+mbe_transform(mbe_t *mbe, const co_aix matrix[6]) {
+    cairo_matrix_t cmtx;
+
+    cmtx.xx = matrix[0];
+    cmtx.xy = matrix[1];
+    cmtx.x0 = matrix[2];
+    cmtx.yx = matrix[3];
+    cmtx.yy = matrix[4];
+    cmtx.y0 = matrix[5];
+
+    cairo_transform(mbe, &cmtx);
+}
+
+static void
+mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius,
+	co_aix angle_start, co_aix angle_stop) {
+    if(angle_start <= angle_stop)
+	cairo_arc(mbe, x, y, radius, angle_start, angle_stop);
+    else
+	cairo_arc_negative(mbe, x, y, radius, angle_start, angle_stop);
+}
+/* @} */
+
+#endif /* __MB_GE_CAIRO_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/mb_graph_engine_skia.h	Thu Nov 12 21:22:30 2009 +0800
@@ -0,0 +1,186 @@
+#ifndef __MB_GE_SKIA_H_
+#define __MB_GE_SKIA_H_
+
+#include <stdio.h>
+#include "mb_img_ldr.h"
+
+/*! \defgroup mb_ge_skia MadButterfly Graphic Engine with Skia
+ * @{
+ */
+#define MBE_OPERATOR_CLEAR CAIRO_OPERATOR_CLEAR
+#define MBE_OPERATOR_SOURCE CAIRO_OPERATOR_SOURCE
+#define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS
+
+#define mbe_ft_font_face_create_for_pattern
+#define mbe_image_surface_create_from_png
+#define mbe_pattern_add_color_stop_rgba
+#define mbe_pattern_create_for_surface
+#define mbe_scaled_font_text_extents
+#define mbe_image_surface_get_stride
+#define mbe_image_surface_get_height
+#define mbe_image_surface_get_width
+#define mbe_image_surface_get_data
+#define mbe_scaled_font_reference
+#define mbe_pattern_create_radial
+#define mbe_pattern_create_linear
+#define mbe_xlib_surface_create
+#define mbe_scaled_font_destroy
+#define mbe_font_face_reference
+#define mbe_set_source_surface
+#define mbe_scaled_font_status
+#define mbe_scaled_font_create
+#define mbe_pattern_set_matrix
+#define mbe_font_face_destroy
+#define mbe_paint_with_alpha
+#define mbe_font_face_status
+#define mbe_surface_destroy
+#define mbe_set_source_rgba
+#define mbe_set_scaled_font
+#define mbe_pattern_destroy
+#define mbe_get_scaled_font
+#define mbe_set_source_rgb
+#define mbe_set_line_width
+#define mbe_get_font_face
+#define mbe_fill_preserve
+#define mbe_set_operator
+#define mbe_get_operator
+#define mbe_set_source
+#define mbe_reset_clip
+#define mbe_get_target
+#define mbe_close_path
+#define mbe_text_path
+#define mbe_show_text
+#define mbe_rectangle
+#define mbe_in_stroke
+#define mbe_new_path
+#define mbe_curve_to
+#define mbe_restore
+#define mbe_move_to
+#define mbe_line_to
+#define mbe_in_fill
+#define mbe_destroy
+#define mbe_stroke
+#define mbe_create
+#define mbe_paint
+#define mbe_save
+#define mbe_fill
+#define mbe_clip
+
+typedef cairo_text_extents_t mbe_text_extents_t;
+typedef cairo_scaled_font_t mbe_scaled_font_t;
+typedef cairo_font_face_t mbe_font_face_t;
+typedef cairo_operator_t mbe_operator_t;
+typedef cairo_surface_t mbe_surface_t;
+typedef cairo_pattern_t mbe_pattern_t;
+typedef cairo_status_t mbe_status_t;
+typedef cairo_matrix_t mbe_matrix_t;
+typedef cairo_t mbe_t;
+typedef float co_aix;
+
+extern mbe_font_face_t * mbe_query_font_face(const char *family,
+					     int slant, int weight);
+extern void mbe_free_font_face(mbe_font_face_t *face);
+
+static mbe_surface_t *
+mbe_image_surface_create_for_data(unsigned char *data,
+				  mb_img_fmt_t fmt,
+				  int width, int height,
+				  int stride) {
+    cairo_format_t _fmt;
+    
+    switch(fmt) {
+    case MB_IFMT_ARGB32:
+	_fmt = CAIRO_FORMAT_ARGB32;
+	break;
+    case MB_IFMT_RGB24:
+	_fmt = CAIRO_FORMAT_RGB24;
+	break;
+    case MB_IFMT_A8:
+	_fmt = CAIRO_FORMAT_A8;
+	break;
+    case MB_IFMT_A1:
+	_fmt = CAIRO_FORMAT_A1;
+	break;
+    default:
+	return NULL;
+    }
+    return cairo_image_surface_create_for_data(data, _fmt,
+					       width, height, stride);
+}
+
+static mb_img_fmt_t
+mbe_image_surface_get_format(mbe_surface_t *surface) {
+    cairo_format_t _fmt;
+    mb_img_fmt_t fmt;
+
+    _fmt = cairo_image_surface_get_format(surface);
+    switch(_fmt) {
+    case CAIRO_FORMAT_ARGB32:
+	fmt = MB_IFMT_ARGB32;
+	break;
+    case CAIRO_FORMAT_RGB24:
+	fmt = MB_IFMT_RGB24;
+	break;
+    case CAIRO_FORMAT_A8:
+	fmt = MB_IFMT_A8;
+	break;
+    case CAIRO_FORMAT_A1:
+	fmt = MB_IFMT_A1;
+	break;
+    default:
+	fmt = MB_IFMT_DUMMY;
+	break;
+    }
+
+    return fmt;
+}
+
+static mbe_surface_t *
+mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) {
+    cairo_format_t _fmt;
+    
+    switch(fmt) {
+    case MB_IFMT_ARGB32:
+	_fmt = CAIRO_FORMAT_ARGB32;
+	break;
+    case MB_IFMT_RGB24:
+	_fmt = CAIRO_FORMAT_RGB24;
+	break;
+    case MB_IFMT_A8:
+	_fmt = CAIRO_FORMAT_A8;
+	break;
+    case MB_IFMT_A1:
+	_fmt = CAIRO_FORMAT_A1;
+	break;
+    default:
+	return NULL;
+    }
+    
+    return cairo_image_surface_create(_fmt, width, height);
+}
+
+static void
+mbe_transform(mbe_t *mbe, const co_aix matrix[6]) {
+    cairo_matrix_t cmtx;
+
+    cmtx.xx = matrix[0];
+    cmtx.xy = matrix[1];
+    cmtx.x0 = matrix[2];
+    cmtx.yx = matrix[3];
+    cmtx.yy = matrix[4];
+    cmtx.y0 = matrix[5];
+
+    cairo_transform(mbe, &cmtx);
+}
+
+static void
+mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius,
+	co_aix angle_start, co_aix angle_stop) {
+    if(angle_start <= angle_stop)
+	cairo_arc(mbe, x, y, radius, angle_start, angle_stop);
+    else
+	cairo_arc_negative(mbe, x, y, radius, angle_start, angle_stop);
+}
+/* @} */
+
+#endif /* __MB_GE_SKIA_H_ */
--- a/src/Makefile.am	Thu Nov 12 21:16:13 2009 +0800
+++ b/src/Makefile.am	Thu Nov 12 21:22:30 2009 +0800
@@ -31,8 +31,12 @@
 libmbfly_la_SOURCES += X_supp.c
 endif
 
+if CAIRO_BACKEND
+libmbfly_la_SOURCES += graph_engine_cairo.c
+
 libmbfly_la_CPPFLAGS = @cairo_CFLAGS@ @pangocairo_CFLAGS@
 libmbfly_la_LDFLAGS = @cairo_LIBS@ @pangocairo_LIBS@
+endif
 
 X_main_SOURCES = X_main.c
 X_main_LDADD = $(top_builddir)/src/libmbfly.la
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/graph_engine_cairo.c	Thu Nov 12 21:22:30 2009 +0800
@@ -0,0 +1,110 @@
+#include <fontconfig/fontconfig.h>
+#include "mb_graph_engine_cairo.h"
+#include "mb_shapes.h"
+
+#ifndef ASSERT
+#define ASSERT(x)
+#endif
+
+/*! \brief Find out a font pattern.
+ *
+ * This function use fontconfig to decide a font file in pattern.  It can
+ * replaced by other mechanism if you think it is not what you want.
+ *
+ * \param slant make font prune if it it non-zero.
+ * \param weight make font normal if it is 100.
+ */
+static
+FcPattern *query_font_pattern(const char *family, int slant, int weight) {
+    FcPattern *ptn, *p, *fn_ptn;
+    FcValue val;
+    FcConfig *cfg;
+    FcBool r;
+    FcResult result;
+    static int slant_map[] = {	/* from MB_FONT_SLANT_* to FC_SLANT_* */
+	FC_SLANT_ROMAN,
+	FC_SLANT_ROMAN,
+	FC_SLANT_ITALIC,
+	FC_SLANT_OBLIQUE};
+
+    cfg = FcConfigGetCurrent();
+    ptn = FcPatternCreate();
+    p = FcPatternCreate();
+    if(ptn == NULL || p == NULL)
+	goto err;
+
+    val.type = FcTypeString;
+    val.u.s = family;
+    FcPatternAdd(ptn, "family", val, FcTrue);
+    
+    val.type = FcTypeInteger;
+    val.u.i = slant_map[slant];
+    FcPatternAdd(ptn, "slant", val, FcTrue);
+    
+    val.type = FcTypeInteger;
+    val.u.i = weight;
+    FcPatternAdd(ptn, "weight", val, FcTrue);
+
+    r = FcConfigSubstituteWithPat(cfg, ptn, NULL, FcMatchPattern);
+    if(!r)
+	goto err;
+    
+    r = FcConfigSubstituteWithPat(cfg, p, ptn, FcMatchFont);
+    if(!r)
+	goto err;
+
+    FcDefaultSubstitute(p);
+
+    fn_ptn = FcFontMatch(cfg, p, &result);
+
+    /* It is supposed to return FcResultMatch.  But, it is no, now.
+     * I don't know why.  Someone should figure out the issue.
+     */
+#if 0
+    if(result != FcResultMatch) {
+	printf("%d %d\n", result, FcResultMatch);
+	goto err;
+    }
+#endif
+    if(fn_ptn == NULL)
+	goto err;
+
+    FcPatternDestroy(ptn);
+    FcPatternDestroy(p);
+    
+    return fn_ptn;
+    
+err:
+    if(ptn)
+	FcPatternDestroy(ptn);
+    if(p)
+	FcPatternDestroy(p);
+    return NULL;
+
+}
+
+/*! \brief Find out a font face for a pattern specified.
+ *
+ * The pattern, here, is a vector of family, slant, and weight.
+ * This function base on fontconfig and cairo FreeType font supporting.
+ * You can replace this function with other font mechanisms.
+ */
+mbe_font_face_t *
+mbe_query_font_face(const char *family, int slant, int weight) {
+    mbe_font_face_t *cface;
+    FcPattern *ptn;
+    
+    ptn = query_font_pattern(family, slant, weight);
+    cface = mbe_ft_font_face_create_for_pattern(ptn);
+    FcPatternDestroy(ptn);
+    
+    return cface;
+}
+
+void
+mbe_free_font_face(mbe_font_face_t *face) {
+    ASSERT(face == NULL);
+
+    mbe_font_face_destroy(face);
+}
+
--- a/src/shape_stext.c	Thu Nov 12 21:16:13 2009 +0800
+++ b/src/shape_stext.c	Thu Nov 12 21:22:30 2009 +0800
@@ -1,7 +1,6 @@
 #include <stdio.h>
 #include "mb_graph_engine.h"
 #include <cairo-ft.h>
-#include <fontconfig/fontconfig.h>
 #include "mb_shapes.h"
 #include "mb_tools.h"
 
@@ -128,106 +127,16 @@
 #define MBE_SET_WIDTH(ext, v) do { ((ext)->width) = v; } while(0)
 #define MBE_SET_HEIGHT(ext, v) do { ((ext)->height) = v; } while(0)
 
-/*! \brief Find out a font pattern.
- *
- * This function use fontconfig to decide a font file in pattern.  It can
- * replaced by other mechanism if you think it is not what you want.
- *
- * \param slant make font prune if it it non-zero.
- * \param weight make font normal if it is 100.
- */
-static
-FcPattern *query_font_pattern(const char *family, int slant, int weight) {
-    FcPattern *ptn, *p, *fn_ptn;
-    FcValue val;
-    FcConfig *cfg;
-    FcBool r;
-    FcResult result;
-    static int slant_map[] = {	/* from MB_FONT_SLANT_* to FC_SLANT_* */
-	FC_SLANT_ROMAN,
-	FC_SLANT_ROMAN,
-	FC_SLANT_ITALIC,
-	FC_SLANT_OBLIQUE};
-
-    cfg = FcConfigGetCurrent();
-    ptn = FcPatternCreate();
-    p = FcPatternCreate();
-    if(ptn == NULL || p == NULL)
-	goto err;
-
-    val.type = FcTypeString;
-    val.u.s = family;
-    FcPatternAdd(ptn, "family", val, FcTrue);
-    
-    val.type = FcTypeInteger;
-    val.u.i = slant_map[slant];
-    FcPatternAdd(ptn, "slant", val, FcTrue);
-    
-    val.type = FcTypeInteger;
-    val.u.i = weight;
-    FcPatternAdd(ptn, "weight", val, FcTrue);
-
-    r = FcConfigSubstituteWithPat(cfg, ptn, NULL, FcMatchPattern);
-    if(!r)
-	goto err;
-    
-    r = FcConfigSubstituteWithPat(cfg, p, ptn, FcMatchFont);
-    if(!r)
-	goto err;
-
-    FcDefaultSubstitute(p);
-
-    fn_ptn = FcFontMatch(cfg, p, &result);
-
-    /* It is supposed to return FcResultMatch.  But, it is no, now.
-     * I don't know why.  Someone should figure out the issue.
-     */
-#if 0
-    if(result != FcResultMatch) {
-	printf("%d %d\n", result, FcResultMatch);
-	goto err;
-    }
-#endif
-    if(fn_ptn == NULL)
-	goto err;
-
-    FcPatternDestroy(ptn);
-    FcPatternDestroy(p);
-    
-    return fn_ptn;
-    
-err:
-    if(ptn)
-	FcPatternDestroy(ptn);
-    if(p)
-	FcPatternDestroy(p);
-    return NULL;
-
+static mb_font_face_t *
+query_font_face(const char *family, int slant, int weight) {
+    return (mb_font_face_t *)mbe_query_font_face(family, slant, weight);
 }
 
-/*! \brief Find out a font face for a pattern specified.
- *
- * The pattern, here, is a vector of family, slant, and weight.
- * This function base on fontconfig and cairo FreeType font supporting.
- * You can replace this function with other font mechanisms.
- */
-static
-mb_font_face_t *query_font_face(const char *family, int slant, int weight) {
-    mbe_font_face_t *cface;
-    FcPattern *ptn;
-    
-    ptn = query_font_pattern(family, slant, weight);
-    cface = mbe_ft_font_face_create_for_pattern(ptn);
-    FcPatternDestroy(ptn);
-    
-    return (mb_font_face_t *)cface;
-}
-
-static
-void free_font_face(mb_font_face_t *face) {
+static void
+free_font_face(mb_font_face_t *face) {
     ASSERT(face == NULL);
 
-    mbe_font_face_destroy((mbe_font_face_t *)face);
+    mbe_free_font_face((mbe_font_face_t *)face);
 }
 
 /*! \brief This is scaled font for specified size and extent.
@@ -248,16 +157,9 @@
 	0, 1,
 	0, 0
     };
-    static mbe_font_options_t *opt = NULL;
     
     ASSERT(matrix != NULL);
     
-    if(opt == NULL) {
-	opt = mbe_font_options_create();
-	if(opt == NULL)
-	    return NULL;
-    }
-
     font_matrix.xx = *matrix++;
     font_matrix.xy = *matrix++;
     font_matrix.x0 = *matrix++;
@@ -265,8 +167,7 @@
     font_matrix.yy = *matrix++;
     font_matrix.y0 = *matrix;
     scaled_font = mbe_scaled_font_create((mbe_font_face_t *)face,
-					   &font_matrix,
-					   &id, opt);
+					 &font_matrix, &id);
 
     return (mb_scaled_font_t *)scaled_font;
 }
--- a/src/shape_text.c	Thu Nov 12 21:16:13 2009 +0800
+++ b/src/shape_text.c	Thu Nov 12 21:22:30 2009 +0800
@@ -207,7 +207,6 @@
     mbe_matrix_t fmatrix;
     mbe_matrix_t ctm;
     mbe_scaled_font_t *new_scaled;
-    mbe_font_options_t *fopt;
 
     pango_layout_get_extents(text->layout, NULL, extents);
     pango_extents_to_pixels(extents,NULL);