diff --git a/gfx/src/mac/Makefile.in b/gfx/src/mac/Makefile.in deleted file mode 100644 index 156a0ebb54fc..000000000000 --- a/gfx/src/mac/Makefile.in +++ /dev/null @@ -1,128 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org Code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - - -LIBRARY_NAME = gfx_mac -EXPORT_LIBRARY = 1 -MODULE = gfx -IS_COMPONENT = 1 -MODULE_NAME = nsGfxMacModule -GRE_MODULE = 1 -LIBXUL_LIBRARY = 1 - -PACKAGE_FILE = gfxmac.pkg - -REQUIRES = xpcom \ - string \ - widget \ - view \ - pref \ - uconv \ - necko \ - unicharutil \ - content \ - layout \ - locale \ - $(NULL) - -CPPSRCS = \ - nsATSUIUtils.cpp \ - nsDeviceContextMac.cpp \ - nsDrawingSurfaceMac.cpp \ - nsFontMetricsMac.cpp \ - nsGfxFactoryMac.cpp \ - nsGraphicState.cpp \ - nsImageMac.cpp \ - nsRegionMac.cpp \ - nsRenderingContextMac.cpp \ - nsMacUnicodeFontInfo.cpp \ - nsUnicodeFontMappingMac.cpp \ - nsUnicodeMappingUtil.cpp \ - nsUnicodeRenderingToolkit.cpp \ - nsFontUtils.cpp \ - $(NULL) - -EXPORTS = \ - nsIImageMac.h \ - nsIDrawingSurfaceMac.h \ - nsGfxUtils.h \ - nsCarbonHelpers.h \ - nsRegionPool.h \ - $(NULL) - -ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT)) -CMMSRCS = nsCocoaImageUtils.mm -endif - -EXTRA_DSO_LDOPTS = \ - $(LIBS_DIR) \ - $(EXTRA_DSO_LIBS) \ - $(MOZ_COMPONENT_LIBS) \ - $(MOZ_UNICHARUTIL_LIBS) \ - ../shared/$(LIB_PREFIX)gfxshared_s.$(LIB_SUFFIX) \ - $(call EXPAND_LIBNAME_PATH,gkgfx,$(DEPTH)/..) \ - $(DEPTH)/modules/libutil/src/$(LIB_PREFIX)mozutil_s.$(LIB_SUFFIX) \ - $(TK_LIBS) \ - $(NULL) - -LOCAL_INCLUDES = \ - -I$(srcdir)/../shared \ - -I$(srcdir)/.. \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - -libs:: fontEncoding.properties - $(INSTALL) $^ $(DIST)/bin/res/fonts - -install:: fontEncoding.properties - $(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/res/fonts - -CXXFLAGS += $(TK_CFLAGS) -CFLAGS += $(TK_CFLAGS) -INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. - -ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT)) -EXTRA_DSO_LDOPTS += -framework Cocoa -endif diff --git a/gfx/src/mac/fontEncoding.properties b/gfx/src/mac/fontEncoding.properties deleted file mode 100644 index e6e7c91c1e3f..000000000000 --- a/gfx/src/mac/fontEncoding.properties +++ /dev/null @@ -1,105 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Mozilla MathML Project. -# -# The Initial Developer of the Original Code is -# The University Of Queensland. -# Portions created by the Initial Developer are Copyright (C) 2001 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Roger B. Sidje -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -# LOCALIZATION NOTE: FILE -# Do not translate anything in this file - -# This is a list of encodings used for special *symbolic fonts* (not documents) for -# which we have converters (i.e., the intl/uconv library contains encoding tables -# that provide a mapping of characters to the indices of the desired glyphshapes -# within these symbolic fonts). -# -# For each 'key = value' pair in this list: -# -# - the 'key' is a lower case ASCII with the *name of the font*, and the -# encoding type (e.g., .ttf for TrueType, and .t1 for Type 1). Note that -# the *name of a font* is not necessarily the *name of the file* that contains -# the font... All whitespace should be stripped from the name. -# -# - the 'value' is the case-sensitive charset string used when setting up the -# corresponding Unicode Converter in the intl/uconv library. -# -# There are different versions of this file per platform - see bug 159243 - - -# Symbol font -encoding.symbol.ttf = Adobe-Symbol-Encoding - -# TeX's Computer Modern fonts (Roman, Math Italic, Symbol and Extension) - -encoding.cmr10.ttf = x-ttf-cmr -encoding.cmmi10.ttf = x-ttf-cmmi -encoding.cmsy10.ttf = x-ttf-cmsy -encoding.cmex10.ttf = x-ttf-cmex - -# Mathematica fonts - -encoding.math1.ttf = x-mathematica1 -encoding.math1-bold.ttf = x-mathematica1 -encoding.math1mono.ttf = x-mathematica1 -encoding.math1mono-bold.ttf = x-mathematica1 - -encoding.math2.ttf = x-mathematica2 -encoding.math2-bold.ttf = x-mathematica2 -encoding.math2mono.ttf = x-mathematica2 -encoding.math2mono-bold.ttf = x-mathematica2 - -encoding.math3.ttf = x-mathematica3 -encoding.math3-bold.ttf = x-mathematica3 -encoding.math3mono.ttf = x-mathematica3 -encoding.math3mono-bold.ttf = x-mathematica3 - -encoding.math4.ttf = x-mathematica4 -encoding.math4-bold.ttf = x-mathematica4 -encoding.math4mono.ttf = x-mathematica4 -encoding.math4mono-bold.ttf = x-mathematica4 - -encoding.math5.ttf = x-mathematica5 -encoding.math5-bold.ttf = x-mathematica5 -encoding.math5bold.ttf = x-mathematica5 -encoding.math5mono.ttf = x-mathematica5 -encoding.math5mono-bold.ttf = x-mathematica5 -encoding.math5monobold.ttf = x-mathematica5 - -# MathType Extra -encoding.mtextra.ttf = x-mtextra - -# Hack for compatibility with Nav4.x (bug 77265, 91171) -# Treat these Symbol fonts as if they have the given encoding -# Disabled on the Mac - bug 159243 -#encoding.wingdings.ttf = windows-1252 -#encoding.webdings.ttf = windows-1252 diff --git a/gfx/src/mac/gfxmac.pkg b/gfx/src/mac/gfxmac.pkg deleted file mode 100644 index db9682d1da58..000000000000 --- a/gfx/src/mac/gfxmac.pkg +++ /dev/null @@ -1,7 +0,0 @@ -[gecko] -#if SHARED_LIBRARY -dist/bin/components/@SHARED_LIBRARY@ -#else -!staticcomp @LIBRARY@ @MODULE_NAME@# -endif -dist/bin/res/fonts/fontEncoding.properties diff --git a/gfx/src/mac/nsATSUIUtils.cpp b/gfx/src/mac/nsATSUIUtils.cpp deleted file mode 100644 index b5036c69c0dc..000000000000 --- a/gfx/src/mac/nsATSUIUtils.cpp +++ /dev/null @@ -1,556 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsATSUIUtils.h" -#include "nsIDeviceContext.h" -#include "nsDrawingSurfaceMac.h" -#include "nsDeviceContextMac.h" -#include "nsTransform2D.h" -#include "plhash.h" -#include "nsFontUtils.h" - -#include -#include - - -//------------------------------------------------------------------------ -// ATSUILayoutCache -// -//------------------------------------------------------------------------ - - -//-------------------------------- -// Class definition -//-------------------------------- -class ATSUILayoutCache -{ -public: - ATSUILayoutCache(); - ~ATSUILayoutCache(); - - PRBool Get(short aFont, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor, ATSUTextLayout *aTxlayout); - void Set(short aFont, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor, ATSUTextLayout aTxlayout); - -private: - typedef struct - { - short font; - short size; - nscolor color; - short boldItalic; - } atsuiLayoutCacheKey; - - PRBool Get(atsuiLayoutCacheKey *key, ATSUTextLayout *txlayout); - void Set(atsuiLayoutCacheKey *key, ATSUTextLayout txlayout); - - static PR_CALLBACK PLHashNumber HashKey(const void *aKey); - static PR_CALLBACK PRIntn CompareKeys(const void *v1, const void *v2); - static PR_CALLBACK PRIntn CompareValues(const void *v1, const void *v2); - static PR_CALLBACK PRIntn FreeHashEntries(PLHashEntry *he, PRIntn italic, void *arg); - - struct PLHashTable* mTable; - PRUint32 mCount; -}; - - -ATSUILayoutCache::ATSUILayoutCache() -{ - mTable = PL_NewHashTable(8, (PLHashFunction)HashKey, - (PLHashComparator)CompareKeys, - (PLHashComparator)CompareValues, - nsnull, nsnull); - mCount = 0; -} - - -//-------------------------------- -// Public methods -//-------------------------------- - -ATSUILayoutCache::~ATSUILayoutCache() -{ - if (mTable) - { - PL_HashTableEnumerateEntries(mTable, FreeHashEntries, 0); - PL_HashTableDestroy(mTable); - mTable = nsnull; - } -} - - -PRBool ATSUILayoutCache::Get(short aFont, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor, ATSUTextLayout *aTxlayout) -{ - atsuiLayoutCacheKey k = {aFont, aSize, aColor, (aBold ? 1 : 0) + (aItalic ? 2 : 0) }; - return Get(&k, aTxlayout); -} - - -void ATSUILayoutCache::Set(short aFont, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor, ATSUTextLayout aTxlayout) -{ - atsuiLayoutCacheKey k = {aFont, aSize, aColor, (aBold ? 1 : 0) + (aItalic ? 2 : 0) }; - return Set(&k, aTxlayout); -} - - -//-------------------------------- -// Private methods -//-------------------------------- - -PRBool ATSUILayoutCache::Get(atsuiLayoutCacheKey *key, ATSUTextLayout *txlayout) -{ - PLHashEntry **hep = PL_HashTableRawLookup(mTable, HashKey(key), key); - PLHashEntry *he = *hep; - if( he ) - { - *txlayout = (ATSUTextLayout)he->value; - return PR_TRUE; - } - return PR_FALSE; -} - - -void ATSUILayoutCache::Set(atsuiLayoutCacheKey *key, ATSUTextLayout txlayout) -{ - atsuiLayoutCacheKey *newKey = new atsuiLayoutCacheKey; - if (newKey) - { - *newKey = *key; - PL_HashTableAdd(mTable, newKey, txlayout); - mCount ++; - } -} - - -PR_CALLBACK PLHashNumber ATSUILayoutCache::HashKey(const void *aKey) -{ - atsuiLayoutCacheKey* key = (atsuiLayoutCacheKey*)aKey; - return key->font + (key->size << 7) + (key->boldItalic << 12) + key->color; -} - - -PR_CALLBACK PRIntn ATSUILayoutCache::CompareKeys(const void *v1, const void *v2) -{ - atsuiLayoutCacheKey *k1 = (atsuiLayoutCacheKey *)v1; - atsuiLayoutCacheKey *k2 = (atsuiLayoutCacheKey *)v2; - return (k1->font == k2->font) && (k1->color == k2->color ) && (k1->size == k2->size) && (k1->boldItalic == k2->boldItalic); -} - - -PR_CALLBACK PRIntn ATSUILayoutCache::CompareValues(const void *v1, const void *v2) -{ - ATSUTextLayout t1 = (ATSUTextLayout)v1; - ATSUTextLayout t2 = (ATSUTextLayout)v2; - return (t1 == t2); -} - - -PR_CALLBACK PRIntn ATSUILayoutCache::FreeHashEntries(PLHashEntry *he, PRIntn italic, void *arg) -{ - delete (atsuiLayoutCacheKey*)he->key; - ATSUDisposeTextLayout((ATSUTextLayout)he->value); - return HT_ENUMERATE_REMOVE; -} - - -#pragma mark - -//------------------------------------------------------------------------ -// nsATSUIUtils -// -//------------------------------------------------------------------------ - - -//-------------------------------- -// globals -//-------------------------------- - -ATSUILayoutCache* nsATSUIUtils::gTxLayoutCache = nsnull; - -PRBool nsATSUIUtils::gIsAvailable = PR_FALSE; -PRBool nsATSUIUtils::gInitialized = PR_FALSE; - - -//-------------------------------- -// Initialize -//-------------------------------- - -void nsATSUIUtils::Initialize() -{ - if (!gInitialized) - { - long version; - gIsAvailable = (::Gestalt(gestaltATSUVersion, &version) == noErr); - - gTxLayoutCache = new ATSUILayoutCache(); - if (!gTxLayoutCache) - gIsAvailable = PR_FALSE; - - gInitialized = PR_TRUE; - } -} - - -//-------------------------------- -// IsAvailable -//-------------------------------- - -PRBool nsATSUIUtils::IsAvailable() -{ - return gIsAvailable; -} - - -#pragma mark - - -//------------------------------------------------------------------------ -// nsATSUIToolkit -// -//------------------------------------------------------------------------ -nsATSUIToolkit::nsATSUIToolkit() -{ - nsATSUIUtils::Initialize(); -} - - -//------------------------------------------------------------------------ -// GetTextLayout -// -//------------------------------------------------------------------------ - -#define FloatToFixed(a) ((Fixed)((float)(a) * fixed1)) -#define ATTR_CNT 5 - -//------------------------------------------------------------------------ -ATSUTextLayout nsATSUIToolkit::GetTextLayout(short aFontNum, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor) -{ - ATSUTextLayout txLayout = nsnull; - OSStatus err; - if (nsATSUIUtils::gTxLayoutCache->Get(aFontNum, aSize, aBold, aItalic, aColor, &txLayout)) - return txLayout; - - UniChar dmy[1]; - err = ::ATSUCreateTextLayoutWithTextPtr (dmy, 0,0,0,0,NULL, NULL, &txLayout); - if(noErr != err) { - NS_WARNING("ATSUCreateTextLayoutWithTextPtr failed"); - // goto errorDone; - return nsnull; - } - - ATSUStyle theStyle; - err = ::ATSUCreateStyle(&theStyle); - if(noErr != err) { - NS_WARNING("ATSUCreateStyle failed"); - // goto errorDoneDestroyTextLayout; - err = ::ATSUDisposeTextLayout(txLayout); - return nsnull; - } - - ATSUAttributeTag theTag[ATTR_CNT]; - ByteCount theValueSize[ATTR_CNT]; - ATSUAttributeValuePtr theValue[ATTR_CNT]; - - //--- Font ID & Face ----- - ATSUFontID atsuFontID; - - // The use of ATSUFONDtoFontID is not recommended, see - // http://developer.apple.com/documentation/Carbon/Reference/ATSUI_Reference/atsu_reference_Reference/chapter_1.2_section_19.html - FMFontStyle fbStyle; - if (::FMGetFontFromFontFamilyInstance(aFontNum, 0, &atsuFontID, &fbStyle) == kFMInvalidFontErr) { - NS_WARNING("FMGetFontFromFontFamilyInstance failed"); - // goto errorDoneDestroyStyle; - err = ::ATSUDisposeStyle(theStyle); - err = ::ATSUDisposeTextLayout(txLayout); - return nsnull; - } - - theTag[0] = kATSUFontTag; - theValueSize[0] = (ByteCount) sizeof(ATSUFontID); - theValue[0] = (ATSUAttributeValuePtr) &atsuFontID; - //--- Font ID & Face ----- - - //--- Size ----- - float dev2app; - short fontsize = aSize; - - dev2app = mContext->DevUnitsToAppUnits(); - // Fixed size = FloatToFixed( roundf(float(fontsize) / dev2app)); - Fixed size = FloatToFixed( (float) rint(float(fontsize) / dev2app)); - if( FixRound ( size ) < 9 && !nsFontUtils::DisplayVerySmallFonts()) - size = X2Fix(9); - - theTag[1] = kATSUSizeTag; - theValueSize[1] = (ByteCount) sizeof(Fixed); - theValue[1] = (ATSUAttributeValuePtr) &size; - //--- Size ----- - - //--- Color ----- - RGBColor color; - - #define COLOR8TOCOLOR16(color8) ((color8 << 8) | color8) - - color.red = COLOR8TOCOLOR16(NS_GET_R(aColor)); - color.green = COLOR8TOCOLOR16(NS_GET_G(aColor)); - color.blue = COLOR8TOCOLOR16(NS_GET_B(aColor)); - theTag[2] = kATSUColorTag; - theValueSize[2] = (ByteCount) sizeof(RGBColor); - theValue[2] = (ATSUAttributeValuePtr) &color; - //--- Color ----- - - //--- Bold ----- - Boolean isBold = aBold ? true : false; - theTag[3] = kATSUQDBoldfaceTag; - theValueSize[3] = (ByteCount) sizeof(Boolean); - theValue[3] = (ATSUAttributeValuePtr) &isBold; - //--- Bold ----- - - //--- Italic ----- - Boolean isItalic = aItalic ? true : false; - theTag[4] = kATSUQDItalicTag; - theValueSize[4] = (ByteCount) sizeof(Boolean); - theValue[4] = (ATSUAttributeValuePtr) &isItalic; - //--- Italic ----- - - err = ::ATSUSetAttributes(theStyle, ATTR_CNT, theTag, theValueSize, theValue); - if(noErr != err) { - NS_WARNING("ATSUSetAttributes failed"); - // goto errorDoneDestroyStyle; - err = ::ATSUDisposeStyle(theStyle); - err = ::ATSUDisposeTextLayout(txLayout); - return nsnull; - } - - err = ::ATSUSetRunStyle(txLayout, theStyle, kATSUFromTextBeginning, kATSUToTextEnd); - if(noErr != err) { - NS_WARNING("ATSUSetRunStyle failed"); - // goto errorDoneDestroyStyle; - err = ::ATSUDisposeStyle(theStyle); - err = ::ATSUDisposeTextLayout(txLayout); - return nsnull; - } - - err = ::ATSUSetTransientFontMatching(txLayout, true); - if(noErr != err) { - NS_WARNING( "ATSUSetTransientFontMatching failed"); - // goto errorDoneDestroyStyle; - err = ::ATSUDisposeStyle(theStyle); - err = ::ATSUDisposeTextLayout(txLayout); - return nsnull; - } - - nsATSUIUtils::gTxLayoutCache->Set(aFontNum, aSize, aBold, aItalic, aColor, txLayout); - - return txLayout; -} - -//------------------------------------------------------------------------ -// PrepareToDraw -// -//------------------------------------------------------------------------ -void nsATSUIToolkit::PrepareToDraw(CGrafPtr aPort, nsIDeviceContext* aContext) -{ - mPort = aPort; - mContext = aContext; -} - -//------------------------------------------------------------------------ -// StartDraw -// -//------------------------------------------------------------------------ -void nsATSUIToolkit::StartDraw( - const PRUnichar *aCharPt, - PRUint32 aLen, - short aSize, short aFontNum, - PRBool aBold, PRBool aItalic, nscolor aColor, ATSUTextLayout& oLayout) -{ - OSStatus err = noErr; - oLayout = GetTextLayout(aFontNum, aSize, aBold, aItalic, aColor); - if (nsnull == oLayout) { - NS_WARNING("GetTextLayout return nsnull"); - return; - } - - // ATSUSetTextPointerLocation won't invalidate atsui's internal cache if aCharPt is - // the same address it already has. therefore, since we are definitely changing the - // text here, we should explicitly invalidate any existing caches - ::ATSUClearLayoutCache(oLayout, kATSUFromTextBeginning); - - err = ::ATSUSetTextPointerLocation( oLayout, (ConstUniCharArrayPtr)aCharPt, 0, aLen, aLen); - if (noErr != err) { - NS_WARNING("ATSUSetTextPointerLocation failed"); - oLayout = nsnull; - } - return; -} - -//------------------------------------------------------------------------ -// GetWidth -// -//------------------------------------------------------------------------ -nsresult -nsATSUIToolkit::GetTextDimensions( - const PRUnichar *aCharPt, - PRUint32 aLen, - nsTextDimensions& oDim, - short aSize, short aFontNum, - PRBool aBold, PRBool aItalic, nscolor aColor) -{ - 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 = ::ATSUGetUnjustifiedBounds(aTxtLayout, 0, aLen, NULL, &after, &ascent, - &descent); - if (noErr != err) - { - NS_WARNING("ATSUGetUnjustifiedBounds failed"); - return NS_ERROR_FAILURE; - } - - oDim.width = FixRound(after); - oDim.ascent = FixRound(ascent); - oDim.descent = FixRound(descent); - // aTxtLayout is cached and does not need to be disposed - return NS_OK; -} - -#ifdef MOZ_MATHML -//------------------------------------------------------------------------ -// GetBoundingMetrics -// -//------------------------------------------------------------------------ -nsresult -nsATSUIToolkit::GetBoundingMetrics( - const PRUnichar *aCharPt, - PRUint32 aLen, - nsBoundingMetrics &oBoundingMetrics, - short aSize, short aFontNum, - PRBool aBold, PRBool aItalic, - nscolor aColor) -{ - 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; - Rect rect; - ATSUTextMeasurement width; - - if((err = ATSUMeasureTextImage(aTxtLayout, - kATSUFromTextBeginning, kATSUToTextEnd, 0, 0, &rect)) != noErr) - { - NS_WARNING("ATSUMeasureTextImage failed"); - return NS_ERROR_FAILURE; - } - - // return the values in points, the caller will convert them into twips - oBoundingMetrics.leftBearing = rect.left; - oBoundingMetrics.rightBearing = rect.right; - oBoundingMetrics.ascent = -rect.top; - oBoundingMetrics.descent = rect.bottom; - - err = ::ATSUGetUnjustifiedBounds(aTxtLayout, kATSUFromTextBeginning, - kATSUToTextEnd, NULL, &width, NULL, NULL); - if (err != noErr) - { - oBoundingMetrics.width = oBoundingMetrics.rightBearing; - } - else - oBoundingMetrics.width = FixRound(width); - - return NS_OK; -} -#endif // MOZ_MATHML - -//------------------------------------------------------------------------ -// DrawString -// -//------------------------------------------------------------------------ -nsresult -nsATSUIToolkit::DrawString( - const PRUnichar *aCharPt, - PRUint32 aLen, - PRInt32 x, PRInt32 y, - short &oWidth, - short aSize, short aFontNum, - PRBool aBold, PRBool aItalic, nscolor aColor) -{ - oWidth = 0; - 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 iAfter; - err = ::ATSUGetUnjustifiedBounds(aTxtLayout, 0, aLen, NULL, &iAfter, NULL, - NULL); - if (noErr != err) { - NS_WARNING("MeasureText failed"); - return NS_ERROR_FAILURE; - } - - err = ::ATSUDrawText(aTxtLayout, 0, aLen, Long2Fix(x), Long2Fix(y)); - if (noErr != err) { - NS_WARNING("ATSUDrawText failed"); - return NS_ERROR_FAILURE; - } - - oWidth = FixRound(iAfter); - // aTxtLayout is cached and does not need to be disposed - return NS_OK; -} diff --git a/gfx/src/mac/nsATSUIUtils.h b/gfx/src/mac/nsATSUIUtils.h deleted file mode 100644 index 8ac4b66e69a8..000000000000 --- a/gfx/src/mac/nsATSUIUtils.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsATSUIUtils_h___ -#define nsATSUIUtils_h___ - - -#include "nsCRT.h" -#include "nsError.h" -#include "nsCoord.h" -#include "nsColor.h" -#include "nsIRenderingContext.h" -#include - -class ATSUILayoutCache; -class nsDrawingSurfaceMac; -class nsIDeviceContext; - - -class nsATSUIUtils -{ -public: - static void Initialize(); - static PRBool IsAvailable(); - - static ATSUILayoutCache* gTxLayoutCache; - -private: - static PRBool gIsAvailable; - static PRBool gInitialized; -}; - - - -class nsATSUIToolkit -{ -public: - nsATSUIToolkit(); - ~nsATSUIToolkit() {}; - - void PrepareToDraw(CGrafPtr aPort, nsIDeviceContext* aContext); - - nsresult GetTextDimensions(const PRUnichar *aCharPt, PRUint32 aLen, nsTextDimensions &oDim, - short aSize, short fontNum, PRBool aBold, - PRBool aItalic, nscolor aColor); - nsresult DrawString(const PRUnichar *aCharPt, PRUint32 aLen, PRInt32 x, PRInt32 y, short &oWidth, - short aSize, short fontNum, PRBool aBold, PRBool aItalic, - nscolor aColor); -#ifdef MOZ_MATHML - nsresult GetBoundingMetrics(const PRUnichar *aCharPt, PRUint32 aLen, nsBoundingMetrics &aBoundingMetrics, - short aSize, short fontNum, PRBool aBold, - PRBool aItalic, nscolor aColor); -#endif // MOZ_MATHML - -private: - void StartDraw(const PRUnichar *aCharPt, PRUint32 aLen, short aSize, short fontNum, PRBool aBold, - PRBool aItalic, nscolor aColor, ATSUTextLayout& oLayout); - - ATSUTextLayout GetTextLayout(short aFontNum, short aSize, PRBool aBold, - PRBool aItalic, nscolor aColor); - -private: - CGrafPtr mPort; - nsIDeviceContext* mContext; -}; - -#endif //nsATSUIUtils_h___ diff --git a/gfx/src/mac/nsCarbonHelpers.h b/gfx/src/mac/nsCarbonHelpers.h deleted file mode 100644 index a40b1e12ba47..000000000000 --- a/gfx/src/mac/nsCarbonHelpers.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef CarbonHelpers_h__ -#define CarbonHelpers_h__ - -#include -#include -#include -#include -#include - -// -// for non-carbon builds, provide various accessors to keep the code below free of ifdefs. -// - -inline void GetWindowUpdateRegion ( WindowPtr window, RgnHandle outUpdateRgn ) -{ - ::GetWindowRegion(window, kWindowUpdateRgn, outUpdateRgn); -} - -inline void SetControlPopupMenuStuff ( ControlHandle control, MenuHandle menu, short aID ) -{ - ::SetControlPopupMenuHandle ( control, menu ); - ::SetControlPopupMenuID ( control, aID ); -} - - -inline WindowRef GetTheWindowList(void) -{ - return GetWindowList(); -} - -#endif /* CarbonHelpers_h__ */ diff --git a/gfx/src/mac/nsCocoaImageUtils.mm b/gfx/src/mac/nsCocoaImageUtils.mm deleted file mode 100644 index 124d685461bb..000000000000 --- a/gfx/src/mac/nsCocoaImageUtils.mm +++ /dev/null @@ -1,56 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Cocoa Image helper functions. - * - * The Initial Developer of the Original Code is - * IBM Corporation. - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Javier Pedemonte (jhpedemonte@gmail.com) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - - -CGContextRef Cocoa_LockFocus(void* view) -{ - if (view) { - NSView* v = (NSView*) view; - [v lockFocus]; - } - return (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; -} - -void Cocoa_UnlockFocus(void* view) -{ - if (view) { - NSView* v = (NSView*) view; - [v unlockFocus]; - } -} diff --git a/gfx/src/mac/nsDeviceContextMac.cpp b/gfx/src/mac/nsDeviceContextMac.cpp deleted file mode 100644 index 105bc160d36f..000000000000 --- a/gfx/src/mac/nsDeviceContextMac.cpp +++ /dev/null @@ -1,1140 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsDeviceContextMac.h" -#include "nsRenderingContextMac.h" -#include "nsIPrintingContext.h" -#include "nsString.h" -#include "nsHashtable.h" -#include "nsFont.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "nsIPref.h" -#include "nsIServiceManager.h" -#include "nsQuickSort.h" -#include "nsUnicodeMappingUtil.h" -#include "nsCarbonHelpers.h" -#include "nsRegionMac.h" -#include "nsIScreenManager.h" -#include "nsIServiceManager.h" -#include "nsReadableUtils.h" -#include "nsUnicharUtils.h" - - -PRUint32 nsDeviceContextMac::mPixelsPerInch = 96; -PRUint32 nsDeviceContextMac::sNumberOfScreens = 0; - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -nsDeviceContextMac :: nsDeviceContextMac() - : DeviceContextImpl(), - mOldPort(nsnull) -{ -} - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -nsDeviceContextMac :: ~nsDeviceContextMac() -{ -} - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac :: Init(nsNativeWidget aNativeWidget) -{ - // cache the screen manager service for later - nsresult ignore; - mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1", &ignore); - NS_ASSERTION ( mScreenManager, "No screen manager, we're in trouble" ); - if ( !mScreenManager ) - return NS_ERROR_FAILURE; - - // figure out how many monitors there are. - if ( !sNumberOfScreens ) - mScreenManager->GetNumberOfScreens(&sNumberOfScreens); - - // get resolution. Ensure that mPixelsToTwips is integral or we - // run into serious rounding problems. - double pix_inch = GetScreenResolution(); //Fix2X((**thepix).hRes); - mPixelsToTwips = nscoord(NSIntPointsToTwips(72)/(float)pix_inch); - mTwipsToPixels = 1.0f/mPixelsToTwips; - - return DeviceContextImpl::Init(aNativeWidget); -} - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac :: CreateRenderingContext(nsIRenderingContext *&aContext) -{ -#ifdef NS_PRINT_PREVIEW - // Defer to Alt when there is one - if (mAltDC && ((mUseAltDC & kUseAltDCFor_CREATERC_PAINT) || (mUseAltDC & kUseAltDCFor_CREATERC_REFLOW))) { - return mAltDC->CreateRenderingContext(aContext); - } -#endif - - nsRenderingContextMac *pContext; - nsresult rv; - - pContext = new nsRenderingContextMac(); - if (nsnull != pContext) { - NS_ADDREF(pContext); - - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - - rv = pContext->Init(this, thePort); - } - else - rv = NS_ERROR_OUT_OF_MEMORY; - - if (NS_OK != rv){ - NS_IF_RELEASE(pContext); - } - aContext = pContext; - return rv; -} - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac :: SupportsNativeWidgets(PRBool &aSupportsWidgets) -{ - //XXX it is very critical that this not lie!! MMP - - // ¥¥¥ VERY IMPORTANT (pinkerton) - // This routine should return true if the widgets behave like Win32 - // "windows", that is they paint themselves and the app never knows about - // them or has to send them update events. We were returning false which - // meant that raptor needed to make sure to redraw them. However, if we - // return false, the widgets never get created because the CreateWidget() - // call in nsView never creates the widget. If we return true (which makes - // things work), we are lying because the controls really need those - // precious update/repaint events. - // - // The situation we need is the following: - // - return false from SupportsNativeWidgets() - // - Create() is called on widgets when the above case is true. - // - // Raptor currently doesn't work this way and needs to be fixed. - // (please remove this comment when this situation is rectified) - - if( nsnull != mSpec){ - aSupportsWidgets = PR_FALSE; - } else { - aSupportsWidgets = PR_TRUE; - } - - //if (nsnull == mSurface) - - //else - //aSupportsWidgets = PR_FALSE; - - return NS_OK; -} - - -// helper function to get the system font for a specific script -#define FONTNAME_MAX_UNICHRS sizeof(fontName255) * 2 -nsresult -GetSystemFontForScript(ThemeFontID aFontID, ScriptCode aScriptCode, - nsAFlatString& aFontName, SInt16& aFontSize, - Style& aFontStyle) -{ - Str255 fontName255; - ::GetThemeFont(aFontID, aScriptCode, fontName255, &aFontSize, &aFontStyle); - if (fontName255[0] == 255) { - NS_WARNING("Too long fong name (> 254 chrs)"); - return NS_ERROR_FAILURE; - } - fontName255[fontName255[0]+1] = 0; - - OSStatus err; - // the theme font could contains font name in different encoding. - // we need to covert them to unicode according to the font's text encoding. - - TECObjectRef converter = 0; - TextEncoding unicodeEncoding = - ::CreateTextEncoding(kTextEncodingUnicodeDefault, - kTextEncodingDefaultVariant, - kTextEncodingDefaultFormat); - - FMFontFamily fontFamily; - TextEncoding fontEncoding = 0; - fontFamily = ::FMGetFontFamilyFromName(fontName255); - err = ::FMGetFontFamilyTextEncoding(fontFamily, &fontEncoding); - - if (err != noErr) { - NS_WARNING("Could not get the encoding for the font."); - return NS_ERROR_FAILURE; - } - err = ::TECCreateConverter(&converter, fontEncoding, unicodeEncoding); - if (err != noErr) { - NS_WARNING("Could not create the converter."); - return NS_ERROR_FAILURE; - } - PRUnichar unicodeFontName[FONTNAME_MAX_UNICHRS + 1]; - ByteCount actualInputLength, actualOutputLength; - err = ::TECConvertText(converter, &fontName255[1], fontName255[0], - &actualInputLength, - (TextPtr)unicodeFontName, - FONTNAME_MAX_UNICHRS * sizeof(PRUnichar), - &actualOutputLength); - if (err != noErr) { - NS_WARNING("Could not convert the font name."); - return NS_ERROR_FAILURE; - } - - ::TECDisposeConverter(converter); - - unicodeFontName[actualOutputLength / sizeof(PRUnichar)] = PRUnichar('\0'); - aFontName = nsDependentString(unicodeFontName); - return NS_OK; -} - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac :: GetSystemFont(nsSystemFontID aID, nsFont *aFont) const -{ - nsresult status = NS_OK; - - switch (aID) { - //--------- - // CSS System Fonts - // - // Important: don't chage the code below, or make sure to preserve - // some compatibility with MacIE5 - developers will appreciate. - // Run the testcase in bug 3371 in quirks mode and strict mode. - //--------- - // css2 - case eSystemFont_Caption: - case eSystemFont_Icon: - case eSystemFont_Menu: - case eSystemFont_MessageBox: - case eSystemFont_SmallCaption: - case eSystemFont_StatusBar: - // css3 - case eSystemFont_Window: - case eSystemFont_Document: - case eSystemFont_Workspace: - case eSystemFont_Desktop: - case eSystemFont_Info: - case eSystemFont_Dialog: - case eSystemFont_Button: - case eSystemFont_PullDownMenu: - case eSystemFont_List: - case eSystemFont_Field: - // moz - case eSystemFont_Tooltips: - case eSystemFont_Widget: - float dev2app; - dev2app = DevUnitsToAppUnits(); - - aFont->style = NS_FONT_STYLE_NORMAL; - aFont->weight = NS_FONT_WEIGHT_NORMAL; - aFont->decorations = NS_FONT_DECORATION_NONE; - - if (aID == eSystemFont_Window || - aID == eSystemFont_Document) { - aFont->name.AssignLiteral("sans-serif"); - aFont->size = NSToCoordRound(aFont->size * 0.875f); // quick hack - } - else - { - ThemeFontID fontID = kThemeViewsFont; - switch (aID) - { - // css2 - case eSystemFont_Caption: fontID = kThemeSystemFont; break; - case eSystemFont_Icon: fontID = kThemeViewsFont; break; - case eSystemFont_Menu: fontID = kThemeSystemFont; break; - case eSystemFont_MessageBox: fontID = kThemeSmallSystemFont; break; - case eSystemFont_SmallCaption: fontID = kThemeSmallEmphasizedSystemFont; break; - case eSystemFont_StatusBar: fontID = kThemeSmallSystemFont; break; - // css3 - //case eSystemFont_Window: = 'sans-serif' - //case eSystemFont_Document: = 'sans-serif' - case eSystemFont_Workspace: fontID = kThemeViewsFont; break; - case eSystemFont_Desktop: fontID = kThemeViewsFont; break; - case eSystemFont_Info: fontID = kThemeViewsFont; break; - case eSystemFont_Dialog: fontID = kThemeSystemFont; break; - case eSystemFont_Button: fontID = kThemePushButtonFont; break; - case eSystemFont_PullDownMenu: fontID = kThemeMenuItemFont; break; - case eSystemFont_List: fontID = kThemeSystemFont; break; - case eSystemFont_Field: fontID = kThemeApplicationFont; break; - // moz - case eSystemFont_Tooltips: fontID = kThemeSmallSystemFont; break; - case eSystemFont_Widget: fontID = kThemeSmallSystemFont; break; - default: break; - } - - nsAutoString fontName; - SInt16 fontSize; - Style fontStyle; - - ScriptCode sysScript = ::GetScriptManagerVariable (smSysScript); - nsresult rv; - rv = GetSystemFontForScript(fontID, smRoman, - fontName, fontSize, fontStyle); - if (NS_FAILED(rv)) - fontName = NS_LITERAL_STRING("Lucida Grande"); - - if (sysScript != smRoman) { - SInt16 localFontSize; - Style localFontStyle; - nsAutoString localSysFontName; - rv = GetSystemFontForScript(fontID, sysScript, - localSysFontName, - localFontSize, localFontStyle); - if (NS_SUCCEEDED(rv) && !fontName.Equals(localSysFontName)) { - fontName += NS_LITERAL_STRING(",") + localSysFontName; - fontSize = localFontSize; - fontStyle = localFontStyle; - } - } - aFont->name = fontName; - aFont->size = NSToCoordRound(float(fontSize) * dev2app); - - if (fontStyle & bold) - aFont->weight = NS_FONT_WEIGHT_BOLD; - if (fontStyle & italic) - aFont->style = NS_FONT_STYLE_ITALIC; - if (fontStyle & underline) - aFont->decorations = NS_FONT_DECORATION_UNDERLINE; - } - break; - - } - - aFont->systemFont = PR_TRUE; - - return status; -} - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac::GetDepth(PRUint32& aDepth) -{ - /* - nsCOMPtr screen; - FindScreenForSurface ( getter_AddRefs(screen) ); - if ( screen ) { - PRInt32 depth; - screen->GetPixelDepth ( &depth ); - aDepth = static_cast(depth); - } - else - aDepth = 1; - */ - - // The above seems correct, however, because of the way Mozilla - // rendering is set upQuickDraw will get confused when - // blitting to a secondary screen with a different bit depth. - // By always returning the bit depth of the primary screen, QD - // can do the proper color mappings. - - if ( !mPrimaryScreen && mScreenManager ) - mScreenManager->GetPrimaryScreen ( getter_AddRefs(mPrimaryScreen) ); - - if(!mPrimaryScreen) { - aDepth = 1; - return NS_OK; - } - - PRInt32 depth; - mPrimaryScreen->GetPixelDepth ( &depth ); - aDepth = static_cast(depth); - - return NS_OK; -} - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac :: CheckFontExistence(const nsString& aFontName) -{ - short fontNum; - if (GetMacFontNumber(aFontName, fontNum)) - return NS_OK; - else - return NS_ERROR_FAILURE; -} - - -// -// FindScreenForSurface -// -// Determines which screen intersects the largest area of the given surface. -// -void -nsDeviceContextMac :: FindScreenForSurface ( nsIScreen** outScreen ) -{ - // optimize for the case where we only have one monitor. - if ( !mPrimaryScreen && mScreenManager ) - mScreenManager->GetPrimaryScreen ( getter_AddRefs(mPrimaryScreen) ); - if ( sNumberOfScreens == 1 ) { - NS_IF_ADDREF(*outScreen = mPrimaryScreen.get()); - return; - } - - nsIWidget* widget = reinterpret_cast(mWidget); // PRAY! - NS_ASSERTION ( widget, "No Widget --> No Window" ); - if ( !widget ) { - NS_IF_ADDREF(*outScreen = mPrimaryScreen.get()); // bail out with the main screen just to be safe. - return; - } - -#if !MOZ_WIDGET_COCOA - // we have a widget stashed inside, get a native WindowRef out of it - WindowRef window = reinterpret_cast(widget->GetNativeData(NS_NATIVE_DISPLAY)); - - StPortSetter setter(window); - - Rect bounds; - ::GetWindowPortBounds ( window, &bounds ); - - if ( mScreenManager ) { - if ( !(bounds.top || bounds.left || bounds.bottom || bounds.right) ) { - NS_WARNING ( "trying to find screen for sizeless window" ); - NS_IF_ADDREF(*outScreen = mPrimaryScreen.get()); - } - else { - // convert window bounds to global coordinates - Point topLeft = { bounds.top, bounds.left }; - Point bottomRight = { bounds.bottom, bounds.right }; - ::LocalToGlobal ( &topLeft ); - ::LocalToGlobal ( &bottomRight ); - Rect globalWindowBounds = { topLeft.v, topLeft.h, bottomRight.v, bottomRight.h } ; - - mScreenManager->ScreenForRect ( globalWindowBounds.left, globalWindowBounds.top, - globalWindowBounds.bottom - globalWindowBounds.top, - globalWindowBounds.right - globalWindowBounds.left, outScreen ); - } - } - else - *outScreen = nsnull; -#else - // in cocoa, we don't have a windowPtr! bail out with the main screen - NS_IF_ADDREF(*outScreen = mPrimaryScreen.get()); -#endif - -} // FindScreenForSurface - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac::GetDeviceSurfaceDimensions(PRInt32 & outWidth, PRInt32 & outHeight) -{ -#ifdef NS_PRINT_PREVIEW - // Defer to Alt when there is one - if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM)) { - return mAltDC->GetDeviceSurfaceDimensions(outWidth, outHeight); - } -#endif - - if( mSpec ) { - // we have a printer device - outWidth = static_cast((mPageRect.right-mPageRect.left)*mDevUnitsToAppUnits); - outHeight = static_cast((mPageRect.bottom-mPageRect.top)*mDevUnitsToAppUnits); - } - else { - // we have a screen device. find the screen that the window is on and - // return its dimensions. - nsCOMPtr screen; - FindScreenForSurface ( getter_AddRefs(screen) ); - if ( screen ) { - PRInt32 width, height, ignored; - screen->GetRect ( &ignored, &ignored, &width, &height ); - - outWidth = NSToIntRound(width * mDevUnitsToAppUnits); - outHeight = NSToIntRound(height * mDevUnitsToAppUnits); - } - else { - NS_WARNING ( "No screen for this surface. How odd" ); - outHeight = 0; - outWidth = 0; - } - } - - return NS_OK; -} - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - */ -NS_IMETHODIMP -nsDeviceContextMac::GetRect(nsRect &aRect) -{ - if( mSpec ) { - // we have a printer device - aRect.x = 0; - aRect.y = 0; - aRect.width = static_cast((mPageRect.right-mPageRect.left)*mDevUnitsToAppUnits); - aRect.height = static_cast((mPageRect.bottom-mPageRect.top)*mDevUnitsToAppUnits); - } - else { - // we have a screen device. find the screen that the window is on and - // return its top/left coordinates. - nsCOMPtr screen; - FindScreenForSurface ( getter_AddRefs(screen) ); - if ( screen ) { - PRInt32 x, y, width, height; - screen->GetRect ( &x, &y, &width, &height ); - - aRect.y = NSToIntRound(y * mDevUnitsToAppUnits); - aRect.x = NSToIntRound(x * mDevUnitsToAppUnits); - aRect.width = NSToIntRound(width * mDevUnitsToAppUnits); - aRect.height = NSToIntRound(height * mDevUnitsToAppUnits); - } - else { - NS_WARNING ( "No screen for this surface. How odd" ); - aRect.x = aRect.y = aRect.width = aRect.height = 0; - } - } - - return NS_OK; - -} // GetDeviceTopLeft - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - */ -NS_IMETHODIMP nsDeviceContextMac::GetClientRect(nsRect &aRect) -{ - if( mSpec ) { - // we have a printer device - aRect.x = aRect.y = 0; - aRect.width = static_cast((mPageRect.right-mPageRect.left)*mDevUnitsToAppUnits); - aRect.height = static_cast((mPageRect.bottom-mPageRect.top)*mDevUnitsToAppUnits); - } - else { - // we have a screen device. find the screen that the window is on and - // return its dimensions. - nsCOMPtr screen; - FindScreenForSurface ( getter_AddRefs(screen) ); - if ( screen ) { - PRInt32 x, y, width, height; - screen->GetAvailRect ( &x, &y, &width, &height ); - - aRect.y = NSToIntRound(y * mDevUnitsToAppUnits); - aRect.x = NSToIntRound(x * mDevUnitsToAppUnits); - aRect.width = NSToIntRound(width * mDevUnitsToAppUnits); - aRect.height = NSToIntRound(height * mDevUnitsToAppUnits); - } - else { - NS_WARNING ( "No screen for this surface. How odd" ); - aRect.x = aRect.y = aRect.width = aRect.height = 0; - } - } - - return NS_OK; -} - - -#pragma mark - - - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsDeviceContextMac::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext) -{ - GrafPtr curPort; - double pix_Inch; - nsDeviceContextMac *macDC; - - aContext = new nsDeviceContextMac(); - if(nsnull == aContext){ - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(aContext); - - macDC = (nsDeviceContextMac*)aContext; - macDC->mSpec = aDevice; - - ::GetPort(&curPort); - - nsCOMPtr printingContext = do_QueryInterface(aDevice); - if (printingContext) { - if (NS_FAILED(printingContext->GetPrinterResolution(&pix_Inch))) - pix_Inch = 72.0; - double top, left, bottom, right; - printingContext->GetPageRect(&top, &left, &bottom, &right); - Rect& pageRect = macDC->mPageRect; - pageRect.top = (PRInt16)top, pageRect.left = (PRInt16)left; - pageRect.bottom = (PRInt16)bottom, pageRect.right = (PRInt16)right; - } - - - ((nsDeviceContextMac*)aContext)->Init(curPort); - - macDC->mTwipsToPixels = pix_Inch/(float)NSIntPointsToTwips(72); - macDC->mPixelsToTwips = 1.0f/macDC->mTwipsToPixels; - macDC->mAppUnitsToDevUnits = macDC->mTwipsToPixels; - macDC->mDevUnitsToAppUnits = 1.0f / macDC->mAppUnitsToDevUnits; - - macDC->mCPixelScale = macDC->mTwipsToPixels / mTwipsToPixels; - - //((nsDeviceContextMac*)aContext)->Init(this); - return NS_OK; -} - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac::BeginDocument(PRUnichar * aTitle, - PRUnichar* aPrintToFileName, - PRInt32 aStartPage, - PRInt32 aEndPage) -{ - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printingContext = do_QueryInterface(mSpec); - if (printingContext) - rv = printingContext->BeginDocument(aTitle, aPrintToFileName, aStartPage, aEndPage); - return rv; -} - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac::EndDocument(void) -{ - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printingContext = do_QueryInterface(mSpec); - if (printingContext) - rv = printingContext->EndDocument(); - return rv; -} - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac::AbortDocument(void) -{ - return EndDocument(); -} - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac::BeginPage(void) -{ - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printingContext = do_QueryInterface(mSpec); - if (printingContext) - rv = printingContext->BeginPage(); - return rv; -} - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -NS_IMETHODIMP nsDeviceContextMac::EndPage(void) -{ - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printingContext = do_QueryInterface(mSpec); - if (printingContext) - rv = printingContext->EndPage(); - return rv; -} - - -#pragma mark - - -//------------------------------------------------------------------------ - -nsHashtable* nsDeviceContextMac :: gFontInfoList = nsnull; - -class FontNameKey : public nsHashKey -{ -public: - FontNameKey(const nsString& aString); - - virtual PRUint32 HashCode(void) const; - virtual PRBool Equals(const nsHashKey *aKey) const; - virtual nsHashKey *Clone(void) const; - - nsAutoString mString; -}; - -FontNameKey::FontNameKey(const nsString& aString) -{ - mString.Assign(aString); -} - -PRUint32 FontNameKey::HashCode(void) const -{ - nsString str; - ToLowerCase(mString, str); - return nsCRT::HashCode(str.get()); -} - -PRBool FontNameKey::Equals(const nsHashKey *aKey) const -{ - return mString.Equals(((FontNameKey*)aKey)->mString, - nsCaseInsensitiveStringComparator()); -} - -nsHashKey* FontNameKey::Clone(void) const -{ - return new FontNameKey(mString); -} - -#pragma mark - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -void nsDeviceContextMac :: InitFontInfoList() -{ - - OSStatus err; - if (!gFontInfoList) - { - gFontInfoList = new nsHashtable(); - if (!gFontInfoList) - return; - - // use the new Font Manager enumeration API. - ATSFontFamilyIterator iter; - err = ::ATSFontFamilyIteratorCreate(kATSFontContextLocal, - NULL, NULL, // filter and its refcon - kATSOptionFlagsDefaultScope, - &iter); - if (err != noErr) - return; - - TextEncoding unicodeEncoding = ::CreateTextEncoding(kTextEncodingUnicodeDefault, - kTextEncodingDefaultVariant, - kUnicodeUTF8Format); - // enumerate all fonts. - TECObjectRef converter = NULL; - TextEncoding oldFontEncoding = 0; - ATSFontFamilyRef fontFamily; - while (::ATSFontFamilyIteratorNext(iter, &fontFamily) == noErr) { - // we'd like to use ATSFontFamilyGetName here, but it's ignorant of the - // font encodings, resulting in garbage names for non-western fonts. - Str255 fontName; - err = ::ATSFontFamilyGetQuickDrawName(fontFamily, fontName); - if (err != noErr || fontName[0] == 0 || fontName[1] == '.' || fontName[1] == '%') - continue; - TextEncoding fontEncoding; - fontEncoding = ::ATSFontFamilyGetEncoding(fontFamily); - if (oldFontEncoding != fontEncoding) { - oldFontEncoding = fontEncoding; - if (converter) - err = ::TECDisposeConverter(converter); - err = ::TECCreateConverter(&converter, fontEncoding, unicodeEncoding); - if (err != noErr) - continue; - } - // convert font name to UNICODE. - char unicodeFontName[sizeof(fontName)]; - ByteCount actualInputLength, actualOutputLength; - err = ::TECConvertText(converter, &fontName[1], fontName[0], &actualInputLength, - (TextPtr)unicodeFontName , sizeof(unicodeFontName), &actualOutputLength); - unicodeFontName[actualOutputLength] = '\0'; - - nsString temp = NS_ConvertUTF8toUTF16(nsDependentCString(unicodeFontName)); - FontNameKey key(temp); - gFontInfoList->Put(&key, (void*)::FMGetFontFamilyFromATSFontFamilyRef(fontFamily)); - } - if (converter) - err = ::TECDisposeConverter(converter); - err = ::ATSFontFamilyIteratorRelease(&iter); - } -} - - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -bool nsDeviceContextMac :: GetMacFontNumber(const nsString& aFontName, short &aFontNum) -{ - //¥TODO?: Maybe we shouldn't call that function so often. If nsFont could store the - // fontNum, nsFontMetricsMac::SetFont() wouldn't need to call this at all. - InitFontInfoList(); - FontNameKey key(aFontName); - aFontNum = (short) NS_PTR_TO_INT32(gFontInfoList->Get(&key)); - return (aFontNum != 0); -} - - -//------------------------------------------------------------------------ -// Override to tweak font settings -nsresult nsDeviceContextMac::CreateFontAliasTable() -{ - nsresult result = NS_OK; - - if (nsnull == mFontAliasTable) { - mFontAliasTable = new nsHashtable(); - if (nsnull != mFontAliasTable) - { - nsAutoString fontTimes; fontTimes.AssignLiteral("Times"); - nsAutoString fontTimesNewRoman; fontTimesNewRoman.AssignLiteral("Times New Roman"); - nsAutoString fontTimesRoman; fontTimesRoman.AssignLiteral("Times Roman"); - nsAutoString fontArial; fontArial.AssignLiteral("Arial"); - nsAutoString fontHelvetica; fontHelvetica.AssignLiteral("Helvetica"); - nsAutoString fontCourier; fontCourier.AssignLiteral("Courier"); - nsAutoString fontCourierNew; fontCourierNew.AssignLiteral("Courier New"); - nsAutoString fontUnicode; fontUnicode.AssignLiteral("Unicode"); - nsAutoString fontBitstreamCyberbit; fontBitstreamCyberbit.AssignLiteral("Bitstream Cyberbit"); - nsAutoString fontNullStr; - - AliasFont(fontTimes, fontTimesNewRoman, fontTimesRoman, PR_FALSE); - AliasFont(fontTimesRoman, fontTimesNewRoman, fontTimes, PR_FALSE); - AliasFont(fontTimesNewRoman, fontTimesRoman, fontTimes, PR_FALSE); - AliasFont(fontArial, fontHelvetica, fontNullStr, PR_FALSE); - AliasFont(fontHelvetica, fontArial, fontNullStr, PR_FALSE); - AliasFont(fontCourier, fontCourierNew, fontNullStr, PR_FALSE); // changed from DeviceContextImpl - AliasFont(fontCourierNew, fontCourier, fontNullStr, PR_FALSE); - AliasFont(fontUnicode, fontBitstreamCyberbit, fontNullStr, PR_FALSE); // XXX ???? - } - else { - result = NS_ERROR_OUT_OF_MEMORY; - } - } - return result; -} - -#pragma mark - - -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/9/98 dwc - */ -PRUint32 nsDeviceContextMac::GetScreenResolution() -{ - static PRBool initialized = PR_FALSE; - if (initialized) - return mPixelsPerInch; - initialized = PR_TRUE; - - nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && prefs) { - PRInt32 intVal; - if (NS_SUCCEEDED(prefs->GetIntPref("layout.css.dpi", &intVal)) && intVal > 0) { - mPixelsPerInch = intVal; - } -#if 0 -// the code here will ignore the default setting of 96dpi and -// instead force approximately 84dpi. There's no real reason for this -// and we shipped Camino0.7 with 96dpi and got no complaints. As -// a result, I'm removing it, but leaving the code for posterity. - else { - short hppi, vppi; - ::ScreenRes(&hppi, &vppi); - mPixelsPerInch = hppi * 1.17f; - } -#endif - } - - return mPixelsPerInch; -} - - -#pragma mark - -//------------------------------------------------------------------------ -nsFontEnumeratorMac::nsFontEnumeratorMac() -{ -} - -NS_IMPL_ISUPPORTS1(nsFontEnumeratorMac, nsIFontEnumerator) - -typedef struct EnumerateFamilyInfo -{ - PRUnichar** mArray; - int mIndex; -} EnumerateFamilyInfo; - -typedef struct EnumerateFontInfo -{ - PRUnichar** mArray; - int mIndex; - int mCount; - ScriptCode mScript; - nsGenericFontNameType mType; -} EnumerateFontInfo; - - - -static int -CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure) -{ - const PRUnichar* str1 = *((const PRUnichar**) aArg1); - const PRUnichar* str2 = *((const PRUnichar**) aArg2); - - // XXX add nsICollation stuff - - return nsCRT::strcmp(str1, str2); -} -static PRBool -EnumerateFamily(nsHashKey *aKey, void *aData, void* closure) - -{ - EnumerateFamilyInfo* info = (EnumerateFamilyInfo*) closure; - PRUnichar** array = info->mArray; - int j = info->mIndex; - - - PRUnichar* str = ToNewUnicode(((FontNameKey*)aKey)->mString); - if (!str) { - for (j = j - 1; j >= 0; j--) { - nsMemory::Free(array[j]); - } - info->mIndex = 0; - return PR_FALSE; - } - array[j] = str; - info->mIndex++; - - return PR_TRUE; -} - -NS_IMETHODIMP -nsFontEnumeratorMac::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult) -{ - if (aCount) { - *aCount = 0; - } - else { - return NS_ERROR_NULL_POINTER; - } - if (aResult) { - *aResult = nsnull; - } - else { - return NS_ERROR_NULL_POINTER; - } - - nsDeviceContextMac::InitFontInfoList(); - nsHashtable* list = nsDeviceContextMac::gFontInfoList; - if(!list) { - return NS_ERROR_FAILURE; - } - PRInt32 items = list->Count(); - PRUnichar** array = (PRUnichar**) - nsMemory::Alloc(items * sizeof(PRUnichar*)); - if (!array) { - return NS_ERROR_OUT_OF_MEMORY; - } - EnumerateFamilyInfo info = { array, 0 }; - list->Enumerate ( EnumerateFamily, &info); - NS_ASSERTION( items == info.mIndex, "didn't get all the fonts"); - if (!info.mIndex) { - nsMemory::Free(array); - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_QuickSort(array, info.mIndex, sizeof(PRUnichar*), - CompareFontNames, nsnull); - - *aCount = info.mIndex; - *aResult = array; - - return NS_OK; -} - -static PRBool -EnumerateFont(nsHashKey *aKey, void *aData, void* closure) - -{ - EnumerateFontInfo* info = (EnumerateFontInfo*) closure; - PRUnichar** array = info->mArray; - int j = info->mCount; - PRBool match = PR_FALSE; - - // we need to match the cast of FMFontFamily in nsDeviceContextMac :: InitFontInfoList() - FMFontFamily fontFamily = (FMFontFamily) NS_PTR_TO_INT32(aData); - TextEncoding fontEncoding; - OSStatus status = ::FMGetFontFamilyTextEncoding(fontFamily, &fontEncoding); - if (noErr == status) { - ScriptCode script; - status = ::RevertTextEncodingToScriptInfo(fontEncoding, &script, nsnull, nsnull); - match = ((noErr == status) && (script == info->mScript)); - } - - if (match) { - PRUnichar* str = ToNewUnicode(((FontNameKey*)aKey)->mString); - if (!str) { - for (j = j - 1; j >= 0; j--) { - nsMemory::Free(array[j]); - } - info->mIndex = 0; - return PR_FALSE; - } - array[j] = str; - info->mCount++; - } - info->mIndex++; - return PR_TRUE; -} -NS_IMETHODIMP -nsFontEnumeratorMac::EnumerateFonts(const char* aLangGroup, - const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult) -{ - if ((! aLangGroup) ||( !aGeneric )) - return NS_ERROR_NULL_POINTER; - - if (aCount) { - *aCount = 0; - } - else { - return NS_ERROR_NULL_POINTER; - } - if (aResult) { - *aResult = nsnull; - } - else { - return NS_ERROR_NULL_POINTER; - } - - if ((!strcmp(aLangGroup, "x-unicode")) || - (!strcmp(aLangGroup, "x-user-def"))) { - return EnumerateAllFonts(aCount, aResult); - } - - nsDeviceContextMac::InitFontInfoList(); - nsHashtable* list = nsDeviceContextMac::gFontInfoList; - if(!list) { - return NS_ERROR_FAILURE; - } - PRInt32 items = list->Count(); - PRUnichar** array = (PRUnichar**) - nsMemory::Alloc(items * sizeof(PRUnichar*)); - if (!array) { - return NS_ERROR_OUT_OF_MEMORY; - } - nsUnicodeMappingUtil* gUtil = nsUnicodeMappingUtil::GetSingleton(); - if(!gUtil) { - return NS_ERROR_FAILURE; - } - - nsAutoString GenName; GenName.AssignWithConversion(aGeneric); - EnumerateFontInfo info = { array, 0 , 0, gUtil->MapLangGroupToScriptCode(aLangGroup) ,gUtil->MapGenericFontNameType(GenName) }; - list->Enumerate ( EnumerateFont, &info); - if (!info.mIndex) { - nsMemory::Free(array); - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_QuickSort(array, info.mCount, sizeof(PRUnichar*), - CompareFontNames, nsnull); - - *aCount = info.mCount; - *aResult = array; - - return NS_OK; -} -NS_IMETHODIMP -nsFontEnumeratorMac::HaveFontFor(const char* aLangGroup,PRBool* aResult) -{ - NS_ENSURE_ARG_POINTER(aLangGroup); - NS_ENSURE_ARG_POINTER(aResult); - *aResult = PR_FALSE; - PRUint32 count; - PRUnichar **ptr; - nsresult res = EnumerateFonts(aLangGroup, "", &count, &ptr); - NS_ENSURE_SUCCESS(res, res); - *aResult = (count > 0); - PRUint32 i; - for(i = 0 ; i < count; i++) - nsMemory::Free(ptr[i]); - nsMemory::Free(ptr); - return NS_OK; -} - -NS_IMETHODIMP -nsFontEnumeratorMac::GetDefaultFont(const char *aLangGroup, - const char *aGeneric, PRUnichar **aResult) -{ - // aLangGroup=null or "" means any (i.e., don't care) - // aGeneric=null or "" means any (i.e, don't care) - - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsFontEnumeratorMac::UpdateFontList(PRBool *updateFontList) -{ - *updateFontList = PR_FALSE; // always return false for now - return NS_OK; -} diff --git a/gfx/src/mac/nsDeviceContextMac.h b/gfx/src/mac/nsDeviceContextMac.h deleted file mode 100644 index 192368cd04d5..000000000000 --- a/gfx/src/mac/nsDeviceContextMac.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDeviceContextMac_h___ -#define nsDeviceContextMac_h___ - -#include "nsDeviceContext.h" -#include "nsIWidget.h" -#include "nsIView.h" -#include "nsIRenderingContext.h" -#include "nsIFontEnumerator.h" -#include -#include - -#include "nsIScreen.h" -#include "nsIScreenManager.h" - - -class nsDeviceContextMac : public DeviceContextImpl -{ -public: - nsDeviceContextMac(); - - NS_IMETHOD Init(nsNativeWidget aNativeWidget); - - /* The following line tells the compiler that we are using the parent class' - functions, unless explicitly overridden. Avoids an ugly warning */ - using DeviceContextImpl::CreateRenderingContext; - NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext); - NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets); - - NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const; - - NS_IMETHOD CheckFontExistence(const nsString& aFontName); - NS_IMETHOD GetDepth(PRUint32& aDepth); - - NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight); - NS_IMETHOD GetRect(nsRect &aRect); - NS_IMETHOD GetClientRect(nsRect &aRect); - - NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice, - nsIDeviceContext *&aContext); - - NS_IMETHOD BeginDocument(PRUnichar * aTitle, - PRUnichar* aPrintToFileName, - PRInt32 aStartPage, - PRInt32 aEndPage); - NS_IMETHOD EndDocument(void); - NS_IMETHOD AbortDocument(void); - - NS_IMETHOD BeginPage(void); - NS_IMETHOD EndPage(void); - PRBool IsPrinter() {if (nsnull != mSpec){return (PR_TRUE);}else{return (PR_FALSE);} }; - - - -protected: - virtual ~nsDeviceContextMac(); - - virtual nsresult CreateFontAliasTable(); - - void FindScreenForSurface ( nsIScreen** outScreen ) ; - - Rect mPageRect; - nsCOMPtr mSpec; - GrafPtr mOldPort; - nsCOMPtr mScreenManager; - nsCOMPtr mPrimaryScreen; // cache the screen for single-monitor systems - -public: - // InitFontInfoList and nsHashTable are static because GetMacFontNumber is static - static void InitFontInfoList(); - static nsHashtable* gFontInfoList; -public: - static bool GetMacFontNumber(const nsString& aFontName, short &fontNum); - -private: - static PRUint32 mPixelsPerInch; - static PRUint32 sNumberOfScreens; // how many screens we have. -public: - static PRUint32 GetScreenResolution(); -}; - - -class nsFontEnumeratorMac : public nsIFontEnumerator -{ -public: - nsFontEnumeratorMac(); - NS_DECL_ISUPPORTS - NS_DECL_NSIFONTENUMERATOR -}; - -#endif /* nsDeviceContextMac_h___ */ diff --git a/gfx/src/mac/nsDrawingSurfaceMac.cpp b/gfx/src/mac/nsDrawingSurfaceMac.cpp deleted file mode 100644 index e953af80b71f..000000000000 --- a/gfx/src/mac/nsDrawingSurfaceMac.cpp +++ /dev/null @@ -1,410 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include - -#include "nsDrawingSurfaceMac.h" -#include "nsGraphicState.h" -#include "nsRegionPool.h" - -#ifdef MOZ_WIDGET_COCOA -// Helper functions to manipulate CGContextRef from a Cocoa NSQuickDrawView. -// Implemented in nsCocoaUtils.mm. -extern CGContextRef Cocoa_LockFocus(void* view); -extern void Cocoa_UnlockFocus(void* view); -#endif - -static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID); -static NS_DEFINE_IID(kIDrawingSurfaceMacIID, NS_IDRAWING_SURFACE_MAC_IID); - - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -nsDrawingSurfaceMac::nsDrawingSurfaceMac() -{ - mPort = NULL; - mGS = sGraphicStatePool.GetNewGS(); //new nsGraphicState(); - mWidth = mHeight = 0; - mLockOffset = mLockHeight = 0; - mLockFlags = 0; - mIsOffscreen = PR_FALSE; - mIsLocked = PR_FALSE; -#ifdef MOZ_WIDGET_COCOA - mWidgetView = nsnull; -#endif -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -nsDrawingSurfaceMac::~nsDrawingSurfaceMac() -{ - if(mIsOffscreen && mPort){ - GWorldPtr offscreenGWorld = (GWorldPtr)mPort; - ::UnlockPixels(::GetGWorldPixMap(offscreenGWorld)); - ::DisposeGWorld(offscreenGWorld); - - nsGraphicsUtils::SetPortToKnownGoodPort(); - } - - if (mGS){ - sGraphicStatePool.ReleaseGS(mGS); //delete mGS; - } -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (nsnull == aInstancePtr) - return NS_ERROR_NULL_POINTER; - - if (aIID.Equals(kIDrawingSurfaceIID)){ - nsIDrawingSurface* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - - if (aIID.Equals(kIDrawingSurfaceMacIID)){ - nsIDrawingSurfaceMac* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - - if (aIID.Equals(kISupportsIID)){ - nsIDrawingSurface* tmp = this; - nsISupports* tmp2 = tmp; - *aInstancePtr = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - - return NS_NOINTERFACE; -} - -NS_IMPL_ADDREF(nsDrawingSurfaceMac) -NS_IMPL_RELEASE(nsDrawingSurfaceMac) - -#pragma mark- - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::Lock(PRInt32 aX, PRInt32 aY, - PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, - PRInt32 *aWidthBytes, PRUint32 aFlags) -{ - - if (!mIsLocked && mIsOffscreen && mPort) - { - // get the offscreen gworld for our use - GWorldPtr offscreenGWorld = (GWorldPtr)mPort; - - // calculate the pixel data size - PixMapHandle thePixMap = ::GetGWorldPixMap(offscreenGWorld); - Ptr baseaddr = ::GetPixBaseAddr(thePixMap); - PRInt32 cmpSize = ((**thePixMap).pixelSize >> 3); - PRInt32 rowBytes = (**thePixMap).rowBytes & 0x3FFF; - - *aBits = baseaddr + (aX * cmpSize) + aY * rowBytes; - *aStride = rowBytes; - *aWidthBytes = aWidth * cmpSize; - - mIsLocked = PR_TRUE; - } - else - { - NS_ASSERTION(0, "nested lock attempt"); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::Unlock(void) -{ - mIsLocked = PR_FALSE; - return NS_OK; -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight) -{ - *aWidth = mWidth; - *aHeight = mHeight; - return NS_OK; -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::IsPixelAddressable(PRBool *aAddressable) -{ - NS_ASSERTION(0, "Not implemented!"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurface.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::GetPixelFormat(nsPixelFormat *aFormat) -{ - //*aFormat = mPixFormat; - NS_ASSERTION(0, "Not implemented!"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -#pragma mark - - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurfaceMac.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::Init(nsIDrawingSurface* aDS) -{ - nsDrawingSurfaceMac* surface = static_cast(aDS); - surface->GetGrafPtr(&mPort); - mGS->Init(surface); - - return NS_OK; -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurfaceMac.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::Init(CGrafPtr aPort) -{ - // set our grafPtr to the passed in port - mPort = aPort; - mGS->Init(aPort); - return NS_OK; -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurfaceMac.h - * @update 3/02/99 dwc - * @return error status - */ -NS_IMETHODIMP nsDrawingSurfaceMac::Init(nsIWidget *aTheWidget) -{ - // get our native graphics port from the widget - mPort = reinterpret_cast(aTheWidget->GetNativeData(NS_NATIVE_GRAPHIC)); - mGS->Init(aTheWidget); -#ifdef MOZ_WIDGET_COCOA - mWidgetView = aTheWidget->GetNativeData(NS_NATIVE_WIDGET); -#endif - return NS_OK; -} - -/** --------------------------------------------------- - * See Documentation in nsIDrawingSurfaceMac.h - * @update 3/02/99 dwc - * @return error status - */ - -NS_IMETHODIMP nsDrawingSurfaceMac::Init(PRUint32 aDepth, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags) -{ - PRUint32 depth; - Rect macRect; - GWorldPtr offscreenGWorld = nsnull; - Boolean tryTempMemFirst = ((aFlags & NS_CREATEDRAWINGSURFACE_SHORTLIVED) != 0); - - depth = aDepth; - mWidth = aWidth; - mHeight = aHeight; - - - // calculate the rectangle - if (aWidth != 0){ - ::SetRect(&macRect, 0, 0, aWidth, aHeight); - }else{ - ::SetRect(&macRect, 0, 0, 2, 2); - } - - // create offscreen, first with normal memory, if that fails use temp memory, if that fails, return - - // Quick and dirty check to make sure there is some memory available. - // GWorld allocations in temp mem can still fail if the heap is totally - // full, because some stuff is allocated in the heap - const long kReserveHeapFreeSpace = (1024 * 1024); - const long kReserveHeapContigSpace = (512 * 1024); - - long totalSpace, contiguousSpace; - - if (tryTempMemFirst) - { - ::NewGWorld(&offscreenGWorld, depth, &macRect, nsnull, nsnull, useTempMem); - if (!offscreenGWorld) - { - // only try the heap if there is enough space - ::PurgeSpace(&totalSpace, &contiguousSpace); // this does not purge memory, just measure it - - if (totalSpace > kReserveHeapFreeSpace && contiguousSpace > kReserveHeapContigSpace) - ::NewGWorld(&offscreenGWorld, depth, &macRect, nsnull, nsnull, 0); - } - } - else // heap first - { - // only try the heap if there is enough space - ::PurgeSpace(&totalSpace, &contiguousSpace); // this does not purge memory, just measure it - - if (totalSpace > kReserveHeapFreeSpace && contiguousSpace > kReserveHeapContigSpace) - ::NewGWorld(&offscreenGWorld, depth, &macRect, nsnull, nsnull, 0); - - if (!offscreenGWorld) - ::NewGWorld(&offscreenGWorld, depth, &macRect, nsnull, nsnull, useTempMem); - } - - if (!offscreenGWorld) - return NS_ERROR_OUT_OF_MEMORY; - - // keep the pixels locked... that's how it works on Windows and we are forced to do - // the same because the API doesn't give us any hook to do it at drawing time. - ::LockPixels(::GetGWorldPixMap(offscreenGWorld)); - - // erase the offscreen area - { - StGWorldPortSetter setter(offscreenGWorld); - ::EraseRect(&macRect); - } - - Init(offscreenGWorld); - mIsOffscreen = PR_TRUE; - return NS_OK; -} - - -// Takes a QD Rect and adds it to the path of the CG Context. This is used -// by QDRegionToRects in order to create a clipping path from a region. -static OSStatus -CreatePathFromRectsProc(UInt16 aMessage, RgnHandle aRegion, const Rect* aRect, - void* aData) -{ - CGContextRef context = static_cast(aData); - - if (aMessage == kQDRegionToRectsMsgParse) - { - CGRect rect = ::CGRectMake(aRect->left, aRect->top, - aRect->right - aRect->left, - aRect->bottom - aRect->top); - ::CGContextAddRect(context, rect); - } - - return noErr; -} - -NS_IMETHODIMP_(CGContextRef) -nsDrawingSurfaceMac::StartQuartzDrawing() -{ - CGContextRef context; -#ifdef MOZ_WIDGET_COCOA - // In Cocoa, we get the context directly from the NSQuickDrawView. - if (mWidgetView) { - context = Cocoa_LockFocus(mWidgetView); - } else -#endif - { - // Convert GrafPort to a CGContext - ::QDBeginCGContext(mPort, &context); - - // Translate to QuickDraw coordinate system - Rect portRect; - ::GetPortBounds(mPort, &portRect); - ::CGContextTranslateCTM(context, 0, (float)(portRect.bottom - portRect.top)); - ::CGContextScaleCTM(context, 1, -1); - } - - if (::IsPortClipRegionEmpty(mPort)) { - // If port clip region is empty, then we need to create 0 by 0 path. - CGRect rect = ::CGRectMake(0, 0, 0, 0); - ::CGContextClipToRect(context, rect); - } else { - // Construct a CG path from the QD region and clip to the path. - StRegionFromPool currentClipRgn; - ::GetPortClipRegion(mPort, currentClipRgn); - ::QDRegionToRects(currentClipRgn, kQDParseRegionFromTopLeft, - CreatePathFromRectsProc, context); - ::CGContextClip(context); - } - - return context; -} - -NS_IMETHODIMP_(void) -nsDrawingSurfaceMac::EndQuartzDrawing(CGContextRef aContext) -{ - // Synchronize the context to QD port before closing it. - ::CGContextSynchronize(aContext); - -#ifdef MOZ_WIDGET_COCOA - if (mWidgetView) - Cocoa_UnlockFocus(mWidgetView); - else -#endif - ::QDEndCGContext(mPort, &aContext); -} diff --git a/gfx/src/mac/nsDrawingSurfaceMac.h b/gfx/src/mac/nsDrawingSurfaceMac.h deleted file mode 100644 index 58b9548da7a4..000000000000 --- a/gfx/src/mac/nsDrawingSurfaceMac.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDrawingSurfaceMac_h___ -#define nsDrawingSurfaceMac_h___ - -#include "nsIDrawingSurface.h" -#include "nsIDrawingSurfaceMac.h" - -#include "nsGfxUtils.h" -#include "nsCarbonHelpers.h" - -class nsGraphicState; - -class nsDrawingSurfaceMac : public nsIDrawingSurface, - nsIDrawingSurfaceMac -{ -public: - nsDrawingSurfaceMac(); - virtual ~nsDrawingSurfaceMac(); - - NS_DECL_ISUPPORTS - - //nsIDrawingSurface interface - NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, - PRUint32 aFlags); - NS_IMETHOD Unlock(void); - NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight); - NS_IMETHOD IsOffscreen(PRBool *aOffScreen) { *aOffScreen = mIsOffscreen; return NS_OK; } - NS_IMETHOD IsPixelAddressable(PRBool *aAddressable); - NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat); - - //nsIDrawingSurfaceMac interface - NS_IMETHOD Init(nsIDrawingSurface* aDS); - NS_IMETHOD Init(CGrafPtr aThePort); - NS_IMETHOD Init(nsIWidget *aTheWidget); - NS_IMETHOD Init(PRUint32 aDepth,PRUint32 aWidth, PRUint32 aHeight,PRUint32 aFlags); - NS_IMETHOD GetGrafPtr(CGrafPtr *aTheGrafPtr) { *aTheGrafPtr = mPort; return NS_OK; } - NS_IMETHOD_(CGContextRef) StartQuartzDrawing(); - NS_IMETHOD_(void) EndQuartzDrawing(CGContextRef aContext); - - // locals - nsGraphicState* GetGS(void) {return mGS;} - -private: - CGrafPtr mPort; // the onscreen or offscreen CGrafPtr; - - PRUint32 mWidth; - PRUint32 mHeight; - PRInt32 mLockOffset; - PRInt32 mLockHeight; - PRUint32 mLockFlags; - PRBool mIsOffscreen; - PRBool mIsLocked; - - nsGraphicState* mGS; // a graphics state for the surface -#ifdef MOZ_WIDGET_COCOA - void* mWidgetView; // non-retained ('weak') ref to NSView -#endif -}; - -#endif diff --git a/gfx/src/mac/nsFontMetricsMac.cpp b/gfx/src/mac/nsFontMetricsMac.cpp deleted file mode 100644 index 03e31f98ff9c..000000000000 --- a/gfx/src/mac/nsFontMetricsMac.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsCarbonHelpers.h" - -#include "nsFontMetricsMac.h" -#include "nsDeviceContextMac.h" -#include "nsUnicodeFontMappingMac.h" -#include "nsUnicodeMappingUtil.h" -#include "nsGfxUtils.h" -#include "nsFontUtils.h" - - -nsFontMetricsMac :: nsFontMetricsMac() -{ - mFontNum = BAD_FONT_NUM; - mFontMapping = nsnull; -} - -nsFontMetricsMac :: ~nsFontMetricsMac() -{ - if (mContext) { - // Notify our device context that owns us so that it can update its font cache - mContext->FontMetricsDeleted(this); - mContext = nsnull; - } - if (mFontMapping) { - delete mFontMapping; - } -} - -//------------------------------------------------------------------------ - -NS_IMPL_ISUPPORTS1(nsFontMetricsMac, nsIFontMetrics) - - -NS_IMETHODIMP nsFontMetricsMac::Init(const nsFont& aFont, nsIAtom* aLangGroup, nsIDeviceContext* aCX) -{ - NS_ASSERTION(!(nsnull == aCX), "attempt to init fontmetrics with null device context"); - - mFont = aFont; - mLangGroup = aLangGroup; - mContext = aCX; - RealizeFont(); - - TextStyle theStyle; - nsFontUtils::GetNativeTextStyle(*this, *mContext, theStyle); - - StTextStyleSetter styleSetter(theStyle); - - FontInfo fInfo; - GetFontInfo(&fInfo); - - float dev2app; - dev2app = mContext->DevUnitsToAppUnits(); - - mLeading = NSToCoordRound(float(fInfo.leading) * dev2app); - mEmAscent = NSToCoordRound(float(fInfo.ascent) * dev2app); - mEmDescent = NSToCoordRound(float(fInfo.descent) * dev2app); - mEmHeight = mEmAscent + mEmDescent; - - mMaxHeight = mEmHeight; - mMaxAscent = mEmAscent; - mMaxDescent = mEmDescent; - - float maxCharWidth = float(::CharWidth('M')); // don't use fInfo.widMax here - mMaxAdvance = NSToCoordRound(maxCharWidth * dev2app); - // If we try to measure draw more than ~32767 pixels - // in one operation, the string may not be drawn: - mMaxStringLength = PR_MAX(1, (PRInt32)floor(32767.0 / maxCharWidth)); - - mAveCharWidth = NSToCoordRound(float(::CharWidth('x')) * dev2app); - mSpaceWidth = NSToCoordRound(float(::CharWidth(' ')) * dev2app); - - Point frac; - frac.h = frac.v = 1; - unsigned char x = 'x'; - short ascent; - if (noErr == ::OutlineMetrics(1, &x, frac, frac, &ascent, 0, 0, 0, 0)) - mXHeight = NSToCoordRound(float(ascent) * dev2app); - else - mXHeight = NSToCoordRound(float(mMaxAscent) * 0.71f); // 0.71 = 5 / 7 - - return NS_OK; -} - -nsUnicodeFontMappingMac* nsFontMetricsMac::GetUnicodeFontMapping() -{ - if (!mFontMapping) - { - // we should pass the documentCharset from the nsIDocument level and - // the lang attribute from the tag level to here. - // XXX hard code to some value till peterl pass them down. - nsAutoString langGroup; - if (mLangGroup) - mLangGroup->ToString(langGroup); - else - langGroup.AssignLiteral("ja"); - - nsString lang; - mFontMapping = new nsUnicodeFontMappingMac(&mFont, mContext, langGroup, lang); - } - - return mFontMapping; -} - - -static void MapGenericFamilyToFont(const nsString& aGenericFamily, nsString& aFontFace, ScriptCode aScriptCode) -{ - // the CSS generic names (conversions from the old Mac Mozilla code for now) - nsUnicodeMappingUtil* unicodeMappingUtil = nsUnicodeMappingUtil::GetSingleton(); - if (unicodeMappingUtil) - { - nsString* foundFont = unicodeMappingUtil->GenericFontNameForScript( - aScriptCode, - unicodeMappingUtil->MapGenericFontNameType(aGenericFamily)); - if (foundFont) - { - aFontFace = *foundFont; - return; - } - } - - NS_ASSERTION(0, "Failed to find a font"); - aFontFace.AssignLiteral("Times"); - - /* - // fall back onto hard-coded font names - if (aGenericFamily.LowerCaseEqualsLiteral("serif")) - { - aFontFace.AssignLiteral("Times"); - } - else if (aGenericFamily.LowerCaseEqualsLiteral("sans-serif")) - { - aFontFace.AssignLiteral("Helvetica"); - } - else if (aGenericFamily.LowerCaseEqualsLiteral("cursive")) - { - aFontFace.AssignLiteral("Apple Chancery"); - } - else if (aGenericFamily.LowerCaseEqualsLiteral("fantasy")) - { - aFontFace.AssignLiteral("Gadget"); - } - else if (aGenericFamily.LowerCaseEqualsLiteral("monospace")) - { - aFontFace.AssignLiteral("Courier"); - } - else if (aGenericFamily.LowerCaseEqualsLiteral("-moz-fixed")) - { - aFontFace.AssignLiteral("Courier"); - } - */ -} - -struct FontEnumData { - FontEnumData(nsIDeviceContext* aDC, nsString& aFaceName, ScriptCode aScriptCode) - : mContext(aDC), mFaceName(aFaceName), mScriptCode(aScriptCode) - {} - nsIDeviceContext* mContext; - nsString& mFaceName; - ScriptCode mScriptCode; -}; - -static PRBool FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData) -{ - FontEnumData* data = (FontEnumData*)aData; - if (aGeneric) - { - nsAutoString realFace; - MapGenericFamilyToFont(aFamily, realFace, data->mScriptCode); - data->mFaceName = realFace; - return PR_FALSE; // stop - } - else - { - nsAutoString realFace; - PRBool aliased; - data->mContext->GetLocalFontName(aFamily, realFace, aliased); - if (aliased || (NS_OK == data->mContext->CheckFontExistence(realFace))) - { - data->mFaceName = realFace; - return PR_FALSE; // stop - } - } - return PR_TRUE; -} - -void nsFontMetricsMac::RealizeFont() -{ - nsAutoString fontName; - nsUnicodeMappingUtil *unicodeMappingUtil; - ScriptCode theScriptCode; - - unicodeMappingUtil = nsUnicodeMappingUtil::GetSingleton (); - if (unicodeMappingUtil) - { - nsAutoString theLangGroupString; - - if (mLangGroup) - mLangGroup->ToString(theLangGroupString); - else - theLangGroupString.AssignLiteral("ja"); - - theScriptCode = unicodeMappingUtil->MapLangGroupToScriptCode( - NS_ConvertUTF16toUTF8(theLangGroupString).get()); - - } - else - theScriptCode = GetScriptManagerVariable (smSysScript); - - FontEnumData fontData(mContext, fontName, theScriptCode); - mFont.EnumerateFamilies(FontEnumCallback, &fontData); - - nsDeviceContextMac::GetMacFontNumber(fontName, mFontNum); -} - - -NS_IMETHODIMP -nsFontMetricsMac::Destroy() -{ - mContext = nsnull; - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP -nsFontMetricsMac :: GetXHeight(nscoord& aResult) -{ - aResult = mXHeight; - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetSuperscriptOffset(nscoord& aResult) -{ - float dev2app; - dev2app = mContext->DevUnitsToAppUnits(); - aResult = NSToCoordRound(float(mMaxAscent / 2) - dev2app); - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetSubscriptOffset(nscoord& aResult) -{ - float dev2app; - dev2app = mContext->DevUnitsToAppUnits(); - aResult = NSToCoordRound(float(mMaxAscent / 2) - dev2app); - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetStrikeout(nscoord& aOffset, nscoord& aSize) -{ - float dev2app; - dev2app = mContext->DevUnitsToAppUnits(); - aOffset = NSToCoordRound(float(mMaxAscent / 2) - dev2app); - aSize = NSToCoordRound(dev2app); - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetUnderline(nscoord& aOffset, nscoord& aSize) -{ - float dev2app; - dev2app = mContext->DevUnitsToAppUnits(); - aOffset = -NSToCoordRound( dev2app ); - aSize = NSToCoordRound( dev2app ); - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac :: GetHeight(nscoord &aHeight) -{ - aHeight = mMaxHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac :: GetNormalLineHeight(nscoord &aHeight) -{ - aHeight = mEmHeight + mLeading; // Mac's leading is external leading - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac :: GetLeading(nscoord &aLeading) -{ - aLeading = mLeading; - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetEmHeight(nscoord &aHeight) -{ - aHeight = mEmHeight; - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetEmAscent(nscoord &aAscent) -{ - aAscent = mEmAscent; - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetEmDescent(nscoord &aDescent) -{ - aDescent = mEmDescent; - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsMac :: GetMaxHeight(nscoord &aHeight) -{ - aHeight = mMaxHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac :: GetMaxAscent(nscoord &aAscent) -{ - aAscent = mMaxAscent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac :: GetMaxDescent(nscoord &aDescent) -{ - aDescent = mMaxDescent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac :: GetMaxAdvance(nscoord &aAdvance) -{ - aAdvance = mMaxAdvance; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac :: GetAveCharWidth(nscoord &aAveCharWidth) -{ - aAveCharWidth = mAveCharWidth; - return NS_OK; -} - -PRInt32 nsFontMetricsMac::GetMaxStringLength() -{ - return mMaxStringLength; -} - -nsresult nsFontMetricsMac :: GetSpaceWidth(nscoord &aSpaceWidth) -{ - aSpaceWidth = mSpaceWidth; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsMac::GetLangGroup(nsIAtom** aLangGroup) -{ - if (!aLangGroup) { - return NS_ERROR_NULL_POINTER; - } - - *aLangGroup = mLangGroup; - NS_IF_ADDREF(*aLangGroup); - - return NS_OK; -} - - -NS_IMETHODIMP nsFontMetricsMac :: GetWidths(const nscoord *&aWidths) -{ - return NS_ERROR_NOT_IMPLEMENTED; //XXX -} - -NS_IMETHODIMP nsFontMetricsMac :: GetFontHandle(nsFontHandle &aHandle) -{ - // NOTE: the name in the mFont may be a comma-separated list of - // font names, like "Verdana, Arial, sans-serif" - // If you want to do the conversion again to a Mac font, you'll - // have to EnumerateFamilies() to resolve it to an installed - // font again. - NS_PRECONDITION(mFontNum != BAD_FONT_NUM, "Font metrics have not been initialized"); - - // We have no 'font handles' on Mac like they have on Windows - // so let's use it for the fontNum. - aHandle = (nsFontHandle)mFontNum; - return NS_OK; -} - diff --git a/gfx/src/mac/nsFontMetricsMac.h b/gfx/src/mac/nsFontMetricsMac.h deleted file mode 100644 index cefb4b11400e..000000000000 --- a/gfx/src/mac/nsFontMetricsMac.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsFontMetricsMac_h__ -#define nsFontMetricsMac_h__ - -#include // for TextStyle - -#include "nsIFontMetrics.h" -#include "nsFont.h" -#include "nsString.h" -#include "nsIDeviceContext.h" -#include "nsCRT.h" -#include "nsIAtom.h" -#include "nsCOMPtr.h" -class nsUnicodeFontMappingMac; - -class nsFontMetricsMac : public nsIFontMetrics -{ -public: - nsFontMetricsMac(); - virtual ~nsFontMetricsMac(); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup, nsIDeviceContext* aContext); - NS_IMETHOD Destroy(); - - NS_IMETHOD GetXHeight(nscoord& aResult); - NS_IMETHOD GetSuperscriptOffset(nscoord& aResult); - NS_IMETHOD GetSubscriptOffset(nscoord& aResult); - NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize); - NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize); - NS_IMETHOD GetHeight(nscoord &aHeight); - NS_IMETHOD GetNormalLineHeight(nscoord &aHeight); - NS_IMETHOD GetLeading(nscoord &aLeading); - NS_IMETHOD GetEmHeight(nscoord &aHeight); - NS_IMETHOD GetEmAscent(nscoord &aAscent); - NS_IMETHOD GetEmDescent(nscoord &aDescent); - NS_IMETHOD GetMaxHeight(nscoord &aHeight); - NS_IMETHOD GetMaxAscent(nscoord &aAscent); - NS_IMETHOD GetMaxDescent(nscoord &aDescent); - NS_IMETHOD GetMaxAdvance(nscoord &aAdvance); - NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); - NS_IMETHOD GetWidths(const nscoord *&aWidths); - NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); - NS_IMETHOD GetFontHandle(nsFontHandle& aHandle); - NS_IMETHOD GetSpaceWidth(nscoord& aSpaceCharWidth); - virtual PRInt32 GetMaxStringLength(); - - nsUnicodeFontMappingMac* GetUnicodeFontMapping(); - -protected: - void RealizeFont(); - - short mFontNum; - nsUnicodeFontMappingMac *mFontMapping; - nscoord mEmHeight; - nscoord mEmAscent; - nscoord mEmDescent; - nscoord mMaxHeight; - nscoord mLeading; - nscoord mMaxAscent; - nscoord mMaxDescent; - nscoord mMaxAdvance; - nscoord mAveCharWidth; - nscoord mSpaceWidth; - nscoord mXHeight; - PRInt32 mMaxStringLength; - nsCOMPtr mLangGroup; - nsIDeviceContext *mContext; -}; - -#endif - - - - diff --git a/gfx/src/mac/nsFontUtils.cpp b/gfx/src/mac/nsFontUtils.cpp deleted file mode 100644 index ce5d771c3ebb..000000000000 --- a/gfx/src/mac/nsFontUtils.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#include "nsIPref.h" -#include "nsIServiceManager.h" - -#include "nsFont.h" -#include "nsDeviceContextMac.h" - -#include "nsFontUtils.h" - -PRBool nsFontUtils::sDisplayVerySmallFonts = true; - - -PRBool -nsFontUtils::DisplayVerySmallFonts() -{ - static PRBool sInitialized = PR_FALSE; - if (sInitialized) - return sDisplayVerySmallFonts; - - sInitialized = PR_TRUE; - - nsresult rv; - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv) && prefs) { - PRBool boolVal; - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.display_very_small_fonts", &boolVal))) { - sDisplayVerySmallFonts = boolVal; - } - } - - return sDisplayVerySmallFonts; -} - - -// A utility routine to the the text style in a convenient manner. -// This is static, which is unfortunate, because it introduces link -// dependencies between libraries that should not exist. -void -nsFontUtils::GetNativeTextStyle(nsIFontMetrics& inMetrics, - const nsIDeviceContext& inDevContext, TextStyle &outStyle) -{ - const nsFont *aFont = &inMetrics.Font(); - - nsFontHandle fontNum; - inMetrics.GetFontHandle(fontNum); - - float dev2app; - dev2app = inDevContext.DevUnitsToAppUnits(); - short textSize = float(aFont->size) / dev2app; - textSize = PR_MAX(1, textSize); - - if (textSize < 9 && !nsFontUtils::DisplayVerySmallFonts()) - textSize = 9; - - Style textFace = normal; - switch (aFont->style) - { - case NS_FONT_STYLE_NORMAL: break; - case NS_FONT_STYLE_ITALIC: textFace |= italic; break; - case NS_FONT_STYLE_OBLIQUE: textFace |= italic; break; //XXX - } - - PRInt32 offset = aFont->weight % 100; - PRInt32 baseWeight = aFont->weight / 100; - NS_ASSERTION((offset < 10) || (offset > 90), "Invalid bolder or lighter value"); - if (offset == 0) { - if (aFont->weight >= NS_FONT_WEIGHT_BOLD) - textFace |= bold; - } else { - if (offset < 10) - textFace |= bold; - } - - RGBColor black = {0}; - - outStyle.tsFont = (short) NS_PTR_TO_INT32(fontNum); - outStyle.tsFace = textFace; - outStyle.tsSize = textSize; - outStyle.tsColor = black; -} - diff --git a/gfx/src/mac/nsFontUtils.h b/gfx/src/mac/nsFontUtils.h deleted file mode 100644 index c8da97830bba..000000000000 --- a/gfx/src/mac/nsFontUtils.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsFontUtils_h_ -#define nsFontUtils_h_ - -#include - -#include "nsIFontMetrics.h" -#include "nsIDeviceContext.h" -#include "gfxCore.h" - -class NS_GFX nsFontUtils -{ -public: - - static void GetNativeTextStyle(nsIFontMetrics& inMetrics, const nsIDeviceContext& inDevContext, TextStyle &outStyle); - static PRBool DisplayVerySmallFonts(); - -protected: - - static PRBool sDisplayVerySmallFonts; - -}; - - - -#endif // nsFontUtils_h_ diff --git a/gfx/src/mac/nsGfxFactoryMac.cpp b/gfx/src/mac/nsGfxFactoryMac.cpp deleted file mode 100644 index 548abdeb7a37..000000000000 --- a/gfx/src/mac/nsGfxFactoryMac.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Patrick C. Beard - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nscore.h" -#include "nsIFactory.h" -#include "nsISupports.h" -#include "nsGfxCIID.h" -#include "nsFontMetricsMac.h" -#include "nsRenderingContextMac.h" -#include "nsImageMac.h" -#include "nsDeviceContextMac.h" -#include "nsRegionMac.h" -#include "nsScriptableRegion.h" -#include "nsBlender.h" -#include "nsCOMPtr.h" -#include "nsUnicodeMappingUtil.h" -#include "gfxImageFrame.h" - -#include "nsIGenericFactory.h" - - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsMac) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextMac) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextMac) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageMac) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionMac) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDrawingSurfaceMac) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorMac) -NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame) - -static NS_IMETHODIMP -nsScriptableRegionConstructor(nsISupports* aOuter, REFNSIID aIID, void** aResult) -{ - NS_ENSURE_NO_AGGREGATION(aOuter); - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - nsCOMPtr region = new nsRegionMac(); - NS_ENSURE_TRUE(region, NS_ERROR_OUT_OF_MEMORY); - nsCOMPtr result(new nsScriptableRegion(region)); - NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); - return result->QueryInterface(aIID, aResult); -} - -static const nsModuleComponentInfo components[] = -{ - { "nsFontMetrics", - NS_FONT_METRICS_CID, - "@mozilla.org/gfx/fontmetrics;1", - nsFontMetricsMacConstructor }, - { "nsDeviceContext", - NS_DEVICE_CONTEXT_CID, - "@mozilla.org/gfx/devicecontext;1", - nsDeviceContextMacConstructor }, - { "nsRenderingContext", - NS_RENDERING_CONTEXT_CID, - "@mozilla.org/gfx/renderingcontext;1", - nsRenderingContextMacConstructor }, - { "nsImage", - NS_IMAGE_CID, - "@mozilla.org/gfx/image;1", - nsImageMacConstructor }, - { "nsRegion", - NS_REGION_CID, - "@mozilla.org/gfx/unscriptable-region;1", - nsRegionMacConstructor }, - { "nsScriptableRegion", - NS_SCRIPTABLE_REGION_CID, - "@mozilla.org/gfx/region;1", - nsScriptableRegionConstructor }, - { "nsBlender", - NS_BLENDER_CID, - "@mozilla.org/gfx/blender;1", - nsBlenderConstructor }, - { "nsDrawingSurface", - NS_DRAWING_SURFACE_CID, - "@mozilla.org/gfx/drawing-surface;1", - nsDrawingSurfaceMacConstructor }, - { "nsFontEnumerator", - NS_FONT_ENUMERATOR_CID, - "@mozilla.org/gfx/fontenumerator;1", - nsFontEnumeratorMacConstructor }, - { "windows image frame", - GFX_IMAGEFRAME_CID, - "@mozilla.org/gfx/image/frame;2", - gfxImageFrameConstructor, }, -}; - -PR_STATIC_CALLBACK(void) -nsGfxMacModuleDtor(nsIModule *self) -{ - nsUnicodeMappingUtil::FreeSingleton(); -} - -NS_IMPL_NSGETMODULE_WITH_DTOR(nsGfxMacModule, components, nsGfxMacModuleDtor) - - diff --git a/gfx/src/mac/nsGfxUtils.h b/gfx/src/mac/nsGfxUtils.h deleted file mode 100644 index e799bea4dec5..000000000000 --- a/gfx/src/mac/nsGfxUtils.h +++ /dev/null @@ -1,401 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsGfxUtils_h_ -#define nsGfxUtils_h_ - -#ifndef CarbonHelpers_h__ -#include "nsCarbonHelpers.h" -#endif // CarbonHelpers_h__ - -#if DEBUG && !defined(XP_MACOSX) -#include "macstdlibextras.h" -#endif - -#include - - -/** ------------------------------------------------------------ - * Used to assert that we're not clobbering a bad port - */ -inline PRBool CurrentPortIsWMPort() -{ - return PR_FALSE; -} - - -//------------------------------------------------------------------------ -// ValidateDrawingState -// -// Test that the current drawing environment is good, which means that -// we have a valid port (as far as we can tell) -//------------------------------------------------------------------------ -inline PRBool ValidateDrawingState() -{ - CGrafPtr curPort; - GDHandle curDevice; - - GetGWorld(&curPort, &curDevice); - - // if we have a window, but we're set to the WM port, things are bad - if (CurrentPortIsWMPort() && (FrontWindow() != nil)) - return false; - - - // see if the device is in the device list. If not, it probably means that - // it's the device for an offscreen GWorld. In that case, the current port - // should be set to that GWorld too. - { - GDHandle thisDevice = GetDeviceList(); - while (thisDevice) - { - if (thisDevice == curDevice) - break; - - thisDevice = GetNextDevice(thisDevice); - } - - if ((thisDevice == nil) && !IsPortOffscreen(curPort)) // nil device is OK only with GWorld - return false; - } - - return true; -} - - -//------------------------------------------------------------------------ -// static graphics utility methods -//------------------------------------------------------------------------ -class nsGraphicsUtils -{ -public: - - //------------------------------------------------------------------------ - // SafeSetPort - // - // Set the port, being sure to set the GDevice to a valid device, since - // the current GDevice may belong to a GWorld. - //------------------------------------------------------------------------ - static void SafeSetPort(CGrafPtr newPort) - { - ::SetGWorld(newPort, ::IsPortOffscreen(newPort) ? nsnull : ::GetMainDevice()); - } - - //------------------------------------------------------------------------ - // SafeSetPortWindowPort - // - // Set the port, being sure to set the GDevice to a valid device, since - // the current GDevice may belong to a GWorld. - //------------------------------------------------------------------------ - static void SafeSetPortWindowPort(WindowPtr window) - { - SafeSetPort(::GetWindowPort(window)); - } - - //------------------------------------------------------------------------ - // SetPortToKnownGoodPort - // - // Set the port to a known good port, if possible. - //------------------------------------------------------------------------ - static void SetPortToKnownGoodPort() - { - WindowPtr firstWindow = GetTheWindowList(); - if (firstWindow) - ::SetGWorld(::GetWindowPort(firstWindow), ::GetMainDevice()); - } - -}; - - -//------------------------------------------------------------------------ -// utility port setting class -// -// This code has to deal with the situation where the current port -// is a GWorld, and the current devices that GWorld's device. So -// when setting the port to an onscreen part, we always reset the -// current device to the main device. -//------------------------------------------------------------------------ -class StPortSetter -{ -public: - StPortSetter(CGrafPtr newPort) - { - InitSetter(newPort); - } - - StPortSetter(WindowPtr window) - { - InitSetter(GetWindowPort(window)); - } - - ~StPortSetter() - { - if (mPortChanged) - ::SetGWorld(mOldPort, mOldDevice); - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); - } - -protected: - void InitSetter(CGrafPtr newPort) - { - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); - // we assume that if the port has been set, then the port/GDevice are - // valid, and do nothing (for speed) - mPortChanged = (newPort != CGrafPtr(GetQDGlobalsThePort())); - if (mPortChanged) - { - ::GetGWorld(&mOldPort, &mOldDevice); - ::SetGWorld(newPort, ::IsPortOffscreen(newPort) ? nsnull : ::GetMainDevice()); - } - } - -protected: - Boolean mPortChanged; - CGrafPtr mOldPort; - GDHandle mOldDevice; -}; - - -//------------------------------------------------------------------------ -// utility class to temporarily set and restore the origin. -// Assumes that the port has already been set up. -//------------------------------------------------------------------------ -class StOriginSetter -{ -public: - - StOriginSetter(WindowRef wind, const Point* newOrigin = nsnull) - { - ::GetWindowPortBounds(wind, &mSavePortRect); - if (newOrigin) - ::SetOrigin(newOrigin->h, newOrigin->v); - else - ::SetOrigin(0, 0); - } - - StOriginSetter(CGrafPtr grafPort, const Point* newOrigin = nsnull) - { - ::GetPortBounds(grafPort, &mSavePortRect); - if (newOrigin) - ::SetOrigin(newOrigin->h, newOrigin->v); - else - ::SetOrigin(0, 0); - } - - ~StOriginSetter() - { - ::SetOrigin(mSavePortRect.left, mSavePortRect.top); - } - -protected: - - Rect mSavePortRect; - -}; - -//------------------------------------------------------------------------ -// utility GWorld port setting class -// -// This should *only* be used to set the port temporarily to the -// GWorld, and then restore it. -//------------------------------------------------------------------------ - -class StGWorldPortSetter -{ -public: - StGWorldPortSetter(GWorldPtr destGWorld) - { - NS_ASSERTION(::IsPortOffscreen(destGWorld), "StGWorldPortSetter should only be used for GWorlds"); - ::GetGWorld(&mOldPort, &mOldDevice); - ::SetGWorld(destGWorld, nsnull); - } - - ~StGWorldPortSetter() - { - ::SetGWorld(mOldPort, mOldDevice); - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); - } - -protected: - GWorldPtr mOldPort; - GDHandle mOldDevice; -}; - -//------------------------------------------------------------------------ -// utility text state save/restore class -//------------------------------------------------------------------------ - -class StTextStyleSetter -{ -public: - StTextStyleSetter(SInt16 fontID, SInt16 fontSize, SInt16 fontFace) - { - SetPortFontStyle(fontID, fontSize, fontFace); - } - - StTextStyleSetter(TextStyle& theStyle) - { - SetPortFontStyle(theStyle.tsFont, theStyle.tsSize, theStyle.tsFace); - } - - ~StTextStyleSetter() - { - ::TextFont(mFontID); - ::TextSize(mFontSize); - ::TextFace(mFontFace); - } - -protected: - - void SetPortFontStyle(SInt16 fontID, SInt16 fontSize, SInt16 fontFace) - { - CGrafPtr curPort; - ::GetPort((GrafPtr*)&curPort); - - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); - - mFontID = ::GetPortTextFont(curPort); - mFontSize = ::GetPortTextSize(curPort); - mFontFace = ::GetPortTextFace(curPort); - - ::TextFont(fontID); - ::TextSize(fontSize); - ::TextFace(fontFace); - - } - -protected: - SInt16 mFontID; - SInt16 mFontSize; - SInt16 mFontFace; -}; - - - - - -/** ------------------------------------------------------------ - * Utility class for saving, locking, and restoring pixel state - */ - -class StPixelLocker -{ -public: - - StPixelLocker(PixMapHandle thePixMap) - : mPixMap(thePixMap) - , mPixelState(0) - { - if (mPixMap) { - mPixelState = ::GetPixelsState(mPixMap); - ::LockPixels(mPixMap); - } - } - - ~StPixelLocker() - { - if (mPixMap) - ::SetPixelsState(mPixMap, mPixelState); - } - -protected: - - - PixMapHandle mPixMap; - GWorldFlags mPixelState; - -}; - - -/** ------------------------------------------------------------ - * Utility class for saving, locking, and restoring handle state - * Ok with null handle - */ - -class StHandleLocker -{ -public: - - StHandleLocker(Handle theHandle) - : mHandle(theHandle) - { - if (mHandle) - { - mOldHandleState = ::HGetState(mHandle); - ::HLock(mHandle); - } - } - - ~StHandleLocker() - { - if (mHandle) - ::HSetState(mHandle, mOldHandleState); - } - -protected: - - Handle mHandle; - SInt8 mOldHandleState; -}; - - -/** - * Stack based utility class for releasing a Quartz color space. - * Use as follows: - * CGColorSpaceRef rgbSpace = ::CGColorSpaceCreateDeviceRGB(); - * StColorSpaceReleaser csReleaser(rgbSpace); - */ -class StColorSpaceReleaser -{ -public: - StColorSpaceReleaser(CGColorSpaceRef inColorSpace) - : mColorSpace(inColorSpace) - { - } - - ~StColorSpaceReleaser() - { - // No need to check for NULL, since CGColorSpaceCreateDeviceRGB(NULL) - // is a noop. - ::CGColorSpaceRelease(mColorSpace); - } - -private: - CGColorSpaceRef mColorSpace; -}; - -#endif // nsGfxUtils_h_ diff --git a/gfx/src/mac/nsGraphicState.cpp b/gfx/src/mac/nsGraphicState.cpp deleted file mode 100644 index 4429c3b0a241..000000000000 --- a/gfx/src/mac/nsGraphicState.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsGraphicState.h" -#include "nsDrawingSurfaceMac.h" -#include "nsRegionMac.h" -#include "nsIFontMetrics.h" -#include "nsCarbonHelpers.h" -#include "nsRegionPool.h" - -nsGraphicStatePool sGraphicStatePool; - - -//------------------------------------------------------------------------ - -nsGraphicStatePool::nsGraphicStatePool() -{ - mFreeList = nsnull; -} - -//------------------------------------------------------------------------ - -nsGraphicStatePool::~nsGraphicStatePool() -{ - nsGraphicState* gs = mFreeList; - while (gs != nsnull) { - nsGraphicState* next = gs->mNext; - delete gs; - gs = next; - } -} - -//------------------------------------------------------------------------ - -nsGraphicState* nsGraphicStatePool::GetNewGS() -{ - nsGraphicState* gs = mFreeList; - if (gs != nsnull) { - mFreeList = gs->mNext; - return gs; - } - return new nsGraphicState; -} - -//------------------------------------------------------------------------ - -void nsGraphicStatePool::ReleaseGS(nsGraphicState* aGS) -{ - // clear the graphics state? this will cause its transformation matrix and regions - // to be released. I'm dubious about that. in fact, shouldn't the matrix always be - // a member object of the graphics state? why have a separate allocation at all? - aGS->Clear(); - aGS->mNext = mFreeList; - mFreeList = aGS; -} - - -#pragma mark - -//------------------------------------------------------------------------ - -nsGraphicState::nsGraphicState() -{ - // everything is initialized to 0 through the 'new' operator -} - -//------------------------------------------------------------------------ - -nsGraphicState::~nsGraphicState() -{ - Clear(); -} - -//------------------------------------------------------------------------ - -void nsGraphicState::Clear() -{ - mTMatrix.SetToIdentity(); - - if (mMainRegion) { - sNativeRegionPool.ReleaseRegion(mMainRegion); //::DisposeRgn(mMainRegion); - mMainRegion = nsnull; - } - - if (mClipRegion) { - sNativeRegionPool.ReleaseRegion(mClipRegion); //::DisposeRgn(mClipRegion); - mClipRegion = nsnull; - } - - NS_IF_RELEASE(mFontMetrics); - - mOffx = 0; - mOffy = 0; - mColor = NS_RGB(255,255,255); - mFont = 0; - mFontMetrics = nsnull; - mCurrFontHandle = 0; - mLineStyle = nsLineStyle_kSolid; -} - -//------------------------------------------------------------------------ - -void nsGraphicState::Init(nsIDrawingSurface* aSurface) -{ - // retrieve the grafPort - nsDrawingSurfaceMac* surface = static_cast(aSurface); - CGrafPtr port; - surface->GetGrafPtr(&port); - - // init from grafPort - Init(port); -} - -//------------------------------------------------------------------------ - -void nsGraphicState::Init(CGrafPtr aPort) -{ - // delete old values - Clear(); - - // init from grafPort (usually an offscreen port) - RgnHandle rgn = sNativeRegionPool.GetNewRegion(); //::NewRgn(); - if ( rgn ) { - Rect bounds; - ::RectRgn(rgn, ::GetPortBounds(aPort, &bounds)); - } - - Rect portBounds; - ::GetPortBounds(aPort, &portBounds); - mOffx = -portBounds.left; - mOffy = -portBounds.top; - - mMainRegion = rgn; - mClipRegion = DuplicateRgn(rgn); -} - -//------------------------------------------------------------------------ - -void nsGraphicState::Init(nsIWidget* aWindow) -{ - // delete old values - Clear(); - - // init from widget - mOffx = (PRInt32)aWindow->GetNativeData(NS_NATIVE_OFFSETX); - mOffy = (PRInt32)aWindow->GetNativeData(NS_NATIVE_OFFSETY); - - RgnHandle widgetRgn = (RgnHandle)aWindow->GetNativeData(NS_NATIVE_REGION); - mMainRegion = DuplicateRgn(widgetRgn); - mClipRegion = DuplicateRgn(widgetRgn); -} - -//------------------------------------------------------------------------ - -void nsGraphicState::Duplicate(nsGraphicState* aGS) -{ - // clear old values? no need, just copying them any way. - // Clear(); - - // copy new ones - mTMatrix.SetMatrix(&aGS->mTMatrix); - - mOffx = aGS->mOffx; - mOffy = aGS->mOffy; - - mMainRegion = DuplicateRgn(aGS->mMainRegion, mMainRegion); - mClipRegion = DuplicateRgn(aGS->mClipRegion, mClipRegion); - - mColor = aGS->mColor; - mFont = aGS->mFont; - - NS_IF_RELEASE(mFontMetrics); - mFontMetrics = aGS->mFontMetrics; - NS_IF_ADDREF(mFontMetrics); - - mCurrFontHandle = aGS->mCurrFontHandle; - - mLineStyle = aGS->mLineStyle; - - mChanges = aGS->mChanges; -} - -//------------------------------------------------------------------------ - -RgnHandle nsGraphicState::DuplicateRgn(RgnHandle aRgn, RgnHandle aDestRgn) -{ - RgnHandle dupRgn = aDestRgn; - if (aRgn) { - if (nsnull == dupRgn) - dupRgn = sNativeRegionPool.GetNewRegion(); //::NewRgn(); - if (dupRgn) - ::CopyRgn(aRgn, dupRgn); - } - return dupRgn; -} diff --git a/gfx/src/mac/nsGraphicState.h b/gfx/src/mac/nsGraphicState.h deleted file mode 100644 index df31dfeac130..000000000000 --- a/gfx/src/mac/nsGraphicState.h +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#ifndef nsGraphicState_h___ -#define nsGraphicState_h___ - -#include "nsIRenderingContext.h" -#include "nsTransform2D.h" -#include "nsCRT.h" - -#ifndef __QUICKDRAW__ -#include -#endif - -//------------------------------------------------------------------------ - -class nsGraphicState -{ -public: - nsGraphicState(); - ~nsGraphicState(); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - void Clear(); - void Init(nsIDrawingSurface* aSurface); - void Init(CGrafPtr aPort); - void Init(nsIWidget* aWindow); - void Duplicate(nsGraphicState* aGS); // would you prefer an '=' operator? - // - no thanks, - void SetChanges(PRUint32 aChanges) { mChanges = aChanges; } - PRUint32 GetChanges() { return mChanges; } - -protected: - RgnHandle DuplicateRgn(RgnHandle aRgn, RgnHandle aDestRgn = nsnull); - -public: - nsTransform2D mTMatrix; // transform that all the graphics drawn here will obey - - PRInt32 mOffx; - PRInt32 mOffy; - - RgnHandle mMainRegion; - RgnHandle mClipRegion; - - nscolor mColor; - PRInt32 mFont; - nsIFontMetrics * mFontMetrics; - PRInt32 mCurrFontHandle; - nsLineStyle mLineStyle; - - PRUint32 mChanges; // flags indicating changes between this graphics state and the previous. - -private: - friend class nsGraphicStatePool; - nsGraphicState* mNext; // link into free list of graphics states. -}; - -//------------------------------------------------------------------------ - -class nsGraphicStatePool -{ -public: - nsGraphicStatePool(); - ~nsGraphicStatePool(); - - nsGraphicState* GetNewGS(); - void ReleaseGS(nsGraphicState* aGS); - -private: - - nsGraphicState* mFreeList; -}; - -//------------------------------------------------------------------------ - -extern nsGraphicStatePool sGraphicStatePool; - -//------------------------------------------------------------------------ - - -#endif //nsGraphicState_h___ diff --git a/gfx/src/mac/nsIDrawingSurfaceMac.h b/gfx/src/mac/nsIDrawingSurfaceMac.h deleted file mode 100644 index ea3120d62271..000000000000 --- a/gfx/src/mac/nsIDrawingSurfaceMac.h +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIDrawingSurfaceMac_h___ -#define nsIDrawingSurfaceMac_h___ - -#include "nsIDrawingSurface.h" -#include "nsIWidget.h" -#include "nsIRenderingContext.h" -#include - -class GraphicsState; - -// windows specific drawing surface method set - -#define NS_IDRAWING_SURFACE_MAC_IID \ -{ 0xd49598bb, 0x04ff, 0x4aba, \ - { 0xab, 0x90, 0x5b, 0xd0, 0xdd, 0x82, 0xba, 0xef } } - -class nsIDrawingSurfaceMac : public nsISupports -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDRAWING_SURFACE_MAC_IID) - - /** - * Initialize a drawing surface using a Macintosh GrafPtr. - * aPort is not owned by this drawing surface, just used by it. - * @param aPort GrafPtr to initialize drawing surface with - * @return error status - **/ - NS_IMETHOD Init(nsIDrawingSurface* aDS) = 0; - - /** - * Initialize a drawing surface using a Macintosh GrafPtr. - * aPort is not owned by this drawing surface, just used by it. - * @param aPort GrafPtr to initialize drawing surface with - * @return error status - **/ - NS_IMETHOD Init(CGrafPtr aPort) = 0; - - /** - * Initialize a drawing surface using a nsIWidget. - * aTheWidget is not owned by this drawing surface, just used by it. - * @param aTheWidget a nsWidget that contains the GrafPtr and all the data needed - * @return error status - **/ - NS_IMETHOD Init(nsIWidget *aTheWidget) = 0; - - /** - * Create and initialize an offscreen drawing surface - * @param aDepth depth of the offscreen drawing surface - * @param aWidth width of the offscreen drawing surface - * @param aHeight height of the offscren drawing surface - * @param aFlags flags used to control type of drawing surface created - * @return error status - **/ - NS_IMETHOD Init(PRUint32 aDepth, PRUint32 aWidth, PRUint32 aHeight,PRUint32 aFlags) = 0; - - /** - * Get a Macintosh GrafPtr that represents the drawing surface. - * @param aPort out parameter for GrafPtr - * @return error status - **/ - NS_IMETHOD GetGrafPtr(CGrafPtr *aPort) = 0; - - /** - * Quartz helper function. Constructs a Quartz context from the drawing - * surface's QuickDraw port. Must be balanced with a call to - * EndQuartzDrawing(). - * @return Quartz drawing context - **/ - NS_IMETHOD_(CGContextRef) StartQuartzDrawing() = 0; - - /** - * Quartz helper function. Releases Quartz context and resets state of - * drawing surface for QuickDraw calls. Must be called when you are done - * drawing to the Quartz context. - * @param Quartz drawing context returned by StartQuartzDrawing() - **/ - NS_IMETHOD_(void) EndQuartzDrawing(CGContextRef aContext) = 0; - -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIDrawingSurfaceMac, - NS_IDRAWING_SURFACE_MAC_IID) - -#endif // nsIDrawingSurfaceMac_h___ diff --git a/gfx/src/mac/nsIImageMac.h b/gfx/src/mac/nsIImageMac.h deleted file mode 100644 index e3e23ece7fd5..000000000000 --- a/gfx/src/mac/nsIImageMac.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Mike Pinkerton (pinkerton@netscape.com) - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIImageMac_h__ -#define nsIImageMac_h__ - - -#include "nsISupports.h" -#include "nsRect.h" -#include - - -// IID for the nsIImage interface -// {DE2628F9-6023-4443-A4C9-CE0CE6DA0628} -#define NS_IIMAGEMAC_IID \ - { 0xDE2628F9, 0x6023, 0x4443, \ - { 0xA4, 0xC9, 0xCE, 0x0C, 0xE6, 0xDA, 0x06, 0x28 } }; - - -// -// nsIImageMac -// - -// MacOS-specific Interface to Images -// -class nsIImageMac : public nsISupports -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IIMAGEMAC_IID) - - // Convert to the os-native PICT format. Most likely - // used for clipboard. The caller is responsible for - // using ::KillPicture() to dispose of |outPicture| - // when it's done. - NS_IMETHOD ConvertToPICT ( PicHandle* outPicture ) = 0; - - // Convert from the os-native PICT format. Most likely - // used for clipboard. - NS_IMETHOD ConvertFromPICT ( PicHandle inPicture ) = 0; - - // Get the underlying CGImageRef. The object that is returned is - // not retained. - NS_IMETHOD GetCGImageRef(CGImageRef* aCGImageRef) = 0; - -}; // nsIImageMac - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIImageMac, NS_IIMAGEMAC_IID) - -#endif diff --git a/gfx/src/mac/nsImageMac.cpp b/gfx/src/mac/nsImageMac.cpp deleted file mode 100644 index 69a1bd861caa..000000000000 --- a/gfx/src/mac/nsImageMac.cpp +++ /dev/null @@ -1,1067 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsImageMac.h" -#include "nsRenderingContextMac.h" -#include "nsDeviceContextMac.h" -#include "nsRegionPool.h" -#include "prmem.h" - -// Number of bits for each component in a pixel. -#define BITS_PER_COMPONENT 8 -// Number of components per pixel (i.e. as in ARGB). -#define COMPS_PER_PIXEL 4 -// Number of bits in a pixel. -#define BITS_PER_PIXEL BITS_PER_COMPONENT * COMPS_PER_PIXEL - -// MacOSX 10.2 supports CGPattern, which does image/pattern tiling for us, and -// is much faster than doing it ourselves. -#define USE_CGPATTERN_TILING - -#if 0 - -// useful region debugging code. -static OSStatus PrintRgnRectProc(UInt16 message, RgnHandle rgn, const Rect *inRect, void *refCon) -{ - UInt32* rectCount = (UInt32*)refCon; - - switch (message) - { - case kQDRegionToRectsMsgInit: - printf("Dumping region 0x%X\n", rgn); - break; - - case kQDRegionToRectsMsgParse: - printf("Rect %d t,l,r,b: %ld, %ld, %ld, %ld\n", *rectCount, inRect->top, inRect->left, inRect->right, inRect->bottom); - (*rectCount)++; - break; - - case kQDRegionToRectsMsgTerminate: - printf("\n"); - break; - } - - return noErr; -} - -static void PrintRegionOutline(RgnHandle inRgn) -{ - static RegionToRectsUPP sCountRectProc = nsnull; - if (!sCountRectProc) - sCountRectProc = NewRegionToRectsUPP(PrintRgnRectProc); - - UInt32 rectCount = 0; - ::QDRegionToRects(inRgn, kQDParseRegionFromTopLeft, sCountRectProc, &rectCount); -} -#endif - -#pragma mark - - -/********************************************************** - nsImageMac - **********************************************************/ -nsImageMac::nsImageMac() -: mImageBits(nsnull) -, mImage(nsnull) -, mWidth(0) -, mHeight(0) -, mRowBytes(0) -, mBytesPerPixel(0) // this value is never initialized; the API that uses it is unused -, mAlphaBits(nsnull) -, mAlphaRowBytes(0) -, mAlphaDepth(0) -, mPendingUpdate(PR_FALSE) -, mOptimized(PR_FALSE) -, mDecodedX1(PR_INT32_MAX) -, mDecodedY1(PR_INT32_MAX) -, mDecodedX2(0) -, mDecodedY2(0) -{ -} - - -nsImageMac::~nsImageMac() -{ - if (mImage) - ::CGImageRelease(mImage); - - if (mImageBits) - PR_Free(mImageBits); - - if (mAlphaBits) - PR_Free(mAlphaBits); -} - - -NS_IMPL_ISUPPORTS2(nsImageMac, nsIImage, nsIImageMac) - - -nsresult -nsImageMac::Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, - nsMaskRequirements aMaskRequirements) -{ - // Assumed: Init only runs once (due to gfxIImageFrame only allowing 1 Init) - - mWidth = aWidth; - mHeight = aHeight; - - switch (aMaskRequirements) - { - case nsMaskRequirements_kNeeds1Bit: - mAlphaDepth = 1; - break; - - case nsMaskRequirements_kNeeds8Bit: - mAlphaDepth = 8; - break; - - case nsMaskRequirements_kNoMask: - default: - break; // avoid compiler warning - } - - // create the memory for the image - // 24-bit images are 8 bits per component; the alpha component is ignored - mRowBytes = CalculateRowBytes(aWidth, aDepth == 24 ? 32 : aDepth); - mImageBits = (PRUint8*) PR_Malloc(mHeight * mRowBytes * sizeof(PRUint8)); - if (!mImageBits) - return NS_ERROR_OUT_OF_MEMORY; - - if (mAlphaDepth) - { - mAlphaRowBytes = CalculateRowBytes(aWidth, mAlphaDepth); - mAlphaBits = (PRUint8*) PR_Malloc(mHeight * mAlphaRowBytes * sizeof(PRUint8)); - if (!mAlphaBits) { - PR_Free(mImageBits); - mImageBits = nsnull; - return NS_ERROR_OUT_OF_MEMORY; - } - } - - return NS_OK; -} - - -// The image bits (mImageBits & mAlphaBits) have been updated, so set the -// mPendingUpdate flag to force the recreation of CGImageRef later. This is a -// lazy update, as ImageUpdated() can be called several times in a row, but -// we only recreate the CGImageRef when needed. -void -nsImageMac::ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, - nsRect *aUpdateRect) -{ - mPendingUpdate = PR_TRUE; - - mDecodedX1 = PR_MIN(mDecodedX1, aUpdateRect->x); - mDecodedY1 = PR_MIN(mDecodedY1, aUpdateRect->y); - - if (aUpdateRect->YMost() > mDecodedY2) - mDecodedY2 = aUpdateRect->YMost(); - - if (aUpdateRect->XMost() > mDecodedX2) - mDecodedX2 = aUpdateRect->XMost(); -} - -/** --------------------------------------------------- - * See documentation in nsIImage.h - */ -PRBool nsImageMac::GetIsImageComplete() { - return mDecodedX1 == 0 && - mDecodedY1 == 0 && - mDecodedX2 == mWidth && - mDecodedY2 == mHeight; -} - -void DataProviderReleaseFunc(void *info, const void *data, size_t size) -{ - PR_Free(const_cast(data)); -} - - -// Create CGImageRef from image bits. Merge alpha bit into mImageBits, which -// contains "place holder" for the alpha information. Then, create the -// CGImageRef for use in drawing. -nsresult -nsImageMac::EnsureCachedImage() -{ - // Only create cached image if mPendingUpdate is set. - if (!mPendingUpdate) - return NS_OK; - - if (mImage) { - ::CGImageRelease(mImage); - mImage = NULL; - } - - PRUint8* imageData = NULL; // data from which to create CGImage - CGImageAlphaInfo alphaInfo; // alpha info for CGImage - void (*releaseFunc)(void *info, const void *data, size_t size) = NULL; - - switch (mAlphaDepth) - { - case 8: - { - // For 8-bit alpha, we create our own storage, since we premultiply the - // alpha info into the image bits, but we still want to keep the original - // image bits (mImageBits). - imageData = (PRUint8*) PR_Malloc(mWidth * mHeight * COMPS_PER_PIXEL); - if (!imageData) - return NS_ERROR_OUT_OF_MEMORY; - PRUint8* tmp = imageData; - - for (PRInt32 y = 0; y < mHeight; y++) - { - PRInt32 rowStart = mRowBytes * y; - PRInt32 alphaRowStart = mAlphaRowBytes * y; - for (PRInt32 x = 0; x < mWidth; x++) - { - // Here we combine the alpha information with each pixel component, - // creating an image with 'premultiplied alpha'. - PRUint8 alpha = mAlphaBits[alphaRowStart + x]; - *tmp++ = alpha; - PRUint32 offset = rowStart + COMPS_PER_PIXEL * x; - FAST_DIVIDE_BY_255(*tmp++, mImageBits[offset + 1] * alpha); - FAST_DIVIDE_BY_255(*tmp++, mImageBits[offset + 2] * alpha); - FAST_DIVIDE_BY_255(*tmp++, mImageBits[offset + 3] * alpha); - } - } - - // The memory that we pass to the CGDataProvider needs to stick around as - // long as the provider does, and the provider doesn't get destroyed until - // the CGImage is destroyed. So we have this small function which is - // called when the provider is destroyed. - releaseFunc = DataProviderReleaseFunc; - alphaInfo = kCGImageAlphaPremultipliedFirst; - break; - } - - case 1: - { - for (PRInt32 y = 0; y < mHeight; y++) - { - PRInt32 rowStart = mRowBytes * y; - PRUint8* alphaRow = mAlphaBits + mAlphaRowBytes * y; - for (PRInt32 x = 0; x < mWidth; x++) - { - // Copy the alpha information into the place holder in the image data. - mImageBits[rowStart + COMPS_PER_PIXEL * x] = - GetAlphaBit(alphaRow, x) ? 255 : 0; - } - } - - alphaInfo = kCGImageAlphaPremultipliedFirst; - imageData = mImageBits; - break; - } - - case 0: - default: - { - alphaInfo = kCGImageAlphaNoneSkipFirst; - imageData = mImageBits; - break; - } - } - - CGColorSpaceRef cs = ::CGColorSpaceCreateDeviceRGB(); - StColorSpaceReleaser csReleaser(cs); - CGDataProviderRef prov = ::CGDataProviderCreateWithData(NULL, imageData, - mRowBytes * mHeight, - releaseFunc); - mImage = ::CGImageCreate(mWidth, mHeight, BITS_PER_COMPONENT, BITS_PER_PIXEL, - mRowBytes, cs, alphaInfo, prov, NULL, TRUE, - kCGRenderingIntentDefault); - ::CGDataProviderRelease(prov); - - mPendingUpdate = PR_FALSE; - return NS_OK; -} - - -NS_IMETHODIMP -nsImageMac::Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, - PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight) -{ - if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1) - return NS_OK; - - nsresult rv = EnsureCachedImage(); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 srcWidth = aSWidth; - PRInt32 srcHeight = aSHeight; - PRInt32 dstWidth = aDWidth; - PRInt32 dstHeight = aDHeight; - - // Ensure that the source rect is no larger than our decoded rect. - // If it is, clip the source rect, and scale the difference to adjust - // the dest rect. - - PRInt32 j = aSX + aSWidth; - PRInt32 z; - if (j > mDecodedX2) { - z = j - mDecodedX2; - aDWidth -= z*dstWidth/srcWidth; - aSWidth -= z; - } - if (aSX < mDecodedX1) { - aDX += (mDecodedX1 - aSX)*dstWidth/srcWidth; - aSX = mDecodedX1; - } - - j = aSY + aSHeight; - if (j > mDecodedY2) { - z = j - mDecodedY2; - aDHeight -= z*dstHeight/srcHeight; - aSHeight -= z; - } - if (aSY < mDecodedY1) { - aDY += (mDecodedY1 - aSY)*dstHeight/srcHeight; - aSY = mDecodedY1; - } - - if (aDWidth <= 0 || aDHeight <= 0 || aSWidth <= 0 || aSHeight <= 0) - return NS_OK; - - nsDrawingSurfaceMac* surface = static_cast(aSurface); - CGContextRef context = surface->StartQuartzDrawing(); - - CGRect srcRect = ::CGRectMake(aSX, aSY, aSWidth, aSHeight); - CGRect destRect = ::CGRectMake(aDX, aDY, aDWidth, aDHeight); - - CGRect drawRect = ::CGRectMake(0, 0, mWidth, mHeight); - if (!::CGRectEqualToRect(srcRect, destRect)) - { - // If drawing a portion of the image, change the drawRect accordingly. - float sx = ::CGRectGetWidth(destRect) / ::CGRectGetWidth(srcRect); - float sy = ::CGRectGetHeight(destRect) / ::CGRectGetHeight(srcRect); - float dx = ::CGRectGetMinX(destRect) - (::CGRectGetMinX(srcRect) * sx); - float dy = ::CGRectGetMinY(destRect) - (::CGRectGetMinY(srcRect) * sy); - drawRect = ::CGRectMake(dx, dy, mWidth * sx, mHeight * sy); - } - - ::CGContextClipToRect(context, destRect); - ::CGContextDrawImage(context, drawRect, mImage); - surface->EndQuartzDrawing(context); - - return NS_OK; -} - - -NS_IMETHODIMP -nsImageMac::Draw(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aX, PRInt32 aY, - PRInt32 aWidth, PRInt32 aHeight) -{ - - return Draw(aContext, aSurface, 0, 0, mWidth, mHeight, aX, aY, aWidth, aHeight); -} - - -NS_IMETHODIMP -nsImageMac::DrawToImage(nsIImage* aDstImage, PRInt32 aDX, PRInt32 aDY, - PRInt32 aDWidth, PRInt32 aDHeight) -{ - nsImageMac* dest = static_cast(aDstImage); - - nsresult rv = EnsureCachedImage(); - NS_ENSURE_SUCCESS(rv, rv); - rv = dest->EnsureCachedImage(); - NS_ENSURE_SUCCESS(rv, rv); - - rv = NS_ERROR_FAILURE; - - // Create image storage. The storage is 'owned' by the CGImageRef created - // below as 'newImageRef'; that is, the storage cannot be deleted until the - // CGImageRef is released. - PRInt32 width = dest->GetWidth(); - PRInt32 height = dest->GetHeight(); - PRInt32 bytesPerRow = dest->GetLineStride(); - PRInt32 totalBytes = height * bytesPerRow; - PRUint8* bitmap = (PRUint8*) PR_Malloc(totalBytes); - if (!bitmap) - return NS_ERROR_OUT_OF_MEMORY; - - CGColorSpaceRef cs = ::CGColorSpaceCreateDeviceRGB(); - StColorSpaceReleaser csReleaser(cs); - CGContextRef bitmapContext = - ::CGBitmapContextCreate(bitmap, width, height, - BITS_PER_COMPONENT, bytesPerRow, - cs, kCGImageAlphaPremultipliedFirst); - - if (bitmapContext) - { - CGRect destRect = ::CGRectMake(0, 0, width, height); - CGRect drawRect = ::CGRectMake(aDX, aDY, aDWidth, aDHeight); - - // clear the bitmap context - ::CGContextClearRect(bitmapContext, destRect); - - // draw destination and then this image into bitmap - ::CGContextDrawImage(bitmapContext, destRect, dest->mImage); - ::CGContextDrawImage(bitmapContext, drawRect, mImage); - - ::CGContextRelease(bitmapContext); - - CGImageAlphaInfo alphaInfo = ::CGImageGetAlphaInfo(dest->mImage); - - // create a new image from the combined bitmap - CGDataProviderRef prov = ::CGDataProviderCreateWithData(NULL, bitmap, - totalBytes, NULL); - CGImageRef newImageRef = ::CGImageCreate(width, height, BITS_PER_COMPONENT, - BITS_PER_PIXEL, bytesPerRow, cs, - alphaInfo, prov, NULL, TRUE, - kCGRenderingIntentDefault); - if (newImageRef) - { - // set new image in destination - dest->AdoptImage(newImageRef, bitmap); - ::CGImageRelease(newImageRef); - rv = NS_OK; - } - - ::CGDataProviderRelease(prov); - } - - return rv; -} - -void -nsImageMac::AdoptImage(CGImageRef aNewImage, PRUint8* aNewBitmap) -{ - NS_PRECONDITION(aNewImage != nsnull && aNewBitmap != nsnull, - "null ptr"); - if (!aNewImage || !aNewBitmap) - return; - - // Free exising image and image bits. - ::CGImageRelease(mImage); - if (mImageBits) - PR_Free(mImageBits); - - // Adopt given image and image bits. - mImage = aNewImage; - ::CGImageRetain(mImage); - mImageBits = aNewBitmap; -} - - -#pragma mark - - -// Frees up memory from any unneeded structures. -nsresult -nsImageMac::Optimize(nsIDeviceContext* aContext) -{ - nsresult rv = EnsureCachedImage(); - NS_ENSURE_SUCCESS(rv, rv); - - // We cannot delete the bitmap data from which mImage was created; the data - // needs to stick around at least as long as the mImage is valid. - // mImageBits is used by all images, except those that have mAlphaDepth == 8 - // (for which we created a separate data store in EnsureCachedImage). - if (mImageBits && mAlphaDepth == 8) { - PR_Free(mImageBits); - mImageBits = NULL; - } - - // mAlphaBits is not really used any more after EnsureCachedImage is called, - // since it's data is merged into mImageBits. - if (mAlphaBits) { - PR_Free(mAlphaBits); - mAlphaBits = NULL; - } - - mOptimized = PR_TRUE; - - return NS_OK; -} - - -NS_IMETHODIMP -nsImageMac::LockImagePixels(PRBool aMaskPixels) -{ - if (!mOptimized) - return NS_OK; - - // Need to recreate mAlphaBits and/or mImageBits. We do so by drawing the - // CGImage into a bitmap context. Afterwards, 'imageBits' contains the - // image data with premultiplied alpha (if applicable). - PRUint8* imageBits = (PRUint8*) PR_Malloc(mHeight * mRowBytes); - if (!imageBits) - return NS_ERROR_OUT_OF_MEMORY; - CGColorSpaceRef cs = ::CGColorSpaceCreateDeviceRGB(); - StColorSpaceReleaser csReleaser(cs); - CGContextRef bitmapContext = - ::CGBitmapContextCreate(imageBits, mWidth, mHeight, BITS_PER_COMPONENT, - mRowBytes, cs, kCGImageAlphaPremultipliedFirst); - if (!bitmapContext) { - PR_Free(imageBits); - return NS_ERROR_FAILURE; - } - - // clear the bitmap context & draw mImage into it - CGRect drawRect = ::CGRectMake(0, 0, mWidth, mHeight); - ::CGContextClearRect(bitmapContext, drawRect); - ::CGContextDrawImage(bitmapContext, drawRect, mImage); - ::CGContextRelease(bitmapContext); - - // 'imageBits' now contains the image and (possibly) alpha bits for image. - // Now we need to separate them out. - - if (mAlphaDepth) { - // Only need to worry about alpha for mAlphaDepth == 1 or 8. - mAlphaBits = (PRUint8*) PR_Malloc(mHeight * mAlphaRowBytes * - sizeof(PRUint8)); - if (!mAlphaBits) { - PR_Free(imageBits); - return NS_ERROR_OUT_OF_MEMORY; - } - } - - switch (mAlphaDepth) - { - case 8: - { - // Need to recreate mImageBits for mAlphaDepth == 8 only. - // See comments nsImageMac::Optimize(). - PRUint8* tmp = imageBits; - mImageBits = (PRUint8*) PR_Malloc(mHeight * mRowBytes * sizeof(PRUint8)); - if (!mImageBits) { - PR_Free(mAlphaBits); - mAlphaBits = nsnull; - PR_Free(imageBits); - return NS_ERROR_OUT_OF_MEMORY; - } - - // split the alpha bits and image bits into their own structure - for (PRInt32 y = 0; y < mHeight; y++) - { - PRInt32 rowStart = mRowBytes * y; - PRInt32 alphaRowStart = mAlphaRowBytes * y; - for (PRInt32 x = 0; x < mWidth; x++) - { - PRUint8 alpha = *tmp++; - mAlphaBits[alphaRowStart + x] = alpha; - PRUint32 offset = rowStart + COMPS_PER_PIXEL * x; - if (alpha) { - mImageBits[offset + 1] = ((PRUint32) *tmp++) * 255 / alpha; - mImageBits[offset + 2] = ((PRUint32) *tmp++) * 255 / alpha; - mImageBits[offset + 3] = ((PRUint32) *tmp++) * 255 / alpha; - } - else { - tmp += 3; - mImageBits[offset + 1] = - mImageBits[offset + 2] = - mImageBits[offset + 3] = 0; - } - } - } - break; - } - - // mImageBits still exists for mAlphaDepth == 1 or mAlphaDepth == 0, - // since the bits are owned by the CGImageRef. So the only thing to - // do is to recreate the alpha bits for mAlphaDepth == 1. - - case 1: - { - // recreate the alpha bits structure - for (PRInt32 y = 0; y < mHeight; y++) - { - PRInt32 rowStart = mRowBytes * y; - PRUint8* alphaRow = mAlphaBits + mAlphaRowBytes * y; - for (PRInt32 x = 0; x < mWidth; x++) - { - if (imageBits[rowStart + COMPS_PER_PIXEL * x]) - SetAlphaBit(alphaRow, x); - else - ClearAlphaBit(alphaRow, x); - } - } - } - - case 0: - default: - break; - } - - PR_Free(imageBits); - return NS_OK; -} - - -NS_IMETHODIMP -nsImageMac::UnlockImagePixels(PRBool aMaskPixels) -{ - if (mOptimized) - Optimize(nsnull); - - return NS_OK; -} - - -#pragma mark - - -/** --------------------------------------------------- - * Calculate rowBytes, making sure that it comes out as - * a multiple of 4. ( 32 / 4 == 8). If you pass true for - * aAllow2Bytes then, for small images (aWidth * aDepth =< 24), you - * get a result which can be a multiple of 2 instead. - * Some parts of the toolbox require this, notably the native icon creation - * code. This is worth experimenting with if you deal with masks of 16x16 icons - * which are frequently 1 bit and thus are considered "small" by this function. - * - * CAUTION: MacOS X is extremely intolerant of divisible by 2 widths. You should never - * pass a PixMap to the OS for drawing with PixMap.rowBytes set to anything other than - * a multiple of 4 on Mac OS X. (CopyBits seems to be OK with divisible by 2 rowbytes, - * at least for the icon code in this class). That's why this function is private and - * wrapped. - * - * See - */ -PRInt32 nsImageMac::CalculateRowBytesInternal(PRUint32 aWidth, PRUint32 aDepth, PRBool aAllow2Bytes) -{ - PRInt32 rowBits = aWidth * aDepth; - //if bits per row is 24 or less, may need 3 bytes or less - return (rowBits > 24 || !aAllow2Bytes) ? - ((aWidth * aDepth + 31) / 32) * 4 : - ((aWidth * aDepth + 15) / 16) * 2; -} - - -/** Protected CalculateRowBytes. Most functions should call this - Requires rowBytes to be a multiple of 4 - @see CalculateRowBytesInternal - */ -PRInt32 nsImageMac::CalculateRowBytes(PRUint32 aWidth, PRUint32 aDepth) -{ - return CalculateRowBytesInternal(aWidth, aDepth, PR_FALSE); -} - - -PRBool nsImageMac::RenderingToPrinter(nsIRenderingContext &aContext) -{ - nsCOMPtr dc; // (this screams for a private interface, sigh!) - aContext.GetDeviceContext(*getter_AddRefs(dc)); - // a weird and wonderful world of scanky casts and oddly-named intefaces. - nsDeviceContextMac* theDevContext = reinterpret_cast(dc.get()); - return theDevContext && theDevContext->IsPrinter(); -} - - -#pragma mark - - -// -// ConvertToPICT -// -// Convert from image bits to a PICT, probably for placement on the clipboard. -// Draw the image into a temporary GWorld, and then blit it into the picture. -// -// XXX TODO In the future, clipboard operations should be converted to using -// the Pasteboard Manager. Then we could simply write our image to a PDF -// context and put that on the clipboard. -// -NS_IMETHODIMP -nsImageMac::ConvertToPICT(PicHandle* outPicture) -{ - *outPicture = nsnull; - Rect picFrame = {0, 0, mHeight, mWidth}; - - PRUint32 pixelDepth = ::CGImageGetBitsPerPixel(mImage); - - // allocate a "normal" GWorld (which owns its own pixels) - GWorldPtr tempGWorld = NULL; - ::NewGWorld(&tempGWorld, pixelDepth, &picFrame, nsnull, nsnull, 0); - if (!tempGWorld) - return NS_ERROR_FAILURE; - - PixMapHandle tempPixMap = ::GetGWorldPixMap(tempGWorld); - if (tempPixMap) - { - StPixelLocker tempPixLocker(tempPixMap); // locks the pixels - - // erase it to white - { - StGWorldPortSetter setter(tempGWorld); - ::BackColor(whiteColor); - ::EraseRect(&picFrame); - } - - // set as current GWorld - GWorldPtr currPort; - GDHandle currDev; - ::GetGWorld(&currPort, &currDev); - ::SetGWorld(tempGWorld, nsnull); - - ::SetOrigin(0, 0); - ::ForeColor(blackColor); - ::BackColor(whiteColor); - - // Get the storage addr for the GWorld and create a bitmap context from it. - // Then we simply call CGContextDrawImage to draw our image into the GWorld. - // NOTE: The width of the created context must be a multiple of 4. - PRUint8* bitmap = (PRUint8*) ::GetPixBaseAddr(tempPixMap); - - PRUint32 bytesPerPixel = ::CGImageGetBitsPerPixel(mImage) / 8; - PRUint32 bitmapWidth = (mWidth + 4) & ~0x3; - PRUint32 bitmapRowBytes = bitmapWidth * bytesPerPixel; - - CGColorSpaceRef cs = ::CGColorSpaceCreateDeviceRGB(); - StColorSpaceReleaser csReleaser(cs); - CGContextRef bitmapContext = - ::CGBitmapContextCreate(bitmap, bitmapWidth, mHeight, - BITS_PER_COMPONENT, - bitmapRowBytes, cs, - kCGImageAlphaPremultipliedFirst); - - NS_ASSERTION(bitmapContext, "Failed to create bitmap context"); - - if (bitmapContext) - { - // Translate to QuickDraw coordinate system - ::CGContextTranslateCTM(bitmapContext, 0, mHeight); - ::CGContextScaleCTM(bitmapContext, 1, -1); - - // Draw image into GWorld - CGRect drawRect = ::CGRectMake(0, 0, mWidth, mHeight); - ::CGContextDrawImage(bitmapContext, drawRect, mImage); - ::CGContextRelease(bitmapContext); - - PicHandle thePicture = ::OpenPicture(&picFrame); - if (thePicture) - { - // blit image from GWorld into Picture - ::CopyBits(::GetPortBitMapForCopyBits(tempGWorld), - ::GetPortBitMapForCopyBits(tempGWorld), - &picFrame, &picFrame, ditherCopy, nsnull); - - ::ClosePicture(); - if (QDError() == noErr) - *outPicture = thePicture; - } - } - - ::SetGWorld(currPort, currDev); // restore to the way things were - } - - ::DisposeGWorld(tempGWorld); // do this after dtor of tempPixLocker! - - return *outPicture ? NS_OK : NS_ERROR_FAILURE; -} - - -NS_IMETHODIMP -nsImageMac::ConvertFromPICT(PicHandle inPicture) -{ - NS_WARNING("ConvertFromPICT is not implemented."); - return NS_ERROR_NOT_IMPLEMENTED; -} - - -NS_IMETHODIMP -nsImageMac::GetCGImageRef(CGImageRef* aCGImageRef) -{ - nsresult rv = EnsureCachedImage(); - if (NS_FAILED(rv)) return rv; - - *aCGImageRef = mImage; - return NS_OK; -} - - -#pragma mark - - -nsresult -nsImageMac::SlowTile(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, const nsRect &aTileRect) -{ - PRInt32 - validX = 0, - validY = 0, - validWidth = mWidth, - validHeight = mHeight; - - // limit the image rectangle to the size of the image data which - // has been validated. - if (mDecodedY2 < mHeight) { - validHeight = mDecodedY2 - mDecodedY1; - } - if (mDecodedX2 < mWidth) { - validWidth = mDecodedX2 - mDecodedX1; - } - if (mDecodedY1 > 0) { - validHeight -= mDecodedY1; - validY = mDecodedY1; - } - if (mDecodedX1 > 0) { - validWidth -= mDecodedX1; - validX = mDecodedX1; - } - - PRInt32 aY0 = aTileRect.y - aSYOffset, - aX0 = aTileRect.x - aSXOffset, - aY1 = aTileRect.y + aTileRect.height, - aX1 = aTileRect.x + aTileRect.width; - - for (PRInt32 y = aY0; y < aY1; y += mHeight + aPadY) - for (PRInt32 x = aX0; x < aX1; x += mWidth + aPadX) - { - Draw(aContext, aSurface, - 0, 0, PR_MIN(validWidth, aX1-x), PR_MIN(validHeight, aY1-y), // src coords - x, y, PR_MIN(validWidth, aX1-x), PR_MIN(validHeight, aY1-y)); // dest coords - } - - return NS_OK; -} - - -nsresult -nsImageMac::DrawTileQuickly(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - const nsRect &aTileRect) -{ - CGColorSpaceRef cs = ::CGColorSpaceCreateDeviceRGB(); - StColorSpaceReleaser csReleaser(cs); - - PRUint32 tiledCols = (aTileRect.width + aSXOffset + mWidth - 1) / mWidth; - PRUint32 tiledRows = (aTileRect.height + aSYOffset + mHeight - 1) / mHeight; - - // XXX note that this code tiles the entire image, even when we just - // need a small portion, which can get expensive - PRUint32 bitmapWidth = tiledCols * mWidth; - PRUint32 bitmapHeight = tiledRows * mHeight; - PRUint32 bitmapRowBytes = tiledCols * mRowBytes; - PRUint32 totalBytes = bitmapHeight * bitmapRowBytes; - PRUint8* bitmap = (PRUint8*) PR_Malloc(totalBytes); - if (!bitmap) - return NS_ERROR_OUT_OF_MEMORY; - - CGContextRef bitmapContext; - bitmapContext = ::CGBitmapContextCreate(bitmap, bitmapWidth, bitmapHeight, - BITS_PER_COMPONENT, bitmapRowBytes, - cs, kCGImageAlphaPremultipliedFirst); - - if (bitmapContext != NULL) - { - // clear the bitmap context - ::CGContextClearRect(bitmapContext, - ::CGRectMake(0, 0, bitmapWidth, bitmapHeight)); - - // prime bitmap with initial tile draw - // Draw image into 'bottom' of bitmap, to make the calculations in the - // following for loops somewhat simpler. - CGRect drawRect = ::CGRectMake(0, bitmapHeight - mHeight, mWidth, mHeight); - ::CGContextDrawImage(bitmapContext, drawRect, mImage); - ::CGContextRelease(bitmapContext); - - // Manually blit image, doubling each time. - // Quartz does not provide any functions for blitting from a context to a - // context, so rather than create a CFImageRef each time through the loop - // in order to blit it to the context, we just do it manually. - PRUint32 tileHeight = mHeight; - for (PRUint32 destCol = 1; destCol < tiledCols; destCol *= 2) - { - PRUint8* srcLine = bitmap; - PRUint32 bytesToCopy = destCol * mRowBytes; - PRUint8* destLine = srcLine + bytesToCopy; - if (destCol * 2 > tiledCols) - { - bytesToCopy = (tiledCols - destCol) * mRowBytes; - } - for (PRUint32 row = 0; row < tileHeight; row++) - { - memcpy(destLine, srcLine, bytesToCopy); - srcLine += bitmapRowBytes; - destLine += bitmapRowBytes; - } - } - - for (PRUint32 destRow = 1; destRow < tiledRows; destRow *= 2) - { - PRUint32 tileRowBytes = mHeight * bitmapRowBytes; - PRUint32 bytesToCopy = destRow * tileRowBytes; - PRUint8* dest = bitmap + bytesToCopy; - if (destRow * 2 > tiledRows) - { - bytesToCopy = (tiledRows - destRow) * tileRowBytes; - } - memcpy(dest, bitmap, bytesToCopy); - } - - // Create final tiled image from bitmap - CGDataProviderRef prov = ::CGDataProviderCreateWithData(NULL, bitmap, - totalBytes, NULL); - CGImageRef tiledImage = ::CGImageCreate(bitmapWidth, bitmapHeight, - BITS_PER_COMPONENT, BITS_PER_PIXEL, - bitmapRowBytes, cs, - kCGImageAlphaPremultipliedFirst, - prov, NULL, TRUE, - kCGRenderingIntentDefault); - ::CGDataProviderRelease(prov); - - nsDrawingSurfaceMac* surface = static_cast(aSurface); - CGContextRef context = surface->StartQuartzDrawing(); - - CGRect srcRect = ::CGRectMake(aSXOffset, aSYOffset, aTileRect.width, - aTileRect.height); - CGRect destRect = ::CGRectMake(aTileRect.x, aTileRect.y, aTileRect.width, - aTileRect.height); - - drawRect = ::CGRectMake(0, 0, bitmapWidth, bitmapHeight); - if (!::CGRectEqualToRect(srcRect, destRect)) - { - // If drawing a portion of the image, change the drawRect accordingly. - float sx = ::CGRectGetWidth(destRect) / ::CGRectGetWidth(srcRect); - float sy = ::CGRectGetHeight(destRect) / ::CGRectGetHeight(srcRect); - float dx = ::CGRectGetMinX(destRect) - (::CGRectGetMinX(srcRect) * sx); - float dy = ::CGRectGetMinY(destRect) - (::CGRectGetMinY(srcRect) * sy); - drawRect = ::CGRectMake(dx, dy, bitmapWidth * sx, bitmapHeight * sy); - } - - ::CGContextClipToRect(context, destRect); - ::CGContextDrawImage(context, drawRect, tiledImage); - - ::CGImageRelease(tiledImage); - surface->EndQuartzDrawing(context); - } - - PR_Free(bitmap); - - return NS_OK; -} - -void -DrawTileAsPattern(void *aInfo, CGContextRef aContext) -{ - CGImageRef image = static_cast (aInfo); - - float width = ::CGImageGetWidth(image); - float height = ::CGImageGetHeight(image); - CGRect drawRect = ::CGRectMake(0, 0, width, height); - ::CGContextDrawImage(aContext, drawRect, image); -} - -nsresult -nsImageMac::DrawTileWithQuartz(nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, - const nsRect &aTileRect) -{ - nsDrawingSurfaceMac* surface = static_cast(aSurface); - CGContextRef context = surface->StartQuartzDrawing(); - ::CGContextSaveGState(context); - - static const CGPatternCallbacks callbacks = {0, &DrawTileAsPattern, NULL}; - - // get the current transform from the context - CGAffineTransform patternTrans = CGContextGetCTM(context); - patternTrans = CGAffineTransformTranslate(patternTrans, aTileRect.x, aTileRect.y); - - CGPatternRef pattern; - pattern = ::CGPatternCreate(mImage, ::CGRectMake(0, 0, mWidth, mHeight), - patternTrans, mWidth + aPadX, mHeight + aPadY, - kCGPatternTilingConstantSpacing, - TRUE, &callbacks); - - CGColorSpaceRef patternSpace = ::CGColorSpaceCreatePattern(NULL); - ::CGContextSetFillColorSpace(context, patternSpace); - ::CGColorSpaceRelease(patternSpace); - - float alpha = 1.0f; - ::CGContextSetFillPattern(context, pattern, &alpha); - ::CGPatternRelease(pattern); - - // set the pattern phase (really -ve x and y offsets, but we negate - // the y offset again to take flipping into account) - ::CGContextSetPatternPhase(context, CGSizeMake(-aSXOffset, aSYOffset)); - - CGRect tileRect = ::CGRectMake(aTileRect.x, - aTileRect.y, - aTileRect.width, - aTileRect.height); - - ::CGContextFillRect(context, tileRect); - - ::CGContextRestoreGState(context); - surface->EndQuartzDrawing(context); - return NS_OK; -} - - -NS_IMETHODIMP nsImageMac::DrawTile(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, - const nsRect &aTileRect) -{ - nsresult rv = EnsureCachedImage(); - NS_ENSURE_SUCCESS(rv, rv); - - if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1) - return NS_OK; - - PRUint32 tiledCols = (aTileRect.width + aSXOffset + mWidth - 1) / mWidth; - PRUint32 tiledRows = (aTileRect.height + aSYOffset + mHeight - 1) / mHeight; - - // The tiling that we do below can be expensive for large background - // images, for which we have few tiles. Plus, the SlowTile call eventually - // calls the Quartz drawing functions, which can take advantage of hardware - // acceleration. So if we have few tiles, we just call SlowTile. -#ifdef USE_CGPATTERN_TILING - const PRUint32 kTilingCopyThreshold = 16; // CG tiling is so much more efficient -#else - const PRUint32 kTilingCopyThreshold = 64; -#endif - if (tiledCols * tiledRows < kTilingCopyThreshold) - return SlowTile(aContext, aSurface, aSXOffset, aSYOffset, 0, 0, aTileRect); - -#ifdef USE_CGPATTERN_TILING - rv = DrawTileWithQuartz(aSurface, aSXOffset, aSYOffset, aPadX, aPadY, aTileRect); -#else - // use the manual methods of tiling - if (!aPadX && !aPadY) - rv = DrawTileQuickly(aContext, aSurface, aSXOffset, aSYOffset, aTileRect); - else - rv = SlowTile(aContext, aSurface, aSXOffset, aSYOffset, aPadX, aPadY, aTileRect); -#endif /* USE_CGPATTERN_TILING */ - - return rv; -} diff --git a/gfx/src/mac/nsImageMac.h b/gfx/src/mac/nsImageMac.h deleted file mode 100644 index deeece84c335..000000000000 --- a/gfx/src/mac/nsImageMac.h +++ /dev/null @@ -1,187 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsImageMac_h___ -#define nsImageMac_h___ - -#include "nsIImage.h" -#include "nsIImageMac.h" - -class nsImageMac : public nsIImage, public nsIImageMac -{ -public: - nsImageMac(); - virtual ~nsImageMac(); - - NS_DECL_ISUPPORTS - - /** - @see nsIImage.h - */ - virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements); - virtual PRInt32 GetBytesPix() { return mBytesPerPixel; } // this is unused - virtual PRBool GetIsRowOrderTopToBottom() { return PR_FALSE; } - - virtual PRInt32 GetWidth() { return mWidth; } - virtual PRInt32 GetHeight() { return mHeight; } - - virtual PRUint8* GetBits() { return mImageBits; } - virtual PRInt32 GetLineStride() { return mRowBytes; } - virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; } - - virtual PRUint8* GetAlphaBits() { return mAlphaBits; } - virtual PRInt32 GetAlphaLineStride() { return mAlphaRowBytes; } - - // Called when an image decoder updates the image bits (mImageBits & - // mAlphaBits). 'aFlags' is ignored. - virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, - nsRect *aUpdateRect); - virtual PRBool GetIsImageComplete(); - - // Optimizes memory usage for object. - virtual nsresult Optimize(nsIDeviceContext* aContext); - - virtual nsColorMap* GetColorMap() { return nsnull; } - - NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, - PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - - NS_IMETHOD Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, - PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight); - - NS_IMETHOD DrawTile(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, - const nsRect &aTileRect); - - - /** - * Get the alpha depth for the image mask - * @update - lordpixel 2001/05/16 - * @return the alpha mask depth for the image, ie, 0, 1 or 8 - */ - virtual PRInt8 GetAlphaDepth() { return mAlphaDepth; } - - NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY, - nscoord aDWidth, nscoord aDHeight); - - virtual void* GetBitInfo() { return nsnull; } - - NS_IMETHOD LockImagePixels(PRBool aMaskPixels); - NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels); - - - // Convert to and from the os-native PICT format. Most likely - // used for clipboard. - NS_IMETHOD ConvertToPICT(PicHandle* outPicture); - NS_IMETHOD ConvertFromPICT(PicHandle inPicture); - - NS_IMETHOD GetCGImageRef(CGImageRef* aCGImageRef); - -protected: - - nsresult SlowTile(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, - const nsRect &aTileRect); - - nsresult DrawTileQuickly(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - const nsRect &aTileRect); - - nsresult DrawTileWithQuartz(nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, - const nsRect &aTileRect); - - static PRInt32 CalculateRowBytes(PRUint32 aWidth, PRUint32 aDepth); - - inline static PRInt32 CalculateRowBytesInternal(PRUint32 aWidth, - PRUint32 aDepth, - PRBool aAllow2Bytes); - - static PRBool RenderingToPrinter(nsIRenderingContext &aContext); - - // Recreate internal image structure from updated image bits. - nsresult EnsureCachedImage(); - - // Get/Set/Clear alpha bit at position 'x' in the row pointed to by 'rowptr'. - inline PRUint8 GetAlphaBit(PRUint8* rowptr, PRUint32 x) { - return (rowptr[x >> 3] & (1 << (7 - x & 0x7))); - } - inline void SetAlphaBit(PRUint8* rowptr, PRUint32 x) { - rowptr[x >> 3] |= (1 << (7 - x & 0x7)); - } - inline void ClearAlphaBit(PRUint8* rowptr, PRUint32 x) { - rowptr[x >> 3] &= ~(1 << (7 - x & 0x7)); - } - - // Takes ownership of the given image and bitmap. The CGImageRef is retained. - void AdoptImage(CGImageRef aNewImage, PRUint8* aNewBitamp); - -private: - - PRUint8* mImageBits; // malloc'd block - CGImageRef mImage; - - PRInt32 mWidth; - PRInt32 mHeight; - - PRInt32 mRowBytes; - PRInt32 mBytesPerPixel; - - // alpha layer members - PRUint8* mAlphaBits; // malloc'd block - - PRInt32 mAlphaRowBytes; // alpha row bytes - PRInt8 mAlphaDepth; // alpha layer depth - - PRPackedBool mPendingUpdate; // true when we need to recreate CGImageRef - PRPackedBool mOptimized; // true when nsImage object has been - // optimized (see |Optimize()|) - - PRInt32 mDecodedX1; // Keeps track of what part of image - PRInt32 mDecodedY1; // has been decoded. - PRInt32 mDecodedX2; - PRInt32 mDecodedY2; -}; - -#endif diff --git a/gfx/src/mac/nsMacGFX.rsrc b/gfx/src/mac/nsMacGFX.rsrc deleted file mode 100644 index 167ea8c6a413..000000000000 Binary files a/gfx/src/mac/nsMacGFX.rsrc and /dev/null differ diff --git a/gfx/src/mac/nsMacResources.cpp b/gfx/src/mac/nsMacResources.cpp deleted file mode 100644 index 48afb020d46e..000000000000 --- a/gfx/src/mac/nsMacResources.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsMacResources.h" -#include -#include - - -short nsMacResources::mRefNum = kResFileNotOpened; -short nsMacResources::mSaveResFile = 0; - -pascal OSErr __NSInitialize(const CFragInitBlock *theInitBlock); -pascal OSErr __initializeResources(const CFragInitBlock *theInitBlock); - -pascal void __NSTerminate(void); -pascal void __terminateResources(void); - -//---------------------------------------------------------------------------------------- -// -//---------------------------------------------------------------------------------------- -pascal OSErr __initializeResources(const CFragInitBlock *theInitBlock) -{ - OSErr err = __NSInitialize(theInitBlock); - if (err) - return err; - - short saveResFile = ::CurResFile(); - - short refNum = FSpOpenResFile(theInitBlock->fragLocator.u.onDisk.fileSpec, fsRdPerm); - nsMacResources::SetLocalResourceFile(refNum); - - ::UseResFile(saveResFile); - - return ::ResError(); -} - - -//---------------------------------------------------------------------------------------- -// -//---------------------------------------------------------------------------------------- -pascal void __terminateResources(void) -{ - ::CloseResFile(nsMacResources::GetLocalResourceFile()); - __NSTerminate(); -} - -//---------------------------------------------------------------------------------------- -// -//---------------------------------------------------------------------------------------- - -nsresult nsMacResources::OpenLocalResourceFile() -{ - if (mRefNum == kResFileNotOpened) - return NS_ERROR_NOT_INITIALIZED; - - mSaveResFile = ::CurResFile(); - ::UseResFile(mRefNum); - - return (::ResError() == noErr ? NS_OK : NS_ERROR_FAILURE); -} - - -//---------------------------------------------------------------------------------------- -// -//---------------------------------------------------------------------------------------- - -nsresult nsMacResources::CloseLocalResourceFile() -{ - if (mRefNum == kResFileNotOpened) - return NS_ERROR_NOT_INITIALIZED; - - ::UseResFile(mSaveResFile); - - return (::ResError() == noErr ? NS_OK : NS_ERROR_FAILURE); -} - diff --git a/gfx/src/mac/nsMacResources.h b/gfx/src/mac/nsMacResources.h deleted file mode 100644 index 80b3fed0bd40..000000000000 --- a/gfx/src/mac/nsMacResources.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsMacResources_h__ -#define nsMacResources_h__ - -#include "nsError.h" - -class nsMacResources -{ -public: - static nsresult OpenLocalResourceFile(); - static nsresult CloseLocalResourceFile(); - - // you shouldn't have to use these: - static void SetLocalResourceFile(short aRefNum) {mRefNum = aRefNum;} - static short GetLocalResourceFile() {return mRefNum;} - -private: - static short mRefNum; - static short mSaveResFile; -}; - -#endif //nsMacResources_h__ - diff --git a/gfx/src/mac/nsMacUnicodeFontInfo.cpp b/gfx/src/mac/nsMacUnicodeFontInfo.cpp deleted file mode 100644 index b4120237b783..000000000000 --- a/gfx/src/mac/nsMacUnicodeFontInfo.cpp +++ /dev/null @@ -1,624 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Frank Yung-Fong Tang - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsMacUnicodeFontInfo.h" -#include "nsCRT.h" -#include "prmem.h" -#include - -//#define DEBUG_TRUE_TYPE -#include "nsICharRepresentable.h" -#include "nsCompressedCharMap.h" -#include "nsIObserver.h" -#include "nsIObserverService.h" -#include "nsIServiceManager.h" -#include "nsDependentString.h" -#include "nsLiteralString.h" -#include "nsDeviceContextMac.h" -#include "nsICharsetConverterManager.h" -#include "nsIPersistentProperties2.h" -#include "nsNetUtil.h" -#include "nsHashtable.h" -#include -#include -#include - -//#define TRACK_INIT_PERFORMANCE - -#ifdef TRACK_INIT_PERFORMANCE -#include -#endif - -class nsFontCleanupObserver : public nsIObserver { -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER - - nsFontCleanupObserver() { } - virtual ~nsFontCleanupObserver() {} -}; - -NS_IMPL_ISUPPORTS1(nsFontCleanupObserver, nsIObserver) - -NS_IMETHODIMP nsFontCleanupObserver::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData) -{ - if (! nsCRT::strcmp(NS_XPCOM_SHUTDOWN_OBSERVER_ID,aTopic)) - { - nsMacUnicodeFontInfo::FreeGlobals(); - } - return NS_OK; -} - -static nsIPersistentProperties* gFontEncodingProperties = nsnull; -static nsICharsetConverterManager* gCharsetManager = nsnull; -static nsObjectHashtable* gFontMaps = nsnull; -static nsFontCleanupObserver *gFontCleanupObserver = nsnull; -static PRUint16* gCCMap = nsnull; - - -#ifdef IS_BIG_ENDIAN -# undef GET_SHORT -# define GET_SHORT(p) (*((PRUint16*)p)) -# undef GET_LONG -# define GET_LONG(p) (*((PRUint32*)p)) -#else -# ifdef IS_LITTLE_ENDIAN -# undef GET_SHORT -# define GET_SHORT(p) (((p)[0] << 8) | (p)[1]) -# undef GET_LONG -# define GET_LONG(p) (((p)[0] << 24) | ((p)[1] << 16) | ((p)[2] << 8) | (p)[3]) -# endif -#endif - -// The following should be defined in ATSTypes.h, but they ar not -enum { - kFMOpenTypeFontTechnology = FOUR_CHAR_CODE('OTTO') -}; - -// The following should be defined in SNFTTypes.h, but they ar not -enum { - headFontTableTag = FOUR_CHAR_CODE('head'), - locaFontTableTag = FOUR_CHAR_CODE('loca') -}; - -#define ADD_GLYPH(a,b) SET_REPRESENTABLE(a,b) -#define FONT_HAS_GLYPH(a,b) IS_REPRESENTABLE(a,b) - -#undef SET_SPACE -#define SET_SPACE(c) ADD_GLYPH(spaces, c) -#undef SHOULD_BE_SPACE -#define SHOULD_BE_SPACE(c) FONT_HAS_GLYPH(spaces, c) - -static PRInt8 -GetIndexToLocFormat(FMFont aFont) -{ - PRUint16 indexToLocFormat; - ByteCount len = 0; - OSStatus err = ::FMGetFontTable(aFont, headFontTableTag, 50, 2, &indexToLocFormat, nsnull); - if (err != noErr) - return -1; - - if (!indexToLocFormat) - return 0; - - return 1; -} - -static PRUint8* -GetSpaces(FMFont aFont, PRUint32* aMaxGlyph) -{ - PRInt8 isLong = GetIndexToLocFormat(aFont); - if (isLong < 0) - return nsnull; - - ByteCount len = 0; - OSStatus err = ::FMGetFontTable(aFont, locaFontTableTag, 0, 0, NULL, &len); - - if ((err != noErr) || (!len)) - return nsnull; - - PRUint8* buf = (PRUint8*) nsMemory::Alloc(len); - NS_ASSERTION(buf, "cannot read 'loca' table because out of memory"); - if (!buf) - return nsnull; - - ByteCount newLen = 0; - err = ::FMGetFontTable(aFont, locaFontTableTag, 0, len, buf, &newLen); - NS_ASSERTION((newLen == len), "cannot read 'loca' table from the font"); - - if (newLen != len) - { - nsMemory::Free(buf); - return nsnull; - } - - if (isLong) - { - PRUint32 longLen = ((len / 4) - 1); - *aMaxGlyph = longLen; - PRUint32* longBuf = (PRUint32*) buf; - for (PRUint32 i = 0; i < longLen; i++) - { - if (longBuf[i] == longBuf[i+1]) - buf[i] = 1; - else - buf[i] = 0; - } - } - else - { - PRUint32 shortLen = ((len / 2) - 1); - *aMaxGlyph = shortLen; - PRUint16* shortBuf = (PRUint16*) buf; - for (PRUint16 i = 0; i < shortLen; i++) - { - if (shortBuf[i] == shortBuf[i+1]) - buf[i] = 1; - else - buf[i] = 0; - } - } - - return buf; -} - -static int spacesInitialized = 0; -static PRUint32 spaces[2048]; -static void InitSpace() -{ - if (!spacesInitialized) - { - spacesInitialized = 1; - SET_SPACE(0x0020); - SET_SPACE(0x00A0); - for (PRUint16 c = 0x2000; c <= 0x200B; c++) - SET_SPACE(c); - SET_SPACE(0x3000); - } -} - -static void HandleFormat4(PRUint16* aEntry, PRUint8* aEnd, - PRUint8* aIsSpace, PRUint32 aMaxGlyph, - PRUint32* aFontInfo) -{ - // notice aIsSpace could be nsnull in case of OpenType font - PRUint8* end = aEnd; - PRUint16* s = aEntry; - PRUint16 segCount = CFSwapInt16BigToHost(s[3]) / 2; - PRUint16* endCode = &s[7]; - PRUint16* startCode = endCode + segCount + 1; - PRUint16* idDelta = startCode + segCount; - PRUint16* idRangeOffset = idDelta + segCount; - PRUint16* glyphIdArray = idRangeOffset + segCount; - - PRUint16 i; - InitSpace(); - - for (i = 0; i < segCount; i++) - { - if (idRangeOffset[i]) - { - PRUint16 startC = CFSwapInt16BigToHost(startCode[i]); - PRUint16 endC = CFSwapInt16BigToHost(endCode[i]); - for (PRUint32 c = startC; c <= endC; c++) - { - PRUint16* g = (CFSwapInt16BigToHost(idRangeOffset[i])/2 + (c - startC) + &idRangeOffset[i]); - if ((PRUint8*) g < end) - { - if (*g) - { - PRUint16 glyph = CFSwapInt16BigToHost(idDelta[i]) + *g; - if (glyph < aMaxGlyph) - { - if (aIsSpace && aIsSpace[glyph]) - { - if (SHOULD_BE_SPACE(c)) - ADD_GLYPH(aFontInfo, c); - } - else - { - ADD_GLYPH(aFontInfo, c); - } - } - } - } - else - { - // XXX should we trust this font at all if it does this? - } - } - } - else - { - PRUint16 endC = CFSwapInt16BigToHost(endCode[i]); - for (PRUint32 c = CFSwapInt16BigToHost(startCode[i]); c <= endC; c++) - { - PRUint16 glyph = CFSwapInt16BigToHost(idDelta[i]) + c; - if (glyph < aMaxGlyph) - { - if (aIsSpace && aIsSpace[glyph]) - { - if (SHOULD_BE_SPACE(c)) - ADD_GLYPH(aFontInfo, c); - } - else - { - ADD_GLYPH(aFontInfo, c); - } - } - } - } - } -} -static PRBool FillFontInfoFromCMAP(FMFont aFont, PRUint32 *aFontInfo, FourCharCode aFontFormat) -{ - ByteCount len; - OSErr err = ::FMGetFontTable(aFont, cmapFontTableTag, 0, 0, NULL, &len); - if((err!=noErr) || (!len)) - return PR_FALSE; - - PRUint8* buf = (PRUint8*) nsMemory::Alloc(len); - NS_ASSERTION(buf, "cannot read cmap because out of memory"); - if (!buf) - return PR_FALSE; - - ByteCount newLen; - err = ::FMGetFontTable(aFont, cmapFontTableTag, 0, len, buf, &newLen); - NS_ASSERTION(newLen == len, "cannot read cmap from the font"); - if (newLen != len) - { - nsMemory::Free(buf); - return PR_FALSE; - } - - PRUint8* p = buf + sizeof(PRUint16); // skip version, move to numberSubtables - PRUint16 n = GET_SHORT(p); // get numberSubtables - p += sizeof(PRUint16); // skip numberSubtables, move to the encoding subtables - - PRUint16 i; - PRUint32 offset; - PRUint32 platformUnicodeOffset = 0; - // we look for platform =3 and encoding =1, - // if we cannot find it but there are a platform = 0 there, we - // remmeber that one and use it. - - for (i = 0; i < n; i++) - { - PRUint16 platformID = GET_SHORT(p); // get platformID - p += sizeof(PRUint16); // move to platformSpecificID - PRUint16 encodingID = GET_SHORT(p); // get platformSpecificID - p += sizeof(PRUint16); // move to offset - offset = GET_LONG(p); // get offset - p += sizeof(PRUint32); // move to next entry -#ifdef DEBUG_TRUE_TYPE - printf("p=%d e=%d offset=%x\n", platformID, encodingID, offset); -#endif - if (platformID == kFontMicrosoftPlatform) - { - if (encodingID == kFontMicrosoftStandardScript) - { // Unicode - // Some fonts claim to be unicode when they are actually - // 'pseudo-unicode' fonts that require a converter... - break; // break out from for(;;) loop - } //if (encodingID == kFontMicrosoftStandardScript) -#if 0 - // if we have other encoding, we can still handle it, so... don't return this early - else if (encodingID == kFontMicrosoftSymbolScript) - { // symbol - NS_ASSERTION(false, "cannot handle symbol font"); - nsMemory::Free(buf); - return PR_FALSE; - } -#endif - } // if (platformID == kFontMicrosoftPlatform) - else { - if (platformID == kFontUnicodePlatform) - { // Unicode - platformUnicodeOffset = offset; - } - } - } // for loop - - NS_ASSERTION((i != n) || ( 0 != platformUnicodeOffset), "do not know the TrueType encoding"); - if ((i == n) && ( 0 == platformUnicodeOffset)) - { - nsMemory::Free(buf); - return PR_FALSE; - } - - // usually, we come here for the entry platform = 3 encoding = 1 - // or if we don't have it but we have a platform = 0 (platformUnicodeOffset != 0) - if(platformUnicodeOffset) - offset = platformUnicodeOffset; - - p = buf + offset; - PRUint16 format = GET_SHORT(p); - NS_ASSERTION((kSFNTLookupSegmentArray == format), "hit some unknown format"); - switch(format) { - case kSFNTLookupSegmentArray: // format 4 - { - PRUint32 maxGlyph; - PRUint8* isSpace = GetSpaces(aFont, &maxGlyph); - // isSpace could be nsnull if the font do not have 'loca' table on Mac. - // Two reason for that: - // First, 'loca' table is not required in OpenType font. - // - // Second, on Mac, the sfnt-housed font may not have 'loca' table. - // exmaple are Beijing and Taipei font. - // see the WARNING section at the following link for details - // http://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html - - HandleFormat4((PRUint16*) (buf + offset), buf+len, isSpace, maxGlyph, aFontInfo); - - if (isSpace) - nsMemory::Free(isSpace); - nsMemory::Free(buf); - return PR_TRUE; - } - break; - default: - { - nsMemory::Free(buf); - return PR_FALSE; - } - break; - } - -} - - - -static PRUint16* InitGlobalCCMap() -{ - PRUint32 info[2048]; - memset(info, 0, sizeof(info)); - -#ifdef TRACK_INIT_PERFORMANCE - AbsoluteTime startTime; - AbsoluteTime endTime; - startTime = UpTime(); -#endif - - FMFontFamilyIterator aFontIterator; - OSStatus status = 0; - FMFont aFont; - FMFontFamily aFontFamily; - status = ::FMCreateFontFamilyIterator(NULL, NULL, kFMDefaultOptions, - &aFontIterator); - while (status == noErr) - { - FourCharCode aFormat; - status = ::FMGetNextFontFamily(&aFontIterator, &aFontFamily); - OSStatus status2; - FMFontStyle aStyle; - status2 = ::FMGetFontFromFontFamilyInstance(aFontFamily, 0, &aFont, &aStyle); - NS_ASSERTION(status2 == noErr, "cannot get font from family"); - if (status2 == noErr) - { - status2 = ::FMGetFontFormat(aFont, &aFormat); -#ifdef DEBUG_TRUE_TYPE - OSStatus status3 = ::FMGetFontFormat(aFont, &aFormat); - const char *four = (const char*) &aFormat; - Str255 familyName; - status3 = ::FMGetFontFamilyName(aFontFamily, familyName); - familyName[familyName[0]+1] = '\0'; - printf("%s format = %c%c%c%c\n", familyName+1, *four, *(four+1), *(four+2), *(four+3)); -#endif - if ((status2 == noErr) && - ((kFMTrueTypeFontTechnology == aFormat) || - (kFMOpenTypeFontTechnology == aFormat))) - { - PRBool ret = FillFontInfoFromCMAP(aFont, info, aFormat); - } - } - } - // Dispose of the contents of the font iterator. - status = ::FMDisposeFontFamilyIterator(&aFontIterator); - - PRUint16* map = MapToCCMap(info); - NS_ASSERTION(map, "cannot create the compressed map"); - - //register an observer to take care of cleanup - gFontCleanupObserver = new nsFontCleanupObserver(); - NS_ASSERTION(gFontCleanupObserver, "failed to create observer"); - if (gFontCleanupObserver) { - // register for shutdown - nsresult rv; - nsCOMPtr observerService(do_GetService("@mozilla.org/observer-service;1", &rv)); - if (NS_SUCCEEDED(rv)) { - rv = observerService->AddObserver(gFontCleanupObserver, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); - } - } - -#ifdef TRACK_INIT_PERFORMANCE - endTime = UpTime(); - Nanoseconds diff = ::AbsoluteToNanoseconds(SubAbsoluteFromAbsolute(endTime, startTime)); - printf("nsMacUnicodeFontInfo::InitGolbal take %d %d nanosecond\n", diff.hi, diff.lo); -#endif - - return map; -} - -// Helper to determine if a font has a private encoding that we know something about -static nsresult -GetEncoding(const nsCString& aFontName, nsACString& aValue) -{ - nsresult rv; - // see if we should init the property - if (! gFontEncodingProperties) { - // but bail out for common fonts used at startup... - if (aFontName.EqualsLiteral("Lucida Grande") || - aFontName.EqualsLiteral("Charcoal") || - aFontName.EqualsLiteral("Chicago") || - aFontName.EqualsLiteral("Capitals") || - aFontName.EqualsLiteral("Gadget") || - aFontName.EqualsLiteral("Sand") || - aFontName.EqualsLiteral("Techno") || - aFontName.EqualsLiteral("Textile") || - aFontName.EqualsLiteral("Geneva") ) - return NS_ERROR_NOT_AVAILABLE; // error mean do not get a special encoding - - // init the property now - rv = NS_LoadPersistentPropertiesFromURISpec(&gFontEncodingProperties, - NS_LITERAL_CSTRING("resource://gre/res/fonts/fontEncoding.properties")); - if (NS_FAILED(rv)) - return rv; - } - - nsCAutoString name(NS_LITERAL_CSTRING("encoding.") + - aFontName + - NS_LITERAL_CSTRING(".ttf")); - name.StripWhitespace(); - ToLowerCase(name); - - nsAutoString value; - rv = gFontEncodingProperties->GetStringProperty(name, value); - if (NS_SUCCEEDED(rv)) - LossyCopyUTF16toASCII(value, aValue); - return rv; -} - -// This function uses the charset converter manager (CCM) to get a pointer on -// the converter for the font whose name is given. The CCM caches the converter. -// The caller holds a reference and should take care of the release. -static nsresult -GetConverter(const nsCString& aFontName, nsIUnicodeEncoder** aConverter) -{ - *aConverter = nsnull; - - nsCAutoString value; - nsresult rv = GetEncoding(aFontName, value); - if (NS_FAILED(rv)) return rv; - - if (!gCharsetManager) - { - rv = CallGetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &gCharsetManager); - if(NS_FAILED(rv)) return rv; - } - - rv = gCharsetManager->GetUnicodeEncoderRaw(value.get(), aConverter); - if (NS_FAILED(rv)) return rv; - - nsIUnicodeEncoder* tmp = *aConverter; - return tmp->SetOutputErrorBehavior(tmp->kOnError_Replace, nsnull, '?'); -} - -// This function uses the charset converter manager to fill the map for the -// font whose name is given -static PRUint16* -GetCCMapThroughConverter(nsIUnicodeEncoder *converter) -{ - // see if we know something about the converter of this font - nsCOMPtr mapper(do_QueryInterface(converter)); - return (mapper ? MapperToCCMap(mapper) : nsnull); -} - -static PRBool PR_CALLBACK -HashtableFreeCCMap(nsHashKey *aKey, void *aData, void *closure) -{ - PRUint16* ccmap = (PRUint16*)aData; - FreeCCMap(ccmap); - return PR_TRUE; -} - -// If the font is symbolic, get its converter and its compressed character map -// (CCMap). The caller holds a reference to the converter (@see GetConverter()). -// The CCMap is cached in a hashtable and will be freed at shutdown. -nsresult -nsMacUnicodeFontInfo::GetConverterAndCCMap(const nsString& aFontName, nsIUnicodeEncoder** aConverter, - PRUint16** aCCMap) -{ - if(NS_SUCCEEDED(GetConverter(NS_ConvertUTF16toUTF8(aFontName), aConverter)) && *aConverter) - { - // make sure we have the hashtable - if(!gFontMaps) - { - gFontMaps = new nsObjectHashtable(nsnull, nsnull, HashtableFreeCCMap, nsnull); - if(!gFontMaps) - { - *aConverter = nsnull; - return NS_ERROR_OUT_OF_MEMORY; - } - } - - // first try to retrieve the ccmap for this font from the hashtable - nsStringKey hashKey(aFontName); - *aCCMap = (PRUint16*) gFontMaps->Get(&hashKey); - if(!*aCCMap) - { - // if it's not already in the hashtable, create it and add it to the hashtable - *aCCMap = GetCCMapThroughConverter(*aConverter); - if(!*aCCMap) - { - *aConverter = nsnull; - return NS_ERROR_FAILURE; - } - gFontMaps->Put(&hashKey, *aCCMap); - } - return NS_OK; - } - return NS_ERROR_FAILURE; -} - - - -PRBool nsMacUnicodeFontInfo::HasGlyphFor(PRUnichar aChar) -{ - if (0xfffd == aChar) - return PR_FALSE; - - if (!gCCMap) - gCCMap = InitGlobalCCMap(); - - NS_ASSERTION(gCCMap, "cannot init global ccmap"); - - if (gCCMap) - return CCMAP_HAS_CHAR(gCCMap, aChar); - - return PR_FALSE; -} - -void nsMacUnicodeFontInfo::FreeGlobals() -{ - NS_IF_RELEASE(gFontEncodingProperties); - NS_IF_RELEASE(gCharsetManager); - - delete gFontMaps; - if (gCCMap) - FreeCCMap(gCCMap); -} diff --git a/gfx/src/mac/nsMacUnicodeFontInfo.h b/gfx/src/mac/nsMacUnicodeFontInfo.h deleted file mode 100644 index ca2da95bd179..000000000000 --- a/gfx/src/mac/nsMacUnicodeFontInfo.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Frank Yung-Fong Tang - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsMacUnicodeFontInfo_h__ -#define nsMacUnicodeFontInfo_h__ - -#include "nscore.h" -class nsString; -class nsIUnicodeEncoder; - -class nsMacUnicodeFontInfo -{ -public: - PRBool HasGlyphFor(PRUnichar aChar); - static void FreeGlobals(); - static nsresult GetConverterAndCCMap(const nsString& aFontName, nsIUnicodeEncoder** aConverter, PRUint16** aCCMap); -}; - -#endif \ No newline at end of file diff --git a/gfx/src/mac/nsRegionMac.cpp b/gfx/src/mac/nsRegionMac.cpp deleted file mode 100644 index 958cdd48eb32..000000000000 --- a/gfx/src/mac/nsRegionMac.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsRegionMac.h" -#include "prmem.h" -#include "nsCarbonHelpers.h" - -#include "nsRegionPool.h" - -static RegionToRectsUPP sAddRectToArrayProc; -static RegionToRectsUPP sCountRectProc; - -static OSStatus -AddRectToArrayProc(UInt16 message, RgnHandle rgn, const Rect *inRect, void *inArray) -{ - if (message == kQDRegionToRectsMsgParse) { - nsRegionRectSet* rects = reinterpret_cast(inArray); - nsRegionRect* rect = &rects->mRects[rects->mNumRects++]; - rect->x = inRect->left; - rect->y = inRect->top; - rect->width = inRect->right - inRect->left; - rect->height = inRect->bottom - inRect->top; - rects->mArea += rect->width * rect->height; - } - - return noErr; -} - -static OSStatus -CountRectProc(UInt16 message, RgnHandle rgn, const Rect* inRect, void* rectCount) -{ - if (message == kQDRegionToRectsMsgParse) - ++(*reinterpret_cast(rectCount)); - - return noErr; -} - -//--------------------------------------------------------------------- - -nsRegionMac::nsRegionMac() -{ - mRegion = nsnull; - mRegionType = eRegionComplexity_empty; - if (!sAddRectToArrayProc) { - sAddRectToArrayProc = NewRegionToRectsUPP(AddRectToArrayProc); - sCountRectProc = NewRegionToRectsUPP(CountRectProc); - } -} - -//--------------------------------------------------------------------- - -nsRegionMac::~nsRegionMac() -{ - if (mRegion != nsnull) { - sNativeRegionPool.ReleaseRegion(mRegion); - mRegion = nsnull; - } -} - -NS_IMPL_ISUPPORTS1(nsRegionMac, nsIRegion) - -//--------------------------------------------------------------------- - -nsresult nsRegionMac::Init(void) -{ - if (mRegion != nsnull) - ::SetEmptyRgn(mRegion); - else - mRegion = sNativeRegionPool.GetNewRegion(); - if (mRegion != nsnull) { - mRegionType = eRegionComplexity_empty; - return NS_OK; - } - return NS_ERROR_OUT_OF_MEMORY; -} - -//--------------------------------------------------------------------- - -void nsRegionMac::SetTo(const nsIRegion &aRegion) -{ - nsRegionMac* pRegion = (nsRegionMac*)&aRegion; - ::CopyRgn(pRegion->mRegion, mRegion); - SetRegionType(); -} - -//--------------------------------------------------------------------- - -void nsRegionMac::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - ::SetRectRgn(mRegion, aX, aY, aX + aWidth, aY + aHeight); - SetRegionType(); -} - -//--------------------------------------------------------------------- - -void nsRegionMac::Intersect(const nsIRegion &aRegion) -{ - nsRegionMac* pRegion = (nsRegionMac*)&aRegion; - ::SectRgn(mRegion, pRegion->mRegion, mRegion); - SetRegionType(); -} - -//--------------------------------------------------------------------- - -void nsRegionMac::Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); - if (rectRgn != nsnull) { - ::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight); - ::SectRgn(mRegion, rectRgn, mRegion); - sNativeRegionPool.ReleaseRegion(rectRgn); - SetRegionType(); - } -} - -//--------------------------------------------------------------------- - -void nsRegionMac::Union(const nsIRegion &aRegion) -{ - nsRegionMac* pRegion = (nsRegionMac*)&aRegion; - ::UnionRgn(mRegion, pRegion->mRegion, mRegion); - SetRegionType(); -} - -//--------------------------------------------------------------------- - -void nsRegionMac::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); - if (rectRgn != nsnull) { - ::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight); - ::UnionRgn(mRegion, rectRgn, mRegion); - sNativeRegionPool.ReleaseRegion(rectRgn); - SetRegionType(); - } -} - -//--------------------------------------------------------------------- - -void nsRegionMac::Subtract(const nsIRegion &aRegion) -{ - nsRegionMac* pRegion = (nsRegionMac*)&aRegion; - ::DiffRgn(mRegion, pRegion->mRegion, mRegion); - SetRegionType(); -} - -//--------------------------------------------------------------------- - -void nsRegionMac::Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); - if (rectRgn != nsnull) { - ::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight); - ::DiffRgn(mRegion, rectRgn, mRegion); - sNativeRegionPool.ReleaseRegion(rectRgn); - SetRegionType(); - } -} - -//--------------------------------------------------------------------- - -PRBool nsRegionMac::IsEmpty(void) -{ - if (mRegionType == eRegionComplexity_empty) - return PR_TRUE; - else - return PR_FALSE; -} - -//--------------------------------------------------------------------- - -PRBool nsRegionMac::IsEqual(const nsIRegion &aRegion) -{ - nsRegionMac* pRegion = (nsRegionMac*)&aRegion; - return(::EqualRgn(mRegion, pRegion->mRegion)); -} - -//--------------------------------------------------------------------- - -void nsRegionMac::GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight) -{ - Rect macRect; - ::GetRegionBounds (mRegion, &macRect); - - *aX = macRect.left; - *aY = macRect.top; - *aWidth = macRect.right - macRect.left; - *aHeight = macRect.bottom - macRect.top; -} - -//--------------------------------------------------------------------- - -void nsRegionMac::Offset(PRInt32 aXOffset, PRInt32 aYOffset) -{ - ::OffsetRgn(mRegion, aXOffset, aYOffset); -} - -//--------------------------------------------------------------------- - -PRBool nsRegionMac::ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - Rect macRect; - ::SetRect(&macRect, aX, aY, aX + aWidth, aY + aHeight); - return(::RectInRgn(&macRect, mRegion)); -} - -//--------------------------------------------------------------------- - -NS_IMETHODIMP nsRegionMac::GetRects(nsRegionRectSet **aRects) -{ - NS_ASSERTION(aRects, "bad ptr"); - - nsRegionRectSet* rects = *aRects; - long numrects = 0; - QDRegionToRects(mRegion, kQDParseRegionFromTopLeft, sCountRectProc, &numrects); - - if (!rects || rects->mRectsLen < (PRUint32) numrects) { - void* buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + sizeof(nsRegionRect) * (numrects - 1)); - - if (!buf) { - if (rects) - rects->mNumRects = 0; - - return NS_ERROR_OUT_OF_MEMORY; - } - - rects = (nsRegionRectSet*) buf; - rects->mRectsLen = numrects; - } - - rects->mNumRects = 0; - rects->mArea = 0; - QDRegionToRects(mRegion, kQDParseRegionFromTopLeft, sAddRectToArrayProc, rects); - - *aRects = rects; - - return NS_OK; -} - -//--------------------------------------------------------------------- - -NS_IMETHODIMP nsRegionMac::FreeRects(nsRegionRectSet *aRects) -{ - if (nsnull != aRects) - PR_Free((void *)aRects); - - return NS_OK; -} - -//--------------------------------------------------------------------- - - -NS_IMETHODIMP nsRegionMac::GetNativeRegion(void *&aRegion) const -{ - aRegion = (void *)mRegion; - return NS_OK; -} - - -nsresult nsRegionMac::SetNativeRegion(void *aRegion) -{ - if (aRegion) { - ::CopyRgn((RgnHandle)aRegion, mRegion); - SetRegionType(); - } else { - Init(); - } - return NS_OK; -} - -//--------------------------------------------------------------------- - -NS_IMETHODIMP nsRegionMac::GetRegionComplexity(nsRegionComplexity &aComplexity) const -{ - aComplexity = mRegionType; - return NS_OK; -} - -//--------------------------------------------------------------------- - - -void nsRegionMac::SetRegionType() -{ - if (::EmptyRgn(mRegion) == PR_TRUE) - mRegionType = eRegionComplexity_empty; - else - if ( ::IsRegionRectangular(mRegion) ) - mRegionType = eRegionComplexity_rect; - else - mRegionType = eRegionComplexity_complex; -} - - -//--------------------------------------------------------------------- - - -void nsRegionMac::SetRegionEmpty() -{ - ::SetEmptyRgn(mRegion); - SetRegionType(); -} - -//--------------------------------------------------------------------- - -RgnHandle nsRegionMac::CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); - if (rectRgn != nsnull) - ::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight); - return rectRgn; -} diff --git a/gfx/src/mac/nsRegionMac.h b/gfx/src/mac/nsRegionMac.h deleted file mode 100644 index e3478cf7965f..000000000000 --- a/gfx/src/mac/nsRegionMac.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRegionMac_h___ -#define nsRegionMac_h___ - -#include "nsIRegion.h" -#include - -//------------------------------------------------------------------------ - -class nsRegionMac : public nsIRegion -{ -public: - nsRegionMac(); - virtual ~nsRegionMac(); - - NS_DECL_ISUPPORTS - - virtual nsresult Init(); - - virtual void SetTo(const nsIRegion &aRegion); - virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - virtual void Intersect(const nsIRegion &aRegion); - virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - virtual void Union(const nsIRegion &aRegion); - virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - virtual void Subtract(const nsIRegion &aRegion); - virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - virtual PRBool IsEmpty(void); - virtual PRBool IsEqual(const nsIRegion &aRegion); - virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight); - virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset); - virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - NS_IMETHOD GetRects(nsRegionRectSet **aRects); - NS_IMETHOD FreeRects(nsRegionRectSet *aRects); - NS_IMETHOD GetNativeRegion(void *&aRegion) const; - virtual nsresult SetNativeRegion(void *aRegion); - NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const; - NS_IMETHOD GetNumRects(PRUint32 *aRects) const { *aRects = 0; return NS_OK; } - -private: - RgnHandle mRegion; - nsRegionComplexity mRegionType; - -private: - virtual void SetRegionType(); - virtual void SetRegionEmpty(); - virtual RgnHandle CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - -}; - -#endif // nsRegionMac_h___ diff --git a/gfx/src/mac/nsRegionPool.cpp b/gfx/src/mac/nsRegionPool.cpp deleted file mode 100644 index 47b4ec30a58a..000000000000 --- a/gfx/src/mac/nsRegionPool.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsRegionPool.h" - - -NS_EXPORT nsNativeRegionPool sNativeRegionPool; - -//------------------------------------------------------------------------ - -nsNativeRegionPool::nsNativeRegionPool() -{ - mRegionSlots = nsnull; - mEmptySlots = nsnull; -} - -//------------------------------------------------------------------------ - -nsNativeRegionPool::~nsNativeRegionPool() -{ - // Release all of the regions. - if (mRegionSlots != nsnull) { - nsRegionSlot* slot = mRegionSlots; - while (slot != nsnull) { - ::DisposeRgn(slot->mRegion); - nsRegionSlot* next = slot->mNext; - delete slot; - slot = next; - } - } - - // Release all empty slots. - if (mEmptySlots != nsnull) { - nsRegionSlot* slot = mEmptySlots; - while (slot != nsnull) { - nsRegionSlot* next = slot->mNext; - delete slot; - slot = next; - } - } -} - -//------------------------------------------------------------------------ - -RgnHandle nsNativeRegionPool::GetNewRegion() -{ - nsRegionSlot* slot = mRegionSlots; - if (slot != nsnull) { - RgnHandle region = slot->mRegion; - - // remove this slot from the free list. - mRegionSlots = slot->mNext; - - // transfer this slot to the empty slot list for reuse. - slot->mRegion = nsnull; - slot->mNext = mEmptySlots; - mEmptySlots = slot; - - // initialize the region. - ::SetEmptyRgn(region); - return region; - } - - // return a fresh new region. a slot will be created to hold it - // if and when the region is released. - return (::NewRgn()); -} - -//------------------------------------------------------------------------ - -void nsNativeRegionPool::ReleaseRegion(RgnHandle aRgnHandle) -{ - nsRegionSlot* slot = mEmptySlots; - if (slot != nsnull) - mEmptySlots = slot->mNext; - else - slot = new nsRegionSlot; - - if (slot != nsnull) { - // put this region on the region list. - slot->mRegion = aRgnHandle; - slot->mNext = mRegionSlots; - mRegionSlots = slot; - } else { - // couldn't allocate a slot, toss the region. - ::DisposeRgn(aRgnHandle); - } -} - diff --git a/gfx/src/mac/nsRegionPool.h b/gfx/src/mac/nsRegionPool.h deleted file mode 100644 index d06b8d9c797f..000000000000 --- a/gfx/src/mac/nsRegionPool.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRegionPool_h___ -#define nsRegionPool_h___ - -#include "nscore.h" -#include - - -class NS_EXPORT nsNativeRegionPool -{ -public: - nsNativeRegionPool(); - ~nsNativeRegionPool(); - - RgnHandle GetNewRegion(); - void ReleaseRegion(RgnHandle aRgnHandle); - -private: - struct nsRegionSlot { - RgnHandle mRegion; - nsRegionSlot* mNext; - }; - - nsRegionSlot* mRegionSlots; - nsRegionSlot* mEmptySlots; -}; - -//------------------------------------------------------------------------ - -extern NS_EXPORT nsNativeRegionPool sNativeRegionPool; - -//------------------------------------------------------------------------ - -class StRegionFromPool -{ -public: - StRegionFromPool() - { - mRegionH = sNativeRegionPool.GetNewRegion(); - } - - ~StRegionFromPool() - { - if ( mRegionH ) - sNativeRegionPool.ReleaseRegion(mRegionH); - } - - operator RgnHandle() const - { - return mRegionH; - } - - private: - RgnHandle mRegionH; -}; - - - -#endif // nsRegionPool_h___ diff --git a/gfx/src/mac/nsRenderingContextMac.cpp b/gfx/src/mac/nsRenderingContextMac.cpp deleted file mode 100644 index 2b154bf06a7e..000000000000 --- a/gfx/src/mac/nsRenderingContextMac.cpp +++ /dev/null @@ -1,1541 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * Mark Mentovai - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIInterfaceRequestorUtils.h" -#include "nsIServiceManager.h" -#include "nsRenderingContextMac.h" -#include "nsDeviceContextMac.h" -#include "nsFontMetricsMac.h" -#include "nsIRegion.h" -#include "nsIEnumerator.h" -#include "nsRegionMac.h" -#include "nsGraphicState.h" - -#include "nsTransform2D.h" -#include "nsVoidArray.h" -#include "nsGfxCIID.h" -#include "nsGfxUtils.h" -#include "nsCOMPtr.h" - -#include "plhash.h" - -#include -#include -#include - -#include "nsRegionPool.h" -#include "nsFontUtils.h" - -#include "nsCarbonHelpers.h" - -#define STACK_THRESHOLD 1000 - - -//------------------------------------------------------------------------ - -nsRenderingContextMac::nsRenderingContextMac() -: mP2T(1.0f) -, mContext(nsnull) -, mCurrentSurface(nsnull) -, mPort(nsnull) -, mGS(nsnull) -, mChanges(kEverythingChanged) -, mRightToLeftText(PR_FALSE) -{ - mFrontSurface = new nsDrawingSurfaceMac(); - NS_IF_ADDREF(mFrontSurface); -} - - -//------------------------------------------------------------------------ - -nsRenderingContextMac::~nsRenderingContextMac() -{ - // restore stuff - NS_IF_RELEASE(mContext); - - // release surfaces - NS_IF_RELEASE(mFrontSurface); - NS_IF_RELEASE(mCurrentSurface); - - mPort = nsnull; - mGS = nsnull; - - // delete the stack and its contents - PRInt32 cnt = mGSStack.Count(); - for (PRInt32 i = 0; i < cnt; i ++) { - nsGraphicState* gs = (nsGraphicState*)mGSStack.ElementAt(i); - if (gs != nsnull) - sGraphicStatePool.ReleaseGS(gs); //delete gs; - } - - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); -} - - -NS_IMPL_ISUPPORTS1(nsRenderingContextMac, nsIRenderingContext) - - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::Init(nsIDeviceContext* aContext, nsIWidget* aWindow) -{ - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); - - // make sure all allocations in the constructor succeeded. - if (nsnull == mFrontSurface) - return NS_ERROR_OUT_OF_MEMORY; - - if (nsnull == aWindow->GetNativeData(NS_NATIVE_WINDOW)) - return NS_ERROR_NOT_INITIALIZED; - - if (aContext != mContext) { - NS_IF_RELEASE(mContext); - mContext = aContext; - NS_IF_ADDREF(mContext); - } - - // select the surface - mFrontSurface->Init(aWindow); - SelectDrawingSurface(mFrontSurface); - - // NOTE: here, we used to clip out the children from mGS->mMainRegion - // and copy the resulting region into mMainRegion and mClipRegion. - // This is no longer necessary because when initializing mGS from an nsIWidget, we - // call GetNativeData(NS_NATIVE_REGION) that now returns the widget's visRegion - // with the children already clipped out (as well as the areas masked by the - // widget's parents). - - return NS_OK; -} - -//------------------------------------------------------------------------ - -// should only be called for an offscreen drawing surface, without an offset or clip region -NS_IMETHODIMP nsRenderingContextMac::Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface) -{ - // make sure all allocations in the constructor succeeded. - if (nsnull == mFrontSurface) - return NS_ERROR_OUT_OF_MEMORY; - - mContext = aContext; - NS_IF_ADDREF(mContext); - - // select the surface - nsDrawingSurfaceMac* surface = static_cast(aSurface); - SelectDrawingSurface(surface); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -// used by nsDeviceContextMac::CreateRenderingContext() for printing -nsresult nsRenderingContextMac::Init(nsIDeviceContext* aContext, CGrafPtr aPort) -{ - // make sure all allocations in the constructor succeeded. - if (nsnull == mFrontSurface) - return NS_ERROR_OUT_OF_MEMORY; - - mContext = aContext; - NS_IF_ADDREF(mContext); - - // select the surface - mFrontSurface->Init(aPort); - SelectDrawingSurface(mFrontSurface); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -void nsRenderingContextMac::SelectDrawingSurface(nsDrawingSurfaceMac* aSurface, PRUint32 aChanges) -{ - NS_PRECONDITION(aSurface != nsnull, "null surface"); - if (! aSurface) - return; - - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); - - // if surface is changing, be extra conservative about graphic state changes. - if (mCurrentSurface != aSurface) - { - aChanges = kEverythingChanged; - - NS_IF_RELEASE(mCurrentSurface); - mCurrentSurface = aSurface; - NS_IF_ADDREF(mCurrentSurface); - } - - CGrafPtr newPort; - aSurface->GetGrafPtr(&newPort); - mPort = newPort; - mGS = aSurface->GetGS(); - mTranMatrix = &(mGS->mTMatrix); - - nsGraphicsUtils::SafeSetPort(mPort); - -#ifndef MOZ_WIDGET_COCOA - // Cocoa widgets automatically set the correct origin, and - // it can differ from this value (because of an oddity where - // the widget shrinks when its partially offscreen). - ::SetOrigin(-mGS->mOffx, -mGS->mOffy); // line order... -#endif - - if (aChanges & kClippingChanged) - ::SetClip(mGS->mClipRegion); // ...does matter - - ::PenNormal(); - ::PenMode(patCopy); - ::TextMode(srcOr); - - if (aChanges & kColorChanged) - SetColor(mGS->mColor); - - if (mGS->mFontMetrics && (aChanges & kFontChanged)) - SetFont(mGS->mFontMetrics); - - if (!mContext) return; - - // GS and context initializations -#if 0 - ((nsDeviceContextMac *)mContext)->InstallColormap(); -#endif - - mP2T = mContext->DevUnitsToAppUnits(); - - if (mGS->mTMatrix.GetType() == MG_2DIDENTITY) { - // apply the new scaling - float app2dev; - app2dev = mContext->AppUnitsToDevUnits(); - mGS->mTMatrix.AddScale(app2dev, app2dev); - } - - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); -} - - -//------------------------------------------------------------------------ - -nsresult nsRenderingContextMac::SetPortTextState() -{ - NS_PRECONDITION(mGS->mFontMetrics != nsnull, "No font metrics in SetPortTextState"); - - if (nsnull == mGS->mFontMetrics) - return NS_ERROR_NULL_POINTER; - - NS_PRECONDITION(mContext != nsnull, "No device context in SetPortTextState"); - - if (nsnull == mContext) - return NS_ERROR_NULL_POINTER; - - TextStyle theStyle; - nsFontUtils::GetNativeTextStyle(*mGS->mFontMetrics, *mContext, theStyle); - - ::TextFont(theStyle.tsFont); - ::TextSize(theStyle.tsSize); - ::TextFace(theStyle.tsFace); - - return NS_OK; -} - - -//------------------------------------------------------------------------ - -void nsRenderingContextMac::SetupPortState() -{ - nsGraphicsUtils::SafeSetPort(mPort); -#ifndef MOZ_WIDGET_COCOA - ::SetOrigin(-mGS->mOffx, -mGS->mOffy); -#endif - ::SetClip(mGS->mClipRegion); -} - -#pragma mark - - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::PushState(void) -{ - // create a GS - nsGraphicState * gs = sGraphicStatePool.GetNewGS(); - if (!gs) - return NS_ERROR_OUT_OF_MEMORY; - - // save the current set of graphics changes. - mGS->SetChanges(mChanges); - - // copy the current GS into it - gs->Duplicate(mGS); - - // put the new GS at the end of the stack - mGSStack.AppendElement(gs); - - // reset the graphics changes. this always represents a delta from previous state to current. - mChanges = 0; - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::PopState(void) -{ - NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); - - PRInt32 count = mGSStack.Count(); - NS_ASSERTION(count > 0, "No state to pop"); - if (count > 0) { - PRInt32 index = count - 1; - - // get the GS from the stack - nsGraphicState* gs = (nsGraphicState *)mGSStack.ElementAt(index); - - // copy the GS into the current one and tell the current surface to use it - mGS->Duplicate(gs); - - SelectDrawingSurface(mCurrentSurface, mChanges); - - // restore the current set of changes. - mChanges = mGS->GetChanges(); - - // remove the GS object from the stack and delete it - mGSStack.RemoveElementAt(index); - sGraphicStatePool.ReleaseGS(gs); - - // make sure the matrix is pointing at the current matrix - mTranMatrix = &(mGS->mTMatrix); - } - - return NS_OK; -} - -#pragma mark - - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::LockDrawingSurface(PRInt32 aX, PRInt32 aY, - PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, - PRInt32 *aWidthBytes, PRUint32 aFlags) -{ - PushState(); - - return mCurrentSurface->Lock(aX, aY, aWidth, aHeight, - aBits, aStride, aWidthBytes, aFlags); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::UnlockDrawingSurface(void) -{ - PopState(); - - mCurrentSurface->Unlock(); - - return NS_OK; -} - -//------------------------------------------------------------------------ - - -NS_IMETHODIMP nsRenderingContextMac::SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface) -{ - nsDrawingSurfaceMac* surface = static_cast(aSurface); - - if (surface != nsnull) - SelectDrawingSurface(surface); // select the offscreen surface... - else - SelectDrawingSurface(mFrontSurface); // ...or get back to the window port - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetDrawingSurface(nsIDrawingSurface* *aSurface) -{ - *aSurface = mCurrentSurface; - // on Mac, select it too, to ensure that the port gets set correct for - // tiling and image drawing - //SelectDrawingSurface(mCurrentSurface); - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, - PRInt32 aSrcX, PRInt32 aSrcY, - const nsRect &aDestBounds, - PRUint32 aCopyFlags) -{ - // hack: shortcut to bypass empty frames - // or frames entirely recovered with other frames - if ((aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER) == 0) - if (::EmptyRgn(mFrontSurface->GetGS()->mMainRegion)) - return NS_OK; - - // retrieve the surface - nsDrawingSurfaceMac* srcSurface = static_cast(aSrcSurf); - CGrafPtr srcPort; - srcSurface->GetGrafPtr(&srcPort); - - // apply the selected transformations - PRInt32 x = aSrcX; - PRInt32 y = aSrcY; - if (aCopyFlags & NS_COPYBITS_XFORM_SOURCE_VALUES) - mGS->mTMatrix.TransformCoord(&x, &y); - - nsRect dstRect = aDestBounds; - if (aCopyFlags & NS_COPYBITS_XFORM_DEST_VALUES) - mGS->mTMatrix.TransformCoord(&dstRect.x, &dstRect.y, &dstRect.width, &dstRect.height); - - // get the source and destination rectangles - Rect macSrcRect, macDstRect; - ::SetRect(&macSrcRect, x, y, x + dstRect.width, y + dstRect.height); - ::SetRect(&macDstRect, dstRect.x, dstRect.y, dstRect.x + dstRect.width, dstRect.y + dstRect.height); - - // get the source clip region - StRegionFromPool clipRgn; - if (!clipRgn) return NS_ERROR_OUT_OF_MEMORY; - - if (aCopyFlags & NS_COPYBITS_USE_SOURCE_CLIP_REGION) { - ::GetPortClipRegion(srcPort, clipRgn); - } else - ::CopyRgn(mGS->mMainRegion, clipRgn); - - // get the destination port and surface - CGrafPtr destPort; - nsDrawingSurfaceMac* destSurface; - if (aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER) { - destSurface = mCurrentSurface; - destPort = mPort; - NS_ASSERTION((destPort != nsnull), "no back buffer"); - } else { - destSurface = mFrontSurface; - mFrontSurface->GetGrafPtr(&destPort); - } - - // we need to select the front surface so that the coordinates are set up correctly - SelectDrawingSurface(destSurface); - - // set the right colors for CopyBits - RGBColor foreColor; - Boolean changedForeColor = false; - ::GetForeColor(&foreColor); - if ((foreColor.red != 0x0000) || (foreColor.green != 0x0000) || (foreColor.blue != 0x0000)) { - RGBColor rgbBlack = {0x0000,0x0000,0x0000}; - ::RGBForeColor(&rgbBlack); - changedForeColor = true; - } - - RGBColor backColor; - Boolean changedBackColor = false; - ::GetBackColor(&backColor); - if ((backColor.red != 0xFFFF) || (backColor.green != 0xFFFF) || (backColor.blue != 0xFFFF)) { - RGBColor rgbWhite = {0xFFFF,0xFFFF,0xFFFF}; - ::RGBBackColor(&rgbWhite); - changedBackColor = true; - } - - // copy the bits now - ::CopyBits( - ::GetPortBitMapForCopyBits(srcPort), - ::GetPortBitMapForCopyBits(destPort), - &macSrcRect, - &macDstRect, - srcCopy, - clipRgn); - - // restore colors and surface - if (changedForeColor) - ::RGBForeColor(&foreColor); - if (changedBackColor) - ::RGBBackColor(&backColor); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface) -{ - aSurface = nsnull; - - PRUint32 depth = 8; - if (mContext) - mContext->GetDepth(depth); - - // get rect - Rect macRect; - // fyi, aBounds->x and aBounds->y are always 0 here - ::SetRect(&macRect, aBounds.x, aBounds.y, aBounds.XMost(), aBounds.YMost()); - - nsDrawingSurfaceMac* surface = new nsDrawingSurfaceMac(); - if (!surface) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(surface); - - nsresult rv = surface->Init(depth, macRect.right, macRect.bottom, aSurfFlags); - if (NS_SUCCEEDED(rv)) - aSurface = surface; - else - delete surface; - - return rv; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DestroyDrawingSurface(nsIDrawingSurface* aSurface) -{ - if (!aSurface) - return NS_ERROR_FAILURE; - - // if that surface is still the current one, select the front surface - if (aSurface == mCurrentSurface) - { - NS_ASSERTION(mCurrentSurface != mFrontSurface, "Nuking the front surface"); - SelectDrawingSurface(mFrontSurface); - } - // release the surface - nsDrawingSurfaceMac* surface = static_cast(aSurface); - NS_IF_RELEASE(surface); - - return NS_OK; -} - - -#pragma mark - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetHints(PRUint32& aResult) -{ - PRUint32 result = 0; - - // QuickDraw is preferred over to ATSUI for drawing 7-bit text - // (it's not 8-bit: the name of the constant is misleading) - result |= NS_RENDERING_HINT_FAST_8BIT_TEXT; - aResult = result; - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::Reset(void) -{ - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetDeviceContext(nsIDeviceContext *&aContext) -{ - if (mContext) { - aContext = mContext; - NS_ADDREF(aContext); - } else { - aContext = nsnull; - } - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::IsVisibleRect(const nsRect& aRect, PRBool &aVisible) -{ - aVisible = PR_TRUE; - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::SetClipRect(const nsRect& aRect, nsClipCombine aCombine) -{ - nsRect trect = aRect; - - mGS->mTMatrix.TransformCoord(&trect.x, &trect.y, &trect.width, &trect.height); - - Rect macRect; - ::SetRect(&macRect, trect.x, trect.y, trect.x + trect.width, trect.y + trect.height); - - StRegionFromPool rectRgn; - RgnHandle clipRgn = mGS->mClipRegion; - if (!clipRgn || !rectRgn) - return NS_ERROR_OUT_OF_MEMORY; - - ::RectRgn(rectRgn, &macRect); - - switch (aCombine) { - case nsClipCombine_kIntersect: - ::SectRgn(clipRgn, rectRgn, clipRgn); - break; - - case nsClipCombine_kUnion: - ::UnionRgn(clipRgn, rectRgn, clipRgn); - break; - - case nsClipCombine_kSubtract: - ::DiffRgn(clipRgn, rectRgn, clipRgn); - break; - - case nsClipCombine_kReplace: -// ::CopyRgn(rectRgn, clipRgn); - ::SectRgn(rectRgn, mGS->mMainRegion, clipRgn); - break; - } - - { - StPortSetter setter(mPort); - ::SetClip(clipRgn); - } - - mGS->mClipRegion = clipRgn; - - // note that the clipping changed. - mChanges |= kClippingChanged; - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetClipRect(nsRect &aRect, PRBool &aClipValid) -{ - Rect cliprect; - - if (mGS->mClipRegion != nsnull) { - ::GetRegionBounds(mGS->mClipRegion, &cliprect); - aRect.SetRect(cliprect.left, cliprect.top, cliprect.right - cliprect.left, cliprect.bottom - cliprect.top); - aClipValid = PR_TRUE; - } else { - aRect.SetRect(0,0,0,0); - aClipValid = PR_FALSE; - } - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine) -{ - RgnHandle regionH; - aRegion.GetNativeRegion((void*&)regionH); - - RgnHandle clipRgn = mGS->mClipRegion; - if (!clipRgn) return NS_ERROR_OUT_OF_MEMORY; - - switch (aCombine) { - case nsClipCombine_kIntersect: - ::SectRgn(clipRgn, regionH, clipRgn); - break; - - case nsClipCombine_kUnion: - ::UnionRgn(clipRgn, regionH, clipRgn); - break; - - case nsClipCombine_kSubtract: - ::DiffRgn(clipRgn, regionH, clipRgn); - break; - - case nsClipCombine_kReplace: -// ::CopyRgn(regionH, clipRgn); - ::SectRgn(regionH, mGS->mMainRegion, clipRgn); - break; - } - - - { - StPortSetter setter(mPort); - ::SetClip(clipRgn); - } - - mGS->mClipRegion = clipRgn; - - // note that the clipping changed. - mChanges |= kClippingChanged; - - return NS_OK; -} - -/** - * Fills in |aRegion| with a copy of the current clip region. - */ -NS_IMETHODIMP nsRenderingContextMac::CopyClipRegion(nsIRegion &aRegion) -{ - nsRegionMac* macRegion = (nsRegionMac*)&aRegion; - macRegion->SetNativeRegion(mGS->mClipRegion); - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetClipRegion(nsIRegion **aRegion) -{ - nsresult rv = NS_OK; - - NS_ASSERTION(!(nsnull == aRegion), "no region ptr"); - - if (nsnull == *aRegion) { - nsRegionMac *rgn = new nsRegionMac(); - - if (nsnull != rgn) { - NS_ADDREF(rgn); - rv = rgn->Init(); - - if (NS_OK != rv) - NS_RELEASE(rgn); - else - *aRegion = rgn; - } else - rv = NS_ERROR_OUT_OF_MEMORY; - } - - if (rv == NS_OK) { - nsRegionMac* macRegion = *(nsRegionMac**)aRegion; - macRegion->SetNativeRegion(mGS->mClipRegion); - } - - return rv; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::SetColor(nscolor aColor) -{ - SetupPortState(); - - #define COLOR8TOCOLOR16(color8) ((color8 << 8) | color8) - - RGBColor color; - color.red = COLOR8TOCOLOR16(NS_GET_R(aColor)); - color.green = COLOR8TOCOLOR16(NS_GET_G(aColor)); - color.blue = COLOR8TOCOLOR16(NS_GET_B(aColor)); - ::RGBForeColor(&color); - mGS->mColor = aColor ; - - mChanges |= kColorChanged; - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetColor(nscolor &aColor) const -{ - aColor = mGS->mColor; - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::SetLineStyle(nsLineStyle aLineStyle) -{ - mGS->mLineStyle = aLineStyle; - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetLineStyle(nsLineStyle &aLineStyle) -{ - aLineStyle = mGS->mLineStyle; - return NS_OK; -} - - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::SetFont(const nsFont& aFont, nsIAtom* aLangGroup) -{ - NS_IF_RELEASE(mGS->mFontMetrics); - - if (mContext) - mContext->GetMetricsFor(aFont, aLangGroup, mGS->mFontMetrics); - - mChanges |= kFontChanged; - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::SetFont(nsIFontMetrics *aFontMetrics) -{ - NS_IF_RELEASE(mGS->mFontMetrics); - mGS->mFontMetrics = aFontMetrics; - NS_IF_ADDREF(mGS->mFontMetrics); - mChanges |= kFontChanged; - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetFontMetrics(nsIFontMetrics *&aFontMetrics) -{ - NS_IF_ADDREF(mGS->mFontMetrics); - aFontMetrics = mGS->mFontMetrics; - return NS_OK; -} - -//------------------------------------------------------------------------ - -// add the passed in translation to the current translation -NS_IMETHODIMP nsRenderingContextMac::Translate(nscoord aX, nscoord aY) -{ - mGS->mTMatrix.AddTranslation((float)aX,(float)aY); - return NS_OK; -} - -//------------------------------------------------------------------------ - -// add the passed in scale to the current scale -NS_IMETHODIMP nsRenderingContextMac::Scale(float aSx, float aSy) -{ - mGS->mTMatrix.AddScale(aSx, aSy); - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetCurrentTransform(nsTransform2D *&aTransform) -{ - aTransform = &mGS->mTMatrix; - return NS_OK; -} - - -#pragma mark - - -// 0 1 2 3 4 5 6 7 -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -static const Pattern dottedPattern = {0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55}; - -// 0 1 2 3 4 5 6 7 -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -// * * * * -static const Pattern dashedPattern = {0xf0,0x78,0x3c,0x1e,0x0f,0x87,0xc3,0xe1}; - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1) -{ - if (mGS->mLineStyle == nsLineStyle_kNone) - return NS_OK; - - SetupPortState(); - - PenState savedPenState; - RGBColor savedBGColor; - if (mGS->mLineStyle == nsLineStyle_kDotted || - mGS->mLineStyle == nsLineStyle_kDashed) { - ::GetPenState(&savedPenState); - ::GetBackColor(&savedBGColor); - - ::PenMode(transparent); - if (mGS->mLineStyle == nsLineStyle_kDashed) - ::PenPat(&dashedPattern); - else - ::PenPat(&dottedPattern); - RGBColor invertedForeColor; - ::GetForeColor(&invertedForeColor); - ::InvertColor(&invertedForeColor); - ::RGBBackColor(&invertedForeColor); - } - - mGS->mTMatrix.TransformCoord(&aX0,&aY0); - mGS->mTMatrix.TransformCoord(&aX1,&aY1); - - // make the line one pixel shorter to match other platforms - nscoord diffX = aX1 - aX0; - if (diffX) - diffX -= (diffX > 0 ? 1 : -1); - - nscoord diffY = aY1 - aY0; - if (diffY) - diffY -= (diffY > 0 ? 1 : -1); - - ::MoveTo(aX0, aY0); - ::Line(diffX, diffY); - - if (mGS->mLineStyle == nsLineStyle_kDotted || - mGS->mLineStyle == nsLineStyle_kDashed) { - ::PenMode(savedPenState.pnMode); - ::PenPat(&savedPenState.pnPat); - ::RGBBackColor(&savedBGColor); - } - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints) -{ - if (mGS->mLineStyle == nsLineStyle_kNone) - return NS_OK; - - SetupPortState(); - - PenState savedPenState; - RGBColor savedBGColor; - if (mGS->mLineStyle == nsLineStyle_kDotted || - mGS->mLineStyle == nsLineStyle_kDashed) { - ::GetPenState(&savedPenState); - ::GetBackColor(&savedBGColor); - - ::PenMode(transparent); - if (mGS->mLineStyle == nsLineStyle_kDashed) - ::PenPat(&dashedPattern); - else - ::PenPat(&dottedPattern); - RGBColor invertedForeColor; - ::GetForeColor(&invertedForeColor); - ::InvertColor(&invertedForeColor); - ::RGBBackColor(&invertedForeColor); - } - - PRInt32 x,y; - - x = aPoints[0].x; - y = aPoints[0].y; - mGS->mTMatrix.TransformCoord((PRInt32*)&x,(PRInt32*)&y); - - ::MoveTo(x,y); - for (PRInt32 i = 1; i < aNumPoints; i++) { - x = aPoints[i].x; - y = aPoints[i].y; - mGS->mTMatrix.TransformCoord((PRInt32*)&x,(PRInt32*)&y); - ::LineTo(x,y); - } - - if (mGS->mLineStyle == nsLineStyle_kDotted || - mGS->mLineStyle == nsLineStyle_kDashed) { - ::PenMode(savedPenState.pnMode); - ::PenPat(&savedPenState.pnPat); - ::RGBBackColor(&savedBGColor); - } - - return NS_OK; -} - - /** - * A note about Quickdraw coordinates: When Apple designed Quickdraw, signed 16-bit coordinates - * were considered to be large enough. Although computer displays with > 65535 pixels in either - * dimension are still far off, most modern graphics systems allow at least 32-bit signed coordinates - * so we have to take extra care when converting from GFX coordinates to Quickdraw coordinates, - * especially when constructing rectangles. - */ - - inline short pinToShort(nscoord value) - { - if (value < -32768) - return -32768; - if (value > 32767) - return 32767; - return (short) value; - } - - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawRect(const nsRect& aRect) -{ - return DrawRect(aRect.x, aRect.y, aRect.width, aRect.height); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - SetupPortState(); - - nscoord x,y,w,h; - Rect therect; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mGS->mTMatrix.TransformCoord(&x, &y, &w, &h); - ::SetRect(&therect, pinToShort(x), pinToShort(y), pinToShort(x + w), pinToShort(y + h)); - ::FrameRect(&therect); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::FillRect(const nsRect& aRect) -{ - return FillRect(aRect.x, aRect.y, aRect.width, aRect.height); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - SetupPortState(); - - nscoord x,y,w,h; - Rect therect; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - // TODO - cps - must debug and fix this - mGS->mTMatrix.TransformCoord(&x, &y, &w, &h); - ::SetRect(&therect, pinToShort(x), pinToShort(y), pinToShort(x + w), pinToShort(y + h)); - ::PaintRect(&therect); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) -{ - SetupPortState(); - - PolyHandle thepoly; - PRInt32 x,y; - - thepoly = ::OpenPoly(); - if (nsnull == thepoly) { - return NS_ERROR_OUT_OF_MEMORY; - } - - x = aPoints[0].x; - y = aPoints[0].y; - mGS->mTMatrix.TransformCoord((PRInt32*)&x,(PRInt32*)&y); - ::MoveTo(x,y); - - for (PRInt32 i = 1; i < aNumPoints; i++) { - x = aPoints[i].x; - y = aPoints[i].y; - - mGS->mTMatrix.TransformCoord((PRInt32*)&x,(PRInt32*)&y); - ::LineTo(x,y); - } - - ::ClosePoly(); - - ::FramePoly(thepoly); - ::KillPoly(thepoly); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) -{ - SetupPortState(); - - PolyHandle thepoly; - PRInt32 x,y; - - thepoly = ::OpenPoly(); - if (nsnull == thepoly) { - return NS_ERROR_OUT_OF_MEMORY; - } - - x = aPoints[0].x; - y = aPoints[0].y; - mGS->mTMatrix.TransformCoord((PRInt32*)&x,(PRInt32*)&y); - ::MoveTo(x,y); - - for (PRInt32 i = 1; i < aNumPoints; i++) { - x = aPoints[i].x; - y = aPoints[i].y; - mGS->mTMatrix.TransformCoord((PRInt32*)&x,(PRInt32*)&y); - ::LineTo(x,y); - } - - ::ClosePoly(); - ::PaintPoly(thepoly); - ::KillPoly(thepoly); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawEllipse(const nsRect& aRect) -{ - return DrawEllipse(aRect.x, aRect.y, aRect.width, aRect.height); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - SetupPortState(); - - nscoord x,y,w,h; - Rect therect; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mGS->mTMatrix.TransformCoord(&x,&y,&w,&h); - ::SetRect(&therect, pinToShort(x), pinToShort(y), pinToShort(x + w), pinToShort(y + h)); - ::FrameOval(&therect); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::FillEllipse(const nsRect& aRect) -{ - return FillEllipse(aRect.x, aRect.y, aRect.width, aRect.height); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - SetupPortState(); - - nscoord x,y,w,h; - Rect therect; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mGS->mTMatrix.TransformCoord(&x,&y,&w,&h); - ::SetRect(&therect, pinToShort(x), pinToShort(y), pinToShort(x + w), pinToShort(y + h)); - ::PaintOval(&therect); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawArc(const nsRect& aRect, - float aStartAngle, float aEndAngle) -{ - return DrawArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, - float aStartAngle, float aEndAngle) -{ - SetupPortState(); - - nscoord x,y,w,h; - Rect therect; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mGS->mTMatrix.TransformCoord(&x,&y,&w,&h); - ::SetRect(&therect, pinToShort(x), pinToShort(y), pinToShort(x + w), pinToShort(y + h)); - ::FrameArc(&therect, (short)aStartAngle, (short)aEndAngle); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::FillArc(const nsRect& aRect, - float aStartAngle, float aEndAngle) -{ - return FillArc(aRect.x, aRect.y, aRect.width, aRect.height, aStartAngle, aEndAngle); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, - float aStartAngle, float aEndAngle) -{ - SetupPortState(); - - nscoord x,y,w,h; - Rect therect; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mGS->mTMatrix.TransformCoord(&x,&y,&w,&h); - ::SetRect(&therect, pinToShort(x), pinToShort(y), pinToShort(x + w), pinToShort(y + h)); - ::PaintArc(&therect, (short)aStartAngle, (short)aEndAngle); - - return NS_OK; -} - -PRInt32 nsRenderingContextMac::GetMaxStringLength() -{ - if (!mGS->mFontMetrics) - return 1; - return static_cast(mGS->mFontMetrics)->GetMaxStringLength(); -} - -#pragma mark - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetWidth(char ch, nscoord &aWidth) -{ - if (ch == ' ' && mGS->mFontMetrics) { - return mGS->mFontMetrics->GetSpaceWidth(aWidth); - } - - char buf[1]; - buf[0] = ch; - return GetWidth(buf, 1, aWidth); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetWidth(PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID) -{ - if (ch == ' ' && mGS->mFontMetrics) { - return mGS->mFontMetrics->GetSpaceWidth(aWidth); - } - - PRUnichar buf[1]; - buf[0] = ch; - return GetWidth(buf, 1, aWidth, aFontID); -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP -nsRenderingContextMac::GetWidthInternal(const char* aString, PRUint32 aLength, nscoord& aWidth) -{ - SetupPortState(); - - // set native font and attributes - SetPortTextState(); - -// below is a bad assert, aString is not guaranteed null terminated... -// NS_ASSERTION(strlen(aString) >= aLength, "Getting width on garbage string"); - - // measure text - short textWidth = ::TextWidth(aString, 0, aLength); - aWidth = NSToCoordRound(float(textWidth) * mP2T); - - return NS_OK; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID) -{ - SetupPortState(); - - nsresult rv = SetPortTextState(); - if (NS_FAILED(rv)) - return rv; - - PRBool rtlText = mRightToLeftText; - - rv = mUnicodeRenderingToolkit.PrepareToDraw(mP2T, mContext, mGS, mPort, rtlText); - if (NS_SUCCEEDED(rv)) - rv = mUnicodeRenderingToolkit.GetWidth(aString, aLength, aWidth, aFontID); - - return rv; -} - -//------------------------------------------------------------------------ - -NS_IMETHODIMP -nsRenderingContextMac::GetTextDimensionsInternal(const char* aString, PRUint32 aLength, - nsTextDimensions& aDimensions) -{ - nsresult rv= GetWidth(aString, aLength, aDimensions.width); - if (NS_SUCCEEDED(rv) && (mGS->mFontMetrics)) - { - mGS->mFontMetrics->GetMaxAscent(aDimensions.ascent); - mGS->mFontMetrics->GetMaxDescent(aDimensions.descent); - } - return rv; -} - -NS_IMETHODIMP -nsRenderingContextMac::GetTextDimensionsInternal(const PRUnichar* aString, PRUint32 aLength, - nsTextDimensions& aDimensions, PRInt32* aFontID) -{ - SetupPortState(); - - nsresult rv = SetPortTextState(); - if (NS_FAILED(rv)) - return rv; - - PRBool rtlText = mRightToLeftText; - - rv = mUnicodeRenderingToolkit.PrepareToDraw(mP2T, mContext, mGS, mPort, rtlText); - if (NS_SUCCEEDED(rv)) - rv = mUnicodeRenderingToolkit.GetTextDimensions(aString, aLength, aDimensions, aFontID); - - return rv; -} - -#pragma mark - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::DrawStringInternal(const char *aString, PRUint32 aLength, - nscoord aX, nscoord aY, - const nscoord* aSpacing) -{ - SetupPortState(); - - PRInt32 x = aX; - PRInt32 y = aY; - - if (mGS->mFontMetrics) { - // set native font and attributes - SetPortTextState(); - } - - mGS->mTMatrix.TransformCoord(&x,&y); - - ::MoveTo(x,y); - if ( aSpacing == NULL ) - ::DrawText(aString,0,aLength); - else - { - int buffer[STACK_THRESHOLD]; - int* spacing = (aLength <= STACK_THRESHOLD ? buffer : new int[aLength]); - if (spacing) - { - mGS->mTMatrix.ScaleXCoords(aSpacing, aLength, spacing); - PRInt32 currentX = x; - for (PRUint32 i = 0; i < aLength; i++) - { - ::DrawChar(aString[i]); - currentX += spacing[i]; - ::MoveTo(currentX, y); - } - if (spacing != buffer) - delete[] spacing; - } - else - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - - - - -//------------------------------------------------------------------------ -NS_IMETHODIMP nsRenderingContextMac::DrawStringInternal(const PRUnichar *aString, PRUint32 aLength, - nscoord aX, nscoord aY, PRInt32 aFontID, - const nscoord* aSpacing) -{ - SetupPortState(); - - nsresult rv = SetPortTextState(); - if (NS_FAILED(rv)) - return rv; - - NS_PRECONDITION(mGS->mFontMetrics != nsnull, "No font metrics in SetPortTextState"); - - if (nsnull == mGS->mFontMetrics) - return NS_ERROR_NULL_POINTER; - - PRBool rtlText = mRightToLeftText; - - rv = mUnicodeRenderingToolkit.PrepareToDraw(mP2T, mContext, mGS, mPort, rtlText); - if (NS_SUCCEEDED(rv)) - rv = mUnicodeRenderingToolkit.DrawString(aString, aLength, aX, aY, aFontID, aSpacing); - - return rv; -} - - -#pragma mark - -//------------------------------------------------------------------------ - -NS_IMETHODIMP nsRenderingContextMac::InvertRect(const nsRect& aRect) -{ - return InvertRect(aRect.x, aRect.y, aRect.width, aRect.height); -} - -NS_IMETHODIMP nsRenderingContextMac::InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - SetupPortState(); - - nscoord x,y,w,h; - Rect therect; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mGS->mTMatrix.TransformCoord(&x, &y, &w, &h); - ::SetRect(&therect, pinToShort(x), pinToShort(y), pinToShort(x + w), pinToShort(y + h)); - ::InvertRect(&therect); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextMac::FlushRect(const nsRect& aRect) -{ - return FlushRect(aRect.x, aRect.y, aRect.width, aRect.height); -} - -NS_IMETHODIMP -nsRenderingContextMac::FlushRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - return NS_OK; -} - -#ifdef MOZ_MATHML - -NS_IMETHODIMP -nsRenderingContextMac::GetBoundingMetricsInternal(const char* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsRenderingContextMac::GetBoundingMetricsInternal(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics, - PRInt32* aFontID) -{ - SetupPortState(); - - nsresult rv = SetPortTextState(); - if(NS_FAILED(rv)) - return rv; - - PRBool rtlText = mRightToLeftText; - - rv = mUnicodeRenderingToolkit.PrepareToDraw(mP2T, mContext, mGS, mPort, rtlText); - if(NS_SUCCEEDED(rv)) - rv = mUnicodeRenderingToolkit.GetTextBoundingMetrics(aString, aLength, aBoundingMetrics, aFontID); - - return rv; -} - - -#endif /* MOZ_MATHML */ - - -NS_IMETHODIMP -nsRenderingContextMac::SetRightToLeftText(PRBool aIsRTL) -{ - mRightToLeftText = aIsRTL; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextMac::GetRightToLeftText(PRBool* aIsRTL) -{ - *aIsRTL = mRightToLeftText; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextMac::DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect) -{ - SetupPortState(); - return nsRenderingContextImpl::DrawImage(aImage, aSrcRect, aDestRect); -} - -NS_IMETHODIMP -nsRenderingContextMac::DrawTile(imgIContainer *aImage, - nscoord aXImageStart, nscoord aYImageStart, - const nsRect * aTargetRect) -{ - SetupPortState(); - return nsRenderingContextImpl::DrawTile(aImage, aXImageStart, aYImageStart, aTargetRect); -} - -#pragma mark - - -PRBool -nsRenderingContextMac::OnTigerOrLater() -{ - static PRBool sInitVer = PR_FALSE; - static PRBool sOnTigerOrLater = PR_FALSE; - if (!sInitVer) { - long version; - OSErr err = ::Gestalt(gestaltSystemVersion, &version); - sOnTigerOrLater = ((err == noErr) && (version >= 0x00001040)); - sInitVer = PR_TRUE; - } - return sOnTigerOrLater; -} - -void* -nsRenderingContextMac::GetNativeGraphicData(GraphicDataType aType) -{ - if (aType == NATIVE_MAC_THING) { - return mPort; - } - - return nsnull; -} diff --git a/gfx/src/mac/nsRenderingContextMac.h b/gfx/src/mac/nsRenderingContextMac.h deleted file mode 100644 index 436eb7f453bd..000000000000 --- a/gfx/src/mac/nsRenderingContextMac.h +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRenderingContextMac_h___ -#define nsRenderingContextMac_h___ - -#include -#include - -#include "nsRenderingContextImpl.h" -#include "nsDrawingSurfaceMac.h" -#include "nsUnicodeRenderingToolkit.h" - -#include "nsVoidArray.h" - -class nsIFontMetrics; -class nsIDeviceContext; -class nsIRegion; -class nsFont; -class nsTransform2D; - -class nsGraphicState; -class nsUnicodeFallbackCache; - -//------------------------------------------------------------------------ - - -class nsRenderingContextMac : public nsRenderingContextImpl -{ -public: - nsRenderingContextMac(); - ~nsRenderingContextMac(); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow); - NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface); - - NS_IMETHOD Reset(void); - NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext); - NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, - PRUint32 aFlags); - NS_IMETHOD UnlockDrawingSurface(void); - NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface); - NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface); - NS_IMETHOD GetHints(PRUint32& aResult); - NS_IMETHOD PushState(void); - NS_IMETHOD PopState(void); - NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible); - NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine); - NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid); - NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine); - NS_IMETHOD CopyClipRegion(nsIRegion &aRegion); - NS_IMETHOD GetClipRegion(nsIRegion **aRegion); - NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle); - NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle); - NS_IMETHOD SetColor(nscolor aColor); - NS_IMETHOD GetColor(nscolor &aColor) const; - NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup); - NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics); - NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics); - NS_IMETHOD Translate(nscoord aX, nscoord aY); - NS_IMETHOD Scale(float aSx, float aSy); - NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform); - NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface); - NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS); - NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1); - NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints); - NS_IMETHOD DrawRect(const nsRect& aRect); - NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - NS_IMETHOD FillRect(const nsRect& aRect); - NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - NS_IMETHOD InvertRect(const nsRect& aRect); - NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - NS_IMETHOD FlushRect(const nsRect& aRect); - NS_IMETHOD FlushRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints); - NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints); - NS_IMETHOD DrawEllipse(const nsRect& aRect); - NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - NS_IMETHOD FillEllipse(const nsRect& aRect); - NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - NS_IMETHOD DrawArc(const nsRect& aRect,float aStartAngle, float aEndAngle); - NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,float aStartAngle, float aEndAngle); - NS_IMETHOD FillArc(const nsRect& aRect,float aStartAngle, float aEndAngle); - NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,float aStartAngle, float aEndAngle); - - NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth, - PRInt32 *aFontID = nsnull) - { return nsRenderingContextImpl::GetWidth(aString, aWidth, aFontID); } - NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth) - { return nsRenderingContextImpl::GetWidth(aString, aWidth); } - NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength, - nscoord& aWidth) - { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth); } - NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, - nscoord &aWidth, PRInt32 *aFontID = nsnull) - { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth, aFontID); } - NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY, - PRInt32 aFontID = -1, - const nscoord* aSpacing = nsnull) - { return nsRenderingContextImpl::DrawString(aString, aX, aY, aFontID, aSpacing); } - - NS_IMETHOD GetWidth(char aC, nscoord &aWidth); - NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth, - PRInt32 *aFontID); - - NS_IMETHOD GetWidthInternal(const char *aString, PRUint32 aLength, nscoord &aWidth); - NS_IMETHOD GetWidthInternal(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, - PRInt32 *aFontID); - - NS_IMETHOD DrawStringInternal(const char *aString, PRUint32 aLength, - nscoord aX, nscoord aY, - const nscoord* aSpacing); - NS_IMETHOD DrawStringInternal(const PRUnichar *aString, PRUint32 aLength, - nscoord aX, nscoord aY, - PRInt32 aFontID, - const nscoord* aSpacing); - - NS_IMETHOD GetTextDimensionsInternal(const char* aString, PRUint32 aLength, - nsTextDimensions& aDimensions); - NS_IMETHOD GetTextDimensionsInternal(const PRUnichar *aString, PRUint32 aLength, - nsTextDimensions& aDimensions,PRInt32 *aFontID); - -#ifdef MOZ_MATHML - /** - * Returns metrics (in app units) of an 8-bit character string - */ - NS_IMETHOD GetBoundingMetricsInternal(const char* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics); - - /** - * Returns metrics (in app units) of a Unicode character string - */ - NS_IMETHOD GetBoundingMetricsInternal(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics, - PRInt32* aFontID = nsnull); - -#endif /* MOZ_MATHML */ - - virtual PRInt32 GetMaxStringLength(); - - NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, - const nsRect &aDestBounds, PRUint32 aCopyFlags); - - virtual void* GetNativeGraphicData(GraphicDataType aType); - - /** - * Let the device context know whether we want text reordered with - * right-to-left base direction - */ - NS_IMETHOD SetRightToLeftText(PRBool aIsRTL); - NS_IMETHOD GetRightToLeftText(PRBool* aIsRTL); - - NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect); - NS_IMETHOD DrawTile(imgIContainer *aImage, - nscoord aXImageStart, nscoord aYImageStart, - const nsRect * aTargetRect); - - //locals - nsresult SetPortTextState(); - nsresult Init(nsIDeviceContext* aContext, CGrafPtr aPort); - - // for determining if we're running on at least Mac OS X 10.4.0 - static PRBool OnTigerOrLater(); - -protected: - enum GraphicStateChanges { - kFontChanged = (1 << 0), - kColorChanged = (1 << 1), - kClippingChanged = (1 << 2), - - kEverythingChanged = 0xFFFFFFFF - }; - - void SelectDrawingSurface(nsDrawingSurfaceMac* aSurface, PRUint32 aChanges = kEverythingChanged); - void SetupPortState(); - -protected: - float mP2T; // Pixel to Twip conversion factor - nsIDeviceContext * mContext; - - nsDrawingSurfaceMac* mFrontSurface; - nsDrawingSurfaceMac* mCurrentSurface; // pointer to the current surface - - CGrafPtr mPort; // current grafPort - shortcut for mCurrentSurface->GetPort() - nsGraphicState * mGS; // current graphic state - shortcut for mCurrentSurface->GetGS() - nsUnicodeRenderingToolkit mUnicodeRenderingToolkit; - nsAutoVoidArray mGSStack; // GraphicStates stack, used for PushState/PopState - PRUint32 mChanges; // bit mask of attributes that have changed since last Push(). - PRBool mRightToLeftText; -}; - -#endif /* nsRenderingContextMac_h___ */ diff --git a/gfx/src/mac/nsUnicodeBlock.h b/gfx/src/mac/nsUnicodeBlock.h deleted file mode 100644 index f519397b5442..000000000000 --- a/gfx/src/mac/nsUnicodeBlock.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsUnicodeBlock_h__ -#define nsUnicodeBlock_h__ - -#include - -enum -{ - smPseudoUnicode = smUninterp + 0, - smPseudoUserDef = smUninterp + 1, - smPseudoTotalScripts = smUninterp + 2 -}; - -typedef enum { - // blocks which always use the same script to render, regardless of the order of fonts - kGreek = 0, - kCyrillic, - kArmenian, - kHebrew, - kArabic, - kDevanagari, - kBengali, - kGurmukhi, - kGujarati, - kOriya, - kTamil, - kTelugu, - kKannada, - kMalayalam, - kThai, - kLao, - kTibetan, - kGeorgian, - kHangul, - kBopomofo, - kEthiopic, - kKhmer, - kCanadian, - kUserDefinedEncoding, - - kUnicodeBlockFixedScriptMax, - - // blocks which may use different script to render, depend on the order of fonts - kBasicLatin = kUnicodeBlockFixedScriptMax, - kLatin , - kCJKMisc, - kHiraganaKatakana, - kCJKIdeographs, - kOthers, - - kUnicodeBlockSize, - - kUnicodeBlockVarScriptMax = kUnicodeBlockSize - kUnicodeBlockFixedScriptMax -} nsUnicodeBlock; - -#endif nsUnicodeBlock_h__ diff --git a/gfx/src/mac/nsUnicodeFallbackCache.h b/gfx/src/mac/nsUnicodeFallbackCache.h deleted file mode 100644 index 5401b473df9c..000000000000 --- a/gfx/src/mac/nsUnicodeFallbackCache.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsUnicodeFallbackCache_h__ -#define nsUnicodeFallbackCache_h__ -#include "prtypes.h" -#include "plhash.h" -#include -#include "nsDebug.h" -#include "nscore.h" - -class nsUnicodeFallbackCache -{ -public: - nsUnicodeFallbackCache() - { - mTable = PL_NewHashTable(8, (PLHashFunction)HashKey, - (PLHashComparator)CompareKeys, - (PLHashComparator)CompareValues, - nsnull, nsnull); - mCount = 0; - }; - ~nsUnicodeFallbackCache() - { - if (mTable) - { - PL_HashTableEnumerateEntries(mTable, FreeHashEntries, 0); - PL_HashTableDestroy(mTable); - mTable = nsnull; - } - }; - - inline PRBool Get(PRUnichar aChar, ScriptCode& oScript) - { - ScriptCode ret = (ScriptCode) - NS_PTR_TO_INT32(PL_HashTableLookup(mTable, (void*)aChar)); - oScript = 0x00FF & ret ; - return 0x00 != (0xFF00 & ret); - }; - - inline void Set(PRUnichar aChar, ScriptCode aScript) - { - PL_HashTableAdd(mTable,(void*) aChar, (void*)(aScript | 0xFF00)); - mCount ++; - }; - - inline static nsUnicodeFallbackCache* GetSingleton() - { - if(! gSingleton) - gSingleton = new nsUnicodeFallbackCache(); - return gSingleton; - } -private: - inline static PR_CALLBACK PLHashNumber HashKey(const void *aKey) - { - return (PRUnichar) NS_PTR_TO_INT32(aKey); - }; - - inline static PR_CALLBACK PRIntn CompareKeys(const void *v1, const void *v2) - { - return (((PRUnichar ) NS_PTR_TO_INT32(v1)) == - ((PRUnichar ) NS_PTR_TO_INT32(v2))); - }; - - inline static PR_CALLBACK PRIntn CompareValues(const void *v1, const void *v2) - { - return (((ScriptCode) NS_PTR_TO_INT32(v1)) == - ((ScriptCode) NS_PTR_TO_INT32(v2))); - }; - inline static PR_CALLBACK PRIntn FreeHashEntries(PLHashEntry *he, PRIntn italic, void *arg) - { - return HT_ENUMERATE_REMOVE; - }; - - struct PLHashTable* mTable; - PRUint32 mCount; - - static nsUnicodeFallbackCache* gSingleton; -}; -#endif nsUnicodeFallbackCache_h__ diff --git a/gfx/src/mac/nsUnicodeFontMappingCache.h b/gfx/src/mac/nsUnicodeFontMappingCache.h deleted file mode 100644 index a344c8256b51..000000000000 --- a/gfx/src/mac/nsUnicodeFontMappingCache.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsUnicodeFontMappingCache_h__ -#define nsUnicodeFontMappingCache_h__ -#include "plhash.h" -#include "nsCRT.h" -#include "nsString.h" -#include "nsUnicodeFontMappingMac.h" - -class nsUnicodeFontMappingCache -{ -public: - nsUnicodeFontMappingCache() - { - mTable = PL_NewHashTable(8, (PLHashFunction)HashKey, - (PLHashComparator)CompareKeys, - (PLHashComparator)CompareValues, - nsnull, nsnull); - mCount = 0; - }; - ~nsUnicodeFontMappingCache() - { - if (mTable) - { - PL_HashTableEnumerateEntries(mTable, FreeHashEntries, 0); - PL_HashTableDestroy(mTable); - mTable = nsnull; - } - }; - - inline PRBool Get(const nsString& key, nsUnicodeFontMappingMac **item) - { - *item = (nsUnicodeFontMappingMac*)PL_HashTableLookup(mTable, &key); - return nsnull != (*item); - }; - inline void Set(const nsString& key, nsUnicodeFontMappingMac *item) - { - nsString *newKey = new nsString(key); - if (newKey) - { - PL_HashTableAdd(mTable, newKey, item); - mCount ++; - } - }; - -private: - inline static PR_CALLBACK PLHashNumber HashKey(const void *aKey) - { - nsString* key = (nsString*)aKey; - return nsCRT::HashCode(key->get()); - }; - inline static PR_CALLBACK PRIntn CompareKeys(const void *v1, const void *v2) - { - return ((nsString *)v1) -> Equals(* ((nsString *)v2)); - }; - inline static PR_CALLBACK PRIntn CompareValues(const void *v1, const void *v2) - { - return ((nsUnicodeFontMappingMac*)v1) -> Equals(* ((nsUnicodeFontMappingMac*)v2)); - }; - inline static PR_CALLBACK PRIntn FreeHashEntries(PLHashEntry *he, PRIntn italic, void *arg) - { - delete (nsString*)he->key; - delete (nsUnicodeFontMappingMac*)he->value; - return HT_ENUMERATE_REMOVE; - }; - - struct PLHashTable* mTable; - PRUint32 mCount; -}; - -#endif /* nsUnicodeFontMappingCache_h__ */ diff --git a/gfx/src/mac/nsUnicodeFontMappingMac.cpp b/gfx/src/mac/nsUnicodeFontMappingMac.cpp deleted file mode 100644 index 91a9454e3802..000000000000 --- a/gfx/src/mac/nsUnicodeFontMappingMac.cpp +++ /dev/null @@ -1,705 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include "nsDeviceContextMac.h" -#include "plhash.h" -#include "nsCRT.h" - -#include "nsUnicodeFontMappingMac.h" -#include "nsUnicodeFontMappingCache.h" -#include "nsUnicodeMappingUtil.h" -#include "nsIUnicodeEncoder.h" -#include "nsCompressedCharMap.h" -#include "nsMacUnicodeFontInfo.h" - -#include - -//------------------------------------------------------------------------ -#include "ignorable.x-ccmap" -DEFINE_X_CCMAP(gIgnorableCCMapExt, /* nothing */); - -//------------------------------------------------------------------------ -static UnicodeToTextInfo gConverters[32] = { - nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, - nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, - nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, - nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull, nsnull -}; -//------------------------------------------------------------------------ -static UnicodeToTextInfo -GetConverterByScript(ScriptCode sc) -{ - // because the Mac QuickDraw BIDI support are quite different from other platform - // we try not to use them and use the XP BIDI feature - // those text will be drawn by ATSUI intead one character at a time - if ((sc == smArabic) || (sc == smHebrew)) - return nsnull; - NS_PRECONDITION(sc < 32, "illegal script id"); - if(sc >= 32) - return nsnull; - if (gConverters[sc] != nsnull) { - return gConverters[sc]; - } - OSStatus err = noErr; - - // - TextEncoding scriptEncoding; - err = ::UpgradeScriptInfoToTextEncoding(sc, kTextLanguageDontCare, kTextRegionDontCare, nsnull, &scriptEncoding); - if ( noErr == err ) - err = ::CreateUnicodeToTextInfoByEncoding(scriptEncoding, &gConverters[sc] ); - - if (noErr != err) - gConverters[sc] = nsnull; - return gConverters[sc]; -} - - -class nsUnicodeFontMappingEntry -{ -public: - nsUnicodeFontMappingEntry( - nsIUnicodeEncoder *aConverter, - PRUint16 *aCCMap, - short aFontNum, - ScriptCode aScript) - : mConverter(aConverter), - mCCMap(aCCMap), - mFontNum(aFontNum), - mScript(aScript) - { - NS_ASSERTION(aConverter || aScript != BAD_SCRIPT, "internal error"); - } - - PRBool Convert( - const PRUnichar *aString, - ByteCount aStringLength, - char *aBuffer, - ByteCount aBufferLength, - ByteCount& oActualLength, - ByteCount& oBytesRead, - OptionBits opts) - { - if(mConverter) - { - oActualLength = aBufferLength; - if(NS_SUCCEEDED(mConverter->Convert(aString, (PRInt32*) &aStringLength, aBuffer, - (PRInt32*) &oActualLength)) && oActualLength) - { - oBytesRead = 2 * aStringLength; - return PR_TRUE; - } - return PR_FALSE; - } - - UnicodeToTextInfo converter = GetConverterByScript(mScript); - if(converter) - { - OSStatus err = ::ConvertFromUnicodeToText(converter, 2 * aStringLength, - (ConstUniCharArrayPtr) aString, - opts, 0, NULL, 0, NULL, - aBufferLength, &oBytesRead, &oActualLength, - (LogicalAddress) aBuffer); - - return (oActualLength > 0 ? PR_TRUE : PR_FALSE); - } - return PR_FALSE; - } - - PRUint16* GetCCMap() - { - return mCCMap; - } - - short GetFontNum() - { - return mFontNum; - } - -private: - nsCOMPtr mConverter; - PRUint16 *mCCMap; // we don't own this buffer, so don't free it - short mFontNum; - ScriptCode mScript; -}; - - -//-------------------------------------------------------------------------- - -static void FillVarBlockToScript( PRInt8 script, PRInt8 *aMap) -{ - if(BAD_SCRIPT == aMap[kBasicLatin - kUnicodeBlockFixedScriptMax]) - aMap[kBasicLatin - kUnicodeBlockFixedScriptMax] = script; - if(BAD_SCRIPT == aMap[kOthers - kUnicodeBlockFixedScriptMax]) - aMap[kOthers - kUnicodeBlockFixedScriptMax] = script; - switch( script ) - { - case smRoman: - case smCentralEuroRoman: - case smVietnamese: - if(BAD_SCRIPT == aMap[kLatin - kUnicodeBlockFixedScriptMax]) - aMap[kLatin - kUnicodeBlockFixedScriptMax] = script; - break; - case smTradChinese: - if(BAD_SCRIPT == aMap[kCJKMisc - kUnicodeBlockFixedScriptMax]) - aMap[kCJKMisc - kUnicodeBlockFixedScriptMax] = script; - if(BAD_SCRIPT == aMap[kCJKIdeographs - kUnicodeBlockFixedScriptMax]) - aMap[kCJKIdeographs - kUnicodeBlockFixedScriptMax] = script; - break; - case smKorean: - case smJapanese: - case smSimpChinese: - if(BAD_SCRIPT == aMap[kCJKMisc - kUnicodeBlockFixedScriptMax]) - aMap[kCJKMisc - kUnicodeBlockFixedScriptMax] = script; - if(BAD_SCRIPT == aMap[kCJKIdeographs - kUnicodeBlockFixedScriptMax]) - aMap[kCJKIdeographs - kUnicodeBlockFixedScriptMax] = script; - if(BAD_SCRIPT == aMap[kHiraganaKatakana - kUnicodeBlockFixedScriptMax]) - aMap[kHiraganaKatakana - kUnicodeBlockFixedScriptMax] = script; - break; - }; -} - -struct MyFontEnumData { - MyFontEnumData(nsIDeviceContext* aDC, nsUnicodeFontMappingMac* fontMapping) : mContext(aDC) { - mFontMapping = fontMapping; - }; - nsIDeviceContext* mContext; - nsUnicodeFontMappingMac* mFontMapping; -}; -//-------------------------------------------------------------------------- - -PRBool nsUnicodeFontMappingMac::FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData) -{ - MyFontEnumData* data = (MyFontEnumData*)aData; - nsUnicodeMappingUtil * info = nsUnicodeMappingUtil::GetSingleton(); - NS_PRECONDITION(info != nsnull, "out of memory"); - if (aGeneric) - { - if(nsnull == info) - return PR_FALSE; - nsGenericFontNameType type = info->MapGenericFontNameType(aFamily); - - if( type != kUnknownGenericFontName) { - for(ScriptCode script = 0; script < 32 ; script++) - { - const nsString* fontName = info->GenericFontNameForScript(script,type); - if(nsnull != fontName) { - short fontNum; - nsDeviceContextMac::GetMacFontNumber(*fontName, fontNum); - - if(0 != fontNum) - { - nsUnicodeFontMappingEntry* entry = new nsUnicodeFontMappingEntry(nsnull, nsnull, fontNum, script); - if (entry) - data->mFontMapping->mFontList.AppendElement(entry); - - if (BAD_FONT_NUM == data->mFontMapping->mScriptFallbackFontIDs[ script ]) - data->mFontMapping->mScriptFallbackFontIDs[ script ] = fontNum; - // since this is a generic font name, it won't impact the order of script we used - } - } - } - } - } - else - { - nsAutoString realFace; - PRBool aliased; - data->mContext->GetLocalFontName(aFamily, realFace, aliased); - if (aliased || (NS_OK == data->mContext->CheckFontExistence(realFace))) - { - short fontNum; - nsDeviceContextMac::GetMacFontNumber(realFace, fontNum); - - if(0 != fontNum) { - nsCOMPtr converter; - PRUint16 *ccmap = nsnull; - - // if this fails, aConverter & aCCMap will be nsnull - nsMacUnicodeFontInfo::GetConverterAndCCMap(realFace, getter_AddRefs(converter), &ccmap); - - ScriptCode script = (converter ? BAD_SCRIPT : ::FontToScript(fontNum)); - - nsUnicodeFontMappingEntry* entry = new nsUnicodeFontMappingEntry(converter, ccmap, fontNum, script); - if(entry) - data->mFontMapping->mFontList.AppendElement(entry); - - // only fill in this information for non-symbolic fonts - if(!converter) - { - if(BAD_FONT_NUM == data->mFontMapping->mScriptFallbackFontIDs[ script ]) - data->mFontMapping->mScriptFallbackFontIDs[ script ] = fontNum; - FillVarBlockToScript( script, data->mFontMapping->mPrivBlockToScript); - } - } - } - } - return PR_TRUE; -} - -PRBool nsUnicodeFontMappingMac::ConvertUnicodeToGlyphs(short aFontNum, - const PRUnichar* aString, ByteCount aStringLength, - char *aBuffer, ByteCount aBufferLength, ByteCount& oActualLength, - ByteCount& oBytesRead, OptionBits opts) -{ - for(PRInt32 i = 0; i < mFontList.Count(); i++) - { - nsUnicodeFontMappingEntry* entry = (nsUnicodeFontMappingEntry*) mFontList[i]; - if(aFontNum == entry->GetFontNum()) - return entry->Convert(aString, aStringLength, aBuffer, aBufferLength, - oActualLength, oBytesRead, opts); - } - return PR_FALSE; -} - - -//-------------------------------------------------------------------------- -nsUnicodeMappingUtil *nsUnicodeFontMappingMac::gUtil = nsnull; - -//-------------------------------------------------------------------------- - -void nsUnicodeFontMappingMac::InitByFontFamily(nsFont* aFont, nsIDeviceContext *aDeviceContext) -{ - MyFontEnumData fontData(aDeviceContext, this); - aFont->EnumerateFamilies(nsUnicodeFontMappingMac::FontEnumCallback, &fontData); -} -//-------------------------------------------------------------------------- - -void nsUnicodeFontMappingMac::processOneLangRegion(const char* aLanguage, const char* aRegion ) -{ - if ((! nsCRT::strcmp(aLanguage,"zh")) && - ((! nsCRT::strcmp(aRegion,"TW")) || (! nsCRT::strcmp(aRegion,"HK")))) - { - FillVarBlockToScript(smTradChinese, mPrivBlockToScript); - } - else if(! nsCRT::strcmp(aLanguage,"zh")) - { - FillVarBlockToScript(smSimpChinese, mPrivBlockToScript); - } - else if(! nsCRT::strcmp(aLanguage,"ko")) - { - FillVarBlockToScript(smKorean, mPrivBlockToScript); - } - else if(! nsCRT::strcmp(aLanguage,"ja")) - { - FillVarBlockToScript(smJapanese, mPrivBlockToScript); - } -} -//-------------------------------------------------------------------------- -PRBool nsUnicodeFontMappingMac::ScriptMapInitComplete() -{ - PRInt32 i; - for(i = kUnicodeBlockFixedScriptMax ; i < kUnicodeBlockSize; i++) { - if(BAD_SCRIPT == mPrivBlockToScript[i - kUnicodeBlockFixedScriptMax]) - return PR_FALSE; - } - return PR_TRUE; -} -//-------------------------------------------------------------------------- - -const PRUnichar kA = PRUnichar('A'); -const PRUnichar kZ = PRUnichar('Z'); -const PRUnichar ka = PRUnichar('a'); -const PRUnichar kz = PRUnichar('z'); -const PRUnichar kComma = PRUnichar(','); -const PRUnichar kUnderline = PRUnichar('_'); -const PRUnichar kSpace = PRUnichar(' '); -const PRUnichar kNullCh = PRUnichar('\0'); -//-------------------------------------------------------------------------- - -void nsUnicodeFontMappingMac::InitByLANG(const nsString& aLANG) -{ - // do not countinue if there are no difference to look at the lang tag - if( ScriptMapInitComplete() ) - return; - const PRUnichar *p = aLANG.get(); - PRUint32 len = aLANG.Length(); - char language[3]; - char region[3]; - language[2] = region[2]= '\0';; - language[0]= language[1] = region[0]= region[1] = ' '; - PRUint32 state = 0; - - for(PRUint32 i = 0; (state != -1) && (i < len); i++, p++) - { - switch (state) { - case 0: - if(( ka <= *p) && (*p <= kz )) { - language[state++] = (char)*p; - } else if( kSpace == *p) { - state = 0; - } else { - state = -1; - } - break; - case 1: - if(( ka <= *p) && (*p <= kz )) { - language[state++] = (char)*p; - } else { - state = -1; - } - break; - case 2: - if(kComma == *p) { - processOneLangRegion(language, region); - return; - } else if(kUnderline == *p) { - state = 3; - } else { - state = -1; - } - break; - case 3: - case 4: - if(( kA <= *p) && (*p <= kZ )) { - region[state - 3] = (char)*p; - state++; - } else { - state = -1; - } - break; - case 5: - if(kComma == *p) { - processOneLangRegion(language, region); - return; - } else { - state = -1; - } - break; - }; - } - if((2 == state) || (5 == state)) { - processOneLangRegion(language, region); - } -} -//-------------------------------------------------------------------------- -void nsUnicodeFontMappingMac::InitByLangGroup(const nsString& aLangGroup) -{ - // do not continue if there are no difference to look at the document Charset - if( ScriptMapInitComplete() ) - return; - if(aLangGroup.LowerCaseEqualsLiteral("x-western")) - { - FillVarBlockToScript(smRoman, mPrivBlockToScript); - } else if(aLangGroup.LowerCaseEqualsLiteral("zh-cn")) - { - FillVarBlockToScript(smSimpChinese, mPrivBlockToScript); - } else if(aLangGroup.LowerCaseEqualsLiteral("ko")) - { - FillVarBlockToScript(smKorean, mPrivBlockToScript); - } else if(aLangGroup.LowerCaseEqualsLiteral("zh-tw") || - aLangGroup.LowerCaseEqualsLiteral("zh-hk")) - { - FillVarBlockToScript(smTradChinese, mPrivBlockToScript); - } else if(aLangGroup.LowerCaseEqualsLiteral("ja")) - { - FillVarBlockToScript(smJapanese, mPrivBlockToScript); - } -} -//-------------------------------------------------------------------------- - -void nsUnicodeFontMappingMac::InitDefaultScriptFonts() -{ - for(PRInt32 i = 0 ; i < smPseudoTotalScripts; i++) - { - // copy from global mapping - if(BAD_FONT_NUM == mScriptFallbackFontIDs[i]) - mScriptFallbackFontIDs[i] = gUtil->ScriptFont(i); - } - for(PRInt32 k = kUnicodeBlockFixedScriptMax ; k < kUnicodeBlockSize; k++) - { - // copy from global mapping - if(BAD_SCRIPT == mPrivBlockToScript[k - kUnicodeBlockFixedScriptMax]) - mPrivBlockToScript[k - kUnicodeBlockFixedScriptMax] = gUtil->BlockToScript((nsUnicodeBlock) k); - } -} -//-------------------------------------------------------------------------- - -nsUnicodeFontMappingMac::nsUnicodeFontMappingMac( - nsFont* aFont, nsIDeviceContext *aDeviceContext, - const nsString& aLangGroup, const nsString& aLANG) -{ - PRInt32 i; - if (!gUtil) - gUtil = nsUnicodeMappingUtil::GetSingleton(); - for(i = kUnicodeBlockFixedScriptMax ; i < kUnicodeBlockSize; i++) - mPrivBlockToScript[i - kUnicodeBlockFixedScriptMax] = BAD_SCRIPT; - for(i = 0 ; i < smPseudoTotalScripts; i++) - mScriptFallbackFontIDs[i] = BAD_FONT_NUM; - - InitByFontFamily(aFont, aDeviceContext); - InitByLANG(aLANG); - InitByLangGroup(aLangGroup); - InitDefaultScriptFonts(); -} -//-------------------------------------------------------------------------- - -nsUnicodeFontMappingMac::~nsUnicodeFontMappingMac() -{ - for(PRInt32 i = 0; i < mFontList.Count(); i++) - { - nsUnicodeFontMappingEntry* entry = (nsUnicodeFontMappingEntry*) mFontList[i]; - delete entry; - } -} -//-------------------------------------------------------------------------- - -PRBool nsUnicodeFontMappingMac::Equals(const nsUnicodeFontMappingMac& aMap) -{ - PRUint32 i; - if(&aMap != this) { - for( i=0; i < smPseudoTotalScripts; i++) - { - if(mScriptFallbackFontIDs[i] != aMap.mScriptFallbackFontIDs[i]) - return PR_FALSE; - } - for( i=0; i < kUnicodeBlockVarScriptMax; i++) - { - if(mPrivBlockToScript[i] != aMap.mPrivBlockToScript[i]) - return PR_FALSE; - } - } - return PR_TRUE; -} - -//-------------------------------------------------------------------------- - -short nsUnicodeFontMappingMac::GetFontID(PRUnichar aChar) { - // initialize to bogus values - short firstSymbolicFont = BAD_FONT_NUM, firstNonSymbolicFont = BAD_FONT_NUM; - PRInt32 firstSymbolicFontIndex = -1; - - // Trap invisible chars - if (CCMAP_HAS_CHAR_EXT(gIgnorableCCMapExt, aChar)) { - return IGNORABLE_FONT_NUM; - } - - // find the first symbolic font that has a glyph for aChar - // and if there is one, remember it's index in the font list - for(PRInt32 i = 0; i < mFontList.Count(); i++) - { - nsUnicodeFontMappingEntry* entry = (nsUnicodeFontMappingEntry*) mFontList[i]; - PRUint16 *ccmap = entry->GetCCMap(); - if(ccmap && CCMAP_HAS_CHAR(ccmap, aChar)) - { - firstSymbolicFontIndex = i; - firstSymbolicFont = entry->GetFontNum(); - break; - } - } - - // find the first non-symbolic font that has a glyph for aChar - nsUnicodeBlock block = GetBlock(aChar); - if(block < kUnicodeBlockFixedScriptMax) - { - firstNonSymbolicFont = mScriptFallbackFontIDs[gUtil->BlockToScript(block)]; - - // if there was no symbolic font we don't need to loop through the list again - if(firstSymbolicFont == BAD_FONT_NUM) - return firstNonSymbolicFont; - - // find the index of the first non symbolic font in the list and return the - // first font (symbolic or non symbolic) in the list that has a glyph for this char - for(PRInt32 i = 0; i < mFontList.Count(); i++) - { - nsUnicodeFontMappingEntry* entry = (nsUnicodeFontMappingEntry*) mFontList[i]; - if(entry->GetFontNum() == firstNonSymbolicFont) - { - return (firstSymbolicFontIndex < i ? firstSymbolicFont : firstNonSymbolicFont); - } - } - return firstNonSymbolicFont; - } - - return (firstSymbolicFont != BAD_FONT_NUM ? firstSymbolicFont : - mScriptFallbackFontIDs[ mPrivBlockToScript[ block - kUnicodeBlockFixedScriptMax] ]); -} - -//------------------------------------------------------------------------ -static nsUnicodeBlock gU0xxxMap[32]= -{ - kBasicLatin, kLatin, // U+0000 - kLatin, kLatin, // U+0100 - kOthers, kOthers, // U+0200 - kOthers, kGreek, // U+0300 - kCyrillic, kCyrillic, // U+0400 - kArmenian, kOthers, // U+0500 - kArabic, kArabic, // U+0600 - kOthers, kOthers, // U+0700 - kOthers, kOthers, // U+0800 - kDevanagari, kBengali, // U+0900 - kGurmukhi, kGujarati, // U+0a00 - kOriya, kTamil, // U+0b00 - kTelugu, kKannada, // U+0c00 - kMalayalam, kOthers , // U+0d00 - kThai, kLao, // U+0e00 - kTibetan, kTibetan, // U+0f00 -}; -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockU0XXX(PRUnichar aChar) -{ - nsUnicodeBlock res = gU0xxxMap[ (aChar >> 7) & 0x1F]; - if(res == kOthers) { - if((0x0200 <= aChar) && ( aChar <= 0x024F )) res = kLatin; - else if((0x0370 <= aChar) && ( aChar <= 0x037F )) res = kGreek; - else if((0x0580 <= aChar) && ( aChar <= 0x058F )) res = kArmenian; - else if((0x0590 <= aChar) && ( aChar <= 0x05ff )) res = kHebrew; - } - return res; -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockU1XXX(PRUnichar aChar) -{ - switch( aChar & 0x0F00 ) - { - case 0x0000: return kGeorgian; - case 0x0100: return kHangul; - case 0x0e00: return kLatin; - case 0x0f00: return kGreek; - default: - { - if ((0x0200 <= aChar) && ( aChar <= 0x037c)) return kEthiopic; - if ((0x0400 <= aChar) && ( aChar <= 0x0676)) return kCanadian; - if ((0x0780 <= aChar) && ( aChar <= 0x07ff)) return kKhmer; - return kOthers; - } - } -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockU2XXX(PRUnichar aChar) -{ - return kOthers; -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockU3XXX(PRUnichar aChar) -{ - if(aChar < 0x3040) return kCJKMisc; - else if(aChar < 0x3100) return kHiraganaKatakana; - else if(aChar < 0x3130) return kBopomofo; - else if(aChar < 0x3190) return kHangul; - else if(aChar >= 0x3400) return kCJKIdeographs; // Unicode 3.0 - else return kCJKMisc; -} - -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockCJKIdeographs(PRUnichar aChar) -{ - return kCJKIdeographs; -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockHangul(PRUnichar aChar) -{ - return kHangul; -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockUAXXX(PRUnichar aChar) -{ - if(aChar < 0xAC00) return kOthers; - else return kHangul; -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockUDXXX(PRUnichar aChar) -{ - if(aChar < 0xD800) return kHangul; - else return kOthers; -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockUEXXX(PRUnichar aChar) -{ - return kOthers; -} -//-------------------------------------------------------------------------- - -static nsUnicodeBlock GetBlockUFXXX(PRUnichar aChar) -{ - // U+FFxx is used more frequently in the U+Fxxxx block - if(aChar >= 0xff00) - { - if(aChar < 0xff60) return kCJKMisc; - else if(aChar < 0xffA0) return kHiraganaKatakana; - else if(aChar < 0xffe0) return kHangul; - else return kOthers; - } - - // The rest is rarely used, we don't care the performance below. - if((0xf780 <= aChar) && (aChar <= 0xf7ff)) return kUserDefinedEncoding; - else if(aChar < 0xf900) return kOthers; - else if(aChar < 0xfb00) return kCJKIdeographs; - else if(aChar < 0xfb10) return kLatin; - else if(aChar < 0xfb18) return kArmenian; - else if(aChar < 0xfb50) return kHebrew; - else if(aChar < 0xfe20) return kArabic; - else if(aChar < 0xfe70) return kOthers; - else return kArabic; -} -//-------------------------------------------------------------------------- - -typedef nsUnicodeBlock (* getUnicodeBlock)(PRUnichar aChar); -static getUnicodeBlock gAllGetBlock[16] = -{ - &GetBlockU0XXX, // 0 - &GetBlockU1XXX, // 1 - &GetBlockU2XXX, // 2 - &GetBlockU3XXX, // 3 - &GetBlockCJKIdeographs, // 4 - &GetBlockCJKIdeographs, // 5 - &GetBlockCJKIdeographs, // 6 - &GetBlockCJKIdeographs, // 7 - &GetBlockCJKIdeographs, // 8 - &GetBlockCJKIdeographs, // 9 - &GetBlockUAXXX, // a - &GetBlockHangul, // b - &GetBlockHangul, // c - &GetBlockUDXXX, // d - &GetBlockUEXXX, // e - &GetBlockUFXXX // f -}; -//-------------------------------------------------------------------------- - -nsUnicodeBlock nsUnicodeFontMappingMac:: GetBlock(PRUnichar aChar) -{ - return (*(gAllGetBlock[(aChar >> 12)]))(aChar); -} diff --git a/gfx/src/mac/nsUnicodeFontMappingMac.h b/gfx/src/mac/nsUnicodeFontMappingMac.h deleted file mode 100644 index 89a6dd2d515e..000000000000 --- a/gfx/src/mac/nsUnicodeFontMappingMac.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsUnicodeFontMappingMac_h__ -#define nsUnicodeFontMappingMac_h__ - -#include "nsUnicodeBlock.h" -#include "nsIDeviceContext.h" -#include "nsFont.h" -#include "nsVoidArray.h" - -#define BAD_FONT_NUM -1 -#define IGNORABLE_FONT_NUM -2 -#define BAD_SCRIPT 0x7f - -class nsUnicodeMappingUtil; -class nsUnicodeFontMappingCache; - -class nsUnicodeFontMappingMac { -public: - nsUnicodeFontMappingMac(nsFont* aFont, nsIDeviceContext *aDeviceContext, - const nsString& aLangGroup, const nsString& aLANG); - ~nsUnicodeFontMappingMac(); - - short GetFontID(PRUnichar aChar); - inline const short *GetScriptFallbackFonts() { - return mScriptFallbackFontIDs; - } - PRBool Equals(const nsUnicodeFontMappingMac& anther); - - PRBool ConvertUnicodeToGlyphs(short aFontNum, const PRUnichar* aString, - ByteCount aStringLength, char *aBuffer, ByteCount aBufferLength, - ByteCount& oActualLength, ByteCount& oBytesRead, OptionBits opts); - - static PRBool FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData); - -protected: - PRBool ScriptMapInitComplete(); - void InitByFontFamily(nsFont* aFont, nsIDeviceContext *aDeviceContext); - void InitByLANG(const nsString& aLANG); - void InitByLangGroup(const nsString& aLangGroup); - void InitDefaultScriptFonts(); - void processOneLangRegion(const char* aLanguage, const char* aRegion ); - nsUnicodeBlock GetBlock(PRUnichar aChar); -private: - - PRInt8 mPrivBlockToScript [kUnicodeBlockVarScriptMax] ; - short mScriptFallbackFontIDs [smPseudoTotalScripts] ; - nsAutoVoidArray mFontList; - - static nsUnicodeMappingUtil* gUtil; -}; - -#endif /* nsUnicodeFontMappingMac_h__ */ diff --git a/gfx/src/mac/nsUnicodeMappingUtil.cpp b/gfx/src/mac/nsUnicodeMappingUtil.cpp deleted file mode 100644 index ab2351e2dd66..000000000000 --- a/gfx/src/mac/nsUnicodeMappingUtil.cpp +++ /dev/null @@ -1,492 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIServiceManager.h" -#include "nsTextFormatter.h" -#include "nsUnicodeMappingUtil.h" -#include "nsUnicodeFontMappingMac.h" -#include "nsDeviceContextMac.h" -#include "nsReadableUtils.h" -#include "nsString.h" -#include "nsCRT.h" - -//-------------------------------------------------------------------------- - -nsUnicodeMappingUtil *nsUnicodeMappingUtil::gSingleton = nsnull; -//-------------------------------------------------------------------------- - -#ifdef DEBUG -static int gUnicodeMappingUtilCount = 0; -#endif - -int PR_CALLBACK nsUnicodeMappingUtil::PrefChangedCallback( const char* aPrefName, void* instance_data) -{ - //printf("PrefChangeCallback \n"); - nsUnicodeMappingUtil::GetSingleton()->Reset(); - return 0; -} - -nsUnicodeMappingUtil::nsUnicodeMappingUtil() -{ - Init(); - MOZ_COUNT_CTOR(nsUnicodeMappingUtil); -#ifdef DEBUG - ++gUnicodeMappingUtilCount; - NS_ASSERTION(gUnicodeMappingUtilCount == 1, "not singleton"); -#endif -} -void nsUnicodeMappingUtil::Reset() -{ - CleanUp(); - Init(); -} -void nsUnicodeMappingUtil::Init() -{ - InitGenericFontMapping(); - InitFromPref(); - InitScriptFontMapping(); - InitBlockToScriptMapping(); -} -void nsUnicodeMappingUtil::CleanUp() -{ - for(int i= 0 ; i < smPseudoTotalScripts; i ++) { - for(int j=0; j < 5; j++) { - if(mGenericFontMapping[i][j]) - delete mGenericFontMapping[i][j]; - } - } -} -//-------------------------------------------------------------------------- - -nsUnicodeMappingUtil::~nsUnicodeMappingUtil() -{ - CleanUp(); - -#ifdef DEBUG - --gUnicodeMappingUtilCount; -#endif - mPref->UnregisterCallback("font.name.", nsUnicodeMappingUtil::PrefChangedCallback, (void*) nsnull); - MOZ_COUNT_DTOR(nsUnicodeMappingUtil); -} - -//-------------------------------------------------------------------------- - -void nsUnicodeMappingUtil::InitGenericFontMapping() -{ - for(int i= 0 ; i < smPseudoTotalScripts; i ++) - for(int j=0; j < 5; j++) - mGenericFontMapping[i][j] = nsnull; - - // We probabaly should put the following info into resource .... - // smRoman - mGenericFontMapping[smRoman][kSerif] = new nsAutoString( NS_LITERAL_STRING("Times") ); - mGenericFontMapping[smRoman][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Helvetica") ); // note: MRJ use Geneva for Sans-Serif - mGenericFontMapping[smRoman][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Courier") ); - mGenericFontMapping[smRoman][kCursive] = new nsAutoString( NS_LITERAL_STRING("Zapf Chancery") ); - mGenericFontMapping[smRoman][kFantasy] = new nsAutoString( NS_LITERAL_STRING("New Century Schlbk") ); - - // smJapanese - static PRUnichar jfontname1[] = { - 0x672C, 0x660E, 0x671D, 0x2212, 0xFF2D, 0x0000 // –{–¾’©|‚l - }; - static PRUnichar jfontname2[] = { - 0x4E38, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x2212, 0xFF2D, 0x0000 // ÛƒSƒVƒbƒN|‚l - }; - static PRUnichar jfontname3[] = { - 0x004F, 0x0073, 0x0061, 0x006B, 0x0061, 0x2212, 0x7B49, 0x5E45, 0x0000 // Osaka|“™• - }; - - mGenericFontMapping[smJapanese][kSerif] = new nsAutoString(jfontname1); - mGenericFontMapping[smJapanese][kSansSerif] = new nsAutoString(jfontname2); - mGenericFontMapping[smJapanese][kMonospace] = new nsAutoString(jfontname3); - - // smTradChinese - mGenericFontMapping[smTradChinese][kSerif] = new nsAutoString( NS_LITERAL_STRING("Apple LiSung Light") ); - mGenericFontMapping[smTradChinese][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Apple LiGothic Medium") ); - mGenericFontMapping[smTradChinese][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Apple LiGothic Medium") ); - - // smKorean - mGenericFontMapping[smKorean][kSerif] = new nsAutoString( NS_LITERAL_STRING("AppleMyungjo") ); - mGenericFontMapping[smKorean][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("AppleGothic") ); - mGenericFontMapping[smKorean][kMonospace] = new nsAutoString( NS_LITERAL_STRING("AppleGothic") ); - - // smArabic - mGenericFontMapping[smArabic][kSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") ); - mGenericFontMapping[smArabic][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") ); - mGenericFontMapping[smArabic][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Monaco") ); - - // smHebrew - mGenericFontMapping[smHebrew][kSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") ); - mGenericFontMapping[smHebrew][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") ); - mGenericFontMapping[smHebrew][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Monaco") ); - - // smCyrillic - mGenericFontMapping[smCyrillic][kSerif] = new nsAutoString( NS_LITERAL_STRING("Latinski") ); - mGenericFontMapping[smCyrillic][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Pryamoy Prop") ); - mGenericFontMapping[smCyrillic][kMonospace] = new nsAutoString( NS_LITERAL_STRING("APC Courier") ); - - // smDevanagari - mGenericFontMapping[smDevanagari][kSerif] = new nsAutoString( NS_LITERAL_STRING("Devanagari MT") ); - mGenericFontMapping[smDevanagari][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Devanagari MT") ); - mGenericFontMapping[smDevanagari][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Devanagari MT") ); - - // smGurmukhi - mGenericFontMapping[smGurmukhi][kSerif] = new nsAutoString( NS_LITERAL_STRING("Gurmukhi MT") ); - mGenericFontMapping[smGurmukhi][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Gurmukhi MT") ); - mGenericFontMapping[smGurmukhi][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Gurmukhi MT") ); - - // smGujarati - mGenericFontMapping[smGujarati][kSerif] = new nsAutoString( NS_LITERAL_STRING("Gujarati MT") ); - mGenericFontMapping[smGujarati][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Gujarati MT") ); - mGenericFontMapping[smGujarati][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Gujarati MT") ); - - // smThai - mGenericFontMapping[smThai][kSerif] = new nsAutoString( NS_LITERAL_STRING("Thonburi") ); - mGenericFontMapping[smThai][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Krungthep") ); - mGenericFontMapping[smThai][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Ayuthaya") ); - - // smSimpChinese - mGenericFontMapping[smSimpChinese][kSerif] = new nsAutoString( NS_LITERAL_STRING("Song") ); - mGenericFontMapping[smSimpChinese][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Hei") ); - mGenericFontMapping[smSimpChinese][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Hei") ); - - // smCentralEuroRoman - mGenericFontMapping[smCentralEuroRoman][kSerif] = new nsAutoString( NS_LITERAL_STRING("Times CE") ); - mGenericFontMapping[smCentralEuroRoman][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Helvetica CE") ); - mGenericFontMapping[smCentralEuroRoman][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Courier CE") ); -} -//-------------------------------------------------------------------------- - -//-------------------------------------------------------------------------- -// nsUnicodeMappingUtil::MapLangGroupToScriptCode -// -// This method normally returns ScriptCode values, but CAN RETURN pseudo- -// ScriptCode values for Unicode (32) and User-Defined (33) -//-------------------------------------------------------------------------- -ScriptCode nsUnicodeMappingUtil::MapLangGroupToScriptCode(const char* aLangGroup) -{ - if(0==nsCRT::strcmp(aLangGroup, "x-western")) { - return smRoman; - } - if(0==nsCRT::strcmp(aLangGroup, "x-central-euro")) { - return smCentralEuroRoman; - } - if(0==nsCRT::strcmp(aLangGroup, "x-cyrillic")) { - return smCyrillic; - } - if(0==nsCRT::strcmp(aLangGroup, "el")) { - return smGreek; - } - if(0==nsCRT::strcmp(aLangGroup, "tr")) { - return smRoman; - } - if(0==nsCRT::strcmp(aLangGroup, "he")) { - return smHebrew; - } - if(0==nsCRT::strcmp(aLangGroup, "ar")) { - return smArabic; - } - if(0==nsCRT::strcmp(aLangGroup, "x-baltic")) { - return smRoman; - } - if(0==nsCRT::strcmp(aLangGroup, "th")) { - return smThai; - } - if(0==nsCRT::strcmp(aLangGroup, "ja")) { - return smJapanese; - } - if(0==nsCRT::strcmp(aLangGroup, "zh-CN")) { - return smSimpChinese; - } - if(0==nsCRT::strcmp(aLangGroup, "ko")) { - return smKorean; - } - if(0==nsCRT::strcmp(aLangGroup, "zh-TW")) { - return smTradChinese; - } - // No separate script code for zh-HK. Use smTradChinese. - if(0==nsCRT::strcmp(aLangGroup, "zh-HK")) { - return smTradChinese; - } - if(0==nsCRT::strcmp(aLangGroup, "x-devanag")) { - return smDevanagari; - } - if(0==nsCRT::strcmp(aLangGroup, "x-tamil")) { - return smTamil; - } - if(0==nsCRT::strcmp(aLangGroup, "x-beng")) { - return smBengali;; - } - if(0==nsCRT::strcmp(aLangGroup, "x-armn")) { - return smArmenian; - } - if(0==nsCRT::strcmp(aLangGroup, "x-geor")) { - return smGeorgian;; - } - if(0==nsCRT::strcmp(aLangGroup, "x-gujr")) { - return smGujarati; - } - if(0==nsCRT::strcmp(aLangGroup, "x-guru")) { - return smGurmukhi; - } - if(0==nsCRT::strcmp(aLangGroup, "x-mlym")) { - return smMalayalam; - } - if(0==nsCRT::strcmp(aLangGroup, "x-khmr")) { - return smKhmer; - } - if(0==nsCRT::strcmp(aLangGroup, "x-ethi")) { - return smEthiopic; - } - if(0==nsCRT::strcmp(aLangGroup, "x-cans")) { - return (smPseudoUnicode); // XXX : no script code for UCA - } - if(0==nsCRT::strcmp(aLangGroup, "x-unicode")) { - return (smPseudoUnicode); - } - if(0==nsCRT::strcmp(aLangGroup, "x-user-def")) { - return (smPseudoUserDef); - } - { - return smRoman; - } -} - -#define FACESIZE 255 // font name is Str255 in Mac script code -void PR_CALLBACK -nsUnicodeMappingUtil::PrefEnumCallback(const char* aName, void* aClosure) -{ - nsUnicodeMappingUtil* Self = (nsUnicodeMappingUtil*)aClosure; - nsCAutoString curPrefName(aName); - - PRInt32 p1 = curPrefName.RFindChar('.'); - if(-1==p1) - return; - PRInt32 p2 = curPrefName.RFindChar('.', p1-1); - if(-1==p1) - return; - - nsCAutoString genName(""); - nsCAutoString langGroup(""); - - curPrefName.Mid(langGroup, p1+1, curPrefName.Length()-p1-1); - curPrefName.Mid(genName, p2+1, p1-p2-1); - - ScriptCode script = Self->MapLangGroupToScriptCode(langGroup.get()); - if(script >= (smPseudoTotalScripts)) - { - // Because of the pseudo-scripts of Unicode and User-Defined, we have to handle - // the expanded ScriptCode value. - return; - } - if((script == smRoman) && !langGroup.Equals(nsCAutoString("x-western"))) { - // need special processing for t,r x-baltic, x-usr-defined - return; - } - - nsString genNameString; - genNameString.AssignWithConversion(genName); - nsGenericFontNameType type = Self->MapGenericFontNameType(genNameString); - if(type >= kUnknownGenericFontName) - return; - - char* valueInUTF8 = nsnull; - Self->mPref->CopyCharPref(aName, &valueInUTF8); - if(!valueInUTF8) - return; - if(!*valueInUTF8) - { - Recycle(valueInUTF8); - return; - } - PRUnichar valueInUCS2[FACESIZE]= { 0 }; - PRUnichar format[] = { '%', 's', 0 }; - PRUint32 n = nsTextFormatter::snprintf(valueInUCS2, FACESIZE, format, valueInUTF8); - Recycle(valueInUTF8); - if(n == 0) - return; - nsString *fontname = new nsAutoString(valueInUCS2); - if(nsnull == fontname) - return; - if( Self->mGenericFontMapping[script][type] ) - delete Self->mGenericFontMapping[script][type]; - Self->mGenericFontMapping[script][type] = fontname; -#ifdef DEBUG_ftang_font - char* utf8 = ToNewUTF8String(*fontname); - printf("font %d %d %s= %s\n",script , type, aName,utf8); - if (utf8) - Recycle(utf8); -#endif -} -void nsUnicodeMappingUtil::InitFromPref() -{ - if (!mPref) { - mPref = do_GetService(NS_PREF_CONTRACTID); - if (!mPref) - return; - mPref->RegisterCallback("font.name.", nsUnicodeMappingUtil::PrefChangedCallback, (void*) nsnull); - } - mPref->EnumerateChildren("font.name.", nsUnicodeMappingUtil::PrefEnumCallback, this); - -} -//-------------------------------------------------------------------------- - -void nsUnicodeMappingUtil::InitScriptFontMapping() -{ - // Get font from Script manager - for(ScriptCode script = 0; script< smPseudoTotalScripts ; script++) - { - mScriptFontMapping[script] = BAD_FONT_NUM; - short fontNum; - if ((smPseudoUnicode == script) || (smPseudoUserDef == script)) - { - char *theNeededPreference; - - if (smPseudoUnicode == script) - theNeededPreference = "font.name.serif.x-unicode"; - else - theNeededPreference = "font.name.serif.x-user-def"; - - char *valueInUTF8 = nsnull; - - mPref->CopyCharPref (theNeededPreference,&valueInUTF8); - - if (valueInUTF8) - { - if (!*valueInUTF8) - Recycle (valueInUTF8); - else - { - PRUnichar valueInUCS2[FACESIZE]= { 0 }; - PRUnichar format[] = { '%', 's', 0 }; - PRUint32 n = nsTextFormatter::snprintf(valueInUCS2, FACESIZE, format, valueInUTF8); - - Recycle (valueInUTF8); - if (n != 0) - { - nsString *fontname = new nsAutoString (valueInUCS2); - - if (nsnull != fontname) - { - short fontID = 0; - - if (nsDeviceContextMac::GetMacFontNumber (*fontname,fontID)) - mScriptFontMapping[script] = fontID; - - delete fontname; - } - } - } - } - } - else { - long fondsize = ::GetScriptVariable(script, smScriptPrefFondSize); - if (!fondsize) - fondsize = ::GetScriptVariable(smUnicodeScript, smScriptPrefFondSize); - - if((fondsize) && ((fondsize >> 16))) { - fontNum = (fondsize >> 16); - mScriptFontMapping[script] = fontNum; - } - } - } -} -//-------------------------------------------------------------------------- -void nsUnicodeMappingUtil::InitBlockToScriptMapping() -{ - static ScriptCode prebuildMapping[kUnicodeBlockSize] = - { - // start the fixed section - smGreek, smCyrillic, smArmenian, - smHebrew, smArabic, smDevanagari, smBengali, - smGurmukhi, smGujarati, smOriya, smTamil, - smTelugu, smKannada, smMalayalam, smThai, - smLao, smTibetan, smGeorgian, smKorean, - smTradChinese, smEthiopic, smKhmer, - smPseudoUnicode, // for Unified Canadian Syllable - smPseudoUserDef, - - // start the variable section - smRoman, smRoman, smJapanese, smJapanese, smJapanese, - smRoman - }; - for(PRUint32 i= 0; i < kUnicodeBlockSize; i++) - { - mBlockToScriptMapping[i] = prebuildMapping[i]; - } -} - -//-------------------------------------------------------------------------- -nsGenericFontNameType nsUnicodeMappingUtil::MapGenericFontNameType(const nsString& aGenericName) -{ - if (aGenericName.LowerCaseEqualsLiteral("serif")) - return kSerif; - if (aGenericName.LowerCaseEqualsLiteral("sans-serif")) - return kSansSerif; - if (aGenericName.LowerCaseEqualsLiteral("monospace")) - return kMonospace; - if (aGenericName.LowerCaseEqualsLiteral("-moz-fixed")) - return kMonospace; - if (aGenericName.LowerCaseEqualsLiteral("cursive")) - return kCursive; - if (aGenericName.LowerCaseEqualsLiteral("fantasy")) - return kFantasy; - - return kUnknownGenericFontName; -} - -//-------------------------------------------------------------------------- - - -//-------------------------------------------------------------------------- - -nsUnicodeMappingUtil* nsUnicodeMappingUtil::GetSingleton() -{ - if( ! gSingleton) - gSingleton = new nsUnicodeMappingUtil(); - return gSingleton; -} - -/* static */ void -nsUnicodeMappingUtil::FreeSingleton() -{ - delete gSingleton; - gSingleton = nsnull; -} - -//-------------------------------------------------------------------------- diff --git a/gfx/src/mac/nsUnicodeMappingUtil.h b/gfx/src/mac/nsUnicodeMappingUtil.h deleted file mode 100644 index 5efda666bb8b..000000000000 --- a/gfx/src/mac/nsUnicodeMappingUtil.h +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#include - -#include "prtypes.h" -#include "nsUnicodeBlock.h" -#include "nsDebug.h" -#include "nscore.h" -#include "nsIPref.h" - -class nsUnicodeFontMappingCache; -class nsString; - - //-------------------------------------------------------------------------- -typedef enum { - kSerif = 0, - kSansSerif, - kMonospace, - kCursive, - kFantasy, - kUnknownGenericFontName -} nsGenericFontNameType; -//-------------------------------------------------------------------------- - -class nsUnicodeMappingUtil { -public: - nsUnicodeMappingUtil(); - ~nsUnicodeMappingUtil(); - void Init(); - void CleanUp(); - void Reset(); - inline ScriptCode BlockToScript(nsUnicodeBlock blockID) - { - NS_PRECONDITION(blockID < kUnicodeBlockSize, "illegal value"); - return (ScriptCode) mBlockToScriptMapping[blockID]; - }; - inline short ScriptFont(ScriptCode script) - { - NS_PRECONDITION(script < smPseudoTotalScripts, "bad script code"); - return mScriptFontMapping[script]; - }; - nsGenericFontNameType MapGenericFontNameType(const nsString& aGenericName); - inline nsString* GenericFontNameForScript(ScriptCode aScript, nsGenericFontNameType aType) const - { - NS_PRECONDITION(aScript < smPseudoTotalScripts, "bad script code"); - NS_PRECONDITION(aType <= kUnknownGenericFontName, "illegal value"); - if( aType >= kUnknownGenericFontName) - return nsnull; - else - return mGenericFontMapping[aScript][aType]; - } - - ScriptCode MapLangGroupToScriptCode(const char* aLangGroup); - static nsUnicodeMappingUtil* GetSingleton(); - static void FreeSingleton(); - nsString *mGenericFontMapping[smPseudoTotalScripts][kUnknownGenericFontName]; - -protected: - void InitGenericFontMapping(); - void InitBlockToScriptMapping(); - void InitScriptFontMapping(); - void InitFromPref(); - - static int PR_CALLBACK_DECL PrefChangedCallback( const char* aPrefName, void* instance_data); - static void PR_CALLBACK_DECL PrefEnumCallback(const char* aName, void* aClosure); - -private: - short mScriptFontMapping[smPseudoTotalScripts]; - PRInt8 mBlockToScriptMapping[kUnicodeBlockSize]; - nsCOMPtr mPref; - - static nsUnicodeMappingUtil* gSingleton; - -}; diff --git a/gfx/src/mac/nsUnicodeRenderingToolkit.cpp b/gfx/src/mac/nsUnicodeRenderingToolkit.cpp deleted file mode 100644 index 0968982d5a12..000000000000 --- a/gfx/src/mac/nsUnicodeRenderingToolkit.cpp +++ /dev/null @@ -1,1925 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsUnicodeRenderingToolkit.h" -#include "nsUnicodeFontMappingMac.h" -#include "nsUnicodeFallbackCache.h" -#include "nsDrawingSurfaceMac.h" -#include "nsTransform2D.h" -#include "nsFontMetricsMac.h" -#include "nsGraphicState.h" -#include "prprf.h" -#include "nsCarbonHelpers.h" -#include "nsISaveAsCharset.h" -#include "nsIComponentManager.h" -#include "nsUnicharUtils.h" - - -#include "nsMacUnicodeFontInfo.h" -#include "nsICharRepresentable.h" - -#include - -#define STACK_TRESHOLD 1000 - -//#define DISABLE_TEC_FALLBACK -//#define DISABLE_PRECOMPOSEHANGUL_FALLBACK -//#define DISABLE_LATINL_FALLBACK -//#define DISABLE_ATSUI_FALLBACK -//#define DISABLE_TRANSLITERATE_FALLBACK -//#define DISABLE_UPLUS_FALLBACK - -#define IS_FORMAT_CONTROL_CHARS(c) ((0x2000==((c)&0xFFF0))||(0x2028==((c)&0xFFF8))) -#define IS_CONTEXTUAL_CHARS(c) ((0x0600<=(c))&&((c)<0x1000)) -#define IS_COMBINING_CHARS(c) ((0x0300<=(c))&&((c)<0x0370)) - -#define QUESTION_FALLBACKSIZE 9 -#define UPLUS_FALLBACKSIZE 9 -#define IN_RANGE(c, l, h) (((l) <= (c)) && ((c) <= (h))) -#define IN_STANDARD_MAC_ROMAN_FONT(c) ( \ - (((c) < 0x180) && (! (\ - (0x0110 == (c)) || \ - (0x012c == (c)) || \ - (0x012d == (c)) || \ - (0x0138 == (c)) || \ - (0x014a == (c)) || \ - (0x014b == (c)) || \ - (0x017f == (c)) \ - )))) -#define IN_SYMBOL_FONT(c) ( \ - IN_RANGE(c, 0x0391, 0x03a1) || \ - IN_RANGE(c, 0x03a3, 0x03a9) || \ - IN_RANGE(c, 0x03b1, 0x03c1) || \ - IN_RANGE(c, 0x03c3, 0x03c9) || \ - (0x2111 == (c)) || \ - (0x2118 == (c)) || \ - (0x211c == (c)) || \ - (0x2135 == (c)) || \ - IN_RANGE(c, 0x2190, 0x2193) || \ - IN_RANGE(c, 0x21d0, 0x21d3) || \ - IN_RANGE(c, 0x21ed, 0x21ee) || \ - (0x2200 == (c)) || \ - (0x2203 == (c)) || \ - (0x2205 == (c)) || \ - (0x2208 == (c)) || \ - (0x2209 == (c)) || \ - (0x2212 == (c)) || \ - (0x2217 == (c)) || \ - (0x221d == (c)) || \ - (0x2220 == (c)) || \ - IN_RANGE(c, 0x2227, 0x222b) || \ - (0x2234 == (c)) || \ - (0x223c == (c)) || \ - (0x2261 == (c)) || \ - (0x2282 == (c)) || \ - (0x2283 == (c)) || \ - (0x2286 == (c)) || \ - (0x2287 == (c)) || \ - (0x2295 == (c)) || \ - (0x2297 == (c)) || \ - (0x22a5 == (c)) || \ - (0x2320 == (c)) || \ - (0x2321 == (c)) || \ - (0x240d == (c)) || \ - (0x2660 == (c)) || \ - (0x2663 == (c)) || \ - (0x2665 == (c)) || \ - (0x2666 == (c)) \ - ) -#define SPECIAL_IN_SYMBOL_FONT(c) ( \ - IN_RANGE(c, 0x2308, 0x230b) || \ - (0x2329 == (c)) || \ - (0x232a == (c)) \ - ) -#define BAD_TEXT_ENCODING 0xFFFFFFFF - -// all the character should not be drawn if there are no glyph -#define IS_ZERO_WIDTH_CHAR(c) ( \ - IN_RANGE(c, 0x200b, 0x200f) || \ - IN_RANGE(c, 0x202a, 0x202e) \ - ) - - -#define IN_ARABIC_PRESENTATION_A(a) ((0xfb50 <= (a)) && ((a) <= 0xfdff)) -#define IN_ARABIC_PRESENTATION_B(a) ((0xfe70 <= (a)) && ((a) <= 0xfeff)) -#define IN_ARABIC_PRESENTATION_A_OR_B(a) (IN_ARABIC_PRESENTATION_A(a) || IN_ARABIC_PRESENTATION_B(a)) - -// We should not use TEC fallback for characters in Latin, Greek and Cyrillic scripts -// because Japanese, Chinese and Korean fonts have these characters. If we let them -// render in the TEC fallback process, then we would use a Japanese/Korean/Chinese font -// to render it even if the current font has a glyph in it. -// if we skip the TEC fallback, then the ATSUI fallback will try to use the glyph -// in the font first (TEC or TEC fallback are using QuickDraw, which can only use -// the glyphs that are in the font script's encoding. But a lot of TrueType fonts -// have hundreds more glyphs in addition to the font scripts. -#define IS_LATIN(c) ( IN_RANGE(c, 0x0000, 0x024F) || IN_RANGE(c, 0x1e00, 0x1eff) ) -#define IS_GREEK(c) ( IN_RANGE(c, 0x0370, 0x03FF) || IN_RANGE(c, 0x1f00, 0x1fff) ) -#define IS_CYRILLIC(c) IN_RANGE(c, 0x0400, 0x04ff) -#define IS_SKIP_TEC_FALLBACK(c) (IS_LATIN(c) || IS_GREEK(c) || IS_CYRILLIC(c)) - -//------------------------------------------------------------------------ -#pragma mark - -//------------------------------------------------------------------------ - -nsUnicodeFallbackCache* nsUnicodeRenderingToolkit :: GetTECFallbackCache() -{ - static nsUnicodeFallbackCache* gTECFallbackCache = nsnull; - - if( ! gTECFallbackCache) - gTECFallbackCache = new nsUnicodeFallbackCache(); - return gTECFallbackCache; -} -//------------------------------------------------------------------------ - -PRBool -nsUnicodeRenderingToolkit::TECFallbackGetDimensions( - const PRUnichar *aCharPt, - nsTextDimensions& oDim, - short origFontNum, - nsUnicodeFontMappingMac& fontMapping) -{ - char buf[20]; - ByteCount processBytes = 0; - ByteCount outLen = 0; - ScriptCode fallbackScript; - nsUnicodeFallbackCache* cache = GetTECFallbackCache(); - short aWidth; - FontInfo finfo; - const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts(); - - if ((0xf780 <= *aCharPt) && (*aCharPt <= 0xf7ff)) - { - // If we are encountering our PUA characters for User-Defined characters, we better - // just drop the high-byte and return the width for the low-byte. - *buf = (*aCharPt & 0x00FF); - ::GetFontInfo(&finfo); - oDim.ascent = finfo.ascent; - oDim.descent = finfo.descent; - - GetScriptTextWidth (buf,1,aWidth); - oDim.width = aWidth; - - return PR_TRUE; - } - else if (cache->Get(*aCharPt, fallbackScript)) - { - if (BAD_SCRIPT == fallbackScript) - return PR_FALSE; - - if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1, - buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask)) - { - ::TextFont(scriptFallbackFonts[fallbackScript]); - GetScriptTextWidth(buf, outLen, aWidth); - ::GetFontInfo(&finfo); - oDim.ascent = finfo.ascent; - oDim.descent = finfo.descent; - oDim.width = aWidth; - ::TextFont(origFontNum); - } - return PR_TRUE; - } - - for(fallbackScript = 0 ; fallbackScript < 32; fallbackScript++) - { - if (BAD_FONT_NUM != scriptFallbackFonts[fallbackScript]) - { - if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1, - buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask)) - { - NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result"); - ::TextFont(scriptFallbackFonts[fallbackScript]); - GetScriptTextWidth(buf, outLen, aWidth); - ::GetFontInfo(&finfo); - oDim.ascent = finfo.ascent; - oDim.descent = finfo.descent; - oDim.width = aWidth; - ::TextFont(origFontNum); - break; - } - } - } - - if (0 == outLen) - fallbackScript = BAD_SCRIPT; - - // put into cache - cache->Set(*aCharPt, fallbackScript); - - return (BAD_SCRIPT != fallbackScript); -} -//------------------------------------------------------------------------ - -#if MOZ_MATHML -PRBool nsUnicodeRenderingToolkit::TECFallbackGetBoundingMetrics( - const PRUnichar *aCharPt, - nsBoundingMetrics& oBoundingMetrics, - short fontNum, - nsUnicodeFontMappingMac& fontMapping) -{ - char buf[STACK_TRESHOLD]; - ByteCount processBytes = 0; - ByteCount outLen = 0; - ScriptCode fallbackScript; - nsUnicodeFallbackCache* cache = GetTECFallbackCache(); - const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts(); - - if((0xf780 <= *aCharPt) && (*aCharPt <= 0xf7ff)) - { - // If we are encountering our PUA characters for User-Defined characters, we better - // just drop the high-byte and return the width for the low-byte. - *buf = (*aCharPt & 0x00FF); - GetScriptTextBoundingMetrics(buf, 1, ::FontToScript(fontNum), oBoundingMetrics); - return PR_TRUE; - } - else if(cache->Get(*aCharPt, fallbackScript)) - { - if(BAD_SCRIPT == fallbackScript) - return PR_FALSE; - - if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1, - buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask)) - { - ::TextFont(scriptFallbackFonts[fallbackScript]); - GetScriptTextBoundingMetrics(buf, outLen, fallbackScript, oBoundingMetrics); - ::TextFont(fontNum); - return PR_TRUE; - } - return PR_FALSE; - } - - for(fallbackScript = 0; fallbackScript < 32; fallbackScript++) - { - if(BAD_FONT_NUM != scriptFallbackFonts[fallbackScript]) - { - if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1, - buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask)) - { - NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result"); - ::TextFont(scriptFallbackFonts[fallbackScript]); - GetScriptTextBoundingMetrics(buf, outLen, fallbackScript, oBoundingMetrics); - ::TextFont(fontNum); - break; - } - } - } - - if(0 == outLen) - fallbackScript = BAD_SCRIPT; - - // put into cache - cache->Set(*aCharPt, fallbackScript); - - return (BAD_SCRIPT != fallbackScript); -} -#endif // MOZ_MATHML -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: TECFallbackDrawChar( - const PRUnichar *aCharPt, - PRInt32 x, - PRInt32 y, - short& oWidth, - short origFontNum, - nsUnicodeFontMappingMac& fontMapping) -{ - char buf[20]; - ByteCount processBytes = 0; - ByteCount outLen = 0; - ScriptCode fallbackScript; - nsUnicodeFallbackCache* cache = GetTECFallbackCache(); - const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts(); - - // since we always call TECFallbackGetWidth before TECFallbackDrawChar - // we could assume that we can always get the script code from cache. - if ((0xf780 <= *aCharPt) && (*aCharPt <= 0xf7ff)) - { - // If we are encountering our PUA characters for User-Defined characters, we better - // just drop the high-byte and draw the text for the low-byte. - *buf = (*aCharPt & 0x00FF); - DrawScriptText (buf,1,x,y,oWidth); - - return PR_TRUE; - } - else if (cache->Get(*aCharPt, fallbackScript)) - { - if (BAD_SCRIPT == fallbackScript) - return PR_FALSE; - - if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1, - buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask)) - { - ::TextFont(scriptFallbackFonts[fallbackScript]); - DrawScriptText(buf, outLen, x, y, oWidth); - ::TextFont(origFontNum); - return PR_TRUE; - } - } - return PR_FALSE; -} -//------------------------------------------------------------------------ -static PRUnichar gSymbolReplacement[]={0xf8ee,0xf8f9,0xf8f0,0xf8fb,0x3008,0x3009}; - -//------------------------------------------------------------------------ - -static nsresult FormAorBIsolated(PRUnichar aChar, nsMacUnicodeFontInfo& aInfo, PRUnichar* aOutChar) -{ - static const PRUnichar arabicisolated[]= - { - // start of form a - 0xFB50, 0x0671, 0xFB52, 0x067B, 0xFB56, 0x067E, 0xFB5A, 0x0680, 0xFB5E, 0x067A, - 0xFB62, 0x067F, 0xFB66, 0x0679, 0xFB6A, 0x06A4, 0xFB6E, 0x06A6, 0xFB72, 0x0684, - 0xFB76, 0x0683, 0xFB7A, 0x0686, 0xFB7E, 0x0687, 0xFB82, 0x068D, 0xFB84, 0x068C, - 0xFB86, 0x068E, 0xFB88, 0x0688, 0xFB8A, 0x0698, 0xFB8C, 0x0691, 0xFB8E, 0x06A9, - 0xFB92, 0x06AF, 0xFB96, 0x06B3, 0xFB9A, 0x06B1, 0xFB9E, 0x06BA, 0xFBA0, 0x06BB, - 0xFBA4, 0x06C0, 0xFBA6, 0x06C1, 0xFBAA, 0x06BE, 0xFBAE, 0x06D2, 0xFBB0, 0x06D3, - 0xFBD3, 0x06AD, 0xFBD7, 0x06C7, 0xFBD9, 0x06C6, 0xFBDB, 0x06C8, 0xFBDD, 0x0677, - 0xFBDE, 0x06CB, 0xFBE0, 0x06C5, 0xFBE2, 0x06C9, 0xFBE4, 0x06D0, 0xFBFC, 0x06CC, - - // start of form b - 0xFE70, 0x064B, 0xFE72, 0x064C, 0xFE74, 0x064D, 0xFE76, 0x064E, 0xFE78, 0x064F, - 0xFE7A, 0x0650, 0xFE7C, 0x0651, 0xFE7E, 0x0652, 0xFE80, 0x0621, 0xFE81, 0x0622, - 0xFE83, 0x0623, 0xFE85, 0x0624, 0xFE87, 0x0625, 0xFE89, 0x0626, 0xFE8D, 0x0627, - 0xFE8F, 0x0628, 0xFE93, 0x0629, 0xFE95, 0x062A, 0xFE99, 0x062B, 0xFE9D, 0x062C, - 0xFEA1, 0x062D, 0xFEA5, 0x062E, 0xFEA9, 0x062F, 0xFEAB, 0x0630, 0xFEAD, 0x0631, - 0xFEAF, 0x0632, 0xFEB1, 0x0633, 0xFEB5, 0x0634, 0xFEB9, 0x0635, 0xFEBD, 0x0636, - 0xFEC1, 0x0637, 0xFEC5, 0x0638, 0xFEC9, 0x0639, 0xFECD, 0x063A, 0xFED1, 0x0641, - 0xFED5, 0x0642, 0xFED9, 0x0643, 0xFEDD, 0x0644, 0xFEE1, 0x0645, 0xFEE5, 0x0646, - 0xFEE9, 0x0647, 0xFEED, 0x0648, 0xFEEF, 0x0649, 0xFEF1, 0x064A, - 0x0000 - }; - const PRUnichar* p; - for ( p= arabicisolated; *p; p += 2) { - if (aChar == *p) { - if (aInfo.HasGlyphFor(*(p+1))) { - *aOutChar = *(p+1); - return NS_OK; - } - } - } - return NS_ERROR_FAILURE; -} -//------------------------------------------------------------------------ - -PRBool -nsUnicodeRenderingToolkit::ATSUIFallbackGetDimensions( - const PRUnichar *aCharPt, - nsTextDimensions& oDim, - short origFontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor) -{ - - nsMacUnicodeFontInfo info; - if (nsATSUIUtils::IsAvailable() - && (IN_STANDARD_MAC_ROMAN_FONT(*aCharPt) - ||IN_SYMBOL_FONT(*aCharPt) - ||SPECIAL_IN_SYMBOL_FONT(*aCharPt) - ||info.HasGlyphFor(*aCharPt))) - { - mATSUIToolkit.PrepareToDraw(mPort, mContext ); - nsresult res; - if (SPECIAL_IN_SYMBOL_FONT(*aCharPt)) - { - short rep = 0; - if ((*aCharPt) > 0x230b) - rep = (*aCharPt) - 0x2325; - else - rep = (*aCharPt) - 0x2308; - res = mATSUIToolkit.GetTextDimensions(gSymbolReplacement+rep, 1, oDim, aSize, - origFontNum, - aBold, aItalic, aColor); - } - else - { - res = mATSUIToolkit.GetTextDimensions(aCharPt, 1, oDim, aSize, - origFontNum, - aBold, aItalic, aColor); - } - if (NS_SUCCEEDED(res)) - return PR_TRUE; - } - - if (IN_ARABIC_PRESENTATION_A_OR_B(*aCharPt)) - { - PRUnichar isolated; - if (NS_SUCCEEDED( FormAorBIsolated(*aCharPt, info, &isolated))) - { - if (ATSUIFallbackGetDimensions(&isolated, oDim, origFontNum, - aSize, aBold, aItalic, aColor)) - return PR_TRUE; - } - } - - // we know some ATSUI font do not have bold, turn it off and try again - if (aBold) - { - if (ATSUIFallbackGetDimensions(aCharPt, oDim, origFontNum, - aSize, PR_FALSE, aItalic, aColor)) - return PR_TRUE; - } - - // we know some ATSUI font do not have italic, turn it off and try again - if (aItalic) - { - if (ATSUIFallbackGetDimensions(aCharPt, oDim, origFontNum, - aSize, PR_FALSE, PR_FALSE, aColor)) - return PR_TRUE; - } - - return PR_FALSE; -} - -//------------------------------------------------------------------------ - -#ifdef MOZ_MATHML -PRBool -nsUnicodeRenderingToolkit::ATSUIFallbackGetBoundingMetrics( - const PRUnichar *aCharPt, - nsBoundingMetrics& oBoundingMetrics, - short origFontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor) -{ - - nsMacUnicodeFontInfo info; - if (nsATSUIUtils::IsAvailable() - && (IN_STANDARD_MAC_ROMAN_FONT(*aCharPt) - ||IN_SYMBOL_FONT(*aCharPt) - ||SPECIAL_IN_SYMBOL_FONT(*aCharPt) - ||info.HasGlyphFor(*aCharPt))) - { - mATSUIToolkit.PrepareToDraw(mPort, mContext ); - nsresult res; - if (SPECIAL_IN_SYMBOL_FONT(*aCharPt)) - { - short rep = 0; - if ((*aCharPt) > 0x230b) - rep = (*aCharPt) - 0x2325; - else - rep = (*aCharPt) - 0x2308; - res = mATSUIToolkit.GetBoundingMetrics(gSymbolReplacement+rep, 1, oBoundingMetrics, aSize, - origFontNum, - aBold, aItalic, aColor); - } - else - { - res = mATSUIToolkit.GetBoundingMetrics(aCharPt, 1, oBoundingMetrics, aSize, - origFontNum, - aBold, aItalic, aColor); - } - if (NS_SUCCEEDED(res)) - return PR_TRUE; - } - - if (IN_ARABIC_PRESENTATION_A_OR_B(*aCharPt)) - { - PRUnichar isolated; - if (NS_SUCCEEDED(FormAorBIsolated(*aCharPt, info, &isolated))) - { - if (ATSUIFallbackGetBoundingMetrics(&isolated, oBoundingMetrics, origFontNum, - aSize, aBold, aItalic, aColor)) - return PR_TRUE; - } - } - - // we know some ATSUI font do not have bold, turn it off and try again - if (aBold) - { - if (ATSUIFallbackGetBoundingMetrics(aCharPt, oBoundingMetrics, origFontNum, - aSize, PR_FALSE, aItalic, aColor)) - return PR_TRUE; - } - - // we know some ATSUI font do not have italic, turn it off and try again - if (aItalic) - { - if (ATSUIFallbackGetBoundingMetrics(aCharPt, oBoundingMetrics, origFontNum, - aSize, PR_FALSE, PR_FALSE, aColor)) - return PR_TRUE; - } - - return PR_FALSE; -} -#endif // MOZ_MATHML - -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: ATSUIFallbackDrawChar( - const PRUnichar *aCharPt, - PRInt32 x, PRInt32 y, - short& oWidth, - short origFontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor) -{ - nsMacUnicodeFontInfo info; - if (nsATSUIUtils::IsAvailable() - && (IN_STANDARD_MAC_ROMAN_FONT(*aCharPt) - ||IN_SYMBOL_FONT(*aCharPt) - ||SPECIAL_IN_SYMBOL_FONT(*aCharPt) - ||info.HasGlyphFor(*aCharPt))) - { - mATSUIToolkit.PrepareToDraw(mPort, mContext ); - nsresult res; - if(SPECIAL_IN_SYMBOL_FONT(*aCharPt)) - { - short rep = 0; - if ((*aCharPt) > 0x230b) - rep = (*aCharPt) - 0x2325; - else - rep = (*aCharPt) - 0x2308; - res = mATSUIToolkit.DrawString(gSymbolReplacement+rep, 1, x, y, oWidth, aSize, - origFontNum, - aBold, aItalic, aColor); - } else { - res = mATSUIToolkit.DrawString(aCharPt, 1, x, y, oWidth, aSize, - origFontNum, - aBold, aItalic, aColor); - } - if (NS_SUCCEEDED(res)) - return PR_TRUE; - } - - if (IN_ARABIC_PRESENTATION_A_OR_B(*aCharPt)) - { - PRUnichar isolated; - if (NS_SUCCEEDED(FormAorBIsolated(*aCharPt, info, &isolated))) { - if (ATSUIFallbackDrawChar(&isolated, x, y, oWidth, origFontNum, - aSize, aBold, aItalic, aColor)) - return PR_TRUE; - } - } - - // we know some ATSUI font do not have bold, turn it off and try again - if (aBold) - { - if (ATSUIFallbackDrawChar(aCharPt, x, y, oWidth, origFontNum, - aSize, PR_FALSE, aItalic, aColor)) - return PR_TRUE; - } - - // we know some ATSUI font do not have italic, turn it off and try again - if (aItalic) - { - if (ATSUIFallbackDrawChar(aCharPt, x, y, oWidth, origFontNum, - aSize, PR_FALSE, PR_FALSE, aColor)) - return PR_TRUE; - } - - return PR_FALSE; -} - -PRBool nsUnicodeRenderingToolkit :: SurrogateGetDimensions( - const PRUnichar *aSurrogatePt, nsTextDimensions& oDim, short origFontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor) -{ - nsresult res; - mATSUIToolkit.PrepareToDraw(mPort, mContext ); - res = mATSUIToolkit.GetTextDimensions(aSurrogatePt, 2, oDim, aSize, - origFontNum, - aBold, aItalic, aColor); - return NS_SUCCEEDED(res); -} - -PRBool nsUnicodeRenderingToolkit :: SurrogateDrawChar( - const PRUnichar *aSurrogatePt, PRInt32 x, PRInt32 y, short& oWidth, short origFontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor) -{ - nsresult res; - mATSUIToolkit.PrepareToDraw(mPort, mContext ); - res = mATSUIToolkit.DrawString(aSurrogatePt, 2, x, y, oWidth, aSize, - origFontNum, - aBold, aItalic, aColor); - return NS_SUCCEEDED(res); -} - -#ifdef MOZ_MATHML -PRBool nsUnicodeRenderingToolkit :: SurrogateGetBoundingMetrics( - const PRUnichar *aSurrogatePt, nsBoundingMetrics& oBoundingMetrics, short origFontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor) -{ - nsresult res; - mATSUIToolkit.PrepareToDraw(mPort, mContext ); - res = mATSUIToolkit.GetBoundingMetrics(aSurrogatePt, 2, oBoundingMetrics, aSize, - origFontNum, - aBold, aItalic, aColor); - - return NS_SUCCEEDED(res); -} -#endif - -static const char question[] = ""; - -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: QuestionMarkFallbackGetWidth( - const PRUnichar *aCharPt, - short& oWidth) -{ - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - short saveSize = ::GetPortTextSize(thePort); - ::TextSize(QUESTION_FALLBACKSIZE); - GetScriptTextWidth(question, 3,oWidth); - ::TextSize(saveSize); - return PR_TRUE; -} -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: QuestionMarkFallbackDrawChar( - const PRUnichar *aCharPt, - PRInt32 x, - PRInt32 y, - short& oWidth) -{ - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - short saveSize = ::GetPortTextSize(thePort); - ::TextSize(QUESTION_FALLBACKSIZE); - DrawScriptText(question, 3, x, y, oWidth); - ::TextSize(saveSize); - return PR_TRUE; -} -//------------------------------------------------------------------------ -PRBool nsUnicodeRenderingToolkit :: LoadTransliterator() -{ - if(mTrans) - return PR_TRUE; - - nsresult res; - mTrans = do_CreateInstance(NS_SAVEASCHARSET_CONTRACTID, &res); - if ( NS_SUCCEEDED(res) ) - { - res = mTrans->Init("x-mac-roman", - nsISaveAsCharset::attr_FallbackQuestionMark + - nsISaveAsCharset::attr_EntityBeforeCharsetConv + - nsISaveAsCharset::attr_IgnoreIgnorables, - nsIEntityConverter::transliterate); - NS_ASSERTION(NS_SUCCEEDED(res), "cannot init the converter"); - if (NS_FAILED(res)) - { - mTrans = nsnull; - return PR_FALSE; - } - } - return PR_TRUE; -} -//------------------------------------------------------------------------ -PRBool nsUnicodeRenderingToolkit :: TransliterateFallbackGetWidth( - const PRUnichar *aCharPt, - short& oWidth) -{ - if(LoadTransliterator()) { - nsAutoString tmp(aCharPt, 1); - char* conv = nsnull; - if(NS_SUCCEEDED(mTrans->Convert(tmp.get(), &conv)) && conv) { - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - short aSize = ::GetPortTextSize(thePort); - PRInt32 l=strlen(conv); - if((l>3) && ('^' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sup - { - short small = aSize * 2 / 3; - ::TextSize(small); - GetScriptTextWidth(conv+2, l-3,oWidth); - ::TextSize(aSize); - } - else if((l>3) && ('v' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sub - { - short small = aSize * 2 / 3; - ::TextSize(small); - GetScriptTextWidth(conv+2, l-3,oWidth); - ::TextSize(aSize); - } - else if((l>1) && ('0' <= conv[0]) && ( conv[0] <= '9') && ('/' == conv[1])) // fract - { - short small = aSize * 2 / 3; - short tmpw=0; - - ::TextSize(small); - GetScriptTextWidth(conv, 1 ,tmpw); - oWidth = tmpw; - - ::TextSize(aSize); - GetScriptTextWidth(conv+1, 1,tmpw); - oWidth += tmpw; - - if(l>2) { - ::TextSize(small); - GetScriptTextWidth(conv+2, l-2,tmpw); - oWidth += tmpw; - ::TextSize(aSize); - } - } else { - GetScriptTextWidth(conv, l,oWidth); - } - - - nsMemory::Free(conv); - return PR_TRUE; - } - } - return PR_FALSE; -} -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: TransliterateFallbackDrawChar( - const PRUnichar *aCharPt, - PRInt32 x, - PRInt32 y, - short& oWidth) -{ - if(LoadTransliterator()) { - nsAutoString tmp(aCharPt, 1); - char* conv = nsnull; - if(NS_SUCCEEDED(mTrans->Convert(tmp.get(), &conv)) && conv) { - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - short aSize = ::GetPortTextSize(thePort); - PRInt32 l=strlen(conv); - if((l>3) && ('^' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sup - { - short small = aSize * 2 / 3; - ::TextSize(small); - DrawScriptText(conv+2, l-3, x, y-small/2, oWidth); - ::TextSize(aSize); - } - else if((l>3) && ('v' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sub - { - short small = aSize * 2 / 3; - ::TextSize(small); - DrawScriptText(conv+2, l-3, x, y+small/2, oWidth); - ::TextSize(aSize); - } - else if((l>1) && ('0' <= conv[0]) && ( conv[0] <= '9') && ('/' == conv[1])) // fract - { - short small = aSize * 2 / 3; - short tmpw=0; - - ::TextSize(small); - DrawScriptText(conv, 1, x, y-small/2, tmpw); - oWidth = tmpw; - - ::TextSize(aSize); - DrawScriptText(conv+1, 1, x+oWidth, y, tmpw); - oWidth += tmpw; - - if(l>2) { - ::TextSize(small); - DrawScriptText(conv+2, l-2, x+oWidth, y+small/2, tmpw); - oWidth += tmpw; - ::TextSize(aSize); - } - } else { - DrawScriptText(conv, l, x, y, oWidth); - } - nsMemory::Free(conv); - return PR_TRUE; - } - } - return PR_FALSE; -} -//------------------------------------------------------------------------ -#define CAN_DO_PRECOMPOSE_HANGUL(u, f) ((0xAC00<=(u)) && ((u)<=0xD7FF) && ((f) != BAD_FONT_NUM)) -#define SBase 0xAC00 -#define LCount 19 -#define VCount 21 -#define TCount 28 -#define NCount (VCount * TCount) -static void UnicodePrecomposedHangulTo4EUCKR(PRUnichar in, char *out) -{ - static const PRUint8 lMap[LCount] = { - 0xa1, 0xa2, 0xa4, 0xa7, 0xa8, 0xa9, 0xb1, 0xb2, 0xb3, 0xb5, - 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe - }; - - static const PRUint8 tMap[TCount] = { - 0xd4, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa9, 0xaa, - 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb4, 0xb5, - 0xb6, 0xb7, 0xb8, 0xba, 0xbb, 0xbc, 0xbd, 0xbe - }; - PRUint16 SIndex, LIndex, VIndex, TIndex; - /* the following line are copy from Unicode 2.0 page 3-13 */ - /* item 1 of Hangul Syllabel Decomposition */ - SIndex = in - SBase; - - /* the following lines are copy from Unicode 2.0 page 3-14 */ - /* item 2 of Hangul Syllabel Decomposition w/ modification */ - LIndex = SIndex / NCount; - VIndex = (SIndex % NCount) / TCount; - TIndex = SIndex % TCount; - // somehow Apple's Korean font show glaph on A4D4 :( so we use '[' + L + V + T + ']' intead of - // Filler + L + V + T to display - // output '[' - *out++ = '['; - // output L - *out++ = 0xA4; - *out++ = lMap[LIndex] ; - // output V - *out++ = 0xA4; - *out++ = (VIndex + 0xbf); - // output T - *out++ = 0xA4; - *out++ = tMap[TIndex] ; - // output ']' - *out++ = ']'; -} - -//------------------------------------------------------------------------ -PRBool nsUnicodeRenderingToolkit :: PrecomposeHangulFallbackGetWidth( - const PRUnichar *aCharPt, - short& oWidth, - short koreanFont, - short origFont) -{ - if(CAN_DO_PRECOMPOSE_HANGUL(*aCharPt, koreanFont)) { - char euckr[8]; - if(koreanFont != origFont) - ::TextFont(koreanFont); - UnicodePrecomposedHangulTo4EUCKR(*aCharPt, euckr); - GetScriptTextWidth(euckr, 8, oWidth); - if(koreanFont != origFont) - ::TextFont(origFont); - return PR_TRUE; - } else { - return PR_FALSE; - } -} -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: PrecomposeHangulFallbackDrawChar( - const PRUnichar *aCharPt, - PRInt32 x, - PRInt32 y, - short& oWidth, - short koreanFont, - short origFont) -{ - if(CAN_DO_PRECOMPOSE_HANGUL(*aCharPt, koreanFont)) { - char euckr[8]; - if(koreanFont != origFont) - ::TextFont(koreanFont); - UnicodePrecomposedHangulTo4EUCKR(*aCharPt, euckr); - DrawScriptText(euckr, 8, x, y, oWidth); - if(koreanFont != origFont) - ::TextFont(origFont); - return PR_TRUE; - } else { - return PR_FALSE; - } -} -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: UPlusFallbackGetWidth( - const PRUnichar *aCharPt, - short& oWidth) -{ - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - short saveSize = ::GetPortTextSize(thePort); - char buf[16]; - PRUint32 len = PR_snprintf(buf, 16 , "", *aCharPt); - ::TextSize(UPLUS_FALLBACKSIZE); - if(len != -1) - GetScriptTextWidth(buf, len, oWidth); - ::TextSize(saveSize); - return (-1 != len); -} -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: UPlusFallbackDrawChar( - const PRUnichar *aCharPt, - PRInt32 x, - PRInt32 y, - short& oWidth) -{ - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - short saveSize = ::GetPortTextSize(thePort); - char buf[16]; - PRUint32 len = PR_snprintf(buf, 16 , "", *aCharPt); - ::TextSize(UPLUS_FALLBACKSIZE); - if(len != -1) - DrawScriptText(buf, len, x, y, oWidth); - ::TextSize(saveSize); - return (-1 != len); -} -//------------------------------------------------------------------------ -/* -# capital mean above -# small mean below -# r - ring below -# R - Ring Above -# d - dot below -# D - Dot Above -# l - line below -# L - Line Above -# c - cedilla -# A - Acute -# x - circumflex below -# X - Circumflex Above -# G - Grave above -# T - Tilde above -# t - tilde below -# B - Breve Above -# b - breve below -# U - Diaeresis Above -# u - diaeresis below -# H - Hook Above -# N - Horn Above -*/ -static const char * const g1E00Dec = -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E00 - U+1E0F - "Ar ar BD bD Bd bd Bl bl CcAccADD dD Dd dd Dl dl " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E10 - U+1E1F - "Dc dc Dx dx ELGeLGELAeLAEx ex Et et EcBecBFD fD " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E20 - U+1E2F - "GL gL HD hD Hd hd HU hU Hc hc Hb hb It it IUAiUA" -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E30 - U+1E3F - "KA kA Kd kd Kl kl Ld ld LdLldLLl ll Lx lx MA mA " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E40 - U+1E4F - "MD mD Md md ND nD Nd nd Nl nl Nx nx OTAoTAOTUoTU" -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E50 - U+1E5F - "OLGoLGOLAoLAPA pA PD pD RD rD Rd rd RdLrdLRl rl " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E60 - U+1E6F - "SD sD Sd sd SADsADSBDsBDSdDsdDTD tD Td td Tl tl " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E70 - U+1E7F - "Tx tx Uu uu Ut ut Ux ux UTAuTAULUuLUVT vT Vd vd " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E80 - U+1E8F - "WG wG WA wA WU wU WD wD Wd wd XD xD XU xU YD Yd " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1E90 - U+1E9F - "ZX zX Zd zd Zl zl Hl tU wR yR aH " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1EA0 - U+1EAF - "Ad ad AH aH AXAaXAAXGaXGAXHaXHAXTaXTAdXadXABAaBA" -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1EB0 - U+1EBF - "ABGaBGABHaBHABTaBTAdBadBEd ed EH eH ET eT EXAeXA" -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1EC0 - U+1ECF - "EXGeXGEXHeXHEXTeXTEdXedXIH iH Id id Od od OH oH " -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1ED0 - U+1EDF - "OXAoXAOXGoXGOXHoXHOXToXTOdXodXOAnoAnOGnoGnOHnoHn" -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1EE0 - U+1EEF - "OHToHTOdTodTUd ud UH uh UAnuAnUGnuGnUHnuHnUTnuTn" -//0 1 2 3 4 5 6 7 8 9 A B C D E F U+1EF0 - U+1EFF - "UdnudnYG yG Yd yd YH yH YT yT " -; -//------------------------------------------------------------------------ -static void CCodeToMacRoman(char aIn, char& aOut,short aWidth, short aHeight, short& oXadj, short& oYadj) -{ - aOut = ' '; - oXadj = oYadj = 0; - switch(aIn) - { - case 'r' : aOut = '\xfb'; oYadj = aHeight * 5 / 6; break ;// # r - ring below - case 'R' : aOut = '\xfb'; break ;// # R - Ring Above - case 'd' : aOut = '\xfa'; oYadj = aHeight * 5 / 6; break ;// # d - dot below - case 'D' : aOut = '\xfa'; break ;// # D - Dot Above - case 'l' : aOut = '_'; break ;// # l - line below - case 'L' : aOut = '\xf8'; break ;// # L - Line Above - case 'c' : aOut = '\xfc'; break ;// # c - cedilla - case 'A' : aOut = '\xab'; break ;// # A - Acute - case 'x' : aOut = '\xf6'; oYadj= aHeight * 5 / 6; break ;// # x - circumflex below - case 'X' : aOut = '\xf6'; break ;// # X - Circumflex Above - case 'G' : aOut = '`'; break ;// # G - Grave above - case 'T' : aOut = '\xf7'; break ;// # T - Tilde above - case 't' : aOut = '\xf7'; oYadj= aHeight * 5 / 6; break ;// # t - tilde below - case 'B' : aOut = '\xf9'; break ;// # B - Breve Above - case 'b' : aOut = '\xf9'; oYadj= aHeight * 5 / 6; break ;// # b - breve below - case 'U' : aOut = '\xac'; break ;// # U - Diaeresis Above - case 'u' : aOut = '\xac'; oYadj= aHeight * 5 / 6; break ;// # u - diaeresis below - case 'H' : aOut = ','; oYadj= - aHeight * 5 / 6; break ;// # H - Hook Above - case 'n' : aOut = ','; oYadj= - aHeight * 5 / 6; oXadj = aWidth /4; break ;// # N - Horn Above - default: NS_ASSERTION(0, "unknown ccode"); - break; - } -} - -PRBool nsUnicodeRenderingToolkit :: LatinFallbackGetWidth( - const PRUnichar *aCharPt, - short& oWidth) -{ - if(0x1E00 == (0xFF00 & *aCharPt)) - { - PRInt32 idx = 3 * ( *aCharPt & 0x00FF); - if(' ' != g1E00Dec[idx]) - { - GetScriptTextWidth(g1E00Dec+idx, 1, oWidth); - return PR_TRUE; - } - } - return PR_FALSE; -} -//------------------------------------------------------------------------ - -PRBool nsUnicodeRenderingToolkit :: LatinFallbackDrawChar( - const PRUnichar *aCharPt, - PRInt32 x, - PRInt32 y, - short& oWidth) -{ - if(0x1E00 == (0xFF00 & *aCharPt)) - { - PRInt32 idx = 3 * ( *aCharPt & 0x00FF); - if(' ' != g1E00Dec[idx]) - { - CGrafPtr thePort; - ::GetPort((GrafPtr*)&thePort); - short aSize = ::GetPortTextSize(thePort); - short dummy; - short realwidth; - char comb[2]; - short xadj; - short yadj; - short yadjB=0; - - PRBool baseTooBig = ('A'<= g1E00Dec[idx] ) && (g1E00Dec[idx] <= 'Z' ) - || ('f' == g1E00Dec[idx])|| ('l' == g1E00Dec[idx])|| ('k' == g1E00Dec[idx]); - PRBool firstIsAbove = ('A'<= g1E00Dec[idx+1]) && (g1E00Dec[idx+1] <= 'Z') ; - PRBool secondIsAbove = ('A'<= g1E00Dec[idx+2]) && (g1E00Dec[idx+2] <= 'Z') ; - - GetScriptTextWidth(g1E00Dec+idx, 1, oWidth); - if(baseTooBig && (firstIsAbove ||secondIsAbove )) - ::TextSize(aSize *3/4); - - DrawScriptText(g1E00Dec+idx, 1, x, y, realwidth); - - if(baseTooBig && (firstIsAbove ||secondIsAbove )) - ::TextSize(aSize); - if(' ' != g1E00Dec[idx+1]) { - CCodeToMacRoman(g1E00Dec[idx+1],comb[0], realwidth, aSize, xadj, yadj); - - GetScriptTextWidth(comb, 1, dummy); - - DrawScriptText( comb, 1, x + xadj + ( realwidth - dummy ) / 2, y + yadj + yadjB, dummy); - } - if(' ' != g1E00Dec[idx+2]) { - if( firstIsAbove && secondIsAbove) - yadjB = yadjB - aSize / 6; - - CCodeToMacRoman(g1E00Dec[idx+2],comb[0], realwidth, aSize, xadj, yadj); - GetScriptTextWidth(comb, 1, dummy); - DrawScriptText( comb, 1, x + xadj+ ( realwidth - dummy ) / 2, y+ yadj + yadjB, dummy); - } - return PR_TRUE; - } - } - return PR_FALSE; -} - -//------------------------------------------------------------------------ -void nsUnicodeRenderingToolkit :: GetScriptTextWidth( - const char* buf, - ByteCount aLen, - short& oWidth) -{ - oWidth = ::TextWidth(buf, 0, aLen); -} - -#if MOZ_MATHML -//------------------------------------------------------------------------ -void nsUnicodeRenderingToolkit::GetScriptTextBoundingMetrics( - const char* buf, - ByteCount aLen, - ScriptCode aScript, - nsBoundingMetrics& oBoundingMetrics) -{ - Point scale = { 1, 1 }; - Fixed stackWidths[STACK_TRESHOLD], *widths; - Fixed stackLefts[STACK_TRESHOLD], *lefts; - Rect stackRects[STACK_TRESHOLD], *rects; - OSStatus err; - - NS_PRECONDITION(aLen > 0, "length must be greater than 0"); - - if(aLen > STACK_TRESHOLD) - { - widths = (Fixed*) nsMemory::Alloc(aLen * sizeof(Fixed)); - lefts = (Fixed*) nsMemory::Alloc(aLen * sizeof(Fixed)); - rects = (Rect*) nsMemory::Alloc(aLen * sizeof(Rect)); - - // if any of the allocations failed the 'else' case below will be executed - } - else - { - widths = stackWidths; - lefts = stackLefts; - rects = stackRects; - } - - if(!GetOutlinePreferred()) - SetOutlinePreferred(PR_TRUE); - - if(widths && lefts && rects && - (err = ::OutlineMetrics(aLen, buf, scale, scale, NULL, NULL, widths, lefts, rects)) == noErr) - { - ByteCount byteIndex = 0, glyphIndex = 0; - - while(byteIndex < aLen) - { - nsBoundingMetrics bounds; - bounds.leftBearing = rects[glyphIndex].left + FixRound(lefts[glyphIndex]); - bounds.rightBearing = rects[glyphIndex].right + FixRound(lefts[glyphIndex]); - bounds.ascent = rects[glyphIndex].bottom; - bounds.descent = -rects[glyphIndex].top; - bounds.width = FixRound(widths[glyphIndex]); - - if(glyphIndex == 0) - oBoundingMetrics = bounds; - else - oBoundingMetrics += bounds; - - // for two byte characters byteIndex will increase by 2 - // while glyph index will only increase by 1 - if(CharacterByteType((Ptr) buf, byteIndex, aScript) == smFirstByte) - byteIndex += 2; - else - byteIndex++; - glyphIndex++; - } - } - else - { - NS_WARNING("OulineMetrics failed"); - - FontInfo fInfo; - ::GetFontInfo(&fInfo); - - oBoundingMetrics.leftBearing = 0; - oBoundingMetrics.rightBearing = ::TextWidth(buf, 0, aLen); - oBoundingMetrics.ascent = fInfo.ascent; - oBoundingMetrics.descent = fInfo.descent; - oBoundingMetrics.width = oBoundingMetrics.rightBearing; - } - - if(aLen > STACK_TRESHOLD) - { - if(widths) - nsMemory::Free(widths); - if(lefts) - nsMemory::Free(lefts); - if(rects) - nsMemory::Free(rects); - } -} -#endif // MOZ_MATHML - -//------------------------------------------------------------------------ -void nsUnicodeRenderingToolkit :: DrawScriptText( - const char* buf, - ByteCount aLen, - PRInt32 x, - PRInt32 y, - short& oWidth) -{ - ::MoveTo(x, y); - ::DrawText(buf,0,aLen); - - Point penLoc; - ::GetPen(&penLoc); - oWidth = penLoc.h - x; -} -//------------------------------------------------------------------------ - -nsresult -nsUnicodeRenderingToolkit::GetTextSegmentWidth( - const PRUnichar *aString, PRUint32 aLength, - short fontNum, nsUnicodeFontMappingMac& fontMapping, - PRUint32& oWidth) -{ - nsTextDimensions dim; - nsresult res = GetTextSegmentDimensions(aString, aLength, fontNum, fontMapping, dim); - oWidth = dim.width; - return res; -} -//------------------------------------------------------------------------ - - -nsresult -nsUnicodeRenderingToolkit::GetTextSegmentDimensions( - const PRUnichar *aString, PRUint32 aLength, - short fontNum, nsUnicodeFontMappingMac& fontMapping, - nsTextDimensions& oDim) -{ - oDim.Clear(); - if(aLength == 0 || fontNum == IGNORABLE_FONT_NUM) - return NS_OK; - NS_PRECONDITION(BAD_FONT_NUM != fontNum, "illegal font num"); - PRUint32 processLen = 0; - char *heapBuf = nsnull; - PRUint32 heapBufSize = 0; - short thisWidth = 0; - char stackBuf[STACK_TRESHOLD]; - char *buf ; - ByteCount processBytes; - ByteCount outLen; - const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts(); - - ::TextFont(fontNum); - - FontInfo fInfo; - ::GetFontInfo(&fInfo); - nsTextDimensions segDim; - segDim.ascent = fInfo.ascent; - segDim.descent = fInfo.descent; - oDim.Combine(segDim); - - // find buf from stack or heap. We only need to do this once in this function. - // put this out of the loop for performance... - ByteCount bufLen = aLength * 2 + 10; - if (bufLen > STACK_TRESHOLD) - { - if (bufLen > heapBufSize) - { - if (heapBuf) - nsMemory::Free(heapBuf); - heapBuf = (char*) nsMemory::Alloc(bufLen); - heapBufSize = bufLen; - if (nsnull == heapBuf) - return NS_ERROR_OUT_OF_MEMORY; - } - buf = heapBuf; - } - else - { - bufLen = STACK_TRESHOLD; - buf = stackBuf; - } - do { - outLen = 0; - processBytes = 0; - - if(fontMapping.ConvertUnicodeToGlyphs(fontNum, aString, aLength - processLen, - buf, bufLen, outLen, processBytes, 0)) - { - GetScriptTextWidth(buf, outLen, thisWidth); - - segDim.Clear(); - segDim.width = thisWidth; - oDim.Combine(segDim); - - NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result"); - - PRInt32 processUnicode = processBytes / 2; - processLen += processUnicode; - aString += processUnicode; - } - - // Cannot precess by TEC, process one char a time by fallback mechanism - if (processLen < aLength) - { - PRBool fallbackDone = PR_FALSE; - segDim.Clear(); - - if (NS_IS_HIGH_SURROGATE(*aString) && - ((processLen+1) < aLength) && - NS_IS_LOW_SURROGATE(*(aString+1))) - { - const nsFont *font = &mGS->mFontMetrics->Font(); - fallbackDone = SurrogateGetDimensions(aString, segDim, fontNum, - font->size, - (font->weight > NS_FONT_WEIGHT_NORMAL), - ((NS_FONT_STYLE_ITALIC == font->style) || - (NS_FONT_STYLE_OBLIQUE == font->style)), - mGS->mColor ); - if (fallbackDone) - { - oDim.Combine(segDim); - // for fallback measure/drawing, we always do one char a time. - aString += 2; - processLen += 2; - continue; - } - } -#ifndef DISABLE_TEC_FALLBACK - // Fallback by try different Script code - if (! IS_SKIP_TEC_FALLBACK(*aString)) - fallbackDone = TECFallbackGetDimensions(aString, segDim, fontNum, fontMapping); -#endif - - // - // We really don't care too much of performance after this - // This will only be called when we cannot display this character in ANY mac script avaliable - // -#ifndef DISABLE_ATSUI_FALLBACK - // Fallback by using ATSUI - if (!fallbackDone) - { - const nsFont *font = &mGS->mFontMetrics->Font(); - fallbackDone = ATSUIFallbackGetDimensions(aString, segDim, fontNum, - font->size, - (font->weight > NS_FONT_WEIGHT_NORMAL), - ((NS_FONT_STYLE_ITALIC == font->style) || - (NS_FONT_STYLE_OBLIQUE == font->style)), - mGS->mColor ); - } - -#endif - if(! fallbackDone) { - if(IS_ZERO_WIDTH_CHAR(*aString)) - { - fallbackDone = PR_TRUE; - } - } -#ifndef DISABLE_LATIN_FALLBACK - if (!fallbackDone) - { - fallbackDone = LatinFallbackGetWidth(aString, thisWidth); - if (fallbackDone) - segDim.width = thisWidth; - } -#endif -#ifndef DISABLE_PRECOMPOSEHANGUL_FALLBACK - if (!fallbackDone) - { - fallbackDone = PrecomposeHangulFallbackGetWidth(aString, thisWidth, - scriptFallbackFonts[smKorean], fontNum); - if (fallbackDone) - segDim.width = thisWidth; - } -#endif -#ifndef DISABLE_TRANSLITERATE_FALLBACK - // Fallback to Transliteration - if (!fallbackDone) - { - fallbackDone = TransliterateFallbackGetWidth(aString, thisWidth); - if (fallbackDone) - segDim.width = thisWidth; - } -#endif -#ifndef DISABLE_UPLUS_FALLBACK - // Fallback to UPlus - if (!fallbackDone) - { - fallbackDone = UPlusFallbackGetWidth(aString, thisWidth); - if (fallbackDone) - segDim.width = thisWidth; - } -#endif - - // Fallback to question mark - if (!fallbackDone) - { - QuestionMarkFallbackGetWidth(aString, thisWidth); - if (fallbackDone) - segDim.width = thisWidth; - } - - oDim.Combine(segDim); - // for fallback measure/drawing, we always do one char a time. - aString++; - processLen++; - } - } while (processLen < aLength); - - // release buffer if it is from heap - if (heapBuf) - nsMemory::Free(heapBuf); - - return NS_OK; -} -//------------------------------------------------------------------------ - -#ifdef MOZ_MATHML -nsresult -nsUnicodeRenderingToolkit::GetTextSegmentBoundingMetrics( - const PRUnichar *aString, PRUint32 aLength, - short fontNum, nsUnicodeFontMappingMac& fontMapping, - nsBoundingMetrics& oBoundingMetrics) -{ - oBoundingMetrics.Clear(); - if(aLength == 0 || fontNum == IGNORABLE_FONT_NUM) - return NS_OK; - NS_PRECONDITION(BAD_FONT_NUM != fontNum, "illegal font num"); - PRBool firstTime = PR_TRUE; - PRUint32 processLen = 0; - nsBoundingMetrics segBoundingMetrics; - char *heapBuf = nsnull; - PRUint32 heapBufSize = 0; - char stackBuf[STACK_TRESHOLD]; - char *buf; - ByteCount processBytes; - ByteCount outLen; - - ::TextFont(fontNum); - ScriptCode script = ::FontToScript(fontNum); - - // find buf from stack or heap. We only need to do this once in this function. - // put this out of the loop for performance... - ByteCount bufLen = aLength * 2 + 10; - if (bufLen > STACK_TRESHOLD) - { - if (bufLen > heapBufSize) - { - if (heapBuf) - nsMemory::Free(heapBuf); - heapBuf = (char*) nsMemory::Alloc(bufLen); - heapBufSize = bufLen; - if (nsnull == heapBuf) - return NS_ERROR_OUT_OF_MEMORY; - } - buf = heapBuf; - } - else - { - bufLen = STACK_TRESHOLD; - buf = stackBuf; - } - - do { - outLen = 0; - processBytes = 0; - - if(fontMapping.ConvertUnicodeToGlyphs(fontNum, aString, aLength - processLen, - buf, bufLen, outLen, processBytes, 0)) - { - segBoundingMetrics.Clear(); - GetScriptTextBoundingMetrics(buf, outLen, script, segBoundingMetrics); - - if(firstTime) { - firstTime = PR_FALSE; - oBoundingMetrics = segBoundingMetrics; - } - else - oBoundingMetrics += segBoundingMetrics; - - NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result"); - - PRInt32 processUnicode = processBytes / 2; - processLen += processUnicode; - aString += processUnicode; - } - - // Cannot process by TEC, process one char a time by fallback mechanism - if (processLen < aLength) - { - PRBool fallbackDone = PR_FALSE; - segBoundingMetrics.Clear(); - - if (NS_IS_HIGH_SURROGATE(*aString) && - ((processLen+1) < aLength) && - NS_IS_LOW_SURROGATE(*(aString+1)) ) - { - const nsFont *font = &mGS->mFontMetrics->Font(); - fallbackDone = SurrogateGetBoundingMetrics(aString, segBoundingMetrics, fontNum, - font->size, - (font->weight > NS_FONT_WEIGHT_NORMAL), - ((NS_FONT_STYLE_ITALIC == font->style) || - (NS_FONT_STYLE_OBLIQUE == font->style)), - mGS->mColor ); - if (fallbackDone) - { - if (firstTime) { - firstTime = PR_FALSE; - oBoundingMetrics = segBoundingMetrics; - } - else - oBoundingMetrics += segBoundingMetrics; - aString += 2; - processLen += 2; - continue; - } - } -#ifndef DISABLE_TEC_FALLBACK - if (! IS_SKIP_TEC_FALLBACK(*aString)) - fallbackDone = TECFallbackGetBoundingMetrics(aString, segBoundingMetrics, fontNum, fontMapping); -#endif - -#ifndef DISABLE_ATSUI_FALLBACK - // Fallback by using ATSUI - if (!fallbackDone) - { - const nsFont *font = &mGS->mFontMetrics->Font(); - fallbackDone = ATSUIFallbackGetBoundingMetrics(aString, segBoundingMetrics, fontNum, - font->size, - (font->weight > NS_FONT_WEIGHT_NORMAL), - ((NS_FONT_STYLE_ITALIC == font->style) || - (NS_FONT_STYLE_OBLIQUE == font->style)), - mGS->mColor ); - } - -#endif - if(! fallbackDone) { - if(IS_ZERO_WIDTH_CHAR(*aString)) - { - fallbackDone = PR_TRUE; - } - } - - if (firstTime) { - firstTime = PR_FALSE; - oBoundingMetrics = segBoundingMetrics; - } - else - oBoundingMetrics += segBoundingMetrics; - // for fallback measure/drawing, we always do one char a time. - aString++; - processLen++; - } - } while (processLen < aLength); - - // release buffer if it is from heap - if (heapBuf) - nsMemory::Free(heapBuf); - - return NS_OK; -} -#endif // MOZ_MATHML -//------------------------------------------------------------------------ - - -nsresult nsUnicodeRenderingToolkit :: DrawTextSegment( - const PRUnichar *aString, PRUint32 aLength, - short fontNum, nsUnicodeFontMappingMac& fontMapping, - PRInt32 x, PRInt32 y, PRUint32& oWidth) -{ - if(aLength == 0 || fontNum == IGNORABLE_FONT_NUM) { - oWidth = 0; - return NS_OK; - } - NS_PRECONDITION(BAD_FONT_NUM != fontNum, "illegal font num"); - short textWidth = 0; - PRUint32 processLen = 0; - char *heapBuf = nsnull; - PRUint32 heapBufSize = 0; - short thisWidth = 0; - char stackBuf[STACK_TRESHOLD]; - char *buf ; - ByteCount processBytes; - ByteCount outLen; - const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts(); - - ::TextFont(fontNum); - - // find buf from stack or heap. We only need to do this once in this function. - // put this out of the loop for performance... - ByteCount bufLen = aLength * 2 + 10; - if( bufLen > STACK_TRESHOLD) - { - if(bufLen > heapBufSize ) - { - if(heapBuf) - delete[] heapBuf; - heapBuf = new char [bufLen]; - heapBufSize = bufLen; - if(nsnull == heapBuf) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - buf = heapBuf; - } else { - bufLen = STACK_TRESHOLD; - buf = stackBuf; - } - - do { - outLen = 0; - processBytes = 0; - - if(fontMapping.ConvertUnicodeToGlyphs(fontNum, aString, aLength - processLen, - buf, bufLen, outLen, processBytes, 0)) - { - DrawScriptText(buf, outLen, x, y, thisWidth); - - textWidth += thisWidth; - x += thisWidth; - - NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result"); - - PRInt32 processUnicode = processBytes / 2; - processLen += processUnicode; - aString += processUnicode; - } - - // Cannot precess by TEC, process one char a time by fallback mechanism - if( processLen < aLength) - { - PRBool fallbackDone = PR_FALSE; - - if (NS_IS_HIGH_SURROGATE(*aString) && - ((processLen+1) < aLength) && - NS_IS_LOW_SURROGATE(*(aString+1)) ) - { - const nsFont *font = &mGS->mFontMetrics->Font(); - fallbackDone = SurrogateDrawChar(aString, x, y, thisWidth, fontNum, - font->size, - (font->weight > NS_FONT_WEIGHT_NORMAL), - ((NS_FONT_STYLE_ITALIC == font->style) || (NS_FONT_STYLE_OBLIQUE == font->style)), - mGS->mColor ); - if (fallbackDone) - { - textWidth += thisWidth; - x += thisWidth; - aString += 2; - processLen += 2; - continue; - } - } -#ifndef DISABLE_TEC_FALLBACK - // Fallback by try different Script code - if (! IS_SKIP_TEC_FALLBACK(*aString)) - fallbackDone = TECFallbackDrawChar(aString, x, y, thisWidth, fontNum, fontMapping); -#endif - // - // We really don't care too much of performance after this - // This will only be called when we cannot display this character in ANY mac script avaliable - // - -#ifndef DISABLE_ATSUI_FALLBACK - // Fallback by using ATSUI - if(! fallbackDone) { - const nsFont *font = &mGS->mFontMetrics->Font(); - fallbackDone = ATSUIFallbackDrawChar(aString, x, y, thisWidth, fontNum, - font->size, - (font->weight > NS_FONT_WEIGHT_NORMAL), - ((NS_FONT_STYLE_ITALIC == font->style) || (NS_FONT_STYLE_OBLIQUE == font->style)), - mGS->mColor ); - } -#endif - if(! fallbackDone) { - if(IS_ZERO_WIDTH_CHAR(*aString)) - { - thisWidth = 0; - fallbackDone = PR_TRUE; - } - } - -#ifndef DISABLE_LATIN_FALLBACK - if(! fallbackDone) - fallbackDone = LatinFallbackDrawChar(aString, x, y, thisWidth); -#endif -#ifndef DISABLE_PRECOMPOSEHANGUL_FALLBACK - if(! fallbackDone) - fallbackDone = PrecomposeHangulFallbackDrawChar(aString, x, y, thisWidth,scriptFallbackFonts[smKorean], fontNum); -#endif -#ifndef DISABLE_TRANSLITERATE_FALLBACK - // Fallback to Transliteration - if(! fallbackDone) { - fallbackDone = TransliterateFallbackDrawChar(aString, x, y, thisWidth); - } -#endif -#ifndef DISABLE_UPLUS_FALLBACK - // Fallback to U+xxxx - if(! fallbackDone) - fallbackDone = UPlusFallbackDrawChar(aString, x, y, thisWidth); -#endif - - // Fallback to question mark - if(! fallbackDone) - QuestionMarkFallbackDrawChar(aString, x, y, thisWidth); - - textWidth += thisWidth; - x += thisWidth; - - // for fallback measure/drawing, we always do one char a time. - aString++; - processLen++; - } - } while (processLen < aLength); - - // release buffer if it is from heap - if(heapBuf) - delete[] heapBuf; - - oWidth = textWidth; - return NS_OK; -} -//------------------------------------------------------------------------ - -nsresult -nsUnicodeRenderingToolkit::GetWidth(const PRUnichar *aString, PRUint32 aLength, - nscoord &aWidth, PRInt32 *aFontID) -{ - nsTextDimensions dim; - - nsresult res = GetTextDimensions(aString, aLength, dim, aFontID); - aWidth = dim.width; - return res; -} - -nsresult -nsUnicodeRenderingToolkit::GetTextDimensions(const PRUnichar *aString, PRUint32 aLength, - nsTextDimensions &aDim, PRInt32 *aFontID) -{ - nsresult res = NS_OK; - nsFontMetricsMac *metrics = (nsFontMetricsMac*) mGS->mFontMetrics; - nsUnicodeFontMappingMac* fontmap = metrics->GetUnicodeFontMapping(); - - PRUint32 i; - short fontNum[2]; - fontNum[0] = fontNum[1] = BAD_FONT_NUM; - PRUint32 start; - - nsTextDimensions textDim; - nsTextDimensions thisDim; - - for(i =0, start = 0; i < aLength; i++) - { - fontNum[ i % 2] = fontmap->GetFontID(aString[i]); - if ((fontNum[0] != fontNum[1]) && (0 != i)) - { // start new font run... - thisDim.Clear(); - res = GetTextSegmentDimensions(aString+start, i - start, fontNum[(i + 1) % 2], *fontmap, thisDim); - if (NS_FAILED (res)) - return res; - textDim.Combine(thisDim); - start = i; - } - } - res = GetTextSegmentDimensions(aString+start, aLength - start, fontNum[(i + 1) % 2], *fontmap, thisDim); - if (NS_FAILED (res)) - return res; - textDim.Combine(thisDim); - - aDim.width = NSToCoordRound(float(textDim.width) * mP2T); - aDim.ascent = NSToCoordRound(float(textDim.ascent) * mP2T); - aDim.descent = NSToCoordRound(float(textDim.descent) * mP2T); - return res; -} -//------------------------------------------------------------------------ - -#ifdef MOZ_MATHML -nsresult -nsUnicodeRenderingToolkit::GetTextBoundingMetrics(const PRUnichar *aString, PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics, PRInt32 *aFontID) -{ - nsresult res = NS_OK; - nsFontMetricsMac *metrics = (nsFontMetricsMac*) mGS->mFontMetrics; - nsUnicodeFontMappingMac* fontmap = metrics->GetUnicodeFontMapping(); - - PRUint32 i; - short fontNum[2]; - fontNum[0] = fontNum[1] = BAD_FONT_NUM; - PRUint32 start; - PRBool firstTime = PR_TRUE; - nsBoundingMetrics thisBoundingMetrics; - - for(i =0, start = 0; i < aLength; i++) - { - fontNum[ i % 2] = fontmap->GetFontID(aString[i]); - if ((fontNum[0] != fontNum[1]) && (0 != i)) - { // start new font run... - res = GetTextSegmentBoundingMetrics(aString+start, i - start, fontNum[(i + 1) % 2], *fontmap, thisBoundingMetrics); - if (NS_FAILED (res)) - return res; - if (firstTime) { - firstTime = PR_FALSE; - aBoundingMetrics = thisBoundingMetrics; - } - else - aBoundingMetrics += thisBoundingMetrics; - start = i; - } - } - res = GetTextSegmentBoundingMetrics(aString+start, aLength - start, fontNum[(i + 1) % 2], *fontmap, thisBoundingMetrics); - if (NS_FAILED (res)) - return res; - if (firstTime) - aBoundingMetrics = thisBoundingMetrics; - else - aBoundingMetrics += thisBoundingMetrics; - - aBoundingMetrics.leftBearing = NSToCoordRound(float(aBoundingMetrics.leftBearing) * mP2T); - aBoundingMetrics.rightBearing = NSToCoordRound(float(aBoundingMetrics.rightBearing) * mP2T); - aBoundingMetrics.ascent = NSToCoordRound(float(aBoundingMetrics.ascent) * mP2T); - aBoundingMetrics.descent = NSToCoordRound(float(aBoundingMetrics.descent) * mP2T); - aBoundingMetrics.width = NSToCoordRound(float(aBoundingMetrics.width) * mP2T); - - return res; -} -#endif // MOZ_MATHML - -//------------------------------------------------------------------------ - -nsresult -nsUnicodeRenderingToolkit::DrawString(const PRUnichar *aString, PRUint32 aLength, - nscoord aX, nscoord aY, PRInt32 aFontID, - const nscoord* aSpacing) -{ - nsresult res = NS_OK; - nsFontMetricsMac *metrics = (nsFontMetricsMac*) mGS->mFontMetrics; - nsUnicodeFontMappingMac* fontmap = metrics->GetUnicodeFontMapping(); - - PRInt32 x = aX; - PRInt32 transformedY = aY; - mGS->mTMatrix.TransformCoord(&x, &transformedY); - - PRUint32 i; - PRInt32 currentX = aX; - PRUint32 thisWidth = 0; - - if (aSpacing) - { - // fix me ftang - handle (mRightToLeftText) here - for (i = 0; i < aLength; ) - { - PRUint32 drawLen; - short curFontNum = fontmap->GetFontID(aString[i]); - - for (drawLen = 1; (i + drawLen) < aLength; drawLen++) - { - PRUnichar uc = aString[i+drawLen]; - if(! (IS_CONTEXTUAL_CHARS(uc) || - IS_FORMAT_CONTROL_CHARS(uc) || - IS_COMBINING_CHARS(uc)) ) { - break; - } - } - - PRInt32 transformedX = currentX, ignoreY = 0; - mGS->mTMatrix.TransformCoord(&transformedX, &ignoreY); - res = DrawTextSegment(aString+i, drawLen, curFontNum, *fontmap, transformedX, transformedY, thisWidth); - if (NS_FAILED(res)) - return res; - - for (PRUint32 j = 0; j < drawLen; j++) - currentX += aSpacing[i + j]; - - i += drawLen; - } - } - else // no spacing array - { - short thisFont, nextFont; - - PRUint32 start; - - // normal left to right - thisFont = fontmap->GetFontID(aString[0]); - for (i = 1, start = 0; i < aLength; i++) - { - PRUnichar uch = aString[i]; - if(! IS_FORMAT_CONTROL_CHARS(uch)) - { - nextFont = fontmap->GetFontID(uch); - if (thisFont != nextFont) - { - // start new font run... - PRInt32 transformedX = currentX, ignoreY = 0; - mGS->mTMatrix.TransformCoord(&transformedX, &ignoreY); - - res = DrawTextSegment(aString + start, i - start, thisFont, *fontmap, transformedX, transformedY, thisWidth); - if (NS_FAILED(res)) - return res; - - currentX += NSToCoordRound(float(thisWidth) * mP2T); - start = i; - thisFont = nextFont; - } - } - } - - PRInt32 transformedX = currentX, ignoreY = 0; - mGS->mTMatrix.TransformCoord(&transformedX, &ignoreY); - res = DrawTextSegment(aString+start, aLength-start, thisFont, *fontmap, transformedX, transformedY, thisWidth); - if (NS_FAILED(res)) - return res; - } - - return NS_OK; -} - - -//------------------------------------------------------------------------ -nsresult -nsUnicodeRenderingToolkit::PrepareToDraw(float aP2T, nsIDeviceContext* aContext, - nsGraphicState* aGS, - CGrafPtr aPort, PRBool aRightToLeftText ) -{ - mP2T = aP2T; - mContext = aContext; - mGS = aGS; - mPort = aPort; - mRightToLeftText = aRightToLeftText; - return NS_OK; -} diff --git a/gfx/src/mac/nsUnicodeRenderingToolkit.h b/gfx/src/mac/nsUnicodeRenderingToolkit.h deleted file mode 100644 index 1c4e667ce0b0..000000000000 --- a/gfx/src/mac/nsUnicodeRenderingToolkit.h +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsUnicodeRenderingToolkit_h__ -#define nsUnicodeRenderingToolkit_h__ - -#include - -#include "nsATSUIUtils.h" - -#include "nsCOMPtr.h" -#include "nsISaveAsCharset.h" -#include "nsIRenderingContext.h" - -class nsUnicodeFallbackCache; -class nsIDeviceContext; -class nsGraphicState; -class nsUnicodeFontMappingMac; - -class nsUnicodeRenderingToolkit -{ -public: - nsUnicodeRenderingToolkit() {}; - virtual ~nsUnicodeRenderingToolkit() {}; - - nsresult PrepareToDraw(float aP2T, nsIDeviceContext* aContext, nsGraphicState* aGS, - CGrafPtr aPort, PRBool aRightToLeftText); - nsresult GetTextDimensions(const PRUnichar *aString, PRUint32 aLength, - nsTextDimensions &aDimension, PRInt32 *aFontID); - nsresult GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, - PRInt32 *aFontID); - - nsresult DrawString(const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, - PRInt32 aFontID, - const nscoord* aSpacing); -#ifdef MOZ_MATHML - nsresult GetTextBoundingMetrics(const PRUnichar *aString, PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics, PRInt32 *aFontID); -#endif // MOZ_MATHML - -private: - // Unicode text measure/drawing functions - PRBool TECFallbackGetDimensions(const PRUnichar *pChar, nsTextDimensions& oWidth, - short fontNum, nsUnicodeFontMappingMac& fontMapping); - PRBool TECFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth, - short fontNum, nsUnicodeFontMappingMac& fontMapping); - - PRBool ATSUIFallbackGetDimensions(const PRUnichar *pChar, nsTextDimensions& oWidth, short fontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor); - PRBool ATSUIFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth, short fontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor); - PRBool SurrogateGetDimensions(const PRUnichar *aSurrogatePt, nsTextDimensions& oWidth, short fontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor); - PRBool SurrogateDrawChar(const PRUnichar *aSurrogatePt, PRInt32 x, PRInt32 y, short& oWidth, short fontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor); - - PRBool UPlusFallbackGetWidth(const PRUnichar *pChar, short& oWidth); - PRBool UPlusFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth); - - PRBool QuestionMarkFallbackGetWidth(const PRUnichar *pChar, short& oWidth); - PRBool QuestionMarkFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth); - - PRBool LatinFallbackGetWidth(const PRUnichar *pChar, short& oWidth); - PRBool LatinFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth); - PRBool PrecomposeHangulFallbackGetWidth(const PRUnichar *pChar, short& oWidth,short koreanFont, short origFont); - PRBool PrecomposeHangulFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth, - short koreanFont, short origFont); - PRBool TransliterateFallbackGetWidth(const PRUnichar *pChar, short& oWidth); - PRBool TransliterateFallbackDrawChar(const PRUnichar *pChar, PRInt32 x, PRInt32 y, short& oWidth); - PRBool LoadTransliterator(); - - void GetScriptTextWidth(const char* aText, ByteCount aLen, short& aWidth); - void DrawScriptText(const char* aText, ByteCount aLen, PRInt32 x, PRInt32 y, short& aWidth); - - nsresult GetTextSegmentWidth(const PRUnichar *aString, PRUint32 aLength, short fontNum, - nsUnicodeFontMappingMac& fontMapping, PRUint32& oWidth); - nsresult GetTextSegmentDimensions(const PRUnichar *aString, PRUint32 aLength, short fontNum, - nsUnicodeFontMappingMac& fontMapping, nsTextDimensions& aDimension); - nsresult DrawTextSegment(const PRUnichar *aString, PRUint32 aLength, short fontNum, - nsUnicodeFontMappingMac& fontMapping, PRInt32 x, PRInt32 y, PRUint32& oWidth); - -#ifdef MOZ_MATHML - PRBool TECFallbackGetBoundingMetrics(const PRUnichar *pChar, nsBoundingMetrics& oBoundingMetrics, - short fontNum, nsUnicodeFontMappingMac& fontMapping); - PRBool ATSUIFallbackGetBoundingMetrics(const PRUnichar *pChar, nsBoundingMetrics& oBoundingMetrics, short fontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor); - PRBool SurrogateGetBoundingMetrics(const PRUnichar *aSurrogatePt, nsBoundingMetrics& oBoundingMetrics, short fontNum, - short aSize, PRBool aBold, PRBool aItalic, nscolor aColor); - void GetScriptTextBoundingMetrics(const char* aText, ByteCount aLen, ScriptCode aScript, nsBoundingMetrics& oBoundingMetrics); - nsresult GetTextSegmentBoundingMetrics(const PRUnichar *aString, PRUint32 aLength, short fontNum, - nsUnicodeFontMappingMac& fontMapping, nsBoundingMetrics& oBoundingMetrics); -#endif // MOZ_MATHML - - nsUnicodeFallbackCache* GetTECFallbackCache(); -private: - float mP2T; // Pixel to Twip conversion factor - nsIDeviceContext *mContext; - nsGraphicState *mGS; // current graphic state - shortcut for mCurrentSurface->GetGS() - - CGrafPtr mPort; // current grafPort - shortcut for mCurrentSurface->GetPort() - nsATSUIToolkit mATSUIToolkit; - nsCOMPtr mTrans; - PRBool mRightToLeftText; - -}; -#endif /* nsUnicodeRenderingToolkit_h__ */ diff --git a/gfx/src/mac/printerplugin/Resources/English.lproj/Localizable.strings b/gfx/src/mac/printerplugin/Resources/English.lproj/Localizable.strings deleted file mode 100644 index 0beacdda089c..000000000000 Binary files a/gfx/src/mac/printerplugin/Resources/English.lproj/Localizable.strings and /dev/null differ diff --git a/gfx/src/mac/printerplugin/Resources/English.lproj/PrintDialogPDE.r b/gfx/src/mac/printerplugin/Resources/English.lproj/PrintDialogPDE.r deleted file mode 100644 index 9f63be44dd9f..000000000000 --- a/gfx/src/mac/printerplugin/Resources/English.lproj/PrintDialogPDE.r +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#include "PrintDialogPDE.h" - - -resource 'CNTL' (ePrintSelectionControlID, "Print Selection Only", purgeable) { -{110, 72, 125, 250}, /* Rect Top, Left, Bottom, Right */ - 0, /* initial value */ - invisible, /* attributes */ - 1, /* max */ - 0, /* min */ - kControlCheckBoxAutoToggleProc, /* Type */ - 0, /* refcon */ - "Print Selection" /* Title */ -}; - -resource 'CNTL' (ePrintFrameAsIsControlID, "Print Frames As Is", purgeable) { -{130, 72, 145, 250}, - 0, - invisible, - 1, - 0, - kControlRadioButtonAutoToggleProc, - 0, - "As laid out on the screen" -}; - - -resource 'CNTL' (ePrintSelectedFrameControlID, "Print Selected Frame", purgeable) { -{150, 72, 165, 250}, - 0, - invisible, - 1, - 0, - kControlRadioButtonAutoToggleProc, - 0, - "The selected frame" -}; - - -resource 'CNTL' (ePrintFramesSeparatelyControlID, "Print Frames Separately", purgeable) { -{170, 72, 185, 250}, - 0, - invisible, - 1, - 0, - kControlRadioButtonAutoToggleProc, - 0, - "Each frame separately" -}; - - -resource 'CNTL' (eShrinkToFiControlID, "Print Shrink To Fit", purgeable) { -{190, 72, 205, 250}, - 0, - invisible, - 1, - 0, - kControlCheckBoxAutoToggleProc, - 0, - "Shrink To Fit Page Width" -}; - -resource 'CNTL' (eRadioGroupControlID, "Radio Group", purgeable) { -{130, 72, 205, 250}, - 0, - visible, - 1, - 0, - kControlRadioGroupProc, - 0, - "RadioGroup" -}; - diff --git a/toolkit/toolkit-makefiles.sh b/toolkit/toolkit-makefiles.sh index 5d542a29ce52..8b0a36e8a93e 100644 --- a/toolkit/toolkit-makefiles.sh +++ b/toolkit/toolkit-makefiles.sh @@ -99,7 +99,6 @@ MAKEFILES_gfx=" gfx/src/beos/Makefile gfx/src/psshared/Makefile gfx/src/photon/Makefile - gfx/src/mac/Makefile gfx/src/windows/Makefile gfx/src/thebes/Makefile gfx/tests/Makefile diff --git a/xpfe/bootstrap/appleevents/Makefile.in b/xpfe/bootstrap/appleevents/Makefile.in index 815bb50b3b44..1a33b9b44305 100644 --- a/xpfe/bootstrap/appleevents/Makefile.in +++ b/xpfe/bootstrap/appleevents/Makefile.in @@ -94,7 +94,6 @@ LIBXUL_LIBRARY = 1 LOCAL_INCLUDES = \ -I$(srcdir) \ -I$(srcdir)/.. \ - -I$(topsrcdir)/gfx/src/mac \ $(NULL) ifdef MOZ_XUL_APP diff --git a/xpfe/bootstrap/appleevents/nsAEWindowClass.cpp b/xpfe/bootstrap/appleevents/nsAEWindowClass.cpp index 424925ddfbae..9d4fe4edad78 100644 --- a/xpfe/bootstrap/appleevents/nsAEWindowClass.cpp +++ b/xpfe/bootstrap/appleevents/nsAEWindowClass.cpp @@ -52,8 +52,6 @@ #include "nsAEWindowClass.h" -#include "nsGfxUtils.h" - using namespace nsWindowUtils; /*---------------------------------------------------------------------------- diff --git a/xpfe/bootstrap/appleevents/nsAEWindowClass.h b/xpfe/bootstrap/appleevents/nsAEWindowClass.h index b0af01e2e5dc..54856210858f 100644 --- a/xpfe/bootstrap/appleevents/nsAEWindowClass.h +++ b/xpfe/bootstrap/appleevents/nsAEWindowClass.h @@ -43,6 +43,7 @@ #include "nsAEGenericClass.h" +#include "nsDebug.h" class AEWindowIterator : public AEClassIterator @@ -189,6 +190,87 @@ class AEWindowClass : public AEGenericClass }; +//------------------------------------------------------------------------ +// ValidateDrawingState +// +// Test that the current drawing environment is good, which means that +// we have a valid port (as far as we can tell) +//------------------------------------------------------------------------ +inline PRBool ValidateDrawingState() +{ + CGrafPtr curPort; + GDHandle curDevice; + + GetGWorld(&curPort, &curDevice); + + // see if the device is in the device list. If not, it probably means that + // it's the device for an offscreen GWorld. In that case, the current port + // should be set to that GWorld too. + { + GDHandle thisDevice = GetDeviceList(); + while (thisDevice) + { + if (thisDevice == curDevice) + break; + + thisDevice = GetNextDevice(thisDevice); + } + + if ((thisDevice == nil) && !IsPortOffscreen(curPort)) // nil device is OK only with GWorld + return false; + } + + return true; +} + +//------------------------------------------------------------------------ +// utility port setting class +// +// This code has to deal with the situation where the current port +// is a GWorld, and the current devices that GWorld's device. So +// when setting the port to an onscreen part, we always reset the +// current device to the main device. +//------------------------------------------------------------------------ +class StPortSetter +{ +public: + StPortSetter(CGrafPtr newPort) + { + InitSetter(newPort); + } + + StPortSetter(WindowPtr window) + { + InitSetter(GetWindowPort(window)); + } + + ~StPortSetter() + { + if (mPortChanged) + ::SetGWorld(mOldPort, mOldDevice); + NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); + } + +protected: + void InitSetter(CGrafPtr newPort) + { + NS_ASSERTION(ValidateDrawingState(), "Bad drawing state"); + // we assume that if the port has been set, then the port/GDevice are + // valid, and do nothing (for speed) + mPortChanged = (newPort != CGrafPtr(GetQDGlobalsThePort())); + if (mPortChanged) + { + ::GetGWorld(&mOldPort, &mOldDevice); + ::SetGWorld(newPort, ::IsPortOffscreen(newPort) ? nsnull : ::GetMainDevice()); + } + } + +protected: + Boolean mPortChanged; + CGrafPtr mOldPort; + GDHandle mOldDevice; +}; + #endif /* __AEWINDOWCLASS__ */ diff --git a/xpfe/bootstrap/appleevents/nsAEWordClass.cpp b/xpfe/bootstrap/appleevents/nsAEWordClass.cpp index fc45ac70bb03..5b33d6fee7aa 100644 --- a/xpfe/bootstrap/appleevents/nsAEWordClass.cpp +++ b/xpfe/bootstrap/appleevents/nsAEWordClass.cpp @@ -45,8 +45,6 @@ #include "AEWordClass.h" -#include "nsGfxUtils.h" - /*---------------------------------------------------------------------------- GetNumItems