FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TxtToRTF()
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
TxtToRTF()
Posted: Tue Jan 13, 2015 12:59 PM

Is there a function Text-Format 2 RTF-Format and visversa and other functions to manage the RTF-Format?
Thanks!

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: TxtToRTF()
Posted: Tue Jan 13, 2015 03:33 PM
Here is one from my notes. Reinaldo seems to know a lot about it. You might also search the forum if you haven't already.

James

Code (fw): Select all Collapse
/*
Author: Reinaldo Crespo-Bazán
Date   : 10/25/2010 
Source: <!-- l --><a class="postlink-local" href="http://forums.fivetechsupport.com/viewtopic.php?f=3&t=15270">viewtopic.php?f=3&t=15270</a><!-- l -->
Note: Convert RTF text to plain text
*/

#DEFINE _cREGEX "\{?\\([a-z]{1,32}[0-9]* ?)([A-z, ]*;)?|}"  //includes fonts

function GetTextFromRTF( cRtfText, lKeepCRLFs )
    local aRet 
    local cStrip, i

    DEFAULT cRtfText := ""
    DEFAULT lKeepCRLFs := .t.
    
    aRet := hb_RegExAll( _cREGEX, cRtfText, .f. )

    if aRet == Nil  ;return cRtfText    ;endif
    
    aSort( aRet,,, { |x,y| len( x[1] ) > len( y[1] ) } )
    for i := 1 to len( aRet )

        cRtfText := StrTran( cRtfText, aRet[ i, 1 ], "" )
        
    Next 
    
    if !lKeepCRLFs
        cRtfText := StrTran( cRtfText, CRLF, " " )
    endif

Return cRtfText
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: TxtToRTF()
Posted: Wed Jan 14, 2015 08:05 AM

James, thanks!
A good code! Meanwhile i found all required functions.

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TxtToRTF()
Posted: Wed Jan 14, 2015 02:36 PM

Günther,

If you want to convert a RTF into standard text, then using a RichEdit control, you could do this:

oRichEdit:LoadRTF( cRTFText ) // RTF

MsgInfo( oRichEdit:GetText() ) // standard text

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TxtToRTF()
Posted: Wed Jan 14, 2015 11:16 PM
byte-one wrote:James, thanks!
A good code! Meanwhile i found all required functions.

Can you please share?
Regards



G. N. Rao.

Hyderabad, India
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: TxtToRTF()
Posted: Thu Jan 15, 2015 03:49 PM

Thanks to all!
In the meantime after tests i found, that many problems are waiting for me, using RTF for my project. Now i explored the GTF-Format. This is for me the right way as the complete source is reachable and no DLL is required.

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: TxtToRTF()
Posted: Thu Jan 15, 2015 05:49 PM

By GTF do you mean "gene transfer format?"

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: TxtToRTF()
Posted: Thu Jan 15, 2015 06:29 PM
Hi everyone;

oRichEdit:GetText()


Yes GetText() method works best but requires to initialize the object which will require a dialog or window. When working on the background , when pulling text from a Blob field or when no RichText object is needed, then my function GetTextFromRTF() is the only choice.

Now i explored the GTF-Format


What is GTF format? Is there a class like RichText(). Please share the code. Thank you.


Reinaldo.
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: TxtToRTF()
Posted: Thu Jan 15, 2015 10:41 PM

Reinaldo, GTF is part from FW! See FORMAT GET.
It can handle texts with different textcolors, fonts and aligns word for word or paragraph. RTF is much more complex!

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TxtToRTF()
Posted: Thu Jan 15, 2015 11:50 PM
Reinaldo

Yes GetText() method works best but requires to initialize the object which will require a dialog or window. When working on the background , when pulling text from a Blob field or when no RichText object is needed, then my function GetTextFromRTF() is the only choice.

Your function works very well in most cases, but was failing when the rtf contained embedded tables and other objects. Have you improved it recently?
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TxtToRTF()
Posted: Fri Jan 16, 2015 01:51 AM

Once we create a richedit control (we can even use a hidden window) it is very easy to convert text to rtf or rtf to text. It is much better to have a function like Reinaldo's which works in all cases.

I am also looking for it there is any way to "render" rtf and html in a rectangle (not a control). I greatly appreciate any suggestions.

Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: TxtToRTF()
Posted: Fri Jan 16, 2015 05:23 AM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 838
Joined: Wed Aug 22, 2007 10:09 AM
Re: TxtToRTF()
Posted: Fri Mar 13, 2015 03:46 PM

Hello,

I am searching too a function like this one, but with accent support, lists, bullets, boxes, pictures, etc to be removed.

Is there an update?.

Thank you very much.

Saludos / Regards,



FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: TxtToRTF()
Posted: Fri Mar 13, 2015 06:41 PM
Rao,

I am also looking for it there is any way to "render" rtf and html in a rectangle (not a control). I greatly appreciate any suggestions.


What do you mean by a rectangle? Just an enclosed area?

Why can't it be a control?

You could probably use a window, dialog, or TPanel object.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 838
Joined: Wed Aug 22, 2007 10:09 AM
Re: TxtToRTF()
Posted: Tue Mar 17, 2015 08:51 PM

Up please!.

Saludos / Regards,



FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40