Opened 4 years ago

Closed 21 months ago

Last modified 16 months ago

#12541 closed defect (fixed)

Allow using -1 font size to mean default

Reported by: wbruhin Owned by:
Priority: normal Milestone: 3.0.0
Component: wxMSW Version: 2.9.1
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

It looks like the problem is simply that the -1 is not causing wxFont on Windows to use the default font's size. It looks like a bunch of stuff was changed in 2.9, but I'm not sure I understand all the changes. In 2.8 we had code like this:

m_pointSize = pointSize == -1 ? wxNORMAL_FONT->GetPointSize() : pointSize;

But in 2.9 it looks like it is converting the point size to a pixel size and it is not checking for -1 at all:

const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
lf.lfHeight = -(int)((pointsize*((double)ppInch)/72.0) + 0.5);

See also email thread on wxPython-dev "wxPy2911preview - default font size - wxWidgets" in Oct 2010.

Change History (7)

comment:1 Changed 4 years ago by wbruhin

Could have been clearer, above is Robin Dunn's response to the following issue reported by jmfauth:

With 2.8 no problem. The font size can be defined in the frame or in the panel with an hard coded size or default size (-1).

  • With 2.9.preview. It's ok, only if the font size is explicitly given (eg 8). If the font size is -1, this defaut font size is not propagated (or rendered correctly) to the children widgets and the widgets are showing on font size closed to, let's say, 1.

comment:2 Changed 4 years ago by vadz

  • Milestone set to 3.0
  • Status changed from new to confirmed
  • Summary changed from setting font size to -1 does not propagate to Allow using -1 font size to mean default

The fact that -1 worked to mean "default font size" in 2.8 was wholly accidental. The only documented way to create a font with default size always was to use wxDEFAULT (which is admittedly a problem in its own right, see #12315).

Maybe we should just change wxDEFAULT value to -1 to allow existing code to work? It seems like a logical thing to do but I just can't help wondering what else is it going to break... But in any case you shouldn't be using hard-coded -1 in your code.

comment:3 Changed 4 years ago by robind

wxGTK is still checking for -1 and also wxDEFAULT.

    SetPointSize( (pointSize == wxDEFAULT || pointSize == -1)
                    ? wxDEFAULT_FONT_SIZE
                    : pointSize );

With a quick browse through wxOSX code it looks it, like wxMSW is not checking for either.

comment:4 Changed 4 years ago by robind

  • Version changed from 2.9.0 to 2.9.1

comment:5 Changed 4 years ago by robind

wxMSW is, of course, checking for wxDEFAULT, but not in the same place where -1 was being checked in 2.8 so I missed it.

comment:6 Changed 21 months ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [73104]) Allow specifying -1 as font size to mean "default" in wxMSW.

This has never been officially documented but used to work in 2.8 and still
works in wxGTK, so make it works in wxMSW too for consistency.

Closes #12541.

comment:7 Changed 16 months ago by VZ

(In [73884]) Allow using wxDEFAULT as font size in wxOSX.

Using wxDEFAULT as the font size in wxOSX resulted in creating 70pt font,
change this to use the normal font size instead for compatibility with the
other platforms.

Also allow using -1 as wxDEFAULT for compatibility with wxGTK, see #12541.

Note: See TracTickets for help on using tickets.