root/trunk/cairo/cairooo/scaledfont.d

Revision 119, 4.0 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     XXX
3     
4 Authors: Daniel Keep
5 Copyright: 2006, Daniel Keep
6 License: BSD v2 (http://opensource.org/licenses/bsd-license.php).
7 **/
8 /**
9     Copyright © 2006 Daniel Keep
10     All rights reserved.
11     
12     Redistribution and use in source and binary forms, with or without
13     modification, are permitted provided that the following conditions are
14     met:
15     
16     * Redistributions of source code must retain the above copyright
17       notice, this list of conditions and the following disclaimer.
18       
19     * Redistributions in binary form must reproduce the above copyright
20       notice, this list of conditions and the following disclaimer in the
21       documentation and/or other materials provided with the distribution.
22     
23     * Neither the name of this software, nor the names of its contributors
24       may be used to endorse or promote products derived from this software
25       without specific prior written permission.
26     
27     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30     PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34     PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36     NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 **/
39 module cairooo.scaledfont;
40
41 private
42 {
43     import cairo.cairo;
44     import cairooo.enums;
45     import cairooo.exceptions;
46     import cairooo.fontextents;
47     import cairooo.fontface;
48     import cairooo.fontoptions;
49     import cairooo.glyph;
50     import cairooo.matrix;
51     import cairooo.textextents;
52 }
53
54 class ScaledFont
55 {
56 private:
57     cairo_scaled_font_t* _handle;
58
59 public:
60     this(cairo_scaled_font_t* handle, bool takeref)
61     {
62         checkStatus(handle);
63         this._handle = handle;
64         if( takeref )
65         {
66             cairo_scaled_font_reference(this.handle);
67             checkStatus(this.handle);
68         }
69     }
70    
71     this(FontFace fontFace, Matrix fontMatrix, Matrix ctm,
72             FontOptions options)
73     {
74         // We need to call the method on the font face itself so that backends
75         // can specialize what kind of ScaledFont they create.
76         auto ScaledFont temp = fontFace.createScaledFont(fontMatrix, ctm,
77                 options);
78         this(temp);
79     }
80
81     this(ScaledFont scaledFont)
82     {
83         this(scaledFont.handle, true);
84     }
85
86     ~this()
87     {
88         cairo_scaled_font_destroy(this.handle);
89     }
90
91     //
92     // cairo api members
93     //
94     FontExtents
95     extents()
96     {
97         scope(success) checkStatus();
98         FontExtents result;
99         cairo_scaled_font_extents(this.handle,
100                 cast(cairo_font_extents_t*) &result);
101         return result;
102     }
103
104     TextExtents
105     glyphExtents(Glyph[] glyphs)
106     {
107         scope(success) checkStatus();
108         TextExtents result;
109         cairo_scaled_font_glyph_extents(this.handle,
110                 cast(cairo_glyph_t*) glyphs, glyphs.length,
111                 cast(cairo_text_extents_t*) &result);
112         return result;
113     }
114
115     //
116     // miscellaneous members
117     //
118     ScaledFont
119     dup()
120     {
121         return new ScaledFont(this);
122     }
123
124     cairo_scaled_font_t*
125     handle()
126     {
127         return this._handle;
128     }
129
130     //
131     // internal stuff
132     //
133     void
134     checkStatus()
135     {
136         .checkStatus(cairo_scaled_font_status(this.handle));
137     }
138
139     void
140     checkStatus(cairo_scaled_font_t* handle)
141     {
142         .checkStatus(cairo_scaled_font_status(handle));
143     }
144 }
Note: See TracBrowser for help on using the browser.