1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /************************************************************************/
20 /************************************************************************/
22 #include <OpenGl_GraphicDriver.hxx>
23 #include <OSD_Localizer.hxx>
35 /************************************************************************/
37 /************************************************************************/
39 Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName,
40 const Graphic3d_ExportFormat theFormat,
41 const Graphic3d_SortType theSortType,
42 const Standard_Integer theWidth,
43 const Standard_Integer theHeight,
44 const Graphic3d_CView& theView,
45 const Aspect_CLayer2d& theLayerUnder,
46 const Aspect_CLayer2d& theLayerOver,
47 const Standard_Real /*thePrecision*/,
48 const Standard_Address /*theProgressBarFunc*/,
49 const Standard_Address /*theProgressObject*/)
52 Standard_Integer aFormat = -1;
53 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
56 case Graphic3d_EF_PostScript:
59 case Graphic3d_EF_EnhPostScript:
62 case Graphic3d_EF_TEX:
65 case Graphic3d_EF_PDF:
68 case Graphic3d_EF_SVG:
71 case Graphic3d_EF_PGF:
74 case Graphic3d_EF_EMF:
75 //aFormat = GL2PS_EMF;
76 aFormat = GL2PS_PGF + 1; // 6
80 return Standard_False;
85 case Graphic3d_ST_Simple:
86 aSortType = GL2PS_SIMPLE_SORT;
88 case Graphic3d_ST_BSP_Tree:
89 aSortType = GL2PS_BSP_SORT;
96 aViewport[2] = theWidth;
97 aViewport[3] = theHeight;
99 GLint aBufferSize = 1024 * 1024;
100 GLint anErrCode = GL2PS_SUCCESS;
102 // gl2ps uses standard write functions and do not check locale
103 OSD_Localizer locate (LC_NUMERIC, "C");
105 while (aBufferSize > 0)
107 // current patch for EMF support in gl2ps uses WinAPI functions to create file
108 FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
109 anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
110 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
112 0, 0, 0, aBufferSize, aFileH, theFileName);
113 if (anErrCode != GL2PS_SUCCESS)
115 // initialization failed
120 Redraw (theView, theLayerUnder, theLayerOver);
122 anErrCode = gl2psEndPage();
126 if (anErrCode == GL2PS_OVERFLOW)
133 return anErrCode == GL2PS_SUCCESS;
135 return Standard_False;