Sample Code - SunSayXY() Word Wrap



SunSayXY() Sample Word Wrap



* Written by Frej Krook 01/10/94
* illustrates SunSayXY word wrap

# INCLUDE 'sunshow.ch'

PROCEDURE  pmain(cFileType)

aDirectory = {}

aDirectory = DIRECTORY("*." + cFileType)

SetVMode(18)

FOR i  =  1 TO LEN(aDirectory)

nFontHandle = LoadHPFont(aDirectory[i,1])

cString = "TIFF is a rich image format which allows a flexibility " +;
          "unheard of in other formats.  Information in the form of " +;
          "tags can be added or removed as needed."

WrapXY(0, 30, 610, nFontHandle, 15, 0, "R", cString)
INKEY(0)

ClearWin(0, 16, 0, 0, 29, 79)   
WrapXY(0, 30, 610, nFontHandle, 15, 0 "C", cString)
INKEY(0)

ClearWin(0, 16, 0, 0, 29, 79)   
WrapXY(0, 30, 610, nFontHandle, 15, 0 "L", cString)

UnLoadFont(nFontHandle)
INKEY(0)
ClearWin(0, 16, 0, 0, 29, 79)

NEXT i
TextMode()
RETURN

PROCEDURE WrapXY(nStartX, nStartY, nEndX, nFontHandle, nFColor, nBColor, cJust,
LOCAL nLineWidth, nChars, nStartLine = 1, nWidth

// Append a space to the string so it justifies correctly
IF SUBSTR(cString, LEN(cString), 1) <> ' '
    cString = cString + ' '
ENDIF

// Calculate the 'column' width
nWidth = nEndX - nStartX

DO WHILE nStartLine < LEN(cString)
    nLineWidth = 0
    nChars = 0
    cHoldString = ""

// Add a character at a time to the cHold string until the width of the column
//is reached
DO WHILE nStartLine + nChars <= LEN(cString) .AND. FetTextWidth(nFontHandle,cH
    ++nChars
    cHoldString = SUBSTR(cString, nStartLine, nChar)
ENDDO

// Find last space in the string segment
    IF nStartLine + nChars <= LEN(cString)
        IF RAT (' ', SUBSTR(cString, nStartLine, nChars)) > 0
            DO WHILE SUBSTR(cString, nStartLine + nChars - 1, 1) = ' ' -- nChars
            END
        END

        IF RAT (' ', SUBSTR(cString, nStartLine, nChars)) > 0
            DO WHILE SUBSTR(cString, nStartLine + nChars - 1, 1) > 0 .AND.  ;
            SUBSTR(cString, nStartLine + nChars - 1,1) <> ' '
            nChars = RAT(' ', SUBSTR(cString, nStartLine, nChars))
        END
    END

// Put text on screen
    DO CASE
        CASE ALLTRIM(cJust) == "R"
            SunSayXY(nEndX - GetTextWidth(nFontHandle, SUBSTR(cString, nStartLine, nChars)
                SUBSTR(cString, nStartLine, nChars - 1)

        CASE ALLTRIM(cJust) == "C"
            SunSayXY(nEndX + (nWidth / 2)) - (GetTextWidth(nFontHandle, SUBSTR(cString, nStartLine, nChars))
                SUBSTR(cString, nStartLine, nChars - 1)

        CASE ALLTRIM(cJust) == "L"
            SunSayXY(nStartX, nStartY, nFontHandle, nFColor, nBColor, "";  ;
                SUBSTR(cString, nStartLine, nChars))

    ENDCASE

// Make sure we don't start a line with a wrapped space
    WHILE SUBSTR(cString, nStartLine, 1) == ' '
        ++ nStartLine
    END
END
RETURN  






Return to Technical Support, Notes, Tips, Tricks
and Programming Information







Return to SunShow Professional Page






Return to SunShow Main