Commit 0a28e5d32c3c96f7f46a2803a526a94ffa5716f0

sammy 2008-05-04T19:39:34

* Put MakeGlyph back into FT*Font classes instead of FT*FontImpl, and make it use as few FT*FontImpl members as possible so that external application may actually have a chance to properly subclass us.

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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
diff --git a/src/FTFont/FTBitmapFont.cpp b/src/FTFont/FTBitmapFont.cpp
index 98d458a..475ae20 100644
--- a/src/FTFont/FTBitmapFont.cpp
+++ b/src/FTFont/FTBitmapFont.cpp
@@ -38,14 +38,14 @@
 
 FTBitmapFont::FTBitmapFont(char const *fontFilePath)
 {
-    impl = new FTBitmapFontImpl(fontFilePath);
+    impl = new FTBitmapFontImpl(this, fontFilePath);
 }
 
 
 FTBitmapFont::FTBitmapFont(unsigned char const *pBufferBytes,
                            size_t bufferSizeInBytes)
 {
-    impl = new FTBitmapFontImpl(pBufferBytes, bufferSizeInBytes);
+    impl = new FTBitmapFontImpl(this, pBufferBytes, bufferSizeInBytes);
 }
 
 
@@ -55,24 +55,15 @@ FTBitmapFont::~FTBitmapFont()
 }
 
 
-//
-//  FTBitmapFontImpl
-//
-
-
-FTGlyph* FTBitmapFontImpl::MakeGlyph(unsigned int g)
+FTGlyph* FTBitmapFont::MakeGlyph(FT_GlyphSlot ftGlyph)
 {
-    FT_GlyphSlot ftGlyph = face.Glyph(g, FT_LOAD_DEFAULT);
+    return new FTBitmapGlyph(ftGlyph);
+}
 
-    if(ftGlyph)
-    {
-        FTBitmapGlyph* tempGlyph = new FTBitmapGlyph(ftGlyph);
-        return tempGlyph;
-    }
 
-    err = face.Error();
-    return NULL;
-}
+//
+//  FTBitmapFontImpl
+//
 
 
 template <typename T>
diff --git a/src/FTFont/FTBitmapFontImpl.h b/src/FTFont/FTBitmapFontImpl.h
index 0fe363a..a0c5f0b 100644
--- a/src/FTFont/FTBitmapFontImpl.h
+++ b/src/FTFont/FTBitmapFontImpl.h
@@ -35,26 +35,18 @@ class FTBitmapFontImpl : public FTFontImpl
     friend class FTBitmapFont;
 
     protected:
-        FTBitmapFontImpl(const char* fontFilePath) :
-            FTFontImpl(fontFilePath) {};
+        FTBitmapFontImpl(FTFont *ftFont, const char* fontFilePath) :
+            FTFontImpl(ftFont, fontFilePath) {};
 
-        FTBitmapFontImpl(const unsigned char *pBufferBytes,
+        FTBitmapFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
                          size_t bufferSizeInBytes) :
-            FTFontImpl(pBufferBytes, bufferSizeInBytes) {};
+            FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes) {};
 
         virtual void Render(const char* string);
 
         virtual void Render(const wchar_t* string);
 
     private:
-        /**
-         * Construct a FTBitmapGlyph.
-         *
-         * @param g The glyph index NOT the char code.
-         * @return  An FTBitmapGlyph or <code>null</code> on failure.
-         */
-        inline virtual FTGlyph* MakeGlyph(unsigned int g);
-
         /* Internal generic Render() implementation */
         template <typename T>
         inline void RenderI(const T* string);
diff --git a/src/FTFont/FTExtrudeFont.cpp b/src/FTFont/FTExtrudeFont.cpp
index dbea5f9..7f251dc 100644
--- a/src/FTFont/FTExtrudeFont.cpp
+++ b/src/FTFont/FTExtrudeFont.cpp
@@ -38,14 +38,14 @@
 
 FTExtrudeFont::FTExtrudeFont(char const *fontFilePath)
 {
-    impl = new FTExtrudeFontImpl(fontFilePath);
+    impl = new FTExtrudeFontImpl(this, fontFilePath);
 }
 
 
 FTExtrudeFont::FTExtrudeFont(const unsigned char *pBufferBytes,
                              size_t bufferSizeInBytes)
 {
-    impl = new FTExtrudeFontImpl(pBufferBytes, bufferSizeInBytes);
+    impl = new FTExtrudeFontImpl(this, pBufferBytes, bufferSizeInBytes);
 }
 
 
