📄 renderpages.cpp
字号:
} return dZoomRetValue;}void GetMinimumPageMargins(OUT RECTD& rdMargins_Inches, IN const PageSpec& ps) { POINTD ptdLogPix = { ps.szlPhysicalPage.cx / ps.szdPhysicalPage_Inches.cx, ps.szlPhysicalPage.cy / ps.szdPhysicalPage_Inches.cy }; rdMargins_Inches.left = ps.ptlOffsetPrintable.x / ptdLogPix.x; rdMargins_Inches.top = ps.ptlOffsetPrintable.y / ptdLogPix.y; // 5/30 PARENTHESIS, "- . - . TO - (. + .) FOR CLARITY rdMargins_Inches.right = (ps.szlPhysicalPage.cx - (ps.szlPrintable.cx + ps.ptlOffsetPrintable.x)) / ptdLogPix.x; rdMargins_Inches.bottom = (ps.szlPhysicalPage.cy - (ps.szlPrintable.cy + ps.ptlOffsetPrintable.y)) / ptdLogPix.y;}BOOL IsPageSpecValid(IN const ::PageSpec& ps, IN double dMinPrintable_Inches, IN BOOL bAllowNonStandardMargins) { BOOL bRetValue = FALSE; if (ps.szlPhysicalPage.cx >= ps.ptlOffsetPrintable.x + ps.szlPrintable.cx && ps.szlPhysicalPage.cy >= ps.ptlOffsetPrintable.y + ps.szlPrintable.cy) { double dMarginExtra = ps.ms.dCutGuideMargin_Inches + ps.ms.dOverlapMargin_Inches; POINTD ptdLogPix; ::CalculatePageLogPix(ptdLogPix, ps); SIZED szdPrintable_Inches = { ps.szlPrintable.cx / ptdLogPix.x, ps.szlPrintable.cy / ptdLogPix.y }; BOOL bMinPrintableOK = szdPrintable_Inches.cx - dMarginExtra >= dMinPrintable_Inches && szdPrintable_Inches.cy - dMarginExtra >= dMinPrintable_Inches ; BOOL bEdgeMarginsOK; if (bAllowNonStandardMargins) { bEdgeMarginsOK = TRUE; } else { RECTD rdMinMargins; ::GetMinimumPageMargins(rdMinMargins, ps); bEdgeMarginsOK = ps.ms.rdEdgeMargins_Inches.left >= rdMinMargins.left && ps.ms.rdEdgeMargins_Inches.top >= rdMinMargins.top && ps.ms.rdEdgeMargins_Inches.right >= rdMinMargins.right && ps.ms.rdEdgeMargins_Inches.bottom >= rdMinMargins.bottom; } bRetValue = bMinPrintableOK && bEdgeMarginsOK; } return bRetValue;}void MakeZoomSettingsConsistent(IN OUT ::RenderSpec& rs, IN const ::PageSpec& ps, IN const ::SourceSpec& ss, IN BOOL bAllowRotation, OUT BOOL& bRotated) { bRotated = FALSE; switch(rs.mode) { case RenderSpec::eMosaic: { ::RenderSpec::MosaicFullDimension fulldim; double dMosaicZoom = ::CalculateZoomFromMosaicSize(rs.szMosaic, rs, ps, ss, fulldim); rs.dZoom = dMosaicZoom; } break; case RenderSpec::eZoom: { SIZE szZoomMosaic; if (bAllowRotation) { ::CalculateMosaicSizeFromZoomWithRotation(szZoomMosaic, bRotated, rs.dZoom, rs, ps, ss); } else { ::CalculateMosaicSizeFromZoom(szZoomMosaic, rs.dZoom, rs, ps, ss); } rs.szMosaic = szZoomMosaic; } break; default: ASSERTFAIL(); break; }}void LandscapeRotatePageSpec(OUT PageSpec& psDest, IN const PageSpec& psSrc) { ::PageSpec psTemp = psSrc; psDest = psSrc; ::LandscapeRot::LandscapeRot rotDir = psSrc.bLandscape ? ::LandscapeRotateBack(psSrc.rotDir) : psSrc.rotDir; if (rotDir != ::LandscapeRot::eNone) { psDest.szlPhysicalPage.cx = psTemp.szlPhysicalPage.cy; psDest.szlPhysicalPage.cy = psTemp.szlPhysicalPage.cx; psDest.szlPrintable.cx = psTemp.szlPrintable.cy; psDest.szlPrintable.cy = psTemp.szlPrintable.cx; psDest.szdPhysicalPage_Inches.cx = psTemp.szdPhysicalPage_Inches.cy; psDest.szdPhysicalPage_Inches.cy = psTemp.szdPhysicalPage_Inches.cx; } switch(rotDir) { case ::LandscapeRot::eNone: break; case ::LandscapeRot::e90: psDest.ptlOffsetPrintable.x = psTemp.szlPhysicalPage.cy - psTemp.szlPrintable.cy - psTemp.ptlOffsetPrintable.y; psDest.ptlOffsetPrintable.y = psTemp.ptlOffsetPrintable.x; break; case ::LandscapeRot::e270: psDest.ptlOffsetPrintable.x = psTemp.ptlOffsetPrintable.y; psDest.ptlOffsetPrintable.y = psTemp.szlPhysicalPage.cx - psTemp.szlPrintable.cx - psTemp.ptlOffsetPrintable.x; break; default: ASSERTFAIL(); break; } LandscapeRotate(psDest.ms.rdEdgeMargins_Inches, psTemp.ms.rdEdgeMargins_Inches, rotDir); psDest.bLandscape = ! psTemp.bLandscape;}#if 0void ReflectPageSpec(OUT PageSpec &psDest, IN const PageSpec& psSrc) { ::PageSpec psTemp = psSrc; // IN CASE psSrc AND psDest REFERENCE SAME OBJECT //5/30 OOPS GET NON-ROTATED STUFF TOO, LAZY WAY psDest = psSrc; psDest.szlPhysicalPage.cx = psTemp.szlPhysicalPage.cy; psDest.szlPhysicalPage.cy = psTemp.szlPhysicalPage.cx; psDest.ptlOffsetPrintable.x = psTemp.ptlOffsetPrintable.y; psDest.ptlOffsetPrintable.y = psTemp.ptlOffsetPrintable.x; psDest.szlPrintable.cx = psTemp.szlPrintable.cy; psDest.szlPrintable.cy = psTemp.szlPrintable.cx; psDest.szdPhysicalPage_Inches.cx = psTemp.szdPhysicalPage_Inches.cy; psDest.szdPhysicalPage_Inches.cy = psTemp.szdPhysicalPage_Inches.cx; // 5/30 ADD MARGINS TO PAGESPEC, ROTATE EDGE MARGINS psDest.ms.rdEdgeMargins_Inches.left = psTemp.ms.rdEdgeMargins_Inches.top; psDest.ms.rdEdgeMargins_Inches.top = psTemp.ms.rdEdgeMargins_Inches.left; psDest.ms.rdEdgeMargins_Inches.right = psTemp.ms.rdEdgeMargins_Inches.bottom; psDest.ms.rdEdgeMargins_Inches.bottom = psTemp.ms.rdEdgeMargins_Inches.right; // 6/3 psDest.bReflected = ! psTemp.bReflected;}#endif void DrawCutGuide(OUT HDC hdc, IN const RECTD& in_rdCutGuide_Inches, IN const POINTD& in_ptdLogPix, IN BOOL bVertical, IN const POINT& ptPage, IN double dCutGuide_Inches) { RECTD rdCutGuide_Inches = in_rdCutGuide_Inches; POINTD ptdLogPix = in_ptdLogPix; if (!bVertical) { ::Reflect(rdCutGuide_Inches); ::Reflect(ptdLogPix); } // VERTICAL CASE POINTD ptdLine1_Inches = { rdCutGuide_Inches.right - CUTGUIDE_LINE_SPACE_INCHES, rdCutGuide_Inches.top }; POINTD ptdLine2_Inches = { rdCutGuide_Inches.right - CUTGUIDE_LINE_SPACE_INCHES, rdCutGuide_Inches.bottom }; POINT ptLine1; ::RoundMult(ptLine1, ptdLine1_Inches, ptdLogPix); POINT ptLine2; ::RoundMult(ptLine2, ptdLine2_Inches, ptdLogPix); RECT rCutGuide; ::RoundMult(rCutGuide, rdCutGuide_Inches, ptdLogPix); LOGFONT lf; ::ZeroMemory(&lf, sizeof(lf)); ::StringCbCopy(lf.lfFaceName, sizeof(lf.lfFaceName), TEXT("Times New Roman")); lf.lfHeight = RW(rCutGuide) / 2; lf.lfWeight = FW_ULTRALIGHT; POINT ptText; ::CenterInRect(ptText, rCutGuide); ptText.x += lf.lfHeight / 2; TCHAR atstrBuff[MAX_CUTGUIDE_CCH]; if (!bVertical) { ::Reflect(ptLine1); ::Reflect(ptLine2); ::Reflect(rCutGuide); ::Reflect(ptText); lf.lfEscapement = 0; ::StringCbPrintf(atstrBuff, sizeof(atstrBuff), TEXT("Cut to within %0.2f inches below the dotted line. Mosaic column = %d, row = %d."), dCutGuide_Inches, ptPage.x+1, ptPage.y+1); } else { lf.lfEscapement = 900; ::StringCbPrintf(atstrBuff, sizeof(atstrBuff), TEXT("Cut to within %0.2f inches left of the dotted line. Mosaic column is %d, row is %d."), dCutGuide_Inches, ptPage.x+1, ptPage.y+1); } int nSaveDC = ::SaveDC(hdc); HPEN hPen = ::CreatePen(PS_DOT, 0, RGB(0,0,0)); HFONT hFont = ::CreateFontIndirect(&lf); HPEN hPenOld = (HPEN) ::SelectObject(hdc, hPen); HFONT hFontOld = (HFONT) ::SelectObject(hdc, hFont); COLORREF clrTextOld = ::SetTextColor(hdc, RGB(0,0,0)); COLORREF clrBkOld = ::SetBkColor(hdc, RGB(0xff, 0xff, 0xff)); int iROPOld = ::SetROP2(hdc, R2_COPYPEN); UINT uiOldAlign = ::SetTextAlign(hdc, TA_CENTER | TA_BOTTOM ); POINT ptOld; ::MoveToEx(hdc, ptLine1.x, ptLine1.y, &ptOld); ::LineTo(hdc, ptLine2.x, ptLine2.y); ::MoveToEx(hdc, ptOld.x, ptOld.y, NULL); ::IntersectClipRect(hdc, rCutGuide); TextOut(hdc, ptText.x, ptText.y, atstrBuff, lstrlen(atstrBuff)); //::DrawText(hdc, atstrBuff, lstrlen(atstrBuff), &rCutGuide, DT_CENTER | DT_VCENTER); ::RestoreDC(hdc, nSaveDC); //::SetTextAlign(hdc, uiOldAlign); //::SetROP2(hdc, iROPOld); //::SetTextColor(hdc, clrTextOld); //::SetBkColor(hdc, clrBkOld); //::SelectObject(hdc, hFontOld); //::SelectObject(hdc, hPenOld); ::DeleteObject(hFont); ::DeleteObject(hPen);}#if 0void RenderMosaicPage( OUT HDC hdc, IN const RECT& rlDest, IN const POINT& ptPage, IN const RenderSpec& rs, IN const PageSpec& ps, IN HENHMETAFILE hMeta, IN const SourceSpec &ss ) { int nSaveDC = ::SaveDC(hdc); // IS ALL PHYSICAL PAGE HEIGHT AVAILABLE FOR PRINTING? // THIS TYPICALLY MEANS PAGE IS TRACTOR-FEAD BOOL bAllHeight = (ps.szlPhysicalPage.cy == ps.szlPrintable.cy); // IS ALL PHYSICAL PAGE WIDTH AVAILABLE FOR PRINTING? BOOL bAllWidth = (ps.szlPhysicalPage.cx == ps.szlPrintable.cx); // PIXELS PER INCH "LOGPIXELS" POINTD ptdPageLogPixels = { ps.szlPhysicalPage.cx / ps.szdPhysicalPage_Inches.cx, ps.szlPhysicalPage.cy / ps.szdPhysicalPage_Inches.cy }; // TOTAL SIZE OF MOSAIC OF PAGES SIZED szdPhysicalMosaic_Inches = { ps.szdPhysicalPage_Inches.cx * rs.szMosaic.cx, ps.szdPhysicalPage_Inches.cy * rs.szMosaic.cy }; // OFFSET INTO PHYSICAL PAGE OF PRINTABLE AREA, IN INCHES POINTD ptdOffsetPrintable_Inches = { ps.ptlOffsetPrintable.x / ptdPageLogPixels.x, ps.ptlOffsetPrintable.y / ptdPageLogPixels.y }; // PAGE PRINTABLE SIZE IN INCHES SIZED szdPrintablePage_Inches = { ps.szlPrintable.cx / ptdPageLogPixels.x, ps.szlPrintable.cy / ptdPageLogPixels.y }; // TOTAL PRINTABLE MOSAIC SIZE IN INCHES SIZED szdPrintableMosaic_Inches = { szdPrintablePage_Inches.cx * rs.szMosaic.cx, szdPrintablePage_Inches.cy * rs.szMosaic.cy }; // OFFSET OF IMAGE SELECTION WITHIN TOTAL IMAGE POINTD ptdImageSelectionOffsetIntoTotal_Inches = { ss.rdSelection_Inches.left - ss.rdTotalImage_Inches.left, ss.rdSelection_Inches.top - ss.rdTotalImage_Inches.top }; // TOTAL FREE PRINTABLE MOSAIC SIZE IN INCHES -- SPACE AVAILABLE FOR THE IMAGE ITSELF // APART FROM OVERLAPPING MARGINS, CUTTING GUIDES, AND EDGE MARGINS SIZED szdMargins_Inches; szdMargins_Inches.cy = ps.rdEdgeMargins_Inches.top + ps.rdEdgeMargins_Inches.bottom - (ps.szdPhysicalPage_Inches.cy - szdPrintablePage_Inches.cy); if (!bAllHeight) { szdMargins_Inches.cy += (rs.szMosaic.cy - 1) * (ps.dOverlapMargin_Inches + (rs.bCutGuides ? ps.dCutGuideMargin_Inches : 0)); } szdMargins_Inches.cx = ps.rdEdgeMargins_Inches.left + ps.rdEdgeMargins_Inches.right - (ps.szdPhysicalPage_Inches.cx - szdPrintablePage_Inches.cx); if (!bAllWidth) { szdMargins_Inches.cx += (rs.szMosaic.cx - 1) * (ps.dOverlapMargin_Inches + (rs.bCutGuides ? ps.dCutGuideMargin_Inches : 0)); } SIZED szdFreePrintableMosaic_Inches = { szdPrintableMosaic_Inches.cx - szdMargins_Inches.cx, szdPrintableMosaic_Inches.cy - szdMargins_Inches.cy }; // IMAGE SELECTION SIZE IN INCHES SIZED szdImageSelection_Inches = { RW(ss.rdSelection_Inches), RH(ss.rdSelection_Inches) }; // ZOOMED SELECTED IMAGE TOTAL SIZE IN INCHES double dZoom; if (rs.mode == RenderSpec::eZoom) { //dZoom = rs.wZoom / 100.0; dZoom = rs.dZoom; } else { if (szdImageSelection_Inches.cx * szdFreePrintableMosaic_Inches.cy < szdImageSelection_Inches.cy * szdFreePrintableMosaic_Inches.cx) { dZoom = szdFreePrintableMosaic_Inches.cy / szdImageSelection_Inches.cy; } else { dZoom = szdFreePrintableMosaic_Inches.cx / szdImageSelection_Inches.cx; } } SIZED szdZoomedImageSelection_Inches = { szdImageSelection_Inches.cx * dZoom, szdImageSelection_Inches.cy * dZoom }; SIZED szdTotalImage_Inches = { RW(ss.rdTotalImage_Inches), RH(ss.rdTotalImage_Inches) }; SIZED szdZoomedTotalImage_Inches = { szdTotalImage_Inches.cx * dZoom, szdTotalImage_Inches.cy * dZoom }; // 5/29 ADD A "bCenter" FLAG TO RenderSpec (WAS DEFAULT) POINTD ptdZoomedImageSelectionOffsetIntoFreePrintableMosaic_Inches = { (rs.bCenter ? ( szdFreePrintableMosaic_Inches.cx - szdZoomedImageSelection_Inches.cx ) / 2.0 : 0.0), (rs.bCenter ? ( szdFreePrintableMosaic_Inches.cy - szdZoomedImageSelection_Inches.cy ) / 2.0 : 0.0) }; RECTD rdZoomedImageSelectionIntoFreePrintableMosaic_Inches = { ptdZoomedImageSelectionOffsetIntoFreePrintableMosaic_Inches.x, ptdZoomedImageSelectionOffsetIntoFreePrintableMosaic_Inches.y, ptdZoomedImageSelectionOffsetIntoFreePrintableMosaic_Inches.x + szdZoomedImageSelection_Inches.cx, ptdZoomedImageSelectionOffsetIntoFreePrintableMosaic_Inches.y + szdZoomedImageSelection_Inches.cy }; RECT rlZoomedImageSelectionIntoFreePrintableMosaic; RoundMult(rlZoomedImageSelectionIntoFreePrintableMosaic, rdZoomedImageSelectionIntoFreePrintableMosaic_Inches, ptdPageLogPixels); POINTD ptdZoomedTotalImageOffsetIntoFreePrintableMosaic_Inches = { ptdZoomedImageSelectionOffsetIntoFreePrintableMosaic_Inches.x - ptdImageSelectionOffsetIntoTotal_Inches.x * dZoom, ptdZoomedImageSelectionOffsetIntoFreePrintableMosaic_Inches.y - ptdImageSelectionOffsetIntoTotal_Inches.y * dZoom }; RECTD rdZoomedTotalImageIntoFreePrintableMosaic_Inches = { ptdZoomedTotalImageOffsetIntoFreePrintableMosaic_Inches.x, ptdZoomedTotalImageOffsetIntoFreePrintableMosaic_Inches.y, ptdZoomedTotalImageOffsetIntoFreePrintableMosaic_Inches.x + szdZoomedTotalImage_Inches.cx, ptdZoomedTotalImageOffsetIntoFreePrintableMosaic_Inches.y + szdZoomedTotalImage_Inches.cy }; RECT rlZoomedTotalImageIntoFreePrintableMosaic; RoundMult(rlZoomedTotalImageIntoFreePrintableMosaic, rdZoomedTotalImageIntoFreePrintableMosaic_Inches, ptdPageLogPixels); // START WITH ENTIRE PRINTABLE RECT -- AS USUAL RELATIVE TO UPPER-LEFT CORNER OR PRINTABLE AREA ITSELF // LATER ALL WILL BE TRANSLATED TO ITS LOCATION IN TOTAL PRINTABLE SPACE // WE ONLY NEED TO CLIP OUT THE CUT GUIDES IF ANY, BECAUSE THE MARGINS ARE TAKEN CARE OF BY CLIPPING // THE SELECTED IMAGE AREA RECTD rdCutoutClipThisPage_Inches = { 0, 0, szdPrintablePage_Inches.cx, szdPrintablePage_Inches.cy }; // JUST AT THE TOP AND TO THE LEFT OF PAGES THAT DON'T LIE AT THE // MOSAIC TOP, LEFT BORDERS (THAT'S ALL YOU NEED TO CUT) if (rs.bCutGuides) { if (ptPage.y != 0) { rdCutoutClipThisPage_Inches.top += ps.dCutGuideMargin_Inches; } if (ptPage.x != 0) { rdCutoutClipThisPage_Inches.left += ps.dCutGuideMargin_Inches; } } RECT rlCutoutClipThisPage;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -