Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-02

Examples of CairoCanvas usage

24 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Juha Manninen

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

Reply by email

Petr Kristan
to Juha Manninen
Juha Manninen wrote 6 lines
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.

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 . EPOS PRO s.r.o., Smilova 333, 530 02 Pardubice tel: +420 461101401 Czech Republic (Eastern Europe) fax: +420 461101481

Reply by email

Juha Manninen
to Petr Kristan
Petr Kristan wrote
TCairoCanvas 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

Reply by email

Juha Manninen
to Juha Manninen

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;
---

Reply by email

Juha Manninen
to Juha Manninen

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

Reply by email

Petr Kristan
to Juha Manninen
Juha Manninen wrote 7 lines
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.

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

Petr Kristan . EPOS PRO s.r.o., Smilova 333, 530 02 Pardubice tel: +420 461101401 Czech Republic (Eastern Europe) fax: +420 461101481

Reply by email

Juha Manninen
to Petr Kristan
Petr Kristan wrote 6 lines
My commandline program version must be linked with gtk in linux. I use this construction: WidgetSet := TGtk2WidgetSet.Create; DrawingRoutine; FreeAndNil(WidgetSet);

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

Reply by email

Graeme Geldenhuys
to Juha Manninen: Does anybody have examples for the package CairoCanvas_pkg that comes with Lazarus? The…
Juha Manninen wrote
I 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 -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Petr Kristan
to Juha Manninen: How to use the WidgetSet? Can you please test with TextOut(), and maybe send a simple…
Juha Manninen wrote 13 lines
On Tue, Feb 10, 2015 at 9:14 AM, Petr Kristan wrote: > My commandline program version must be linked with gtk in linux. > I use this construction: > > WidgetSet := TGtk2WidgetSet.Create; > DrawingRoutine; > FreeAndNil(WidgetSet); 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.

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

Petr Kristan . EPOS PRO s.r.o., Smilova 333, 530 02 Pardubice tel: +420 461101401 Czech Republic (Eastern Europe) fax: +420 461101481

Reply by email

Juha Manninen
to Graeme Geldenhuys: Must you use Cairo? I'm just asking, because if Cairo is not a requirement then very…
Graeme Geldenhuys wrote 10 lines
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.

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

Reply by email

Graeme Geldenhuys
to Juha Manninen
Juha Manninen wrote
I 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 -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 20 lines
On 2015-02-10 09:42, Juha Manninen wrote: > > I 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.

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.

Reply by email

Juha Manninen
to Petr Kristan: Here is an linux working example: {$mode objfpc}{$H+} uses Classes, SysUtils, Gtk2Int,…
Petr Kristan wrote
c.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

Reply by email

Juha Manninen
to Michael Van Canneyt: It is a completely reworked version of the one in fpGUI, without external dependencies…
Michael Van Canneyt wrote 10 lines
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.

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

Reply by email

Michael Van Canneyt
to Juha Manninen
Juha Manninen wrote 19 lines
On Tue, Feb 10, 2015 at 2:27 PM, Michael Van Canneyt wrote: > 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. 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?

You can check libharu.

Michael

Reply by email

Henry Vermaak
to Michael Van Canneyt
Michael Van Canneyt wrote 22 lines
On Tue, 10 Feb 2015, Juha Manninen wrote: >On Tue, Feb 10, 2015 at 2:27 PM, Michael Van Canneyt > wrote: >>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. > >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? You can check libharu.

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

Reply by email

Petr Kristan
to Juha Manninen: Wow, my test code only needed the font definition, then it works. My bad, I should have…
Juha Manninen wrote 17 lines
On Tue, Feb 10, 2015 at 11:40 AM, Petr Kristan wrote: > c.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.

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

Petr Kristan . EPOS PRO s.r.o., Smilova 333, 530 02 Pardubice tel: +420 461101401 Czech Republic (Eastern Europe) fax: +420 461101481

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: It is a completely reworked version of the one in fpGUI, without external dependencies…
Michael Van Canneyt wrote
so 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 -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Graeme Geldenhuys
to Juha Manninen: On Tue, Feb 10, 2015 at 2:27 PM, Michael Van Canneyt Sounds very good! This will be…
Juha Manninen wrote
BTW, 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 -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Juha Manninen
to Graeme Geldenhuys: This should be possible with the one included in fpGUI, once you strip the print preview…
Graeme Geldenhuys wrote
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).

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

Reply by email

Graeme Geldenhuys
to Juha Manninen
Juha Manninen wrote
property 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 -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email