@@ -55,23 +55,21 @@ FTExtrudeFont::~FTExtrudeFont()
 }
 
 
-//
-//  FTExtrudeFontImpl
-//
-
-
-FTGlyph* FTExtrudeFontImpl::MakeGlyph(unsigned int glyphIndex)
+FTGlyph* FTExtrudeFont::MakeGlyph(FT_GlyphSlot ftGlyph)
 {
-    FT_GlyphSlot ftGlyph = face.Glyph(glyphIndex, FT_LOAD_NO_HINTING);
-
-    if(ftGlyph)
+    FTExtrudeFontImpl *myimpl = dynamic_cast<FTExtrudeFontImpl *>(impl);
+    if(!myimpl)
     {
-        FTExtrudeGlyph* tempGlyph = new FTExtrudeGlyph(ftGlyph, depth, front,
-                                                       back, useDisplayLists);
-        return tempGlyph;
+        return NULL;
     }
 
-    err = face.Error();
-    return NULL;
+    return new FTExtrudeGlyph(ftGlyph, myimpl->depth, myimpl->front,
+                              myimpl->back, myimpl->useDisplayLists);
 }
 
+
+//
+//  FTExtrudeFontImpl
+//
+
+
diff --git a/src/FTFont/FTExtrudeFontImpl.h b/src/FTFont/FTExtrudeFontImpl.h
index 3b418db..eab0093 100644
--- a/src/FTFont/FTExtrudeFontImpl.h
+++ b/src/FTFont/FTExtrudeFontImpl.h
@@ -35,13 +35,14 @@ class FTExtrudeFontImpl : public FTFontImpl
     friend class FTExtrudeFont;
 
     protected:
-        FTExtrudeFontImpl(const char* fontFilePath) :
-          FTFontImpl(fontFilePath), depth(0.0f), front(0.0f), back(0.0f) {};
+        FTExtrudeFontImpl(FTFont *ftFont, const char* fontFilePath) :
+            FTFontImpl(ftFont, fontFilePath),
+            depth(0.0f), front(0.0f), back(0.0f) {};
 
-        FTExtrudeFontImpl(const unsigned char *pBufferBytes,
+        FTExtrudeFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
                           size_t bufferSizeInBytes) :
-          FTFontImpl(pBufferBytes, bufferSizeInBytes),
-          depth(0.0f), front(0.0f), back(0.0f) {};
+            FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+            depth(0.0f), front(0.0f), back(0.0f) {};
 
         /**
          * Set the extrusion distance for the font.
@@ -69,14 +70,6 @@ class FTExtrudeFontImpl : public FTFontImpl
 
     private:
         /**
-         * Construct a FTPolygonGlyph.
-         *
-         * @param glyphIndex The glyph index NOT the char code.
-         * @return An FTExtrudeGlyph or <code>null</code> on failure.
-         */
-        virtual FTGlyph* MakeGlyph(unsigned int glyphIndex);
-
-        /**
          * The extrusion distance for the font.
          */
         float depth;
diff --git a/src/FTFont/FTFont.cpp b/src/FTFont/FTFont.cpp
index 549518f..3843847 100644
--- a/src/FTFont/FTFont.cpp
+++ b/src/FTFont/FTFont.cpp
@@ -221,7 +221,8 @@ FT_Error FTFont::Error() const
 //
 
 
-FTFontImpl::FTFontImpl(char const *fontFilePath) :
+FTFontImpl::FTFontImpl(FTFont *ftFont, char const *fontFilePath) :
+    base(ftFont),
     face(fontFilePath),
     useDisplayLists(true),
     glyphList(0)
@@ -234,8 +235,9 @@ FTFontImpl::FTFontImpl(char const *fontFilePath) :
 }
 
 
-FTFontImpl::FTFontImpl(const unsigned char *pBufferBytes,
+FTFontImpl::FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
                        size_t bufferSizeInBytes) :
+    base(ftFont),
     face(pBufferBytes, bufferSizeInBytes),
     useDisplayLists(true),
     glyphList(0)
