Bye bye non-cairo GTK gfx. b=383889 r+sr=vladimir

This commit is contained in:
mats.palmgren@bredband.net 2007-06-15 19:13:52 -07:00
Родитель cc63f583ec
Коммит df0f128cb1
70 изменённых файлов: 16 добавлений и 30552 удалений

Просмотреть файл

@ -155,7 +155,6 @@ gfx/idl/Makefile
gfx/public/Makefile
gfx/src/Makefile
gfx/src/beos/Makefile
gfx/src/gtk/Makefile
gfx/src/ps/Makefile
gfx/src/psshared/Makefile
gfx/src/photon/Makefile

Просмотреть файл

@ -50,10 +50,9 @@ libgkgfx.so
libgtksuperwin.so
libgtkembedmoz.so
libgfxpsshar.so
components/libgfx_gtk.so
components/libgkgfxthebes.so
components/libgfxps.so
components/gfx.xpt
components/libwidget_gtk.so
components/libwidget_gtk2.so
components/widget.xpt

Просмотреть файл

@ -42,10 +42,9 @@ libgkgfx.so
libgtksuperwin.so
libgtkembedmoz.so
libgfxpsshar.so
components/libgfx_gtk.so
components/libgkgfxthebes.so
components/libgfxps.so
components/gfx.xpt
components/libwidget_gtk.so
components/libwidget_gtk2.so
components/widget.xpt

Просмотреть файл

@ -77,9 +77,6 @@ endif
ifdef MOZ_ENABLE_CAIRO_GFX
DIRS += thebes
else
ifdef MOZ_ENABLE_GTK2
DIRS += gtk
endif
ifdef MOZ_ENABLE_PHOTON
DIRS += photon
endif
@ -108,7 +105,7 @@ ifeq (,$(filter windows,$(MOZ_WIDGET_TOOLKIT)))
REQUIRES += uconv
endif
ifneq (,$(filter gtk2 beos windows os2,$(MOZ_WIDGET_TOOLKIT)))
ifneq (,$(filter beos windows os2,$(MOZ_WIDGET_TOOLKIT)))
CPPSRCS += imgScaler.cpp
endif

Просмотреть файл

@ -1,203 +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):
# Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
#
# 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
MODULE = gfx
LIBRARY_NAME = gfx_gtk
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsGfxGTKModule
GRE_MODULE = 1
LIBXUL_LIBRARY = 1
REQUIRES = xpcom \
string \
widget \
view \
util \
pref \
uconv \
unicharutil \
locale \
necko \
$(NULL)
# Sun's Complex Text Layout support
ifdef SUNCTL
REQUIRES += ctl
endif
# Code used by the GTK+ gfx module
X11SHARED_LCPPSRCS = \
nsAntiAliasedGlyph.cpp \
nsX11AlphaBlend.cpp \
nsXFontAAScaledBitmap.cpp \
nsXFontNormal.cpp \
$(NULL)
ifdef MOZ_ENABLE_FREETYPE2
X11SHARED_LCPPSRCS += \
nsFontFreeType.cpp \
nsFT2FontNode.cpp \
nsFT2FontCatalog.cpp \
nsNameValuePairDB.cpp \
$(NULL)
endif
CPPSRCS = \
nsDeviceContextGTK.cpp \
nsDrawingSurfaceGTK.cpp \
nsGfxFactoryGTK.cpp \
nsGraphicsStateGTK.cpp \
nsImageGTK.cpp \
nsGCCache.cpp \
nsRenderingContextGTK.cpp \
nsFontMetricsUtils.cpp \
$(NULL)
ifdef MOZ_ENABLE_COREXFONTS
CPPSRCS += \
$(X11SHARED_LCPPSRCS) \
nsFontMetricsGTK.cpp \
nsGdkUtils.cpp
endif
ifdef MOZ_ENABLE_XFT
CPPSRCS += \
nsFontMetricsXft.cpp
endif
ifdef MOZ_ENABLE_PANGO
CPPSRCS += \
nsFontMetricsPango.cpp \
mozilla-decoder.cpp
endif
ifdef MOZ_ENABLE_GTK2
CPPSRCS += \
nsRegionGTK2.cpp \
$(NULL)
endif
GARBAGE += $(X11SHARED_LCPPSRCS) $(XPU_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))
ifdef MOZ_ENABLE_FREETYPE2
# the SHARED_LIBRARY_LIBS line must be before the rules.mk include
SHARED_LIBRARY_LIBS += ../freetype/$(LIB_PREFIX)gfxft2_s.$(LIB_SUFFIX)
endif
EXTRA_DSO_LDOPTS = ../shared/$(LIB_PREFIX)gfxshared_s.$(LIB_SUFFIX)
include $(topsrcdir)/config/rules.mk
ifdef MOZ_ENABLE_XINERAMA
GFX_XINERAMA_LIBS += $(MOZ_XINERAMA_LIBS)
endif
ifdef MOZ_ENABLE_XFT
EXTRA_DSO_LDOPTS += $(FT2_LIBS)
libs:: fontEncoding.properties pangoFontEncoding.properties
$(INSTALL) $^ $(DIST)/bin/res/fonts
install:: fontEncoding.properties pangoFontEncoding.properties
$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/res/fonts
endif
ifdef MOZ_ENABLE_GTK2
EXTRA_DSO_LDOPTS += \
$(LIBS_DIR) \
-lgkgfx \
$(GFX_XINERAMA_LIBS) \
$(MOZ_JS_LIBS) \
$(MOZ_UNICHARUTIL_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
endif
ifdef MOZ_ENABLE_PANGO
EXTRA_DSO_LDOPTS += $(MOZ_PANGO_LIBS)
endif
EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS) $(MOZ_XFT_LIBS) $(MOZ_GTK2_LIBS)
CXXFLAGS += $(MOZ_GTK2_CFLAGS)
CFLAGS += $(MOZ_GTK2_CFLAGS)
ifeq ($(OS_ARCH), SunOS)
ifndef GNU_CC
# When using Sun's WorkShop compiler, including
# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
# causes most of these compiles to fail with:
# line 29: Error: Multiple declaration for std::tm.
# So, this gets around the problem.
DEFINES += -D_TIME_H=1
endif
endif
ifeq ($(OS_ARCH), OpenVMS)
DEFINES += -DGENERIC_MOTIF_REDEFINES
OS_CXXFLAGS += -Wc,warn=disa=NOSIMPINT
endif
ifdef MOZ_ENABLE_POSTSCRIPT
DEFINES += -DUSE_POSTSCRIPT
EXTRA_DSO_LDOPTS += -lgfxpsshar
endif
LOCAL_INCLUDES = \
-I../.. \
-I$(srcdir)/. \
-I$(srcdir)/.. \
-I$(srcdir)/../shared \
-I$(srcdir)/../x11shared \
$(MOZ_XFT_CFLAGS) \
$(NULL)
ifdef MOZ_ENABLE_FREETYPE2
INCLUDES += $(FT2_CFLAGS)
LOCAL_INCLUDES += -I$(srcdir)/../freetype
endif
export:: $(addprefix $(srcdir)/../x11shared/,$(X11SHARED_LCPPSRCS))
$(INSTALL) $^ .

Просмотреть файл

@ -1,206 +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>
# Jungshik Shin <jshin@mailaps.org>
#
# 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
# glyph shapes within these symbolic fonts).
#
# This file also lists truetype cmap tables for single byte ('narrow') special
# *symbolic fonts*. At the moment, only two values, 'mac_roman'
# and 'unicode' are recognized. These cmaps are used to translate custom font
# codes obtained through converters in intl/uconv library into glyph indices of # fonts with Freetype library. Do not change the value unless you're familiar
# with the internals of Freetype and Mozilla-Xft. If you're interested,
# see
# http://freetype.sourceforge.net/freetype2/docs/reference/ft2-base_interface.html#FT_Encoding
# and
# http://bugzilla.mozilla.org/show_bug.cgi?id=176290
#
# 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.
# For truetype cmaps, use .ftcmap in place of .ttf or .t1.
#
# - the 'value' is the case-sensitive charset string used when setting up the
# corresponding Unicode Converter in the intl/uconv library.
# - the 'value' for ftcmap is either mac_roman
# or unicode.
# If you have Symbol (Adobe) type 1 font, keep the following lines
# commented out (you do NOT need them). However, with truetype Symbol
# font, you do need them.
# Symbol font
#encoding.symbol.ttf = Adobe-Symbol-Encoding
#encoding.symbol.ftcmap = mac_roman
# 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
encoding.cmr10.ftcmap = unicode
encoding.cmmi10.ftcmap = unicode
encoding.cmsy10.ftcmap = unicode
encoding.cmex10.ftcmap = unicode
# 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
encoding.math1.ftcmap = mac_roman
encoding.math1-bold.ftcmap = mac_roman
encoding.math1mono.ftcmap = mac_roman
encoding.math1mono-bold.ftcmap = mac_roman
encoding.math2.ftcmap = mac_roman
encoding.math2-bold.ftcmap = mac_roman
encoding.math2mono.ftcmap = mac_roman
encoding.math2mono-bold.ftcmap = mac_roman
encoding.math3.ftcmap = mac_roman
encoding.math3-bold.ftcmap = mac_roman
encoding.math3mono.ftcmap = mac_roman
encoding.math3mono-bold.ftcmap = mac_roman
encoding.math4.ftcmap = mac_roman
encoding.math4-bold.ftcmap = mac_roman
encoding.math4mono.ftcmap = mac_roman
encoding.math4mono-bold.ftcmap = mac_roman
encoding.math5.ftcmap = mac_roman
encoding.math5-bold.ftcmap = mac_roman
encoding.math5bold.ftcmap = mac_roman
encoding.math5mono.ftcmap = mac_roman
encoding.math5mono-bold.ftcmap = mac_roman
encoding.math5monobold.ftcmap = mac_roman
# MathType Extra
encoding.mtextra.ttf = x-mtextra
encoding.mtextra.ftcmap = mac_roman
# Tamil fonts (TSCII encoding : see
# http://www.tscii.org and http://www.tamil.net). Not all 'TSCII fonts' are
# equal. I've confirmed the following fonts work, but other 'TSCII fonts' may
# not work. These fonts have pseudo-Unicode cmap with TSCII
# interpreted as Windows-1252.
#
encoding.tsc_paranarpdf.ttf = x-tamilttf-0.wide
encoding.tsc_paranbold.ttf = x-tamilttf-0.wide
encoding.tsc_paranarho.ttf = x-tamilttf-0.wide
encoding.tsc_kannadaasan.ttf = x-tamilttf-0.wide
encoding.tscu_comic.ttf = x-tamilttf-0.wide
encoding.tscu_times.ttf = x-tamilttf-0.wide
encoding.tscu_paranar.ttf = x-tamilttf-0.wide
encoding.tscu_paranarbold.ttf = x-tamilttf-0.wide
# These two fonts have conflicting MacRoman and Unicode Cmaps
# that get fontconfig confused.
#encoding.tsc_avarangal.ttf = x-tamilttf-0.wide
#encoding.tsc_avarangalfxd.ttf = x-tamilttf-0.wide
# These two fonts don't have Unicode cmap but have pseudo-Apple Roman cmap
# with TSCII assignment.
encoding.tsc_aandaal.ttf = x-tscii-0
encoding.tsc_aandaal.ftcmap = mac_roman
encoding.tsc_aparanarpdf.ttf = x-tscii-0
encoding.tsc_aparanarpdf.ftcmap = mac_roman
# The suffix '.wide' has to be added to encoding names to identify
# these fonts as 'wide' non-Unicode fonts.
# Korean Jamo TTFs
encoding.unbatang.ttf = x-koreanjamo-0.wide
# Thai TTFs
# glyph arrangement : TIS620-2 Windows encoding,
# code points used : Unicode Thai block + about 10 PUA code points in U+F700,
# coverage : US-ASCII, Thai (U+0E00-U+0E07F), punctuation marks
# U+2018, U+2019, U+201c, U+201d, U+2022, U+2013, U+2014 )
#
# These familes of fonts and other fonts with the same PUA assignment
# are included as a part of Thai language support in most Linux distributions.
# These lines have to be commented out by default because the encoder for
# x-thaittf-0 is only available with 'enable-ctl' which is not turned on
# by default.
#encoding.norasi.ttf = x-thaittf-0.wide
#encoding.garuda.ttf = x-thaittf-0.wide
#encoding.dbthaitext.ttf = x-thaittf-0.wide
# SunIndic fonts.
# glyph arrangement : Nominal glyphs for Indic scripts at their Unicode code
# points along with presentation forms in PUA
# coverage : US-ASCII, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya,
# Tamil, Telugu, Kanada, Malayalam
# Note : Currently only Devanagari is supported with this encoding.
# Two fonts in this family is available for free download at
# <http://www.sun.com/developers/gadc>.
encoding.saraswati5.ttf = x-sun-unicode-india-0.wide

Просмотреть файл

@ -1,13 +0,0 @@
[gecko]
#if SHARED_LIBRARY
dist/bin/components/@SHARED_LIBRARY@
#else
!staticcomp @LIBRARY@ @MODULE_NAME@
#endif
#if MOZ_ENABLE_XFT
dist/bin/res/fonts/fontEncoding.properties
#endif
#if MOZ_ENABLE_PANGO
dist/bin/res/fonts/pangoFontEncoding.properties
#endif

Просмотреть файл

@ -1,381 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** 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 Christopher Blizzard
* <blizzard@mozilla.org>. Portions created by the Initial Developer
* are Copyright (C) 2004 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#define PANGO_ENABLE_BACKEND
#define PANGO_ENABLE_ENGINE
#include "mozilla-decoder.h"
#include <pango/pangofc-fontmap.h>
#include <pango/pangofc-font.h>
#include <gdk/gdkpango.h>
#include "nsString.h"
#include "nsIPersistentProperties2.h"
#include "nsNetUtil.h"
#include "nsReadableUtils.h"
#include "nsICharsetConverterManager.h"
#include "nsICharRepresentable.h"
#include "nsCompressedCharMap.h"
#undef DEBUG_CUSTOM_ENCODER
G_DEFINE_TYPE (MozillaDecoder, mozilla_decoder, PANGO_TYPE_FC_DECODER)
MozillaDecoder *mozilla_decoder_new (void);
static FcCharSet *mozilla_decoder_get_charset (PangoFcDecoder *decoder,
PangoFcFont *fcfont);
static PangoGlyph mozilla_decoder_get_glyph (PangoFcDecoder *decoder,
PangoFcFont *fcfont,
guint32 wc);
static PangoFcDecoder *mozilla_find_decoder (FcPattern *pattern,
gpointer user_data);
typedef struct _MozillaDecoderPrivate MozillaDecoderPrivate;
#define MOZILLA_DECODER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MOZILLA_TYPE_DECODER, MozillaDecoderPrivate))
struct _MozillaDecoderPrivate {
char *family;
char *encoder;
char *cmap;
gboolean is_wide;
FcCharSet *charset;
nsCOMPtr<nsIUnicodeEncoder> uEncoder;
};
static nsICharsetConverterManager *gCharsetManager = NULL;
static NS_DEFINE_CID(kCharsetConverterManagerCID,
NS_ICHARSETCONVERTERMANAGER_CID);
// Hash tables that hold the custom encodings and custom cmaps used in
// various fonts.
GHashTable *encoder_hash = NULL;
GHashTable *cmap_hash = NULL;
GHashTable *wide_hash = NULL;
void
mozilla_decoder_init (MozillaDecoder *decoder)
{
}
void
mozilla_decoder_class_init (MozillaDecoderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
PangoFcDecoderClass *parent_class = PANGO_FC_DECODER_CLASS (klass);
/* object_class->finalize = test_finalize; */
parent_class->get_charset = mozilla_decoder_get_charset;
parent_class->get_glyph = mozilla_decoder_get_glyph;
g_type_class_add_private (object_class, sizeof (MozillaDecoderPrivate));
}
MozillaDecoder *
mozilla_decoder_new(void)
{
return (MozillaDecoder *)g_object_new(MOZILLA_TYPE_DECODER, NULL);
}
#ifdef DEBUG_CUSTOM_ENCODER
void
dump_hash(char *key, char *val, void *arg)
{
printf("%s -> %s\n", key, val);
}
#endif
/**
* mozilla_decoders_init:
*
* #mozilla_decoders_init:
*
* This initializes all of the application-specific custom decoders
* that Mozilla uses. This should only be called once during the
* lifetime of the application.
*
* Return value: zero on success, not zero on failure.
*
**/
int
mozilla_decoders_init(void)
{
static PRBool initialized = PR_FALSE;
if (initialized)
return 0;
PangoContext* context = gdk_pango_context_get ();
PangoFontMap* fontmap = pango_context_get_font_map (context);
g_object_unref (context);
if (!PANGO_IS_FC_FONT_MAP (fontmap))
return -1;
encoder_hash = g_hash_table_new(g_str_hash, g_str_equal);
cmap_hash = g_hash_table_new(g_str_hash, g_str_equal);
wide_hash = g_hash_table_new(g_str_hash, g_str_equal);
PRBool dumb = PR_FALSE;
nsCOMPtr<nsIPersistentProperties> props;
nsCOMPtr<nsISimpleEnumerator> encodeEnum;
NS_LoadPersistentPropertiesFromURISpec(getter_AddRefs(props),
NS_LITERAL_CSTRING("resource://gre/res/fonts/pangoFontEncoding.properties"));
if (!props)
goto loser;
// Enumerate the properties in this file and figure out all of the
// fonts for which we have custom encodings.
props->Enumerate(getter_AddRefs(encodeEnum));
if (!encodeEnum)
goto loser;
while (encodeEnum->HasMoreElements(&dumb), dumb) {
nsCOMPtr<nsIPropertyElement> prop;
encodeEnum->GetNext(getter_AddRefs(prop));
if (!prop)
goto loser;
nsCAutoString name;
prop->GetKey(name);
nsAutoString value;
prop->GetValue(value);
if (!StringBeginsWith(name, NS_LITERAL_CSTRING("encoding."))) {
printf("string doesn't begin with encoding?\n");
continue;
}
name = Substring(name, 9);
if (StringEndsWith(name, NS_LITERAL_CSTRING(".ttf"))) {
name = Substring(name, 0, name.Length() - 4);
// Strip off a .wide if it's there.
if (StringEndsWith(value, NS_LITERAL_STRING(".wide"))) {
g_hash_table_insert(wide_hash, g_strdup(name.get()),
g_strdup("wide"));
value = Substring(value, 0, name.Length() - 5);
}
g_hash_table_insert(encoder_hash,
g_strdup(name.get()),
g_strdup(NS_ConvertUTF16toUTF8(value).get()));
}
else if (StringEndsWith(name, NS_LITERAL_CSTRING(".ftcmap"))) {
name = Substring(name, 0, name.Length() - 7);
g_hash_table_insert(cmap_hash,
g_strdup(name.get()),
g_strdup(NS_ConvertUTF16toUTF8(value).get()));
}
else {
printf("unknown suffix used for mapping\n");
}
}
pango_fc_font_map_add_decoder_find_func(PANGO_FC_FONT_MAP(fontmap),
mozilla_find_decoder,
NULL,
NULL);
initialized = PR_TRUE;
#ifdef DEBUG_CUSTOM_ENCODER
printf("*** encoders\n");
g_hash_table_foreach(encoder_hash, (GHFunc)dump_hash, NULL);
printf("*** cmaps\n");
g_hash_table_foreach(cmap_hash, (GHFunc)dump_hash, NULL);
#endif
return 0;
loser:
return -1;
}
FcCharSet *
mozilla_decoder_get_charset (PangoFcDecoder *decoder,
PangoFcFont *fcfont)
{
MozillaDecoderPrivate *priv = MOZILLA_DECODER_GET_PRIVATE(decoder);
if (priv->charset)
return priv->charset;
// First time this has been accessed. Populate the charset.
priv->charset = FcCharSetCreate();
if (!gCharsetManager) {
CallGetService(kCharsetConverterManagerCID, &gCharsetManager);
}
nsCOMPtr<nsIUnicodeEncoder> encoder;
nsCOMPtr<nsICharRepresentable> represent;
if (!gCharsetManager)
goto end;
gCharsetManager->GetUnicodeEncoderRaw(priv->encoder, getter_AddRefs(encoder));
if (!encoder)
goto end;
encoder->SetOutputErrorBehavior(encoder->kOnError_Replace, nsnull, '?');
priv->uEncoder = encoder;
represent = do_QueryInterface(encoder);
if (!represent)
goto end;
PRUint32 map[UCS2_MAP_LEN];
memset(map, 0, sizeof(map));
represent->FillInfo(map);
for (int i = 0; i < NUM_UNICODE_CHARS; i++) {
if (IS_REPRESENTABLE(map, i))
FcCharSetAddChar(priv->charset, i);
}
end:
return priv->charset;
}
PangoGlyph
mozilla_decoder_get_glyph (PangoFcDecoder *decoder,
PangoFcFont *fcfont,
guint32 wc)
{
MozillaDecoderPrivate *priv = MOZILLA_DECODER_GET_PRIVATE(decoder);
PangoGlyph retval = 0;
PRUnichar inchar = wc;
PRInt32 inlen = 1;
char outchar[2] = {0,0};
PRInt32 outlen = 2;
priv->uEncoder->Convert(&inchar, &inlen, outchar, &outlen);
if (outlen != 1) {
printf("Warning: mozilla_decoder_get_glyph doesn't support more than one character conversions.\n");
return 0;
}
FT_Face face = pango_fc_font_lock_face(fcfont);
#ifdef DEBUG_CUSTOM_ENCODER
char *filename;
FcPatternGetString(fcfont->font_pattern, FC_FILE, 0, (FcChar8 **)&filename);
printf("filename is %s\n", filename);
#endif
// Make sure to set the right charmap before trying to get the
// glyph
if (priv->cmap) {
if (!strcmp(priv->cmap, "mac_roman")) {
FT_Select_Charmap(face, ft_encoding_apple_roman);
}
else if (!strcmp(priv->cmap, "unicode")) {
FT_Select_Charmap(face, ft_encoding_unicode);
}
else {
printf("Warning: Invalid charmap entry for family %s\n",
priv->family);
}
}
// Standard 8 bit to glyph translation
if (!priv->is_wide) {
FcChar32 blah = PRUint8(outchar[0]);
retval = FT_Get_Char_Index(face, blah);
#ifdef DEBUG_CUSTOM_ENCODER
printf("wc 0x%x outchar[0] 0x%x index 0x%x retval 0x%x face %p\n",
wc, outchar[0], blah, retval, (void *)face);
#endif
}
else {
printf("Warning: We don't support .wide fonts!\n");
retval = 0;
}
pango_fc_font_unlock_face(fcfont);
return retval;
}
PangoFcDecoder *
mozilla_find_decoder (FcPattern *pattern, gpointer user_data)
{
// Compare the family name of the font that's been opened to see
// if we have a custom decoder.
const char *orig = NULL;
FcPatternGetString(pattern, FC_FAMILY, 0, (FcChar8 **)&orig);
nsCAutoString family;
family.Assign(orig);
family.StripWhitespace();
ToLowerCase(family);
char *encoder = (char *)g_hash_table_lookup(encoder_hash, family.get());
if (!encoder)
return NULL;
MozillaDecoder *decoder = mozilla_decoder_new();
MozillaDecoderPrivate *priv = MOZILLA_DECODER_GET_PRIVATE(decoder);
priv->family = g_strdup(family.get());
priv->encoder = g_strdup(encoder);
char *cmap = (char *)g_hash_table_lookup(cmap_hash, family.get());
if (cmap)
priv->cmap = g_strdup(cmap);
char *wide = (char *)g_hash_table_lookup(wide_hash, family.get());
if (wide)
priv->is_wide = TRUE;
return PANGO_FC_DECODER(decoder);
}

Просмотреть файл

@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** 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 Christopher Blizzard
* <blizzard@mozilla.org>. Portions created by the Initial Developer
* are Copyright (C) 2004 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#ifndef _MOZILLA_DECODER_H
#define _MOZILLA_DECODER_H
#include <pango/pangofc-decoder.h>
G_BEGIN_DECLS
#define MOZILLA_TYPE_DECODER (mozilla_decoder_get_type())
#define MOZILLA_DECODER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOZILLA_TYPE_DECODER, MozillaDecoder))
#define MOZILLA_IS_DECODER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOZILLA_TYPE_DECODER))
typedef struct _MozillaDecoder MozillaDecoder;
typedef struct _MozillaDecoderClass MozillaDecoderClass;
#define MOZILLA_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOZILLA_TYPE_DECODER, MozillaDecoderClass))
#define MOZILLA_IS_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOZILLA_TYPE_DECODER))
#define MOZILLA_DECODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOZILLA_TYPE_DECODER, MozillaDecoderClass))
struct _MozillaDecoder
{
PangoFcDecoder parent_instance;
};
struct _MozillaDecoderClass
{
PangoFcDecoderClass parent_class;
};
GType mozilla_decoder_get_type (void);
int mozilla_decoders_init (void);
G_END_DECLS
#endif /*_MOZILLA_DECODER_H */

Просмотреть файл

