Annotation of mstools/samples/fontview/display.c, revision 1.1

1.1     ! root        1: #include <windows.h>
        !             2: #include <string.h>
        !             3: 
        !             4: // These are the functions in this file:
        !             5: void DrawAscii (HDC hdc, RECT *pRect, WORD direction);
        !             6: 
        !             7: /* A data structure that DrawAscii will use */
        !             8: 
        !             9: char ascii[]=
        !            10:        {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
        !            11:        20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
        !            12:        ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',',
        !            13:        '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        !            14:        ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F',
        !            15:        'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
        !            16:        'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`',
        !            17:        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
        !            18:        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        !            19:        '{', '|', '}', '~', '',
        !            20:        128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
        !            21:        141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
        !            22:        154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
        !            23:        167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
        !            24:        180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192,
        !            25:        193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
        !            26:        206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
        !            27:        219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
        !            28:        232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
        !            29:        245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 000, 000};
        !            30: 
        !            31: /* A function that the CharSet window will use to display the text */
        !            32: 
        !            33: void DrawAscii (
        !            34:        HDC hdc,
        !            35:        RECT *pRect,
        !            36:        WORD direction)
        !            37: {
        !            38:        char *pch;
        !            39:        int h, w, incx, incy, width, l;
        !            40:        int index, wDisplay;
        !            41:        POINT pt;
        !            42:        TEXTMETRIC tm;
        !            43:        BOOL bLineMode = FALSE;
        !            44: 
        !            45:        /* for debugging */
        !            46:        char szTmp [100];
        !            47:        int i, j, result;
        !            48: 
        !            49:        i; j; result; szTmp; //unreferenced
        !            50: 
        !            51:        GetTextMetrics (hdc, &tm);
        !            52:        h = tm.tmHeight;
        !            53:        w = tm.tmMaxCharWidth;
        !            54: 
        !            55:        switch (direction) {
        !            56:                // OS/2 did stuff with character direction... Windows doesn't
        !            57:                default:
        !            58:                        incx = 0;
        !            59:                        incy = h;
        !            60:                        pt.x = 0;
        !            61:                        pt.y = 0;
        !            62:                        break;
        !            63:        }
        !            64: 
        !            65:        pch = &(ascii[tm.tmFirstChar]);
        !            66:        wDisplay = pRect->right -pRect->left;
        !            67: 
        !            68:        if (bLineMode) { // Calculate how long an entire line can be...
        !            69:                while (pch) {
        !            70:                        index = 0;
        !            71:                        width = 0;
        !            72:                        while ((index < (int)strlen(pch))
        !            73:                        && (pt.x + width) < (wDisplay - (w/2)) ) {
        !            74: #if defined (NT)
        !            75:                SIZE size;
        !            76:                GetTextExtentPoint (hdc, pch, ++index, &size);
        !            77:                width = size.cx;
        !            78: #elif defined (WIN16)
        !            79:                width = LOWORD (GetTextExtent (hdc, pch, ++index));
        !            80: #endif
        !            81:                                l = strlen(pch);
        !            82: 
        !            83:                                if ((int)pch[index] > (int)tm.tmLastChar) {
        !            84:                                        break;
        !            85:                                }
        !            86:                        }
        !            87:                        index--;
        !            88: 
        !            89:                        if (index<=0) {
        !            90:                                pch = NULL;
        !            91:                        } else if (index>=(int)strlen(pch)) {
        !            92:                                TextOut (hdc, pt.x, pt.y, pch, strlen(pch));
        !            93:                                pch = NULL;
        !            94:                        } else {
        !            95:                                TextOut (hdc, pt.x, pt.y, pch, index);
        !            96:                                pt.x += incx;
        !            97:                                pt.y += incy;
        !            98:                                pch += index;
        !            99:                        }
        !           100:                }
        !           101:        } else { // One Character at a time...
        !           102:                while (pch[0] && ((int)pch[0]<=(int)tm.tmLastChar)) {
        !           103: #if defined (NT)
        !           104:                SIZE size;
        !           105:                GetTextExtentPoint (hdc, pch, 1, &size);
        !           106:                width = size.cx;
        !           107: #elif defined (WIN16)
        !           108:                width = LOWORD(GetTextExtent (hdc, pch, 1));
        !           109: #endif
        !           110:                        if ((pt.x + width) > wDisplay) {
        !           111:                                pt.x = 0;
        !           112:                                pt.y += incy;
        !           113:                        }
        !           114:                        TextOut (hdc, pt.x, pt.y, pch, 1);
        !           115:                        pt.x += width;
        !           116:                        pch++;
        !           117:                }
        !           118:        }
        !           119: 
        !           120: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.