1. Yuri Denshchik
  2. PowerBuilder
  3. Thursday, 22 June 2017 15:43 PM UTC

We have our custom font (ttf) that we want to use in PB application. We don't want to register it globally, the idea is to use it privately just for our application and no other application should see it in the list of available fonts. 

In .Net there is a PrivateFontCollection Class that allow to use a font privately. Is it possible to achieve similar thing in PB?

Thank you,

Yuri

Accepted Answer
Bernhard Stoeter Accepted Answer Pending Moderation
  1. Friday, 23 June 2017 06:14 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Yuri,

I do it this way:

Declare two local or global external functions:
// GDI32.dll
function long AddFontResourceExW( readonly string as_FontFile, ulong aul_FontCharacteristics, ulong aul_Reserved ) library "GDI32.dll" alias for "AddFontResourceExW"
function boolean RemoveFontResourceExW( readonly string as_FonfFile, ulong aul_FontCharacteristics, ulong aul_Reserved ) library "GDI32.dll" alias for "RemoveFontResourceExW"


Load the font before using with:
public function long of_addfont (readonly string as_fontfile):
long    ll_rc

ll_rc = AddFontResourceExW( as_FontFile, 16 /* FR_PRIVATE 0x10 */ + 32 /* FR_NOT_ENUM 0x20 */, 0 )

return ll_rc

 

and unload it after using with:
public function boolean of_removefont (readonly string as_fontfile):
boolean    lb_rc

lb_rc = RemoveFontResourceExW( as_FontFile, 16 /* FR_PRIVATE 0x10 */ + 32 /* FR_NOT_ENUM 0x20 */, 0 )

return lb_rc

 

...of_AddFont( "c:\Temp\MyFont.ttf" )
// Use font
... of_RemoveFont( "c:\Temp\MyFont.ttf" )

 

I called "of_AddFont()" on application start and "of_RemoveFont()" on application close.

Hope this helps,
Regards
Bernhard

 

Comment
  1. Yuri Denshchik
  2. Monday, 26 June 2017 18:10 PM UTC
Works perfectly!



Thank you Bernhard.



-Yuri

  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Thursday, 9 December 2021 16:28 PM UTC
  2. PowerBuilder
  3. # 1

FYI- appeon's native PDF will NOT work with this.

 

https://www.appeon.com/standardsupport/track/view?id=7256

Comment
  1. mike S
  2. Tuesday, 14 December 2021 14:11 PM UTC
use @mark's suggestion to make it private only (16): AddFontResourceExW( ls_DynLoadedFontFile, 16 , 0) and it will work with native pdf!

  1. Helpful
There are no comments made yet.
Mark Lee @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 14 December 2021 10:08 AM UTC
  2. PowerBuilder
  3. # 2

Hi All,

 

If you enable the packaging custom fonts in the generated PDF files for NativePDF, then you can't use AddFontResourceExW function to mark a font as not enumerable.

We suggest that you use AddFontResourceExW and RemoveFontResourceExW functions and do not specify the FR_NOT_ENUM parameter any longer.

The reference code is as follows:

 

AddFontResourceExW( ls_DynLoadedFontFile, 16 /* FR_PRIVATE 0x10 */, 0)

RemoveFontResourceExW( ls_DynLoadedFontFile, 16 /* FR_PRIVATE 0x10 */, 0)

 

Regards,

 

Comment
  1. mike S
  2. Tuesday, 14 December 2021 14:09 PM UTC
brilliant!
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.