root/trunk/cairo/cairooo/cairo.d

Revision 119, 4.2 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 /**
2     This module provides functions for loading the cairo library at runtime,
3     and for checking what version of the cairo library has been loaded.
4
5     When using the cairooo binding, you need to call the appropriate load
6     function for each package before using it.  You may also optionally pass
7     the name of the library to load the package's functionality from, although
8     this should be autodetected by the binding based on your operating system.
9
10 Examples:
11 ------------------------------------------------------------------------------
12 import std.stdio;
13 import cairooo.all;
14
15 void main()
16 {
17     // Loads the cairooo binding using the default library location
18     Cairo.load();
19
20     // Displays the version of the loaded cairo library.
21     writefln("cairo version: %s", Cairo.cairoVersionString);
22 }
23 ------------------------------------------------------------------------------
24 Authors: Daniel Keep
25 Copyright: 2006, Daniel Keep
26 License: BSD v2 (http://opensource.org/licenses/bsd-license.php).
27 **/
28 /**
29     Copyright © 2006 Daniel Keep
30     All rights reserved.
31     
32     Redistribution and use in source and binary forms, with or without
33     modification, are permitted provided that the following conditions are
34     met:
35     
36     * Redistributions of source code must retain the above copyright
37       notice, this list of conditions and the following disclaimer.
38       
39     * Redistributions in binary form must reproduce the above copyright
40       notice, this list of conditions and the following disclaimer in the
41       documentation and/or other materials provided with the distribution.
42     
43     * Neither the name of this software, nor the names of its contributors
44       may be used to endorse or promote products derived from this software
45       without specific prior written permission.
46     
47     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50     PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
51     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
52     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
53     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
54     PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
55     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
56     NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
57     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 **/
59 module cairooo.cairo;
60
61 private
62 {
63     import std.string;
64     import cairo.cairo;
65     import cairo.loader;
66 }
67
68 /**
69     This exception is thrown when the binding cannot load the cairo library,
70     or it cannot find a function in the library.
71 **/
72 alias cairo.loader.CairoLoaderException CairoLoaderException;
73
74 /**
75     This class provides a few functions for loading the binding, and accessing
76     the underlying cairo library's version number.
77 **/
78 class Cairo
79 {
80     /**
81         Loads the default cairo library, and attempts to bind this package's
82         functions.
83     **/
84     static
85     void
86     load()
87     {
88         cairo_load();
89     }
90
91     /**
92         Loads the cairo library from the given file path, and attempts to bind
93         this package's functions.
94
95     Params:
96         libName = The path to load the cairo library from.  Depending on your
97                   system, this need not be an absolute pathname.  Generally,
98                   provided that the library is on your system PATH or LIBPATH,
99                   then the name of the library should be sufficient.
100
101                   For example, on Windows you might use "libcairo-2.dll",
102                   whilst linux users might use "libcairo-2.so".
103     **/
104     static
105     void
106     load(char[] libName)
107     {
108         cairo_load(libName);
109     }
110    
111     /**
112         Returns the version of the underlying cairo library.
113     **/
114     static
115     int
116     cairoVersion()
117     {
118         return cairo_version();
119     }
120
121     /// ditto
122     static
123     char[]
124     cairoVersionString()
125     {
126         return .toString(cairo_version_string());
127     }
128 }
Note: See TracBrowser for help on using the browser.