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); }
bool CTrack::PtInBorder(CPoint pt) { CAGMatrix Matrix = m_Matrix * m_ViewToDeviceMatrix; Matrix.Inverse().Transform(pt); CRect Rect = m_Distort.Rect; Rect.InflateRect(2*_OFFSET, 2*_OFFSET); bool bInOuterRect = !!Rect.PtInRect(pt); Rect.DeflateRect(3*_OFFSET, 3*_OFFSET); bool bInInnerRect = !!Rect.PtInRect(pt); return bInOuterRect && !bInInnerRect; }
void CTrack::Highlight(bool bOn, HDC hDC, bool bHash) { if (!m_pAGDC) return; m_bIsHighlight = bOn; m_bHash = bHash; if (!hDC) hDC = m_pAGDC->GetHDC(); CPoint pt[4]; pt[0] = m_Distort.p[0]; pt[1] = m_Distort.p[1]; pt[2] = m_Distort.p[2]; pt[3] = m_Distort.p[3]; CAGMatrix Matrix = m_Matrix * m_ViewToDeviceMatrix; if (!(m_iWhatCanDo & TR_DRAWASLINE)) { CRect Offset(-1, -1, 0, 0); Matrix.Inverse().Transform((CPoint*)&Offset, 2, false); pt[0].x += Offset.left; pt[0].y += Offset.top; pt[1].x += Offset.right; pt[1].y += Offset.top; pt[2].x += Offset.right; pt[2].y += Offset.bottom; pt[3].x += Offset.left; pt[3].y += Offset.bottom; } Matrix.Transform(pt[0]); Matrix.Transform(pt[1]); Matrix.Transform(pt[2]); Matrix.Transform(pt[3]); // Before drawing the transform border, open up the clipping to include a border pixel HRGN hClipRegion = m_pAGDC->SaveClipRegion(); CRect rClipRect = m_PageRect; rClipRect.InflateRect(1, 1); // Add a border pixel rClipRect.InflateRect(H_SIZE, H_SIZE); // Add the tracking handle size m_pAGDC->SetClipRect(rClipRect); Hline(hDC, pt[0].x, pt[0].y, pt[1].x, pt[1].y, m_bHash); Hline(hDC, pt[1].x, pt[1].y, pt[2].x, pt[2].y, m_bHash); Hline(hDC, pt[2].x, pt[2].y, pt[3].x, pt[3].y, m_bHash); Hline(hDC, pt[3].x, pt[3].y, pt[0].x, pt[0].y, m_bHash); m_pAGDC->RestoreClipRegion(hClipRegion); }
void CTrack::Highlight(bool bOn, HDC hDC, bool bHash) { if (!m_pAGDC) return; m_bIsHighlight = bOn; m_bHash = bHash; if (!hDC) hDC = m_pAGDC->GetHDC(); POINT pt[4]; pt[0] = m_Distort.p[0]; pt[1] = m_Distort.p[1]; pt[2] = m_Distort.p[2]; pt[3] = m_Distort.p[3]; CAGMatrix Matrix = m_Matrix * m_ViewToDeviceMatrix; if (!(m_iWhatCanDo & TR_DRAWASLINE)) { RECT Offset = {-1, -1, 0, 0}; Matrix.Inverse().Transform((POINT*)&Offset, 2, false); pt[0].x += Offset.left; pt[0].y += Offset.top; pt[1].x += Offset.right; pt[1].y += Offset.top; pt[2].x += Offset.right; pt[2].y += Offset.bottom; pt[3].x += Offset.left; pt[3].y += Offset.bottom; } Matrix.Transform(pt[0]); Matrix.Transform(pt[1]); Matrix.Transform(pt[2]); Matrix.Transform(pt[3]); // Before drawing the transform border, open up the clipping to include a border pixel HRGN hClipRegion = m_pAGDC->SaveClipRegion(); RECT rClipRect = m_PageRect; ::InflateRect(&rClipRect, 1, 1); // Add a border pixel m_pAGDC->SetClipRect(rClipRect, false/*bIncludeRawDC*/); HlineFlash(hDC, pt[0].x, pt[0].y, pt[1].x, pt[1].y, m_bHash); HlineFlash(hDC, pt[1].x, pt[1].y, pt[2].x, pt[2].y, m_bHash); HlineFlash(hDC, pt[2].x, pt[2].y, pt[3].x, pt[3].y, m_bHash); HlineFlash(hDC, pt[3].x, pt[3].y, pt[0].x, pt[0].y, m_bHash); m_pAGDC->RestoreClipRegion(hClipRegion); }
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 CTrack::Delta(int dx, int dy) { POINT ptOffset = {dx, dy}; CAGMatrix CombinedMatrix = m_Matrix * m_ViewToDeviceMatrix; CombinedMatrix.Inverse().Transform(&ptOffset, 1, false); m_bMoved = true; Draw(false/*bOn*/); m_Matrix.Translate(ptOffset.x, ptOffset.y); if (m_pDrawProc && m_pAGDC) { HDC hDC = m_pAGDC->GetHDC(); m_pDrawProc(hDC, false/*bOn*/, TOOLCODE_UPDATE, m_pData); } Draw(true/*bOn*/); }
void CNewDocWizStep1::UpdateSample(int idSample) { HWND hWnd = GetDlgItem(idSample); if (!hWnd) return; // If it is our first time in, initialize the sample rectangle if (::IsRectEmpty(&m_SampleRect)) { ::GetClientRect(hWnd, &m_SampleRect); if (::GetParent(hWnd)) ::MapWindowPoints(hWnd, ::GetParent(hWnd), (LPPOINT)&m_SampleRect.left, 2); } SIZE DocSize = {(int)(m_Data->m_fWidth * 1000), (int)(m_Data->m_fHeight * 1000)}; RECT NewRect; ::SetRect(&NewRect, 0, 0, DocSize.cx, DocSize.cy); CAGMatrix Matrix; Matrix.ScaleToFit(m_SampleRect, NewRect); Matrix.Transform(NewRect); ::MoveWindow(hWnd, NewRect.left, NewRect.top, WIDTH(NewRect), HEIGHT(NewRect), true/*bRepaint*/); }
void CCalSupport::DrawBackgroundRectangle(const RECT& Rect, const CAGMatrix& Matrix, COLORREF FillColor) { POINT pPoints[4]; Matrix.TransformRectToPolygon(Rect, pPoints); HRGN hClipRegion = m_dc.SaveClipRegion(); m_dc.SetClipRectangle(pPoints); // Draw the interior if (FillColor != CLR_NONE) m_dc.FillRectangle(pPoints, FillColor); m_dc.RestoreClipRegion(hClipRegion); }
void CCalSupport::DrawRectangle(const RECT& Rect, const CAGMatrix& Matrix, COLORREF LineColor, int LineWidth, COLORREF FillColor, const CString& strText, const CAGSpec& Spec, int VertJust, int nLineWidth, int nLineHeight) { //j #define RND (int)(255 * ((double)rand() / RAND_MAX)) //j LineColor = RGB(RND, RND, RND); POINT pPoints[4]; Matrix.TransformRectToPolygon(Rect, pPoints); HRGN hClipRegion = m_dc.SaveClipRegion(); m_dc.SetClipRectangle(pPoints); // Draw the interior if (FillColor != CLR_NONE) m_dc.FillRectangle(pPoints, FillColor); // Draw the text if (!strText.IsEmpty()) { CRect RectDeflated = Rect; RectDeflated.DeflateRect(nLineWidth, nLineHeight); Spec.DrawTextAligned(&m_dc, strText, NULL, RectDeflated, (eVertJust)VertJust); } // Draw the outline (non-hairline) if (LineWidth >= LT_Normal) { int iLineWidth = dtoi(m_dc.GetViewToDeviceMatrix().TransformDistance(2*LineWidth+1)); m_dc.DrawRectangle(pPoints, LineColor, iLineWidth, CLR_NONE); } m_dc.RestoreClipRegion(hClipRegion); // Draw the outline (hairline) if (LineWidth == LT_Hairline) m_dc.DrawRectangle(pPoints, LineColor, LT_Hairline, CLR_NONE); }
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(); }
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; }
void CTrack::Draw(bool bOn, HDC hDC) { if (!m_pAGDC) return; m_bIsDrawn = bOn; if (!hDC) hDC = m_pAGDC->GetHDC(); POINT pt[4]; pt[0] = m_Distort.p[0]; pt[1] = m_Distort.p[1]; pt[2] = m_Distort.p[2]; pt[3] = m_Distort.p[3]; CAGMatrix Matrix = m_Matrix * m_ViewToDeviceMatrix; // A trick to draw the selection rectangle outside of a transformed object if (!(m_iWhatCanDo & TR_DRAWASLINE)) { RECT Offset = {-1, -1, 0, 0}; Matrix.Inverse().Transform((POINT*)&Offset, 2, false); pt[0].x += Offset.left; pt[0].y += Offset.top; pt[1].x += Offset.right; pt[1].y += Offset.top; pt[2].x += Offset.right; pt[2].y += Offset.bottom; pt[3].x += Offset.left; pt[3].y += Offset.bottom; } Matrix.Transform(pt[0]); Matrix.Transform(pt[1]); Matrix.Transform(pt[2]); Matrix.Transform(pt[3]); // Before drawing the transform border, open up the clipping to include a border pixel HRGN hClipRegion = m_pAGDC->SaveClipRegion(); RECT rClipRect = m_PageRect; ::InflateRect(&rClipRect, 1, 1); // Add a border pixel m_pAGDC->SetClipRect(rClipRect, false/*bIncludeRawDC*/); if (m_iWhatCanDo & TR_DRAWASLINE) { Dline(hDC, pt[0].x, pt[0].y, pt[2].x, pt[2].y, bOn); } else { Hline(hDC, pt[0].x, pt[0].y, pt[1].x, pt[1].y, bOn); Hline(hDC, pt[1].x, pt[1].y, pt[2].x, pt[2].y, bOn); Hline(hDC, pt[2].x, pt[2].y, pt[3].x, pt[3].y, bOn); Hline(hDC, pt[3].x, pt[3].y, pt[0].x, pt[0].y, bOn); } DrawHandles(hDC, bOn, pt); m_pAGDC->RestoreClipRegion(hClipRegion); }
//--------------------------------------------------------------------------// // 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); }
void CCalSupport::Draw() { COLORREF LineColor = m_pCalSym->m_LineColor; bool bInvisible = (LineColor == CLR_NONE); int LineWidth = m_pCalSym->m_LineWidth; if (bInvisible) LineWidth = LT_None; CAGMatrix LineInverseMatrix = m_dc.GetSymbolMatrix(); double fAngle = LineInverseMatrix.GetAngle(); LineInverseMatrix.Rotate(-fAngle, -fAngle); LineInverseMatrix = LineInverseMatrix.Inverse(); int nLineSize = (LineWidth == LT_Hairline ? 0 : LineWidth); int nLineWidth = dtoi(LineInverseMatrix.TransformWidth(nLineSize)); int nLineHeight = dtoi(LineInverseMatrix.TransformHeight(nLineSize)); RECT SymbolRect = m_pCalSym->m_DestRect; int iSymbolHeight = HEIGHT(SymbolRect); int iTitleHeight = (iSymbolHeight * m_pCalSym->m_uCalStyles.TitleSize) / 100; int iWeekHeight = (iSymbolHeight * m_pCalSym->m_uCalStyles.DayOfWkSize) / 100; int iDatesHeight = (iSymbolHeight - iTitleHeight - iWeekHeight); int iDateHeight = ((iDatesHeight - nLineHeight) / 6); int iDateWidth = (WIDTH(SymbolRect) - nLineWidth) / 7; // Fill the 3 big background areas RECT TitleRect = SymbolRect; TitleRect.bottom = TitleRect.top + iTitleHeight; RECT WeekRect = SymbolRect; WeekRect.top = TitleRect.bottom; WeekRect.bottom = WeekRect.top + iWeekHeight; RECT DateRect = SymbolRect; DateRect.top = WeekRect.bottom; DateRect.bottom = DateRect.top + iDatesHeight; COLORREF TitleFillColor = (m_pCalSym->m_FillColor == CLR_DEFAULT ? CLR_NONE : m_pCalSym->m_FillColor); COLORREF WeekFillColor = (m_pCalSym->m_FillColor2 == CLR_DEFAULT ? CLR_NONE : m_pCalSym->m_FillColor2); COLORREF DateFillColor = (m_pCalSym->m_FillColor3 == CLR_DEFAULT ? CLR_NONE : m_pCalSym->m_FillColor3); CAGMatrix Matrix = m_dc.GetSymbolToDeviceMatrix(); DrawBackgroundRectangle(TitleRect, Matrix, TitleFillColor); DrawBackgroundRectangle(WeekRect, Matrix, WeekFillColor); DrawBackgroundRectangle(DateRect, Matrix, DateFillColor); // Compute the Title rect TitleRect = SymbolRect; TitleRect.bottom = TitleRect.top + iTitleHeight + nLineHeight; // Draw the Title box and text m_pCalSym->m_SpecMonth.m_HorzJust = (eTSJust)m_pCalSym->m_uCalStyles1.TitleHorzJust; DrawRectangle(TitleRect, Matrix, LineColor, LineWidth, CLR_NONE, GetTitleStr(), m_pCalSym->m_SpecMonth, m_pCalSym->m_uCalStyles1.TitleVertJust, nLineWidth, nLineHeight); // Compute the Week rect WeekRect.left = SymbolRect.left; WeekRect.right = WeekRect.left + iDateWidth + nLineWidth; WeekRect.top = TitleRect.bottom - nLineHeight; WeekRect.bottom = WeekRect.top + iWeekHeight + nLineHeight; // Draw the Week boxes and text m_pCalSym->m_SpecWeek.m_HorzJust = (eTSJust)m_pCalSym->m_uCalStyles1.WeekHorzJust; bool bSunStart = (m_pCalSym->m_uCalStyles.WeekStart == CALSTYLES::SUNDAY_START); for (int i=0; i<7; i++) { int iDay = (bSunStart ? i : i+1); DrawRectangle(WeekRect, Matrix, LineColor, LineWidth, CLR_NONE, GetWeekStr(iDay), m_pCalSym->m_SpecWeek, m_pCalSym->m_uCalStyles1.WeekVertJust, nLineWidth, nLineHeight); // Update the Week rect WeekRect.left += iDateWidth; WeekRect.right = WeekRect.left + iDateWidth + nLineWidth; if (i == 5) WeekRect.right = SymbolRect.right; } // Compute the Date rect DateRect.left = 0; DateRect.right = 0; DateRect.top = WeekRect.bottom - nLineHeight; DateRect.bottom = DateRect.top + iDateHeight + nLineHeight; // Draw the Date boxes and text m_pCalSym->m_SpecDays.m_HorzJust = (eTSJust)m_pCalSym->m_uCalStyles1.DateHorzJust; int nDaysInMonth = GetDaysInMonth(); int iDay = 2 - GetFirstDayOfMonth(); for (int y=0; y<6; y++) { DateRect.left = SymbolRect.left; DateRect.right = DateRect.left + iDateWidth + nLineWidth; bool bRowEmpty = true; for (int x=0; x<7; x++) { bool bDraw = false; CString strText; if (iDay <= nDaysInMonth) { bDraw = true; if (iDay >= 1) { strText = String("%d", iDay); bRowEmpty = false; } } else { bool bHideUnusedBoxes = (m_pCalSym->m_uCalStyles.HideBoxes == 1); bool bHideAllBoxes = (m_pCalSym->m_uCalStyles.HideAllBoxes == 1); bool bHideEmptyRows = (m_pCalSym->m_uCalStyles.HideAllBoxes == 0); bool bHide = bHideUnusedBoxes && (bHideAllBoxes || (bHideEmptyRows && bRowEmpty)); bDraw = !bHide; } if (bDraw) DrawRectangle(DateRect, Matrix, LineColor, LineWidth, CLR_NONE, strText, m_pCalSym->m_SpecDays, m_pCalSym->m_uCalStyles1.DateVertJust, nLineWidth, nLineHeight); iDay++; // Update the Date rect DateRect.left += iDateWidth; DateRect.right = DateRect.left + iDateWidth + nLineWidth; if (x == 5) DateRect.right = SymbolRect.right; } // Update the Date rect DateRect.top += iDateHeight; DateRect.bottom = DateRect.top + iDateHeight + nLineHeight; if (y == 4) DateRect.bottom = SymbolRect.bottom; } }
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; }