~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/extras/FreeType/contrib/ftos2/ifi/test.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/extras/FreeType/contrib/ftos2/ifi/test.c,v 1.2 2003/01/12 03:55:43 tsi Exp $ */
 
2
 
 
3
#include <os2.h>
 
4
 
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
#include <string.h>
 
8
#include "32pmifi.h"
 
9
 
 
10
//#define USE_ORIG
 
11
#ifdef USE_ORIG
 
12
#  pragma import (fdhdr, "FONT_DRIVER_DISPATCH_TABLE", "TRUETYPE", 0)
 
13
#else
 
14
#  if defined USE_ATM
 
15
#    pragma import (fdhdr, "FONT_DRIVER_DISPATCH_TABLE", "PMATM", 0)
 
16
#  else
 
17
#    pragma import (fdhdr, "FONT_DRIVER_DISPATCH_TABLE", "FREETYPE", 0)
 
18
#  endif
 
19
#endif
 
20
 
 
21
extern FDHEADER fdhdr;
 
22
 
 
23
char *fontnames[20] = {
 
24
 "G:\\OS2\\MDOS\\WINOS2\\SYSTEM\\SYMBOL.TTF",
 
25
 "G:\\OS2\\MDOS\\WINOS2\\SYSTEM\\WINGDING.TTF",
 
26
 "G:\\PSFONTS\\ARIALB.ttf",
 
27
 "G:\\PSFONTS\\ARIALI.ttf",
 
28
 "G:\\PSFONTS\\ARIALZ.ttf",
 
29
 "G:\\PSFONTS\\COUR.TTF",
 
30
 "G:\\PSFONTS\\COURB.TTF",
 
31
 "G:\\PSFONTS\\COURI.TTF",
 
32
 "G:\\PSFONTS\\COURZ.TTF",
 
33
 "G:\\PSFONTS\\ARIAL.ttf",
 
34
 "G:\\PSFONTS\\TIMESB.TTF",
 
35
 "G:\\PSFONTS\\TIMESI.ttf",
 
36
 "G:\\PSFONTS\\TIMESZ.ttf",
 
37
 "G:\\PSFONTS\\TIMES.TTF",
 
38
 "G:\\PSFONTS\\ARIBLK.ttf",
 
39
 "G:\\CHINESE\\AVSV.TTF",
 
40
 "G:\\CHINESE\\MINGLI.TTC",
 
41
 "D:\\PSFONTS\\TNRMT30.TTF"
 
42
};
 
43
 
 
44
#define FNTNAME1 "\\PSFONTS\\TIMES.TTF"
 
45
#ifdef USE_ATM
 
46
#  define FNTNAME2 "\\PSFONTS\\helv.ofm"
 
47
#else
 
48
#  define FNTNAME2 "\\PSFONTS\\symbol.tTf"
 
49
#endif
 
50
 
 
51
#define BUFSIZE 32768
 
52
 
 
53
void ShowChar(PCHARATTR pca, PBITMAPMETRICS pbmm) {
 
54
   int i, j;
 
55
   int bufwidth = ((pbmm->sizlExtent.cx + 31) & -32) / 8;
 
56
 
 
57
   for (i =0; i <  pbmm->sizlExtent.cy; i++) {
 
58
      for (j = 0; j < bufwidth * 8; j++)
 
59
         if (pca->pBuffer[i * bufwidth + j / 8] & (1 << (7-(j % 8))))
 
60
            printf("*");
 
61
         else
 
62
            printf(" ");
 
63
      printf("\n");
 
64
   }
 
65
}
 
66
 
 
67
void main(int argc, char **argv)
 
