Solved

replace operations in an RTF file

Posted on 2000-03-30
12
155 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
Comment Utility
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
Comment Utility
or probably
memo1.clear;
memo1.lines.add(richedit1.lines);
then other stuff ..
0
 

Author Comment

by:yegor
Comment Utility
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
 

Author Comment

by:yegor
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:yegor
Comment Utility
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
Comment Utility
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
Comment Utility
this link shloud help you:
http://www.wotsit.org/download.asp?f=rtf15
0
 
LVL 4

Expert Comment

by:Radler
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now