2
// FontBackendHandler.cs
5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
32
namespace Xwt.GtkBackend
34
public class FontBackendHandler: IFontBackendHandler
36
public object Create (string fontName, double size, FontSizeUnit sizeUnit, FontStyle style, FontWeight weight, FontStretch stretch)
38
string s = sizeUnit == FontSizeUnit.Points ? size.ToString () : size + "px";
39
return FontDescription.FromString (fontName + " " + s);
42
#region IFontBackendHandler implementation
44
public object Copy (object handle)
46
FontDescription d = (FontDescription) handle;
50
public object SetSize (object handle, double size, FontSizeUnit sizeUnit)
52
FontDescription d = (FontDescription) handle;
54
if (sizeUnit == FontSizeUnit.Points)
55
d.Size = (int) (size * Pango.Scale.PangoScale);
57
d.AbsoluteSize = (int) (size * Pango.Scale.PangoScale);
61
public object SetFamily (object handle, string family)
63
FontDescription fd = (FontDescription) handle;
69
public object SetStyle (object handle, FontStyle style)
71
FontDescription fd = (FontDescription) handle;
73
fd.Style = (Pango.Style)(int)style;
77
public object SetWeight (object handle, FontWeight weight)
79
FontDescription fd = (FontDescription) handle;
81
fd.Weight = (Pango.Weight)(int)weight;
85
public object SetStretch (object handle, FontStretch stretch)
87
FontDescription fd = (FontDescription) handle;
89
fd.Stretch = (Pango.Stretch)(int)stretch;
93
public double GetSize (object handle)
95
FontDescription fd = (FontDescription) handle;
96
return (double)fd.Size / (double) Pango.Scale.PangoScale;
99
public string GetFamily (object handle)
101
FontDescription fd = (FontDescription) handle;
105
public FontStyle GetStyle (object handle)
107
FontDescription fd = (FontDescription) handle;
108
return (FontStyle)(int)fd.Style;
111
public FontWeight GetWeight (object handle)
113
FontDescription fd = (FontDescription) handle;
114
return (FontWeight)(int)fd.Weight;
117
public FontStretch GetStretch (object handle)
119
FontDescription fd = (FontDescription) handle;
120
return (FontStretch)(int)fd.Stretch;