@@ -518,21 +520,40 @@ float FTFontImpl::Advance(const wchar_t* string)
 
 bool FTFontImpl::CheckGlyph(const unsigned int characterCode)
 {
-    if(NULL == glyphList->Glyph(characterCode))
+    if(glyphList->Glyph(characterCode))
     {
-        unsigned int glyphIndex = glyphList->FontIndex(characterCode);
-        FTGlyph* tempGlyph = MakeGlyph(glyphIndex);
-        if(NULL == tempGlyph)
-        {
-            if(0 == err)
-            {
-                err = 0x13;
-            }
+        return true;
+    }
 
-            return false;
+    /*
+     * FIXME: load options are not the same for all subclasses:
+     *  FTBitmapGlyph: FT_LOAD_DEFAULT
+     *  FTExtrudeGlyph: FT_LOAD_NO_HINTING
+     *  FTOutlineGlyph: FT_LOAD_NO_HINTING
+     *  FTPixmapGlyph: FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP
+     *  FTPolygonGlyph: FT_LOAD_NO_HINTING
+     *  FTTextureGlyph: FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP
+     */
+    unsigned int glyphIndex = glyphList->FontIndex(characterCode);
+    FT_GlyphSlot ftGlyph = face.Glyph(glyphIndex, FT_LOAD_NO_HINTING);
+
+    if(!ftGlyph)
+    {
+        err = face.Error();
+        return false;
+    }
+
+    FTGlyph* tempGlyph = base->MakeGlyph(ftGlyph);
+    if(NULL == tempGlyph)
+    {
+        if(0 == err)
+        {
+            err = 0x13;
         }
-        glyphList->Add(tempGlyph, characterCode);
+
+        return false;
     }
+    glyphList->Add(tempGlyph, characterCode);
 
     return true;
 }
diff --git a/src/FTFont/FTFontImpl.h b/src/FTFont/FTFontImpl.h
index 438aba4..97cb51b 100644
--- a/src/FTFont/FTFontImpl.h
+++ b/src/FTFont/FTFontImpl.h
@@ -41,9 +41,10 @@ class FTFontImpl
         friend class FTFont;
 
     protected:
-        FTFontImpl(char const *fontFilePath);
+        FTFontImpl(FTFont *ftFont, char const *fontFilePath);
 
-        FTFontImpl(const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
+        FTFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
+                   size_t bufferSizeInBytes);
 
         virtual ~FTFontImpl();
 
@@ -98,17 +99,6 @@ class FTFontImpl
         float Advance(const char* string);
 
         /**
-         * Construct a glyph of the correct type.
-         *
-         * Clients must override the function and return their specialised
-         * FTGlyph.
-         *
-         * @param g The glyph index NOT the char code.
-         * @return  An FT****Glyph or <code>null</code> on failure.
-         */
-        virtual FTGlyph* MakeGlyph(unsigned int g) = 0;
-
-        /**
          * Current face object
          */
         FTFace face;
@@ -132,6 +122,11 @@ class FTFontImpl
 
     private:
         /**
+         * A link back to the object of which we are the implementation.
+         */
+        FTFont *base;
+
+        /**
          * Render a character.
          * This function does an implicit conversion on its arguments.
          *
diff --git a/src/FTFont/FTOutlineFont.cpp b/src/FTFont/FTOutlineFont.cpp
index 8b4ef63..0d7a582 100644
--- a/src/FTFont/FTOutlineFont.cpp
+++ b/src/FTFont/FTOutlineFont.cpp
@@ -38,14 +38,14 @@
 
 FTOutlineFont::FTOutlineFont(char const *fontFilePath)
 {
-    impl = new FTOutlineFontImpl(fontFilePath);
+    impl = new FTOutlineFontImpl(this, fontFilePath);
 }
 
 
 FTOutlineFont::FTOutlineFont(const unsigned char *pBufferBytes,
                              size_t bufferSizeInBytes)
 {
-    impl = new FTOutlineFontImpl(pBufferBytes, bufferSizeInBytes);
+    impl = new FTOutlineFontImpl(this, pBufferBytes, bufferSizeInBytes);
 }
 
 
@@ -55,26 +55,24 @@ FTOutlineFont::~FTOutlineFont()
 }
 
 
-//
-//  FTOutlineFontImpl
-//
-
-
-FTGlyph* FTOutlineFontImpl::MakeGlyph(unsigned int g)
+FTGlyph* FTOutlineFont::MakeGlyph(FT_GlyphSlot ftGlyph)
 {
-    FT_GlyphSlot ftGlyph = face.Glyph(g, FT_LOAD_NO_HINTING);
-
-    if(ftGlyph)
+    FTOutlineFontImpl *myimpl = dynamic_cast<FTOutlineFontImpl *>(impl);
+    if(!myimpl)
     {
-        FTOutlineGlyph* tempGlyph = new FTOutlineGlyph(ftGlyph, outset, useDisplayLists);
-        return tempGlyph;
+        return NULL;
     }
 
-    err = face.Error();
-    return NULL;
+    return new FTOutlineGlyph(ftGlyph, myimpl->outset,
+                              myimpl->useDisplayLists);
 }
 
 
+//
+//  FTOutlineFontImpl
+//
+
+
 template <typename T>
 inline void FTOutlineFontImpl::RenderI(const T* string)
 {
diff --git a/src/FTFont/FTOutlineFontImpl.h b/src/FTFont/FTOutlineFontImpl.h
index 9b0afec..d62be83 100644
--- a/src/FTFont/FTOutlineFontImpl.h
+++ b/src/FTFont/FTOutlineFontImpl.h
@@ -35,12 +35,13 @@ class FTOutlineFontImpl : public FTFontImpl
     friend class FTOutlineFont;
 
     protected:
-        FTOutlineFontImpl(const char* fontFilePath) :
-            FTFontImpl(fontFilePath), outset(0.0f) {};
+        FTOutlineFontImpl(FTFont *ftFont, const char* fontFilePath) :
+            FTFontImpl(ftFont, fontFilePath), outset(0.0f) {};
 
-        FTOutlineFontImpl(const unsigned char *pBufferBytes,
+        FTOutlineFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
                           size_t bufferSizeInBytes) :
-            FTFontImpl(pBufferBytes, bufferSizeInBytes), outset(0.0f) {};
+            FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+            outset(0.0f) {};
 
         /**
          * Set the outset distance for the font. Only implemented by
@@ -82,14 +83,6 @@ class FTOutlineFontImpl : public FTFontImpl
 
     private:
         /**
-         * Construct a FTOutlineGlyph.
-         *
-         * @param g The glyph index NOT the char code.
-         * @return  An FTOutlineGlyph or <code>null</code> on failure.
-         */
-        inline virtual FTGlyph* MakeGlyph(unsigned int g);
-
-        /**
          * The outset distance for the font.
          */
         float outset;
diff --git a/src/FTFont/FTPixmapFont.cpp b/src/FTFont/FTPixmapFont.cpp
index ca69c39..4c62f13 100644
--- a/src/FTFont/FTPixmapFont.cpp
+++ b/src/FTFont/FTPixmapFont.cpp
@@ -38,14 +38,14 @@
 
 FTPixmapFont::FTPixmapFont(char const *fontFilePath)
 {
-    impl = new FTPixmapFontImpl(fontFilePath);
+    impl = new FTPixmapFontImpl(this, fontFilePath);
 }
 
 
 FTPixmapFont::FTPixmapFont(const unsigned char *pBufferBytes,
                            size_t bufferSizeInBytes)
 {
-    impl = new FTPixmapFontImpl(pBufferBytes, bufferSizeInBytes);
+    impl = new FTPixmapFontImpl(this, pBufferBytes, bufferSizeInBytes);
 }
 
 
@@ -55,25 +55,15 @@ FTPixmapFont::~FTPixmapFont()
 }
 
 
