int CLabelView::PrintLabelsBackward(PrintContext &pc, int nSide) { CPmwDoc* pDoc = GetDocument(); CLabelPrintDialog* pDialog = (CLabelPrintDialog*)pc.m_pPD; int nTotalPages = pDialog->m_nTotalPages; // Set the side. DWORD dwCurrentPage = pDoc->CurrentPageIndex(); if (nSide != (int)dwCurrentPage) { pDoc->GotoPage((DWORD)nSide, FALSE); } // Start at requested first label for first page. int nError = 0; // Run through all the pages. for (int nPage = nTotalPages; nPage-- > 0;) { pc.m_nStartingLabel = (nPage == 0) ? pDialog->m_nStartingLabel : 0; SetLabelVariables(pc, nPage); if ((nError = OnPrintLabels(pc, nPage, nTotalPages)) != 0) { // Aack! We got an error. Leave now. break; } } // Reset the page. if (dwCurrentPage != pDoc->CurrentPageIndex()) { pDoc->GotoPage(dwCurrentPage, FALSE); } return nError; }
void CLabelView::OnDraw(CDC* pDC) { // Print preview comes in as printing. Printing case does not come here. // So, IsPrinting() flag determines preview. if (!pDC->IsPrinting() || m_pPreviewExtent == NULL) { INHERITED::OnDraw(pDC); return; } /* // Save the scaled_source x0 and y0 in the printer rc since we will be // changing them. */ // Save the in extent since it gets change during interrupt. PBOX InExtent = m_pPreviewExtent->extent; PBOX SourcePbox = printer_rc.source_pbox; PPNT SourceOrigin; SourceOrigin.x = printer_rc.scaled_source_x0; SourceOrigin.y = printer_rc.scaled_source_y0; /* Get the document to work with. */ CPmwDoc* pDoc = GetDocument(); int nPrintOrientation = pDoc->get_orientation(); BOOL fLandscape = (nPrintOrientation == LANDSCAPE); /* Get the App and its info. */ CPmwApp* pApp = GET_PMWAPP(); CPaperInfo* pPaperInfo = pApp->GetPaperInfo(nPrintOrientation); CPrinterInfo* pPrinterInfo = pApp->GetPrinterInfo(nPrintOrientation); CFixedRect PaperPhysicalMargins = pPaperInfo->PhysicalMargins(); /* Get the paper info. */ CPaperInfo* pLabelInfo = pDoc->GetPaperInfo(); CFixedRect Margins = pLabelInfo->Margins(); // If this is landscape, rotate the margins correctly. pPrinterInfo->OrientRect(&Margins); /* Compute the number of slots we need to print. */ int nSlot = m_pPreviewExtent->update_object == NULL ? 0 : m_pPreviewExtent->m_nPreviewSlot; int nSlots = pLabelInfo->Slots(); /* Run through all the slots. */ while (nSlot < nSlots) { /* // Setup the parameters for this slot so that we will draw in the correct // spot on the page. */ ASSERT(pDoc->CurrentPageIndex() == 0 || pDoc->CurrentPageIndex() == 1); CFixedRect SlotBounds = pLabelInfo->SlotBounds(nSlot); BOOL fBack = (pDoc->CurrentPageIndex() == 1); CFixedPoint Dims = pLabelInfo->PaperDims(); CFixed lLeft = SlotBounds.Left; CFixed lTop = SlotBounds.Top; CFixed lWidth = SlotBounds.Width(); CFixed lHeight = SlotBounds.Height(); if (fLandscape) { switch (pPrinterInfo->Orientation()) { case 90: { // 90 degree rotation (like lasers) SlotBounds.Left = Dims.y - (lTop + lHeight); SlotBounds.Top = lLeft; break; } // case -1: // case 270: default: { // 270 degree rotation (like dot-matrix) SlotBounds.Left = lTop; SlotBounds.Top = Dims.x - (lLeft + lWidth); break; } } if (fBack) { // We are printing the back side. Reverse the slot. SlotBounds.Left = Dims.y - (SlotBounds.Left + lHeight); } SlotBounds.Right = SlotBounds.Left + lHeight; SlotBounds.Bottom = SlotBounds.Top + lWidth; } else { // Portrait. if (fBack) { // We are printing the back side. Reverse the slot. SlotBounds.Left = Dims.x - SlotBounds.Right; SlotBounds.Right = SlotBounds.Left + lWidth; } } CFixedPoint Org; Org.x = Margins.Left-PaperPhysicalMargins.Left; Org.y = Margins.Top-PaperPhysicalMargins.Top; if (fLandscape) { /* Printout is landscape. Reverse the origins. */ CFixed t = Org.x; Org.x = Org.y; Org.y = t; } PPNT Delta; Delta.x = MulFixed(SlotBounds.Left + Org.x, PAGE_RESOLUTION); Delta.y = MulFixed(SlotBounds.Top + Org.y, PAGE_RESOLUTION); printer_rc.source_pbox.x0 = SourcePbox.x0 - Delta.x; printer_rc.source_pbox.y0 = SourcePbox.y0 - Delta.y; printer_rc.source_pbox.x1 = SourcePbox.x1 - Delta.x; printer_rc.source_pbox.y1 = SourcePbox.y1 - Delta.y; printer_rc.scaled_source_x0 = /*SourceOrigin.x*/ - Delta.x*printer_rc.x_resolution; printer_rc.scaled_source_y0 = /*SourceOrigin.y*/ - Delta.y*printer_rc.y_resolution; if (IsBoxOnBox(&printer_rc.source_pbox, &InExtent)) { // Do the draw. INHERITED::OnDraw(pDC); if (m_pPreviewExtent->update_object != NULL) { m_pPreviewExtent->m_nPreviewSlot = nSlot; m_pPreviewExtent->extent = InExtent; break; } } /* // Update the parameters for the next label to draw. */ nSlot++; } /* // Restore the scaled source x0 from the saved values. */ printer_rc.source_pbox = SourcePbox; printer_rc.scaled_source_x0 = SourceOrigin.x; printer_rc.scaled_source_y0 = SourceOrigin.y; }
void CLabelView::OnDraw(PrintContext* pc) { CPmwDoc* pDoc = GetDocument(); DWORD dwPage = pDoc->CurrentPageIndex(); // Verify we are doing a normal page. if (dwPage != 0 && dwPage != 1) { // Non-standard page (like the "key" page). Defer to the base class. CPmwView::OnDraw(pc); return; } /* // Save the scaled_source x0 and y0 in the printer rc since we will be // changing them. */ PBOX SourcePbox = printer_rc.source_pbox; PPNT SourceOrigin; SourceOrigin.x = printer_rc.scaled_source_x0; SourceOrigin.y = printer_rc.scaled_source_y0; /* Get the document to work with. */ int nPrintOrientation = pDoc->get_orientation(); BOOL fLandscape = (nPrintOrientation == LANDSCAPE); /* Get the App and its info. */ CPmwApp* pApp = GET_PMWAPP(); CPaperInfo* pPaperInfo = pApp->GetPaperInfo(nPrintOrientation); CPrinterInfo* pPrinterInfo = pApp->GetPrinterInfo(nPrintOrientation); CFixedRect PaperPhysicalMargins = pPaperInfo->PhysicalMargins(); /* Get the paper info. */ CPaperInfo* pLabelInfo = pDoc->GetPaperInfo(); CFixedRect Margins = pLabelInfo->Margins(); // If this is landscape, rotate the margins correctly. pPrinterInfo->OrientRect(&Margins); /* Get the label print dialog. */ CLabelPrintDialog* pDialog = (CLabelPrintDialog*)pc->m_pPD; /* Get the name list. */ CStdMacroServer* pMacroServer = pDoc->GetMacroServer(); NameListRecord* pNameList = pMacroServer->GetNameList(); /* Compute the number of slots we need to print. */ int nSlot = pc->m_nStartingLabel; int nSlots = pLabelInfo->Slots(); /* Run through all the slots. */ while (nSlot < nSlots && !UserAbort) { /* // See if the name we want is the one that's bound. */ if (pc->m_nBoundName != pc->m_nCurrentName) { pc->m_nBoundName = pc->m_nCurrentName; ASSERT(pc->m_pCursor != NULL); if (pc->m_pCursor != NULL) { pMacroServer->BindToRecord(pc->m_pCursor, pNameList->Name(pc->m_nBoundName)); pDoc->ReflowMacros(); } } /* // Setup the parameters for this slot so that we will draw in the correct // spot on the page. */ ASSERT(dwPage == 0 || dwPage == 1); CFixedRect SlotBounds = pLabelInfo->SlotBounds(nSlot); BOOL fBack = (dwPage == 1); CFixedPoint Dims = pLabelInfo->PaperDims(); CFixed lLeft = SlotBounds.Left; CFixed lTop = SlotBounds.Top; CFixed lWidth = SlotBounds.Width(); CFixed lHeight = SlotBounds.Height(); if (fLandscape) { switch (pPrinterInfo->Orientation()) { case 90: { // 90 degree rotation (like lasers) SlotBounds.Left = Dims.y - (lTop + lHeight); SlotBounds.Top = lLeft; break; } // case -1: // case 270: default: { // 270 degree rotation (like dot-matrix) SlotBounds.Left = lTop; SlotBounds.Top = Dims.x - (lLeft + lWidth); break; } } if (fBack) { // We are printing the back side. Reverse the slot. SlotBounds.Left = Dims.y - (SlotBounds.Left + lHeight); } SlotBounds.Right = SlotBounds.Left + lHeight; SlotBounds.Bottom = SlotBounds.Top + lWidth; } else { // Portrait. if (fBack) { // We are printing the back side. Reverse the slot. SlotBounds.Left = Dims.x - SlotBounds.Right; SlotBounds.Right = SlotBounds.Left + lWidth; } } CFixedPoint Org; Org.x = Margins.Left-PaperPhysicalMargins.Left; Org.y = Margins.Top-PaperPhysicalMargins.Top; if (fLandscape) { /* Printout is landscape. Reverse the origins. */ CFixed t = Org.x; Org.x = Org.y; Org.y = t; } PPNT Delta; Delta.x = MulFixed(SlotBounds.Left + Org.x, PAGE_RESOLUTION); Delta.y = MulFixed(SlotBounds.Top + Org.y, PAGE_RESOLUTION); printer_rc.source_pbox.x0 = SourcePbox.x0 - Delta.x; printer_rc.source_pbox.y0 = SourcePbox.y0 - Delta.y; printer_rc.source_pbox.x1 = SourcePbox.x1 - Delta.x; printer_rc.source_pbox.y1 = SourcePbox.y1 - Delta.y; printer_rc.scaled_source_x0 = /*SourceOrigin.x*/ - Delta.x*printer_rc.x_resolution; printer_rc.scaled_source_y0 = /*SourceOrigin.y*/ - Delta.y*printer_rc.y_resolution; /* // Do the draw. */ CPmwView::OnDraw(&pc->m_dcPrint); /* // Update the parameters for the next label to draw. */ if (pDialog->m_fCollate) { if (++pc->m_nCurrentName == pNameList->Names()) { /* Reset the name index. */ pc->m_nCurrentName = (pNameList->Names() == 0) ? -1 : 0; /* Advance to the next copy. */ pc->m_nCurrentCopy++; if (pc->m_nCurrentCopy == pDialog->m_nLabelCopies) { /* All done! */ break; } /* // Finished another set. // If we need to stop here, do so now. */ if (pDialog->m_fPageBreak) { /* Move to the next page. */ break; } } } else { /* We want to do the next copy. */ if (++pc->m_nCurrentCopy == pDialog->m_nLabelCopies) { /* Reset the copy count. */ pc->m_nCurrentCopy = 0; /* Advance to the next name. */ pc->m_nCurrentName++; if (pc->m_nCurrentName == pNameList->Names()) { /* All done! */ break; } /* // Finished another set. // If we need to stop here, do so now. */ if (pDialog->m_fPageBreak) { /* Move to the next page. */ break; } } } nSlot++; } /* // Restore the scaled source x0 from the saved values. */ printer_rc.source_pbox = SourcePbox; printer_rc.scaled_source_x0 = SourceOrigin.x; printer_rc.scaled_source_y0 = SourceOrigin.y; }