[NUI] Fix Svace issue (#949)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / FontDescription.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 namespace Tizen.NUI
18 {
19
20     internal class FontDescription : global::System.IDisposable
21     {
22         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
23         protected bool swigCMemOwn;
24
25         internal FontDescription(global::System.IntPtr cPtr, bool cMemoryOwn)
26         {
27             swigCMemOwn = cMemoryOwn;
28             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
29         }
30
31         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FontDescription obj)
32         {
33             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
34         }
35
36         //A Flag to check who called Dispose(). (By User or DisposeQueue)
37         private bool isDisposeQueued = false;
38         /// <summary>
39         /// A Flat to check if it is already disposed.
40         /// </summary>
41         protected bool disposed = false;
42
43         ~FontDescription()
44         {
45             if (!isDisposeQueued)
46             {
47                 isDisposeQueued = true;
48                 DisposeQueue.Instance.Add(this);
49             }
50         }
51
52         public void Dispose()
53         {
54             //Throw excpetion if Dispose() is called in separate thread.
55             if (!Window.IsInstalled())
56             {
57                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
58             }
59
60             if (isDisposeQueued)
61             {
62                 Dispose(DisposeTypes.Implicit);
63             }
64             else
65             {
66                 Dispose(DisposeTypes.Explicit);
67                 System.GC.SuppressFinalize(this);
68             }
69         }
70
71         protected virtual void Dispose(DisposeTypes type)
72         {
73             if (disposed)
74             {
75                 return;
76             }
77
78             if (type == DisposeTypes.Explicit)
79             {
80                 //Called by User
81                 //Release your own managed resources here.
82                 //You should release all of your own disposable objects here.
83             }
84
85             //Release your own unmanaged resources here.
86             //You should not access any managed member here except static instance.
87             //because the execution order of Finalizes is non-deterministic.
88
89             if (swigCPtr.Handle != global::System.IntPtr.Zero)
90             {
91                 if (swigCMemOwn)
92                 {
93                     swigCMemOwn = false;
94                     Interop.FontClient.delete_FontDescription(swigCPtr);
95                 }
96                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
97             }
98             disposed = true;
99         }
100
101         public FontDescription() : this(Interop.FontClient.new_FontDescription(), true)
102         {
103             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104         }
105
106         public string Path
107         {
108             set
109             {
110                 Interop.FontClient.FontDescription_path_set(swigCPtr, value);
111                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112             }
113             get
114             {
115                 string ret = Interop.FontClient.FontDescription_path_get(swigCPtr);
116                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117                 return ret;
118             }
119         }
120
121         public string Family
122         {
123             set
124             {
125                 Interop.FontClient.FontDescription_family_set(swigCPtr, value);
126                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127             }
128             get
129             {
130                 string ret = Interop.FontClient.FontDescription_family_get(swigCPtr);
131                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132                 return ret;
133             }
134         }
135
136         public FontWidthType Width
137         {
138             set
139             {
140                 Interop.FontClient.FontDescription_width_set(swigCPtr, (int)value);
141                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142             }
143             get
144             {
145                 FontWidthType ret = (FontWidthType)Interop.FontClient.FontDescription_width_get(swigCPtr);
146                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147                 return ret;
148             }
149         }
150
151         public FontWeightType Weight
152         {
153             set
154             {
155                 Interop.FontClient.FontDescription_weight_set(swigCPtr, (int)value);
156                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157             }
158             get
159             {
160                 FontWeightType ret = (FontWeightType)Interop.FontClient.FontDescription_weight_get(swigCPtr);
161                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162                 return ret;
163             }
164         }
165
166         public FontSlantType Slant
167         {
168             set
169             {
170                 Interop.FontClient.FontDescription_slant_set(swigCPtr, (int)value);
171                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172             }
173             get
174             {
175                 FontSlantType ret = (FontSlantType)Interop.FontClient.FontDescription_slant_get(swigCPtr);
176                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177                 return ret;
178             }
179         }
180
181     }
182
183 }