📄 khtml_scaling_patch.txt
字号:
- */- int computeLength(DOM::CSSPrimitiveValueImpl *val, RenderStyle *style, QPaintDeviceMetrics *devMetrics );-- float computeLengthFloat(DOM::CSSPrimitiveValueImpl *val, RenderStyle *style, QPaintDeviceMetrics *devMetrics );-- /* * mostly just removes the url("...") brace */ DOM::DOMString parseURL(const DOM::DOMString &url);-- /*- Sets the font to the size closest to the requested one while trying not to use a scaled bitmap font- */- void setFontSize( QFont &f, int pixelSize, const KHTMLSettings *s, QPaintDeviceMetrics *devMetrics );- }; Index: css/cssstyleselector.cpp===================================================================RCS file: /home/kde/kdelibs/khtml/css/cssstyleselector.cpp,vretrieving revision 1.169.2.4diff -u -p -b -r1.169.2.4 cssstyleselector.cpp--- css/cssstyleselector.cpp 2001/11/01 18:56:45 1.169.2.4+++ css/cssstyleselector.cpp 2002/03/11 11:31:02@@ -828,7 +828,7 @@ void CSSOrderedPropertyList::append(DOM: // ------------------------------------------------------------------------------------- // this is mostly boring stuff on how to apply a certain rule to the renderstyle... -static Length convertToLength( CSSPrimitiveValueImpl *primitiveValue, RenderStyle *style, QPaintDeviceMetrics *paintDeviceMetrics, bool *ok = 0 )+static Length convertToLength( CSSPrimitiveValueImpl *primitiveValue, RenderStyle *style, DOM::DocumentImpl *doc, bool *ok = 0 ) { Length l; if ( !primitiveValue ) {@@ -837,7 +837,7 @@ static Length convertToLength( CSSPrimit } else { int type = primitiveValue->primitiveType(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- l = Length(computeLength(primitiveValue, style, paintDeviceMetrics), Fixed);+ l = Length(primitiveValue->computeLength(style, doc), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) l = Length(int(primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE)), Percent); else if(type == CSSPrimitiveValue::CSS_NUMBER)@@ -852,7 +852,8 @@ void khtml::applyRule(khtml::RenderStyle { CSSValueImpl *value = prop->value(); - QPaintDeviceMetrics *paintDeviceMetrics = e->ownerDocument()->paintDeviceMetrics();+ DOM::DocumentImpl *doc = e->ownerDocument();+ QPaintDeviceMetrics *paintDeviceMetrics = doc->paintDeviceMetrics(); //kdDebug( 6080 ) << "applying property " << prop->m_id << endl; @@ -880,7 +881,6 @@ void khtml::applyRule(khtml::RenderStyle case CSS_VAL_FIXED: { style->setBackgroundAttachment(false);- DocumentImpl *doc = e->ownerDocument(); // only use slow repaints if we actually have a background pixmap if( style->backgroundImage() ) doc->view()->useSlowRepaints();@@ -1291,7 +1291,6 @@ void khtml::applyRule(khtml::RenderStyle p = ABSOLUTE; break; case CSS_VAL_FIXED: {- DocumentImpl *doc = e->ownerDocument(); doc->view()->useSlowRepaints(); p = FIXED; break;@@ -1392,7 +1391,7 @@ void khtml::applyRule(khtml::RenderStyle Length l; int type = primitiveValue->primitiveType(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- l = Length(computeLength(primitiveValue, style, paintDeviceMetrics), Fixed);+ l = Length(primitiveValue->computeLength(style, doc), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) l = Length((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else@@ -1406,7 +1405,7 @@ void khtml::applyRule(khtml::RenderStyle Length l; int type = primitiveValue->primitiveType(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- l = Length(computeLength(primitiveValue, style, paintDeviceMetrics), Fixed);+ l = Length(primitiveValue->computeLength(style, doc), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) l = Length((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else@@ -1418,7 +1417,7 @@ void khtml::applyRule(khtml::RenderStyle { if(!primitiveValue) break; short spacing = 0;- spacing = computeLength(primitiveValue, style, paintDeviceMetrics);+ spacing = primitiveValue->computeLength(style, doc); style->setBorderSpacing(spacing); break; }@@ -1624,7 +1623,7 @@ void khtml::applyRule(khtml::RenderStyle width = 5; break; case CSS_VAL_INVALID:- width = computeLength(primitiveValue, style, paintDeviceMetrics);+ width = primitiveValue->computeLength(style, doc); break; default: return;@@ -1676,7 +1675,7 @@ void khtml::applyRule(khtml::RenderStyle return; } if(!primitiveValue) return;- int width = computeLength(primitiveValue, style, paintDeviceMetrics);+ int width = primitiveValue->computeLength(style, doc); // reason : letter or word spacing may be negative. // if( width < 0 ) return; switch(prop->m_id)@@ -1774,7 +1773,7 @@ void khtml::applyRule(khtml::RenderStyle } else if(primitiveValue && !apply) { int type = primitiveValue->primitiveType(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- l = Length(computeLength(primitiveValue, style, paintDeviceMetrics), Fixed);+ l = Length(primitiveValue->computeLength(style, doc), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) l = Length((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else@@ -1851,7 +1850,7 @@ void khtml::applyRule(khtml::RenderStyle { int type = primitiveValue->primitiveType(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- l = Length(computeLength(primitiveValue, style, paintDeviceMetrics), Fixed);+ l = Length(primitiveValue->computeLength(style, doc), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) { // ### compute from parents height!!!@@ -1918,7 +1917,7 @@ void khtml::applyRule(khtml::RenderStyle int type = primitiveValue->primitiveType(); Length l; if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- l = Length( computeLength(primitiveValue, style, paintDeviceMetrics), Fixed );+ l = Length( primitiveValue->computeLength(style, doc), Fixed ); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) l = Length( int( primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) ), Percent ); @@ -1932,7 +1931,7 @@ void khtml::applyRule(khtml::RenderStyle QFont f = style->font(); int oldSize; float size = 0;- int minFontSize = e->ownerDocument()->view()->part()->settings()->minFontSize();+ int minFontSize = doc->view()->part()->settings()->minFontSize(); float toPix = 1.; // fallback if ( !khtml::printpainter )@@ -1940,7 +1939,7 @@ void khtml::applyRule(khtml::RenderStyle if ( !khtml::printpainter && toPix < 96./72. ) toPix = 96./72.; - QValueList<int> standardSizes = e->ownerDocument()->view()->part()->fontSizes();+ QValueList<int> standardSizes = doc->view()->part()->fontSizes(); if(e->parentNode()) { oldSize = e->parentNode()->style()->font().pixelSize(); } else {@@ -1990,7 +1989,7 @@ void khtml::applyRule(khtml::RenderStyle if(e->parentNode()) parentStyle = e->parentNode()->style(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- size = computeLengthFloat(primitiveValue, parentStyle, paintDeviceMetrics);+ size = primitiveValue->computeLengthFloat(parentStyle, doc); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) size = (primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) * parentStyle->font().pixelSize()) / 100;@@ -2005,10 +2004,8 @@ void khtml::applyRule(khtml::RenderStyle //kdDebug( 6080 ) << "computed raw font size: " << size << endl; - const KHTMLSettings *s = e->ownerDocument()->view()->part()->settings();+ doc->setFontSize( f, (int)size ); - setFontSize( f, (int)size, s, paintDeviceMetrics );- //KGlobal::charsets()->setQFont(f, e->ownerDocument()->view()->part()->settings()->charset); style->setFont(f); return;@@ -2056,7 +2053,7 @@ void khtml::applyRule(khtml::RenderStyle if(primitiveValue->getIdent() == CSS_VAL_NORMAL) lineHeight = Length(-100, Percent); else if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG)- lineHeight = Length(computeLength(primitiveValue, style, paintDeviceMetrics), Fixed);+ lineHeight = Length(primitiveValue->computeLength(style, doc), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) lineHeight = Length(int( style->font().pixelSize() * int( primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE)) ) / 100, Fixed); else if(type == CSSPrimitiveValue::CSS_NUMBER)@@ -2109,10 +2106,10 @@ void khtml::applyRule(khtml::RenderStyle RectImpl *rect = primitiveValue->getRectValue(); if ( !rect ) break;- top = convertToLength( rect->top(), style, paintDeviceMetrics );- right = convertToLength( rect->right(), style, paintDeviceMetrics );- bottom = convertToLength( rect->bottom(), style, paintDeviceMetrics );- left = convertToLength( rect->left(), style, paintDeviceMetrics );+ top = convertToLength( rect->top(), style, doc );+ right = convertToLength( rect->right(), style, doc );+ bottom = convertToLength( rect->bottom(), style, doc );+ left = convertToLength( rect->left(), style, doc ); } else if ( primitiveValue->getIdent() != CSS_VAL_AUTO ) { break;@@ -2146,7 +2143,7 @@ void khtml::applyRule(khtml::RenderStyle if(!value->isValueList()) return; CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value); int len = list->length();- const KHTMLSettings *s = e->ownerDocument()->view()->part()->settings();+ const KHTMLSettings *s = doc->view()->part()->settings(); QString available = s->availableFamilies(); QFont f = style->font(); QString family;Index: rendering/render_replaced.cpp===================================================================RCS file: /home/kde/kdelibs/khtml/rendering/render_replaced.cpp,vretrieving revision 1.53diff -u -p -b -r1.53 render_replaced.cpp--- rendering/render_replaced.cpp 2001/07/29 19:48:46 1.53+++ rendering/render_replaced.cpp 2002/03/11 11:31:02@@ -29,6 +29,8 @@ #include "misc/helper.h" #include "khtmlview.h"+#include "khtml_part.h"+#include "khtml_settings.h" using namespace khtml; @@ -94,7 +96,8 @@ short RenderReplaced::calcReplacedWidth( if ( ih > 0 && ( h.isPercent() || h.isFixed() ) ) width = ( ( h.isPercent() ? calcReplacedHeight() : h.value )*intrinsicWidth() ) / ih; else- width = intrinsicWidth();+ // width = intrinsicWidth();+ width = ( intrinsicWidth() * root()->view()->part()->scalingFactor() ) / 100; break; } case Percent:@@ -113,7 +116,8 @@ short RenderReplaced::calcReplacedWidth( width = w.value; break; default:- width = intrinsicWidth();+ width = ( intrinsicWidth() * root()->view()->part()->scalingFactor() ) / 100;+ //width = intrinsicWidth(); break; }; @@ -132,7 +136,8 @@ int RenderReplaced::calcReplacedHeight() if( iw > 0 && ( w.isFixed() || w.isPercent() )) height = (( w.isPercent() ? calcReplacedWidth() : w.value ) * intrinsicHeight()) / iw; else- height = intrinsicHeight();+ // height = intrinsicHeight();+ height = ( intrinsicHeight() * root()->view()->part()->scalingFactor() ) / 100; } break; case Percent:@@ -155,7 +160,8 @@ int RenderReplaced::calcReplacedHeight() height = h.value; break; default:- height = intrinsicHeight();+ height = ( intrinsicHeight() * root()->view()->part()->scalingFactor() ) / 100;+ //height = intrinsicHeight(); }; return height;Index: xml/dom_docimpl.cpp===================================================================RCS file: /home/kde/kdelibs/khtml/xml/dom_docimpl.cpp,vretrieving revision 1.102.2.3diff -u -p -b -r1.102.2.3 dom_docimpl.cpp--- xml/dom_docimpl.cpp 2001/11/01 18:36:11 1.102.2.3+++ xml/dom_docimpl.cpp 2002/03/11 11:31:03@@ -43,6 +43,7 @@ #include <qstack.h> #include <qlist.h> #include <qpaintdevicemetrics.h>+#include <qfontdatabase.h> #include "misc/htmlhashes.h" #include "misc/loader.h" #include <kdebug.h>@@ -591,7 +592,7 @@ void DocumentImpl::recalcStyle() if(size < settings->minFontSize()) size = settings->minFontSize(); - khtml::setFontSize( f, int(size), settings, paintDeviceMetrics() );+ setFontSize( f, int(size) ); KGlobal::charsets()->setQFont(f, settings->charset()); } @@ -1450,6 +1451,63 @@ void DocumentImpl::removeWindowEventList EventListener *DocumentImpl::createHTMLEventListener(QString code) { return view()->part()->createHTMLEventListener(code);+}++void DocumentImpl::setFontSize( QFont &f, int pixelSize )+{+ QFontDatabase db;+ const KHTMLSettings *settings = m_view->part()->settings();++ uint fixedFontSize = settings->fixedFontSize();+ if ( fixedFontSize != 0 )+ {+ f.setPixelSize( fixedFontSize );+ return;+ }++ float size = ( pixelSize * m_view->part()->scalingFactor() ) / 100;++ float toPix = 1.;+ if ( !khtml::printpainter && m_paintDeviceMetrics )+ toPix = m_paintDeviceMetrics->logicalDpiY()/72.;++ // ok, now some magic to get a nice unscaled font+ // ### all other font properties should be set before this one!!!!+ // ####### make it use the charset needed!!!!+ QFont::CharSet cs = settings->charset();+ QString charset = KGlobal::charsets()->xCharsetName( cs );++ if( !db.isSmoothlyScalable(f.family(), db.styleString(f), charset) )+ {+ QValueList<int> pointSizes = db.smoothSizes(f.family(), db.styleString(f), charset);+ // lets see if we find a nice looking font, which is not too far away+ // from the requested one.+ //kdDebug() << "khtml::setFontSize family = " << f.family() << " size requested=" << size << endl;++ QValueList<int>::Iterator it;+ float diff = 1; // ### 100% deviation+ float bestSize = 0;+ for( it = pointSizes.begin(); it != pointSizes.end(); ++it )+ {+ float newDiff = ((*it)*toPix - size)/size;+ //kdDebug( 6080 ) << "smooth font size: " << *it << " diff=" << newDiff << endl;+ if(newDiff < 0) newDiff = -newDiff;+ if(newDiff < diff)+ {+ diff = newDiff;+ bestSize = *it;+ }+ }+ //kdDebug( 6080 ) << "best smooth font size: " << bestSize << " diff=" << diff << endl;+ if ( bestSize != 0 && diff < 0.2 ) // 20% deviation, otherwise we use a scaled font...+ size = bestSize*toPix;+// else if ( size > 4 && size < 16 )+// size = float( int( ( size + 1 ) / 2 )*2 );+ }++ //qDebug(" -->>> using %f pixel font", size);++ f.setPixelSizeFloat( size ); } // ----------------------------------------------------------------------------Index: xml/dom_docimpl.h===================================================================RCS file: /home/kde/kdelibs/khtml/xml/dom_docimpl.h,vretrieving revision 1.57.2.1diff -u -p -b -r1.57.2.1 dom_docimpl.h--- xml/dom_docimpl.h 2001/08/27 12:50:17 1.57.2.1+++ xml/dom_docimpl.h 2002/03/11 11:31:03@@ -264,6 +264,10 @@ public: virtual void removeWindowEventListener(int id); EventListener *createHTMLEventListener(QString code); + /*+ Sets the font to the size closest to the requested one while trying not to use a scaled bitmap font+ */+ void setFontSize( QFont &f, int pixelSize ); signals: void finishedParsing();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -