2
// CMTextMarkupAttributes.cs: Implements CMTextMarkup Attributes
4
// Authors: Marek Safar (marek.safar@gmail.com)
6
// Copyright 2012 Xamarin Inc
8
// Permission is hereby granted, free of charge, to any person obtaining
9
// a copy of this software and associated documentation files (the
10
// "Software"), to deal in the Software without restriction, including
11
// without limitation the rights to use, copy, modify, merge, publish,
12
// distribute, sublicense, and/or sell copies of the Software, and to
13
// permit persons to whom the Software is furnished to do so, subject to
14
// the following conditions:
16
// The above copyright notice and this permission notice shall be
17
// included in all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using System.Runtime.InteropServices;
33
using MonoMac.Foundation;
34
using MonoMac.CoreFoundation;
35
using MonoMac.ObjCRuntime;
37
namespace MonoMac.CoreMedia {
39
public struct TextMarkupColor
41
public TextMarkupColor (float red, float green, float blue, float alpha)
44
if (red < 0 || red > 1.0)
45
throw new ArgumentOutOfRangeException ("red");
46
if (green < 0 || green > 1.0)
47
throw new ArgumentOutOfRangeException ("green");
48
if (blue < 0 || blue > 1.0)
49
throw new ArgumentOutOfRangeException ("blue");
50
if (alpha < 0 || alpha > 1.0)
51
throw new ArgumentOutOfRangeException ("alpha");
59
public float Red { get; private set; }
60
public float Green { get; private set; }
61
public float Blue { get; private set; }
62
public float Alpha { get; private set; }
66
public class CMTextMarkupAttributes : DictionaryContainer
70
public static readonly NSString ForegroundColorARGB;
71
public static readonly NSString BackgroundColorARGB;
72
public static readonly NSString BoldStyle;
73
public static readonly NSString ItalicStyle;
74
public static readonly NSString UnderlineStyle;
75
public static readonly NSString FontFamilyName;
76
public static readonly NSString RelativeFontSize;
80
var handle = Dlfcn.dlopen (Constants.CoreMediaLibrary, 0);
81
if (handle == IntPtr.Zero)
84
ForegroundColorARGB = Dlfcn.GetStringConstant (handle, "kCMTextMarkupAttribute_ForegroundColorARGB");
85
BackgroundColorARGB = Dlfcn.GetStringConstant (handle, "kCMTextMarkupAttribute_BackgroundColorARGB");
86
BoldStyle = Dlfcn.GetStringConstant (handle, "kCMTextMarkupAttribute_BoldStyle");
87
ItalicStyle = Dlfcn.GetStringConstant (handle, "kCMTextMarkupAttribute_ItalicStyle");
88
UnderlineStyle = Dlfcn.GetStringConstant (handle, "kCMTextMarkupAttribute_UnderlineStyle");
89
FontFamilyName = Dlfcn.GetStringConstant (handle, "kCMTextMarkupAttribute_FontFamilyName");
90
RelativeFontSize = Dlfcn.GetStringConstant (handle, "kCMTextMarkupAttribute_RelativeFontSize");
92
Dlfcn.dlclose (handle);
97
public CMTextMarkupAttributes ()
102
public CMTextMarkupAttributes (NSDictionary dictionary)
107
public TextMarkupColor? ForegroundColor {
109
var array = GetArray<NSNumber> (Keys.ForegroundColorARGB);
113
return new TextMarkupColor (array [1].FloatValue, array [2].FloatValue, array [3].FloatValue, array [0].FloatValue);
118
SetArrayValue (Keys.ForegroundColorARGB, new [] {
119
NSNumber.FromFloat (v.Alpha),
120
NSNumber.FromFloat (v.Red),
121
NSNumber.FromFloat (v.Green),
122
NSNumber.FromFloat (v.Blue)
125
RemoveValue (Keys.ForegroundColorARGB);
130
public TextMarkupColor? BackgroundColor {
132
var array = GetArray<NSNumber> (Keys.BackgroundColorARGB);
136
return new TextMarkupColor (array [1].FloatValue, array [2].FloatValue, array [3].FloatValue, array [0].FloatValue);
141
SetArrayValue (Keys.BackgroundColorARGB, new [] {
142
NSNumber.FromFloat (v.Alpha),
143
NSNumber.FromFloat (v.Red),
144
NSNumber.FromFloat (v.Green),
145
NSNumber.FromFloat (v.Blue)
148
RemoveValue (Keys.BackgroundColorARGB);
155
return GetBoolValue (Keys.BoldStyle);
158
SetBooleanValue (Keys.BoldStyle, value);
162
public bool? Italic {
164
return GetBoolValue (Keys.ItalicStyle);
167
SetBooleanValue (Keys.ItalicStyle, value);
171
public bool? Underline {
173
return GetBoolValue (Keys.UnderlineStyle);
176
SetBooleanValue (Keys.UnderlineStyle, value);
180
public string FontFamilyName {
182
return GetStringValue (Keys.FontFamilyName);
185
SetStringValue (Keys.FontFamilyName, value);
189
public int? RelativeFontSize {
191
return GetInt32Value (Keys.RelativeFontSize);
195
throw new ArgumentOutOfRangeException ("value");
197
SetNumberValue (Keys.RelativeFontSize, value);