Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about Android development and PDF

Make vertical PDF display fit according to height

More
IP: 192.168.0.71 8 years 4 months ago - 8 years 4 months ago #13046 by msanchezv
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:
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:
Code:
@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!
Last edit: 8 years 4 months ago by msanchezv.
More
IP: 192.168.0.71 8 years 4 months ago #13047 by nermeen
The problem is that the x (in vLayout) is not calculated based on the scale (so after zoom it gives wrong results), it should be calculated as:
Code:
if (w + m_page_gap < m_w) cw = m_w; else cw = (int) (w + m_page_gap * m_scale); int x = Math.abs(cw - w) / 2;

We have created a KB to explain the full code, check Vertical mode that fits to screen Height
More
IP: 192.168.0.71 8 years 4 months ago - 8 years 4 months ago #13048 by msanchezv
Nice! It works!. Thank you again nermeen.

Something I miss is a guide about the variables that control the customization of the display, what they mean (m_w, th_w, cx, m_page_gap, ... etc.).
Last edit: 8 years 4 months ago by msanchezv.
Time to create page: 0.398 seconds
Powered by Kunena Forum