window font in HPDF

213 views
Skip to first unread message

Quique

unread,
Nov 5, 2022, 11:08:52 AM11/5/22
to Harbour Users
How can I select a window font in harupdf?

I want use "Curier New". I tried:

hpdf_getFont( ::hDC,  "Curier New"  , NIL )
hpdf_getFont( ::hDC,  "Curier-New"  , NIL )
hpdf_getFont( ::hDC,  "Curier New"  , "WinAnsiEncoding" )
hpdf_getFont( ::hDC,  "Curier-New"  , "WinAnsiEncoding" )

On the other hand, how can change font if the font tried doesn't exist.

if I use

hpdf_getFont( ::hDC,  "Curier-New"  , "WinAnsiEncoding" )

it causes an invalid pdf, then if I use this line, how can I know this font doesn't exist and change it by other default font?

Alain Aupeix

unread,
Nov 5, 2022, 11:30:11 AM11/5/22
to harbou...@googlegroups.com, Quique
Le 05/11/2022 à 16:08, Quique a écrit :
How can I select a window font in harupdf?

I want use "Curier New". I tried:

Humm ... Courier New

No ?

A+

--


Alain Aupeix
Sites web : JujuLand | Pissobi-Lacassagne | Gadel
X.ubuntu 16.04 | H.arbour 3.2.0-1 (r2022-10-23 11:30) | Hw.gui 2.23-4 (r3133) | G.ramps 5.1.2


Quique

unread,
Nov 5, 2022, 11:33:31 AM11/5/22
to Harbour Users
Sorry, I wrote wrong,  I tried:

hpdf_getFont( ::hDC,  "Courier New"  , NIL )
hpdf_getFont( ::hDC,  "Courier-New"  , NIL )
hpdf_getFont( ::hDC,  "Courier New"  , "WinAnsiEncoding" )
hpdf_getFont( ::hDC,  "Courier-New"  , "WinAnsiEncoding" )

Lautaro Moreira

unread,
Nov 5, 2022, 11:03:18 PM11/5/22
to harbou...@googlegroups.com, Quique

Hello,

For use "Courier-New" :

....

/*

                    "Courier New" =>"cour.ttf"
                    "Courier New Bold" => "courbd.ttf"
                    "Courier New Bold Italic"=>"courbi.ttf"
                    "Courier New Italic" =>"couri.ttf"

*/

cFontName := HPDF_LoadTTFontFromFile( ::hPdf, "cour.ttf", .t. )

HPDF_GetFont( ::hPdf, cFontName, "WinAnsiEncoding" )

...

Best Regards,

Lautaro Moreira

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/71d0eb77-f75b-4d43-a8a6-fa7dad6b4e72n%40googlegroups.com.

Quique

unread,
Nov 6, 2022, 6:15:59 PM11/6/22
to Harbour Users
Thank you. It works fine, now I need to read all .ttf files to know wich file belongs to each font, because I don't know how each user has customized each report.

Maurizio la Cecilia