-//
-//  FTPixmapFontImpl
-//
-
-
-FTGlyph* FTPixmapFontImpl::MakeGlyph(unsigned int g)
+FTGlyph* FTPixmapFont::MakeGlyph(FT_GlyphSlot ftGlyph)
 {
-    FT_GlyphSlot ftGlyph = face.Glyph(g, FT_LOAD_NO_HINTING
-                                          | FT_LOAD_NO_BITMAP);
+    return new FTPixmapGlyph(ftGlyph);
+}
 
-    if(ftGlyph)
-    {
-        FTPixmapGlyph* tempGlyph = new FTPixmapGlyph(ftGlyph);
-        return tempGlyph;
-    }
 
-    err = face.Error();
-    return NULL;
-}
+//
+//  FTPixmapFontImpl
+//
 
 
 template <typename T>
diff --git a/src/FTFont/FTPixmapFontImpl.h b/src/FTFont/FTPixmapFontImpl.h
index 0a15045..7e8e436 100644
--- a/src/FTFont/FTPixmapFontImpl.h
+++ b/src/FTFont/FTPixmapFontImpl.h
@@ -35,12 +35,12 @@ class FTPixmapFontImpl : public FTFontImpl
     friend class FTPixmapFont;
 
     protected:
-        FTPixmapFontImpl(const char* fontFilePath) :
-            FTFontImpl(fontFilePath) {};
+        FTPixmapFontImpl(FTFont *ftFont, const char* fontFilePath) :
+            FTFontImpl(ftFont, fontFilePath) {};
 
