#569 ooDialog - getTextSize broken

v4.0
closed
5
2012-08-14
2009-01-17
No

ooDialog uses an external function: GetStdTextSize() to calculate the size of a rectangle needed to display any give string in dialog units.

This function is very broken in that it will only return the correct result if the dialog is using the System 8 pt font. If the dialog is using any other font, the results are incorrect, sometimes by a lot.

System 8 pt font was the font used for dialogs in early versions of Windows. But today, no (hardly any) dialog box uses System 8 pt.

The problem is compounded because GetStdTextSize() is used in the implementation of a number of methods in different classes throughout ooDialog.

I am attaching a sample program that demonstrates the problem when run under 3.2.0. To run the programy you need all 3 files:

calcStringSizeStraight.rex
fontCalcStraight.rc
resource.h

The program uses getTextSize() to calculate the size of a rectanger needed for each of 3 strings:

San Diego is great
ooRexx is the best
And ooDialog is better

It then places the strings in a straight line on the dialog book with no space between each string. It also has a push button allowing the font to be increased.

It shows that the strings are never aligned correctly under 3.2.0 and that the problem gets worse the bigger the font.

Discussion

  • Mark Miesfeld

    Mark Miesfeld - 2009-01-17

    Program showing getTextSize() problem

     
  • Mark Miesfeld

    Mark Miesfeld - 2009-01-17

    Resource script file for the program

     
    Attachments
  • Mark Miesfeld

    Mark Miesfeld - 2009-01-17

    File Added: fontCalcStraight.rc

     
  • Mark Miesfeld

    Mark Miesfeld - 2009-01-17

    File Added: resource.h

     
  • Mark Miesfeld

    Mark Miesfeld - 2009-01-17

    Symbol definition file for the program

     
    Attachments
  • Mark Miesfeld

    Mark Miesfeld - 2009-01-19

    Committed revision 3964.

    This commit removes the broken GetStdTextSize() external function and replaces it with code written using the 4.0.0 native API, that works correctly. Function is provided to get the text size in either dialog units or in pixels. Dialog units would be used to help lay out a dialog template. Pixels are used to position / re-position controls after the underlying dialog is created.

    Two methods are added to support this

    getTextSizeDlg() (Dialog units)
    getTextSizeScreen() (Pixels)

    The documented getTextSize() method is marked as deprecated and simply forwards to getTextSizeDlg() which takes the same args.

    The undocumented getStdTextSize() method was removed, since it had never been documented. It was completely broken, returning the (incorrect) size in pixels some times and the (incorrect) size in dialog units at other times. getTextSizeScreen() implements what I took to be its intended function, correctly.

    This change has the potential of altering the appearance of current ooDialog programs. Which is why I was careful to put all the changes, and only the changes, in this one commit. It could be backed out.

    Take the case where a user is trying to position controls using the size of text labels and the getTextSize() method. Because GetStdTextSize() was broken for any dialog using a font other than 8 pt System, the user would not get the controls positioned correctly. (If they were using a different font.) If they hard coded in a fudge factor to try and fix the positioning, it is likely that the fudge factor will now be off.

    We'll have to see what comes up in the beta.

    This commit also fixes [ 2516354 ] Standard dialogs in ooDialog use archaic Windows font. The fix to both bugs is intertwined because of the use of GetStdTextSize() throughout the ooDialog code.

     
  • Mark Miesfeld

    Mark Miesfeld - 2010-02-19

    The fix for this item was in the 4.0.0 release.

     


Anonymous

Cancel  Add attachments





Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks