mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 19:37:15 +00:00
Bug 162332 - Use ATSUGetUnjustifiedBounds instead of ATSUMeasureText. r=mano, sr=peterv.
This commit is contained in:
parent
064c7eb606
commit
9d656b0fd0
@ -202,6 +202,8 @@ ATSUILayoutCache* nsATSUIUtils::gTxLayoutCache = nsnull;
|
||||
PRBool nsATSUIUtils::gIsAvailable = PR_FALSE;
|
||||
PRBool nsATSUIUtils::gInitialized = PR_FALSE;
|
||||
|
||||
fpMeasureText_type nsATSUIUtils::fpMeasureText = nsnull;
|
||||
|
||||
|
||||
//--------------------------------
|
||||
// Initialize
|
||||
@ -209,17 +211,41 @@ PRBool nsATSUIUtils::gInitialized = PR_FALSE;
|
||||
|
||||
void nsATSUIUtils::Initialize()
|
||||
{
|
||||
if (!gInitialized)
|
||||
{
|
||||
gInitialized = PR_TRUE;
|
||||
if (!gInitialized)
|
||||
{
|
||||
long version;
|
||||
gIsAvailable = (::Gestalt(gestaltATSUVersion, &version) == noErr);
|
||||
|
||||
long version;
|
||||
gIsAvailable = (::Gestalt(gestaltATSUVersion, &version) == noErr);
|
||||
gTxLayoutCache = new ATSUILayoutCache();
|
||||
if (!gTxLayoutCache)
|
||||
gIsAvailable = PR_FALSE;
|
||||
|
||||
gTxLayoutCache = new ATSUILayoutCache();
|
||||
if (!gTxLayoutCache)
|
||||
gIsAvailable = PR_FALSE;
|
||||
}
|
||||
// ATSUMeasureText is deprecated starting in Mac OS X 10.2, and replaced by
|
||||
// ATSUGetUnjustifiedBounds. Try to dynamically load the latter.
|
||||
CFBundleRef bundle =
|
||||
::CFBundleGetBundleWithIdentifier(CFSTR("com.apple.ApplicationServices"));
|
||||
if (bundle)
|
||||
{
|
||||
// We dynamically load the function and only use if available (OS X 10.2+)
|
||||
fpMeasureText = (fpMeasureText_type)
|
||||
::CFBundleGetFunctionPointerForName(bundle,
|
||||
CFSTR("ATSUGetUnjustifiedBounds"));
|
||||
}
|
||||
if (fpMeasureText == NULL)
|
||||
{
|
||||
// If the function is not found (which would happen on OS X 10.1), then
|
||||
// default to using ATSUMeasureText.
|
||||
bundle = ::CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
|
||||
if (bundle)
|
||||
{
|
||||
fpMeasureText = (fpMeasureText_type)
|
||||
::CFBundleGetFunctionPointerForName(bundle,
|
||||
CFSTR("ATSUMeasureText"));
|
||||
}
|
||||
}
|
||||
|
||||
gInitialized = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -412,22 +438,23 @@ nsATSUIToolkit::GetTextDimensions(
|
||||
{
|
||||
if (!nsATSUIUtils::IsAvailable())
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
|
||||
StPortSetter setter(mPort);
|
||||
|
||||
|
||||
ATSUTextLayout aTxtLayout;
|
||||
StartDraw(aCharPt, aLen, aSize, aFontNum, aBold, aItalic, aColor, aTxtLayout);
|
||||
if (nsnull == aTxtLayout)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
OSStatus err = noErr;
|
||||
ATSUTextMeasurement after;
|
||||
ATSUTextMeasurement ascent;
|
||||
ATSUTextMeasurement descent;
|
||||
err = ::ATSUMeasureText(aTxtLayout, 0, aLen, NULL, &after, &ascent, &descent);
|
||||
if (noErr != err)
|
||||
OSStatus err = noErr;
|
||||
ATSUTextMeasurement after;
|
||||
ATSUTextMeasurement ascent;
|
||||
ATSUTextMeasurement descent;
|
||||
err = nsATSUIUtils::fpMeasureText(aTxtLayout, 0, aLen, NULL, &after, &ascent,
|
||||
&descent);
|
||||
if (noErr != err)
|
||||
{
|
||||
NS_WARNING("ATSUMeasureText failed");
|
||||
NS_WARNING("MeasureText failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -479,8 +506,9 @@ nsATSUIToolkit::GetBoundingMetrics(
|
||||
oBoundingMetrics.ascent = -rect.top;
|
||||
oBoundingMetrics.descent = rect.bottom;
|
||||
|
||||
if((err = ATSUMeasureText(aTxtLayout, kATSUFromTextBeginning, kATSUToTextEnd,
|
||||
NULL, &width, NULL, NULL)) != noErr)
|
||||
err = nsATSUIUtils::fpMeasureText(aTxtLayout, kATSUFromTextBeginning,
|
||||
kATSUToTextEnd, NULL, &width, NULL, NULL);
|
||||
if (err != noErr)
|
||||
{
|
||||
oBoundingMetrics.width = oBoundingMetrics.rightBearing;
|
||||
}
|
||||
@ -518,9 +546,10 @@ nsATSUIToolkit::DrawString(
|
||||
|
||||
OSStatus err = noErr;
|
||||
ATSUTextMeasurement iAfter;
|
||||
err = ::ATSUMeasureText( aTxtLayout, 0, aLen, NULL, &iAfter, NULL, NULL );
|
||||
err = nsATSUIUtils::fpMeasureText(aTxtLayout, 0, aLen, NULL, &iAfter, NULL,
|
||||
NULL);
|
||||
if (noErr != err) {
|
||||
NS_WARNING("ATSUMeasureText failed");
|
||||
NS_WARNING("MeasureText failed");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -50,12 +50,23 @@ class ATSUILayoutCache;
|
||||
class nsDrawingSurfaceMac;
|
||||
class nsIDeviceContext;
|
||||
|
||||
// ATSUMeasureText and ATSUGetUnjustifiedBounds share the same signature.
|
||||
typedef OSStatus (*fpMeasureText_type) (ATSUTextLayout, UniCharArrayOffset,
|
||||
UniCharCount, ATSUTextMeasurement*,
|
||||
ATSUTextMeasurement*,
|
||||
ATSUTextMeasurement*,
|
||||
ATSUTextMeasurement*);
|
||||
|
||||
class nsATSUIUtils
|
||||
{
|
||||
public:
|
||||
static void Initialize();
|
||||
static PRBool IsAvailable();
|
||||
|
||||
// Function pointer which points to either ATSUMeasureText or
|
||||
// ATSUGetUnjustifiedBounds
|
||||
static fpMeasureText_type fpMeasureText;
|
||||
|
||||
static ATSUILayoutCache* gTxLayoutCache;
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user