root/trunk/cairo/cairooo_snippets/snippets/text_extents.d

Revision 119, 0.8 kB (checked in by DRK, 6 years ago)

* Added bindings for the Glitz and Xlib backends.
* Checked in cairooo: an OO layer on top of the cairo binding.
* Added snippets directory for cairooo
* Added basic tutorial on how to use cairooo
* Added a simple demo program.
* Added scripts for building import libraries.
* Fixed several bugs.
* Drank WAAY too much coffee.

Line 
1 module snippets.text_extents;
2
3 private
4 {
5     import std.math;
6     import cairooo.all;
7     import snippets.common;
8 }
9
10 void snippet_text_extents(Context cr, int width, int height)
11 {
12     TextExtents extents;
13     char[] utf8 = "cairo";
14     double x, y;
15
16     cr.selectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
17     cr.setFontSize(0.4);
18     extents = cr.textExtents(utf8);
19
20     x = 0.1; y = 0.6;
21
22     cr.moveTo(x, y);
23     cr.showText(utf8);
24
25     // draw helping lines
26     cr.setSourceRGBA(1, 0.2, 0.2, 0.6);
27     cr.arc(x, y, 0.05, 0, 2*PI);
28     cr.fill();
29     cr.moveTo(x, y);
30     cr.relLineTo(0, -extents.height);
31     cr.relLineTo(extents.width, 0);
32     cr.relLineTo(extents.xBearing, -extents.yBearing);
33     cr.stroke();
34 }
35
36 static this()
37 {
38     snippets_hash["text_extents"] = &snippet_text_extents;
39 }
Note: See TracBrowser for help on using the browser.