Hello all!
I have been testing the SDK and I realised that we have a vertical/horizontal display mode (fitting width) that use PDFLayoutVert, single mode that use PDFLayoutDual, etc.
The problem is: What does it happen when we want to have a vertical / single (with vertical display) that fits to the height to display all the document in the screen and avoid doing scroll inside one only page?
I talked about it with nermeen and we get some approach: replace vLayout from PDFLayoutVert (or some class extended from that) with the following code:
@Override public void vLayout() {
/* ORIGINAL CODE
if(this.m_w > 0 && this.m_h > 0 && this.m_doc != null && this.m_pages != null) {
int cnt = this.m_doc.GetPageCount();
this.m_scale_min = (float)(this.m_w - this.m_page_gap) / this.m_page_maxw;
this.m_scale_max = this.m_scale_min * this.m_zoom_level;
if(this.m_scale < this.m_scale_min) {
this.m_scale = this.m_scale_min;
}
if(this.m_scale > this.m_scale_max) {
this.m_scale = this.m_scale_max;
}
boolean clip = this.m_scale / this.m_scale_min > this.m_zoom_level_clip;
this.m_tw = (int)(this.m_page_maxw * this.m_scale);
this.m_th = 0;
int y = this.m_page_gap >> 1;
for(int cur = 0; cur < cnt; ++cur) {
int w = (int)(this.m_doc.GetPageWidth(cur) * this.m_scale);
int h = (int)(this.m_doc.GetPageHeight(cur) * this.m_scale);
int x = (int)(this.m_page_maxw * this.m_scale) + this.m_page_gap - w >> 1;
this.m_pages[cur].vLayout(x, y, this.m_scale, clip);
y += h + this.m_page_gap;
}
this.m_th = y - (this.m_page_gap >> 1);
int a = this.m_th +1;
}*/
//NEW CODE
if (this.m_w > 0 && this.m_h > 0 && this.m_doc != null && this.m_pages != null) {
int cnt = m_doc.GetPageCount();
int cur;
m_scale_min = (m_h - m_page_gap) / m_page_maxh;
m_scale_max = m_scale_min * m_zoom_level;
if (m_scale < m_scale_min) m_scale = m_scale_min;
if (m_scale > m_scale_max) m_scale = m_scale_max;
boolean clip = m_scale / m_scale_min > m_zoom_level_clip;
m_tw = (int) (m_page_maxw * m_scale);
m_th = 0;
int y = m_page_gap >> 1;
for (cur = 0; cur < cnt; cur++) {
int w = (int) (m_doc.GetPageWidth(cur) * m_scale);
int h = (int) (m_doc.GetPageHeight(cur) * m_scale);
int x = Math.abs(m_w - w) / 2;
m_pages[cur].vLayout(x, y, m_scale, clip);
y += h + m_page_gap;
}
m_th = y - (m_page_gap >> 1);
}
}
, Now if we select in Global config the def_view = 0 (Vertical) It will show as we expected: vertical and the whole page in the screen.
Now, the problem is that when we zoom, we cannot move to the right of half of the pagebeing an "invisible wall" that stop us.
I think the problem is in the way it get the X position with vGetX() and vSetX(...) but I cannot modify it first and I don't know what to change.
Our modified code is the code before (put inside a extended MyPDFLayoutVert class from PDFLayoutVert) and a extended MyPDFLayoutView class from PDFLayoutView to override method PDFSetView(style) and replace the layout used with MyPDFLayoutVert:
@Override
public void PDFSetView(int style)
{
PDFLayout.PDFPos pos = null;
if(m_layout != null)
pos = m_layout.vGetPos(0, 0);
PDFClose();
switch( style )
{
case 3:
{
PDFLayoutDual layout = new PDFLayoutDual(getContext());
boolean paras[] = new boolean[this.PDFGetDoc().GetPageCount()];
int cur = 0;
while( cur < paras.length )
{
paras[cur] = false;
cur++;
}
layout.vSetLayoutPara(null, paras, Global.rtol, false);
m_layout = layout;
}
break;
case 4:
{
PDFLayoutDual layout = new PDFLayoutDual(getContext());
boolean paras[] = new boolean[this.PDFGetDoc().GetPageCount()];
int cur = 0;
while( cur < paras.length )
{
paras[cur] = true;
cur++;
}
layout.vSetLayoutPara(null, paras, Global.rtol, false);
m_layout = layout;
}
break;
case 6:
{
PDFLayoutDual layout = new PDFLayoutDual(getContext());
layout.vSetLayoutPara(null, null, Global.rtol, false);
m_layout = layout;
}
break;
default:
{
MyPDFLayoutVert layout = new MyPDFLayoutVert(getContext());
m_layout = layout;
}
break;
}
Global.def_view = style;
//m_layout.vOpen(m_doc, this);
m_layout.vOpen(this.PDFGetDoc(), this);
if(m_bmp_format != Bitmap.Config.ALPHA_8)
{
m_layout.vSetBmpFormat(m_bmp_format);
m_bmp_format = Bitmap.Config.ALPHA_8;
}
if( getWidth() > 0 && getHeight() > 0 )
{
m_layout.vResize(getWidth(), getHeight());
if( m_goto_pos != null )
{
m_layout.vSetPos(0, 0, m_goto_pos);
m_goto_pos = null;
invalidate();
}
else if( pos != null )
{
m_layout.vSetPos(0, 0, pos);
m_layout.vMoveEnd();
}
}
invalidate();
}
Why can't I zoom in / move to the half right of the page? Is it calculating wrongly it x position? How could I fix it?
Thank you!