Back to index

tetex-bin  3.0
t1test.c
Go to the documentation of this file.
00001 /* $XConsortium: t1test.c,v 1.2 91/10/10 11:19:53 rws Exp $ */
00002 /* Copyright International Business Machines,Corp. 1991
00003  * All Rights Reserved
00004  *
00005  * License to use, copy, modify, and distribute this software
00006  * and its documentation for any purpose and without fee is
00007  * hereby granted, provided that the above copyright notice
00008  * appear in all copies and that both that copyright notice and
00009  * this permission notice appear in supporting documentation,
00010  * and that the name of IBM not be used in advertising or
00011  * publicity pertaining to distribution of the software without
00012  * specific, written prior permission.
00013  *
00014  * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
00015  * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
00016  * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
00018  * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
00019  * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
00020  * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
00021  * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
00022  * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
00023  * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00024  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00025  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00026  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00027  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00028  * SOFTWARE.
00029  */
00030 
00031 #include <stdlib.h>
00032 #include "ffilest.h"
00033 #ifdef XSERVER
00034 #include "FSproto.h"
00035 #endif
00036  
00037 void Display();
00038  
00039 #define DECIPOINTSPERINCH 722.7
00040 #define DEFAULTRES 75
00041 #define DEFAULTPOINTSIZE 120
00042  
00043 FontScalableRec vals;
00044 FontEntryRec entry;
00045  
00046 typedef char *encoding[256];
00047 
00048 /* PostScript ISOLatin1Encoding */
00049 
00050 char *ISOLatin1[256] = {
00051         /* '000  000  "00 */ NULL,
00052         /* '001  001  "01 */ NULL,
00053         /* '002  002  "02 */ NULL,
00054         /* '003  003  "03 */ NULL,
00055         /* '004  004  "04 */ NULL,
00056         /* '005  005  "05 */ NULL,
00057         /* '006  006  "06 */ NULL,
00058         /* '007  007  "07 */ NULL,
00059         /* '010  008  "08 */ NULL,
00060         /* '011  009  "09 */ NULL,
00061         /* '012  010  "0A */ NULL,
00062         /* '013  011  "0B */ NULL,
00063         /* '014  012  "0C */ NULL,
00064         /* '015  013  "0D */ NULL,
00065         /* '016  014  "0E */ NULL,
00066         /* '017  015  "0F */ NULL,
00067         /* '020  016  "10 */ NULL,
00068         /* '021  017  "11 */ NULL,
00069         /* '022  018  "12 */ NULL,
00070         /* '023  019  "13 */ NULL,
00071         /* '024  020  "14 */ NULL,
00072         /* '025  021  "15 */ NULL,
00073         /* '026  022  "16 */ NULL,
00074         /* '027  023  "17 */ NULL,
00075         /* '030  024  "18 */ NULL,
00076         /* '031  025  "19 */ NULL,
00077         /* '032  026  "1A */ NULL,
00078         /* '033  027  "1B */ NULL,
00079         /* '034  028  "1C */ NULL,
00080         /* '035  029  "1D */ NULL,
00081         /* '036  030  "1E */ NULL,
00082         /* '037  031  "1F */ NULL,
00083         /* '040  032  "20 */ "space",
00084         /* '041  033  "21 */ "exclam",
00085         /* '042  034  "22 */ "quotedbl",
00086         /* '043  035  "23 */ "numbersign",
00087         /* '044  036  "24 */ "dollar",
00088         /* '045  037  "25 */ "percent",
00089         /* '046  038  "26 */ "ampersand",
00090         /* '047  039  "27 */ "quoteright",
00091         /* '050  040  "28 */ "parenleft",
00092         /* '051  041  "29 */ "parenright",
00093         /* '052  042  "2A */ "asterisk",
00094         /* '053  043  "2B */ "plus",
00095         /* '054  044  "2C */ "comma",
00096         /* '055  045  "2D */ "hyphen",
00097         /* '056  046  "2E */ "period",
00098         /* '057  047  "2F */ "slash",
00099         /* '060  048  "30 */ "zero",
00100         /* '061  049  "31 */ "one",
00101         /* '062  050  "32 */ "two",
00102         /* '063  051  "33 */ "three",
00103         /* '064  052  "34 */ "four",
00104         /* '065  053  "35 */ "five",
00105         /* '066  054  "36 */ "six",
00106         /* '067  055  "37 */ "seven",
00107         /* '070  056  "38 */ "eight",
00108         /* '071  057  "39 */ "nine",
00109         /* '072  058  "3A */ "colon",
00110         /* '073  059  "3B */ "semicolon",
00111         /* '074  060  "3C */ "less",
00112         /* '075  061  "3D */ "equal",
00113         /* '076  062  "3E */ "greater",
00114         /* '077  063  "3F */ "question",
00115         /* '100  064  "40 */ "at",
00116         /* '101  065  "41 */ "A",
00117         /* '102  066  "42 */ "B",
00118         /* '103  067  "43 */ "C",
00119         /* '104  068  "44 */ "D",
00120         /* '105  069  "45 */ "E",
00121         /* '106  070  "46 */ "F",
00122         /* '107  071  "47 */ "G",
00123         /* '110  072  "48 */ "H",
00124         /* '111  073  "49 */ "I",
00125         /* '112  074  "4A */ "J",
00126         /* '113  075  "4B */ "K",
00127         /* '114  076  "4C */ "L",
00128         /* '115  077  "4D */ "M",
00129         /* '116  078  "4E */ "N",
00130         /* '117  079  "4F */ "O",
00131         /* '120  080  "50 */ "P",
00132         /* '121  081  "51 */ "Q",
00133         /* '122  082  "52 */ "R",
00134         /* '123  083  "53 */ "S",
00135         /* '124  084  "54 */ "T",
00136         /* '125  085  "55 */ "U",
00137         /* '126  086  "56 */ "V",
00138         /* '127  087  "57 */ "W",
00139         /* '130  088  "58 */ "X",
00140         /* '131  089  "59 */ "Y",
00141         /* '132  090  "5A */ "Z",
00142         /* '133  091  "5B */ "bracketleft",
00143         /* '134  092  "5C */ "backslash",
00144         /* '135  093  "5D */ "bracketright",
00145         /* '136  094  "5E */ "asciicircum",
00146         /* '137  095  "5F */ "underscore",
00147         /* '140  096  "60 */ "quoteleft",
00148         /* '141  097  "61 */ "a",
00149         /* '142  098  "62 */ "b",
00150         /* '143  099  "63 */ "c",
00151         /* '144  100  "64 */ "d",
00152         /* '145  101  "65 */ "e",
00153         /* '146  102  "66 */ "f",
00154         /* '147  103  "67 */ "g",
00155         /* '150  104  "68 */ "h",
00156         /* '151  105  "69 */ "i",
00157         /* '152  106  "6A */ "j",
00158         /* '153  107  "6B */ "k",
00159         /* '154  108  "6C */ "l",
00160         /* '155  109  "6D */ "m",
00161         /* '156  110  "6E */ "n",
00162         /* '157  111  "6F */ "o",
00163         /* '160  112  "70 */ "p",
00164         /* '161  113  "71 */ "q",
00165         /* '162  114  "72 */ "r",
00166         /* '163  115  "73 */ "s",
00167         /* '164  116  "74 */ "t",
00168         /* '165  117  "75 */ "u",
00169         /* '166  118  "76 */ "v",
00170         /* '167  119  "77 */ "w",
00171         /* '170  120  "78 */ "x",
00172         /* '171  121  "79 */ "y",
00173         /* '172  122  "7A */ "z",
00174         /* '173  123  "7B */ "braceleft",
00175         /* '174  124  "7C */ "bar",
00176         /* '175  125  "7D */ "braceright",
00177         /* '176  126  "7E */ "asciitilde",
00178         /* '177  127  "7F */ NULL,
00179         /* '200  128  "80 */ NULL,
00180         /* '201  129  "81 */ NULL,
00181         /* '202  130  "82 */ NULL,
00182         /* '203  131  "83 */ NULL,
00183         /* '204  132  "84 */ NULL,
00184         /* '205  133  "85 */ NULL,
00185         /* '206  134  "86 */ NULL,
00186         /* '207  135  "87 */ NULL,
00187         /* '210  136  "88 */ NULL,
00188         /* '211  137  "89 */ NULL,
00189         /* '212  138  "8A */ NULL,
00190         /* '213  139  "8B */ NULL,
00191         /* '214  140  "8C */ NULL,
00192         /* '215  141  "8D */ NULL,
00193         /* '216  142  "8E */ NULL,
00194         /* '217  143  "8F */ NULL,
00195         /* '220  144  "90 */ "dotlessi",
00196         /* '221  145  "91 */ "grave",
00197         /* '222  146  "92 */ "acute",
00198         /* '223  147  "93 */ "circumflex",
00199         /* '224  148  "94 */ "tilde",
00200         /* '225  149  "95 */ "macron",
00201         /* '226  150  "96 */ "breve",
00202         /* '227  151  "97 */ "dotaccent",
00203         /* '230  152  "98 */ "dieresis",
00204         /* '231  153  "99 */ NULL,
00205         /* '232  154  "9A */ "ring",
00206         /* '233  155  "9B */ "cedilla",
00207         /* '234  156  "9C */ NULL,
00208         /* '235  157  "9D */ "hungarumlaut",
00209         /* '236  158  "9E */ "ogonek",
00210         /* '237  159  "9F */ "caron",
00211         /* '240  160  "A0 */ "space",
00212         /* '241  161  "A1 */ "exclamdown",
00213         /* '242  162  "A2 */ "cent",
00214         /* '243  163  "A3 */ "sterling",
00215         /* '244  164  "A4 */ "currency",
00216         /* '245  165  "A5 */ "yen",
00217         /* '246  166  "A6 */ "brokenbar",
00218         /* '247  167  "A7 */ "section",
00219         /* '250  168  "A8 */ "dieresis",
00220         /* '251  169  "A9 */ "copyright",
00221         /* '252  170  "AA */ "ordfeminine",
00222         /* '253  171  "AB */ "guillemotleft",
00223         /* '254  172  "AC */ "logicalnot",
00224         /* '255  173  "AD */ "hyphen",
00225         /* '256  174  "AE */ "registered",
00226         /* '257  175  "AF */ "macron",
00227         /* '260  176  "B0 */ "degree",
00228         /* '261  177  "B1 */ "plusminus",
00229         /* '262  178  "B2 */ "twosuperior",
00230         /* '263  179  "B3 */ "threesuperior",
00231         /* '264  180  "B4 */ "acute",
00232         /* '265  181  "B5 */ "mu",
00233         /* '266  182  "B6 */ "paragraph",
00234         /* '267  183  "B7 */ "periodcentered",
00235         /* '270  184  "B8 */ "cedilla",
00236         /* '271  185  "B9 */ "onesuperior",
00237         /* '272  186  "BA */ "ordmasculine",
00238         /* '273  187  "BB */ "guillemotright",
00239         /* '274  188  "BC */ "onequarter",
00240         /* '275  189  "BD */ "onehalf",
00241         /* '276  190  "BE */ "threequarters",
00242         /* '277  191  "BF */ "questiondown",
00243         /* '300  192  "C0 */ "Agrave",
00244         /* '301  193  "C1 */ "Aacute",
00245         /* '302  194  "C2 */ "Acircumflex",
00246         /* '303  195  "C3 */ "Atilde",
00247         /* '304  196  "C4 */ "Adieresis",
00248         /* '305  197  "C5 */ "Aring",
00249         /* '306  198  "C6 */ "AE",
00250         /* '307  199  "C7 */ "Ccedilla",
00251         /* '310  200  "C8 */ "Egrave",
00252         /* '311  201  "C9 */ "Eacute",
00253         /* '312  202  "CA */ "Ecircumflex",
00254         /* '313  203  "CB */ "Edieresis",
00255         /* '314  204  "CC */ "Igrave",
00256         /* '315  205  "CD */ "Iacute",
00257         /* '316  206  "CE */ "Icircumflex",
00258         /* '317  207  "CF */ "Idieresis",
00259         /* '320  208  "D0 */ "Eth",
00260         /* '321  209  "D1 */ "Ntilde",
00261         /* '322  210  "D2 */ "Ograve",
00262         /* '323  211  "D3 */ "Oacute",
00263         /* '324  212  "D4 */ "Ocircumflex",
00264         /* '325  213  "D5 */ "Otilde",
00265         /* '326  214  "D6 */ "Odieresis",
00266         /* '327  215  "D7 */ "multiply",
00267         /* '330  216  "D8 */ "Oslash",
00268         /* '331  217  "D9 */ "Ugrave",
00269         /* '332  218  "DA */ "Uacute",
00270         /* '333  219  "DB */ "Ucircumflex",
00271         /* '334  220  "DC */ "Udieresis",
00272         /* '335  221  "DD */ "Yacute",
00273         /* '336  222  "DE */ "Thorn",
00274         /* '337  223  "DF */ "Germandbls",
00275         /* '340  224  "E0 */ "agrave",
00276         /* '341  225  "E1 */ "aacute",
00277         /* '342  226  "E2 */ "acircumflex",
00278         /* '343  227  "E3 */ "atilde",
00279         /* '344  228  "E4 */ "adieresis",
00280         /* '345  229  "E5 */ "aring",
00281         /* '346  230  "E6 */ "ae",
00282         /* '347  231  "E7 */ "ccedilla",
00283         /* '350  232  "E8 */ "egrave",
00284         /* '351  233  "E9 */ "eacute",
00285         /* '352  234  "EA */ "ecircumflex",
00286         /* '353  235  "EB */ "edieresis",
00287         /* '354  236  "EC */ "igrave",
00288         /* '355  237  "ED */ "iacute",
00289         /* '356  238  "EE */ "icircumflex",
00290         /* '357  239  "EF */ "idieresis",
00291         /* '360  240  "F0 */ "eth",
00292         /* '361  241  "F1 */ "ntilde",
00293         /* '362  242  "F2 */ "ograve",
00294         /* '363  243  "F3 */ "oacute",
00295         /* '364  244  "F4 */ "ocircumflex",
00296         /* '365  245  "F5 */ "otilde",
00297         /* '366  246  "F6 */ "odieresis",
00298         /* '367  247  "F7 */ "divide",
00299         /* '370  248  "F8 */ "oslash",
00300         /* '371  249  "F9 */ "ugrave",
00301         /* '372  250  "FA */ "uacute",
00302         /* '373  251  "FB */ "ucircumflex",
00303         /* '374  252  "FC */ "udieresis",
00304         /* '375  253  "FD */ "yacute",
00305         /* '376  254  "FE */ "thorn",
00306         /* '377  255  "FF */ "ydieresis"};
00307 
00308 int main(argc, argv)
00309        int argc;
00310        char *argv[];
00311 {
00312        int h;
00313        char temp[80];
00314        char file[80];
00315        char glyphcode[1];
00316        FontPtr fontptr;
00317        CharInfoRec *glyphs[1];
00318        int count;
00319        int code;
00320        int rc = -1;
00321        float efactor = 1.0, slant = 0.0;
00322        encoding *ev = &ISOLatin1;
00323  
00324        T1FillVals(&vals);
00325        Type1RegisterFontFileFunctions();
00326        entry.name.name = "-adobe-utopia-medium-r-normal--0-0-0-0-p-0-iso8859-1";
00327  
00328        for (;;) {
00329                printf("T1TEST: ");
00330                gets(temp);
00331                glyphcode[0] = '\0';
00332  
00333                switch(temp[0]) {
00334  
00335                    case 'E':
00336                        if (1 != sscanf(&temp[2], "%f", &efactor))
00337                                printf("expansion factor?\n");
00338                        break;
00339  
00340                    case 'S':
00341                        if (1 != sscanf(&temp[2], "%f", &slant))
00342                                printf("slant?\n");
00343                        break;
00344  
00345                    case 'c':
00346                        if (1 != sscanf(&temp[2], "%c", glyphcode))
00347                                printf("glyph code?\n");
00348                        break;
00349  
00350                    case 'x':
00351                        if (1 != sscanf(&temp[2], "%x", &code))
00352                                printf("glyph code?\n");
00353                        else
00354                                glyphcode[0] = code;
00355                        break;
00356  
00357                    case 'd':
00358                        if (1 != sscanf(&temp[2], "%d", &code))
00359                                printf("glyph code?\n");
00360                        else
00361                                glyphcode[0] = code;
00362                        break;
00363  
00364                    case 'h':
00365                        if (1 != sscanf(&temp[2], "%d", &h))
00366                                printf("height?\n");
00367                        vals.pixel = h;
00368                      vals.point = (vals.pixel * DECIPOINTSPERINCH) / vals.y;
00369                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
00370                             file, &vals, 0, 0, efactor, slant);
00371                        break;
00372  
00373                    case 'f':
00374                        if (1 != sscanf(&temp[2], "%s", file))
00375                                printf("file name?\n");
00376                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
00377                             file, &vals, 0, 0, efactor, slant);
00378                        break;
00379  
00380                    case 't':
00381                        if (1 != sscanf(&temp[2], "%s", file))
00382                                printf("file name?\n");
00383                        vals.pixel = 8;
00384                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
00385                             file, &vals, 0, 0, efactor, slant);
00386                        if (rc != Successful) break;
00387                        vals.pixel = 20;
00388                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
00389                             file, &vals, 0, 0, efactor, slant);
00390                        if (rc != Successful) break;
00391                        vals.pixel = 50;
00392                        rc = Type1OpenScalable(*ev, &fontptr, 0, &entry,
00393                             file, &vals, 0, 0, efactor, slant);
00394                        glyphcode[0] = 'A';
00395                        printf("From font '%s':\n", file);
00396                        break;
00397  
00398                    case 'q':
00399                        return 0;
00400  
00401                    default:
00402                        printf("unknown command '%c', must one of 'ESqfchdxt'\n", temp[0]);
00403  
00404                }
00405                if (rc == Successful) {
00406                       if (glyphcode[0] != '\0') {
00407                               (*fontptr->get_glyphs)(fontptr, 1, glyphcode, 0, &count, glyphs);
00408                               if (count > 0)
00409                                       Display(glyphs[0]);
00410                               else
00411                                       printf("Code %x not valid in this font\n", glyphcode[0]);
00412                       }
00413                }
00414                else
00415                       printf("Bad font (rc = %d, file='%s')\n", rc, file);
00416        }
00417 }
00418  
00419 void Display(glyph)
00420        CharInfoRec *glyph;
00421 {
00422        int h,w;
00423        unsigned char *p;
00424        int data;
00425        int i;
00426  
00427        p = (unsigned char *) glyph->bits;
00428  
00429        printf("Metrics: left=%d, right=%d, w=%d, above=%d, below=%d\n",
00430                glyph->metrics.leftSideBearing,
00431                glyph->metrics.rightSideBearing,
00432                glyph->metrics.characterWidth,
00433                glyph->metrics.ascent,
00434                glyph->metrics.descent);
00435  
00436        for (h=glyph->metrics.ascent + glyph->metrics.descent; --h >= 0;) {
00437                w = glyph->metrics.rightSideBearing - glyph->metrics.leftSideBearing;
00438                while (w > 0) {
00439                        data = *p++;
00440                        for (i=0; i<8; i++) {
00441                                if (--w < 0)
00442                                        break;
00443                                if (data & 0x80)
00444                                        printf("X");
00445                                else
00446                                        printf(".");
00447                                data <<= 1;
00448                        }
00449                }
00450                printf("\n");
00451        }
00452 }
00453  
00454 T1FillVals(vals)
00455     FontScalablePtr vals;
00456 {
00457     fsResolution *res;
00458     int         x_res = DEFAULTRES;
00459     int         y_res = DEFAULTRES;
00460     int         pointsize = DEFAULTPOINTSIZE;  /* decipoints */
00461     int         num_res;
00462  
00463     /* Must have x, y, and pixel */
00464     if (!vals->x || !vals->y || !vals->pixel) {
00465         res = (fsResolution *) GetClientResolutions(&num_res);
00466         if (num_res) {
00467             if (res->x_resolution)
00468                 x_res = res->x_resolution;
00469             if (res->y_resolution)
00470                 y_res = res->y_resolution;
00471             if (res->point_size)
00472                 pointsize = res->point_size;
00473         }
00474         if (!vals->x)
00475             vals->x = x_res;
00476         if (!vals->y)
00477             vals->y = y_res;
00478         if (!vals->point) {
00479             if (!vals->pixel) vals->point = pointsize;
00480             else vals->point = (vals->pixel * DECIPOINTSPERINCH) / vals->y;
00481         }
00482         if (!vals->pixel)
00483             vals->pixel = (vals->point * vals->y) / DECIPOINTSPERINCH;
00484         /* Make sure above arithmetic is normally in range and will
00485            round properly. +++ */
00486     }
00487 }
00488  
00489 int CheckFSFormat(format, fmask, bit, byte, scan, glyph, image)
00490        int format,fmask,*bit,*byte,*scan,*glyph,*image;
00491 {
00492        *bit = *byte = 1;
00493        *glyph = *scan = *image = 1;
00494        return Successful;
00495  
00496 }
00497  
00498 char *MakeAtom(p)
00499        char *p;
00500 {
00501        return p;
00502 }
00503 GetClientResolutions(resP)
00504        int *resP;
00505 {
00506        *resP = 0;
00507 };
00508 
00509 char *Xalloc(size)
00510        int size;
00511 {
00512        extern char *malloc();
00513        return(malloc(size));
00514 }
00515  
00516 void Xfree()
00517 {
00518        free();
00519 }
00520 
00521 FontDefaultFormat() { ; }
00522  
00523 FontFileRegisterRenderer() { ; }
00524  
00525 GenericGetBitmaps() { ; }
00526 GenericGetExtents() { ; }
00527  
00528 FontParseXLFDName() { ; }
00529 FontComputeInfoAccelerators() { ; }