[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
rjw
rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:39:04 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 837508762d8db2fcdd30ca95f1d81c66a142ba50
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Sep 13 22:38:06 2002 +0000
Made justified text work correctly in khtml for rendering
and selection. Optimized selection point calculation by
only doing characters measurements once.
* khtml/rendering/font.cpp:
(Font::floatCharacterWidths):
* khtml/rendering/font.h:
* khtml/rendering/render_text.cpp:
(TextSlave::checkSelectionPoint):
(RenderText::position):
* kwq/KWQFontMetrics.mm:
(QFontMetrics::width):
(QFontMetrics::floatWidth):
(QFontMetrics::floatCharacterWidths):
* kwq/KWQPainter.mm:
(QPainter::drawText):
* kwq/WebCoreTextRenderer.h:
* kwq/qt/qfontmetrics.h:
Adding padding and widths buffer to our canonical measurement
method. The padding argument is used to 'pad' measurements in
that same way that drawing is padded. The widths parameter
allows a caller to pass a buffer to get all the individual
character widths for the run of characters in the string.
* Misc.subproj/WebStringTruncator.m:
(+[WebStringTruncator rightTruncateString:toWidth:withFont:]):
(+[WebStringTruncator centerTruncateString:toWidth:withFont:]):
* WebCoreSupport.subproj/WebTextRenderer.h:
* WebCoreSupport.subproj/WebTextRenderer.m:
(-[WebTextRenderer widthForCharacters:length:]):
(-[WebTextRenderer drawGlyphs:numGlyphs:fromGlyphPosition:toGlyphPosition:atPoint:withPadding:withTextColor:backgroundColor:]):
(-[WebTextRenderer floatWidthForCharacters:stringLength:characterPosition:]):
(-[WebTextRenderer floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:]):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2062 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index 56bbc95..c8a1f82 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,3 +1,24 @@
+2002-09-13 Richard Williamson (Home) <rjw at apple.com>
+
+ Made justified text work correctly in khtml for rendering
+ and selection. Optimized selection point calculation by
+ only doing characters measurements once.
+
+ * khtml/rendering/font.cpp:
+ (Font::floatCharacterWidths):
+ * khtml/rendering/font.h:
+ * khtml/rendering/render_text.cpp:
+ (TextSlave::checkSelectionPoint):
+ (RenderText::position):
+ * kwq/KWQFontMetrics.mm:
+ (QFontMetrics::width):
+ (QFontMetrics::floatWidth):
+ (QFontMetrics::floatCharacterWidths):
+ * kwq/KWQPainter.mm:
+ (QPainter::drawText):
+ * kwq/WebCoreTextRenderer.h:
+ * kwq/qt/qfontmetrics.h:
+
2002-09-13 Darin Adler <darin at apple.com>
Quiet error messages related to the slot/signal changes.
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 56bbc95..c8a1f82 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,24 @@
+2002-09-13 Richard Williamson (Home) <rjw at apple.com>
+
+ Made justified text work correctly in khtml for rendering
+ and selection. Optimized selection point calculation by
+ only doing characters measurements once.
+
+ * khtml/rendering/font.cpp:
+ (Font::floatCharacterWidths):
+ * khtml/rendering/font.h:
+ * khtml/rendering/render_text.cpp:
+ (TextSlave::checkSelectionPoint):
+ (RenderText::position):
+ * kwq/KWQFontMetrics.mm:
+ (QFontMetrics::width):
+ (QFontMetrics::floatWidth):
+ (QFontMetrics::floatCharacterWidths):
+ * kwq/KWQPainter.mm:
+ (QPainter::drawText):
+ * kwq/WebCoreTextRenderer.h:
+ * kwq/qt/qfontmetrics.h:
+
2002-09-13 Darin Adler <darin at apple.com>
Quiet error messages related to the slot/signal changes.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 56bbc95..c8a1f82 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,24 @@
+2002-09-13 Richard Williamson (Home) <rjw at apple.com>
+
+ Made justified text work correctly in khtml for rendering
+ and selection. Optimized selection point calculation by
+ only doing characters measurements once.
+
+ * khtml/rendering/font.cpp:
+ (Font::floatCharacterWidths):
+ * khtml/rendering/font.h:
+ * khtml/rendering/render_text.cpp:
+ (TextSlave::checkSelectionPoint):
+ (RenderText::position):
+ * kwq/KWQFontMetrics.mm:
+ (QFontMetrics::width):
+ (QFontMetrics::floatWidth):
+ (QFontMetrics::floatCharacterWidths):
+ * kwq/KWQPainter.mm:
+ (QPainter::drawText):
+ * kwq/WebCoreTextRenderer.h:
+ * kwq/qt/qfontmetrics.h:
+
2002-09-13 Darin Adler <darin at apple.com>
Quiet error messages related to the slot/signal changes.
diff --git a/WebCore/khtml/rendering/font.cpp b/WebCore/khtml/rendering/font.cpp
index 6029105..a44e608 100644
--- a/WebCore/khtml/rendering/font.cpp
+++ b/WebCore/khtml/rendering/font.cpp
@@ -108,9 +108,9 @@ float Font::floatWidth( QChar *chs, int slen, int pos, int len ) const
}
-float Font::floatCharacterWidth( QChar *chs, int slen, int pos) const
+void Font::floatCharacterWidths( QChar *str, int slen, int pos, int len, int toAdd, float *buffer) const
{
- return fm.floatCharacterWidth(chs, slen, pos);
+ fm.floatCharacterWidths(str, slen, pos, len, toAdd, buffer);
}
#endif
diff --git a/WebCore/khtml/rendering/font.h b/WebCore/khtml/rendering/font.h
index 7dab2bd..3eb7849 100644
--- a/WebCore/khtml/rendering/font.h
+++ b/WebCore/khtml/rendering/font.h
@@ -89,7 +89,7 @@ public:
#ifdef APPLE_CHANGES
float floatWidth( QChar *str, int slen, int pos, int len ) const;
- float floatCharacterWidth( QChar *str, int slen, int pos ) const;
+ void floatCharacterWidths( QChar *str, int slen, int pos, int len, int toAdd, float *buffer) const;
#endif
int width( QChar *str, int slen, int pos, int len ) const;
int width( QChar *str, int slen, int pos ) const;
diff --git a/WebCore/khtml/rendering/render_text.cpp b/WebCore/khtml/rendering/render_text.cpp
index 11111f0..b4d293d 100644
--- a/WebCore/khtml/rendering/render_text.cpp
+++ b/WebCore/khtml/rendering/render_text.cpp
@@ -161,12 +161,15 @@ FindSelectionResult TextSlave::checkSelectionPoint(int _x, int _y, int _tx, int
#ifdef APPLE_CHANGES
// Floating point version needed for best results with Mac OS X text.
float delta = _x - (_tx + m_x);
- //kdDebug(6040) << "TextSlave::checkSelectionPoint delta=" << delta << endl;
+ float widths[m_len];
+
+ // Do width calculations for whole run once.
+ f->floatCharacterWidths( text->str->s, text->str->l, m_start, m_len, m_toAdd, &widths[0]);
int pos = 0;
if ( m_reversed ) {
delta -= m_width;
while(pos < m_len) {
- float w = f->floatCharacterWidth( text->str->s, text->str->l, m_start + pos);
+ float w = widths[pos];
float w2 = w/2;
w -= w2;
delta += w2;
@@ -177,7 +180,7 @@ FindSelectionResult TextSlave::checkSelectionPoint(int _x, int _y, int _tx, int
}
} else {
while(pos < m_len) {
- float w = f->floatCharacterWidth( text->str->s, text->str->l, m_start + pos);
+ float w = widths[pos];
float w2 = w/2;
w -= w2;
delta -= w2;
@@ -854,7 +857,7 @@ void RenderText::position(int x, int y, int from, int len, int width, bool rever
TextSlave *s = new TextSlave(x, y, from, len,
baselinePosition( firstLine ),
- width, reverse, spaceAdd, firstLine);
+ width+spaceAdd, reverse, spaceAdd, firstLine);
if(m_lines.count() == m_lines.size())
m_lines.resize(m_lines.size()*2+1);
diff --git a/WebCore/kwq/KWQFontMetrics.h b/WebCore/kwq/KWQFontMetrics.h
index 43bfcfb..064966d 100644
--- a/WebCore/kwq/KWQFontMetrics.h
+++ b/WebCore/kwq/KWQFontMetrics.h
@@ -54,7 +54,7 @@ public:
int charWidth(const QString &, int pos) const;
int width(const QChar *, int len) const;
float floatWidth(const QChar *, int slen, int pos, int len) const;
- float floatCharacterWidth(const QChar *, int slen, int pos) const;
+ float floatCharacterWidths(const QChar *, int slen, int pos, int len, int toAdd, float *buffer) const;
QRect boundingRect(const QString &, int len=-1) const;
QRect boundingRect(int, int, int, int, int, const QString &) const;
diff --git a/WebCore/kwq/KWQFontMetrics.mm b/WebCore/kwq/KWQFontMetrics.mm
index 996b4b2..5adfe84 100644
--- a/WebCore/kwq/KWQFontMetrics.mm
+++ b/WebCore/kwq/KWQFontMetrics.mm
@@ -112,7 +112,7 @@ float QFontMetrics::xHeight() const
int QFontMetrics::width(QChar qc) const
{
UniChar c = qc.unicode();
- return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:&c stringLength:1 fromCharacterPosition:0 numberOfCharacters:1 applyRounding:YES attemptFontSubstitution: YES]);
+ return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:&c stringLength:1 fromCharacterPosition:0 numberOfCharacters:1 withPadding: 0 applyRounding:YES attemptFontSubstitution: YES widths: 0]);
}
int QFontMetrics::charWidth(const QString &s, int pos) const
@@ -123,27 +123,27 @@ int QFontMetrics::charWidth(const QString &s, int pos) const
int QFontMetrics::width(char c) const
{
UniChar ch = (uchar) c;
- return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:&ch stringLength:1 fromCharacterPosition:0 numberOfCharacters:1 applyRounding:YES attemptFontSubstitution: YES]);
+ return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:&ch stringLength:1 fromCharacterPosition:0 numberOfCharacters:1 withPadding: 0 applyRounding:YES attemptFontSubstitution: YES widths: 0]);
}
int QFontMetrics::width(const QString &qstring, int len) const
{
- return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:(const UniChar *)qstring.unicode() stringLength:len fromCharacterPosition:0 numberOfCharacters:len applyRounding:YES attemptFontSubstitution: YES]);
+ return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:(const UniChar *)qstring.unicode() stringLength:len fromCharacterPosition:0 numberOfCharacters:len withPadding: 0 applyRounding:YES attemptFontSubstitution: YES widths: 0]);
}
int QFontMetrics::width(const QChar *uchars, int len) const
{
- return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:(const UniChar *)uchars stringLength:len fromCharacterPosition:0 numberOfCharacters:len applyRounding:YES attemptFontSubstitution: YES]);
+ return ROUND_TO_INT([data->getRenderer() floatWidthForCharacters:(const UniChar *)uchars stringLength:len fromCharacterPosition:0 numberOfCharacters:len withPadding: 0 applyRounding:YES attemptFontSubstitution: YES widths: 0]);
}
float QFontMetrics::floatWidth(const QChar *uchars, int slen, int pos, int len) const
{
- return [data->getRenderer() floatWidthForCharacters:(const UniChar *)uchars stringLength:slen fromCharacterPosition:pos numberOfCharacters:len applyRounding: YES attemptFontSubstitution: YES];
+ return [data->getRenderer() floatWidthForCharacters:(const UniChar *)uchars stringLength:slen fromCharacterPosition:pos numberOfCharacters:len withPadding: 0 applyRounding: YES attemptFontSubstitution: YES widths: 0];
}
-float QFontMetrics::floatCharacterWidth(const QChar *uchars, int slen, int pos) const
+float QFontMetrics::floatCharacterWidths(const QChar *uchars, int slen, int pos, int len, int toAdd, float *buffer) const
{
- return [data->getRenderer() floatWidthForCharacters:(const UniChar *)uchars stringLength:slen fromCharacterPosition:pos numberOfCharacters:1 applyRounding: YES attemptFontSubstitution: YES];
+ return [data->getRenderer() floatWidthForCharacters:(const UniChar *)uchars stringLength:slen fromCharacterPosition:pos numberOfCharacters:len withPadding: toAdd applyRounding: YES attemptFontSubstitution: YES widths: (float *)buffer];
}
QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
diff --git a/WebCore/kwq/KWQPainter.mm b/WebCore/kwq/KWQPainter.mm
index e29718e..b39608d 100644
--- a/WebCore/kwq/KWQPainter.mm
+++ b/WebCore/kwq/KWQPainter.mm
@@ -359,7 +359,7 @@ void QPainter::drawText(int x, int y, int, int, int alignmentFlags, const QStrin
const UniChar* str = (const UniChar*)qstring.unicode();
if (alignmentFlags & Qt::AlignRight)
- x -= ROUND_TO_INT([renderer floatWidthForCharacters:(const UniChar *)str stringLength:qstring.length() fromCharacterPosition:0 numberOfCharacters:qstring.length() applyRounding:YES attemptFontSubstitution: YES]);
+ x -= ROUND_TO_INT([renderer floatWidthForCharacters:(const UniChar *)str stringLength:qstring.length() fromCharacterPosition:0 numberOfCharacters:qstring.length() withPadding: 0 applyRounding:YES attemptFontSubstitution: YES widths: 0]);
[renderer drawCharacters:str stringLength:qstring.length()
fromCharacterPosition:0
diff --git a/WebCore/kwq/WebCoreTextRenderer.h b/WebCore/kwq/WebCoreTextRenderer.h
index 5469f58..843c85a 100644
--- a/WebCore/kwq/WebCoreTextRenderer.h
+++ b/WebCore/kwq/WebCoreTextRenderer.h
@@ -38,7 +38,7 @@
- (float)xHeight;
// horizontal metrics
-- (float)floatWidthForCharacters:(const unichar *)characters stringLength:(unsigned)length fromCharacterPosition: (int)pos numberOfCharacters: (int)len applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptFontSubstitution;
+- (float)floatWidthForCharacters:(const unichar *)characters stringLength:(unsigned)length fromCharacterPosition: (int)pos numberOfCharacters: (int)len withPadding: (int)padding applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptFontSubstitution widths: (float *)buffer;
// drawing
- (void)drawCharacters:(const UniChar *)characters stringLength:(unsigned)length fromCharacterPosition:(int)from toCharacterPosition:(int)to atPoint:(NSPoint)point withPadding: (int)padding withTextColor:(NSColor *)textColor backgroundColor:(NSColor *)backgroundColor;
diff --git a/WebCore/kwq/qt/qfontmetrics.h b/WebCore/kwq/qt/qfontmetrics.h
index 43bfcfb..064966d 100644
--- a/WebCore/kwq/qt/qfontmetrics.h
+++ b/WebCore/kwq/qt/qfontmetrics.h
@@ -54,7 +54,7 @@ public:
int charWidth(const QString &, int pos) const;
int width(const QChar *, int len) const;
float floatWidth(const QChar *, int slen, int pos, int len) const;
- float floatCharacterWidth(const QChar *, int slen, int pos) const;
+ float floatCharacterWidths(const QChar *, int slen, int pos, int len, int toAdd, float *buffer) const;
QRect boundingRect(const QString &, int len=-1) const;
QRect boundingRect(int, int, int, int, int, const QString &) const;
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 88d7e8c..53e534d 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,21 @@
+2002-09-13 Richard Williamson (Home) <rjw at apple.com>
+
+ Adding padding and widths buffer to our canonical measurement
+ method. The padding argument is used to 'pad' measurements in
+ that same way that drawing is padded. The widths parameter
+ allows a caller to pass a buffer to get all the individual
+ character widths for the run of characters in the string.
+
+ * Misc.subproj/WebStringTruncator.m:
+ (+[WebStringTruncator rightTruncateString:toWidth:withFont:]):
+ (+[WebStringTruncator centerTruncateString:toWidth:withFont:]):
+ * WebCoreSupport.subproj/WebTextRenderer.h:
+ * WebCoreSupport.subproj/WebTextRenderer.m:
+ (-[WebTextRenderer widthForCharacters:length:]):
+ (-[WebTextRenderer drawGlyphs:numGlyphs:fromGlyphPosition:toGlyphPosition:atPoint:withPadding:withTextColor:backgroundColor:]):
+ (-[WebTextRenderer floatWidthForCharacters:stringLength:characterPosition:]):
+ (-[WebTextRenderer floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:]):
+
2002-09-13 Darin Adler <darin at apple.com>
Fix dataSource-related plugin crash.
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index 88d7e8c..53e534d 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,21 @@
+2002-09-13 Richard Williamson (Home) <rjw at apple.com>
+
+ Adding padding and widths buffer to our canonical measurement
+ method. The padding argument is used to 'pad' measurements in
+ that same way that drawing is padded. The widths parameter
+ allows a caller to pass a buffer to get all the individual
+ character widths for the run of characters in the string.
+
+ * Misc.subproj/WebStringTruncator.m:
+ (+[WebStringTruncator rightTruncateString:toWidth:withFont:]):
+ (+[WebStringTruncator centerTruncateString:toWidth:withFont:]):
+ * WebCoreSupport.subproj/WebTextRenderer.h:
+ * WebCoreSupport.subproj/WebTextRenderer.m:
+ (-[WebTextRenderer widthForCharacters:length:]):
+ (-[WebTextRenderer drawGlyphs:numGlyphs:fromGlyphPosition:toGlyphPosition:atPoint:withPadding:withTextColor:backgroundColor:]):
+ (-[WebTextRenderer floatWidthForCharacters:stringLength:characterPosition:]):
+ (-[WebTextRenderer floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:]):
+
2002-09-13 Darin Adler <darin at apple.com>
Fix dataSource-related plugin crash.
diff --git a/WebKit/Misc.subproj/WebStringTruncator.m b/WebKit/Misc.subproj/WebStringTruncator.m
index 2956998..75b1a58 100644
--- a/WebKit/Misc.subproj/WebStringTruncator.m
+++ b/WebKit/Misc.subproj/WebStringTruncator.m
@@ -70,18 +70,18 @@ static float currentEllipsisWidth;
[string getCharacters:stringBuffer];
renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font];
width = [renderer floatWidthForCharacters:stringBuffer
- stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength applyRounding: NO attemptFontSubstitution: YES];
+ stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength withPadding: 0 applyRounding: NO attemptFontSubstitution: YES widths: 0];
if (width <= maxWidth)
return string;
ellipsis = ELLIPSIS_CHARACTER;
- ellipsisWidth = [renderer floatWidthForCharacters:&ellipsis stringLength:1 fromCharacterPosition: 0 numberOfCharacters: 1 applyRounding: NO attemptFontSubstitution: YES];
+ ellipsisWidth = [renderer floatWidthForCharacters:&ellipsis stringLength:1 fromCharacterPosition: 0 numberOfCharacters: 1 withPadding: 0 applyRounding: NO attemptFontSubstitution: YES widths: 0];
maxWidth -= ellipsisWidth;
while (width > maxWidth && truncatedLength){
truncatedLength--;
width = [renderer floatWidthForCharacters:stringBuffer
- stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength applyRounding: NO attemptFontSubstitution: YES];
+ stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength withPadding: 0 applyRounding: NO attemptFontSubstitution: YES widths: 0];
}
stringBuffer[truncatedLength++] = ELLIPSIS_CHARACTER;
@@ -111,7 +111,7 @@ static float currentEllipsisWidth;
[WebTextRendererFactory createSharedFactory];
currentRenderer = [[[WebTextRendererFactory sharedFactory] rendererWithFont:font] retain];
ellipsis = ELLIPSIS_CHARACTER;
- currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis stringLength:1 fromCharacterPosition: 0 numberOfCharacters: 1 applyRounding: NO attemptFontSubstitution: YES];
+ currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis stringLength:1 fromCharacterPosition: 0 numberOfCharacters: 1 withPadding: 0 applyRounding: NO attemptFontSubstitution: YES widths: 0];
}
ASSERT(currentRenderer);
@@ -130,7 +130,7 @@ static float currentEllipsisWidth;
}
width = [currentRenderer floatWidthForCharacters:stringBuffer
- stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength applyRounding: NO attemptFontSubstitution: YES];
+ stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength withPadding: 0 applyRounding: NO attemptFontSubstitution: YES widths: 0];
if (width <= maxWidth) {
return string;
}
@@ -170,7 +170,7 @@ static float currentEllipsisWidth;
keepCount:keepCount
toBuffer:stringBuffer];
- width = [currentRenderer floatWidthForCharacters:stringBuffer stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength applyRounding: NO attemptFontSubstitution: YES];
+ width = [currentRenderer floatWidthForCharacters:stringBuffer stringLength:truncatedLength fromCharacterPosition: 0 numberOfCharacters: truncatedLength withPadding: 0 applyRounding: NO attemptFontSubstitution: YES widths: 0];
if (width <= maxWidth) {
keepCountForLargestKnownToFit = keepCount;
widthForLargestKnownToFit = width;
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRenderer.h b/WebKit/WebCoreSupport.subproj/WebTextRenderer.h
index f31a46d..c4a4485 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRenderer.h
+++ b/WebKit/WebCoreSupport.subproj/WebTextRenderer.h
@@ -30,7 +30,4 @@ typedef struct GlyphMap GlyphMap;
- initWithFont:(NSFont *)font;
-// Set applyRounding = NO to get an Cocoa equivalent width.
-- (float)floatWidthForCharacters:(const unichar *)characters stringLength:(unsigned)length fromCharacterPosition: (int)pos numberOfCharacters: (int)len applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptFontSubstitution;
-
@end
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
index 3bab301..fc24534 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
@@ -340,7 +340,7 @@ static BOOL bufferTextDrawing = NO;
- (int)widthForCharacters:(const UniChar *)characters length:(unsigned)stringLength
{
- return ROUND_TO_INT([self floatWidthForCharacters:characters stringLength:stringLength fromCharacterPosition:0 numberOfCharacters:stringLength applyRounding:YES attemptFontSubstitution: YES]);
+ return ROUND_TO_INT([self floatWidthForCharacters:characters stringLength:stringLength fromCharacterPosition:0 numberOfCharacters:stringLength withPadding: 0 applyRounding:YES attemptFontSubstitution: YES widths: 0]);
}
- (int)widthForString:(NSString *)string
@@ -458,6 +458,7 @@ static BOOL bufferTextDrawing = NO;
// Calculate advances for the entire string taking into account.
// 1. Rounding of spaces.
// 2. Ceil word widths to guarantee integer word widths.
+ // 3. Any justification padding.
for (i = 0; i < numGlyphs; i++) {
advances[i].width = widthForGlyph(self, glyphToWidthMap, glyphs[i]);
if (glyphs[i] == spaceGlyph){
@@ -466,8 +467,16 @@ static BOOL bufferTextDrawing = NO;
advances[i-1].width += ceil (wordWidth) - wordWidth;
}
if (padding > 0){
- advances[i].width = ROUND_TO_INT(advances[i].width) + padPerSpace;
- padding -= padPerSpace;
+ // Only use left over padding if note evenly divisible by
+ // number of spaces.
+ if (padding < padPerSpace){
+ advances[i].width = ROUND_TO_INT(advances[i].width) + padding;
+ padding = 0;
+ }
+ else {
+ advances[i].width = ROUND_TO_INT(advances[i].width) + padPerSpace;
+ padding -= padPerSpace;
+ }
}
else
advances[i].width = ROUND_TO_INT(advances[i].width);
@@ -790,24 +799,39 @@ cleanup:
// Return the width of the first complete character at the specified position. Even though
// the first 'character' may contain more than one unicode characters this method will
// work correctly.
- return [self floatWidthForCharacters:characters stringLength:stringLength fromCharacterPosition:pos numberOfCharacters:1 applyRounding: YES attemptFontSubstitution: YES];
+ return [self floatWidthForCharacters:characters stringLength:stringLength fromCharacterPosition:pos numberOfCharacters:1 withPadding: 0 applyRounding: YES attemptFontSubstitution: YES widths: nil];
}
- (float)floatWidthForCharacters:(const UniChar *)characters stringLength:(unsigned)stringLength fromCharacterPosition: (int)pos numberOfCharacters: (int)len
{
- return [self floatWidthForCharacters:characters stringLength:stringLength fromCharacterPosition:pos numberOfCharacters:len applyRounding: YES attemptFontSubstitution: YES];
+ return [self floatWidthForCharacters:characters stringLength:stringLength fromCharacterPosition:pos numberOfCharacters:len withPadding: 0 applyRounding: YES attemptFontSubstitution: YES widths: nil];
}
-- (float)floatWidthForCharacters:(const UniChar *)characters stringLength:(unsigned)stringLength fromCharacterPosition: (int)pos numberOfCharacters: (int)len applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptSubstitution
+- (float)floatWidthForCharacters:(const UniChar *)characters stringLength:(unsigned)stringLength fromCharacterPosition: (int)pos numberOfCharacters: (int)len withPadding: (int)padding applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptSubstitution widths: (float *)widthBuffer;
{
float totalWidth = 0;
unsigned int i, clusterLength;
NSFont *substituteFont = nil;
ATSGlyphRef glyphID;
float lastWidth = 0;
-
+ uint numSpaces = 0;
+ int padPerSpace = 0;
+
+ if (len <= 0)
+ return 0;
+
+ // If the padding is non-zero, count the number of spaces in the string
+ // and divide that by the padding for per space addition.
+ if (padding > 0){
+ for (i = pos; i < (uint)pos+len; i++){
+ if (characters[i] == NON_BREAKING_SPACE || characters[i] == SPACE)
+ numSpaces++;
+ }
+ padPerSpace = ceil ((((float)padding) / ((float)numSpaces)));
+ }
+
//printf("width: font %s, size %.1f, text \"%s\"\n", [[font fontName] cString], [font pointSize], [[NSString stringWithCharacters:characters length:length] UTF8String]);
for (i = pos; i < stringLength; i++) {
UniChar c = characters[i];
@@ -826,9 +850,10 @@ cleanup:
if ((int)i - pos >= len) {
// Check if next character is a space. If so, we have to apply rounding.
if (c == SPACE && applyRounding) {
- //totalWidth -= lastWidth;
- //totalWidth += ROUND_TO_INT(lastWidth);
- totalWidth += ceil(totalWidth) - totalWidth;
+ float delta = ceil(totalWidth) - totalWidth;
+ totalWidth += delta;
+ if (widthBuffer)
+ widthBuffer[i - pos - 1] += delta;
}
break;
}
@@ -851,30 +876,48 @@ cleanup:
clusterLength = findLengthOfCharacterCluster (&characters[i], stringLength - i);
substituteFont = [self substituteFontForCharacters: &characters[i] length: clusterLength];
if (substituteFont) {
- lastWidth = [[[WebTextRendererFactory sharedFactory] rendererWithFont: substituteFont] floatWidthForCharacters: &characters[i] stringLength: clusterLength fromCharacterPosition: pos numberOfCharacters: len applyRounding: YES attemptFontSubstitution: NO];
+ lastWidth = [[[WebTextRendererFactory sharedFactory] rendererWithFont: substituteFont] floatWidthForCharacters: &characters[i] stringLength: clusterLength fromCharacterPosition: pos numberOfCharacters: len withPadding: 0 applyRounding: YES attemptFontSubstitution: NO widths: 0];
}
}
if (glyphID > 0 || ((glyphID == 0) && substituteFont == nil)) {
if (glyphID == spaceGlyph && applyRounding) {
if (lastWidth > 0){
- //totalWidth -= lastWidth;
- //totalWidth += ROUND_TO_INT(lastWidth);
- totalWidth += ceil(totalWidth) - totalWidth;
+ float delta = ceil(totalWidth) - totalWidth;
+ totalWidth += delta;
+ if (widthBuffer)
+ widthBuffer[i - pos - 1] += delta;
}
lastWidth = ROUND_TO_INT(widthForGlyph(self, glyphToWidthMap, glyphID));
+ if (padding > 0){
+ // Only use left over padding if note evenly divisible by
+ // number of spaces.
+ if (padding < padPerSpace){
+ lastWidth += padding;
+ padding = 0;
+ }
+ else {
+ lastWidth += padPerSpace;
+ padding -= padPerSpace;
+ }
+ }
}
else
lastWidth = widthForGlyph(self, glyphToWidthMap, glyphID);
}
-
+ if (widthBuffer)
+ widthBuffer[i - pos] = lastWidth;
totalWidth += lastWidth;
}
// Don't ever apply rounding for single character. Single character measurement
// intra word needs to be non-ceiled.
- if ((len > 1 || stringLength == 1) && applyRounding)
- totalWidth += ceil(totalWidth) - totalWidth;
+ if ((len > 1 || stringLength == 1) && applyRounding){
+ float delta = ceil(totalWidth) - totalWidth;
+ totalWidth += delta;
+ if (widthBuffer)
+ widthBuffer[len-1] += delta;
+ }
return totalWidth;
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list