|
楼主 |
发表于 2005-10-26 21:38:19
|
显示全部楼层
a testcase.
[code:1]
#include <cairo.h>
#include <cairo-ft.h>
#include <math.h>
#define WIDTH 40
#define HEIGHT 180
#define TEXT " cairo 竖写文字测试"
int main() {
cairo_surface_t * sr;
cairo_t * cr;
cairo_font_face_t * font_face;
cairo_matrix_t font_matrix;
cairo_text_extents_t extents;
cairo_font_options_t *options;
double y = 0;
FcPattern * pattern, * resolved;
FcResult result;
pattern = FcPatternCreate ();
#if 0
FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *)"bitstream vera sans");
#else
FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *)"sans");
#endif
FcConfigSubstitute (NULL, pattern, FcMatchPattern);
FcDefaultSubstitute (pattern);
resolved = FcFontMatch (NULL, pattern, &result);
/* vertical layout */
FcPatternDel (resolved, FC_VERTICAL_LAYOUT);
FcPatternAddBool (resolved, FC_VERTICAL_LAYOUT, FcTrue);
font_face = cairo_ft_font_face_create_for_pattern (resolved);
cairo_matrix_init_scale (&font_matrix, 14.0, 14.0);
sr = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT);
cr = cairo_create (sr);
cairo_set_font_face (cr, font_face);
cairo_set_font_matrix (cr, &font_matrix);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0, 0, 1.0);
cairo_text_extents (cr, TEXT, &extents);
cairo_move_to (cr, -extents.x_bearing, y - extents.y_bearing);
cairo_show_text (cr, TEXT);
cairo_surface_write_to_png (sr, "cairo-vertical-layout-text.png");
FcPatternDestroy (pattern);
FcPatternDestroy (resolved);
cairo_font_face_destroy (font_face);
cairo_destroy (cr);
cairo_surface_destroy (sr);
return 0;
}
[/code:1] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|