//--------------------------------------------------------------------------// // Print single-fold card. // //--------------------------------------------------------------------------// bool CAGDoc::PrintCardSingle(PRINTSIDE PrintSide, char *pszDriver, char *pszDevice, char *pszOutput, DEVMODE *pDevMode, bool &bRotated, const char *pszFileName) { if (m_nPages != 4) return (false); bool bPortrait = (m_AGDocType == DOC_CARDHH || m_AGDocType == DOC_CARDFH); if (pDevMode) { if (bPortrait) pDevMode->dmOrientation = DMORIENT_PORTRAIT; else pDevMode->dmOrientation = DMORIENT_LANDSCAPE; pDevMode->dmFields |= DM_ORIENTATION; } CAGDC *pDC = new CAGDC(pszDriver, pszDevice, pszOutput, pDevMode); CAGDCInfo di = pDC->GetDeviceInfo(); if (pDevMode && pDevMode->dmOrientation == DMORIENT_PORTRAIT && di.m_nHorzSize > di.m_nVertSize) { delete pDC; pDevMode->dmOrientation = DMORIENT_LANDSCAPE; pDC = new CAGDC(pszDriver, pszDevice, pszOutput, pDevMode); di = pDC->GetDeviceInfo(); } else if (pDevMode && pDevMode->dmOrientation == DMORIENT_LANDSCAPE && di.m_nVertSize > di.m_nHorzSize) { delete pDC; pDevMode->dmOrientation = DMORIENT_PORTRAIT; pDC = new CAGDC(pszDriver, pszDevice, pszOutput, pDevMode); di = pDC->GetDeviceInfo(); } RECT DestRect; RECT SrcRect; SIZE sizePage; CAGMatrix ViewMatrix; bool bFlip; if (! pDC->StartDoc("Create and Print")) { delete pDC; return (false); } if (PrintSide == PRINT_OUTSIDE || PrintSide == PRINT_BOTH) { if (! pDC->StartPage()) { pDC->AbortDoc(); delete pDC; return (false); } //------------------------------------------------------------------// // Front // //------------------------------------------------------------------// CAGPage *pPage = GetPage(1); pPage->GetPageSize(&sizePage); ::SetRect(&SrcRect, 0, 0, sizePage.cx, sizePage.cy); GetSFPageRect(1, bPortrait, false, pDC, di, DestRect, bFlip, bRotated); ViewMatrix.ScaleAndCenter(DestRect, SrcRect, bFlip); pDC->SetViewingMatrix(ViewMatrix); pPage->Draw(*pDC); //------------------------------------------------------------------// // Back // //------------------------------------------------------------------// pPage = GetPage(4); pPage->GetPageSize(&sizePage); ::SetRect(&SrcRect, 0, 0, sizePage.cx, sizePage.cy); GetSFPageRect(4, bPortrait, false, pDC, di, DestRect, bFlip, bRotated); ViewMatrix.ScaleAndCenter(DestRect, SrcRect, bFlip); pDC->SetViewingMatrix(ViewMatrix); pPage->Draw(*pDC); //------------------------------------------------------------------// // BatchPrint filename. // //------------------------------------------------------------------// if (pszFileName) { LOGFONT Font; memset(&Font, 0, sizeof(Font)); Font.lfHeight = -(12 * APP_RESOLUTION / 72); lstrcpy(Font.lfFaceName, "Times New Roman"); pDC->SetFont(&Font); pDC->SetTextColor(RGB (0, 0, 0)); pDC->ExtTextOut(APP_RESOLUTION / 8, SrcRect.bottom - (APP_RESOLUTION / 8), 0, NULL, pszFileName, lstrlen(pszFileName), NULL); } if (! pDC->EndPage()) { pDC->AbortDoc(); delete pDC; return (false); } } if (PrintSide == PRINT_INSIDE || PrintSide == PRINT_BOTH) { if (! pDC->StartPage()) { pDC->AbortDoc(); delete pDC; return (false); } bool bPage2Empty = GetPage(2)->IsEmpty(); bool bPage3Empty = GetPage(3)->IsEmpty(); //------------------------------------------------------------------// // Inside Left / Top // //------------------------------------------------------------------// CAGPage *pPage = GetPage(2); pPage->GetPageSize(&sizePage); ::SetRect(&SrcRect, 0, 0, sizePage.cx, sizePage.cy); GetSFPageRect(2, bPortrait, ! bPage3Empty, pDC, di, DestRect, bFlip, bRotated); ViewMatrix.ScaleAndCenter(DestRect, SrcRect, bFlip); pDC->SetViewingMatrix(ViewMatrix); pPage->Draw(*pDC); //------------------------------------------------------------------// // BatchPrint filename. // //------------------------------------------------------------------// if (pszFileName) { LOGFONT Font; memset(&Font, 0, sizeof(Font)); Font.lfHeight = -(12 * APP_RESOLUTION / 72); lstrcpy(Font.lfFaceName, "Times New Roman"); pDC->SetFont(&Font); pDC->SetTextColor(RGB(0, 0, 0)); pDC->ExtTextOut(APP_RESOLUTION / 8, SrcRect.bottom - (APP_RESOLUTION / 8), 0, NULL, pszFileName, lstrlen(pszFileName), NULL); } //------------------------------------------------------------------// // Inside Right / Bottom // //------------------------------------------------------------------// pPage = GetPage(3); pPage->GetPageSize(&sizePage); ::SetRect(&SrcRect, 0, 0, sizePage.cx, sizePage.cy); GetSFPageRect(3, bPortrait, ! bPage2Empty, pDC, di, DestRect, bFlip, bRotated); ViewMatrix.ScaleAndCenter(DestRect, SrcRect, bFlip); pDC->SetViewingMatrix(ViewMatrix); pPage->Draw(*pDC); if (! pDC->EndPage()) { pDC->AbortDoc(); delete pDC; return (false); } } if (! pDC->EndDoc()) { pDC->AbortDoc(); delete pDC; return (false); } delete pDC; return (true); }
bool CFYSPrintDoc::CreateXmlDoc(CString& strOrderId, CString& strCorrId, CString& strFYSInfo, bool bUnpackFiles) { if (!m_pAGDoc) return false; CWaitCursor Wait; Initialize(); if (!CreateDirAndSubDirs()) return false; // Documents element CString strDocFileName; { // strip the last "\" int nLen = m_strFYSTempPath.GetLength(); CString strTempPath = m_strFYSTempPath.Left(nLen-1); strDocFileName = TempFileName(strTempPath, "4YS", "txt"); strDocFileName = m_strFYSTempPath + strDocFileName; FILE* docout = NULL; errno_t err = fopen_s(&docout, strDocFileName, "wb"); if (!docout || err != 0) { SetError(String("Failed to open %s", strDocFileName)); return false; } SIZE PageSize = {0,0}; m_pAGDoc->GetPageSize(PageSize); double dx = DINCHES(PageSize.cx); double dy = DINCHES(PageSize.cy); fprintf(docout, " <Documents Count='1'>\r\n"); fprintf(docout, " <Document CLT_CorrelationID='%s' FYS_CorrelationID='%s'>\r\n", strOrderId, strCorrId); fprintf(docout, " <GreetingCard PageWidth='%0.5G' PageHeight='%0.5G' />\r\n", dx, dy); int nPages = m_pAGDoc->GetNumPages(); for (int nPage = 0; nPage < nPages; nPage++) { CAGPage* pPage = m_pAGDoc->GetPage(nPage); if (!pPage) continue; if (!PageHasSymbols(pPage)) continue; fprintf(docout, "\t\t\t<Page PageNumber='%d'>\r\n", nPage+1); int nLayers = pPage->GetNumLayers(); for (int nLayer = 0; nLayer < nLayers; nLayer++) { CAGLayer* pLayer = pPage->GetLayer(nLayer); if (!pLayer) continue; int nSymbols = pLayer->GetNumSymbols(); for (int nSymbol = nSymbols - 1; nSymbol >= 0; nSymbol--) { bool bRetVal = true; CAGSym* pSym = pLayer->GetSymbol(nSymbol); if (!pSym || pSym->IsHidden()) continue; pSym->RegisterFileSpecsCallback(fnFileSpecs, (LPARAM)this); int idSym = pSym->GetID(); bool bReposition = (idSym == IDR_AGLOGO || idSym == IDR_CARDBACK_COPYRIGHT); if (bReposition) { // Move these symbols up to make room for the FYS logo CAGMatrix Matrix = pSym->GetMatrix(); Matrix.Translate(0, -(INCHES(0.5))); pSym->SetMatrix(Matrix); } pSym->WriteFYSXml(docout, 4); if (bReposition) { CAGMatrix Matrix = pSym->GetMatrix(); Matrix.Translate(0, INCHES(0.5)); pSym->SetMatrix(Matrix); } if (pSym->IsImage()) { CAGSymImage* pSymImage = (CAGSymImage*)pSym; CString strSep("\\"); CString strImagePath = m_strFYSTempPath + IMAGES_PATH + strSep; bRetVal = DumpImageFile(pSymImage, strImagePath); if (bRetVal) { SIZE PageSize; pPage->GetPageSize(PageSize); if (pSymImage->DoCoverDraw() && pSymImage->IsCoverAllowed()) pSymImage->WriteXmlRects(docout, PageSize, 4); } } pSym->UnregisterFileSpecsCallback(); if (!bRetVal) return false; } } fprintf(docout, "\t\t\t</Page>\r\n"); } fprintf(docout, " </Document>\r\n"); fprintf(docout, " </Documents>\r\n"); fclose(docout); } CString strSep("\\"); CString strFontsPath = m_strFYSTempPath + FONTS_PATH + strSep; DumpFontFiles(strFontsPath); // Get Configuration element if (!GetConfigurationElement(strFYSInfo)) { CleanUpEx(strDocFileName); return false; } // Get Resources element if (!GetResourcesElement()) { CleanUpEx(strDocFileName); return false; } // Write CreateAndPrint.xml file CString strXmlPath = m_strFYSTempPath + XML_PATH + strSep; if (!WriteCreatePrintXml(strDocFileName, strXmlPath)) { CleanUpEx(strDocFileName); return false; } // Write StreamHdr.xml file if (!WriteXmlStreamHeader(strXmlPath)) { CleanUp(); return false; } // Write 4YourSoul.txt file if (!CreateSendFile()) { CleanUp(); return false; } if (bUnpackFiles) UnpackFiles(); CleanUp(); return true; }