1. Font picker dialog

Ok, here is the font picker for screen fonts. I also have a font picker
for printer fonts which will only show fonts that work for the default
printer.

In case anyone is interested I have a fairly complete printer library I
wrote last year before David got printer dialog into winlib. It has some
extra capabilities such as the ability for the coder to preprompt the
printer mode (portrait/landscape), the print from-to pages (from a print
dialog routine by Barrend Maaskant),disable the print to file button as
well as interface with the print setup dialog. It also has routines for
1Up, 2Up and 4Up printing per page, selecting of print font and more.
Again the code is not very professional or efficient but works.

Enjoy,
Judith Evans

--Sfontdlg.ew
--choose fonts for screen.
--choose fonts for printer: Pfontdlg.ew
--some of this code 'borrowed' from Win32lib.ew by David Cuny

constant
    xchoosefont = linkFunc(comdlg32, "ChooseFontA", {C_POINTER},C_LONG)

global constant     CF_SCREENFONTS  = 1,
                    CF_PRINTERFONTS = 2,
                    CF_EFFECTS      = 256  --strikeout, underline,
color

constant
                    CF_choosefont_Structsize   = 0, --choosefont struct
                    CF_choosefont_WindowHandle = 4,
                    CF_choosefont_PrinterDC    = 8,
                    CF_choosefont_LogFontPtr   = 12,
                    CF_choosefont_point_size   = 16,
                    CF_choosefont_Flags        = 20,
                    CF_choosefont_RGB          = 24,
                    CF_choosefont_stuff        = 40,
                    CF_choosefont_Ptr_lzstyle  = 44,
                    CF_choosefont_Type         = 48,
                    CF_choosefont_missing      = 50,
                    CF_choosefont_min          = 52,
                    CF_choosefont_max          = 56,

                    CF_choosefont_size         = 60,


                    LF_logfont_Height          = 0, --logfont struct
                    LF_logfont_Width           = 4,
                    LF_logfont_Escapement      = 8,
                    LF_logfont_Orient          = 12,
                    LF_logfont_Bold            = 16,
                    LF_logfont_Italic          = 20,
                    LF_logfont_Underline       = 21,
                    LF_logfont_Strikeout       = 22,
                    LF_logfont_CharSet         = 23,
                    LF_logfont_OutPrecision    = 24,
                    LF_logfont_ClipPrecisio    = 25,
                    LF_logfont_Quality         = 26,
                    LF_logfont_PitchFamily     = 27,
                    LF_FaceName                = 28,

                    LF_StructSize              = 60 --maximum guess
constant    IsTrue=1

global function GetFontDlg(atom owner)
atom handle, ok
atom cfPtr, lfPtr, hPtr
sequence faceName
integer facePts
integer faceAtt
integer faceBold, faceItalic, faceStrikeout, faceUnderline, fontColor
faceBold=0 faceItalic=0 faceStrikeout=0 faceUnderline=0


    --get window handle
    handle=getHandle(owner)

    --create CF_choosefont structure
    cfPtr = allocate(CF_choosefont_size)
    mem_set(cfPtr,0,CF_choosefont_size)

    --create LF_logfont structure
    lfPtr= allocate(LF_StructSize)
    mem_set(lfPtr,0,LF_StructSize)

    --populate structure
    poke4(cfPtr+CF_choosefont_Structsize,CF_choosefont_size)
    poke4(cfPtr+CF_choosefont_WindowHandle,handle)
    poke4(cfPtr+CF_choosefont_Flags, CF_SCREENFONTS+CF_EFFECTS)
    poke4(cfPtr+CF_choosefont_LogFontPtr,lfPtr)

    --call the dialog
    ok=c_func(xchoosefont,{cfPtr})
    if ok then
        --use logfont pointer to get the facename
        lfPtr=peek4u(cfPtr+CF_choosefont_LogFontPtr)
        if lfPtr then
            --got pointer successfully
            faceName=peek_string( lfPtr+LF_FaceName)
            facePts = peek4u(cfPtr+CF_choosefont_point_size)
            faceBold=peek(lfPtr+LF_logfont_Bold)

            --get font characteristics
            if faceBold then
                if faceBold=188 then    --s/b 700 according to
documentation
                    faceBold=Bold       --in win32lib
                end if
            end if
            faceItalic=peek(lfPtr+LF_logfont_Italic)
            if faceItalic=IsTrue then
                faceItalic=Italic
            end if

            --get font effects
            faceStrikeout=peek(lfPtr+LF_logfont_Strikeout)
            if faceStrikeout=IsTrue then
                faceStrikeout=Strikeout
            end if
            faceUnderline=peek(lfPtr+LF_logfont_Underline)
            if faceUnderline=IsTrue then
                faceUnderline=Underline
            end if
            faceAtt=faceBold+faceItalic+faceStrikeout+faceUnderline

            --get font color
            fontColor=peek4u(cfPtr+CF_choosefont_RGB)

            free(lfPtr)
            free(cfPtr)
            return {faceName,facePts/10,faceAtt,fontColor}
        else
            free(lfPtr)
            free(cfPtr)
            return -1
        end if
    else
    free(lfPtr)
    free(cfPtr)
    return 0
    end if

end function

new topic     » topic index » view message » categorize

2. Re: Font picker dialog

In case anyone is wondering why there is the 'maximum guess' in the
structure: I don't always know how to break out c structures to euphoria and
there were a lot of other fields I didn't want anyway. So I was lazy.....

Judith

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu