📄 khtml_scaling_patch.txt
字号:
Index: khtml_part.cpp===================================================================RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,vretrieving revision 1.530.2.16diff -u -p -b -r1.530.2.16 khtml_part.cpp--- khtml_part.cpp 2001/11/09 02:50:23 1.530.2.16+++ khtml_part.cpp 2002/03/11 11:30:59@@ -467,6 +467,8 @@ void KHTMLPart::init( KHTMLView *view, G d = new KHTMLPartPrivate(parent()); kdDebug(6050) << "KHTMLPart::init this=" << this << " d=" << d << endl; + m_scalingFactor = 100;+ d->m_view = view; setWidget( d->m_view ); @@ -4360,6 +4362,13 @@ void KHTMLPart::slotActiveFrameChanged( // (note: childObject returns 0 if the argument is 0) d->m_extension->setExtensionProxy( KParts::BrowserExtension::childObject( d->m_activeFrame ) );+}++void KHTMLPart::setScalingFactor( ushort factor )+{+ m_scalingFactor = factor;+ if ( d->m_doc )+ d->m_doc->applyChanges(); } void KHTMLPart::setActiveNode(const DOM::Node &node)Index: khtml_part.h===================================================================RCS file: /home/kde/kdelibs/khtml/khtml_part.h,vretrieving revision 1.146.2.1diff -u -p -b -r1.146.2.1 khtml_part.h--- khtml_part.h 2001/10/30 00:22:51 1.146.2.1+++ khtml_part.h 2002/03/11 11:30:59@@ -722,6 +722,9 @@ public: */ QString jsDefaultStatusBarText() const; + void setScalingFactor( ushort factor );+ ushort scalingFactor() const { return m_scalingFactor; }+ signals: /** * Emitted if the cursor is moved over an URL.@@ -1046,6 +1049,8 @@ private: void checkEmitLoadEvent(); void emitLoadEvent(); void emitUnloadEvent();++ ushort m_scalingFactor; KHTMLPartPrivate *d; friend class KHTMLPartPrivate;Index: khtml_settings.cc===================================================================RCS file: /home/kde/kdelibs/khtml/khtml_settings.cc,vretrieving revision 1.65.2.1diff -u -p -b -r1.65.2.1 khtml_settings.cc--- khtml_settings.cc 2001/09/07 15:05:44 1.65.2.1+++ khtml_settings.cc 2002/03/11 11:31:00@@ -126,6 +126,9 @@ void KHTMLSettings::init( KConfig * conf if ( reset || config->hasKey( "MinimumFontSize" ) ) m_minFontSize = config->readNumEntry( "MinimumFontSize", HTML_DEFAULT_MIN_FONT_SIZE ); + if ( reset || config->hasKey( "FixedFontSize" ) )+ m_fixedFontSize = config->readNumEntry( "FixedFontSize", 0 );+ if ( reset || config->hasKey( "MediumFontSize" ) ) { m_fontSize = config->readNumEntry( "MediumFontSize", 10 ); resetFontSizes();Index: khtml_settings.h===================================================================RCS file: /home/kde/kdelibs/khtml/khtml_settings.h,vretrieving revision 1.23diff -u -p -b -r1.23 khtml_settings.h--- khtml_settings.h 2001/03/10 21:21:12 1.23+++ khtml_settings.h 2002/03/11 11:31:00@@ -82,6 +82,7 @@ public: void resetFontSizes(); int minFontSize() const { return m_minFontSize; }+ uint fixedFontSize() const { return m_fixedFontSize; } // the charset used to display the current document. QFont::CharSet charset() const { return m_charset; }@@ -137,6 +138,7 @@ private: int m_fontSize; QValueList<int> m_fontSizes; int m_minFontSize;+ uint m_fixedFontSize; QFont::CharSet m_charset; QFont::CharSet m_script;Index: css/css_valueimpl.cpp===================================================================RCS file: /home/kde/kdelibs/khtml/css/css_valueimpl.cpp,vretrieving revision 1.49diff -u -p -b -r1.49 css_valueimpl.cpp--- css/css_valueimpl.cpp 2001/07/29 16:12:45 1.49+++ css/css_valueimpl.cpp 2002/03/11 11:31:00@@ -29,9 +29,17 @@ #include "dom_string.h" #include "dom_stringimpl.h" #include "dom_nodeimpl.h"+#include "xml/dom_docimpl.h"+#include "rendering/render_style.h" #include "misc/loader.h"+#include "misc/helper.h" +#include "khtmlview.h"+#include "khtml_part.h"+#include "khtml_settings.h"++#include <qpaintdevicemetrics.h> #include <kdebug.h> #include "cssvalues.h"@@ -657,6 +665,61 @@ DOM::DOMString CSSPrimitiveValueImpl::cs break; } return text;+}++int CSSPrimitiveValueImpl::computeLength(khtml::RenderStyle *style, DOM::DocumentImpl *doc )+{+ return ( int ) computeLengthFloat( style, doc );+}++float CSSPrimitiveValueImpl::computeLengthFloat(khtml::RenderStyle *style, DOM::DocumentImpl *doc )+{+ float dpiY = 72.; // fallback+ QPaintDeviceMetrics *devMetrics = doc->paintDeviceMetrics();+ if ( devMetrics )+ dpiY = devMetrics->logicalDpiY();+ if ( !khtml::printpainter && dpiY < 96 )+ dpiY = 96.;++ float factor = 1.;+ float documentScalingFactor = (float)doc->view()->part()->scalingFactor() / 100.;+ switch(m_type)+ {+ case CSSPrimitiveValue::CSS_EMS:+ factor = style->font().pixelSize();+ documentScalingFactor = 1.;+ break;+ case CSSPrimitiveValue::CSS_EXS:+ {+ QFontMetrics fm = khtml::fontMetrics(style->font());+ QRect b = fm.boundingRect('x');+ factor = b.height();+ documentScalingFactor = 1.;+ break;+ }+ case CSSPrimitiveValue::CSS_PX:+ break;+ case CSSPrimitiveValue::CSS_CM:+ factor = dpiY/2.54; //72dpi/(2.54 cm/in)+ break;+ case CSSPrimitiveValue::CSS_MM:+ factor = dpiY/25.4;+ break;+ case CSSPrimitiveValue::CSS_IN:+ factor = dpiY;+ break;+ case CSSPrimitiveValue::CSS_PT:+ factor = dpiY/72.;+ break;+ case CSSPrimitiveValue::CSS_PC:+ // 1 pc == 12 pt+ factor = dpiY*12./72.;+ break;+ default:+ return -1;+ }+ return m_value.num*factor*documentScalingFactor;+ } // -----------------------------------------------------------------Index: css/css_valueimpl.h===================================================================RCS file: /home/kde/kdelibs/khtml/css/css_valueimpl.h,vretrieving revision 1.24diff -u -p -b -r1.24 css_valueimpl.h--- css/css_valueimpl.h 2001/07/29 16:12:45 1.24+++ css/css_valueimpl.h 2002/03/11 11:31:00@@ -32,6 +32,7 @@ namespace khtml { class CachedImage;+ class RenderStyle; }; namespace DOM {@@ -177,6 +178,20 @@ public: virtual bool parseString( const DOMString &string, bool = false); virtual DOM::DOMString cssText() const;++ /*+ * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get+ * the fontinfo in case val is defined in em or ex.+ *+ * The metrics have to be a bit different for screen and printer output.+ * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi+ *+ * this is screen/printer dependent, so we probably need a config option for this,+ * and some tool to calibrate.+ */+ int computeLength(khtml::RenderStyle *style, DOM::DocumentImpl *doc );++ float computeLengthFloat(khtml::RenderStyle *style, DOM::DocumentImpl *doc ); protected: int m_type;Index: css/csshelper.cpp===================================================================RCS file: /home/kde/kdelibs/khtml/css/csshelper.cpp,vretrieving revision 1.28.2.1diff -u -p -b -r1.28.2.1 csshelper.cpp--- css/csshelper.cpp 2001/08/10 20:46:39 1.28.2.1+++ css/csshelper.cpp 2002/03/11 11:31:00@@ -22,78 +22,11 @@ */ #include "csshelper.h" -#include <qfontmetrics.h>-#include <qfontinfo.h>-#include <qpaintdevice.h>-#include <qpaintdevicemetrics.h>-#include <qfontdatabase.h>--#include <kcharsets.h>-#include <kglobal.h>-#include <kdebug.h>--#include "rendering/render_style.h"-#include "css_valueimpl.h"-#include "dom/css_value.h"-#include "misc/helper.h" #include "xml/dom_stringimpl.h"-#include "khtml_settings.h" using namespace DOM; using namespace khtml; -int khtml::computeLength(DOM::CSSPrimitiveValueImpl *val, RenderStyle *style, QPaintDeviceMetrics *devMetrics )-{- return ( int ) computeLengthFloat( val, style, devMetrics );-}--float khtml::computeLengthFloat(DOM::CSSPrimitiveValueImpl *val, RenderStyle *style, QPaintDeviceMetrics *devMetrics )-{- unsigned short type = val->primitiveType();-- float dpiY = 72.; // fallback- if ( devMetrics )- dpiY = devMetrics->logicalDpiY();- if ( !khtml::printpainter && dpiY < 96 )- dpiY = 96.;-- float factor = 1.;- switch(type)- {- case CSSPrimitiveValue::CSS_EMS:- factor = style->font().pixelSize();- break;- case CSSPrimitiveValue::CSS_EXS:- {- QFontMetrics fm = khtml::fontMetrics(style->font());- QRect b = fm.boundingRect('x');- factor = b.height();- break;- }- case CSSPrimitiveValue::CSS_PX:- break;- case CSSPrimitiveValue::CSS_CM:- factor = dpiY/2.54; //72dpi/(2.54 cm/in)- break;- case CSSPrimitiveValue::CSS_MM:- factor = dpiY/25.4;- break;- case CSSPrimitiveValue::CSS_IN:- factor = dpiY;- break;- case CSSPrimitiveValue::CSS_PT:- factor = dpiY/72.;- break;- case CSSPrimitiveValue::CSS_PC:- // 1 pc == 12 pt- factor = dpiY*12./72.;- break;- default:- return -1;- }- return val->getFloatValue(type)*factor;-}- DOMString khtml::parseURL(const DOMString &url) { DOMStringImpl* i = url.implementation();@@ -138,52 +71,3 @@ DOMString khtml::parseURL(const DOMStrin return j; } --void khtml::setFontSize( QFont &f, int pixelsize, const KHTMLSettings *s, QPaintDeviceMetrics *devMetrics )-{- QFontDatabase db;-- float size = pixelsize;-- float toPix = 1.;- if ( !khtml::printpainter )- toPix = devMetrics->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 = s->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: css/csshelper.h===================================================================RCS file: /home/kde/kdelibs/khtml/css/csshelper.h,vretrieving revision 1.8diff -u -p -b -r1.8 csshelper.h--- css/csshelper.h 2001/06/02 23:37:07 1.8+++ css/csshelper.h 2002/03/11 11:31:00@@ -41,29 +41,9 @@ namespace khtml class RenderStyle; /*- * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get- * the fontinfo in case val is defined in em or ex.- *- * The metrics have to be a bit different for screen and printer output.- * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi- *- * this is screen/printer dependent, so we probably need a config option for this,- * and some tool to calibrate.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -