Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1

TOPIC:

center vertically with vertical layout? 2 years 8 months ago #15562

  • arlomedia
  • arlomedia's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 56
  • Thank you received: 1
I'm currently using the vertical layout (Global.def_view = 0) to scroll long documents vertically, but if the document height is less than the viewer height, the document is top-aligned. I would like the document to be vertically centered if it is shorter than the viewer. I see that def_view = 3 uses vertical centering, but then longer documents scroll horizontally.

I tried calling Document.Open() first, then calling GetPageCount() on the Document object, then setting def_view to 3 if the page count is 1 or 0 if the page count is more than one, then calling PDFLayoutView.PDFOpen() (def_view has to be set before PDFOpen()). That seems to work, but I wanted to check and see if there is a better way?

BTW, this wouldn't work if the document has two pages and its height is still less than the viewer height, but it's not a priority to support that scenario. In most cases, only single-page documents will have a document height less than the viewer height.

Please Log in or Create an account to join the conversation.

center vertically with vertical layout? 2 years 8 months ago #15564

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
dear user:
it can be checked, by aspect ratio of total height of all pages and max width.
you may compare these 2 values:
1. (total height of all pages) / (max width)
2. (screen height) / (screen width).

Please Log in or Create an account to join the conversation.

center vertically with vertical layout? 2 years 8 months ago #15568

  • arlomedia
  • arlomedia's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 56
  • Thank you received: 1
You're right, I can calculate the actual length of the document with Document.GetPageHeight() and Document.GetPageCount() rather than just assuming a multi-page document will be taller than the viewer.

The part I was concerned about was changing Global.def_view each time I load a document. Will that cause any problems, or is there a single view that will provide the two behaviors I'm looking for (vertically centering of short documents and vertical scrolling of long documents)?

Please Log in or Create an account to join the conversation.

center vertically with vertical layout? 2 years 8 months ago #15569

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
the perfect solution for you, shall not be change view mode by checking total height.
you shall always use PDFLayoutVert, and modify codes for method:
PDFLayoutVert.vLayout()
this method only has 30 lines, that set (x,y) and scale for each page.

you can calculate total height in a new loop, if total height less than member m_h, then adjust y offset for each page.
The following user(s) said Thank You: arlomedia

Please Log in or Create an account to join the conversation.

Last edit: by radaee.

center vertically with vertical layout? 2 years 8 months ago #15570

  • arlomedia
  • arlomedia's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 56
  • Thank you received: 1
Okay, good. Here's what I came up with. Starting at the line that initializes y, I replaced the rest of the function with this:
for(cur = 0;cur < cnt;cur++){
   if(Global.fit_different_page_size && m_scales[cur] == 0) {
      m_scales[cur] = ((float)(m_w - m_page_gap)) / m_doc.GetPageWidth(cur);
      m_scales_min[cur] = ((float)(m_w - m_page_gap)) / m_doc.GetPageWidth(cur);
   }
   float pageScale = Global.fit_different_page_size ? m_scales[cur] : m_scale;
   int h = (int)(m_doc.GetPageHeight(cur) * pageScale);
   m_th += h + m_page_gap;
}
int y = m_page_gap>>1;
if (m_th < m_h) {
   y += (m_h - m_th) / 2;
}
boolean clip = m_scale / m_scale_min > m_zoom_level_clip;
for(cur = 0;cur < cnt;cur++)
{
          float pageScale = Global.fit_different_page_size ? m_scales[cur] : m_scale;
   int w = (int)(m_doc.GetPageWidth(cur) * pageScale);
   int h = (int)(m_doc.GetPageHeight(cur) * pageScale);
   int x = Global.fit_different_page_size ? m_page_gap >> 1:
         ((int)(m_page_maxw * pageScale) + m_page_gap - w)>>1;
   boolean clipPage = Global.fit_different_page_size ? pageScale / m_scales_min[cur] > m_zoom_level_clip : clip;
   m_pages[cur].vLayout(x, y, pageScale, clipPage);
   y += h + m_page_gap;
}

This also takes into account document zooming and documents with different-sized pages. And then def_view can stay at 0.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum