libharu

libharu

Postby AntoninoP » Mon Feb 26, 2018 4:59 pm

Hello,
In harbour\contrib\hbhpdf there is a cool library for create PDF file.
Would be great use it to create the pdf in FiveWin... any chance?
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: libharu

Postby cnavarro » Mon Feb 26, 2018 5:15 pm

Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: libharu

Postby AntoninoP » Tue Feb 27, 2018 9:42 am

can you do a summary? they are 5 pages in Spanish... :lol: :lol:
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: libharu

Postby cnavarro » Tue Feb 27, 2018 11:49 am

Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: libharu

Postby Carlos Mora » Tue Feb 27, 2018 6:59 pm

Ciao Antonino :D ,
AntoninoP wrote:can you do a summary? they are 5 pages in Spanish... :lol: :lol:

I wrote the class Cristobal refered you to, and it is basically a wrapper to HaruPDF to make it look like FW's TPrinter, with few exceptions that I couldn't overcome easily, mainly FONT. Fonts are handled very different in Haru and PDF technology in general, but with few effort you can translate your prints based on TPrinter to THaruPDF.

You are right, the doc is written in Spanish, I should be better write it in English.

The project in BitBucket repository is complete,and includes a very complete example. Try it in your own code, I'm pretty sure you will find help in this forum if you run into trouble. The library is _FAST_, has no external dependencies like pdf printers or OCX, just add the provided dll's, and produces very compact pdfs.

It also makes some optimizations for you. If you put the same image in several points in your pdf, the library is smart enough to include only one copy of the image and use it as an indexed image in the resulting document, so the size is kept into the minimun.

KR
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 989
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: libharu

Postby AntoninoP » Thu Mar 01, 2018 9:45 am

The idea is good, but the implementation look a little lazy:
The SetPage method takes the nPage from this list but this implementation calls HPDF_Page_SetSize that take the values from this list

I tried using this code:
Code: Select all  Expand view  RUN

