Recent

Author Topic: how to use the units -no information about this  (Read 11481 times)

alaa123456789

  • Full Member
  • ***
  • Posts: 203
Re: how to use the units -no information about this
« Reply #15 on: January 15, 2022, 01:02:52 pm »
RSVG unit how to use it to show svg file on the form


This to get you started. I tried it on one file and it seems right.
Thanks engkin for your help , i tried your code please have a look on attached files ,i had errors

i am using lazarus on windows
thanks

dbannon

  • Hero Member
  • *****
  • Posts: 2018
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to use the units -no information about this
« Reply #16 on: January 15, 2022, 01:15:31 pm »
You clearly have some required units not mentioned in the Uses clauses. PGError

You also seem to have declared variables called Width and Height, but TForm1 being a form, will have its own Width and Height declared, use other names.

Pugchar is also probably a type declared in another unit you need to add to Uses.

Hopefully, the code, not shown in your image will give you a clue about just what those extra units are. Maybe a text search just above where your extra units are installed will help ?

grep -rni PGError <laz_config_dir>

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

alaa123456789

  • Full Member
  • ***
  • Posts: 203
Re: how to use the units -no information about this
« Reply #17 on: January 15, 2022, 01:45:12 pm »


Hopefully, the code, not shown in your image will give you a clue about just what those extra units are. Maybe a text search just above where your extra units are installed will help ?

grep -rni PGError <laz_config_dir>

Davo
the code is done by engkin and it is attached , please download and have a look on it

Quote
You also seem to have declared variables called Width and Height, but TForm1 being a form, will have its own Width and Height declared, use other names.

Pugchar is also probably a type declared in another unit you need to add to Uses.
how we will know where is source unit for this ?
thanks

dbannon

  • Hero Member
  • *****
  • Posts: 2018
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to use the units -no information about this
« Reply #18 on: January 15, 2022, 01:59:15 pm »
Attached ?  I don't see your code attached and its different from what engkin posted earlier (at least in that you have put function into the TForm1).

Did you use the   " ,rsvg  ,gdk2pixbuf; " that engkin mentioned ?  I doubt that he would have posted without testing, his work is good.

Its midnight here, i will be back tomorrow if engkin has not sorted it out by then....

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

alaa123456789

  • Full Member
  • ***
  • Posts: 203
Re: how to use the units -no information about this
« Reply #19 on: January 15, 2022, 02:05:03 pm »
Attached ?  I don't see your code attached and its different from what engkin posted earlier (at least in that you have put function into the TForm1)

Davo

Quote
Did you use the   " ,rsvg  ,gdk2pixbuf; " that engkin mentioned ?  I doubt that he would have posted without testing, his work is good.
yes same i didnt change anything except i added the procedure to form to use it later in button click ,please see the snip for where i attached the code

thanks

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: how to use the units -no information about this
« Reply #20 on: January 15, 2022, 03:58:22 pm »
Sorry for the trouble I caused. While testing, Lazarus added the variables and their units automatically.

Attached is my test. Notice that I intentionally left the console open as it displayed messages about not found font and the replacement font used...etc.


NOTE:
Remove .jpg from the extension, had to add it to please my phone.

alaa123456789

  • Full Member
  • ***
  • Posts: 203
Re: how to use the units -no information about this
« Reply #21 on: January 15, 2022, 05:13:16 pm »
Sorry for the trouble I caused. While testing, Lazarus added the variables and their units automatically.

Attached is my test. Notice that I intentionally left the console open as it displayed messages about not found font and the replacement font used...etc.


NOTE:
Remove .jpg from the extension, had to add it to please my phone.
thanks engkin ,still not working please see photos

thanks

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: how to use the units -no information about this
« Reply #22 on: January 15, 2022, 08:13:33 pm »
Your best bet is to replicate my test. I ran it inside GIMP (I believe it was version 2.0).

BobDog

  • Full Member
  • ***
  • Posts: 248
Re: how to use the units -no information about this
« Reply #23 on: January 15, 2022, 09:24:23 pm »

I don't use the Lazarus ide, but usually Geany.
I give the command line to Geany
FT_00_CM=fpc "%f" -FuC:\\Users\\Computer\\Desktop\\units64 -S2 -Sg -Un -O3 -Op2
As you see I keep a folder units64 on my desktop.
I copy the unit files from the fpc distro and pop them in this folder when needed.
(.ppu and .o)
I dont really bother with TForm1 e.t.c., If I need graphics I can use the graph unit or gdi graphics on the console.








dbannon

  • Hero Member
  • *****
  • Posts: 2018
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to use the units -no information about this
« Reply #24 on: January 16, 2022, 12:13:32 am »
engkin's recent code worked fine for me. I had to do three things -

1. In rsvg, there is an ifdef Windows that sets DYNLINK, but just under it there is another line that defines DYNLINK irrespective of using Windows or not. I am using Linux and needed to comment out the unilateral define.

2. I installed librsvg-dev

3. engkin's code, in unit1, pointed to a specific svg file I did not have. So I copied the powered-by.svg from my Lazarus src to this project's working dir and edited engkin's code accordingly.

