Commit a14d0834 authored by rjw's avatar rjw

More tweaks to text underlining.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@522 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8e0b0f36
2001-12-20 Richard Williamson <rjw@apple.com>
More tweaks to text layout and underlining.
* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
* src/kwq/KWQFontMetrics.mm: (QFontMetrics::baselineOffset),
(QFontMetrics::ascent), (QFontMetrics::descent), (QFontMetrics::height),
(QFontMetrics::width):
* src/kwq/KWQPainter.mm: (QPainter::drawText):
* src/kwq/qt/qfontmetrics.h:
2001-12-18 Maciej Stachowiak <mjs@apple.com>
* src/kwq/KWQCString.mm: (QCString::QCString),
......
2001-12-20 Richard Williamson <rjw@apple.com>
More tweaks to text layout and underlining.
* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
* src/kwq/KWQFontMetrics.mm: (QFontMetrics::baselineOffset),
(QFontMetrics::ascent), (QFontMetrics::descent), (QFontMetrics::height),
(QFontMetrics::width):
* src/kwq/KWQPainter.mm: (QPainter::drawText):
* src/kwq/qt/qfontmetrics.h:
2001-12-18 Maciej Stachowiak <mjs@apple.com>
* src/kwq/KWQCString.mm: (QCString::QCString),
......
2001-12-20 Richard Williamson <rjw@apple.com>
More tweaks to text layout and underlining.
* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
* src/kwq/KWQFontMetrics.mm: (QFontMetrics::baselineOffset),
(QFontMetrics::ascent), (QFontMetrics::descent), (QFontMetrics::height),
(QFontMetrics::width):
* src/kwq/KWQPainter.mm: (QPainter::drawText):
* src/kwq/qt/qfontmetrics.h:
2001-12-18 Maciej Stachowiak <mjs@apple.com>
* src/kwq/KWQCString.mm: (QCString::QCString),
......
......@@ -170,6 +170,11 @@ void RenderImage::printObject(QPainter *p, int /*_x*/, int /*_y*/, int /*_w*/, i
if(cWidth > 2 && cHeight > 2)
{
//qDebug("qDrawShadePanel %d/%d/%d/%d", _tx + leftBorder, _ty + topBorder, cWidth, cHeight);
#ifdef _KWQ_
p->setPen (Qt::lightGray);
p->setBrush (Qt::NoBrush);
p->drawRect (_tx, _ty, cWidth, cHeight);
#else
qDrawShadePanel( p, _tx + leftBorder + leftPad, _ty + topBorder + topPad, cWidth, cHeight,
KApplication::palette().inactive(), true, 1 );
if(berrorPic && !pix.isNull() && (cWidth >= pix.width()+4) && (cHeight >= pix.height()+4) )
......@@ -191,6 +196,7 @@ void RenderImage::printObject(QPainter *p, int /*_x*/, int /*_y*/, int /*_w*/, i
if (aw>15 && ah>fm.height())
p->drawText(ax, ay, aw, ah , Qt::WordBreak, text );
}
#endif
}
}
else if (image && !image->isTransparent())
......
......@@ -114,10 +114,7 @@ void TextSlave::printDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
#ifdef _KWQ_
int underlineOffset = pt->fontMetrics().height();
int descent = pt->fontMetrics().descent();
if (descent >= 3)
underlineOffset -= (descent - 2);
int underlineOffset = pt->fontMetrics().baselineOffset() + 2;
#else
int underlineOffset = ( pt->fontMetrics().height() + m_baseline ) / 2;
if(underlineOffset <= m_baseline) underlineOffset = m_baseline+1;
......@@ -126,6 +123,8 @@ void TextSlave::printDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
if(deco & UNDERLINE){
//fprintf (stderr, "UNDERLINE (%d, %d) to (%d, %d)\n", _tx, _ty + underlineOffset, _tx + width, _ty + underlineOffset );
pt->drawLine(_tx, _ty + underlineOffset, _tx + width, _ty + underlineOffset );
//pt->drawLine(_tx, _ty, _tx + width, _ty );
//pt->drawLine(_tx, _ty + pt->fontMetrics().height(), _tx + width, _ty + pt->fontMetrics().height() );
}
if(deco & OVERLINE)
pt->drawLine(_tx, _ty, _tx + width, _ty );
......
......@@ -81,6 +81,7 @@ public:
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
#ifdef _KWQ_
int baselineOffset();
void _initialize();
#if (defined(__APPLE__) && defined(__OBJC__) && defined(__cplusplus))
//void _initializeWithData(QFontMetricsPrivate *);
......
......@@ -32,8 +32,9 @@
#import <KWQTextStorage.h>
#import <KWQTextContainer.h>
#define ROUND_TO_INT(f) ((int)rint((f)))
#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;
......@@ -250,23 +251,29 @@ QFontMetrics::~QFontMetrics()
}
int QFontMetrics::baselineOffset()
{
return ascent();
}
int QFontMetrics::ascent() const
{
// Qt seems to use [font defaultLineHeightForFont] + [font descender] instead
// of what seems more natural [font ascender].
// Remember that descender is negative.
//return ROUND_TO_INT([data->font defaultLineHeightForFont] + [data->font descender]);
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:
// "This is always equal to ascent()+descent()+1 (the 1 is for the base line)."
// However, the [font defaultLineHeightForFont] seems more appropriate.
//return ROUND_TO_INT([data->font defaultLineHeightForFont]);
return ROUND_TO_INT([data->font ascender] - [data->font descender] + 1);
return ascent() + descent() + 1;
}
......@@ -301,12 +308,6 @@ int QFontMetrics::width(const QString &qstring, int len) const
}
int QFontMetrics::descent() const
{
return -ROUND_TO_INT([data->font descender]);
}
QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
{
NSString *string;
......
......@@ -451,6 +451,9 @@ void QPainter::drawTiledPixmap( int x, int y, int w, int h,
@end
#endif
#define FLOOR_TO_INT(x) (int)(floor(x))
#define ROUND_TO_INT(x) (int)(((x) > floor(x) + .5) ? ceil(x) : floor(x))
// y is the baseline
void QPainter::drawText(int x, int y, const QString &qstring, int len)
{
......@@ -469,8 +472,8 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
// This will draw the text from the top of the bounding box down.
// Qt expects to draw from the baseline.
y = y - (int)([font defaultLineHeightForFont] + [font descender]);
//y = y - (int)([font defaultLineHeightForFont]);
// Remember that descender is negative.
y = y - (ROUND_TO_INT([font defaultLineHeightForFont]) - FLOOR_TO_INT(-[font descender]));
#ifdef SLOW_SAFE_DRAWING
......
......@@ -81,6 +81,7 @@ public:
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
#ifdef _KWQ_
int baselineOffset();
void _initialize();
#if (defined(__APPLE__) && defined(__OBJC__) && defined(__cplusplus))
//void _initializeWithData(QFontMetricsPrivate *);
......
......@@ -170,6 +170,11 @@ void RenderImage::printObject(QPainter *p, int /*_x*/, int /*_y*/, int /*_w*/, i
if(cWidth > 2 && cHeight > 2)
{
//qDebug("qDrawShadePanel %d/%d/%d/%d", _tx + leftBorder, _ty + topBorder, cWidth, cHeight);
#ifdef _KWQ_
p->setPen (Qt::lightGray);
p->setBrush (Qt::NoBrush);
p->drawRect (_tx, _ty, cWidth, cHeight);
#else
qDrawShadePanel( p, _tx + leftBorder + leftPad, _ty + topBorder + topPad, cWidth, cHeight,
KApplication::palette().inactive(), true, 1 );
if(berrorPic && !pix.isNull() && (cWidth >= pix.width()+4) && (cHeight >= pix.height()+4) )
......@@ -191,6 +196,7 @@ void RenderImage::printObject(QPainter *p, int /*_x*/, int /*_y*/, int /*_w*/, i
if (aw>15 && ah>fm.height())
p->drawText(ax, ay, aw, ah , Qt::WordBreak, text );
}
#endif
}
}
else if (image && !image->isTransparent())
......
......@@ -114,10 +114,7 @@ void TextSlave::printDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
#ifdef _KWQ_
int underlineOffset = pt->fontMetrics().height();
int descent = pt->fontMetrics().descent();
if (descent >= 3)
underlineOffset -= (descent - 2);
int underlineOffset = pt->fontMetrics().baselineOffset() + 2;
#else
int underlineOffset = ( pt->fontMetrics().height() + m_baseline ) / 2;
if(underlineOffset <= m_baseline) underlineOffset = m_baseline+1;
......@@ -126,6 +123,8 @@ void TextSlave::printDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
if(deco & UNDERLINE){
//fprintf (stderr, "UNDERLINE (%d, %d) to (%d, %d)\n", _tx, _ty + underlineOffset, _tx + width, _ty + underlineOffset );
pt->drawLine(_tx, _ty + underlineOffset, _tx + width, _ty + underlineOffset );
//pt->drawLine(_tx, _ty, _tx + width, _ty );
//pt->drawLine(_tx, _ty + pt->fontMetrics().height(), _tx + width, _ty + pt->fontMetrics().height() );
}
if(deco & OVERLINE)
pt->drawLine(_tx, _ty, _tx + width, _ty );
......
......@@ -32,8 +32,9 @@
#import <KWQTextStorage.h>
#import <KWQTextContainer.h>
#define ROUND_TO_INT(f) ((int)rint((f)))
#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;
......@@ -250,23 +251,29 @@ QFontMetrics::~QFontMetrics()
}
int QFontMetrics::baselineOffset()
{
return ascent();
}
int QFontMetrics::ascent() const
{
// Qt seems to use [font defaultLineHeightForFont] + [font descender] instead
// of what seems more natural [font ascender].
// Remember that descender is negative.
//return ROUND_TO_INT([data->font defaultLineHeightForFont] + [data->font descender]);
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:
// "This is always equal to ascent()+descent()+1 (the 1 is for the base line)."
// However, the [font defaultLineHeightForFont] seems more appropriate.
//return ROUND_TO_INT([data->font defaultLineHeightForFont]);
return ROUND_TO_INT([data->font ascender] - [data->font descender] + 1);
return ascent() + descent() + 1;
}
......@@ -301,12 +308,6 @@ int QFontMetrics::width(const QString &qstring, int len) const
}
int QFontMetrics::descent() const
{
return -ROUND_TO_INT([data->font descender]);
}
QRect QFontMetrics::boundingRect(const QString &qstring, int len) const
{
NSString *string;
......
......@@ -451,6 +451,9 @@ void QPainter::drawTiledPixmap( int x, int y, int w, int h,
@end
#endif
#define FLOOR_TO_INT(x) (int)(floor(x))
#define ROUND_TO_INT(x) (int)(((x) > floor(x) + .5) ? ceil(x) : floor(x))
// y is the baseline
void QPainter::drawText(int x, int y, const QString &qstring, int len)
{
......@@ -469,8 +472,8 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
// This will draw the text from the top of the bounding box down.
// Qt expects to draw from the baseline.
y = y - (int)([font defaultLineHeightForFont] + [font descender]);
//y = y - (int)([font defaultLineHeightForFont]);
// Remember that descender is negative.
y = y - (ROUND_TO_INT([font defaultLineHeightForFont]) - FLOOR_TO_INT(-[font descender]));
#ifdef SLOW_SAFE_DRAWING
......
......@@ -81,6 +81,7 @@ public:
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
#ifdef _KWQ_
int baselineOffset();
void _initialize();
#if (defined(__APPLE__) && defined(__OBJC__) && defined(__cplusplus))
//void _initializeWithData(QFontMetricsPrivate *);
......
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