JBoolean CBPTPrinter::EndUserPrintSetup ( const JBroadcaster::Message& message, JBoolean* changed ) { assert( itsCBPrintSetupDialog != NULL ); const JBoolean ok = JXPTPrinter::EndUserPrintSetup(message, changed); if (ok) { *changed = JI2B(*changed || itsCBPrintSetupDialog->ShouldPrintHeader() != itsPrintHeaderFlag); itsPrintHeaderFlag = itsCBPrintSetupDialog->ShouldPrintHeader(); if (GetPageHeight() <= GetHeaderLineCount()) { SetPageHeight(GetHeaderLineCount() + 1); *changed = kJTrue; } } itsCBPrintSetupDialog = NULL; return ok; }
long CSTEditorDoc::GetPrintLinesPerPage (CDC * pDCPrint) { CFont Font; TEXTMETRIC tm; CFont * pOldFont = SelectPrintFont(pDCPrint, &Font); pDCPrint->GetTextMetrics(&tm); pDCPrint->SelectObject(pOldFont); CSize Size(tm.tmAveCharWidth, tm.tmHeight); pDCPrint->LPtoHIMETRIC(&Size); return (Size.cy > 0 ? GetPageHeight() / Size.cy : 0); }
//Get paper type of page wxPaperSize wxPopplerConvPPM::GetPagePaperSize(int page) { if (!isready) return wxPAPER_NONE; if (page < 1) return wxPAPER_NONE; // Convert to wxPaperSize wxSize ps; double scalef = 254.0 / 72.0; // Change size from point to real size (mm) ps.SetWidth((int)(GetPageWidth(page) * scalef)); ps.SetHeight((int)(GetPageHeight(page) * scalef)); // Page format wxPrintPaperDatabase* printPaperDatabase = new wxPrintPaperDatabase; printPaperDatabase->CreateDatabase(); wxPrintPaperType* paperType = printPaperDatabase->FindPaperType(ps); if (paperType == NULL) { return wxPAPER_NONE; } return paperType->GetId(); }
bool PCL5Driver::NextBand(BBitmap* bitmap, BPoint* offset) { DBGMSG(("> nextBand\n")); try { BRect bounds = bitmap->Bounds(); RECT rc; rc.left = (int)bounds.left; rc.top = (int)bounds.top; rc.right = (int)bounds.right; rc.bottom = (int)bounds.bottom; int height = rc.bottom - rc.top + 1; int x = (int)offset->x; int y = (int)offset->y; int pageHeight = GetPageHeight(); if (y + height > pageHeight) height = pageHeight - y; rc.bottom = height - 1; DBGMSG(("height = %d\n", height)); DBGMSG(("x = %d\n", x)); DBGMSG(("y = %d\n", y)); if (get_valid_rect(bitmap, &rc)) { DBGMSG(("validate rect = %d, %d, %d, %d\n", rc.left, rc.top, rc.right, rc.bottom)); x = rc.left; y += rc.top; int width = rc.right - rc.left + 1; int widthByte = (width + 7) / 8; // byte boundary int height = rc.bottom - rc.top + 1; int in_size = widthByte; int out_size = (widthByte * 6 + 4) / 5; int delta = bitmap->BytesPerRow(); DBGMSG(("width = %d\n", width)); DBGMSG(("widthByte = %d\n", widthByte)); DBGMSG(("height = %d\n", height)); DBGMSG(("in_size = %d\n", in_size)); DBGMSG(("out_size = %d\n", out_size)); DBGMSG(("delta = %d\n", delta)); DBGMSG(("renderobj->Get_pixel_depth() = %d\n", fHalftone->GetPixelDepth())); uchar* ptr = static_cast<uchar*>(bitmap->Bits()) + rc.top * delta + (rc.left * fHalftone->GetPixelDepth()) / 8; int compressionMethod; int compressedSize; const uchar* buffer; uchar* in_buffer = new uchar[in_size]; uchar* out_buffer = new uchar[out_size]; auto_ptr<uchar> _in_buffer (in_buffer); auto_ptr<uchar> _out_buffer(out_buffer); DBGMSG(("move\n")); _Move(x, y); _StartRasterGraphics(width, height); const bool color = GetJobData()->GetColor() == JobData::kColor; const int num_planes = color ? 3 : 1; if (color) { fHalftone->SetPlanes(Halftone::kPlaneRGB1); fHalftone->SetBlackValue(Halftone::kLowValueMeansBlack); } for (int i = rc.top; i <= rc.bottom; i++) { for (int plane = 0; plane < num_planes; plane ++) { fHalftone->Dither(in_buffer, ptr, x, y, width); compressedSize = pack_bits(out_buffer, in_buffer, in_size); if (compressedSize + _BytesToEnterCompressionMethod(2) < in_size + _BytesToEnterCompressionMethod(0)) { compressionMethod = 2; // back bits buffer = out_buffer; } else { compressionMethod = 0; // uncompressed buffer = in_buffer; compressedSize = in_size; } _RasterGraphics( compressionMethod, buffer, compressedSize, plane == num_planes - 1); } ptr += delta; y++; } _EndRasterGraphics(); } else DBGMSG(("band bitmap is clean.\n")); if (y >= pageHeight) { offset->x = -1.0; offset->y = -1.0; } else offset->y += height; DBGMSG(("< nextBand\n")); return true; } catch (TransportException& err) { BAlert* alert = new BAlert("", err.What(), "OK"); alert->Go(); return false; } }
HRESULT CSTEditorDoc::GetPages (CStringArray &pages) { TCHAR szTempName[_MAX_PATH]; TCHAR szPath[_MAX_PATH]; long lLinesPerPage; long lLineNum = 0; CDC dcPrint; TEXTMETRIC tm; CFont Font; CFont * pOldFont; long lCharsPerLine = 80; if (FAILED(AttachPrinterDC(&dcPrint))) { return (E_FAIL); } dcPrint.m_bPrinting = TRUE; CRect rect; rect.SetRect( 0, 0, GetPageWidth (), GetPageHeight () ); // printing lLinesPerPage = GetPrintLinesPerPage(&dcPrint); HDC hdcMeta = NULL; CDC dcMeta; for (LINEDESC * pLine = m_Edit.m_pLine; NULL != pLine; pLine = pLine->pNext) { bool bSuccess; CString strText; bSuccess = m_Edit.ExpandLine (pLine, strText); ASSERT (bSuccess); strText.TrimRight (); // if text line is empty make it a line with a single // blank character if (strText.IsEmpty()) { strText = _T(" "); } while (!strText.IsEmpty()) { if (hdcMeta == NULL) { VERIFY(GetTempPath(sizeof(szPath), szPath) != 0); VERIFY(GetTempFileName(szPath, _T("pst"), 0, szTempName) != 0); pages.Add( szTempName ); CString strDesc; CString strAppl; TCHAR* pBuf; strAppl = GetPathName(); // read documentation of CreateEnhMetaFile() to understand the // formatting of this string strDesc.Format("STEditor %s Page %d ", strAppl, pLine->iLineNo); pBuf = strDesc.GetBuffer(0); pBuf[8] = 0; pBuf[strDesc.GetLength() - 1] = 0; strDesc.ReleaseBuffer(); hdcMeta = ::CreateEnhMetaFile( dcPrint, szTempName, &rect, strDesc); if (!hdcMeta) { return (E_FAIL); } dcMeta.Attach(hdcMeta); dcMeta.m_bPrinting = TRUE; dcMeta.SetMapMode (MM_TEXT); pOldFont = SelectPrintFont(&dcMeta, &Font); dcMeta.GetTextMetrics(&tm); CSize tmSize(tm.tmAveCharWidth, tm.tmHeight); dcMeta.LPtoHIMETRIC(&tmSize); lCharsPerLine = GetPageWidth() / tmSize.cx; } dcMeta.TextOut(0, lLineNum * tm.tmHeight, strText.Left(lCharsPerLine)); lLineNum++; if (strText.GetLength() > lCharsPerLine) { strText = strText.Mid(lCharsPerLine); } else { strText = _T(""); } if (lLineNum >= lLinesPerPage) { lLineNum = 0; dcMeta.SelectObject(pOldFont); Font.DeleteObject(); dcMeta.Detach(); DeleteEnhMetaFile (CloseEnhMetaFile(hdcMeta)); hdcMeta = NULL; } } } if (NULL != hdcMeta) { dcMeta.SelectObject(pOldFont); dcMeta.Detach(); DeleteEnhMetaFile (CloseEnhMetaFile(hdcMeta)); hdcMeta = NULL; } return (S_OK); }