示例#1
0
文件: printout.cpp 项目: brho/xword
void
MyPrintout::LayoutColumns()
{
    m_pageRect = GetLogicalPageMarginsRect(*g_pageSetupData);

    // A full column
    m_columnWidth = m_pageRect.width
                  - (m_gridRect.width - GRID_PADDING)
                  - COLUMN_PADDING;


    // Unscale the DC for measuring.
    wxDC * dc = GetDC();
    SaveUserScale();
    // Measure the width of the largest clue number
    const int max_clue_number = std::max(m_puz->m_across.back().Number(),
                                         m_puz->m_down  .back().Number());
    dc->SetFont(m_numberFont);
    if (max_clue_number >= 100)
        dc->GetTextExtent(FormatNumber(999), &m_numberWidth, NULL);
    else
        dc->GetTextExtent(FormatNumber(99),  &m_numberWidth, NULL);
    RestoreUserScale();

    // The portion of the column that is taken up by clue text.
    m_clueWidth = m_columnWidth - (m_numberWidth + NUMBER_PADDING);
}
示例#2
0
/*****
OVERRIDE
Called by the framework to configure the printout. Paginates the set of diagrams
by setting (in RFCanvas::mBlockPages) the number indicating the page that each
block of diagrams gets printed on. Since pagination has to work for both preview
and printed image, compute pagination normalized to the page width -- which
means that we're using the vertical aspect ratio of the page margins rect and of
the blocks of diagram. We only break pages between complete blocks of diagrams.
*****/
void RFPrintout::OnPreparePrinting()
{
  // We do all our drawing in device coordinates so that drawing is done at
  // maximum device resolution on the printed page.
  MapScreenSizeToDevice();
  wxRect pmRect = GetLogicalPageMarginsRect(*gApp->GetPageSetupDialogData());
  double pageAR = double(pmRect.height) / pmRect.width;
  
  // Paginate the blocks of diagrams
  gCanvas->mBlockPages.clear();
  double curAR = 0.0;
  int curPage = 1;
  for (size_t i = 0; i < gCanvas->mImageBlocks.size(); ++i) {
    double blockAR = double(gCanvas->mImageBlocks[i]) / gCanvas->mImageWidth;
    if (curAR + blockAR <= pageAR) {
      curAR += blockAR;
    }
    else {
      curPage++;
      curAR = blockAR;
    }
    gCanvas->mBlockPages.push_back(curPage);
  }
  
}
示例#3
0
文件: printout.cpp 项目: brho/xword
void
MyPrintout::DrawText()
{
    wxDC * dc = GetDC();

    // Scale the DC.
    MapScreenSizeToPageMargins(*g_pageSetupData);

    m_pageRect = GetLogicalPageMarginsRect(*g_pageSetupData);
    int x = m_pageRect.x;
    int y = m_pageRect.y;

    LayoutColumns();

    // Title and author
    dc->SetFont(m_titleFont);
    DrawTextLine(WrapText(m_puz->m_title, m_columnWidth), &x, &y);

    dc->SetFont(m_authorFont);
    DrawTextLine(WrapText(m_puz->m_author, m_columnWidth), &x, &y);

    // Draw clue lists
    const wxString heading_list[2] = { _T("ACROSS"), _T("DOWN") };
    const XPuzzle::ClueList * clue_list[2] = { &m_puz->m_across, &m_puz->m_down };
    for (int i = 0; i < 2; ++i)
    {
        // Add some space above ACROSS and DOWN clues.
        y += CLUE_HEADING_PADDING;

        // Draw the heading
        dc->SetFont(m_headingFont);
        DrawTextLine(WrapText(heading_list[i], m_columnWidth), &x, &y);

        // Draw the clues
        for (XPuzzle::ClueList::const_iterator it = clue_list[i]->begin();
             it != clue_list[i]->end();
             ++it)
        {
            DrawClue(*it, &x, &y);
        }
    }
}
示例#4
0
/*****
Print a single page of the document.
*****/
bool RFPrintout::OnPrintPage(int page)
{
  // Set the DC scale to map the total image width to the page margins rect
  // width and put the origin at the top left of the page margins rect.
  wxRect pmRect = GetLogicalPageMarginsRect(*gApp->GetPageSetupDialogData());
#ifdef __WXGTK__
  /* With wxGTK 2.8.0rc1 (print code @ CVS @ 061118), each page's
     image appears more and more offset towards the top. It's probably
     a wx issue, so this is a temporary fix - CAF
   */
  OffsetLogicalOrigin(pmRect.x, -page * pmRect.y);
#else
  OffsetLogicalOrigin(pmRect.x, pmRect.y);
#endif
  
  gCanvas->mDCScale = double(pmRect.width) / gCanvas->mImageWidth;
  gCanvas->mIsPrinting = true;
  gCanvas->mPrintPage = page;
  gCanvas->DoDraw(*GetDC());
  gCanvas->mIsPrinting = false;
  return true;
}
示例#5
0
bool wxSFPrintout::OnPrintPage(int page)
{
	wxUnusedVar( page );

    wxASSERT_MSG(m_pCanvas, wxT("Shape canvas must be set in the wxSFPrintout class instance."));

    wxDC *dc = GetDC();
    if (dc && m_pCanvas)
    {
        // get grawing size
        wxRect fitRect, totalBB = m_pCanvas->GetTotalBoundingBox();
        wxCoord maxX = totalBB.GetRight();
        wxCoord maxY = totalBB.GetBottom();

        // set printing mode
        switch( m_pCanvas->GetPrintMode() )
        {
            case wxSFShapeCanvas::prnFIT_TO_PAGE:
                FitThisSizeToPage(wxSize(maxX, maxY));
                fitRect = GetLogicalPageRect();
                break;

            case wxSFShapeCanvas::prnFIT_TO_PAPER:
                FitThisSizeToPaper(wxSize(maxX, maxY));
                fitRect = GetLogicalPaperRect();
                break;

            case wxSFShapeCanvas::prnFIT_TO_MARGINS:
                FitThisSizeToPageMargins(wxSize(maxX, maxY), *g_pageSetupData);
                fitRect = GetLogicalPageMarginsRect(*g_pageSetupData);
                break;

            case wxSFShapeCanvas::prnMAP_TO_PAGE:
                MapScreenSizeToPage();
                fitRect = GetLogicalPageRect();
                break;

            case wxSFShapeCanvas::prnMAP_TO_PAPER:
                MapScreenSizeToPaper();
                fitRect = GetLogicalPaperRect();
                break;

            case wxSFShapeCanvas::prnMAP_TO_MARGINS:
                MapScreenSizeToPage();
                fitRect = GetLogicalPageMarginsRect(*g_pageSetupData);
                break;

            case wxSFShapeCanvas::prnMAP_TO_DEVICE:
                MapScreenSizeToDevice();
                fitRect = GetLogicalPageRect();
                break;
        }

        // This offsets the image so that it is centered within the reference
        // rectangle defined above.

        wxCoord xoff = ((fitRect.width - maxX - totalBB.GetLeft()) / 2) - fitRect.x;
        wxCoord yoff = ((fitRect.height - maxY - totalBB.GetTop()) / 2) - fitRect.y;

        switch( m_pCanvas->GetPrintHAlign() )
        {
            case wxSFShapeCanvas::halignLEFT:
                xoff = 0;
                break;

            case wxSFShapeCanvas::halignRIGHT:
                xoff = fitRect.width - totalBB.GetWidth();
                break;

            default:
                break;
        }

        switch( m_pCanvas->GetPrintVAlign() )
        {
            case wxSFShapeCanvas::valignTOP:
                yoff = 0;
                break;

            case wxSFShapeCanvas::valignBOTTOM:
                yoff = fitRect.height - totalBB.GetHeight();
                break;

            default:
                break;
        }

        OffsetLogicalOrigin(xoff, yoff);

        // store current canvas properties
        double prevScale = m_pCanvas->GetScale();
        long prevStyle = m_pCanvas->GetStyle();
        wxColour prevColour = m_pCanvas->GetCanvasColour();

        // disable canvas background drawing if required
        if( !m_pCanvas->ContainsStyle( wxSFShapeCanvas::sfsPRINT_BACKGROUND ) )
        {
            m_pCanvas->RemoveStyle( wxSFShapeCanvas::sfsGRADIENT_BACKGROUND );
            m_pCanvas->RemoveStyle( wxSFShapeCanvas::sfsGRID_SHOW );
            m_pCanvas->SetCanvasColour( *wxWHITE);
        }

        // draw the canvas content without any scale (dc is scaled by the printing framework)
#if wxVERSION_NUMBER < 2900
		double nScale = 1;
		if( wxSFShapeCanvas::IsGCEnabled() ) dc->GetUserScale( &nScale, &nScale );
        m_pCanvas->SetScale(1);

		#ifdef __WXMSW__
		wxSFScaledDC sdc( (wxWindowDC*)dc, nScale );
		sdc.PrepareGC();
        m_pCanvas->DrawContent(sdc, sfNOT_FROM_PAINT);
        #else
		m_pCanvas->DrawContent(*dc, sfNOT_FROM_PAINT);
		#endif

        m_pCanvas->SetScale(prevScale);
#else
		m_pCanvas->SetScale(1);
		m_pCanvas->DrawContent(*dc, sfNOT_FROM_PAINT);
		m_pCanvas->SetScale(prevScale);
#endif

        // restore previous canvas properties if needed
        if( !m_pCanvas->ContainsStyle( wxSFShapeCanvas::sfsPRINT_BACKGROUND ) )
        {
            m_pCanvas->SetStyle( prevStyle );
            m_pCanvas->SetCanvasColour( prevColour );
        }

        return true;
    }
    else
        return false;
}
示例#6
0
void MyPrintout::DrawPageOne()
{
    // You might use THIS code if you were scaling graphics of known size to fit
    // on the page. The commented-out code illustrates different ways of scaling
    // the graphics.

    // We know the graphic is 230x350. If we didn't know this, we'd need to
    // calculate it.
    wxCoord maxX = 230;
    wxCoord maxY = 350;

    // This sets the user scale and origin of the DC so that the image fits
    // within the paper rectangle (but the edges could be cut off by printers
    // that can't print to the edges of the paper -- which is most of them. Use
    // this if your image already has its own margins.
//    FitThisSizeToPaper(wxSize(maxX, maxY));
//    wxRect fitRect = GetLogicalPaperRect();

    // This sets the user scale and origin of the DC so that the image fits
    // within the page rectangle, which is the printable area on Mac and MSW
    // and is the entire page on other platforms.
//    FitThisSizeToPage(wxSize(maxX, maxY));
//    wxRect fitRect = GetLogicalPageRect();

    // This sets the user scale and origin of the DC so that the image fits
    // within the page margins as specified by g_PageSetupData, which you can
    // change (on some platforms, at least) in the Page Setup dialog. Note that
    // on Mac, the native Page Setup dialog doesn't let you change the margins
    // of a wxPageSetupDialogData object, so you'll have to write your own dialog or
    // use the Mac-only wxMacPageMarginsDialog, as we do in this program.
    FitThisSizeToPageMargins(wxSize(maxX, maxY), *g_pageSetupData);
    wxRect fitRect = GetLogicalPageMarginsRect(*g_pageSetupData);

    // This sets the user scale and origin of the DC so that the image appears
    // on the paper at the same size that it appears on screen (i.e., 10-point
    // type on screen is 10-point on the printed page) and is positioned in the
    // top left corner of the page rectangle (just as the screen image appears
    // in the top left corner of the window).
//    MapScreenSizeToPage();
//    wxRect fitRect = GetLogicalPageRect();

    // You could also map the screen image to the entire paper at the same size
    // as it appears on screen.
//    MapScreenSizeToPaper();
//    wxRect fitRect = GetLogicalPaperRect();

    // You might also wish to do you own scaling in order to draw objects at
    // full native device resolution. In this case, you should do the following.
    // Note that you can use the GetLogicalXXXRect() commands to obtain the
    // appropriate rect to scale to.
//    MapScreenSizeToDevice();
//    wxRect fitRect = GetLogicalPageRect();

    // Each of the preceding Fit or Map routines positions the origin so that
    // the drawn image is positioned at the top left corner of the reference
    // rectangle. You can easily center or right- or bottom-justify the image as
    // follows.

    // This offsets the image so that it is centered within the reference
    // rectangle defined above.
    wxCoord xoff = (fitRect.width - maxX) / 2;
    wxCoord yoff = (fitRect.height - maxY) / 2;
    OffsetLogicalOrigin(xoff, yoff);

    // This offsets the image so that it is positioned at the bottom right of
    // the reference rectangle defined above.
//    wxCoord xoff = (fitRect.width - maxX);
//    wxCoord yoff = (fitRect.height - maxY);
//    OffsetLogicalOrigin(xoff, yoff);

    wxGetApp().Draw(*GetDC());
}
示例#7
0
文件: printout.cpp 项目: brho/xword
void
MyPrintout::LayoutGrid(double gridScale)
{
    // Calculate the grid rectangle and prepare m_drawer for drawing the grid.
    // After calling this function, m_gridRect will contain the bounding
    // rectangle for the grid.

    // We'll draw the grid without scaling the DC, because our scaling is bound
    // to look *much* better than if we used wxDC::SetUserScale, which would
    // distort the grid.
    // The grid will rarely take exactly the space we give it, since
    // XGridDrawer ensures that all squares are the same size.

    wxDC * dc = GetDC();
    dc->SetUserScale(1, 1);
    dc->SetDeviceOrigin(0, 0);
    const wxRect pageRect = GetLogicalPageMarginsRect(*g_pageSetupData);

    // Calculate the grid width and height
    //------------------------------------

    // The most space we will allow the grid to take up
    const double maxGridWidth  = pageRect.width  * (gridScale - GRID_PADDING);
    const double maxGridHeight = pageRect.height * (gridScale - GRID_PADDING);

    // Calculate the size of each square
    const int borderSize = m_drawer.GetBorderSize();
    const int gridWidth  = m_puz->m_grid.GetWidth();
    const int gridHeight = m_puz->m_grid.GetHeight();

    // The largest a square can be is the total allowed space less the borders
    // divided by the number of squares in a row / col.
    const double boxWidth =
        (maxGridWidth  - borderSize * (gridWidth + 1)) / gridWidth;

    const double boxHeight =
        (maxGridHeight - borderSize * (gridHeight + 1)) / gridHeight;

    const double boxSize = std::min(boxWidth, boxHeight);

    // Calculate the grid size based on the size of a square.
    // This is the boxSize times the number of squares in the row / col plus
    // borders.
    m_gridRect.width  = (boxSize + borderSize) * gridWidth  + borderSize;
    m_gridRect.height = (boxSize + borderSize) * gridHeight + borderSize;

    // Setup the grid drawer with our calculated size
    m_drawer.SetMaxSize(m_gridRect.width, m_gridRect.height);
    m_drawer.SetAlign(m_gridAlign);

    // Add padding to the bounding rect
    const int padding = std::min(pageRect.width, pageRect.height) * GRID_PADDING;
    m_gridRect.width  += padding;
    m_gridRect.height += padding;

    // Align the grid
    //---------------
    m_gridRect.x = pageRect.x;
    m_gridRect.y = pageRect.y;

    if ((m_gridAlign & wxALIGN_RIGHT) != 0)
        m_gridRect.x += pageRect.width - m_gridRect.width;
    if ((m_gridAlign & wxALIGN_BOTTOM) != 0)
        m_gridRect.y += pageRect.height - m_gridRect.height;

    // Scale the DC.
    MapScreenSizeToPageMargins(*g_pageSetupData);

    // Adapt the grid rect to the user scale.
    m_gridRect.x      = dc->DeviceToLogicalX(m_gridRect.x);
    m_gridRect.y      = dc->DeviceToLogicalY(m_gridRect.y);
    m_gridRect.width  = dc->DeviceToLogicalXRel(m_gridRect.width);
    m_gridRect.height = dc->DeviceToLogicalYRel(m_gridRect.height);
}