Re: Wx

  • From: <jaffar@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 25 Mar 2008 22:40:13 +0800

Hi Octavian. Here are some notes for you which i had gotten from my research. I have tried them and they work, but i would think the best way would be to call the DC or draw context function. Anyway, I had the 3 outlined methods tried out, all worked successfully, and you can choose which method would suit you best.

Notes below.
Implementing superscript/subscript
1. Representation
In richtextbuffer.h (or textctrl.h in SVN trunk), we have the
wxTEXT_ATTR_EFFECT_SUBSCRIPT and wxTEXT_ATTR_EFFECT_SUPERSCRIPT text
effect styles defined. So you would do this programmatically:
wxTextAttrEx attr;
attr.SetTextEffects(wxTEXT_ATTR_EFFECT_SUPERSCRIPT);
attr.SetTextEffectFlags(wxTEXT_ATTR_EFFECT_SUPERSCRIPT);
control->SetStyle(from, to, attr);
(The purpose of SetTextEffectFlags is to indicate which flags are
relevant to the current operation, i.e. setting the given styles.)
In Word and OpenOffice, the font you specify for the superscript text is
not the one that’s used – some multiplication factor is used to scale
the font. This could be hardwired, simplifying the API, or it could be
specified (optionally). You might use an existing field to do this, e.g.
m_outlineLevel since this is a paragraph attribute and wouldn’t be used
for at the character level anyway. You could have new functions to
access this, e.g. wxTextAttrEx::SetScriptSize,
wxTextAttrEx::GetScriptSize. A value of zero would cause the default to
be used. We would probably need an extra flag, wxTEXT_ATTR_SCRIPT_SIZE
to indicate whether this is set.
I’m also assuming that the positioning is hard-wired to be the top or
the bottom of the text to the left of the super/subscript text. This
probably doesn’t need customisation.
2. Drawing implementation
In wxRichTextPlainText::Draw, the new effect flags will need to be
checked – if either is present, the smaller font must be created from
the current attribute font and a scale factor, and x and y text
positions should be recalculated to allow for the smaller font. So,
something like:
if (textAttr.GetFont().Ok()) // this has been moved up w.r.t. current
SVN so GetCharHeight returns correct value
wxCheckSetFont(dc, textAttr.GetFont());
int charHeight = dc.GetCharHeight();
int x = rect.x;
int y = rect.y + (rect.height - charHeight - (descent - m_descent));
if (textAttr.HasTextEffects() & (textAttr.GetTextEffects() &
(wxTEXT_ATTR_EFFECT_SUBSCRIPT| wxTEXT_ATTR_EFFECT_SUPERSCRIPT)))
{
wxFont scriptFont(textAttr.GetFont().GetPointSize() * 0.5, ...);
wxCheckSetFont(dc, scriptFont);
// y is already correct for superscript
if (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT)
{
y = rect.y + (rect.height – dc.GetCharHeight() – (descent – m_descent)
}
}
wxRichTextPlainText::GetRangeSize needs a similar treatment to make sure
the text width is calculated using the smaller font, but the height
should continue to reflect the specified (larger) font. So
dc.GetCharHeight() should be used to calculate the line height with the
_attribute_ font set in the DC, whereas ‘w’ should be calculated with
smaller font set.
3. UI implementation
The font page (richtextfontpage.h/cpp) needs to be updated to allow
specification of superscript or subscript. This can be done with 3-state
checkboxes via the DialogBlocks .pjd file in src/richtextctrl (copy an
existing one, e.g. Capitals). Then the code in TransferDataFromWindow/
TransferDataToWindow needs changing – should be obvious from the
existing handling what’s required. It probably also needs event handlers
for the two new checkboxes to clear (or rather make indeterminate) the
other checkbox so you can’t specify subscript and superscript
simultaneously.
UpdatePreview() can be updated to simply scale the font if either of the
new styles are set.
Cheers!
----- Original Message ----- From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, March 25, 2008 6:15 PM
Subject: Re: Wx


Ok, thanks Jaffar. I am using the font class, and TextAttr, but I don't know how to set superscripts or subscripts.

I tried to find if there is a method, or maybe a hack for assigning a pre-made RTF string to the rich text widget, but I also couldn't find it. That way could have been a solution for creating superscripts or subscripts.

Thanks.


Octavian

----- Original Message ----- From: <jaffar@xxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, March 25, 2008 11:35 AM
Subject: Re: Wx


Hi Octavian. Yes it is possible if you call the font class, then assign atributes to it. I'll do some research later and give you more details. Cheers! ----- Original Message ----- From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, March 25, 2008 2:10 AM
Subject: Wx


Hi,

Does anyone know if wxWidgets TextCtrl widget allows using superscripts or subscripts when the control is used as a Rich Text control?

Thanks.

Octavian

__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind


__________ Information from ESET Smart Security, version of virus signature database 2929 (20080307) __________

The message was checked by ESET Smart Security.

http://www.eset.com



__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind


__________ Information from ESET Smart Security, version of virus signature database 2929 (20080307) __________

The message was checked by ESET Smart Security.

http://www.eset.com



__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

  • Follow-Ups:
    • Re: Wx
      • From: Octavian Rasnita
  • References:
    • Wx
      • From: Octavian Rasnita
    • Re: Wx
      • From: jaffar
    • Re: Wx
      • From: Octavian Rasnita

Other related posts: