TxtToRTF()

TxtToRTF()

Postby byte-one » 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
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: TxtToRTF()

Postby James Bott » Tue Jan 13, 2015 3: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: Select all  Expand view  RUN
/*
Author: Reinaldo Crespo-Bazán
Date   : 10/25/2010
Source: viewtopic.php?f=3&t=15270
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
 
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: TxtToRTF()

Postby byte-one » Wed Jan 14, 2015 8:05 am

James, thanks!
A good code! Meanwhile i found all required functions.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: TxtToRTF()

Postby Antonio Linares » Wed Jan 14, 2015 2: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TxtToRTF()

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TxtToRTF()

Postby byte-one » Thu Jan 15, 2015 3: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
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: TxtToRTF()

Postby James Bott » Thu Jan 15, 2015 5:49 pm

By GTF do you mean "gene transfer format?"
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: TxtToRTF()

Postby reinaldocrespo » Thu Jan 15, 2015 6: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.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: TxtToRTF()

Postby byte-one » 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
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: TxtToRTF()

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TxtToRTF()

Postby nageswaragunupudi » Fri Jan 16, 2015 1: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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: TxtToRTF()

Postby Antonio Linares » Fri Jan 16, 2015 5:23 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TxtToRTF()

Postby MOISES » Fri Mar 13, 2015 3: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
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: TxtToRTF()

Postby James Bott » Fri Mar 13, 2015 6: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: TxtToRTF()

Postby MOISES » Tue Mar 17, 2015 8:51 pm

Up please!.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests