void CEnvelopeWizard::SetImageSize(CAGSymImage* pImage, POINT* pCenterPoint) { if (!pImage) return; // The image symbol should be at (0,0) and have a unity matrix CRect DestRect = pImage->GetDestRect(); DestRect.MoveToXY(0,0); pImage->SetDestRect(DestRect); // Maintain a maximum image size using the symbol's matrix CAGMatrix NewMatrix; if (DestRect.Width() > m_nMaxImageSize || DestRect.Height() > m_nMaxImageSize) { int dx = m_nMaxImageSize; int dy = m_nMaxImageSize; double fScale = ScaleToFit(&dx, &dy, DestRect.Width(), DestRect.Height(), true/*bUseSmallerFactor*/); NewMatrix.Scale(fScale, fScale); NewMatrix.Transform(DestRect); } if (pCenterPoint) NewMatrix.Translate(pCenterPoint->x - DestRect.Width()/2, pCenterPoint->y - DestRect.Height()/2); pImage->SetMatrix(NewMatrix); }
void CDocWindow::HandleImageRecolor(int x, int y, CImageObject* pObject) { if (pObject == NULL) return; BITMAPINFOHEADER* pBitmap = pObject->GetDib(); if (pBitmap != NULL) { CRect DestRect = pObject->GetDestRect(); CFloodFill FloodFill; CAGMatrix Matrix; CPoint pt(x, y); if (m_pClientDC) m_pClientDC->GetViewToDeviceMatrix().Inverse().Transform(pt); double xScale = (double)DibWidth(pBitmap) / DestRect.Width(); double yScale = (double)DibHeight(pBitmap) / DestRect.Height(); Matrix.Translate(-DestRect.left, -DestRect.top); Matrix.Scale(xScale, yScale, 0, 0); Matrix.Transform(pt); FloodFill.Fill(pBitmap, &DestRect, pt.x, pt.y, (m_fUsePrimaryColor ? m_PrimaryColor : m_SecondaryColor)); } // Invalidate the image's current location InvalidateImage(pObject); pObject->SetModified(true); //if (pDIBNew) //{ // pObject->SetDib(pDIBNew); // free(pDIB); //} //else //{ // // Adjust the image's matrix // CRect DestRect = pObject->GetDestRect(); // CAGMatrix Matrix = pObject->GetMatrix(); // Matrix.Transform(DestRect); // Matrix.Scale((bFlipX ? -1 : 1), (bFlipY ? -1 : 1), // (DestRect.left + DestRect.right) / 2, // (DestRect.top + DestRect.bottom) / 2); // pObject->SetMatrix(Matrix); //} }
void CDocWindow::SetupPageView(bool bSetScrollbars) { #define OUTSIDE_PADDING_X 10 #define OUTSIDE_PADDING_Y 10 if (!m_hWnd) return; if (!m_pClientDC) return; if (m_PageRect.IsRectEmpty()) return; // Suspend any selection tracking m_Select.SuspendTracking(); // Clear the old page from the offscreen DC m_pClientDC->Clear(); // Invalidate the old page rect (m_PageViewRect) before we change it InvalidatePage(); // Now figure out how much window area we have for the document display CRect WndRect; GetClientRect(&WndRect); // Subtract the outside padding WndRect.bottom -= m_ShadowSize.cx; WndRect.right -= m_ShadowSize.cy; WndRect.InflateRect(-OUTSIDE_PADDING_X, -OUTSIDE_PADDING_Y); // Convert to Document coordinates m_pClientDC->GetDeviceMatrix().Inverse().Transform(WndRect); int xVisible = WndRect.Width(); int yVisible = WndRect.Height(); // Fit the extended page into the available window space int dxPage = m_PageRect.Width(); int dyPage = m_PageRect.Height(); if (!dxPage) dxPage = 1; if (!dyPage) dyPage = 1; double fxPageScale = (double)xVisible / dxPage; double fyPageScale = (double)yVisible / dyPage; double fFitInWindowScale = min(fxPageScale, fyPageScale); if (!fFitInWindowScale) fFitInWindowScale = 1.0; // Default the scroll position to the center of the current page int xPos = -1; int yPos = -1; // Special setting to indicate a zoom into the center of the SELECTED OBJECT if (m_fZoomScale == -1.0 && m_Select.GetSelected()) { CRect DestRect = m_Select.GetSelected()->GetDestRectTransformed(); int dxObject = DestRect.Width(); int dyObject = DestRect.Height(); if (!dxObject) dxObject = 1; if (!dyObject) dyObject = 1; double fxObjectScale = (double)xVisible / dxObject; double fyObjectScale = (double)yVisible / dyObject; double fFitScaleObject = min(fxObjectScale, fyObjectScale); m_fZoomScale = fFitScaleObject / fFitInWindowScale; m_iZoom = dtoi(m_fZoomScale - 1.0); // Set the (x,y) position to be the center of the object xPos = (DestRect.left + DestRect.right) / 2; yPos = (DestRect.top + DestRect.bottom) / 2; } // Special setting to indicate a zoom into the width of the FULL PAGE if (m_fZoomScale <= 0) { m_fZoomScale = fxPageScale / fFitInWindowScale; m_iZoom = dtoi(m_fZoomScale - 1.0); } // Compute the scale and adjust the visible area double fScale = fFitInWindowScale * m_fZoomScale; xVisible = dtoi((double)xVisible / fScale); yVisible = dtoi((double)yVisible / fScale); // If the (x,y) position was set to the object center, adjust it by 1/2 the visible area if (xPos >= 0 || yPos >= 0) { xPos -= xVisible / 2; yPos -= yVisible / 2; } // Setup the scrollbars if (bSetScrollbars) SetupScrollbars(xPos, yPos, dxPage, dyPage, xVisible, yVisible, true/*bRedraw*/); // Get the updated position xPos = GetScrollPos(SB_HORZ); yPos = GetScrollPos(SB_VERT); // Calculate a view matrix int xExcess = xVisible - dxPage; if (xExcess < 0) xExcess = 0; int yExcess = yVisible - dyPage; if (yExcess < 0) yExcess = 0; CAGMatrix ViewMatrix; ViewMatrix.Translate(xExcess/2 - xPos, yExcess/2 - yPos); ViewMatrix.Scale(fScale, fScale); ViewMatrix.Translate(WndRect.left, WndRect.top); m_pClientDC->SetViewingMatrix(ViewMatrix); // Compute the new page view rectangle (screen coordinates) CSize PageSize(m_PageRect.Width(), m_PageRect.Height()); m_pClientDC->SetClipToView(PageSize, &m_PageViewRect, true/*bIncludeRawDC*/); // Invalidate the new page rect (m_PageViewRect) now that we've changed it InvalidatePage(); // Resume any selection tracking m_Select.ResumeTracking(); }
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; }