unread,
Nov 7, 2022, 2:08:22 AM11/7/22
to Harbour User Group
Hi,
hbwin offers the wanted functions:


  • win_EnumFonts( [<hDC>] )  aFonts
    enumerates the fonts available on a specified <hDC> device.
    returns array of sub-arrays of all available fonts for the device given, where each sub-array corresponds to each enumerated font instance. Structure of sub-array is: {cFacename, lFixedPitch, lTrueType, nCharset}
    If <hDC> omitted, default is screen.

  • win_EnumFontFamilies([<hDC>], [<cFaceName>] aFonts
    It's similar to above win_EnumFonts() but accepts an optional <cFaceName> argument that limits enumaration on the given face (font) name only.
    Returns array of sub-arrays of the given font instances, if available, (or all available fonts, when <cFaceName> omitted) for the specified device, where each sub-array corresponds to each enumerated font instance. Structure of sub-array is: {cFacename, lFixedPitch, lTrueType, nCharset}
    If no <hDC> specified, default is screen.
    Worth to note that MS is suggesting the usage of this function, instead of win_EnumFonts(), which "is provided only for compatibility with 16-bit versions of Windows".


Best regards.
--
Maurizio 

Quique

unread,
Nov 7, 2022, 10:15:56 AM11/7/22
to Harbour Users
Thank you, It help me with user interface, but it doesn't solve the problem with HPDF, because the windows names are not the same that the names used in HPDF.

On the other hand, I need review how they work, becaus both return different results:

win_EnumFonts() returns an array with 233 items including "Courier", "Courier New", "Courier New Baltic", "Courier New CE", "Courier New CYR", "Courier New Greek", "Courier New TUR".

but win_EnumFontFamilies() (recomended by MS) returns an array with 1006 items including "Courier" and nine "Courier New". More "Courier New" that win_EnumFonts(), but without specifying type.

José M. C. Quintas

unread,
Nov 7, 2022, 1:26:26 PM11/7/22
to harbou...@googlegroups.com

Do you check existing fonts?

https://libharu.sourceforge.net/fonts.html


José M. C. Quintas

Quique

unread,
Nov 8, 2022, 3:01:58 PM11/8/22
to Harbour Users

That page have the fonts used by HPDF, but not the windows name fonts, and it not say how know if the name used is right

Maurício Faria

unread,
Nov 10, 2022, 7:52:25 AM11/10/22
to harbou...@googlegroups.com
Hi.
You can embed a TTF font in the PDF file.
The PDF file will be bigger, but many font problems goes away...
 
https://libharu.sourceforge.net/document_handling.html#HPDF_LoadTTFontFromFile
 
[[]] Mauricio

Quique

unread,
Nov 10, 2022, 12:02:54 PM11/10/22
to Harbour Users

Thanks you, but we return to the start,  I need the names of windows fonts for HPDF

José M. C. Quintas

unread,
Nov 10, 2022, 2:37:58 PM11/10/22
to harbou...@googlegroups.com

Check the url, it shows how to load file and get name.

José M. C. Quintas

Quique

unread,
Nov 10, 2022, 6:07:11 PM11/10/22
to Harbour Users
Yes, as I said in a previous post, I'm going to have to read all the font files to get the HPDF names, and make a table (hash) with the names of windows and font files and maybe the HPDF names all at once.

Luigi Ferraris

unread,
Nov 21, 2022, 8:34:06 AM11/21/22
to Harbour Users
Hi,
first of all, this answer is based on my (little) experience with libHaru.

First, libHaru doesn't has a friendly font engine, but you can create one as your need.

1) You can load a ttf from file, using:
   <fontRawName> := HPDF_LoadTTFontFromFile( <ptrDoc>, <fileName>, .T. ) // .t. required to embedding font properties. I suggest to you to enable.
   Warning: if <fontRawName> is empty, libHaru fails to load an external font file (iow see libHaru error)
   Note(1): many .ttf font can't be loaded with libHaru (e.g. barcode font) or due to libHaru codePage/encoder "incompatibility".
   Note(2): do not alter anyway the <fontRawName> (e.g. ALLTRIM()). This is the internal font name from libHaru pow.
   
2) The <fontRawName> will be used to retrieve a font pointer required by libHaru "to use" font.
   <ptrFont> := HPDF_GetFont( <ptrDoc>, <fontRawName> ) read Note(3)
   or
   <ptrFont> := HPDF_GetFont( <ptrDoc>, <fontRawName>, <haruEncoderStrName> ) read Note(3)
   
   Note(3): <haruEncoderStrName> "normally" can be omitted and is the "current" libHaru encoder; some/many times is useful.
      Keep in mind Note(1). You need to check before production use!!!

3) Now you can set the font to be used to paint text
   HPDF_Page_SetFontAndSize( <ptrPage>, <ptrFont>, <fontSize> ) ==> boolean (false failed)
   
   
By default, libHaru has these Courier <fontRawName>: "Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique",
so You do not need to load external but I think was an example.

WARNING: always keep in mind your Harbour program codePage and libHaru encoder!!!

Obviously, you can read/load Windows .ttf fonts, from its directory but you ALWAYS need to keep track of libHaru <fontRawName> because it can be different (perhaps) from the Windows font name (showed) (e.g. " goofy_ " vs "goofy_" ).

Best regards
Luigi
Reply all
Reply to author
Forward
0 new messages