From 200335a17f7365c2be6f1ecd9cd905bee883c0c8 Mon Sep 17 00:00:00 2001 From: ggarand Date: Mon, 23 Jul 2007 00:45:37 +0000 Subject: [PATCH] some work toward having separate settings for the global zoom factor and font-specific font scale factor. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/KDE/kdelibs@691141 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- khtml/css/cssstyleselector.cpp | 6 +++--- khtml/khtml_part.cpp | 44 ++++++++++++++++++++++++++++++++++-------- khtml/khtml_part.h | 19 ++++++++++++++++-- khtml/khtmlpart_p.h | 3 +++ khtml/khtmlview.cpp | 2 +- 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/khtml/css/cssstyleselector.cpp b/khtml/css/cssstyleselector.cpp index 5173ffc5d..4622b7a5b 100644 --- a/khtml/css/cssstyleselector.cpp +++ b/khtml/css/cssstyleselector.cpp @@ -227,7 +227,7 @@ CSSStyleSelector::CSSStyleSelector( DocumentImpl* doc, QString userStyleSheet, S logicalDpiY = doc->logicalDpiY(); if(logicalDpiY) // this may be null, not everyone uses khtmlview (Niko) - computeFontSizes(logicalDpiY, view ? view->part()->zoomFactor() : 100); + computeFontSizes(logicalDpiY, view ? view->part()->fontScaleFactor() : 100); if ( !userStyleSheet.isEmpty() ) { userSheet = new DOM::CSSStyleSheetImpl(doc); @@ -3070,7 +3070,7 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value ) if ( !khtml::printpainter && type != CSSPrimitiveValue::CSS_EMS && type != CSSPrimitiveValue::CSS_EXS && view && view->part()) size = int( primitiveValue->computeLengthFloat(parentStyle, logicalDpiY) * - view->part()->zoomFactor() ) / 100; + view->part()->fontScaleFactor() ) / 100; else size = int( primitiveValue->computeLengthFloat(parentStyle, logicalDpiY) ); } @@ -3150,7 +3150,7 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value ) if ( !khtml::printpainter && type != CSSPrimitiveValue::CSS_EMS && type != CSSPrimitiveValue::CSS_EXS && view && view->part()) lineHeight = Length(primitiveValue->computeLength(style, logicalDpiY) * - view->part()->zoomFactor()/100, Fixed ); + view->part()->fontScaleFactor()/100, Fixed ); else lineHeight = Length(primitiveValue->computeLength(style, logicalDpiY), Fixed ); } else if (type == CSSPrimitiveValue::CSS_PERCENTAGE) diff --git a/khtml/khtml_part.cpp b/khtml/khtml_part.cpp index f7648ad8f..267215589 100644 --- a/khtml/khtml_part.cpp +++ b/khtml/khtml_part.cpp @@ -5370,6 +5370,7 @@ void KHTMLPart::saveState( QDataStream &stream ) stream << d->m_encoding << d->m_sheetUsed << docState; stream << d->m_zoomFactor; + stream << d->m_fontScaleFactor; stream << d->m_httpHeaders; stream << d->m_pageServices; @@ -5455,6 +5456,10 @@ void KHTMLPart::restoreState( QDataStream &stream ) int zoomFactor; stream >> zoomFactor; setZoomFactor(zoomFactor); + + int fontScaleFactor; + stream >> fontScaleFactor; + setFontScaleFactor(fontScaleFactor); stream >> d->m_httpHeaders; stream >> d->m_pageServices; @@ -5713,14 +5718,7 @@ void KHTMLPart::setZoomFactor (int percent) d->m_zoomFactor = percent; if(d->m_view) { - QApplication::setOverrideCursor( Qt::WaitCursor ); - -// ### make the increasing/decreasing of font size a separate setting -// -// if (d->m_doc->styleSelector()) -// d->m_doc->styleSelector()->computeFontSizes(d->m_doc->paintDeviceMetrics(), d->m_zoomFactor); -// d->m_doc->recalcStyle( NodeImpl::Force ); - + QApplication::setOverrideCursor( Qt::WaitCursor ); d->m_view->setZoomLevel( d->m_zoomFactor ); QApplication::restoreOverrideCursor(); } @@ -5739,6 +5737,36 @@ void KHTMLPart::setZoomFactor (int percent) } } +void KHTMLPart::setFontScaleFactor(int percent) +{ + if (percent < minZoom) percent = minZoom; + if (percent > maxZoom) percent = maxZoom; + if (d->m_fontScaleFactor == percent) return; + d->m_fontScaleFactor = percent; + + if(d->m_view) { + QApplication::setOverrideCursor( Qt::WaitCursor ); + if (d->m_doc->styleSelector()) + d->m_doc->styleSelector()->computeFontSizes(d->m_doc->paintDeviceMetrics(), d->m_fontScaleFactor); + d->m_doc->recalcStyle( NodeImpl::Force ); + QApplication::restoreOverrideCursor(); + } + + ConstFrameIt it = d->m_frames.begin(); + const ConstFrameIt end = d->m_frames.end(); + for (; it != end; ++it ) + if ( !( *it )->m_part.isNull() && (*it)->m_part->inherits( "KHTMLPart" ) ) { + KParts::ReadOnlyPart* const p = ( *it )->m_part; + static_cast( p )->setFontScaleFactor(d->m_fontScaleFactor); + } +} + +int KHTMLPart::fontScaleFactor() const +{ + return d->m_fontScaleFactor; +} + + void KHTMLPart::slotZoomView( int delta ) { if ( delta < 0 ) diff --git a/khtml/khtml_part.h b/khtml/khtml_part.h index 80e86dfaf..df844567b 100644 --- a/khtml/khtml_part.h +++ b/khtml/khtml_part.h @@ -735,8 +735,7 @@ public: /** * Sets the Zoom factor. The value is given in percent, larger values mean a - * generally larger font and larger page contents. It is not guaranteed that - * all parts of the page are scaled with the same factor though. + * generally larger font and larger page contents. * * The given value should be in the range of 20..300, values outside that * range are not guaranteed to work. A value of 100 will disable all zooming @@ -751,6 +750,22 @@ public: int zoomFactor() const; /** + * Sets the scale factor to be applied to fonts. The value is given in percent, + * larger values mean generally larger fonts. + * + * The given value should be in the range of 20..300, values outside that + * range are not guaranteed to work. A value of 100 will disable all scaling of font sizes + * and show the page with the sizes determined via the given lengths in the + * stylesheets. + */ + void setFontScaleFactor(int percent); + + /** + * Returns the current font scale factor. + */ + int fontScaleFactor() const; + + /** * Returns the text the user has marked. */ virtual QString selectedText() const; diff --git a/khtml/khtmlpart_p.h b/khtml/khtmlpart_p.h index 40552a763..a248c4687 100644 --- a/khtml/khtmlpart_p.h +++ b/khtml/khtmlpart_p.h @@ -148,6 +148,7 @@ public: m_bClearing = false; m_bCleared = false; m_zoomFactor = 100; + m_fontScaleFactor = 100; m_bDnd = true; m_startOffset = m_endOffset = 0; m_startBeforeEnd = true; @@ -213,6 +214,7 @@ public: m_caretMode = part->d->m_caretMode; m_designMode = part->d->m_designMode; m_zoomFactor = part->d->m_zoomFactor; + m_fontScaleFactor = part->d->m_fontScaleFactor; m_autoDetectLanguage = part->d->m_autoDetectLanguage; m_encoding = part->d->m_encoding; m_haveEncoding = part->d->m_haveEncoding; @@ -368,6 +370,7 @@ public: KHTMLPart::GUIProfile m_guiProfile; int m_zoomFactor; + int m_fontScaleFactor; QString m_strSelectedURL; QString m_strSelectedURLTarget; diff --git a/khtml/khtmlview.cpp b/khtml/khtmlview.cpp index 59376b1a1..5eddcb77d 100644 --- a/khtml/khtmlview.cpp +++ b/khtml/khtmlview.cpp @@ -3067,7 +3067,7 @@ void KHTMLView::print(bool quick) khtml::setPrintPainter( 0 ); setMediaType( oldMediaType ); m_part->xmlDocImpl()->setPaintDevice( this ); - m_part->xmlDocImpl()->styleSelector()->computeFontSizes(m_part->xmlDocImpl()->logicalDpiY(), m_part->zoomFactor()); + m_part->xmlDocImpl()->styleSelector()->computeFontSizes(m_part->xmlDocImpl()->logicalDpiY(), m_part->fontScaleFactor()); m_part->xmlDocImpl()->updateStyleSelector(); viewport()->unsetCursor(); } -- 2.11.4.GIT