Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

replace operations in an RTF file

Posted on 2000-03-30
12
160 Views
Last Modified: 2010-04-04
Hello!

I have an RTF file containing five different fonts, intermixed, so that a word is sometimes written with two or three fonts...

What I need is to replace all characters of a given font (one after another) with characters of a different font (having another encoding)... and to do that many times, processing all the alphabet, so that finally I have an RTF file containing only one font (but its encoding differs from that of the original fonts).

I have tried to use the standard methods, like

RichEdit1.FindText(...);
RichEdit1.SelLength := ...;
if RichEdit1.SelAttributes.Name = ... then begin
RichEdit1.SelText := ...
RichEdit1.SelAttributes.Name := ...
     end;

yet all this does not seem to work!

Problems:

1. EXTREMELY slow,
2. takes up so much resources that the machines nearly hangs if the file is "large" (50 Kb!!!).

I would be very grateful for a working piece of code. It's an absolutely urgent job.

A lot of thanks in advance,

yegor
0
Comment
Question by:yegor
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2671165
HI
for a quick an easy way
you could always do something like:
(memo1 is hidden)

memo1.lines := richedit1.lines;
richedit1.clear;
richedit1.font. := ...
" -- "   . style := ...
" -- " . color := ...
richedit1.lines := memo1.lines;
memo1.clear;

that would make all the same text in richedit.

BTW
  you.ve asked this question twice better delete the other copy to save your points .
0
 
LVL 17

Expert Comment

by:inthe
ID: 2671172
or probably
memo1.clear;
memo1.lines.add(richedit1.lines);
then other stuff ..
0
 

Author Comment

by:yegor
ID: 2671296
I see I have not explained my problem clearly enough... An example of what I am in need of advice on:

a word in RTF:

#x //in font 1
#x //in font 2
#y //in font 3
#y //in font 4

has to be changed (depending on the fonts used for each character!) to:

#a1 //new font
#a2 //new font, etc.

The problem is that the same character of the original RTF file has to be changed into DIFFERENT characters when in DIFFERENT fonts. So every time before converting the RichEdit1.SelAttributes.Name has to be checked somehow to determine what character to change to...

yegor
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:yegor
ID: 2671304
I see I have not explained my problem clearly enough... An example of what I am in need of advice on:

a word in RTF:

#x //in font 1
#x //in font 2
#y //in font 3
#y //in font 4

has to be changed (depending on the fonts used for each character!) to:

#a1 //new font
#a2 //new font, etc.

The problem is that the same character of the original RTF file has to be changed into DIFFERENT characters when in DIFFERENT fonts. So every time before converting the RichEdit1.SelAttributes.Name has to be checked somehow to determine what character to change to...

yegor
0
 
LVL 2

Expert Comment

by:rene100
ID: 2672410
I think there is no other solution as to change the rtf-code directly....all other possibilites will be too slow...it shouldn't be too hard to to that: rtf stores all used fonts in a fonttabel at the beginning of the file, giving then indexes to the fonts (f0....fn), so you have to search these indexes, then you know which font is used for which text.

regards
rene
0
 
LVL 4

Expert Comment

by:Radler
ID: 2673093
Hi yegor,

A hint to solve your problem:
To call your replacement code do this:
begin
   RichEdit1.Lines.BeginUpdate;
   MakeMyChanges( RichEdit1 );
   RichEdit1.Lines.EndUpdate;
end;

If dont appreciated tell us.
Good luck.
T++, Radler.
0
 

Author Comment

by:yegor
ID: 2674656
rene100,

yes, this seems to be the only way... I know about the font labels at the beginning of an rtf file, but I do not know what to do next, I mean, it looks like

\par 2 \'d1\plain\lang1024\f8\fs16 \'e5\plain\lang1024\f2\fs16 \'e9 \'e1\plain\lang1024\f5\fs16 \'fd\plain\lang1024\f2\fs16  \plain\lang1024\f6\fs16 \'e8\plain\lang1024\f2\fs16 \'f1\'ea\'ee\'ed\plain\lang1024\f5\fs16 \'e8\plain\lang1024\f2\fs16  \'ea\'fa \'e1\plain\lang1024\f4\fs16 \'e3\plain\lang1024\f2\fs16 \'f3:
\par 3 \'e2\'f1\plain\lang1024\f7\fs16 \'ff\plain\lang1024\f2\fs16  \'f2\plain\lang1024\f8\fs16 \'fd\plain\lang1024\f2\fs16 \'ec\'fa \'e1\plain\lang1024\f8\fs16 \'fb\plain\lang1024\f2\fs16 \'f8\'e0, \plain\lang1024\f6\fs16 \'e8\plain\lang1024\f2\fs16  \'e1\'e5\plain\lang1024\f12\fs16 \'e7\plain\lang1024\f2\fs16  \'ed\'e5\'e3w \'ed\'e8\'f7\'f2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'e6\'e5 \'e1\plain\lang1024\f8\fs16 \'fb\plain\lang1024\f2\fs16 \'f1\'f2\'fc, \plain\lang1024\f9\fs16 e\plain\lang1024\f2\fs16 \'e6\'e5 \'e1\plain\lang1024\f8\fs16 \'fb\plain\lang1024\f2\fs16 \'f1\'f2\'fc.
\par 4 \'c2\'fa \'f2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'ec\'fa \'e6\'e8\'e2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'f2\'fa \'e1\plain\lang1024\f5\fs16 \'fd\plain\lang1024\f2\fs16 , \plain\lang1024\f6\fs16 \'e8\plain\lang1024\f2\fs16  \'e6\'e8\'e2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'f2\'fa \'e1\plain\lang1024\f5\fs16 \'fd\plain\lang1024\f2\fs16  \'f1\'e2\plain\lang1024\f8\fs16 \'fd\plain\lang1024\f2\fs16 \'f2\'fa \'f7\'e5\'eb\'ee\'e2\plain\lang1024\f8\fs16 \'fd\plain\lang1024\f2\fs16 \'eaw\'ec\'fa:

