Annotation of mstools/mfc/samples/showfont/drawing.cpp, revision 1.1

1.1     ! root        1: // drawing.cpp : Drawing functions for the ShowFont main window.
        !             2: //
        !             3: // This is a part of the Microsoft Foundation Classes C++ library. 
        !             4: // Copyright (C) 1992 Microsoft Corporation 
        !             5: // All rights reserved. 
        !             6: //  
        !             7: // This source code is only intended as a supplement to the 
        !             8: // Microsoft Foundation Classes Reference and Microsoft 
        !             9: // QuickHelp documentation provided with the library. 
        !            10: // See these sources for detailed information regarding the 
        !            11: // Microsoft Foundation Classes product.
        !            12: 
        !            13: #include "showfont.h"
        !            14: 
        !            15: /////////////////////////////////////////////////////////////////////////////
        !            16: 
        !            17: // InitDC:
        !            18: // Prepare for drawing in this DC.
        !            19: //
        !            20: void CMainWindow::InitDC(CDC& dc)
        !            21: {
        !            22:        dc.SetBkMode(nBkMode);
        !            23:        dc.SetBkColor(rgbBkColor);
        !            24:        dc.SetTextColor(rgbTextColor);
        !            25:        dc.SetTextAlign(nAlignLCR | nAlignTBB);
        !            26: }
        !            27: 
        !            28: /////////////////////////////////////////////////////////////////////////////
        !            29: 
        !            30: // GetStringExtent:
        !            31: // A helper function which calculates the extent of a string in a given font.
        !            32: //
        !            33: static short GetStringExtent(CDC& dc, PSTR pString, CFont* font)
        !            34: {
        !            35:        CFont* oldFont = dc.SelectObject(font);
        !            36:        if (oldFont == NULL)
        !            37:                return 0;
        !            38: 
        !            39:        CSize sizeExtent = dc.GetTextExtent(pString, strlen(pString));
        !            40:        dc.SelectObject(oldFont);
        !            41:        return (sizeExtent.cx);
        !            42: }
        !            43: 
        !            44: /////////////////////////////////////////////////////////////////////////////
        !            45: 
        !            46: // StringOut:
        !            47: // Helper routine for font-specific text out.
        !            48: //
        !            49: static short StringOut(CDC& dc, short x, short y, PSTR pString, CFont* newFont)
        !            50: {
        !            51:        CFont* oldFont = dc.SelectObject(newFont);
        !            52:        if (oldFont == NULL)
        !            53:                return 0;
        !            54:        CSize sizeExtent = dc.GetTextExtent(pString, strlen(pString));
        !            55:        dc.TextOut(x, y, pString, strlen(pString));
        !            56:        dc.SelectObject(oldFont);
        !            57:        return (sizeExtent.cx);
        !            58: }
        !            59: 
        !            60: /////////////////////////////////////////////////////////////////////////////
        !            61: 
        !            62: // ShowString:
        !            63: // Draw the string in the client area of this window at the current point.
        !            64: //
        !            65: void CMainWindow::ShowString()
        !            66: {
        !            67:        short nAlign;
        !            68:        CFont italicFont, underlineFont, strikeOutFont, boldFont;
        !            69: 
        !            70:        LOGFONT logFont;
        !            71:        pTheFont->GetObject(sizeof(LOGFONT), &logFont);
        !            72:        logFont.lfItalic = TRUE;
        !            73:        italicFont.CreateFontIndirect(&logFont);
        !            74: 
        !            75:        logFont.lfItalic = FALSE;
        !            76:        logFont.lfUnderline = TRUE;
        !            77:        underlineFont.CreateFontIndirect(&logFont);
        !            78: 
        !            79:        logFont.lfUnderline = FALSE;
        !            80:        logFont.lfStrikeOut = TRUE;
        !            81:        strikeOutFont.CreateFontIndirect(&logFont);
        !            82: 
        !            83:        logFont.lfStrikeOut = FALSE;
        !            84:        logFont.lfWeight = FW_BOLD;
        !            85:        boldFont.CreateFontIndirect(&logFont);
        !            86: 
        !            87:        // Draw text examples.
        !            88:        //
        !            89:        CClientDC dc(this);
        !            90:        InitDC(dc);
        !            91:        int x = ptCurrent.x;
        !            92:        int y = ptCurrent.y;
        !            93: 
        !            94:        nAlign =  nAlignLCR | nAlignTBB;    /* GetTextAlign(hDC); */
        !            95: 
        !            96:        if ((nAlign & TA_CENTER) == TA_CENTER)
        !            97:        {
        !            98:                int tmpX = x;
        !            99:                nAlignLCR = TA_LEFT;
        !           100:                dc.SetTextAlign(nAlignLCR | nAlignTBB);
        !           101:                x += StringOut(dc, x, y, ", and ", pTheFont);
        !           102:                x += StringOut(dc, x, y, "strikeout", &strikeOutFont);
        !           103:                x += StringOut(dc, x, y, " in a single line.", pTheFont);
        !           104:                x = tmpX;
        !           105: 
        !           106:                nAlignLCR = TA_RIGHT;
        !           107:                dc.SetTextAlign(nAlignLCR | nAlignTBB);
        !           108:                x -= StringOut(dc, x, y, "underline", &underlineFont);
        !           109:                x -= StringOut(dc, x, y, ", ", pTheFont);
        !           110:                x -= StringOut(dc, x, y, "italic", &italicFont);
        !           111:                x -= StringOut(dc, x, y, ", ", pTheFont);
        !           112:                x -= StringOut(dc, x, y, "bold", &boldFont);
        !           113:                x -= StringOut(dc, x, y, "You can use ", pTheFont);
        !           114:                nAlignLCR = TA_CENTER;
        !           115:        }
        !           116:        else if ((nAlign & TA_CENTER) == TA_RIGHT)
        !           117:        {
        !           118:                x -= StringOut(dc, x, y, " in a single line.", pTheFont);
        !           119:                x -= StringOut(dc, x, y, "strikeout", &strikeOutFont);
        !           120:                x -= StringOut(dc, x, y, ", and ", pTheFont);
        !           121:                x -= StringOut(dc, x, y, "underline", &underlineFont);
        !           122:                x -= StringOut(dc, x, y, ", ", pTheFont);
        !           123:                x -= StringOut(dc, x, y, "italic", &italicFont);
        !           124:                x -= StringOut(dc, x, y, ", ", pTheFont);
        !           125:                x -= StringOut(dc, x, y, "bold", &boldFont);
        !           126:                x -= StringOut(dc, x, y, "You can use ", pTheFont);
        !           127:        }
        !           128:        else
        !           129:        {
        !           130:                x += StringOut(dc, x, y, "You can use ", pTheFont);
        !           131:                x += StringOut(dc, x, y, "bold", &boldFont);
        !           132:                x += StringOut(dc, x, y, ", ", pTheFont);
        !           133:                x += StringOut(dc, x, y, "italic", &italicFont);
        !           134:                x += StringOut(dc, x, y, ", ", pTheFont);
        !           135:                x += StringOut(dc, x, y, "underline", &underlineFont);
        !           136:                x += StringOut(dc, x, y, ", and ", pTheFont);
        !           137:                x += StringOut(dc, x, y, "strikeout", &strikeOutFont);
        !           138:                x += StringOut(dc, x, y, " in a single line.", pTheFont);
        !           139:        }
        !           140: }
        !           141: 
        !           142: /////////////////////////////////////////////////////////////////////////////
        !           143: 
        !           144: // ShowCharacterSet:
        !           145: // Similar to ShowString, but show the entire character set in four rows.
        !           146: //
        !           147: void ShowCharacterSet(CDC& dc, CFont* newFont)
        !           148: {
        !           149:        CFont* oldFont = dc.SelectObject(newFont);
        !           150:        if (oldFont == NULL)
        !           151:                return;
        !           152: 
        !           153:        TEXTMETRIC TextMetric;
        !           154: 
        !           155:        dc.GetTextMetrics(&TextMetric);
        !           156:        nLineSpace = (TextMetric.tmHeight + TextMetric.tmExternalLeading)*2;
        !           157: 
        !           158:        int y = ptCurrent.y;
        !           159:        for (int iLine = 0; iLine < 4; iLine++)
        !           160:        {
        !           161:                dc.TextOut(ptCurrent.x, y, outputText[iLine], 64);
        !           162:                y += nLineSpace;
        !           163:        }
        !           164:        dc.SelectObject(oldFont);
        !           165: }
        !           166: 

unix.superglobalmegacorp.com

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