2 function box_text($str, $x, $y)
6 $ext = $con->text_extents($str);
7 $sf = $con->get_scaled_font();
8 $sext = $sf->text_extents("text");
9 $lw = $con->get_line_width();
10 $con->rectangle($x +
$ext["x_bearing"]-$lw/2, $y +
$ext["y_bearing"] - $lw/2, $ext["width"]+
$lw, $ext["height"]+
$lw);
13 $con->show_text($str);
16 $sur = new CairoImageSurface(FORMAT_ARGB32
, 38, 34);
17 $con = new CairoContext($sur);
19 $con->set_source_rgb(1,1,1);
22 $con->select_font_face("Bitstream Vera Sans");
23 $con->set_font_size(12);
25 $con->set_line_width(1);
26 $ext = $con->text_extents("text");
28 $con->set_source_rgb(0,0,0);
29 box_text("text", 0, -$ext["y_bearing"]);
30 $mat = new CairoMatrix();
31 $mat->translate(6,16);
33 $con->set_font_matrix($mat);
34 $con->set_source_rgb(0,0,1);
35 box_text("text", 0, -$ext["y_bearing"]);
37 $sur->write_to_png("font-matrix-translation-php.png");