//------------------------------------------------------------------------------
METHOD SetPage( nPageSize )
   static aFW2HARUSizes
   if empty(aFW2HARUSizes)
      aFW2HARUSizes := {}
      aAdd(aFW2HARUSizes, { 8.5 *72     ,11   *72     }) //#define DMPAPER_LETTER    1       // Letter 8 1/2 x 11 in
      aAdd(aFW2HARUSizes, { 8.5 *72     ,11   *72     }) //#define DMPAPER_LETTERSMALL 2       // Letter Small 8 1/2 x 11 in
      aAdd(aFW2HARUSizes, {11   *72     ,17   *72     }) //#define DMPAPER_TABLOID   3       // Tabloid 11 x 17 in
      aAdd(aFW2HARUSizes, {11   *72     ,17   *72     }) ////#define DMPAPER_LEDGER    4       // Ledger 17 x 11 in
      aAdd(aFW2HARUSizes, { 8.5 *72     ,14   *72     }) //#define DMPAPER_LEGAL     5       // Legal 8 1/2 x 14 in
      aAdd(aFW2HARUSizes, { 5.5 *72     , 8.5 *72     }) //#define DMPAPER_STATEMENT   6       // Statement 5 1/2 x 8 1/2 in
      aAdd(aFW2HARUSizes, { 7.25*72     ,10.5 *72     }) //#define DMPAPER_EXECUTIVE   7       // Executive 7 1/4 x 10 1/2 in
      aAdd(aFW2HARUSizes, {29.7 *72/2.54,42   *72/2.54}) //#define DMPAPER_A3      8       // A3 297 x 420 mm
      aAdd(aFW2HARUSizes, {21   *72/2.54,29.7 *72/2.54}) //#define DMPAPER_A4      9       // A4 210 x 297 mm
      aAdd(aFW2HARUSizes, {21   *72/2.54,29.7 *72/2.54}) //#define DMPAPER_A4SMALL   10      // A4 Small 210 x 297 mm
      aAdd(aFW2HARUSizes, {14.8 *72/2.54,21   *72/2.54}) //#define DMPAPER_A5      11      // A5 148 x 210 mm
      aAdd(aFW2HARUSizes, {25   *72/2.54,35.4 *72/2.54}) //#define DMPAPER_B4      12      // B4 250 x 354
      aAdd(aFW2HARUSizes, {18.2 *72/2.54,25.7 *72/2.54}) //#define DMPAPER_B5      13      // B5 182 x 257 mm
      aAdd(aFW2HARUSizes, { 8.5 *72     ,13   *72     }) //#define DMPAPER_FOLIO     14      // Folio 8 1/2 x 13 in
      aAdd(aFW2HARUSizes, {25.5 *72/2.54,27.5 *72/2.54}) //#define DMPAPER_QUARTO    15      // Quarto 215 x 275 mm
      aAdd(aFW2HARUSizes, {10   *72     ,14   *72     }) //#define DMPAPER_10X14     16      // 10x14 in
      aAdd(aFW2HARUSizes, {11   *72     ,17   *72     }) //#define DMPAPER_11X17     17      // 11x17 in
      aAdd(aFW2HARUSizes, { 8.5 *72     ,11   *72     }) //#define DMPAPER_NOTE      18      // Note 8 1/2 x 11 in
      aAdd(aFW2HARUSizes, {3.875*72     ,8.875*72     }) //#define DMPAPER_ENV_9     19      // Envelope #9 3 7/8 x 8 7/8
      aAdd(aFW2HARUSizes, {4.125*72     , 9.5 *72     }) //#define DMPAPER_ENV_10    20      // Envelope #10 4 1/8 x 9 1/2
      aAdd(aFW2HARUSizes, { 4.5 *72     ,10.375*72    }) //#define DMPAPER_ENV_11    21      // Envelope #11 4 1/2 x 10 3/8
      aAdd(aFW2HARUSizes, { 4.75*72     ,11   *72     }) //#define DMPAPER_ENV_12    22      // Envelope #12 4 3\4 x 11
      aAdd(aFW2HARUSizes, { 5   *72     ,11.5 *72     }) //#define DMPAPER_ENV_14    23      // Envelope #14 5 x 11 1/2
      aAdd(aFW2HARUSizes, {17   *72     ,22   *72     }) //#define DMPAPER_CSHEET    24      // C size sheet 17 x 22-inches
      aAdd(aFW2HARUSizes, {22   *72     ,34   *72     }) //#define DMPAPER_DSHEET    25      // D size sheet 22- by 34-inches
      aAdd(aFW2HARUSizes, {34   *72     ,44   *72     }) //#define DMPAPER_ESHEET    26      // E size sheet 34x44
      aAdd(aFW2HARUSizes, {11   *72/2.54,22   *72/2.54}) //#define DMPAPER_ENV_DL    27      // Envelope DL 110 x 220mm
      aAdd(aFW2HARUSizes, {16.2 *72/2.54,22.9 *72/2.54}) //#define DMPAPER_ENV_C5    28      // Envelope C5 162 x 229 mm
      aAdd(aFW2HARUSizes, {23.4 *72/2.54,45.8 *72/2.54}) //#define DMPAPER_ENV_C3    29      // Envelope C3  324 x 458 mm
      aAdd(aFW2HARUSizes, {22.9 *72/2.54,32.4 *72/2.54}) //#define DMPAPER_ENV_C4    30      // Envelope C4  229 x 324 mm
      aAdd(aFW2HARUSizes, {11.4 *72/2.54,16.2 *72/2.54}) //#define DMPAPER_ENV_C6    31      // Envelope C6  114 x 162 mm
      aAdd(aFW2HARUSizes, {11.4 *72/2.54,22.9 *72/2.54}) //#define DMPAPER_ENV_C65   32      // Envelope C65 114 x 229 mm
      aAdd(aFW2HARUSizes, {25   *72/2.54,25.3 *72/2.54}) //#define DMPAPER_ENV_B4    33      // Envelope B4  250 x 353 mm
      aAdd(aFW2HARUSizes, {17.6 *72/2.54,25   *72/2.54}) //#define DMPAPER_ENV_B5    34      // Envelope B5  176 x 250 mm
      aAdd(aFW2HARUSizes, {17.6 *72/2.54,12.5 *72/2.54}) //#define DMPAPER_ENV_B6    35      // Envelope B6  176 x 125 mm
      aAdd(aFW2HARUSizes, {11   *72/2.54,23   *72/2.54}) //#define DMPAPER_ENV_ITALY   36      // Envelope 110 x 230 mm
      aAdd(aFW2HARUSizes, {3.875*72     , 7.5 *72     }) //#define DMPAPER_ENV_MONARCH 37      // Envelope Monarch 3.875 x 7.5 in
      aAdd(aFW2HARUSizes, {3.625*72     , 6.5 *72     }) //#define DMPAPER_ENV_PERSONAL 38       // 6 3/4 Envelope 3 5/8 x 6 1/2 in
      aAdd(aFW2HARUSizes, {14.875*72    ,11   *72     }) //#define DMPAPER_FANFOLD_US  39      // US Std Fanfold 14 7/8 x 11 in
      aAdd(aFW2HARUSizes, { 8.5 *72     ,12   *72     }) //#define DMPAPER_FANFOLD_STD_GERMAN  40  // German Std Fanfold 8 1/2 x 12 in
      aAdd(aFW2HARUSizes, { 8.5 *72     ,13   *72     }) //#define DMPAPER_FANFOLD_LGL_GERMAN  41  // German Legal Fanfold 8 1/2 x 13 in
    endif
   //------------------------------------------------------------------------------
   ::nWidth := aFW2HARUSizes[nPageSize,1]
   ::nHeight := aFW2HARUSizes[nPageSize,2]
   ::SyncPage()

