Commit 050dcb5a authored by rjw's avatar rjw

iFinally fixed underlining, HONEST!


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@534 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0d6e98f1
2002-01-09 Richard Williamson <rjw@apple.com>
Re-implemented underlining. Now it REALLY works, honest.
* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
* src/kwq/KWQFontMetrics.mm: (+[KWQLayoutInfo
drawUnderlineForString:atPoint:withFont:color:]):
* src/kwq/KWQMetrics.h:
* src/kwq/KWQPainter.mm: (QPainter::drawUnderlineForText):
* src/kwq/qt/qpainter.h:
2001-12-20 Richard Williamson <rjw@apple.com>
More tweaks to text layout and underlining.
......
2002-01-09 Richard Williamson <rjw@apple.com>
Re-implemented underlining. Now it REALLY works, honest.
* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
* src/kwq/KWQFontMetrics.mm: (+[KWQLayoutInfo
drawUnderlineForString:atPoint:withFont:color:]):
* src/kwq/KWQMetrics.h:
* src/kwq/KWQPainter.mm: (QPainter::drawUnderlineForText):
* src/kwq/qt/qpainter.h:
2001-12-20 Richard Williamson <rjw@apple.com>
More tweaks to text layout and underlining.
......
2002-01-09 Richard Williamson <rjw@apple.com>
Re-implemented underlining. Now it REALLY works, honest.
* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
* src/kwq/KWQFontMetrics.mm: (+[KWQLayoutInfo
drawUnderlineForString:atPoint:withFont:color:]):
* src/kwq/KWQMetrics.h:
* src/kwq/KWQPainter.mm: (QPainter::drawUnderlineForText):
* src/kwq/qt/qpainter.h:
2001-12-20 Richard Williamson <rjw@apple.com>
More tweaks to text layout and underlining.
......
......@@ -114,7 +114,7 @@ void TextSlave::printDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
#ifdef _KWQ_
int underlineOffset = pt->fontMetrics().baselineOffset() + 2;
//int underlineOffset = pt->fontMetrics().baselineOffset() + 2;
#else
int underlineOffset = ( pt->fontMetrics().height() + m_baseline ) / 2;
if(underlineOffset <= m_baseline) underlineOffset = m_baseline+1;
......@@ -122,7 +122,12 @@ 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 );
#ifdef _KWQ_
QConstString s(m_text, m_len);
pt->drawUnderlineForText(_tx, _ty + m_baseline, s.string());
#else
pt->drawLine(_tx, _ty + underlineOffset, _tx + width, _ty + underlineOffset );
#endif
//pt->drawLine(_tx, _ty, _tx + width, _ty );
//pt->drawLine(_tx, _ty + pt->fontMetrics().height(), _tx + width, _ty + pt->fontMetrics().height() );
}
......
......@@ -97,6 +97,20 @@ static NSMutableDictionary *metricsCache = nil;
}
}
+ (void)drawUnderlineForString: (NSString *)string atPoint: (NSPoint)p withFont: (NSFont *)font color: (NSColor *)color
{
KWQLayoutInfo *metricsCache = [KWQLayoutInfo getMetricsForFont: font];
NSLayoutManager *layoutManager = [metricsCache layoutManagerForString: string];
if (layoutManager != nil){
unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
[metricsCache setColor: color];
[metricsCache setFont: font];
[KWQTextStorage setString: string attributes: [metricsCache attributes]];
NSRect lineRect = [layoutManager lineFragmentRectForGlyphAtIndex: 0 effectiveRange: 0];
[layoutManager underlineGlyphRange:NSMakeRange (0, numberOfGlyphs) underlineType:NSSingleUnderlineStyle lineFragmentRect:lineRect lineFragmentGlyphRange:NSMakeRange (0, numberOfGlyphs) containerOrigin:p];
}
}
+ (KWQLayoutInfo *)getMetricsForFont: (NSFont *)aFont
{
......
......@@ -34,6 +34,7 @@
}
+ (void)drawString: (NSString *)string atPoint: (NSPoint)p withFont: (NSFont *)font color: (NSColor *)color;
+ (void)drawUnderlineForString: (NSString *)string atPoint: (NSPoint)p withFont: (NSFont *)font color: (NSColor *)color;
+ (KWQLayoutInfo *)getMetricsForFont: (NSFont *)aFont;
+ (void)setMetric: (KWQLayoutInfo *)info forFont: (NSFont *)aFont;
- initWithFont: (NSFont *)aFont;
......
......@@ -174,6 +174,10 @@ public:
// private ---------------------------------------------------------------------
#ifdef _KWQ_
void drawUnderlineForText(int x, int y, const QString &, int len=-1);
#endif
private:
// no copying or assignment
// note that these are "standard" (no pendantic stuff needed)
......
......@@ -511,6 +511,27 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
_unlockFocus();
}
void QPainter::drawUnderlineForText(int x, int y, const QString &qstring, int len)
{
NSString *string;
NSFont *font;
_lockFocus();
//font = data->qfont.data->font;
font = data->qfont.font;
if (len == -1)
string = QSTRING_TO_NSSTRING(qstring);
else
string = QSTRING_TO_NSSTRING_LENGTH(qstring,len);
y = y - (ROUND_TO_INT([font defaultLineHeightForFont]) - FLOOR_TO_INT(-[font descender]));
[KWQLayoutInfo drawUnderlineForString: string atPoint: NSMakePoint(x, y) withFont: font color: data->qpen.color().color];
_unlockFocus();
}
void QPainter::drawText(int x, int y, int w, int h, int flags, const QString&qstring, int len,
QRect *br, char **internal)
......
......@@ -174,6 +174,10 @@ public:
// private ---------------------------------------------------------------------
#ifdef _KWQ_
void drawUnderlineForText(int x, int y, const QString &, int len=-1);
#endif
private:
// no copying or assignment
// note that these are "standard" (no pendantic stuff needed)
......
......@@ -114,7 +114,7 @@ void TextSlave::printDecoration( QPainter *pt, RenderText* p, int _tx, int _ty,
#ifdef _KWQ_
int underlineOffset = pt->fontMetrics().baselineOffset() + 2;
//int underlineOffset = pt->fontMetrics().baselineOffset() + 2;
#else
int underlineOffset = ( pt->fontMetrics().height() + m_baseline ) / 2;
if(underlineOffset <= m_baseline) underlineOffset = m_baseline+1;
......@@ -122,7 +122,12 @@ 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 );
#ifdef _KWQ_
QConstString s(m_text, m_len);
pt->drawUnderlineForText(_tx, _ty + m_baseline, s.string());
#else
pt->drawLine(_tx, _ty + underlineOffset, _tx + width, _ty + underlineOffset );
#endif
//pt->drawLine(_tx, _ty, _tx + width, _ty );
//pt->drawLine(_tx, _ty + pt->fontMetrics().height(), _tx + width, _ty + pt->fontMetrics().height() );
}
......
......@@ -97,6 +97,20 @@ static NSMutableDictionary *metricsCache = nil;
}
}
+ (void)drawUnderlineForString: (NSString *)string atPoint: (NSPoint)p withFont: (NSFont *)font color: (NSColor *)color
{
KWQLayoutInfo *metricsCache = [KWQLayoutInfo getMetricsForFont: font];
NSLayoutManager *layoutManager = [metricsCache layoutManagerForString: string];
if (layoutManager != nil){
unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
[metricsCache setColor: color];
[metricsCache setFont: font];
[KWQTextStorage setString: string attributes: [metricsCache attributes]];
NSRect lineRect = [layoutManager lineFragmentRectForGlyphAtIndex: 0 effectiveRange: 0];
[layoutManager underlineGlyphRange:NSMakeRange (0, numberOfGlyphs) underlineType:NSSingleUnderlineStyle lineFragmentRect:lineRect lineFragmentGlyphRange:NSMakeRange (0, numberOfGlyphs) containerOrigin:p];
}
}
+ (KWQLayoutInfo *)getMetricsForFont: (NSFont *)aFont
{
......
......@@ -34,6 +34,7 @@
}
+ (void)drawString: (NSString *)string atPoint: (NSPoint)p withFont: (NSFont *)font color: (NSColor *)color;
+ (void)drawUnderlineForString: (NSString *)string atPoint: (NSPoint)p withFont: (NSFont *)font color: (NSColor *)color;
+ (KWQLayoutInfo *)getMetricsForFont: (NSFont *)aFont;
+ (void)setMetric: (KWQLayoutInfo *)info forFont: (NSFont *)aFont;
- initWithFont: (NSFont *)aFont;
......
......@@ -511,6 +511,27 @@ void QPainter::drawText(int x, int y, const QString &qstring, int len)
_unlockFocus();
}
void QPainter::drawUnderlineForText(int x, int y, const QString &qstring, int len)
{
NSString *string;
NSFont *font;
_lockFocus();
//font = data->qfont.data->font;
font = data->qfont.font;
if (len == -1)
string = QSTRING_TO_NSSTRING(qstring);
else
string = QSTRING_TO_NSSTRING_LENGTH(qstring,len);
y = y - (ROUND_TO_INT([font defaultLineHeightForFont]) - FLOOR_TO_INT(-[font descender]));
[KWQLayoutInfo drawUnderlineForString: string atPoint: NSMakePoint(x, y) withFont: font color: data->qpen.color().color];
_unlockFocus();
}
void QPainter::drawText(int x, int y, int w, int h, int flags, const QString&qstring, int len,
QRect *br, char **internal)
......
......@@ -174,6 +174,10 @@ public:
// private ---------------------------------------------------------------------
#ifdef _KWQ_
void drawUnderlineForText(int x, int y, const QString &, int len=-1);
#endif
private:
// no copying or assignment
// note that these are "standard" (no pendantic stuff needed)
......
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