column to start printing
Moderator: Rathinagiri
column to start printing
Hi all,
I need to print a fixed word followed by a variable field. How can I calculate the column to start printing the variable?
ex:
NAME := "Carlo"
@030,050 PRINT 'My name is ' Font 'calibri' Size 12
@030,??? PRINT NAME Font 'calibri' SIZE 12 BOLD
I hope I was clear
Thanks
Carlo
I need to print a fixed word followed by a variable field. How can I calculate the column to start printing the variable?
ex:
NAME := "Carlo"
@030,050 PRINT 'My name is ' Font 'calibri' Size 12
@030,??? PRINT NAME Font 'calibri' SIZE 12 BOLD
I hope I was clear
Thanks
Carlo
- AUGE_OHR
- Posts: 2117
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: column to start printing
hi,
use
to calculate Size of Text
use
Code: Select all
nPixelX := GetTextWidth( hDC, TRIM( cText ), hFont )have fun
Jimmy
Jimmy
Re: column to start printing
I would use
NAME := "Carlo"
Ctxt := 'My name is '
@030,050 PRINT Ctxt Font 'calibri' Size 12
@030,050+len(Ctxt) PRINT NAME Font 'calibri' SIZE 12 BOLD
NAME := "Carlo"
Ctxt := 'My name is '
@030,050 PRINT Ctxt Font 'calibri' Size 12
@030,050+len(Ctxt) PRINT NAME Font 'calibri' SIZE 12 BOLD
All The Best,
Franco
Canada
Franco
Canada
Re: column to start printing
Thanks AUGE_OHRAUGE_OHR wrote: ↑Thu Dec 09, 2021 11:45 pm hi,
useto calculate Size of TextCode: Select all
nPixelX := GetTextWidth( hDC, TRIM( cText ), hFont )
Could you please explain it to me better, using my example?
Carlo
Re: column to start printing
Thanks franco but I think that your solution doesn't work
Function "LEN" does not take into account the text's font and his size
Carlo
- AUGE_OHR
- Posts: 2117
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: column to start printing
hi,
try this
Code: Select all
LOCAL cNAME := "Carlo"
LOCAL cFont := 'calibri'
LOCAL nSize := 12
@030,050 PRINT 'My name is ' Font cFont Size nSize
// correction
// nCol := CalcWide(cName,cFont , nSize)
nCol := CalcWide('My name is ',cFont , nSize)
@030,nCol PRINT cNAME Font cFont SIZE nSize
FUNCTION CalcWidth(cName,cFont,nSize, lBold)
LOCAL hDC := GetDC(0)
// HMG_CreateFont ( [ hDC ] , cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeOut ) --> hFont
LOCAL hFont := HMG_CreateFont( hDC, cFont , nSize, IF(lBold,.T.,.F.), .F., .F., .F. )
nPixelX := GetTextWidth( hDC, cName, hFont )
RETURN nPixelX
have fun
Jimmy
Jimmy
Re: column to start printing
Unfortunately, I can't quite agree with what you wrote.AUGE_OHR wrote: ↑Sat Dec 11, 2021 1:09 am hi,try this
Code: Select all
LOCAL cNAME := "Carlo" LOCAL cFont := 'calibri' LOCAL nSize := 12 @030,050 PRINT 'My name is ' Font cFont Size nSize // correction // nCol := CalcWide(cName,cFont , nSize) nCol := CalcWide('My name is ',cFont , nSize) @030,nCol PRINT cNAME Font cFont SIZE nSize FUNCTION CalcWidth(cName,cFont,nSize, lBold) LOCAL hDC := GetDC(0) // HMG_CreateFont ( [ hDC ] , cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeOut ) --> hFont LOCAL hFont := HMG_CreateFont( hDC, cFont , nSize, IF(lBold,.T.,.F.), .F., .F., .F. ) nPixelX := GetTextWidth( hDC, cName, hFont ) RETURN nPixelX
First, there is a logical error in the placement of the second phrase in the printout. It should be
Code: Select all
@030,050 + nCol PRINT cNAME Font cFont SIZE nSize BOLDThird, you refer to the object hDC: = GetDC (0), which is the desktop / screen and its DPI. The DPI of the screen has nothing to do with the DPI of the printer.
So, we need some additional information:
DPI of the printer, converting pixels to millimeters.
I would do it this way
Code: Select all
cTextToPrint := 'My name is '
cName := "Carlo"
cPrintFontName := "Calibri"
nPrintFontSize := 12
nLenTextToPrint := GetTxtLen ( cTextToPrint, cPrintFontName, nPrintFontSize )
@030,050 PRINT cTextToPrint Font cPrintFontName Size nPrintFontSize
@030,050 + nLenTextToPrint PRINT cName Font cPrintFontName SIZE nPrintFontSize BOLD
***************************************************************************************************
FUNCTION GetTxtLen ( cText, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeout )
RETURN HMG_GethDCTextWidthinMM (OpenPrinterGetPageDC(), cText, cPrintFont, nFontSize, lBold, lItalic, lUnderline, lStrikeout )
***************************************************************************************************
FUNCTION HMG_GethDCTextWidthInMM (hDC, cText, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeout)
RETURN (HMG_GethDCTextWidthInPx (hDC, cText, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeout) * 25.4 ) / HMG_GetPrinterResolution( hDC )[1]
***************************************************************************************************
FUNCTION HMG_GethDCTextWidthInPx (hDC, cText, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeout)
Local hFont
Default cText:=""
Default cFontName := _HMG_SYSDATA [ 342 ]
Default nFontSize := _HMG_SYSDATA [ 343 ]
Default lItalic := .F.
Default lUnderline := .F.
Default lStrikeout := .F.
Default lBold := .F.
hFont := HMG_CreateFont (hDC, cFontName, nFontSize, lBold, lItalic, lUnderline, lStrikeOut )
RETURN GetTextWidth( hDC, cText, hFont )
***********************************************************************
#pragma begindump
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"
#include <windows.h>
#include <hbapi.h>
HB_FUNC ( HMG_GETPRINTERRESOLUTION )
{
hb_reta (2);
hb_storvni ( GetDeviceCaps( (HDC) hb_parnl (1), LOGPIXELSX ), -1, 1 );
hb_storvni ( GetDeviceCaps( (HDC) hb_parnl (1), LOGPIXELSY ), -1, 2 );
}
#pragma ENDDUMP
************************************************************************************************************
Re: column to start printing
Is hpdfprint in pixels or millimeters ?
I am having this problem with printing memo files to hpdfprint.
One of these options could work for me, I may need help because I need to make the line length to stop at the end of a word.
Someone may have this solution already.
Thanks.
I am having this problem with printing memo files to hpdfprint.
One of these options could work for me, I may need help because I need to make the line length to stop at the end of a word.
Someone may have this solution already.
Thanks.
All The Best,
Franco
Canada
Franco
Canada
Re: column to start printing
Hpdfprint is in millimeters also.franco wrote: ↑Sat Dec 11, 2021 4:51 pm Is hpdfprint in pixels or millimeters ?
I am having this problem with printing memo files to hpdfprint.
One of these options could work for me, I may need help because I need to make the line length to stop at the end of a word.
Someone may have this solution already.
Thanks.
Look at this topic, I think this may be helpful https://www.hmgforum.com/viewtopic.php?p=57056#p57056
Re: column to start printing
I have been offline for a bit.
Thanks to all for advive. I now have time to check this out.
Thanks to all for advive. I now have time to check this out.
All The Best,
Franco
Canada
Franco
Canada