mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-19 07:26:26 +00:00
Fixed #5438 - Mac Buttons not displaying Japanese correctly.
This commit is contained in:
parent
75be6d7408
commit
c0ce68f0fb
@ -29,6 +29,10 @@
|
||||
#include <ControlDefinitions.h>
|
||||
#endif
|
||||
|
||||
#include <Appearance.h>
|
||||
#include <TextUtils.h>
|
||||
#include <UnicodeConverter.h>
|
||||
#include <Fonts.h>
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
@ -106,10 +110,7 @@ PRBool nsMacControl::OnPaint(nsPaintEvent &aEvent)
|
||||
// update title
|
||||
if (mLabel != mLastLabel)
|
||||
{
|
||||
mLastLabel = mLabel;
|
||||
Str255 aStr;
|
||||
StringToStr255(mLabel, aStr);
|
||||
::SetControlTitle(mControl, aStr);
|
||||
NSStringSetControlTitle(mControl,mLabel);
|
||||
}
|
||||
|
||||
// update bounds
|
||||
@ -400,3 +401,129 @@ void nsMacControl::Str255ToString(const Str255& aStr255, nsString& aText)
|
||||
|
||||
aText = buffer;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void nsMacControl::NSStringSetControlTitle(ControlHandle theControl, nsString title)
|
||||
{
|
||||
TextStyle theStyle;
|
||||
ScriptCode fontScript;
|
||||
OSErr err;
|
||||
UnicodeToTextRunInfo unicodeTextRunInfo;
|
||||
const PRUnichar* unicodeText;
|
||||
char* scriptRunText;
|
||||
size_t unicodeTextLengthInBytes, unicodeTextReadInBytes,
|
||||
scriptRunTextSizeInBytes, scriptRunTextLengthInBytes,
|
||||
scriptCodeRunListLength;
|
||||
ScriptCodeRun convertedTextScript;
|
||||
|
||||
NS_PRECONDITION(mFontMetrics != nsnull, "nsMacControl::NSStringSetControlTitle: no Font Metrics");
|
||||
|
||||
//
|
||||
// determine the script of the font that the control is supposed to be drawn in
|
||||
//
|
||||
nsFontMetricsMac::GetNativeTextStyle(*mFontMetrics, *mContext, theStyle);
|
||||
fontScript = ::FontToScript(theStyle.tsFont);
|
||||
|
||||
//
|
||||
// create a Unicode Conveter object (from Unicode -> font)
|
||||
//
|
||||
err = ::CreateUnicodeToTextRunInfoByScriptCode(1,&fontScript,&unicodeTextRunInfo);
|
||||
NS_ASSERTION(err==noErr,"nsMacControl::NSStringSetControlTitle: CreateUnicodeToTextRunInfoByScriptCode failed.");
|
||||
if (err!=noErr) { return; }
|
||||
|
||||
//
|
||||
// get the Unicode text and prepare buffers
|
||||
//
|
||||
unicodeText = title.GetUnicode();
|
||||
unicodeTextLengthInBytes = title.Length() * sizeof(PRUnichar);
|
||||
scriptRunTextSizeInBytes = unicodeTextLengthInBytes * 2;
|
||||
scriptRunText = new char[scriptRunTextSizeInBytes];
|
||||
|
||||
|
||||
//
|
||||
// convert from Unicode to script run
|
||||
//
|
||||
err = ::ConvertFromUnicodeToScriptCodeRun(unicodeTextRunInfo,
|
||||
unicodeTextLengthInBytes,unicodeText,
|
||||
0, /* no flags */
|
||||
0,NULL,NULL,NULL, /* no offset arrays */
|
||||
scriptRunTextSizeInBytes,&unicodeTextReadInBytes,&scriptRunTextLengthInBytes,
|
||||
scriptRunText,
|
||||
1 /* count of scrip runs*/,&scriptCodeRunListLength,&convertedTextScript);
|
||||
if (err!=noErr)
|
||||
{
|
||||
//
|
||||
// the font script is not capable of rendering this string, we need to find an installed
|
||||
// script that can
|
||||
//
|
||||
err = ::CreateUnicodeToTextRunInfoByScriptCode(0,NULL,&unicodeTextRunInfo);
|
||||
NS_ASSERTION(err==noErr,"nsMacControl::NSStringSetControlTitle: CreateUnicodeToTextRunInfoByScriptCode failed.");
|
||||
if (err!=noErr) { return; }
|
||||
|
||||
//
|
||||
// convert from Unicode to script run
|
||||
//
|
||||
err = ::ConvertFromUnicodeToScriptCodeRun(unicodeTextRunInfo,
|
||||
unicodeTextLengthInBytes,unicodeText,
|
||||
0, /* no flags */
|
||||
0,NULL,NULL,NULL, /* no offset arrays */
|
||||
scriptRunTextSizeInBytes,&unicodeTextReadInBytes,&scriptRunTextLengthInBytes,
|
||||
scriptRunText,
|
||||
1 /* count of scrip runs*/,&scriptCodeRunListLength,&convertedTextScript);
|
||||
NS_ASSERTION(err==noErr,"nsMacControl::NSStringSetControlTitle: CreateUnicodeToTextRunInfoByScriptCode failed.");
|
||||
if (err!=noErr) { delete [] scriptRunText; return;}
|
||||
}
|
||||
|
||||
scriptRunText[scriptRunTextLengthInBytes] = 0; // null terminate
|
||||
|
||||
if (convertedTextScript.script!=fontScript)
|
||||
SetupMacControlFontForScript(convertedTextScript.script);
|
||||
|
||||
//
|
||||
// set the control title
|
||||
//
|
||||
::SetControlTitle(theControl,c2pstr(scriptRunText));
|
||||
delete [] scriptRunText;
|
||||
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsMacControl::SetupMacControlFontForScript(short theScript)
|
||||
{
|
||||
short themeFontID;
|
||||
Str255 themeFontName;
|
||||
SInt16 themeFontSize;
|
||||
Style themeFontStyle;
|
||||
TextStyle theStyle;
|
||||
OSErr err;
|
||||
|
||||
NS_PRECONDITION(mFontMetrics != nsnull, "No font metrics in SetupMacControlFont");
|
||||
NS_PRECONDITION(mContext != nsnull, "No context metrics in SetupMacControlFont");
|
||||
|
||||
nsFontMetricsMac::GetNativeTextStyle(*mFontMetrics, *mContext, theStyle);
|
||||
|
||||
//
|
||||
// take the script and select and override font
|
||||
//
|
||||
err = ::GetThemeFont(kThemeSystemFont,theScript,themeFontName,&themeFontSize,&themeFontStyle);
|
||||
NS_ASSERTION(err==noErr,"nsMenu::NSStringNewMenu: GetThemeFont failed.");
|
||||
::GetFNum(themeFontName,&themeFontID);
|
||||
|
||||
// if needed, impose a min size of 9pt on the control font
|
||||
if (theStyle.tsSize < 9)
|
||||
theStyle.tsSize = 9;
|
||||
|
||||
ControlFontStyleRec fontStyleRec;
|
||||
fontStyleRec.flags = (kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask);
|
||||
fontStyleRec.font = themeFontID;
|
||||
fontStyleRec.size = theStyle.tsSize;
|
||||
fontStyleRec.style = theStyle.tsFace;
|
||||
::SetControlFontStyle(mControl, &fontStyleRec);
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ protected:
|
||||
virtual void GetRectForMacControl(nsRect &outRect);
|
||||
void SetupMacControlFont();
|
||||
void ControlChanged(PRInt32 aNewValue);
|
||||
void NSStringSetControlTitle(ControlHandle theControl, nsString title);
|
||||
void SetupMacControlFontForScript(short theScript);
|
||||
|
||||
nsString mLabel;
|
||||
PRBool mWidgetArmed;
|
||||
|
Loading…
x
Reference in New Issue
Block a user