2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 using System.ComponentModel;
18 using System.Collections.Generic;
19 using Tizen.NUI.BaseComponents;
25 /// FontClient provides access to font information and resources.
27 /// <since_tizen> 5 </since_tizen>
28 public class FontClient : BaseHandle
30 private static readonly FontClient instance = FontClient.Get();
32 internal FontClient(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
36 internal FontClient() : this(Interop.FontClient.NewFontClient(), true)
38 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41 internal FontClient(FontClient handle) : this(Interop.FontClient.NewFontClient(FontClient.getCPtr(handle)), true)
43 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
46 internal static uint DefaultPointSize
50 uint ret = Interop.FontClient.DefaultPointSizeGet();
51 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
57 /// Gets the singleton pattern of the FontClient object.
59 /// <since_tizen> 5 </since_tizen>
60 public static FontClient Instance
69 /// This is used to pre-cache fonts in order to improve the runtime performance of the application.
71 /// <param name="fallbackFamilyList">A list of fallback font families to be pre-cached.</param>
72 /// <param name="extraFamilyList">A list of additional font families to be pre-cached.</param>
73 /// <param name="localeFamily">A locale font family to be pre-cached.</param>
74 /// <param name="useThread">True if the font client should create thread and perform pre-caching, false otherwise.</param>
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 public static void PreCache(List<string> fallbackFamilyList, List<string> extraFamilyList, string localeFamily, bool useThread)
78 int fallbackFamilySize = fallbackFamilyList?.Count ?? 0;
79 int extraFamilySize = extraFamilyList?.Count ?? 0;
80 string[] fallbackFamilyArray = fallbackFamilySize > 0 ? fallbackFamilyList.ToArray() : null;
81 string[] extraFamilyArray = extraFamilySize > 0 ? extraFamilyList.ToArray() : null;
83 Interop.FontClient.PreCache(fallbackFamilyArray, fallbackFamilySize, extraFamilyArray, extraFamilySize, localeFamily, useThread);
84 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 /// Called when the user changes the system defaults.
90 /// <since_tizen> 5 </since_tizen>
91 public void ResetSystemDefaults()
93 Interop.FontClient.ResetSystemDefaults(SwigCPtr);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98 /// Retrieves the font point size of a given font id.
100 /// <param name="id">The font identifier.</param>
101 /// <returns>The point size in 26.6 fractional points.</returns>
102 /// <since_tizen> 5 </since_tizen>
103 public uint GetPointSize(uint id)
105 uint ret = Interop.FontClient.GetPointSize(SwigCPtr, id);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 /// Whether the given character is supported by the font.
113 /// <param name="fontId">The id of the font.</param>
114 /// <param name="character">The character in a font.</param>
115 /// <returns>True if the character is supported by the font.</returns>
116 /// <since_tizen> 5 </since_tizen>
117 public bool IsCharacterSupportedByFont(uint fontId, uint character)
119 bool ret = Interop.FontClient.IsCharacterSupportedByFont(SwigCPtr, fontId, character);
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125 /// Finds the default font for displaying a UTF-32 character.
127 /// <param name="charcode">The character for which a font is needed.</param>
128 /// <param name="requestedPointSize">The point size in 26.6 fractional points. The default point size is 12*64.</param>
129 /// <param name="preferColor">True if a color font is preferred.</param>
130 /// <returns>A valid font identifier. Zero if the font does not exist.</returns>
131 /// <since_tizen> 5 </since_tizen>
132 public uint FindDefaultFont(uint charcode, uint requestedPointSize, bool preferColor)
134 uint ret = Interop.FontClient.FindDefaultFont(SwigCPtr, charcode, requestedPointSize, preferColor);
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// Find the default font for displaying a UTF-32 character.
142 /// <param name="charcode">The character for which a font is needed.</param>
143 /// <param name="requestedPointSize">The point size in 26.6 fractional points. The default point size is 12*64.</param>
144 /// <returns>A valid font identifier. Zero if the font does not exist.</returns>
145 /// <since_tizen> 5 </since_tizen>
146 public uint FindDefaultFont(uint charcode, uint requestedPointSize)
148 uint ret = Interop.FontClient.FindDefaultFont(SwigCPtr, charcode, requestedPointSize);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 /// Find the default font for displaying a UTF-32 character.
156 /// <param name="charcode">The character for which a font is needed.</param>
157 /// <returns>A valid font identifier. Zero if the font does not exist.</returns>
158 /// <since_tizen> 5 </since_tizen>
159 public uint FindDefaultFont(uint charcode)
161 uint ret = Interop.FontClient.FindDefaultFont(SwigCPtr, charcode);
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167 /// Retrieve the unique identifier for a font.
169 /// <param name="path">The path to a font file.</param>
170 /// <param name="requestedPointSize">The point size in 26.6 fractional points. The default point size is 12*64.</param>
171 /// <param name="faceIndex">The index of the font face.</param>
172 /// <returns>A valid font identifier. Zero if the font does not exist.</returns>
173 /// <since_tizen> 5 </since_tizen>
174 public uint GetFontId(string path, uint requestedPointSize, uint faceIndex)
176 uint ret = Interop.FontClient.GetFontId(SwigCPtr, path, requestedPointSize, faceIndex);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182 /// Retrieve the unique identifier for a font.
184 /// <param name="path">The path to a font file.</param>
185 /// <param name="requestedPointSize">The point size in 26.6 fractional points. The default point size is 12*64.</param>
186 /// <returns>A valid font identifier. Zero if the font does not exist.</returns>
187 /// <since_tizen> 5 </since_tizen>
188 public uint GetFontId(string path, uint requestedPointSize)
190 uint ret = Interop.FontClient.GetFontId(SwigCPtr, path, requestedPointSize);
191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 /// Retrieve the unique identifier for a font.
198 /// <param name="path">The path to a font file.</param>
199 /// <returns>A valid font identifier. Zero if the font does not exist.</returns>
200 /// <since_tizen> 5 </since_tizen>
201 public uint GetFontId(string path)
203 uint ret = Interop.FontClient.GetFontId(SwigCPtr, path);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 /// Check to see if a font is scalable.
211 /// <param name="path">The path where the font file is located.</param>
212 /// <returns>True if scalable.</returns>
213 /// <since_tizen> 5 </since_tizen>
214 public bool IsScalable(string path)
216 bool ret = Interop.FontClient.IsScalable(SwigCPtr, path);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222 /// Adds custom fonts directory.
224 /// <param name="path">Path to the fonts directory.</param>
225 /// <returns>True if the fonts can be added.</returns>
226 /// <since_tizen> 5 </since_tizen>
227 public bool AddCustomFontDirectory(string path)
229 bool ret = Interop.FontClient.AddCustomFontDirectory(SwigCPtr, path);
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 /// Retrieve the list of font info supported by the system.
237 /// <returns>The list of FontInfo</returns>
239 /// <see cref="Tizen.NUI.Text.FontInfo"/>
242 /// The following example demonstrates how to use the GetSystemFonts method.
244 /// var fontList = FontClient.Instance.GetSystemFonts();
245 /// foreach(Tizen.NUI.Text.FontInfo fontInfo in fontList)
247 /// string fontFamily = fontInfo.Family;
248 /// string fontPath = fontInfo.Path;
249 /// FontWidthType fontWidth = fontInfo.Style.Width;
250 /// FontWeightType fontWeight = fontInfo.Style.Weight;
251 /// FontSlantType fontSlant = fontInfo.Style.Slant;
255 [EditorBrowsable(EditorBrowsableState.Never)]
256 public List<FontInfo> GetSystemFonts()
258 using PropertyArray fontArray = new PropertyArray(Interop.FontClient.GetSystemFonts(SwigCPtr), true);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 List<FontInfo> fontInfoList;
262 fontInfoList = TextUtils.GetFontInfoList(fontArray);
266 internal static FontClient Get()
268 FontClient ret = new FontClient(Interop.FontClient.Get(), true);
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 internal FontClient Assign(FontClient handle)
275 FontClient ret = new FontClient(Interop.FontClient.Assign(SwigCPtr, FontClient.getCPtr(handle)), false);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 internal void SetDpi(uint horizontalDpi, uint verticalDpi)
282 Interop.FontClient.SetDpi(SwigCPtr, horizontalDpi, verticalDpi);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 internal void GetDpi(SWIGTYPE_p_unsigned_int horizontalDpi, SWIGTYPE_p_unsigned_int verticalDpi)
288 Interop.FontClient.GetDpi(SwigCPtr, SWIGTYPE_p_unsigned_int.getCPtr(horizontalDpi), SWIGTYPE_p_unsigned_int.getCPtr(verticalDpi));
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 internal int GetDefaultFontSize()
294 int ret = Interop.FontClient.GetDefaultFontSize(SwigCPtr);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 internal void GetDefaultFonts(SWIGTYPE_p_std__vectorT_Dali__TextAbstraction__FontDescription_t defaultFonts)
301 Interop.FontClient.GetDefaultFonts(SwigCPtr, SWIGTYPE_p_std__vectorT_Dali__TextAbstraction__FontDescription_t.getCPtr(defaultFonts));
302 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 internal void GetDefaultPlatformFontDescription(FontDescription fontDescription)
307 Interop.FontClient.GetDefaultPlatformFontDescription(SwigCPtr, FontDescription.getCPtr(fontDescription));
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 internal void GetDescription(uint id, FontDescription fontDescription)
313 Interop.FontClient.GetDescription(SwigCPtr, id, FontDescription.getCPtr(fontDescription));
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal uint FindFallbackFont(uint charcode, FontDescription preferredFontDescription, uint requestedPointSize, bool preferColor)
319 uint ret = Interop.FontClient.FindFallbackFont(SwigCPtr, charcode, FontDescription.getCPtr(preferredFontDescription), requestedPointSize, preferColor);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 internal uint FindFallbackFont(uint charcode, FontDescription preferredFontDescription, uint requestedPointSize)
326 uint ret = Interop.FontClient.FindFallbackFont(SwigCPtr, charcode, FontDescription.getCPtr(preferredFontDescription), requestedPointSize);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 internal uint FindFallbackFont(uint charcode, FontDescription preferredFontDescription)
333 uint ret = Interop.FontClient.FindFallbackFont(SwigCPtr, charcode, FontDescription.getCPtr(preferredFontDescription));
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 internal uint GetFontId(FontDescription preferredFontDescription, uint requestedPointSize, uint faceIndex)
340 uint ret = Interop.FontClient.GetFontId(SwigCPtr, FontDescription.getCPtr(preferredFontDescription), requestedPointSize, faceIndex);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 internal uint GetFontId(FontDescription preferredFontDescription, uint requestedPointSize)
347 uint ret = Interop.FontClient.GetFontId(SwigCPtr, FontDescription.getCPtr(preferredFontDescription), requestedPointSize);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 internal uint GetFontId(FontDescription preferredFontDescription)
354 uint ret = Interop.FontClient.GetFontId(SwigCPtr, FontDescription.getCPtr(preferredFontDescription));
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359 internal bool IsScalable(FontDescription fontDescription)
361 bool ret = Interop.FontClient.IsScalable(SwigCPtr, FontDescription.getCPtr(fontDescription));
362 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366 internal void GetFixedSizes(string path, SWIGTYPE_p_Dali__VectorT_uint32_t_TypeTraitsT_uint32_t_t__IS_TRIVIAL_TYPE__true_t sizes)
368 Interop.FontClient.GetFixedSizes(SwigCPtr, path, SWIGTYPE_p_Dali__VectorT_uint32_t_TypeTraitsT_uint32_t_t__IS_TRIVIAL_TYPE__true_t.getCPtr(sizes));
369 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372 internal void GetFixedSizes(FontDescription fontDescription, SWIGTYPE_p_Dali__VectorT_uint32_t_TypeTraitsT_uint32_t_t__IS_TRIVIAL_TYPE__true_t sizes)
374 Interop.FontClient.GetFixedSizes(SwigCPtr, FontDescription.getCPtr(fontDescription), SWIGTYPE_p_Dali__VectorT_uint32_t_TypeTraitsT_uint32_t_t__IS_TRIVIAL_TYPE__true_t.getCPtr(sizes));
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 internal void GetFontMetrics(uint fontId, FontMetrics metrics)
380 Interop.FontClient.GetFontMetrics(SwigCPtr, fontId, FontMetrics.getCPtr(metrics));
381 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 internal uint GetGlyphIndex(uint fontId, uint charcode)
386 uint ret = Interop.FontClient.GetGlyphIndex(SwigCPtr, fontId, charcode);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 internal bool GetGlyphMetrics(GlyphInfo array, uint size, GlyphType type, bool horizontal)
393 bool ret = Interop.FontClient.GetGlyphMetrics(SwigCPtr, GlyphInfo.getCPtr(array), size, (int)type, horizontal);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398 internal bool GetGlyphMetrics(GlyphInfo array, uint size, GlyphType type)
400 bool ret = Interop.FontClient.GetGlyphMetrics(SwigCPtr, GlyphInfo.getCPtr(array), size, (int)type);
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 internal void CreateBitmap(uint fontId, uint glyphIndex, bool softwareItalic, bool softwareBold, FontClient.GlyphBufferData data, int outlineWidth)
407 Interop.FontClient.CreateBitmap(SwigCPtr, fontId, glyphIndex, softwareItalic, softwareBold, FontClient.GlyphBufferData.getCPtr(data), outlineWidth);
408 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411 internal PixelData CreateBitmap(uint fontId, uint glyphIndex, int outlineWidth)
413 PixelData ret = new PixelData(Interop.FontClient.CreateBitmap(SwigCPtr, fontId, glyphIndex, outlineWidth), true);
414 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 internal void CreateVectorBlob(uint fontId, uint glyphIndex, SWIGTYPE_p_p_Dali__TextAbstraction__VectorBlob blob, SWIGTYPE_p_unsigned_int blobLength, SWIGTYPE_p_unsigned_int nominalWidth, SWIGTYPE_p_unsigned_int nominalHeight)
420 Interop.FontClient.CreateVectorBlob(SwigCPtr, fontId, glyphIndex, SWIGTYPE_p_p_Dali__TextAbstraction__VectorBlob.getCPtr(blob), SWIGTYPE_p_unsigned_int.getCPtr(blobLength), SWIGTYPE_p_unsigned_int.getCPtr(nominalWidth), SWIGTYPE_p_unsigned_int.getCPtr(nominalHeight));
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424 internal GlyphInfo GetEllipsisGlyph(uint requestedPointSize)
426 GlyphInfo ret = new GlyphInfo(Interop.FontClient.GetEllipsisGlyph(SwigCPtr, requestedPointSize), false);
427 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431 internal bool IsColorGlyph(uint fontId, uint glyphIndex)
433 bool ret = Interop.FontClient.IsColorGlyph(SwigCPtr, fontId, glyphIndex);
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 internal class GlyphBufferData : Disposable
440 public GlyphBufferData() : this(Interop.FontClient.NewFontClientGlyphBufferData(), true)
442 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445 internal GlyphBufferData(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
449 /*public byte[] Buffer
453 Interop.FontClient.GlyphBufferDataBufferSet(swigCPtr, value);
454 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
458 global::System.IntPtr cPtr = Interop.FontClient.GlyphBufferDataBufferGet(swigCPtr);
459 SWIGTYPE_p_unsigned_char ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_unsigned_char(cPtr, false);
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 Interop.FontClient.GlyphBufferDataWidthSet(SwigCPtr, value);
470 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
474 uint ret = Interop.FontClient.GlyphBufferDataWidthGet(SwigCPtr);
475 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
484 Interop.FontClient.GlyphBufferDataHeightSet(SwigCPtr, value);
485 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489 uint ret = Interop.FontClient.GlyphBufferDataHeightGet(SwigCPtr);
490 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
495 public PixelFormat Format
499 Interop.FontClient.GlyphBufferDataFormatSet(SwigCPtr, (int)value);
500 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 PixelFormat ret = (PixelFormat)Interop.FontClient.GlyphBufferDataFormatGet(SwigCPtr);
505 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
510 /// This will not be public opened.
511 [EditorBrowsable(EditorBrowsableState.Never)]
512 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
514 Interop.FontClient.DeleteFontClientGlyphBufferData(swigCPtr);