Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / statetypes.cc
blobb6baced2ff3ad4d6da80e414552cce10ac1de2ba
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 Henrik Tidefelt
19 #include <cmath>
21 #include "Shapes_Helpers_decls.h"
23 #include "shapestypes.h"
24 #include "shapesexceptions.h"
25 #include "astexpr.h"
26 #include "consts.h"
27 #include "globals.h"
28 #include "angleselect.h"
29 #include "astvar.h"
30 #include "astclass.h"
31 #include "shapescore.h"
32 #include "simplepdfo.h"
33 #include "isnan.h"
34 #include "pdffunctiontypes.h"
36 #include <limits>
37 #include <ctype.h>
38 #include <stack>
40 using namespace Shapes;
41 using namespace std;
44 Lang::DynamicBindings::DynamicBindings( )
45 { }
46 Lang::DynamicBindings::~DynamicBindings( )
47 { }
49 RefCountPtr< const Lang::Class > Lang::DynamicBindings::TypeID( new Lang::SystemFinalClass( strrefdup( "DynamicBindings" ) ) );
50 TYPEINFOIMPL( DynamicBindings );
51 DISPATCHIMPL( DynamicBindings );
54 Lang::DynamicBindingsPair::DynamicBindingsPair( const RefCountPtr< const Lang::DynamicBindings > & car, const RefCountPtr< const Lang::DynamicBindings > & cdr, bool override )
55 : override_( override ), car_( car ), cdr_( cdr )
56 { }
58 Lang::DynamicBindingsPair::~DynamicBindingsPair( )
59 { }
61 void
62 Lang::DynamicBindingsPair::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
64 if( override_ )
66 cdr_->bind( bindings, sysBindings );
67 MapType carBindings;
68 Kernel::SystemDynamicVariables * carSysBindings = 0;
69 car_->bind( carBindings, & carSysBindings );
71 if( bindings.empty( ) )
73 bindings.swap( carBindings );
75 else
77 MapType::iterator dst = bindings.begin( );
78 /* Merge the MapType bindings */
79 for( MapType::const_iterator src = carBindings.begin( ); src != carBindings.end( ); )
81 if( src->first < dst->first )
83 bindings.insert( dst, *src );
84 ++src;
85 continue;
87 if( src->first > dst->first )
89 dst = bindings.lower_bound( src->first );
90 if( dst == bindings.end( ) )
92 for( ; src != carBindings.end( ); ++src )
94 bindings.insert( bindings.end( ), *src );
96 break;
98 continue; /* Should we do something more clever here? */
100 /* If we reach here, the bindings appeared in both maps, and we ignore that in the car part. */
101 ++src;
105 if( carSysBindings != 0 )
107 if( *sysBindings == 0 )
109 *sysBindings = carSysBindings;
111 else
113 /* Merge the SystemDynamicVariables bindings */
114 (*sysBindings)->addFrom( *carSysBindings );
115 delete carSysBindings;
119 else
121 car_->bind( bindings, sysBindings );
122 cdr_->bind( bindings, sysBindings );
126 void
127 Lang::DynamicBindingsPair::show( std::ostream & os ) const
129 bool showCar = false;
130 if( dynamic_cast< const Lang::DynamicBindingsNull * >( car_.getPtr( ) ) == 0 )
132 showCar = true;
133 car_->show( os );
135 if( dynamic_cast< const Lang::DynamicBindingsNull * >( cdr_.getPtr( ) ) == 0 )
137 if( showCar )
139 os << " & " ;
141 cdr_->show( os );
145 void
146 Lang::DynamicBindingsPair::gcMark( Kernel::GCMarkedSet & marked )
148 const_cast< Lang::DynamicBindings * >( car_.getPtr( ) )->gcMark( marked );
149 const_cast< Lang::DynamicBindings * >( cdr_.getPtr( ) )->gcMark( marked );
153 Lang::DynamicBindingsNull::DynamicBindingsNull( )
156 Lang::DynamicBindingsNull::~DynamicBindingsNull( )
159 void
160 Lang::DynamicBindingsNull::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
164 void
165 Lang::DynamicBindingsNull::show( std::ostream & os ) const
167 os << "@(an empty set of dynamic bindings)" ;
170 void
171 Lang::DynamicBindingsNull::gcMark( Kernel::GCMarkedSet & marked )
176 Lang::UserDynamicBinding::UserDynamicBinding( const Kernel::DynamicEnvironmentKeyType & _key, const char * _id, const Ast::DynamicBindingExpression * bindingExpr, const Kernel::VariableHandle & _var )
177 : key_( _key ), id_( _id ), bindingExpr_( bindingExpr ), var_( _var )
180 Lang::UserDynamicBinding::~UserDynamicBinding( )
183 void
184 Lang::UserDynamicBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
186 MapType::iterator i = bindings.find( key_ );
187 if( i != bindings.end( ) )
189 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), i->second.second->idLoc( ) );
191 bindings.insert( MapType::value_type( key_, MapType::value_type::second_type( var_, bindingExpr_ ) ) );
194 void
195 Lang::UserDynamicBinding::show( std::ostream & os ) const
197 os << "@" << id_ << ":" ;
200 var_->getUntyped( )->show( os );
202 catch( ... )
204 os << "<thunk>" ;
208 void
209 Lang::UserDynamicBinding::gcMark( Kernel::GCMarkedSet & marked )
211 var_->gcMark( marked );
215 namespace Shapes
217 namespace Kernel
220 class UserDynamicBindingContinuation : public Kernel::Continuation
222 Kernel::DynamicEnvironmentKeyType key_;
223 const char * name_;
224 const Ast::DynamicBindingExpression * bindingExpr_;
225 Kernel::ContRef cont_;
226 public:
227 UserDynamicBindingContinuation( const Ast::SourceLocation & traceLoc, const Kernel::DynamicEnvironmentKeyType & key, const char * name, const Ast::DynamicBindingExpression * bindingExpr, const Kernel::ContRef & cont )
228 : Kernel::Continuation( traceLoc ), key_( key ), name_( name ), bindingExpr_( bindingExpr ), cont_( cont )
230 virtual ~UserDynamicBindingContinuation( )
232 virtual void takeHandle( Kernel::VariableHandle val, Kernel::EvalState * evalState, bool dummy ) const
234 cont_->takeValue( Kernel::ValueRef( new Lang::UserDynamicBinding( key_, name_, bindingExpr_, val ) ),
235 evalState );
237 virtual Kernel::ContRef up( ) const
239 return cont_;
241 virtual RefCountPtr< const char > description( ) const
243 return strrefdup( "make user dynamic binding" );
245 virtual void gcMark( Kernel::GCMarkedSet & marked )
247 cont_->gcMark( marked );
255 Kernel::UserDynamicVariableProperties::UserDynamicVariableProperties( const char * name, const Kernel::DynamicEnvironmentKeyType & key, const RefCountPtr< const Lang::Function > & filter, const Kernel::VariableHandle & defaultVal )
256 : DynamicVariableProperties( name ), key_( key ), filter_( filter ), defaultVal_( defaultVal )
259 Kernel::UserDynamicVariableProperties::~UserDynamicVariableProperties( )
262 Kernel::VariableHandle
263 Kernel::UserDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
267 return dyn->getVarHandle( key_ );
269 catch( const NonLocalExit::DynamicBindingNotFound & ball )
271 return defaultVal_;
275 void
276 Kernel::UserDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
278 if( filter_ == Lang::THE_IDENTITY )
280 Kernel::ContRef cont = evalState->cont_;
281 cont->takeValue( Kernel::ValueRef( new Lang::UserDynamicBinding( key_, name_, bindingExpr, val ) ),
282 evalState );
283 return;
286 evalState->cont_ = Kernel::ContRef( new Kernel::UserDynamicBindingContinuation( bindingExpr->exprLoc( ), key_, name_, bindingExpr, evalState->cont_ ) );
288 filter_->call( filter_, evalState, val, bindingExpr->exprLoc( ) );
292 Kernel::UserDynamicStateProperties::UserDynamicStateProperties( const char * name, const Kernel::DynamicEnvironmentKeyType & key, const Kernel::PassedEnv & defaultStateEnv, Kernel::PassedDyn defaultStateDyn, Ast::StateReference * defaultState )
293 : DynamicStateProperties( name ), key_( key ),
294 defaultStateEnv_( defaultStateEnv ), defaultStateDyn_( defaultStateDyn ), defaultState_( defaultState )
297 Kernel::UserDynamicStateProperties::~UserDynamicStateProperties( )
300 Kernel::StateHandle
301 Kernel::UserDynamicStateProperties::fetch( const Kernel::PassedDyn & dyn ) const
305 throw Exceptions::NotImplemented( "Fetching dynamic states" );
306 // return dyn->getStateHandle( key_ );
308 catch( const NonLocalExit::DynamicBindingNotFound & ball )
310 return defaultState_->getHandle( defaultStateEnv_, defaultStateDyn_ );
314 void
315 Kernel::UserDynamicStateProperties::makeBinding( Kernel::StateHandle val, const Ast::DynamicStateBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
317 throw Exceptions::NotImplemented( "Creation of dynamic state bindings" );
322 Lang::WidthBinding::WidthBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, Concrete::Length val )
323 : bindingExpr_( bindingExpr ), val_( val ), id_( id )
326 Lang::WidthBinding::~WidthBinding( )
329 void
330 Lang::WidthBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
332 if( *sysBindings == 0 )
334 *sysBindings = new Kernel::SystemDynamicVariables( );
335 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
336 newState->width_ = val_;
337 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
338 return;
341 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
343 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
344 newState->width_ = val_;
345 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
346 return;
349 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
351 if( ! IS_NAN( newState->width_ ) )
353 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
356 newState->width_ = val_;
357 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
360 void
361 Lang::WidthBinding::show( std::ostream & os ) const
363 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
364 << double( val_.offtype< 1, 0 >( ) ) * Interaction::displayUnitFactor << Interaction::displayUnitName ;
367 void
368 Lang::WidthBinding::gcMark( Kernel::GCMarkedSet & marked )
373 Kernel::WidthDynamicVariableProperties::WidthDynamicVariableProperties( const char * _name )
374 : Kernel::DynamicVariableProperties( _name )
377 Kernel::WidthDynamicVariableProperties::~WidthDynamicVariableProperties( )
380 Kernel::VariableHandle
381 Kernel::WidthDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
383 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
384 return Kernel::VariableHandle( new Kernel::Variable( RefCountPtr< const Lang::Value >( new Lang::Length( graphicsState->width_ ) ) ) );
387 void
388 Kernel::WidthDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
392 RefCountPtr< const Lang::Length > len = val->tryVal< const Lang::Length >( );
393 if( len->getScalar( ) < 0 )
395 throw Exceptions::OutOfRange( bindingExpr->exprLoc( ), strrefdup( "The length must be non-negative." ) );
397 Kernel::ContRef cont = evalState->cont_;
398 cont->takeValue( Kernel::ValueRef( new Lang::WidthBinding( name_, bindingExpr, len->get( ) ) ),
399 evalState );
400 return;
402 catch( const NonLocalExit::NotThisType & ball )
404 /* never mind */
409 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
410 Kernel::ContRef cont = evalState->cont_;
411 cont->takeValue( Kernel::ValueRef( new Lang::WidthBinding( name_, bindingExpr, Concrete::Length( -1 ) ) ),
412 evalState );
413 return;
415 catch( const NonLocalExit::NotThisType & ball )
417 /* never mind */
420 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Length::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
424 Lang::MiterLimitBinding::MiterLimitBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, Concrete::Length val )
425 : bindingExpr_( bindingExpr ), val_( val ), id_( id )
428 Lang::MiterLimitBinding::~MiterLimitBinding( )
431 void
432 Lang::MiterLimitBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
434 if( *sysBindings == 0 )
436 *sysBindings = new Kernel::SystemDynamicVariables( );
437 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
438 newState->miterLimit_ = val_;
439 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
440 return;
443 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
445 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
446 newState->miterLimit_ = val_;
447 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
448 return;
451 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
453 if( ! IS_NAN( newState->miterLimit_ ) )
455 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
458 newState->miterLimit_ = val_;
459 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
462 void
463 Lang::MiterLimitBinding::show( std::ostream & os ) const
465 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
466 << double( val_.offtype< 1, 0 >( ) ) * Interaction::displayUnitFactor << Interaction::displayUnitName ;
469 void
470 Lang::MiterLimitBinding::gcMark( Kernel::GCMarkedSet & marked )
475 Kernel::MiterLimitDynamicVariableProperties::MiterLimitDynamicVariableProperties( const char * name )
476 : Kernel::DynamicVariableProperties( name )
479 Kernel::MiterLimitDynamicVariableProperties::~MiterLimitDynamicVariableProperties( )
482 Kernel::VariableHandle
483 Kernel::MiterLimitDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
485 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
486 return Kernel::VariableHandle( new Kernel::Variable( RefCountPtr< const Lang::Value >( new Lang::Length( graphicsState->miterLimit_ ) ) ) );
489 void
490 Kernel::MiterLimitDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
494 RefCountPtr< const Lang::Length > len = val->tryVal< const Lang::Length >( );
495 if( len->getScalar( ) < 0 )
497 throw Exceptions::OutOfRange( bindingExpr->exprLoc( ), strrefdup( "The length must be non-negative." ) );
499 Kernel::ContRef cont = evalState->cont_;
500 cont->takeValue( Kernel::ValueRef( new Lang::MiterLimitBinding( name_, bindingExpr, len->get( ) ) ),
501 evalState );
502 return;
504 catch( const NonLocalExit::NotThisType & ball )
506 /* never mind */
511 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
512 Kernel::ContRef cont = evalState->cont_;
513 cont->takeValue( Kernel::ValueRef( new Lang::MiterLimitBinding( name_, bindingExpr, Concrete::Length( -1 ) ) ),
514 evalState );
515 return;
517 catch( const NonLocalExit::NotThisType & ball )
519 /* never mind */
522 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Length::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
526 Lang::CapStyle::CapStyle( const Lang::CapStyle::ValueType & cap )
527 : cap_( cap )
530 RefCountPtr< const Lang::Class > Lang::CapStyle::TypeID( new Lang::SystemFinalClass( strrefdup( "CapStyle" ) ) );
531 TYPEINFOIMPL( CapStyle );
534 Lang::JoinStyle::JoinStyle( const Lang::JoinStyle::ValueType & join )
535 : join_( join )
538 RefCountPtr< const Lang::Class > Lang::JoinStyle::TypeID( new Lang::SystemFinalClass( strrefdup( "JoinStyle" ) ) );
539 TYPEINFOIMPL( JoinStyle );
542 Lang::BlendMode::BlendMode( const Lang::BlendMode::ValueType & mode )
543 : mode_( mode )
546 RefCountPtr< const Lang::Class > Lang::BlendMode::TypeID( new Lang::SystemFinalClass( strrefdup( "BlendMode" ) ) );
547 TYPEINFOIMPL( BlendMode );
549 std::map< Lang::BlendMode::ValueType, RefCountPtr< SimplePDF::PDF_Object > > Lang::BlendMode::resourceMap;
551 void
552 Lang::BlendMode::applyGraphicsState( std::ostream & os, SimplePDF::PDF_Resources * resources, const Lang::BlendMode::ValueType & mode )
554 typedef typeof resourceMap MapType;
555 MapType::const_iterator i = resourceMap.find( mode );
556 if( i != resourceMap.end( ) )
558 os << resources->nameofGraphicsState( i->second ) << " gs " ;
560 else
562 RefCountPtr< SimplePDF::PDF_Dictionary > dic;
563 (*dic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
565 RefCountPtr< SimplePDF::PDF_Object > indirection = SimplePDF::indirect( dic, & Kernel::theIndirectObjectCount );
566 resourceMap.insert( MapType::value_type( mode, indirection ) );
567 switch( mode )
569 case NORMAL:
570 (*dic)[ "BM" ] = SimplePDF::newName( "Normal" );
571 break;
572 case MULTIPLY:
573 (*dic)[ "BM" ] = SimplePDF::newName( "Multiply" );
574 break;
575 case SCREEN:
576 (*dic)[ "BM" ] = SimplePDF::newName( "Screen" );
577 break;
578 case OVERLAY:
579 (*dic)[ "BM" ] = SimplePDF::newName( "Overlay" );
580 break;
581 case DARKEN:
582 (*dic)[ "BM" ] = SimplePDF::newName( "Darken" );
583 break;
584 case LIGHTEN:
585 (*dic)[ "BM" ] = SimplePDF::newName( "Lighten" );
586 break;
587 case COLOR_DODGE:
588 (*dic)[ "BM" ] = SimplePDF::newName( "ColorDodge" );
589 break;
590 case COLOR_BURN:
591 (*dic)[ "BM" ] = SimplePDF::newName( "ColorBurn" );
592 break;
593 case HARD_LIGHT:
594 (*dic)[ "BM" ] = SimplePDF::newName( "HardLight" );
595 break;
596 case SOFT_LIGHT:
597 (*dic)[ "BM" ] = SimplePDF::newName( "SoftLight" );
598 break;
599 case DIFFERENCE:
600 (*dic)[ "BM" ] = SimplePDF::newName( "Difference" );
601 break;
602 case EXCLUSION:
603 (*dic)[ "BM" ] = SimplePDF::newName( "Exclusion" );
604 break;
605 case HUE:
606 (*dic)[ "BM" ] = SimplePDF::newName( "Hue" );
607 break;
608 case SATURATION:
609 (*dic)[ "BM" ] = SimplePDF::newName( "Saturation" );
610 break;
611 case COLOR:
612 (*dic)[ "BM" ] = SimplePDF::newName( "Color" );
613 break;
614 case LUMINOSITY:
615 (*dic)[ "BM" ] = SimplePDF::newName( "Luminosity" );
616 break;
617 case BLEND_SAME:
618 // We leave the graphics state dictionary empty!
619 break;
620 default:
621 throw Exceptions::InternalError( strrefdup( "BlendMode switch out of range." ) );
623 os << resources->nameofGraphicsState( indirection ) << " gs " ;
628 Kernel::GraphicsState::GraphicsState( )
629 : strokingColor_( NullPtr< const Lang::Color >( ) ),
630 nonStrokingColor_( NullPtr< const Lang::Color >( ) ),
631 width_( std::numeric_limits< double >::signaling_NaN( ) ),
632 cap_( Lang::CapStyle::CAP_UNDEFINED ),
633 join_( Lang::JoinStyle::JOIN_UNDEFINED ),
634 miterLimit_( std::numeric_limits< double >::signaling_NaN( ) ),
635 dash_( NullPtr< const Lang::Dash >( ) ),
636 blend_( Lang::BlendMode::BLEND_UNDEFINED ),
637 alphaIsShape_( true ),
638 strokingAlpha_( NullPtr< const Lang::Alpha >( ) ),
639 nonStrokingAlpha_( NullPtr< const Lang::Alpha >( ) )
642 Kernel::GraphicsState::GraphicsState( const Kernel::GraphicsState & orig )
643 : strokingColor_( orig.strokingColor_ ),
644 nonStrokingColor_( orig.nonStrokingColor_ ),
645 width_( orig.width_ ),
646 cap_( orig.cap_ ),
647 join_( orig.join_ ),
648 miterLimit_( orig.miterLimit_ ),
649 dash_( orig.dash_ ),
650 blend_( orig.blend_ ),
651 alphaIsShape_( orig.alphaIsShape_ ),
652 strokingAlpha_( orig.strokingAlpha_ ),
653 nonStrokingAlpha_( orig.nonStrokingAlpha_ )
656 Kernel::GraphicsState::GraphicsState( const Kernel::GraphicsState & newValues, const Kernel::GraphicsState & oldValues )
657 : strokingColor_( oldValues.strokingColor_ ),
658 nonStrokingColor_( oldValues.nonStrokingColor_ ),
659 width_( oldValues.width_ ),
660 cap_( oldValues.cap_ ),
661 join_( oldValues.join_ ),
662 miterLimit_( oldValues.miterLimit_ ),
663 dash_( oldValues.dash_ ),
664 blend_( oldValues.blend_ ),
665 alphaIsShape_( oldValues.alphaIsShape_ ),
666 strokingAlpha_( oldValues.strokingAlpha_ ),
667 nonStrokingAlpha_( oldValues.nonStrokingAlpha_ )
669 if( newValues.strokingColor_ != NullPtr< const Lang::Color >( ) )
671 strokingColor_ = newValues.strokingColor_;
673 if( newValues.nonStrokingColor_ != NullPtr< const Lang::Color >( ) )
675 nonStrokingColor_ = newValues.nonStrokingColor_;
677 if( ! IS_NAN( newValues.width_ ) )
679 width_ = newValues.width_;
681 if( newValues.cap_ != Lang::CapStyle::CAP_UNDEFINED )
683 cap_ = newValues.cap_;
685 if( newValues.join_ != Lang::JoinStyle::JOIN_UNDEFINED )
687 join_ = newValues.join_;
689 if( ! IS_NAN( newValues.miterLimit_ ) )
691 miterLimit_ = newValues.miterLimit_;
693 if( newValues.dash_ != NullPtr< const Lang::Dash >( ) )
695 dash_ = newValues.dash_;
697 if( newValues.blend_ != Lang::BlendMode::BLEND_UNDEFINED )
699 blend_ = newValues.blend_;
701 if( newValues.strokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
703 strokingAlpha_ = newValues.strokingAlpha_;
704 alphaIsShape_ = newValues.alphaIsShape_;
706 if( newValues.nonStrokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
708 nonStrokingAlpha_ = newValues.nonStrokingAlpha_;
709 alphaIsShape_ = newValues.alphaIsShape_;
713 Kernel::GraphicsState::GraphicsState( bool setDefaults )
714 : strokingColor_( Lang::THE_BLACK ),
715 nonStrokingColor_( Lang::THE_BLACK ),
716 width_( 1 ),
717 cap_( Lang::CapStyle::CAP_BUTT ),
718 join_( Lang::JoinStyle::JOIN_MITER ),
719 miterLimit_( 10 ),
720 dash_( Lang::THE_SOLID_DASH ),
721 blend_( Lang::BlendMode::NORMAL ),
722 alphaIsShape_( false ),
723 strokingAlpha_( Lang::THE_OPAQUE ),
724 nonStrokingAlpha_( Lang::THE_OPAQUE )
726 if( ! setDefaults )
728 throw Exceptions::InternalError( strrefdup( "setDefaults must be true in GraphicsState::GraphicsState." ) );
732 Kernel::GraphicsState::~GraphicsState( )
735 void
736 Kernel::GraphicsState::print( std::ostream & os, const std::string & indentation ) const
738 if( ! IS_NAN( width_ ) )
740 os << indentation << Interaction::DYNAMIC_VARIABLE_PREFIX << Lang::DYNAMIC_VARIABLE_ID_WIDTH << ": " << width_ / Interaction::displayUnit << Interaction::displayUnitName << std::endl ;
742 if( strokingColor_ != NullPtr< const Lang::Color >( ) )
744 os << indentation << Interaction::DYNAMIC_VARIABLE_PREFIX << Lang::DYNAMIC_VARIABLE_ID_STROKING << ": " ;
745 strokingColor_->show( os );
746 os << std::endl ;
748 if( nonStrokingColor_ != NullPtr< const Lang::Color >( ) )
750 os << indentation << Interaction::DYNAMIC_VARIABLE_PREFIX << Lang::DYNAMIC_VARIABLE_ID_NONSTROKING << ": " ;
751 nonStrokingColor_->show( os );
752 os << std::endl ;
754 os << "(and a bunch of other variables...)" << std::endl ;
757 bool
758 Kernel::GraphicsState::synchStrokingColor( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
760 if( force || strokingColor_ != ref->strokingColor_ )
762 if( ref->strokingColor_ == NullPtr< const Lang::Color >( ) )
764 return false;
766 strokingColor_ = ref->strokingColor_;
767 strokingColor_->setStroking( os );
768 return true;
770 return false;
773 bool
774 Kernel::GraphicsState::synchNonStrokingColor( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
776 if( force || nonStrokingColor_ != ref->nonStrokingColor_ )
778 if( ref->nonStrokingColor_ == NullPtr< const Lang::Color >( ) )
780 return false;
782 nonStrokingColor_ = ref->nonStrokingColor_;
783 nonStrokingColor_->setNonStroking( os );
784 return true;
786 return false;
789 bool
790 Kernel::GraphicsState::synchStrokingAlpha( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
792 if( force || strokingAlpha_ != ref->strokingAlpha_ || alphaIsShape_ != ref->strokingAlpha_->isShape_ )
794 if( ref->strokingAlpha_ == NullPtr< const Lang::Alpha >( ) )
796 return false;
798 strokingAlpha_ = ref->strokingAlpha_;
799 alphaIsShape_ = strokingAlpha_->isShape_;
801 const SimplePDF::PDF_Version::Version ALPHA_VERSION = SimplePDF::PDF_Version::PDF_1_4;
802 if( Kernel::the_PDF_version.greaterOrEqual( ALPHA_VERSION ) )
804 Lang::Alpha::applyGraphicsState( os, resources, *strokingAlpha_, true );
805 return true;
807 else
809 Kernel::the_PDF_version.message( ALPHA_VERSION, "The graphics state stroking alpha setting was ignored." );
812 return false;
815 bool
816 Kernel::GraphicsState::synchNonStrokingAlpha( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
818 if( force || nonStrokingAlpha_ != ref->nonStrokingAlpha_ || alphaIsShape_ != ref->nonStrokingAlpha_->isShape_ )
820 if( ref->nonStrokingAlpha_ == NullPtr< const Lang::Alpha >( ) )
822 return false;
824 nonStrokingAlpha_ = ref->nonStrokingAlpha_;
825 alphaIsShape_ = nonStrokingAlpha_->isShape_;
827 const SimplePDF::PDF_Version::Version ALPHA_VERSION = SimplePDF::PDF_Version::PDF_1_4;
828 if( Kernel::the_PDF_version.greaterOrEqual( ALPHA_VERSION ) )
830 Lang::Alpha::applyGraphicsState( os, resources, *nonStrokingAlpha_, false );
831 return true;
833 else
835 Kernel::the_PDF_version.message( ALPHA_VERSION, "The graphics state non-stroking alpha setting was ignored." );
838 return false;
841 bool
842 Kernel::GraphicsState::synchWidth( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
844 if( force || width_ != ref->width_ )
846 if( IS_NAN( ref->width_ ) ||
847 ref->width_ < Concrete::ZERO_LENGTH )
849 return false;
851 width_ = ref->width_;
852 os << width_.offtype< 1, 0 >( ) << " w " ;
853 return true;
855 return false;
858 bool
859 Kernel::GraphicsState::synchCap( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
861 if( force || cap_ != ref->cap_ )
863 if( ref->cap_ != Lang::CapStyle::CAP_UNDEFINED &&
864 ref->cap_ != Lang::CapStyle::CAP_SAME )
866 cap_ = ref->cap_;
867 os << cap_ << " J " ;
868 return true;
871 return false;
874 bool
875 Kernel::GraphicsState::synchJoin( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
877 if( force || join_ != ref->join_ )
879 if( ref->join_ != Lang::JoinStyle::JOIN_UNDEFINED &&
880 ref->join_ != Lang::JoinStyle::JOIN_SAME )
882 join_ = ref->join_;
883 os << join_ << " j " ;
884 return true;
887 return false;
890 bool
891 Kernel::GraphicsState::synchMiterLimit( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
893 if( force || miterLimit_ != ref->miterLimit_ )
895 if( IS_NAN( ref->miterLimit_ ) ||
896 ref->miterLimit_ < Concrete::ZERO_LENGTH )
898 return false;
900 miterLimit_ = ref->miterLimit_;
901 os << miterLimit_.offtype< 1, 0 >( ) << " M " ;
902 return true;
904 return false;
907 bool
908 Kernel::GraphicsState::synchDash( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
910 if( force || dash_ != ref->dash_ )
912 if( ref->dash_ == NullPtr< const Lang::Dash >( ) )
914 return false;
916 dash_ = ref->dash_;
917 dash_->setDash( os );
918 return true;
920 return false;
923 bool
924 Kernel::GraphicsState::synchBlend( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
926 if( force || blend_ != ref->blend_ )
928 if( ref->blend_ == Lang::BlendMode::BLEND_UNDEFINED )
930 return false;
932 blend_ = ref->blend_;
933 const SimplePDF::PDF_Version::Version BLEND_VERSION = SimplePDF::PDF_Version::PDF_1_4;
934 if( Kernel::the_PDF_version.greaterOrEqual( BLEND_VERSION ) )
936 Lang::BlendMode::applyGraphicsState( os, resources, blend_ );
937 return true;
939 else
941 Kernel::the_PDF_version.message( BLEND_VERSION, "The graphics state blend mode setting was ignored." );
944 return false;
948 bool
949 Kernel::GraphicsState::synchForStroke( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
951 bool anyChange = false;
952 anyChange = synchStrokingColor( os, ref, resources, force ) || anyChange;
953 anyChange = synchStrokingAlpha( os, ref, resources, force ) || anyChange;
954 anyChange = synchWidth( os, ref, resources, force ) || anyChange;
955 anyChange = synchCap( os, ref, resources, force ) || anyChange;
956 anyChange = synchJoin( os, ref, resources, force ) || anyChange;
957 anyChange = synchMiterLimit( os, ref, resources, force ) || anyChange;
958 anyChange = synchDash( os, ref, resources, force ) || anyChange;
959 if( anyChange )
961 os << std::endl ;
963 return anyChange;
966 bool
967 Kernel::GraphicsState::synchForNonStroke( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
969 bool anyChange = false;
970 anyChange = synchNonStrokingColor( os, ref, resources, force ) || anyChange;
971 anyChange = synchNonStrokingAlpha( os, ref, resources, force ) || anyChange;
972 if( anyChange )
974 os << std::endl ;
976 return anyChange;
979 bool
980 Kernel::GraphicsState::synchStrokingColorWithNonStrokingColor( std::ostream & os, SimplePDF::PDF_Resources * resources, Concrete::Length width )
982 bool anyChange = false;
984 if( ! IS_NAN( width ) && width_ != width )
986 width_ = width;
987 os << width_.offtype< 1, 0 >( ) << " w " ;
988 anyChange = true;
991 if( strokingColor_ != nonStrokingColor_ )
993 strokingColor_ = nonStrokingColor_;
994 strokingColor_->setStroking( os );
997 if( anyChange )
999 os << std::endl ;
1001 return anyChange;
1005 Lang::Alpha::Alpha( bool isShape, double a )
1006 : isShape_( isShape ), a_( a )
1009 Lang::Alpha::~Alpha( )
1012 RefCountPtr< const Lang::Class > Lang::Alpha::TypeID( new Lang::SystemFinalClass( strrefdup( "Alpha" ) ) );
1013 TYPEINFOIMPL( Alpha );
1015 void
1016 Lang::Alpha::applyGraphicsState( std::ostream & os, SimplePDF::PDF_Resources * resources, const Lang::Alpha & self, bool isStroking )
1018 typedef typeof strokingShapeResourcemap MapType;
1019 MapType * resourceMap;
1020 if( self.isShape_ )
1022 if( isStroking )
1024 resourceMap = & strokingShapeResourcemap;
1026 else
1028 resourceMap = & nonStrokingShapeResourcemap;
1031 else
1033 if( isStroking )
1035 resourceMap = & strokingOpacityResourcemap;
1037 else
1039 resourceMap = & nonStrokingOpacityResourcemap;
1042 MapType::const_iterator i = resourceMap->find( self.a_ );
1043 if( i != resourceMap->end( ) )
1045 os << resources->nameofGraphicsState( i->second ) << " gs " ;
1047 else
1049 RefCountPtr< SimplePDF::PDF_Dictionary > dic;
1050 (*dic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
1051 RefCountPtr< SimplePDF::PDF_Object > indirection = SimplePDF::indirect( dic, & Kernel::theIndirectObjectCount );
1053 resourceMap->insert( MapType::value_type( self.a_, indirection ) );
1054 if( self.a_ >= 0 )
1056 (*dic)[ "AIS" ] = SimplePDF::newBoolean( self.isShape_ );
1057 if( isStroking )
1059 (*dic)[ "CA" ] = SimplePDF::newFloat( self.a_ );
1061 else
1063 (*dic)[ "ca" ] = SimplePDF::newFloat( self.a_ );
1066 // If self.a_ < 0 we just leave the graphics state dictionary empty
1068 os << resources->nameofGraphicsState( indirection ) << " gs " ;
1072 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::strokingShapeResourcemap;
1073 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::strokingOpacityResourcemap;
1074 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::nonStrokingShapeResourcemap;
1075 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::nonStrokingOpacityResourcemap;
1078 Lang::AlphaBinding::AlphaBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, const RefCountPtr< const Lang::Alpha > & alpha, bool isStroking )
1079 : bindingExpr_( bindingExpr ), alpha_( alpha ), isStroking_( isStroking ), id_( id )
1082 Lang::AlphaBinding::~AlphaBinding( )
1085 void
1086 Lang::AlphaBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1088 if( *sysBindings == 0 ) {
1089 *sysBindings = new Kernel::SystemDynamicVariables( );
1090 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1091 if( isStroking_ )
1093 newState->strokingAlpha_ = alpha_;
1095 else
1097 newState->nonStrokingAlpha_ = alpha_;
1099 newState->alphaIsShape_ = alpha_->isShape_;
1100 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1101 return;
1104 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1106 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1107 if( isStroking_ )
1109 newState->strokingAlpha_ = alpha_;
1111 else
1113 newState->nonStrokingAlpha_ = alpha_;
1115 newState->alphaIsShape_ = alpha_->isShape_;
1116 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1117 return;
1120 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1122 if( isStroking_ )
1124 if( newState->strokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
1126 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1128 newState->strokingAlpha_ = alpha_;
1130 else
1132 if( newState->nonStrokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
1134 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1136 newState->nonStrokingAlpha_ = alpha_;
1138 newState->alphaIsShape_ = alpha_->isShape_;
1139 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1142 void
1143 Lang::AlphaBinding::show( std::ostream & os ) const
1145 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1146 alpha_->show( os );
1149 void
1150 Lang::AlphaBinding::gcMark( Kernel::GCMarkedSet & marked )
1152 const_cast< Lang::Alpha * >( alpha_.getPtr( ) )->gcMark( marked );
1157 Kernel::AlphaDynamicVariableProperties::AlphaDynamicVariableProperties( const char * name, bool isStroking )
1158 : Kernel::DynamicVariableProperties( name ), isStroking_( isStroking )
1161 Kernel::AlphaDynamicVariableProperties::~AlphaDynamicVariableProperties( )
1164 Kernel::VariableHandle
1165 Kernel::AlphaDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1167 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1168 if( isStroking_ )
1170 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->strokingAlpha_ ) );
1172 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->nonStrokingAlpha_ ) );
1175 void
1176 Kernel::AlphaDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1180 RefCountPtr< const Lang::Alpha > alpha = val->tryVal< const Lang::Alpha >( );
1181 Kernel::ContRef cont = evalState->cont_;
1182 cont->takeValue( Kernel::ValueRef( new Lang::AlphaBinding( name_, bindingExpr, alpha, isStroking_ ) ),
1183 evalState );
1184 return;
1186 catch( const NonLocalExit::NotThisType & ball )
1188 /* never mind */
1193 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1194 Kernel::ContRef cont = evalState->cont_;
1195 cont->takeValue( Kernel::ValueRef( new Lang::AlphaBinding( name_, bindingExpr, RefCountPtr< const Lang::Alpha >( new Lang::Alpha( true, -1 ) ), isStroking_ ) ),
1196 evalState );
1197 return;
1199 catch( const NonLocalExit::NotThisType & ball )
1201 /* never mind */
1204 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Alpha::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1208 Lang::SoftMask::SoftMask( )
1209 : graphicsStateResource_( NullPtr< SimplePDF::PDF_Object >( ) )
1211 static size_t callCount = 0;
1212 ++callCount;
1213 if( callCount > 2 )
1215 throw Exceptions::InternalError( strrefdup( "The None soft mask should be generated at most twice!" ) );
1218 RefCountPtr< SimplePDF::PDF_Dictionary > dic;
1219 graphicsStateResource_ = SimplePDF::indirect( dic, & Kernel::theIndirectObjectCount );
1221 (*dic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
1222 (*dic)[ "SMask" ] = SimplePDF::newName( "None" );
1225 Lang::SoftMask::SoftMask( SubType subType, const RefCountPtr< const Lang::TransparencyGroup > & tpGroup, const RefCountPtr< const Lang::Color > & background, const RefCountPtr< const Lang::PDF_Function > & transfer )
1226 : graphicsStateResource_( NullPtr< SimplePDF::PDF_Object >( ) )
1228 RefCountPtr< SimplePDF::PDF_Dictionary > gsDic;
1229 graphicsStateResource_ = SimplePDF::indirect( gsDic, & Kernel::theIndirectObjectCount );
1231 RefCountPtr< SimplePDF::PDF_Dictionary > smDic;
1233 (*gsDic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
1234 (*gsDic)[ "SMask" ] = smDic;
1235 (*smDic)[ "G" ] = tpGroup->getPDF_Object( );
1237 switch( subType )
1239 case ALPHA:
1241 (*smDic)[ "S" ] = SimplePDF::newName( "Alpha" );
1242 if( background != NullPtr< const Lang::Color >( ) )
1244 throw Exceptions::InternalError( strrefdup( "Attempt to create Alpha soft mask with BC." ) );
1247 break;
1248 case LUMINOSITY:
1250 (*smDic)[ "S" ] = SimplePDF::newName( "Luminosity" );
1251 if( background != NullPtr< const Lang::Color >( ) )
1253 (*smDic)[ "BC" ] = background->componentVector( );
1254 if( ! tpGroup->colorSpace( )->containsColor( background.getPtr( ) ) )
1256 throw Exceptions::OutOfRange( "The background color is not in the transparency groups color space." );
1260 break;
1261 default:
1262 throw Exceptions::InternalError( strrefdup( "SoftMask::SoftMask: Enum switch out of range." ) );
1264 if( transfer != NullPtr< const Lang::PDF_Function >( ) )
1266 if( ! transfer->matchesDimensions( 1, 1 ) )
1268 throw Exceptions::InternalError( strrefdup( "SoftMask::SoftMask: The transfer function arity should be correct at this point." ) );
1270 (*smDic)[ "TR" ] = transfer->getFunction( );
1274 Lang::SoftMask::~SoftMask( )
1277 RefCountPtr< const Lang::Class > Lang::SoftMask::TypeID( new Lang::SystemFinalClass( strrefdup( "SoftMask" ) ) );
1278 TYPEINFOIMPL( SoftMask );
1281 Lang::Dash::Iterator::Iterator( RefCountPtr< std::list< Concrete::Length > > _pattern, double _scale, std::list< Concrete::Length >::const_iterator _i, bool _on, Concrete::Length _length )
1282 : mem_( _pattern ), begin_( _pattern->begin( ) ), end_( _pattern->end( ) ), scale_( _scale ), i_( _i ), on_( _on ), length_( _scale * _length )
1285 Lang::Dash::Iterator &
1286 Lang::Dash::Iterator::operator ++ ( )
1288 ++i_;
1289 if( i_ == end_ )
1291 i_ = begin_;
1292 on_ = true;
1294 else
1296 on_ = ! on_;
1298 length_ = scale_ * (*i_);
1299 return *this;
1302 bool
1303 Lang::Dash::Iterator::isOn( ) const
1305 return on_;
1308 Concrete::Length
1309 Lang::Dash::Iterator::getLength( ) const
1311 return length_;
1315 Lang::Dash::Dash( )
1316 : pattern_( new list< Concrete::Length >( ) ), phase_( 0 ), scale_( 1 )
1319 Lang::Dash::Dash( RefCountPtr< std::list< Concrete::Length > > _pattern, Concrete::Length _phase, double _scale )
1320 : pattern_( _pattern ), phase_( _phase ), scale_( _scale ), myLength_( 0 )
1322 for( list< Concrete::Length >::const_iterator i = pattern_->begin( ); i != pattern_->end( ); ++i )
1324 myLength_ += (*i);
1328 Lang::Dash::Dash( RefCountPtr< std::list< Concrete::Length > > _pattern, Concrete::Length _phase, double _scale, Concrete::Length _length )
1329 : pattern_( _pattern ), phase_( _phase ), scale_( _scale ), myLength_( _length )
1332 DISPATCHIMPL( Dash );
1334 Lang::Dash::~Dash( )
1337 RefCountPtr< const Lang::Class > Lang::Dash::TypeID( new Lang::SystemFinalClass( strrefdup( "Dash" ) ) );
1338 TYPEINFOIMPL( Dash );
1341 void
1342 Lang::Dash::setDash( ostream & os ) const
1344 // Negative scale means that the dash shall not be altered
1345 if( scale_ < 0 )
1347 return;
1350 os << "[ " ;
1351 for( list< Concrete::Length >::const_iterator i = pattern_->begin( ); i != pattern_->end( ); ++i )
1353 os << Concrete::Length::offtype( *i ) * scale_ << " " ;
1355 os << "] " << Concrete::Length::offtype( phase_ ) * scale_ << " d " ;
1358 RefCountPtr< SimplePDF::PDF_Vector >
1359 Lang::Dash::getDashArray( ) const
1361 if( scale_ < 0 )
1363 throw Exceptions::MiscellaneousRequirement( "The same-as-before dash cannot be represented in PDF." );
1366 RefCountPtr< SimplePDF::PDF_Vector > res = RefCountPtr< SimplePDF::PDF_Vector >( new SimplePDF::PDF_Vector );
1367 for( list< Concrete::Length >::const_iterator i = pattern_->begin( ); i != pattern_->end( ); ++i )
1369 res->vec.push_back( SimplePDF::newFloat( Concrete::Length::offtype( *i ) * scale_ ) );
1372 return res;
1375 RefCountPtr< const Lang::Dash >
1376 Lang::Dash::scaled( double factor ) const
1378 return RefCountPtr< const Lang::Dash >( new Lang::Dash( pattern_, phase_, scale_ * factor, myLength_ ) );
1381 RefCountPtr< const Lang::Dash >
1382 Lang::Dash::shifted( Concrete::Length dist ) const
1384 return RefCountPtr< const Lang::Dash >( new Lang::Dash( pattern_, phase_ + dist / scale_, scale_, myLength_ ) );
1387 Concrete::Length
1388 Lang::Dash::length( ) const
1390 return myLength_ * scale_;
1393 bool
1394 Lang::Dash::isSolid( ) const
1396 return pattern_->empty( );
1399 Lang::Dash::Iterator
1400 Lang::Dash::begin( ) const
1402 Concrete::Length tmpPhase = modPhysical( phase_, myLength_ );
1403 if( tmpPhase < 0 )
1405 tmpPhase += myLength_;
1407 std::list< Concrete::Length >::const_iterator i = pattern_->begin( );
1408 bool on = true;
1409 while( tmpPhase >= *i )
1411 tmpPhase -= *i;
1412 on = ! on;
1413 ++i;
1415 return Lang::Dash::Iterator( pattern_, scale_, i, on, *i - tmpPhase );
1418 Lang::Color::Color( )
1421 DISPATCHIMPL( Color );
1423 Lang::Color::~Color( )
1426 RefCountPtr< const Lang::Class > Lang::Color::TypeID = NullPtr< const Lang::Class >( ); /* The value is set in main */
1428 RefCountPtr< const char >
1429 Lang::Color::staticTypeName( )
1431 return TypeID->getPrettyName( );
1435 Lang::Gray::Gray( const Concrete::Gray & components )
1436 : components_( components )
1439 DISPATCHIMPL( Gray );
1441 Lang::Gray::~Gray( )
1444 RefCountPtr< const Lang::Class > Lang::Gray::TypeID( new Lang::SystemFinalClass( strrefdup( "Gray" ) ) );
1445 TYPEINFOIMPL( Gray );
1447 void
1448 Lang::Gray::show( std::ostream & os ) const
1450 os << "[gray " << components_.gr_ << "]" ;
1453 void
1454 Lang::Gray::setStroking( ostream & os ) const
1456 components_.setStroking( os );
1459 void
1460 Lang::Gray::setNonStroking( ostream & os ) const
1462 components_.setNonStroking( os );
1465 RefCountPtr< SimplePDF::PDF_Vector >
1466 Lang::Gray::componentVector( ) const
1468 return components_.componentVector( );
1472 Lang::RGB::RGB( const Concrete::RGB & components )
1473 : components_( components )
1476 DISPATCHIMPL( RGB );
1478 Lang::RGB::~RGB( )
1481 RefCountPtr< const Lang::Class > Lang::RGB::TypeID( new Lang::SystemFinalClass( strrefdup( "RGB" ) ) );
1482 TYPEINFOIMPL( RGB );
1484 void
1485 Lang::RGB::show( std::ostream & os ) const
1487 os << "[rgb " << components_.r_ << " " << components_.g_ << " " << components_.b_ << "]" ;
1490 void
1491 Lang::RGB::setStroking( ostream & os ) const
1493 components_.setStroking( os );
1496 void
1497 Lang::RGB::setNonStroking( ostream & os ) const
1499 components_.setNonStroking( os );
1502 RefCountPtr< SimplePDF::PDF_Vector >
1503 Lang::RGB::componentVector( ) const
1505 return components_.componentVector( );
1509 Lang::CMYK::CMYK( const Concrete::CMYK & components )
1510 : components_( components )
1513 DISPATCHIMPL( CMYK );
1515 Lang::CMYK::~CMYK( )
1518 RefCountPtr< const Lang::Class > Lang::CMYK::TypeID( new Lang::SystemFinalClass( strrefdup( "CMYK" ) ) );
1519 TYPEINFOIMPL( CMYK );
1521 void
1522 Lang::CMYK::show( std::ostream & os ) const
1524 os << "[cmyk " << components_.c_ << " " << components_.m_ << " " << components_.y_ << " " << components_.k_ << "]" ;
1527 void
1528 Lang::CMYK::setStroking( ostream & os ) const
1530 components_.setStroking( os );
1533 void
1534 Lang::CMYK::setNonStroking( ostream & os ) const
1536 components_.setNonStroking( os );
1539 RefCountPtr< SimplePDF::PDF_Vector >
1540 Lang::CMYK::componentVector( ) const
1542 return components_.componentVector( );
1546 Lang::StrokingBinding::StrokingBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, RefCountPtr< const Lang::Color > color )
1547 : bindingExpr_( bindingExpr ), color_( color ), id_( id )
1550 Lang::StrokingBinding::~StrokingBinding( )
1553 void
1554 Lang::StrokingBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1556 if( *sysBindings == 0 )
1558 *sysBindings = new Kernel::SystemDynamicVariables( );
1559 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1560 newState->strokingColor_ = color_;
1561 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1562 return;
1565 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1567 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1568 newState->strokingColor_ = color_;
1569 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1570 return;
1573 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1575 if( newState->strokingColor_ != NullPtr< const Lang::Color >( ) )
1577 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1580 newState->strokingColor_ = color_;
1581 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1584 void
1585 Lang::StrokingBinding::show( std::ostream & os ) const
1587 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1588 color_->show( os );
1591 void
1592 Lang::StrokingBinding::gcMark( Kernel::GCMarkedSet & marked )
1594 const_cast< Lang::Color * >( color_.getPtr( ) )->gcMark( marked );
1599 Kernel::StrokingDynamicVariableProperties::StrokingDynamicVariableProperties( const char * name )
1600 : Kernel::DynamicVariableProperties( name )
1603 Kernel::StrokingDynamicVariableProperties::~StrokingDynamicVariableProperties( )
1606 Kernel::VariableHandle
1607 Kernel::StrokingDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1609 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1610 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->strokingColor_ ) );
1613 void
1614 Kernel::StrokingDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1618 RefCountPtr< const Lang::Color > color = val->tryVal< const Lang::Color >( );
1619 Kernel::ContRef cont = evalState->cont_;
1620 cont->takeValue( Kernel::ValueRef( new Lang::StrokingBinding( name_, bindingExpr, color ) ),
1621 evalState );
1622 return;
1624 catch( const NonLocalExit::NotThisType & ball )
1626 /* never mind */
1631 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1632 Kernel::ContRef cont = evalState->cont_;
1633 cont->takeValue( Kernel::ValueRef( new Lang::StrokingBinding( name_, bindingExpr, RefCountPtr< const Lang::Color >( new Lang::Gray( -1 ) ) ) ),
1634 evalState );
1635 return;
1637 catch( const NonLocalExit::NotThisType & ball )
1639 /* never mind */
1642 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Color::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1646 Lang::NonStrokingBinding::NonStrokingBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, RefCountPtr< const Lang::Color > color )
1647 : bindingExpr_( bindingExpr ), color_( color ), id_( id )
1650 Lang::NonStrokingBinding::~NonStrokingBinding( )
1653 void
1654 Lang::NonStrokingBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1656 if( *sysBindings == 0 )
1658 *sysBindings = new Kernel::SystemDynamicVariables( );
1659 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1660 newState->nonStrokingColor_ = color_;
1661 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1662 return;
1665 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1667 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1668 newState->nonStrokingColor_ = color_;
1669 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1670 return;
1673 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1675 if( newState->nonStrokingColor_ != NullPtr< const Lang::Color >( ) )
1677 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1680 newState->nonStrokingColor_ = color_;
1681 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1684 void
1685 Lang::NonStrokingBinding::show( std::ostream & os ) const
1687 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1688 color_->show( os );
1691 void
1692 Lang::NonStrokingBinding::gcMark( Kernel::GCMarkedSet & marked )
1694 const_cast< Lang::Color * >( color_.getPtr( ) )->gcMark( marked );
1699 Kernel::NonStrokingDynamicVariableProperties::NonStrokingDynamicVariableProperties( const char * name )
1700 : Kernel::DynamicVariableProperties( name )
1703 Kernel::NonStrokingDynamicVariableProperties::~NonStrokingDynamicVariableProperties( )
1706 Kernel::VariableHandle
1707 Kernel::NonStrokingDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1709 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1710 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->nonStrokingColor_ ) );
1713 void
1714 Kernel::NonStrokingDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1718 RefCountPtr< const Lang::Color > color = val->tryVal< const Lang::Color >( );
1719 Kernel::ContRef cont = evalState->cont_;
1720 cont->takeValue( Kernel::ValueRef( new Lang::NonStrokingBinding( name_, bindingExpr, color ) ),
1721 evalState );
1722 return;
1724 catch( const NonLocalExit::NotThisType & ball )
1726 /* never mind */
1731 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1732 Kernel::ContRef cont = evalState->cont_;
1733 cont->takeValue( Kernel::ValueRef( new Lang::NonStrokingBinding( name_, bindingExpr, RefCountPtr< const Lang::Color >( new Lang::Gray( -1 ) ) ) ),
1734 evalState );
1735 return;
1737 catch( const NonLocalExit::NotThisType & ball )
1739 /* never mind */
1742 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Color::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1746 Lang::DashBinding::DashBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, RefCountPtr< const Lang::Dash > dash )
1747 : bindingExpr_( bindingExpr ), dash_( dash ), id_( id )
1750 Lang::DashBinding::~DashBinding( )
1753 void
1754 Lang::DashBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1756 if( *sysBindings == 0 )
1758 *sysBindings = new Kernel::SystemDynamicVariables( );
1759 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1760 newState->dash_ = dash_;
1761 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1762 return;
1765 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1767 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1768 newState->dash_ = dash_;
1769 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1770 return;
1773 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1775 if( newState->dash_ != NullPtr< const Lang::Dash >( ) )
1777 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1780 newState->dash_ = dash_;
1781 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1784 void
1785 Lang::DashBinding::show( std::ostream & os ) const
1787 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1788 dash_->show( os );
1791 void
1792 Lang::DashBinding::gcMark( Kernel::GCMarkedSet & marked )
1794 const_cast< Lang::Dash * >( dash_.getPtr( ) )->gcMark( marked );
1799 Kernel::DashDynamicVariableProperties::DashDynamicVariableProperties( const char * _name )
1800 : Kernel::DynamicVariableProperties( _name )
1803 Kernel::DashDynamicVariableProperties::~DashDynamicVariableProperties( )
1806 Kernel::VariableHandle
1807 Kernel::DashDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1809 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1810 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->dash_ ) );
1813 void
1814 Kernel::DashDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1818 RefCountPtr< const Lang::Dash > dash = val->tryVal< const Lang::Dash >( );
1819 Kernel::ContRef cont = evalState->cont_;
1820 cont->takeValue( Kernel::ValueRef( new Lang::DashBinding( name_, bindingExpr, dash ) ),
1821 evalState );
1822 return;
1824 catch( const NonLocalExit::NotThisType & ball )
1826 /* never mind */
1831 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1832 Kernel::ContRef cont = evalState->cont_;
1833 cont->takeValue( Kernel::ValueRef( new Lang::DashBinding( name_, bindingExpr, RefCountPtr< const Lang::Dash >( new Lang::Dash( RefCountPtr< std::list< Concrete::Length > >( new std::list< Concrete::Length >( ) ), 0, -1 ) ) ) ),
1834 evalState );
1835 return;
1837 catch( const NonLocalExit::NotThisType & ball )
1839 /* never mind */
1842 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Dash::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1847 Lang::CapStyleBinding::CapStyleBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, const Lang::CapStyle::ValueType & cap )
1848 : bindingExpr_( bindingExpr ), cap_( cap ), id_( id )
1851 Lang::CapStyleBinding::~CapStyleBinding( )
1854 void
1855 Lang::CapStyleBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1857 if( *sysBindings == 0 ) {
1858 *sysBindings = new Kernel::SystemDynamicVariables( );
1859 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1860 newState->cap_ = cap_;
1861 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1862 return;
1865 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1867 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1868 newState->cap_ = cap_;
1869 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1870 return;
1873 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1875 if( newState->cap_ != Lang::CapStyle::CAP_UNDEFINED )
1877 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1880 newState->cap_ = cap_;
1881 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1884 void
1885 Lang::CapStyleBinding::show( std::ostream & os ) const
1887 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
1888 << "<internal-enum>" ;
1891 void
1892 Lang::CapStyleBinding::gcMark( Kernel::GCMarkedSet & marked )
1897 Kernel::CapStyleDynamicVariableProperties::CapStyleDynamicVariableProperties( const char * name )
1898 : Kernel::DynamicVariableProperties( name )
1901 Kernel::CapStyleDynamicVariableProperties::~CapStyleDynamicVariableProperties( )
1904 Kernel::VariableHandle
1905 Kernel::CapStyleDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1907 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1908 return Helpers::newValHandle( new Lang::CapStyle( graphicsState->cap_ ) );
1911 void
1912 Kernel::CapStyleDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1916 RefCountPtr< const Lang::CapStyle > cap = val->tryVal< const Lang::CapStyle >( );
1917 Kernel::ContRef cont = evalState->cont_;
1918 cont->takeValue( Kernel::ValueRef( new Lang::CapStyleBinding( name_, bindingExpr, cap->cap_ ) ),
1919 evalState );
1920 return;
1922 catch( const NonLocalExit::NotThisType & ball )
1924 /* never mind */
1929 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1930 Kernel::ContRef cont = evalState->cont_;
1931 cont->takeValue( Kernel::ValueRef( new Lang::CapStyleBinding( name_, bindingExpr, Lang::CapStyle::CAP_SAME ) ),
1932 evalState );
1933 return;
1935 catch( const NonLocalExit::NotThisType & ball )
1937 /* never mind */
1940 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::CapStyle::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1944 Lang::JoinStyleBinding::JoinStyleBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, const Lang::JoinStyle::ValueType & join )
1945 : bindingExpr_( bindingExpr ), join_( join ), id_( id )
1948 Lang::JoinStyleBinding::~JoinStyleBinding( )
1951 void
1952 Lang::JoinStyleBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1954 if( *sysBindings == 0 ) {
1955 *sysBindings = new Kernel::SystemDynamicVariables( );
1956 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1957 newState->join_ = join_;
1958 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1959 return;
1962 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1964 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1965 newState->join_ = join_;
1966 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1967 return;
1970 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1972 if( newState->join_ != Lang::JoinStyle::JOIN_UNDEFINED )
1974 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1977 newState->join_ = join_;
1978 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1981 void
1982 Lang::JoinStyleBinding::show( std::ostream & os ) const
1984 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
1985 << "<internal-enum>" ;
1988 void
1989 Lang::JoinStyleBinding::gcMark( Kernel::GCMarkedSet & marked )
1994 Kernel::JoinStyleDynamicVariableProperties::JoinStyleDynamicVariableProperties( const char * name )
1995 : Kernel::DynamicVariableProperties( name )
1998 Kernel::JoinStyleDynamicVariableProperties::~JoinStyleDynamicVariableProperties( )
2001 Kernel::VariableHandle
2002 Kernel::JoinStyleDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
2004 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
2005 return Helpers::newValHandle( new Lang::JoinStyle( graphicsState->join_ ) );
2008 void
2009 Kernel::JoinStyleDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
2013 RefCountPtr< const Lang::JoinStyle > join = val->tryVal< const Lang::JoinStyle >( );
2014 Kernel::ContRef cont = evalState->cont_;
2015 cont->takeValue( Kernel::ValueRef( new Lang::JoinStyleBinding( name_, bindingExpr, join->join_ ) ),
2016 evalState );
2017 return;
2019 catch( const NonLocalExit::NotThisType & ball )
2021 /* never mind */
2026 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
2027 Kernel::ContRef cont = evalState->cont_;
2028 cont->takeValue( Kernel::ValueRef( new Lang::JoinStyleBinding( name_, bindingExpr, Lang::JoinStyle::JOIN_SAME ) ),
2029 evalState );
2030 return;
2032 catch( const NonLocalExit::NotThisType & ball )
2034 /* never mind */
2037 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::JoinStyle::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
2041 Lang::BlendModeBinding::BlendModeBinding( const char * id, const Ast::DynamicBindingExpression * bindingExpr, const Lang::BlendMode::ValueType & blend )
2042 : bindingExpr_( bindingExpr ), blend_( blend ), id_( id )
2045 Lang::BlendModeBinding::~BlendModeBinding( )
2048 void
2049 Lang::BlendModeBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
2051 if( *sysBindings == 0 ) {
2052 *sysBindings = new Kernel::SystemDynamicVariables( );
2053 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
2054 newState->blend_ = blend_;
2055 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
2056 return;
2059 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
2061 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
2062 newState->blend_ = blend_;
2063 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
2064 return;
2067 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
2069 if( newState->blend_ != Lang::BlendMode::BLEND_UNDEFINED )
2071 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
2074 newState->blend_ = blend_;
2075 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
2078 void
2079 Lang::BlendModeBinding::show( std::ostream & os ) const
2081 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
2082 << "<internal-enum>" ;
2085 void
2086 Lang::BlendModeBinding::gcMark( Kernel::GCMarkedSet & marked )
2091 Kernel::BlendModeDynamicVariableProperties::BlendModeDynamicVariableProperties( const char * _name )
2092 : Kernel::DynamicVariableProperties( _name )
2095 Kernel::BlendModeDynamicVariableProperties::~BlendModeDynamicVariableProperties( )
2098 Kernel::VariableHandle
2099 Kernel::BlendModeDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
2101 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
2102 return Helpers::newValHandle( new Lang::BlendMode( graphicsState->blend_ ) );
2105 void
2106 Kernel::BlendModeDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
2110 RefCountPtr< const Lang::BlendMode > blend = val->tryVal< const Lang::BlendMode >( );
2111 Kernel::ContRef cont = evalState->cont_;
2112 cont->takeValue( Kernel::ValueRef( new Lang::BlendModeBinding( name_, bindingExpr, blend->mode_ ) ),
2113 evalState );
2114 return;
2116 catch( const NonLocalExit::NotThisType & ball )
2118 /* never mind */
2123 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
2124 Kernel::ContRef cont = evalState->cont_;
2125 cont->takeValue( Kernel::ValueRef( new Lang::BlendModeBinding( name_, bindingExpr, Lang::BlendMode::BLEND_SAME ) ),
2126 evalState );
2127 return;
2129 catch( const NonLocalExit::NotThisType & ball )
2131 /* never mind */
2134 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::BlendMode::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
2139 Lang::ColorSpace::ColorSpace( )
2142 Lang::ColorSpace::~ColorSpace( )
2145 RefCountPtr< const Lang::Class > Lang::ColorSpace::TypeID( new Lang::SystemFinalClass( strrefdup( "ColorSpace" ) ) );
2146 TYPEINFOIMPL( ColorSpace );
2150 Lang::InheritedColorSpace::InheritedColorSpace( )
2153 Lang::InheritedColorSpace::~InheritedColorSpace( )
2156 RefCountPtr< SimplePDF::PDF_Name >
2157 Lang::InheritedColorSpace::name( ) const
2159 throw Exceptions::InternalError( "InheritedColorSpace::name was invoked." );
2162 size_t
2163 Lang::InheritedColorSpace::numberOfComponents( ) const
2165 throw Exceptions::InternalError( "InheritedColorSpace::numerOfComponents was invoked." );
2168 bool
2169 Lang::InheritedColorSpace::containsColor( const Lang::Color * col ) const
2171 throw Exceptions::InternalError( "InheritedColorSpace::containsColor was invoked." );
2175 Kernel::Auto_qQ::Auto_qQ( Kernel::GraphicsState * graphicsState, Kernel::TextState * textState, std::ostream & os, bool active )
2176 : graphicsState_( graphicsState ), graphicsEnterState_( 0 ), textState_( textState ), textEnterState_( 0 ), os_( os ), activated_( false )
2178 if( active )
2180 activate( );
2184 void
2185 Kernel::Auto_qQ::activate( )
2187 if( activated_ )
2189 throw Exceptions::InternalError( "Multiple activation of Auto_qQ." );
2191 activated_ = true;
2192 graphicsEnterState_ = new Kernel::GraphicsState( *graphicsState_ );
2193 textEnterState_ = new Kernel::TextState( *textState_ );
2194 os_ << "q" << std::endl ;
2197 Kernel::Auto_qQ::~Auto_qQ( )
2199 if( activated_ )
2201 *graphicsState_ = *graphicsEnterState_;
2202 delete graphicsEnterState_;
2203 *textState_ = *textEnterState_;
2204 delete textEnterState_;
2205 os_ << "Q" << std::endl ;