Recent

Author Topic: wrap text around image  (Read 17142 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 444
wrap text around image
« on: September 23, 2016, 05:54:38 pm »
Can a paragraph or image be set to wrap text around the image?

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: wrap text around image
« Reply #1 on: September 23, 2016, 06:47:37 pm »
nope.

KMemo is the only solution I know of.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: wrap text around image
« Reply #2 on: September 23, 2016, 10:26:12 pm »
You sure are selling KMemo.

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: wrap text around image
« Reply #3 on: September 23, 2016, 10:39:54 pm »
Hahaha.. you can imagine that all these threads would go to Kmemo maintainer rather than me!  :D

The actual problem is RichEdit component.. or I should say RichEdit components. It's because all other systems has pretty poor support of layout abilities for their RichEdit components as well.

In the end RichMemo (RichEdit) component is very nice component to show something simple, like End-User agreement or a help for an application.

When it comes to typographical tasks, such as the one you need. It's really not powerful enough.

BUT, in the most recent versions of RichEdit (Windows 8 or so), Microsoft did add the feature to wrap around a pasted image. But these features are not available in Windows XP for sure.

KMemo, is by the only, open source (and thus free) FreePascal and LCL friendly component. It's not relaying on system APIs, like RichMemo does, thus it doesn't have these limitations.

There're some others components, i.e. TSynEdit. But they're more "code-editting" oriented and are not useful for complex scripts processing (like you need).

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: wrap text around image
« Reply #4 on: September 23, 2016, 10:43:20 pm »
1) Btw, there's a way to "emulate" wrapping text around an image.
All you need to do is to set paragraph offset, so it would look like it's wrapping the image.

The image has to be drawn outside of RichMemo's text... which is a completely different story and its own set of complexity.

2) You might want to play with RTF a little bit. (Modern editors should allow you to save an image wrapped by text in RTF). But I doubt RichMemo would be able to replicate that.

3) Yet another thing to try is to use Windows 10 RichEdit .dll on Windows XP machine. I can imagine it won't work, but something that could be tested.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: wrap text around image
« Reply #5 on: September 24, 2016, 02:44:11 pm »
I have tried to use direct RTF commands, but none were effective for the RichMemo driver. It may be possible that Windows 8+ drivers could apply the code.

I also have the PolyEdit word processor, and it can't wrap around an image either, and it is fairly sophisticated.

In addition I have DavkaWriter. It had originally been RTF based, and when it was, it couldn't do image wrapping. Currently it does, but it has a proprietary format, and when it exports to an RTF format it does not include the image if it was a wrap-around object.

So I guess it is a "dead horse" that I am kicking.

Likewise, I haven't looked into it, but I surmise that if Kmemo can do it, it must not be creating RTF files. That, or they are only Windows 8+ compatible.

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: wrap text around image
« Reply #6 on: September 24, 2016, 03:00:58 pm »
try this file.
It's generated in OpenOffice Writer. (see the image).

Wordwad is unable to show wrapping properly.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: wrap text around image
« Reply #7 on: September 24, 2016, 05:26:34 pm »
It looks like it builds a mock image or mask for wrapping. Perhaps like you were referring to with building an image off page. Unfortunately, RichMemo did not load the image from your file. So it can't make use of the method.

PolyEdit, WordPad, and DavkaWriter could not read the file either. The later two even halted, saying that it was a corrupt file. Only OpenOffice could read and display the image. It wrapped fine with it.

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: wrap text around image
« Reply #8 on: September 24, 2016, 06:02:21 pm »
OpenOffice is using a hack. It saves the image as a bookmark.
No surprise other editors are having problems reading it.

One can consider this as openoffice-rtf :)

Consider not using textwrap for this first version. Though it depends on how much time you have (until the release date)

Such issues are reasons for me to advocate for Kmemo, even thought I am not the author of it. It's opensource and can be fixed and update. Something that we don't have with richedits

« Last Edit: September 24, 2016, 06:04:02 pm by skalogryz »

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: wrap text around image
« Reply #9 on: September 24, 2016, 08:25:43 pm »
As I mentioned, I have not reviewed Kmemo. Yet I doubt that their methods are transferable... just like OpenOffice. It is OK for a user that wants to be "stand alone", and it may be the future of RTF, but it is currently a better method for a proprietary editor. Not RTF.

My goals at present are to have an open architecture that all can read. It might be a dumb idea, when it comes down to it, yet as you have said... a first version.

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

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: wrap text around image
« Reply #10 on: September 24, 2016, 08:44:51 pm »
I was going to point out that using REO_WRAPTEXTAROUND should do what you want, but I was not happy with it.

