#1 2014-09-25 15:11:55

kalwados
Member
Registered: 2011-04-18
Posts: 15

Embedding OpenType Fonts (otf)?

Hello,

I need to create PDF from RichText documents, which uses fonts from the "Myriad Pro" family (Adobe). The fonts are installed as OpenType fonts on the Windows 7 machine.

When creating PDF documents using TPdfDocumentGDI with EmbeddedTTF := True, those fonts are NOT embedded into the PDF file; all text uses "Arial Unicode MS" as fallback; which looks not as desired when viewing the PDF on a different computer (without those fonts installed).

I've tracked down the problem to function EnumFontsProcW in TPdfDocument: Only fonts which are pure TrueType fonts are collected in FTrueTypeFonts array.
What would be necessary to also embed OpenType fonts into the PDF document?

TIA
Achim

Offline

#2 2014-09-25 16:34:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,232
Website

Re: Embedding OpenType Fonts (otf)?

I do not know if opentype fonts can be embedded with the same APIs we are using.

Perhaps another feature request ticket.

Offline

#3 2014-09-26 07:36:33

kalwados
Member
Registered: 2011-04-18
Posts: 15

Re: Embedding OpenType Fonts (otf)?

Hello ab,

I've modified the function ENumFontsProcW as following:

"var TextMetric" changed from TTextMetric to TNewTextMetric as described in MSDN documentation:
http://msdn.microsoft.com/en-us/library … 85%29.aspx

Now I can test TextMetric.ntmFlags for OpenType fonts.
With that new modified code, the "Myriad Pro" font gets embedded into the PDF file.

However, the PDF file size increases from 5 KB (not embedded) to 180 KB (EmbeddedWholeTTF = False) and up to 510 KB (EmbeddedWholeTTF = True), but the OpenType font file is only 94 KB. I don't know why the PDF gets that large. And I don't have any tools to analyze the PDF files.

Here are my changes:

const
  NTM_PS_OPENTYPE = (1 shl 17);  // Bit 17: PostScript OpenType font
  NTM_TT_OPENTYPE = (1 shl 18);  // Bit 18: TrueType OpenType font

function EnumFontsProcW(var LogFont: TLogFontW; var TextMetric: TNewTextMetric;
  FontType: Integer; var List: TRawUTF8DynArray): Integer; stdcall;
// we enumerate all available fonts, whatever the charset is, because
// we may won't enumerate Arial or Times New Roman if current FCharSet is
// chinese e.g.
var Temp: RawUTF8;
begin
  with LogFont do
    if (   (FontType=TRUETYPE_FONTTYPE) 
        or ((TextMetric.ntmFlags and NTM_PS_OPENTYPE) <> 0) // <<< added
        or ((TextMetric.ntmFlags and NTM_TT_OPENTYPE) <> 0) // <<< added
    )
    and (lfFaceName[0]<>'@')
    then begin
      Temp := RawUnicodeToUtf8(lfFaceName,StrLenW(lfFaceName));
      if (pointer(List)=nil) or (List[high(List)]<>Temp) then
        AddRawUTF8(List,Temp,true,true);
    end;
  Result := 1;
end;

Nevertheless I will submit a feature request.

Regards,
Achim

Offline

#4 2014-09-26 09:38:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,232
Website

Re: Embedding OpenType Fonts (otf)?

Yes you can create a ticket and link to this thread.

Offline

#5 2014-09-29 09:08:19

kalwados
Member
Registered: 2011-04-18
Posts: 15

Re: Embedding OpenType Fonts (otf)?

Offline

Board footer

Powered by FluxBB