On Sun, 06 Mar 2016 03:15:06 -0600, Michael Van Canneyt <mich...@freepascal.org> wrote:



On Sat, 5 Mar 2016, Jesus Reyes A. wrote:

On Sat, 05 Mar 2016 14:03:49 -0600, Michael Van Canneyt <mich...@freepascal.org> wrote:

 This is what I get with the normal test font:
http://www.freepascal.org/~michael/test.pdf
 Can you please try with the original font too, please ?
(freesans is freely available)
If that works, it would mean there is something wrong with the Arial font handling.
 Michael.

your file looks like the one I produced here when using "Visor de documentos" which happen to be evince, this is what it looks http://ctrlv.in/722669 the only change I did was adding JRAXX at the end of every P.WriteText'd string where XX is the index of each instance. Seems only latin text is working.

Strange, because if I recall correctly it was tested with Cyrillic, and that worked ?

Later I will try with other readers.

Please do, I'd welcome any hints as to what could be wrong !

(evince is one of the readers that was used to test, BTW)

Michael.

The problem of evince not showing some texts it's because the compressed font file stream size is written with an incorrect value. There is an option to enable font file compression (poCompressFonts) but in the code, compression is always enabled, the compressed stream size is returned in the function that writes down the compressed stream, too late because the /length item was already written using the uncompressed size. The attached patch addresses both problems and makes sure length1 item is not written down if not needed.

This however doesn't fix the Cyrillic and other texts :(

Jesus Reyes A.
Index: fppdf.pp
===================================================================
--- fppdf.pp    (revisión: 33164)
+++ fppdf.pp    (copia de trabajo)
@@ -396,8 +396,10 @@
   private
     FKey: TPDFName;
     FObj: TPDFObject;
+    FHidden: Boolean;
   protected
     procedure Write(const AStream: TStream);override;
+    property Hidden : Boolean read FHidden write FHidden;
   public
     constructor Create(Const ADocument : TPDFDocument; const AKey: string; 
const AValue: TPDFObject);
     destructor Destroy; override;
@@ -2397,10 +2399,13 @@
 
 procedure TPDFDictionaryItem.Write(const AStream: TStream);
 begin
-  FKey.Write(AStream);
-  TPDFObject.WriteString(' ', AStream);
-  FObj.Write(AStream);
-  TPDFObject.WriteString(CRLF, AStream);
+  if not FHidden then
+  begin
+    FKey.Write(AStream);
+    TPDFObject.WriteString(' ', AStream);
+    FObj.Write(AStream);
+    TPDFObject.WriteString(CRLF, AStream);
+  end;
 end;
 
 constructor TPDFDictionaryItem.Create(Const ADocument : TPDFDocument;const 
AKey: string; const AValue: TPDFObject);
@@ -2484,7 +2489,7 @@
 var
   ISize,i, NumImg, NumFnt: integer;
   Value: string;
-  M : TMemoryStream;
+  M, Buf : TMemoryStream;
   E : TPDFDictionaryItem;
   D : TPDFDictionary;
 begin
@@ -2520,18 +2525,29 @@
           if Pos('Length1', E.FKey.Name) > 0 then
           begin
             M:=TMemoryStream.Create;
+            Buf:=TMemoryStream.Create;
             try
               Value:=E.FKey.Name;
               NumFnt:=StrToInt(Copy(Value, Succ(Pos(' ', Value)), 
Length(Value) - Pos(' ', Value)));
               m.LoadFromFile(Document.FontFiles[NumFnt]);
+              // write buffer with compressed (if requested) fontfile stream
+              ISize := TPDFEmbeddedFont.WriteEmbeddedFont(Document, M, Buf);
+              D:=Document.GlobalXRefs[AObject].Dict;
+              // if compression was enabled write Filter
+              if poCompressFonts in Document.Options then
+              begin
+                D.AddName('Filter','FlateDecode');
+                LastElement.Write(AStream);
+              end;
               // write fontfile stream length in xobject dictionary
-              D:=Document.GlobalXRefs[AObject].Dict;
-              D.AddInteger('Length',M.Size);
+              D.AddInteger('Length',ISize);
               LastElement.Write(AStream);
               WriteString('>>', AStream);
               // write fontfile stream in xobject dictionary
-              TPDFEmbeddedFont.WriteEmbeddedFont(Document, M, AStream);
+              Buf.Position := 0;
+              Buf.SaveToStream(AStream);
             finally
+              Buf.Free;
               M.Free;
             end;
           end;
@@ -3099,8 +3115,8 @@
 
 begin
   FDict:=CreateGlobalXRef.Dict;
-  FDict.AddName('Filter','FlateDecode');
   FDict.AddInteger('Length1 
'+IntToStr(EmbeddedFontNum),StrToInt(FontDef.FOriginalSize));
+  FDict.LastElement.Hidden := not (poCompressFonts in Options);
 end;
 
 procedure TPDFDocument.CreateImageEntry(ImgWidth, ImgHeight, NumImg: integer);
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to