FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HowTo: superscript and subscript with richtextbox.d?

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Thu Jun 02, 2005 10:21 am    Post subject: HowTo: superscript and subscript with richtextbox.d? Reply with quote

The notes with the 05-May-22 snapshot indicates that superscript and subscript are implemented.

I was trying to figure out how to do that. The richtextbox.d has the following, which doesn't seem to provide for direct specification of superscript and subscript:

private const DWORD FONT_MASK = CFM_BOLD | CFM_ITALIC | CFM_STRIKEOUT | CFM_UNDERLINE | CFM_CHARSET | CFM_FACE | CFM_SIZE | CFM_UNDERLINETYPE | CFM_WEIGHT;

Should this also have:
CFM_SUPERSCRIPT | CFM_SUBSCRIPT |
(both seem to work out to be 0x00030000)

from richedit.h (and winapi.h)
#define CFE_SUBSCRIPT 0x00010000
#define CFE_SUPERSCRIPT 0x00020000

#define CFM_SUBSCRIPT CFE_SUBSCRIPT | CFE_SUPERSCRIPT
#define CFM_SUPERSCRIPT CFM_SUBSCRIPT

so that dwEffects can respond to:
CFE_SUBSCRIPT
and
CFE_SUPERSCRIPT

The documentation page at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/charformat2.asp

indicates you can achieve the superscript and subscript effects indirectly by adjusting CFM_SIZE with yHeight and CFM_OFFSET with yOffset, but that seems more complicated.


Also, perhaps code in drawing.d needs to be tweaked:
// Flags.
enum FontStyle: ubyte
{
REGULAR = 0,
BOLD = 1,
ITALIC = 2,
UNDERLINE = 4,
STRIKEOUT = 8,
}


I was going to try to see what would be involved in getting this to work, but I'm unable to use makelib.bat to rebuild dfl.lib (problem with corrupted shell32_dfl.lib and user32_dfl.lib as noted in another post)

Am I doing something wrong? Is the yOffset and yHeight the way to accomplish this? If any case, can you provide a code example?

Thanks for your great work of dfl!
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Jun 02, 2005 11:50 am    Post subject: Re: HowTo: superscript and subscript with richtextbox.d? Reply with quote

Lynn wrote:
The notes with the 05-May-22 snapshot indicates that superscript and subscript are implemented.

I was trying to figure out how to do that. The richtextbox.d has the following, which doesn't seem to provide for direct specification of superscript and subscript:

I forgot about CFE_SUBSCRIPT | CFE_SUPERSCRIPT. DFL is using the yOffset value. Check out the charformat.d example,
Code:
selectionColor = Color(0);
selectedText = "\r\n\r\nH";
selectionFont = new Font("Small Fonts", 6f);
selectionCharOffset = -40;
selectedText = "2";
selectionCharOffset = 0;
selectionFont = font; // Set the font back to the default rtb.font.
selectedText = "O";

selectedText = "\r\n\r\nx";
selectionFont = new Font("Small Fonts", 6f);
selectionCharOffset = 100;
selectedText = "3";
selectionCharOffset = 0;
selectionFont = font; // Set the font back to the default rtb.font.
selectedText = " + 1";
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Thu Jun 02, 2005 1:32 pm    Post subject: Reply with quote

Sorry, I didn't see the charformat.d example. Thanks for providing it, but I'd still appreciate having CFM_SUPERSCRIPT and CFE_SUPERSCRIPT working (as well as CFM_SUBSCRIPT and CFE_SUBSCRIPT).

I'm trying to be able to rebuild dfl.lib with debugging enabled to perhaps help implement this.
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Thu Jun 02, 2005 3:01 pm    Post subject: Reply with quote

I wrestled with Superscript and Subscript capabilities, and have something for you to consider.

winapi.d
Code:

  CFE_SUPERSCRIPT = 0x00020000,  // existing
   
  CFM_SUBSCRIPT = CFE_SUBSCRIPT | CFE_SUPERSCRIPT,
  CFM_SUPERSCRIPT = CFM_SUBSCRIPT,

  CFU_UNDERLINE = 1,


richtextbox.d
Code:

private const DWORD FONT_MASK = CFM_BOLD | CFM_ITALIC |
                       CFM_STRIKEOUT | CFM_UNDERLINE | CFM_CHARSET |
                       CFM_FACE | CFM_SIZE | CFM_UNDERLINETYPE |
                       CFM_WEIGHT | CFM_SUBSCRIPT | CFM_SUPERSCRIPT;
   
final void setSuperscript(bool superscriptFlag)
{
  if(!created) {
    return;
  }      
  CHARFORMAT2A cf;
         
  cf.cbSize = cf.sizeof;
  cf.dwMask = FONT_MASK;
  _getFormat(&cf);

  if (superscriptFlag == true) {
    cf.dwEffects |= CFE_SUPERSCRIPT;
  }
  else {
    cf.dwEffects &= ~CFE_SUPERSCRIPT;
  }
  _setFormat(&cf);
}
   
   
final void setSubscript(bool subscriptFlag)
{
  if(!created) {
    return;
  }      
  CHARFORMAT2A cf;
         
  cf.cbSize = cf.sizeof;
  cf.dwMask = FONT_MASK;
  _getFormat(&cf);

  if (subscriptFlag == true) {
    cf.dwEffects |= CFE_SUBSCRIPT;
  }
  else {
    cf.dwEffects &= ~CFE_SUBSCRIPT;
  }
  _setFormat(&cf);
}


charformat.d
Code:

with(rtb)
{
   selectionColor = Color(0);
   selectedText = "Then the developers said, ";
         
   selectionColor = Color(0xFF, 0, 0);
   selectionFont = new Font("Arial", 12f);
   selectedText = "\"DFL is wonderful\"";
   selectionFont = font; // Set the font back to the default rtb.font.
         
   selectionColor = Color(0);
   selectedText = " and proceeded to ";
       
   setSuperscript(true);
   selectedText = "..1.. ";
         
   setSuperscript(false);
   selectedText = "..2.. ";
         
   selectionFont = new Font("Courier New", 10f, FontStyle.ITALIC);
   selectedText = "astonish the ";

   setSubscript(true);
   selectedText = "..3.. ";
         
   setSubscript(false);
   selectedText = "..4.. ";
       
  selectionFont = new Font("Courier New", 10f,
         cast(FontStyle)(FontStyle.ITALIC | FontStyle.BOLD));
  selectedText = "world ";
         
  selectionFont = font; // Set the font back to the default rtb.font.
  selectedText = "with the app they developed.";
}


The above seems all wrong, but seems to work. I would have expected the LOGFONTA structure to have had variables for lfSubscript and lfSuperscript that would correspond to how lfItalic, lfUnderline, etc. are handled, but LOGFONTA didn't. (Or at least one of them since they are mutually exclusive.)

HTH ... there may certainly be a better way to accomplish this.
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Jun 02, 2005 3:49 pm    Post subject: Reply with quote

Lynn wrote:
I wrestled with Superscript and Subscript capabilities, and have something for you to consider.

Thanks. You're on the right track, but FONT_MASK is only used for selectionFont; it's a mask of flags of things a Font (class instance) sets in a CHARFORMAT2. The dwMask should just be CFM_SUPERSCRIPT | CFM_SUBSCRIPT for this. I'll add selectionSubscript and selectionSuperscript for DFL 0.9.
- Chris
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Thu Jun 02, 2005 4:09 pm    Post subject: Reply with quote

Quote:

I'll add selectionSubscript and selectionSuperscript for DFL 0.9.


Great. Keep up the good work.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group