I do some test on PrintLen...
Both side are for monospace and non-fixed fonts...
BTW, how to tell font is monospace or not ?
the ssw :
Code: Select all
#include <hmg.ch>
Function Main
MEMVAR _HMG_SYSDATA
Load Window Main
Main.Center
Main.Activate
Return NIL
FUNCTION TestFontWidth()
LOCAL aFont, aFontSize, aText
LOCAL cFontName, cText, cText1, cNum
LOCAL nFontSize, nOneInch, nPAWidth, nPAHeight, nPAHorOffset, nPAVerOffset, nI
LOCAL nRow1, nRow2, nCol1, nCol2, nRow, nCol, nOneCm, nPrintLen, nJ
LOCAL nVSpace, nMyPrintLen
LOCAL lSuccess
MEMVAR _HMG_SYSDATA
aText := { "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", ;
"abcdefghijklmnopqrstuvwxyz0123456789", ;
"人的一生,平安就好。", ;
hb_UChar( 0x250C) + Replicate( hb_UChar ( 0x2500),20) + hb_UChar( 0x2510), ;
hb_UChar( 0x2502) + "12345678901234567890" + hb_UChar( 0x2502)}
aFontSize := { 10, 12, 14}
aFont := { "CONSOLAS", "COURIER"}
*- cText := "123456789012345678901234567890123456789012345678901234567890"
*- aFont := GetFont()
*- cFontname := aFont[ 1] && "CONSOLAS"
*- nFontSize := 12
SELECT PRINTER DIALOG TO lSuccess PREVIEW
IF lSuccess
nOneInch := 25.4
nOneCm := 10
nPAWidth := GetPrintableAreaWidth()
nPAHeight := GetPrintableAreaHeight()
nPAHorOffset := GetPrintableAreaHorizontalOffset()
nPAVerOffset := GetPrintableAreaVerticalOffset()
START PRINTDOC
START PRINTPAGE
CmBlock( nPAWidth, nPAHeight)
nRow := 5
nCol := 0
nVSpace := 5
FOR nI := 1 TO LEN( aFontSize)
nFontSize := aFontSize[ nI]
nVSpace := nFontSize / 2 + 1
nRow += nVSpace
FOR nJ := 1 TO LEN( aText)
cText := aText[ nJ]
*- nRow += nFontSize
*- nRow1 := nRow2 := nRow
*- @ nRow1, 0 PRINT LINE TO nRow2, nPAWidth PENWIDTH 0.1 COLOR SILVER
nRow += nVSpace + 3
FOR nC := 1 TO LEN( aFont)
cFontName := aFont[ nC]
nCol := ( nC-1) * 110
cText1 := cText + PADL( nFontSize, 3)
@ nRow, nCol PRINT cText1 FONT cFontName SIZE nFontSize
*- nRow += nI
*- nRow1 := nRow2 := nRow
*- @ nRow1, 0 PRINT LINE TO nRow2, nPAWidth PENWIDTH 0.1 COLOR SILVER
nPrintLen := PrintLen( cText, nFontSize, cFontName)
nMyPrintLen := MyPrintLen( cText, nFontSize)
cText1 := "PrintLen : " + PADL( nPrintLen, 5) + ", me : " + PADL( nMyPrintLen, 5) + " mm."
*- nRow += nVSpace
@ nRow + nVSpace, nCol PRINT cText1 FONT cFontName SIZE nFontSize COLOR BLUE
NEXT
nRow += nVSpace
*- @ nRow, nCol PRINT cText1 FONT cFontName SIZE nI BOLD
*- nRow += nI
*- @ nRow, nCol PRINT cText1 FONT cFontName SIZE nI ITALIC
NEXT
NEXT
END PRINTPAGE
END PRINTDOC
ENDIF
RETURN NIL
function printLen( cString, nFontsize, cFontname)
return round(gettextwidth(Nil,cString,cFontname)*0.0254*nFontsize,2)
FUNCTION MyPrintLen( cString, nFontSize)
LOCAL nFontWidth
nFontWidth := nFontSize * .555
RETURN( LEN( cString) * nFontWidth * 25.4 / 72.272)
FUNCTION CmBlock( nPAWidth, nPAHeight)
LOCAL cNum
LOCAL nOneCm, nOneInch
LOCAL nI, nRow, nRow1, nRow2, nCol, nCol1, nCol2
MEMVAR _HMG_SYSDATA
nOneCm := 10
nOneInch := 25.4
*- Vertical Line
nI := 0
DO WHILE nI < nPAWidth
* cm V-Line
IF MOD( nI, nOneCm) == 0
nRow1 := 0
nRow2 := nPaHeight
nCol1 := nCol2 := nI
@ nRow1, nCol1 PRINT LINE TO nRow2, nCol2 PENWIDTH 0.05 COLOR AQUA
cNum := ALLTRIM( STR( INT( MOD( nI, 110))))
@ 0, nCol1 PRINT cNum FONT "CONSOLAS" SIZE 10
@ nPAHeight - 5, nCol2 PRINT cNum FONT "CONSOLAS" SIZE 10
ENDIF
* Inch V-Line
IF MOD( nI, nOneInch) == 0
nRow1 := 0
nRow2 := nPaHeight
nCol1 := nCol2 := nI
@ nRow1, nCol1 PRINT LINE TO nRow2, nCol2 PENWIDTH 0.05 COLOR SILVER
ENDIF
nI++
ENDDO
*- Horizonal Line
nI := 0
DO WHILE nI < nPAHeight
IF MOD( nI, nOneCm) == 0
nRow1 := nRow2 := nI
nCol1 := 0
nCol2 := nPAWidth
@ nRow1, nCol1 PRINT LINE TO nRow2, nCol2 PENWIDTH 0.05 COLOR AQUA
ENDIF
nI++
ENDDO
RETURN NIL
TIA
rgds,
Chang