EldoS | Feel safer!

Software components for data protection, secure storage and transfer

make a subset of font embeded

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#9935
Posted: 05/07/2009 03:15:30
by Gerald So (Basic support level)
Joined: 05/07/2009
Posts: 7

I have tried SecureBlackBox.PDF to sign PDF files, testing the "TinySigner" sample I get a big PDF file with the whole .ttf file embedded. What I want is not this but a subset embedded. I read many things in internet but got no answer.
In the SecureBlackBox's help file I notice that the "ElPDFCIDFontDescriptor" has a "CIDSet", it seems that if "CIDSet" was set correctly then the result PDF file would be the subset embedded. Is this true? If so, how to make a correct "CIDSet"?

Any helps are welcom.
#9937
Posted: 05/07/2009 04:04:27
by Dmytro Bogatskyy (EldoS Corp.)

Quote
In the SecureBlackBox's help file I notice that the "ElPDFCIDFontDescriptor" has a "CIDSet", it seems that if "CIDSet" was set correctly then the result PDF file would be the subset embedded. Is this true? If so, how to make a correct "CIDSet"?

Code
CIDSet is byte array identifying which CIDs are present in the CIDFont file.If this entry is present, the CIDFont contains only a subset of the glyphs in the character collection defined by the CIDSystemInfo dictionary. If it is absent, the only indication of a CIDFont subset is the subset tag in the FontName entry.
The data is organized as a table of bits indexed by CID. The bits should be stored in bytes with the high-order bit first. Each bit corresponds to a CID. The most significant bit of the first byte corresponds to CID 0, the next bit to CID 1, and so on.

Quote
I have tried SecureBlackBox.PDF to sign PDF files, testing the "TinySigner" sample I get a big PDF file with the whole .ttf file embedded. What I want is not this but a subset embedded. I read many things in internet but got no answer.

If disk space matters, then maybe it is better to use Type1 Fonts. Please, see 'Helvetica, Win-1252' for 'Widget font and encoding' option
#9944
Posted: 05/07/2009 15:41:03
by Gerald So (Basic support level)
Joined: 05/07/2009
Posts: 7

Thanks! It's what I need.
For systems rarely install Type1 fonts of Chinese codes so I should try CIDfonts.
#9957
Posted: 05/08/2009 08:57:14
by Gerald So (Basic support level)
Joined: 05/07/2009
Posts: 7

Oh! Nothing have been changed. The result is still a big .pdf file which contains the whole .ttf file in it. Below is my code:

//process the .utf file
....
//make CIDSet
if Wid.SignerInfo <> '' then
begin
SetLength(CIDSet, 8192);
for i := 0 to 8191 do CIDSet[i] := 0;
for i := 4 to 15 do CIDSet[i] := 255;
WStr := UTF8ToWideStr(Wid.SignerInfo[1], Length(Wid.SignerInfo));
for i := 0 to Length(Wstr) - 1 do
begin
j := Integer(Word(Wstr[i]));
if j < 128 then Continue;
l := j shr 3;
j := j and 7;
CIDSet[l] := CIDSet[l] or BitMask[j]; //Array[0..7] of Byte = (128,64,32,16,8,4,2,1);
end;
FontDescriptor.CIDSet := CIDSet;
end;
Font0.BaseFont := FontDescriptor.FontName;
Font0.Encoding := 'Identity-H';
....

I think more things have to do, maybe a hard working. :(
#9962
Posted: 05/08/2009 17:19:10
by Dmytro Bogatskyy (EldoS Corp.)

Everything you set to a font properties is added to a pdf document. The PDF component doesn't parse TrueType Font data. That's why the document still big. First you need to get smaller ttf (only with those characters you need) and then regenerate font metrics.
As for the Chinese codes, I think, if you remove other glyphs the ttf data will not change significantly.
#9964
Posted: 05/09/2009 03:21:34
by Gerald So (Basic support level)
Joined: 05/07/2009
Posts: 7

Hi, after a hard reading (the PDF specification from ADOBE) I know that to embed subsets of TrueType or OpenType font files into a PDF file, we need to extract the font metrics from the font files and build the required tables ourself. This is very difficult to me, so I decide to leave the font files out for they generally have installed in systems.
Now my broblem is how to 'tell' the PDF reader where to find those font files. I have tried the SimpleFont, it can only display latin characters. Chinese characters become to strange symbols. Then, I tried the other way. In the sample 'TinySigner', within that 'AddTrueTypeFont' procedure, comment this line:
// FontDescriptor.FontFile2 := Buf;
the PDF reader gave me a error report and displayed all charaters as a small point.

Please tell me what's wrong or how to do that.
#9968
Posted: 05/09/2009 17:37:05
by Dmytro Bogatskyy (EldoS Corp.)

Quote
// FontDescriptor.FontFile2 := Buf;
the PDF reader gave me a error report and displayed all charaters as a small point.

This means that Adobe can't find the font. Check the File\Preference\Fonts tab in Adobe.
Try to set FontFamily for the FontDescriptor object and change font type to TrueType.
Unfortunately, I'm not aware how to make Adobe undertand external fonts without embedding them.
If you decide to use fonts in this way, then we could investigate and develop this for you, see Custom services
Quote
I have tried the SimpleFont, it can only display latin characters.

No, for example Type1 Font (Simple Font) could display not only Latin characters, but others as well. You need to use Encoding object to remap character codes to the glyph names. The only limitation that you can have 256 different characters, but this should be enough for the signature.
For the next version we have added AutoAdjustEncoding property. That will create Encoding object automatically depending on the text, you will only need to set correct glyph names for those characters through OnLookupGlyphName event. Of course, in your case the Asian fonts should be installed, but I think it is better then to installl font separately.
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 2369 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!