@ -1,993 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// vim:cindent:ts=2:et:sw=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):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
* 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 <math.h>
#include "nspr.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsCRT.h"
#include "nsDeviceContextGTK.h"
#include "nsGfxCIID.h"
#ifdef USE_POSTSCRIPT
#include "nsGfxPSCID.h"
#include "nsIDeviceContextPS.h"
#endif /* USE_POSTSCRIPT */
#include "nsFontMetricsUtils.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#ifdef MOZ_WIDGET_GTK2
#include <pango/pango.h>
#include <pango/pangox.h>
#include <pango/pango-fontmap.h>
#endif
#ifdef MOZ_ENABLE_XFT
#include "nsFontMetricsUtils.h"
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
static PRInt32 GetXftDPI(void);
#endif
#include <X11/Xatom.h>
#include "nsIDeviceContextSpec.h"
static PRInt32 GetOSDPI(void);
#define GDK_DEFAULT_FONT1 "-*-helvetica-medium-r-*--*-120-*-*-*-*-iso8859-1"
#define GDK_DEFAULT_FONT2 "-*-fixed-medium-r-*-*-*-120-*-*-*-*-*-*"
/**
* A singleton instance of nsSystemFontsGTK is created by the first
* device context and destroyed by the module destructor.
*/
class nsSystemFontsGTK {
public:
nsSystemFontsGTK(float aPixelsToTwips);
const nsFont& GetDefaultFont() { return mDefaultFont; }
const nsFont& GetMenuFont() { return mMenuFont; }
const nsFont& GetFieldFont() { return mFieldFont; }
const nsFont& GetButtonFont() { return mButtonFont; }
private:
nsresult GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
float aPixelsToTwips) const;
/*
* The following system font constants exist:
*
* css2: http://www.w3.org/TR/REC-CSS2/fonts.html#x27
* eSystemFont_Caption, eSystemFont_Icon, eSystemFont_Menu,
* eSystemFont_MessageBox, eSystemFont_SmallCaption,
* eSystemFont_StatusBar,
* // css3
* eSystemFont_Window, eSystemFont_Document,
* eSystemFont_Workspace, eSystemFont_Desktop,
* eSystemFont_Info, eSystemFont_Dialog,
* eSystemFont_Button, eSystemFont_PullDownMenu,
* eSystemFont_List, eSystemFont_Field,
* // moz
* eSystemFont_Tooltips, eSystemFont_Widget
*/
nsFont mDefaultFont;
nsFont mButtonFont;
nsFont mFieldFont;
nsFont mMenuFont;
};
nscoord nsDeviceContextGTK::mDpi = 96;
static nsSystemFontsGTK *gSystemFonts = nsnull;
nsDeviceContextGTK::nsDeviceContextGTK()
: DeviceContextImpl()
{
mTwipsToPixels = 1.0;
mPixelsToTwips = 1.0;
mDepth = 0 ;
mNumCells = 0;
mDeviceWindow = nsnull;
}
nsDeviceContextGTK::~nsDeviceContextGTK()
{
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
prefs->UnregisterCallback("layout.css.dpi",
prefChanged, (void *)this);
}
}
/* static */ void nsDeviceContextGTK::Shutdown()
{
if (gSystemFonts) {
delete gSystemFonts;
gSystemFonts = nsnull;
}
}
NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
{
GtkRequisition req;
GtkWidget *sb;
// get the screen object and its width/height
// XXXRight now this will only get the primary monitor.
if (!mScreenManager)
mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
if (!mScreenManager) {
return NS_ERROR_FAILURE;
}
#ifdef MOZ_WIDGET_GTK2
if (aNativeWidget) {
// can only be a gdk window
if (GDK_IS_WINDOW(aNativeWidget))
mDeviceWindow = GDK_WINDOW(aNativeWidget);
else
NS_WARNING("unsupported native widget type!");
}
#endif
nsCOMPtr<nsIScreen> screen;
mScreenManager->GetPrimaryScreen ( getter_AddRefs(screen) );
if ( screen ) {
PRInt32 depth;
screen->GetPixelDepth ( &depth );
mDepth = NS_STATIC_CAST ( PRUint32, depth );
}
static int initialized = 0;
PRInt32 prefVal = -1;
if (!initialized) {
initialized = 1;
// Set prefVal the value of the preference
// "layout.css.dpi"
// or -1 if we can't get it.
// If it's negative, we pretend it's not set.
// If it's 0, it means force use of the operating system's logical
// resolution.
// If it's positive, we use it as the logical resolution
nsresult res;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &res));
if (NS_SUCCEEDED(res) && prefs) {
res = prefs->GetIntPref("layout.css.dpi", &prefVal);
if (NS_FAILED(res)) {
prefVal = -1;
}
prefs->RegisterCallback("layout.css.dpi", prefChanged,
(void *)this);
}
SetDPI(prefVal);
} else {
SetDPI(mDpi); // to setup p2t and t2p
}
#ifdef DEBUG
static PRBool once = PR_TRUE;
if (once) {
printf("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n", mDpi, mTwipsToPixels, mPixelsToTwips,mDepth);
once = PR_FALSE;
}
#endif
DeviceContextImpl::CommonInit();
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContext(nsIRenderingContext *&aContext)
{
#ifdef NS_PRINT_PREVIEW
// Defer to Alt when there is one
if (mAltDC && ((mUseAltDC & kUseAltDCFor_CREATERC_PAINT) || (mUseAltDC & kUseAltDCFor_CREATERC_REFLOW))) {
return mAltDC->CreateRenderingContext(aContext);
}
#endif
nsresult rv;
GtkWidget *w = (GtkWidget*)mWidget;
// to call init for this, we need to have a valid nsDrawingSurfaceGTK created
nsIRenderingContext* pContext = new nsRenderingContextGTK();
if (nsnull != pContext)
{
NS_ADDREF(pContext);
// create the nsDrawingSurfaceGTK
nsDrawingSurfaceGTK* surf = new nsDrawingSurfaceGTK();
if (surf && w)
{
GdkDrawable *gwin = nsnull;
GdkDrawable *win = nsnull;
// FIXME
if (GTK_IS_LAYOUT(w))
gwin = (GdkDrawable*)GTK_LAYOUT(w)->bin_window;
else
gwin = (GdkDrawable*)(w)->window;
// window might not be realized... ugh
if (gwin)
gdk_window_ref(gwin);
else {
win = gdk_pixmap_new(nsnull,
w->allocation.width,
w->allocation.height,
gdk_rgb_get_visual()->depth);
#ifdef MOZ_WIDGET_GTK2
gdk_drawable_set_colormap(win, gdk_rgb_get_colormap());
#endif
}
GdkGC *gc = gdk_gc_new(win);
// init the nsDrawingSurfaceGTK
rv = surf->Init(win,gc);
if (NS_OK == rv)
// Init the nsRenderingContextGTK
rv = pContext->Init(this, surf);
}
else
rv = NS_ERROR_OUT_OF_MEMORY;
}
else
rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_OK != rv)
{
NS_IF_RELEASE(pContext);
}
aContext = pContext;
return rv;
}
NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContextInstance(nsIRenderingContext *&aContext)
{
nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextGTK();
if (!renderingContext)
return NS_ERROR_OUT_OF_MEMORY;
aContext = renderingContext;
NS_ADDREF(aContext);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
//XXX it is very critical that this not lie!! MMP
// read the comments in the mac code for this
aSupportsWidgets = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
{
nsresult status = NS_OK;
if (!gSystemFonts) {
gSystemFonts = new nsSystemFontsGTK(mPixelsToTwips);
}
switch (aID) {
case eSystemFont_Menu: // css2
case eSystemFont_PullDownMenu: // css3
*aFont = gSystemFonts->GetMenuFont();
break;
case eSystemFont_Field: // css3
case eSystemFont_List: // css3
*aFont = gSystemFonts->GetFieldFont();
break;
case eSystemFont_Button: // css3
*aFont = gSystemFonts->GetButtonFont();
break;
case eSystemFont_Caption: // css2
case eSystemFont_Icon: // css2
case eSystemFont_MessageBox: // css2
case eSystemFont_SmallCaption: // css2
case eSystemFont_StatusBar: // css2
case eSystemFont_Window: // css3
case eSystemFont_Document: // css3
case eSystemFont_Workspace: // css3
case eSystemFont_Desktop: // css3
case eSystemFont_Info: // css3
case eSystemFont_Dialog: // css3
case eSystemFont_Tooltips: // moz
case eSystemFont_Widget: // moz
*aFont = gSystemFonts->GetDefaultFont();
break;
}
return status;
}
NS_IMETHODIMP nsDeviceContextGTK::CheckFontExistence(const nsString& aFontName)
{
return NS_FontMetricsFamilyExists(this, aFontName);
}
NS_IMETHODIMP nsDeviceContextGTK::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
{
#ifdef NS_PRINT_PREVIEW
// Defer to Alt when there is one
if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM)) {
return mAltDC->GetDeviceSurfaceDimensions(aWidth, aHeight);
}
#endif
PRInt32 width = 0, height = 0;
nsCOMPtr<nsIScreen> screen;
mScreenManager->GetPrimaryScreen(getter_AddRefs(screen));
if (screen) {
PRInt32 x, y;
screen->GetRect(&x, &y, &width, &height);
}
aWidth = NSToIntRound(float(width) * mDevUnitsToAppUnits);
aHeight = NSToIntRound(float(height) * mDevUnitsToAppUnits);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::GetRect(nsRect &aRect)
{
// if we have an initialized widget for this device context, use it
// to try and get real screen coordinates.
if (mDeviceWindow) {
gint x, y, width, height, depth;
x = y = width = height = 0;
gdk_window_get_geometry(mDeviceWindow, &x, &y, &width, &height,
&depth);
gdk_window_get_origin(mDeviceWindow, &x, &y);
nsCOMPtr<nsIScreen> screen;
mScreenManager->ScreenForRect(x, y, width, height, getter_AddRefs(screen));
screen->GetRect(&aRect.x, &aRect.y, &aRect.width, &aRect.height);
aRect.x = NSToIntRound(mDevUnitsToAppUnits * aRect.x);
aRect.y = NSToIntRound(mDevUnitsToAppUnits * aRect.y);
aRect.width = NSToIntRound(mDevUnitsToAppUnits * aRect.width);
aRect.height = NSToIntRound(mDevUnitsToAppUnits * aRect.height);
}
else {
PRInt32 width, height;
GetDeviceSurfaceDimensions(width, height);
aRect.x = 0;
aRect.y = 0;
aRect.width = width;
aRect.height = height;
}
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::GetClientRect(nsRect &aRect)
{
// if we have an initialized widget for this device context, use it
// to try and get real screen coordinates.
if (mDeviceWindow) {
gint x, y, width, height, depth;
x = y = width = height = 0;
gdk_window_get_geometry(mDeviceWindow, &x, &y, &width, &height,
&depth);
gdk_window_get_origin(mDeviceWindow, &x, &y);
nsCOMPtr<nsIScreen> screen;
mScreenManager->ScreenForRect(x, y, width, height, getter_AddRefs(screen));
screen->GetAvailRect(&aRect.x, &aRect.y, &aRect.width, &aRect.height);
aRect.x = NSToIntRound(mDevUnitsToAppUnits * aRect.x);
aRect.y = NSToIntRound(mDevUnitsToAppUnits * aRect.y);
aRect.width = NSToIntRound(mDevUnitsToAppUnits * aRect.width);
aRect.height = NSToIntRound(mDevUnitsToAppUnits * aRect.height);
}
else {
PRInt32 width, height;
GetDeviceSurfaceDimensions(width, height);
aRect.x = 0;
aRect.y = 0;
aRect.width = width;
aRect.height = height;
}
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
nsIDeviceContext *&aContext)
{
nsresult rv;
#if 0
PrintMethod method;
nsDeviceContextSpecGTK *spec = NS_STATIC_CAST(nsDeviceContextSpecGTK *, aDevice);
rv = spec->GetPrintMethod(method);
if (NS_FAILED(rv))
return rv;
#endif
#ifdef USE_POSTSCRIPT
// if (method == pmPostScript) // PostScript
{
// default/PS
static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID);
// Create a Postscript device context
nsCOMPtr<nsIDeviceContextPS> dcps(do_CreateInstance(kCDeviceContextPS, &rv));
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create PS Device context.");
if (NS_FAILED(rv))
return NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE;
rv = dcps->SetSpec(aDevice);
if (NS_FAILED(rv))
return rv;
rv = dcps->InitDeviceContextPS((nsIDeviceContext*)aContext,
(nsIDeviceContext*)this);
if (NS_FAILED(rv))
return rv;
rv = dcps->QueryInterface(NS_GET_IID(nsIDeviceContext),
(void **)&aContext);
return rv;
}
#endif /* USE_POSTSCRIPT */
NS_WARNING("no print module created.");
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP nsDeviceContextGTK::BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::EndDocument(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::AbortDocument(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::BeginPage(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::EndPage(void)
{
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::GetDepth(PRUint32& aDepth)
{
aDepth = mDepth;
return NS_OK;
}
nsresult
nsDeviceContextGTK::SetDPI(PRInt32 aPrefDPI)
{
PRInt32 OSVal = GetOSDPI();
if (aPrefDPI > 0) {
// If there's a valid pref value for the logical resolution,
// use it.
mDpi = aPrefDPI;
} else if ((aPrefDPI == 0) || (OSVal > 96)) {
// Either if the pref is 0 (force use of OS value) or the OS
// value is bigger than 96, use the OS value.
mDpi = OSVal;
} else {
// if we couldn't get the pref or it's negative, and the OS
// value is under 96ppi, then use 96.
mDpi = 96;
}
int pt2t = 72;
// make p2t a nice round number - this prevents rounding problems
mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(mDpi)));
mTwipsToPixels = 1.0f / mPixelsToTwips;
// XXX need to reflow all documents
return NS_OK;
}
static void DoClearCachedSystemFonts()
{
//clear our cache of stored system fonts
if (gSystemFonts) {
delete gSystemFonts;
gSystemFonts = nsnull;
}
}
NS_IMETHODIMP
nsDeviceContextGTK::ClearCachedSystemFonts()
{
DoClearCachedSystemFonts();
return NS_OK;
}
int nsDeviceContextGTK::prefChanged(const char *aPref, void *aClosure)
{
nsDeviceContextGTK *context = (nsDeviceContextGTK*)aClosure;
nsresult rv;
if (nsCRT::strcmp(aPref, "layout.css.dpi")==0) {
PRInt32 dpi;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
rv = prefs->GetIntPref(aPref, &dpi);
if (NS_SUCCEEDED(rv))
context->SetDPI(dpi);
// If this pref changes, we have to clear our cache of stored system
// fonts.
DoClearCachedSystemFonts();
}
return 0;
}
#define DEFAULT_TWIP_FONT_SIZE 240
nsSystemFontsGTK::nsSystemFontsGTK(float aPixelsToTwips)
: mDefaultFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mButtonFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mFieldFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE),
mMenuFont("sans-serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE,
DEFAULT_TWIP_FONT_SIZE)
{
/*
* Much of the widget creation code here is similar to the code in
* nsLookAndFeel::InitColors().
*/
// mDefaultFont
GtkWidget *label = gtk_label_new("M");
GtkWidget *parent = gtk_fixed_new();
GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
gtk_container_add(GTK_CONTAINER(parent), label);
gtk_container_add(GTK_CONTAINER(window), parent);
gtk_widget_ensure_style(label);
GetSystemFontInfo(label, &mDefaultFont, aPixelsToTwips);
gtk_widget_destroy(window); // no unref, windows are different
// mFieldFont
GtkWidget *entry = gtk_entry_new();
parent = gtk_fixed_new();
window = gtk_window_new(GTK_WINDOW_POPUP);
gtk_container_add(GTK_CONTAINER(parent), entry);
gtk_container_add(GTK_CONTAINER(window), parent);
gtk_widget_ensure_style(entry);
GetSystemFontInfo(entry, &mFieldFont, aPixelsToTwips);
gtk_widget_destroy(window); // no unref, windows are different
// mMenuFont
GtkWidget *accel_label = gtk_accel_label_new("M");
GtkWidget *menuitem = gtk_menu_item_new();
GtkWidget *menu = gtk_menu_new();
gtk_object_ref(GTK_OBJECT(menu));
gtk_object_sink(GTK_OBJECT(menu));
gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
gtk_menu_append(GTK_MENU(menu), menuitem);
gtk_widget_ensure_style(accel_label);
GetSystemFontInfo(accel_label, &mMenuFont, aPixelsToTwips);
gtk_widget_unref(menu);
// mButtonFont
parent = gtk_fixed_new();
GtkWidget *button = gtk_button_new();
label = gtk_label_new("M");
window = gtk_window_new(GTK_WINDOW_POPUP);
gtk_container_add(GTK_CONTAINER(button), label);
gtk_container_add(GTK_CONTAINER(parent), button);
gtk_container_add(GTK_CONTAINER(window), parent);
gtk_widget_ensure_style(label);
GetSystemFontInfo(label, &mButtonFont, aPixelsToTwips);
gtk_widget_destroy(window); // no unref, windows are different
}
#if 0 // debugging code to list the font properties
static void
ListFontProps(XFontStruct *aFont, Display *aDisplay)
{
printf("\n\n");
for (int i = 0, n = aFont->n_properties; i < n; ++i) {
XFontProp *prop = aFont->properties + i;
char *atomName = ::XGetAtomName(aDisplay, prop->name);
// 500 is just a guess
char *cardName = (prop->card32 > 0 && prop->card32 < 500)
? ::XGetAtomName(aDisplay, prop->card32)
: 0;
printf("%s : %ld (%s)\n", atomName, prop->card32, cardName?cardName:"");
::XFree(atomName);
if (cardName)
::XFree(cardName);
}
printf("\n\n");
}
#endif
#if defined(MOZ_ENABLE_COREXFONTS)
#define LOCATE_MINUS(pos, str) { \
pos = str.FindChar('-'); \
if (pos < 0) \
return ; \
}
#define NEXT_MINUS(pos, str) { \
pos = str.FindChar('-', pos+1); \
if (pos < 0) \
return ; \
}
static void
AppendFontFFREName(nsString& aString, const char* aXLFDName)
{
// convert fontname from XFLD to FFRE and append, ie. from
// -adobe-courier-medium-o-normal--14-140-75-75-m-90-iso8859-15
// to
// adobe-courier-iso8859-15
nsCAutoString nameStr(aXLFDName);
PRInt32 pos1, pos2;
// remove first '-' and everything before it.
LOCATE_MINUS(pos1, nameStr);
nameStr.Cut(0, pos1+1);
// skip foundry and family name
LOCATE_MINUS(pos1, nameStr);
NEXT_MINUS(pos1, nameStr);
pos2 = pos1;
// find '-' just before charset registry
for (PRInt32 i=0; i < 10; i++) {
NEXT_MINUS(pos2, nameStr);
}
// remove everything in between
nameStr.Cut(pos1, pos2-pos1);
aString.AppendWithConversion(nameStr.get());
}
#endif /* MOZ_ENABLE_COREXFONTS */
#ifdef MOZ_WIDGET_GTK2
#ifdef MOZ_ENABLE_COREXFONTS
static void xlfd_from_pango_font_description(GtkWidget *aWidget,
const PangoFontDescription *aFontDesc,
nsString& aFontName);
#endif /* MOZ_ENABLE_COREXFONTS */
nsresult
nsSystemFontsGTK::GetSystemFontInfo(GtkWidget *aWidget, nsFont* aFont,
float aPixelsToTwips) const
{
GtkSettings *settings = gtk_widget_get_settings(aWidget);
aFont->style = NS_FONT_STYLE_NORMAL;
aFont->decorations = NS_FONT_DECORATION_NONE;
gchar *fontname;
g_object_get(settings, "gtk-font-name", &fontname, NULL);
PangoFontDescription *desc;
desc = pango_font_description_from_string(fontname);
aFont->systemFont = PR_TRUE;
g_free(fontname);
aFont->name.Truncate();
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
aFont->name.Assign(PRUnichar('"'));
aFont->name.AppendWithConversion(pango_font_description_get_family(desc));
aFont->name.Append(PRUnichar('"'));
}
#endif /* MOZ_ENABLE_XFT */
#ifdef MOZ_ENABLE_COREXFONTS
// if name already set by Xft, do nothing
if (!aFont->name.Length()) {
xlfd_from_pango_font_description(aWidget, desc, aFont->name);
}
#endif /* MOZ_ENABLE_COREXFONTS */
aFont->weight = pango_font_description_get_weight(desc);
float size = float(pango_font_description_get_size(desc) / PANGO_SCALE);
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
PRInt32 dpi = GetXftDPI();
if (dpi != 0) {
// pixels/inch * twips/pixel * inches/twip == 1, except it isn't, since
// our idea of dpi may be different from Xft's.
size *= float(dpi) * aPixelsToTwips * (1.0f/1440.0f);
}
}
#endif /* MOZ_ENABLE_XFT */
aFont->size = NSFloatPointsToTwips(size);
pango_font_description_free(desc);
return NS_OK;
}
#endif /* MOZ_WIDGET_GTK2 */
#ifdef MOZ_WIDGET_GTK2
/* static */
PRInt32
GetOSDPI(void)
{
GtkSettings *settings = gtk_settings_get_default();
// first try to get the gtk2 dpi
gint dpi = 0;
// See if there's a gtk-xft-dpi object on the settings object - note
// that we don't have to free the spec since it isn't addrefed
// before being returned. It's just part of an internal object.
// The gtk-xft-dpi setting is included in rh8 and might be included
// in later versions of gtk, so we conditionally check for it.
GParamSpec *spec;
spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(settings)),
"gtk-xft-dpi");
if (spec) {
g_object_get(G_OBJECT(settings),
"gtk-xft-dpi", &dpi,
NULL);
}
if (dpi > 0)
return NSToCoordRound(dpi / 1024.0);
#ifdef MOZ_ENABLE_XFT
// try to get it from xft
PRInt32 xftdpi = GetXftDPI();
if (xftdpi)
return xftdpi;
#endif /* MOZ_ENABLE_XFT */
// fall back to the physical resolution
float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f;
return NSToCoordRound(float(::gdk_screen_width()) / screenWidthIn);
}
#endif /* MOZ_WIDGET_GTK2 */
#ifdef MOZ_ENABLE_XFT
/* static */
PRInt32
GetXftDPI(void)
{
char *val = XGetDefault(GDK_DISPLAY(), "Xft", "dpi");
if (val) {
char *e;
double d = strtod(val, &e);
if (e != val)
return NSToCoordRound(d);
}
return 0;
}
#endif /* MOZ_ENABLE_XFT */
#if defined(MOZ_WIDGET_GTK2) && defined(MOZ_ENABLE_COREXFONTS)
// xlfd_from_pango_font_description copied from vte, which was
// written by nalin@redhat.com, and added some codes.
static void
xlfd_from_pango_font_description(GtkWidget *aWidget,
const PangoFontDescription *aFontDesc,
nsString& aFontName)
{
char *spec;
PangoContext *context;
PangoFont *font;
PangoXSubfont *subfont_ids;
PangoFontMap *fontmap;
int *subfont_charsets, i, count = 0;
char *tmp, *subfont;
char *encodings[] = {
"ascii-0",
"big5-0",
"dos-437",
"dos-737",
"gb18030.2000-0",
"gb18030.2000-1",
"gb2312.1980-0",
"iso8859-1",
"iso8859-2",
"iso8859-3",
"iso8859-4",
"iso8859-5",
"iso8859-7",
"iso8859-8",
"iso8859-9",
"iso8859-10",
"iso8859-15",
"iso10646-0",
"iso10646-1",
"jisx0201.1976-0",
"jisx0208.1983-0",
"jisx0208.1990-0",
"jisx0208.1997-0",
"jisx0212.1990-0",
"jisx0213.2000-1",
"jisx0213.2000-2",
"koi8-r",
"koi8-u",
"koi8-ub",
"ksc5601.1987-0",
"ksc5601.1992-3",
"tis620-0",
"iso8859-13",
"microsoft-cp1251"
"misc-fontspecific",
};
#if XlibSpecificationRelease >= 6
XOM xom;
#endif
if (!aFontDesc) {
return;
}
context = gtk_widget_get_pango_context(GTK_WIDGET(aWidget));
pango_context_set_language (context, gtk_get_default_language ());
fontmap = pango_x_font_map_for_display(GDK_DISPLAY());
if (!fontmap) {
return;
}
font = pango_font_map_load_font(fontmap, context, aFontDesc);
if (!font) {
return;
}
#if XlibSpecificationRelease >= 6
xom = XOpenOM (GDK_DISPLAY(), NULL, NULL, NULL);
if (xom) {
XOMCharSetList cslist;
int n_encodings = 0;
cslist.charset_count = 0;
XGetOMValues (xom,
XNRequiredCharSet, &cslist,
NULL);
n_encodings = cslist.charset_count;
if (n_encodings) {
char **xom_encodings = (char**) g_malloc (sizeof(char*) * n_encodings);
for (i = 0; i < n_encodings; i++) {
xom_encodings[i] = g_ascii_strdown (cslist.charset_list[i], -1);
}
count = pango_x_list_subfonts(font, xom_encodings, n_encodings,
&subfont_ids, &subfont_charsets);
for(i = 0; i < n_encodings; i++) {
g_free (xom_encodings[i]);
}
g_free (xom_encodings);
}
XCloseOM (xom);
}
#endif
if (count == 0) {
count = pango_x_list_subfonts(font, encodings, G_N_ELEMENTS(encodings),
&subfont_ids, &subfont_charsets);
}
for (i = 0; i < count; i++) {
subfont = pango_x_font_subfont_xlfd(font, subfont_ids[i]);
AppendFontFFREName(aFontName, subfont);
g_free(subfont);
aFontName.Append(PRUnichar(','));
}
spec = pango_font_description_to_string(aFontDesc);
if (subfont_ids != NULL) {
g_free(subfont_ids);
}
if (subfont_charsets != NULL) {
g_free(subfont_charsets);
}
g_free(spec);
g_object_unref(font);
}
#endif /* MOZ_WIDGET_GTK2 && MOZ_ENABLE_COREXFONTS */

Просмотреть файл

@ -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 nsDeviceContextGTK_h___
#define nsDeviceContextGTK_h___
#include "nsDeviceContext.h"
#include "nsUnitConversion.h"
#include "nsIWidget.h"
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsRenderingContextGTK.h"
#include "nsIScreenManager.h"
class nsDeviceContextGTK : public DeviceContextImpl
{
public:
nsDeviceContextGTK();
virtual ~nsDeviceContextGTK();
static void Shutdown(); // to be called from module destructor
NS_IMETHOD Init(nsNativeWidget aNativeWidget);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
NS_IMETHOD CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));}
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetClientRect(nsRect &aRect);
NS_IMETHOD GetRect(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);
NS_IMETHOD GetDepth(PRUint32& aDepth);
NS_IMETHOD ClearCachedSystemFonts();
static int prefChanged(const char *aPref, void *aClosure);
protected:
nsresult SetDPI(PRInt32 aPrefDPI);
private:
PRUint32 mDepth;
PRBool mWriteable;
PRUint32 mNumCells;
static nscoord mDpi;
float mWidthFloat;
float mHeightFloat;
PRInt32 mWidth;
PRInt32 mHeight;
GdkWindow *mDeviceWindow;
nsCOMPtr<nsIScreenManager> mScreenManager;
nsresult GetSystemFontInfo(GdkFont* iFont, nsSystemFontID anID, nsFont* aFont) const;
};
// used by several files
#define NS_TO_GDK_RGB(ns) \
((ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff))
#define GDK_COLOR_TO_NS_RGB(c) \
((nscolor) NS_RGB(c.red, c.green, c.blue))
#endif /* nsDeviceContextGTK_h___ */

Просмотреть файл

@ -1,365 +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 <gdk/gdkx.h>
#include <gdk/gdkprivate.h>
#include "nsDrawingSurfaceGTK.h"
NS_IMPL_ISUPPORTS1(nsDrawingSurfaceGTK, nsIDrawingSurface)
//#define CHEAP_PERFORMANCE_MEASUREMENT
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
static PRTime mLockTime, mUnlockTime;
#endif
#ifdef MOZ_ENABLE_XFT
#include <X11/Xft/Xft.h>
#endif
nsDrawingSurfaceGTK :: nsDrawingSurfaceGTK()
{
GdkVisual *v;
mPixmap = nsnull;
mGC = nsnull;
mDepth = 0;
mWidth = 0;
mHeight = 0;
mFlags = 0;
mImage = nsnull;
mLockWidth = 0;
mLockHeight = 0;
mLockFlags = 0;
mLockX = 0;
mLockY = 0;
mLocked = PR_FALSE;
v = ::gdk_rgb_get_visual();
mPixFormat.mRedMask = v->red_mask;
mPixFormat.mGreenMask = v->green_mask;
mPixFormat.mBlueMask = v->blue_mask;
// FIXME
mPixFormat.mAlphaMask = 0;
mPixFormat.mRedCount = ConvertMaskToCount(v->red_mask);
mPixFormat.mGreenCount = ConvertMaskToCount(v->green_mask);
mPixFormat.mBlueCount = ConvertMaskToCount(v->blue_mask);;
mPixFormat.mRedShift = v->red_shift;
mPixFormat.mGreenShift = v->green_shift;
mPixFormat.mBlueShift = v->blue_shift;
// FIXME
mPixFormat.mAlphaShift = 0;
mDepth = v->depth;
#ifdef MOZ_ENABLE_XFT
mXftDraw = nsnull;
#endif
}
nsDrawingSurfaceGTK :: ~nsDrawingSurfaceGTK()
{
if (mPixmap)
::gdk_pixmap_unref(mPixmap);
if (mImage)
::gdk_image_destroy(mImage);
if (mGC)
gdk_gc_unref(mGC);
#ifdef MOZ_ENABLE_XFT
if (mXftDraw)
XftDrawDestroy(mXftDraw);
#endif
}
/**
* Lock a rect of a drawing surface and return a
* pointer to the upper left hand corner of the
* bitmap.
* @param aX x position of subrect of bitmap
* @param aY y position of subrect of bitmap
* @param aWidth width of subrect of bitmap
* @param aHeight height of subrect of bitmap
* @param aBits out parameter for upper left hand
* corner of bitmap
* @param aStride out parameter for number of bytes
* to add to aBits to go from scanline to scanline
* @param aWidthBytes out parameter for number of
* bytes per line in aBits to process aWidth pixels
* @return error status
*
**/
NS_IMETHODIMP nsDrawingSurfaceGTK :: Lock(PRInt32 aX, PRInt32 aY,
PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride,
PRInt32 *aWidthBytes, PRUint32 aFlags)
{
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
mLockTime = PR_Now();
// MOZ_TIMER_RESET(mLockTime);
// MOZ_TIMER_START(mLockTime);
#endif
#if 0
g_print("nsDrawingSurfaceGTK::Lock() called\n" \
" aX = %i, aY = %i,\n" \
" aWidth = %i, aHeight = %i,\n" \
" aBits, aStride, aWidthBytes,\n" \
" aFlags = %i\n", aX, aY, aWidth, aHeight, aFlags);
#endif
if (mLocked)
{
NS_ASSERTION(0, "nested lock attempt");
return NS_ERROR_FAILURE;
}
mLocked = PR_TRUE;
mLockX = aX;
mLockY = aY;
mLockWidth = aWidth;
mLockHeight = aHeight;
mLockFlags = aFlags;
// Obtain an ximage from the pixmap.
mImage = ::gdk_image_get(mPixmap, mLockX, mLockY, mLockWidth, mLockHeight);
if (!mImage) {
mLocked = PR_FALSE;
return NS_ERROR_FAILURE;
}
*aBits = GDK_IMAGE_XIMAGE(mImage)->data;
// Use GDK_IMAGE_XIMAGE(mImage)->bits_per_pixel instead of mImage->bpp
// since, although bpp is documented as *bytes* per pixel, GDK1 sometimes
// set it as *bits* per pixel.
*aWidthBytes = aWidth * ((GDK_IMAGE_XIMAGE(mImage)->bits_per_pixel + 7) / 8);
*aStride = GDK_IMAGE_XIMAGE(mImage)->bytes_per_line;
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
// MOZ_TIMER_STOP(mLockTime);
// MOZ_TIMER_LOG(("Time taken to lock: "));
// MOZ_TIMER_PRINT(mLockTime);
printf("Time taken to lock: %d\n", PR_Now() - mLockTime);
#endif
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: Unlock(void)
{
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
mUnlockTime = PR_Now();
#endif
// g_print("nsDrawingSurfaceGTK::UnLock() called\n");
if (!mLocked)
{
NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
return NS_ERROR_FAILURE;
}
// If the lock was not read only, put the bits back on the pixmap
if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY))
{
#if 0
g_print("%p gdk_draw_image(pixmap=%p,lockx=%d,locky=%d,lockw=%d,lockh=%d)\n",
this,
mPixmap,
mLockX, mLockY,
mLockWidth, mLockHeight);
#endif
gdk_draw_image(mPixmap,
mGC,
mImage,
0, 0,
mLockX, mLockY,
mLockWidth, mLockHeight);
}
if (mImage)
::gdk_image_destroy(mImage);
mImage = nsnull;
mLocked = PR_FALSE;
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
printf("Time taken to unlock: %d\n", PR_Now() - mUnlockTime);
#endif
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
{
*aWidth = mWidth;
*aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: IsOffscreen(PRBool *aOffScreen)
{
*aOffScreen = mIsOffscreen;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: IsPixelAddressable(PRBool *aAddressable)
{
// FIXME
*aAddressable = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetPixelFormat(nsPixelFormat *aFormat)
{
*aFormat = mPixFormat;
return NS_OK;
}
nsresult nsDrawingSurfaceGTK :: Init(GdkDrawable *aDrawable, GdkGC *aGC)
{
if (mGC)
gdk_gc_unref(mGC);
mGC = gdk_gc_ref(aGC);
mPixmap = aDrawable;
#ifdef MOZ_WIDGET_GTK2
gint width = 0;
gint height = 0;
gdk_drawable_get_size(aDrawable, &width, &height);
mWidth = width;
mHeight = height;
#endif /* MOZ_WIDGET_GTK2 */
// XXX was i smoking crack when i wrote this comment?
// this is definatly going to be on the screen, as it will be the window of a
// widget or something.
mIsOffscreen = PR_FALSE;
if (mImage)
gdk_image_destroy(mImage);
mImage = nsnull;
g_return_val_if_fail(mPixmap != nsnull, NS_ERROR_FAILURE);
return NS_OK;
}
nsresult nsDrawingSurfaceGTK :: Init(GdkGC *aGC, PRUint32 aWidth,
PRUint32 aHeight, PRUint32 aFlags)
{
// ::g_return_val_if_fail (aGC != nsnull, NS_ERROR_FAILURE);
// ::g_return_val_if_fail ((aWidth > 0) && (aHeight > 0), NS_ERROR_FAILURE);
if (mGC)
gdk_gc_unref(mGC);
mGC = gdk_gc_ref(aGC);
mWidth = aWidth;
mHeight = aHeight;
mFlags = aFlags;
// we can draw on this offscreen because it has no parent
mIsOffscreen = PR_TRUE;
mPixmap = ::gdk_pixmap_new(nsnull, mWidth, mHeight, mDepth);
#ifdef MOZ_WIDGET_GTK2
gdk_drawable_set_colormap(GDK_DRAWABLE(mPixmap), gdk_rgb_get_colormap());
#endif
if (mImage)
gdk_image_destroy(mImage);
mImage = nsnull;
return mPixmap ? NS_OK : NS_ERROR_FAILURE;
}
#ifdef MOZ_ENABLE_XFT
XftDraw *nsDrawingSurfaceGTK :: GetXftDraw(void)
{
if (!mXftDraw) {
mXftDraw = XftDrawCreate(GDK_DISPLAY(), GDK_WINDOW_XWINDOW(mPixmap),
GDK_VISUAL_XVISUAL(::gdk_rgb_get_visual()),
GDK_COLORMAP_XCOLORMAP(::gdk_rgb_get_cmap()));
}
return mXftDraw;
}
void nsDrawingSurfaceGTK :: GetLastXftClip(nsIRegion **aLastRegion)
{
*aLastRegion = mLastXftClip.get();
NS_IF_ADDREF(*aLastRegion);
}
void nsDrawingSurfaceGTK :: SetLastXftClip(nsIRegion *aLastRegion)
{
mLastXftClip = aLastRegion;
}
#endif /* MOZ_ENABLE_XFT */
/* inline */
PRUint8
nsDrawingSurfaceGTK::ConvertMaskToCount(unsigned long val)
{
PRUint8 retval = 0;
PRUint8 cur_bit = 0;
// walk through the number, incrementing the value if
// the bit in question is set.
while (cur_bit < (sizeof(unsigned long) * 8)) {
if ((val >> cur_bit) & 0x1) {
retval++;
}
cur_bit++;
}
return retval;
}

Просмотреть файл

@ -1,148 +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 nsDrawingSurfaceGTK_h___
#define nsDrawingSurfaceGTK_h___
#include "nsIDrawingSurface.h"
#include "nsTimer.h"
#include "nsIRegion.h"
#include "nsCOMPtr.h"
#include <gtk/gtk.h>
#ifdef MOZ_ENABLE_XFT
typedef struct _XftDraw XftDraw;
#endif
class nsDrawingSurfaceGTK : public nsIDrawingSurface
{
public:
nsDrawingSurfaceGTK();
virtual ~nsDrawingSurfaceGTK();
/**
* Initialize a drawing surface using a windows DC.
* aDC is "owned" by the drawing surface until the drawing
* surface is destroyed.
* @param aDC HDC to initialize drawing surface with
* @return error status
**/
nsresult Init(GdkDrawable *aDrawable, GdkGC *aGC);
/**
* Initialize an offscreen drawing surface using a
* windows DC. aDC is not "owned" by this drawing surface, instead
* it is used to create a drawing surface compatible
* with aDC. if width or height are less than zero, aDC will
* be created with no offscreen bitmap installed.
* @param aDC HDC to initialize drawing surface with
* @param aWidth width of drawing surface
* @param aHeight height of drawing surface
* @param aFlags flags used to control type of drawing
* surface created
* @return error status
**/
nsresult Init(GdkGC *aGC, PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags);
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);
NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
/* below are utility functions used mostly for nsRenderingContext and nsImage
* to plug into gdk_* functions for drawing. You should not set a pointer
* that might hang around with the return from these. instead use the ones
* above. pav
*/
GdkDrawable *GetDrawable(void) { return mPixmap; }
void GetSize(PRUint32 *aWidth, PRUint32 *aHeight) { *aWidth = mWidth; *aHeight = mHeight; }
PRInt32 GetDepth() { return mDepth; }
#ifdef MOZ_ENABLE_XFT
XftDraw *GetXftDraw (void);
void GetLastXftClip (nsIRegion **aLastRegion);
void SetLastXftClip (nsIRegion *aLastRegion);
#endif /* MOZ_ENABLE_XFT */
protected:
inline PRUint8 ConvertMaskToCount(unsigned long val);
private:
/* general */
GdkPixmap *mPixmap;
GdkGC *mGC;
gint mDepth;
nsPixelFormat mPixFormat;
PRUint32 mWidth;
PRUint32 mHeight;
PRUint32 mFlags;
PRBool mIsOffscreen;
/* for locks */
GdkImage *mImage;
PRInt32 mLockX;
PRInt32 mLockY;
PRUint32 mLockWidth;
PRUint32 mLockHeight;
PRUint32 mLockFlags;
PRBool mLocked;
#ifdef MOZ_ENABLE_XFT
XftDraw *mXftDraw;
nsCOMPtr<nsIRegion> mLastXftClip;
#endif
// MOZ_TIMER_DECLARE(mLockTime)
// MOZ_TIMER_DECLARE(mUnlockTime)
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,448 +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 nsFontMetricsGTK_h__
#define nsFontMetricsGTK_h__
#include "nsDeviceContextGTK.h"
#include "nsIFontMetrics.h"
#include "nsIFontEnumerator.h"
#include "nsFont.h"
#include "nsString.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsRenderingContextGTK.h"
#include "nsICharRepresentable.h"
#include "nsCompressedCharMap.h"
#include "nsIFontMetricsGTK.h"
#ifdef MOZ_ENABLE_FREETYPE2
#include "nsIFontCatalogService.h"
#endif
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#undef FONT_HAS_GLYPH
#define FONT_HAS_GLYPH(map, char) IS_REPRESENTABLE(map, char)
#define WEIGHT_INDEX(weight) (((weight) / 100) - 1)
typedef struct nsFontCharSetInfo nsFontCharSetInfo;
typedef gint (*nsFontCharSetConverter)(nsFontCharSetInfo* aSelf,
XFontStruct* aFont, const PRUnichar* aSrcBuf, PRInt32 aSrcLen,
char* aDestBuf, PRInt32 aDestLen);
struct nsFontCharSet;
struct nsFontFamily;
struct nsFontNode;
struct nsFontStretch;
struct nsFontWeight;
class nsXFont;
class nsFontGTKUserDefined;
class nsFontMetricsGTK;
class nsFreeTypeFace;
class nsFontGTK;
struct nsFontStretch
{
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
void SortSizes(void);
nsFontGTK** mSizes;
PRUint16 mSizesAlloc;
PRUint16 mSizesCount;
char* mScalable;
PRBool mOutlineScaled;
nsVoidArray mScaledFonts;
#ifdef MOZ_ENABLE_FREETYPE2
nsITrueTypeFontCatalogEntry* mFreeTypeFaceID;
#endif
};
struct nsFontStyle
{
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
void FillWeightHoles(void);
nsFontWeight* mWeights[9];
};
struct nsFontWeight
{
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
void FillStretchHoles(void);
nsFontStretch* mStretches[9];
};
struct nsFontNode
{
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
void FillStyleHoles(void);
nsCAutoString mName;
nsFontCharSetInfo* mCharSetInfo;
nsFontStyle* mStyles[3];
PRUint8 mHolesFilled;
PRUint8 mDummy;
};
class nsFontNodeArray : public nsAutoVoidArray
{
public:
nsFontNodeArray() {};
nsFontNode* GetElement(PRInt32 aIndex)
{
return (nsFontNode*) ElementAt(aIndex);
};
};
/*
* Font Language Groups
*
* These Font Language Groups (FLG) indicate other related
* encodings to look at when searching for glyphs
*
*/
typedef struct nsFontLangGroup {
const char *mFontLangGroupName;
nsIAtom* mFontLangGroupAtom;
} nsFontLangGroup;
struct nsFontCharSetMap
{
const char* mName;
nsFontLangGroup* mFontLangGroup;
nsFontCharSetInfo* mInfo;
};
class nsFontGTK
{
public:
nsFontGTK();
nsFontGTK(nsFontGTK*);
virtual ~nsFontGTK();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
void LoadFont(void);
PRBool IsEmptyFont(XFontStruct*);
inline int SupportsChar(PRUint32 aChar)
{ return mCCMap && CCMAP_HAS_CHAR_EXT(mCCMap, aChar); };
virtual GdkFont* GetGDKFont(void);
virtual nsXFont* GetXFont(void);
virtual PRBool GetXFontIs10646(void);
virtual PRBool IsFreeTypeFont(void);
virtual gint GetWidth(const PRUnichar* aString, PRUint32 aLength) = 0;
virtual gint DrawString(nsRenderingContextGTK* aContext,
nsDrawingSurfaceGTK* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength) = 0;
#ifdef MOZ_MATHML
// bounding metrics for a string
// remember returned values are not in app units
// - to emulate GetWidth () above
virtual nsresult
GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics) = 0;
#endif
PRUint16* mCCMap;
nsFontCharSetInfo* mCharSetInfo;
char* mName;
nsFontGTKUserDefined* mUserDefinedFont;
PRUint16 mSize;
PRUint16 mAABaseSize;
PRInt16 mBaselineAdjust;
// these values are not in app units, they need to be scaled with
// nsIDeviceContext::DevUnitsToAppUnits()
PRInt16 mMaxAscent;
PRInt16 mMaxDescent;
protected:
GdkFont* mFont;
GdkFont* mFontHolder;
nsXFont* mXFont;
PRBool mAlreadyCalledLoadFont;
};
struct nsFontSwitchGTK {
// Simple wrapper on top of nsFontGTK for the moment
// Could hold other attributes of the font
nsFontGTK* mFontGTK;
};
typedef PRBool (*PR_CALLBACK nsFontSwitchCallbackGTK)
(const nsFontSwitchGTK *aFontSwitch,
const PRUnichar *aSubstring,
PRUint32 aSubstringLength,
void *aData);
class nsFontMetricsGTK : public nsIFontMetricsGTK
{
public:
nsFontMetricsGTK();
virtual ~nsFontMetricsGTK();
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);
virtual PRInt32 GetMaxStringLength();
NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup);
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
NS_IMETHOD GetSpaceWidth(nscoord &aSpaceWidth);
NS_IMETHOD ResolveForwards(const PRUnichar* aString, PRUint32 aLength,
nsFontSwitchCallbackGTK aFunc, void* aData);
nsFontGTK* FindFont(PRUint32 aChar);
nsFontGTK* FindUserDefinedFont(PRUint32 aChar);
nsFontGTK* FindStyleSheetSpecificFont(PRUint32 aChar);
nsFontGTK* FindStyleSheetGenericFont(PRUint32 aChar);
nsFontGTK* FindLangGroupPrefFont(nsIAtom* aLangGroup, PRUint32 aChar);
nsFontGTK* FindLangGroupFont(nsIAtom* aLangGroup, PRUint32 aChar, nsCString* aName);
nsFontGTK* FindAnyFont(PRUint32 aChar);
nsFontGTK* FindSubstituteFont(PRUint32 aChar);
nsFontGTK* SearchNode(nsFontNode* aNode, PRUint32 aChar);
nsFontGTK* TryAliases(nsCString* aName, PRUint32 aChar);
nsFontGTK* TryFamily(nsCString* aName, PRUint32 aChar);
nsFontGTK* TryNode(nsCString* aName, PRUint32 aChar);
nsFontGTK* TryNodes(nsACString &aFFREName, PRUint32 aChar);
nsFontGTK* TryLangGroup(nsIAtom* aLangGroup, nsCString* aName, PRUint32 aChar);
nsFontGTK* AddToLoadedFontsList(nsFontGTK* aFont);
nsFontGTK* FindNearestSize(nsFontStretch* aStretch, PRUint16 aSize);
nsFontGTK* GetAASBBaseFont(nsFontStretch* aStretch,
nsFontCharSetInfo* aCharSet);
nsFontGTK* PickASizeAndLoad(nsFontStretch* aStretch,
nsFontCharSetInfo* aCharSet,
PRUint32 aChar,
const char *aName);
// nsIFontMetricsGTK (calls from the font rendering layer)
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth,
nsRenderingContextGTK *aContext);
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
nsRenderingContextGTK *aContext);
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
#endif /* MOZ_MATHML */
virtual GdkFont* GetCurrentGDKFont(void);
virtual nsresult SetRightToLeftText(PRBool aIsRTL);
virtual PRBool GetRightToLeftText();
virtual nsresult GetClusterInfo(const PRUnichar *aText,
PRUint32 aLength,
PRUint8 *aClusterStarts);
virtual PRInt32 GetPosition(const PRUnichar *aText,
PRUint32 aLength,
nsPoint aPt);
virtual nsresult GetRangeWidth(const PRUnichar *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
virtual nsresult GetRangeWidth(const char *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
static nsresult FamilyExists(nsIDeviceContext *aDevice, const nsString& aName);
static PRUint32 GetHints(void);
//friend struct nsFontGTK;
nsFontGTK **mLoadedFonts;
PRUint16 mLoadedFontsAlloc;
PRUint16 mLoadedFontsCount;
nsFontGTK *mSubstituteFont;
nsCStringArray mFonts;
PRInt32 mFontsIndex;
nsAutoVoidArray mFontIsGeneric;
nsCAutoString mDefaultFont;
nsCString *mGeneric;
nsCOMPtr<nsIAtom> mLangGroup;
nsCAutoString mUserDefined;
PRUint8 mTriedAllGenerics;
PRUint8 mIsUserDefined;
protected:
void RealizeFont();
nsFontGTK* LocateFont(PRUint32 aChar, PRInt32 & aCount);
nsIDeviceContext *mDeviceContext;
nsFontGTK *mWesternFont;
nsFontGTK *mCurrentFont;
nscoord mLeading;
nscoord mEmHeight;
nscoord mEmAscent;
nscoord mEmDescent;
nscoord mMaxHeight;
nscoord mMaxAscent;
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mXHeight;
nscoord mSuperscriptOffset;
nscoord mSubscriptOffset;
nscoord mStrikeoutSize;
nscoord mStrikeoutOffset;
nscoord mUnderlineSize;
nscoord mUnderlineOffset;
nscoord mSpaceWidth;
nscoord mAveCharWidth;
PRInt32 mMaxStringLength;
PRUint16 mPixelSize;
PRUint8 mStretchIndex;
PRUint8 mStyleIndex;
nsFontCharSetConverter mDocConverterType;
};
class nsFontEnumeratorGTK : public nsIFontEnumerator
{
public:
nsFontEnumeratorGTK();
NS_DECL_ISUPPORTS
NS_DECL_NSIFONTENUMERATOR
};
class nsHashKey;
PRBool FreeNode(nsHashKey* aKey, void* aData, void* aClosure);
nsFontCharSetInfo *GetCharSetInfo(const char *aCharSetName);
#ifdef MOZ_ENABLE_FREETYPE2
void CharSetNameToCodeRangeBits(const char*, PRUint32*, PRUint32*);
#endif
nsFontCharSetMap *GetCharSetMap(const char *aCharSetName);
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,304 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** 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
* Christopher Blizzard <blizzard@mozilla.org>.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#include "nsIFontMetrics.h"
#include "nsIFontEnumerator.h"
#include "nsCRT.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsIFontMetricsGTK.h"
#include <pango/pango.h>
class nsFontMetricsPango : public nsIFontMetricsGTK
{
public:
nsFontMetricsPango();
virtual ~nsFontMetricsPango();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
// nsISupports
NS_DECL_ISUPPORTS
// nsIFontMetrics
NS_IMETHOD Init (const nsFont& aFont, nsIAtom* aLangGroup,
nsIDeviceContext *aContext);
NS_IMETHOD Destroy();
NS_IMETHOD GetLangGroup (nsIAtom** aLangGroup);
NS_IMETHOD GetFontHandle (nsFontHandle &aHandle);
NS_IMETHOD GetXHeight (nscoord& aResult)
{ aResult = mXHeight; return NS_OK; };
NS_IMETHOD GetSuperscriptOffset (nscoord& aResult)
{ aResult = mSuperscriptOffset;
return NS_OK; };
NS_IMETHOD GetSubscriptOffset (nscoord& aResult)
{ aResult = mSubscriptOffset;
return NS_OK; };
NS_IMETHOD GetStrikeout (nscoord& aOffset, nscoord& aSize)
{ aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
return NS_OK; };
NS_IMETHOD GetUnderline (nscoord& aOffset, nscoord& aSize)
{ aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
return NS_OK; };
NS_IMETHOD GetHeight (nscoord &aHeight)
{ aHeight = mMaxHeight;
return NS_OK; };
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)
{ aHeight = mEmHeight + mLeading;
return NS_OK; };
NS_IMETHOD GetLeading (nscoord &aLeading)
{ aLeading = mLeading;
return NS_OK; };
NS_IMETHOD GetEmHeight (nscoord &aHeight)
{ aHeight = mEmHeight;
return NS_OK; };
NS_IMETHOD GetEmAscent (nscoord &aAscent)
{ aAscent = mEmAscent;
return NS_OK; };
NS_IMETHOD GetEmDescent (nscoord &aDescent)
{ aDescent = mEmDescent;
return NS_OK; };
NS_IMETHOD GetMaxHeight (nscoord &aHeight)
{ aHeight = mMaxHeight;
return NS_OK; };
NS_IMETHOD GetMaxAscent (nscoord &aAscent)
{ aAscent = mMaxAscent;
return NS_OK; };
NS_IMETHOD GetMaxDescent (nscoord &aDescent)
{ aDescent = mMaxDescent;
return NS_OK; };
NS_IMETHOD GetMaxAdvance (nscoord &aAdvance)
{ aAdvance = mMaxAdvance;
return NS_OK; };
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceCharWidth)
{ aSpaceCharWidth = mSpaceWidth;
return NS_OK; };
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)
{ aAveCharWidth = mAveCharWidth;
return NS_OK; };
PRInt32 GetMaxStringLength() { return mMaxStringLength; }
// nsIFontMetricsGTK (calls from the font rendering layer)
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth,
nsRenderingContextGTK *aContext);
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
nsRenderingContextGTK *aContext);
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
#endif /* MOZ_MATHML */
virtual GdkFont* GetCurrentGDKFont(void);
virtual nsresult SetRightToLeftText(PRBool aIsRTL);
virtual PRBool GetRightToLeftText();
virtual nsresult GetClusterInfo(const PRUnichar *aText,
PRUint32 aLength,
PRUint8 *aClusterStarts);
virtual PRInt32 GetPosition(const PRUnichar *aText,
PRUint32 aLength,
nsPoint aPt);
virtual nsresult GetRangeWidth(const PRUnichar *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
virtual nsresult GetRangeWidth(const char *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
// get hints for the font
static PRUint32 GetHints (void);
// drawing surface methods
static nsresult FamilyExists (nsIDeviceContext *aDevice,
const nsString &aName);
private:
// generic font metrics class bits
nsCStringArray mFontList;
nsAutoVoidArray mFontIsGeneric;
nsIDeviceContext *mDeviceContext;
nsCOMPtr<nsIAtom> mLangGroup;
nsCString *mGenericFont;
float mPointSize;
nsCAutoString mDefaultFont;
// Pango-related items
PangoFontDescription *mPangoFontDesc;
PangoContext *mPangoContext;
PangoContext *mLTRPangoContext;
PangoContext *mRTLPangoContext;
PangoAttrList *mPangoAttrList;
PRBool mIsRTL;
// Cached font metrics
nscoord mXHeight;
nscoord mSuperscriptOffset;
nscoord mSubscriptOffset;
nscoord mStrikeoutOffset;
nscoord mStrikeoutSize;
nscoord mUnderlineOffset;
nscoord mUnderlineSize;
nscoord mMaxHeight;
nscoord mLeading;
nscoord mEmHeight;
nscoord mEmAscent;
nscoord mEmDescent;
nscoord mMaxAscent;
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mSpaceWidth;
nscoord mPangoSpaceWidth;
nscoord mAveCharWidth;
PRInt32 mMaxStringLength;
// Private methods
nsresult RealizeFont(void);
nsresult CacheFontMetrics(void);
static PRBool EnumFontCallback(const nsString &aFamily,
PRBool aIsGeneric, void *aData);
void DrawStringSlowly(const gchar *aText,
const PRUnichar *aOrigString,
PRUint32 aLength,
GdkDrawable *aDrawable,
GdkGC *aGC, gint aX, gint aY,
PangoLayoutLine *aLine,
const nscoord *aSpacing);
nsresult GetTextDimensionsInternal(const gchar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
nsRenderingContextGTK *aContext);
void FixupSpaceWidths (PangoLayout *aLayout, const char *aString);
};
class nsFontEnumeratorPango : public nsIFontEnumerator
{
public:
nsFontEnumeratorPango();
NS_DECL_ISUPPORTS
NS_DECL_NSIFONTENUMERATOR
};

Просмотреть файл

@ -1,153 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** 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
* Christopher Blizzard <blizzard@mozilla.org>.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
// welcome to the dumping ground for font metrics stuff that has to
// know about both the xft and core fonts code.
#ifdef MOZ_ENABLE_XFT
#include "nsFontMetricsXft.h"
#include "nsIPref.h"
#include "nsServiceManagerUtils.h"
#include "prenv.h"
#endif /* MOZ_ENABLE_XFT */
#ifdef MOZ_ENABLE_COREXFONTS
#include "nsFontMetricsGTK.h"
#endif
#ifdef MOZ_ENABLE_PANGO
#include "nsFontMetricsPango.h"
#include "prenv.h"
#endif
#include "nsFontMetricsUtils.h"
PRUint32
NS_FontMetricsGetHints(void)
{
#ifdef MOZ_ENABLE_PANGO
if (NS_IsPangoEnabled()) {
return nsFontMetricsPango::GetHints();
}
#endif
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
return nsFontMetricsXft::GetHints();
}
#endif
#ifdef MOZ_ENABLE_COREXFONTS
return nsFontMetricsGTK::GetHints();
#endif
}
nsresult
NS_FontMetricsFamilyExists(nsIDeviceContext *aDevice, const nsString &aName)
{
#ifdef MOZ_ENABLE_PANGO
if (NS_IsPangoEnabled()) {
return nsFontMetricsPango::FamilyExists(aDevice, aName);
}
#endif
#ifdef MOZ_ENABLE_XFT
// try to fall through to the core fonts if xft fails
if (NS_IsXftEnabled()) {
return nsFontMetricsXft::FamilyExists(aDevice, aName);
}
#endif
#ifdef MOZ_ENABLE_COREXFONTS
return nsFontMetricsGTK::FamilyExists(aDevice, aName);
#endif
}
#if defined(MOZ_ENABLE_XFT) && defined(MOZ_ENABLE_COREXFONTS)
PRBool
NS_IsXftEnabled(void)
{
static PRBool been_here = PR_FALSE;
static PRBool cachedXftSetting = PR_TRUE;
if (!been_here) {
been_here = PR_TRUE;
nsCOMPtr<nsIPref> prefService;
prefService = do_GetService(NS_PREF_CONTRACTID);
if (!prefService)
return PR_TRUE;
nsresult rv;
rv = prefService->GetBoolPref("fonts.xft.enabled", &cachedXftSetting);
// Yes, this makes sense. If xft is compiled in and there's no
// pref, it's automatically enabled. If there's no pref, check
// the environment.
if (NS_FAILED(rv)) {
char *val = PR_GetEnv("GDK_USE_XFT");
if (val && val[0] == '0') {
cachedXftSetting = PR_FALSE;
goto end;
}
cachedXftSetting = PR_TRUE;
}
}
end:
return cachedXftSetting;
}
#endif
#if defined(MOZ_ENABLE_PANGO) && (defined(MOZ_ENABLE_XFT) || defined(MOZ_ENABLE_COREXFONTS))
PRBool
NS_IsPangoEnabled(void)
{
char *val = PR_GetEnv("MOZ_DISABLE_PANGO");
if (val)
return FALSE;
return TRUE;
}
#endif

Просмотреть файл

@ -1,62 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** 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
* Christopher Blizzard <blizzard@mozilla.org>.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#ifndef __nsFontMetricsUtils_h
#define __nsFontMetricsUtils_h
extern PRUint32 NS_FontMetricsGetHints ();
extern nsresult NS_FontMetricsFamilyExists(nsIDeviceContext *aDevice,
const nsString &aName);
#ifdef MOZ_ENABLE_XFT
#ifdef MOZ_ENABLE_COREXFONTS
extern PRBool NS_IsXftEnabled();
#else
inline PRBool NS_IsXftEnabled() { return PR_TRUE; }
#endif
#endif
#ifdef MOZ_ENABLE_PANGO
#if defined(MOZ_ENABLE_XFT) || defined(MOZ_ENABLE_COREXFONTS)
extern PRBool NS_IsPangoEnabled();
#else
inline PRBool NS_IsPangoEnabled() { return PR_TRUE; }
#endif
#endif
#endif /* __nsFontMetricsUtils_h */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,350 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** 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
* Christopher Blizzard <blizzard@mozilla.org>.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#include "nsIFontMetrics.h"
#include "nsIFontEnumerator.h"
#include "nsCRT.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsIFontMetricsGTK.h"
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
class nsFontXft;
class nsFontMetricsXft;
typedef nsresult (nsFontMetricsXft::*GlyphEnumeratorCallback)
(const FcChar32 *aString,
PRUint32 aLen, nsFontXft *aFont,
void *aData);
class nsFontMetricsXft : public nsIFontMetricsGTK
{
public:
nsFontMetricsXft();
virtual ~nsFontMetricsXft();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
// nsISupports
NS_DECL_ISUPPORTS
// nsIFontMetrics
NS_IMETHOD Init (const nsFont& aFont, nsIAtom* aLangGroup,
nsIDeviceContext *aContext);
NS_IMETHOD Destroy();
NS_IMETHOD GetLangGroup (nsIAtom** aLangGroup);
NS_IMETHOD GetFontHandle (nsFontHandle &aHandle);
NS_IMETHOD GetXHeight (nscoord& aResult)
{ aResult = mXHeight; return NS_OK; };
NS_IMETHOD GetSuperscriptOffset (nscoord& aResult)
{ aResult = mSuperscriptOffset;
return NS_OK; };
NS_IMETHOD GetSubscriptOffset (nscoord& aResult)
{ aResult = mSubscriptOffset;
return NS_OK; };
NS_IMETHOD GetStrikeout (nscoord& aOffset, nscoord& aSize)
{ aOffset = mStrikeoutOffset;
aSize = mStrikeoutSize;
return NS_OK; };
NS_IMETHOD GetUnderline (nscoord& aOffset, nscoord& aSize)
{ aOffset = mUnderlineOffset;
aSize = mUnderlineSize;
return NS_OK; };
NS_IMETHOD GetHeight (nscoord &aHeight)
{ aHeight = mMaxHeight;
return NS_OK; };
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)
{ aHeight = mEmHeight + mLeading;
return NS_OK; };
NS_IMETHOD GetLeading (nscoord &aLeading)
{ aLeading = mLeading;
return NS_OK; };
NS_IMETHOD GetEmHeight (nscoord &aHeight)
{ aHeight = mEmHeight;
return NS_OK; };
NS_IMETHOD GetEmAscent (nscoord &aAscent)
{ aAscent = mEmAscent;
return NS_OK; };
NS_IMETHOD GetEmDescent (nscoord &aDescent)
{ aDescent = mEmDescent;
return NS_OK; };
NS_IMETHOD GetMaxHeight (nscoord &aHeight)
{ aHeight = mMaxHeight;
return NS_OK; };
NS_IMETHOD GetMaxAscent (nscoord &aAscent)
{ aAscent = mMaxAscent;
return NS_OK; };
NS_IMETHOD GetMaxDescent (nscoord &aDescent)
{ aDescent = mMaxDescent;
return NS_OK; };
NS_IMETHOD GetMaxAdvance (nscoord &aAdvance)
{ aAdvance = mMaxAdvance;
return NS_OK; };
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceCharWidth)
{ aSpaceCharWidth = mSpaceWidth;
return NS_OK; };
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)
{ aAveCharWidth = mAveCharWidth;
return NS_OK; };
PRInt32 GetMaxStringLength() { return mMaxStringLength; }
// nsIFontMetricsGTK (calls from the font rendering layer)
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth,
nsRenderingContextGTK *aContext);
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext);
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface);
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
nsRenderingContextGTK *aContext);
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
PRInt32 *aFontID,
nsRenderingContextGTK *aContext);
#endif /* MOZ_MATHML */
virtual GdkFont* GetCurrentGDKFont(void);
virtual nsresult SetRightToLeftText(PRBool aIsRTL);
virtual PRBool GetRightToLeftText();
virtual nsresult GetClusterInfo(const PRUnichar *aText,
PRUint32 aLength,
PRUint8 *aClusterStarts);
virtual PRInt32 GetPosition(const PRUnichar *aText,
PRUint32 aLength,
nsPoint aPt);
virtual nsresult GetRangeWidth(const PRUnichar *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
virtual nsresult GetRangeWidth(const char *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
// get hints for the font
static PRUint32 GetHints (void);
// drawing surface methods
static nsresult FamilyExists (nsIDeviceContext *aDevice,
const nsString &aName);
nsresult DrawStringCallback (const FcChar32 *aString, PRUint32 aLen,
nsFontXft *aFont, void *aData);
nsresult TextDimensionsCallback (const FcChar32 *aString, PRUint32 aLen,
nsFontXft *aFont, void *aData);
nsresult GetWidthCallback (const FcChar32 *aString, PRUint32 aLen,
nsFontXft *aFont, void *aData);
#ifdef MOZ_MATHML
nsresult BoundingMetricsCallback (const FcChar32 *aString, PRUint32 aLen,
nsFontXft *aFont, void *aData);
#endif /* MOZ_MATHML */
private:
enum FontMatch {
eNoMatch,
eBestMatch,
eAllMatching
};
// local methods
nsresult RealizeFont (void);
nsresult CacheFontMetrics (void);
// Guaranteed to return either null or a font on which |GetXftFont|
// returns non-null.
nsFontXft *FindFont (PRUint32);
void SetupFCPattern (void);
void DoMatch (PRBool aMatchAll);
gint RawGetWidth (const PRUnichar* aString,
PRUint32 aLength);
nsresult SetupMiniFont (void);
nsresult DrawUnknownGlyph (FcChar32 aChar,
nscoord aX,
nscoord aY,
XftColor *aColor,
XftDraw *aDraw);
nsresult EnumerateXftGlyphs (const FcChar32 *aString,
PRUint32 aLen,
GlyphEnumeratorCallback aCallback,
void *aCallbackData);
nsresult EnumerateGlyphs (const char *aString,
PRUint32 aLen,
GlyphEnumeratorCallback aCallback,
void *aCallbackData);
nsresult EnumerateGlyphs (const PRUnichar *aString,
PRUint32 aLen,
GlyphEnumeratorCallback aCallback,
void *aCallbackData);
void PrepareToDraw (nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface,
XftDraw **aDraw, XftColor &aColor);
// called when enumerating font families
static PRBool EnumFontCallback (const nsString &aFamily,
PRBool aIsGeneric, void *aData);
// generic font metrics class bits
nsCStringArray mFontList;
nsAutoVoidArray mFontIsGeneric;
nsIDeviceContext *mDeviceContext;
nsCOMPtr<nsIAtom> mLangGroup;
nsCString *mGenericFont;
float mPixelSize;
nsCAutoString mDefaultFont;
// private to DoMatch and FindFont; this array may contain fonts
// for which |GetXftFont| returns null (which are not allowed outside
// of those two functions).
nsVoidArray mLoadedFonts;
// Xft-related items
nsFontXft *mWesternFont;
FcPattern *mPattern;
FontMatch mMatchType;
// for rendering unknown fonts
XftFont *mMiniFont;
nscoord mMiniFontWidth;
nscoord mMiniFontHeight;
nscoord mMiniFontPadding;
nscoord mMiniFontYOffset;
nscoord mMiniFontAscent;
nscoord mMiniFontDescent;
// Cached font metrics
nscoord mXHeight;
nscoord mSuperscriptOffset;
nscoord mSubscriptOffset;
nscoord mStrikeoutOffset;
nscoord mStrikeoutSize;
nscoord mUnderlineOffset;
nscoord mUnderlineSize;
nscoord mMaxHeight;
nscoord mLeading;
nscoord mEmHeight;
nscoord mEmAscent;
nscoord mEmDescent;
nscoord mMaxAscent;
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mSpaceWidth;
nscoord mAveCharWidth;
PRInt32 mMaxStringLength;
};
class nsFontEnumeratorXft : public nsIFontEnumerator
{
public:
nsFontEnumeratorXft();
NS_DECL_ISUPPORTS
NS_DECL_NSIFONTENUMERATOR
};

Просмотреть файл

@ -1,270 +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 the Mozilla browser.
*
* 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):
* Stuart Parmenter <pavlov@netscape.com>
* Mike Shaver <shaver@zeroknowledge.com>
* Tomi Leppikangas <Tomi.Leppikangas@oulu.fi>
*
* 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 <stdio.h>
#include "nsGCCache.h"
#include "nsISupportsUtils.h"
#include <gdk/gdkx.h>
#include <gdk/gdkprivate.h>
#include <X11/Xlib.h>
/* The GC cache is shared among all windows, since it doesn't hog
any scarce resources (like colormap entries.) */
GdkRegion *nsGCCache::copyRegion = NULL;
nsGCCache::nsGCCache()
{
MOZ_COUNT_CTOR(nsGCCache);
PR_INIT_CLIST(&GCCache);
PR_INIT_CLIST(&GCFreeList);
for (int i = 0; i < GC_CACHE_SIZE; i++) {
GCCacheEntry *entry = new GCCacheEntry();
entry->gc=NULL;
PR_INSERT_LINK(&entry->clist, &GCFreeList);
}
DEBUG_METER(memset(&GCCacheStats, 0, sizeof(GCCacheStats));)
}
/* static */ void
nsGCCache::Shutdown()
{
if (copyRegion) {
gdk_region_destroy(copyRegion);
copyRegion = nsnull;
}
}
void
nsGCCache::move_cache_entry(PRCList *clist)
{
/* thread on the freelist, at the front */
PR_REMOVE_LINK(clist);
PR_INSERT_LINK(clist, &GCFreeList);
}
void
nsGCCache::free_cache_entry(PRCList *clist)
{
GCCacheEntry *entry = (GCCacheEntry *)clist;
gdk_gc_unref(entry->gc);
if (entry->clipRegion)
gdk_region_destroy(entry->clipRegion);
/* thread on the freelist, at the front */
PR_REMOVE_LINK(clist);
memset(entry, 0, sizeof(*entry));
PR_INSERT_LINK(clist, &GCFreeList);
}
nsGCCache::~nsGCCache()
{
PRCList *head;
MOZ_COUNT_DTOR(nsGCCache);
ReportStats();
while (!PR_CLIST_IS_EMPTY(&GCCache)) {
head = PR_LIST_HEAD(&GCCache);
if (head == &GCCache)
break;
free_cache_entry(head);
}
while (!PR_CLIST_IS_EMPTY(&GCFreeList)) {
head = PR_LIST_HEAD(&GCFreeList);
if (head == &GCFreeList)
break;
PR_REMOVE_LINK(head);
delete (GCCacheEntry *)head;
}
}
void
nsGCCache::ReportStats() {
DEBUG_METER(
fprintf(stderr, "GC Cache:\n\thits:");
int hits = 0;
for (int i = 0; i < GC_CACHE_SIZE; i++) {
fprintf(stderr, " %4d", GCCacheStats.hits[i]);
hits+=GCCacheStats.hits[i];
}
int total = hits + GCCacheStats.misses;
float percent = float(float(hits) / float(total));
percent *= 100;
fprintf(stderr, "\n\thits: %d, misses: %d, hit percent: %f%%\n",
hits, GCCacheStats.misses, percent);
);
}
/* Dispose of entries matching the given flags, compressing the GC cache */
void nsGCCache::Flush(unsigned long flags)
{
while (!PR_CLIST_IS_EMPTY(&GCCache)) {
PRCList *head = PR_LIST_HEAD(&GCCache);
if (head == &GCCache)
break;
GCCacheEntry *entry = (GCCacheEntry *)head;
if (entry->flags & flags)
free_cache_entry(head);
}
}
GdkGC *nsGCCache::GetGC(GdkWindow *window, GdkGCValues *gcv, GdkGCValuesMask flags, GdkRegion *clipRegion)
{
PRCList *iter;
GCCacheEntry *entry;
DEBUG_METER(int i = 0;)
for (iter = PR_LIST_HEAD(&GCCache); iter != &GCCache;
iter = PR_NEXT_LINK(iter)) {
entry = (GCCacheEntry *)iter;
if (flags == entry->flags &&
!memcmp (gcv, &entry->gcv, sizeof (*gcv))) {
/* if there's a clipRegion, we have to match */
if ((clipRegion && entry->clipRegion &&
gdk_region_equal(clipRegion, entry->clipRegion)) ||
/* and if there isn't, we can't have one */
(!clipRegion && !entry->clipRegion)) {
/* move to the front of the list, if needed */
if (iter != PR_LIST_HEAD(&GCCache)) {
PR_REMOVE_LINK(iter);
PR_INSERT_LINK(iter, &GCCache);
}
DEBUG_METER(GCCacheStats.hits[i]++;)
return gdk_gc_ref(entry->gc);
}
}
DEBUG_METER(++i;)
}
/* might need to forcibly free the LRU cache entry */
if (PR_CLIST_IS_EMPTY(&GCFreeList)) {
DEBUG_METER(GCCacheStats.reclaim++);
move_cache_entry(PR_LIST_TAIL(&GCCache));
}
DEBUG_METER(GCCacheStats.misses++;)
iter = PR_LIST_HEAD(&GCFreeList);
PR_REMOVE_LINK(iter);
PR_INSERT_LINK(iter, &GCCache);
entry = (GCCacheEntry *)iter;
if (!entry->gc) {
// No old GC, greate new
entry->gc = gdk_gc_new_with_values(window, gcv, flags);
entry->flags = flags;
entry->gcv = *gcv;
entry->clipRegion = NULL;
//printf("creating new gc=%X\n",entry->gc);
}
else if ( G_OBJECT(entry->gc)->ref_count > 1 ) {
// Old GC still in use, create new
gdk_gc_unref(entry->gc);
entry->gc=gdk_gc_new_with_values(window, gcv, flags);
entry->flags = flags;
entry->gcv = *gcv;
entry->clipRegion = NULL;
//printf("creating new (use)gc=%X\n",entry->gc);
}
else {
ReuseGC(entry, gcv, flags);
}
if (clipRegion) {
entry->clipRegion = gdk_region_copy(clipRegion);
if (entry->clipRegion)
gdk_gc_set_clip_region(entry->gc, entry->clipRegion);
/* XXX what if it fails? */
}
return gdk_gc_ref(entry->gc);
}
void nsGCCache::ReuseGC(GCCacheEntry *entry, GdkGCValues *gcv, GdkGCValuesMask flags)
{
// We have old GC, reuse it and check what
// we have to change
GdkGCValues xvalues;
int xvalues_mask = 0;
if (entry->clipRegion) {
// set it to none here and then set the clip region with
// gdk_gc_set_clip_region in GetGC()
xvalues.clip_mask = None;
xvalues_mask |= GDK_GC_CLIP_MASK;
gdk_region_destroy(entry->clipRegion);
entry->clipRegion = NULL;
}
if (entry->gcv.foreground.pixel != gcv->foreground.pixel) {
xvalues.foreground.pixel = gcv->foreground.pixel;
xvalues_mask |= GDK_GC_FOREGROUND;
}
if (entry->gcv.function != gcv->function) {
xvalues.function = gcv->function;
xvalues_mask |= GDK_GC_FUNCTION;
}
if(entry->gcv.font != gcv->font && flags & GDK_GC_FONT) {
xvalues.font = gcv->font;
xvalues_mask |= GDK_GC_FONT;
}
if (entry->gcv.line_style != gcv->line_style) {
xvalues.line_style = gcv->line_style;
xvalues_mask |= GDK_GC_LINE_STYLE;
}
if (xvalues_mask != 0) {
gdk_gc_set_values(entry->gc, &xvalues, (GdkGCValuesMask)xvalues_mask);
}
entry->flags = flags;
entry->gcv = *gcv;
}

Просмотреть файл

@ -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 the Mozilla browser.
*
* 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):
* Stuart Parmenter <pavlov@netscape.com>
* Mike Shaver <shaver@zeroknowledge.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 <gdk/gdk.h>
#include <string.h>
#include "prclist.h"
#ifndef nsGCCache_h___
#define nsGCCache_h___
#define countof(x) ((int)(sizeof(x) / sizeof (*x)))
#define GC_CACHE_SIZE 10
#ifdef DEBUG
#define DEBUG_METER(x) x
#else
#define DEBUG_METER(x)
#endif
struct GCCacheEntry
{
PRCList clist;
GdkGCValuesMask flags;
GdkGCValues gcv;
GdkRegion *clipRegion;
GdkGC *gc;
};
class nsGCCache
{
public:
nsGCCache();
virtual ~nsGCCache();
static void Shutdown();
void Flush(unsigned long flags);
GdkGC *GetGC(GdkWindow *window, GdkGCValues *gcv, GdkGCValuesMask flags, GdkRegion *clipRegion);
private:
void ReuseGC(GCCacheEntry *entry, GdkGCValues *gcv, GdkGCValuesMask flags);
PRCList GCCache;
PRCList GCFreeList;
void free_cache_entry(PRCList *clist);
void move_cache_entry(PRCList *clist);
static GdkRegion *copyRegion;
void ReportStats();
DEBUG_METER(
struct {
int hits[GC_CACHE_SIZE];
int misses;
int reclaim;
} GCCacheStats;
)
};
#endif

Просмотреть файл

@ -1,91 +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) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@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 "nsGdkUtils.h"
#include <gdk/gdkprivate.h>
#include <gdk/gdkx.h>
void
my_gdk_draw_text(GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *text,
gint text_length)
{
g_return_if_fail (drawable != NULL);
g_return_if_fail (font != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (text != NULL);
if (GDK_IS_WINDOW(drawable) && GDK_WINDOW_OBJECT(drawable)->destroyed)
return;
if (font->type == GDK_FONT_FONT)
{
XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT(font);
// gdk does this... we don't need it..
// XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
// We clamp the sizes down to 32768 which is the maximum width of
// a window. Even if a font was 1 pixel high and started at the
// left, the maximum size of a draw request could only be 32k.
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
XDrawString (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable),
GDK_GC_XGC(gc), x, y, text, MIN(text_length, 32768));
}
else
{
XDrawString16 (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable),
GDK_GC_XGC(gc), x, y, (XChar2b *) text,
MIN((text_length / 2), 32768));
}
}
else if (font->type == GDK_FONT_FONTSET)
{
XFontSet fontset = (XFontSet) GDK_FONT_XFONT(font);
XmbDrawString (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable),
fontset, GDK_GC_XGC(gc), x, y, text, text_length);
}
else
g_error("undefined font type\n");
}

Просмотреть файл

@ -1,52 +0,0 @@
/* -*- Mode: C++; tab-width: 1; 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) 2002
* 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 nsGdkUtils_h___
#define nsGdkUtils_h___
#include <gtk/gtk.h>
// replacment for gdk_draw_text that doesn't do XSetFont
void my_gdk_draw_text(GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *text,
gint text_length);
#endif /* nsGdkUtils_h___ */

Просмотреть файл

@ -1,300 +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
* Christopher Blizzard.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzzard <blizzard@mozilla.org>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
* 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 "gfx-config.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsCOMPtr.h"
#include "nsGfxCIID.h"
#include "nsBlender.h"
#include "nsRenderingContextGTK.h"
#include "nsDeviceContextGTK.h"
#include "nsScriptableRegion.h"
#include "nsDeviceContextGTK.h"
#include "nsImageGTK.h"
#include "nsFontList.h"
#include "nsRegionGTK.h"
#include "nsGCCache.h"
#ifdef MOZ_ENABLE_PANGO
#include "nsFontMetricsPango.h"
#endif
#ifdef MOZ_ENABLE_XFT
#include "nsFontMetricsXft.h"
#endif
#ifdef MOZ_ENABLE_COREXFONTS
#include "nsFontMetricsGTK.h"
#endif
#include "nsFontMetricsUtils.h"
#include "gfxImageFrame.h"
#ifdef MOZ_ENABLE_FREETYPE2
#include "nsFT2FontCatalog.h"
#include "nsFreeType.h"
#endif
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionGTK)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList)
NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
#ifdef MOZ_ENABLE_FREETYPE2
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFT2FontCatalog)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFreeType2, Init)
#endif
// our custom constructors
static nsresult
nsFontMetricsConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsIFontMetrics *result;
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
#ifdef MOZ_ENABLE_PANGO
if (NS_IsPangoEnabled()) {
result = new nsFontMetricsPango();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
} else {
#endif
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
result = new nsFontMetricsXft();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
} else {
#endif
#ifdef MOZ_ENABLE_COREXFONTS
result = new nsFontMetricsGTK();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
#endif
#ifdef MOZ_ENABLE_XFT
}
#endif
#ifdef MOZ_ENABLE_PANGO
}
#endif
NS_ADDREF(result);
nsresult rv = result->QueryInterface(aIID, aResult);
NS_RELEASE(result);
return rv;
}
static nsresult
nsFontEnumeratorConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsIFontEnumerator *result;
if (!aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
#ifdef MOZ_ENABLE_PANGO
if (NS_IsPangoEnabled()) {
result = new nsFontEnumeratorPango();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
} else {
#endif
#ifdef MOZ_ENABLE_XFT
if (NS_IsXftEnabled()) {
result = new nsFontEnumeratorXft();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
} else {
#endif
#ifdef MOZ_ENABLE_COREXFONTS
result = new nsFontEnumeratorGTK();
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
#endif
#ifdef MOZ_ENABLE_XFT
}
#endif
#ifdef MOZ_ENABLE_PANGO
}
#endif
NS_ADDREF(result);
nsresult rv = result->QueryInterface(aIID, aResult);
NS_RELEASE(result);
return rv;
}
static NS_IMETHODIMP nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
nsIScriptableRegion *inst;
if ( !aResult )
{
rv = NS_ERROR_NULL_POINTER;
return rv;
}
*aResult = nsnull;
if (aOuter)
{
rv = NS_ERROR_NO_AGGREGATION;
return rv;
}
// create an nsRegionGtk and get the scriptable region from it
nsCOMPtr <nsIRegion> rgn;
NS_NEWXPCOM(rgn, nsRegionGTK);
nsCOMPtr<nsIScriptableRegion> scriptableRgn;
if (rgn != nsnull)
{
scriptableRgn = new nsScriptableRegion(rgn);
inst = scriptableRgn;
}
if (!inst)
{
rv = NS_ERROR_OUT_OF_MEMORY;
return rv;
}
NS_ADDREF(inst);
// release our variable above now that we have created our owning
// reference - we don't want this to go out of scope early!
scriptableRgn = nsnull;
rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
return rv;
}
static const nsModuleComponentInfo components[] =
{
{ "Gtk Font Metrics",
NS_FONT_METRICS_CID,
// "@mozilla.org/gfx/font_metrics/gtk;1",
"@mozilla.org/gfx/fontmetrics;1",
nsFontMetricsConstructor },
{ "Gtk Device Context",
NS_DEVICE_CONTEXT_CID,
// "@mozilla.org/gfx/device_context/gtk;1",
"@mozilla.org/gfx/devicecontext;1",
nsDeviceContextGTKConstructor },
{ "Gtk Rendering Context",
NS_RENDERING_CONTEXT_CID,
// "@mozilla.org/gfx/rendering_context/gtk;1",
"@mozilla.org/gfx/renderingcontext;1",
nsRenderingContextGTKConstructor },
{ "Gtk Image",
NS_IMAGE_CID,
// "@mozilla.org/gfx/image/gtk;1",
"@mozilla.org/gfx/image;1",
nsImageGTKConstructor },
{ "Gtk Region",
NS_REGION_CID,
"@mozilla.org/gfx/region/gtk;1",
nsRegionGTKConstructor },
{ "Scriptable Region",
NS_SCRIPTABLE_REGION_CID,
// "@mozilla.org/gfx/scriptable_region;1",
"@mozilla.org/gfx/region;1",
nsScriptableRegionConstructor },
{ "Blender",
NS_BLENDER_CID,
// "@mozilla.org/gfx/blender;1",
"@mozilla.org/gfx/blender;1",
nsBlenderConstructor },
{ "GTK Font Enumerator",
NS_FONT_ENUMERATOR_CID,
// "@mozilla.org/gfx/font_enumerator/gtk;1",
"@mozilla.org/gfx/fontenumerator;1",
nsFontEnumeratorConstructor },
{ "Font List",
NS_FONTLIST_CID,
// "@mozilla.org/gfx/fontlist;1"
NS_FONTLIST_CONTRACTID,
nsFontListConstructor },
{ "windows image frame",
GFX_IMAGEFRAME_CID,
"@mozilla.org/gfx/image/frame;2",
gfxImageFrameConstructor, },
#ifdef MOZ_ENABLE_FREETYPE2
{ "TrueType Font Catalog Service",
NS_FONTCATALOGSERVICE_CID,
"@mozilla.org/gfx/xfontcatalogservice;1",
nsFT2FontCatalogConstructor },
{ "FreeType2 routines",
NS_FREETYPE2_CID,
NS_FREETYPE2_CONTRACTID,
nsFreeType2Constructor },
#endif
};
PR_STATIC_CALLBACK(nsresult)
nsGfxGTKModuleCtor(nsIModule *self)
{
nsImageGTK::Startup();
return NS_OK;
}
PR_STATIC_CALLBACK(void)
nsGfxGTKModuleDtor(nsIModule *self)
{
nsRenderingContextGTK::Shutdown();
nsDeviceContextGTK::Shutdown();
nsImageGTK::Shutdown();
nsGCCache::Shutdown();
}
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsGfxGTKModule, components,
nsGfxGTKModuleCtor, nsGfxGTKModuleDtor)

Просмотреть файл

@ -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) 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 "nsGraphicsStateGTK.h"
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::nsGraphicsState()
{
mMatrix = nsnull;
mClipRegion = nsnull;
mColor = 0;
mLineStyle = nsLineStyle_kSolid;
mFontMetrics = nsnull;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::~nsGraphicsState()
{
NS_IF_RELEASE(mFontMetrics);
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::nsGraphicsStatePool()
{
mFreeList = nsnull;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Public nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
/* static */ nsGraphicsState *
nsGraphicsStatePool::GetNewGS()
{
nsGraphicsStatePool * thePool = PrivateGetPool();
return thePool->PrivateGetNewGS();
}
//////////////////////////////////////////////////////////////////////////
/* static */ void
nsGraphicsStatePool::ReleaseGS(nsGraphicsState* aGS)
{
nsGraphicsStatePool * thePool = PrivateGetPool();
thePool->PrivateReleaseGS(aGS);
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Private nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::gsThePool = nsnull;
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::PrivateGetPool()
{
if (nsnull == gsThePool)
{
gsThePool = new nsGraphicsStatePool();
}
return gsThePool;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::~nsGraphicsStatePool()
{
nsGraphicsState* gs = mFreeList;
while (gs != nsnull) {
nsGraphicsState* next = gs->mNext;
delete gs;
gs = next;
}
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState *
nsGraphicsStatePool::PrivateGetNewGS()
{
nsGraphicsState* gs = mFreeList;
if (gs != nsnull) {
mFreeList = gs->mNext;
return gs;
}
return new nsGraphicsState;
}
//////////////////////////////////////////////////////////////////////////
void
nsGraphicsStatePool::PrivateReleaseGS(nsGraphicsState* aGS)
{
// aGS->Clear();
aGS->mNext = mFreeList;
mFreeList = aGS;
}
//////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -1,90 +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 nsGraphicsStateGTK_h___
#define nsGraphicsStateGTK_h___
#include "nsIRenderingContext.h"
#include "nsIFontMetrics.h"
#include "nsTransform2D.h"
#include "nsRegionGTK.h"
#include "nsCOMPtr.h"
class nsGraphicsState
{
public:
nsTransform2D *mMatrix;
nsCOMPtr<nsIRegion> mClipRegion;
nscolor mColor;
nsLineStyle mLineStyle;
nsIFontMetrics *mFontMetrics;
nsGraphicsState *mNext; // link into free list of graphics states.
friend class nsGraphicsStatePool;
#ifndef USE_GS_POOL
friend class nsRenderingContextGTK;
#endif
private:
nsGraphicsState();
~nsGraphicsState();
};
class nsGraphicsStatePool
{
public:
static nsGraphicsState * GetNewGS();
static void ReleaseGS(nsGraphicsState* aGS);
nsGraphicsStatePool();
~nsGraphicsStatePool();
private:
nsGraphicsState* mFreeList;
static nsGraphicsStatePool * PrivateGetPool();
nsGraphicsState * PrivateGetNewGS();
void PrivateReleaseGS(nsGraphicsState* aGS);
static nsGraphicsStatePool * gsThePool;
};
#endif /* nsGraphicsStateGTK_h___ */

Просмотреть файл

@ -1,150 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* ***** 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
* Christopher Blizzard <blizzard@mozilla.org>.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
#ifndef __nsIFontMetricsGTK_h
#define __nsIFontMetricsGTK_h
#include "nsIFontMetrics.h"
#include "nsIRenderingContext.h"
#include "nsDrawingSurfaceGTK.h"
class nsRenderingContextGTK;
class nsIFontMetricsGTK : public nsIFontMetrics {
public:
// Get the width for this string. aWidth will be updated with the
// width in points, not twips. Callers must convert it if they
// want it in another format.
virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth,
nsRenderingContextGTK *aContext) = 0;
// aCachedOffset will be updated with a new offset.
virtual nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID,
nsRenderingContextGTK *aContext) = 0;
// Get the text dimensions for this string
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext) = 0;
virtual nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext)=0;
virtual nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID,
nsRenderingContextGTK *aContext)=0;
// Draw a string using this font handle on the surface passed in.
virtual nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface) = 0;
// aCachedOffset will be updated with a new offset.
virtual nsresult DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing,
nsRenderingContextGTK *aContext,
nsDrawingSurfaceGTK *aSurface) = 0;
#ifdef MOZ_MATHML
// These two functions get the bounding metrics for this handle,
// updating the aBoundingMetrics in Points. This means that the
// caller will have to update them to twips before passing it
// back.
virtual nsresult GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
nsRenderingContextGTK *aContext) = 0;
// aCachedOffset will be updated with a new offset.
virtual nsresult GetBoundingMetrics(const PRUnichar *aString,
PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics,
PRInt32 *aFontID,
nsRenderingContextGTK *aContext) = 0;
#endif /* MOZ_MATHML */
// Get a GdkFont for this handle, if there is one. This can
// return 0, which means there is no GdkFont associated with this
// particular handle.
virtual GdkFont* GetCurrentGDKFont(void) = 0;
// Set the direction of the text rendering
virtual nsresult SetRightToLeftText(PRBool aIsRTL) = 0;
virtual PRBool GetRightToLeftText() = 0;
virtual nsresult GetClusterInfo(const PRUnichar *aText,
PRUint32 aLength,
PRUint8 *aClusterStarts) = 0;
virtual PRInt32 GetPosition(const PRUnichar *aText,
PRUint32 aLength,
nsPoint aPt) = 0;
virtual nsresult GetRangeWidth(const PRUnichar *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth) = 0;
virtual nsresult GetRangeWidth(const char *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth) = 0;
virtual PRInt32 GetMaxStringLength() = 0;
};
#endif /* __nsIFontMetricsGTK_h */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,229 +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 nsImageGTK_h___
#define nsImageGTK_h___
#include "nsIImage.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <gdk/gdk.h>
#include "nsRegion.h"
#ifdef MOZ_WIDGET_GTK2
#include "nsIGdkPixbufImage.h"
#endif
class nsDrawingSurfaceGTK;
class nsImageGTK :
#ifdef MOZ_WIDGET_GTK2
public nsIGdkPixbufImage
#else
public nsIImage
#endif
{
public:
nsImageGTK();
virtual ~nsImageGTK();
static void Startup();
static void Shutdown();
NS_DECL_ISUPPORTS
/**
@see nsIImage.h
*/
virtual PRInt32 GetBytesPix() { return mNumBytesPixel; }
virtual PRInt32 GetHeight();
virtual PRInt32 GetWidth();
virtual PRUint8* GetBits();
virtual void* GetBitInfo();
virtual PRBool GetIsRowOrderTopToBottom() { return PR_TRUE; }
virtual PRInt32 GetLineStride();
virtual nsColorMap* GetColorMap();
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 DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
nscoord aDWidth, nscoord aDHeight);
NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
nsIDrawingSurface* aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset,
PRInt32 aPadX, PRInt32 aPadY,
const nsRect &aTileRect);
void UpdateCachedImage();
virtual void ImageUpdated(nsIDeviceContext *aContext,
PRUint8 aFlags, nsRect *aUpdateRect);
virtual PRBool GetIsImageComplete();
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight,
PRInt32 aDepth,
nsMaskRequirements aMaskRequirements);
virtual nsresult Optimize(nsIDeviceContext* aContext);
virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull || mAlphaPixmap != nsnull; }
virtual PRUint8* GetAlphaBits();
virtual PRInt32 GetAlphaLineStride();
/**
* 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() {
if (mTrueAlphaBits)
return mTrueAlphaDepth;
else
return mAlphaDepth;
}
NS_IMETHOD LockImagePixels(PRBool aMaskPixels);
NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels);
#ifdef MOZ_WIDGET_GTK2
NS_IMETHOD_(GdkPixbuf*) GetGdkPixbuf();
#endif
private:
/**
* Calculate the amount of memory needed for the initialization of the image
*/
void ComputeMetrics() {
mRowBytes = (mWidth * mDepth) >> 5;
if (((PRUint32)mWidth * mDepth) & 0x1F)
mRowBytes++;
mRowBytes <<= 2;
mSizeImage = mRowBytes * mHeight;
};
void ComputePaletteSize(PRIntn nBitCount);
private:
static unsigned scaled6[1<<6];
static unsigned scaled5[1<<5];
void DrawComposited32(PRBool isLSB, PRBool flipBytes,
PRUint8 *imageOrigin, PRUint32 imageStride,
PRUint8 *alphaOrigin, PRUint32 alphaStride,
unsigned width, unsigned height,
XImage *ximage, unsigned char *readData, unsigned char *srcData);
void DrawComposited24(PRBool isLSB, PRBool flipBytes,
PRUint8 *imageOrigin, PRUint32 imageStride,
PRUint8 *alphaOrigin, PRUint32 alphaStride,
unsigned width, unsigned height,
XImage *ximage, unsigned char *readData, unsigned char *srcData);
void DrawComposited16(PRBool isLSB, PRBool flipBytes,
PRUint8 *imageOrigin, PRUint32 imageStride,
PRUint8 *alphaOrigin, PRUint32 alphaStride,
unsigned width, unsigned height,
XImage *ximage, unsigned char *readData, unsigned char *srcData);
void DrawCompositedGeneral(PRBool isLSB, PRBool flipBytes,
PRUint8 *imageOrigin, PRUint32 imageStride,
PRUint8 *alphaOrigin, PRUint32 alphaStride,
unsigned width, unsigned height,
XImage *ximage, unsigned char *readData, unsigned char *srcData);
inline void DrawComposited(nsIRenderingContext &aContext,
nsIDrawingSurface* aSurface,
PRInt32 srcWidth, PRInt32 srcHeight,
PRInt32 dstWidth, PRInt32 dstHeight,
PRInt32 dstOrigX, PRInt32 dstOrigY,
PRInt32 aDX, PRInt32 aDY,
PRInt32 aDWidth, PRInt32 aDHeight);
inline void DrawCompositeTile(nsIRenderingContext &aContext,
nsIDrawingSurface* aSurface,
PRInt32 aSX, PRInt32 aSY,
PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY,
PRInt32 aDWidth, PRInt32 aDHeight);
inline void TilePixmap(GdkPixmap *src, GdkPixmap *dest, PRInt32 aSXOffset, PRInt32 aSYOffset,
const nsRect &destRect, const nsRect &clipRect, PRBool useClip);
inline void CreateOffscreenPixmap(PRInt32 aWidth, PRInt32 aHeight);
inline void SetupGCForAlpha(GdkGC *aGC, PRInt32 aX, PRInt32 aY);
void SlowTile(nsDrawingSurfaceGTK *aSurface, const nsRect &aTileRect,
PRInt32 aSXOffset, PRInt32 aSYOffset, const nsRect& aRect, PRBool aIsValid);
PRUint8 *mImageBits;
GdkPixmap *mImagePixmap;
PRUint8 *mTrueAlphaBits;
PRUint8 *mAlphaBits;
GdkPixmap *mAlphaPixmap;
XImage *mAlphaXImage;
PRInt32 mWidth;
PRInt32 mHeight;
PRInt32 mRowBytes;
PRInt32 mSizeImage;
PRInt32 mDecodedX1; // Keeps track of what part of image
PRInt32 mDecodedY1; // has been decoded.
PRInt32 mDecodedX2;
PRInt32 mDecodedY2;
nsRegion mUpdateRegion;
// alpha layer members
PRInt32 mAlphaRowBytes; // alpha bytes per row
PRInt32 mTrueAlphaRowBytes; // alpha bytes per row
PRInt8 mAlphaDepth; // alpha layer depth
PRInt8 mTrueAlphaDepth; // alpha layer depth
PRPackedBool mIsSpacer;
PRPackedBool mPendingUpdate;
PRInt8 mNumBytesPixel;
PRUint8 mFlags; // flags set by ImageUpdated
PRInt8 mDepth; // bits per pixel
PRPackedBool mOptimized;
};
#endif

Просмотреть файл

