@@ -185,7 +185,7 @@ void QgsComposerHtml::loadHtml()
185185 mLoaded = false ;
186186
187187 // reset page size. otherwise viewport size increases but never decreases again
188- mWebPage ->setViewportSize ( QSize ( 0 , 0 ) );
188+ mWebPage ->setViewportSize ( QSize ( maxFrameWidth () * mHtmlUnitsToMM , 0 ) );
189189
190190 // set html, using the specified url as base if in Url mode
191191 mWebPage ->mainFrame ()->setHtml ( loadedHtml, mContentMode == QgsComposerHtml::Url ? QUrl ( mActualFetchedUrl ) : QUrl () );
@@ -220,21 +220,28 @@ void QgsComposerHtml::frameLoaded( bool ok )
220220 mLoaded = true ;
221221}
222222
223+ double QgsComposerHtml::maxFrameWidth () const
224+ {
225+ double maxWidth = 0 ;
226+ QList<QgsComposerFrame*>::const_iterator frameIt = mFrameItems .constBegin ();
227+ for ( ; frameIt != mFrameItems .constEnd (); ++frameIt )
228+ {
229+ maxWidth = qMax ( maxWidth, ( *frameIt )->boundingRect ().width () );
230+ }
231+
232+ return maxWidth;
233+ }
234+
223235void QgsComposerHtml::recalculateFrameSizes ()
224236{
225- if ( frameCount () < 1 ) return ;
237+ if ( frameCount () < 1 ) return ;
226238
227239 QSize contentsSize = mWebPage ->mainFrame ()->contentsSize ();
228240
229241 // find maximum frame width
230- double maxFrameWidth = 0 ;
231- QList<QgsComposerFrame*>::const_iterator frameIt = mFrameItems .constBegin ();
232- for ( ; frameIt != mFrameItems .constEnd (); ++frameIt )
233- {
234- maxFrameWidth = qMax ( maxFrameWidth, ( *frameIt )->boundingRect ().width () );
235- }
242+ double maxWidth = maxFrameWidth ();
236243 // set content width to match maximum frame width
237- contentsSize.setWidth ( maxFrameWidth * mHtmlUnitsToMM );
244+ contentsSize.setWidth ( maxWidth * mHtmlUnitsToMM );
238245
239246 mWebPage ->setViewportSize ( contentsSize );
240247 mSize .setWidth ( contentsSize.width () / mHtmlUnitsToMM );
0 commit comments