Board index » delphi » TRichEdit - subscripts, superscripts ?

TRichEdit - subscripts, superscripts ?

Is it possible to display subscripts and superscripts with TRichEdit? For
instance I want to write x^2 or sqr(x), in a proper science way ?

Best regards

Ivan

 

Re:TRichEdit - subscripts, superscripts ?


Quote
In article <3a6df554_1@dnews>, Ivan Voutchkov wrote:
> Is it possible to display subscripts and superscripts with TRichEdit? For
> instance I want to write x^2 or sqr(x), in a proper science way ?

Well, yes and no <g>. You have to use a little API here since the
TTextAttributes class used to implement DefAttributes does not surface this
ability (since it was designed to be compatible to TFont).

You should be able to set sub/superscripts by sending an EM_SETCHARFORMAT
message to a TRichedit. Something like this:

 Var
   format: TCharFormat;  { defined in Unit RichEdit }

 FillChar( format, sizeof(format), 0);
 With format Do Begin
   cbSize:= Sizeof(format);
   dwMask:= CFM_OFFSET;
   yOffset:= 60;    { superscript by 60 twips, negative values give
subscripts}
 End;  
 richedit1.Perform( EM_SETCHARFORMAT, SCF_SELECTION,
                    LongInt(@format));

The message affects the current selection. If there is none it will affect
new text inserted via seltext.

The problem here is that the rich edit common control version 1 does not
adjust the line spacing properly when you add sub- or superscripted text to
a line, the text may be cut off at the top or bottom. This version of the
control also has no way to manually adjust the linespacing. There are
wrappers for version 2 and 3 of the control around, e.g. the TRxrichEdit
component in RXLib. These versions handle sub/superscripted text correctly
but they require riched20.dll on the target system and it may not be
present on all of them.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: Till Feb.2001 i will only visit the groups on weekends, so  be
patient if i don't reply immediately.

Re:TRichEdit - subscripts, superscripts ?


Thanks Peter. As always - very helpful. However, where do I get the RXLib
from ? Couldn't I for instance supply riched20.dll with the installation
package ? Would this solve the problem of not having the file on the target
system ?

regards

Ivan

"Peter Below (TeamB)" <100113.1...@compuXXserve.com> wrote in message
news:VA.000067e3.013339fd@antispam.compuserve.com...

Quote
> In article <3a6df554_1@dnews>, Ivan Voutchkov wrote:
> > Is it possible to display subscripts and superscripts with TRichEdit?
For
> > instance I want to write x^2 or sqr(x), in a proper science way ?

> Well, yes and no <g>. You have to use a little API here since the
> TTextAttributes class used to implement DefAttributes does not surface
this
> ability (since it was designed to be compatible to TFont).

> You should be able to set sub/superscripts by sending an EM_SETCHARFORMAT
> message to a TRichedit. Something like this:

>  Var
>    format: TCharFormat;  { defined in Unit RichEdit }

>  FillChar( format, sizeof(format), 0);
>  With format Do Begin
>    cbSize:= Sizeof(format);
>    dwMask:= CFM_OFFSET;
>    yOffset:= 60;    { superscript by 60 twips, negative values give
> subscripts}
>  End;
>  richedit1.Perform( EM_SETCHARFORMAT, SCF_SELECTION,
>                     LongInt(@format));

> The message affects the current selection. If there is none it will affect
> new text inserted via seltext.

> The problem here is that the rich edit common control version 1 does not
> adjust the line spacing properly when you add sub- or superscripted text
to
> a line, the text may be cut off at the top or bottom. This version of the
> control also has no way to manually adjust the linespacing. There are
> wrappers for version 2 and 3 of the control around, e.g. the TRxrichEdit
> component in RXLib. These versions handle sub/superscripted text correctly
> but they require riched20.dll on the target system and it may not be
> present on all of them.

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!
> Note: Till Feb.2001 i will only visit the groups on weekends, so  be
> patient if i don't reply immediately.

Re:TRichEdit - subscripts, superscripts ?


Quote
In article <3a70794a_1@dnews>, Ivan Voutchkov wrote:
> Thanks Peter. As always - very helpful. However, where do I get the RXLib
> from ?

  http://www.rxlib.com

Quote
> Couldn't I for instance supply riched20.dll with the installation
> package ?

You have to check on Microsofts websize whether this DLL is redistributable.
There are probably different versions for Win9x and NT, if you install the
wrong one you can seriously{*word*222}up a users system. And it may depend on
other system DLLs as well.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: Till Feb.2001 i will only visit the groups on weekends, so  be patient
if i don't reply immediately.

Re:TRichEdit - subscripts, superscripts ?


RxLib can be found at www.rxlib.com.

The RTF 3.0 dll can be found in the MS Office Resource Kit.  Check the MS
web site.  I believe that there is only 1 version of the dll but I'm not
sure.  NT4.0 supports RTF ver 2.0, while WIN 2K supports RTF 3.0.  Also try
doing a Search on www.dogpile.com for Rich Text Format.  I'd send you my
links but Windows crashed on me about 2 weeks ago and I lost them all :(
--

Roy Owen
Servant PC Resources, Inc.

Other Threads