@ -1,417 +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
* Stuart Parmenter.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@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 <gtk/gtk.h>
#include <gdk/gdkprivate.h>
#include "nsRegionGTK.h"
#include "xregion.h"
#include "prmem.h"
#ifdef DEBUG_REGIONS
static int nRegions;
#endif
GdkRegion *nsRegionGTK::copyRegion = nsnull;
nsRegionGTK::nsRegionGTK()
{
#ifdef DEBUG_REGIONS
++nRegions;
printf("REGIONS+ = %i\n", nRegions);
#endif
mRegion = nsnull;
}
nsRegionGTK::~nsRegionGTK()
{
#ifdef DEBUG_REGIONS
--nRegions;
printf("REGIONS- = %i\n", nRegions);
#endif
if (mRegion)
::gdk_region_destroy(mRegion);
mRegion = nsnull;
}
NS_IMPL_ISUPPORTS1(nsRegionGTK, nsIRegion)
/* static */ void
nsRegionGTK::Shutdown()
{
if (copyRegion) {
gdk_region_destroy(copyRegion);
copyRegion = nsnull;
}
}
GdkRegion *
nsRegionGTK::GetCopyRegion() {
if (!copyRegion) copyRegion = gdk_region_new();
return copyRegion;
}
GdkRegion *
nsRegionGTK::gdk_region_copy(GdkRegion *region)
{
return gdk_regions_union(region, GetCopyRegion());
}
GdkRegion *
nsRegionGTK::gdk_region_from_rect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
GdkRectangle grect;
grect.x = aX;
grect.y = aY;
grect.width = aWidth;
grect.height = aHeight;
return ::gdk_region_union_with_rect(GetCopyRegion(), &grect);
}
nsresult nsRegionGTK::Init(void)
{
if (mRegion) {
gdk_region_destroy(mRegion);
mRegion = nsnull;
}
return NS_OK;
}
void nsRegionGTK::SetTo(const nsIRegion &aRegion)
{
Init();
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
mRegion = gdk_region_copy(pRegion->mRegion);
}
void nsRegionGTK::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
Init();
mRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
}
void nsRegionGTK::Intersect(const nsIRegion &aRegion)
{
if(!mRegion) {
NS_WARNING("mRegion is NULL");
return;
}
nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;
GdkRegion *nRegion = ::gdk_regions_intersect(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
}
void nsRegionGTK::Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
if(!mRegion) {
NS_WARNING("mRegion is NULL");
return;
}
GdkRegion *tRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
GdkRegion *nRegion = ::gdk_regions_intersect(mRegion, tRegion);
::gdk_region_destroy(tRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
}
void nsRegionGTK::Union(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (pRegion->mRegion && !::gdk_region_empty(pRegion->mRegion)) {
if (mRegion) {
if (::gdk_region_empty(mRegion)) {
::gdk_region_destroy(mRegion);
mRegion = gdk_region_copy(pRegion->mRegion);
} else {
GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
}
} else
mRegion = gdk_region_copy(pRegion->mRegion);
}
}
void nsRegionGTK::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
if (mRegion) {
GdkRectangle grect;
grect.x = aX;
grect.y = aY;
grect.width = aWidth;
grect.height = aHeight;
if (grect.width > 0 && grect.height > 0) {
if (::gdk_region_empty(mRegion)) {
::gdk_region_destroy(mRegion);
mRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
} else {
GdkRegion *nRegion = ::gdk_region_union_with_rect(mRegion, &grect);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
}
}
} else {
mRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
}
}
void nsRegionGTK::Subtract(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (pRegion->mRegion) {
if (mRegion) {
GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
} else {
mRegion = ::gdk_regions_subtract(GetCopyRegion(), pRegion->mRegion);
}
}
}
void nsRegionGTK::Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
if (mRegion) {
GdkRegion *tRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, tRegion);
::gdk_region_destroy(mRegion);
::gdk_region_destroy(tRegion);
mRegion = nRegion;
} else {
GdkRegion *tRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
mRegion = ::gdk_regions_subtract(GetCopyRegion(), tRegion);
::gdk_region_destroy(tRegion);
}
}
PRBool nsRegionGTK::IsEmpty(void)
{
if (!mRegion)
return PR_TRUE;
return (::gdk_region_empty(mRegion));
}
PRBool nsRegionGTK::IsEqual(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (mRegion && pRegion->mRegion) {
return(::gdk_region_equal(mRegion, pRegion->mRegion));
} else if (!mRegion && !pRegion->mRegion) {
return PR_TRUE;
} else if ((mRegion && !pRegion->mRegion) || (!mRegion && pRegion->mRegion)) {
return PR_FALSE;
}
return PR_FALSE;
}
void nsRegionGTK::GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
{
if (mRegion) {
GdkRectangle rect;
::gdk_region_get_clipbox(mRegion, &rect);
*aX = rect.x;
*aY = rect.y;
*aWidth = rect.width;
*aHeight = rect.height;
} else {
*aX = 0;
*aY = 0;
*aWidth = 0;
*aHeight = 0;
}
}
void nsRegionGTK::Offset(PRInt32 aXOffset, PRInt32 aYOffset)
{
if (mRegion) {
::gdk_region_offset(mRegion, aXOffset, aYOffset);
}
}
PRBool nsRegionGTK::ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
if (mRegion) {
GdkOverlapType containment;
GdkRectangle rect;
rect.x = aX;
rect.y = aY;
rect.width = aWidth;
rect.height = aHeight;
containment = ::gdk_region_rect_in(mRegion, &rect);
if (containment != GDK_OVERLAP_RECTANGLE_OUT)
return PR_TRUE;
}
return PR_FALSE;
}
NS_IMETHODIMP nsRegionGTK::GetRects(nsRegionRectSet **aRects)
{
*aRects = nsnull;
if (!mRegion)
return NS_OK;
nsRegionRectSet *rects = nsnull;
GdkRegionPrivate *priv = nsnull;
Region pRegion;
int nbox = 0;
BOX *pbox = nsnull;
nsRegionRect *rect = nsnull;
priv = (GdkRegionPrivate *)mRegion;
pRegion = priv->xregion;
pbox = pRegion->rects;
nbox = pRegion->numRects;
NS_ASSERTION(!(nsnull == aRects), "bad ptr");
//code lifted from old xfe. MMP
rects = *aRects;
if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox))
{
void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));
if (nsnull == buf)
{
if (nsnull != rects)
rects->mNumRects = 0;
return NS_OK;
}
rects = (nsRegionRectSet *)buf;
rects->mRectsLen = nbox;
}
rects->mNumRects = nbox;
rects->mArea = 0;
rect = &rects->mRects[0];
while (nbox--)
{
rect->x = pbox->x1;
rect->width = (pbox->x2 - pbox->x1);
rect->y = pbox->y1;
rect->height = (pbox->y2 - pbox->y1);
rects->mArea += rect->width * rect->height;
pbox++;
rect++;
}
*aRects = rects;
return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::FreeRects(nsRegionRectSet *aRects)
{
if (nsnull != aRects)
PR_Free((void *)aRects);
return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::GetNativeRegion(void *&aRegion) const
{
aRegion = (void *)mRegion;
return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::GetRegionComplexity(nsRegionComplexity &aComplexity) const
{
// cast to avoid const-ness problems on some compilers
if (((nsRegionGTK*)this)->IsEmpty())
aComplexity = eRegionComplexity_empty;
else
aComplexity = eRegionComplexity_complex;
return NS_OK;
}
void nsRegionGTK::SetRegionEmpty()
{
if (!IsEmpty()) {
::gdk_region_destroy(mRegion);
}
}
NS_IMETHODIMP nsRegionGTK::GetNumRects(PRUint32 *aRects) const
{
if (!mRegion)
*aRects = 0;
GdkRegionPrivate *priv = (GdkRegionPrivate *)mRegion;
Region pRegion = priv->xregion;
*aRects = pRegion->numRects;
return NS_OK;
}

Просмотреть файл

@ -1,81 +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
* Stuart Parmenter.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@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 nsRegionGTK_h___
#define nsRegionGTK_h___
#include "nsIRegion.h"
#include <gdk/gdk.h>
class nsRegionGTK : public nsIRegion
{
public:
nsRegionGTK();
virtual ~nsRegionGTK();
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;
NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const;
NS_IMETHOD GetNumRects(PRUint32 *aRects) const;
private:
GdkRegion *mRegion;
};
#endif // nsRegionGTK_h___

Просмотреть файл

@ -1,381 +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
* Stuart Parmenter.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@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 <gdk/gdkregion.h>
#include "nsRegionGTK.h"
#include "nsMemory.h"
#ifdef DEBUG_REGIONS
static int nRegions;
#endif
nsRegionGTK::nsRegionGTK()
{
#ifdef DEBUG_REGIONS
++nRegions;
printf("REGIONS+ = %i\n", nRegions);
#endif
mRegion = nsnull;
}
nsRegionGTK::~nsRegionGTK()
{
#ifdef DEBUG_REGIONS
--nRegions;
printf("REGIONS- = %i\n", nRegions);
#endif
if (mRegion)
gdk_region_destroy(mRegion);
mRegion = nsnull;
}
NS_IMPL_ISUPPORTS1(nsRegionGTK, nsIRegion)
nsresult nsRegionGTK::Init(void)
{
if (mRegion) {
gdk_region_destroy(mRegion);
mRegion = nsnull;
}
return NS_OK;
}
void nsRegionGTK::SetTo(const nsIRegion &aRegion)
{
Init();
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
mRegion = gdk_region_copy(pRegion->mRegion);
}
void nsRegionGTK::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
Init();
GdkRectangle rect;
rect.x = aX;
rect.y = aY;
rect.width = aWidth;
rect.height = aHeight;
mRegion = gdk_region_rectangle(&rect);
}
void nsRegionGTK::Intersect(const nsIRegion &aRegion)
{
if(!mRegion) {
NS_WARNING("mRegion is NULL");
return;
}
nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;
gdk_region_intersect(mRegion, pRegion->mRegion);
}
void nsRegionGTK::Intersect(PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight)
{
if(!mRegion) {
NS_WARNING("mRegion is NULL");
return;
}
GdkRectangle rect;
rect.x = aX;
rect.y = aY;
rect.width = aWidth;
rect.height = aHeight;
GdkRegion *tRegion = gdk_region_rectangle(&rect);
gdk_region_intersect(mRegion, tRegion);
gdk_region_destroy(tRegion);
}
void nsRegionGTK::Union(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (pRegion->mRegion && !gdk_region_empty(pRegion->mRegion)) {
if (mRegion) {
if (gdk_region_empty(mRegion)) {
gdk_region_destroy(mRegion);
mRegion = gdk_region_copy(pRegion->mRegion);
} else {
gdk_region_union(mRegion, pRegion->mRegion);
}
} else
mRegion = gdk_region_copy(pRegion->mRegion);
}
}
void nsRegionGTK::Union(PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight)
{
GdkRectangle grect;
grect.x = aX;
grect.y = aY;
grect.width = aWidth;
grect.height = aHeight;
if (mRegion) {
if (grect.width > 0 && grect.height > 0) {
if (gdk_region_empty(mRegion)) {
gdk_region_destroy(mRegion);
mRegion = gdk_region_rectangle(&grect);
} else {
gdk_region_union_with_rect(mRegion, &grect);
}
}
} else {
mRegion = gdk_region_rectangle(&grect);
}
}
void nsRegionGTK::Subtract(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (pRegion->mRegion) {
if (mRegion) {
gdk_region_subtract(mRegion, pRegion->mRegion);
} else {
mRegion = gdk_region_new();
gdk_region_subtract(mRegion, pRegion->mRegion);
}
}
}
void nsRegionGTK::Subtract(PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight)
{
GdkRectangle rect;
rect.x = aX;
rect.y = aY;
rect.width = aWidth;
rect.height = aHeight;
GdkRegion *tRegion = gdk_region_rectangle(&rect);
if (mRegion) {
gdk_region_subtract(mRegion, tRegion);
} else {
NS_WARNING("subtracting from a non-region?");
mRegion = gdk_region_new();
gdk_region_subtract(mRegion, tRegion);
}
gdk_region_destroy(tRegion);
}
PRBool nsRegionGTK::IsEmpty(void)
{
if (!mRegion)
return PR_TRUE;
return (gdk_region_empty(mRegion));
}
PRBool nsRegionGTK::IsEqual(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (mRegion && pRegion->mRegion) {
return(gdk_region_equal(mRegion, pRegion->mRegion));
} else if (!mRegion && !pRegion->mRegion) {
return PR_TRUE;
} else if ((mRegion && !pRegion->mRegion) || (!mRegion && pRegion->mRegion)) {
return PR_FALSE;
}
return PR_FALSE;
}
void nsRegionGTK::GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
{
if (mRegion) {
GdkRectangle rect;
gdk_region_get_clipbox(mRegion, &rect);
*aX = rect.x;
*aY = rect.y;
*aWidth = rect.width;
*aHeight = rect.height;
} else {
*aX = 0;
*aY = 0;
*aWidth = 0;
*aHeight = 0;
}
}
void nsRegionGTK::Offset(PRInt32 aXOffset, PRInt32 aYOffset)
{
if (mRegion) {
gdk_region_offset(mRegion, aXOffset, aYOffset);
}
}
PRBool nsRegionGTK::ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
if (mRegion) {
GdkOverlapType containment;
GdkRectangle rect;
rect.x = aX;
rect.y = aY;
rect.width = aWidth;
rect.height = aHeight;
containment = gdk_region_rect_in(mRegion, &rect);
if (containment != GDK_OVERLAP_RECTANGLE_OUT)
return PR_TRUE;
}
return PR_FALSE;
}
NS_IMETHODIMP nsRegionGTK::GetRects(nsRegionRectSet **aRects)
{
nsRegionRectSet *retval;
nsRegionRect *regionrect;
*aRects = nsnull;
if (!mRegion)
return NS_OK;
GdkRectangle *rects = nsnull;
gint nrects = 0;
gdk_region_get_rectangles(mRegion, &rects, &nrects);
// There are no rectangles in this region but we still need to
// return an empty structure.
if (!nrects) {
retval = (nsRegionRectSet *)nsMemory::Alloc(sizeof(nsRegionRectSet));
if (!retval)
return NS_ERROR_OUT_OF_MEMORY;
retval->mNumRects = 0;
retval->mRectsLen = 0;
retval->mArea = 0;
*aRects = retval;
return NS_OK;
}
// allocate space for our return values
retval = (nsRegionRectSet *)
nsMemory::Alloc(sizeof(nsRegionRectSet) +
(sizeof(nsRegionRect) * (nrects - 1)));
if (!retval)
return NS_ERROR_OUT_OF_MEMORY;
regionrect = &retval->mRects[0];
retval->mNumRects = nrects;
retval->mRectsLen = nrects;
int currect = 0;
while (currect < nrects) {
regionrect->x = rects[currect].x;
regionrect->y = rects[currect].y;
regionrect->width = rects[currect].width;
regionrect->height = rects[currect].height;
retval->mArea += rects[currect].width * rects[currect].height;
currect++;
regionrect++;
}
// they are allocated as one lump
g_free(rects);
*aRects = retval;
return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::FreeRects(nsRegionRectSet *aRects)
{
if (nsnull != aRects)
nsMemory::Free(aRects);
return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::GetNativeRegion(void *&aRegion) const
{
aRegion = (void *)mRegion;
return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::GetRegionComplexity(nsRegionComplexity &aComplexity) const
{
// cast to avoid const-ness problems on some compilers
if (((nsRegionGTK*)this)->IsEmpty())
aComplexity = eRegionComplexity_empty;
else
aComplexity = eRegionComplexity_complex;
return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::GetNumRects(PRUint32 *aRects) const
{
if (!mRegion)
*aRects = 0;
GdkRectangle *rects = nsnull;
gint nrects = 0;
gdk_region_get_rectangles(mRegion, &rects, &nrects);
// freed as one lump
g_free(rects);
*aRects = nrects;
return NS_OK;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,308 +0,0 @@
/* -*- Mode: C++; tab-width: 1; 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 nsRenderingContextGTK_h___
#define nsRenderingContextGTK_h___
#include "nsRenderingContextImpl.h"
#include "nsUnitConversion.h"
#include "nsFont.h"
#include "nsPoint.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsTransform2D.h"
#include "nsIWidget.h"
#include "nsRect.h"
#include "nsIDeviceContext.h"
#include "nsVoidArray.h"
#include "nsGfxCIID.h"
#include "nsDrawingSurfaceGTK.h"
#include "nsRegionGTK.h"
#include "nsIFontMetricsGTK.h"
#include <gtk/gtk.h>
class nsRenderingContextGTK : public nsRenderingContextImpl
{
public:
nsRenderingContextGTK();
virtual ~nsRenderingContextGTK();
static nsresult Shutdown(); // release statics
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);
virtual void* GetNativeGraphicData(GraphicDataType aType);
#if 0
NS_IMETHOD PushState(PRInt32 aFlags);
#endif
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 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);
NS_IMETHOD GetTextDimensionsInternal(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID);
NS_IMETHOD GetTextDimensionsInternal(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
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);
NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
NS_IMETHOD GetRightToLeftText(PRBool* aIsRTL);
NS_IMETHOD GetClusterInfo(const PRUnichar *aText, PRUint32 aLength,
PRUint8 *aClusterStarts);
virtual PRInt32 GetPosition(const PRUnichar *aText, PRUint32 aLength,
nsPoint aPt);
NS_IMETHOD GetRangeWidth(const PRUnichar *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
NS_IMETHOD GetRangeWidth(const char *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect);
//locals
NS_IMETHOD CommonInit();
void CreateClipRegion();
GdkGC *GetGC() {
if (!mGC)
UpdateGC();
return gdk_gc_ref(mGC);
}
void SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine);
// cause the GC to be updated
void UpdateGC();
// Get a pointer to the trans matrix
nsTransform2D *GetTranMatrix() {
return mTranMatrix;
}
private:
nsDrawingSurfaceGTK *mOffscreenSurface;
nsDrawingSurfaceGTK *mSurface;
nsIDeviceContext *mContext;
nsIFontMetricsGTK *mFontMetrics;
nsCOMPtr<nsIRegion> mClipRegion;
float mP2T;
GdkWChar* mDrawStringBuf;
PRUint32 mDrawStringSize;
// graphic state stack (GraphicsState)
nsAutoVoidArray mStateCache;
GdkGC *mGC;
GdkFunction mFunction;
GdkLineStyle mLineStyle;
char mDashList[2];
int mDashes;
nscolor mCurrentColor;
nsLineStyle mCurrentLineStyle;
// ConditionRect is used to fix coordinate overflow problems for
// rectangles after they are transformed to screen coordinates
void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h) {
if ( y < -32766 ) {
y = -32766;
}
if ( y + h > 32766 ) {
h = 32766 - y;
}
if ( x < -32766 ) {
x = -32766;
}
if ( x + w > 32766 ) {
w = 32766 - x;
}
}
};
#endif /* nsRenderingContextGTK_h___ */

Просмотреть файл

@ -1,120 +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>
# Jungshik Shin <jshin@mailaps.org>
# Christopher Blizzard <blizzard@mozilla.org>
#
# 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 file contains supported custom encodings for pango font
# rendering. For information about the specific encodings, look at
# fontEncoding.properties. It contains a lot more verbiage than you
# will find here. There are a lot of encodings supported in the old
# encoding file that pango supports directly, so there should be
# little reason to use those custom encodings. The pango custom code
# doesn't support .wide fonts, so consider yourself warned!
#
# To be honest, we basically support mathml and that's about it.
encoding.cmr10.ttf = x-ttf-cmr
encoding.cmmi10.ttf = x-ttf-cmmi
encoding.cmsy10.ttf = x-ttf-cmsy
encoding.cmex10.ttf = x-ttf-cmex
encoding.cmr10.ftcmap = unicode
encoding.cmmi10.ftcmap = unicode
encoding.cmsy10.ftcmap = unicode
encoding.cmex10.ftcmap = unicode
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
encoding.math1.ftcmap = mac_roman
encoding.math1-bold.ftcmap = mac_roman
encoding.math1mono.ftcmap = mac_roman
encoding.math1mono-bold.ftcmap = mac_roman
encoding.math2.ftcmap = mac_roman
encoding.math2-bold.ftcmap = mac_roman
encoding.math2mono.ftcmap = mac_roman
encoding.math2mono-bold.ftcmap = mac_roman
encoding.math3.ftcmap = mac_roman
encoding.math3-bold.ftcmap = mac_roman
encoding.math3mono.ftcmap = mac_roman
encoding.math3mono-bold.ftcmap = mac_roman
encoding.math4.ftcmap = mac_roman
encoding.math4-bold.ftcmap = mac_roman
encoding.math4mono.ftcmap = mac_roman
encoding.math4mono-bold.ftcmap = mac_roman
encoding.math5.ftcmap = mac_roman
encoding.math5-bold.ftcmap = mac_roman
encoding.math5bold.ftcmap = mac_roman
encoding.math5mono.ftcmap = mac_roman
encoding.math5mono-bold.ftcmap = mac_roman
encoding.math5monobold.ftcmap = mac_roman
encoding.mtextra.ttf = x-mtextra
encoding.mtextra.ftcmap = mac_roman

Просмотреть файл

@ -1,177 +0,0 @@
/* $XConsortium: region.h,v 11.13 91/09/10 08:21:49 rws Exp $ */
/************************************************************************
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
************************************************************************/
#ifndef _XREGION_H
#define _XREGION_H
typedef struct {
short x1, x2, y1, y2;
} Box, BOX, BoxRec, *BoxPtr;
typedef struct {
short x, y, width, height;
}RECTANGLE, RectangleRec, *RectanglePtr;
#ifdef TRUE
#undef TRUE
#endif
#define TRUE 1
#ifndef FALSE
#define FALSE 0
#endif
#ifndef MAXSHORT
#define MAXSHORT 32767
#endif
#ifndef MINSHORT
#define MINSHORT -MAXSHORT
#endif
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
/*
* clip region
*/
typedef struct _XRegion {
long size;
long numRects;
BOX *rects;
BOX extents;
} REGION;
/* Xutil.h contains the declaration:
* typedef struct _XRegion *Region;
*/
/* 1 if two BOXs overlap.
* 0 if two BOXs do not overlap.
* Remember, x2 and y2 are not in the region
*/
#define EXTENTCHECK(r1, r2) \
((r1)->x2 > (r2)->x1 && \
(r1)->x1 < (r2)->x2 && \
(r1)->y2 > (r2)->y1 && \
(r1)->y1 < (r2)->y2)
/*
* update region extents
*/
#define EXTENTS(r,idRect){\
if((r)->x1 < (idRect)->extents.x1)\
(idRect)->extents.x1 = (r)->x1;\
if((r)->y1 < (idRect)->extents.y1)\
(idRect)->extents.y1 = (r)->y1;\
if((r)->x2 > (idRect)->extents.x2)\
(idRect)->extents.x2 = (r)->x2;\
if((r)->y2 > (idRect)->extents.y2)\
(idRect)->extents.y2 = (r)->y2;\
}
/*
* Check to see if there is enough memory in the present region.
*/
#define MEMCHECK(reg, rect, firstrect){\
if ((reg)->numRects >= ((reg)->size - 1)){\
(firstrect) = (BOX *) Xrealloc \
((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
if ((firstrect) == 0)\
return(0);\
(reg)->size *= 2;\
(rect) = &(firstrect)[(reg)->numRects];\
}\
}
/* this routine checks to see if the previous rectangle is the same
* or subsumes the new rectangle to add.
*/
#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
(!(((Reg)->numRects > 0)&&\
((R-1)->y1 == (Ry1)) &&\
((R-1)->y2 == (Ry2)) &&\
((R-1)->x1 <= (Rx1)) &&\
((R-1)->x2 >= (Rx2))))
/* add a rectangle to the given Region */
#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
(r)->x1 = (rx1);\
(r)->y1 = (ry1);\
(r)->x2 = (rx2);\
(r)->y2 = (ry2);\
EXTENTS((r), (reg));\
(reg)->numRects++;\
(r)++;\
}\
}
/* add a rectangle to the given Region */
#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
if ((rx1 < rx2) && (ry1 < ry2) &&\
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
(r)->x1 = (rx1);\
(r)->y1 = (ry1);\
(r)->x2 = (rx2);\
(r)->y2 = (ry2);\
(reg)->numRects++;\
(r)++;\
}\
}
#define EMPTY_REGION(pReg) pReg->numRects = 0
#define REGION_NOT_EMPTY(pReg) pReg->numRects
#define INBOX(r, x, y) \
( ( ((r).x2 > x)) && \
( ((r).x1 <= x)) && \
( ((r).y2 > y)) && \
( ((r).y1 <= y)) )
/*
* number of points to buffer before sending them off
* to scanlines() : Must be an even number
*/
#define NUMPTSTOBUFFER 200
/*
* used to allocate buffers for points and link
* the buffers together
*/
typedef struct _POINTBLOCK {
XPoint pts[NUMPTSTOBUFFER];
struct _POINTBLOCK *next;
} POINTBLOCK;
#endif

Просмотреть файл

@ -1,6 +0,0 @@
This dir, x11shared, is for code common to multiple X11
implementations (eg: gtk, xlib, xprint).
Code that is being (or would be) *replicated* in several
of these should be factored out and put here.

Просмотреть файл

@ -1,178 +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
* Jungshik Shin <jshin@mailaps.org>
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
/*========================================================
This file contains a precompiled CCMap for a class of Unicode
characters (dbyte_special_chars) to be identified quickly by Mozilla.
It was generated by ccmapbin.pl which you can find under
mozilla/intl/unicharutil/tools.
Enumerated below are characters included in the precompiled CCMap
which is human-readable but not so human-friendly. If you
needs to modify the list of characters belonging to "dbyte_special_chars",
you have to make a new file (with the name of your choice)
listing characters (one character per line) you want to put
into "dbyte_special_chars" in the format
0xuuuu // comment
In addition, the input file can have the following optional lines that
read
VARIABLE::gDoubleByteSpecialCharsCCMap
CLASS::dbyte_special_chars
DESCRIPTION:: description of a character class
FILE:: mozilla source file to include the output file
Then, run the following in the current directory.
perl ccmapbin.pl input_file [gDoubleByteSpecialCharsCCMap [dbyte_special_chars]]
which will generate dbyte_special_chars.ccmap (or dbyte_special_chars.x-ccmap if the ccmap
includes non-BMP characters.). gDoubleByteSpecialCharsCCMap is used as the prefix
in macros for the array initializer and the array size.
(see bug 180266, bug 167136, and bug 224337)
*/
/*
VARIABLE:: gDoubleByteSpecialCharsCCMap
CLASS:: dbyte_special_chars
DESCRIPTION:: description of a character class
FILE:: mozilla source file to include output files
0X000152 : LATIN CAPITAL LIGATURE OE
0X000153 : LATIN SMALL LIGATURE OE
0X000160 : LATIN CAPITAL LETTER S WITH CARON
0X000161 : LATIN SMALL LETTER S WITH CARON
0X000178 : LATIN CAPITAL LETTER Y WITH DIAERESIS
0X00017D : LATIN CAPITAL LETTER Z WITH CARON
0X00017E : LATIN SMALL LETTER Z WITH CARON
0X000192 : LATIN SMALL LETTER F WITH HOOK
0X0002C6 : MODIFIER LETTER CIRCUMFLEX ACCENT
0X0002DC : SMALL TILDE
0X002013 : EN DASH
0X002018 : LEFT SINGLE QUOTATION MARK
0X002019 : RIGHT SINGLE QUOTATION MARK
0X00201A : SINGLE LOW-9 QUOTATION MARK
0X00201C : LEFT DOUBLE QUOTATION MARK
0X00201D : RIGHT DOUBLE QUOTATION MARK
0X00201E : DOUBLE LOW-9 QUOTATION MARK
0X002020 : DAGGER
0X002021 : DOUBLE DAGGER
0X002022 : BULLET
0X002026 : HORIZONTAL ELLIPSIS
0X002030 : PER MILLE SIGN
0X002039 : SINGLE LEFT-POINTING ANGLE QUOTATION MARK
0X00203A : SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
0X0020AC : EURO SIGN
0X002122 : TRADE MARK SIGN
*/
#if (defined(IS_LITTLE_ENDIAN) || ALU_SIZE == 16)
// Precompiled CCMap for Little Endian(16/32/64bit)
// and Big Endian(16bit)
#define gDoubleByteSpecialCharsCCMap_SIZE 144
#define gDoubleByteSpecialCharsCCMap_INITIALIZER \
/* 000000 */ 0x0030,0x0010,0x0060,0x0010,0x0010,0x0010,0x0010,0x0010, \
0x0010,0x0010,0x0010,0x0010,0x0010,0x0010,0x0010,0x0010, \
/* 000010 */ 0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000020 */ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000030 */ 0x0020,0x0040,0x0050,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000040 */ 0x0000,0x0000,0x0000,0x0000,0x0000,0x000C,0x0003,0x6100, \
0x0000,0x0004,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000050 */ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0040,0x1000,0x0000,0x0000, \
/* 000060 */ 0x0070,0x0080,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000070 */ 0x0000,0x7708,0x0047,0x0601,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x1000,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000080 */ 0x0000,0x0000,0x0004,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
#elif (ALU_SIZE == 32)
// Precompiled CCMap for Big Endian(32bit)
#define gDoubleByteSpecialCharsCCMap_SIZE 144
#define gDoubleByteSpecialCharsCCMap_INITIALIZER \
/* 000000 */ 0x0030,0x0010,0x0060,0x0010,0x0010,0x0010,0x0010,0x0010, \
0x0010,0x0010,0x0010,0x0010,0x0010,0x0010,0x0010,0x0010, \
/* 000010 */ 0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000020 */ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000030 */ 0x0020,0x0040,0x0050,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000040 */ 0x0000,0x0000,0x0000,0x0000,0x000C,0x0000,0x6100,0x0003, \
0x0004,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000050 */ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x1000,0x0040,0x0000,0x0000, \
/* 000060 */ 0x0070,0x0080,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000070 */ 0x7708,0x0000,0x0601,0x0047,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x1000,0x0000,0x0000,0x0000,0x0000, \
/* 000080 */ 0x0000,0x0000,0x0000,0x0004,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
#elif (ALU_SIZE == 64)
// Precompiled CCMap for Big Endian(64bit)
#define gDoubleByteSpecialCharsCCMap_SIZE 144
#define gDoubleByteSpecialCharsCCMap_INITIALIZER \
/* 000000 */ 0x0030,0x0010,0x0060,0x0010,0x0010,0x0010,0x0010,0x0010, \
0x0010,0x0010,0x0010,0x0010,0x0010,0x0010,0x0010,0x0010, \
/* 000010 */ 0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000020 */ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000030 */ 0x0020,0x0040,0x0050,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000040 */ 0x0000,0x0000,0x0000,0x0000,0x6100,0x0003,0x000C,0x0000, \
0x0000,0x0000,0x0004,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000050 */ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1000,0x0040, \
/* 000060 */ 0x0070,0x0080,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020, \
/* 000070 */ 0x0601,0x0047,0x7708,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x1000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
/* 000080 */ 0x0000,0x0004,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, \
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
#else
#error "We don't support this architecture."
#endif

Просмотреть файл

@ -1,235 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@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 "gfx-config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include "nsCRT.h"
#include "nsAntiAliasedGlyph.h"
nsAntiAliasedGlyph::nsAntiAliasedGlyph(PRUint32 aMaxWidth, PRUint32 aMaxHeight,
PRUint32 aBorder)
{
mMaxWidth = aMaxWidth;
mMaxHeight = aMaxHeight;
mBorder = aBorder;
mBufferWidth = mBorder + mMaxWidth + mBorder;
mBufferHeight = mBorder + mMaxHeight + mBorder;
mAscent = 0;
mDescent = 0;
mLBearing = 0;
mRBearing = 0;
mWidth = 0;
mHeight = 0;
mAdvance = 0;
mOwnBuffer = PR_FALSE;
mBuffer = nsnull;
mBufferLen = 0;
}
nsAntiAliasedGlyph::~nsAntiAliasedGlyph()
{
if (mOwnBuffer)
nsMemory::Free(mBuffer);
}
PRBool
nsAntiAliasedGlyph::Init()
{
return Init(nsnull, 0);
}
PRBool
nsAntiAliasedGlyph::Init(PRUint8 *aBuffer, PRUint32 aBufferLen)
{
mBufferLen = mBufferWidth * mBufferHeight;
if (aBufferLen >= mBufferLen) {
mBuffer = aBuffer;
mOwnBuffer = PR_FALSE;
}
else {
mBuffer = (PRUint8 *)nsMemory::Alloc(mBufferLen);
if (!mBuffer) {
mBufferLen = 0;
return PR_FALSE;
}
mOwnBuffer = PR_TRUE;
}
memset(mBuffer, 0, mBufferLen);
return PR_TRUE;
}
#ifdef MOZ_ENABLE_FREETYPE2
PRBool
nsAntiAliasedGlyph::WrapFreeType(FT_BBox *aBbox, FT_BitmapGlyph aSlot,
PRUint8 *aBuffer, PRUint32 aBufferLen)
{
mAscent = aBbox->yMax;
mDescent = aBbox->yMin;
mLBearing = aBbox->xMin;
mRBearing = aBbox->xMax;
mAdvance = aSlot->root.advance.x>>16;
mWidth = aSlot->bitmap.width;
mHeight = aSlot->bitmap.rows;
if (aSlot->bitmap.pixel_mode == ft_pixel_mode_grays) {
mBufferWidth = aSlot->bitmap.pitch;
mBufferHeight = aSlot->bitmap.rows;
mBufferLen = mBufferWidth * mBufferHeight;
mBuffer = aSlot->bitmap.buffer;
mOwnBuffer = PR_FALSE;
return PR_TRUE;
}
else {
// expand the data from 1 bit to 8 bit
mBufferWidth = aSlot->bitmap.width;
mBufferHeight = aSlot->bitmap.rows;
if (!Init(aBuffer, aBufferLen))
return PR_FALSE;
int pitch = aSlot->bitmap.pitch;
for (int row=0; row<aSlot->bitmap.rows; row++) {
for (int j=0; j<aSlot->bitmap.width; j++) {
int byte = aSlot->bitmap.buffer[(j>>3) + (row*pitch)];
if (!((byte<<(j&0x7)) & 0x80))
continue;
mBuffer[j+(row*mBufferWidth)] = 255;
}
}
}
return PR_TRUE;
}
#endif
PRBool
nsAntiAliasedGlyph::SetImage(XCharStruct *aCharStruct, XImage *aXImage)
{
NS_ASSERTION(mBuffer, "null buffer (was Init called?)");
if (!mBuffer)
return PR_FALSE;
PRUint32 src_width = GLYPH_RIGHT_EDGE(aCharStruct)
- GLYPH_LEFT_EDGE(aCharStruct);
PRUint32 src_height = aXImage->height;
if ((src_width > mMaxWidth) || (src_height > mMaxHeight)) {
NS_ASSERTION(src_width<=mMaxWidth,"unexpected width");
NS_ASSERTION(src_height<=mMaxHeight,"unexpected height");
return PR_FALSE;
}
mAscent = aCharStruct->ascent;
mDescent = aCharStruct->descent;
mLBearing = aCharStruct->lbearing;
mRBearing = aCharStruct->rbearing;
mWidth = src_width;
mHeight = src_height;
mAdvance = aCharStruct->width;
NS_ASSERTION(aXImage->format==ZPixmap,"unexpected image format");
if (aXImage->format != ZPixmap)
return PR_FALSE;
int bits_per_pixel = aXImage->bits_per_pixel;
memset((char*)mBuffer, 0, mBufferLen);
PRUint32 x, y;
PRUint32 src_index = 0;
PRUint32 dst_index = mBorder + (mBorder*mBufferWidth);
PRInt32 delta_dst_row = -src_width + mBufferWidth;
PRUint8 *pSrcLineStart = (PRUint8 *)aXImage->data;
if (bits_per_pixel == 16) {
for (y=0; y<src_height; y++) {
PRUint16 *src = (PRUint16*)pSrcLineStart;
for (x=0; x<src_width; x++,src++,dst_index++) {
if (*src & 0x1)
mBuffer[dst_index] = 0xFF;
}
// move to the next row
dst_index += delta_dst_row;
pSrcLineStart += aXImage->bytes_per_line;
}
return PR_TRUE;
}
else if (bits_per_pixel == 24) {
PRUint8 *src = (PRUint8*)aXImage->data;
for (y=0; y<src_height; y++) {
for (x=0; x<src_width; x++,src_index+=3,dst_index++) {
if (src[src_index] & 0x1)
mBuffer[dst_index] = 0xFF;
}
// move to the next row
dst_index += delta_dst_row;
src_index += -3*src_width + aXImage->bytes_per_line;
}
return PR_TRUE;
}
else if (bits_per_pixel == 32) {
for (y=0; y<src_height; y++) {
PRUint32 *src = (PRUint32*)pSrcLineStart;
for (x=0; x<src_width; x++,src++,dst_index++) {
if (*src & 0x100)
mBuffer[dst_index] = 0xFF;
}
// move to the next row
dst_index += delta_dst_row;
pSrcLineStart += aXImage->bytes_per_line;
}
return PR_TRUE;
}
else {
NS_ASSERTION(0, "do not support current bits_per_pixel");
return PR_FALSE;
}
}
PRBool
nsAntiAliasedGlyph::SetSize(GlyphMetrics *aGlyphMetrics)
{
mAscent = aGlyphMetrics->ascent;
mDescent = aGlyphMetrics->descent;
mLBearing = aGlyphMetrics->lbearing;
mRBearing = aGlyphMetrics->rbearing;
mWidth = aGlyphMetrics->width;
mHeight = aGlyphMetrics->height;
mAdvance = aGlyphMetrics->advance;
return PR_TRUE;
}

Просмотреть файл

@ -1,85 +0,0 @@
#ifndef NSANTIALIASEDGLYPH_H
#define NSANTIALIASEDGLYPH_H
#include "gfx-config.h"
#include "nscore.h"
#ifdef MOZ_ENABLE_FREETYPE2
#include <ft2build.h>
#include FT_GLYPH_H
#endif
struct _XImage;
#ifndef MIN
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) (((a) >= (b)) ? (a) : (b))
#endif
#define GLYPH_LEFT_EDGE(m) MIN(0, (m)->lbearing)
#define GLYPH_RIGHT_EDGE(m) MAX((m)->width, (m)->rbearing)
typedef struct _GlyphMetrics {
PRUint32 width;
PRUint32 height;
PRInt32 lbearing;
PRInt32 rbearing;
PRInt32 advance;
PRInt32 ascent;
PRInt32 descent;
} GlyphMetrics;
//
// Grey scale image
//
class nsAntiAliasedGlyph {
public:
nsAntiAliasedGlyph(PRUint32 aWidth, PRUint32 aHeight, PRUint32 aBorder);
~nsAntiAliasedGlyph();
PRBool Init(); // alloc a buffer
PRBool Init(PRUint8 *aBuffer, PRUint32 aBufferLen); // use this buffer
#ifdef MOZ_ENABLE_FREETYPE2
PRBool WrapFreeType(FT_BBox *aBbox, FT_BitmapGlyph aSlot,
PRUint8 *aBuffer, PRUint32 aBufLen);
#endif
inline PRUint32 GetBorder() { return mBorder; };
inline PRUint8 *GetBuffer() { return mBuffer; };
inline PRUint32 GetBufferLen() { return mBufferLen; };
inline PRUint32 GetBufferWidth() { return mBufferWidth; };
inline PRUint32 GetBufferHeight() { return mBufferHeight; };
inline PRInt32 GetAdvance() { return mAdvance; };
inline PRInt32 GetLBearing() { return mLBearing; };
inline PRInt32 GetRBearing() { return mRBearing; };
inline PRUint32 GetWidth() { return mWidth; };
inline PRUint32 GetHeight() { return mHeight; };
PRBool SetImage(XCharStruct *, _XImage *);
PRBool SetSize(GlyphMetrics *);
protected:
PRUint32 mBorder;
PRInt32 mAscent;
PRInt32 mDescent;
PRInt32 mLBearing;
PRInt32 mRBearing;
PRInt32 mAdvance;
PRUint32 mWidth;
PRUint32 mHeight;
PRUint32 mMaxWidth;
PRUint32 mMaxHeight;
PRUint32 mBufferWidth; // mWidth may be smaller
PRUint32 mBufferHeight; // mHeight may be smaller
PRBool mOwnBuffer;
PRUint8 *mBuffer;
PRUint32 mBufferLen;
};
#endif /* NSANTIALIASEDGLYPH_H */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,189 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@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 NS_FT2_FONT_CATALOG_H
#define NS_FT2_FONT_CATALOG_H
#include "gfx-config.h"
#include "nsIFontCatalogService.h"
#if (defined(MOZ_ENABLE_FREETYPE2))
#include "nsFreeType.h"
#include "nsICharRepresentable.h"
#include "nsCompressedCharMap.h"
#include "nsString.h"
#include "nsIPref.h"
#include "nsNameValuePairDB.h"
#include "nsICharsetConverterManager.h"
//
// To limit the potential for namespace collision we limit the
// number of Moz files that include FreeType's include (and hence
// have FreeType typedefs, macros, and defines).
//
struct FT_LibraryRec_;
typedef signed long FT_Long;
typedef unsigned short FT_UShort;
#define PUBLIC_FONT_SUMMARY_NAME NS_LITERAL_CSTRING(".mozilla_font_summary.ndb")
#define FONT_SUMMARIES_SUBDIR NS_LITERAL_CSTRING("catalog")
#define FONT_DOWNLOAD_SUBDIR NS_LITERAL_CSTRING("fonts")
#define FONT_SUMMARIES_EXTENSION NS_LITERAL_CSTRING(".ndb")
#define FONT_SUMMARY_VERSION_TAG "FontSummaryVersion"
#define FONT_SUMMARY_VERSION_MAJOR 1
#define FONT_SUMMARY_VERSION_MINOR 0
#define FONT_SUMMARY_VERSION_REV 0
#define FC_FILE_OKAY 0
#define FC_FILE_GARBLED 1
#define FC_FILE_MODIFIED 2
#define STRMATCH(s1,s2) (strcmp((s1),(s2))==0)
#define STRNMATCH(s1,s2,l) (strncmp((s1),(s2),(l))==0)
#define STRCASEMATCH(s1,s2) (strcasecmp((s1),(s2))==0)
typedef struct {
const char *mDirName; // encoded in the native charset
} nsDirCatalogEntry;
#define CPR1 1 // designate CodePageRange1 to use for "GetRangeLanguage"
#define CPR2 2 // designate CodePageRange2 to use for "GetRangeLanguage"
typedef struct {
nsFontCatalogEntry **fonts;
int numFonts;
int numSlots;
} nsFontCatalog;
typedef struct {
nsDirCatalogEntry **dirs;
int numDirs;
int numSlots;
} nsDirCatalog;
typedef struct {
const char *vendorID;
const char *vendorName;
} nsFontVendorName;
typedef struct {
unsigned long bit;
const char *language;
} nsulCodePageRangeLanguage;
#endif
class nsFT2FontCatalog : public nsIFontCatalogService {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFONTCATALOGSERVICE
nsFT2FontCatalog();
virtual ~nsFT2FontCatalog();
#if (defined(MOZ_ENABLE_FREETYPE2))
void FreeGlobals();
PRBool InitGlobals(FT_LibraryRec_ *);
void GetFontNames(const nsACString & aFamilyName,
const nsACString & aLanguage,
PRUint16 aWeight,
PRUint16 aWidth,
PRUint16 aSlant,
PRUint16 aSpacing,
nsFontCatalog* aFC);
static const char* GetFileName(nsFontCatalogEntry *aFce);
static const char* GetFamilyName(nsFontCatalogEntry *aFce);
static PRInt32* GetEmbeddedBitmapHeights(nsFontCatalogEntry *aFce);
static PRInt32 GetFaceIndex(nsFontCatalogEntry *aFce);
static PRInt32 GetNumEmbeddedBitmaps(nsFontCatalogEntry *aFce);
static const char* GetFoundry(nsFontCatalogEntry *aFce);
protected:
static void AddDir(nsDirCatalog *dc, nsDirCatalogEntry *dir);
PRBool AddFceIfCurrent(const char*, nsHashtable*, PRInt64, nsFontCatalog*);
void AddFont(nsFontCatalog *fc, nsFontCatalogEntry *fce);
int CheckFontSummaryVersion(nsNameValuePairDB *aDB);
#ifdef DEBUG
void DumpFontCatalog(nsFontCatalog *fc);
void DumpFontCatalogEntry(nsFontCatalogEntry *);
#endif
void FixUpFontCatalog(nsFontCatalog *fc);
static PRBool FreeFceHashEntry(nsHashKey* aKey, void* aData, void* aClosure);
void FreeFontCatalog(nsFontCatalog *fc);
static void FreeFontCatalogEntry(nsFontCatalogEntry *);
void FreeDirCatalog(nsDirCatalog *dc);
void FreeDirCatalogEntry(nsDirCatalogEntry *);
static void GetDirsPrefEnumCallback(const char* aName, void* aClosure);
int GetFontCatalog(FT_LibraryRec_*, nsFontCatalog *, nsDirCatalog *);
PRBool GetFontSummaryName(const nsACString &, const nsACString &,
nsACString &, nsACString &);
unsigned long GetRangeLanguage(const nsACString &, PRInt16 aRange);
PRBool HandleFontDir(FT_LibraryRec_ *, nsFontCatalog *,
const nsACString &, const nsACString &);
void HandleFontFile(FT_LibraryRec_ *, nsFontCatalog *, const char*);
PRBool IsSpace(FT_Long);
nsDirCatalog *NewDirCatalog();
nsFontCatalogEntry* NewFceFromFontFile(FT_LibraryRec_*, const char*,int,int*);
nsFontCatalogEntry* NewFceFromSummary(nsNameValuePairDB *aDB);
nsFontCatalog *NewFontCatalog();
PRBool ReadFontDirSummary(const nsACString&, nsHashtable*);
PRBool ParseCCMapLine(nsCompressedCharMap*,long,const char*);
void PrintCCMap(nsNameValuePairDB *aDB, PRUint16 *aCCMap);
void PrintFontSummaries(nsNameValuePairDB *, nsFontCatalog *);
void PrintFontSummaryVersion(nsNameValuePairDB *aDB);
void PrintPageBits(nsNameValuePairDB*,PRUint16*,PRUint32);
int ReadFontSummaries(nsHashtable*, nsNameValuePairDB *);
static nsIPref* sPref;
nsFontCatalog *mFontCatalog;
PRPackedBool mIsNewCatalog;
static nsHashtable *sVendorNames;
nsHashtable *mRange1Language;
nsHashtable *mRange2Language;
PRBool mAvailableFontCatalogService;
nsCOMPtr<nsIFreeType2> mFt2;
#endif
};
#endif /* NS_FT2_FONT_CATALOG_H */

Просмотреть файл

@ -1,449 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@netscape.com>
* Louie Zhao <louie.zhao@sun.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 "gfx-config.h"
#include "nsFT2FontNode.h"
#include "nsFontDebug.h"
#if (!defined(MOZ_ENABLE_FREETYPE2))
void nsFT2FontNode::FreeGlobals() {}
nsresult nsFT2FontNode::InitGlobals()
{
FREETYPE_FONT_PRINTF(("freetype not compiled in"));
NS_WARNING("freetype not compiled in");
return NS_OK;
}
void nsFT2FontNode::GetFontNames(const char* aPattern,
nsFontNodeArray* aNodes) {}
#else
#include "nsFreeType.h"
#include "nsFontFreeType.h"
#include "nsIServiceManager.h"
#include "nsIMutableArray.h"
#include "nsArrayUtils.h"
nsHashtable* nsFT2FontNode::mFreeTypeNodes = nsnull;
PRBool nsFT2FontNode::sInited = PR_FALSE;
nsIFontCatalogService* nsFT2FontNode::sFcs = nsnull;
void
nsFT2FontNode::FreeGlobals()
{
NS_IF_RELEASE(sFcs);
if (mFreeTypeNodes) {
mFreeTypeNodes->Reset(FreeNode, nsnull);
delete mFreeTypeNodes;
mFreeTypeNodes = nsnull;
}
sInited = PR_FALSE;
}
nsresult
nsFT2FontNode::InitGlobals()
{
NS_ASSERTION(sInited==PR_FALSE,
"nsFT2FontNode::InitGlobals called more than once");
sInited = PR_TRUE;
nsresult rv = ::CallGetService("@mozilla.org/gfx/xfontcatalogservice;1",
&sFcs);
if (NS_FAILED(rv)) {
NS_ERROR("Font Catalog Service init failed\n");
return NS_ERROR_FAILURE;
}
mFreeTypeNodes = new nsHashtable();
if (!mFreeTypeNodes)
return NS_ERROR_FAILURE;
LoadNodeTable();
WeightTableInitCorrection(nsFreeTypeFont::sLinearWeightTable,
nsFreeType2::gAATTDarkTextMinValue,
nsFreeType2::gAATTDarkTextGain);
return NS_OK;
}
void
nsFT2FontNode::GetFontNames(const char* aPattern, nsFontNodeArray* aNodes)
{
int j;
PRBool rslt;
PRUint32 count, i;
char *pattern, *foundry, *family, *charset, *encoding;
const char *charSetName;
nsFontNode *node;
nsCOMPtr<nsIArray> arrayFC;
nsCAutoString familyTmp, languageTmp;
FONT_CATALOG_PRINTF(("looking for FreeType font matching %s", aPattern));
nsCAutoString patt(aPattern);
ToLowerCase(patt);
pattern = strdup(patt.get());
NS_ASSERTION(pattern, "failed to copy pattern");
if (!pattern)
goto cleanup_and_return;
rslt = ParseXLFD(pattern, &foundry, &family, &charset, &encoding);
if (!rslt)
goto cleanup_and_return;
// unable to handle "name-charset-*"
if (charset && !encoding) {
goto cleanup_and_return;
}
if (family)
familyTmp.Assign(family);
sFcs->GetFontCatalogEntries(familyTmp, languageTmp, 0, 0, 0, 0,
getter_AddRefs(arrayFC));
if (!arrayFC)
goto cleanup_and_return;
arrayFC->GetLength(&count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsITrueTypeFontCatalogEntry> fce = do_QueryElementAt(arrayFC, i);
if (!fce)
continue;
nsCAutoString foundryName, familyName;
PRUint32 flags, codePageRange1, codePageRange2;
PRUint16 weight, width;
fce->GetFamilyName(familyName);
fce->GetFlags(&flags);
fce->GetWidth(&width);
fce->GetWeight(&weight);
fce->GetCodePageRange1(&codePageRange1);
fce->GetCodePageRange2(&codePageRange2);
if (!charset) { // get all encoding
FONT_CATALOG_PRINTF(("found FreeType %s-%s-*-*", foundryName.get(),
familyName.get()));
for (j=0; j<32; j++) {
unsigned long bit = 1 << j;
if (bit & codePageRange1) {
charSetName = nsFreeType2::GetRange1CharSetName(bit);
NS_ASSERTION(charSetName, "failed to get charset name");
if (!charSetName)
continue;
node = LoadNode(fce, charSetName, aNodes);
}
if (bit & codePageRange2) {
charSetName = nsFreeType2::GetRange2CharSetName(bit);
if (!charSetName)
continue;
LoadNode(fce, charSetName, aNodes);
}
}
if (foundryName.IsEmpty() && !familyName.IsEmpty() && flags&FCE_FLAGS_SYMBOL) {
// the "registry-encoding" is not used but LoadNode will fail without
// some value for this
LoadNode(fce, "symbol-fontspecific", aNodes);
}
}
if (charset && encoding) { // get this specific encoding
PRUint32 cpr1_bits, cpr2_bits;
nsCAutoString charsetName(charset);
charsetName.Append('-');
charsetName.Append(encoding);
CharSetNameToCodeRangeBits(charsetName.get(), &cpr1_bits, &cpr2_bits);
if (!(cpr1_bits & codePageRange1)
&& !(cpr2_bits & codePageRange2))
continue;
FONT_CATALOG_PRINTF(("found FreeType -%s-%s-%s",
familyName.get(),charset,encoding));
LoadNode(fce, charsetName.get(), aNodes);
}
}
FREE_IF(pattern);
return;
cleanup_and_return:
FONT_CATALOG_PRINTF(("nsFT2FontNode::GetFontNames failed"));
FREE_IF(pattern);
return;
}
nsFontNode*
nsFT2FontNode::LoadNode(nsITrueTypeFontCatalogEntry *aFce,
const char *aCharSetName,
nsFontNodeArray* aNodes)
{
nsFontCharSetMap *charSetMap = GetCharSetMap(aCharSetName);
if (!charSetMap->mInfo) {
return nsnull;
}
nsCAutoString nodeName, familyName;
aFce->GetVendorID(nodeName);
aFce->GetFamilyName(familyName);
nodeName.Append('-');
nodeName.Append(familyName);
nodeName.Append('-');
nodeName.Append(aCharSetName);
nsCStringKey key(nodeName);
nsFontNode* node = (nsFontNode*) mFreeTypeNodes->Get(&key);
if (!node) {
node = new nsFontNode;
if (!node) {
return nsnull;
}
mFreeTypeNodes->Put(&key, node);
node->mName = nodeName;
nsFontCharSetMap *charSetMap = GetCharSetMap(aCharSetName);
node->mCharSetInfo = charSetMap->mInfo;
}
PRInt64 styleFlags;
PRUint16 fceWeight, fceWidth;
aFce->GetStyleFlags(&styleFlags);
aFce->GetWidth(&fceWidth);
aFce->GetWeight(&fceWeight);
int styleIndex;
if (styleFlags & FT_STYLE_FLAG_ITALIC)
styleIndex = NS_FONT_STYLE_ITALIC;
else
styleIndex = NS_FONT_STYLE_NORMAL;
nsFontStyle* style = node->mStyles[styleIndex];
if (!style) {
style = new nsFontStyle;
if (!style) {
return nsnull;
}
node->mStyles[styleIndex] = style;
}
int weightIndex = WEIGHT_INDEX(fceWeight);
nsFontWeight* weight = style->mWeights[weightIndex];
if (!weight) {
weight = new nsFontWeight;
if (!weight) {
return nsnull;
}
style->mWeights[weightIndex] = weight;
}
nsFontStretch* stretch = weight->mStretches[fceWidth];
if (!stretch) {
stretch = new nsFontStretch;
if (!stretch) {
return nsnull;
}
weight->mStretches[fceWidth] = stretch;
}
if (!stretch->mFreeTypeFaceID) {
stretch->mFreeTypeFaceID = aFce;
}
if (aNodes) {
int i, n, found = 0;
n = aNodes->Count();
for (i=0; i<n; i++) {
if (aNodes->GetElement(i) == node) {
found = 1;
}
}
if (!found) {
aNodes->AppendElement(node);
}
}
return node;
}
PRBool
nsFT2FontNode::LoadNodeTable()
{
int j;
nsCOMPtr<nsIArray> arrayFC;
nsCAutoString family, language;
sFcs->GetFontCatalogEntries(family, language, 0, 0, 0, 0,
getter_AddRefs(arrayFC));
if (!arrayFC)
return PR_FALSE;
PRUint32 count, i;
arrayFC->GetLength(&count);
for (i = 0; i < count; i++) {
const char *charsetName;
nsCOMPtr<nsITrueTypeFontCatalogEntry> fce = do_QueryElementAt(arrayFC, i);
if (!fce)
continue;
PRUint32 flags, codePageRange1, codePageRange2;
PRUint16 weight, width;
fce->GetFlags(&flags);
fce->GetWidth(&width);
fce->GetWeight(&weight);
fce->GetCodePageRange1(&codePageRange1);
fce->GetCodePageRange2(&codePageRange2);
if ((!flags&FCE_FLAGS_ISVALID)
|| (weight < 100) || (weight > 900) || (width > 8))
continue;
for (j=0; j<32; j++) {
unsigned long bit = 1 << j;
if (!(bit & codePageRange1))
continue;
charsetName = nsFreeType2::GetRange1CharSetName(bit);
NS_ASSERTION(charsetName, "failed to get charset name");
if (!charsetName)
continue;
LoadNode(fce, charsetName, nsnull);
}
for (j=0; j<32; j++) {
unsigned long bit = 1 << j;
if (!(bit & codePageRange2))
continue;
charsetName = nsFreeType2::GetRange2CharSetName(bit);
if (!charsetName)
continue;
LoadNode(fce, charsetName, nsnull);
}
}
return PR_TRUE;
}
//
// Parse XLFD
// The input is a typical XLFD string.
//
// the XLFD entries look like this:
// -adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1
// -adobe-courier-medium-r-*-*-12-*-*-*-*-*-*-*
//
// the fields are:
// -foundry-family-weight-slant-width-style-pixelsize-pointsize-
// resolution_x-resolution_y-spacing-avg_width-registry-encoding
//
// see ftp://ftp.x.org/pub/R6.4/xc/doc/hardcopy/XLFD
//
PRBool
nsFT2FontNode::ParseXLFD(char *aPattern, char** aFoundry, char** aFamily,
char** aCharset, char** aEncoding)
{
char *p;
int i;
*aFoundry = nsnull;
*aFamily = nsnull;
*aCharset = nsnull;
*aEncoding = nsnull;
// start of pattern
p = aPattern;
NS_ASSERTION(*p == '-',"garbled pattern: does not start with a '-'");
if (*p++ != '-')
return PR_FALSE;
// foundry
NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern");
if (!*p)
return PR_FALSE;
if (*p == '*')
*aFoundry = nsnull;
else
*aFoundry = p;
while (*p && (*p!='-'))
p++;
if (!*p)
return PR_TRUE; // short XLFD
NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of foundry");
*p++ = '\0';
// family
if (!*p)
return PR_TRUE; // short XLFD
if (*p == '*')
*aFamily = nsnull;
else
*aFamily = p;
while (*p && (*p!='-'))
p++;
if (!*p)
return PR_TRUE; // short XLFD
NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of family");
*p++ = '\0';
// skip forward to charset
for (i=0; i<10; i++) {
while (*p && (*p!='-'))
p++;
if (!*p)
return PR_TRUE; // short XLFD
*p++ = '\0';
}
// charset
NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern");
if (!*p)
return PR_FALSE;
if (*p == '*')
*aCharset = nsnull;
else
*aCharset = p;
while (*p && (*p!='-'))
p++;
if (!*p)
return PR_TRUE; // short XLFD
NS_ASSERTION(*p == '-',"garbled pattern: cannot find end of charset");
*p++ = '\0';
// encoding
NS_ASSERTION(*p,"garbled pattern: unexpected end of pattern");
if (!*p)
return PR_FALSE;
if (*p == '*')
*aEncoding = nsnull;
else
*aEncoding = p;
while (*p && (*p!='-'))
p++;
if (*p)
return PR_TRUE; // short XLFD
return PR_TRUE;
}
#endif

Просмотреть файл

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@netscape.com>
* Louie Zhao <louie.zhao@sun.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 NS_FT2_FONT_NODE_H
#define NS_FT2_FONT_NODE_H
#include "nsFontMetricsGTK.h"
class nsFT2FontNode {
public:
static void FreeGlobals();
static nsresult InitGlobals();
static void GetFontNames(const char* aPattern, nsFontNodeArray* aNodes);
#if (defined(MOZ_ENABLE_FREETYPE2))
protected:
static PRBool ParseXLFD(char *, char**, char**, char**, char**);
static nsFontNode* LoadNode(nsITrueTypeFontCatalogEntry*,
const char*,
nsFontNodeArray*);
static PRBool LoadNodeTable();
static nsHashtable *mFreeTypeNodes;
static PRBool sInited;
static nsIFontCatalogService* sFcs;
#endif //MOZ_ENABLE_FREETYPE2
};
#endif

Просмотреть файл

@ -1,105 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@netscape.com>
* Louie Zhao <louie.zhao@sun.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 nsFontDebug_h__
#define nsFontDebug_h__
#define NS_FONT_DEBUG_LOAD_FONT 0x01
#define NS_FONT_DEBUG_CALL_TRACE 0x02
#define NS_FONT_DEBUG_FIND_FONT 0x04
#define NS_FONT_DEBUG_SIZE_FONT 0x08
#define NS_FONT_DEBUG_SCALED_FONT 0x10
#define NS_FONT_DEBUG_BANNED_FONT 0x20
#define NS_FONT_DEBUG_FONT_CATALOG 0x100
#define NS_FONT_DEBUG_FONT_SCAN 0x200
#define NS_FONT_DEBUG_FREETYPE_FONT 0x400
#define NS_FONT_DEBUG_FREETYPE_GRAPHICS 0x800
#undef NS_FONT_DEBUG
#define NS_FONT_DEBUG 1
#ifdef NS_FONT_DEBUG
# define DEBUG_PRINTF(x) \
DEBUG_PRINTF_MACRO(x, 0xFFFF)
# define DEBUG_PRINTF_MACRO(x, type) \
PR_BEGIN_MACRO \
if (gFontDebug & (type)) { \
printf x ; \
printf(", %s %d\n", __FILE__, __LINE__); \
} \
PR_END_MACRO
#else
# define DEBUG_PRINTF_MACRO(x, type) \
PR_BEGIN_MACRO \
PR_END_MACRO
#endif
#define FIND_FONT_PRINTF(x) \
DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_FIND_FONT)
#define SIZE_FONT_PRINTF(x) \
DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_SIZE_FONT)
#define SCALED_FONT_PRINTF(x) \
DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_SCALED_FONT)
#define BANNED_FONT_PRINTF(x) \
DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_BANNED_FONT)
#define FONT_CATALOG_PRINTF(x) \
DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_FONT_CATALOG)
#define FONT_SCAN_PRINTF(x) \
PR_BEGIN_MACRO \
if (gFontDebug & NS_FONT_DEBUG_FONT_SCAN) { \
printf x ; \
fflush(stdout); \
} \
PR_END_MACRO
#define FREETYPE_FONT_PRINTF(x) \
DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_FREETYPE_FONT)
#ifdef MOZ_ENABLE_FREETYPE2
extern PRUint32 gFontDebug;
#endif
#endif

