diff --git a/mozilla/widget/macbuild/widget.xml b/mozilla/widget/macbuild/widget.xml index d91b6d9c0a3..e02f9b91def 100644 --- a/mozilla/widget/macbuild/widget.xml +++ b/mozilla/widget/macbuild/widget.xml @@ -1311,6 +1311,13 @@ Text Debug + + Name + nsStylClipboardUtils.cpp + MacOS + Text + Debug + Name WidgetSupportDebug.shlb @@ -1597,6 +1604,11 @@ nsMacNativeUnicodeConverter.cpp MacOS + + Name + nsStylClipboardUtils.cpp + MacOS + Name WidgetSupportDebug.shlb @@ -2862,6 +2874,13 @@ Text Debug + + Name + nsStylClipboardUtils.cpp + MacOS + Text + Debug + Name WidgetSupport.shlb @@ -3148,6 +3167,11 @@ nsMacNativeUnicodeConverter.cpp MacOS + + Name + nsStylClipboardUtils.cpp + MacOS + Name WidgetSupport.shlb @@ -4399,6 +4423,13 @@ Text Debug + + Name + nsStylClipboardUtils.cpp + MacOS + Text + Debug + Name WidgetSupportDebug.shlb @@ -4675,6 +4706,11 @@ nsMacNativeUnicodeConverter.cpp MacOS + + Name + nsStylClipboardUtils.cpp + MacOS + Name WidgetSupportDebug.shlb @@ -5926,6 +5962,13 @@ Text Debug + + Name + nsStylClipboardUtils.cpp + MacOS + Text + Debug + Name WidgetSupport.shlb @@ -6202,6 +6245,11 @@ nsMacNativeUnicodeConverter.cpp MacOS + + Name + nsStylClipboardUtils.cpp + MacOS + Name WidgetSupport.shlb @@ -6529,6 +6577,12 @@ nsMacNativeUnicodeConverter.cpp MacOS + + widgetDebug.shlb + Name + nsStylClipboardUtils.cpp + MacOS + Static Libs diff --git a/mozilla/widget/src/mac/Makefile.in b/mozilla/widget/src/mac/Makefile.in index 8bf6346f4bc..8ff205b5ade 100644 --- a/mozilla/widget/src/mac/Makefile.in +++ b/mozilla/widget/src/mac/Makefile.in @@ -87,6 +87,7 @@ CPPSRCS = nsAppShell.cpp \ nsWidgetSupport.cpp \ nsWindow.cpp \ nsMacNativeUnicodeConverter.cpp \ + nsStylClipboardUtils.cpp \ $(GFX_LCPPSRCS) \ $(NULL) diff --git a/mozilla/widget/src/mac/nsStylClipboardUtils.cpp b/mozilla/widget/src/mac/nsStylClipboardUtils.cpp new file mode 100644 index 00000000000..1168521c802 --- /dev/null +++ b/mozilla/widget/src/mac/nsStylClipboardUtils.cpp @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.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. + * + * The Initial Developer of the Original Code is is Netscape + * Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsStylClipboardUtils.h" +#include "nsMemory.h" +#include "nsCarbonHelpers.h" + +#include + +nsresult CreateStylFromScriptRuns(ScriptCodeRun *scriptCodeRuns, + ItemCount scriptRunOutLen, + char **stylData, + PRInt32 *stylLen) +{ + PRInt32 scrpRecLen = sizeof(short) + sizeof(ScrpSTElement) * scriptRunOutLen; + StScrpRec *scrpRec = NS_REINTERPRET_CAST(StScrpRec*, + nsMemory::Alloc(scrpRecLen)); + NS_ENSURE_TRUE(scrpRec, NS_ERROR_OUT_OF_MEMORY); + + OSErr err; + Str255 themeFontName; + SInt16 textSize; + Style textStyle; + short fontFamilyID; + FontInfo fontInfo; + RGBColor textColor; + textColor.red = textColor.green = textColor.blue = 0; + + // save font settings + CGrafPtr curPort; + short saveFontFamilyID; + SInt16 saveTextSize; + Style saveTextStyle; + ::GetPort((GrafPtr*)&curPort); + saveFontFamilyID = ::GetPortTextFont(curPort); + saveTextSize = ::GetPortTextSize(curPort); + saveTextStyle = ::GetPortTextFace(curPort); + + scrpRec->scrpNStyles = scriptRunOutLen; + for (ItemCount i = 0; i < scriptRunOutLen; i++) { + scrpRec->scrpStyleTab[i].scrpStartChar = scriptCodeRuns[i].offset; + + err = ::GetThemeFont( +#if TARGET_CARBON + kThemeApplicationFont, +#else + kThemeSystemFont, +#endif + scriptCodeRuns[i].script, + themeFontName, + &textSize, + &textStyle); + + if (err != noErr) + break; + + ::GetFNum(themeFontName, &fontFamilyID); + ::TextFont(fontFamilyID); + ::TextSize(textSize); + ::TextFace(textStyle); + ::GetFontInfo(&fontInfo); + + scrpRec->scrpStyleTab[i].scrpFont = fontFamilyID; + scrpRec->scrpStyleTab[i].scrpHeight = fontInfo.ascent + + fontInfo.descent + + fontInfo.leading; + scrpRec->scrpStyleTab[i].scrpAscent = fontInfo.ascent; + scrpRec->scrpStyleTab[i].scrpFace = textStyle; + scrpRec->scrpStyleTab[i].scrpSize = textSize; + scrpRec->scrpStyleTab[i].scrpColor = textColor; + } + + // restore font settings + ::TextFont(saveFontFamilyID); + ::TextSize(saveTextSize); + ::TextFace(saveTextStyle); + + if (err != noErr) { + nsMemory::Free(scrpRec); + return NS_ERROR_FAILURE; + } + + *stylData = NS_REINTERPRET_CAST(char*, scrpRec); + *stylLen = scrpRecLen; + + return NS_OK; +} diff --git a/mozilla/widget/src/mac/nsStylClipboardUtils.h b/mozilla/widget/src/mac/nsStylClipboardUtils.h new file mode 100644 index 00000000000..68f4c99a689 --- /dev/null +++ b/mozilla/widget/src/mac/nsStylClipboardUtils.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.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. + * + * The Initial Developer of the Original Code is is Netscape + * Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsStylClipboardUtils_h___ +#define nsStylClipboardUtils_h___ + +#include "prtypes.h" +#include "nscore.h" +#include + +nsresult CreateStylFromScriptRuns(ScriptCodeRun *scriptCodeRuns, + ItemCount scriptRunOutLen, + char **stylData, + PRInt32 *stylLen); + +#endif // nsStylClipboardUtils_h___