Merge branch 'gh/maint-clean' into ht/-include
[shapes.git] / source / globals.cc
blob85312af69131f024525e875ca009a9d93a0d0354
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008, 2010 Henrik Tidefelt
19 #include "globals.h"
21 #include "shapesscanner.h"
22 #include "shapestypes.h"
23 #include "ast.h"
24 #include "astfun.h"
25 #include "refcount.h"
26 #include "texlabelmanager.h"
27 #include "statetypes.h"
28 #include "pdfstructure.h"
29 #include "functiontypes.h"
30 #include "containertypes.h"
31 #include "shapescore.h"
32 #include "consts.h"
33 #include "basicsimplex.h"
34 #include "debuglog.h"
35 #include "shapesexceptions.h"
37 #include <climits>
39 using namespace std;
40 using namespace Shapes;
42 ShapesScanner Ast::theShapesScanner;
43 Kernel::PassedEnv Kernel::theGlobalEnvironment = 0;
44 std::list< Kernel::Environment * > Kernel::theEnvironmentList;
45 SimplePDF::PDF_Version Kernel::the_PDF_version;
46 bool Kernel::allowTransparency = true;
47 bool Kernel::allowSingletonPaths = true;
48 size_t Kernel::theIndirectObjectCount = 1; /* Never use 0! */
49 SimplePDF::DocumentInfo Kernel::theDocInfo;
50 Kernel::Import Kernel::thePDFImporter;
51 Kernel::DebugLog Kernel::theDebugLog;
52 Kernel::TeXLabelManager Kernel::theTeXLabelManager;
53 RefCountPtr< const Kernel::GraphicsState > Kernel::THE_NO_STATE = NullPtr< const Kernel::GraphicsState >( );
54 RefCountPtr< const Lang::Function > Kernel::THE_NO_FUNCTION = NullPtr< const Lang::Function >( );
56 Concrete::Length Computation::the_arcdelta( 0.1 ); /* that is, 0.1bp */
57 double Computation::the_dtMin = 1e-4;
58 bool Computation::dtMinIsError = true;
59 Concrete::Length Computation::theDistanceTol( 1e-3 );
60 Concrete::Length Computation::theTrixelizeSplicingTol( 1e-5 );
61 Concrete::Length Computation::theTrixelizeOverlapTol( 1e-3 );
62 RefCountPtr< const Computation::PaintedPolygon3D > Computation::THE_NULL_POLYGON3D( new Computation::NullPolygon3D( ) );
63 bool Computation::fontMetricGuessIsError = false;
64 Computation::BasicSimplex Computation::theTwoTriangleSimplex( 3, 6 ); // 3 variables ( x, y, r ), 6 equations.
66 Ast::Expression * Ast::theProgram;
67 std::list< Ast::Node * > * Ast::theInteractiveInput;
68 PtrOwner_back_Access< std::list< Ast::AnalysisEnvironment * > > Ast::theAnalysisEnvironmentList;
69 Ast::AnalysisEnvironment * Ast::theGlobalAnalysisEnvironment;
70 const Ast::FileID * Ast::SourceLocation::UNKNOWN_FILE = Ast::FileID::build_internal( "*uninitialized*" );
71 Ast::SourceLocation Ast::THE_UNKNOWN_LOCATION( Ast::SourceLocation::UNKNOWN_FILE ); // This is a special value. See SourceLocation.
72 Ast::DummyExpression Ast::THE_CORE_DEFAULT_VALUE_EXPRESSION = Ast::DummyExpression( Ast::SourceLocation( Ast::FileID::build_internal( "< core function default value >" ) ) );
73 Ast::DummyExpression Ast::THE_INTERNAL_VALUE_EXPRESSION = Ast::DummyExpression( Ast::SourceLocation( Ast::FileID::build_internal( "< internally passed value >" ) ) );
75 PtrOwner_back_Access< std::list< Exceptions::Exception * > > Kernel::thePostCheckErrorsList;
76 PtrOwner_back_Access< std::list< Exceptions::Exception * > > Ast::theAnalysisErrorsList;
78 #ifdef HAVE_FT2
79 FT_Library Kernel::theFreeType;
80 const char *
81 Kernel::FreeTypeErrorMessage( FT_Error code )
83 #undef __FTERRORS_H__
84 #define FT_ERRORDEF( e, v, s ) case e: return s;
85 #define FT_ERROR_START_LIST {
86 #define FT_ERROR_END_LIST default: return "(Bad FreeType error code.)"; }
87 switch( code )
88 #include FT_ERRORS_H
91 #endif
94 bool Interaction::debugBacktrace = true;
95 bool Interaction::debugSystem = false;
96 size_t Interaction::debugStep = INT_MAX;
97 const char * Interaction::displayUnitName = "cm";
98 Concrete::Length Interaction::displayUnit( 72 / 2.54 );
99 double Interaction::displayUnitFactor = -1;
100 bool Interaction::fontMetricMessages = false;
101 bool Interaction::fontMetricDebug = false;
102 bool Interaction::characterColumnInBytes = false;
103 bool Interaction::pdfLaTeXInteractionTo_stderr = false;
104 bool Interaction::logGlobals = false;
105 Interaction::WarningAction Interaction::warningAction = Interaction::WARNING_DISPLAY;
107 RefCountPtr< const Lang::GroupNull2D > Lang::THE_NULL2D( new Lang::GroupNull2D( ) );
108 RefCountPtr< const Lang::GroupNull3D > Lang::THE_NULL3D( new Lang::GroupNull3D( ) );
109 RefCountPtr< const Lang::DynamicBindings > Lang::THE_NULL_DYNAMIC_BINDINGS( new Lang::DynamicBindingsNull( ) );
110 RefCountPtr< const Lang::LightGroup > Lang::THE_NULL_LIGHTS( new Lang::LightNull( ) );
111 RefCountPtr< const Lang::SingleListNull > Lang::THE_CONS_NULL( new Lang::SingleListNull( ) );
112 RefCountPtr< const Lang::SpecularReflectionNull > Lang::THE_SPECULARREFLECTION_NULL( new Lang::SpecularReflectionNull( ) );
113 //RefCountPtr< const Lang::PaintedPolygon2D > Computation::THE_NULL_POLYGON2D( new Computation::NullPolygon2D( ) );
114 RefCountPtr< const Lang::ColorSpace > Lang::THE_INHERITED_COLOR_SPACE( new Lang::InheritedColorSpace( ) );
115 RefCountPtr< const Lang::ColorSpace > Lang::THE_COLOR_SPACE_DEVICE_GRAY( new Lang::DeviceColorSpace< Lang::Gray >( "DeviceGray", 1 ) );
116 RefCountPtr< const Lang::ColorSpace > Lang::THE_COLOR_SPACE_DEVICE_RGB( new Lang::DeviceColorSpace< Lang::RGB >( "DeviceRGB", 3 ) );
117 RefCountPtr< const Lang::ColorSpace > Lang::THE_COLOR_SPACE_DEVICE_CMYK( new Lang::DeviceColorSpace< Lang::CMYK >( "DeviceCMYK", 4 ) );
118 RefCountPtr< const Lang::Drawable2D > Lang::THE_POINTPICTURE = NullPtr< const Lang::Drawable2D >( );
119 RefCountPtr< const Lang::Void > Lang::THE_VOID( new Lang::Void( ) );
120 RefCountPtr< const Lang::ElementaryPath2D > Lang::THE_EMPTYPATH2D( new Lang::ElementaryPath2D( ) );
121 RefCountPtr< const Lang::ElementaryPath3D > Lang::THE_EMPTYPATH3D( new Lang::ElementaryPath3D( ) );
122 RefCountPtr< const Lang::Boolean > Lang::THE_FALSE( new Lang::Boolean( false ) );
123 RefCountPtr< const Lang::Boolean > Lang::THE_TRUE( new Lang::Boolean( true ) );
124 RefCountPtr< const Lang::Gray > Lang::THE_BLACK( new Lang::Gray( Concrete::Gray( 0 ) ) );
125 RefCountPtr< const Lang::Gray > Lang::THE_OCCLUDING_WHITE( new Lang::Gray( Concrete::Gray( 1 ) ) );
126 RefCountPtr< const Lang::Alpha > Lang::THE_OPAQUE( new Lang::Alpha( false, 1 ) );
127 RefCountPtr< const Lang::Class > Lang::THE_OBJECT( new Lang::Object( ) );
128 RefCountPtr< const Lang::Dash > Lang::THE_SOLID_DASH( new Lang::Dash( ) );
129 RefCountPtr< const Lang::SoftMask > Lang::THE_NONE_MASK( new Lang::SoftMask( ) );
130 RefCountPtr< const Lang::SoftMask > Lang::THE_SAME_MASK( new Lang::SoftMask( ) );
132 RefCountPtr< const char > BuiltInFonts::HELVETICA = strrefdup( "Helvetica" );
133 RefCountPtr< const Lang::Font > Lang::THE_FONT_HELVETICA( new Lang::PDFStandardFont( BuiltInFonts::HELVETICA ) );
135 Kernel::Arguments Kernel::EMPTY_ARGLIST( new Kernel::EvaluatedFormals( Ast::FileID::build_internal( "< the empty arg list >" ) ) );
136 RefCountPtr< const Lang::Structure > Lang::THE_EMPTY_STRUCT( new Lang::Structure( new Ast::ArgListExprs( true ), Lang::THE_CONS_NULL, true ) );
137 Kernel::VariableHandle Kernel::THE_SLOT_VARIABLE( new Kernel::Variable( RefCountPtr< const Lang::Value >( new Lang::Void ) ) );
138 Kernel::VariableHandle Kernel::THE_VOID_VARIABLE( new Kernel::Variable( RefCountPtr< const Lang::Value >( new Lang::Void ) ) );
139 Kernel::VariableHandle Kernel::THE_FALSE_VARIABLE( new Kernel::Variable( Lang::THE_FALSE ) );
140 Kernel::VariableHandle Kernel::THE_TRUE_VARIABLE( new Kernel::Variable( Lang::THE_TRUE ) );
141 Kernel::StateHandle Kernel::THE_SLOT_STATE = Kernel::StateHandle( NullPtr< Kernel::State >( ) );
144 * Two global Symbol objects were moved to elementarytypes.cc to ensure they get initialized after the static variables in Lang::Symbol.
146 Lang::Transform2D Lang::THE_2D_IDENTITY( 1, 0,
147 0, 1,
148 Concrete::ZERO_LENGTH, Concrete::ZERO_LENGTH );
149 Lang::Transform3D Lang::THE_3D_IDENTITY( 1, 0, 0,
150 0, 1, 0,
151 0, 0, 1,
152 Concrete::ZERO_LENGTH, Concrete::ZERO_LENGTH, Concrete::ZERO_LENGTH );
155 * Be sure to initiate this after globals that it relies on!
157 RefCountPtr< const Kernel::GraphicsState > Kernel::THE_DEFAULT_STATE( new Kernel::GraphicsState( true ) );
160 void
161 Shapes::Kernel::registerGlobals( Kernel::Environment * env )
163 env->initDefine( "CAP_BUTT", RefCountPtr< const Lang::CapStyle >( new Lang::CapStyle( Lang::CapStyle::CAP_BUTT ) ) );
164 env->initDefine( "CAP_ROUND", RefCountPtr< const Lang::CapStyle >( new Lang::CapStyle( Lang::CapStyle::CAP_ROUND ) ) );
165 env->initDefine( "CAP_SQUARE", RefCountPtr< const Lang::CapStyle >( new Lang::CapStyle( Lang::CapStyle::CAP_SQUARE ) ) );
166 env->initDefine( "JOIN_MITER", RefCountPtr< const Lang::JoinStyle >( new Lang::JoinStyle( Lang::JoinStyle::JOIN_MITER ) ) );
167 env->initDefine( "JOIN_ROUND", RefCountPtr< const Lang::JoinStyle >( new Lang::JoinStyle( Lang::JoinStyle::JOIN_ROUND ) ) );
168 env->initDefine( "JOIN_BEVEL", RefCountPtr< const Lang::JoinStyle >( new Lang::JoinStyle( Lang::JoinStyle::JOIN_BEVEL ) ) );
169 env->initDefine( "GRAY_BLACK", Lang::THE_BLACK );
170 env->initDefine( "OCCLUDING", Lang::THE_OCCLUDING_WHITE );
171 env->initDefine( "GRAY_WHITE", RefCountPtr< const Lang::Gray >( new Lang::Gray( Concrete::Gray( 1 ) ) ) );
172 env->initDefine( "RGB_BLACK", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 0, 0, 0 ) ) ) );
173 env->initDefine( "RGB_WHITE", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 1, 1, 1 ) ) ) );
174 env->initDefine( "RGB_RED", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 1, 0, 0 ) ) ) );
175 env->initDefine( "RGB_GREEN", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 0, 1, 0 ) ) ) );
176 env->initDefine( "RGB_BLUE", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 0, 0, 1 ) ) ) );
177 env->initDefine( "RGB_YELLOW", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 1, 1, 0 ) ) ) );
178 env->initDefine( "RGB_CYAN", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 0, 1, 1 ) ) ) );
179 env->initDefine( "RGB_MAGENTA", RefCountPtr< const Lang::RGB >( new Lang::RGB( Concrete::RGB( 1, 0, 1 ) ) ) );
180 env->initDefine( "BLEND_NORMAL", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::NORMAL ) ) );
181 env->initDefine( "BLEND_MULTIPLY", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::MULTIPLY ) ) );
182 env->initDefine( "BLEND_SCREEN", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::SCREEN ) ) );
183 env->initDefine( "BLEND_OVERLAY", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::OVERLAY ) ) );
184 env->initDefine( "BLEND_DARKEN", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::DARKEN ) ) );
185 env->initDefine( "BLEND_LIGHTEN", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::LIGHTEN ) ) );
186 env->initDefine( "BLEND_COLOR_DODGE", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::COLOR_DODGE ) ) );
187 env->initDefine( "BLEND_COLOR_BURN", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::COLOR_BURN ) ) );
188 env->initDefine( "BLEND_HARD_LIGHT", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::HARD_LIGHT ) ) );
189 env->initDefine( "BLEND_SOFT_LIGHT", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::SOFT_LIGHT ) ) );
190 env->initDefine( "BLEND_DIFFERENCE", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::DIFFERENCE ) ) );
191 env->initDefine( "BLEND_EXCLUSION", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::EXCLUSION ) ) );
192 env->initDefine( "BLEND_HUE", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::HUE ) ) );
193 env->initDefine( "BLEND_SATURATION", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::SATURATION ) ) );
194 env->initDefine( "BLEND_COLOR", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::COLOR ) ) );
195 env->initDefine( "BLEND_LUMINOSITY", RefCountPtr< const Lang::BlendMode >( new Lang::BlendMode( Lang::BlendMode::LUMINOSITY ) ) );
196 env->initDefine( "DEVICE_GRAY", Lang::THE_COLOR_SPACE_DEVICE_GRAY );
197 env->initDefine( "DEVICE_RGB", Lang::THE_COLOR_SPACE_DEVICE_RGB );
198 env->initDefine( "DEVICE_CMYK", RefCountPtr< const Lang::ColorSpace >( new Lang::DeviceColorSpace< Lang::CMYK >( "DeviceCMYK", 4 ) ) );
200 env->initDefineDynamicHandler( Lang::HANDLER_NO_INTERSECTION, "Failed to find intersection." );
202 env->initDefine( "void", Lang::THE_VOID );
203 env->initDefine( "null", static_cast< RefCountPtr< const Lang::Geometric2D > >( Lang::THE_NULL2D ) );
204 env->initDefine( "null3D", static_cast< RefCountPtr< const Lang::Geometric3D > >( Lang::THE_NULL3D ) );
205 env->initDefine( "nullbind", Lang::THE_NULL_DYNAMIC_BINDINGS );
206 env->initDefine( "emptypath", Lang::THE_EMPTYPATH2D );
207 env->initDefine( "emptypath3D", Lang::THE_EMPTYPATH3D );
208 env->initDefine( "pointpicture", static_cast< RefCountPtr< const Lang::Geometric2D > >( Lang::THE_POINTPICTURE ) );
209 env->initDefine( "NO_MASK", Lang::THE_NONE_MASK );
211 env->initDefine( "arcdelta", static_cast< RefCountPtr< const Lang::Length > >( new Lang::Length( Computation::the_arcdelta ) ) );
213 env->initDefineCoreFunction( Lang::THE_NO_ARROW );
214 env->initDefineCoreFunction( Lang::THE_IDENTITY );
216 env->initDefineCoreFunction( Ast::THE_FUNCTION_coords2D );
217 env->initDefineCoreFunction( Ast::THE_FUNCTION_cornercoords2D );
218 env->initDefineCoreFunction( Ast::THE_FUNCTION_coords3D );
219 env->initDefineCoreFunction( Ast::THE_FUNCTION_TeX );