- Posts: 56
- Thank you received: 1
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
center vertically with vertical layout?
IP: 75.164.131.1
4 years 7 months ago #15562
by arlomedia
center vertically with vertical layout? was created by arlomedia
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.
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.
IP: 111.196.242.102
4 years 7 months ago #15564
by radaee
Replied by radaee on topic center vertically with vertical layout?
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).
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).
IP: 75.164.131.1
4 years 7 months ago #15568
by arlomedia
Replied by arlomedia on topic center vertically with vertical layout?
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)?
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)?
IP: 111.196.240.141
4 years 7 months ago - 4 years 7 months ago #15569
by radaee
Replied by radaee on topic center vertically with vertical layout?
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.
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.
Last edit: 4 years 7 months ago by radaee.
IP: 75.164.131.1
4 years 7 months ago #15570
by arlomedia
Replied by arlomedia on topic center vertically with vertical layout?
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:
This also takes into account document zooming and documents with different-sized pages. And then def_view can stay at 0.
Code:
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.
Time to create page: 0.417 seconds