postscript.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: postscript.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:03:51 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: postscript.cpp,v 1000.1 2004/06/01 21:03:51 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software / database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software / database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Peter Meric
- *
- * File Description:
- * CPostscript - Postscript output
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/print/postscript.hpp>
- #include <gui/utils/rgba_color.hpp>
- #include <gui/print/vector_object.hpp>
- #include "page_buffers.hpp"
- #include "postscript_defs.hpp"
- BEGIN_NCBI_SCOPE
- CPostscript::CPostscript()
- : m_PageCount(0),
- m_PageBuffers(new CPageBuffers())
- {
- }
- CPostscript::~CPostscript()
- {
- }
- void CPostscript::SetOptions(const CPrintOptions& options)
- {
- m_Options = options;
- }
- void CPostscript::PrintBuffer(const CPBuffer* buf)
- {
- m_PageBuffers->Add(buf);
- }
- void CPostscript::BeginDocument()
- {
- PrintStrings(*m_Strm, s_PS_topA);
- *m_Strm << "%%Title: " << m_Options.GetTitle() << endl;
- PrintStrings(*m_Strm, s_PS_topB);
- // print the prolog
- PrintStrings(*m_Strm, s_PS_prologA);
- *m_Strm << "% color command - r g b C" << endl;
- if (m_Options.GetGrayscale()) {
- *m_Strm << "/C { C_GREY } bind def" << endl;
- } else {
- *m_Strm << "/C { C_RGB } bind def" << endl;
- }
- PrintStrings(*m_Strm, s_PS_colors);
- PrintStrings(*m_Strm, s_PS_prologB);
- }
- void CPostscript::EndDocument()
- {
- *m_Strm << "%%Pages: " << m_PageCount << endl;
- PrintStrings(*m_Strm, s_PS_bottom);
- }
- void CPostscript::ShowPage()
- {
- /*
- if (m_PageBuffers->Empty()) {
- return;
- }
- */
- BeginPage();
- ITERATE(CPageBuffers, it, *m_PageBuffers) {
- CVectorPrinter::PrintBuffer(*it);
- }
- EndPage();
- m_PageBuffers->Clear();
- }
- void CPostscript::BeginPage()
- {
- *m_Strm << "%Page: " << ++m_PageCount << endl;
- *m_Strm << "bop" << endl;
- // landscape mode
- CBBox <3> bbox = m_PageBuffers->GetBoundingBox();
- *m_Strm << "% bounding box: " << bbox << endl;
- const pair<float, float> xs = bbox.GetNthRange(0);
- *m_Strm << "/dwidth { " << xs.second - xs.first << " } def" << endl;
- const pair<float, float> ys = bbox.GetNthRange(1);
- *m_Strm << "/dheight { " << ys.second - ys.first << " } def" << endl;
- *m_Strm << "lscape" << endl;
- // print header
- string header(m_Options.GetHeader());
- if (header.length() > 0) {
- *m_Strm << "(" << header << ") pghead" << endl;
- }
- }
- void CPostscript::EndPage()
- {
- if (m_PageCount == 0) {
- return;
- }
- // print footer
- string footer(m_Options.GetFooter());
- if (footer.length() > 0) {
- *m_Strm << "(" << footer << ") pgfoot" << endl;
- }
- *m_Strm << "eop" << endl;
- }
- void CPostscript::PrintObject(const CObject* obj, CPrintState& state)
- {
- CRgbaColor& curr_nonstipple = state.m_NonStipple;
- const CPVecText* txt = dynamic_cast < const CPVecText*>(obj);
- if (txt) {
- // set the text color
- const CRgbaColor& color = txt->GetColor();
- if ( !(color == curr_nonstipple) ) {
- color.PrintTo(*m_Strm, false);
- *m_Strm << " C" << endl;
- curr_nonstipple = color;
- }
- // output the text, font and font size
- *m_Strm << '(' << txt->GetText() << ") /" << txt->GetFont() << " 8 ";
- // output the text position and the showtext command
- const float* p = txt->GetPosition();
- *m_Strm << p[0] << ' ' << p[1] << " showtext" << endl;
- return;
- }
- const CPVecPoint* point = dynamic_cast < const CPVecPoint*>(obj);
- if (point) {
- const CRgbaColor& color = point->GetColor();
- if ( !(color == curr_nonstipple) ) {
- color.PrintTo(*m_Strm, false);
- *m_Strm << " C" << endl;
- curr_nonstipple = color;
- }
- *m_Strm << point << " P" << endl;
- return;
- }
- const CPVecPolygon* poly = dynamic_cast < const CPVecPolygon*>(obj);
- if ( !poly ) {
- return;
- }
- if (poly->IsFlatColored()) {
- const CRgbaColor& color = (*poly->begin())->GetColor();
- if ( !(color == curr_nonstipple) ) {
- color.PrintTo(*m_Strm, false);
- *m_Strm << " C" << endl;
- curr_nonstipple = color;
- }
- ITERATE(CPVecPolygon, it, *poly) {
- const CPVecPoint* p = *it;
- p->PrintTo(*m_Strm, CPVecPoint::eCoordXY); // only print X, Y coordinates
- *m_Strm << " ";
- }
- *m_Strm << " T" << endl;
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: postscript.cpp,v $
- * Revision 1000.1 2004/06/01 21:03:51 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8
- *
- * Revision 1.8 2004/05/21 22:27:50 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.7 2003/08/15 17:02:16 meric
- * Updates include paths for print-related files from gui/utils to gui/print
- *
- * Revision 1.6 2003/06/25 18:02:51 meric
- * Source rearrangement: move "private" headers into the src/ tree
- *
- * Revision 1.5 2003/06/24 21:48:51 meric
- * Modifications to allow for includes to be moved from postscript.hpp
- *
- * Revision 1.4 2003/06/18 17:25:39 meric
- * Final phase of print reorg: remove dependence on gui/opengl and OpenGL
- *
- * Revision 1.3 2003/06/18 16:40:33 meric
- * First phase of print reorg: remove dependence on gui/opengl and OpenGL
- * except for class COpenGLPrintBuffer
- *
- * Revision 1.2 2003/06/16 12:44:52 dicuccio
- * Clean-up after initial commit
- *
- * Revision 1.1 2003 / 06 / 13 18:13:56 meric
- * Initial version
- *
- *
- * ===========================================================================
- */