Re: [Okular-devel] Patch for best fit zoom

2010-01-21 Thread Albert Astals Cid
A Dilluns, 18 de gener de 2010, Thomas Fischer va escriure:
 Hello,
 
 as a regular Okular user, I have an itch that I was scratching: I was
 looking for a zoom setting that is appropriate both for viewing
 presentations (in non-fullscreen mode) and text documents (portrait
 format).
 I came up with a best fit zoom level which corresponds to the existing
 fit width and fit page zoom levels.
 The best-fit setting compares the aspect ratios of the document and the
 viewing area it is shown in. If the aspect ratios nearly match, a page
 will be shown in fit page mode. This is useful e.g. for presentations,
 where a slide has a similar aspect ratio like the screen. If the aspect
 ratio is very different, such as in cases with portrait text documents,
 the document is scaled to fit width and you only have to scroll
 vertically. If the document is much wider, it is scaled to fit the
 height and you scroll horizontally only.
 
 The attached patch introduces this feature while being just below 7k in
 size. Additionally, I removed/replaced some fit text zoom which seemed
 to be dead code. The patch is for KDE 4.3.4, but it should be no problem
 apply it to the upcoming 4.4 or trunk.

4.4 is frozen for new features since a lot of time ago, any new feature will 
be for 4.5

 
 However, there is one major bug in my patch. If the ratio between aspect
 ratios is very close to switching between either of the three zooming
 modes, Okular may continuously switch between two modes. This seems to
 happen as Okular shows scrollbars if necessary, which change the view
 area's size (and this aspect), which in turn triggers the change in
 mode. As this new mode does not need scrollbars, they get disabled again
 and the circle closes. I have not yet found a nice and clean solution
 here.

AFAIK you can trigger thist without your patch too.

 
 Comments are welcome.

Here it comes:
The code is isolated enough to guarantee that it will not affect the rest of 
the functionality, that is good.
On the other side i am not sure the functionality makes sense in general, so 
i'd like input from someone else stating they find the feature interesting 
(yes, asking your friends to say so is cheating ;-))

So anyone from the list would comment on the usefulness of the patch?

Albert

 
 Bye,
 Thomas
 
___
Okular-devel mailing list
Okular-devel@kde.org
https://mail.kde.org/mailman/listinfo/okular-devel


[Okular-devel] Patch for best fit zoom

2010-01-18 Thread Thomas Fischer
Hello,

as a regular Okular user, I have an itch that I was scratching: I was 
looking for a zoom setting that is appropriate both for viewing 
presentations (in non-fullscreen mode) and text documents (portrait 
format).
I came up with a best fit zoom level which corresponds to the existing 
fit width and fit page zoom levels.
The best-fit setting compares the aspect ratios of the document and the 
viewing area it is shown in. If the aspect ratios nearly match, a page 
will be shown in fit page mode. This is useful e.g. for presentations, 
where a slide has a similar aspect ratio like the screen. If the aspect 
ratio is very different, such as in cases with portrait text documents, 
the document is scaled to fit width and you only have to scroll 
vertically. If the document is much wider, it is scaled to fit the 
height and you scroll horizontally only.

The attached patch introduces this feature while being just below 7k in 
size. Additionally, I removed/replaced some fit text zoom which seemed 
to be dead code. The patch is for KDE 4.3.4, but it should be no problem 
apply it to the upcoming 4.4 or trunk.

However, there is one major bug in my patch. If the ratio between aspect 
ratios is very close to switching between either of the three zooming 
modes, Okular may continuously switch between two modes. This seems to 
happen as Okular shows scrollbars if necessary, which change the view 
area's size (and this aspect), which in turn triggers the change in 
mode. As this new mode does not need scrollbars, they get disabled again 
and the circle closes. I have not yet found a nice and clean solution 
here.

Comments are welcome.

Bye,
Thomas
diff -Naur orig_kdegraphics-4.3.4/okular/part.rc kdegraphics-4.3.4/okular/part.rc
--- orig_kdegraphics-4.3.4/okular/part.rc	2009-02-18 17:28:33.0 +0100
+++ kdegraphics-4.3.4/okular/part.rc	2010-01-16 17:38:49.0 +0100
@@ -29,6 +29,7 @@
 Action name=view_zoom_out/
 Action name=view_fit_to_width/
 Action name=view_fit_to_page/
+Action name=view_fit_to_best/
 Action name=zoom_fit_rect/
 Separator/
 Action name=view_continuous/
diff -Naur orig_kdegraphics-4.3.4/okular/ui/pageview.cpp kdegraphics-4.3.4/okular/ui/pageview.cpp
--- orig_kdegraphics-4.3.4/okular/ui/pageview.cpp	2009-11-27 14:03:14.0 +0100
+++ kdegraphics-4.3.4/okular/ui/pageview.cpp	2010-01-16 18:44:47.0 +0100
@@ -159,7 +159,7 @@
 KAction * aZoomOut;
 KToggleAction * aZoomFitWidth;
 KToggleAction * aZoomFitPage;
-KToggleAction * aZoomFitText;
+KToggleAction * aZoomFitBest;
 KActionMenu * aViewMode;
 KToggleAction * aViewContinuous;
 QAction * aPrevAction;
@@ -345,7 +345,7 @@
 d-aToggleAnnotator = 0;
 d-aZoomFitWidth = 0;
 d-aZoomFitPage = 0;
-d-aZoomFitText = 0;
+d-aZoomFitBest = 0;
 d-aViewMode = 0;
 d-aViewContinuous = 0;
 d-aPrevAction = 0;
@@ -465,11 +465,10 @@
 ac-addAction(view_fit_to_page, d-aZoomFitPage );
 connect( d-aZoomFitPage, SIGNAL( toggled( bool ) ), SLOT( slotFitToPageToggled( bool ) ) );
 
-/*
-d-aZoomFitText  = new KToggleAction(KIcon( zoom-fit-best ), i18n(Fit Text), this);
-ac-addAction(zoom_fit_text, d-aZoomFitText );
-connect( d-aZoomFitText, SIGNAL( toggled( bool ) ), SLOT( slotFitToTextToggled( bool ) ) );
-*/
+d-aZoomFitBest  = new KToggleAction(KIcon( zoom-fit-best ), i18n(Fit Best), this);
+ac-addAction(view_fit_to_best, d-aZoomFitBest );
+connect( d-aZoomFitBest, SIGNAL( toggled( bool ) ), SLOT( slotFitToBestToggled( bool ) ) );
+
 
 // View-Layout actions
 d-aViewMode = new KActionMenu( KIcon( view-split-left-right ), i18n( View Mode ), this );
@@ -592,7 +591,7 @@
 Okular::Settings::setViewMode( 0 );
 d-aZoomFitWidth-setChecked( true );
 d-aZoomFitPage-setChecked( false );
-//d-aZoomFitText-setChecked( false );
+d-aZoomFitBest-setChecked( false );
 d-aViewMode-menu()-actions().at( 0 )-setChecked( true );
 viewport()-setUpdatesEnabled( false );
 slotRelayoutPages();
@@ -2462,6 +2461,35 @@
 item-setWHZC( (int)(zoom * width), (int)(zoom * height), zoom, crop );
 d-zoomFactor = zoom;
 }
+else if ( d-zoomMode == ZoomFitBest )
+{
+double uiAspect = (double)rowHeight / (double)colWidth;
+double pageAspect = (double)height / (double)width;
+
+if ( ( uiAspect / pageAspect )  1.25 )
+{
+// UI space is relatively much higher than the page
+zoom = (double)rowHeight / (double)height;
+}
+else if ( ( uiAspect / pageAspect )  0.8 )
+{
+// UI space is relatively much wider than the page in relation
+zoom = (double)colWidth / (double)width;
+}
+else
+{
+// aspect ratios of page and UI space are very similar
+double scaleW = (double)colWidth / (double)width;
+double scaleH = (double)rowHeight / (double)height;