Adding Subscript/Superscript to a Richedit...

Hi, I don't know if it's possible but I'd like to be able to add a superscript and subscript characters, to a character in a TRichedit. Googling around I've seen some articles outlining some methods that I haven't really tested yet. I'm wondering if the subscript/superscript additions would still be within the "realm" of the one character they were attached to (which is what I'm wanting)... or do the subscript/superscript occupy their own separate character positions within the RichEdit? Ideally I'd like each character of my RichEdit to have both a superscript and a subscript, to which I could assign separate values to (maybe I'm asking for the moon...).
 
I see there is a component "RxRichEdit" ... wondering if anyone has some experience with that. I've never installed anything from the Jvcl/Jedi package before... it seems like a big deal. Would I have to install all the jedi package, or can I just install this RxRichEdit component?

Thanks!
    Shawn

P.S: I use Delphi 7
shawn857Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jimyXCommented:
Hi Shawn,
I don't know if it's possible but I'd like to be able to add a superscript and subscript characters, to a character in a TRichedit

It is possible:
{Source}
//http://www.swissdelphicenter.ch/en/showcode.php?id=1331
uses RichEdit;

type
  TCharacterFormat = (CFM_Superscript, CFM_Subscript, CFM_Normal);

procedure RE_SetCharFormat(RichEdit: TRichEdit; CharacterFormat: TCharacterFormat);
var
  Format: TCharFormat;
begin
  FillChar(Format, SizeOf(Format), 0);
  with Format do
  begin
    cbSize := SizeOf(Format);
    dwMask := CFM_OFFSET;

    case CharacterFormat of
      CFM_Superscript: yOffset := 60;
      CFM_Subscript: yOffset := -60;
      CFM_Normal: yOffset := 0;
    end;
  end;

  Richedit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.SelAttributes.Size:= 6; // reduce the font size, but not necessary
  RE_SetCharFormat(RichEdit1, CFM_Subscript);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  RichEdit1.SelAttributes.Size:= 6; // reduce the font size, but not necessary
  RE_SetCharFormat(RichEdit1, CFM_Superscript);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  RichEdit1.SelAttributes.Size:= 8; // the normal font size
  RE_SetCharFormat(RichEdit1, CFM_Normal);
end;

Open in new window


I'm wondering if the subscript/superscript additions would still be within the "realm" of the one character they were attached to (which is what I'm wanting)... or do the subscript/superscript occupy their own separate character positions within the RichEdit?

When using rtf format (.rtf / .doc files) there are extra format tags added which are invisible, but those keep the effects you apply on the text. i.e in sub/superscript example, your character will still be that one normal character but surrounded with sub/superscript tags:

For instance, this is how empty RichEdit looks when saved to file (.rtf):
{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fnil MS Sans Serif;}}
\viewkind4\uc1\pard\ltrpar\f0\fs16 
\par }
 

Open in new window


When adding 'Shown' as text becomes:
{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fcharset0 Tahoma;}{\f1\fnil MS Sans Serif;}}
\viewkind4\uc1\pard\ltrpar\lang1033\f0\fs16 Shawn\lang1025\f1 
\par }
 

Open in new window


When apply subscript on 'w':
{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1025{\fonttbl{\f0\fswiss\fcharset0 Tahoma;}{\f1\fnil MS Sans Serif;}}
\viewkind4\uc1\pard\ltrpar\lang1033\f0\fs16 Sha\dn6\fs12 w\up0\fs16 n\lang1025\f1 
\par }
 

Open in new window


But of course you don't see those formatting tags unless you use notepad to open the .rtf files.

Ideally I'd like each character of my RichEdit to have both a superscript and a subscript, to which I could assign separate values to (maybe I'm asking for the moon...)

What do you mean? one character has both formats at the same time? You need to explain more please.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shawn857Author Commented:
Hi Jimy, thanks for replying. Yes, each character in the RichEdit having BOTH a subscript and a superscript at the same time - like in the image attached. Is that possible?

Thanks!
     Shawn
supersub.PNG
0
jimyXCommented:
> "RxRichEdit" ... wondering if anyone has some experience with that.
it seems like a big deal. Would I have to install all the jedi package, or can I just install this RxRichEdit component?

I haven't used this component.
But with jedi package, you have to install the whole thing.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

jimyXCommented:
> each character in the RichEdit having BOTH a subscript and a superscript at the same time - like in the image attached. Is that possible?

If that could be done with WordPad it could be done with RichEdit.
Have you tried WordPad?
Let me find out...

PS: I will be away for couple of hours.
0
shawn857Author Commented:
I found this article on how to make subscript/superscript in Wordpad:

http://www.keynotesupport.com/pc/word-wordpad-keyboard-shortcuts.shtml

It looks like it treats the subscript (or superscript) as a whole new character.

Thanks
   Shawn
0
jimyXCommented:
> It looks like it treats the subscript (or superscript) as a whole new character.

I don't think so, again with 'shawn' added as text in WrodPad, and 'w' is subscript-ed, rtf looks:
{\rtf1\fbidis\ansi\ansicpg1256\deff0\nouicompat\deflang1025{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 6.2.9200}\viewkind4\uc1 
\pard\ltrpar\sa200\sl276\slmult1\f0\fs22\lang9 sha\sub w\nosupersub n\par
}
 

Open in new window


So no new character, the 'w' was stressed with tag "sub".

That doesn't seem possible in WordPad nor in RichEdit, not even with basic MS Word, unless using Add-ons and most likely those add-ons use objects to handle such char complexity combination, similar to math equations. At the end you will be working inside framework that accepts certain set of symbols rather than merely adding characters and apply simple styles on them.
0
shawn857Author Commented:
Yeah that sounds like it would be more trouble than it's worth, wouldn't it? Not to worry anyway Jimy - all I had to do was sleep on it last night and I came up with a much more elegant and clean solution to my problem than using subscripts/superscripts! Sorry for the wild goose chase and thank you for your attention.

Cheers
   Shawn
0
jimyXCommented:
Probably it would have been troublesome.
Glad you sort it out, to the way you like.
0
shawn857Author Commented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.