-        FTPixmapFontImpl(const unsigned char *pBufferBytes,
+        FTPixmapFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
                          size_t bufferSizeInBytes) :
-            FTFontImpl(pBufferBytes, bufferSizeInBytes) {};
+            FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes) {};
 
         /**
          * Renders a string of characters
@@ -73,14 +73,6 @@ class FTPixmapFontImpl : public FTFontImpl
         virtual void Render(const wchar_t *string, int renderMode);
 
     private:
-        /**
-         * Construct a FTPixmapGlyph.
-         *
-         * @param g The glyph index NOT the char code.
-         * @return  An FTPixmapGlyph or <code>null</code> on failure.
-         */
-        inline virtual FTGlyph* MakeGlyph(unsigned int g);
-
         /* Internal generic Render() implementation */
         template <typename T>
         inline void RenderI(const T* string);
diff --git a/src/FTFont/FTPolygonFont.cpp b/src/FTFont/FTPolygonFont.cpp
index 0235e67..7ab7726 100644
--- a/src/FTFont/FTPolygonFont.cpp
+++ b/src/FTFont/FTPolygonFont.cpp
@@ -38,14 +38,14 @@
 
 FTPolygonFont::FTPolygonFont(char const *fontFilePath)
 {
-    impl = new FTPolygonFontImpl(fontFilePath);
+    impl = new FTPolygonFontImpl(this, fontFilePath);
 }
 
 
 FTPolygonFont::FTPolygonFont(const unsigned char *pBufferBytes,
                              size_t bufferSizeInBytes)
 {
-    impl = new FTPolygonFontImpl(pBufferBytes, bufferSizeInBytes);
+    impl = new FTPolygonFontImpl(this, pBufferBytes, bufferSizeInBytes);
 }
 
 
@@ -55,23 +55,21 @@ FTPolygonFont::~FTPolygonFont()
 }
 
 
-//
-//  FTPolygonFontImpl
-//
-
-
-FTGlyph* FTPolygonFontImpl::MakeGlyph(unsigned int g)
+FTGlyph* FTPolygonFont::MakeGlyph(FT_GlyphSlot ftGlyph)
 {
-    FT_GlyphSlot ftGlyph = face.Glyph(g, FT_LOAD_NO_HINTING);
-
-    if(ftGlyph)
+    FTPolygonFontImpl *myimpl = dynamic_cast<FTPolygonFontImpl *>(impl);
+    if(!myimpl)
     {
-        FTPolygonGlyph* tempGlyph = new FTPolygonGlyph(ftGlyph, outset,
-                                                       useDisplayLists);
-        return tempGlyph;
+        return NULL;
     }
 
-    err = face.Error();
-    return NULL;
+    return new FTPolygonGlyph(ftGlyph, myimpl->outset,
+                              myimpl->useDisplayLists);
 }
 
+
+//
+//  FTPolygonFontImpl
+//
+
+
diff --git a/src/FTFont/FTPolygonFontImpl.h b/src/FTFont/FTPolygonFontImpl.h
index 8943937..02c98bf 100644
--- a/src/FTFont/FTPolygonFontImpl.h
+++ b/src/FTFont/FTPolygonFontImpl.h
@@ -35,12 +35,13 @@ class FTPolygonFontImpl : public FTFontImpl
     friend class FTPolygonFont;
 
     protected:
-        FTPolygonFontImpl(const char* fontFilePath) :
-            FTFontImpl(fontFilePath), outset(0.0f) {};
+        FTPolygonFontImpl(FTFont *ftFont, const char* fontFilePath) :
+            FTFontImpl(ftFont, fontFilePath), outset(0.0f) {};
 
-        FTPolygonFontImpl(const unsigned char *pBufferBytes,
+        FTPolygonFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
                           size_t bufferSizeInBytes) :
