55
66namespace HarfBuzzSharp
77{
8+ /// <summary>
9+ /// Represents a blob of data in memory.
10+ /// </summary>
11+ /// <remarks>
12+ /// </remarks>
813 public unsafe class Blob : NativeObject
914 {
1015 private static readonly Lazy < Blob > emptyBlob = new Lazy < Blob > ( ( ) => new StaticBlob ( HarfBuzzApi . hb_blob_get_empty ( ) ) ) ;
1116
17+ /// <summary>
18+ /// Gets a reference to the empty <see cref="T:HarfBuzzSharp.Blob" /> instance.
19+ /// </summary>
20+ /// <value></value>
21+ /// <remarks>
22+ /// </remarks>
1223 public static Blob Empty => emptyBlob . Value ;
1324
1425 internal Blob ( IntPtr handle )
1526 : base ( handle )
1627 {
1728 }
1829
30+ /// <param name="data">The data to wrap.</param>
31+ /// <param name="length">The length of the data being wrapped.</param>
32+ /// <param name="mode">The memory mode to use.</param>
33+ /// <summary>Creates a new <see cref="T:HarfBuzzSharp.Blob" /> instance, wrapping the specified data.</summary>
34+ /// <remarks>If there was a problem creating the blob, or if the data length was zero, then an empty blob will be created.</remarks>
1935 public Blob ( IntPtr data , int length , MemoryMode mode )
2036 : this ( data , length , mode , null )
2137 {
2238 }
2339
40+ /// <param name="data">The data to wrap.</param>
41+ /// <param name="length">The length of the data being wrapped.</param>
42+ /// <param name="mode">The memory mode to use.</param>
43+ /// <param name="releaseDelegate">The delegate to invoke when the data is not needed anymore.</param>
44+ /// <summary>Creates a new <see cref="T:HarfBuzzSharp.Blob" /> instance, wrapping the specified data.</summary>
45+ /// <remarks>If there was a problem creating the blob, or if the data length was zero, then an empty blob will be created.</remarks>
2446 public Blob ( IntPtr data , int length , MemoryMode mode , ReleaseDelegate releaseDelegate )
2547 : this ( Create ( data , length , mode , releaseDelegate ) )
2648 {
2749 }
2850
51+ /// <param name="disposing">
52+ /// <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
53+ /// <summary>Releases the unmanaged resources used by the <see cref="T:HarfBuzzSharp.Blob" /> and optionally releases the managed resources.</summary>
54+ /// <remarks>Always dispose the object before you release your last reference to the <see cref="T:HarfBuzzSharp.Blob" />. Otherwise, the resources it is using will not be freed until the garbage collector calls the finalizer.</remarks>
2955 protected override void Dispose ( bool disposing ) =>
3056 base . Dispose ( disposing ) ;
3157
58+ /// <summary>Releases the unmanaged resources used.</summary>
59+ /// <remarks>
60+ /// </remarks>
3261 protected override void DisposeHandler ( )
3362 {
3463 if ( Handle != IntPtr . Zero ) {
3564 HarfBuzzApi . hb_blob_destroy ( Handle ) ;
3665 }
3766 }
3867
68+ /// <summary>
69+ /// Gets the length of blob data in bytes.
70+ /// </summary>
71+ /// <value></value>
72+ /// <remarks>
73+ /// </remarks>
3974 public int Length => ( int ) HarfBuzzApi . hb_blob_get_length ( Handle ) ;
4075
76+ /// <summary>
77+ /// Gets the number of faces in this blob.
78+ /// </summary>
79+ /// <value></value>
80+ /// <remarks>
81+ /// </remarks>
4182 public int FaceCount => ( int ) HarfBuzzApi . hb_face_count ( Handle ) ;
4283
84+ /// <summary>
85+ /// Gets the value indicating whether the blob is immutable.
86+ /// </summary>
87+ /// <value></value>
88+ /// <remarks>
89+ /// </remarks>
4390 public bool IsImmutable => HarfBuzzApi . hb_blob_is_immutable ( Handle ) ;
4491
92+ /// <summary>Makes the blob immutable.</summary>
93+ /// <remarks>
94+ /// </remarks>
4595 public void MakeImmutable ( ) => HarfBuzzApi . hb_blob_make_immutable ( Handle ) ;
4696
97+ /// <summary>Returns a stream that wraps the data.</summary>
98+ /// <returns>Returns the stream that wraps the data.</returns>
99+ /// <remarks>If the data is released, then the stream becomes invalid.</remarks>
47100 public unsafe Stream AsStream ( )
48101 {
49102 uint length ;
50103 var dataPtr = HarfBuzzApi . hb_blob_get_data ( Handle , & length ) ;
51104 return new UnmanagedMemoryStream ( ( byte * ) dataPtr , length ) ;
52105 }
53106
107+ /// <summary>Returns a span that wraps the data.</summary>
108+ /// <returns>Returns the span that wraps the data.</returns>
109+ /// <remarks>If the data is released, then the span becomes invalid.</remarks>
54110 public unsafe Span < byte > AsSpan ( )
55111 {
56112 uint length ;
57113 var dataPtr = HarfBuzzApi . hb_blob_get_data ( Handle , & length ) ;
58114 return new Span < byte > ( dataPtr , ( int ) length ) ;
59115 }
60116
117+ /// <param name="fileName">The path to the file to load.</param>
118+ /// <summary>Creates a new <see cref="T:HarfBuzzSharp.Blob" /> instance from the contents of the file.</summary>
119+ /// <returns>Returns the new <see cref="T:HarfBuzzSharp.Blob" /> instance.</returns>
120+ /// <remarks>
121+ /// </remarks>
61122 public static Blob FromFile ( string fileName )
62123 {
63124 if ( ! File . Exists ( fileName ) ) {
@@ -68,6 +129,11 @@ public static Blob FromFile (string fileName)
68129 return new Blob ( blob ) ;
69130 }
70131
132+ /// <param name="stream">The stream to use.</param>
133+ /// <summary>Creates a new <see cref="T:HarfBuzzSharp.Blob" /> instance from the contents of the stream.</summary>
134+ /// <returns>Returns the new <see cref="T:HarfBuzzSharp.Blob" /> instance.</returns>
135+ /// <remarks>
136+ /// </remarks>
71137 public static unsafe Blob FromStream ( Stream stream )
72138 {
73139 // TODO: check to see if we can avoid the second copy (the ToArray)
0 commit comments