Commit 83750876 authored by rjw's avatar rjw
Browse files

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
parent 00c21071
2002-09-13 Richard Williamson (Home) <rjw@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@apple.com>
 
Quiet error messages related to the slot/signal changes.
......
2002-09-13 Richard Williamson (Home) <rjw@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@apple.com>
 
Quiet error messages related to the slot/signal changes.
......
2002-09-13 Richard Williamson (Home) <rjw@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@apple.com>
 
Quiet error messages related to the slot/signal changes.
......
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
2002-09-13 Richard Williamson (Home) <rjw@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@apple.com>
Fix dataSource-related plugin crash.
......
2002-09-13 Richard Williamson (Home) <rjw@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@apple.com>
Fix dataSource-related plugin crash.
......
......@@ -70,18 +70,18 @@ + (NSString *)rightTruncateString:(NSString *)string toWidth:(float)maxWidth wit
[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 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
[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 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
}
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 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
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;
......
......@@ -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
......@@ -340,7 +340,7 @@ - (void)dealloc
- (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 @@ - (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs from
// 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 @@ - (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs from
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 @@ - (float)floatWidthForCharacters:(const UniChar *)characters stringLength:(unsig
// 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 @@ - (float)floatWidthForCharacters:(const UniChar *)characters stringLength:(unsig
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 @@ - (float)floatWidthForCharacters:(const UniChar *)characters stringLength:(unsig
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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment