📄 viewableprintpageslist.cpp
字号:
/* * * viewableprintpageslist.cpp * Copyright (C) 2006 Michael H. Overlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact at poster_printer@yahoo.com */#include "viewableprintpageslist.h"#include "..\lib\gdiutils.h"#include "..\lib\image.h"#include "..\lib\mathutils.h"#include "..\lib\renderpages.h"#define LAYOUT_PAPERDISTANCE_INCHES 3.0#define PAPER_SHADOW_INCHES 0.25 // 0.5#define HANDSEL_PAPER_COLOR RGB(0xff, 0xff, 0x80)#define ARROWSEL_PAPER_COLOR RGB(0x80, 0x80, 0xff)#define HANDARROWSEL_PAPER_COLOR RGB(0x80, 0xff, 0x80)#define DRAFT_MAXIMUM_DIMENSION_PIXELS 300ViewablePrintPagesList::ViewablePrintPagesList(IN HENHMETAFILE hMeta, IN HENHMETAFILE hMetaDraft, IN const RenderSpec& rs, IN const PageSpec &ps, IN const SourceSpec& ss) { // 7/3 m_hMeta = hMeta; m_hMetaDraft = hMetaDraft; m_rs = rs; m_ps = ps; m_ss = ss; m_ls.dPaperDistance_Inches = LAYOUT_PAPERDISTANCE_INCHES; this->CalculateLayout(); m_hbrPaper = (HBRUSH) ::GetStockObject(WHITE_BRUSH); m_hbrHandSel = ::CreateSolidBrush(HANDSEL_PAPER_COLOR); m_hbrArrowSel = ::CreateSolidBrush(ARROWSEL_PAPER_COLOR); m_hbrHandArrowSel = ::CreateSolidBrush(HANDARROWSEL_PAPER_COLOR); m_hbrPaperShadow = (HBRUSH) ::GetStockObject(DKGRAY_BRUSH);}ViewablePrintPagesList::~ViewablePrintPagesList() { ::DeleteObject(m_hbrHandSel); ::DeleteObject(m_hbrArrowSel); ::DeleteObject(m_hbrHandArrowSel); //7/5 ////6/3 //::DeleteEnhMetaFile(m_hMeta); //// 7/3 //if (m_hMetaDraft != NULL) { // ::DeleteEnhMetaFile(m_hMetaDraft); //}}uint ViewablePrintPagesList::GetCount(void) const { return m_uiCount; }void ViewablePrintPagesList::GetBounds(OUT RECTD& rd) const { rd = m_rdBounds_Inches; }void ViewablePrintPagesList::GetItemRuledBounds(IN uint uiItem, OUT RECTD& rd) const { rd = this->m_vil[uiItem].rdPaper_Inches;}void ViewablePrintPagesList::GetItemBounds(IN uint uiItem, OUT RECTD& rd) const { rd = this->m_vil[uiItem].rdBounds_Inches; }// DOING IT THE LAZY WAY, COULD BE MORE EFFICIENTBOOL ViewablePrintPagesList::ItemFromPt(OUT uint& uiItem, IN const POINTD& ptd) const { for(uint ui = 0; ui < m_vil.size(); ++ui) { const ViewablePrintPagesList::ItemLayout il = m_vil[ui]; if (PtInRect(il.rdPaper_Inches, ptd)) { uiItem = ui; return TRUE; } } return FALSE; }// DOING IT THE LAZY WAY, COULD BE MORE EFFICIENTBOOL ViewablePrintPagesList::ItemsFromRect(OUT std::vector<uint>& vuiItem, const RECTD& rd) const { BOOL bRetValue = FALSE; for(uint ui = 0; ui < m_vil.size(); ++ui) { const ViewablePrintPagesList::ItemLayout il = m_vil[ui]; RECTD rdIntersect; if (IntersectRect(rdIntersect, rd, il.rdPaper_Inches)) { vuiItem.push_back(ui); bRetValue = TRUE; } } return bRetValue;}void ViewablePrintPagesList::DrawItem(OUT HDC hdcDest, IN const CoordTrans& trans, IN const RECT& rDest, IN uint uiItem, IN ViewableList::SelectionSpec sel, IN BOOL bDraft) const { ItemLayout il = m_vil[uiItem]; //POINTD ptdTopLeft_Inches = { il.rdBounds_Inches.left, il.rdBounds_Inches.top }; this->DrawSelection(hdcDest, trans, rDest, il, sel); this->DrawPaper(hdcDest, trans, rDest, il, sel); //RECT rPaper; //trans.DoTrans(il.rdPaper_Inches, rPaper); if (!bDraft || m_hMetaDraft != NULL) { RECT rPaperPrintable; trans.DoTrans(il.rdPaperPrintable_Inches, rPaperPrintable); HENHMETAFILE hMetaUse = (bDraft ? m_hMetaDraft : m_hMeta); RenderMosaicPage( hdcDest, rPaperPrintable, il.ptInMosaic, m_rs, m_ps, hMetaUse, m_ss ); } else { RECT rDestRendered; trans.DoTrans(il.rdRenderedImage_Inches, rDestRendered); // DEBUG - FIX -- TEMP DRAFT ::FillSolidColor(hdcDest, rDestRendered, RGB(0xc0, 0xc0, 0xc0)); }}void ViewablePrintPagesList::Draw(OUT HDC hdcDest, IN const CoordTrans& trans, IN const RECT& rDest, const std::vector<ViewableList::SelectionSpec> &vsel, IN BOOL bDraft) const { for(uint uiItem = 0; uiItem < this->GetCount(); ++uiItem) { this->DrawItem(hdcDest, trans, rDest, uiItem, vsel[uiItem], bDraft); }}void ViewablePrintPagesList::Draw(OUT HDC hdcDest, IN const CoordTrans& trans, IN const RECT& rDest, IN BOOL bDraft) const { for(uint uiItem = 0; uiItem < this->GetCount(); ++uiItem) { this->DrawItem(hdcDest, trans, rDest, uiItem, ViewableList::eNormal, bDraft); }}void ViewablePrintPagesList::GetItemSelectableBounds(IN uint uiItem, OUT RECTD& rd) const { //rd = this->m_vil[uiItem].rdPaperPrintable_Inches; rd = this->m_vil[uiItem].rdRenderedImage_Inches;}// ****// **** private:// ****void ViewablePrintPagesList::CalculateLayout(void) { POINTD ptdLogPix; ::CalculatePageLogPix(ptdLogPix, m_ps); m_paper.szd_Inches = m_ps.szdPhysicalPage_Inches; m_paper.dShadow_Inches = PAPER_SHADOW_INCHES; m_uiCount = m_rs.szMosaic.cx * m_rs.szMosaic.cy; SIZED szdPaperAndShadow_Inches = { m_paper.szd_Inches.cx + m_paper.dShadow_Inches, m_paper.szd_Inches.cy + m_paper.dShadow_Inches }; POINTD ptdPrintableOffset_Inches = { m_ps.ptlOffsetPrintable.x / ptdLogPix.x, m_ps.ptlOffsetPrintable.y / ptdLogPix.y }; SIZED szdPrintable_Inches = { m_ps.szlPrintable.cx / ptdLogPix.x, m_ps.szlPrintable.cy / ptdLogPix.y }; SIZED szdItem_Inches = { szdPaperAndShadow_Inches.cx + m_ls.dPaperDistance_Inches, szdPaperAndShadow_Inches.cy + m_ls.dPaperDistance_Inches }; POINTD ptdPaperOffsetIntoItemBounds_Inches = { ( szdItem_Inches.cx - m_paper.szd_Inches.cx ) / 2, ( szdItem_Inches.cy - m_paper.szd_Inches. cy ) / 2 }; const POINTD ptdItemRowBasis = { 0, szdItem_Inches.cy }; const POINTD ptdItemColBasis = { szdItem_Inches.cx, 0 }; POINTD ptdItem = { 0, 0 }; for(uint uiRow = 0; uiRow < (uint) m_rs.szMosaic.cy; ++uiRow) { ptdItem.x = 0; for(uint uiCol = 0; uiCol < (uint) m_rs.szMosaic.cx; ++uiCol) { ItemLayout il; il.ptInMosaic.x = uiCol; il.ptInMosaic.y = uiRow; ::SetRect(il.rdPaper_Inches, ptdItem, m_paper.szd_Inches); ::OffsetRect(il.rdPaper_Inches, ptdPaperOffsetIntoItemBounds_Inches.x, ptdPaperOffsetIntoItemBounds_Inches.y); ::SetRect(il.rdPaperPrintable_Inches, ptdItem, szdPrintable_Inches); ::OffsetRect(il.rdPaperPrintable_Inches, ptdPrintableOffset_Inches.x, ptdPrintableOffset_Inches.y); ::OffsetRect(il.rdPaperPrintable_Inches, ptdPaperOffsetIntoItemBounds_Inches.x, ptdPaperOffsetIntoItemBounds_Inches.y); // 6/1 // 7/2 //POINT ptPage = { uiCol, uiRow }; ::CalculateReneredImageBoundsRelPrintable(il.rdRenderedImage_Inches, il.ptInMosaic, m_rs, m_ps, m_ss); ::OffsetRect(il.rdRenderedImage_Inches, // 7/2 //il.rdPaperPrintable_Inches.left - il.rdRenderedImage_Inches.left, //il.rdPaperPrintable_Inches.top - il.rdRenderedImage_Inches.top il.rdPaperPrintable_Inches.left, il.rdPaperPrintable_Inches.top ); ::SetRect( il.rdShadowBottom_Inches, il.rdPaper_Inches.left + m_paper.dShadow_Inches, il.rdPaper_Inches.bottom, il.rdPaper_Inches.right + m_paper.dShadow_Inches, il.rdPaper_Inches.bottom + m_paper.dShadow_Inches ); ::SetRect( il.rdShadowRight_Inches, il.rdPaper_Inches.right, il.rdPaper_Inches.top + m_paper.dShadow_Inches, il.rdPaper_Inches.right + m_paper.dShadow_Inches, il.rdPaper_Inches.bottom ); ::SetRect(il.rdBounds_Inches, ptdItem, szdItem_Inches); m_vil.push_back(il); ::AddToPoint(ptdItem, ptdItemColBasis); if (uiCol == 0 && uiRow == 0) { m_rdBounds_Inches = il.rdBounds_Inches; } else { ::UnionRect(m_rdBounds_Inches, m_rdBounds_Inches, il.rdBounds_Inches); } } ::AddToPoint(ptdItem, ptdItemRowBasis); }}void ViewablePrintPagesList::DrawPaper(OUT HDC hdcDest, IN const CoordTrans& trans, IN const RECT& rDest, const ItemLayout& il, IN ViewableList::SelectionSpec sel) const { RECT rPaper; trans.DoTrans(il.rdPaper_Inches, rPaper); RECT rShadow1; trans.DoTrans(il.rdShadowBottom_Inches, rShadow1); RECT rShadow2; trans.DoTrans(il.rdShadowRight_Inches, rShadow2); HBRUSH hbrOld = (HBRUSH) ::SelectObject(hdcDest, m_hbrPaper); ::PatBlt(hdcDest, rPaper.left, rPaper.top, RW(rPaper), RH(rPaper), PATCOPY); ::SelectObject(hdcDest, m_hbrPaperShadow); ::PatBlt(hdcDest, rShadow1.left, rShadow1.top, RW(rShadow1), RH(rShadow1), PATCOPY); ::PatBlt(hdcDest, rShadow2.left, rShadow2.top, RW(rShadow2), RH(rShadow2), PATCOPY); ::SelectObject(hdcDest, hbrOld);}void ViewablePrintPagesList::DrawSelection(OUT HDC hdcDest, IN const CoordTrans& trans, IN const RECT& rDest, const ItemLayout& il, IN ViewableList::SelectionSpec sel) const { RECT rBounds; trans.DoTrans(il.rdBounds_Inches, rBounds); HBRUSH hbr = NULL; switch(sel) { case ViewableList::eNormal: hbr = NULL; break; case ViewableList::eHandSel: hbr = m_hbrHandSel; break; case ViewableList::eArrowSel: hbr = m_hbrArrowSel; break; case ViewableList::eHandArrowSel: hbr = m_hbrHandArrowSel; break; default: ASSERTFAIL(); break; } if (hbr != NULL) { HBRUSH hbrOld = (HBRUSH) ::SelectObject(hdcDest, hbr); ::PatBlt(hdcDest, rBounds.left, rBounds.top, RW(rBounds), RH(rBounds), PATCOPY); ::SelectObject(hdcDest, hbrOld); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -