Does anybody have examples for the package CairoCanvas_pkg that comes with Lazarus?
The package dir has none.
I am most interested in textual data + PDF, thus TCairoPdfCanvas and TCairoPsCanvas, but other examples are welcome, too.
Regards,
Juha

Mailing lists / lazarus / 2015-02
24 messages · 6 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Does anybody have examples for the package CairoCanvas_pkg that comes with Lazarus?
The package dir has none.
I am most interested in textual data + PDF, thus TCairoPdfCanvas and TCairoPsCanvas, but other examples are welcome, too.
Regards,
Juha
TCairoCanvas works as clasic TCanvas.
You can create TCairo*Canvas of your choice, set some specific properties as OutputFileName, XDPI, YDPI, PaperWidth, PaperHeight, Orientation and draw on it like on normal TCanvas.
Petr
Petr Kristan wroteTCairoCanvas works as clasic TCanvas.
Thanks, I will experiment with it.
What is the purpose of unit CairoCanvasAll?
First it says :
{ The CairoCanvas package can be compiled on all platforms. This unit defines what units are available on which platform. }
but then :
{$IFNDEF win64}
uses
{%H-}CairoCanvas, {%H-}CairoPrinter;
{$ENDIF}as if Win64 was not supported.
Juha
Strange.
I am testing on Windows, Gtk+ for Windows runtime environment is installed. My project depends on cairocanvas_pkg.lpk
When I run the test below without the TextOut line, it works and file "abcdef.pdf" indeed contains an ellipse.
With the TextOut line it throws a SIGFPE. I cannot step into the method even with all debug info enabled.
In Assembler debug window I can see it happened in _cairo_win32_font_face_scaled_font_create.
Ideas? How to solve it? Could it be some missing DLL? It did not complain about DLLs.
Am I doing something very stupid? It is possible because I have limited experience with graphics and canvas methods.
Juha
---
uses ... ,
CairoCanvas;
...
procedure TForm1.Button1Click(Sender: TObject);
var
PdfCanvas: TCairoPdfCanvas;
begin
PdfCanvas := TCairoPdfCanvas.Create;
try
PdfCanvas.OutputFileName := 'abcdef.pdf';
PdfCanvas.Ellipse(20, 20, 50, 70);
PdfCanvas.TextOut(50, 100, 'abcdef');
finally
PdfCanvas.Free;
end;
end;
---On Linux it does not throw an exception but it does not work either. There is no text.
I tested other CairoCanvas variants, PS and PNG, and they behave the same. The code is in ancestor TCairoPrinterCanvas.TextOut.
Has anybody tried text output with CairoCanvas? Maybe it only works with graphics.
Juha
I normaly use it with graphics.
My commandline program version must be linked with gtk in linux. I use this construction:
WidgetSet := TGtk2WidgetSet.Create;
DrawingRoutine;
FreeAndNil(WidgetSet);Petr
How to use the WidgetSet?
Can you please test with TextOut(), and maybe send a simple example program or application. I still have not found any. I would be happy to add an "example" directory below components\cairocanvas if you want.
Juha
I normaly use it with graphics. My commandline program version must be linked with gtk in…
Petr Kristan wroteMy commandline program version must be linked with gtk in linux.
Then it is not really a command line program! ;-)
Regards,
- Graeme -
Does anybody have examples for the package CairoCanvas_pkg that comes with Lazarus? The…
Juha Manninen wroteI am most interested in textual data + PDF, thus TCairoPdfCanvas and TCairoPsCanvas, but other examples are welcome, too.
Must you use Cairo? I'm just asking, because if Cairo is not a requirement then very good alternatives exits.
eg: I've used AggPas (one included with fpGUI as it is more up to date than the Lazarus one) in console and CGI apps to generate graphs and images (with or without text) - no dependencies on GUI toolkits or external libraries.
For PDF output, again fpGUI includes an excellent custom written PDF engine which I have used for reporting in my commercial software. It has some excellent features other pascal based PDF engines don't have. I believe Michael van Canneyt also used it as the basis for the new PDF engine included with FPC trunk.
Regards,
- Graeme -
How to use the WidgetSet? Can you please test with TextOut(), and maybe send a simple…
Here is an linux working example:
{$mode objfpc}{$H+}
uses
Classes, SysUtils, Gtk2Int, InterfaceBase, CairoCanvas,
GdkCairoCanvas, Printers;
var
c: TFilePrinterCanvas;
begin
WidgetSet := TGtk2WidgetSet.Create;
c := TCairoPdfCanvas.Create(nil);
c.OutputFileName := '/tmp/a.pdf';
c.XDPI := 75;
c.YDPI := 75;
c.PaperWidth := 100;
c.PaperHeight := 100;
c.Font.Name := 'Arial';
c.Font.Height := 12;
c.TextOut(0, 0, 'Hello word');
FreeAndNil(c);
FreeAndNil(WidgetSet);
end.Petr
Must you use Cairo? I'm just asking, because if Cairo is not a requirement then very…
I did not know of such PDF engine. So far I know that PowerPdf lib is limited.
External library dependencies are not desired and this sounds promising! What about font embedding and Unicode support in PDF? What is the best way to test it? From fpGUI or from FPC trunk? Does your version have many dependencies for other parts of fpGUI?
Juha
Juha Manninen wroteI did not know of such PDF engine. So far I know that PowerPdf lib is limited.
That's normally the case - the internet is full of unknown gems. :) A couple months back somebody asked about PDF engines in one of the mailing lists. I posted the few I knew about after I did my own research. PowerPDF was not that great.
What about font embedding and Unicode support in PDF?
Both supported.
What is the best way to test it? From fpGUI or from FPC trunk?
To be honest, I haven't tried the one Michael created yet. He just asked me how to get in contact with the original author for the PDF engine included with fpGUI so he could ask permission and credit him. Michael is probably the best person to answer questions about the one in FPC trunk.
The engine in fpGUI has a very small dependency on fpGUI, but that is very easy to refactor and abstract out. A few minutes dependency is mainly due to the "print preview" window functionality.
fpGUI includes a PDF demo: <fpgui>/examples/gui/reporting/
The demo shows single & multiple pages, sections, graphs, outlines, grids, embedded images and font support. It can also preset viewing preferences when viewing with Adobe Acrobat Reader or compatible viewers.
Does your version have many dependencies for other parts of fpGUI?
No. It is 100% implemented in Object Pascal, and I would estimate 95% is all non-gui code. As I mentioned, it is pretty much only the print preview window which ties it to fpGUI.
Regards,
- Graeme -
It is a completely reworked version of the one in fpGUI, without external dependencies but with serious improvements: the font embedding in the fpgui version is, well, rudimentary, so that has been completely reworked, it can now embed fonts on-the-fly, without external tools :)
I also made a start of improving memory usage, page caching and made the start for compression.
I haven't committed the reworked version yet, but it is nearly complete, so you can expect this soon.
Michael.
Here is an linux working example: {$mode objfpc}{$H+} uses Classes, SysUtils, Gtk2Int,…
Petr Kristan wrotec.Font.Name := 'Arial'; c.Font.Height := 12;
Wow, my test code only needed the font definition, then it works. My bad, I should have tested that. Normal GUI canvas has some font by default. I added a simple program to components/cairocanvas/example which draws an ellipse and text.
You can improve it if you want and send a patch.
Your example adds a dependency for GTK2. It is logically wrong if you only want to demonstrate CairoCanvas.
My understanding is that GTK2 depends on CairoCanvas, not the other way around. What is the purpose of the WidgetSet variable? You create it but don't use it for anything. My prog works without it now that it has a font defined. The only dependency in the uses section of my program is CairoCanvas.
Juha
It is a completely reworked version of the one in fpGUI, without external dependencies…
Sounds very good! This will be included in some future FPC release. Even better! I will be following the trunk commits.
BTW, does anybody know how to create PDFs with embedded fonts in a server without X or any other GUI?
What libs are needed?
Juha
You can check libharu.
Michael
The only snag is that the Unicode support hasn't been released last time I checked, so you'll have to build the development version from source. We embed the Liberation TrueType fonts and that works quite well.
Henry
Wow, my test code only needed the font definition, then it works. My bad, I should have…
It is about two years when I used this last time. And it was neded. It is good to hear, that I can remove this dependency.
Petr
It is a completely reworked version of the one in fpGUI, without external dependencies…
Michael Van Canneyt wroteso that has been completely reworked, it can now embed fonts on-the-fly, without external tools :)
Oh, that would be a welcome change. Because of that external tool (it worked but was clunky), I kept my reports with the standard PDF fonts.
Regards,
- Graeme -
On Tue, Feb 10, 2015 at 2:27 PM, Michael Van Canneyt Sounds very good! This will be…
Juha Manninen wroteBTW, does anybody know how to create PDFs with embedded fonts in a server without X or any other GUI? What libs are needed?
This should be possible with the one included in fpGUI, once you strip the print preview dependency. Not a large job, so could be done in a pinch until Michael releases the one in FPC trunk.
The other concern (?) is if the one in trunk could work with FPC 2.6.4 too? In case developers want to use the PDF engine, but not move their projects to FPC trunk (unicode RTL etc).
Regards,
- Graeme -
Must you use Cairo? I'm just asking, because if Cairo is not a requirement then very…
Where can I download that aggpas?
Mattias
Mattias Gaertner wroteWhere can I download that aggpas?
It's included in the fpGUI repo (latest is in the 'develop' branch), but can still be used stand-alone.
https://github.com/graemeg/fpGUI/tree/develop/src/corelib/render/software
Regards,
- Graeme -
This should be possible with the one included in fpGUI, once you strip the print preview…
Graeme Geldenhuys wroteThe other concern (?) is if the one in trunk could work with FPC 2.6.4 too? In case developers want to use the PDF engine, but not move their projects to FPC trunk (unicode RTL etc).
That is not a problem. I am now experimenting with FPC 3 anyway. I am testing the FpGui version until Michael commits his. The dependency for FpGui does not matter during tests.
One property name is wrong, should be PaperWidth.
property PaperHeight: integer read GetPaperHeight;
property PagerWidth: integer read GetPaperWidth;The API is very different than what for example PowerPdf has. I must lean it more and ask questions in FpGui list.
Regards,
Juha
Juha Manninen wroteproperty PagerWidth: integer read GetPaperWidth;
Ah, well spotted. I'll fix this right now.
The API is very different than what for example PowerPdf has.
As far as I understood the author wrote everything from scratch based directly on the PDF specification - he didn't use any existing projects or libraries as the base.
I'm also still in the process of translating all the French words in the code to English.
Regards,
- Graeme -