Commit 4f3b5bbd958a4abe05f7d3831b103bb72b9b9488

Werner Lemberg 2006-05-04T07:13:05

* src/lzw/ftlzw2.c: Renamed to... * src/lzw/ftlzw.c: This. * src/lzw/Jamfile, src/lzw/rules.mk: Updated. * builds/mac/FreeType.m68k_cfm.make.txt, builds/mac/FreeType.m68k_far.make.txt, builds/mac/FreeType.ppc_carbon.make.txt, builds/mac/FreeType.ppc_classic.make.txt: Updated.

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
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
diff --git a/ChangeLog b/ChangeLog
index 842cd62..399ebb4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-05-04  Werner Lemberg  <wl@gnu.org>
+
+	* src/lzw/ftlzw2.c: Renamed to...
+	* src/lzw/ftlzw.c: This.
+
+	* src/lzw/Jamfile, src/lzw/rules.mk: Updated.
+
+	* builds/mac/FreeType.m68k_cfm.make.txt,
+	builds/mac/FreeType.m68k_far.make.txt,
+	builds/mac/FreeType.ppc_carbon.make.txt,
+	builds/mac/FreeType.ppc_classic.make.txt: Updated.
+
 2006-05-03  David Turner  <david@freetype.org>
 
 	Allow compilation again with C++ compilers.
@@ -26,17 +38,6 @@
 
 2006-05-02  David Turner  <david@freetype.org>
 