Murray Sargent is one of the few people that might know. In fact he mentioned it while replying to a comment in 2006 on his blog:
Quote
Bob F asked how to wrap text around objects.
...
If you set REO_WRAPTEXTAROUND when inserting the object, the text should wrap around the object, which will be left justified. If you set both REO_WRAPTEXTAROUND and REO_ALIGNTORIGHT, the text should wrap around a right-justified object.

Bob tried it, and:
Quote
REO_WRAPTEXTAROUND seems to work but it appears to have some rather severe painting issues.  And, RichEdit does not save the effect when its content is saved to a file.  That may explain why REO_WRAPTEXTAROUND doesn’t seem to be documented anywhere.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: wrap text around image
« Reply #11 on: September 24, 2016, 08:59:50 pm »
Murray Sargent is one of the few people that might know. In fact he mentioned it while replying to a comment in 2006 on his blog:
The same blog (it looks it's the only page on the internet that actually speaks about the flag)  mentions that the feature only worked in RichEdit 3.0, and was disabled in later versions.
I cannot confirm this, since I tried to downshift from version 4.1 to 3.0 and it didn't make any difference - the flag (even though it is documented in MSDN) doesn't seem to be operational.

I'd personally look into Text Object Model. Maybe one of its interfaces actually allows to control text wrapping, but since no-one else has found it before I don't think it's actually there.
« Last Edit: September 24, 2016, 09:05:40 pm by skalogryz »

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: wrap text around image
« Reply #12 on: September 25, 2016, 02:17:49 pm »
There are three RTF codes that I have tried...  \wraparound  \shpwr2  \shpwrk3

Since they have not had any effect, I have assumed that I don't know how to place them, or RichMemo's RichEdit version doesn't support them, or Windows XP just can't do it. Do you know which of these would be the problem?

Code: Pascal  [Select][+][-]
  1. function BitmapToRTF(pict: TBitmap): string;
  2. var
  3.     bi,bb,rtf: string;
  4.     bis,bbs: Cardinal;
  5.     achar: ShortString;
  6.     hexpict: string;
  7.     I: Integer;
  8. begin
  9.     GetDIBSizes(pict.Handle,bis,bbs);
  10.     SetLength(bi,bis);
  11.     SetLength(bb,bbs);
  12.     GetDIB(pict.Handle,pict.Palette,PChar(bi)^,PChar(bb)^);
  13.  
  14.     rtf := '{\rtf1{\pict\dibitmap '; // method 0
  15.    
  16.     rtf := '{\rtf1{\wraparound\pict\dibitmap ';  // method 1
  17.  
  18.     rtf := '{\rtf1{\shpwr2\pict\dibitmap ';  // method 2
  19.  
  20.     rtf := '{\rtf1{\shpwrk3\pict\dibitmap ';  // method 3
  21.  
  22.     SetLength(hexpict,(Length(bb) + Length(bi)) * 2);
  23.     I := 2;
  24.     for bis := 1 to Length(bi) do
  25.         begin
  26.         achar := Format('%x',[Integer(bi[bis])]);
  27.         if Length(achar) = 1 then achar := '0' + achar;
  28.         hexpict[I-1] := achar[1];
  29.         hexpict[I] := achar[2];
  30.         Inc(I,2);
  31.         end;
  32.     for bbs := 1 to Length(bb) do
  33.         begin
  34.         achar := Format('%x',[Integer(bb[bbs])]);
  35.         if Length(achar) = 1 then
  36.         achar := '0' + achar;
  37.         hexpict[I-1] := achar[1];
  38.         hexpict[I] := achar[2];
  39.         Inc(I,2);
  40.         end;
  41.     rtf := rtf + hexpict + ' }}';
  42.  
  43.     Result := rtf;
  44. end;
  45.  

I have also been assuming that the image frame is applicable to the command requirement.

Rick
« Last Edit: September 25, 2016, 03:09:00 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: wrap text around image
« Reply #13 on: September 25, 2016, 05:54:35 pm »
I don't really know, but checking the RTF version 1.5 Specification showed that shpwrk should be used with shpwr2 or shpwr4. I did not see wraparound.

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: wrap text around image
« Reply #14 on: September 25, 2016, 07:31:17 pm »
Wraparound is found in "Rich Text Format (RTF) Specification Version 1.9.1"

I have been looking more closely at it. It must be accompanied with a rigorous series of commands that define a frame. Its designer must have gone "mad" afterward.. or he already was. I am working at sorting out its puzzle.

It seems that you build a frame (by the series), then you can put something in it (I am hoping an image), and text that is outside of it will wrap around it. That is what I think. I am not certain.

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

 

TinyPortal © 2005-2018