NCBI C++ ToolKit
pdf_grabber.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Bob Falk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
34 #include <gui/opengl/glresmgr.hpp>
36 #include <gui/print/pdf.hpp>
38 
39 #include <util/image/image.hpp>
40 
41 #include <corelib/ncbifile.hpp>
42 
44 
46  : m_Pane(pane)
47  , m_OutputStream(NULL)
48 {
49 }
50 
51 
53 {
54  if (ostr) {
55  m_OutputStream = ostr;
56  }
57 }
58 
61 {
62  if (progress != NULL)
63  progress->SetGLContext();
64 
65  x_BeginCaptures(tex_size);
66 
69 
70  unique_ptr<CNcbiOstream> pstrm;
71  if ( !m_OutputStream ) {
72  string pdfname = CDir::ConcatPath(m_Directory, m_BaseImageName + "." + m_ImageFormat);
73  pstrm.reset(new CNcbiOfstream(pdfname.c_str(), ios::out | ios::binary));
74  m_OutputStream = pstrm.get();
75  }
77 
78 
79  // Set the size of the rendered area (full viewport)
80  CMedia m("",
84 
85  // to have margins we have to pass in a viewport that fits within them
86  // (e.g. 20,20,20,20 = vp(20, 20, width-40, height-40) but for now
87  // we are using the screens viewport size only
92 
94 
96 
97 
98  //***************************************************
99 
100  m_Pdf->BeginDocument();
101  m_Pdf->BeginPage();
102  if (m_TitleHeight>0.0f)
103  m_Pane.AddTitle(true);
104 
106  m_Pdf->EndPage();
107 
108  m_Pdf->EndDocument();
109  x_EndCaptures();
110 
112 
113  return eSuccess;
114 }
115 
116 void CPdfGrabber::x_BeginCaptures(int /*buffer_size*/)
117 {
118  m_ModelViewScaler = 1.0f;
119  m_GuideWidthX = 0;
120  m_GuideWidthY = 0;
121 
122 
123  m_Pdf.Reset(new CPdf());
124 
125  CPrintOptions po;
127  string pdfname = CDir::ConcatPath(m_Directory, m_BaseImageName + "." + m_ImageFormat);
128  po.SetFilename(pdfname.c_str());
129  po.SetMarginBottom(20);
130  po.SetMarginLeft(20);
131  po.SetMarginRight(20);
132  po.SetMarginTop(20);
133  po.SetPagesWide(1);
134  po.SetPagesTall(1);
135 
137  m_Pdf->SetOptions(po);
138 }
139 
141 {
142 }
143 
145 {
147  CGlRenderPdf* rpdf = NULL;
148  if (mgr.IsNull()) {
149  rpdf = new CGlRenderPdf();
150  mgr.Reset(rpdf);
152  rpdf->SetPdf(m_Pdf);
153  } else {
154  rpdf = dynamic_cast<CGlRenderPdf*>(mgr.GetPointerOrNull());
155  _ASSERT(rpdf);
156  rpdf->SetPdf(m_Pdf);
157  rpdf->ResetState();
158  }
160 }
161 
CGlRenderPdf.
Definition: glrenderpdf.hpp:74
CUnit::TPdfUnit GetHeight(void) const
Definition: print_media.cpp:92
CUnit::TPdfUnit GetWidth(void) const
Definition: print_media.cpp:86
CPdfGrabber(IVectorGraphicsRenderer &pane)
Definition: pdf_grabber.cpp:45
void SetOutputStream(CNcbiOstream *ostr)
Definition: pdf_grabber.cpp:52
void x_BeginCaptures(int buffer_size)
Called to setup values before image capturing starts.
IVectorGraphicsRenderer & m_Pane
Pane display canvas for the tree we are saving.
Definition: pdf_grabber.hpp:80
void x_InitRenderer()
Instantiates the PDF renderer.
CNcbiOstream * m_OutputStream
Definition: pdf_grabber.hpp:96
void x_EndCaptures()
Called to restore values (in pane) when capturing stops.
virtual eCaptureResult GrabImages(int tex_size, IImageGrabberProgress *p=NULL)
Grab the requested images.
Definition: pdf_grabber.cpp:60
CVect2< float > m_ModelViewScaler
Ratio scalers for the drawing area that maps to the images.
Definition: pdf_grabber.hpp:94
CRef< CPdf > m_Pdf
Definition: pdf_grabber.hpp:88
Definition: pdf.hpp:62
virtual void BeginPage(void)
Definition: pdf.cpp:204
virtual void EndPage(void)
Definition: pdf.cpp:208
virtual void BeginDocument(void)
Definition: pdf.cpp:88
virtual void SetOptions(const CPrintOptions &options)
Definition: pdf.cpp:74
virtual void SetOutputStream(CNcbiOstream *ostream)
Definition: pdf.cpp:81
virtual void EndDocument(void)
Definition: pdf.cpp:1471
void SetPagesTall(unsigned int w)
void SetFilename(const string &filename)
void SetMedia(const CMedia &media)
void DisableGouraudShading(bool b)
void SetMarginLeft(TPdfUnit h)
void SetOutputFormat(TOutputFormat fmt)
void SetPagesWide(unsigned int w)
void SetPageOrientation(TPageOrientation orient)
void SetMarginTop(TPdfUnit h)
const CMedia & GetMedia(void) const
void SetMarginRight(TPdfUnit w)
void SetMarginBottom(TPdfUnit w)
virtual void ResetState()
@ ePdfUnit
Definition: print_utils.hpp:52
virtual CPrintOptions & GetOptions()
virtual void SetGLContext()
std::string m_BaseImageName
Image name without its appended number (e.g. img for img1, img2...)
TModelUnit m_TitleHeight
Allow space at the top for a title.
std::string m_Directory
Target directory for saved images.
std::string m_ImageFormat
Image output format (e.g. jpeg, png...)
int m_GuideWidthX
If we are making space for printing guides (margins) on the sides, those margins may have different s...
bool m_DisableGouraudShaded
If true, disable gouraud-shaded polys (shadingtype 4)
Interface class for the pdf renderer.
virtual const TVPRect & GetViewportRect() const =0
virtual void RenderVectorGraphics(int vp_width, int vp_height)=0
virtual void UpdateVectorLayout()=0
virtual void AddTitle(bool b)=0
std::ofstream out("events_result.xml")
main entry point for tests
#define NULL
Definition: ncbistd.hpp:225
static string ConcatPath(const string &first, const string &second)
Concatenate two parts of the path for the current OS.
Definition: ncbifile.cpp:776
static CGlResMgr & Instance()
Definition: glresmgr.cpp:59
T Height() const
Definition: glrect.hpp:90
CIRef< IRender > GetRenderer(ERenderTarget target)
Returns first renderer in m_Renderers that renders to 'target'.
Definition: glresmgr.cpp:269
T Width() const
Definition: glrect.hpp:86
void AddRenderer(CIRef< IRender > rm)
Get/Set Renderer.
Definition: glresmgr.cpp:243
void SetCurrentRenderer(CIRef< IRender > rm)
Set current renderer (rm must already be in m_Renderers)
Definition: glresmgr.cpp:281
@ eRenderPDF
Definition: glstate.hpp:61
void SetPdf(CRef< CPdf > &pdf)
m_Pdf does the actually writing to the file
Definition: glrenderpdf.hpp:80
TObjectType * ReleaseOrNull(void)
Release a reference to the object and return a pointer to the object.
Definition: ncbiobj.hpp:816
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
#define _ASSERT
Modified on Thu Apr 25 08:22:10 2024 by modify_doxy.py rev. 669887