68
{
 
69
   char          fname[260];
 
70
   PFDDISPATCH   pfdisp;
 
71
   LONG          rc;
 
72
   HFF           hff, hff2;      /* font file */
 
73
   HFC           hfc, hfc2;      /* font context */
 
74
   static   IFIMETRICS    ifimet[12];      /* IFI metrics */
 
75
   CONTEXTINFO   ci;
 
76
   CHARATTR      charattr; /* character attributes */
 
77
   BITMAPMETRICS bmm;      /* bit-map metrics */
 
78
   PBYTE         buf;
 
79
   int           glyph = 0, i, j;
 
80
   int           numFaces;
 
81
   int           faceIndex = 0;
 
82
 
 
83
   switch (argc) {
 
84
      case 4:
 
85
         strcpy(fname, argv[1]);
 
86
         glyph = atoi(argv[2]);
 
87
         faceIndex = atoi(argv[3]);
 
88
         break;
 
89
 
 
90
      case 2:
 
91
         glyph = atoi(argv[1]);
 
92
      case 1:
 
93
         strcpy(fname, FNTNAME1);
 
94
         break;
 
95
 
 
96
      default:
 
97
         strcpy(fname, argv[1]);
 
98
         glyph = atoi(argv[2]);
 
99
   }
 
100
 
 
101
   buf = (PBYTE)malloc(BUFSIZE);
 
102
   if (strncmp("OS/2 FONT DRIVER", fdhdr.strId, 16)) {
 
103
      printf("Invalid Font Driver\n");
 
104
      return;
 
105
   }
 
106
   printf("Font Driver OK, ");
 
107
   printf("Version %d\n", fdhdr.ulVersion);
 
108
   printf("Technology: %s\n", fdhdr.szTechnology);
 
109
 
 
110
   hff = fdhdr.pfddisp->FdLoadFontFile(fname);
 
111
   printf("Loading font... HFF = %X\n", hff);
 
112
   if (hff == (HFF)0xFFFFFFFF)
 
113
      return;
 
114
 
 
115
/*   rc = fdhdr.pfddisp->FdConvertFontFile("G:\\PSFONTS\\TIMES.TTF",
 
116
           "G:\\PSFONTS", buf); */
 
117
 
 
118
#if 0
 
119
   for (i = 0; i < 18; i++) {
 
120
      hff = fdhdr.pfddisp->FdLoadFontFile(fontnames[i]);
 
121
      if (hff == (HFF)-1) {
 
122
         printf("x");
 
123
         continue;
 
124
      }
 
125
      numFaces = fdhdr.pfddisp->FdQueryFaces(hff, NULL, 0, -1, 0);
 
126
      if (numFaces < 0) {
 
127
         printf("x");
 
128
         continue;
 
129
      }
 
130
      for (j = 0; j < numFaces; j++) {
 
131
         rc = fdhdr.pfddisp->FdQueryFaces(hff, &ifimet[0], 238, 1, j);
 
132
         if (rc < 0) {
 
133
            printf("x");
 
134
            continue;
 
135
         }
 
136
      }
 
137
 
 
138
      rc = fdhdr.pfddisp->FdUnloadFontFile(hff);
 
139
      if (rc)
 
140
         printf("x");
 
141
      else
 
142
         printf(".");
 
143
   }
 
144
   printf("\n");
 
145
#endif
 
146
 
 
147
   hff = fdhdr.pfddisp->FdLoadFontFile(FNTNAME2);
 
148
   hff = fdhdr.pfddisp->FdLoadFontFile(fname);
 
149
   rc = fdhdr.pfddisp->FdUnloadFontFile(hff);
 
150
 
 
151
   hff = fdhdr.pfddisp->FdLoadFontFile(fname);
 
152
   printf("Loading font... HFF = %X\n", hff);
 
153
   if (hff == (HFF)0xFFFFFFFF)
 
154
      return;
 
155
   numFaces = fdhdr.pfddisp->FdQueryFaces(hff, NULL, 0, -1, 0);
 
156
   printf("Number of faces = %d\n", numFaces);
 
157
   rc = fdhdr.pfddisp->FdQueryFaces(hff, &ifimet[0], sizeof(IFIMETRICS), numFaces, 0);
 
158
   printf("Querying faces... RC = %X\n", rc);
 
159
   hfc = fdhdr.pfddisp->FdOpenFontContext(hff, faceIndex);
 
160
   printf("Opening context... HFC = %X\n", hfc);
 
161
   if (hfc == (HFC)0xFFFFFFFF) {
 
162
      rc = fdhdr.pfddisp->FdUnloadFontFile(hff);
 
163
      printf("Unloading font... RC = %X\n", rc);
 
164
   }
 
165
   ci.cb = sizeof(ci);
 
166
   ci.fl = 0;
 
167
/*   ci.sizlPPM.cx = 3618;
 
168
   ci.sizlPPM.cy = 3622;
 
169
   ci.pfxSpot.x = 46340;
 
170
   ci.pfxSpot.y = 46340;
 
171
   ci.matXform.eM11 = 511;
 
172
   ci.matXform.eM12 = 0;
 
173
   ci.matXform.eM21 = 0;
 
174
   ci.matXform.eM22 = 511; */
 
175
   ci.sizlPPM.cx = 3622;
 
176
   ci.sizlPPM.cy = 3622;
 
177
   ci.pfxSpot.x = 46340;
 
178
   ci.pfxSpot.y = 46340;
 
179
   ci.matXform.eM11 = 768;
 
180
   ci.matXform.eM12 = 0;
 
181
   ci.matXform.eM21 = 0;
 
182
   ci.matXform.eM22 = 768;
 
183
 
 
184
   rc = fdhdr.pfddisp->FdQueryFaceAttr(hfc, FD_QUERY_ABC_WIDTHS, buf,
 
185
                                       sizeof(ABC_TRIPLETS), NULL, glyph);
 
186
   printf("Querying face attrs... RC = %d\n", rc);
 
187
   rc = fdhdr.pfddisp->FdQueryFaceAttr(hfc, FD_QUERY_KERNINGPAIRS, buf,
 
188
                                       ifimet[0].cKerningPairs * sizeof(FD_KERNINGPAIRS),
 
189
                                       NULL, 0);
 
190
 
 
191
 
 
192
   rc = fdhdr.pfddisp->FdSetFontContext(hfc, &ci);
 
193
   printf("Setting context... rc = %X\n", rc);
 
194
 
 
195
   charattr.cb = sizeof(charattr);
 
196
   charattr.iQuery = FD_QUERY_BITMAPMETRICS | FD_QUERY_CHARIMAGE;
 
197
//   charattr.iQuery = FD_QUERY_OUTLINE;
 
198
   charattr.gi = glyph;
 
199
   charattr.pBuffer = buf;
 
200
   charattr.cbLen = BUFSIZE;
 
201
   if (rc == -1)
 
202
      return;
 
203
   rc = fdhdr.pfddisp->FdQueryCharAttr(hfc, &charattr, &bmm);
 
204
   printf("Querying char attrs... bytes = %d\n", rc);
 
205
   ShowChar(&charattr, &bmm);
 
206
 
 
207
//   rc = fdhdr.pfddisp->FdQueryCharAttr(hfc, &charattr, &bmm, NULL);
 
208
//   printf("Querying char attrs... bytes = %d\n", rc);
 
209
 
 
210
   hff2 = fdhdr.pfddisp->FdLoadFontFile(FNTNAME2);
 
211
   printf("Loading font... HFF = %X\n", hff2);
 
212
   if (hff2 == (HFF)0xFFFFFFFF)
 
213
      return;
 
214
 
 
215
   charattr.cbLen = 0;
 
216
   rc = fdhdr.pfddisp->FdQueryCharAttr(hfc, &charattr, &bmm);
 
217
   printf("Querying char attrs... bytes = %d\n", rc);
 
218
   rc = fdhdr.pfddisp->FdQueryFaces(hff2, &ifimet[0], sizeof(ifimet), 1, 0);
 
219
   printf("Querying faces... RC = %X\n", rc);
 
220
   hfc2 = fdhdr.pfddisp->FdOpenFontContext(hff2, 0);
 
221
   printf("Opening context... HFC = %X\n", hfc2);
 
222
   if (hfc2 == (HFC)0xFFFFFFFF) {
 
223
      rc = fdhdr.pfddisp->FdUnloadFontFile(hff2);
 
224
      printf("Unloading font... RC = %X\n", rc);
 
225
   }
 
226
   rc = fdhdr.pfddisp->FdCloseFontContext(hfc);
 
227
   printf("Closing context... RC = %X\n", rc);
 
228
   rc = fdhdr.pfddisp->FdUnloadFontFile(hff);
 
229
   printf("Unloading font... RC = %X\n", rc);
 
230
   rc = fdhdr.pfddisp->FdUnloadFontFile(hff);
 
231
   printf("Unloading font... RC = %X\n", rc);
 
232
 
 
233
   rc = fdhdr.pfddisp->FdCloseFontContext(hfc2);
 
234
   printf("Closing context... RC = %X\n", rc);
 
235
   rc = fdhdr.pfddisp->FdUnloadFontFile(hff2);
 
236
   printf("Unloading font... RC = %X\n", rc);
 
237
   rc = fdhdr.pfddisp->FdUnloadFontFile(hff2);
 
238
   printf("Unloading font... RC = %X\n", rc);
 
239
}