NCBI C++ ToolKit
pdf.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_UTILS__PDF_HPP
2 #define GUI_UTILS__PDF_HPP
3 
4 /* $Id: pdf.hpp 45960 2021-01-20 14:07:15Z grichenk $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Peter Meric, Bob Falk
30  *
31  * File Description:
32  * CPdf - Adobe PDF output
33  *
34  */
35 
36 #include <corelib/ncbistd.hpp>
39 #include <gui/print/pdf_object.hpp>
41 #include <gui/opengl/glpane.hpp>
42 #include <gui/opengl/glmodel2d.hpp>
43 
44 #include <gui/utils/vect2.hpp>
45 #include <gui/utils/vect4.hpp>
46 
48 
49 
50 class CPdfDictionary;
51 class CPdfTrailer;
52 class CPageHandler;
53 class CPdfObjectWriter;
54 class CPVecText;
55 class CPVecLine;
56 class CPVecPolygon;
57 class CGlVboNode;
59 
60 
62 {
63 public:
64  enum EContentType { ePdfLines, ePdfTris, ePdfFlatTris, ePdfQuads, ePdfText, ePdfPoints, eMisc };
65 
66 public:
69 
70 
71  CPdf();
72  virtual ~CPdf();
73 
74  virtual void SetOptions(const CPrintOptions& options);
75  virtual void SetOutputStream(CNcbiOstream* ostream);
76 
77  bool GetIsGreyscale() const { return m_IsGreyScale; }
78  void SetIsGreyscale(bool b) { m_IsGreyScale = b; }
79 
80  virtual void BeginDocument(void);
81  virtual void EndDocument(void);
82 
83  void WriteObject(TPdfObjectRef& obj);
84 
85  virtual TPdfObjectRef BeginContent(EContentType t);
86  virtual TPdfObjectRef GetCurrentContent() {return m_CurrentContent;}
87  virtual void EndContent();
88 
89  virtual TPdfObjectRef BeginAnnot();
90  virtual void EndAnnot();
91 
92  virtual TPdfObjectRef BeginReference();
93  virtual void EndReference();
94 
95  CRef<CPdfFontHandler> GetFontHandler() { return m_FontHandler; }
96 
97  CRef<CPdfDictionary> PageDictionary() { return m_PageDictionary; }
98 
99  /// Write a string of text at the specified position (in screen coords). Must
100  /// have a current contect object (via BeginConent)
101  void PrintText(CRef<CPdfFontHandler> font_handler,
102  EFontFace face,
103  float font_size,
104  CVect2<float>& p,
105  const char* txt,
106  const CRgbaColor& c);
107  /// Write a string of text at the specified position and orientation (in
108  /// screen coords). Must have a current contect object (via BeginConent)
109  void PrintText(CRef<CPdfFontHandler> font_handler,
110  EFontFace face,
111  float font_size,
112  CMatrix3<double>& mat,
113  const char* txt,
114  const CRgbaColor& c);
115 
116 
117  /// Print contents of (2D) model
118  void PrintModel(CGlPane& pane, CGlModel2D& model,
119  CRgbaGradColorTable* color_table=NULL);
120 
121  void AddTooltip(CGlPane& pane, const string& txt, CVect4<float>& rect);
122  void AddJSTooltip(CGlPane& pane, const string& txt, const string& title, CVect4<float>& rect);
123 
124  /// Checks the buffer type and prints accodingly tris, points or lines
125  void PrintBuffer(CGlVboNode* node, const TVPRect& viewport,
126  CRgbaGradColorTable* color_table=NULL);
127 
128  /// Prints the points in buffer "node" to the pdf using current graphics
129  /// state, modelview and projection matrices, and viewport
130  void PrintPointBuffer(CGlVboNode* node, const TVPRect& vp,
131  CRgbaGradColorTable* color_table=NULL);
132  /// Prints the lines in buffer "node" to the pdf using current graphics
133  /// state, modelview and projection matrices, and viewport
134  void PrintLineBuffer(CGlVboNode* node, const TVPRect& vp,
135  CRgbaGradColorTable* color_table=NULL);
136  /// Prints AddShadedTris and RenderShaderInstance to save an instance of
137  /// shaded triangles to the pdf
138  void PrintTriBuffer(CGlVboNode* node, const TVPRect& vp,
139  CRgbaGradColorTable* color_table=NULL);
140  /// Quads are only supported as non-shaded (records error if shaded)
141  void PrintQuadBuffer(CGlVboNode* node, const TVPRect& vp,
142  CRgbaGradColorTable* color_table=NULL);
143 
144  /// Add a triangle buffer to the pdf (but do not display it)
145  /// Returns the ID of the triangle shader object in the pdf file
146  /// The first version of the function iterates over data to find the range
147  string AddShadedTris(CGlVboNode* node,
148  const TVPRect& vp,
149  CRgbaGradColorTable* color_table,
151  string AddShadedTris(CGlVboNode* node,
152  const TVPRect& vp,
153  CPdfObject::EBitCount bit_count,
154  CRgbaGradColorTable* color_table,
155  int range_minx, int range_maxx,
156  int range_miny, int range_maxy);
157 
158  /// Display an instance of a set of shaded triangles "shader_id", which
159  /// is returned by AddShadedTris. The location is transformed by
160  /// the current OpenGL modelview and projection matrices and viewport.
161  void RenderShaderInstance(CGlVboNode* node, const string& shader_id, const TVPRect& vp);
162 
163  virtual void BeginPage(void);
164  virtual void EndPage(void);
165 
166 protected:
167  // Return an id for a pdf graphics state that supports the alpha value of
168  // the given node (within a small tolerance) or "" if alpha is 1.0 (alpha is
169  // alpha from glstate color or, if not given, alpha from first vertex)
170  virtual string x_GetAlphaGraphicsState(CGlVboNode* node);
171  virtual string x_GetAlphaGraphicsState(CGlVboNode* node, float alpha);
172  virtual string x_GetAlphaGraphicsState(float alpha);
173 
174  /// For triangles in which vertices are all the same color
175  void x_PrintFlatTriBuffer(CGlVboNode* node, const TVPRect& vp,
176  CRgbaGradColorTable* color_table=NULL);
177 
178  /// Return true if node has color buffer and update array with those colors.
179  /// If false is returned
180  bool x_GetColors(CGlVboNode* node, vector<CRgbaColor>& colors,
181  CRgbaGradColorTable* color_table);
182 
183 private:
184  unique_ptr<CPdfObjectWriter> m_ObjectWriter;
186 
187  // If true, all output is forced to greyscale colors
189 
190  //
191  // document objects
192  //
193  vector<TPdfObjectRef> m_PrintInEndDoc;
194 
199  unique_ptr<CPageHandler> m_PageHandler;
204 
205  /// forbidden
206  CPdf(const CPdf&);
207  CPdf& operator=(const CPdf&);
208 };
209 
210 
211 
213 
214 
215 #endif // GUI_UTILS__PDF_HPP
CGlModel2D Base class for a model set up for rendering purposes.
Definition: glmodel2d.hpp:64
class CGlPane
Definition: glpane.hpp:62
CGlVboNode A rendering node that holds a vertex buffer object.
Definition: glvbonode.hpp:64
Definition: pdf.hpp:62
unique_ptr< CPdfObjectWriter > m_ObjectWriter
Definition: pdf.hpp:184
EContentType
Definition: pdf.hpp:64
@ ePdfTris
Definition: pdf.hpp:64
CRef< CPdfDictionary > PageDictionary()
Definition: pdf.hpp:97
CRef< CPdfTrailer > m_Trailer
Definition: pdf.hpp:200
vector< TPdfObjectRef > m_PrintInEndDoc
Definition: pdf.hpp:193
CRef< CIdGenerator > m_ObjIdGenerator
Definition: pdf.hpp:185
CGlTextureFont::EFontFace EFontFace
Definition: pdf.hpp:68
TPdfObjectRef m_CurrentAnnot
Definition: pdf.hpp:197
CPdf & operator=(const CPdf &)
TPdfObjectRef m_Fonts
Definition: pdf.hpp:201
CRef< CPdfFontHandler > GetFontHandler()
Definition: pdf.hpp:95
CRef< CPdfObject > TPdfObjectRef
Definition: pdf.hpp:67
bool m_IsGreyScale
Definition: pdf.hpp:188
CRef< CPdfDictionary > m_PageDictionary
Definition: pdf.hpp:202
unique_ptr< CPageHandler > m_PageHandler
Definition: pdf.hpp:199
TPdfObjectRef m_CurrentContent
Definition: pdf.hpp:196
bool GetIsGreyscale() const
Definition: pdf.hpp:77
CRef< CPdfFontHandler > m_FontHandler
Definition: pdf.hpp:203
void SetIsGreyscale(bool b)
Definition: pdf.hpp:78
virtual TPdfObjectRef GetCurrentContent()
Definition: pdf.hpp:86
TPdfObjectRef m_CurrentReference
Definition: pdf.hpp:198
CPdf(const CPdf &)
forbidden
TPdfObjectRef m_Catalog
Definition: pdf.hpp:195
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
CRgbaGradColorTable Provides a storage for colors (to eliminate color creation overhead) and Function...
virtual void SetOutputStream(CNcbiOstream *ostream)
virtual void BeginDocument(void)=0
virtual void EndDocument(void)=0
virtual void SetOptions(const CPrintOptions &options)
static const Colors colors
Definition: cn3d_colors.cpp:50
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define NULL
Definition: ncbistd.hpp:225
EFontFace
Set of pre-defined fonts for which we know we have valid font files.
CNcbiOstream & WriteObject(CNcbiOstream &str, TConstObjectPtr ptr, TTypeInfo info)
#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::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_GUIPRINT_EXPORT
Definition: gui_export.h:516
EIPRangeType t
Definition: ncbi_localip.c:101
Modified on Fri Sep 20 14:57:52 2024 by modify_doxy.py rev. 669887