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

Go to the SVN repository for this file.

1 #ifndef GUI_PRINT___GL_RENDER_MANAGER_PDF__HPP
2 #define GUI_PRINT___GL_RENDER_MANAGER_PDF__HPP
3 
4 /* $Id: glrenderpdf.hpp 43853 2019-09-10 17:42:16Z evgeniev $
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: Bob Falk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <gui/opengl.h>
36 #include <gui/gui.hpp>
37 
39 
40 #include <gui/print/pdf.hpp>
41 
42 /** @addtogroup GUI_PRINT
43  *
44  * @{
45  */
46 
48 
49 
50 //////////////////////////////////////////////////////////////////////////////
51 /// CGlRenderPdf
52 ///
53 /// Connect the CGlRender interface to the CPdf object for file output.
54 /// PDF has some differences from OpenGL on how it handles polygons. (Aside
55 /// from the fact that it only handles 2D drawing). In particular, there are
56 /// two distinct kinds of polygons for PDF files, Gouraud shaded triangles, and
57 /// flat (uniformally) shaded n-sided polygons.
58 ///
59 /// The flat polygons also cannot be tiled. If two adjacent 'flat' polygons
60 /// share vertices, like two triangles that form a quad, there will generally
61 /// remain a visible crack between them. This class uses these definitions, along
62 /// with state options set by the user, to determine what kind of geometry to
63 /// generate.
64 ///
65 /// Currently there are some cases, particularly more complex polygons
66 /// created by tiling together triangles as you would normally do in OpenGL that
67 /// could be formed into an n-sided pdf polygon but are instead saved in the PDF
68 /// file as a set of gouraud shaded triangles. We could, in the future, do the
69 /// geomtric processing to find all the unshared edges and use those to try and
70 /// create the polygons outer edge.
71 ///
72 ///
74 {
75 public:
77  virtual ~CGlRenderPdf() {}
78 
79  /// m_Pdf does the actually writing to the file
80  void SetPdf(CRef<CPdf>& pdf) { m_Pdf = pdf;}
81  CRef<CPdf> GetPdf() { return m_Pdf; }
82 
83  virtual bool IsSimplified() const;
84 
85  virtual bool IsPrinterFriendly() const { return true; };
86 
87  virtual void SetIsGreyscale(bool b);
88 
89  virtual ERenderTarget GetApi() { return eRenderPDF; }
90 
91  virtual void Hint(GLenum, GLenum) {}
92 
93  /// Specialized for models - which are just collections of buffers
94  virtual void Render(CGlPane& pane, CGlModel2D* model);
95  /// Add a vertex and decompose quads into tris if needed
96  virtual void Vertex3f(GLfloat x, GLfloat y, GLfloat z);
97 
98  /// Set OpenGL state needed for writing text (call before DrawText)
99  virtual void BeginText(const CGlTextureFont* font,
100  const CRgbaColor& color);
101  /// Same as above, but get color from m_RenderNode.m_State
102  virtual void BeginText(const CGlTextureFont* font);
103  /// Pops matrices and attributes after writing text
104  virtual void EndText();
105  /// Write text at specified model coords
106  virtual void WriteText(TModelUnit x, TModelUnit y,
107  const char* text,
108  TModelUnit rotate_degrees = 0.0);
109 
110  /// Write text at specified model coords inside box defined by
111  /// (x,y,width,height) with specified alignment, truncation and rotation
112  virtual void WriteText(TModelUnit x, TModelUnit y,
113  TModelUnit width, TModelUnit height,
114  const char* text,
117  TModelUnit rotate_degrees = 0.0f);
118 
119  virtual void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
120 
121  /// PDF only - get size of pdf 'window' (pagesize)
122  void GetScreenSize(int& width, int& height) const;
123 
124 protected:
125  /// Send the current buffer to the pdf library for rendering.
126  virtual void x_RenderBuffer(CGlVboNode* node);
127 
129 };
130 
131 
133 
134 /* @} */
135 
136 #endif // GUI_PRINT___GL_RENDER_MANAGER_PDF__HPP
CGlModel2D Base class for a model set up for rendering purposes.
Definition: glmodel2d.hpp:64
class CGlPane
Definition: glpane.hpp:62
CGlRenderPdf.
Definition: glrenderpdf.hpp:74
CGlVboNode A rendering node that holds a vertex buffer object.
Definition: glvbonode.hpp:64
CObject –.
Definition: ncbiobj.hpp:180
virtual void BeginText(const CGlTextureFont *font, const CRgbaColor &color)
Text is drawn is pixel coordinates.
virtual void WriteText(TModelUnit x, TModelUnit y, const char *text, TModelUnit rotate_degrees=0.0)
Write text at specified model coords.
virtual void SetIsGreyscale(bool)
virtual void Render(CGlPane &pane, CGlModel2D *model)
virtual bool IsSimplified() const
virtual void EndText()
Pops matrices and attributes after writing text.
virtual void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
virtual void Vertex3f(GLfloat x, GLfloat y, GLfloat z)
Explicit support not currently available for: GLbyte, GlShort and GLint calls, e.g.
virtual void x_RenderBuffer(CGlVboNode *node)
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static int trunc
Definition: array_out.c:8
GLdouble TModelUnit
Definition: gltypes.hpp:48
ERenderTarget
Different api levels based on information from OpenGL driver.
Definition: glstate.hpp:61
ETruncate
Definition: glfont.hpp:62
int TAlign
Definition: glfont.hpp:113
@ eAlign_Center
Definition: glfont.hpp:111
@ eRenderPDF
Definition: glstate.hpp:61
@ eTruncate_Ellipsis
Definition: glfont.hpp:70
CRef< CPdf > m_Pdf
virtual void Hint(GLenum, GLenum)
Definition: glrenderpdf.hpp:91
CRef< CPdf > GetPdf()
Definition: glrenderpdf.hpp:81
virtual ERenderTarget GetApi()
Overridden in subclasses to return the supported rendering target.
Definition: glrenderpdf.hpp:89
virtual bool IsPrinterFriendly() const
Definition: glrenderpdf.hpp:85
void SetPdf(CRef< CPdf > &pdf)
m_Pdf does the actually writing to the file
Definition: glrenderpdf.hpp:80
virtual ~CGlRenderPdf()
Definition: glrenderpdf.hpp:77
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIPRINT_EXPORT
Definition: gui_export.h:516
n background color
static void text(MDB_val *v)
Definition: mdb_dump.c:62
Standard mechanism to include OpenGL headers for all platforms.
Modified on Tue May 21 10:56:07 2024 by modify_doxy.py rev. 669887