-            FTFontImpl(pBufferBytes, bufferSizeInBytes), outset(0.0f) {};
+            FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
+            outset(0.0f) {};
 
         /**
          * Set the outset distance for the font. Only implemented by
@@ -52,14 +53,6 @@ class FTPolygonFontImpl : public FTFontImpl
 
     private:
         /**
-         * Construct a FTPolygonGlyph.
-         *
-         * @param g The glyph index NOT the char code.
-         * @return  An FTPolygonGlyph or <code>null</code> on failure.
-         */
-        virtual FTGlyph* MakeGlyph(unsigned int g);
-
-        /**
          * The outset distance (front and back) for the font.
          */
         float outset;
diff --git a/src/FTFont/FTTextureFont.cpp b/src/FTFont/FTTextureFont.cpp
index 741f5b8..b3e9e80 100644
--- a/src/FTFont/FTTextureFont.cpp
+++ b/src/FTFont/FTTextureFont.cpp
@@ -43,14 +43,14 @@
 
 FTTextureFont::FTTextureFont(char const *fontFilePath)
 {
-    impl = new FTTextureFontImpl(fontFilePath);
+    impl = new FTTextureFontImpl(this, fontFilePath);
 }
 
 
 FTTextureFont::FTTextureFont(const unsigned char *pBufferBytes,
                              size_t bufferSizeInBytes)
 {
-    impl = new FTTextureFontImpl(pBufferBytes, bufferSizeInBytes);
+    impl = new FTTextureFontImpl(this, pBufferBytes, bufferSizeInBytes);
 }
 
 
@@ -60,6 +60,18 @@ FTTextureFont::~FTTextureFont()
 }
 
 
+FTGlyph* FTTextureFont::MakeGlyph(FT_GlyphSlot ftGlyph)
+{
+    FTTextureFontImpl *myimpl = dynamic_cast<FTTextureFontImpl *>(impl);
+    if(!myimpl)
+    {
+        return NULL;
+    }
+
+    return myimpl->MakeGlyph(ftGlyph);
+}
+
+
 //
 //  FTTextureFontImpl
 //
@@ -79,8 +91,8 @@ static inline GLuint NextPowerOf2(GLuint in)
 }
 
 
-FTTextureFontImpl::FTTextureFontImpl(const char* fontFilePath)
-:   FTFontImpl(fontFilePath),
+FTTextureFontImpl::FTTextureFontImpl(FTFont *ftFont, const char* fontFilePath)
+:   FTFontImpl(ftFont, fontFilePath),
     maximumGLTextureSize(0),
     textureWidth(0),
     textureHeight(0),
@@ -94,9 +106,10 @@ FTTextureFontImpl::FTTextureFontImpl(const char* fontFilePath)
 }
 
 
-FTTextureFontImpl::FTTextureFontImpl(const unsigned char *pBufferBytes,
-                                         size_t bufferSizeInBytes)
-:   FTFontImpl(pBufferBytes, bufferSizeInBytes),
+FTTextureFontImpl::FTTextureFontImpl(FTFont *ftFont,
+                                     const unsigned char *pBufferBytes,
+                                     size_t bufferSizeInBytes)
+:   FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
     maximumGLTextureSize(0),
     textureWidth(0),
     textureHeight(0),
@@ -120,47 +133,39 @@ FTTextureFontImpl::~FTTextureFontImpl()
 }
 
 
