home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 January / PCWorld_2003-01_cd.bin / Software / Topware / zme / zme5-trcz.exe / digifoto.ZHT1 / main.js < prev    next >
Encoding:
Text File  |  2002-11-22  |  13.5 KB  |  373 lines

  1. function GeneratePreview(cSourcePath, cDestPath, cID)
  2. {
  3.   //MessageBox("cSourcePath = " + cSourcePath + "\ncDestPath = " + cDestPath + "\ncID = " + cID, "Preview", MB_OK);
  4. }
  5.  
  6. function GetPageFN(iPage) {
  7.   if (iPage == 1) {
  8.     return "index.htm";
  9.   }
  10.  
  11.   return "page" + IntToStr(iPage, 5) + ".htm";
  12. }
  13.  
  14. function GetImgPageFN(iFile) {
  15.   return "ipage" + IntToStr(iFile, 5) + ".htm";
  16. }
  17.  
  18. function GetPagesNavigation(iPagesCount, iCurPage) {
  19.   cNavigation = "";
  20.   for (iPage=1; iPage <= iPagesCount; iPage++) {
  21.     if (iPage == iCurPage) {
  22.       cNavigation += "<B>"+IntToStr(iPage, 0)+"</B>\n";
  23.     } else {
  24.       cNavigation += "<A HREF=\""+GetPageFN(iPage)+"\">"+IntToStr(iPage, 0)+"</A>\n";
  25.     }
  26.   }
  27.   return cNavigation;
  28. }
  29.  
  30. function GetImgPagesNavigation(iFilesCount, iCurFile) {
  31.   cNavigation = "";
  32.   for (iFile=1; iFile <= iFilesCount; iFile++) {
  33.     if (iFile == iCurFile) {
  34.       cNavigation += "<B>"+IntToStr(iFile, 0)+"</B>\n";
  35.     } else {
  36.       cNavigation += "<A HREF=\""+GetImgPageFN(iFile)+"\">"+IntToStr(iFile, 0)+"</A>\n";
  37.     }
  38.   }
  39.   return cNavigation;
  40. }
  41.  
  42. function GenerateAlbum(cSourcePath, cDestPath)
  43. {
  44.   var iFilesCount = lSelectedFiles.GetCount();
  45.  
  46.   var iPagesCount = Math.ceil(iFilesCount / (iCols*iRows));
  47.  
  48.   var iNavStyle = parseInt(cNavStyle);
  49.   var iImgNavStyle = parseInt(cImgNavStyle);
  50.  
  51.   var tPage = new CTemplate();
  52.   tPage.Load(cSourcePath + "page.tpl", 0);
  53.   tPage.SetReplace("${CSS_FILENAME}", "page.css");
  54.  
  55.   tPage.SetReplace("${TITLE}", cTitle);
  56.   tPage.SetReplace("${HEADER}", ReplaceExifStrings(cHeader, "", ""));
  57.   tPage.SetReplace("${FOOTER}", ReplaceExifStrings(cFooter, "", ""));
  58.  
  59.   var tPageCSS = new CTemplate();
  60.   tPageCSS.Load(cSourcePath + "css.tpl", 0);
  61.  
  62.   var iDescTDWidth = iThnWidth+4;
  63.   var iThnTDWidth = iThnWidth+12;
  64.   var iThnTDHeight = iThnHeight+12;
  65.   var iOrgTDWidth = iThnWidth+4;
  66.  
  67.   var iThnTableWidth = (iCols)*(iThnTDWidth) + (iCols+1)*(1); // (1) ... cellspacing="1"
  68.  
  69.   tPageCSS.SetReplace("${BGCOLOR}", HEXColor(iBgColor));
  70.   tPageCSS.SetReplace("${HEAD_FONT_SIZE}", iHeaderFontSize);
  71.   tPageCSS.SetReplace("${HEAD_FONT_COLOR}", HEXColor(iHeaderFontColor));
  72.   tPageCSS.SetReplace("${THN_TABLE_WIDTH}", iThnTableWidth);
  73.   tPageCSS.SetReplace("${DESC_FONT_SIZE}", iDescFontSize);
  74.   tPageCSS.SetReplace("${DESC_FONT_COLOR}", HEXColor(iDescFontColor));
  75.   tPageCSS.SetReplace("${DESC_BGCOLOR}", HEXColor(iDescBgColor));
  76.   tPageCSS.SetReplace("${DESC_LINK_COLOR}", HEXColor(iDescLinkColor));
  77.   tPageCSS.SetReplace("${DESC_TD_WIDTH}", iDescTDWidth);
  78.   tPageCSS.SetReplace("${THN_TD_WIDTH}", iThnTDWidth);
  79.   tPageCSS.SetReplace("${THN_TD_HEIGHT}", iThnTDHeight);
  80.   tPageCSS.SetReplace("${ORG_TD_WIDTH}", iOrgTDWidth);
  81.   tPageCSS.SetReplace("${THN_BGCOLOR}", HEXColor(iThnBgColor));
  82.   tPageCSS.SetReplace("${ORG_FONT_SIZE}", iOrgFontSize);
  83.   tPageCSS.SetReplace("${ORG_FONT_COLOR}", HEXColor(iOrgFontColor));
  84.   tPageCSS.SetReplace("${ORG_BGCOLOR}", HEXColor(iOrgBgColor));
  85.   tPageCSS.SetReplace("${ORG_LINK_COLOR}", HEXColor(iOrgLinkColor));
  86.   tPageCSS.SetReplace("${FOOT_FONT_SIZE}", iFooterFontSize);
  87.   tPageCSS.SetReplace("${FOOT_FONT_COLOR}", HEXColor(iFooterFontColor));
  88.   tPageCSS.SetReplace("${NAV_FONT_SIZE}", iNavFontSize);
  89.   tPageCSS.SetReplace("${NAV_FONT_COLOR}", HEXColor(iNavFontColor));
  90.   tPageCSS.SetReplace("${NAV_BGCOLOR}", HEXColor(iNavBgColor));
  91.   tPageCSS.SetReplace("${NAV_TEXT_BGCOLOR}", HEXColor(iNavTextBgColor));
  92.   tPageCSS.SetReplace("${NAV_LINK_COLOR}", HEXColor(iNavLinkColor));
  93.  
  94.   SaveString(cDestPath + "page.css", tPageCSS.Replace(), 0);
  95.  
  96.  
  97.  
  98.   var tImg = new CTemplate();
  99.   tImg.Load(cSourcePath + "page.tpl", 0);
  100.   tImg.SetReplace("${CSS_FILENAME}", "img.css");
  101.  
  102.   tImg.SetReplace("${TITLE}", cImgTitle);
  103.  
  104.   var tImgCSS = new CTemplate();
  105.   tImgCSS.Load(cSourcePath + "css.tpl", 0);
  106.  
  107.   var iImgDescTDWidth = iImgWidth+4;
  108.   var iImgTDWidth = iImgWidth+12;
  109.   var iImgTDHeight = iImgHeight+12;
  110.   var iImgOrgTDWidth = iImgWidth+4;
  111.  
  112.   var iImgTableWidth = iImgTDWidth + 2; // 2 ... 2 x cellspacing="1"
  113.  
  114.   tImgCSS.SetReplace("${BGCOLOR}", HEXColor(iImgBgColor));
  115.   tImgCSS.SetReplace("${HEAD_FONT_SIZE}", iImgHeaderFontSize);
  116.   tImgCSS.SetReplace("${HEAD_FONT_COLOR}", HEXColor(iImgHeaderFontColor));
  117.   tImgCSS.SetReplace("${THN_TABLE_WIDTH}", iImgTableWidth);
  118.   tImgCSS.SetReplace("${DESC_FONT_SIZE}", iImgDescFontSize);
  119.   tImgCSS.SetReplace("${DESC_FONT_COLOR}", HEXColor(iImgDescFontColor));
  120.   tImgCSS.SetReplace("${DESC_BGCOLOR}", HEXColor(iImgDescBgColor));
  121.   tImgCSS.SetReplace("${DESC_LINK_COLOR}", HEXColor(iImgDescLinkColor));
  122.   tImgCSS.SetReplace("${DESC_TD_WIDTH}", iImgDescTDWidth);
  123.   tImgCSS.SetReplace("${THN_TD_WIDTH}", iImgTDWidth);
  124.   tImgCSS.SetReplace("${THN_TD_HEIGHT}", iImgTDHeight);
  125.   tImgCSS.SetReplace("${ORG_TD_WIDTH}", iImgOrgTDWidth);
  126.   tImgCSS.SetReplace("${THN_BGCOLOR}", HEXColor(iImgImgBgColor));
  127.   tImgCSS.SetReplace("${ORG_FONT_SIZE}", iImgOrgFontSize);
  128.   tImgCSS.SetReplace("${ORG_FONT_COLOR}", HEXColor(iImgOrgFontColor));
  129.   tImgCSS.SetReplace("${ORG_BGCOLOR}", HEXColor(iImgOrgBgColor));
  130.   tImgCSS.SetReplace("${ORG_LINK_COLOR}", HEXColor(iImgOrgLinkColor));
  131.   tImgCSS.SetReplace("${FOOT_FONT_SIZE}", iImgFooterFontSize);
  132.   tImgCSS.SetReplace("${FOOT_FONT_COLOR}", HEXColor(iImgFooterFontColor));
  133.   tImgCSS.SetReplace("${NAV_FONT_SIZE}", iImgNavFontSize);
  134.   tImgCSS.SetReplace("${NAV_FONT_COLOR}", HEXColor(iImgNavFontColor));
  135.   tImgCSS.SetReplace("${NAV_BGCOLOR}", HEXColor(iImgNavBgColor));
  136.   tImgCSS.SetReplace("${NAV_TEXT_BGCOLOR}", HEXColor(iImgNavTextBgColor));
  137.   tImgCSS.SetReplace("${NAV_LINK_COLOR}", HEXColor(iImgNavLinkColor));
  138.  
  139.   SaveString(cDestPath + "img.css", tImgCSS.Replace(), 0);
  140.  
  141.   var tNav = new CTemplate();
  142.   if (iNavStyle == 1) {
  143.     tNav.Load(cSourcePath + "nav_1.tpl", 0);
  144.   }
  145.   if (iNavStyle == 2) {
  146.     tNav.Load(cSourcePath + "nav_2.tpl", 0);
  147.   }
  148.  
  149.   var tImgNav = new CTemplate();
  150.   if (iImgNavStyle == 1) {
  151.     tImgNav.Load(cSourcePath + "img_nav_1.tpl", 0);
  152.   }
  153.   if (iImgNavStyle == 2) {
  154.     tImgNav.Load(cSourcePath + "img_nav_2.tpl", 0);
  155.   }
  156.  
  157.   var tRow = new CTemplate();
  158.   tRow.Load(cSourcePath + "row.tpl", 0);
  159.  
  160.   var tImgRow = new CTemplate();
  161.   tImgRow.Load(cSourcePath + "row.tpl", 0);
  162.  
  163.   var tDescCol = new CTemplate();
  164.   tDescCol.Load(cSourcePath + "desc_col.tpl", 0);
  165.  
  166.   var tImgDescCol = new CTemplate();
  167.   tImgDescCol.Load(cSourcePath + "desc_col.tpl", 0);
  168.  
  169.   var tThnCol = new CTemplate();
  170.   tThnCol.Load(cSourcePath + "img_col.tpl", 0);
  171.  
  172.   var tImgCol = new CTemplate();
  173.   tImgCol.Load(cSourcePath + "img_col.tpl", 0);
  174.  
  175.   var tOrgCol = new CTemplate();
  176.   tOrgCol.Load(cSourcePath + "org_col.tpl", 0);
  177.  
  178.   var tImgOrgCol = new CTemplate();
  179.   tImgOrgCol.Load(cSourcePath + "org_col.tpl", 0);
  180.  
  181.   var pMagImg0 = new CImage();
  182.   pMagImg0.Load(cSourcePath + "magnify-.png", 0);
  183.  
  184.   var pMagImg1 = new CImage();
  185.   pMagImg1.Load(cSourcePath + "magnify+.png", 0);
  186.  
  187.   var cRows = "";
  188.   var cDescCols = "";
  189.   var cImgCols = "";
  190.   var cOrgCols = "";
  191.  
  192.   var iCol = 0;
  193.   var iRow = 0;
  194.   var iPage = 1;
  195.  
  196.   var iImgFrom = 1;
  197.   var iImgTo = 1;
  198.  
  199. //  for (var iFile = 1; ((iFile <= iFilesCount) || (iCol != 0) || (iRow != 0)); iFile++) {
  200.   for (var iFile = 1; ((iFile <= iFilesCount) || (iCol != 0)); iFile++) {
  201.     if (iFile <= iFilesCount) {
  202.  
  203. // FILE 
  204.       iImgTo = iFile;
  205.       cFileName = lSelectedFiles.GetAt(iFile-1);
  206.       cThnFileName = "thn" + IntToStr(iFile, 5) + ".jpg";
  207.       cImgFileName = "img" + IntToStr(iFile, 5) + ".jpg";
  208.       cOrgFileName = "org" + IntToStr(iFile, 5) + ".jpg";
  209.  
  210. // LOAD FILE
  211.       var pImg = new CImage();
  212.       pImg.Load(cFileName, 0);
  213.  
  214. // MAKE IMAGE
  215.       pImg.Resize(iImgWidth, iImgHeight, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  216.       var rcMag = pMagImg0.GetRect();
  217.       if (bImgMag) {
  218.         pMagImg0.Draw(pImg, rcMag, pImg.GetWidth()-rcMag.Width()-1, pImg.GetHeight()-rcMag.Height()-1, 192, GFX_KEEP_ALPHA);
  219.       }
  220.       pImg.SaveAs(cDestPath + cImgFileName, JPGformat, iImgJPEG, 0);
  221.  
  222. // IMAGE HEADER
  223.       tImg.SetReplace("${HEADER}", ReplaceExifStrings(cImgHeader, cFileName, cDestPath + cImgFileName)); 
  224.  
  225. // IMAGE NAVIGATION
  226.       if (iFile > 1) {
  227.         tImgNav.SetReplace("${NAV_FIRST}", "<a href=\""+GetImgPageFN(1)+"\">|<</a>");
  228.         tImgNav.SetReplace("${NAV_PREV}", "<a href=\""+GetImgPageFN(iFile-1)+"\"><<</a>");
  229.       } else {
  230.         tImgNav.SetReplace("${NAV_FIRST}", "|<");
  231.         tImgNav.SetReplace("${NAV_PREV}", "<<");
  232.       }
  233.       if (iFile < iFilesCount) {
  234.         tImgNav.SetReplace("${NAV_NEXT}", "<a href=\""+GetImgPageFN(iFile+1)+"\">>></a>");
  235.         tImgNav.SetReplace("${NAV_LAST}", "<a href=\""+GetImgPageFN(iFilesCount)+"\">>|</a>");
  236.       } else {
  237.         tImgNav.SetReplace("${NAV_NEXT}", ">>");
  238.         tImgNav.SetReplace("${NAV_LAST}", ">|");
  239.       }
  240.       if (iImgNavStyle == 1) {
  241.         tImgNav.SetReplace("${NAV_IMG}", iFile);
  242.         tImgNav.SetReplace("${NAV_IMGS}", iFilesCount);
  243.       } else {
  244.         tImgNav.SetReplace("${NAV_NAV}", GetImgPagesNavigation(iFilesCount, iFile));
  245.       }
  246.       tImg.SetReplace("${NAV}", tImgNav.Replace());
  247.  
  248. // IMAGE TABLE
  249.       tImgDescCol.SetReplace("${IMG_DESC}", ReplaceExifStrings(cImgDesc, cFileName, cDestPath + cImgFileName));
  250.       tImgRow.SetReplace("${DESC_COLS}", tImgDescCol.Replace());
  251.  
  252.       tImgCol.SetReplace("${IMG_PAGE_FILENAME}", GetPageFN(iPage));
  253.       tImgCol.SetReplace("${IMG_FILENAME}", cImgFileName); 
  254.       tImgCol.SetReplace("${IMG_WIDTH}", pImg.GetWidth()); 
  255.       tImgCol.SetReplace("${IMG_HEIGHT}", pImg.GetHeight()); 
  256.       tImgRow.SetReplace("${IMG_COLS}", tImgCol.Replace());
  257.  
  258.       if (bImgOriginal) {
  259.         tImgOrgCol.SetReplace("${ORG_FILENAME}", cOrgFileName);
  260.         tImgOrgCol.SetReplace("${ORG_DESC}", ReplaceExifStrings(cImgOrgDesc, cFileName, "")); 
  261.         CopyFile(cFileName, cDestPath + cOrgFileName, FIL_OM_OVERWRITE);
  262.         tImgRow.SetReplace("${ORG_COLS}", tImgOrgCol.Replace());
  263.       }
  264.       tImg.SetReplace("${ROWS}", tImgRow.Replace());
  265.  
  266. // IMAGE FOOTER
  267.       tImg.SetReplace("${FOOTER}", ReplaceExifStrings(cImgFooter, cFileName, cDestPath + cImgFileName)); 
  268.  
  269. // IMAGE SAVE
  270.       SaveString(cDestPath + GetImgPageFN(iFile), tImg.Replace(), 0);
  271.  
  272.  
  273. // MAKE THUMB
  274.       pImg.Resize(iThnWidth, iThnHeight, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  275. //BOOL CJSImage::Draw(CJSImage* pDstImage, CJSRect* pSrcRect, int iPosX, int iPosY, int iAlpha, int iFlags)
  276.       var rcMag = pMagImg1.GetRect();
  277.       if (bThnMag) {
  278.         pMagImg1.Draw(pImg, rcMag, pImg.GetWidth()-rcMag.Width()-1, pImg.GetHeight()-rcMag.Height()-1, 192, GFX_KEEP_ALPHA);
  279.       }
  280.       pImg.SaveAs(cDestPath + cThnFileName, JPGformat, iTNJPEG, 0);
  281.  
  282. // THUMB TABLE
  283.       tDescCol.SetReplace("${IMG_DESC}", ReplaceExifStrings(cDesc, cFileName, cDestPath + cImgFileName)); 
  284.       cDescCols += tDescCol.Replace();
  285.  
  286.       tThnCol.SetReplace("${IMG_PAGE_FILENAME}", GetImgPageFN(iFile));
  287.       tThnCol.SetReplace("${IMG_FILENAME}", cThnFileName);
  288.       tThnCol.SetReplace("${IMG_WIDTH}", pImg.GetWidth());
  289.       tThnCol.SetReplace("${IMG_HEIGHT}", pImg.GetHeight());
  290.       cImgCols += tThnCol.Replace();
  291.  
  292.  
  293.       if (bOriginal) {
  294.         tOrgCol.SetReplace("${ORG_FILENAME}", cOrgFileName);
  295.         tOrgCol.SetReplace("${ORG_DESC}", ReplaceExifStrings(cOrgDesc, cFileName, cFileName)); 
  296.         if (!bImgOriginal) { // if not copied in IMAGE processing
  297.           CopyFile(cFileName, cDestPath + cOrgFileName, FIL_OM_OVERWRITE);
  298.         }
  299.         cOrgCols += tOrgCol.Replace();
  300.       }
  301.  
  302.       pImg.Close();
  303.  
  304.     } else { // no other files to process, make table complete
  305.       cDescCols += "  <td class=\"img_desc_td_empty\"></td>\r\n";
  306.       cImgCols += "  <td class=\"img_td_empty\"></td>\r\n";
  307.       if (bOriginal) {
  308.         cOrgCols += "  <td class=\"img_org_td_empty\"></td>\r\n";
  309.       }
  310.     }
  311.  
  312.     iCol++;
  313.  
  314.     if (iCol >= iCols) {
  315.       tRow.SetReplace("${DESC_COLS}", cDescCols);
  316.       tRow.SetReplace("${IMG_COLS}", cImgCols);
  317.       tRow.SetReplace("${ORG_COLS}", cOrgCols);
  318.       cRows += tRow.Replace();
  319.  
  320.       cDescCols = "";
  321.       cImgCols = "";
  322.       cOrgCols = "";
  323.       iCol = 0;
  324.  
  325.       iRow++;
  326.     }
  327.  
  328.     if ((iRow >= iRows) || ((iFile >= iFilesCount) && (iCol == 0))) {
  329.  
  330.       if (iPage > 1) {
  331.         tNav.SetReplace("${NAV_FIRST}", "<a href=\""+GetPageFN(1)+"\">|<</a>");
  332.         tNav.SetReplace("${NAV_PREV}", "<a href=\""+GetPageFN(iPage-1)+"\"><<</a>");
  333.       } else {
  334.         tNav.SetReplace("${NAV_FIRST}", "|<");
  335.         tNav.SetReplace("${NAV_PREV}", "<<");
  336.       }
  337.       if (iPage < iPagesCount) {
  338.         tNav.SetReplace("${NAV_NEXT}", "<a href=\""+GetPageFN(iPage+1)+"\">>></a>");
  339.         tNav.SetReplace("${NAV_LAST}", "<a href=\""+GetPageFN(iPagesCount)+"\">>|</a>");
  340.       } else {
  341.         tNav.SetReplace("${NAV_NEXT}", ">>");
  342.         tNav.SetReplace("${NAV_LAST}", ">|");
  343.       }
  344.       if (iNavStyle == 1) {
  345.         tNav.SetReplace("${NAV_PAGE}", iPage);
  346.         tNav.SetReplace("${NAV_PAGES}", iPagesCount);
  347.         tNav.SetReplace("${NAV_IMGFROM}", iImgFrom);
  348.         tNav.SetReplace("${NAV_IMGTO}", iImgTo);
  349.         tNav.SetReplace("${NAV_IMGS}", iFilesCount);
  350.       } else {
  351.         tNav.SetReplace("${NAV_NAV}", GetPagesNavigation(iPagesCount, iPage));
  352.       }
  353.       tPage.SetReplace("${NAV}", tNav.Replace());
  354.       tPage.SetReplace("${ROWS}", cRows);
  355.  
  356.       SaveString(cDestPath + GetPageFN(iPage), tPage.Replace(), 0);
  357.  
  358.       cRows = "";
  359.       iRow = 0;
  360.  
  361.       iImgFrom = iFile + 1;
  362.  
  363.       iPage++;
  364.     }
  365.  
  366.   }
  367.  
  368.   return cDestPath + GetPageFN(1);
  369.   
  370. }
  371.  
  372. INIT_OK;
  373.