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

Go to the SVN repository for this file.

1 #ifndef GUI_UTILS__PDF_OBJECT_HPP
2 #define GUI_UTILS__PDF_OBJECT_HPP
3 
4 /* $Id: pdf_object.hpp 33070 2015-05-20 19:55:09Z falkrb $
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
30  *
31  * File Description:
32  * CPdfObject - Stream for output of Adobe PDF objects
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <gui/gui.hpp>
39 
40 #include <gui/utils/vect2.hpp>
41 #include <gui/utils/matrix3.hpp>
42 #include <gui/utils/rgba_color.hpp>
44 
45 
47 
48 
49 
51 {
52 public:
53  enum EBitCount { e8Bit = 8, e16Bit = 16, e24Bit = 24, e32Bit = 32 };
54  enum EPdfFilter { eNone, eASCIIHex };
55 
56 public:
59 
60 
61 
62  CPdfObject(unsigned int obj_num,
63  unsigned int generation = 0,
64  bool allowCompression = false);
65 
66  // direct access to write buffer
67  CNcbiOstream& GetWriteBuffer(void);
68 
69  /// gs
70  void PushGraphicsState();
71  void PopGraphicsState();
72  void SetGraphicsState(const string& state);
73  /// RG
74  void SetColor(const CRgbaColor& c);
75  /// rg
76  void SetFillColor(const CRgbaColor& c);
77  void SetLineWidth(float w);
78  void SetLineCapStyle(int cap_style);
79  void SetLineJoinStyle(int join_style);
80  // Set dashes with same paramters used by glLineStipple
81  void SetLineDashStyle(int factor, short pattern);
82  void Line(CVect2<float>& p1, CVect2<float>& p2);
83  void SetClipBox(int x, int y, int width, int height);
84  void Text(CRef<CPdfFontHandler> font_handler,
85  EFontFace face,
86  float font_size,
87  CVect2<float>& p,
88  const char* txt);
89  void Text(CRef<CPdfFontHandler> font_handler,
90  EFontFace face,
91  float font_size,
92  CMatrix3<double>& mat,
93  const char* txt);
94  void StartTris(EPdfFilter filter,
95  EBitCount bits_per_coord,
96  int range_minx,
97  int range_maxx,
98  int range_miny,
99  int range_maxy);
100 
101  void Tri(CVect2<float>& p1, CVect2<float>& p2, CVect2<float>& p3);
102  void Poly(vector<CVect2<float> >& verts);
103 
104  void Tri(int edge_flag,
105  CVect2<float> p1, const CRgbaColor& c1,
106  CVect2<float> p2, const CRgbaColor& c2,
107  CVect2<float> p3, const CRgbaColor& c3);
108  void Tri(int edge_flag,
109  CVect2<float> p1, const CRgbaColor& c1);
110  void EndTris();
111 
112  void Quad(CVect2<float>& p1,
113  CVect2<float>& p2,
114  CVect2<float>& p3,
115  CVect2<float>& p4);
116 
117 
118  //void SetLineWidth();
119  //void SetLineElbow()
120 
121  unsigned int GetObjNum(void) const;
122  unsigned int GetGeneration(void) const;
123  virtual string GetSeparator(void) const;
124 
125  // print the CPdfObject
126  virtual void PrintTo(CNcbiOstream& stream) const;
127 
129 
130  CPdfDictionary& GetDictionary(void);
131  TPdfEltRef& operator[](const string& key);
132 
133 protected:
134  void x_PrintTo(CNcbiOstream& stream);
135 
136  /// Convert floating point values into hexidecimal based on the
137  /// current range and m_BitsPerCood
138  string x_GetHex(double f);
139  string x_GetHex(double f, int bits);
140 
141 
142 private:
143  unsigned int m_ObjNum;
144  unsigned int m_Generation;
148 
149  /// Current State
154  string m_FontName;
155  float m_FontSize;
156 
157  /// Current triangle rendering parameters
160 
165 
166  /// multipliers for vertex values based on ratio of range max value
169 };
170 
171 
172 inline CPdfObject& pdfbrk(CPdfObject& pdfstrm)
173 {
174  pdfstrm.GetWriteBuffer() << pdfstrm.GetSeparator();
175  return pdfstrm;
176 }
177 
178 
179 template <typename T>
180 inline CPdfObject& operator<<(CPdfObject& pdfobj, const T& obj)
181 {
182  pdfobj.GetWriteBuffer() << obj;
183  return pdfobj;
184 }
185 
186 
187 inline CNcbiOstream& operator<<(CNcbiOstream& strm, const CPdfObject& obj)
188 {
189  obj.PrintTo(strm);
190  return strm;
191 }
192 
193 
194 class CPdfTrailer : public CPdfObject
195 {
196 public:
198  virtual ~CPdfTrailer() {}
199  virtual void PrintTo(CNcbiOstream& stream) const;
200 };
201 
202 
203 template <typename T>
204 inline CPdfTrailer& operator<<(CPdfTrailer& pdfobj, const T& obj)
205 {
206  NCBI_THROW(CException, eUnknown, "CPdfObject::operator<< - illegal use of CPdfTrailer");
207 }
208 
209 
210 
212 
213 
214 #endif // GUI_UTILS__PDF_OBJECT_HPP
CObject –.
Definition: ncbiobj.hpp:180
string m_FontName
Definition: pdf_object.hpp:154
float m_FontSize
Definition: pdf_object.hpp:155
CNcbiOstream & GetWriteBuffer(void)
Definition: pdf_object.cpp:587
unsigned int m_ObjNum
Definition: pdf_object.hpp:143
CPdfDictionary m_Dictionary
Definition: pdf_object.hpp:146
CRgbaColor m_DrawColor
Current State.
Definition: pdf_object.hpp:150
virtual string GetSeparator(void) const
Definition: pdf_object.cpp:593
double m_PositionMultX
multipliers for vertex values based on ratio of range max value
Definition: pdf_object.hpp:167
virtual void PrintTo(CNcbiOstream &stream) const
Definition: pdf_object.cpp:490
EBitCount m_BitsPerCoord
Definition: pdf_object.hpp:159
CNcbiOstrstream m_Buffer
Definition: pdf_object.hpp:145
CGlTextureFont::EFontFace EFontFace
Definition: pdf_object.hpp:58
CRef< CPdfElement > TPdfEltRef
Definition: pdf_object.hpp:57
double m_PositionMultY
Definition: pdf_object.hpp:168
bool m_AllowCompression
Definition: pdf_object.hpp:147
bool m_DrawColorSet
Definition: pdf_object.hpp:151
bool m_FillColorSet
Definition: pdf_object.hpp:153
EPdfFilter m_PdfFilter
Current triangle rendering parameters.
Definition: pdf_object.hpp:158
CRgbaColor m_FillColor
Definition: pdf_object.hpp:152
unsigned int m_Generation
Definition: pdf_object.hpp:144
virtual void PrintTo(CNcbiOstream &stream) const
Definition: pdf_object.cpp:598
virtual ~CPdfTrailer()
Definition: pdf_object.hpp:198
CRef –.
Definition: ncbiobj.hpp:618
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
Definition: svg.hpp:432
Definition: svg.hpp:498
#define T(s)
Definition: common.h:230
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
EFontFace
Set of pre-defined fonts for which we know we have valid font files.
@ eUnknown
Definition: app_popup.hpp:72
#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
const struct ncbi::grid::netcache::search::fields::KEY key
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
CPdfObject & operator<<(CPdfObject &pdfobj, const T &obj)
Definition: pdf_object.hpp:180
CPdfObject & pdfbrk(CPdfObject &pdfstrm)
Definition: pdf_object.hpp:172
Modified on Fri Feb 23 11:45:22 2024 by modify_doxy.py rev. 669887