[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
darin
darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:57:32 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 7aac3c0520031a66f4625d8ce6e4ae309ee65644
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Mar 15 15:49:54 2002 +0000
Optimizations for creating empty QFont objects, measuring certain single
characters, and copying QFontMetrics objects. Makes loading NSView.html about
18% faster.
* src/kwq/qt/qfontmetrics.h: Use a ref-counted pointer so QFontMetrics objects
for the same QFont can share data.
* src/kwq/KWQFont.mm: (loadDefaultFont): New, used to load the default
font used for default-initialized QFont objects.
(QFont::_initializeWithFont): Don't recompute theh family name, point size, or
traits.
(QFont::setFamily), (QFont::setPixelSizeFloat), (QFont::setWeight),
(QFont::setItalic),: autorelease the font, as we do in the destructor, since
someone could still be using the result of getFont.
(QFont::operator==): Add a comment about a problem with this function.
* src/kwq/KWQFontMetrics.mm: (QFontMetrics::QFontMetrics): Add a refCount, and
a cached width for space and lower-case "x", the two single characters that
are often measured.
(QFontMetrics::~QFontMetrics): Simplify.
(QFontMetrics::operator=): Just copy the underlying data pointer rather than
making our own KWQLayoutInfo object.
(QFontMetrics::baselineOffset): Make const.
(QFontMetrics::width): Add the caching for space and "x".
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@748 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index df5fc1c..a1c534a 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,3 +1,30 @@
+2002-03-15 Darin Adler <darin at apple.com>
+
+ Optimizations for creating empty QFont objects, measuring certain single
+ characters, and copying QFontMetrics objects. Makes loading NSView.html about
+ 18% faster.
+
+ * src/kwq/qt/qfontmetrics.h: Use a ref-counted pointer so QFontMetrics objects
+ for the same QFont can share data.
+
+ * src/kwq/KWQFont.mm: (loadDefaultFont): New, used to load the default
+ font used for default-initialized QFont objects.
+ (QFont::_initializeWithFont): Don't recompute theh family name, point size, or
+ traits.
+ (QFont::setFamily), (QFont::setPixelSizeFloat), (QFont::setWeight),
+ (QFont::setItalic),: autorelease the font, as we do in the destructor, since
+ someone could still be using the result of getFont.
+ (QFont::operator==): Add a comment about a problem with this function.
+
+ * src/kwq/KWQFontMetrics.mm: (QFontMetrics::QFontMetrics): Add a refCount, and
+ a cached width for space and lower-case "x", the two single characters that
+ are often measured.
+ (QFontMetrics::~QFontMetrics): Simplify.
+ (QFontMetrics::operator=): Just copy the underlying data pointer rather than
+ making our own KWQLayoutInfo object.
+ (QFontMetrics::baselineOffset): Make const.
+ (QFontMetrics::width): Add the caching for space and "x".
+
2002-03-15 Richard Williamson <rjw at apple.com>
Optimizations that remove unnecessary cfstring allocations of local scope
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index df5fc1c..a1c534a 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,30 @@
+2002-03-15 Darin Adler <darin at apple.com>
+
+ Optimizations for creating empty QFont objects, measuring certain single
+ characters, and copying QFontMetrics objects. Makes loading NSView.html about
+ 18% faster.
+
+ * src/kwq/qt/qfontmetrics.h: Use a ref-counted pointer so QFontMetrics objects
+ for the same QFont can share data.
+
+ * src/kwq/KWQFont.mm: (loadDefaultFont): New, used to load the default
+ font used for default-initialized QFont objects.
+ (QFont::_initializeWithFont): Don't recompute theh family name, point size, or
+ traits.
+ (QFont::setFamily), (QFont::setPixelSizeFloat), (QFont::setWeight),
+ (QFont::setItalic),: autorelease the font, as we do in the destructor, since
+ someone could still be using the result of getFont.
+ (QFont::operator==): Add a comment about a problem with this function.
+
+ * src/kwq/KWQFontMetrics.mm: (QFontMetrics::QFontMetrics): Add a refCount, and
+ a cached width for space and lower-case "x", the two single characters that
+ are often measured.
+ (QFontMetrics::~QFontMetrics): Simplify.
+ (QFontMetrics::operator=): Just copy the underlying data pointer rather than
+ making our own KWQLayoutInfo object.
+ (QFontMetrics::baselineOffset): Make const.
+ (QFontMetrics::width): Add the caching for space and "x".
+
2002-03-15 Richard Williamson <rjw at apple.com>
Optimizations that remove unnecessary cfstring allocations of local scope
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index df5fc1c..a1c534a 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,30 @@
+2002-03-15 Darin Adler <darin at apple.com>
+
+ Optimizations for creating empty QFont objects, measuring certain single
+ characters, and copying QFontMetrics objects. Makes loading NSView.html about
+ 18% faster.
+
+ * src/kwq/qt/qfontmetrics.h: Use a ref-counted pointer so QFontMetrics objects
+ for the same QFont can share data.
+
+ * src/kwq/KWQFont.mm: (loadDefaultFont): New, used to load the default
+ font used for default-initialized QFont objects.
+ (QFont::_initializeWithFont): Don't recompute theh family name, point size, or
+ traits.
+ (QFont::setFamily), (QFont::setPixelSizeFloat), (QFont::setWeight),
+ (QFont::setItalic),: autorelease the font, as we do in the destructor, since
+ someone could still be using the result of getFont.
+ (QFont::operator==): Add a comment about a problem with this function.
+
+ * src/kwq/KWQFontMetrics.mm: (QFontMetrics::QFontMetrics): Add a refCount, and
+ a cached width for space and lower-case "x", the two single characters that
+ are often measured.
+ (QFontMetrics::~QFontMetrics): Simplify.
+ (QFontMetrics::operator=): Just copy the underlying data pointer rather than
+ making our own KWQLayoutInfo object.
+ (QFontMetrics::baselineOffset): Make const.
+ (QFontMetrics::width): Add the caching for space and "x".
+
2002-03-15 Richard Williamson <rjw at apple.com>
Optimizations that remove unnecessary cfstring allocations of local scope
diff --git a/WebCore/kwq/KWQFont.mm b/WebCore/kwq/KWQFont.mm
index 29c8e4c..e87b509 100644
--- a/WebCore/kwq/KWQFont.mm
+++ b/WebCore/kwq/KWQFont.mm
@@ -32,61 +32,60 @@
For this implementation Qt pixelSize is interpreted as Cocoa pointSize.
*/
-QFont::QFont()
-{
- _initialize();
-}
-
+static NSFont *defaultFont = 0;
+static NSString *defaultFontFamilyName;
+static float defaultFontSize;
+static int defaultFontTrait;
-void QFont::_initialize()
+static void
+loadDefaultFont()
{
- _initializeWithFont (0);
+ if (defaultFont)
+ return;
+ defaultFont = [[NSFont userFontOfSize: (float)12.0] retain];
+ defaultFontFamilyName = [[defaultFont familyName] retain];
+ defaultFontSize = [defaultFont pointSize];
+ defaultFontTrait = [[NSFontManager sharedFontManager] traitsOfFont:defaultFont] & (NSBoldFontMask | NSItalicFontMask);
}
-static NSFont *_defaultNSFont = 0;
-
-NSFont *QFont::defaultNSFont()
+QFont::QFont()
{
- if (_defaultNSFont == 0)
- _defaultNSFont = [[NSFont userFontOfSize: (float)12.0] retain];
- return _defaultNSFont;
+ _initializeWithFont(0);
}
-void QFont::_initializeWithFont (const QFont *withFont)
+void QFont::_initializeWithFont(const QFont *withFont)
{
- if (withFont){
+ if (withFont) {
font = [withFont->font retain];
_family = [withFont->_family retain];
_size = withFont->_size;
_trait = withFont->_trait;
- }
- else {
- font = [defaultNSFont() retain];
- _family = [[font familyName] retain];
- _size = [font pointSize];
- _trait = [[NSFontManager sharedFontManager] traitsOfFont: font] & (NSBoldFontMask | NSItalicFontMask);
+ } else {
+ loadDefaultFont();
+ font = [defaultFont retain];
+ _family = [defaultFontFamilyName retain];
+ _size = defaultFontSize;
+ _trait = defaultFontTrait;
}
}
-
QFont::QFont(const QFont ©From)
{
_initializeWithFont(©From);
}
-
QFont::~QFont()
{
_free();
}
-void QFont::_free(){
+void QFont::_free()
+{
[_family release];
[font autorelease];
- font = 0;
+ font = nil;
}
-
// member functions --------------------------------------------------------
#ifdef DEBUG_GETFONT
@@ -155,7 +154,7 @@ static NSMutableDictionary *fontCache = 0;
NSFont *QFont::getFont()
{
- if (font == nil){
+ if (font == nil) {
NSString *fontKey;
#ifdef DEBUG_GETFONT
getFontCount++;
@@ -192,7 +191,7 @@ void QFont::setFamily(const QString &qfamilyName)
{
[_family release];
_family = [_FAST_QSTRING_TO_NSSTRING(qfamilyName) retain];
- [font release];
+ [font autorelease];
font = nil;
}
@@ -201,7 +200,7 @@ void QFont::setPixelSizeFloat(float sz)
{
if (sz != _size){
_size = sz;
- [font release];
+ [font autorelease];
font = nil;
}
}
@@ -210,15 +209,15 @@ void QFont::setPixelSizeFloat(float sz)
void QFont::setWeight(int weight)
{
if (weight == Bold){
- if (!bold()){
- [font release];
+ if (!bold()) {
+ [font autorelease];
font = nil;
}
_trait |= NSBoldFontMask;
}
else if (weight == Normal){
if (bold()){
- [font release];
+ [font autorelease];
font = nil;
}
_trait = _trait & (~NSBoldFontMask);
@@ -238,7 +237,7 @@ bool QFont::setItalic(bool flag)
{
if (flag){
if (!italic()){
- [font release];
+ [font autorelease];
font = nil;
}
_trait |= NSItalicFontMask;
@@ -246,7 +245,7 @@ bool QFont::setItalic(bool flag)
}
else{
if (italic()){
- [font release];
+ [font autorelease];
font = nil;
}
_trait = _trait & (~NSItalicFontMask);
@@ -279,6 +278,7 @@ QFont &QFont::operator=(const QFont &assignFrom)
bool QFont::operator==(const QFont &compareFont) const
{
+ // FIXME: This does not do the right thing when the font is nil
return [compareFont.font isEqual: font];
}
diff --git a/WebCore/kwq/KWQFontMetrics.h b/WebCore/kwq/KWQFontMetrics.h
index 4bc1cd6..b462a8e 100644
--- a/WebCore/kwq/KWQFontMetrics.h
+++ b/WebCore/kwq/KWQFontMetrics.h
@@ -41,7 +41,6 @@
class QFontMetricsPrivate;
-
// class QFontMetrics ==========================================================
class QFontMetrics {
@@ -59,6 +58,10 @@ public:
QFontMetrics(const QFontMetrics &);
~QFontMetrics();
+ // operators ---------------------------------------------------------------
+
+ QFontMetrics &operator=(const QFontMetrics &);
+
// member functions --------------------------------------------------------
int ascent() const;
@@ -77,26 +80,10 @@ public:
int *tabarray=0, char **intern=0 ) const;
int rightBearing(QChar) const;
int leftBearing(QChar) const;
-
- // operators ---------------------------------------------------------------
-
- QFontMetrics &operator=(const QFontMetrics &);
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
-#ifdef _KWQ_
- int baselineOffset();
- void _initialize();
-#if (defined(__APPLE__) && defined(__OBJC__) && defined(__cplusplus))
- //void _initializeWithData(QFontMetricsPrivate *);
- void _initializeWithFont (NSFont *font);
-#else
- void _initializeWithFont(void *);
-#endif
- void _free();
+ int baselineOffset() const;
- QFontMetricsPrivate *data;
-#endif
+private:
+ KWQRefPtr<QFontMetricsPrivate> data;
}; // class QFontMetrics =======================================================
diff --git a/WebCore/kwq/KWQFontMetrics.mm b/WebCore/kwq/KWQFontMetrics.mm
index 224ab5d..9d7280f 100644
--- a/WebCore/kwq/KWQFontMetrics.mm
+++ b/WebCore/kwq/KWQFontMetrics.mm
@@ -35,8 +35,6 @@
#define FLOOR_TO_INT(x) (int)(floor(x))
#define ROUND_TO_INT(x) (int)(((x) > (floor(x) + .5)) ? ceil(x) : floor(x))
//#define ROUND_TO_INT(f) ((int)(rint(f)))
-const float LargeNumberForText = 1.0e7;
-
@implementation KWQSmallLayoutFragment
- (NSRange)glyphRange
@@ -307,71 +305,51 @@ static NSMutableDictionary *metricsCache = nil;
struct QFontMetricsPrivate {
-friend class QFontMetrics;
-public:
- QFontMetricsPrivate(NSFont *aFont)
+ QFontMetricsPrivate(NSFont *aFont)
{
- font = [aFont retain];
+ refCount = 0;
+ font = [aFont retain];
info = [[KWQLayoutInfo getMetricsForFont: aFont] retain];
+ spaceWidth = -1;
+ xWidth = -1;
}
-
~QFontMetricsPrivate()
{
- if (info){
- [info release];
- info = 0;
- }
- if (font){
- [font release];
- font = 0;
- }
+ [info release];
+ [font release];
}
-
-private:
+ int refCount;
KWQLayoutInfo *info;
NSFont *font;
+ int spaceWidth;
+ int xWidth;
};
-
QFontMetrics::QFontMetrics()
{
- _initialize();
}
-
QFontMetrics::QFontMetrics(const QFont &withFont)
+: data(new QFontMetricsPrivate(const_cast<QFont&>(withFont).getFont()))
{
- _initializeWithFont (((QFont)withFont).getFont());
-}
-
-
-QFontMetrics::QFontMetrics(const QFontMetrics ©From)
-{
- _initializeWithFont(copyFrom.data->font);
}
-void QFontMetrics::_initialize()
+QFontMetrics::QFontMetrics(const QFontMetrics &withFont)
+: data(withFont.data)
{
- _initializeWithFont (0);
}
-void QFontMetrics::_initializeWithFont (NSFont *font)
+QFontMetrics::~QFontMetrics()
{
- data = new QFontMetricsPrivate(font);
}
-void QFontMetrics::_free(){
- delete data;
-}
-
-
-QFontMetrics::~QFontMetrics()
+QFontMetrics &QFontMetrics::operator=(const QFontMetrics &withFont)
{
- _free();
+ data = withFont.data;
+ return *this;
}
-
-int QFontMetrics::baselineOffset()
+int QFontMetrics::baselineOffset() const
{
return ascent();
}
@@ -381,14 +359,11 @@ int QFontMetrics::ascent() const
return ROUND_TO_INT([data->font ascender]);
}
-
-
int QFontMetrics::descent() const
{
return ROUND_TO_INT(-[data->font descender]);
}
-
int QFontMetrics::height() const
{
// According to Qt documentation:
@@ -396,17 +371,27 @@ int QFontMetrics::height() const
return ascent() + descent() + 1;
}
-
int QFontMetrics::width(QChar qc) const
{
ushort c = qc.unicode();
+ switch (c) {
+ // cheesy, we use the char version of width to do the work here,
+ // and since it doesn't have the optimization, we don't get an
+ // infinite loop
+ case ' ':
+ if (data->spaceWidth < 0)
+ data->spaceWidth = width(' ');
+ return data->spaceWidth;
+ case 'x':
+ if (data->xWidth < 0)
+ data->xWidth = width('x');
+ return data->xWidth;
+ }
NSString *string = [NSString stringWithCharacters: (const unichar *)&c length: 1];
int stringWidth = ROUND_TO_INT([data->info rectForString: string].size.width);
return stringWidth;
}
-
-
int QFontMetrics::width(char c) const
{
NSString *string = [NSString stringWithCString: &c length: 1];
@@ -414,7 +399,6 @@ int QFontMetrics::width(char c) const
return stringWidth;
}
-
int QFontMetrics::width(const QString &qstring, int len) const
{
NSString *string;
@@ -429,11 +413,9 @@ int QFontMetrics::width(const QString &qstring, int len) const
int QFontMetrics::_width(CFStringRef string) const
{
- int stringWidth = ROUND_TO_INT([data->info rectForString: (NSString *)string].size.width);
- return stringWidth;
+ return ROUND_TO_INT([data->info rectForString: (NSString *)string].size.width);
}
-
QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
{
NSString *string;
@@ -450,7 +432,6 @@ QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
ROUND_TO_INT(rect.size.height));
}
-
QRect QFontMetrics::boundingRect(QChar qc) const
{
ushort c = qc.unicode();
@@ -463,7 +444,6 @@ QRect QFontMetrics::boundingRect(QChar qc) const
ROUND_TO_INT(rect.size.height));
}
-
QSize QFontMetrics::size(int, const QString &qstring, int len, int tabstops,
int *tabarray, char **intern ) const
{
@@ -483,26 +463,14 @@ QSize QFontMetrics::size(int, const QString &qstring, int len, int tabstops,
return QSize (ROUND_TO_INT(rect.size.width),ROUND_TO_INT(rect.size.height));
}
-
int QFontMetrics::rightBearing(QChar) const
{
_logNotYetImplemented();
return 0;
}
-
int QFontMetrics::leftBearing(QChar) const
{
_logNotYetImplemented();
return 0;
}
-
-
-QFontMetrics &QFontMetrics::operator=(const QFontMetrics &assignFrom)
-{
- _free();
- _initializeWithFont(assignFrom.data->font);
- return *this;
-}
-
-
diff --git a/WebCore/kwq/qt/qfontmetrics.h b/WebCore/kwq/qt/qfontmetrics.h
index 4bc1cd6..b462a8e 100644
--- a/WebCore/kwq/qt/qfontmetrics.h
+++ b/WebCore/kwq/qt/qfontmetrics.h
@@ -41,7 +41,6 @@
class QFontMetricsPrivate;
-
// class QFontMetrics ==========================================================
class QFontMetrics {
@@ -59,6 +58,10 @@ public:
QFontMetrics(const QFontMetrics &);
~QFontMetrics();
+ // operators ---------------------------------------------------------------
+
+ QFontMetrics &operator=(const QFontMetrics &);
+
// member functions --------------------------------------------------------
int ascent() const;
@@ -77,26 +80,10 @@ public:
int *tabarray=0, char **intern=0 ) const;
int rightBearing(QChar) const;
int leftBearing(QChar) const;
-
- // operators ---------------------------------------------------------------
-
- QFontMetrics &operator=(const QFontMetrics &);
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
-#ifdef _KWQ_
- int baselineOffset();
- void _initialize();
-#if (defined(__APPLE__) && defined(__OBJC__) && defined(__cplusplus))
- //void _initializeWithData(QFontMetricsPrivate *);
- void _initializeWithFont (NSFont *font);
-#else
- void _initializeWithFont(void *);
-#endif
- void _free();
+ int baselineOffset() const;
- QFontMetricsPrivate *data;
-#endif
+private:
+ KWQRefPtr<QFontMetricsPrivate> data;
}; // class QFontMetrics =======================================================
diff --git a/WebCore/src/kwq/KWQFont.mm b/WebCore/src/kwq/KWQFont.mm
index 29c8e4c..e87b509 100644
--- a/WebCore/src/kwq/KWQFont.mm
+++ b/WebCore/src/kwq/KWQFont.mm
@@ -32,61 +32,60 @@
For this implementation Qt pixelSize is interpreted as Cocoa pointSize.
*/
-QFont::QFont()
-{
- _initialize();
-}
-
+static NSFont *defaultFont = 0;
+static NSString *defaultFontFamilyName;
+static float defaultFontSize;
+static int defaultFontTrait;
-void QFont::_initialize()
+static void
+loadDefaultFont()
{
- _initializeWithFont (0);
+ if (defaultFont)
+ return;
+ defaultFont = [[NSFont userFontOfSize: (float)12.0] retain];
+ defaultFontFamilyName = [[defaultFont familyName] retain];
+ defaultFontSize = [defaultFont pointSize];
+ defaultFontTrait = [[NSFontManager sharedFontManager] traitsOfFont:defaultFont] & (NSBoldFontMask | NSItalicFontMask);
}
-static NSFont *_defaultNSFont = 0;
-
-NSFont *QFont::defaultNSFont()
+QFont::QFont()
{
- if (_defaultNSFont == 0)
- _defaultNSFont = [[NSFont userFontOfSize: (float)12.0] retain];
- return _defaultNSFont;
+ _initializeWithFont(0);
}
-void QFont::_initializeWithFont (const QFont *withFont)
+void QFont::_initializeWithFont(const QFont *withFont)
{
- if (withFont){
+ if (withFont) {
font = [withFont->font retain];
_family = [withFont->_family retain];
_size = withFont->_size;
_trait = withFont->_trait;
- }
- else {
- font = [defaultNSFont() retain];
- _family = [[font familyName] retain];
- _size = [font pointSize];
- _trait = [[NSFontManager sharedFontManager] traitsOfFont: font] & (NSBoldFontMask | NSItalicFontMask);
+ } else {
+ loadDefaultFont();
+ font = [defaultFont retain];
+ _family = [defaultFontFamilyName retain];
+ _size = defaultFontSize;
+ _trait = defaultFontTrait;
}
}
-
QFont::QFont(const QFont ©From)
{
_initializeWithFont(©From);
}
-
QFont::~QFont()
{
_free();
}
-void QFont::_free(){
+void QFont::_free()
+{
[_family release];
[font autorelease];
- font = 0;
+ font = nil;
}
-
// member functions --------------------------------------------------------
#ifdef DEBUG_GETFONT
@@ -155,7 +154,7 @@ static NSMutableDictionary *fontCache = 0;
NSFont *QFont::getFont()
{
- if (font == nil){
+ if (font == nil) {
NSString *fontKey;
#ifdef DEBUG_GETFONT
getFontCount++;
@@ -192,7 +191,7 @@ void QFont::setFamily(const QString &qfamilyName)
{
[_family release];
_family = [_FAST_QSTRING_TO_NSSTRING(qfamilyName) retain];
- [font release];
+ [font autorelease];
font = nil;
}
@@ -201,7 +200,7 @@ void QFont::setPixelSizeFloat(float sz)
{
if (sz != _size){
_size = sz;
- [font release];
+ [font autorelease];
font = nil;
}
}
@@ -210,15 +209,15 @@ void QFont::setPixelSizeFloat(float sz)
void QFont::setWeight(int weight)
{
if (weight == Bold){
- if (!bold()){
- [font release];
+ if (!bold()) {
+ [font autorelease];
font = nil;
}
_trait |= NSBoldFontMask;
}
else if (weight == Normal){
if (bold()){
- [font release];
+ [font autorelease];
font = nil;
}
_trait = _trait & (~NSBoldFontMask);
@@ -238,7 +237,7 @@ bool QFont::setItalic(bool flag)
{
if (flag){
if (!italic()){
- [font release];
+ [font autorelease];
font = nil;
}
_trait |= NSItalicFontMask;
@@ -246,7 +245,7 @@ bool QFont::setItalic(bool flag)
}
else{
if (italic()){
- [font release];
+ [font autorelease];
font = nil;
}
_trait = _trait & (~NSItalicFontMask);
@@ -279,6 +278,7 @@ QFont &QFont::operator=(const QFont &assignFrom)
bool QFont::operator==(const QFont &compareFont) const
{
+ // FIXME: This does not do the right thing when the font is nil
return [compareFont.font isEqual: font];
}
diff --git a/WebCore/src/kwq/KWQFontMetrics.mm b/WebCore/src/kwq/KWQFontMetrics.mm
index 224ab5d..9d7280f 100644
--- a/WebCore/src/kwq/KWQFontMetrics.mm
+++ b/WebCore/src/kwq/KWQFontMetrics.mm
@@ -35,8 +35,6 @@
#define FLOOR_TO_INT(x) (int)(floor(x))
#define ROUND_TO_INT(x) (int)(((x) > (floor(x) + .5)) ? ceil(x) : floor(x))
//#define ROUND_TO_INT(f) ((int)(rint(f)))
-const float LargeNumberForText = 1.0e7;
-
@implementation KWQSmallLayoutFragment
- (NSRange)glyphRange
@@ -307,71 +305,51 @@ static NSMutableDictionary *metricsCache = nil;
struct QFontMetricsPrivate {
-friend class QFontMetrics;
-public:
- QFontMetricsPrivate(NSFont *aFont)
+ QFontMetricsPrivate(NSFont *aFont)
{
- font = [aFont retain];
+ refCount = 0;
+ font = [aFont retain];
info = [[KWQLayoutInfo getMetricsForFont: aFont] retain];
+ spaceWidth = -1;
+ xWidth = -1;
}
-
~QFontMetricsPrivate()
{
- if (info){
- [info release];
- info = 0;
- }
- if (font){
- [font release];
- font = 0;
- }
+ [info release];
+ [font release];
}
-
-private:
+ int refCount;
KWQLayoutInfo *info;
NSFont *font;
+ int spaceWidth;
+ int xWidth;
};
-
QFontMetrics::QFontMetrics()
{
- _initialize();
}
-
QFontMetrics::QFontMetrics(const QFont &withFont)
+: data(new QFontMetricsPrivate(const_cast<QFont&>(withFont).getFont()))
{
- _initializeWithFont (((QFont)withFont).getFont());
-}
-
-
-QFontMetrics::QFontMetrics(const QFontMetrics ©From)
-{
- _initializeWithFont(copyFrom.data->font);
}
-void QFontMetrics::_initialize()
+QFontMetrics::QFontMetrics(const QFontMetrics &withFont)
+: data(withFont.data)
{
- _initializeWithFont (0);
}
-void QFontMetrics::_initializeWithFont (NSFont *font)
+QFontMetrics::~QFontMetrics()
{
- data = new QFontMetricsPrivate(font);
}
-void QFontMetrics::_free(){
- delete data;
-}
-
-
-QFontMetrics::~QFontMetrics()
+QFontMetrics &QFontMetrics::operator=(const QFontMetrics &withFont)
{
- _free();
+ data = withFont.data;
+ return *this;
}
-
-int QFontMetrics::baselineOffset()
+int QFontMetrics::baselineOffset() const
{
return ascent();
}
@@ -381,14 +359,11 @@ int QFontMetrics::ascent() const
return ROUND_TO_INT([data->font ascender]);
}
-
-
int QFontMetrics::descent() const
{
return ROUND_TO_INT(-[data->font descender]);
}
-
int QFontMetrics::height() const
{
// According to Qt documentation:
@@ -396,17 +371,27 @@ int QFontMetrics::height() const
return ascent() + descent() + 1;
}
-
int QFontMetrics::width(QChar qc) const
{
ushort c = qc.unicode();
+ switch (c) {
+ // cheesy, we use the char version of width to do the work here,
+ // and since it doesn't have the optimization, we don't get an
+ // infinite loop
+ case ' ':
+ if (data->spaceWidth < 0)
+ data->spaceWidth = width(' ');
+ return data->spaceWidth;
+ case 'x':
+ if (data->xWidth < 0)
+ data->xWidth = width('x');
+ return data->xWidth;
+ }
NSString *string = [NSString stringWithCharacters: (const unichar *)&c length: 1];
int stringWidth = ROUND_TO_INT([data->info rectForString: string].size.width);
return stringWidth;
}
-
-
int QFontMetrics::width(char c) const
{
NSString *string = [NSString stringWithCString: &c length: 1];
@@ -414,7 +399,6 @@ int QFontMetrics::width(char c) const
return stringWidth;
}
-
int QFontMetrics::width(const QString &qstring, int len) const
{
NSString *string;
@@ -429,11 +413,9 @@ int QFontMetrics::width(const QString &qstring, int len) const
int QFontMetrics::_width(CFStringRef string) const
{
- int stringWidth = ROUND_TO_INT([data->info rectForString: (NSString *)string].size.width);
- return stringWidth;
+ return ROUND_TO_INT([data->info rectForString: (NSString *)string].size.width);
}
-
QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
{
NSString *string;
@@ -450,7 +432,6 @@ QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
ROUND_TO_INT(rect.size.height));
}
-
QRect QFontMetrics::boundingRect(QChar qc) const
{
ushort c = qc.unicode();
@@ -463,7 +444,6 @@ QRect QFontMetrics::boundingRect(QChar qc) const
ROUND_TO_INT(rect.size.height));
}
-
QSize QFontMetrics::size(int, const QString &qstring, int len, int tabstops,
int *tabarray, char **intern ) const
{
@@ -483,26 +463,14 @@ QSize QFontMetrics::size(int, const QString &qstring, int len, int tabstops,
return QSize (ROUND_TO_INT(rect.size.width),ROUND_TO_INT(rect.size.height));
}
-
int QFontMetrics::rightBearing(QChar) const
{
_logNotYetImplemented();
return 0;
}
-
int QFontMetrics::leftBearing(QChar) const
{
_logNotYetImplemented();
return 0;
}
-
-
-QFontMetrics &QFontMetrics::operator=(const QFontMetrics &assignFrom)
-{
- _free();
- _initializeWithFont(assignFrom.data->font);
- return *this;
-}
-
-
diff --git a/WebCore/src/kwq/qt/qfontmetrics.h b/WebCore/src/kwq/qt/qfontmetrics.h
index 4bc1cd6..b462a8e 100644
--- a/WebCore/src/kwq/qt/qfontmetrics.h
+++ b/WebCore/src/kwq/qt/qfontmetrics.h
@@ -41,7 +41,6 @@
class QFontMetricsPrivate;
-
// class QFontMetrics ==========================================================
class QFontMetrics {
@@ -59,6 +58,10 @@ public:
QFontMetrics(const QFontMetrics &);
~QFontMetrics();
+ // operators ---------------------------------------------------------------
+
+ QFontMetrics &operator=(const QFontMetrics &);
+
// member functions --------------------------------------------------------
int ascent() const;
@@ -77,26 +80,10 @@ public:
int *tabarray=0, char **intern=0 ) const;
int rightBearing(QChar) const;
int leftBearing(QChar) const;
-
- // operators ---------------------------------------------------------------
-
- QFontMetrics &operator=(const QFontMetrics &);
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
-#ifdef _KWQ_
- int baselineOffset();
- void _initialize();
-#if (defined(__APPLE__) && defined(__OBJC__) && defined(__cplusplus))
- //void _initializeWithData(QFontMetricsPrivate *);
- void _initializeWithFont (NSFont *font);
-#else
- void _initializeWithFont(void *);
-#endif
- void _free();
+ int baselineOffset() const;
- QFontMetricsPrivate *data;
-#endif
+private:
+ KWQRefPtr<QFontMetricsPrivate> data;
}; // class QFontMetrics =======================================================
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list