[ wxwindows-Bugs-1910313 ] GetTextExtent wrong results for JP font
SourceForge.net
noreply at sourceforge.net
Fri Mar 14 03:35:27 PDT 2008
Bugs item #1910313, was opened at 2008-03-09 02:54
Message generated for change (Comment added) made by csomor
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: Pending
>Resolution: Fixed
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: Stefan Csomor (csomor)
Date: 2008-03-14 11:35
Message:
Logged In: YES
user_id=81467
Originator: NO
fix committed to trunk and WX_2_8_BRANCH
Thanks,
Stefan
----------------------------------------------------------------------
Comment By: Stefan Csomor (csomor)
Date: 2008-03-14 10:10
Message:
Logged In: YES
user_id=81467
Originator: NO
Hi Nusi
perfect, thanks for spotting this, yes, if I turn off this transient font
matching for drawing, David's sample just shows squares, so the default
font itself is not able to show it, so the measuring is for the squares,
while the drawing has the fallback activated, I'll turn this on for all
cases now (including char-by-char measuring)
Thanks once again,
Stefan
----------------------------------------------------------------------
Comment By: nusi (nusi)
Date: 2008-03-12 23:01
Message:
Logged In: YES
user_id=1559311
Originator: NO
Index: graphics.cpp
===================================================================
--- graphics.cpp (revision 52458)
+++ graphics.cpp (working copy)
@@ -1908,6 +1908,9 @@
wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of
the text") );
+ status = ::ATSUSetTransientFontMatching( atsuLayout , true );
+ wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font
matching") );
+
ATSUTextMeasurement textBefore, textAfter;
ATSUTextMeasurement textAscent, textDescent;
----------------------------------------------------------------------
Comment By: nusi (nusi)
Date: 2008-03-12 22:59
Message:
Logged In: YES
user_id=1559311
Originator: NO
Stefan, the issue is in wxMacCoreGraphicsContext::GetTextExtent() in
graphics.cpp.
It happens because DrawText() uses a different calculation as
GetTextExtent().
Just look at the patch, it will explain everything.
----------------------------------------------------------------------
Comment By: David Whetstone (dwhetstone)
Date: 2008-03-10 23: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 17: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-09 07: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