1
1
using System ;
2
2
using System . Drawing ;
3
+ using System . Drawing . Imaging ;
3
4
using System . Drawing . Text ;
4
5
using OpenBveApi . Math ;
5
6
using OpenBveApi . Textures ;
@@ -19,7 +20,7 @@ public class OpenGlFontTable : IDisposable
19
20
20
21
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
21
22
// Must remain, else will be disposed of by the GC as this is a separate assembly
22
- private readonly Bitmap bitmap ;
23
+ private readonly byte [ ] myBytes ;
23
24
/// <summary>The border around glpyhs on the font bitmap</summary>
24
25
const int drawBorder = 20 ;
25
26
/// <summary>The border used when calculating texture co-ordinates</summary>
@@ -36,7 +37,7 @@ public OpenGlFontTable(Font font, int offset)
36
37
* */
37
38
Vector2 [ ] physicalSizes = new Vector2 [ 256 ] ;
38
39
Vector2 [ ] typographicSizes = new Vector2 [ 256 ] ;
39
- bitmap = new Bitmap ( 1 , 1 , PixelFormat . Format32bppArgb ) ;
40
+ Bitmap bitmap = new Bitmap ( 1 , 1 , PixelFormat . Format32bppArgb ) ;
40
41
Graphics graphics = Graphics . FromImage ( bitmap ) ;
41
42
graphics . TextRenderingHint = TextRenderingHint . ClearTypeGridFit ;
42
43
double lineHeight = 0 ;
@@ -120,7 +121,18 @@ public OpenGlFontTable(Font font, int offset)
120
121
Characters [ i ] = new OpenGlFontChar ( new Vector4 ( x0 , y0 , x1 - x0 , y1 - y0 ) , new Vector2 ( physicalSizes [ i ] . X + 2.0 * coordinateBorder , physicalSizes [ i ] . Y + 2.0 * coordinateBorder ) , typographicSizes [ i ] ) ;
121
122
}
122
123
graphics . Dispose ( ) ;
123
- Texture = new Texture ( bitmap ) ;
124
+ BitmapData data = bitmap . LockBits ( new Rectangle ( 0 , 0 , bitmap . Width , bitmap . Height ) , ImageLockMode . ReadOnly , bitmap . PixelFormat ) ;
125
+ if ( data . Stride == 4 * data . Width ) {
126
+ /*
127
+ * Copy the data from the bitmap
128
+ * to the array in BGRA format.
129
+ */
130
+ myBytes = new byte [ data . Stride * data . Height ] ;
131
+ System . Runtime . InteropServices . Marshal . Copy ( data . Scan0 , myBytes , 0 , data . Stride * data . Height ) ;
132
+ bitmap . UnlockBits ( data ) ;
133
+ }
134
+ Texture = new Texture ( bitmap . Width , bitmap . Height , OpenBveApi . Textures . PixelFormat . RGBAlpha , myBytes , null ) ;
135
+ bitmap . Dispose ( ) ;
124
136
}
125
137
126
138
/// <summary>Rounds the specified value to the next-highest power of two.</summary>
@@ -145,16 +157,7 @@ private static uint RoundToPowerOfTwo(uint value)
145
157
146
158
public void Dispose ( )
147
159
{
148
- Dispose ( true ) ;
149
160
GC . SuppressFinalize ( this ) ;
150
161
}
151
-
152
- private void Dispose ( bool currentlyDisposing )
153
- {
154
- if ( currentlyDisposing )
155
- {
156
- bitmap . Dispose ( ) ;
157
- }
158
- }
159
162
}
160
163
}
0 commit comments