home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
FONT.PRG
< prev
next >
Wrap
Text File
|
1994-02-22
|
6KB
|
163 lines
////////////////////////////
//
// Clip-4-Win font demo
//
// Copyright (C) 1992 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
//
// Compile: font /n /w
// Link: /se:600 font achoice,,,,clip4win.def
//
//
// Note: I apologise to those who would prefer "font" to be used
// properly (i.e. as distinct from a type face). I guess
// the MS people either didn't realise the difference or
// didn't care. I'm going to continue the trend. Sorry.
//
////////////////////////////
#include "windows.ch"
#include "font.ch"
#include "textmetr.ch"
static hWnd
static cAppName := "C4WFont"
function main()
local nEvent, hDC, hFont, hOldFont, nColour := RGB(0, 0, 0), i
local aFont := {16, 16, 450, 0, 400, .f., .f., .f., 1, 0, 0, 0, 0, "Arial"}
local aShow := { {200, 200, 300}, {50, 200, 900}, {400, 50, 3150} }
local lDelFont := .f. // this isn't actually needed, because it's
// ok to use DeleteObject() with stock objects
// (it's ignored)
local nKey, aTM
local aStockFonts := ;
{ ;
{"OEM_FIXED_FONT", OEM_FIXED_FONT}, ;
{"ANSI_FIXED_FONT", ANSI_FIXED_FONT}, ;
{"ANSI_VAR_FONT", ANSI_VAR_FONT}, ;
{"SYSTEM_FONT", SYSTEM_FONT}, ;
{"DEVICE_DEFAULT_FONT", DEVICE_DEFAULT_FONT}, ;
{"SYSTEM_FIXED_FONT", SYSTEM_FIXED_FONT} ;
}
hWnd = WinSetup(cAppName, "Clip-4-Win font demo")
SetColor("n/w,+w/n,+w,+w,+w/n")
do while .t.
do while (nEvent := ChkEvent()) == EVENT_NONE
enddo
do case
case nEvent == EVENT_REDRAW
// You can see the difference between ? and @ ... SAY
@ 1,0 say " Press 1 to choose a stock font"
@ 2,0 say " Press 2 to use ChooseFont()..."
SetPos(15, 0)
? " Press 1 to choose a stock font"
? " Press 2 to use ChooseFont()..."
case nEvent == EVENT_KEY .and. (nKey := inkey(0)) == asc("1")
if (i := achoice(5, 5, 20, 75, aColumn(aStockFonts, 1))) != 0
InvalidateRect(hWnd) // clear the window
UpdateWindow(hWnd) // and make sure it's finished
if lDelFont
DeleteObject(C4W_SetFont()) // delete the old font
endif
// this works but is dumb (slow, and thrashes the VMM):
// hFont = GetStockObject(aColumn(aStockFonts, 2)[i])
hFont = GetStockObject(aStockFonts[i, 2])
// NOTE: See the NOTE below about proportional fonts.
hDC = GetDC(hWnd)
hOldFont = SelectObject(hDC, hFont)
if GetTextMetrics(hDC, @aTM) // see TEXTMETR.PRG
C4W_SetFont(hFont, (aTM[TM_AveCharWidth] + aTM[TM_MaxCharWidth]) / 2)
else
C4W_SetFont(hFont)
endif
SelectObject(hDC, hOldFont)
ReleaseDC(hWnd, hDC)
lDelFont = .f. // no need to delete the new font
endif
case nEvent == EVENT_KEY .and. nKey == asc("2")
aFont = ChooseFont(aFont, , , @nColour)
if aFont != nil // else user chose cancel/close or hit Esc
InvalidateRect(hWnd) // clear the window
UpdateWindow(hWnd) // and make sure it's finished
hDC = GetDC(hWnd)
SetTextColor(hDC, nColour)
for i = 1 to len(aShow)
aFont[LF_Escapement] = aShow[i, 3]
hFont = CreateFont(aFont)
hOldFont = SelectObject(hDC, hFont)
TextOut(hDC, aShow[i, 1], aShow[i, 2], "Clip-4-Win")
SelectObject(hDC, hOldFont)
DeleteObject(hFont)
next i
/*
* NOTE:
*
* Using a proportional font for Clipper's output
* (i.e. for ?, ??, @ ... SAY, TBrowse, etc.) is going to
* cause problems. Clipper doesn't have built-in support
* for proportional fonts, and it puts output characters
* either at a row,col position or at the current position
* (possibly +1 col). Neither of these is entirely right
* for proportional fonts: the 1st means you need to use the
* width of the widest character to decide where columns are
* (otherwise some chars will overlap others), and the 2nd
* way of positioning output means tabular output may not
* line up properly.
*
* Getting the caret (if you have one) in the right place is
* bound to be a litle painful. You're *advised* to use
* non-proportional (i.e. fixed) fonts!! Otherwise, you might
* like to consider using GetTextExtent(), quite possibly with
* DrawText() or TextOut().
*
* The C4W_SetFont() function can return the width and height
* that will be used for the chars of the font. It defaults
* to using the average char width (see TEXTMETR.CH). If you
* are careful with how you do output, that is fine and lets
* you get nicely formatted output, despite using e.g. @ ... SAY.
* You might like to consider using "SAY.CH", of course.
*
* However, for this sample let's change the column width to
* be the average of the average and widest chars.
*/
if lDelFont
DeleteObject(C4W_SetFont()) // delete the old font
endif
aFont[LF_Escapement] = 0
hFont = CreateFont(aFont) // here's the new font
hOldFont = SelectObject(hDC, hFont)
if GetTextMetrics(hDC, @aTM) // see TEXTMETR.PRG
C4W_SetFont(hFont, (aTM[TM_AveCharWidth] + aTM[TM_MaxCharWidth]) / 2)
else
C4W_SetFont(hFont)
endif
SelectObject(hDC, hOldFont)
ReleaseDC(hWnd, hDC)
lDelFont = .t. // need to delete this font eventually
endif
endcase
enddo
return 0
// this isn't terribly fast, but it's handy
static function aColumn(aTable, n) // --> column n of aTable
local aRet := {}
aeval(aTable, {|a| aadd(aRet, a[n])}) // aeval() and aadd() are both slow!
return aRet