This is different to the getDC() function, which only returns the DC with the default font installed. This one assigns the 'current' font to the DC.
Note that id can have the form {id, DC} which allows you to pass an existing DC, to which you can assign a font to. The DC passed is returned by this routine. However, if DC is zero, a new DC is created.
Example:
atom dc
dc = assignFont(myPixMap)
w32Proc( xTextOut, {dc, x, y, textaddr, textlen} )
releaseDC(dc)
See Also: convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
This can be used to speed up setFont and EzCreateFont calls by allowing you to pre-calculate the font heights that Windows needs to find the correct font. See example for how it can be used.
id is either a control's ID or a sequence starting with a control's DC or a Window handle.
points is either a single font point value, or a sequence containing
a set of point values to convert.
pLogRes is a flag - w32True or w32False. If w32True then the logical device
resolution is used otherwise the physical device resolution is used.
Note that if the points is supplied as a sequence, the the return value is also a sequence of the same length.
Examples:
sequence lFontHeights
-- Calc font heights to be used.
-- This returns a set of 4 height values.
lFontHeights = convPointsToLogical(mainpanel, {10,12,15,26}, w32True)
. . .
-- Set the font using one of the precalc heights.
setFont(mainpanel, "Arial", {lFontHeights[kHeading1]}, Normal)
See Also: assignFont, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
This is a low-level routine that is not normally required to be called
directly. It is primarily for advanced users.
The parameters are:
id : The control whose Device Context will be used.
pDC : The device context. If zero, the routine will get and release the device context itself.
faceName : font name
iHeight : font size, * 10 (i.e.: 125 = 12.5 points
iWidth : Note this is no longer supported.
iAttributes : flags for attributes, see Bold, etc.
fLogRes : if true, uses logical resolution instead of screen res.
logfont : if non-zero, a pointer to user-supplied LOGFONT structure.
See Also: assignFont, convPointsToLogical, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
Note 1: The averages are not integers. You may have to floor() them.
Note 2: These are averages! Be wary of this when using them to calculate
field sizes for proportional fonts.
Example
sequence extent
integer fldWidth
extent = getCharExtent( MyWindow )
-- Calculate the amount of space need to display the text.
fldWidth = floor(extent[1] * length(text))
Example #2: Calculate the size of some buttons
sequence btntext, extent, btns
integer btnheight, btnwidth
sequence x
integer y
-- the strings to measure
btntext = {"&Print", "&Cancel", "&Ok", "&Help"}
-- measure the string
extent = getTextExtent( MyWindow, btntext )
-- calc button dimensions
btnheight = extent[2] + 10 -- adjust for borders
btnwidth = extent[1] + 8 -- adjust for borders
-- Draw the buttons
btns = {}
x = 5
y = 10
for i = 1 to length(btntext) do
btns &= create(PushButton, MyWindow, btntext[i],
x, y, btnwidth, btnheight, 0)
y += btnheight + 1
end for
See Also: assignFont, convPointsToLogical, EzCreateFont, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
Calling this function brings up the modal "Select Font" dialog, allowing the user to select a font from the list of available fonts.
Example:
integer flags, points
atom color
sequence font
object result
-- get a font choice from the user
result = getFontDialog( MyWindow )
if sequence( result ) then
-- get the values
font = result[1]
points = result[2]
flags = result[3]
color = result[4]
end if
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
flags is the sum of various flags. Supported values to add up are listed here
In addition, two canned flag combinations are provided:
The extra argument can be any atom or a sequence of pairs. The first element of the pair is a flag name as above, and the second element depends on the flag. Only some values for the flag are supported (and meaningful). Conversely, if you specify a flag listed below, you must supply the corresponding extra data. Results are undefined if extra data is missing when the use of a flag would require some.
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
The field can be one of:
Please refer to Microsoft documentation for the meaning and measurement units related to these fields. The otmxxx fields are outline font metrics.
Example:
-- get the descent for the default font
integer descent
setDefaultFont( MyWindow )
descent = getFontMetric( MyWindow, tmDescent )
wPrintf( MyWindow, "The default font's descent is %", descent )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
The argument is either:
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
Example:
-- show the metrics of the default font
sequence size
setDefaultFont( MyWindow )
size = getFontSize( MyWindow )
wPrintf( MyWindow, "The default font is %d by %d", size )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
The textset parameter can either be a normal text string or a sequence of
strings.
Note: The first or only & character in each string will not be included
in the metrics.
Example #1: Show the size of a text string.
sequence text, extent
-- the string to measure
text = "Hi, there!"
-- measure the string
extent = getTextExtent( MyWindow, text )
-- show results
wPrintf( MyWindow, "The string %s is %d by %d pixels",
{string, extent[1], extent[2]} )
Example #2: Calculate the size of some buttons
sequence btntext, extent, btns
integer btnheight, btnwidth
sequence x
integer y
-- the strings to measure
btntext = {"&Print", "&Cancel", "&Ok", "&Help"}
-- measure the string
extent = getTextExtent( MyWindow, btntext )
-- calc button dimensions
btnheight = extent[2] + 10 -- adjust for borders
btnwidth = extent[1] + 8 -- adjust for borders
-- Draw the buttons
btns = {}
x = 5
y = 10
for i = 1 to length(btntext) do
btns &= create(PushButton, MyWindow, btntext[i],
x, y, btnwidth, btnheight, 0)
y += btnheight + 1
end for
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
Example:
-- restore MyWindow to the default font
setDefaultFont( MyWindow )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
id can be either a single control's id, or a sequence list of ids.
w32FontName is the name of a font, eg. "Arial"
For RichEdit controls this parameter can also specify the color of the font.
In this case it takes to form {color, name}, eg. {Red, "Arial"}
The attributes flag can be a atom that combines the following:
or a sequence of nine elements. This form is used when using non-TrueType
fonts or using some of the advanced features of the Windows font engine.
For RichEdit controls only, the attrib parameter can also prepend "ALL" to the attrib sequence so that all the text is set to the font, otherwise the change of font just applies to the insertion point.
For example:
-- change the font in MyWindow
setFont( MyWindow, "Arial", 10, Bold+Italic )
wPuts( MyWindow, "This is Arial 10 point bold italic." )
setFont( MyWindow, "System", 14, {Bold,0,0,0,ANSI_CHARSET,0,0,0,0} )
setFont( MyWindow, "Symbol", 10, {0,0,0,0,SYMBOL_CHARSET,0,0,0,0} )
change all the text to courier.
setFont( MyRichEdit, "Courier New", 12, {"ALL",Normal} )
-- Set a group of fields to all the same font.
setFont( {fld1, fld3, fld2, fld7}, "Arial", 10, Normal)
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
You can use the following names for the standard font weights. Also, you can use
w32GetValue to just return the current bold weight value.
For video devices, there is not much difference in the rendering, but on other devices it might make a difference.
Example:
integer lOldWeight
lOldWeight = setFontWeight(FW_LIGHT)
setFont(aControl, "Courier New", 12, Bold)
----------------------------------------------------------------------------
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
Default values are { "MS Sans Serif", 8 points, Normal }.
Example:
setHintFont( "Times New Roman", 10, Bold)
You can also call setFont( tooltipControl )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
Example:
-- move the pen
setPenPos( MyWindow, 10, 10 )
-- display message
wPuts( MyWindow, "This is at {10,10}" )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
font is one of the system constants...
Example
setStartupFont(SYSTEM_FIXED_FONT)
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
The default option is AlignTop. Options include:
Example:
-- draw a line
drawLine( Win, 10, 100, 100, 100 )
-- top alignment (default)
setTextAlign( Win, AlignTop )
setPenPos( Win, 10, 100 )
wPuts( Win, "AlignTop" )
-- bottom alignment
setTextAlign( Win, AlignBottom )
setPenPos( Win, 10, 100 )
wPuts( Win, "AlignBottom" )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
To set the color of the graphics pen, use setPenColor.
Example:
-- draw text in red in TheWindow
setTextColor( TheWindow, Red )
wPuts( TheWindow, "This text is in red" )
setTextColor( TheWindow, "Cyan" )
wPuts( TheWindow, "This text is in cyan" )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, showChars, useLogicalResolution, wPrint, wPrintf, wPuts
If pFlag is zero, then the wPrint routine acts like Euphoria's
print command and displays normal characters as numbers in a sequence.
If pFlag is non-zero, the wPrint command displays these characters
as quoted characters.
The initial setting is zero.
Example
showChars(0)
wPrint(mywin, "abc") -- displays {97,98,99}
showChars(1)
wPrint(mywin, "abc") -- displays {'a','b','c'}
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, useLogicalResolution, wPrint, wPrintf, wPuts
pLogRes is 1 to use logical resolution (initial value), 0 to use physical resolution, w32GetValue to just return the current value of the flag.
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, wPrint, wPrintf, wPuts
window specifies the Window to receive the data.
For example:
-- dump s to the window
wPrint( MyWindow, s )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrintf, wPuts
window specifies the Window to receive the text.
window can either be a single window id, or a sequence in the form
{ id, x, y } where x and y is the pen position to write at.
This is usually used inside an Paint event handler.
Note that this does not handle NEWLINE characters, use drawText for that.
Example:
-- show value of a
wPrintf( MyWindow, "the value of a is %d", {a} )
-- Now print at pen position (5,25).
wPrintf( {MyWindow, 5, 25}, "Code %s", {theCode} )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPuts
The window parameter determines what Window will be written to.
It can be either a control id or a sequence in the form {id, X, Y} to move
the pen to X,Y before writing the text.
This is usually used inside an Paint event handler.
If text is actually a number, it will be converted to text first. The text parameters can also be used to specify a formatting string. To do so place the format string as the first element and the second element then should contain a list of parameters for the format string.
It is also possible to supply a RAM address if the text is pre-stored in memory rather than a sequence. To do this, you must format the second parameter as {{RAMaddress, length}}
Example:
-- put text in a window
wPuts( MyWindow, "Hello, World!" )
wPuts( TotalAmountFld, 1234.56 )
wPuts( {MyWindow, 17, 5}, {"Name: %s", {firstName}} )
wPuts( MyWindow, {{hSavedText, 45}} )
See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontDialog, getFontDialogEx, getFontMetric, getFontPointSize, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setStartupFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf