00001 /* 00002 * Copyright (C) 2006, iRex Technologies B.V. 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2, or (at your option) 00007 * any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "controller.h" 00020 #include "PDFViewerLog.h" 00021 #include <libermanifest/ermanifest.h> 00022 00023 void Controller::validateSettings() 00024 { 00025 // validate 00026 PDFDoc * pdfdoc = core->getPDFDoc(); 00027 if (settings.getCurrentPage() <= 0 || 00028 settings.getCurrentPage() > pdfdoc->getNumPages()) 00029 { 00030 settings.setCurrentPage(1); 00031 } 00032 00033 if ((settings.getZoom() > ZoomMax || 00034 settings.getZoom() < ZoomMin ) && 00035 settings.getZoom() != ZoomWidth) 00036 { 00037 settings.setZoom(ZoomPage); 00038 } 00039 00040 if (settings.getRotate() != 0 && 00041 settings.getRotate() != 90 && 00042 settings.getRotate() != 180 && 00043 settings.getRotate() != 270) 00044 { 00045 settings.setRotate(0); 00046 } 00047 00048 if (settings.getRotate() == 180) 00049 { 00050 settings.setRotate(0); 00051 } 00052 else if (settings.getRotate() == 90) 00053 { 00054 settings.setRotate(270); 00055 } 00056 00057 PV_LOGPRINTF("Current page %d zoom factor %lf rotate %d x %d y %d mode %d\n", 00058 settings.getCurrentPage(), 00059 settings.getZoom(), 00060 settings.getRotate(), 00061 settings.getScreenX(), 00062 settings.getScreenY(), 00063 settings.getMode()); 00064 } 00065 00066 double Controller::calZoom(const int page) 00067 { 00068 if (page < 1 || 00069 page > core->getNumPages()) 00070 { 00071 return DefZoom; 00072 } 00073 00074 if (settings.getZoom() > 0) 00075 { 00076 return core->verifyZoomMax(settings.getZoom(), page); 00077 } 00078 00079 int rot = core->getPageRotate(page); 00080 rot += settings.getRotate(); 00081 if (rot >= 360) rot -= 360; 00082 else if (rot < 0) rot += 360; 00083 double uw = core->getPageWidth(page); 00084 double uh = core->getPageHeight(page); 00085 double ut; 00086 if (rot == 90 || rot == 270) 00087 { 00088 ut = uw; uw = uh; uh = ut; 00089 } 00090 if (ZoomPage == settings.getZoom()) 00091 { 00092 uw = settings.getScreenWidth() / uw; 00093 uh = settings.getScreenHeight() / uh; 00094 return (uw < uh) ? (uw * 100) : (uh * 100); 00095 } 00096 else if (ZoomWidth == settings.getZoom()) 00097 { 00098 if (settings.getRotate() == 0 || 00099 settings.getRotate() == 180) 00100 { 00101 return (100 * settings.getScreenWidth() / uw); 00102 } 00103 else if (settings.getRotate() == 90 || 00104 settings.getRotate() == 270) 00105 { 00106 return (100 * settings.getScreenHeight() / uh); 00107 } 00108 } 00109 return DefZoom; 00110 } 00111