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

Go to the SVN repository for this file.

1 #ifndef GUI_UTILS__SVG_RENDERER_HPP
2 #define GUI_UTILS__SVG_RENDERER_HPP
3 
4 /* $Id: svg_renderer.hpp 45024 2020-05-09 02:03: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: Vladislav Evgeniev
30  *
31  * File Description: SVG file rendering
32  *
33  */
34 
35 #include <stack>
36 #include <gui/opengl.h>
37 #include <gui/gui.hpp>
38 
41 #include <gui/print/svg.hpp>
42 
43 
44 /** @addtogroup GUI_PRINT
45  *
46  * @{
47  */
48 
50 
52 {
53 public:
54  virtual bool IsSimplified() const { return m_Simplified; };
55  void SetSimplified(bool simplified = true) { m_Simplified = simplified; };
56 
57  virtual bool IsPrinterFriendly() const { return true; };
58 
59  virtual void SetIsGreyscale(bool b) { m_IsGreyscale = b; };
60 
61  virtual ERenderTarget GetApi() { return eRenderSVG; }
62 
63  virtual void Hint(GLenum, GLenum) {}
64 
65  virtual void Initialize(const TVPRect& viewport);
66  virtual void Finalize();
67 
68  virtual void Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
69 
70  virtual void Ortho(GLdouble left, GLdouble right,
71  GLdouble bottom, GLdouble top,
72  GLdouble nearVal, GLdouble farVal);
73 
74  /// Set OpenGL state needed for writing text (call before DrawText)
75  virtual void BeginText(const CGlTextureFont* font,
76  const CRgbaColor& color);
77  /// Same as above, but get color from m_RenderNode.m_State
78  virtual void BeginText(const CGlTextureFont* font);
79  /// Pops matrices and attributes after writing text
80  virtual void EndText();
81  /// Write text at specified model coords
82  virtual void WriteText(TModelUnit x, TModelUnit y,
83  const char* text,
84  TModelUnit rotate_degrees = 0.0);
85 
86  /// Write text at specified model coords inside box defined by
87  /// (x,y,width,height) with specified alignment, truncation and rotation
88  virtual void WriteText(TModelUnit x, TModelUnit y,
89  TModelUnit width, TModelUnit height,
90  const char* text,
93  TModelUnit rotate_degrees = 0.0f);
94 
95  void Write(CNcbiOstream& ostrm);
96 
97  virtual void BeginClippingRect(GLint x, GLint y, GLsizei width, GLsizei height);
98  virtual void EndClippingRect();
99 
100 protected:
101  virtual void x_RenderBuffer(CGlVboNode *node);
102  void x_PrintLineBuffer(CGlVboNode &node);
103  void x_PrintPointBuffer(CGlVboNode &node);
104  void x_PrintTriBuffer(CGlVboNode &node);
105  void x_PrintQuadBuffer(CGlVboNode &node);
106 
107  void x_ProjectVertex(CVect2<float>& vertex);
108  void x_ProjectVertices(vector<CVect2<float>>& vertices);
109  string x_PolygonStippleToPattern(const GLubyte* stipple, const CRgbaColor& fill_rgba_color);
110  string x_LinearGradient(std::vector<CRgbaColor> const& colors);
111  string x_ClippingRect(GLint x, GLint y, GLsizei width, GLsizei height);
112  void x_GetGradientColors(vector<CVect2<float>> const& vertices, vector<CRgbaColor> const &colors, vector<CRgbaColor>& gradient);
113  void x_GetLineStyle(CGlVboNode &node, GLushort &pattern, GLint &factor, double &width, svg::Stroke::ELineCapStyle &lcap, svg::Stroke::ELineJoinStyle &ljoin);
114 
115 private:
116  bool m_Simplified = false;
117  bool m_IsGreyscale = false;
118  int m_Height;
122  unique_ptr<svg::SVG> m_SVG;
124  std::stack<std::string> m_ClippingStack;
125 };
126 
127 
129 
130 /* @} */
131 
132 #endif // GUI_UTILS__SVG_RENDERER_HPP
CGlVboNode A rendering node that holds a vertex buffer object.
Definition: glvbonode.hpp:64
CObject –.
Definition: ncbiobj.hpp:180
virtual void EndClippingRect()
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 BeginClippingRect(GLint x, GLint y, GLsizei width, GLsizei height)
virtual void EndText()
Pops matrices and attributes after writing text.
virtual void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
virtual void x_RenderBuffer(CGlVboNode *node)
virtual void Ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal)
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static const Colors colors
Definition: cn3d_colors.cpp:50
static int trunc
Definition: array_out.c:8
string
Definition: cgiapp.hpp:687
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
@ eRenderSVG
Definition: glstate.hpp:61
@ eTruncate_Ellipsis
Definition: glfont.hpp:70
map< string, string > m_LinearGradients
virtual ERenderTarget GetApi()
Overridden in subclasses to return the supported rendering target.
virtual void SetIsGreyscale(bool b)
void SetSimplified(bool simplified=true)
std::stack< std::string > m_ClippingStack
virtual void Hint(GLenum, GLenum)
map< string, string > m_ClippingRects
map< string, string > m_PolygonStipplePatterns
virtual bool IsPrinterFriendly() const
virtual bool IsSimplified() const
std::string m_ClippingId
unique_ptr< svg::SVG > m_SVG
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:55
#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
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 Thu May 02 14:33:54 2024 by modify_doxy.py rev. 669887