PrintLen on Test

Moderator: Rathinagiri

User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: PrintLen on Test

Post by hmgchang »

Dear Sirs,

After applying your new PrintLen....
Attachments
the PrintLen value... Pixel ? mm ?
the PrintLen value... Pixel ? mm ?
testfontwidth on Microsoft XPS Document Writer.JPG (86.86 KiB) Viewed 4202 times
Just Hmg It !
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: PrintLen on Test

Post by hmgchang »

Dear Masters,

Till now I am still struggling with the correct string width printed by the PRINT DATA command, Anyone pls help !

TIA....

best rgds,
Chang
Just Hmg It !
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: PrintLen on Test

Post by dragancesu »

Each font is defined by the need to know the size, height and width character

example
PRIVATE cFontName: = "Courier", nFontSize: = 10, nFontHeight: = 5, nCharWidth = 2.5

and then it is easy
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: PrintLen on Test

Post by hmgchang »

Thanks Mr. Dragancesu,

According to the syntax, i provide fontname, fontsize, fontattribute( B, I or U).
I dont understand how to define the nFontHeight and nCharWidth that related to
fontname and fontsize. Can you pls give me some advise or sample ?

TIA

best rgds,
Chang
Just Hmg It !
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: PrintLen on Test

Post by dragancesu »

No table for it, print out and measure it
(might have but not looking)

when look:

Java have font functions https://docs.oracle.com/javase/tutorial ... gtext.html
but for display (pixel) and you need for print (mm)
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: PrintLen on Test

Post by hmgchang »

Dear Masters and Mr. Rathinagiri,

Thanks for the your printlen function.
I experimented and modified your printlen function,

Code: Select all

function printLen( cString, nFontsize, cFontname)
  cCreateFont := _HMG_CREATEFONT( OpenPrinterGetDC(), cFontname, nFontSize )
  nGetTextWidth := gettextwidth( OpenPrinterGetDC(), cString, cCreateFont )
	nWidth := nGetTextWidth * 25.4 / 600
	RETURN( ROUND( nWidth, 2))
	*- return round( nGetTextWidth * 0.0254 * nFontsize, 2 ) 
and the result,
printlen.JPG
printlen.JPG (76.3 KiB) Viewed 4076 times
it works but not perfectly, esp with the fontsize 8, any suggestions ?
_FontSizeWidth.zip
(3.41 KiB) Downloaded 249 times
Just Hmg It !
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: PrintLen on Test

Post by hmgchang »

But on Epson L210 Color Printer, the formula should be :
nWidth := nGetTextWidth * 25.4 / 360

Now, my question is :
1. How to get the printer name selected ?
2. How the number 600 ( for HP LaserJet) or 360 ( Epson Color Printer) related to printer resolution ?

TIA
Just Hmg It !
Post Reply