Просмотреть файл

@ -1,967 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@netscape.com>
* Louie Zhao <louie.zhao@sun.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 ***** */
#ifdef DEBUG
// set this to 1 to have the code draw the bounding boxes
#define DEBUG_SHOW_GLYPH_BOX 0
#endif
#include "gfx-config.h"
#include "nsFontFreeType.h"
#include "nsUnicharUtils.h"
#if (!defined(MOZ_ENABLE_FREETYPE2))
nsFreeTypeFont *
nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *, PRUint16, const char *)
{
return nsnull;
}
#else
#include "nsX11AlphaBlend.h"
#include "nsAntiAliasedGlyph.h"
#include "nsFontDebug.h"
#include "nsIServiceManager.h"
// macros to handle FreeType2 16.16 numbers
#define FT_16_16_TO_REG(x) ((x)>>16)
#define IMAGE_BUFFER_SIZE 2048
PRUint32 deltaMicroSeconds(PRTime aStartTime, PRTime aEndTime);
void GetFallbackGlyphMetrics(FT_BBox *aBoundingBox, FT_Face aFace);
PRUint8 nsFreeTypeFont::sLinearWeightTable[256];
//
// class nsFreeTypeXImage definition
//
class nsFreeTypeXImage : public nsFreeTypeFont {
public:
nsFreeTypeXImage(nsITrueTypeFontCatalogEntry *aFaceID, PRUint16 aPixelSize,
const char *aName);
gint DrawString(nsRenderingContextGTK* aContext,
nsDrawingSurfaceGTK* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength);
protected:
nsFreeTypeXImage();
};
//
// class nsFreeTypeXImageSBC (Single Byte Converter) definition
//
class nsFreeTypeXImageSBC : public nsFreeTypeXImage {
public:
nsFreeTypeXImageSBC(nsITrueTypeFontCatalogEntry *aFaceID,
PRUint16 aPixelSize, const char *aName);
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics);
#endif
virtual gint GetWidth(const PRUnichar* aString, PRUint32 aLength);
virtual gint DrawString(nsRenderingContextGTK* aContext,
nsDrawingSurfaceGTK* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength);
protected:
nsFreeTypeXImageSBC();
};
#ifdef ENABLE_TIME_MACROS
PRUint32
deltaMicroSeconds(PRTime aStartTime, PRTime aEndTime)
{
PRUint32 delta;
PRUint64 loadTime64;
LL_SUB(loadTime64, aEndTime, aStartTime);
LL_L2UI(delta, loadTime64);
return delta;
}
#endif
//
// class nsFreeTypeFont data/functions
//
nsFreeTypeFont::nsFreeTypeFont()
{
NS_ERROR("should never call nsFreeTypeFont::nsFreeTypeFont");
}
nsFreeTypeFont *
nsFreeTypeFont::NewFont(nsITrueTypeFontCatalogEntry *aFaceID,
PRUint16 aPixelSize, const char *aName)
{
// Make sure FreeType is available
nsresult rv;
nsCOMPtr<nsIFreeType2> ft2 = do_GetService(NS_FREETYPE2_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
NS_ERROR("FreeType2 routines not available");
return nsnull;
}
// for now we only support ximage (XGetImage/alpha-blend/XPutImage) display
// when we support XRender then we will need to test if it is
// available and if so use it since it is faster than ximage.
PRBool ximage = PR_TRUE;
PRBool render = PR_FALSE;
nsFreeTypeFont *ftfont;
nsCAutoString familyName;
aFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType2::GetCustomEncoderInfo(familyName.get());
if (ximage) {
if (ffei) {
ftfont = new nsFreeTypeXImageSBC(aFaceID, aPixelSize, aName);
}
else {
ftfont = new nsFreeTypeXImage(aFaceID, aPixelSize, aName);
}
return ftfont;
}
else if (render) {
NS_ERROR("need to construct a render type FreeType object");
return nsnull;
}
NS_ERROR("need to construct other type FreeType objects");
return nsnull;
}
FT_Face
nsFreeTypeFont::getFTFace()
{
FT_Face face = nsnull;
FTC_Manager mgr;
nsresult rv;
mFt2->GetFTCacheManager(&mgr);
rv = mFt2->ManagerLookupSize(mgr, &mImageDesc.font, &face, nsnull);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get face/size");
if (NS_FAILED(rv))
return nsnull;
return face;
}
nsFreeTypeFont::nsFreeTypeFont(nsITrueTypeFontCatalogEntry *aFaceID,
PRUint16 aPixelSize, const char *aName)
{
PRBool anti_alias = PR_TRUE;
PRBool embedded_bimap = PR_FALSE;
mFaceID = aFaceID;
mPixelSize = aPixelSize;
mImageDesc.font.face_id = (void*)mFaceID;
mImageDesc.font.pix_width = aPixelSize;
mImageDesc.font.pix_height = aPixelSize;
mImageDesc.image_type = 0;
if (aPixelSize < nsFreeType2::gAntiAliasMinimum) {
mImageDesc.image_type |= ftc_image_mono;
anti_alias = PR_FALSE;
}
if (nsFreeType2::gFreeType2Autohinted)
mImageDesc.image_type |= ftc_image_flag_autohinted;
if (nsFreeType2::gFreeType2Unhinted)
mImageDesc.image_type |= ftc_image_flag_unhinted;
PRUint32 num_embedded_bitmaps, i;
PRInt32* embedded_bitmapheights;
mFaceID->GetEmbeddedBitmapHeights(&num_embedded_bitmaps,
&embedded_bitmapheights);
// check if we have an embedded bitmap
if (aPixelSize <= nsFreeType2::gEmbeddedBitmapMaximumHeight) {
if (num_embedded_bitmaps) {
for (i=0; i<num_embedded_bitmaps; i++) {
if (embedded_bitmapheights[i] == aPixelSize) {
embedded_bimap = PR_TRUE;
// unhinted must be set for embedded bitmaps to be used
mImageDesc.image_type |= ftc_image_flag_unhinted;
break;
}
}
}
}
nsresult rv;
// we checked for this earlier so it should not fail now
mFt2 = do_GetService(NS_FREETYPE2_CONTRACTID, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to find FreeType routines");
FREETYPE_FONT_PRINTF(("anti_alias=%d, embedded_bitmap=%d, "
"AutoHinted=%d, gFreeType2Unhinted = %d, "
"size=%dpx, \"%s\"",
anti_alias, embedded_bimap,
nsFreeType2::gFreeType2Autohinted,
nsFreeType2::gFreeType2Unhinted,
aPixelSize, aName));
}
void
nsFreeTypeFont::LoadFont()
{
if (mAlreadyCalledLoadFont) {
return;
}
mAlreadyCalledLoadFont = PR_TRUE;
PRUint32 size;
mFaceID->GetCCMap(&size, &mCCMap);
#ifdef NS_FONT_DEBUG_LOAD_FONT
nsCAutoString fileName;
mFaceID->GetFileName(fileName);
if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) {
printf("loaded \"%s\", size=%d, filename=%s\n",
mName, mSize, fileName.get());
}
#endif
}
nsFreeTypeFont::~nsFreeTypeFont()
{
}
#ifdef MOZ_MATHML
nsresult
nsFreeTypeFont::GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics)
{
return doGetBoundingMetrics(aString, aLength,
&aBoundingMetrics.leftBearing,
&aBoundingMetrics.rightBearing,
&aBoundingMetrics.ascent,
&aBoundingMetrics.descent,
&aBoundingMetrics.width);
}
#endif
nsresult
nsFreeTypeFont::doGetBoundingMetrics(const PRUnichar* aString, PRUint32 aLength,
PRInt32* aLeftBearing,
PRInt32* aRightBearing,
PRInt32* aAscent,
PRInt32* aDescent,
PRInt32* aWidth)
{
nsresult rv;
*aLeftBearing = 0;
*aRightBearing = 0;
*aAscent = 0;
*aDescent = 0;
*aWidth = 0;
if (aLength < 1) {
return NS_ERROR_FAILURE;
}
FT_Pos pos = 0;
FT_BBox bbox;
// initialize to "uninitialized" values
bbox.xMin = bbox.yMin = 32000;
bbox.xMax = bbox.yMax = -32000;
// get the face/size from the FreeType cache
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return NS_ERROR_FAILURE;
FTC_Image_Cache icache;
mFt2->GetImageCache(&icache);
if (!icache)
return NS_ERROR_FAILURE;
// get the text size
PRUint32 i, extraSurrogateLength;
for (i=0; i<aLength; i+=1+extraSurrogateLength) {
FT_UInt glyph_index;
FT_Glyph glyph;
FT_BBox glyph_bbox;
FT_Pos advance;
extraSurrogateLength=0;
FT_ULong code_point = aString[i];
if(i<aLength-1 && NS_IS_HIGH_SURROGATE(code_point) && NS_IS_LOW_SURROGATE(aString[i+1])) {
// if surrogate, make UCS4 code point from high aString[i] surrogate and
// low surrogate aString[i+1]
code_point = SURROGATE_TO_UCS4(code_point, aString[i+1]);
// skip aString[i+1], it is already used as low surrogate
extraSurrogateLength = 1;
}
mFt2->GetCharIndex(face, code_point, &glyph_index);
//NS_ASSERTION(glyph_index,"failed to get glyph");
if (glyph_index) {
rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph);
NS_ASSERTION(NS_SUCCEEDED(rv),"error loading glyph");
}
if ((glyph_index) && (NS_SUCCEEDED(rv))) {
mFt2->GlyphGetCBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox);
advance = FT_16_16_TO_REG(glyph->advance.x);
}
else {
// allocate space to draw an empty box in
GetFallbackGlyphMetrics(&glyph_bbox, face);
advance = glyph_bbox.xMax + 1;
}
bbox.xMin = PR_MIN(pos+glyph_bbox.xMin, bbox.xMin);
bbox.xMax = PR_MAX(pos+glyph_bbox.xMax, bbox.xMax);
bbox.yMin = PR_MIN(glyph_bbox.yMin, bbox.yMin);
bbox.yMax = PR_MAX(glyph_bbox.yMax, bbox.yMax);
pos += advance;
}
// check we got at least one size
if (bbox.xMin > bbox.xMax)
bbox.xMin = bbox.xMax = bbox.yMin = bbox.yMax = 0;
*aLeftBearing = bbox.xMin;
*aRightBearing = bbox.xMax;
*aAscent = bbox.yMax;
*aDescent = -bbox.yMin;
*aWidth = pos;
return NS_OK;
}
GdkFont*
nsFreeTypeFont::GetGDKFont()
{
return nsnull;
}
PRBool
nsFreeTypeFont::GetGDKFontIs10646()
{
return PR_TRUE;
}
PRBool
nsFreeTypeFont::IsFreeTypeFont()
{
return PR_TRUE;
}
gint
nsFreeTypeFont::GetWidth(const PRUnichar* aString, PRUint32 aLength)
{
FT_UInt glyph_index;
FT_Glyph glyph;
FT_Pos origin_x = 0;
// get the face/size from the FreeType cache
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return 0;
FTC_Image_Cache icache;
mFt2->GetImageCache(&icache);
if (!icache)
return 0;
PRUint32 i, extraSurrogateLength;
for (i=0; i<aLength; i+=1+extraSurrogateLength) {
extraSurrogateLength=0;
FT_ULong code_point = aString[i];
if(i<aLength-1 && NS_IS_HIGH_SURROGATE(code_point) && NS_IS_LOW_SURROGATE(aString[i+1])) {
// if surrogate, make UCS4 code point from high aString[i] surrogate and
// low surrogate aString[i+1]
code_point = SURROGATE_TO_UCS4(code_point, aString[i+1]);
// skip aString[i+1], it is already used as low surrogate
extraSurrogateLength = 1;
}
mFt2->GetCharIndex((FT_Face)face, code_point, &glyph_index);
nsresult rv;
rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph);
NS_ASSERTION(NS_SUCCEEDED(rv),"error loading glyph");
if (NS_FAILED(rv)) {
origin_x += face->size->metrics.x_ppem/2 + 2;
continue;
}
origin_x += FT_16_16_TO_REG(glyph->advance.x);
}
return origin_x;
}
gint
nsFreeTypeFont::DrawString(nsRenderingContextGTK* aContext,
nsDrawingSurfaceGTK* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength)
{
NS_ERROR("should never call nsFreeTypeFont::DrawString");
return 0;
}
PRUint32
nsFreeTypeFont::Convert(const PRUnichar* aSrc, PRUint32 aSrcLen,
PRUnichar* aDest, PRUint32 aDestLen)
{
NS_ERROR("should not be calling nsFreeTypeFont::Convert");
return 0;
}
int
nsFreeTypeFont::ascent()
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return 0;
return FT_DESIGN_UNITS_TO_PIXELS(face->ascender, face->size->metrics.y_scale);
}
int
nsFreeTypeFont::descent()
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return 0;
return FT_DESIGN_UNITS_TO_PIXELS(-face->descender, face->size->metrics.y_scale);
}
int
nsFreeTypeFont::max_ascent()
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return 0;
TT_OS2 * tt_os2;
mFt2->GetSfntTable(face, ft_sfnt_os2, (void**)&tt_os2);
NS_ASSERTION(tt_os2, "unable to get OS2 table");
if (tt_os2)
return FT_DESIGN_UNITS_TO_PIXELS(tt_os2->sTypoAscender,
face->size->metrics.y_scale);
else
return FT_DESIGN_UNITS_TO_PIXELS(face->bbox.yMax,
face->size->metrics.y_scale);
}
int
nsFreeTypeFont::max_descent()
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return 0;
TT_OS2 *tt_os2;
mFt2->GetSfntTable(face, ft_sfnt_os2, (void**)&tt_os2);
NS_ASSERTION(tt_os2, "unable to get OS2 table");
if (tt_os2)
return FT_DESIGN_UNITS_TO_PIXELS(-tt_os2->sTypoDescender,
face->size->metrics.y_scale);
else
return FT_DESIGN_UNITS_TO_PIXELS(-face->bbox.yMin,
face->size->metrics.y_scale);
}
int
nsFreeTypeFont::max_width()
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return 0;
return FT_DESIGN_UNITS_TO_PIXELS(face->max_advance_width,
face->size->metrics.x_scale);
}
PRBool
nsFreeTypeFont::getXHeight(unsigned long &val)
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face || !val)
return PR_FALSE;
val = FT_DESIGN_UNITS_TO_PIXELS(face->height, face->size->metrics.y_scale);
return PR_TRUE;
}
PRBool
nsFreeTypeFont::underlinePosition(long &val)
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return PR_FALSE;
val = FT_DESIGN_UNITS_TO_PIXELS(-face->underline_position,
face->size->metrics.y_scale);
return PR_TRUE;
}
PRBool
nsFreeTypeFont::underline_thickness(unsigned long &val)
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return PR_FALSE;
val = FT_DESIGN_UNITS_TO_PIXELS(face->underline_thickness,
face->size->metrics.y_scale);
return PR_TRUE;
}
PRBool
nsFreeTypeFont::superscript_y(long &val)
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return PR_FALSE;
TT_OS2 *tt_os2;
mFt2->GetSfntTable(face, ft_sfnt_os2, (void**)&tt_os2);
NS_ASSERTION(tt_os2, "unable to get OS2 table");
if (!tt_os2)
return PR_FALSE;
val = FT_DESIGN_UNITS_TO_PIXELS(tt_os2->ySuperscriptYOffset,
face->size->metrics.y_scale);
return PR_TRUE;
}
PRBool
nsFreeTypeFont::subscript_y(long &val)
{
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return PR_FALSE;
TT_OS2 *tt_os2;
mFt2->GetSfntTable(face, ft_sfnt_os2, (void**)&tt_os2);
NS_ASSERTION(tt_os2, "unable to get OS2 table");
if (!tt_os2)
return PR_FALSE;
val = FT_DESIGN_UNITS_TO_PIXELS(tt_os2->ySubscriptYOffset,
face->size->metrics.y_scale);
// some fonts have the sign wrong. it should be always positive.
val = (val < 0) ? -val : val;
return PR_TRUE;
}
//
// class nsFreeTypeRender
//
// this needs to be written
class nsFreeTypeRender : nsFreeTypeFont {
private:
nsFreeTypeRender();
};
//
// class nsFreeTypeXImage data/functions
//
nsFreeTypeXImage::nsFreeTypeXImage()
{
NS_ERROR("should never call nsFreeTypeXImage::nsFreeTypeXImage");
}
nsFreeTypeXImage::nsFreeTypeXImage(nsITrueTypeFontCatalogEntry *aFaceID,
PRUint16 aPixelSize, const char *aName)
: nsFreeTypeFont(aFaceID, aPixelSize, aName)
{
//NS_ERROR("should never call nsFreeTypeXImage::nsFreeTypeXImage");
}
gint
nsFreeTypeXImage::DrawString(nsRenderingContextGTK* aContext,
nsDrawingSurfaceGTK* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength)
{
#if DEBUG_SHOW_GLYPH_BOX
PRUint32 x, y;
// grey shows image size
// red shows character cells
// green box shows text ink
#endif
if (aLength < 1) {
return 0;
}
// get the face/size from the FreeType cache
FT_Face face = getFTFace();
NS_ASSERTION(face, "failed to get face/size");
if (!face)
return 0;
nsresult rslt;
PRInt32 leftBearing, rightBearing, ascent, descent, width;
rslt = doGetBoundingMetrics(aString, aLength, &leftBearing, &rightBearing,
&ascent, &descent, &width);
if (NS_FAILED(rslt))
return 0;
// make sure we bring down enough background for blending
rightBearing = PR_MAX(rightBearing, width+1);
// offset in the ximage to the x origin
PRInt32 x_origin = PR_MAX(0, -leftBearing);
// offset in the ximage to the x origin
PRInt32 y_origin = ascent;
PRInt32 x_pos = x_origin;
int image_width = x_origin + rightBearing;
int image_height = y_origin + PR_MAX(descent, 0);
if ((image_width<=0) || (image_height<=0)) {
// if we do not have any pixels then no point in trying to draw
// eg: the space char has 0 height
NS_ASSERTION(width>=0, "Negative width");
return width;
}
Display *dpy = GDK_DISPLAY();
Drawable win = GDK_WINDOW_XWINDOW(aSurface->GetDrawable());
GC gc = GDK_GC_XGC(aContext->GetGC());
XGCValues values;
if (!XGetGCValues(dpy, gc, GCForeground, &values)) {
NS_ERROR("failed to get foreground pixel");
return 0;
}
nscolor color = nsX11AlphaBlend::PixelToNSColor(values.foreground);
#if DEBUG_SHOW_GLYPH_BOX
// show X/Y origin
XDrawLine(dpy, win, DefaultGC(dpy, 0), aX-2, aY, aX+2, aY);
XDrawLine(dpy, win, DefaultGC(dpy, 0), aX, aY-2, aX, aY+2);
// show width
XDrawLine(dpy, win, DefaultGC(dpy, 0), aX-x_origin, aY-y_origin-2,
aX+rightBearing, aY-y_origin-2);
#endif
//
// Get the background
//
XImage *sub_image = nsX11AlphaBlend::GetBackground(dpy, DefaultScreen(dpy),
win, aX-x_origin, aY-y_origin,
image_width, image_height);
if (sub_image==nsnull) {
#ifdef DEBUG
int screen = DefaultScreen(dpy);
// complain if the requested area is not completely off screen
int win_width = DisplayWidth(dpy, screen);
int win_height = DisplayHeight(dpy, screen);
if (((int)(aX-leftBearing+image_width) > 0) // not hidden to left
&& ((int)(aX-leftBearing) < win_width) // not hidden to right
&& ((int)(aY-ascent+image_height) > 0)// not hidden to top
&& ((int)(aY-ascent) < win_height)) // not hidden to bottom
{
NS_ASSERTION(sub_image, "failed to get the image");
}
#endif
return 0;
}
#if DEBUG_SHOW_GLYPH_BOX
DEBUG_AADRAWBOX(sub_image,0,0,image_width,image_height,0,0,0,255/4);
nscolor black NS_RGB(0,255,0);
blendPixel blendPixelFunc = nsX11AlphaBlend::GetBlendPixel();
// x origin
for (x=0; x<(unsigned int)image_height; x++)
if (x%4==0) (*blendPixelFunc)(sub_image, x_origin, x, black, 255/2);
// y origin
for (y=0; y<(unsigned int)image_width; y++)
if (y%4==0) (*blendPixelFunc)(sub_image, y, ascent-1, black, 255/2);
#endif
FTC_Image_Cache icache;
mFt2->GetImageCache(&icache);
if (!icache)
return 0;
//
// Get aa glyphs and blend with background
//
blendGlyph blendGlyph = nsX11AlphaBlend::GetBlendGlyph();
PRUint32 i, extraSurrogateLength;
for (i=0; i<aLength; i+=1+extraSurrogateLength) {
FT_UInt glyph_index;
FT_Glyph glyph;
nsresult rv;
FT_BBox glyph_bbox;
FT_ULong code_point = aString[i];
extraSurrogateLength = 0;
if(i<aLength-1 && NS_IS_HIGH_SURROGATE(code_point) && NS_IS_LOW_SURROGATE(aString[i+1])) {
// if surrogate, make UCS4 code point from high aString[i] surrogate and
// low surrogate aString[i+1]
code_point = SURROGATE_TO_UCS4(code_point, aString[i+1]);
// skip aString[i+1], it is already used as low surrogate
extraSurrogateLength = 1;
}
mFt2->GetCharIndex(face, code_point, &glyph_index);
if (glyph_index) {
rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph);
}
if ((glyph_index) && (NS_SUCCEEDED(rv))) {
mFt2->GlyphGetCBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox);
}
else {
// draw an empty box for the missing glyphs
GetFallbackGlyphMetrics(&glyph_bbox, face);
int x, y, w = glyph_bbox.xMax, h = glyph_bbox.yMax;
for (x=1; x<w; x++) {
XPutPixel(sub_image, x_pos+x, ascent-1, values.foreground);
XPutPixel(sub_image, x_pos+x, ascent-h, values.foreground);
}
for (y=1; y<h; y++) {
XPutPixel(sub_image, x_pos+1, ascent-y, values.foreground);
XPutPixel(sub_image, x_pos+w-1, ascent-y, values.foreground);
x = (y*(w-2))/h;
XPutPixel(sub_image, x_pos+x+1, ascent-y, values.foreground);
}
x_pos += w + 1;
continue;
}
FT_BitmapGlyph slot = (FT_BitmapGlyph)glyph;
nsAntiAliasedGlyph aaglyph(glyph_bbox.xMax-glyph_bbox.xMin,
glyph_bbox.yMax-glyph_bbox.yMin, 0);
PRUint8 buf[IMAGE_BUFFER_SIZE]; // try to use the stack for data
if (!aaglyph.WrapFreeType(&glyph_bbox, slot, buf, IMAGE_BUFFER_SIZE)) {
NS_ERROR("failed to wrap freetype image");
XDestroyImage(sub_image);
return 0;
}
//
// blend the aa-glyph onto the background
//
NS_ASSERTION(ascent>=glyph_bbox.yMax,"glyph too tall");
NS_ASSERTION(x_pos>=-aaglyph.GetLBearing(),"glyph extends too far to left");
#if DEBUG_SHOW_GLYPH_BOX
// draw box around part of glyph that extends to the left
// of the main area (negative LBearing)
if (aaglyph.GetLBearing() < 0) {
DEBUG_AADRAWBOX(sub_image, x_pos + aaglyph.GetLBearing(),
ascent-glyph_bbox.yMax,
-aaglyph.GetLBearing(), glyph_bbox.yMax, 255,0,0, 255/4);
}
// draw box around main glyph area
DEBUG_AADRAWBOX(sub_image, x_pos, ascent-glyph_bbox.yMax,
aaglyph.GetAdvance(), glyph_bbox.yMax, 0,255,0, 255/4);
// draw box around part of glyph that extends to the right
// of the main area (negative LBearing)
if (aaglyph.GetRBearing() > (int)aaglyph.GetAdvance()) {
DEBUG_AADRAWBOX(sub_image, x_pos + aaglyph.GetAdvance(),
ascent-glyph_bbox.yMax,
aaglyph.GetRBearing()-aaglyph.GetAdvance(),
glyph_bbox.yMax, 0,0,255, 255/4);
}
#endif
(*blendGlyph)(sub_image, &aaglyph, sLinearWeightTable, color,
x_pos + aaglyph.GetLBearing(), ascent-glyph_bbox.yMax);
x_pos += aaglyph.GetAdvance();
}
//
// Send it to the display
//
XPutImage(dpy, win, gc, sub_image, 0, 0, aX-x_origin , aY-ascent,
image_width, image_height);
XDestroyImage(sub_image);
return width;
}
///////////////////////////////////////////////////////////////////////
//
// class nsFreeTypeXImage data/functions
//
///////////////////////////////////////////////////////////////////////
nsFreeTypeXImageSBC::nsFreeTypeXImageSBC()
{
NS_ERROR("should never call nsFreeTypeXImageSBC::nsFreeTypeXImageSBC");
}
nsFreeTypeXImageSBC::nsFreeTypeXImageSBC(nsITrueTypeFontCatalogEntry *aFaceID,
PRUint16 aPixelSize,
const char *aName)
: nsFreeTypeXImage(aFaceID, aPixelSize, aName)
{
}
#ifdef MOZ_MATHML
nsresult
nsFreeTypeXImageSBC::GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics)
{
nsresult res;
char buf[512];
PRInt32 bufLen = sizeof(buf);
PRInt32 stringLen = aLength;
nsCAutoString familyName;
mFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType2::GetCustomEncoderInfo(familyName.get());
NS_ASSERTION(ffei,"failed to find font encoder info");
if (!ffei)
return NS_ERROR_FAILURE;
res = ffei->mEncodingInfo->mConverter->Convert(aString, &stringLen,
buf, &bufLen);
NS_ASSERTION((aLength&&bufLen)||(!aLength&&!bufLen), "converter failed");
//
// Widen to 16 bit
//
PRUnichar unibuf[512];
int i;
for (i=0; i<bufLen; i++) {
unibuf[i] = (unsigned char)buf[i];
}
res = nsFreeTypeXImage::GetBoundingMetrics(unibuf, bufLen, aBoundingMetrics);
return res;
}
#endif
gint
nsFreeTypeXImageSBC::GetWidth(const PRUnichar* aString, PRUint32 aLength)
{
char buf[512];
PRInt32 bufLen = sizeof(buf);
PRInt32 stringLen = aLength;
nsCAutoString familyName;
mFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType2::GetCustomEncoderInfo(familyName.get());
NS_ASSERTION(ffei,"failed to find font encoder info");
if (!ffei)
return 0;
ffei->mEncodingInfo->mConverter->Convert(aString, &stringLen,
buf, &bufLen);
NS_ASSERTION((aLength&&bufLen)||(!aLength&&!bufLen), "converter failed");
//
// Widen to 16 bit
//
PRUnichar unibuf[512];
int i;
for (i=0; i<bufLen; i++) {
unibuf[i] = (unsigned char)buf[i];
}
return nsFreeTypeXImage::GetWidth(unibuf, bufLen);
}
gint
nsFreeTypeXImageSBC::DrawString(nsRenderingContextGTK* aContext,
nsDrawingSurfaceGTK* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength)
{
char buf[512];
PRInt32 bufLen = sizeof(buf);
PRInt32 stringLen = aLength;
nsCAutoString familyName;
mFaceID->GetFamilyName(familyName);
nsTTFontFamilyEncoderInfo *ffei =
nsFreeType2::GetCustomEncoderInfo(familyName.get());
NS_ASSERTION(ffei,"failed to find font encoder info");
if (!ffei)
return 0;
ffei->mEncodingInfo->mConverter->Convert(aString, &stringLen,
buf, &bufLen);
NS_ASSERTION((aLength&&bufLen)||(!aLength&&!bufLen), "converter failed");
//
// Widen to 16 bit
//
PRUnichar unibuf[512];
int i;
for (i=0; i<bufLen; i++) {
unibuf[i] = (unsigned char)buf[i];
}
return nsFreeTypeXImage::DrawString(aContext, aSurface, aX, aY,
unibuf, bufLen);
}
void
GetFallbackGlyphMetrics(FT_BBox *aBoundingBox, FT_Face aFace) {
aBoundingBox->xMin = 0;
aBoundingBox->yMin = 0;
aBoundingBox->xMax = PR_MAX(aFace->size->metrics.x_ppem/2 - 1, 0);
aBoundingBox->yMax = PR_MAX(aFace->size->metrics.y_ppem/2, 1);
}
void
WeightTableInitCorrection(PRUint8* aTable, PRUint8 aMinValue,
double aGain)
{
// setup the wieghting table
for (int i=0; i<256; i++) {
int val = i + (int)rint((double)(i-aMinValue)*aGain);
val = PR_MAX(0, val);
val = PR_MIN(val, 255);
aTable[i] = (PRUint8)val;
}
}
#endif

