зеркало из https://github.com/mozilla/gecko-dev.git
Bug 418105: Remove non-cairo Mac gfx code from the tree, r=joshmoz, sr=vladimir, a1.9=beltzner
This commit is contained in:
Родитель
7d85b9f381
Коммит
5a55d3fa52
|
@ -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
|
|
@ -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 <rbs@maths.uq.edu.au>
|
||||
#
|
||||
# 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
|
|
@ -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
|
|
@ -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 <Gestalt.h>
|
||||
#include <FixMath.h>
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// 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;
|
||||
}
|
|
@ -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 <ATSUnicode.h>
|
||||
|
||||
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___
|
|
@ -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 <ConditionalMacros.h>
|
||||
#include <ControlDefinitions.h>
|
||||
#include <Menus.h>
|
||||
#include <MacWindows.h>
|
||||
#include <LowMem.h>
|
||||
|
||||
//
|
||||
// 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__ */
|
|
@ -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 <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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 <Types.h>
|
||||
#include <Quickdraw.h>
|
||||
|
||||
#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<nsIDeviceContextSpec> mSpec;
|
||||
GrafPtr mOldPort;
|
||||
nsCOMPtr<nsIScreenManager> mScreenManager;
|
||||
nsCOMPtr<nsIScreen> 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___ */
|
|
@ -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 <MacMemory.h>
|
||||
|
||||
#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<nsDrawingSurfaceMac*>(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<CGrafPtr>(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<CGContextRef>(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);
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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 <TextEdit.h> // 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<nsIAtom> mLangGroup;
|
||||
nsIDeviceContext *mContext;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -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<nsIPref> 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;
|
||||
}
|
||||
|
|
@ -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 <TextEdit.h>
|
||||
|
||||
#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_
|
|
@ -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 <beard@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 ***** */
|
||||
|
||||
#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<nsIRegion> region = new nsRegionMac();
|
||||
NS_ENSURE_TRUE(region, NS_ERROR_OUT_OF_MEMORY);
|
||||
nsCOMPtr<nsIScriptableRegion> 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)
|
||||
|
||||
|
|
@ -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 <LowMem.h>
|
||||
|
||||
|
||||
/** ------------------------------------------------------------
|
||||
* 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_
|
|
@ -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<nsDrawingSurfaceMac*>(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;
|
||||
}
|
|
@ -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 <Quickdraw.h>
|
||||
#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? <anonymous>
|
||||
// - no thanks, <pierre>
|
||||
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___
|
|
@ -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 <QDOffscreen.h>
|
||||
|
||||
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___
|
|
@ -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 <Quickdraw.h>
|
||||
|
||||
|
||||
// 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
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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
|
Двоичные данные
gfx/src/mac/nsMacGFX.rsrc
Двоичные данные
gfx/src/mac/nsMacGFX.rsrc
Двоичный файл не отображается.
|
@ -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 <Resources.h>
|
||||
#include <MacWindows.h>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -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__
|
||||
|
|
@ -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 <ftang@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 ***** */
|
||||
|
||||
#include "nsMacUnicodeFontInfo.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prmem.h"
|
||||
#include <Fonts.h>
|
||||
|
||||
//#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 <ATSTypes.h>
|
||||
#include <SFNTTypes.h>
|
||||
#include <SFNTLayoutTypes.h>
|
||||
|
||||
//#define TRACK_INIT_PERFORMANCE
|
||||
|
||||
#ifdef TRACK_INIT_PERFORMANCE
|
||||
#include <DriverServices.h>
|
||||
#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<nsIObserverService> 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<nsICharRepresentable> 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);
|
||||
}
|
|
@ -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 <ftang@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 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
|
|
@ -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<nsRegionRectSet*>(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<long*>(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;
|
||||
}
|
|
@ -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 <Quickdraw.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
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___
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <Quickdraw.h>
|
||||
|
||||
|
||||
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___
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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 <QDOffscreen.h>
|
||||
#include <UnicodeConverter.h>
|
||||
|
||||
#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___ */
|
|
@ -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 <Script.h>
|
||||
|
||||
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__
|
|
@ -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 <Script.h>
|
||||
#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__
|
|
@ -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__ */
|
|
@ -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 <Script.h>
|
||||
#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 <UnicodeConverter.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
#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<nsIUnicodeEncoder> 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<nsIUnicodeEncoder> 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);
|
||||
}
|
|
@ -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__ */
|
|
@ -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 <pp@ludusdesign.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 ***** */
|
||||
|
||||
#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 // 本明朝-M
|
||||
};
|
||||
static PRUnichar jfontname2[] = {
|
||||
0x4E38, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x2212, 0xFF2D, 0x0000 // 丸ゴシック-M
|
||||
};
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
|
@ -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 <Script.h>
|
||||
|
||||
#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<nsIPref> mPref;
|
||||
|
||||
static nsUnicodeMappingUtil* gSingleton;
|
||||
|
||||
};
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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 <UnicodeConverter.h>
|
||||
|
||||
#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<nsISaveAsCharset> mTrans;
|
||||
PRBool mRightToLeftText;
|
||||
|
||||
};
|
||||
#endif /* nsUnicodeRenderingToolkit_h__ */
|
Двоичный файл не отображается.
|
@ -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 <Carbon/Carbon.r>
|
||||
#include <HIToolbox/ControlDefinitions.r>
|
||||
|
||||
#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"
|
||||
};
|
||||
|
|
@ -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
|
||||
|
|
|
@ -94,7 +94,6 @@ LIBXUL_LIBRARY = 1
|
|||
LOCAL_INCLUDES = \
|
||||
-I$(srcdir) \
|
||||
-I$(srcdir)/.. \
|
||||
-I$(topsrcdir)/gfx/src/mac \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_XUL_APP
|
||||
|
|
|
@ -52,8 +52,6 @@
|
|||
|
||||
#include "nsAEWindowClass.h"
|
||||
|
||||
#include "nsGfxUtils.h"
|
||||
|
||||
using namespace nsWindowUtils;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
|
||||
#include "nsAEGenericClass.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
|
||||
class AEWindowIterator : public AEClassIterator
|
||||
|
@ -189,6 +190,87 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// 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__ */
|
||||
|
||||
|
||||
|
|
|
@ -45,8 +45,6 @@
|
|||
|
||||
#include "AEWordClass.h"
|
||||
|
||||
#include "nsGfxUtils.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
GetNumItems
|
||||
|
|
Загрузка…
Ссылка в новой задаче