Commit a9a6aa3e3c428999a165e10fbfb6a1ee425f4161

henry 2003-04-06T23:50:29

Minor formatting changes

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
diff --git a/src/FTSimpleLayout.cpp b/src/FTSimpleLayout.cpp
index c28bd6d..e6eb569 100644
--- a/src/FTSimpleLayout.cpp
+++ b/src/FTSimpleLayout.cpp
@@ -1,53 +1,56 @@
-#include "FTSimpleLayout.h"
+#include <ctype.h>
 
 #include "FTFont.h"
 #include "FTGlyphContainer.h"
 #include "FTBBox.h"
+#include "FTSimpleLayout.h"
 
-#include <ctype.h>
-
+FTSimpleLayout::FTSimpleLayout()
+:   currentFont(NULL),
+    lineLength(100.0f),
+    alignment(ALIGN_LEFT),
+    lineSpacing(1.0f)
+{}
 
-FTSimpleLayout::FTSimpleLayout() {
-   currentFont = NULL;
-   lineLength = 100.0f;
-   alignment = ALIGN_LEFT;
-   lineSpacing = 1.0f;
-} /* FTSimpleLayout::FTSimpleLayout() */
+void FTSimpleLayout::BBox(const char *String,float& llx, float& lly, float& llz, float& urx, float& ury, float& urz)
+{
+    FTBBox bounds; 
 
-void FTSimpleLayout::BBox(const char *String,float& llx, float& lly, float& llz, float& urx, float& ury, float& urz) {
-   FTBBox bounds; 
-   
-   WrapText(String,&bounds); 
-   llx = bounds.lowerX; lly = bounds.lowerY; llz = bounds.lowerZ;
-   urx = bounds.upperX; ury = bounds.upperY; urz = bounds.upperZ;
+    WrapText(String,&bounds);
+    llx = bounds.lowerX; lly = bounds.lowerY; llz = bounds.lowerZ;
+    urx = bounds.upperX; ury = bounds.upperY; urz = bounds.upperZ;
 } /* FTSimpleLayout::BBox() */
 
-void FTSimpleLayout::BBox(const wchar_t *String,float& llx, float& lly, float& llz, float& urx, float& ury, float& urz) {
-   FTBBox bounds; 
-   
-   WrapText(String,&bounds); 
-   llx = bounds.lowerX; lly = bounds.lowerY; llz = bounds.lowerZ;
-   urx = bounds.upperX; ury = bounds.upperY; urz = bounds.upperZ;
+void FTSimpleLayout::BBox(const wchar_t *String,float& llx, float& lly, float& llz, float& urx, float& ury, float& urz) 
+{
+    FTBBox bounds; 
+
+    WrapText(String,&bounds);
+    llx = bounds.lowerX; lly = bounds.lowerY; llz = bounds.lowerZ;
+    urx = bounds.upperX; ury = bounds.upperY; urz = bounds.upperZ;
 } /* FTSimpleLayout::BBox() */
 
-void FTSimpleLayout::Render(const char *String) {
-   pen.x = pen.y = 0.0f;
-   WrapText(String,NULL);
+void FTSimpleLayout::Render(const char *String) 
+{
+    pen.x = pen.y = 0.0f;
+    WrapText(String,NULL);
 } /* FTSimpleLayout::Render() */
 
-void FTSimpleLayout::Render(const wchar_t* String) {
-   pen.x = pen.y = 0.0f;
-   WrapText(String,NULL);
+void FTSimpleLayout::Render(const wchar_t* String) 
+{
+    pen.x = pen.y = 0.0f;
+    WrapText(String,NULL);
 } /* FTSimpleLayout::Render() */
 
-void FTSimpleLayout::WrapText(const char *Buffer,FTBBox *bounds) {
-   int breakIdx = 0;					// The index of the last break character
-   int lineStart = 0;				// The character index of the line start
-   float nextStart = 0.0;			// The total width of the line being generated
-   float breakWidth = 0.0;			// The width of the line up to the last word break
-   float currentWidth = 0.0;		// The width of all characters on the line being generated
-   float prevWidth;					// The width of all characters but the current glyph
-   float wordLength = 0.0;			// The length of the block since the last break character
+void FTSimpleLayout::WrapText(const char *Buffer,FTBBox *bounds) 
+{
+   int breakIdx = 0;                    // The index of the last break character
+   int lineStart = 0;               // The character index of the line start
+   float nextStart = 0.0f;           // The total width of the line being generated
+   float breakWidth = 0.0f;          // The width of the line up to the last word break
+   float currentWidth = 0.0f;        // The width of all characters on the line being generated
+   float prevWidth;                 // The width of all characters but the current glyph
+   float wordLength = 0.0f;          // The length of the block since the last break character
    float glyphWidth,advance;
    FTBBox glyphBounds;
    /* Reset the pen position */
@@ -131,13 +134,13 @@ void FTSimpleLayout::WrapText(const char *Buffer,FTBBox *bounds) {
 } /* FTSimpleLayout::WrapText() */
 
 void FTSimpleLayout::WrapText(const wchar_t* Buffer,FTBBox *bounds) {
-   int breakIdx = 0;					// The index of the last break character
-   int lineStart = 0;				// The character index of the line start
-   float nextStart = 0.0;			// The total width of the line being generated
-   float breakWidth = 0.0;			// The width of the line up to the last word break
-   float currentWidth = 0.0;		// The width of all characters on the line being generated
-   float prevWidth;					// The width of all characters but the current glyph
-   float wordLength = 0.0;			// The length of the block since the last break character
+   int breakIdx = 0;                    // The index of the last break character
+   int lineStart = 0;               // The character index of the line start
+   float nextStart = 0.0f;           // The total width of the line being generated
+   float breakWidth = 0.0f;          // The width of the line up to the last word break
+   float currentWidth = 0.0f;        // The width of all characters on the line being generated
+   float prevWidth;                 // The width of all characters but the current glyph
+   float wordLength = 0.0f;          // The length of the block since the last break character
    float glyphWidth,advance;
    FTBBox glyphBounds;
    /* Reset the pen position */
diff --git a/test/demo.cpp b/test/demo.cpp
index 0ae110e..bdc2808 100644
--- a/test/demo.cpp
+++ b/test/demo.cpp
@@ -1,6 +1,3 @@
-// source changed by mrn@paus.ch/ max rheiner
-// original source: henryj@paradise.net.nz
-
 #include <iostream>
 #include <stdlib.h> // exit()
 
@@ -16,7 +13,7 @@
 #include "FTGLTextureFont.h"
 #include "FTGLPixmapFont.h"
 
-//#include "mmgr.h"
+#include "mmgr.h"
 
 static FTFont* fonts[5];
 static int width;
@@ -25,13 +22,13 @@ static int height;
 
 // YOU'LL PROBABLY WANT TO CHANGE THESE
 #ifdef __linux__
-	#define DEFAULT_FONT "/usr/share/fonts/truetype/arial.ttf"
+    #define DEFAULT_FONT "/usr/share/fonts/truetype/arial.ttf"
 #endif
 #ifdef __APPLE_CC__
-	#define DEFAULT_FONT "/Users/henry/Development/PROJECTS/FTGL/ftglcvs/FTGL/test/arial.ttf"
+    #define DEFAULT_FONT "/Users/henry/Development/PROJECTS/FTGL/test/font_pack/arial.ttf"
 #endif
 #ifdef WIN32
-	#define DEFAULT_FONT "C:\\WINNT\\Fonts\\arial.ttf"
+    #define DEFAULT_FONT "C:\\WINNT\\Fonts\\arial.ttf"
 #endif
 
 
@@ -56,7 +53,7 @@ my_init( const char* font_filename )
         {
             std::cout << "Reading font " << i << " from " << font_filename << std::endl;
 
-            int point_size = 24;
+            int point_size = 48;
             if (!fonts[i]->FaceSize(point_size))
             {
                 std::cerr << "ERROR: Unable to set font face size " << point_size << std::endl;
@@ -68,97 +65,95 @@ my_init( const char* font_filename )
 static void
 do_ortho()
 {
-  int w;
-  int h;
-  GLdouble size;
-  GLdouble aspect;
-
-  w = width;
-  h = height;
-  aspect = (GLdouble)w / (GLdouble)h;
-
-  // Use the whole window.
-  glViewport(0, 0, w, h);
-
-  // We are going to do some 2-D orthographic drawing.
-  glMatrixMode(GL_PROJECTION);
-  glLoadIdentity();
-  size = (GLdouble)((w >= h) ? w : h) / 2.0;
-  if (w <= h) {
-    aspect = (GLdouble)h/(GLdouble)w;
-    glOrtho(-size, size, -size*aspect, size*aspect,
-            -100000.0, 100000.0);
-  }
-  else {
-    aspect = (GLdouble)w/(GLdouble)h;
-    glOrtho(-size*aspect, size*aspect, -size, size,
-            -100000.0, 100000.0);
-  }
-
-  // Make the world and window coordinates coincide so that 1.0 in
-  // model space equals one pixel in window space.
-  glScaled(aspect, aspect, 1.0);
-
-   // Now determine where to draw things.
-  glMatrixMode(GL_MODELVIEW);
-  glLoadIdentity();
+    int w;
+    int h;
+    GLdouble size;
+    GLdouble aspect;
+    
+    w = width;
+    h = height;
+    aspect = (GLdouble)w / (GLdouble)h;
+    
+    // Use the whole window.
+    glViewport(0, 0, w, h);
+    
+    // We are going to do some 2-D orthographic drawing.
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+    size = (GLdouble)((w >= h) ? w : h) / 2.0;
+    if (w <= h) {
+        aspect = (GLdouble)h/(GLdouble)w;
+        glOrtho(-size, size, -size*aspect, size*aspect,
+                -100000.0, 100000.0);
+    }
+    else {
+        aspect = (GLdouble)w/(GLdouble)h;
+        glOrtho(-size*aspect, size*aspect, -size, size,
+                -100000.0, 100000.0);
+    }
+    
+    // Make the world and window coordinates coincide so that 1.0 in
+    // model space equals one pixel in window space.
+    glScaled(aspect, aspect, 1.0);
+    
+    // Now determine where to draw things.
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
 }
 
 
 void
 my_reshape(int w, int h)
 {
-  width = w;
-  height = h;
-
-  do_ortho( );
+    width = w;
+    height = h;
+    
+    do_ortho( );
 }
 
 void
 my_handle_key(unsigned char key, int x, int y)
 {
-   switch (key) {
-
-	   //!!ELLERS
-   case 'q':   // Esc or 'q' Quits the program.
-   case 27:    
-	   {
-       for (int i=0; i<5; i++) {
-           if (fonts[i]) {
-               delete fonts[i];
-               fonts[i] = 0;
-           }
-       }
-      exit(1);
-	   }
-      break;
-
-   default:
-      break;
-   }
+    switch (key) {
+        case 'q':   // Esc or 'q' Quits the program.
+        case 27:
+        {
+            for (int i=0; i<5; i++) {
+                if (fonts[i]) {
+                    delete fonts[i];
+                    fonts[i] = 0;
+                }
+            }
+            exit(1);
+        }
+            break;
+        default:
+            break;
+    }
 }
 
 void
 draw_scene()
 {
-   /* Set up some strings with the characters to draw. */
-   unsigned int count = 0;
-   char string[8][256];
-   int i;
-   for (i=1; i < 32; i++) { /* Skip zero - it's the null terminator! */
-      string[0][count] = i;
-      count++;
-   }
-   string[0][count] = '\0';
+    /* Set up some strings with the characters to draw. */
+    unsigned int count = 0;
+    char string[8][256];
+    int i;
+    for (i=1; i < 32; i++) { /* Skip zero - it's the null terminator! */
+        string[0][count] = i;
+        count++;
+    }
 
-   count = 0;
-   for (i=32; i < 64; i++) {
-      string[1][count] = i;
-      count++;
-   }
-   string[1][count] = '\0';
+    string[0][count] = '\0';
 
-   count = 0;
+    count = 0;
+    for (i=32; i < 64; i++) {
+        string[1][count] = i;
+        count++;
+    }
+    string[1][count] = '\0';
+
+    count = 0;
    for (i=64; i < 96; i++) {
       string[2][count] = i;
       count++;
@@ -253,72 +248,72 @@ my_idle()
 int 
 file_exists( const char * filename )
 {
-	FILE * fp = fopen( filename, "r" );
-
-	if ( fp == NULL )
-	{
-		// That fopen failed does _not_ definitely mean the file isn't there 
-		// but for now this is ok
-		return 0;
-	}
-	fclose( fp );
-	return 1;
+    FILE * fp = fopen( filename, "r" );
+
+    if ( fp == NULL )
+    {
+        // That fopen failed does _not_ definitely mean the file isn't there 
+        // but for now this is ok
+        return 0;
+    }
+    fclose( fp );
+    return 1;
 }
 
 void
 usage( const char * program )
 {
-	std::cerr << "Usage: " << program << " <filename.ttf>\n" << std::endl;
+    std::cerr << "Usage: " << program << " <filename.ttf>\n" << std::endl;
 }
 
 int
 main(int argc, char **argv)
 {
-	char * filename;
-
-	glutInitWindowSize(600, 600);
-	glutInit(&argc, argv);
-	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
-
-	glutCreateWindow("FTGL demo");
-
-	if ( argc >= 2 ) 
-	{
-		if ( !file_exists( argv[ 1 ] ))
-		{
-			usage( argv[ 0 ]);
-			std::cerr << "Couldn't open file '" << argv[ 1 ] << "'" << std::endl;
-			exit( -1 );
-		}
-		filename = argv[ 1 ];
-	}
-	else 
-	{
-		// try a default font
-		filename = DEFAULT_FONT;
-
-		if ( !file_exists( filename ))
-		{
-			usage( argv[ 0 ]);
-			std::cerr << "Couldn't open default file '" << filename << "'" << std::endl;
-			exit( -1 );
-		}
-	}
-
-	my_init( filename );
-
-	glutDisplayFunc(my_display);
-	glutReshapeFunc(my_reshape);
-	glutIdleFunc(my_idle);
-	glutKeyboardFunc(my_handle_key);
-
-	glutMainLoop();
-        
-        for(int x = 0; x < 5; ++x)
+    char * filename;
+
+    glutInitWindowSize(600, 600);
+    glutInit(&argc, argv);
+    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
+
+    glutCreateWindow("FTGL demo");
+
+    if ( argc >= 2 ) 
+    {
+        if ( !file_exists( argv[ 1 ] ))
+        {
+            usage( argv[ 0 ]);
+            std::cerr << "Couldn't open file '" << argv[ 1 ] << "'" << std::endl;
+            exit( -1 );
+        }
+        filename = argv[ 1 ];
+    }
+    else 
+    {
+        // try a default font
+        filename = DEFAULT_FONT;
+
+        if ( !file_exists( filename ))
         {
-            delete fonts[x];
+            usage( argv[ 0 ]);
+            std::cerr << "Couldn't open default file '" << filename << "'" << std::endl;
+            exit( -1 );
         }
+    }
+
+    my_init( filename );
+
+    glutDisplayFunc(my_display);
+    glutReshapeFunc(my_reshape);
+    glutIdleFunc(my_idle);
+    glutKeyboardFunc(my_handle_key);
+
+    glutMainLoop();
+        
+    for(int x = 0; x < 5; ++x)
+    {
+        delete fonts[x];
+    }
         
-	return 0;
+    return 0;
 }