Initial mappings: Horizontal, Vertical, VerticalPaired. Issues: Unable to annotate all pages... other code ( PagePosition Handler etc?) must be assuming layout.presentation
parent
e92c65b4e1
commit
ccdd1996cb
4 changed files with 273 additions and 4 deletions
@ -0,0 +1,60 @@ |
||||
#include "gui/LayoutMapper.h" |
||||
|
||||
|
||||
#define XYH( x,y,r,c,off) (( c * y + x) - off%c) |
||||
#define XYV( x,y,r,c,off) (( r* x + y) - off%r) |
||||
#define XYVP( x,y,r,c,off ) (((( y+ r* int(x/2))*2 + x%2 ) - off % 2) |
||||
|
||||
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B)) |
||||
|
||||
|
||||
LayoutMapper::LayoutMapper( int pages, int rORc, bool isR , int off, LayoutType type ){ |
||||
|
||||
if(isR){ |
||||
r = MAX(1, rORc); |
||||
c = MAX(1, (pages + off + (rORc -1) )/rORc); // using + ( rORc-1) to round up (int)pages/rows
|
||||
}else{ |
||||
c = MAX(1, rORc); |
||||
r = MAX(1, (pages + off + (rORc -1) )/rORc);
|
||||
} |
||||
|
||||
layoutType = type; |
||||
switch ( type){ |
||||
case Horizontal: |
||||
offset = off % c; |
||||
break; |
||||
case Vertical: //vertical layout
|
||||
offset = off % r; |
||||
break; |
||||
case VerticalPaired: |
||||
offset = off % (2*r); |
||||
break;
|
||||
} |
||||
possiblePages = r * c; |
||||
rORc = rORc; |
||||
actualPages = pages; |
||||
} |
||||
|
||||
|
||||
int LayoutMapper::map(int x, int y){
|
||||
int res; |
||||
switch( layoutType) |
||||
{ |
||||
case Horizontal: |
||||
res = (x + c * y); |
||||
break; |
||||
|
||||
case Vertical: //vertical layout
|
||||
res = (y + r* x); |
||||
break; |
||||
|
||||
case VerticalPaired: |
||||
res = ((( y + r*( (int)(x/2) )) * 2 ) + x %2); |
||||
break; |
||||
} |
||||
res -= offset; |
||||
if( res>=actualPages) res = -1; |
||||
|
||||
return res; |
||||
} |
||||
@ -0,0 +1,63 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* A layout manager - map where( row,column) to which page( document index) |
||||
* |
||||
* @author Justin Jones |
||||
* https://github.com/xournalpp/xournalpp
|
||||
* |
||||
* @license GNU GPLv2 or later |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
enum LayoutType { |
||||
Horizontal, |
||||
Vertical, |
||||
VerticalPaired, |
||||
//TODO: add in Right to Left mappings for other cultures (i.e. Japanese )
|
||||
}; |
||||
|
||||
/**
|
||||
* @brief Allow different orderings of document pages in layout. |
||||
*/ |
||||
|
||||
class LayoutMapper |
||||
{ |
||||
|
||||
public: |
||||
int c=0; |
||||
int r=0; |
||||
int rORc; |
||||
int actualPages=0; |
||||
int possiblePages=0; |
||||
int offset = 0; |
||||
LayoutType layoutType; |
||||
|
||||
|
||||
/**
|
||||
* Initialize mapper of LayoutType with number of pages and of fixed rows or columns |
||||
* @param pages The number of pages in the document |
||||
* @param rORc Number of rows OR columns depending on boolean flag isR |
||||
* @param isR How to interpret rORc: True is rows |
||||
* @param off Pages to offset - usually one or zero in order to pair up properly |
||||
* @param type Specify LayoutType desired. Options include: Horizontal, Vertical, VerticalPaired
|
||||
*
|
||||
* @return Page index to put at coordinates
|
||||
*/
|
||||
LayoutMapper( int pages, int rORc, bool isR , int off, LayoutType type ); |
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Map page location to document index |
||||
*
|
||||
* @param x Row we are interested in |
||||
* @param y Column we are interested in |
||||
*
|
||||
* @return Page index to put at coordinates
|
||||
*/ |
||||
int map(int x, int y); |
||||
|
||||
}; |
||||
Loading…
Reference in new issue