RETURN Self

//------------------------------------------------------------------------------
METHOD SyncPage()
    LOCAL tmp
   //------------------------------------------------------------------------------
   IF ::hPage != NIL
      if ::nOrientation = HPDF_PAGE_LANDSCAPE .and. ::nWidth<::nHeight
         tmp := ::nWidth
         ::nWidth := ::nHeight
         ::nHeight := tmp
      endif
      if ::nOrientation = HPDF_PAGE_PORTRAIT .and. ::nWidth>::nHeight
         tmp := ::nWidth
         ::nWidth := ::nHeight
         ::nHeight := tmp
      endif
      HPDF_Page_SetWidth( ::hPage, ::nWidth)
      HPDF_Page_SetHeight( ::hPage, ::nHeight)
   ENDIF

RETURN NIL


Cmtr2Pix and Mmtr2Pix are wrong, it should return an array with converted value (maybe it is the old interface):
Code: Select all  Expand view  RUN
METHOD Cmtr2Pix( nRow, nCol )

   nRow *= 72 / 2.54
   nCol *= 72 / 2.54

RETURN {nRow,nCol}

METHOD Mmtr2Pix( nRow, nCol )

   nRow *= 72 / 25.4
   nCol *= 72 / 25.4

RETURN {nRow,nCol}


FillRect is missing:
Code: Select all  Expand view  RUN
METHOD FillRect(aRect, hBrush)
   LOCAL nColor := BrushColor(hBrush)
   ::Rect(aRect[1],aRect[2],aRect[1]+aRect[3],aRect[2]+aRect[4],nColor)
return nil


#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>

HB_FUNC( BRUSHCOLOR )
{
   LOGBRUSH lb;
    if( hb_parnl( 1 ) )
    {
       #ifndef _WIN64
          GetObject( ( HGDIOBJ ) hb_parnl( 1 ), sizeof( LOGBRUSH ), ( LPSTR ) &lb );
       #else
          GetObject( ( HGDIOBJ ) hb_parnll( 1 ), sizeof( LOGBRUSH ), ( LPSTR ) &lb );
       #endif
       hb_retnl( lb.lbColor );
    }
    else
       hb_retnl( 0 );
}

#pragma ENDDUMP


For now it is what I saw, It should be a transparent replace for TPrinter...
When I will have time I will do a Pull Request on BitBucket ;)

Antonino
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: libharu

Postby AntoninoP » Thu Mar 01, 2018 11:50 am

About the font, Starting from this code
I created this FiveWin program:
Code: Select all  Expand view  RUN
#include <fivewin.ch>

#define  HKEY_LOCAL_MACHINE      2147483650        // 0x80000002
 
