home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 September / PCWorld_2004-09_cd.bin / software / temacd / zoner / zme6_trial_cz.exe / book1.ZHT / main.js < prev    next >
Encoding:
Text File  |  2004-03-09  |  7.2 KB  |  218 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 GetPageFN(iPage) {
  15.   if (iPage == 1) {
  16.     return "index.htm";
  17.   }
  18.  
  19.   return "page" + IntToStr(iPage, 5) + ".htm";
  20. }
  21.  
  22. var iThnWidth = 160;
  23. var iThnHeight = 120;
  24. var rcThn;
  25.  
  26. function ProcessImage(pImg, pDestImg) {
  27.   pImg.Resize(rcThn.Width()-4, rcThn.Height()-4, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  28.   var rcResized = pImg.GetRect();
  29.  
  30.   pImg.Shadow(iShadowColor, iShadowAlpha*2.55, iShadowXOffset, iShadowYOffset, iShadowBlur, 0);
  31.  
  32.   //pImg.Resize(rcThn.Width(), rcThn.Height(), GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  33.   var rcResized = pImg.GetRect();
  34.  
  35.   var fAngle = Math.random()*fMaxAngle*2-fMaxAngle;
  36.   pImg.Rotate(fAngle, 0, GFX_INTERPOLATE);
  37.  
  38.   var rcImg = pImg.GetRect();
  39.  
  40.   var iOffsetX = (iThnWidth - rcImg.Width()) / 2;
  41.   var iOffsetY = (iThnHeight - rcImg.Height()) / 2;
  42.  
  43.   pImg.Draw(pDestImg, rcImg, iOffsetX, iOffsetY, 255, GFX_KEEP_ALPHA);
  44.  
  45.   return GetRotatedImageMap(rcResized, fAngle, iOffsetX, iOffsetY);
  46. }
  47.  
  48. function GenerateAlbum(cSourcePath, cDestPath)
  49. {
  50.   rcThn = CalcRectBeforeRotate(fMaxAngle, iThnWidth, iThnHeight);
  51.  
  52.   var iFilesCount = lSelectedFiles.GetCount();
  53.  
  54.   var iPagesCount = Math.ceil(iFilesCount / 6);
  55.  
  56.   CopyFile(cSourcePath + "0101.jpg", cDestPath + "0101.jpg", FIL_OM_OVERWRITE);
  57.  
  58.   CopyFile(cSourcePath + "0201.jpg", cDestPath + "0201.jpg", FIL_OM_OVERWRITE);
  59.   CopyFile(cSourcePath + "0203.jpg", cDestPath + "0203.jpg", FIL_OM_OVERWRITE);
  60.   CopyFile(cSourcePath + "0205.jpg", cDestPath + "0205.jpg", FIL_OM_OVERWRITE);
  61.  
  62.   CopyFile(cSourcePath + "0301.jpg", cDestPath + "0301.jpg", FIL_OM_OVERWRITE);
  63.  
  64.   CopyFile(cSourcePath + "0401.jpg", cDestPath + "0401.jpg", FIL_OM_OVERWRITE);
  65.   CopyFile(cSourcePath + "0403.jpg", cDestPath + "0403.jpg", FIL_OM_OVERWRITE);
  66.   CopyFile(cSourcePath + "0405.jpg", cDestPath + "0405.jpg", FIL_OM_OVERWRITE);
  67.  
  68.   CopyFile(cSourcePath + "0501.jpg", cDestPath + "0501.jpg", FIL_OM_OVERWRITE);
  69.  
  70.   CopyFile(cSourcePath + "0601.jpg", cDestPath + "0601.jpg", FIL_OM_OVERWRITE);
  71.   CopyFile(cSourcePath + "0603.jpg", cDestPath + "0603.jpg", FIL_OM_OVERWRITE);
  72.   CopyFile(cSourcePath + "0605.jpg", cDestPath + "0605.jpg", FIL_OM_OVERWRITE);
  73.  
  74.   CopyFile(cSourcePath + "0701.jpg", cDestPath + "0701.jpg", FIL_OM_OVERWRITE);
  75.  
  76.   CopyFile(cSourcePath + "0801.jpg", cDestPath + "0801.jpg", FIL_OM_OVERWRITE);
  77.   CopyFile(cSourcePath + "0803.jpg", cDestPath + "0803.jpg", FIL_OM_OVERWRITE);
  78.   CopyFile(cSourcePath + "0805.jpg", cDestPath + "0805.jpg", FIL_OM_OVERWRITE);
  79.  
  80.   CopyFile(cSourcePath + "0901.jpg", cDestPath + "0901.jpg", FIL_OM_OVERWRITE);
  81.  
  82.   var tPage = new CTemplate();
  83.   tPage.Load(cSourcePath + "page.tpl", 0);
  84.  
  85.   tPage.SetReplace("${TITLE}", cTitle);
  86.   tPage.SetReplace("${HEAD_FONT_SIZE}", iHeaderFontSize);
  87.   tPage.SetReplace("${HEAD_FONT_COLOR}", HEXColor(iHeaderFontColor));
  88.   tPage.SetReplace("${FOOT_FONT_SIZE}", iFooterFontSize);
  89.   tPage.SetReplace("${FOOT_FONT_COLOR}", HEXColor(iFooterFontColor));
  90.   tPage.SetReplace("${HEADER}", ReplaceExifStrings(cHeader, "", ""));
  91.   tPage.SetReplace("${FOOTER}", ReplaceExifStrings(cFooter, "", ""));
  92.  
  93.   var tImg = new CTemplate();
  94.   tImg.Load(cSourcePath + "img.tpl", 0);
  95.  
  96.   var tNoImg = new CTemplate();
  97.   tNoImg.Load(cSourcePath + "noimg.tpl", 0);
  98.  
  99.   var tPgn = new CTemplate();
  100.   tPgn.Load(cSourcePath + "pgn.tpl", 0);
  101.  
  102.   var tMap = new CTemplate();
  103.   tMap.Load(cSourcePath + "map.tpl", 0);
  104.  
  105.   var iPage = 1;
  106.   var iImg = 1;
  107.   var cMaps = "";
  108.  
  109.   for (var iFile = 1; ((iFile <= iFilesCount) || (iImg != 1)); iFile++) {
  110.     if (iFile <= iFilesCount) {
  111.  
  112.       var cFileName = lSelectedFiles.GetAt(iFile-1);
  113.       var cImgFileName = "img" + IntToStr(iFile, 5) + ".jpg";
  114.       var cThnFileName = "thn" + IntToStr(iPage, 3) + "-" + iImg + ".jpg";
  115.       var cMapName = "imgMap" + iImg;
  116.  
  117.       var pOrigImg = new CImage();
  118.       pOrigImg.Load(cFileName, 0);
  119.  
  120.       pOrigImg.Resize(iImgWidth, iImgHeight, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  121.       pOrigImg.SaveAs(cDestPath + cImgFileName, JPGformat, iImgJPEG, 0);
  122.  
  123.       var pImg = new CImage();
  124.       pImg.Load(cSourcePath + "img" + iImg + ".jpg", 0);
  125.       var cMapCoords = ProcessImage(pOrigImg, pImg);
  126.       pImg.SaveAs(cDestPath + cThnFileName, JPGformat, iTNJPEG, 0);
  127.  
  128.       pOrigImg.Close();
  129.       pImg.Close();
  130.  
  131.       tMap.SetReplace("${MAP_NAME}", cMapName);
  132.       tMap.SetReplace("${MAP_HREF}", cImgFileName);
  133.       tMap.SetReplace("${MAP_COORDS}", cMapCoords);
  134.       cMaps += tMap.Replace();
  135.  
  136.       tImg.SetReplace("${THN_FILENAME}", cThnFileName);
  137.       tImg.SetReplace("${THN_MAPNAME}", cMapName);
  138.  
  139.       tPage.SetReplace("${IMG"+iImg+"}", tImg.Replace()); 
  140.  
  141.       pImg.Close();
  142.       pOrigImg.Close();
  143.  
  144.     } else { // no other files to process, make table complete
  145.       var cThnFileName = "thn" + IntToStr(iPage, 3) + "-" + iImg + ".jpg";
  146.       CopyFile(cSourcePath + "img" + iImg + ".jpg", cDestPath + cThnFileName, FIL_OM_OVERWRITE);
  147.       tNoImg.SetReplace("${THN_FILENAME}", cThnFileName);
  148.  
  149.       tPage.SetReplace("${IMG"+iImg+"}", tNoImg.Replace()); 
  150.     }
  151.  
  152.     iImg++;
  153.  
  154.     if (iImg > 6) {
  155.       if (iPage > 1) {
  156.         tPage.SetReplace("${PREV}", "  <a href=\""+GetPageFN(iPage-1)+"\"><<</a>");
  157.       } else {
  158.         tPage.SetReplace("${PREV}", "  ");
  159.       }
  160.       if (iPage < iPagesCount) {
  161.         tPage.SetReplace("${NEXT}", "<a href=\""+GetPageFN(iPage+1)+"\">>></a>  ");
  162.       } else {
  163.         tPage.SetReplace("${NEXT}", "  ");
  164.       }
  165.       tPage.SetReplace("${MAPS}", cMaps);
  166.  
  167.       var pFont = NewFont("Tahoma", 20, 0, 0);
  168.       var pText = new CImage();
  169.       var pImg = new CImage();
  170.  
  171.       var cPgnFileName = "pgn" + IntToStr(iPage, 3) + "-" + 1 + ".jpg";
  172.  
  173.       pText.CreateText((iPage-1)*2+1, 140, pFont, 0, 0, 0, GFX_TEXT_TRANSPARENT | GFX_TEXT_CENTER);
  174.       pText.Resize(70, 20, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  175.       var rcText = pText.GetRect();
  176.  
  177.       pImg.Load(cSourcePath + "pgn1.jpg", 0);
  178.       pText.Draw(pImg, rcText, 0, 0, 255, GFX_KEEP_ALPHA);
  179.       pImg.SaveAs(cDestPath + cPgnFileName, JPGformat, 70, 0);
  180.  
  181.       tPgn.SetReplace("${THN_FILENAME}", cPgnFileName);
  182.       tPage.SetReplace("${PGN1}", tPgn.Replace());
  183.  
  184.       pImg.Close();
  185.       pText.Close();
  186.  
  187.       var cPgnFileName = "pgn" + IntToStr(iPage, 3) + "-" + 2 + ".jpg";
  188.  
  189.       pText.CreateText((iPage-1)*2+2, 140, pFont, 0, 0, 0, GFX_TEXT_TRANSPARENT | GFX_TEXT_CENTER);
  190.       pText.Resize(70, 20, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  191.       var rcText = pText.GetRect();
  192.  
  193.       pImg.Load(cSourcePath+"pgn2.jpg", 0);
  194.       pText.Draw(pImg, rcText, 0, 0, 255, GFX_KEEP_ALPHA);
  195.       pImg.SaveAs(cDestPath + cPgnFileName, JPGformat, 70, 0);
  196.  
  197.       tPgn.SetReplace("${THN_FILENAME}", cPgnFileName);
  198.       tPage.SetReplace("${PGN2}", tPgn.Replace());
  199.  
  200.       pImg.Close();
  201.       pText.Close();
  202.  
  203.       SaveString(cDestPath + GetPageFN(iPage), tPage.Replace(), 0);
  204.  
  205.       cMaps = "";
  206.       iImg = 1;
  207.  
  208.       iPage++;
  209.     }
  210.  
  211.   }
  212.  
  213.   return cDestPath + GetPageFN(1);
  214.   
  215. }
  216.  
  217. INIT_OK;
  218.