Просмотреть файл

@ -1,121 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@netscape.com>
* Louie Zhao <louie.zhao@sun.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 nsFontFreeType_h__
#define nsFontFreeType_h__
#include "gfx-config.h"
#include "nsFontMetricsGTK.h"
#include "nsFreeType.h"
#if (!defined(MOZ_ENABLE_FREETYPE2))
class nsFreeTypeFont : public nsFontGTK {
public:
static nsFreeTypeFont *NewFont(nsITrueTypeFontCatalogEntry*,
PRUint16, const char *);
};
#else
class nsFreeTypeFont : public nsFontGTK
{
public:
nsFreeTypeFont();
nsFreeTypeFont(nsITrueTypeFontCatalogEntry *, PRUint16, const char *);
virtual ~nsFreeTypeFont(void);
static nsFreeTypeFont *NewFont(nsITrueTypeFontCatalogEntry*,
PRUint16, const char *);
void LoadFont(void);
virtual GdkFont* GetGDKFont(void);
virtual PRBool GetGDKFontIs10646(void);
virtual PRBool IsFreeTypeFont(void);
virtual gint GetWidth(const PRUnichar* aString, PRUint32 aLength);
virtual gint DrawString(nsRenderingContextGTK* aContext,
nsDrawingSurfaceGTK* aSurface, nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength);
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics);
#endif
virtual nsresult doGetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
PRInt32* aLeftBearing,
PRInt32* aRightBearing,
PRInt32* aAscent,
PRInt32* aDescent,
PRInt32* aWidth);
virtual PRUint32 Convert(const PRUnichar* aSrc, PRUint32 aSrcLen,
PRUnichar* aDest, PRUint32 aDestLen);
FT_Face getFTFace();
int ascent();
int descent();
PRBool getXHeight(unsigned long &val);
int max_ascent();
int max_descent();
int max_width();
PRBool superscript_y(long &val);
PRBool subscript_y(long &val);
PRBool underlinePosition(long &val);
PRBool underline_thickness(unsigned long &val);
FT_Error FaceRequester(FT_Face* aface);
static void FreeGlobals();
static PRUint8 sLinearWeightTable[256];
protected:
XImage *GetXImage(PRUint32 width, PRUint32 height);
nsITrueTypeFontCatalogEntry *mFaceID;
PRUint16 mPixelSize;
FTC_Image_Desc mImageDesc;
nsCOMPtr<nsIFreeType2> mFt2;
};
void WeightTableInitCorrection(PRUint8*, PRUint8, double);
#endif
#endif

Просмотреть файл

@ -1,543 +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):
* Brian Stell <bstell@ix.netcom.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 "nspr.h"
#include "nsCOMPtr.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsNameValuePairDB.h"
#include "nsILocalFile.h"
#define NVPDB_VERSION_MAJOR 1
#define NVPDB_VERSION_MINOR 0
#define NVPDB_VERSION_MAINTENANCE 0
#ifdef DEBUG
# define NVPDB_PRINTF(x) \
PR_BEGIN_MACRO \
printf x ; \
printf(", %s %d\n", __FILE__, __LINE__); \
PR_END_MACRO
#else
# define NVPDB_PRINTF(x)
#endif
PRBool
nsNameValuePairDB::CheckHeader()
{
const char *name, *value;
int num, major, minor, maintenance;
PRBool foundVersion = PR_FALSE;
if (!mFile)
return PR_FALSE;
if (fseek(mFile, 0L, SEEK_SET) != 0)
return PR_FALSE;
mCurrentGroup = 0;
mAtEndOfGroup = PR_FALSE;
while (GetNextElement(&name, &value) > 0) {
if (*name == '\0') // ignore comments
continue;
if (strcmp(name, "Version")==0) {
foundVersion = PR_TRUE;
num = sscanf(value, "%d.%d.%d", &major, &minor, &maintenance);
if (num != 3) {
NVPDB_PRINTF(("failed to parse version number (%s)", value));
return PR_FALSE;
}
// NVPDB_VERSION_MAJOR
// It is presumed that major versions are not backwards compatibile.
if (major != NVPDB_VERSION_MAJOR) {
NVPDB_PRINTF(("version major %d != %d", major, NVPDB_VERSION_MAJOR));
return PR_FALSE;
}
// NVPDB_VERSION_MINOR
// It is presumed that minor versions are backwards compatible
// but will have additional features.
// Put any tests related to minor versions here.
// NVPDB_VERSION_MAINTENANCE
// It is presumed that maintenance versions are backwards compatible,
// have no new features, but can have bug fixes.
// Put any tests related to maintenance versions here.
mMajorNum = major;
mMinorNum = minor;
mMaintenanceNum = maintenance;
}
}
return foundVersion;
}
//
// Re-get an element. Used if the element is bigger than
// the buffer that was first passed in
//
// PRInt32 GetCurrentElement(const char** aName, const char** aValue,
// char *aBuffer, PRUint32 aBufferLen);
//
// to implement this the GetNextElement methods need to save
// the file position so this routine can seek backward to it.
//
PRInt32
nsNameValuePairDB::GetNextElement(const char** aName, const char** aValue)
{
return GetNextElement(aName, aValue, mBuf, sizeof(mBuf));
}
//
// Get the next element
//
// returns 1 if complete element read
// return 0 on end of file
// returns a negative number on error
// if error < -NVPDB_MIN_BUFLEN
// then the value is the negative of the needed buffer len
//
//
PRInt32
nsNameValuePairDB::GetNextElement(const char** aName, const char** aValue,
char *aBuffer, PRUint32 aBufferLen)
{
char *line, *name, *value;
unsigned int num;
int len;
unsigned int groupNum;
*aName = "";
*aValue = "";
if (aBufferLen < NVPDB_MIN_BUFLEN) {
return NVPDB_BUFFER_TOO_SMALL;
}
if (mAtEndOfGroup) {
return NVPDB_END_OF_GROUP;
}
//
// Get a line
//
line = fgets(aBuffer, aBufferLen, mFile);
if (!line) {
if (feof(mFile)) { // end of file
mAtEndOfGroup = PR_TRUE;
mAtEndOfCatalog = PR_TRUE;
return NVPDB_END_OF_FILE;
}
return NVPDB_FILE_IO_ERROR;
}
//
// Check we got a complete line
//
len = strlen(line);
NS_ASSERTION(len!=0, "an empty string is invalid");
if (len == 0)
return NVPDB_GARBLED_LINE;
if (line[len-1] != '\n') {
len++; // space for the line terminator
while (1) {
int val = getc(mFile);
if (val == EOF)
return -len;
len++;
if (val == '\n')
return -len;
}
}
len--;
line[len] = '\0';
//NVPDB_PRINTF(("line = (%s)", line));
//
// Check the group number
//
num = sscanf(line, "%u", &groupNum);
if ((num != 1) || (groupNum != (unsigned)mCurrentGroup))
return NVPDB_END_OF_GROUP;
//
// Get the name
//
name = strchr(line, ' ');
if ((!name) || (name[1]=='\0'))
return NVPDB_GARBLED_LINE;
name++;
//
// If it is a comment
// return a blank name (strlen(*aName)==0)
// return the comment in the value field
//
if (*name == '#') {
*aValue = name;
return 1;
}
//
// Get the value
//
value = strchr(name, '=');
if (!value)
return NVPDB_GARBLED_LINE;
*value = '\0';
value++;
//
// Check for end of group
//
if (strcmp(name,"end")==0) {
mAtEndOfGroup = PR_TRUE;
return NVPDB_END_OF_GROUP;
}
//
// Got the name and value
//
*aName = name;
*aValue = value;
return 1;
}
PRBool
nsNameValuePairDB::GetNextGroup(const char** aType)
{
return GetNextGroup(aType, nsnull, 0);
}
PRBool
nsNameValuePairDB::GetNextGroup(const char** aType, const char* aName)
{
return GetNextGroup(aType, aName, strlen(aName));
}
PRBool
nsNameValuePairDB::GetNextGroup(const char** aType, const char* aName, int aLen)
{
const char *name, *value;
long pos = 0;
*aType = "";
if (mAtEndOfCatalog)
return PR_FALSE;
//
// Move to end of current Group
//
while (GetNextElement(&name, &value) > 0)
continue;
mCurrentGroup++;
mAtEndOfGroup = PR_FALSE;
// save current pos in case this in not the desired type
// and we need to backup
if (aName)
pos = ftell(mFile);
// check if there are more Groups
if (GetNextElement(&name, &value) <= 0) {
mAtEndOfGroup = PR_TRUE;
mAtEndOfCatalog = PR_TRUE;
return PR_FALSE;
}
if (strcmp(name,"begin"))
goto GetNext_Error;
// check if this is the desired type
if (aName) {
if (strncmp(value,aName,aLen)) {
fseek(mFile, pos, SEEK_SET);
mCurrentGroup--;
mAtEndOfGroup = PR_TRUE;
return PR_FALSE;
}
}
*aType = value;
return PR_TRUE;
GetNext_Error:
mError = PR_TRUE;
NVPDB_PRINTF(("GetNext_Error"));
return PR_FALSE;
}
nsNameValuePairDB::nsNameValuePairDB()
{
mFile = nsnull;
mBuf[0] = '\0';
mMajorNum = 0;
mMinorNum = 0;
mMaintenanceNum = 0;
mCurrentGroup = 0;
mAtEndOfGroup = PR_FALSE;
mAtEndOfCatalog = PR_FALSE;
mError = PR_FALSE;
}
nsNameValuePairDB::~nsNameValuePairDB()
{
if (mFile) {
fclose(mFile);
mFile = nsnull;
}
}
PRBool
nsNameValuePairDB::OpenForRead(const nsACString & aCatalogName) // native charset
{
nsresult result;
nsCOMPtr<nsILocalFile> local_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID,
&result);
if (NS_FAILED(result))
goto error_return;
local_file->InitWithNativePath(aCatalogName);
local_file->OpenANSIFileDesc("r", &mFile);
if (mFile && CheckHeader())
return PR_TRUE;
error_return:
mError = PR_TRUE;
NVPDB_PRINTF(("OpenForRead error"));
return PR_FALSE;
}
PRBool
nsNameValuePairDB::OpenTmpForWrite(const nsACString& aCatalogName) // native charset
{
nsresult result;
nsCOMPtr<nsILocalFile> local_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID,
&result);
if (NS_FAILED(result))
return PR_FALSE;
local_file->InitWithNativePath(aCatalogName + NS_LITERAL_CSTRING(".tmp"));
local_file->OpenANSIFileDesc("w+", &mFile);
if (mFile == nsnull)
return PR_FALSE;
// Write the header
mAtEndOfGroup = PR_TRUE;
mCurrentGroup = -1;
PutStartGroup("Header");
char buf[64];
PutElement("", "########################################");
PutElement("", "# #");
PutElement("", "# Name Value Pair DB #");
PutElement("", "# #");
PutElement("", "# This is a program generated file #");
PutElement("", "# #");
PutElement("", "# Do not edit #");
PutElement("", "# #");
PutElement("", "########################################");
PR_snprintf(buf, sizeof(buf), "%d.%d.%d", NVPDB_VERSION_MAJOR,
NVPDB_VERSION_MINOR, NVPDB_VERSION_MAINTENANCE);
PutElement("Version", buf);
PutEndGroup("Header");
return PR_TRUE;
}
PRBool
nsNameValuePairDB::PutElement(const char* aName, const char* aValue)
{
if (mAtEndOfGroup) {
mError = PR_TRUE;
NVPDB_PRINTF(("PutElement_Error"));
return PR_FALSE;
}
if ((!*aName) && (*aValue == '#'))
fprintf(mFile, "%u %s\n", mCurrentGroup, aValue);
else
fprintf(mFile, "%u %s=%s\n", mCurrentGroup, aName, aValue);
#ifdef DEBUG
fflush(mFile);
#endif
return PR_TRUE;
}
PRBool
nsNameValuePairDB::PutEndGroup(const char* aType)
{
if (mAtEndOfGroup) {
mError = PR_TRUE;
NVPDB_PRINTF(("PutEndGroup_Error"));
return PR_FALSE;
}
mAtEndOfGroup = PR_TRUE;
fprintf(mFile, "%u end=%s\n", mCurrentGroup, aType);
#ifdef DEBUG
fflush(mFile);
#endif
return PR_TRUE;
}
PRBool
nsNameValuePairDB::PutStartGroup(const char* aType)
{
if (!mAtEndOfGroup) {
mError = PR_TRUE;
NVPDB_PRINTF(("PutStartGroup_Error"));
#ifdef DEBUG
fflush(mFile);
#endif
return PR_FALSE;
}
mAtEndOfGroup = PR_FALSE;
mCurrentGroup++;
fprintf(mFile, "%u begin=%s\n", mCurrentGroup, aType);
#ifdef DEBUG
fflush(mFile);
#endif
return PR_TRUE;
}
PRBool
nsNameValuePairDB::RenameTmp(const char* aCatalogName)
{
nsresult rv;
nsCOMPtr<nsILocalFile> dir;
PRBool exists = PR_FALSE;
nsCAutoString old_name(aCatalogName);
nsDependentCString current_name(aCatalogName);
nsCAutoString tmp_name(aCatalogName);
nsCAutoString old_name_tail;
nsCAutoString current_name_tail;
nsCOMPtr<nsILocalFile> old_file;
nsCOMPtr<nsILocalFile> current_file;
nsCOMPtr<nsILocalFile> tmp_file;
nsCAutoString parent_dir;
nsCAutoString parent_path;
nsCAutoString cur_path;
//
// Split the parent dir and file name
//
PRInt32 slash = 0, last_slash = -1;
nsCAutoString fontDirName(aCatalogName);
// RFindChar not coded so do it by hand
while ((slash=fontDirName.FindChar('/', slash))>=0) {
last_slash = slash;
slash++;
}
if (last_slash < 0)
goto Rename_Error;
fontDirName.Left(parent_dir, last_slash);
dir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv))
goto Rename_Error;
dir->InitWithNativePath(parent_dir);
dir->GetNativePath(parent_path);
if (!mAtEndOfGroup || mError)
goto Rename_Error;
//
// check that we have a tmp copy
//
tmp_name.Append(".tmp");
tmp_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv))
goto Rename_Error;
tmp_file->InitWithNativePath(tmp_name);
tmp_file->Exists(&exists);
if (!exists)
goto Rename_Error;
//
// get rid of any old copy
//
old_name.Append(".old");
old_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv))
goto Rename_Error;
old_file->InitWithNativePath(old_name);
//
// Check we have a current copy
//
current_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
if (NS_FAILED(rv))
goto Rename_Error;
current_file->InitWithNativePath(current_name);
current_file->Exists(&exists);
if (exists) {
//
// Rename the current copy to old
//
current_file->GetNativePath(cur_path);
old_name.Right(old_name_tail, old_name.Length() - last_slash - 1);
rv = current_file->MoveToNative(dir, old_name_tail);
if (NS_FAILED(rv))
goto Rename_Error;
}
//
// Rename the tmp to current
//
current_name_tail = Substring(current_name, last_slash+1,
current_name.Length() - (last_slash + 1));
rv = tmp_file->MoveToNative(dir, current_name_tail);
if (NS_FAILED(rv))
goto Rename_Error;
//
// remove the previous copy
//
if (exists) {
old_file->Remove(PR_FALSE);
}
return PR_TRUE;
Rename_Error:
mError = PR_TRUE;
NVPDB_PRINTF(("Rename_Error"));
return PR_FALSE;
}