proc main()
   LOCAL oReg := TReg32():New(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion\Fonts", .t.)
   LOCAL cKey, cValue
   LOCAL nId := 1, aInfos := {}
   
   //? oReg:nError
   do while .t.
      oReg:nError := MY_REGENUMVALUE(oReg:nHandle, nId, @cKey, @cValue)
      aadd(aInfos, { cKey, cValue })
      if oReg:nError<>0
         exit
      endif
      nId += 1        
   enddo
   XBROWSER aInfos
return

#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>

#ifndef _WIN64
#define fw_parh hb_parnl
#else
#define fw_parh hb_parnll
#endif

HB_FUNC( MY_REGENUMVALUE ) // ( nKey, nIndex, @cKeyName, @uValue ) --> nResult
{
   BYTE name[ 1024 ];
   BYTE value[ 1024 ];
   DWORD lName=1024, lValue=1024, type = 0;
 
   hb_retnl( RegEnumValueA( ( HKEY ) fw_parh( 1 ), hb_parnl( 2 ), ( LPSTR ) name, &lName, 0, &type, value, &lValue ) );
   hb_storc( ( const char * ) name, 3 );
 
   switch( type )
   {
      case REG_SZ:
            hb_storc( ( const char * ) value, 4 );
           break;
 
      case REG_DWORD:
           hb_stornl( * ( ( LPDWORD ) value ), 4 );
           break;     
   }
}

#pragma ENDDUMP


That enumerate all installed fonts with filename.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: libharu

Postby mastintin » Mon Mar 05, 2018 5:37 pm

AntoninoP.
Fix this bug :

in METHOD SayRotate

- HPDF_Page_SetRGBFill( ::hPage, ( Int( nClrText / 0x10000 ) % 256 ) / 256.00, ( Int( nClrText / 0x100 ) % 256 ) / 256.00 , ( nClrText % 256 ) / 256.00 )

+ HPDF_Page_SetRGBFill( ::hPage, ( nClrText % 256 ) / 256.00, ( Int( nClrText / 0x100 ) % 256 ) / 256.00 , ( Int( nClrText / 0x10000 ) % 256 ) / 256.00 )


Add methods ...

METHOD SetAuthor( cAuthor ) INLINE HPDF_SetInfoAttr( ::hPdf, HPDF_INFO_AUTHOR, cAuthor ) // 2
METHOD SetTitle( cTitle ) INLINE HPDF_SetInfoAttr( ::hPdf, HPDF_INFO_TITLE, cTitle ) //5

METHOD GetAuthor() INLINE HPDF_GetInfoAttr( ::hPdf, HPDF_INFO_AUTHOR ) // 2
METHOD GetTitle() INLINE HPDF_GetInfoAttr( ::hPdf, HPDF_INFO_TITLE )

METHOD SetPermission( cMode )

default cMode := ''

cMode := upper( cMode )

SWITCH cMode
CASE "READ" ; HPDF_SetPermission( ::hPage, HPDF_ENABLE_READ ) ; EXIT
CASE "PRINT" ; HPDF_SetPermission( ::hPage, HPDF_ENABLE_PRINT ) ; EXIT
CASE "COPY" ; HPDF_SetPermission( ::hPage, HPDF_ENABLE_COPY ) ; EXIT
CASE "EDIT" ; HPDF_SetPermission( ::hPage, HPDF_ENABLE_EDIT ) ; EXIT
CASE "EDIT_ALL" ; HPDF_SetPermission( ::hPage, HPDF_ENABLE_EDIT_ALL ) ; EXIT
ENDSWITCH

Return nil
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: libharu

Postby AntoninoP » Mon Mar 05, 2018 6:27 pm

Really I would write:
Code: Select all  Expand view  RUN
HPDF_Page_SetRGBFill( ::hPage, HB_BitAnd(Int( nClrText),0xFF ) / 255.00, HB_BitAnd(HB_BitShift(Int( nClrText),-8),0xFF ) / 255.00,HB_BitAnd(HB_BitShift(Int( nClrText),-16),0xFF ) / 255.00 )

Anyway the maintainer is Carlos...
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 63 guests