-FTGlyph* FTTextureFontImpl::MakeGlyph(unsigned int glyphIndex)
+FTGlyph* FTTextureFontImpl::MakeGlyph(FT_GlyphSlot ftGlyph)
 {
-    FT_GlyphSlot ftGlyph = face.Glyph(glyphIndex, FT_LOAD_NO_HINTING
-                                                   | FT_LOAD_NO_BITMAP);
+    glyphHeight = static_cast<int>(charSize.Height() + 0.5);
+    glyphWidth = static_cast<int>(charSize.Width() + 0.5);
+
+    if(glyphHeight < 1) glyphHeight = 1;
+    if(glyphWidth < 1) glyphWidth = 1;
 
-    if(ftGlyph)
+    if(textureIDList.empty())
     {
-        glyphHeight = static_cast<int>(charSize.Height() + 0.5);
-        glyphWidth = static_cast<int>(charSize.Width() + 0.5);
+        textureIDList.push_back(CreateTexture());
+        xOffset = yOffset = padding;
+    }
 
-        if(glyphHeight < 1) glyphHeight = 1;
-        if(glyphWidth < 1) glyphWidth = 1;
+    if(xOffset > (textureWidth - glyphWidth))
+    {
+        xOffset = padding;
+        yOffset += glyphHeight;
 
-        if(textureIDList.empty())
+        if(yOffset > (textureHeight - glyphHeight))
         {
             textureIDList.push_back(CreateTexture());
-            xOffset = yOffset = padding;
-        }
-
-        if(xOffset > (textureWidth - glyphWidth))
-        {
-            xOffset = padding;
-            yOffset += glyphHeight;
-
-            if(yOffset > (textureHeight - glyphHeight))
-            {
-                textureIDList.push_back(CreateTexture());
-                yOffset = padding;
-            }
+            yOffset = padding;
         }
+    }
 
-        FTTextureGlyph* tempGlyph = new FTTextureGlyph(ftGlyph, textureIDList[textureIDList.size() - 1],
-                                                        xOffset, yOffset, textureWidth, textureHeight);
-        xOffset += static_cast<int>(tempGlyph->BBox().Upper().X() - tempGlyph->BBox().Lower().X() + padding + 0.5);
+    FTTextureGlyph* tempGlyph = new FTTextureGlyph(ftGlyph, textureIDList[textureIDList.size() - 1],
+                                                    xOffset, yOffset, textureWidth, textureHeight);
+    xOffset += static_cast<int>(tempGlyph->BBox().Upper().X() - tempGlyph->BBox().Lower().X() + padding + 0.5);
 
-        --remGlyphs;
-        return tempGlyph;
-    }
+    --remGlyphs;
 
-    err = face.Error();
-    return NULL;
+    return tempGlyph;
 }
 
 
diff --git a/src/FTFont/FTTextureFontImpl.h b/src/FTFont/FTTextureFontImpl.h
index 5b52361..8989bc9 100644
--- a/src/FTFont/FTTextureFontImpl.h
+++ b/src/FTFont/FTTextureFontImpl.h
@@ -37,9 +37,9 @@ class FTTextureFontImpl : public FTFontImpl
     friend class FTTextureFont;
 
     protected:
-        FTTextureFontImpl(const char* fontFilePath);
+        FTTextureFontImpl(FTFont *ftFont, const char* fontFilePath);
 
-        FTTextureFontImpl(const unsigned char *pBufferBytes,
+        FTTextureFontImpl(FTFont *ftFont, const unsigned char *pBufferBytes,
                           size_t bufferSizeInBytes);
 
         virtual ~FTTextureFontImpl();
@@ -86,12 +86,9 @@ class FTTextureFontImpl : public FTFontImpl
 
     private:
         /**
-         * Construct a FTTextureGlyph.
-         *
-         * @param glyphIndex The glyph index NOT the char code.
-         * @return  An FTTextureGlyph or <code>null</code> on failure.
+         * Create an FTTextureGlyph object for the base class.
          */
-        inline virtual FTGlyph* MakeGlyph(unsigned int glyphIndex);
+        FTGlyph* MakeGlyph(FT_GlyphSlot ftGlyph);
 
         /**
          * Get the size of a block of memory required to layout the glyphs
diff --git a/src/FTGL/FTFont.h b/src/FTGL/FTFont.h
index bb056ea..14e2e01 100644
--- a/src/FTGL/FTFont.h
+++ b/src/FTGL/FTFont.h
@@ -57,6 +57,7 @@ class FTGL_EXPORT FTFont
 {
         /* Allow FTLayout classes to access this->impl. */
         friend class FTLayoutImpl;
+        friend class FTFontImpl;
 
     protected:
         FTFont();
@@ -303,6 +304,17 @@ class FTGL_EXPORT FTFont
         FT_Error Error() const;
 
     protected:
+        /**
+         * Construct a glyph of the correct type.
+         *
+         * Clients must override the function and return their specialised
+         * FTGlyph.
+         *
+         * @param slot  A FreeType glyph slot.
+         * @return  An FT****Glyph or <code>null</code> on failure.
+         */
+        virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot) = 0;
+
         FTFontImpl *impl;
 };
 
diff --git a/src/FTGL/FTGLBitmapFont.h b/src/FTGL/FTGLBitmapFont.h
index a2d092d..d2fb1ba 100644
--- a/src/FTGL/FTGLBitmapFont.h
+++ b/src/FTGL/FTGLBitmapFont.h
@@ -67,6 +67,18 @@ class FTGL_EXPORT FTBitmapFont : public FTFont
          * Destructor
          */
         ~FTBitmapFont();
