[ wxwindows-Bugs-1910313 ] GetTextExtent wrong results for JP font

SourceForge.net noreply at sourceforge.net
Mon Mar 10 15:00:37 PDT 2008


Bugs item #1910313, was opened at 2008-03-08 17:54
Message generated for change (Comment added) made by dwhetstone
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1910313&group_id=9863

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: wxMac specific
Group: Platform specific
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: David Whetstone (dwhetstone)
Assigned to: Stefan Csomor (csomor)
Summary: GetTextExtent wrong results for JP font

Initial Comment:
GetTextExtent() on wxMac 2.8.7 returns incorrect results for japanese and other similar fonts.  The following code draws two strings, one in roman characters and another in japanese characters.  Each string has a red rectangle drawn to its text extent. While the roman string is neatly encompassed by its rectangle, the rectangle for the japanese string falls far short.  An image of the result is attached.

#include "wx/wx.h"

class TestFrame : public wxFrame
    {
    public:
        TestFrame() : wxFrame(NULL, wxID_ANY, wxT("Test"))
        {
        }
        
        void DrawString(wxDC& dc, const wxString & txt, int vOffset)
        {
            wxSize sz = GetClientSize();
            wxSize ext = dc.GetTextExtent(txt);
            
            int x = wxMax(0, (sz.x-ext.x)/2);
            int y = wxMax(0, (sz.y-ext.y)/2) + vOffset;
            
            dc.SetPen(*wxRED_PEN);
            dc.DrawRectangle(x, y, ext.x, ext.y);
            dc.SetPen(*wxBLACK_PEN);
            dc.DrawText(txt, x, y);
        }
        
        void OnPaint(wxPaintEvent& event)
        {
            wxPaintDC dc(this);
            wxFont font(24, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
            font.SetNoAntiAliasing(true);
            dc.SetFont(font);
            DrawString(dc, wxT("ABCDE"), -25);
            DrawString(dc, wxT("カタカナ ひらがな ローマ字"), 25);
        }
        
    private:
        DECLARE_EVENT_TABLE()
    };

BEGIN_EVENT_TABLE(TestFrame, wxFrame)
EVT_PAINT(TestFrame::OnPaint)
END_EVENT_TABLE()

class TestApp : public wxApp
    {
    public:
        bool OnInit()
        {
            TestFrame * frame = new TestFrame();
            frame->Show(true);
            return true;
        }
    };

DECLARE_APP(TestApp)
IMPLEMENT_APP(TestApp)



----------------------------------------------------------------------

>Comment By: David Whetstone (dwhetstone)
Date: 2008-03-10 15:00

Message:
Logged In: YES 
user_id=989860
Originator: YES

csomor: I'm getting different results from you.  This bug also exists for
me with the current trunk (2.9), built with the same configure options
(repeated here because of line breaks in my previous post).  

../configure --enable-universal_binary
--with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk
--with-macosx-version-min=10.4  --disable-shared --enable-unicode
--disable-debug --enable-catch_segvs  --enable-graphics_ctx
--enable-mediactrl --with-opengl --enable-monolithic --with-libjpeg=builtin
--with-libpng=builtin --with-libtiff=builtin --with-expat=builtin
--enable-gui --enable-xrc --enable-mdi --enable-gif  --enable-pcx
--enable-iff --enable-pnm --enable-xpm

----------------------------------------------------------------------

Comment By: David Whetstone (dwhetstone)
Date: 2008-03-09 09:16

Message:
Logged In: YES 
user_id=989860
Originator: YES

This is on OS X 10.5.2 using the WX_2_8_BRANCH from svn configured  with
the following options:

../configure --enable-universal_binary
--with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk -
-with-macosx-version-min=10.4  --disable-shared --enable-unicode
--enable-debug --enable-c
atch_segvs  --enable-graphics_ctx --enable-mediactrl --with-opengl
--enable-monolithic --w
ith-libjpeg=builtin --with-libpng=builtin --with-libtiff=builtin
--with-expat=builtin --en
able-gui --enable-xrc --enable-mdi --enable-gif  --enable-pcx --enable-iff
--enable-pnm --
enable-xpm 


----------------------------------------------------------------------

Comment By: Stefan Csomor (csomor)
Date: 2008-03-08 22:32

Message:
Logged In: YES 
user_id=81467
Originator: NO

could you please provide more details - are you using the unicode build -
on which OS X version are you running this, is this a 2.8.7 download or the
WX_2_8_BRANCH from svn (eg the current trunk runs the sample with no
problem on 10.5.2)

Thanks a lot,

Stefan

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1910313&group_id=9863




More information about the wx-dev mailing list