It then compiled OK and ran. Initially, I had a just a black window, but realised it was a positioning thing, if I expanded the window, down, there was our familiar logo.

Now, point 1 and 2 are Linux specific but hint that you must have the "SAX renderer" library installed, in Windows I guess thats a DLL. I don't know how DLL's work so don't know if you also need the headers.

The third point is just about putting a suitable svg file somewhere where the app can find it. engkin's code does not test for it apparently.

engkin's code also uses writeln, I'm guessing that means something he has done lets writeln write to a "consol" even though its Windows, way, way beyond my Windows experience, I'd expect that writeln to crash the app.

(but I'd like to know how to do that, I do not understand how anyone can develop code without  a console to drop messages to.)

Overall, with its heavy dependencies on libraries, appears to me that BGRA is still a better option.

EDIT: Getting back to your question, how to use Units ? Your initial try objected to a missing PGError and Pugchar, they are found when you include "glib2" up around line 30 of Unit1.  enjkin also seems to have used "Variants", looks unnecessary to me.

EDIT2: Err, am I missing something here ?  All these GTK calls, unit dependencies etc. How are they going to work on Windows ?  It is possible to install GTK2 on Windows but why would you ?   This looks like Linux only code to me.


Davo
« Last Edit: January 16, 2022, 12:36:47 am by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: how to use the units -no information about this
« Reply #25 on: January 16, 2022, 06:48:46 am »
The third point is just about putting a suitable svg file somewhere where the app can find it. engkin's code does not test for it apparently.

It was a quick test, meant to give a starting point.

engkin's code also uses writeln, I'm guessing that means something he has done lets writeln write to a "consol" even though its Windows, way, way beyond my Windows experience, I'd expect that writeln to crash the app.

(but I'd like to know how to do that, I do not understand how anyone can develop code without  a console to drop messages to.)
For Windows, find it in:
Project Options
  Compiler Options
    Config and Target
      Win32 gui application <==== remove the checkmark


enjkin also seems to have used "Variants", looks unnecessary to me.

To display the results of gdk_pixbuf_get_* calls, but did not need it as the format was described in the unit gdk2pixbuf near the type of variable colorspace. And a few lines of Writeln were good enough.

EDIT2: Err, am I missing something here ?  All these GTK calls, unit dependencies etc. How are they going to work on Windows ?  It is possible to install GTK2 on Windows but why would you ?   This looks like Linux only code to me.

There are good libraries that need GTK to run on Windows. GIMP comes with GTK, probably because it uses GTK dependant libs.



Using a TImage instead of Canvas:
Code: Pascal  [Select][+][-]
  1. uses
  2. ...
  3. ,GraphType
  4. ;
  5.  
  6. procedure Test_rsvg(fn:string; AImage:TImage);
  7. var
  8. ...
  9.   LRawImg:TRawImage; //unit GraphType
  10. begin
  11. ...
  12.   //Draw pix
  13.   LRawImg.Init; //LRawImg is a TRawImage from unit GraphType
  14.   LRawImg.Description.Init_BPP32_R8G8B8A8_BIO_TTB(width,height);
  15.   LRawImg.Data:=pixels;
  16.   LRawImg.DataSize:=width*height*4;
  17.  
  18.   AImage.Width:=width;  //AImage is a TImage
  19.   AImage.Height:=height;
  20.   AImage.Picture.Bitmap.LoadFromRawImage(LRawImg,false);
  21. ...
  22. end;

dbannon

  • Hero Member
  • *****
  • Posts: 2018
    • tomboy-ng, a rewrite of the classic Tomboy
Re: how to use the units -no information about this
« Reply #26 on: January 16, 2022, 07:33:30 am »
certainly not criticizing engkin, far from it !  Just trying to clarify things for our friend alaa123456789.

He is on Windows so might struggle with those GTK libraries. But I am not much help at all on Windows issues. Last time I used Windows for any more than an hour at a time was on Windows98 !

Now, that extra code you posted, it replaces the GTK dependent stuff ?  But he will still need a rsvg dll ?

Thanks for that tip engkin about windows console, will try that next time I am debugger there ! I hate not having a console.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: how to use the units -no information about this
« Reply #27 on: January 16, 2022, 05:49:55 pm »
certainly not criticizing engkin, far from it !  Just trying to clarify things for our friend alaa123456789.

Don't hesitate to criticize. I miss Taazz, he used to do that frequently.

He is on Windows so might struggle with those GTK libraries. But I am not much help at all on Windows issues. Last time I used Windows for any more than an hour at a time was on Windows98 !

Now, that extra code you posted, it replaces the GTK dependent stuff ?  But he will still need a rsvg dll ?

No, it will not replace GTK. It is just a faster way to draw the svg file on a TImage instead of using the TCanvas of the form.

alaa123456789

  • Full Member
  • ***
  • Posts: 203
Re: how to use the units -no information about this
« Reply #28 on: January 16, 2022, 06:12:49 pm »
Quote
Using a TImage instead of Canvas:
Code: Pascal  [Select][+][-]
  1. uses
  2. ...
  3. ,GraphType
  4. ;
  5.  
  6. procedure Test_rsvg(fn:string; AImage:TImage);
  7. var
  8. ...
  9.   LRawImg:TRawImage; //unit GraphType
  10. begin
  11. ...
  12.   //Draw pix
  13.   LRawImg.Init; //LRawImg is a TRawImage from unit GraphType
  14.   LRawImg.Description.Init_BPP32_R8G8B8A8_BIO_TTB(width,height);
  15.   LRawImg.Data:=pixels;
  16.   LRawImg.DataSize:=width*height*4;
  17.  
  18.   AImage.Width:=width;  //AImage is a TImage
  19.   AImage.Height:=height;
  20.   AImage.Picture.Bitmap.LoadFromRawImage(LRawImg,false);
  21. ...
  22. end;
thanks engkin,but could you please complete example because it is like solving a puzzle when i am trying to try your code always have an issue
this time stopped on "pixels" not defined type
we are just beginner to figure out this type to which unit belong it really hard

thanks

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: how to use the units -no information about this
« Reply #29 on: January 16, 2022, 10:11:55 pm »
thanks engkin,but could you please complete example because it is like solving a puzzle when i am trying to try your code always have an issue
this time stopped on "pixels" not defined type
we are just beginner to figure out this type to which unit belong it really hard

No problem, just drop a button and an image on a form and here is the source code:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,StdCtrls,ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1:TButton;
  16.     Image1:TImage;
  17.     procedure Button1Click(Sender:TObject);
  18.   private
  19.   public
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. uses
  30.    rsvg
  31.   ,glib2
  32.   ,gdk2pixbuf
  33.  
  34.   ,GraphType
  35.   ;
  36.  
  37. procedure Test_rsvg(fn:string; AImage:TImage);
  38. var
  39.   e:PGError;
  40.   h:PRsvgHandle;
  41.   buf:PGdkPixbuf;
  42.   channels,bits_per_sample,width,height,rowstride:LongInt;
  43.   colorspace:TGdkColorspace;
  44.   alpha:boolean32;
  45.   pixels:Pguchar;
  46.   LRawImg:TRawImage;
  47. begin
  48.   rsvg_init;
  49.  
  50.   //read a file
  51.   h:=rsvg_handle_new_from_file(pchar(fn),e);
  52.   if h=nil then
  53.   begin
  54.     WriteLn('rsvg_handle_new_from_file: ',e^.message);
  55.     exit;
  56.   end;
  57.  
  58.   //Get pix
  59.   buf:=rsvg_handle_get_pixbuf(h);
  60.  
  61.   //Get pix info
  62.   colorspace       := gdk_pixbuf_get_colorspace(buf);
  63.   channels         := gdk_pixbuf_get_n_channels(buf);
  64.   alpha            := gdk_pixbuf_get_has_alpha(buf);
  65.   bits_per_sample  := gdk_pixbuf_get_bits_per_sample(buf);
  66.   pixels           := gdk_pixbuf_get_pixels(buf);
  67.   width            := gdk_pixbuf_get_width(buf);
  68.   height           := gdk_pixbuf_get_height(buf);
  69.   rowstride        := gdk_pixbuf_get_rowstride(buf);
  70.  
  71.   WriteLn('colorspace      : ', colorspace     );
  72.   WriteLn('channels        : ', channels       );
  73.   WriteLn('alpha           : ', alpha          );
  74.   WriteLn('bits_per_sample : ', bits_per_sample);
  75.   WriteLn('width           : ', width          );
  76.   WriteLn('height          : ', height         );
  77.   WriteLn('rowstride       : ', rowstride      );
  78.  
  79.   //Draw pix
  80.   LRawImg.Init; //LRawImg is a TRawImage from unit GraphType
  81.   LRawImg.Description.Init_BPP32_R8G8B8A8_BIO_TTB(width,height);
  82.   LRawImg.Data     := pixels;
  83.   LRawImg.DataSize := width*height*4;
  84.  
  85.   AImage.Width     := width;  //AImage is a TImage
  86.   AImage.Height    := height;
  87.   AImage.Picture.Bitmap.LoadFromRawImage(LRawImg,false);
  88.  
  89.   //clean up
  90.   rsvg_handle_close(h,e);
  91.   rsvg_term;
  92. end;
  93.  
  94. { TForm1 }
  95.  
  96. procedure TForm1.Button1Click(Sender:TObject);
  97. begin
  98.   Test_rsvg('logo.svg',Image1);
  99. end;
  100.  
  101. end.

Make sure to get the console window by:
Quote
Project Options
  Compiler Options
    Config and Target
      Win32 gui application <==== remove the checkmark

I did some more tests and this library, librsvg-2-2, fails with some files. At this point you better use something else, or if you insist try to get a newer version. The one I have is over 10 years old. But again, I don't see the point. Either way when you test the code, try to use a simple svg file.

 

TinyPortal © 2005-2018