+
+    protected:
+        /**
+         * Construct a glyph of the correct type.
+         *
+         * Clients must override the function and return their specialised
+         * FTGlyph.
+         *
+         * @param slot  A FreeType glyph slot.
+         * @return  An FT****Glyph or <code>null</code> on failure.
+         */
+        virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
 };
 
 #define FTGLBitmapFont FTBitmapFont
diff --git a/src/FTGL/FTGLExtrdFont.h b/src/FTGL/FTGLExtrdFont.h
index c53f9cd..47d6714 100644
--- a/src/FTGL/FTGLExtrdFont.h
+++ b/src/FTGL/FTGLExtrdFont.h
@@ -68,6 +68,18 @@ class FTGL_EXPORT FTExtrudeFont : public FTFont
          * Destructor
          */
         ~FTExtrudeFont();
+
+    protected:
+        /**
+         * Construct a glyph of the correct type.
+         *
+         * Clients must override the function and return their specialised
+         * FTGlyph.
+         *
+         * @param slot  A FreeType glyph slot.
+         * @return  An FT****Glyph or <code>null</code> on failure.
+         */
+        virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
 };
 
 #define FTGLExtrdFont FTExtrudeFont
diff --git a/src/FTGL/FTGLOutlineFont.h b/src/FTGL/FTGLOutlineFont.h
index 90c6ae2..bbf62da 100644
--- a/src/FTGL/FTGLOutlineFont.h
+++ b/src/FTGL/FTGLOutlineFont.h
@@ -67,6 +67,18 @@ class FTGL_EXPORT FTOutlineFont : public FTFont
          * Destructor
          */
         ~FTOutlineFont();
+
+    protected:
+        /**
+         * Construct a glyph of the correct type.
+         *
+         * Clients must override the function and return their specialised
+         * FTGlyph.
+         *
+         * @param slot  A FreeType glyph slot.
+         * @return  An FT****Glyph or <code>null</code> on failure.
+         */
+        virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
 };
 
 #define FTGLOutlineFont FTOutlineFont
diff --git a/src/FTGL/FTGLPixmapFont.h b/src/FTGL/FTGLPixmapFont.h
index b070048..c90b9c5 100644
--- a/src/FTGL/FTGLPixmapFont.h
+++ b/src/FTGL/FTGLPixmapFont.h
@@ -67,6 +67,18 @@ class FTGL_EXPORT FTPixmapFont : public FTFont
          * Destructor
          */
         ~FTPixmapFont();
+
+    protected:
+        /**
+         * Construct a glyph of the correct type.
+         *
+         * Clients must override the function and return their specialised
+         * FTGlyph.
+         *
+         * @param slot  A FreeType glyph slot.
+         * @return  An FT****Glyph or <code>null</code> on failure.
+         */
+        virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
 };
 
 #define FTGLPixmapFont FTPixmapFont
diff --git a/src/FTGL/FTGLPolygonFont.h b/src/FTGL/FTGLPolygonFont.h
index 0985434..1dab097 100644
--- a/src/FTGL/FTGLPolygonFont.h
+++ b/src/FTGL/FTGLPolygonFont.h
@@ -67,6 +67,18 @@ class FTGL_EXPORT FTPolygonFont : public FTFont
          * Destructor
          */
         ~FTPolygonFont();
+
+    protected:
+        /**
+         * Construct a glyph of the correct type.
+         *
+         * Clients must override the function and return their specialised
+         * FTGlyph.
+         *
+         * @param slot  A FreeType glyph slot.
+         * @return  An FT****Glyph or <code>null</code> on failure.
+         */
+        virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
 };
 
 #define FTGLPolygonFont FTPolygonFont
diff --git a/src/FTGL/FTGLTextureFont.h b/src/FTGL/FTGLTextureFont.h
index 5f5d13d..03991e9 100644
--- a/src/FTGL/FTGLTextureFont.h
+++ b/src/FTGL/FTGLTextureFont.h
@@ -67,6 +67,18 @@ class  FTGL_EXPORT FTTextureFont : public FTFont
          * Destructor
          */
         virtual ~FTTextureFont();
+
+    protected:
+        /**
+         * Construct a glyph of the correct type.
+         *
+         * Clients must override the function and return their specialised
+         * FTGlyph.
+         *
+         * @param slot  A FreeType glyph slot.
+         * @return  An FT****Glyph or <code>null</code> on failure.
+         */
+        virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot);
 };
 
 #define FTGLTextureFont FTTextureFont