~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.Gtk/Xwt.GtkBackend/FontBackendHandler.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// FontBackendHandler.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2011 Xamarin Inc
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using Xwt.Backends;
 
29
using Pango;
 
30
using Xwt.Drawing;
 
31
 
 
32
namespace Xwt.GtkBackend
 
33
{
 
34
        public class FontBackendHandler: IFontBackendHandler
 
35
        {
 
36
                public object Create (string fontName, double size, FontSizeUnit sizeUnit, FontStyle style, FontWeight weight, FontStretch stretch)
 
37
                {
 
38
                        string s = sizeUnit == FontSizeUnit.Points ? size.ToString () : size + "px";
 
39
                        return FontDescription.FromString (fontName + " " + s);
 
40
                }
 
41
 
 
42
                #region IFontBackendHandler implementation
 
43
                
 
44
                public object Copy (object handle)
 
45
                {
 
46
                        FontDescription d = (FontDescription) handle;
 
47
                        return d.Copy ();
 
48
                }
 
49
                
 
50
                public object SetSize (object handle, double size, FontSizeUnit sizeUnit)
 
51
                {
 
52
                        FontDescription d = (FontDescription) handle;
 
53
                        d = d.Copy ();
 
54
                        if (sizeUnit == FontSizeUnit.Points)
 
55
                                d.Size = (int) (size * Pango.Scale.PangoScale);
 
56
                        else
 
57
                                d.AbsoluteSize = (int) (size * Pango.Scale.PangoScale);
 
58
                        return d;
 
59
                }
 
60
 
 
61
                public object SetFamily (object handle, string family)
 
62
                {
 
63
                        FontDescription fd = (FontDescription) handle;
 
64
                        fd = fd.Copy ();
 
65
                        fd.Family = family;
 
66
                        return fd;
 
67
                }
 
68
 
 
69
                public object SetStyle (object handle, FontStyle style)
 
70
                {
 
71
                        FontDescription fd = (FontDescription) handle;
 
72
                        fd = fd.Copy ();
 
73
                        fd.Style = (Pango.Style)(int)style;
 
74
                        return fd;
 
75
                }
 
76
 
 
77
                public object SetWeight (object handle, FontWeight weight)
 
78
                {
 
79
                        FontDescription fd = (FontDescription) handle;
 
80
                        fd = fd.Copy ();
 
81
                        fd.Weight = (Pango.Weight)(int)weight;
 
82
                        return fd;
 
83
                }
 
84
 
 
85
                public object SetStretch (object handle, FontStretch stretch)
 
86
                {
 
87
                        FontDescription fd = (FontDescription) handle;
 
88
                        fd = fd.Copy ();
 
89
                        fd.Stretch = (Pango.Stretch)(int)stretch;
 
90
                        return fd;
 
91
                }
 
92
                
 
93
                public double GetSize (object handle)
 
94
                {
 
95
                        FontDescription fd = (FontDescription) handle;
 
96
                        return (double)fd.Size / (double) Pango.Scale.PangoScale;
 
97
                }
 
98
 
 
99
                public string GetFamily (object handle)
 
100
                {
 
101
                        FontDescription fd = (FontDescription) handle;
 
102
                        return fd.Family;
 
103
                }
 
104
 
 
105
                public FontStyle GetStyle (object handle)
 
106
                {
 
107
                        FontDescription fd = (FontDescription) handle;
 
108
                        return (FontStyle)(int)fd.Style;
 
109
                }
 
110
 
 
111
                public FontWeight GetWeight (object handle)
 
112
                {
 
113
                        FontDescription fd = (FontDescription) handle;
 
114
                        return (FontWeight)(int)fd.Weight;
 
115
                }
 
116
 
 
117
                public FontStretch GetStretch (object handle)
 
118
                {
 
119
                        FontDescription fd = (FontDescription) handle;
 
120
                        return (FontStretch)(int)fd.Stretch;
 
121
                }
 
122
                #endregion
 
123
 
 
124
 
 
125
        }
 
126
}
 
127