Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Faxual II for CA-Clipper - // ripex2.prg http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
//  ripex2.prg
//
//  Faxual II RIP example 2.  Print a text file to a fax file using
//  a fixed-pitch font.
//
//  Usage: RIPEX2 <text-file-name>
//
//  Compile with /n /w ($Clip: -nw$)
//

#define SYSFONT "sys20x32.xfb"  // Stock fixed-pitch font
#define OUTFILE "ripex2.tif"    // Output file name

#define LMARGIN 50              // 1/4" left margin
#define TMARGIN 50              // 1/4" top margin
#define BMARGIN 50              // 1/4" bottom margin

procedure Main(file)
    local text
    local hfont
    local i

    // Load the text file.

    if file == NIL
        ? "You must specify a file name"
        quit
    endif

    text := memoread(file)

    if len(text) == 0
        ? "Couldn't read " + file + " (or it's empty)"
        quit
    endif

    // Load the font.

    hfont := FontLoadXFB(SYSFONT)

    if hfont == 0
        ? SYSFONT + ": " + F2ErrorMessage(F2Error())
        quit
    endif

    // Create the output file and select the font we just loaded.

    RipBegin(OUTFILE)
    RipFont(hfont)

    // Position for writing the first line.

    RipMoveTo(LMARGIN, TMARGIN + FontAscent(RipFont()))

    // Write text, a line at a time.

    for i := 1 to mlcount(text, 80, 8)

        RipWrite(memoline(text, 80, i, 8))
        RipMoveTo(LMARGIN, RipCurY() + FontLineSpacing(RipFont()))

        if RipCurY() + FontDescent(RipFont()) > RipLength() - BMARGIN
            // We've moved off the bottom of the page, so eject it and
            // start a new one.
            RipEject()
        endif

    next

    // Eject the last page.  Cut it off short so we don't waste paper
    // if it's mostly blank.

    RipEject(RipCutoff() + BMARGIN)
    RipEnd()

    // Unload the font.  Not strictly necessary since the program is
    // about to end, but good practice.

    FontUnload(hfont)

    return

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson