Recent

Author Topic: RichMemo Insert Graphics  (Read 11979 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 444
RichMemo Insert Graphics
« on: August 01, 2016, 07:08:50 pm »
Using Windows XP Pro, Laz vrs 1.4.4, FPC vrs 2.6.4, windows unit

I am employing the following two procedures to insert a graphic at a text position.
I have already tried to use your InDelInline(inlineimg, PageMemo.SelStart, 0, ImgSize)
method, and it works... but I can't figure out how to load a disk image into an ImageList.

So I have been trying to use this different method that is supposed to do the same thing.
My current problem is that it crashes in the GetImageFile at "if not OpenPictureDialog1.Execute then exit;"

It reports: Raised exception class "External: SIGSEGV" in the above quoted code line.

That crash is before it gets to "InsertImageFromFile(PageMemo, PageMemo.SelStart, ImgFile, ImgSize)",
which is what I expect to perform the task.

I need to be able to insert images, such as GIS and aerials, into the document.
Afterward I am wanting to be able to resize the image to fit within the page size.

Code: Pascal  [Select][+][-]
  1. procedure TCmdForm.MnuDiskImageClick(Sender: TObject);
  2. var
  3.   //inlineimg: TInlineImage;
  4.   InsImage: TImage;
  5.   ImgSize: Types.TSize;
  6.   ImgWide,ImgTall: integer;
  7.   ImgFile: string;
  8. begin
  9.  
  10.   { // using this section
  11.   OpenDialog1.Title:= 'Select Image-File';
  12.   OpenDialog1.Filter:= 'Jpeg (*.jpg)|*.jpg|Ping (*.png)|*.png|Tiff (*.tif)|*.tif';
  13.   OpenDialog1.Execute;
  14.   if (OpenDialog1.Files.Count = 1) and (FileExistsUTF8(OpenDialog1.FileName))
  15.      then begin
  16.           // not being used
  17.           end;
  18.   } // end of not using this section
  19.  
  20.   GetImageFile;  // used instead of the above
  21.  
  22.   ImgFile:= OpenPictureDialog1.Filename;
  23.   InsImage.Picture:= Image1.Picture;
  24.  
  25.   InsImage.proportional:= true;
  26.   ImgWide:= round(InsImage.Width*72/96);
  27.   ImgTall:= round(InsImage.Height*72/96);
  28.   ImgSize:= Types.Size(ImgWide,ImgTall);
  29.  
  30.   //InsertImageFromFileNoResize(PageMemo, PageMemo.SelStart, ImgFile);
  31.   InsertImageFromFile(PageMemo, PageMemo.SelStart, ImgFile, ImgSize);
  32.  
  33.   // Inline example. It works... but coding an image into ImageList is not obvious.
  34.   (*
  35.   //ImageList2.LoadFromFile(ImgFile);  // ??? an idea, but not tested
  36.   inlineimg:= TInlineImage.Create;
  37.   inlineimg.imageList:=ImageList2;
  38.   inlineimg.frame:=framecnt;
  39.  
  40.   // must use Types.Size and the following method to avoid conflict...
  41.   ImgWide:= round(ImageList2.Width*72/96);
  42.   ImgTall:= round(ImageList2.Height*72/96);
  43.   ImgSize:= Types.Size(ImgWide,ImgTall);
  44.  
  45.   PageMemo.InDelInline(inlineimg, PageMemo.SelStart, 0, ImgSize);
  46.  
  47.   inc(framecnt);
  48.   if framecnt>=ImageList1.Count then framecnt:=0;
  49.   *)
  50. end;
  51.  
  52. procedure TCmdForm.GetImageFile;
  53. begin
  54.   //OpenPictureDialog1.Options:= OpenPictureDialog1.Options+[ofFileMustExist];    // has a conflict
  55.   if not OpenPictureDialog1.Execute then exit;
  56.   try
  57.     //--------------------------------------------------------------------------
  58.     // Loading directly into a TImage. This will load any registered image
  59.     // format. .bmp, .xpm, .png are the standard LCL formats.
  60.     // The jpeg units register .jpeg and .jpg.
  61.     Image1.Picture.LoadFromFile(OpenPictureDialog1.Filename);
  62.     //--------------------------------------------------------------------------
  63.  
  64.     //UpdateInfo(OpenPictureDialog1.Filename);  // has a conflict
  65.   except
  66.     on E: Exception do begin
  67.       MessageDlg('Error','Error: '+E.Message,mtError,[mbOk],0);
  68.     end;
  69.   end;
  70. end;
  71.  

Rick
« Last Edit: August 13, 2016, 08:28:08 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: RichMemo Insert Graphics
« Reply #1 on: August 02, 2016, 03:00:39 pm »
That crash is before it gets to "InsertImageFromFile(PageMemo, PageMemo.SelStart, ImgFile, ImgSize)",
which is what I expect to perform the task.
Apparently the problem is not with RichMemo itself but the code loading the image.

I'm attaching a sample project that allows to insert an arbitrary image (.png, .jpg or .bmp) file into RichMemo.

But...

I need to be able to insert images, such as GIS and aerials, into the document.
Afterward I am wanting to be able to resize the image to fit within the page size.

RichMemo is not very usable for formatting tasks as you need it. At least at the moment.
It doesn't have any capabilities of resizing the inserted image.
It doesn't (and it seems like it won't) have any abilities to make the text flow around the image.

