00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "LayoutMgr.h"
00020 #include "controller.h"
00021 #include "PDFViewerLog.h"
00022
00023 CLayoutMgr::CLayoutMgr(void)
00024 : posTab(NULL)
00025 , posLen(0)
00026 {
00027 }
00028
00029 CLayoutMgr::~CLayoutMgr(void)
00030 {
00031 }
00032
00033 void CLayoutMgr::clear()
00034 {
00035 if (posTab)
00036 {
00037 delete [] posTab; posTab = NULL; posLen = 0;
00038 }
00039 }
00040
00041 double CLayoutMgr::initPagesPosition(Controller * ctrl)
00042 {
00043 if (posTab && posLen != ctrl->core->getNumPages())
00044 {
00045 delete [] posTab; posTab = NULL; posLen = ctrl->core->getNumPages();
00046 }
00047
00048 if (NULL == posTab)
00049 {
00050 posLen = ctrl->core->getNumPages();
00051 posTab = new rectangle[posLen];
00052 }
00053
00054
00055 bound.left = bound.top = bound.right = bound.bottom = 0;
00056
00057
00058 double zoom = ctrl->calZoom(ctrl->settings.getCurrentPage());
00059
00060 int width = 0, height = 0, tmp = 0, rot = 0;
00061 PDFDoc * pdfdoc = ctrl->core->getPDFDoc();
00062
00063 for(int i = 1; i <= posLen; ++i)
00064 {
00065 width = (int)(pdfdoc->getPageCropWidth(i) * zoom * 0.01 + 0.5);
00066 height = (int)(pdfdoc->getPageCropHeight(i) * zoom * 0.01 + 0.5);
00067 rot = pdfdoc->getPageRotate(i);
00068 if (rot >= 360) rot -= 360;
00069 else if (rot < 0) rot += 360;
00070 if (rot == 90 || rot == 270)
00071 {
00072 tmp = width; width = height; height = tmp;
00073 }
00074
00075 if (bound.right < width)
00076 {
00077 bound.right = width;
00078 }
00079 posTab[i - 1].right = width;
00080 posTab[i - 1].top = bound.bottom;
00081 posTab[i - 1].bottom = posTab[i - 1].top + height;
00082 bound.bottom += height + 1;
00083 }
00084
00085
00086 for(int i = 1; i <= posLen; ++i)
00087 {
00088 posTab[i - 1].left = (bound.right - posTab[i - 1].right) / 2;
00089 posTab[i - 1].right += posTab[i - 1].left;
00090
00091
00092 }
00093
00094 return zoom;
00095 }
00096
00097 void CLayoutMgr::getPageRect(const int page, rectangle & rect)
00098 {
00099 rect = posTab[page - 1];
00100 }
00101
00102 const rectangle & CLayoutMgr::getPageRect(const int page) const
00103 {
00104 return posTab[page - 1];
00105 }
00106
00107 int CLayoutMgr::getPagesVisible(int & start, int & end, const rectangle & rect)
00108 {
00109 start = -1; end = -1;
00110 int max = 0, tmp = 0, index = -1;
00111 for(int i = 0; i < posLen; ++i)
00112 {
00113 if (rect.bottom < posTab[i].top) return index;
00114 if ((tmp = rect.isIntersect(posTab[i])) > 0)
00115 {
00116 if (start == -1)
00117 {
00118 start = i + 1; end = start;
00119 }
00120 else
00121 {
00122 ++end;
00123 }
00124 if (max < tmp) { max = tmp; index = i + 1; }
00125 }
00126 }
00127 return index;
00128 }
00129
00131
00132
00133
00134
00135 int CLayoutMgr::hitTest(const point & pt, const int start , const int end)
00136 {
00137 for(int i = start; i <= end; ++i)
00138 {
00139 if (posTab[i - 1].hitTest(pt))
00140 {
00141 return i;
00142 }
00143 }
00144 return -1;
00145 }
00146
00147 int CLayoutMgr::hitTest(const int x, const int y, const int start , const int end)
00148 {
00149 for(int i = start; i <= end; ++i)
00150 {
00151 if (posTab[i - 1].hitTest(x, y))
00152 {
00153 return i;
00154 }
00155 }
00156 return -1;
00157 }
00158
00159
00161
00162 void CLayoutMgr::screenToVirtualScreen(Controller * ctrl, rectangle & rect)
00163 {
00164
00165 rect.left += ctrl->settings.getScreenX();
00166 rect.top += ctrl->settings.getScreenY();
00167 rect.right += ctrl->settings.getScreenX();
00168 rect.bottom += ctrl->settings.getScreenY();
00169 }
00170
00171 void CLayoutMgr::screenToVirtualScreen(Controller * ctrl, point & pt)
00172 {
00173 pt.x += ctrl->settings.getScreenX();
00174 pt.y += ctrl->settings.getScreenY();
00175 }
00176
00177
00178 void CLayoutMgr::virtualScreenToScreen(Controller * ctrl, const rectangle & rect)
00179 {
00180 ctrl->settings.setScreenX(rect.left);
00181 ctrl->settings.setScreenY(rect.top);
00182 }
00183
00185
00187 void CLayoutMgr::rotate(Controller * ctrl, const int angle)
00188 {
00189 CPageInfo * page = ctrl->pageList.getPage(ctrl->settings.getCurrentPage());
00190 if (NULL == page) return;
00191
00192
00193 rectangle rect; rect.left = 0; rect.top = 0;
00194 rect.right = ctrl->settings.getScreenWidth();
00195 rect.bottom = ctrl->settings.getScreenHeight();
00196 if (ctrl->settings.getScreenX() > 0) rect.left = ctrl->settings.getScreenX();
00197 if (ctrl->settings.getScreenY() > 0) rect.top = ctrl->settings.getScreenY();
00198 if (rect.right > ctrl->settings.getScreenX() + page->bitmap->getWidth())
00199 {
00200 rect.right = ctrl->settings.getScreenX() + page->bitmap->getWidth();
00201 }
00202 if (rect.bottom > ctrl->settings.getScreenY() + page->bitmap->getHeight())
00203 {
00204 rect.bottom = ctrl->settings.getScreenY() + page->bitmap->getHeight();
00205 }
00206 point center;
00207 center.x = (rect.left + rect.right) / 2;
00208 center.y = (rect.top + rect.bottom) / 2;
00209 int distX = 0, distY = 0;
00210
00211
00212 if (angle == 90)
00213 {
00214 distX = center.x - ctrl->settings.getScreenX();
00215 distY = page->bitmap->getHeight() - center.y + ctrl->settings.getScreenY();
00216 ctrl->settings.setScreenX(center.x - distY);
00217 ctrl->settings.setScreenY(center.y - distX);
00218 }
00219 else if (angle == -90)
00220 {
00221 distX = page->bitmap->getWidth() - center.x + ctrl->settings.getScreenX();
00222 distY = center.y - ctrl->settings.getScreenY();
00223 ctrl->settings.setScreenX(center.x - distY);
00224 ctrl->settings.setScreenY(center.y - distX);
00225 }
00226 }
00227
00228 void CLayoutMgr::updatePageRect(const int x, const int y, const int width, const int height)
00229 {
00230 bound.left = x; bound.top = y;
00231 bound.right = x + width;
00232 bound.bottom = y + height;
00233 }
00234
00235 GBool CLayoutMgr::hitTest(const int x, const int y)
00236 {
00237 return bound.hitTest(x, y);
00238 }
00239