On November 16, 2011 7:46:08 AM Albert Astals Cid wrote:
> A Dimarts, 15 de novembre de 2011, Stephen Anthony vàreu escriure:
> > I've been looking over the codebase for the past few hours, but I
> > can't seem to find which class is responsible for this.  A little
> > explanation first:
> > 
> > I'm trying to implement the oft-requested feature of no spacing
> > between facing pages, to more accurately emulate the behaviour of
> > reading a book or magazine.
> 
> Cool :-)

OK, I've attached a patch which implements this functionality (against 
current git revision).  A few notes:

1)  When in facing pages mode, the pages are positioned such that they 
touch the virtual 'center dividing line' of the viewable area.

2)  This new behaviour is always active when in the appropriate mode.  I 
don't really think it should be made configurable as a setting, but if so, 
more work will have to be done to integrate the setting into the UI.

2)  I would suggest changing the view mode "Facing Pages (Centre First 
Page)" to be called "Book Mode" or something similar.  I didn't do this, 
since it probably entails editing the manual, snapshots of the UI, etc.  
It would make much clearer the intent of the mode.

3)  Perhaps in "Centre First Page" mode, the last page could also be 
centered *if* the end of the document contains only a single page in the 
view.  Currently, this last page will appear to the left.  This isn't 
strictly necessary, but it might look a bit nicer.

Anyway, I hope this patch can be applied.

Thanks,
Steve A.
diff --git a/ui/pageview.cpp b/ui/pageview.cpp
index 56be30d..b6b6bef 100644
--- a/ui/pageview.cpp
+++ b/ui/pageview.cpp
@@ -3628,8 +3628,9 @@ void PageView::slotRelayoutPages()
 
     // handle the 'center first page in row' stuff
     int nCols = viewColumns();
-    bool centerFirstPage = Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::FacingFirstCentered;
+    const bool centerFirstPage = Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::FacingFirstCentered;
     const bool continuousView = Okular::Settings::viewContinuous();
+    const bool facingPages = centerFirstPage || Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::Facing;
 
     // set all items geometry and resize contents. handle 'continuous' and 'single' modes separately
 
@@ -3640,7 +3641,8 @@ void PageView::slotRelayoutPages()
             pageCount += nCols - 1;
         // Here we find out column's width and row's height to compute a table
         // so we can place widgets 'centered in virtual cells'.
-	int nRows = (int)ceil( (float)pageCount / (float)nCols );
+        // Facing pages are centered as a unit, with their edges touching in the middle.
+        int nRows = (int)ceil( (float)pageCount / (float)nCols );
 
         int * colWidth = new int[ nCols ],
             * rowHeight = new int[ nRows ],
@@ -3693,7 +3695,7 @@ void PageView::slotRelayoutPages()
 
         // 3) arrange widgets inside cells (and refine fullHeight if needed)
         int insertX = 0,
-            insertY = fullHeight < viewportHeight ? ( viewportHeight - fullHeight ) / 2 : 0;
+            insertY = fullHeight < viewportHeight ? (( viewportHeight - fullHeight ) >> 1) : 0;
         const int origInsertY = insertY;
         cIdx = 0;
         rIdx = 0;
@@ -3711,8 +3713,26 @@ void PageView::slotRelayoutPages()
             if ( continuousView || rIdx == pageRowIdx )
             {
                 const bool reallyDoCenterFirst = item->pageNumber() == 0 && centerFirstPage;
-                item->moveTo( (reallyDoCenterFirst ? 0 : insertX) + ( (reallyDoCenterFirst ? fullWidth : cWidth) - item->croppedWidth()) / 2,
-                              (continuousView ? insertY : origInsertY) + (rHeight - item->croppedHeight()) / 2 );
+                int actualX = 0;
+                if ( reallyDoCenterFirst )
+                {
+                    // page is centered across entire viewport
+                    actualX = (fullWidth - item->croppedWidth()) >> 1;
+                }
+                else if ( facingPages )
+                {
+                    // page edges 'touch' the center of the viewport
+                    actualX = ( (centerFirstPage && item->pageNumber() % 2 == 1) ||
+                                (!centerFirstPage && item->pageNumber() % 2 == 0) ) ?
+                        (fullWidth >> 1) - item->croppedWidth() - 1 : (fullWidth >> 1) + 1;
+                }
+                else
+                {
+                    // page is centered within its virtual column
+                    actualX = insertX + ((cWidth - item->croppedWidth()) >> 1);
+                }
+                item->moveTo( actualX,
+                              (continuousView ? insertY : origInsertY) + ((rHeight - item->croppedHeight()) >> 1) );
                 item->setVisible( true );
             }
             else
_______________________________________________
Okular-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/okular-devel

Reply via email to