For sophisticated tasks I'd recommend to use other controls. For example K-Memo

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #2 on: August 02, 2016, 05:57:37 pm »
OK. I finally got my chicken between the asterisks (see the attach file)! Thanks for the help. There isn't anything intuitive about doing graphics.

However, the image is not selectable for copying or deleting. I did not include the list code. Is that the problem?

I am also going to need to access its properties so that I may resize it. Are those things doable?

The following is how I had to implement your code...

Code: Pascal  [Select][+][-]
  1. procedure TCmdForm.MnuDiskImageClick(Sender: TObject);
  2.   var
  3.     pic : TPicture;
  4.     ip  : TRichMemoInlinePicture;
  5.     sz  : TSize;
  6.   begin
  7.     OpenDialog1.Title:= 'Select Image-File';
  8.     OpenDialog1.Filter:= 'Jpeg (*.jpg)|*.jpg|Ping (*.png)|*.png|Tiff (*.tif)|*.tif';
  9.     if OpenDialog1.Execute then begin
  10.       pic:=TPicture.Create;
  11.       try
  12.         pic.LoadFromFile(OpenDialog1.FileName);
  13.       except
  14.         on e: Exception do begin
  15.           pic.Free;
  16.           ShowMessage('unable to read image file: '+OpenDialog1.FileName+#13#10+e.Message);
  17.           Exit;
  18.         end;
  19.       end;
  20.       ip:=TRichMemoInlinePicture.Create(pic);
  21.  
  22.       // todo: Size is expected to be in points, not image pixel!!!
  23.       sz:=Types.Size(round(pic.Width*72/96), round(pic.Height*72/96));  //  Types.Size instead of Size
  24.  
  25.       PageMemo.InDelInline(ip, PageMemo.SelStart, 0, sz);
  26.       //picList.Add(pic);  // don't know what the list is for
  27.       //pic.free;
  28.     end;
  29.   end;
  30.  

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: RichMemo Insert Graphics
« Reply #3 on: August 02, 2016, 06:02:41 pm »
However, the image is not selectable for copying or deleting. I did not include the list code. Is that the problem?
I am also going to need to access its properties so that I may resize it. Are those things doable?
I'm afraid this is where opensource principle has to come into play.

There's no RichMemo api what would allow you to do that.
However, there're Windows API what could allow you to implement the mentioned above.
You could add the necessary routines to RichMemo. (If you're going to do that please send patches).

If you're looking for a ready-to-go solution, I'd recommend to review K-Memo.


rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #4 on: August 02, 2016, 06:17:29 pm »
skalogryz,

I had originally looked into K-controls and K-memo, but I was discouraged by their note..  "printing and previewing might not work in some widgetsets in Lazarus". I am not familiar with what widgetsets actually are, but printing is important to me, and I saw that RichMemo was printing.

As to messing with lower level system functions, I don't think I am up to it. I haven't kept up with that stuff since the DOS days. I have only done high level programming ever since Turbo Pascal hit the market.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: RichMemo Insert Graphics
« Reply #5 on: August 03, 2016, 02:36:40 pm »
I had originally looked into K-controls and K-memo, but I was discouraged by their note..  "printing and previewing might not work in some widgetsets in Lazarus". I am not familiar with what widgetsets actually are, but printing is important to me, and I saw that RichMemo was printing.
Well, the same applies to RichMemo. It's generally because printing itself might be developed well enough for a particular widgetset.
Even more, RichMemo printing was more or less tested in Windows. For other widgetsets it has not been even started.

As to messing with lower level system functions, I don't think I am up to it. I haven't kept up with that stuff since the DOS days. I have only done high level programming ever since Turbo Pascal hit the market.
I could create some routines for you, that could help making an inserted image selectable and resize it.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #6 on: August 03, 2016, 02:40:38 pm »
skalogryz,

Quote
I could create some routines for you, that could help making an inserted image selectable and resize it.

Please do... I could use the help.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #7 on: August 03, 2016, 02:49:41 pm »
I installed K-controls and gave it a run through. It failed at reading a semitic UTF8 file. It showed a content area for it, but the entire section was white. One of my goals is to compose a Biblical Text reader/editor, which encompasses Hebrew, Syriac, Greek, and English. Richmemo has already succeeded at loading the entire Syriac New Testament.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: RichMemo Insert Graphics
« Reply #8 on: August 03, 2016, 03:05:21 pm »
It failed at reading a semitic UTF8 file.
btw, can I have an example of the file? (it's needed to improve RTF support for Linux system)

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #9 on: August 03, 2016, 04:46:31 pm »
Licensing is involved. The file was constructed by a scholar who also engages in profit. It is available for personal and academic use, but not for commercial use without paying a contractual fee. I don't expect that your use would be commercial, but I also can't be sure of how it might be passed around.

Nevertheless, if a small portion of the file will serve your needs, it would be allowed by the less than 10% rule (as to the document's total volume). If however you need the entire file I will have to ask you to acquire it directly from him. I am sure he would accept you on an academic license.

Rick
« Last Edit: August 03, 2016, 06:48:20 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #10 on: August 03, 2016, 09:37:54 pm »
skalogryz

See if the attached works for your testing needs. It contains an RTF, PDF, TXT, OTF, Licence and ReadMe files.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #11 on: August 05, 2016, 03:55:17 pm »
I just noticed that the inserted image doesn't save with the file. It loads back without the image. This the asterisk to asterisk RTF code that appears in the file... *{\pict\wmetafile0
}*

Look like it needs to be converted into one of these beasties...

Code: Pascal  [Select][+][-]
  1. {\pict\wmetafile8\picw8994\pich6746\picwgoal5099\pichgoal3825
  2. 0100090000033afc0100000024fc01000000050000000b0200000000050000000c025a1a222324
  3. fc0100430f2000cc000000ff005401000000005a1a2223000000002800000054010000ff000000
  4. 010018000000000004f80300c40e0000c40e000000000000000000001a0b081b0c09160b07241b
  5. 18302b2a1f1d1d1b1d1e393e41111a1e0812190b151f1d29332b39452636432d3a4a3c4c594558
  6. 5f1e32373c50554a606551676d546a70243b430c262d122d372b485148646f34545f2343502648
  7. 55274a573356602340493b575e4561683c585f48646b4561683650574e686f5c767d5771783f59
  8. 60253f462b454c49636a587279556d733e515813232900050b09131a090b150000080d0c160a09
  9. 13070511060813010714000713192c39354d59314c5a3d5a68304a5a314b5c3f57694a62743e54
  10. 662135471223361425382a3b4e1b2f410f23351f3547223a4c304a5b4f697a3d5a6931515c3d5d
  11. 684b6b7650707b4969743a5a652b4856213e4c304b5925404e1e3747263d4d35495a3
  12. }
  13.  

The above is a partial code list. I had to chop off a very large portion of the code to be able to post it.

Rick
« Last Edit: August 05, 2016, 04:22:16 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #12 on: August 05, 2016, 04:30:49 pm »
I copy/pasted the previously posted glyph code from another editor. But after saving it, and then loading it into RichMemo, it would not read the glyph code. It just ignored it, and showed the page without it.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: RichMemo Insert Graphics
« Reply #13 on: August 05, 2016, 05:18:06 pm »
Licensing is involved.
Maybe, but not for this code...
It it simply that Windows Meta files are not supported by default on *nixes.
Just convert the metafile to a bmp or jpg or png if you need it on other platforms.
Windows meta files are a proprietary format. And there are libraries under linux that can read and write them (multiple).
Specialize a type, not a var.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: RichMemo Insert Graphics
« Reply #14 on: August 05, 2016, 06:35:14 pm »
Thaddy,

The file that was loaded into each editor was a JPG, and I am using Windows XP.

btw. Your quote from "Licensing is involved" is in reference to another issue.

Thanks for your reply, Rick.
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

 

TinyPortal © 2005-2018