Просмотреть файл

@ -1,94 +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):
* Brian Stell <bstell@ix.netcom.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 NSNAMEVALUEPAIRDB_H
#define NSNAMEVALUEPAIRDB_H
#include "nsString.h"
#define FC_BUF_LEN 1024
#define NVPDB_MIN_BUFLEN 100
//
// Errors
//
#define NVPDB_END_OF_FILE 0
#define NVPDB_BUFFER_TOO_SMALL -1
#define NVPDB_END_OF_GROUP -2
#define NVPDB_FILE_IO_ERROR -3
#define NVPDB_GARBLED_LINE -4
class nsNameValuePairDB {
public:
nsNameValuePairDB();
~nsNameValuePairDB();
inline PRBool HadError() { return mError; };
// implement this to re-read an element if it is larger than the buffer
// PRInt32 GetCurrentElement(const char** aName, const char** aValue,
// char *aBuffer, PRUint32 aBufferLen);
PRBool GetNextGroup(const char** aType);
PRBool GetNextGroup(const char** aType, const char* aName);
PRBool GetNextGroup(const char** aType, const char* aName, int aLen);
PRInt32 GetNextElement(const char** aName, const char** aValue);
PRInt32 GetNextElement(const char** aName, const char** aValue,
char *aBuffer, PRUint32 aBufferLen);
PRBool OpenForRead(const nsACString& aCatalogName); // native charset
PRBool OpenTmpForWrite(const nsACString& aCatalogName); // native charset
PRBool PutElement(const char* aName, const char* aValue);
PRBool PutEndGroup(const char* aType);
PRBool PutStartGroup(const char* aType);
PRBool RenameTmp(const char* aCatalogName);
protected:
PRBool CheckHeader();
PRUint16 mMajorNum;
PRUint16 mMinorNum;
PRUint16 mMaintenanceNum;
FILE* mFile;
char mBuf[FC_BUF_LEN];
PRInt32 mCurrentGroup;
PRPackedBool mAtEndOfGroup;
PRPackedBool mAtEndOfCatalog;
PRPackedBool mError;
private:
};
#endif /* NSNAMEVALUEPAIRDB_H */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,106 +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 Netscape.com 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):
* Brian Stell <bstell@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 nsX11AlphaBlend_h__
#define nsX11AlphaBlend_h__
#include <X11/Xlib.h>
#include "nsColor.h"
class nsAntiAliasedGlyph;
#ifdef DEBUG
#ifndef DEBUG_SHOW_GLYPH_BOX
# define DEBUG_SHOW_GLYPH_BOX 0
#endif
void AADrawBox(XImage *, PRInt32, PRInt32, PRInt32, PRInt32, nscolor, PRUint8);
#if DEBUG_SHOW_GLYPH_BOX
# define DEBUG_AADRAWBOX(i,x,y,w,h,r,g,b,a) \
PR_BEGIN_MACRO \
nscolor color NS_RGB((r),(g),(b)); \
AADrawBox((i), (x), (y), (w), (h), color, (a)); \
PR_END_MACRO
#else
# define DEBUG_AADRAWBOX(i,x,y,w,h,r,g,b,a)
#endif
#endif
void nsX11AlphaBlendFreeGlobals(void);
nsresult nsX11AlphaBlendInitGlobals(Display *dsp);
typedef void (*blendGlyph)(XImage *, nsAntiAliasedGlyph *, PRUint8*,
nscolor, int, int);
typedef void (*blendPixel)(XImage *, int, int, nscolor, int);
typedef nscolor (*pixelToNSColor)(unsigned long aPixel);
///////////////////////////////////////////////////////////////////////
//
// class nsX11AlphaBlend class definition
//
///////////////////////////////////////////////////////////////////////
class nsX11AlphaBlend {
public:
inline static PRBool CanAntiAlias() { return sAvailable; };
inline static blendPixel GetBlendPixel() { return sBlendPixel; };
inline static blendGlyph GetBlendGlyph() { return sBlendMonoImage; };
static XImage* GetXImage(PRUint32 width, PRUint32 height);
static void FreeGlobals();
static nsresult InitGlobals(Display *dsp);
static XImage* GetBackground(Display *, int, Drawable,
PRInt32, PRInt32, PRUint32, PRUint32);
static nscolor PixelToNSColor(unsigned long aPixel);
protected:
static void ClearGlobals();
static void ClearFunctions();
static PRBool InitLibrary(Display *dsp);
static PRBool sAvailable;
static PRUint16 sBitmapPad;
static PRUint16 sBitsPerPixel;
static blendGlyph sBlendMonoImage;
static blendPixel sBlendPixel;
static PRUint16 sBytesPerPixel;
static int sDepth;
static PRBool sInited;
static pixelToNSColor sPixelToNSColor;
};
#endif /* nsX11AlphaBlend_h__ */

Просмотреть файл

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@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 nsXFont_h__
#define nsXFont_h__
class nsXFont {
public:
virtual ~nsXFont() { };
virtual void DrawText8(GdkDrawable *Drawable, GdkGC *GC, PRInt32,
PRInt32, const char *, PRUint32) = 0;
virtual void DrawText16(GdkDrawable *Drawable, GdkGC *GC, PRInt32,
PRInt32, const XChar2b *, PRUint32) = 0;
virtual PRBool GetXFontProperty(Atom, unsigned long *) = 0;
virtual XFontStruct *GetXFontStruct() = 0;
inline PRBool IsSingleByte() { return mIsSingleByte; };
virtual PRBool LoadFont() = 0;
virtual void TextExtents8(const char *, PRUint32, PRInt32*, PRInt32*,
PRInt32*, PRInt32*, PRInt32*) = 0;
virtual void TextExtents16(const XChar2b *, PRUint32, PRInt32*,
PRInt32*, PRInt32*, PRInt32*, PRInt32*) =0;
virtual PRInt32 TextWidth8(const char *, PRUint32) = 0;
virtual PRInt32 TextWidth16(const XChar2b *, PRUint32) = 0;
//protected:
virtual void UnloadFont() = 0;
protected:
PRBool mIsSingleByte;
};
#endif /* nsXFont_h__ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,126 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@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 nsXFontAAScaledBitmap_h__
#define nsXFontAAScaledBitmap_h__
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include "nspr.h"
#include "nsXFont.h"
#include "nsAntiAliasedGlyph.h"
extern PRUint8 gAASBDarkTextMinValue;
extern double gAASBDarkTextGain;
extern PRUint8 gAASBLightTextMinValue;
extern double gAASBLightTextGain;
#define SCALED_SIZE(x) (PRInt32)(rint(((double)(x))*mRatio))
class nsHashtable;
class nsXFontAAScaledBitmap : public nsXFont {
public:
// we use PRUint16 instead of PRUint32 for the final two arguments in this
// constructor to work around a GCC 2.95[.3] bug which would otherwise cause
// these parameters to be corrupted in the callee. n.b. at the time of
// writing the only caller is passing PRUint16 values anyway (and within
// the constructor we go on toassign a parameter to a PRUint16-sized member
// variable) so semantically nothing is lost.
nsXFontAAScaledBitmap(Display *aDisplay, int aScreen, GdkFont *,
PRUint16, PRUint16);
~nsXFontAAScaledBitmap();
void DrawText8(GdkDrawable *Drawable, GdkGC *GC, PRInt32, PRInt32,
const char *, PRUint32);
void DrawText16(GdkDrawable *Drawable, GdkGC *GC, PRInt32, PRInt32,
const XChar2b *, PRUint32);
PRBool GetXFontProperty(Atom, unsigned long *);
XFontStruct *GetXFontStruct();
PRBool LoadFont();
void TextExtents8(const char *, PRUint32, PRInt32*, PRInt32*,
PRInt32*, PRInt32*, PRInt32*);
void TextExtents16(const XChar2b *, PRUint32, PRInt32*, PRInt32*,
PRInt32*, PRInt32*, PRInt32*);
PRInt32 TextWidth8(const char *, PRUint32);
PRInt32 TextWidth16(const XChar2b *, PRUint32);
void UnloadFont();
public:
static PRBool InitGlobals(Display *aDisplay, int aScreen);
static void FreeGlobals();
protected:
void DrawText8or16(GdkDrawable *Drawable, GdkGC *GC, PRInt32,
PRInt32, void *, PRUint32);
void TextExtents8or16(void *, PRUint32, PRInt32*, PRInt32*,
PRInt32*, PRInt32*, PRInt32*);
PRBool GetScaledGreyImage(const char *, nsAntiAliasedGlyph **);
#ifdef DEBUG
void dump_XImage_blue_data(XImage *ximage);
#endif
static PRBool DisplayIsLocal(Display *);
protected:
PRBool mAlreadyLoaded;
Display *mDisplay;
GC mForegroundGC;
GdkFont *mGdkFont;
nsHashtable* mGlyphHash;
double mRatio;
XFontStruct mScaledFontInfo;
GlyphMetrics mScaledMax;
int mScreen;
Pixmap mUnscaledBitmap;
XFontStruct *mUnscaledFontInfo;
GlyphMetrics mUnscaledMax;
PRUint16 mUnscaledSize;
// class globals
protected:
static Display *sDisplay;
static GC sBackgroundGC; // used to clear the pixmaps
// before drawing the glyph
static PRUint8 sWeightedScaleDarkText[256];
static PRUint8 sWeightedScaleLightText[256];
};
#endif /* nsXFontAAScaledBitmap_h__ */

Просмотреть файл

@ -1,152 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@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 "gfx-config.h"
#include "nscore.h"
#include "nsXFontNormal.h"
#include "nsRenderingContextGTK.h"
#include "nsGdkUtils.h"
void
nsXFontNormal::DrawText8(GdkDrawable *aDrawable, GdkGC *aGC,
PRInt32 aX, PRInt32 aY,
const char *aString, PRUint32 aLength)
{
my_gdk_draw_text(aDrawable, mGdkFont, aGC, aX, aY, aString, aLength);
}
void
nsXFontNormal::DrawText16(GdkDrawable *aDrawable, GdkGC *aGC,
PRInt32 aX, PRInt32 aY,
const XChar2b *aString, PRUint32 aLength)
{
my_gdk_draw_text(aDrawable, mGdkFont, aGC, aX, aY,
(const char *)aString, aLength*2);
}
PRBool
nsXFontNormal::GetXFontProperty(Atom aAtom, unsigned long *aValue)
{
NS_ASSERTION(mGdkFont, "GetXFontProperty called before font loaded");
if (mGdkFont==nsnull)
return PR_FALSE;
XFontStruct *fontInfo = (XFontStruct *)GDK_FONT_XFONT(mGdkFont);
return ::XGetFontProperty(fontInfo, aAtom, aValue);
}
XFontStruct *
nsXFontNormal::GetXFontStruct()
{
NS_ASSERTION(mGdkFont, "GetXFontStruct called before font loaded");
if (mGdkFont==nsnull)
return nsnull;
return (XFontStruct *)GDK_FONT_XFONT(mGdkFont);
}
PRBool
nsXFontNormal::LoadFont()
{
if (!mGdkFont)
return PR_FALSE;
XFontStruct *fontInfo = (XFontStruct *)GDK_FONT_XFONT(mGdkFont);
mIsSingleByte = (fontInfo->min_byte1 == 0) && (fontInfo->max_byte1 == 0);
return PR_TRUE;
}
nsXFontNormal::nsXFontNormal(GdkFont *aGdkFont)
{
mGdkFont = ::gdk_font_ref(aGdkFont);
}
void
nsXFontNormal::TextExtents8(const char *aString, PRUint32 aLength,
PRInt32* aLBearing, PRInt32* aRBearing,
PRInt32* aWidth, PRInt32* aAscent,
PRInt32* aDescent)
{
gdk_text_extents(mGdkFont, aString, aLength,
aLBearing, aRBearing, aWidth, aAscent, aDescent);
}
void
nsXFontNormal::TextExtents16(const XChar2b *aString, PRUint32 aLength,
PRInt32* aLBearing, PRInt32* aRBearing,
PRInt32* aWidth, PRInt32* aAscent,
PRInt32* aDescent)
{
gdk_text_extents(mGdkFont, (const char *)aString, aLength*2,
aLBearing, aRBearing, aWidth, aAscent, aDescent);
}
PRInt32
nsXFontNormal::TextWidth8(const char *aString, PRUint32 aLength)
{
NS_ASSERTION(mGdkFont, "TextWidth8 called before font loaded");
if (mGdkFont==nsnull)
return 0;
PRInt32 width = gdk_text_width(mGdkFont, aString, aLength);
return width;
}
PRInt32
nsXFontNormal::TextWidth16(const XChar2b *aString, PRUint32 aLength)
{
NS_ASSERTION(mGdkFont, "TextWidth16 called before font loaded");
if (mGdkFont==nsnull)
return 0;
PRInt32 width = gdk_text_width(mGdkFont, (const char *)aString, aLength*2);
return width;
}
void
nsXFontNormal::UnloadFont()
{
delete this;
}
nsXFontNormal::~nsXFontNormal()
{
if (mGdkFont) {
::gdk_font_unref(mGdkFont);
}
}

Просмотреть файл

@ -1,73 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* ***** 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):
* Brian Stell <bstell@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 nsXFontNormal_h__
#define nsXFontNormal_h__
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include "nspr.h"
#include "nsXFont.h"
class nsXFontNormal : public nsXFont {
public:
nsXFontNormal(GdkFont *);
~nsXFontNormal();
void DrawText8(GdkDrawable *Drawable, GdkGC *GC, PRInt32, PRInt32,
const char *, PRUint32);
void DrawText16(GdkDrawable *Drawable, GdkGC *GC, PRInt32, PRInt32,
const XChar2b *, PRUint32);
PRBool GetXFontProperty(Atom, unsigned long *);
XFontStruct *GetXFontStruct();
PRBool LoadFont();
void TextExtents8(const char *, PRUint32, PRInt32*, PRInt32*,
PRInt32*, PRInt32*, PRInt32*);
void TextExtents16(const XChar2b *, PRUint32, PRInt32*, PRInt32*,
PRInt32*, PRInt32*, PRInt32*);
PRInt32 TextWidth8(const char *, PRUint32);
PRInt32 TextWidth16(const XChar2b *, PRUint32);
void UnloadFont();
protected:
GdkFont *mGdkFont;
};
#endif /* nsXFontNormal_h__ */

Просмотреть файл

@ -276,9 +276,6 @@ else # Platform-specific GFX layer
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
COMPONENT_LIBS += gfx_mac
endif
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
COMPONENT_LIBS += gfx_gtk
endif
ifdef MOZ_ENABLE_PHOTON
COMPONENT_LIBS += gfx_photon
endif

Просмотреть файл

@ -82,9 +82,7 @@
#ifdef MOZ_CAIRO_GFX
# define GFX_MODULES MODULE(nsGfxModule)
#else
# if defined(MOZ_WIDGET_GTK2)
# define GFX_MODULES MODULE(nsGfxGTKModule)
# elif defined(MOZ_WIDGET_PHOTON)
# if defined(MOZ_WIDGET_PHOTON)
# define GFX_MODULES MODULE(nsGfxPhModule)
# elif defined(XP_WIN)
# define GFX_MODULES MODULE(nsGfxModule)

Просмотреть файл

@ -69,15 +69,13 @@ REQUIRES = xpcom \
layout \
util \
locale \
thebes \
cairo \
$(NULL)
ifeq ($(MOZ_ENABLE_CAIRO_GFX),1)
REQUIRES += thebes cairo
ifeq ($(MOZ_ENABLE_GLITZ),1)
REQUIRES += glitz glitzglx
endif
endif
CSRCS = \
mozcontainer.c \
@ -130,11 +128,9 @@ EXTRA_DSO_LDOPTS += \
$(MOZ_STARTUP_NOTIFICATION_LIBS) \
$(XLDFLAGS) \
$(XLIBS) \
$(MOZ_GTK2_LIBS)
ifeq ($(MOZ_ENABLE_CAIRO_GFX),1)
EXTRA_DSO_LDOPTS += -lthebes
endif
$(MOZ_GTK2_LIBS) \
-lthebes \
$(NULL)
EXPORTS = \
nsIGdkPixbufImage.h \
@ -156,10 +152,7 @@ CFLAGS += $(MOZ_GTK2_CFLAGS) $(MOZ_STARTUP_NOTIFICATION_CFLAGS)
CXXFLAGS += $(MOZ_GTK2_CFLAGS) $(MOZ_STARTUP_NOTIFICATION_CFLAGS)
DEFINES += -DUSE_XIM
ifdef MOZ_ENABLE_CAIRO_GFX
DEFINES += -DCAIRO_GFX
endif
ifdef MOZ_ENABLE_POSTSCRIPT
DEFINES += -DUSE_POSTSCRIPT

Просмотреть файл

@ -390,22 +390,9 @@ nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK()
delete mPrintJob;
}
#ifdef MOZ_CAIRO_GFX
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK,
nsIDeviceContextSpec)
#else
/* Use only PostScript module */
#if defined(USE_POSTSCRIPT)
NS_IMPL_ISUPPORTS2(nsDeviceContextSpecGTK,
nsIDeviceContextSpec,
nsIDeviceContextSpecPS)
#else
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK,
nsIDeviceContextSpec)
#endif
#endif
#ifdef MOZ_CAIRO_GFX
//#define USE_PDF 1
#include "gfxPDFSurface.h"
#include "gfxPSSurface.h"
@ -447,7 +434,6 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurfac
return NS_OK;
}
#endif
/** -------------------------------------------------------
* Initialize the nsDeviceContextSpecGTK

Просмотреть файл

@ -45,12 +45,6 @@
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
#ifndef MOZ_CAIRO_GFX
#ifdef USE_POSTSCRIPT
#include "nsIDeviceContextSpecPS.h"
#endif /* USE_POSTSCRIPT */
#endif
#include "nsCRT.h" /* should be <limits.h>? */
#include "nsIPrintJobGTK.h"
@ -65,20 +59,13 @@ typedef enum
} PrintMethod;
class nsDeviceContextSpecGTK : public nsIDeviceContextSpec
#ifndef MOZ_CAIRO_GFX
#ifdef USE_POSTSCRIPT
, public nsIDeviceContextSpecPS
#endif /* USE_POSTSCRIPT */
#endif
{
public:
nsDeviceContextSpecGTK();
NS_DECL_ISUPPORTS
#ifdef MOZ_CAIRO_GFX
NS_IMETHOD GetSurfaceForPrinter(gfxASurface **surface);
#endif
NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPS, PRBool aIsPrintPreview);
NS_IMETHOD ClosePrintManager();

Просмотреть файл

@ -58,10 +58,8 @@
#include <gdk/gdkx.h>
#include "nsCRT.h"
#ifdef MOZ_CAIRO_GFX
#include "gfxASurface.h"
#include "nsImageToPixbuf.h"
#endif
static PRLogModuleInfo *sDragLm = NULL;
@ -203,7 +201,6 @@ nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
1,
&event);
#ifdef MOZ_CAIRO_GFX
GdkPixbuf* dragPixbuf = nsnull;
nsRect dragRect;
if (mHasImage || mSelection) {
@ -222,10 +219,7 @@ nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
mScreenY - NSToIntRound(dragRect.y));
else
gtk_drag_set_icon_default(context);
#else
// use a default icon
gtk_drag_set_icon_default(context);
#endif
gtk_target_list_unref(sourceList);
}

Просмотреть файл

@ -37,11 +37,9 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#ifdef MOZ_CAIRO_GFX
#include "gfxASurface.h"
#include "gfxImageSurface.h"
#include "gfxContext.h"
#endif
#include "nsIGdkPixbufImage.h"
@ -70,7 +68,6 @@ nsImageToPixbuf::ConvertImageToPixbuf(nsIImage* aImage)
GdkPixbuf*
nsImageToPixbuf::ImageToPixbuf(nsIImage* aImage)
{
#ifdef MOZ_CAIRO_GFX
PRInt32 width = aImage->GetWidth(),
height = aImage->GetHeight();
@ -78,15 +75,8 @@ nsImageToPixbuf::ImageToPixbuf(nsIImage* aImage)
aImage->GetSurface(getter_AddRefs(surface));
return SurfaceToPixbuf(surface, width, height);
#else
nsCOMPtr<nsIGdkPixbufImage> img(do_QueryInterface(aImage));
if (img)
return img->GetGdkPixbuf();
return NULL;
#endif
}
#ifdef MOZ_CAIRO_GFX
GdkPixbuf*
nsImageToPixbuf::SurfaceToPixbuf(gfxASurface* aSurface, PRInt32 aWidth, PRInt32 aHeight)
{
@ -162,4 +152,3 @@ nsImageToPixbuf::SurfaceToPixbuf(gfxASurface* aSurface, PRInt32 aWidth, PRInt32
return pixbuf;
}
#endif

Просмотреть файл

@ -50,10 +50,8 @@ class nsImageToPixbuf : public nsIImageToPixbuf {
// Friendlier version of ConvertImageToPixbuf for callers inside of
// widget
static GdkPixbuf* ImageToPixbuf(nsIImage* aImage);
#ifdef MOZ_CAIRO_GFX
static GdkPixbuf* SurfaceToPixbuf(gfxASurface* aSurface,
PRInt32 aWidth, PRInt32 aHeight);
#endif
private:
~nsImageToPixbuf() {}
};

Просмотреть файл

@ -63,11 +63,9 @@
#include <gdk/gdkprivate.h>
#include <gdk/gdkx.h>
#ifdef MOZ_CAIRO_GFX
#include "gfxContext.h"
#include "gfxPlatformGtk.h"
#include "gfxXlibNativeRenderer.h"
#endif
NS_IMPL_ISUPPORTS2(nsNativeThemeGTK, nsITheme, nsIObserver)
@ -463,7 +461,6 @@ NativeThemeErrorHandler(Display* dpy, XErrorEvent* error) {
return 0;
}
#ifdef MOZ_CAIRO_GFX
class ThemeRenderer : public gfxXlibNativeRenderer {
public:
ThemeRenderer(GtkWidgetState aState, GtkThemeWidgetType aGTKWidgetType,
@ -525,7 +522,6 @@ ThemeRenderer::NativeDraw(Display* dpy, Drawable drawable, Visual* visual,
g_object_unref(G_OBJECT(gdkPixmap));
return NS_OK;
}
#endif
static PRBool
GetExtraSizeForWidget(PRUint8 aWidgetType, nsIntMargin* aExtra)
@ -571,55 +567,6 @@ nsNativeThemeGTK::DrawWidgetBackground(nsIRenderingContext* aContext,
&flags))
return NS_OK;
#ifndef MOZ_CAIRO_GFX
GdkWindow* window = NS_STATIC_CAST(GdkWindow*,
aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_GDK_DRAWABLE));
nsTransform2D* transformMatrix;
aContext->GetCurrentTransform(transformMatrix);
nsRect tr(aRect);
transformMatrix->TransformCoord(&tr.x, &tr.y, &tr.width, &tr.height);
GdkRectangle gdk_rect = {tr.x, tr.y, tr.width, tr.height};
nsRect cr(aClipRect);
transformMatrix->TransformCoord(&cr.x, &cr.y, &cr.width, &cr.height);
GdkRectangle gdk_clip = {cr.x, cr.y, cr.width, cr.height};
NS_ASSERTION(!IsWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType),
"Trying to render an unsafe widget!");
PRBool safeState = IsWidgetStateSafe(mSafeWidgetStates, aWidgetType, &state);
XErrorHandler oldHandler = nsnull;
if (!safeState) {
gLastXError = 0;
oldHandler = XSetErrorHandler(NativeThemeErrorHandler);
}
moz_gtk_widget_paint(gtkWidgetType, window, &gdk_rect, &gdk_clip, &state,
flags);
if (!safeState) {
gdk_flush();
XSetErrorHandler(oldHandler);
if (gLastXError) {
#ifdef DEBUG
printf("GTK theme failed for widget type %d, error was %d, state was "
"[active=%d,focused=%d,inHover=%d,disabled=%d]\n",
aWidgetType, gLastXError, state.active, state.focused,
state.inHover, state.disabled);
#endif
NS_WARNING("GTK theme failed; disabling unsafe widget");
SetWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType);
// force refresh of the window, because the widget was not
// successfully drawn it must be redrawn using the default look
RefreshWidgetWindow(aFrame);
} else {
SetWidgetStateSafe(mSafeWidgetStates, aWidgetType, &state);
}
}
#else
nsCOMPtr<nsIDeviceContext> dctx = nsnull;
aContext->GetDeviceContext(*getter_AddRefs(dctx));
PRInt32 p2a = dctx->AppUnitsPerDevPixel();
@ -706,7 +653,6 @@ nsNativeThemeGTK::DrawWidgetBackground(nsIRenderingContext* aContext,
SetWidgetStateSafe(mSafeWidgetStates, aWidgetType, &state);
}
}
#endif
return NS_OK;
}

Просмотреть файл

@ -104,7 +104,6 @@ static const char sAccessibilityKey [] = "config.use_system_prefs.accessibility"
#include "nsIInterfaceRequestorUtils.h"
#include "nsAutoPtr.h"
#ifdef MOZ_CAIRO_GFX
#include "gfxPlatformGtk.h"
#include "gfxXlibSurface.h"
#include "gfxContext.h"
@ -114,7 +113,6 @@ static const char sAccessibilityKey [] = "config.use_system_prefs.accessibility"
#include "gfxGlitzSurface.h"
#include "glitz-glx.h"
#endif
#endif
/* For PrepareNativeWidget */
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
@ -464,11 +462,9 @@ nsWindow::Destroy(void)
// window this isn't going to harm anything.
mWindowGroup = nsnull;
#ifdef MOZ_CAIRO_GFX
// Destroy thebes surface now. Badness can happen if we destroy
// the surface after its X Window.
mThebesSurface = nsnull;
#endif
if (mDragMotionTimerID) {
gtk_timeout_remove(mDragMotionTimerID);
@ -1652,7 +1648,6 @@ nsWindow::OnExposeEvent(GtkWidget *aWidget, GdkEventExpose *aEvent)
nsCOMPtr<nsIRenderingContext> rc = getter_AddRefs(GetRenderingContext());
#ifdef MOZ_CAIRO_GFX
PRBool translucent;
GetWindowTranslucency(translucent);
nsIntRect boundsRect;
@ -1722,16 +1717,17 @@ nsWindow::OnExposeEvent(GtkWidget *aWidget, GdkEventExpose *aEvent)
}
#endif // MOZ_ENABLE_GLITZ
}
#endif // MOZ_CAIRO_GFX
#if 0
// NOTE: Paint flashing region would be wrong for cairo, since
// cairo inflates the update region, etc. So don't paint flash
// for cairo.
#if !defined(MOZ_CAIRO_GFX) && defined(DEBUG)
#ifdef DEBUG
if (WANT_PAINT_FLASHING && aEvent->window)
gdk_window_flash(aEvent->window, 1, 100, aEvent->region);
#endif // !defined(MOZ_CAIRO_GFX) && defined(DEBUG)
#endif
#endif
nsPaintEvent event(PR_TRUE, NS_PAINT, this);
event.refPoint.x = aEvent->area.x;
event.refPoint.y = aEvent->area.y;
@ -1745,8 +1741,6 @@ nsWindow::OnExposeEvent(GtkWidget *aWidget, GdkEventExpose *aEvent)
// DispatchEvent can Destroy us (bug 378273), avoid doing any paint
// operations below if that happened - it will lead to XError and exit().
if (NS_LIKELY(!mIsDestroyed)) {
#ifdef MOZ_CAIRO_GFX
if (status != nsEventStatus_eIgnore) {
if (translucent) {
nsRefPtr<gfxPattern> pattern = ctx->PopGroup();
@ -1794,8 +1788,6 @@ nsWindow::OnExposeEvent(GtkWidget *aWidget, GdkEventExpose *aEvent)
}
ctx->Restore();
#endif // MOZ_CAIRO_GFX
}
g_free(rects);
@ -5728,7 +5720,6 @@ IM_get_input_context(nsWindow *aWindow)
#endif
#ifdef MOZ_CAIRO_GFX
// return the gfxASurface for rendering to this widget
gfxASurface*
nsWindow::GetThebesSurface()
@ -5791,4 +5782,3 @@ nsWindow::GetThebesSurface()
return mThebesSurface;
}
#endif

Просмотреть файл

@ -350,9 +350,7 @@ public:
NS_IMETHOD UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas);
#endif
#ifdef MOZ_CAIRO_GFX
gfxASurface *GetThebesSurface();
#endif
#ifdef ACCESSIBILITY
static PRBool sAccessibilityEnabled;
@ -386,9 +384,7 @@ private:
PRUint32 mTransparencyBitmapWidth;
PRUint32 mTransparencyBitmapHeight;
#ifdef MOZ_CAIRO_GFX
nsRefPtr<gfxASurface> mThebesSurface;
#endif
#ifdef ACCESSIBILITY
nsCOMPtr<nsIAccessible> mRootAccessible;

Просмотреть файл

@ -93,7 +93,7 @@ bin/xpicleanup
bin/res/cmessage.txt
; this is used by gtk embedding clients
bin/libgtkembedmoz.so
; This is used by libgfxps and libgfx_gtk
; This is used by libgfxps
bin/libgfxpsshar.so
bin/components/alerts.xpt
bin/components/libaccessibility.so
@ -159,7 +159,6 @@ bin/components/composer.xpt
bin/components/libdocshell.so
bin/components/libeditor.so
bin/components/libembedcomponents.so
bin/components/libgfx_gtk.so
bin/components/libgfxps.so
bin/components/libgfxxprint.so
bin/components/libimglib2.so