void CEnvelopeWizard::AddDroppedGraphic(int nDragImage, POINT point) { if (!m_pEnvelopeDoc) return; CAGPage* pPage = m_pEnvelopeDoc->GetPage(0); if (!pPage) return; CAGLayer* pUserLayer = pPage->GetUserLayer(); if (!pUserLayer) return; CAGSymImage* pImage = m_pGraphics[nDragImage]; if (!pImage) return; CAGSymImage* pNewImage = (CAGSymImage*)pImage->Duplicate(); if (!pNewImage) return; SetImageSize(pNewImage, &point); pUserLayer->AddSymbol(pNewImage); GetDocWin()->SymbolUnselect(true); GetDocWin()->SymbolSelect(pNewImage); GetDocWin()->SymbolInvalidate(pNewImage); }
bool CXMLDlg::AddImage(HGLOBAL hMemory, bool bIsDIB, CAGPage* pPage, RECT* pDestRect) { if (!pPage || !pDestRect) { ASSERT(false); return false; } RECT MaxBounds = {0,0,0,0}; SIZE PageSize = {0,0}; pPage->GetPageSize(PageSize); ::SetRect(&MaxBounds, 0, 0, PageSize.cx, PageSize.cy); CAGSym* pSym = NULL; if (bIsDIB) { char* pMemory = (char*)::GlobalLock(hMemory); if (!pMemory) return false; // do we have a bitmap file header preceding the DIB? BITMAPFILEHEADER* pBMPFile = (BITMAPFILEHEADER*)pMemory; #define BFT_BITMAP 0x4d42 /* 'BM' */ if (pBMPFile->bfType == BFT_BITMAP) pMemory += sizeof(BITMAPFILEHEADER); BITMAPINFOHEADER* pDIB = (BITMAPINFOHEADER*)pMemory; if (pDIB->biCompression == BI_RGB) { CAGSymImage* pSymImage = new CAGSymImage(pDIB, MaxBounds); pSym = pSymImage; } ::GlobalUnlock(hMemory); } else { CAGSymImage* pSymImage = new CAGSymImage(hMemory, MaxBounds); pSym = pSymImage; } if (!pSym) { ASSERT(false); return false; } pSym->SetDestRect(*pDestRect); CAGLayer* pActiveLayer = pPage->GetActiveLayer(); if (pActiveLayer) pActiveLayer->AddSymbol(pSym); else ASSERT(false); return true; }
void CEnvelopeWizard::InitGraphics(CAGDoc* pPrevDoc) { for (int nIndex = 0; nIndex < MAX_NUM_PICTURES; nIndex++) m_pGraphics[nIndex] = NULL; if (!pPrevDoc) return; int nGraphicItem = 0; for (int nIndex = 0; nIndex < MAX_PAGES_TO_CHECK; nIndex++) { CAGPage* pPage = pPrevDoc->GetPage(nIndex); if (!pPage) continue; int nLayers = pPage->GetNumLayers(); for (int l = 0; l < nLayers; l++) { CAGLayer* pLayer = pPage->GetLayer(l); if (!pLayer) continue; int nSymbols = pLayer->GetNumSymbols(); for (int i = 0; i < nSymbols; i++) { CAGSym* pSym = (CAGSym*)pLayer->GetSymbol(i); if (!pSym) continue; if (!pSym->IsImage()) continue; CAGSymImage* pImage = (CAGSymImage*)pSym; if (pImage->IsLocked() || pImage->IsDeleted()) continue; CAGSymImage* pNewImage = (CAGSymImage*)pImage->Duplicate(); if (!pNewImage) return; // Add a copy of the image symbol to the list // Be sure to set its location to (0,0) to make it easier to add to the envelope CRect DestRect = pNewImage->GetDestRectTransformed(); DestRect.MoveToXY(0,0); pNewImage->SetDestRect(DestRect); pNewImage->SetMatrix(CAGMatrix()); pNewImage->SetHidden(false); m_pGraphics[nGraphicItem] = pNewImage; nGraphicItem++; } } } }
bool CFYSPrintDoc::PageHasSymbols(CAGPage* pPage) { bool bRetVal = false; int nLayers = pPage->GetNumLayers(); if (nLayers <= 0) return bRetVal; for (int nLayer = 0; nLayer < nLayers; nLayer++) { CAGLayer* pLayer = pPage->GetLayer(nLayer); if (!pLayer) continue; if (pLayer->GetNumSymbols()) { bRetVal = true; break; } } return bRetVal; }
void CEnvelopeWizard::CreateEnvelope(CAGDoc** ppAGDoc) { m_pEnvelopeDoc = new CAGDoc(); // Let the caller take control over this document if (ppAGDoc) *ppAGDoc = m_pEnvelopeDoc; if (!m_pEnvelopeDoc) return; m_pEnvelopeDoc->SetPortrait(m_PageSize.cx <= m_PageSize.cy); m_pEnvelopeDoc->SetDocType(DOC_ENVELOPE); m_pEnvelopeDoc->SetFileName(CString("Untitled")); m_pEnvelopeDoc->SetModified(true); CAGPage* pPage = new CAGPage(m_PageSize.cx, m_PageSize.cy); if (!pPage) return; m_pEnvelopeDoc->AddPage(pPage); int nLayers = 2; for (int j = 0; j < nLayers; j++) pPage->AddLayer(new CAGLayer()); CAGLayer* pUserLayer = pPage->GetUserLayer(); if (!pUserLayer) return; CAGLayer* pMasterLayer = pPage->GetMasterLayer(); if (!pUserLayer) return; m_nMaxImageSize = m_PageSize.cy / 2; m_pEnvelopePicture->GetPictureList()->DrawListViewThumbnails(); // Add the Background Item CAGSymGraphic* pBackground = new CAGSymRectangle(); if (pBackground) { RECT BackgroundRect; ::SetRect(&BackgroundRect, 0, 0, m_PageSize.cx, m_PageSize.cy); pBackground->SetDestRect(BackgroundRect); pBackground->SetID(IDR_ENVELOPE_BACKGROUND); pBackground->SetFillColor(RGB(240,240,255)); pBackground->SetFillColor2(RGB(255,255,255)); pBackground->SetFillType(FT_Solid); pBackground->SetHidden(true); pUserLayer->AddSymbol(pBackground); } int xCenter = m_PageSize.cx / 2; int yCenter = m_PageSize.cy / 2; RECT rMargins = { INCHES(0.375), INCHES(0.375), m_PageSize.cx - INCHES(0.375), m_PageSize.cy - INCHES(0.375)}; // Add the Send Address Text Item CAGSymText* pSendAddr = new CAGSymText(ST_TEXT); if (pSendAddr) { RECT SendRect; SendRect.left = xCenter - (INCHES(1.75)/2); SendRect.top = yCenter - (INCHES(1)/2); SendRect.right = SendRect.left + INCHES(3.0); SendRect.bottom = SendRect.top + INCHES(1.1); pSendAddr->Create(SendRect); pSendAddr->SetID(IDR_ENVELOPE_SEND); SetAddressText(pSendAddr, m_strSendAddress); pSendAddr->SelectAll(false); pSendAddr->SetHorzJust(eFlushLeft); pSendAddr->SetVertJust(eVertTop); pSendAddr->SetEmphasis(false, false, false); pUserLayer->AddSymbol(pSendAddr); } // Add the Return Address Text Item CAGSymText* pReturnAddr = new CAGSymText(ST_TEXT); if (pReturnAddr) { RECT ReturnRect; ReturnRect.left = rMargins.left; ReturnRect.top = rMargins.top; ReturnRect.right = ReturnRect.left + INCHES(3.0); ReturnRect.bottom = ReturnRect.top + INCHES(1.1); pReturnAddr->Create(ReturnRect); pReturnAddr->SetID(IDR_ENVELOPE_RETURN); SetAddressText(pReturnAddr, m_strReturnAddress); pReturnAddr->SelectAll(false); pReturnAddr->SetHorzJust(eFlushLeft); pReturnAddr->SetVertJust(eVertTop); pReturnAddr->SetEmphasis(false, false, false); pUserLayer->AddSymbol(pReturnAddr); } // Add the first image to the document CAGSymImage* pImage = m_pGraphics[0]; if (!pImage) return; CAGSymImage* pNewImage = (CAGSymImage*)pImage->Duplicate(); if (!pNewImage) return; SetImageSize(pNewImage); pNewImage->SetID(IDC_ENVELOPE_PIC_0); pUserLayer->AddSymbol(pNewImage); GetDocWin()->SymbolUnselect(true); GetDocWin()->SymbolSelect(pNewImage); GetDocWin()->Position(POS_LEFT, POS_BOTTOM, 0/*id*/); }
void CXMLDlg::CreateGraphicItem(HTREEITEM pItem, CAGPage* pPage, POINT& ptOffset, CString& szParentItemType) { HTREEITEM pChildItem = m_treeOutput.GetChildItem(pItem); if (!pChildItem) { ASSERT(false); return; } COLORREF LineColor = RGB(0,0,0); int iLineWidth = LT_None; FillType tFillType = FT_None; COLORREF FillColor = RGB(0,0,0); COLORREF FillColor2 = RGB(0,0,0); LineStart tStart = LS_LeftTop; POINT* pPoints = new POINT[5000]; int nPoints = 0; CRect DestRect; double fAngle = 0.0; while (pChildItem) { CString szItemType = m_treeOutput.GetItemText(pChildItem); if (!szItemType.CompareNoCase(_T("pt")) ) { POINT Location = {0,0}; GetCurrentObjectLocation(pChildItem, Location); pPoints[nPoints++] = Location; } else { CString szTitle; CString szValue; Separate(m_treeOutput.GetItemText(pChildItem), szTitle, szValue); if (!szTitle.CompareNoCase(_T("x")) ) { DestRect.left = INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("y")) ) { DestRect.top = INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("dx")) ) { DestRect.right = DestRect.left + INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("dy")) ) { DestRect.bottom = DestRect.top + INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("angle")) ) { fAngle = atof(szValue); } else if (!szTitle.CompareNoCase(_T("filltype")) ) { if (!szValue.CompareNoCase(_T("Solid"))) tFillType = FT_Solid; else if (!szValue.CompareNoCase(_T("SweepRight"))) tFillType = FT_SweepRight; else if (!szValue.CompareNoCase(_T("SweepDown"))) tFillType = FT_SweepDown; else if (!szValue.CompareNoCase(_T("RadialCenter"))) tFillType = FT_RadialCenter; else if (!szValue.CompareNoCase(_T("RadialCorner"))) tFillType = FT_RadialCorner; } else if (!szTitle.CompareNoCase(_T("fillcolor")) ) { FillColor = ParseColor(szValue); } else if (!szTitle.CompareNoCase(_T("fillblendcolor")) ) { FillColor2 = ParseColor(szValue); } else if (!szTitle.CompareNoCase(_T("linetype")) ) { if (!szValue.CompareNoCase(_T("Hairline"))) iLineWidth = LT_Hairline; else if (!szValue.CompareNoCase(_T("Normal"))) iLineWidth = POINTUNITS(1); } else if (!szTitle.CompareNoCase(_T("linecolor")) ) { LineColor = ParseColor(szValue); } else if (!szTitle.CompareNoCase(_T("linewidth")) ) { iLineWidth = POINTUNITS(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("start")) ) { if (!szValue.CompareNoCase(_T("UpperLeft"))) tStart = LS_LeftTop; else if (!szValue.CompareNoCase(_T("UpperRight"))) tStart = LS_RightTop; else if (!szValue.CompareNoCase(_T("LowerRight"))) tStart = LS_RightBottom; else if (!szValue.CompareNoCase(_T("LowerLeft"))) tStart = LS_LeftBottom; } } pChildItem = m_treeOutput.GetNextItem(pChildItem, TVGN_NEXT); } CAGSymGraphic* pSym = NULL; if (!szParentItemType.CompareNoCase(_T("rectangle"))) { CAGSymRectangle* pSym1 = new CAGSymRectangle(); pSym = pSym1; } else if (!szParentItemType.CompareNoCase(_T("ellipse"))) { CAGSymEllipse* pSym1 = new CAGSymEllipse(); pSym = pSym1; } else if (!szParentItemType.CompareNoCase(_T("drawing"))) { CAGSymDrawing* pSym1 = new CAGSymDrawing(); // Due to a conversion bug, flip the y value of each point within the drawing int iOffset = DestRect.bottom + DestRect.top; for (int i = 0; i < nPoints; i++) pPoints[i].y = iOffset - pPoints[i].y; pSym1->SetPoints(pPoints, nPoints); pSym = pSym1; } else if (!szParentItemType.CompareNoCase(_T("line"))) { CAGSymLine* pSym1 = new CAGSymLine(); pSym1->SetLineStart(tStart); pSym = pSym1; } else if (!szParentItemType.CompareNoCase(_T("border"))) { CAGSymRectangle* pSym1 = new CAGSymRectangle(); pSym = pSym1; // Ignore everything because the data is bad; make it a black, 5 point, unfilled rectangle LineColor = RGB(0,0,0); iLineWidth = POINTUNITS(5); tFillType = FT_None; FillColor = RGB(0,0,0); FillColor2 = RGB(0,0,0); } else if (!szParentItemType.CompareNoCase(_T("hyperlink"))) { } delete [] pPoints; if (!pSym) { ASSERT(false); return; } DestRect.OffsetRect(-ptOffset.x, -ptOffset.y); pSym->SetLineColor(LineColor); pSym->SetLineWidth(iLineWidth); pSym->SetFillType(tFillType); pSym->SetFillColor(FillColor); pSym->SetFillColor2(FillColor2); pSym->SetDestRect(DestRect); if (fAngle) { CAGMatrix Matrix; Matrix.Rotate(-fAngle, -fAngle, ((DestRect.left + DestRect.right) / 2), ((DestRect.top + DestRect.bottom) / 2)); pSym->SetMatrix(Matrix); } CAGLayer* pActiveLayer = pPage->GetActiveLayer(); if (pActiveLayer) pActiveLayer->AddSymbol(pSym); }
void CXMLDlg::CreateTextItem(HTREEITEM pItem, CAGPage* pPage, POINT& ptOffset) { HTREEITEM pChildItem = m_treeOutput.GetChildItem(pItem); if (!pChildItem) { ASSERT(false); return; } // Initialize the text properties: Color, Valign, HAlign, Angle, Font COLORREF Color = RGB(0,0,0); eTSJustTypes HAlignment = eRagCentered; eVertJust VAlignment = eVertTop; LOGFONT Font; memset(&Font, 0, sizeof(Font)); Font.lfWeight = FW_NORMAL; Font.lfCharSet = ANSI_CHARSET; //j DEFAULT_CHARSET Font.lfItalic = false; Font.lfUnderline = false; Font.lfStrikeOut = false; lstrcpy(Font.lfFaceName, "Arial"); Font.lfHeight = -POINTUNITS(14); #define MAX_SPECS 1000 int pCharOffsets[MAX_SPECS]; CAGSpec* pSpecs[MAX_SPECS]; int nSpecs = 0; char* pTextBuffer = new char[10000]; if (!pTextBuffer) { ASSERT(false); return; } *pTextBuffer = '\0'; CRect DestRect; double fAngle = 0.0; while (pChildItem) { CString szItemType = m_treeOutput.GetItemText(pChildItem); if (!szItemType.CompareNoCase(_T("style")) ) { int iOffset = lstrlen(pTextBuffer); CAGSpec* pSpec = HandleAddText(pChildItem, Font, Color, HAlignment, (BYTE*)pTextBuffer + iOffset); if (pSpec) { pSpecs[nSpecs] = pSpec; pCharOffsets[nSpecs] = iOffset; nSpecs++; } } else { CString szTitle; CString szValue; Separate(m_treeOutput.GetItemText(pChildItem), szTitle, szValue); if (!szTitle.CompareNoCase(_T("x")) ) { DestRect.left = INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("y")) ) { DestRect.top = INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("dx")) ) { DestRect.right = DestRect.left + INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("dy")) ) { DestRect.bottom = DestRect.top + INCHES(atof(szValue)); } else if (!szTitle.CompareNoCase(_T("angle")) ) { fAngle = atof(szValue); } else if (!szTitle.CompareNoCase(_T("valign")) ) { if (!szValue.CompareNoCase(_T("Top"))) VAlignment = eVertTop; else if (!szValue.CompareNoCase(_T("Middle"))) VAlignment = eVertCentered; else if (!szValue.CompareNoCase(_T("Bottom"))) VAlignment = eVertBottom; } } pChildItem = m_treeOutput.GetNextItem(pChildItem, TVGN_NEXT); } if (!nSpecs) { delete [] pTextBuffer; return; } DestRect.OffsetRect(-ptOffset.x, -ptOffset.y); CAGSymText* pText = new CAGSymText(ST_TEXT); if (pText) { pText->Create(DestRect); pText->SetVertJust(VAlignment); if (fAngle) { CAGMatrix Matrix; Matrix.Rotate(-fAngle, -fAngle, ((DestRect.left + DestRect.right) / 2), ((DestRect.top + DestRect.bottom) / 2)); pText->SetMatrix(Matrix); } // Set the text and specs pText->SetText(pTextBuffer, nSpecs, pSpecs, pCharOffsets); // Add the text symbol to the page/layer CAGLayer* pActiveLayer = pPage->GetActiveLayer(); if (pActiveLayer) pActiveLayer->AddSymbol(pText); } else ASSERT(false); delete [] pTextBuffer; }
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; }