Documentation for Win32lib v0.60.6
Table of Contents

Fonts

These routines allow you to work with text.


Such as displaying text, changing the font, and so on.

  • func assignFont( integer id)    Gets the device context for id with the current font installed.
  • func convPointsToLogical(object id, object points, integer pLogRes)   Calculates the 'logical' height of a font given its 'points' size.
  • func EzCreateFont( integer id, atom pDC, sequence faceName, integer iDeciPtHeight, integer iDeciPtWidth, object iAttributes, integer fLogRes, atom logfont )   Creates a Font resource
  • proc getCharExtent( integer Id)    Gets the average character width and height for the Id's current font.
  • func getFontMetric( id, field )    Gets font metric field value for id's current font.
  • func getFontSize( id )    Gets font metrics for id's current font.
  • func getTextExtent( integer Id, sequence textset )    Gets the metrics of the textset strings, using Id's current font.
  • func getTextHeight( integer Id, sequence text )    Gets the height of the text using the current font for the id
  • func getTextWidth( integer Id, sequence text )    Gets the width of the text using the current font for the id
  • proc setDefaultFont( id )   Set the font to default system font.
  • proc setFont( object id, sequence fontname, object size, object attributes )   Set the font for a control or window.
  • func setFontWeight( integer pNewWeight)    Sets what you mean by 'bold' when using setFont(..., Bold )
  • proc setHintFont( font, point size, attributes )   Set font type and size for the control's hints.
  • proc setPenPos( window, x, y )    Position the text pen in window.
  • proc setTextAlign( id, style )   Set the font alignment to use when printing text.
  • proc setTextColor( integer window, object color )    Set the text color to use when drawing text in window.
  • proc showChars(integer pFlag)    Determines if wPrint displays characters or numbers
  • func useLogicalResolution(integer pLogRes)   Sets the flag that determines if logical font resolution is used or not.
  • proc wPrint( window, object )    Equivalent to Euphoria's print() routine.
  • proc wPrintf( window, format, data )    Equivalent to Euphoria's printf() routine.
  • proc wPuts( object window, object text )    Equivalent to Euphoria's puts() function.

    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    assignFont
    ( integer id)

    Gets the device context for id with the current font installed.

    Returns: ATOM: A Device Context (hDC)

    Category: Fonts

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    convPointsToLogical
    (object id, object points, integer pLogRes)

    Calculates the 'logical' height of a font given its 'points' size.

    Returns: The logical font height.

    Category: Fonts

    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 containing a control's DC.
    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    EzCreateFont
    ( integer id, atom pDC, sequence faceName, integer iDeciPtHeight, integer iDeciPtWidth, object iAttributes, integer fLogRes, atom logfont )

    Creates a Font resource

    Returns: The new font resource.

    Category: Fonts

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    getCharExtent
    ( integer Id)

    Gets the average character width and height for the Id's current font.

    Returns: SEQUENCE: avgwidth, avgheight

    Category: Fonts

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    getFontMetric
    ( id, field )

    Gets font metric field value for id's current font.

    Returns: field's value

    Category: Fonts

    The field can be one of:

  • tmHeight
  • tmAscent
  • tmDescent
  • tmInternalLeading
  • tmExternalLeading
  • tmAveCharWidth
  • tmMaxCharWidth
  • tmWeight
  • tmOverhang
  • tmDigitizedAspectX
  • tmDigitizedAspectY
  • tmFirstChar
  • tmLastChar
  • tmDefaultChar
  • tmBreakChar
  • tmItalic
  • tmUnderlined
  • tmStruckOut
  • tmPitchAndFamily
  • tmCharSet
  • ntmFlags
  • ntmSizeEM
  • ntmCellHeight
  • ntmAveWidth

    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, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    getFontSize
    ( id )

    Gets font metrics for id's current font.

    Returns: { width, height } of average character.

    Category: Fonts

    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, getFontMetric, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    getTextExtent
    ( integer Id, sequence textset )

    Gets the metrics of the textset strings, using Id's current font.

    Returns: SEQUENCE: maxwidth, maxheight, minwidth, minheight, totalwidth, totalheight

    Category: Fonts

    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, getFontMetric, getFontSize, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    getTextHeight
    ( integer Id, sequence text )

    Gets the height of the text using the current font for the id

    Returns: ATOM: Height of the text.

    Category: Fonts

    See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontMetric, getFontSize, getTextExtent, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    getTextWidth
    ( integer Id, sequence text )

    Gets the width of the text using the current font for the id

    Returns: ATOM: Width of the text.

    Category: Fonts

    See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontMetric, getFontSize, getTextExtent, getTextHeight, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setDefaultFont
    ( id )

    Set the font to default system font.

    Category: Fonts

    Example:

          -- restore MyWindow to the default font
           setDefaultFont( MyWindow )
    

    See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setFont
    ( object id, sequence fontname, object size, object attributes )

    Set the font for a control or window.

    Category: Fonts

    id can be either a single control's id, or a sequence list of ids.

    fontname 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:

  • Normal
  • Bold
  • Italic
  • Underline
  • Strikeout

    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.

  • [1] Attributes (eg Bold+Italic)
  • [2] Average Char Width
  • [3] Escapement (How much it slopes in 10-degree increments)
  • [4] Orientation (Should be set to the same as Escapement)
  • [5] CharSet (eg. ANSI_CHARSET, SYMBOL_CHARSET)
  • [6] OutPrecision
  • [7] ClipPrecision
  • [8] Quality
  • [9] PitchAndFamily

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    setFontWeight
    ( integer pNewWeight)

    Sets what you mean by 'bold' when using setFont(..., Bold )

    Returns: The font weight setting before you changed it.

    Category: Fonts

    Use can use the following names for the standard font weights...

  • FW_DONTCARE Sets to the Windows default.
  • FW_THIN
  • FW_EXTRALIGHT aka FW_ULTRALIGHT
  • FW_LIGHT
  • FW_NORMAL aka FW_REGULAR
  • FW_MEDIUM
  • FW_SEMIBOLD aka FW_DEMIBOLD
  • FW_BOLD The default for Win32lib
  • FW_EXTRABOLD aka FW_ULTRABOLD
  • FW_HEAVY aka FW_BLACK

    Note, if you call this function with pNewWeight set to -1, the current weight value is returned without changing it.

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setHintFont
    ( font, point size, attributes )

    Set font type and size for the control's hints.

    Category: Fonts

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setPenPos
    ( window, x, y )

    Position the text pen in window.

    Category: Fonts

    Example:

          -- move the pen
           setPenPos( MyWindow, 10, 10 )
    

    -- display message wPuts( MyWindow, "This is at {10,10}" )

    See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setTextAlign
    ( id, style )

    Set the font alignment to use when printing text.

    Category: Fonts

    The default option is AlignTop. Options include:

  • AlignTop: Text is displayed below {x,y}
  • AlignBottom: Text is displayed above {x,y}
  • AlignBaseline: Text is displayed on baseline {x,y}

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    setTextColor
    ( integer window, object color )

    Set the text color to use when drawing text in window.

    Category: Fonts

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, showChars, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    showChars
    (integer pFlag)

    Determines if wPrint displays characters or numbers

    Category: Fonts

    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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, useLogicalResolution, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [func]
    useLogicalResolution
    (integer pLogRes)

    Sets the flag that determines if logical font resolution is used or not.

    Returns: The previous value of the flag

    Category: Fonts

    pLogRes is 1 to use logical resolution (initial value), 0 to use physical resolution.

    See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, wPrint, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    wPrint
    ( window, object )

    Equivalent to Euphoria's print() routine.

    Category: Fonts

    window specifies the Window to receive the data.

    For example:

          -- dump s to the window
           wPrint( MyWindow, s )
    

    See Also: assignFont, convPointsToLogical, EzCreateFont, getCharExtent, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrintf, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    wPrintf
    ( window, format, data )

    Equivalent to Euphoria's printf() routine.

    Category: Fonts

    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 onPaint 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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPuts


    Documentation for Win32lib v0.60.6
    Table of Contents

    [proc]
    wPuts
    ( object window, object text )

    Equivalent to Euphoria's puts() function.

    Category: Fonts

    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 onPaint 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, getFontMetric, getFontSize, getTextExtent, getTextHeight, getTextWidth, setDefaultFont, setFont, setFontWeight, setHintFont, setPenPos, setTextAlign, setTextColor, showChars, useLogicalResolution, wPrint, wPrintf