-	* include/freetype/ftstream.h (FT_FRAME_ENTER, FT_FRAME_EXIT,
-	FT_FRAME_EXTRACT, FT_FRAME_RELEASE: Use FT_DEBUG_INNER to report the
-	place where the frames were entered, extracted, exited or released
-	in the memory debugger.
-
-	* src/base/ftstream.c (FT_Stream_ReleaseFrame) [FT_DEBUG_MEMORY]:
-	Call ft_mem_free.
-	(FT_Stream_EnterFrame) [FT_DEBUG_MEMORY]: Use ft_mem_qalloc.
-	(FT_Stream_ExitFrame) [FT_DEBUG_MEMORY]: Use ft_mem_free.
-
-
 	Update the memory management functions and macros to safely deal
 	with array size buffer overflows.  This corresponds to attemps to
 	allocate arrays that are too large.  For an example, consider the
@@ -96,6 +97,17 @@
 	* src/base/ftutil.c: Remove special code for FT_STRICT_ALIASING.
 	(ft_mem_alloc. ft_mem_realloc, ft_mem_qrealloc): Rewrite.
 
+
+	* include/freetype/ftstream.h (FT_FRAME_ENTER, FT_FRAME_EXIT,
+	FT_FRAME_EXTRACT, FT_FRAME_RELEASE): Use FT_DEBUG_INNER to report the
+	place where the frames were entered, extracted, exited or released
+	in the memory debugger.
+
+	* src/base/ftstream.c (FT_Stream_ReleaseFrame) [FT_DEBUG_MEMORY]:
+	Call ft_mem_free.
+	(FT_Stream_EnterFrame) [FT_DEBUG_MEMORY]: Use ft_mem_qalloc.
+	(FT_Stream_ExitFrame) [FT_DEBUG_MEMORY]: Use ft_mem_free.
+
 2006-04-30  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
 
 	* src/base/ftobjs.c (Mac_Read_POST_Resource): Correct pfb_pos
diff --git a/builds/mac/FreeType.m68k_cfm.make.txt b/builds/mac/FreeType.m68k_cfm.make.txt
index d645323..37b7739 100644
--- a/builds/mac/FreeType.m68k_cfm.make.txt
+++ b/builds/mac/FreeType.m68k_cfm.make.txt
@@ -56,7 +56,7 @@ SrcFiles        =  \xB6
 				  :src:cid:type1cid.c \xB6
 				  :src:gxvalid:gxvalid.c \xB6
 				  :src:gzip:ftgzip.c \xB6
-				  :src:lzw:ftlzw2.c \xB6
+				  :src:lzw:ftlzw.c \xB6
 				  :src:otvalid:otvalid.c \xB6
 				  :src:pcf:pcf.c \xB6
 				  :src:pfr:pfr.c \xB6
@@ -100,7 +100,7 @@ ObjFiles-68K    =  \xB6
 				  "{ObjDir}type1cid.c.o" \xB6
 				  "{ObjDir}gxvalid.c.o" \xB6
 				  "{ObjDir}ftgzip.c.o" \xB6
-				  "{ObjDir}ftlzw2.c.o" \xB6
+				  "{ObjDir}ftlzw.c.o" \xB6
 				  "{ObjDir}otvalid.c.o" \xB6
 				  "{ObjDir}pcf.c.o" \xB6
 				  "{ObjDir}pfr.c.o" \xB6
@@ -171,7 +171,7 @@ FreeType.m68k_cfm.o  \xC4\xC4  {ObjFiles-68K} {LibFiles-68K} {\xA5MondoBuild\xA5
 "{ObjDir}type1cid.c.o" \xC4 :src:cid:type1cid.c
 "{ObjDir}gxvalid.c.o" \xC4 :src:gxvalid:gxvalid.c
 "{ObjDir}ftgzip.c.o" \xC4 :src:gzip:ftgzip.c
-"{ObjDir}ftlzw2.c.o" \xC4 :src:lzw:ftlzw2.c
+"{ObjDir}ftlzw.c.o" \xC4 :src:lzw:ftlzw.c
 "{ObjDir}otvalid.c.o" \xC4 :src:otvalid:otvalid.c
 "{ObjDir}pcf.c.o" \xC4 :src:pcf:pcf.c
 "{ObjDir}pfr.c.o" \xC4 :src:pfr:pfr.c
diff --git a/builds/mac/FreeType.m68k_far.make.txt b/builds/mac/FreeType.m68k_far.make.txt
index 256f680..a7527bf 100644
--- a/builds/mac/FreeType.m68k_far.make.txt
+++ b/builds/mac/FreeType.m68k_far.make.txt
@@ -55,7 +55,7 @@ SrcFiles        =  \xB6
 				  :src:cid:type1cid.c \xB6
 				  :src:gxvalid:gxvalid.c \xB6
 				  :src:gzip:ftgzip.c \xB6
-				  :src:lzw:ftlzw2.c \xB6
+				  :src:lzw:ftlzw.c \xB6
 				  :src:otvalid:otvalid.c \xB6
 				  :src:pcf:pcf.c \xB6
 				  :src:pfr:pfr.c \xB6
@@ -99,7 +99,7 @@ ObjFiles-68K    =  \xB6
 				  "{ObjDir}type1cid.c.o" \xB6
 				  "{ObjDir}gxvalid.c.o" \xB6
 				  "{ObjDir}ftgzip.c.o" \xB6
-				  "{ObjDir}ftlzw2.c.o" \xB6
+				  "{ObjDir}ftlzw.c.o" \xB6
 				  "{ObjDir}otvalid.c.o" \xB6
 				  "{ObjDir}pcf.c.o" \xB6
 				  "{ObjDir}pfr.c.o" \xB6
@@ -170,7 +170,7 @@ FreeType.m68k_far.o  \xC4\xC4  {ObjFiles-68K} {LibFiles-68K} {\xA5MondoBuild\xA5
 "{ObjDir}type1cid.c.o" \xC4 :src:cid:type1cid.c
 "{ObjDir}gxvalid.c.o" \xC4 :src:gxvalid:gxvalid.c
 "{ObjDir}ftgzip.c.o" \xC4 :src:gzip:ftgzip.c
-"{ObjDir}ftlzw2.c.o" \xC4 :src:lzw:ftlzw2.c
+"{ObjDir}ftlzw.c.o" \xC4 :src:lzw:ftlzw.c
 "{ObjDir}otvalid.c.o" \xC4 :src:otvalid:otvalid.c
 "{ObjDir}pcf.c.o" \xC4 :src:pcf:pcf.c
 "{ObjDir}pfr.c.o" \xC4 :src:pfr:pfr.c
diff --git a/builds/mac/FreeType.ppc_carbon.make.txt b/builds/mac/FreeType.ppc_carbon.make.txt
index 55198cc..3e0a689 100644
--- a/builds/mac/FreeType.ppc_carbon.make.txt
+++ b/builds/mac/FreeType.ppc_carbon.make.txt
@@ -56,7 +56,7 @@ SrcFiles        =  \xB6
 				  :src:cid:type1cid.c \xB6
 				  :src:gxvalid:gxvalid.c \xB6
 				  :src:gzip:ftgzip.c \xB6
-				  :src:lzw:ftlzw2.c \xB6
+				  :src:lzw:ftlzw.c \xB6
 				  :src:otvalid:otvalid.c \xB6
 				  :src:pcf:pcf.c \xB6
 				  :src:pfr:pfr.c \xB6
@@ -100,7 +100,7 @@ ObjFiles-PPC    =  \xB6
 				  "{ObjDir}type1cid.c.x" \xB6
 				  "{ObjDir}gxvalid.c.x" \xB6
 				  "{ObjDir}ftgzip.c.x" \xB6
-				  "{ObjDir}ftlzw2.c.x" \xB6
+				  "{ObjDir}ftlzw.c.x" \xB6
 				  "{ObjDir}otvalid.c.x" \xB6
 				  "{ObjDir}pcf.c.x" \xB6
 				  "{ObjDir}pfr.c.x" \xB6
@@ -171,7 +171,7 @@ FreeType.ppc_carbon.o  \xC4\xC4  {ObjFiles-PPC} {LibFiles-PPC} {\xA5MondoBuild\x
 "{ObjDir}type1cid.c.x" \xC4 :src:cid:type1cid.c
 "{ObjDir}gxvalid.c.x" \xC4 :src:gxvalid:gxvalid.c
 "{ObjDir}ftgzip.c.x" \xC4 :src:gzip:ftgzip.c
-"{ObjDir}ftlzw2.c.x" \xC4 :src:lzw:ftlzw2.c
+"{ObjDir}ftlzw.c.x" \xC4 :src:lzw:ftlzw.c
 "{ObjDir}otvalid.c.x" \xC4 :src:otvalid:otvalid.c
 "{ObjDir}pcf.c.x" \xC4 :src:pcf:pcf.c
 "{ObjDir}pfr.c.x" \xC4 :src:pfr:pfr.c
diff --git a/builds/mac/FreeType.ppc_classic.make.txt b/builds/mac/FreeType.ppc_classic.make.txt
index 9478d9b..727f359 100644
--- a/builds/mac/FreeType.ppc_classic.make.txt
+++ b/builds/mac/FreeType.ppc_classic.make.txt
@@ -56,7 +56,7 @@ SrcFiles        =  \xB6
 				  :src:cid:type1cid.c \xB6
 				  :src:gxvalid:gxvalid.c \xB6
 				  :src:gzip:ftgzip.c \xB6
-				  :src:lzw:ftlzw2.c \xB6
+				  :src:lzw:ftlzw.c \xB6
 				  :src:otvalid:otvalid.c \xB6
 				  :src:pcf:pcf.c \xB6
 				  :src:pfr:pfr.c \xB6
@@ -100,7 +100,7 @@ ObjFiles-PPC    =  \xB6
 				  "{ObjDir}type1cid.c.x" \xB6
 				  "{ObjDir}gxvalid.c.x" \xB6
 				  "{ObjDir}ftgzip.c.x" \xB6
-				  "{ObjDir}ftlzw2.c.x" \xB6
+				  "{ObjDir}ftlzw.c.x" \xB6
 				  "{ObjDir}otvalid.c.x" \xB6
 				  "{ObjDir}pcf.c.x" \xB6
 				  "{ObjDir}pfr.c.x" \xB6
@@ -171,7 +171,7 @@ FreeType.ppc_classic.o  \xC4\xC4  {ObjFiles-PPC} {LibFiles-PPC} {\xA5MondoBuild\
 "{ObjDir}type1cid.c.x" \xC4 :src:cid:type1cid.c
 "{ObjDir}gxvalid.c.x" \xC4 :src:gxvalid:gxvalid.c
 "{ObjDir}ftgzip.c.x" \xC4 :src:gzip:ftgzip.c
-"{ObjDir}ftlzw2.c.x" \xC4 :src:lzw:ftlzw2.c
+"{ObjDir}ftlzw.c.x" \xC4 :src:lzw:ftlzw.c
 "{ObjDir}otvalid.c.x" \xC4 :src:otvalid:otvalid.c
 "{ObjDir}pcf.c.x" \xC4 :src:pcf:pcf.c
 "{ObjDir}pfr.c.x" \xC4 :src:pfr:pfr.c
diff --git a/src/lzw/Jamfile b/src/lzw/Jamfile
index f14b8c3..6f1f516 100644
--- a/src/lzw/Jamfile
+++ b/src/lzw/Jamfile
@@ -1,6 +1,6 @@
 # FreeType 2 src/lzw Jamfile
 #
-# Copyright 2004 by
+# Copyright 2004, 2006 by
 # David Turner, Robert Wilhelm, and Werner Lemberg.
 #
 # This file is part of the FreeType project, and may only be used, modified,
@@ -11,7 +11,6 @@
 
 SubDir  FT2_TOP $(FT2_SRC_DIR) lzw ;
 
-Library  $(FT2_LIB) : ftlzw2.c ;
+Library  $(FT2_LIB) : ftlzw.c ;
 
 # end of src/lzw Jamfile
-
diff --git a/src/lzw/ftlzw.c b/src/lzw/ftlzw.c
new file mode 100644
index 0000000..45fbf7b
--- /dev/null
+++ b/src/lzw/ftlzw.c
@@ -0,0 +1,413 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftlzw.c                                                                */
+/*                                                                         */
+/*    FreeType support for .Z compressed files.                            */
+/*                                                                         */
+/*  This optional component relies on NetBSD's zopen().  It should mainly  */
+/*  be used to parse compressed PCF fonts, as found with many X11 server   */
+/*  distributions.                                                         */
+/*                                                                         */
+/*  Copyright 2004, 2005, 2006 by                                          */
+/*  Albert Chin-A-Young.                                                   */
+/*                                                                         */
+/*  Based on code in src/gzip/ftgzip.c, Copyright 2004 by                  */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+#include <ft2build.h>
+#include FT_INTERNAL_MEMORY_H
+#include FT_INTERNAL_STREAM_H
+#include FT_INTERNAL_DEBUG_H
+#include FT_LZW_H
+#include <string.h>
+#include <stdio.h>
+
+
+#include FT_MODULE_ERRORS_H
+
+#undef __FTERRORS_H__
+
+#define FT_ERR_PREFIX  LZW_Err_
+#define FT_ERR_BASE    FT_Mod_Err_LZW
+
+#include FT_ERRORS_H
+
+
+#ifdef FT_CONFIG_OPTION_USE_LZW
+
+#include "ftzopen.h"
+
+
+/***************************************************************************/
+/***************************************************************************/
+/*****                                                                 *****/
+/*****                  M E M O R Y   M A N A G E M E N T              *****/
+/*****                                                                 *****/
+/***************************************************************************/
+/***************************************************************************/
+
+/***************************************************************************/
+/***************************************************************************/
+/*****                                                                 *****/
+/*****                   F I L E   D E S C R I P T O R                 *****/
+/*****                                                                 *****/
+/***************************************************************************/
+/***************************************************************************/
+
+#define FT_LZW_BUFFER_SIZE  4096
+
+  typedef struct  FT_LZWFileRec_
+  {
+    FT_Stream       source;         /* parent/source stream        */
+    FT_Stream       stream;         /* embedding stream            */
+    FT_Memory       memory;         /* memory allocator            */
+    FT_LzwStateRec  lzw;            /* lzw decompressor state      */
+
+    FT_Byte         buffer[FT_LZW_BUFFER_SIZE]; /* output buffer      */
+    FT_ULong        pos;                        /* position in output */
+    FT_Byte*        cursor;
+    FT_Byte*        limit;
+
+  } FT_LZWFileRec, *FT_LZWFile;
+
+
+  /* check and skip .Z header */
+  static FT_Error
+  ft_lzw_check_header( FT_Stream  stream )
+  {
+    FT_Error  error;
+    FT_Byte   head[2];
+
+
+    if ( FT_STREAM_SEEK( 0 )       ||
+         FT_STREAM_READ( head, 2 ) )
+      goto Exit;
+
+    /* head[0] && head[1] are the magic numbers */
+    if ( head[0] != 0x1f ||
+         head[1] != 0x9d )
+      error = LZW_Err_Invalid_File_Format;
+
+  Exit:
+    return error;
+  }
+
+
+  static FT_Error
+  ft_lzw_file_init( FT_LZWFile  zip,
+                    FT_Stream   stream,
+                    FT_Stream   source )
+  {
+    FT_LzwState  lzw   = &zip->lzw;
+    FT_Error     error = LZW_Err_Ok;
+
+
+    zip->stream = stream;
+    zip->source = source;
+    zip->memory = stream->memory;
+
+    zip->limit  = zip->buffer + FT_LZW_BUFFER_SIZE;
+    zip->cursor = zip->limit;
+    zip->pos    = 0;
+
+    /* check and skip .Z header */
+    {
+      stream = source;
+
+      error = ft_lzw_check_header( source );
+      if ( error )
+        goto Exit;
+    }
+
+    /* initialize internal lzw variable */
+    ft_lzwstate_init( lzw, source );
+
+  Exit:
+    return error;
+  }
+
+
+  static void
+  ft_lzw_file_done( FT_LZWFile  zip )
+  {
+    /* clear the rest */
+    ft_lzwstate_done( &zip->lzw );
+
+    zip->memory = NULL;
+    zip->source = NULL;
+    zip->stream = NULL;
+  }
+
+
+  static FT_Error
+  ft_lzw_file_reset( FT_LZWFile  zip )
+  {
+    FT_Stream  stream = zip->source;
+    FT_Error   error;
+
+
+    if ( !FT_STREAM_SEEK( 0 ) )
+    {
+      ft_lzwstate_reset( &zip->lzw );
+
+      zip->limit  = zip->buffer + FT_LZW_BUFFER_SIZE;
+      zip->cursor = zip->limit;
+      zip->pos    = 0;
+    }
+
+    return error;
+  }
+
+
+  static FT_Error
+  ft_lzw_file_fill_output( FT_LZWFile  zip )
+  {
+    FT_LzwState  lzw = &zip->lzw;
+    FT_ULong     count;
+    FT_Error     error   = 0;
+
+
+    zip->cursor = zip->buffer;
+
+    count = ft_lzwstate_io( lzw, zip->buffer, FT_LZW_BUFFER_SIZE );
+
+    zip->limit = zip->cursor + count;
+
+    if ( count == 0 )
+      error = LZW_Err_Invalid_Stream_Operation;
+
+    return error;
+  }
+
+
+  /* fill output buffer; `count' must be <= FT_LZW_BUFFER_SIZE */
+  static FT_Error
+  ft_lzw_file_skip_output( FT_LZWFile  zip,
+                           FT_ULong    count )
+  {
+    FT_Error  error = LZW_Err_Ok;
+
+
+    /* first, we skip what we can from the output buffer */
+    {
+      FT_ULong  delta = (FT_ULong)( zip->limit - zip->cursor );
+
+
+      if ( delta >= count )
+        delta = count;
+
+      zip->cursor += delta;
+      zip->pos    += delta;
+
+      count -= delta;
+    }
+
+    /* next, we skip as many bytes remaining as possible */
+    while ( count > 0 )
+    {
+      FT_ULong  delta = FT_LZW_BUFFER_SIZE;
+      FT_ULong  numread;
+
+
+      if ( delta > count )
+        delta = count;
+
+      numread = ft_lzwstate_io( &zip->lzw, NULL, delta );
+      if ( numread < delta )
+      {
+        /* not enough bytes */
+        error = LZW_Err_Invalid_Stream_Operation;
+        break;
+      }
+
+      zip->pos += delta;
+      count    -= delta;
+    }
+
+    return error;
+  }
+
+
+  static FT_ULong
+  ft_lzw_file_io( FT_LZWFile  zip,
+                  FT_ULong    pos,
+                  FT_Byte*    buffer,
+                  FT_ULong    count )
+  {
+    FT_ULong  result = 0;
+    FT_Error  error;
+
+
+    /* seeking backwards. */
+    if ( pos < zip->pos )
+    {
+      /* If the new position is within the output buffer, simply       */
+      /* decrement pointers, otherwise we reset the stream completely! */
+      if ( ( zip->pos - pos ) <= (FT_ULong)( zip->cursor - zip->buffer ) )
+      {
+        zip->cursor -= zip->pos - pos;
+        zip->pos     = pos;
+      }
+      else
+      {
+        error = ft_lzw_file_reset( zip );
+        if ( error )
+          goto Exit;
+      }
+    }
+
+    /* skip unwanted bytes */
+    if ( pos > zip->pos )
+    {
+      error = ft_lzw_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) );
+      if ( error )
+        goto Exit;
+    }
+
+    if ( count == 0 )
+      goto Exit;
+
+    /* now read the data */
+    for (;;)
+    {
+      FT_ULong  delta;
+
+
+      delta = (FT_ULong)( zip->limit - zip->cursor );
+      if ( delta >= count )
+        delta = count;
+
+      FT_MEM_COPY( buffer + result, zip->cursor, delta );
+      result      += delta;
+      zip->cursor += delta;
+      zip->pos    += delta;
+
+      count -= delta;
+      if ( count == 0 )
+        break;
+
+      error = ft_lzw_file_fill_output( zip );
+      if ( error )
+        break;
+    }
+
+  Exit:
+    return result;
+  }
+
+
+/***************************************************************************/
+/***************************************************************************/
+/*****                                                                 *****/
+/*****            L Z W   E M B E D D I N G   S T R E A M              *****/
+/*****                                                                 *****/
+/***************************************************************************/
+/***************************************************************************/
+
+  static void
+  ft_lzw_stream_close( FT_Stream  stream )
+  {
+    FT_LZWFile  zip    = (FT_LZWFile)stream->descriptor.pointer;
+    FT_Memory   memory = stream->memory;
+
+
+    if ( zip )
+    {
+      /* finalize lzw file descriptor */
+      ft_lzw_file_done( zip );
+
+      FT_FREE( zip );
+
+      stream->descriptor.pointer = NULL;
+    }
+  }
+
+
+  static FT_ULong
+  ft_lzw_stream_io( FT_Stream  stream,
+                    FT_ULong   pos,
+                    FT_Byte*   buffer,
+                    FT_ULong   count )
+  {
+    FT_LZWFile  zip = (FT_LZWFile)stream->descriptor.pointer;
+
+
+    return ft_lzw_file_io( zip, pos, buffer, count );
+  }
+
+
+  FT_EXPORT_DEF( FT_Error )
+  FT_Stream_OpenLZW( FT_Stream  stream,
+                     FT_Stream  source )
+  {
+    FT_Error    error;
+    FT_Memory   memory = source->memory;
+    FT_LZWFile  zip;
+
+
+    /*
+     *  Check the header right now; this prevents allocation of a huge
+     *  LZWFile object (400 KByte of heap memory) if not necessary.
+     *
+     *  Did I mention that you should never use .Z compressed font
+     *  files?
+     */
+    error = ft_lzw_check_header( source );
+    if ( error )
+      goto Exit;
+
+    FT_ZERO( stream );
+    stream->memory = memory;
+
+    if ( !FT_NEW( zip ) )
+    {
+      error = ft_lzw_file_init( zip, stream, source );
+      if ( error )
+      {
+        FT_FREE( zip );
+        goto Exit;
+      }
+
+      stream->descriptor.pointer = zip;
+    }
+
+    stream->size  = 0x7FFFFFFFL;  /* don't know the real size! */
+    stream->pos   = 0;
+    stream->base  = 0;
+    stream->read  = ft_lzw_stream_io;
+    stream->close = ft_lzw_stream_close;
+
+  Exit:
+    return error;
+  }
+
+
+#include "ftzopen.c"
+
+
+#else  /* !FT_CONFIG_OPTION_USE_LZW */
+
+
+  FT_EXPORT_DEF( FT_Error )
+  FT_Stream_OpenLZW( FT_Stream  stream,
+                     FT_Stream  source )
+  {
+    FT_UNUSED( stream );
+    FT_UNUSED( source );
+
+    return LZW_Err_Unimplemented_Feature;
+  }
+
+
+#endif /* !FT_CONFIG_OPTION_USE_LZW */
+
+
+/* END */
diff --git a/src/lzw/ftlzw2.c b/src/lzw/ftlzw2.c
deleted file mode 100644
index f051777..0000000
--- a/src/lzw/ftlzw2.c
+++ /dev/null
@@ -1,413 +0,0 @@
-/***************************************************************************/
-/*                                                                         */
-/*  ftlzw2.c                                                               */
-/*                                                                         */
-/*    FreeType support for .Z compressed files (reimplementation).         */
-/*                                                                         */
-/*  This optional component relies on NetBSD's zopen().  It should mainly  */
-/*  be used to parse compressed PCF fonts, as found with many X11 server   */
-/*  distributions.                                                         */
-/*                                                                         */
-/*  Copyright 2004, 2005, 2006 by                                          */
-/*  Albert Chin-A-Young.                                                   */
-/*                                                                         */
-/*  Based on code in src/gzip/ftgzip.c, Copyright 2004 by                  */
-/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
-/*                                                                         */
-/*  This file is part of the FreeType project, and may only be used,       */
-/*  modified, and distributed under the terms of the FreeType project      */
-/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
-/*  this file you indicate that you have read the license and              */
-/*  understand and accept it fully.                                        */
-/*                                                                         */
-/***************************************************************************/
-
-#include <ft2build.h>
-#include FT_INTERNAL_MEMORY_H
-#include FT_INTERNAL_STREAM_H
-#include FT_INTERNAL_DEBUG_H
-#include FT_LZW_H
-#include <string.h>
-#include <stdio.h>
-
-
-#include FT_MODULE_ERRORS_H
-
-#undef __FTERRORS_H__
-
-#define FT_ERR_PREFIX  LZW_Err_
-#define FT_ERR_BASE    FT_Mod_Err_LZW
-
-#include FT_ERRORS_H
-
-
-#ifdef FT_CONFIG_OPTION_USE_LZW
-
-#include "ftzopen.h"
-
-
-/***************************************************************************/
-/***************************************************************************/
-/*****                                                                 *****/
-/*****                  M E M O R Y   M A N A G E M E N T              *****/
-/*****                                                                 *****/
-/***************************************************************************/
-/***************************************************************************/
-
-/***************************************************************************/
-/***************************************************************************/
-/*****                                                                 *****/
-/*****                   F I L E   D E S C R I P T O R                 *****/
-/*****                                                                 *****/
-/***************************************************************************/
-/***************************************************************************/
-
-#define FT_LZW_BUFFER_SIZE  4096
-
-  typedef struct  FT_LZWFileRec_
-  {
-    FT_Stream       source;         /* parent/source stream        */
-    FT_Stream       stream;         /* embedding stream            */
-    FT_Memory       memory;         /* memory allocator            */
-    FT_LzwStateRec  lzw;            /* lzw decompressor state      */
-
-    FT_Byte         buffer[FT_LZW_BUFFER_SIZE]; /* output buffer      */
-    FT_ULong        pos;                        /* position in output */
-    FT_Byte*        cursor;
-    FT_Byte*        limit;
-
-  } FT_LZWFileRec, *FT_LZWFile;
-
-
-  /* check and skip .Z header */
-  static FT_Error
-  ft_lzw_check_header( FT_Stream  stream )
-  {
-    FT_Error  error;
-    FT_Byte   head[2];
-
-
-    if ( FT_STREAM_SEEK( 0 )       ||
-         FT_STREAM_READ( head, 2 ) )
-      goto Exit;
-
-    /* head[0] && head[1] are the magic numbers */
-    if ( head[0] != 0x1f ||
-         head[1] != 0x9d )
-      error = LZW_Err_Invalid_File_Format;
-
-  Exit:
-    return error;
-  }
-
-
-  static FT_Error
-  ft_lzw_file_init( FT_LZWFile  zip,
-                    FT_Stream   stream,
-                    FT_Stream   source )
-  {
-    FT_LzwState  lzw   = &zip->lzw;
-    FT_Error     error = LZW_Err_Ok;
-
-
-    zip->stream = stream;
-    zip->source = source;
-    zip->memory = stream->memory;
-
-    zip->limit  = zip->buffer + FT_LZW_BUFFER_SIZE;
-    zip->cursor = zip->limit;
-    zip->pos    = 0;
-
-    /* check and skip .Z header */
-    {
-      stream = source;
-
-      error = ft_lzw_check_header( source );
-      if ( error )
-        goto Exit;
-    }
-
-    /* initialize internal lzw variable */
-    ft_lzwstate_init( lzw, source );
-
-  Exit:
-    return error;
-  }
-
-
-  static void
-  ft_lzw_file_done( FT_LZWFile  zip )
-  {
-    /* clear the rest */
-    ft_lzwstate_done( &zip->lzw );
-
-    zip->memory = NULL;
-    zip->source = NULL;
-    zip->stream = NULL;
-  }
-
-
-  static FT_Error
-  ft_lzw_file_reset( FT_LZWFile  zip )
-  {
-    FT_Stream  stream = zip->source;
-    FT_Error   error;
-
-
-    if ( !FT_STREAM_SEEK( 0 ) )
-    {
-      ft_lzwstate_reset( &zip->lzw );
-
-      zip->limit  = zip->buffer + FT_LZW_BUFFER_SIZE;
-      zip->cursor = zip->limit;
-      zip->pos    = 0;
-    }
-
-    return error;
-  }
-
-
-  static FT_Error
-  ft_lzw_file_fill_output( FT_LZWFile  zip )
-  {
-    FT_LzwState  lzw = &zip->lzw;
-    FT_ULong     count;
-    FT_Error     error   = 0;
-
-
-    zip->cursor = zip->buffer;
-
-    count = ft_lzwstate_io( lzw, zip->buffer, FT_LZW_BUFFER_SIZE );
-
-    zip->limit = zip->cursor + count;
-
-    if ( count == 0 )
-      error = LZW_Err_Invalid_Stream_Operation;
-
-    return error;
-  }
-
-
-  /* fill output buffer; `count' must be <= FT_LZW_BUFFER_SIZE */
-  static FT_Error
-  ft_lzw_file_skip_output( FT_LZWFile  zip,
-                           FT_ULong    count )
-  {
-    FT_Error  error = LZW_Err_Ok;
-
-
-    /* first, we skip what we can from the output buffer */
-    {
-      FT_ULong  delta = (FT_ULong)( zip->limit - zip->cursor );
-
-
-      if ( delta >= count )
-        delta = count;
-
-      zip->cursor += delta;
-      zip->pos    += delta;
-
-      count -= delta;
-    }
-
-    /* next, we skip as many bytes remaining as possible */
-    while ( count > 0 )
-    {
-      FT_ULong  delta = FT_LZW_BUFFER_SIZE;
-      FT_ULong  numread;
-
-
-      if ( delta > count )
-        delta = count;
-
-      numread = ft_lzwstate_io( &zip->lzw, NULL, delta );
-      if ( numread < delta )
-      {
-        /* not enough bytes */
-        error = LZW_Err_Invalid_Stream_Operation;
-        break;
-      }
-
-      zip->pos += delta;
-      count    -= delta;
-    }
-
-    return error;
-  }
-
-
-  static FT_ULong
-  ft_lzw_file_io( FT_LZWFile  zip,
-                  FT_ULong    pos,
-                  FT_Byte*    buffer,
-                  FT_ULong    count )
-  {
-    FT_ULong  result = 0;
-    FT_Error  error;
-
-
-    /* seeking backwards. */
-    if ( pos < zip->pos )
-    {
-      /* If the new position is within the output buffer, simply       */
-      /* decrement pointers, otherwise we reset the stream completely! */
-      if ( ( zip->pos - pos ) <= (FT_ULong)( zip->cursor - zip->buffer ) )
-      {
-        zip->cursor -= zip->pos - pos;
-        zip->pos     = pos;
-      }
-      else
-      {
-        error = ft_lzw_file_reset( zip );
-        if ( error )
-          goto Exit;
-      }
-    }
-
-    /* skip unwanted bytes */
-    if ( pos > zip->pos )
-    {
-      error = ft_lzw_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) );
-      if ( error )
-        goto Exit;
-    }
-
-    if ( count == 0 )
-      goto Exit;
-
-    /* now read the data */
-    for (;;)
-    {
-      FT_ULong  delta;
-
-
-      delta = (FT_ULong)( zip->limit - zip->cursor );
-      if ( delta >= count )
-        delta = count;
-
-      FT_MEM_COPY( buffer + result, zip->cursor, delta );
-      result      += delta;
-      zip->cursor += delta;
-      zip->pos    += delta;
-
-      count -= delta;
-      if ( count == 0 )
-        break;
-
-      error = ft_lzw_file_fill_output( zip );
-      if ( error )
-        break;
-    }
-
-  Exit:
-    return result;
-  }
-
-
-/***************************************************************************/
-/***************************************************************************/
-/*****                                                                 *****/
-/*****            L Z W   E M B E D D I N G   S T R E A M              *****/
-/*****                                                                 *****/
-/***************************************************************************/
-/***************************************************************************/
-
-  static void
-  ft_lzw_stream_close( FT_Stream  stream )
-  {
-    FT_LZWFile  zip    = (FT_LZWFile)stream->descriptor.pointer;
-    FT_Memory   memory = stream->memory;
-
-
-    if ( zip )
-    {
-      /* finalize lzw file descriptor */
-      ft_lzw_file_done( zip );
-
-      FT_FREE( zip );
-
-      stream->descriptor.pointer = NULL;
-    }
-  }
-
-
-  static FT_ULong
-  ft_lzw_stream_io( FT_Stream  stream,
-                    FT_ULong   pos,
-                    FT_Byte*   buffer,
-                    FT_ULong   count )
-  {
-    FT_LZWFile  zip = (FT_LZWFile)stream->descriptor.pointer;
-
-
-    return ft_lzw_file_io( zip, pos, buffer, count );
-  }
-
-
-  FT_EXPORT_DEF( FT_Error )
-  FT_Stream_OpenLZW( FT_Stream  stream,
-                     FT_Stream  source )
-  {
-    FT_Error    error;
-    FT_Memory   memory = source->memory;
-    FT_LZWFile  zip;
-
-
-    /*
-     *  Check the header right now; this prevents allocation of a huge
-     *  LZWFile object (400 KByte of heap memory) if not necessary.
-     *
-     *  Did I mention that you should never use .Z compressed font
-     *  files?
-     */
-    error = ft_lzw_check_header( source );
-    if ( error )
-      goto Exit;
-
-    FT_ZERO( stream );
-    stream->memory = memory;
-
-    if ( !FT_NEW( zip ) )
-    {
-      error = ft_lzw_file_init( zip, stream, source );
-      if ( error )
-      {
-        FT_FREE( zip );
-        goto Exit;
-      }
-
-      stream->descriptor.pointer = zip;
-    }
-
-    stream->size  = 0x7FFFFFFFL;  /* don't know the real size! */
-    stream->pos   = 0;
-    stream->base  = 0;
-    stream->read  = ft_lzw_stream_io;
-    stream->close = ft_lzw_stream_close;
-
-  Exit:
-    return error;
-  }
-
-
-#include "ftzopen.c"
-
-
-#else  /* !FT_CONFIG_OPTION_USE_LZW */
-
-
-  FT_EXPORT_DEF( FT_Error )
-  FT_Stream_OpenLZW( FT_Stream  stream,
-                     FT_Stream  source )
-  {
-    FT_UNUSED( stream );
-    FT_UNUSED( source );
-
-    return LZW_Err_Unimplemented_Feature;
-  }
-
-
-#endif /* !FT_CONFIG_OPTION_USE_LZW */
-
-
-/* END */
diff --git a/src/lzw/rules.mk b/src/lzw/rules.mk
index 8d44673..5550a48 100644
--- a/src/lzw/rules.mk
+++ b/src/lzw/rules.mk
@@ -3,7 +3,7 @@
 #
 
 
-# Copyright 2004, 2005 by
+# Copyright 2004, 2005, 2006 by
 # Albert Chin-A-Young.
 #
 # Based on src/lzw/rules.mk, Copyright 2002 by
@@ -28,7 +28,7 @@ LZW_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(LZW_DIR))
 
 # LZW support sources (i.e., C files)
 #
-LZW_DRV_SRC := $(LZW_DIR)/ftlzw2.c
+LZW_DRV_SRC := $(LZW_DIR)/ftlzw.c
 
 # LZW support headers
 #
@@ -41,12 +41,12 @@ LZW_DRV_H := $(LZW_DIR)/ftzopen.h \
 #   LZW_DRV_OBJ_M is used during `multi' builds
 #   LZW_DRV_OBJ_S is used during `single' builds
 #
-LZW_DRV_OBJ_M := $(OBJ_DIR)/ftlzw2.$O
-LZW_DRV_OBJ_S := $(OBJ_DIR)/ftlzw2.$O
+LZW_DRV_OBJ_M := $(OBJ_DIR)/ftlzw.$O
+LZW_DRV_OBJ_S := $(OBJ_DIR)/ftlzw.$O
 
 # LZW support source file for single build
 #
-LZW_DRV_SRC_S := $(LZW_DIR)/ftlzw2.c
+LZW_DRV_SRC_S := $(LZW_DIR)/ftlzw.c
 
 
 # LZW support - single object