| 1 |
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later |
| 2 |
// Copyright (C) 2012 SIL International |
| 3 |
System; |
| 4 |
using System.Runtime.InteropServices; |
| 5 |
|
| 6 |
namespace NGraphite |
| 7 |
{ |
| 8 |
public class Font : IDisposable |
| 9 |
{ |
| 10 |
IntPtr _font; |
| 11 |
Face _face; |
| 12 |
|
| 13 |
internal IntPtr FontPtr |
| 14 |
{ |
| 15 |
get { return _font; } |
| 16 |
} |
| 17 |
|
| 18 |
public Font(float ppm, Face face) |
| 19 |
{ |
| 20 |
_face = face; |
| 21 |
_font = Graphite2Api.MakeFont(ppm, _face.FacePtr); |
| 22 |
} |
| 23 |
|
| 24 |
public Segment MakeSeg(UInt32 script, Featureval feats, string str, Bidirtl dir) |
| 25 |
{ |
| 26 |
IntPtr strPtr = Marshal.StringToCoTaskMemUni(str); |
| 27 |
IntPtr error = new IntPtr(0); |
| 28 |
int numCodePoints = Graphite2Api.CountUnicodeCharacters(Encform.Utf16, strPtr, IntPtr.Zero, ref error); |
| 29 |
IntPtr segmentPtr = Graphite2Api.MakeSeg(_font, _face.FacePtr, script, feats.FeatureValPtr, Encform.Utf16, strPtr, numCodePoints, dir); |
| 30 |
Marshal.FreeCoTaskMem(strPtr); |
| 31 |
return new Segment(segmentPtr); |
| 32 |
} |
| 33 |
|
| 34 |
#region IDisposable implementation |
| 35 |
public void Dispose() |
| 36 |
{ |
| 37 |
Graphite2Api.FontDestroy(_font); |
| 38 |
} |
| 39 |
#endregion |
| 40 |
} |
| 41 |
} |
| 42 |
|