etc.

I know that \par marks the beginning of a new line, but I do not know where the description of a character starts and where it ends... and what all these 'c1 refer to... otherwise I would have processed that as a plain text file without asking for help... if you know where to get a readable description of rtf format specification, I shall be grateful if you let me know...

Radler, perhaps it is a good idea, if it helps recover the resources barbarously eaten up by standard rtf processing... I shall try and then come back again.

Thank you,

yegor
0
 

Author Comment

by:yegor
ID: 2674695
rene100,

yes, this seems to be the only way... I know about the font labels at the beginning of an rtf file, but I do not know what to do next, I mean, it looks like

\par 2 \'d1\plain\lang1024\f8\fs16 \'e5\plain\lang1024\f2\fs16 \'e9 \'e1\plain\lang1024\f5\fs16 \'fd\plain\lang1024\f2\fs16  \plain\lang1024\f6\fs16 \'e8\plain\lang1024\f2\fs16 \'f1\'ea\'ee\'ed\plain\lang1024\f5\fs16 \'e8\plain\lang1024\f2\fs16  \'ea\'fa \'e1\plain\lang1024\f4\fs16 \'e3\plain\lang1024\f2\fs16 \'f3:
\par 3 \'e2\'f1\plain\lang1024\f7\fs16 \'ff\plain\lang1024\f2\fs16  \'f2\plain\lang1024\f8\fs16 \'fd\plain\lang1024\f2\fs16 \'ec\'fa \'e1\plain\lang1024\f8\fs16 \'fb\plain\lang1024\f2\fs16 \'f8\'e0, \plain\lang1024\f6\fs16 \'e8\plain\lang1024\f2\fs16  \'e1\'e5\plain\lang1024\f12\fs16 \'e7\plain\lang1024\f2\fs16  \'ed\'e5\'e3w \'ed\'e8\'f7\'f2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'e6\'e5 \'e1\plain\lang1024\f8\fs16 \'fb\plain\lang1024\f2\fs16 \'f1\'f2\'fc, \plain\lang1024\f9\fs16 e\plain\lang1024\f2\fs16 \'e6\'e5 \'e1\plain\lang1024\f8\fs16 \'fb\plain\lang1024\f2\fs16 \'f1\'f2\'fc.
\par 4 \'c2\'fa \'f2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'ec\'fa \'e6\'e8\'e2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'f2\'fa \'e1\plain\lang1024\f5\fs16 \'fd\plain\lang1024\f2\fs16 , \plain\lang1024\f6\fs16 \'e8\plain\lang1024\f2\fs16  \'e6\'e8\'e2\plain\lang1024\f8\fs16 \'ee\plain\lang1024\f2\fs16 \'f2\'fa \'e1\plain\lang1024\f5\fs16 \'fd\plain\lang1024\f2\fs16  \'f1\'e2\plain\lang1024\f8\fs16 \'fd\plain\lang1024\f2\fs16 \'f2\'fa \'f7\'e5\'eb\'ee\'e2\plain\lang1024\f8\fs16 \'fd\plain\lang1024\f2\fs16 \'eaw\'ec\'fa:

etc.

I know that \par marks the beginning of a new line, but I do not know where the description of a character starts and where it ends... and what all these 'c1 refer to... otherwise I would have processed that as a plain text file without asking for help... if you know where to get a readable description of rtf format specification, I shall be grateful if you let me know...

Radler, perhaps it is a good idea, if it helps recover the resources barbarously eaten up by standard rtf processing... I shall try and then come back again.

Thank you,

yegor
0
 
LVL 2

Accepted Solution

by:
rene100 earned 400 total points
ID: 2674719
this link shloud help you:
http://www.wotsit.org/download.asp?f=rtf15
0
 
LVL 4

Expert Comment

by:Radler
ID: 2674827
I've thinked about this way rene, but I'm incert about the yegor detail's operations, so a bit harder answer after this try.

T++, Radler.
0
 

Author Comment

by:yegor
ID: 2675189
Thank you all. As usual, I do not know how to make one half of my points go to one expert, and the other half to another (this would be fair I think)... Since no such option is provided, my points go to rene100. Radler, you have a chance to get all the points I still have by answering my next question (I think it's easier than this one...)

And a final remark (maybe that's interesting): I have found a quick and dirty work-around for my problem: I have converted the rtf file to html (there's lot of programs which do this) and processed it as a plain text file. As html syntax is quite clear and straitforward, this has worked fine...

Thank you all, and please help me with my next problem,

yegor
0
 
LVL 4

Expert Comment

by:Radler
ID: 2680278
Hi yegor,

Thanks by consideration.
Your second doubt is about the system resources spended by this operation. without a code snipet is too hard give a hint, but the first is check for memory leaks.


T++, Radler.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question