Commit 59259511f2e23a0678ea48eb6b8bea65f5a17f2f

henry 2002-12-16T08:27:39

Refactored FTFont to get rid of Open function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
diff --git a/HISTORY.txt b/HISTORY.txt
index a5631f4..6014f5a 100644
--- a/HISTORY.txt
+++ b/HISTORY.txt
@@ -9,8 +9,8 @@ FTGL 2.0 (FTGL_2_0_0)
     - Rewriting FTGLDemo.
     - Minor fixes for irix.
     - Removed a bunch of redundant members and made them function locals.
-    - Removed Close() from FTFont because there was no way to handle it
-      correctly.
+    - Removed the Open() & Close() functions from FTFont because there was
+      no way to handle Close correctly and Open is redundant.
     - Improved the robustness of some of the error handling.
     - Removed the FTCharmap Platform/Encoding function.
     - Unit tests.
diff --git a/demo/FTGLDemo.cpp b/demo/FTGLDemo.cpp
index 5f8c5ca..dcec0db 100644
--- a/demo/FTGLDemo.cpp
+++ b/demo/FTGLDemo.cpp
@@ -100,16 +100,16 @@ void setUpLighting()
 
 void setUpFonts( const char* fontfile)
 {
-	fonts[FTGL_BITMAP] = new FTGLBitmapFont;
-	fonts[FTGL_PIXMAP] = new FTGLPixmapFont;
-	fonts[FTGL_OUTLINE] = new FTGLOutlineFont;
-	fonts[FTGL_POLYGON] = new FTGLPolygonFont;
-	fonts[FTGL_EXTRUDE] = new FTGLExtrdFont;
-	fonts[FTGL_TEXTURE] = new FTGLTextureFont;
+	fonts[FTGL_BITMAP] = new FTGLBitmapFont( fontfile);
+	fonts[FTGL_PIXMAP] = new FTGLPixmapFont( fontfile);
+	fonts[FTGL_OUTLINE] = new FTGLOutlineFont( fontfile);
+	fonts[FTGL_POLYGON] = new FTGLPolygonFont( fontfile);
+	fonts[FTGL_EXTRUDE] = new FTGLExtrdFont( fontfile);
+	fonts[FTGL_TEXTURE] = new FTGLTextureFont( fontfile);
 
 	for( int x = 0; x < 6; ++x)
 	{
-		if( !fonts[x]->Open( fontfile))
+		if( fonts[x]->Error())
 		{
 			fprintf( stderr, "Failed to open font %s", fontfile);
 			exit(1);
@@ -126,9 +126,9 @@ void setUpFonts( const char* fontfile)
 		fonts[x]->CharMap(ft_encoding_unicode);
 	}
 	
-	infoFont = new FTGLPixmapFont;
+	infoFont = new FTGLPixmapFont( fontfile);
 	
-	if( !infoFont->Open( FONT_INFO))
+	if( infoFont->Error())
 	{
 		fprintf( stderr, "Failed to open font %s", FONT_INFO);
 		exit(1);
diff --git a/include/FTFont.h b/include/FTFont.h
index c135ea6..9164430 100755
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -29,23 +29,13 @@ class FTGL_EXPORT FTFont
 {
     public:
         /**
-         * Default Constructor
-         */
-        FTFont();
-        
-        /**
-         * Destructor
-         */
-        virtual ~FTFont();
-        
-        /**
          * Open and read a font file.
          *
          * @param fontname  font file name.
          * @return          <code>true</code> if file has opened
          *                  successfully.
          */
-        bool Open( const char* fontname);
+        FTFont( const char* fontname);
         
         /**
          * Open and read a font from a buffer in memory.
@@ -55,8 +45,13 @@ class FTGL_EXPORT FTFont
          * @return          <code>true</code> if the data stream has
          *                  opened successfully.
          */
-        bool Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
-
+        FTFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
+        
+        /**
+         * Destructor
+         */
+        virtual ~FTFont();
+        
         /**
          * Attach auxilliary file to font e.g font metrics.
          *
diff --git a/include/FTGLBitmapFont.h b/include/FTGLBitmapFont.h
index 05b95b0..c5baeea 100755
--- a/include/FTGLBitmapFont.h
+++ b/include/FTGLBitmapFont.h
@@ -19,7 +19,9 @@ class FTGL_EXPORT FTGLBitmapFont : public FTFont
         /**
          * Constructor
          */
-        FTGLBitmapFont();
+        FTGLBitmapFont( const char* fontname);
+
+        FTGLBitmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
 
         /**
          * Destructor
diff --git a/include/FTGLExtrdFont.h b/include/FTGLExtrdFont.h
index 12bcdb3..c23c2de 100644
--- a/include/FTGLExtrdFont.h
+++ b/include/FTGLExtrdFont.h
@@ -21,7 +21,9 @@ class FTGL_EXPORT FTGLExtrdFont : public FTFont
 		/**
 		 * Default Constructor
 		 */
-		FTGLExtrdFont();
+		FTGLExtrdFont( const char* fontname);
+		
+		FTGLExtrdFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
 		
 		/**
 		 * Destructor
diff --git a/include/FTGLOutlineFont.h b/include/FTGLOutlineFont.h
index 28eeee6..09ffc66 100755
--- a/include/FTGLOutlineFont.h
+++ b/include/FTGLOutlineFont.h
@@ -20,7 +20,9 @@ class FTGL_EXPORT FTGLOutlineFont : public FTFont
         /**
          * Default Constructor
          */
-        FTGLOutlineFont();
+        FTGLOutlineFont( const char* fontname);
+        
+        FTGLOutlineFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
         
         /**
          * Destructor
diff --git a/include/FTGLPixmapFont.h b/include/FTGLPixmapFont.h
index 172430d..f98ec48 100755
--- a/include/FTGLPixmapFont.h
+++ b/include/FTGLPixmapFont.h
@@ -21,7 +21,9 @@ class FTGL_EXPORT FTGLPixmapFont : public FTFont
         /**
          * Default Constructor
          */
-        FTGLPixmapFont();
+        FTGLPixmapFont( const char* fontname);
+        
+        FTGLPixmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
         
         /**
          * Destructor
diff --git a/include/FTGLPolygonFont.h b/include/FTGLPolygonFont.h
index 269b489..8e33f66 100755
--- a/include/FTGLPolygonFont.h
+++ b/include/FTGLPolygonFont.h
@@ -20,7 +20,9 @@ class FTGL_EXPORT FTGLPolygonFont : public FTFont
         /**
          * Default Constructor
          */
-        FTGLPolygonFont();
+        FTGLPolygonFont( const char* fontname);
+        
+        FTGLPolygonFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
         
         /**
          * Destructor
diff --git a/include/FTGLTextureFont.h b/include/FTGLTextureFont.h
index f041b16..f877197 100755
--- a/include/FTGLTextureFont.h
+++ b/include/FTGLTextureFont.h
@@ -17,9 +17,11 @@ class  FTGL_EXPORT FTGLTextureFont : public FTFont
 {
     public:
         /**
-         * Default Constructor
+         * Constructor
          */
-        FTGLTextureFont();
+        FTGLTextureFont( const char* fontname);
+        
+        FTGLTextureFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
         
         /**
          * Destructor
diff --git a/mac/FTGL.pbproj/henry.pbxuser b/mac/FTGL.pbproj/henry.pbxuser
index e3594fd..b809477 100644
--- a/mac/FTGL.pbproj/henry.pbxuser
+++ b/mac/FTGL.pbproj/henry.pbxuser
@@ -2,8 +2,8 @@
 {
 	66BA088A01C46338000ABFD4 = {
 		activeBuildStyle = 66BA088D01C46338000ABFD4;
-		activeExecutable = 66BA08EF01C4657A000ABFD4;
-		activeTarget = 66BA089001C4635F000ABFD4;
+		activeExecutable = F597CC9302C5420F01F03BCF;
+		activeTarget = F597CC8B02C5420F01F03BCF;
 		addToTargets = (
 			66BA089001C4635F000ABFD4,
 		);
@@ -14,7 +14,7 @@
 			F597CC9302C5420F01F03BCF,
 		);
 		perUserDictionary = {
-			PBXPerProjectTemplateStateSaveDate = 61685642;
+			PBXPerProjectTemplateStateSaveDate = 61714274;
 			"PBXTemplateGeometry-F5314676015831810DCA290F" = {
 				ContentSize = "{685, 434}";
 				LeftSlideOut = {
@@ -141,31 +141,33 @@
 				StatusViewVisible = YES;
 				Template = F5314676015831810DCA290F;
 				ToolbarVisible = YES;
-				WindowLocation = "{27, 462}";
+				WindowLocation = "{7, 352}";
 			};
-			"PBXTemplateGeometry-F5CA7ECB015C094F0DCA290F" = {
-				ContentSize = "{668, 621}";
+			"PBXTemplateGeometry-F5534CB2020F3F8A0DCA290F" = {
+				ContentSize = "{594, 303}";
 				LeftSlideOut = {
 					Collapsed = NO;
-					Frame = "{{0, 0}, {668, 621}}";
+					Frame = "{{0, 23}, {594, 280}}";
 					Split0 = {
-						Collapsed = NO;
-						Frame = "{{0, 0}, {668, 621}}";
+						ActiveTab = 1;
+						ActiveTabName = PBXRunSessionModule;
+						Collapsed = YES;
+						Frame = "{{0, 0}, {594, 280}}";
 						Split0 = {
-							Frame = "{{0, 0}, {668, 621}}";
+							Frame = "{{1e+06, 1e+06}, {594, 0}}";
 						};
 						SplitCount = 1;
 						Tab0 = {
-							Frame = "{{0, 0}, {484, 208}}";
+							Frame = "{{0, 0}, {804, 321}}";
 						};
 						Tab1 = {
 							Debugger = {
 								Collapsed = NO;
-								Frame = "{{0, 0}, {664, 208}}";
+								Frame = "{{0, 0}, {594, 274}}";
 								Split0 = {
-									Frame = "{{0, 24}, {664, 184}}";
+									Frame = "{{0, 24}, {594, 250}}";
 									Split0 = {
-										Frame = "{{0, 0}, {325, 184}}";
+										Frame = "{{0, 0}, {290, 250}}";
 									};
 									Split1 = {
 										DebugVariablesTableConfiguration = (
@@ -174,9 +176,9 @@
 											Value,
 											85,
 											Summary,
-											96.123,
+											62.123,
 										);
-										Frame = "{{334, 0}, {330, 184}}";
+										Frame = "{{299, 0}, {295, 250}}";
 									};
 									SplitCount = 2;
 								};
@@ -190,14 +192,14 @@
 								TabCount = 2;
 								TabsVisible = YES;
 							};
-							Frame = "{{0, 0}, {664, 208}}";
+							Frame = "{{0, 0}, {594, 274}}";
 							LauncherConfigVersion = 7;
 						};
 						Tab2 = {
-							Frame = "{{0, 0}, {664, 50}}";
+							Frame = "{{0, 0}, {594, 274}}";
 							LauncherConfigVersion = 3;
 							Runner = {
-								Frame = "{{0, 0}, {664, 50}}";
+								Frame = "{{0, 0}, {594, 274}}";
 							};
 						};
 						Tab3 = {
@@ -214,12 +216,12 @@
 					};
 					SplitCount = 1;
 					Tab0 = {
-						Frame = "{{0, 0}, {313, 531}}";
+						Frame = "{{0, 0}, {300, 533}}";
 						GroupTreeTableConfiguration = (
 							TargetStatusColumn,
 							18,
 							MainColumn,
-							280,
+							267,
 						);
 					};
 					Tab1 = {
@@ -243,7 +245,7 @@
 						Frame = "{{0, 0}, {200, 100}}";
 					};
 					Tab3 = {
-						Frame = "{{0, 0}, {200, 557}}";
+						Frame = "{{0, 0}, {200, 386}}";
 						TargetTableConfiguration = (
 							ActiveObject,
 							16,
@@ -258,16 +260,16 @@
 							enabledColumn,
 							31,
 						);
-						Frame = "{{0, 0}, {250, 100}}";
+						Frame = "{{0, 0}, {250, 386}}";
 					};
 					TabCount = 5;
 					TabsVisible = NO;
 				};
 				NavBarShownByDefault = YES;
-				StatusViewVisible = NO;
-				Template = F5CA7ECB015C094F0DCA290F;
-				ToolbarVisible = NO;
-				WindowLocation = "{48, 349}";
+				StatusViewVisible = YES;
+				Template = F5534CB2020F3F8A0DCA290F;
+				ToolbarVisible = YES;
+				WindowLocation = "{4, 483}";
 			};
 			PBXWorkspaceContents = (
 				{
@@ -439,7 +441,7 @@
 					WindowLocation = "{856, 356}";
 				},
 			);
-			PBXWorkspaceStateSaveDate = 61685642;
+			PBXWorkspaceStateSaveDate = 61714274;
 		};
 		projectwideBuildSettings = {
 		};
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index 0f5d142..ef13936 100755
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -4,49 +4,42 @@
 #include    "FTBBox.h"
 
 
-FTFont::FTFont()
+FTFont::FTFont( const char* fontname)
 :   numFaces(0),
-    glyphList(0),
-    err(0)
-{}
-
-
-FTFont::~FTFont()
-{
-    delete glyphList;
-}
-
-
-bool FTFont::Open( const char* fontname)
+    glyphList(0)
 {
     if( face.Open( fontname))
     {
         err = 0;
-        return true;
     }
     else
     {
         err = face.Error();
-        return false;
     }
 }
 
 
-bool FTFont::Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+FTFont::FTFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   numFaces(0),
+    glyphList(0)
 {
     if( face.Open( pBufferBytes, bufferSizeInBytes ))
     {
         err = 0;
-        return true;
     }
     else
     {
         err = face.Error();
-        return false;
     }
 }
 
 
+FTFont::~FTFont()
+{
+    delete glyphList;
+}
+
+
 bool FTFont::Attach( const char* filename)
 {
     if( face.Attach( filename))
diff --git a/src/FTGLBitmapFont.cpp b/src/FTGLBitmapFont.cpp
index 5ed6f62..51ff9e2 100755
--- a/src/FTGLBitmapFont.cpp
+++ b/src/FTGLBitmapFont.cpp
@@ -2,7 +2,13 @@
 #include "FTBitmapGlyph.h"
 
 
-FTGLBitmapFont::FTGLBitmapFont()
+FTGLBitmapFont::FTGLBitmapFont( const char* fontname)
+:   FTFont( fontname)
+{}
+
+
+FTGLBitmapFont::FTGLBitmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   FTFont( pBufferBytes, bufferSizeInBytes)
 {}
 
 
diff --git a/src/FTGLExtrdFont.cpp b/src/FTGLExtrdFont.cpp
index 12c92bc..2beed8e 100644
--- a/src/FTGLExtrdFont.cpp
+++ b/src/FTGLExtrdFont.cpp
@@ -2,8 +2,15 @@
 #include    "FTExtrdGlyph.h"
 
 
-FTGLExtrdFont::FTGLExtrdFont()
-:   depth(0.0f)
+FTGLExtrdFont::FTGLExtrdFont( const char* fontname)
+:   FTFont( fontname),
+    depth( 0.0f)
+{}
+
+
+FTGLExtrdFont::FTGLExtrdFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   FTFont( pBufferBytes, bufferSizeInBytes),
+    depth( 0.0f)
 {}
 
 
diff --git a/src/FTGLOutlineFont.cpp b/src/FTGLOutlineFont.cpp
index 71e5718..cfbbf2f 100755
--- a/src/FTGLOutlineFont.cpp
+++ b/src/FTGLOutlineFont.cpp
@@ -2,7 +2,13 @@
 #include    "FTOutlineGlyph.h"
 
 
-FTGLOutlineFont::FTGLOutlineFont()
+FTGLOutlineFont::FTGLOutlineFont( const char* fontname)
+:   FTFont( fontname)
+{}
+
+
+FTGLOutlineFont::FTGLOutlineFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   FTFont( pBufferBytes, bufferSizeInBytes)
 {}
 
 
diff --git a/src/FTGLPixmapFont.cpp b/src/FTGLPixmapFont.cpp
index 0658b2b..7c86894 100755
--- a/src/FTGLPixmapFont.cpp
+++ b/src/FTGLPixmapFont.cpp
@@ -2,7 +2,13 @@
 #include    "FTPixmapGlyph.h"
 
 
-FTGLPixmapFont::FTGLPixmapFont()
+FTGLPixmapFont::FTGLPixmapFont( const char* fontname)
+:   FTFont( fontname)
+{}
+
+
+FTGLPixmapFont::FTGLPixmapFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   FTFont( pBufferBytes, bufferSizeInBytes)
 {}
 
 
diff --git a/src/FTGLPolygonFont.cpp b/src/FTGLPolygonFont.cpp
index 9ebd286..8fe9a0e 100755
--- a/src/FTGLPolygonFont.cpp
+++ b/src/FTGLPolygonFont.cpp
@@ -2,7 +2,13 @@
 #include    "FTPolyGlyph.h"
 
 
-FTGLPolygonFont::FTGLPolygonFont()
+FTGLPolygonFont::FTGLPolygonFont( const char* fontname)
+:   FTFont( fontname)
+{}
+
+
+FTGLPolygonFont::FTGLPolygonFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   FTFont( pBufferBytes, bufferSizeInBytes)
 {}
 
 
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index 8ae3037..4f9fbd6 100755
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -18,8 +18,9 @@ inline GLuint NextPowerOf2( GLuint in)
 }
 
 
-FTGLTextureFont::FTGLTextureFont()
-:   maxTextSize(0),
+FTGLTextureFont::FTGLTextureFont( const char* fontname)
+:   FTFont( fontname),
+    maxTextSize(0),
     textureWidth(0),
     textureHeight(0),
     numTextures(0),
@@ -27,10 +28,28 @@ FTGLTextureFont::FTGLTextureFont()
     glyphHeight(0),
     glyphWidth(0),
     padding(3),
-    remGlyphs(0),
     xOffset(0),
     yOffset(0)
-{}
+{
+    remGlyphs = numGlyphs = face.GlyphCount();
+}
+
+
+FTGLTextureFont::FTGLTextureFont( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   FTFont( pBufferBytes, bufferSizeInBytes),
+    maxTextSize(0),
+    textureWidth(0),
+    textureHeight(0),
+    numTextures(0),
+    textMem(0),
+    glyphHeight(0),
+    glyphWidth(0),
+    padding(3),
+    xOffset(0),
+    yOffset(0)
+{
+    remGlyphs = numGlyphs = face.GlyphCount();
+}
 
 
 FTGLTextureFont::~FTGLTextureFont()
@@ -93,8 +112,6 @@ bool FTGLTextureFont::MakeGlyphList()
     if( !maxTextSize)
         glGetIntegerv( GL_MAX_TEXTURE_SIZE, (GLint*)&maxTextSize);
 
-    remGlyphs = numGlyphs = face.GlyphCount();
-
     return FTFont::MakeGlyphList();
 }
 
diff --git a/test/demo.cpp b/test/demo.cpp
index 3fe2657..b48af92 100644
--- a/test/demo.cpp
+++ b/test/demo.cpp
@@ -41,14 +41,14 @@ my_init( const char* font_filename )
     glClearColor(0.0, 0.0, 0.0, 0.0);
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
-    fonts[0] = new FTGLOutlineFont;
-    fonts[1] = new FTGLPolygonFont;
-    fonts[2] = new FTGLTextureFont;
-    fonts[3] = new FTGLBitmapFont;
-    fonts[4] = new FTGLPixmapFont;
+    fonts[0] = new FTGLOutlineFont( font_filename);
+    fonts[1] = new FTGLPolygonFont( font_filename);
+    fonts[2] = new FTGLTextureFont( font_filename);
+    fonts[3] = new FTGLBitmapFont( font_filename);
+    fonts[4] = new FTGLPixmapFont( font_filename);
     for (int i=0; i< 5; i++)
     {
-        if (!fonts[i]->Open(font_filename))
+        if (fonts[i]->Error())
         {
             std::cerr << "ERROR: Unable to open file " << font_filename << std::endl;
         }