Problem with CairoCanvas pdf text lazarus / 39-Graphics ---------------------------------------------------------------------- ph2 · 2016-11-10 08:06 Hello! I've encountered a problem with CairoCanvas printing out some longer texts out incorrectly when ran on Debian, but working correctly on Ubuntu etc. Text on Debian is printed far left outside the pdf paper area and clipped out, while it is correctly printed on Ubuntu. This is my reduced example code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...type  TTempCairoPdfCanvas = class(TCairoPdfCanvas) ... constructor TTempCairoPdfCanvas.Create;begin  inherited Create;  Stream:=TMemoryStream.Create;  CreateHandle;end;              procedure TForm1.Button1Click(Sender: TObject);var   FDoc: TTempCairoPdfCanvas;   Rect: TRect;   FileStream: TFileStream;begin  FDoc := TTempCairoPdfCanvas.Create;  Rect.Left := 36;  Rect.Right := 503;  Rect.Top := 107;  Rect.Bottom := 123;  FDoc.BeginDoc;  //FDoc.Font.Name:='Times';  FDoc.Font.Name:='Arial';  FDoc.Font.Size:=12;  FDoc.Font.Color:=clBlack;  FDoc.Font.Orientation := 0;   FDoc.Brush.Color:=clBlack;  FDoc.TextRect(Rect, 36, 107, 'Some bit longer text to print out to a pdf file here like this, hope it will print out fine.', FDoc.TextStyle);  FDoc.EndDoc;  FileStream := TFileStream.Create('./test.pdf', fmCreate);  FDoc.Stream.Seek(0, fsFromBeginning);  FileStream.CopyFrom(FDoc.Stream, FDoc.Stream.Size);  FileStream.Free;  OpenDocument('./test.pdf');end; Basically creating a canvas and drawing text on it, then saving the stream to a file. On Ubuntu it works fine, the whole text prints on the page but on Debian, the text only shows 'will print out fine.' When I change the font to Times, now it prints it out fine on Debian as well. Any clue why this might be happening? ---------------------------------------------------------------------- Graeme · 2016-11-10 14:47 Any specific reason you are using CairoPDFCanvas? If not, try fcl-pdf included with FPC (trunk) and will be included with FPC 3.0.2 as well. The code can be copied from FPC (trunk) and used with FPC 2.6.4 as well. The PDF results is consistent no matter the platform. We also tested with about 8 different PDF viewers. ---------------------------------------------------------------------- ph2 · 2016-11-11 07:06 CairoCanvas is used in production code inherited from someone else, currently compiled with FPC 2.6.4. It might be possible to replace it with another package like fcl-pdf with some effort though, but it will require bit of testing to implement. ---------------------------------------------------------------------- marcov · 2016-11-11 08:10 Afaik when a font can't be found, the X system grabs the "nearest" one? So maybe it is a question of making sure the fontpackage with "arial" is also installed on debian? (I assume it is in the fontpackage released by MS?) ---------------------------------------------------------------------- ph2 · 2016-11-11 08:36 I've already installed the Microsoft TrueType core fonts on Debian, didn't change the behaviour before or after. Tested with other famous Microsoft fonts and the text drawing works as expected on other fonts than Arial or Verdana. These two seem to split the text to two lines and draw the first line above the clipped rectangle on the pdf? ---------------------------------------------------------------------- Graeme · 2016-11-11 09:13 I don't know CairoPDFCanvas, but does it adhere to the license of the font? Some fonts don't allow embedding, and fcl-pdf will prevent such fonts from being embedded in a PDF. Then again, if you see partial text using Arial, then it's probably not that. I'm just thinking out loud here. ;-) Again, never used CairoPDFCanvas... How does it know what size Canvas you have? From your code sameple I don't see anything related to the available "canvas" size? Or does CairoPDFCanvas automatically make a canvas large enough for all its content to fit on? With fcl-pdf you set the page size and orientation, and that tells TPDFDocument what space you have to render content per page.