1 module skia.SKFontStyleSet;
2 
3 import skia.SKObject;
4 import skia.SKTypeface;
5 import skia.SKFontStyle;
6 import skia.Definitions;
7 import skia.SkiaApi;
8 import skia.SKString;
9 import skia.Exceptions;
10 
11 // class SKFontStyleSet : SKObject, IEnumerable<SKFontStyle>, IReadOnlyCollection<SKFontStyle>, IReadOnlyList<SKFontStyle>
12 
13 class SKFontStyleSet : SKObject
14 {
15 	this(void* handle, bool owns)
16 	{
17     super (handle, owns);
18 	}
19 
20 	this ()
21 	{
22     this (SkiaApi.sk_fontstyleset_create_empty (), true);
23 	}
24 
25 	protected override void Dispose (bool disposing) 
26   {
27     return 	super.Dispose (disposing);
28   }
29 	
30 
31 	int Count()
32   {
33     return SkiaApi.sk_fontstyleset_get_count (cast(sk_fontstyleset_t*)Handle);
34   } 
35 
36 	// SKFontStyle this[int index]()
37   // {
38   //   return GetStyle (index);
39   // } 
40 
41 	string GetStyleName (int index)
42 	{
43 		SKString str = new SKString ();
44 		
45 		
46     	SkiaApi.sk_fontstyleset_get_style (cast(sk_fontstyleset_t*)Handle, index, null, cast(sk_string_t*)str.Handle);
47 			// GC.KeepAlive(this);
48 			return cast(string)str;
49 	}
50 
51 	SKTypeface CreateTypeface (int index)
52 	{
53 		if (index < 0 || index >= Count)
54 			throw new ArgumentOutOfRangeException ("Index was out of range. Must be non-negative and less than the size of the set.", index.stringof);
55 
56 		auto tf = SKTypeface.GetObject (SkiaApi.sk_fontstyleset_create_typeface (cast(sk_fontstyleset_t*)Handle, index));
57 		tf.PreventPublicDisposal ();
58 		// GC.KeepAlive(this);
59 		return tf;
60 	}
61 
62 	SKTypeface CreateTypeface (SKFontStyle style)
63 	{
64 		if (style is null)
65 			throw new ArgumentNullException (style.stringof);
66 
67 		auto tf = SKTypeface.GetObject (SkiaApi.sk_fontstyleset_match_style (cast(sk_fontstyleset_t*)Handle, cast(sk_fontstyle_t*)style.Handle));
68 		tf.PreventPublicDisposal ();
69 		// GC.KeepAlive(this);
70 		return tf;
71 	}
72 
73 	// IEnumerator<SKFontStyle> GetEnumerator ()
74   // {
75   //   return GetStyles ().GetEnumerator ();
76   // } 
77 
78 	// IEnumerator IEnumerable.GetEnumerator ()
79   // {
80   //   return GetStyles ().GetEnumerator ();
81   // }
82 
83 	// private IEnumerable<SKFontStyle> GetStyles ()
84 	// {
85 	// 	auto count = Count;
86 	// 	for (var i = 0; i < count; i++) {
87 	// 		yield return GetStyle (i);
88 	// 	}
89 	// }
90 
91 	private SKFontStyle GetStyle (int index)
92 	{
93 		auto fontStyle = new SKFontStyle ();
94 		SkiaApi.sk_fontstyleset_get_style (cast(sk_fontstyleset_t*)Handle, index, cast(sk_fontstyle_t*)fontStyle.Handle, null);
95 		return fontStyle;
96 	}
97 
98 	static SKFontStyleSet GetObject (void* handle)
99   {
100     return GetOrAddObject!(SKFontStyleSet)(handle, delegate SKFontStyleSet (h, o) { return new SKFontStyleSet (h, o);});
101   }
102 }
103