Update procedures
[shapes.git] / source / statetypes.cc
blobaafb13ee934c244a1c0808b11926a928d05872c8
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 <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 Ast::PlacedIdentifier * 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 << Interaction::DYNAMIC_VARIABLE_PREFIX << 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 Ast::PlacedIdentifier * id_;
224 const Ast::DynamicBindingExpression * bindingExpr_;
225 Kernel::ContRef cont_;
226 public:
227 UserDynamicBindingContinuation( const Ast::SourceLocation & traceLoc, const Kernel::DynamicEnvironmentKeyType & key, const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Kernel::ContRef & cont )
228 : Kernel::Continuation( traceLoc ), key_( key ), id_( id ), 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_, id_, 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 Ast::PlacedIdentifier * id, const Kernel::DynamicEnvironmentKeyType & key, const RefCountPtr< const Lang::Function > & filter, const Kernel::VariableHandle & defaultVal )
256 : DynamicVariableProperties( id ), 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_, id_, bindingExpr, val ) ),
282 evalState );
283 return;
286 evalState->cont_ = Kernel::ContRef( new Kernel::UserDynamicBindingContinuation( bindingExpr->exprLoc( ), key_, id_, bindingExpr, evalState->cont_ ) );
288 filter_->call( filter_, evalState, val, bindingExpr->exprLoc( ) );
292 Kernel::UserDynamicStateProperties::UserDynamicStateProperties( const Ast::PlacedIdentifier * id, const Kernel::PassedEnv & defaultStateEnv, Kernel::PassedDyn defaultStateDyn, Ast::StateReference * defaultState )
293 : DynamicStateProperties( id ),
294 // key_( key ),
295 defaultStateEnv_( defaultStateEnv ), defaultStateDyn_( defaultStateDyn ), defaultState_( defaultState )
298 Kernel::UserDynamicStateProperties::~UserDynamicStateProperties( )
301 Kernel::StateHandle
302 Kernel::UserDynamicStateProperties::fetch( const Kernel::PassedDyn & dyn ) const
306 throw Exceptions::NotImplemented( "Fetching dynamic states" );
307 // return dyn->getStateHandle( key_ );
309 catch( const NonLocalExit::DynamicBindingNotFound & ball )
311 return defaultState_->getHandle( defaultStateEnv_, defaultStateDyn_ );
315 void
316 Kernel::UserDynamicStateProperties::makeBinding( Kernel::StateHandle val, const Ast::DynamicStateBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
318 throw Exceptions::NotImplemented( "Creation of dynamic state bindings" );
323 Lang::WidthBinding::WidthBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, Concrete::Length val )
324 : bindingExpr_( bindingExpr ), val_( val ), id_( id )
327 Lang::WidthBinding::~WidthBinding( )
330 void
331 Lang::WidthBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
333 if( *sysBindings == 0 )
335 *sysBindings = new Kernel::SystemDynamicVariables( );
336 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
337 newState->width_ = val_;
338 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
339 return;
342 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
344 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
345 newState->width_ = val_;
346 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
347 return;
350 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
352 if( ! IS_NAN( newState->width_ ) )
354 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
357 newState->width_ = val_;
358 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
361 void
362 Lang::WidthBinding::show( std::ostream & os ) const
364 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
365 << double( val_.offtype< 1, 0 >( ) ) * Interaction::displayUnitFactor << Interaction::displayUnitName ;
368 void
369 Lang::WidthBinding::gcMark( Kernel::GCMarkedSet & marked )
374 Kernel::WidthDynamicVariableProperties::WidthDynamicVariableProperties( const Ast::PlacedIdentifier * id )
375 : Kernel::DynamicVariableProperties( id )
378 Kernel::WidthDynamicVariableProperties::~WidthDynamicVariableProperties( )
381 Kernel::VariableHandle
382 Kernel::WidthDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
384 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
385 return Kernel::VariableHandle( new Kernel::Variable( RefCountPtr< const Lang::Value >( new Lang::Length( graphicsState->width_ ) ) ) );
388 void
389 Kernel::WidthDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
393 RefCountPtr< const Lang::Length > len = val->tryVal< const Lang::Length >( );
394 if( len->getScalar( ) < 0 )
396 throw Exceptions::OutOfRange( bindingExpr->exprLoc( ), strrefdup( "The length must be non-negative." ) );
398 Kernel::ContRef cont = evalState->cont_;
399 cont->takeValue( Kernel::ValueRef( new Lang::WidthBinding( id_, bindingExpr, len->get( ) ) ),
400 evalState );
401 return;
403 catch( const NonLocalExit::NotThisType & ball )
405 /* never mind */
410 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
411 Kernel::ContRef cont = evalState->cont_;
412 cont->takeValue( Kernel::ValueRef( new Lang::WidthBinding( id_, bindingExpr, Concrete::Length( -1 ) ) ),
413 evalState );
414 return;
416 catch( const NonLocalExit::NotThisType & ball )
418 /* never mind */
421 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Length::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
425 Lang::MiterLimitBinding::MiterLimitBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, double val )
426 : bindingExpr_( bindingExpr ), val_( val ), id_( id )
429 Lang::MiterLimitBinding::~MiterLimitBinding( )
432 void
433 Lang::MiterLimitBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
435 if( *sysBindings == 0 )
437 *sysBindings = new Kernel::SystemDynamicVariables( );
438 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
439 newState->miterLimit_ = val_;
440 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
441 return;
444 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
446 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
447 newState->miterLimit_ = val_;
448 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
449 return;
452 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
454 if( ! IS_NAN( newState->miterLimit_ ) )
456 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
459 newState->miterLimit_ = val_;
460 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
463 void
464 Lang::MiterLimitBinding::show( std::ostream & os ) const
466 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
467 if( val_ >= 0 )
469 os << val_ ;
471 else
473 Lang::THE_VOID->show( os );
477 void
478 Lang::MiterLimitBinding::gcMark( Kernel::GCMarkedSet & marked )
483 Kernel::MiterLimitDynamicVariableProperties::MiterLimitDynamicVariableProperties( const Ast::PlacedIdentifier * id )
484 : Kernel::DynamicVariableProperties( id )
487 Kernel::MiterLimitDynamicVariableProperties::~MiterLimitDynamicVariableProperties( )
490 Kernel::VariableHandle
491 Kernel::MiterLimitDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
493 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
494 return Kernel::VariableHandle( new Kernel::Variable( RefCountPtr< const Lang::Value >( new Lang::Float( graphicsState->miterLimit_ ) ) ) );
497 void
498 Kernel::MiterLimitDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
502 double lim = val->tryVal< const Lang::Float >( )->val_;
503 if( lim < 1 )
505 throw Exceptions::OutOfRange( bindingExpr->exprLoc( ), strrefdup( "The miter limit must be at least 1. Change the join style rather than the miter limit if you always want bevel joins." ) );
507 Kernel::ContRef cont = evalState->cont_;
508 cont->takeValue( Kernel::ValueRef( new Lang::MiterLimitBinding( id_, bindingExpr, lim ) ),
509 evalState );
510 return;
512 catch( const NonLocalExit::NotThisType & ball )
514 /* never mind */
519 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
520 Kernel::ContRef cont = evalState->cont_;
521 cont->takeValue( Kernel::ValueRef( new Lang::MiterLimitBinding( id_, bindingExpr, -1 ) ),
522 evalState );
523 return;
525 catch( const NonLocalExit::NotThisType & ball )
527 /* never mind */
530 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Float::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
534 Lang::CapStyle::CapStyle( const Lang::CapStyle::ValueType & cap )
535 : cap_( cap )
538 RefCountPtr< const Lang::Class > Lang::CapStyle::TypeID( new Lang::SystemFinalClass( strrefdup( "CapStyle" ) ) );
539 TYPEINFOIMPL( CapStyle );
542 Lang::JoinStyle::JoinStyle( const Lang::JoinStyle::ValueType & join )
543 : join_( join )
546 RefCountPtr< const Lang::Class > Lang::JoinStyle::TypeID( new Lang::SystemFinalClass( strrefdup( "JoinStyle" ) ) );
547 TYPEINFOIMPL( JoinStyle );
550 Lang::BlendMode::BlendMode( const Lang::BlendMode::ValueType & mode )
551 : mode_( mode )
554 RefCountPtr< const Lang::Class > Lang::BlendMode::TypeID( new Lang::SystemFinalClass( strrefdup( "BlendMode" ) ) );
555 TYPEINFOIMPL( BlendMode );
557 std::map< Lang::BlendMode::ValueType, RefCountPtr< SimplePDF::PDF_Object > > Lang::BlendMode::resourceMap;
559 void
560 Lang::BlendMode::applyGraphicsState( std::ostream & os, SimplePDF::PDF_Resources * resources, const Lang::BlendMode::ValueType & mode )
562 typedef typeof resourceMap MapType;
563 MapType::const_iterator i = resourceMap.find( mode );
564 if( i != resourceMap.end( ) )
566 os << resources->nameofGraphicsState( i->second ) << " gs " ;
568 else
570 RefCountPtr< SimplePDF::PDF_Dictionary > dic;
571 (*dic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
573 RefCountPtr< SimplePDF::PDF_Object > indirection = SimplePDF::indirect( dic, & Kernel::theIndirectObjectCount );
574 resourceMap.insert( MapType::value_type( mode, indirection ) );
575 switch( mode )
577 case NORMAL:
578 (*dic)[ "BM" ] = SimplePDF::newName( "Normal" );
579 break;
580 case MULTIPLY:
581 (*dic)[ "BM" ] = SimplePDF::newName( "Multiply" );
582 break;
583 case SCREEN:
584 (*dic)[ "BM" ] = SimplePDF::newName( "Screen" );
585 break;
586 case OVERLAY:
587 (*dic)[ "BM" ] = SimplePDF::newName( "Overlay" );
588 break;
589 case DARKEN:
590 (*dic)[ "BM" ] = SimplePDF::newName( "Darken" );
591 break;
592 case LIGHTEN:
593 (*dic)[ "BM" ] = SimplePDF::newName( "Lighten" );
594 break;
595 case COLOR_DODGE:
596 (*dic)[ "BM" ] = SimplePDF::newName( "ColorDodge" );
597 break;
598 case COLOR_BURN:
599 (*dic)[ "BM" ] = SimplePDF::newName( "ColorBurn" );
600 break;
601 case HARD_LIGHT:
602 (*dic)[ "BM" ] = SimplePDF::newName( "HardLight" );
603 break;
604 case SOFT_LIGHT:
605 (*dic)[ "BM" ] = SimplePDF::newName( "SoftLight" );
606 break;
607 case DIFFERENCE:
608 (*dic)[ "BM" ] = SimplePDF::newName( "Difference" );
609 break;
610 case EXCLUSION:
611 (*dic)[ "BM" ] = SimplePDF::newName( "Exclusion" );
612 break;
613 case HUE:
614 (*dic)[ "BM" ] = SimplePDF::newName( "Hue" );
615 break;
616 case SATURATION:
617 (*dic)[ "BM" ] = SimplePDF::newName( "Saturation" );
618 break;
619 case COLOR:
620 (*dic)[ "BM" ] = SimplePDF::newName( "Color" );
621 break;
622 case LUMINOSITY:
623 (*dic)[ "BM" ] = SimplePDF::newName( "Luminosity" );
624 break;
625 case BLEND_SAME:
626 // We leave the graphics state dictionary empty!
627 break;
628 default:
629 throw Exceptions::InternalError( strrefdup( "BlendMode switch out of range." ) );
631 os << resources->nameofGraphicsState( indirection ) << " gs " ;
636 Kernel::GraphicsState::GraphicsState( )
637 : strokingColor_( NullPtr< const Lang::Color >( ) ),
638 nonStrokingColor_( NullPtr< const Lang::Color >( ) ),
639 width_( std::numeric_limits< double >::signaling_NaN( ) ),
640 cap_( Lang::CapStyle::CAP_UNDEFINED ),
641 join_( Lang::JoinStyle::JOIN_UNDEFINED ),
642 miterLimit_( std::numeric_limits< double >::signaling_NaN( ) ),
643 dash_( NullPtr< const Lang::Dash >( ) ),
644 blend_( Lang::BlendMode::BLEND_UNDEFINED ),
645 alphaIsShape_( true ),
646 strokingAlpha_( NullPtr< const Lang::Alpha >( ) ),
647 nonStrokingAlpha_( NullPtr< const Lang::Alpha >( ) )
650 Kernel::GraphicsState::GraphicsState( const Kernel::GraphicsState & orig )
651 : strokingColor_( orig.strokingColor_ ),
652 nonStrokingColor_( orig.nonStrokingColor_ ),
653 width_( orig.width_ ),
654 cap_( orig.cap_ ),
655 join_( orig.join_ ),
656 miterLimit_( orig.miterLimit_ ),
657 dash_( orig.dash_ ),
658 blend_( orig.blend_ ),
659 alphaIsShape_( orig.alphaIsShape_ ),
660 strokingAlpha_( orig.strokingAlpha_ ),
661 nonStrokingAlpha_( orig.nonStrokingAlpha_ )
664 Kernel::GraphicsState::GraphicsState( const Kernel::GraphicsState & newValues, const Kernel::GraphicsState & oldValues )
665 : strokingColor_( oldValues.strokingColor_ ),
666 nonStrokingColor_( oldValues.nonStrokingColor_ ),
667 width_( oldValues.width_ ),
668 cap_( oldValues.cap_ ),
669 join_( oldValues.join_ ),
670 miterLimit_( oldValues.miterLimit_ ),
671 dash_( oldValues.dash_ ),
672 blend_( oldValues.blend_ ),
673 alphaIsShape_( oldValues.alphaIsShape_ ),
674 strokingAlpha_( oldValues.strokingAlpha_ ),
675 nonStrokingAlpha_( oldValues.nonStrokingAlpha_ )
677 if( newValues.strokingColor_ != NullPtr< const Lang::Color >( ) )
679 strokingColor_ = newValues.strokingColor_;
681 if( newValues.nonStrokingColor_ != NullPtr< const Lang::Color >( ) )
683 nonStrokingColor_ = newValues.nonStrokingColor_;
685 if( ! IS_NAN( newValues.width_ ) )
687 width_ = newValues.width_;
689 if( newValues.cap_ != Lang::CapStyle::CAP_UNDEFINED )
691 cap_ = newValues.cap_;
693 if( newValues.join_ != Lang::JoinStyle::JOIN_UNDEFINED )
695 join_ = newValues.join_;
697 if( ! IS_NAN( newValues.miterLimit_ ) )
699 miterLimit_ = newValues.miterLimit_;
701 if( newValues.dash_ != NullPtr< const Lang::Dash >( ) )
703 dash_ = newValues.dash_;
705 if( newValues.blend_ != Lang::BlendMode::BLEND_UNDEFINED )
707 blend_ = newValues.blend_;
709 if( newValues.strokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
711 strokingAlpha_ = newValues.strokingAlpha_;
712 alphaIsShape_ = newValues.alphaIsShape_;
714 if( newValues.nonStrokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
716 nonStrokingAlpha_ = newValues.nonStrokingAlpha_;
717 alphaIsShape_ = newValues.alphaIsShape_;
721 Kernel::GraphicsState::GraphicsState( bool setDefaults )
722 : strokingColor_( Lang::THE_BLACK ),
723 nonStrokingColor_( Lang::THE_BLACK ),
724 width_( 1 ),
725 cap_( Lang::CapStyle::CAP_BUTT ),
726 join_( Lang::JoinStyle::JOIN_MITER ),
727 miterLimit_( 10 ),
728 dash_( Lang::THE_SOLID_DASH ),
729 blend_( Lang::BlendMode::NORMAL ),
730 alphaIsShape_( false ),
731 strokingAlpha_( Lang::THE_OPAQUE ),
732 nonStrokingAlpha_( Lang::THE_OPAQUE )
734 if( ! setDefaults )
736 throw Exceptions::InternalError( strrefdup( "setDefaults must be true in GraphicsState::GraphicsState." ) );
740 Kernel::GraphicsState::~GraphicsState( )
743 void
744 Kernel::GraphicsState::print( std::ostream & os, const std::string & indentation ) const
746 if( ! IS_NAN( width_ ) )
748 os << indentation ;
749 Lang::DYNAMIC_VARIABLE_ID_WIDTH.show( os, Ast::Identifier::DYNAMIC_VARIABLE );
750 os << ": " << width_ / Interaction::displayUnit << Interaction::displayUnitName << std::endl ;
752 if( strokingColor_ != NullPtr< const Lang::Color >( ) )
754 os << indentation ;
755 Lang::DYNAMIC_VARIABLE_ID_STROKING.show( os, Ast::Identifier::DYNAMIC_VARIABLE );
756 os << ": " ;
757 strokingColor_->show( os );
758 os << std::endl ;
760 if( nonStrokingColor_ != NullPtr< const Lang::Color >( ) )
762 os << indentation ;
763 Lang::DYNAMIC_VARIABLE_ID_NONSTROKING.show( os, Ast::Identifier::DYNAMIC_VARIABLE );
764 os << ": " ;
765 nonStrokingColor_->show( os );
766 os << std::endl ;
768 os << "(and a bunch of other variables...)" << std::endl ;
771 bool
772 Kernel::GraphicsState::synchStrokingColor( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
774 if( force || strokingColor_ != ref->strokingColor_ )
776 if( ref->strokingColor_ == NullPtr< const Lang::Color >( ) )
778 return false;
780 strokingColor_ = ref->strokingColor_;
781 strokingColor_->setStroking( os );
782 return true;
784 return false;
787 bool
788 Kernel::GraphicsState::synchNonStrokingColor( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
790 if( force || nonStrokingColor_ != ref->nonStrokingColor_ )
792 if( ref->nonStrokingColor_ == NullPtr< const Lang::Color >( ) )
794 return false;
796 nonStrokingColor_ = ref->nonStrokingColor_;
797 nonStrokingColor_->setNonStroking( os );
798 return true;
800 return false;
803 bool
804 Kernel::GraphicsState::synchStrokingAlpha( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
806 if( force || strokingAlpha_ != ref->strokingAlpha_ || alphaIsShape_ != ref->strokingAlpha_->isShape_ )
808 if( ref->strokingAlpha_ == NullPtr< const Lang::Alpha >( ) )
810 return false;
812 strokingAlpha_ = ref->strokingAlpha_;
813 alphaIsShape_ = strokingAlpha_->isShape_;
815 const SimplePDF::PDF_Version::Version ALPHA_VERSION = SimplePDF::PDF_Version::PDF_1_4;
816 if( Kernel::the_PDF_version.greaterOrEqual( ALPHA_VERSION ) )
818 Lang::Alpha::applyGraphicsState( os, resources, *strokingAlpha_, true );
819 return true;
821 else
823 Kernel::the_PDF_version.message( ALPHA_VERSION, "The graphics state stroking alpha setting was ignored." );
826 return false;
829 bool
830 Kernel::GraphicsState::synchNonStrokingAlpha( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
832 if( force || nonStrokingAlpha_ != ref->nonStrokingAlpha_ || alphaIsShape_ != ref->nonStrokingAlpha_->isShape_ )
834 if( ref->nonStrokingAlpha_ == NullPtr< const Lang::Alpha >( ) )
836 return false;
838 nonStrokingAlpha_ = ref->nonStrokingAlpha_;
839 alphaIsShape_ = nonStrokingAlpha_->isShape_;
841 const SimplePDF::PDF_Version::Version ALPHA_VERSION = SimplePDF::PDF_Version::PDF_1_4;
842 if( Kernel::the_PDF_version.greaterOrEqual( ALPHA_VERSION ) )
844 Lang::Alpha::applyGraphicsState( os, resources, *nonStrokingAlpha_, false );
845 return true;
847 else
849 Kernel::the_PDF_version.message( ALPHA_VERSION, "The graphics state non-stroking alpha setting was ignored." );
852 return false;
855 bool
856 Kernel::GraphicsState::synchWidth( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
858 if( force || width_ != ref->width_ )
860 if( IS_NAN( ref->width_ ) ||
861 ref->width_ < Concrete::ZERO_LENGTH )
863 return false;
865 width_ = ref->width_;
866 os << width_.offtype< 1, 0 >( ) << " w " ;
867 return true;
869 return false;
872 bool
873 Kernel::GraphicsState::synchCap( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
875 if( force || cap_ != ref->cap_ )
877 if( ref->cap_ != Lang::CapStyle::CAP_UNDEFINED &&
878 ref->cap_ != Lang::CapStyle::CAP_SAME )
880 cap_ = ref->cap_;
881 os << cap_ << " J " ;
882 return true;
885 return false;
888 bool
889 Kernel::GraphicsState::synchJoin( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
891 if( force || join_ != ref->join_ )
893 if( ref->join_ != Lang::JoinStyle::JOIN_UNDEFINED &&
894 ref->join_ != Lang::JoinStyle::JOIN_SAME )
896 join_ = ref->join_;
897 os << join_ << " j " ;
898 return true;
901 return false;
904 bool
905 Kernel::GraphicsState::synchMiterLimit( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
907 if( force || miterLimit_ != ref->miterLimit_ )
909 if( IS_NAN( ref->miterLimit_ ) ||
910 ref->miterLimit_ < 0 )
912 return false;
914 miterLimit_ = ref->miterLimit_;
915 os << miterLimit_ << " M " ;
916 return true;
918 return false;
921 bool
922 Kernel::GraphicsState::synchDash( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
924 if( force || dash_ != ref->dash_ )
926 if( ref->dash_ == NullPtr< const Lang::Dash >( ) )
928 return false;
930 dash_ = ref->dash_;
931 dash_->setDash( os );
932 return true;
934 return false;
937 bool
938 Kernel::GraphicsState::synchBlend( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
940 if( force || blend_ != ref->blend_ )
942 if( ref->blend_ == Lang::BlendMode::BLEND_UNDEFINED )
944 return false;
946 blend_ = ref->blend_;
947 const SimplePDF::PDF_Version::Version BLEND_VERSION = SimplePDF::PDF_Version::PDF_1_4;
948 if( Kernel::the_PDF_version.greaterOrEqual( BLEND_VERSION ) )
950 Lang::BlendMode::applyGraphicsState( os, resources, blend_ );
951 return true;
953 else
955 Kernel::the_PDF_version.message( BLEND_VERSION, "The graphics state blend mode setting was ignored." );
958 return false;
962 bool
963 Kernel::GraphicsState::synchForStroke( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
965 bool anyChange = false;
966 anyChange = synchStrokingColor( os, ref, resources, force ) || anyChange;
967 anyChange = synchStrokingAlpha( os, ref, resources, force ) || anyChange;
968 anyChange = synchWidth( os, ref, resources, force ) || anyChange;
969 anyChange = synchCap( os, ref, resources, force ) || anyChange;
970 anyChange = synchJoin( os, ref, resources, force ) || anyChange;
971 anyChange = synchMiterLimit( os, ref, resources, force ) || anyChange;
972 anyChange = synchDash( os, ref, resources, force ) || anyChange;
973 if( anyChange )
975 os << std::endl ;
977 return anyChange;
980 bool
981 Kernel::GraphicsState::synchForNonStroke( std::ostream & os, const GraphicsState * ref, SimplePDF::PDF_Resources * resources, bool force )
983 bool anyChange = false;
984 anyChange = synchNonStrokingColor( os, ref, resources, force ) || anyChange;
985 anyChange = synchNonStrokingAlpha( os, ref, resources, force ) || anyChange;
986 if( anyChange )
988 os << std::endl ;
990 return anyChange;
993 bool
994 Kernel::GraphicsState::synchStrokingColorWithNonStrokingColor( std::ostream & os, SimplePDF::PDF_Resources * resources, Concrete::Length width )
996 bool anyChange = false;
998 if( ! IS_NAN( width ) && width_ != width )
1000 width_ = width;
1001 os << width_.offtype< 1, 0 >( ) << " w " ;
1002 anyChange = true;
1005 if( strokingColor_ != nonStrokingColor_ )
1007 strokingColor_ = nonStrokingColor_;
1008 strokingColor_->setStroking( os );
1011 if( anyChange )
1013 os << std::endl ;
1015 return anyChange;
1019 Lang::Alpha::Alpha( bool isShape, double a )
1020 : isShape_( isShape ), a_( a )
1023 Lang::Alpha::~Alpha( )
1026 RefCountPtr< const Lang::Class > Lang::Alpha::TypeID( new Lang::SystemFinalClass( strrefdup( "Alpha" ) ) );
1027 TYPEINFOIMPL( Alpha );
1029 void
1030 Lang::Alpha::applyGraphicsState( std::ostream & os, SimplePDF::PDF_Resources * resources, const Lang::Alpha & self, bool isStroking )
1032 typedef typeof strokingShapeResourcemap MapType;
1033 MapType * resourceMap;
1034 if( self.isShape_ )
1036 if( isStroking )
1038 resourceMap = & strokingShapeResourcemap;
1040 else
1042 resourceMap = & nonStrokingShapeResourcemap;
1045 else
1047 if( isStroking )
1049 resourceMap = & strokingOpacityResourcemap;
1051 else
1053 resourceMap = & nonStrokingOpacityResourcemap;
1056 MapType::const_iterator i = resourceMap->find( self.a_ );
1057 if( i != resourceMap->end( ) )
1059 os << resources->nameofGraphicsState( i->second ) << " gs " ;
1061 else
1063 RefCountPtr< SimplePDF::PDF_Dictionary > dic;
1064 (*dic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
1065 RefCountPtr< SimplePDF::PDF_Object > indirection = SimplePDF::indirect( dic, & Kernel::theIndirectObjectCount );
1067 resourceMap->insert( MapType::value_type( self.a_, indirection ) );
1068 if( self.a_ >= 0 )
1070 (*dic)[ "AIS" ] = SimplePDF::newBoolean( self.isShape_ );
1071 if( isStroking )
1073 (*dic)[ "CA" ] = SimplePDF::newFloat( self.a_ );
1075 else
1077 (*dic)[ "ca" ] = SimplePDF::newFloat( self.a_ );
1080 // If self.a_ < 0 we just leave the graphics state dictionary empty
1082 os << resources->nameofGraphicsState( indirection ) << " gs " ;
1086 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::strokingShapeResourcemap;
1087 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::strokingOpacityResourcemap;
1088 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::nonStrokingShapeResourcemap;
1089 std::map< double, RefCountPtr< SimplePDF::PDF_Object > > Lang::Alpha::nonStrokingOpacityResourcemap;
1092 Lang::AlphaBinding::AlphaBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const RefCountPtr< const Lang::Alpha > & alpha, bool isStroking )
1093 : bindingExpr_( bindingExpr ), alpha_( alpha ), isStroking_( isStroking ), id_( id )
1096 Lang::AlphaBinding::~AlphaBinding( )
1099 void
1100 Lang::AlphaBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1102 if( *sysBindings == 0 ) {
1103 *sysBindings = new Kernel::SystemDynamicVariables( );
1104 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1105 if( isStroking_ )
1107 newState->strokingAlpha_ = alpha_;
1109 else
1111 newState->nonStrokingAlpha_ = alpha_;
1113 newState->alphaIsShape_ = alpha_->isShape_;
1114 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1115 return;
1118 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1120 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1121 if( isStroking_ )
1123 newState->strokingAlpha_ = alpha_;
1125 else
1127 newState->nonStrokingAlpha_ = alpha_;
1129 newState->alphaIsShape_ = alpha_->isShape_;
1130 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1131 return;
1134 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1136 if( isStroking_ )
1138 if( newState->strokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
1140 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1142 newState->strokingAlpha_ = alpha_;
1144 else
1146 if( newState->nonStrokingAlpha_ != NullPtr< const Lang::Alpha >( ) )
1148 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1150 newState->nonStrokingAlpha_ = alpha_;
1152 newState->alphaIsShape_ = alpha_->isShape_;
1153 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1156 void
1157 Lang::AlphaBinding::show( std::ostream & os ) const
1159 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1160 alpha_->show( os );
1163 void
1164 Lang::AlphaBinding::gcMark( Kernel::GCMarkedSet & marked )
1166 const_cast< Lang::Alpha * >( alpha_.getPtr( ) )->gcMark( marked );
1171 Kernel::AlphaDynamicVariableProperties::AlphaDynamicVariableProperties( const Ast::PlacedIdentifier * id, bool isStroking )
1172 : Kernel::DynamicVariableProperties( id ), isStroking_( isStroking )
1175 Kernel::AlphaDynamicVariableProperties::~AlphaDynamicVariableProperties( )
1178 Kernel::VariableHandle
1179 Kernel::AlphaDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1181 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1182 if( isStroking_ )
1184 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->strokingAlpha_ ) );
1186 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->nonStrokingAlpha_ ) );
1189 void
1190 Kernel::AlphaDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1194 RefCountPtr< const Lang::Alpha > alpha = val->tryVal< const Lang::Alpha >( );
1195 Kernel::ContRef cont = evalState->cont_;
1196 cont->takeValue( Kernel::ValueRef( new Lang::AlphaBinding( id_, bindingExpr, alpha, isStroking_ ) ),
1197 evalState );
1198 return;
1200 catch( const NonLocalExit::NotThisType & ball )
1202 /* never mind */
1207 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1208 Kernel::ContRef cont = evalState->cont_;
1209 cont->takeValue( Kernel::ValueRef( new Lang::AlphaBinding( id_, bindingExpr, RefCountPtr< const Lang::Alpha >( new Lang::Alpha( true, -1 ) ), isStroking_ ) ),
1210 evalState );
1211 return;
1213 catch( const NonLocalExit::NotThisType & ball )
1215 /* never mind */
1218 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Alpha::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1222 Lang::SoftMask::SoftMask( )
1223 : graphicsStateResource_( NullPtr< SimplePDF::PDF_Object >( ) )
1225 static size_t callCount = 0;
1226 ++callCount;
1227 if( callCount > 2 )
1229 throw Exceptions::InternalError( strrefdup( "The None soft mask should be generated at most twice!" ) );
1232 RefCountPtr< SimplePDF::PDF_Dictionary > dic;
1233 graphicsStateResource_ = SimplePDF::indirect( dic, & Kernel::theIndirectObjectCount );
1235 (*dic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
1236 (*dic)[ "SMask" ] = SimplePDF::newName( "None" );
1239 Lang::SoftMask::SoftMask( SubType subType, const RefCountPtr< const Lang::TransparencyGroup > & tpGroup, const RefCountPtr< const Lang::Color > & background, const RefCountPtr< const Lang::PDF_Function > & transfer )
1240 : graphicsStateResource_( NullPtr< SimplePDF::PDF_Object >( ) )
1242 RefCountPtr< SimplePDF::PDF_Dictionary > gsDic;
1243 graphicsStateResource_ = SimplePDF::indirect( gsDic, & Kernel::theIndirectObjectCount );
1245 RefCountPtr< SimplePDF::PDF_Dictionary > smDic;
1247 (*gsDic)[ "Type" ] = SimplePDF::newName( "ExtGState" );
1248 (*gsDic)[ "SMask" ] = smDic;
1249 (*smDic)[ "G" ] = tpGroup->getPDF_Object( );
1251 switch( subType )
1253 case ALPHA:
1255 (*smDic)[ "S" ] = SimplePDF::newName( "Alpha" );
1256 if( background != NullPtr< const Lang::Color >( ) )
1258 throw Exceptions::InternalError( strrefdup( "Attempt to create Alpha soft mask with BC." ) );
1261 break;
1262 case LUMINOSITY:
1264 (*smDic)[ "S" ] = SimplePDF::newName( "Luminosity" );
1265 if( background != NullPtr< const Lang::Color >( ) )
1267 (*smDic)[ "BC" ] = background->componentVector( );
1268 if( ! tpGroup->colorSpace( )->containsColor( background.getPtr( ) ) )
1270 throw Exceptions::OutOfRange( "The background color is not in the transparency groups color space." );
1274 break;
1275 default:
1276 throw Exceptions::InternalError( strrefdup( "SoftMask::SoftMask: Enum switch out of range." ) );
1278 if( transfer != NullPtr< const Lang::PDF_Function >( ) )
1280 if( ! transfer->matchesDimensions( 1, 1 ) )
1282 throw Exceptions::InternalError( strrefdup( "SoftMask::SoftMask: The transfer function arity should be correct at this point." ) );
1284 (*smDic)[ "TR" ] = transfer->getFunction( );
1288 Lang::SoftMask::~SoftMask( )
1291 RefCountPtr< const Lang::Class > Lang::SoftMask::TypeID( new Lang::SystemFinalClass( strrefdup( "SoftMask" ) ) );
1292 TYPEINFOIMPL( SoftMask );
1295 Lang::Dash::Iterator::Iterator( RefCountPtr< std::list< Concrete::Length > > _pattern, double _scale, std::list< Concrete::Length >::const_iterator _i, bool _on, Concrete::Length _length )
1296 : mem_( _pattern ), begin_( _pattern->begin( ) ), end_( _pattern->end( ) ), scale_( _scale ), i_( _i ), on_( _on ), length_( _scale * _length )
1299 Lang::Dash::Iterator &
1300 Lang::Dash::Iterator::operator ++ ( )
1302 ++i_;
1303 if( i_ == end_ )
1305 i_ = begin_;
1306 on_ = true;
1308 else
1310 on_ = ! on_;
1312 length_ = scale_ * (*i_);
1313 return *this;
1316 bool
1317 Lang::Dash::Iterator::isOn( ) const
1319 return on_;
1322 Concrete::Length
1323 Lang::Dash::Iterator::getLength( ) const
1325 return length_;
1329 Lang::Dash::Dash( )
1330 : pattern_( new list< Concrete::Length >( ) ), phase_( 0 ), scale_( 1 )
1333 Lang::Dash::Dash( RefCountPtr< std::list< Concrete::Length > > _pattern, Concrete::Length _phase, double _scale )
1334 : pattern_( _pattern ), phase_( _phase ), scale_( _scale ), myLength_( 0 )
1336 for( list< Concrete::Length >::const_iterator i = pattern_->begin( ); i != pattern_->end( ); ++i )
1338 myLength_ += (*i);
1342 Lang::Dash::Dash( RefCountPtr< std::list< Concrete::Length > > _pattern, Concrete::Length _phase, double _scale, Concrete::Length _length )
1343 : pattern_( _pattern ), phase_( _phase ), scale_( _scale ), myLength_( _length )
1346 DISPATCHIMPL( Dash );
1348 Lang::Dash::~Dash( )
1351 RefCountPtr< const Lang::Class > Lang::Dash::TypeID( new Lang::SystemFinalClass( strrefdup( "Dash" ) ) );
1352 TYPEINFOIMPL( Dash );
1355 void
1356 Lang::Dash::setDash( ostream & os ) const
1358 // Negative scale means that the dash shall not be altered
1359 if( scale_ < 0 )
1361 return;
1364 os << "[ " ;
1365 for( list< Concrete::Length >::const_iterator i = pattern_->begin( ); i != pattern_->end( ); ++i )
1367 os << Concrete::Length::offtype( *i ) * scale_ << " " ;
1369 os << "] " << Concrete::Length::offtype( phase_ ) * scale_ << " d " ;
1372 RefCountPtr< SimplePDF::PDF_Vector >
1373 Lang::Dash::getDashArray( ) const
1375 if( scale_ < 0 )
1377 throw Exceptions::MiscellaneousRequirement( "The same-as-before dash cannot be represented in PDF." );
1380 RefCountPtr< SimplePDF::PDF_Vector > res = RefCountPtr< SimplePDF::PDF_Vector >( new SimplePDF::PDF_Vector );
1381 for( list< Concrete::Length >::const_iterator i = pattern_->begin( ); i != pattern_->end( ); ++i )
1383 res->vec.push_back( SimplePDF::newFloat( Concrete::Length::offtype( *i ) * scale_ ) );
1386 return res;
1389 RefCountPtr< const Lang::Dash >
1390 Lang::Dash::scaled( double factor ) const
1392 return RefCountPtr< const Lang::Dash >( new Lang::Dash( pattern_, phase_, scale_ * factor, myLength_ ) );
1395 RefCountPtr< const Lang::Dash >
1396 Lang::Dash::shifted( Concrete::Length dist ) const
1398 return RefCountPtr< const Lang::Dash >( new Lang::Dash( pattern_, phase_ + dist / scale_, scale_, myLength_ ) );
1401 Concrete::Length
1402 Lang::Dash::length( ) const
1404 return myLength_ * scale_;
1407 bool
1408 Lang::Dash::isSolid( ) const
1410 return pattern_->empty( );
1413 Lang::Dash::Iterator
1414 Lang::Dash::begin( ) const
1416 Concrete::Length tmpPhase = modPhysical( phase_, myLength_ );
1417 if( tmpPhase < 0 )
1419 tmpPhase += myLength_;
1421 std::list< Concrete::Length >::const_iterator i = pattern_->begin( );
1422 bool on = true;
1423 while( tmpPhase >= *i )
1425 tmpPhase -= *i;
1426 on = ! on;
1427 ++i;
1429 return Lang::Dash::Iterator( pattern_, scale_, i, on, *i - tmpPhase );
1432 Lang::Color::Color( )
1435 DISPATCHIMPL( Color );
1437 Lang::Color::~Color( )
1440 RefCountPtr< const Lang::Class > Lang::Color::TypeID = NullPtr< const Lang::Class >( ); /* The value is set in main */
1442 RefCountPtr< const char >
1443 Lang::Color::staticTypeName( )
1445 return TypeID->getPrettyName( );
1449 Lang::Gray::Gray( const Concrete::Gray & components )
1450 : components_( components )
1453 DISPATCHIMPL( Gray );
1455 Lang::Gray::~Gray( )
1458 RefCountPtr< const Lang::Class > Lang::Gray::TypeID( new Lang::SystemFinalClass( strrefdup( "Gray" ) ) );
1459 TYPEINFOIMPL( Gray );
1461 void
1462 Lang::Gray::show( std::ostream & os ) const
1464 os << "[gray " << components_.gr_ << "]" ;
1467 void
1468 Lang::Gray::setStroking( ostream & os ) const
1470 components_.setStroking( os );
1473 void
1474 Lang::Gray::setNonStroking( ostream & os ) const
1476 components_.setNonStroking( os );
1479 RefCountPtr< SimplePDF::PDF_Vector >
1480 Lang::Gray::componentVector( ) const
1482 return components_.componentVector( );
1486 Lang::RGB::RGB( const Concrete::RGB & components )
1487 : components_( components )
1490 DISPATCHIMPL( RGB );
1492 Lang::RGB::~RGB( )
1495 RefCountPtr< const Lang::Class > Lang::RGB::TypeID( new Lang::SystemFinalClass( strrefdup( "RGB" ) ) );
1496 TYPEINFOIMPL( RGB );
1498 void
1499 Lang::RGB::show( std::ostream & os ) const
1501 os << "[rgb " << components_.r_ << " " << components_.g_ << " " << components_.b_ << "]" ;
1504 void
1505 Lang::RGB::setStroking( ostream & os ) const
1507 components_.setStroking( os );
1510 void
1511 Lang::RGB::setNonStroking( ostream & os ) const
1513 components_.setNonStroking( os );
1516 RefCountPtr< SimplePDF::PDF_Vector >
1517 Lang::RGB::componentVector( ) const
1519 return components_.componentVector( );
1523 Lang::CMYK::CMYK( const Concrete::CMYK & components )
1524 : components_( components )
1527 DISPATCHIMPL( CMYK );
1529 Lang::CMYK::~CMYK( )
1532 RefCountPtr< const Lang::Class > Lang::CMYK::TypeID( new Lang::SystemFinalClass( strrefdup( "CMYK" ) ) );
1533 TYPEINFOIMPL( CMYK );
1535 void
1536 Lang::CMYK::show( std::ostream & os ) const
1538 os << "[cmyk " << components_.c_ << " " << components_.m_ << " " << components_.y_ << " " << components_.k_ << "]" ;
1541 void
1542 Lang::CMYK::setStroking( ostream & os ) const
1544 components_.setStroking( os );
1547 void
1548 Lang::CMYK::setNonStroking( ostream & os ) const
1550 components_.setNonStroking( os );
1553 RefCountPtr< SimplePDF::PDF_Vector >
1554 Lang::CMYK::componentVector( ) const
1556 return components_.componentVector( );
1560 Lang::StrokingBinding::StrokingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, RefCountPtr< const Lang::Color > color )
1561 : bindingExpr_( bindingExpr ), color_( color ), id_( id )
1564 Lang::StrokingBinding::~StrokingBinding( )
1567 void
1568 Lang::StrokingBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1570 if( *sysBindings == 0 )
1572 *sysBindings = new Kernel::SystemDynamicVariables( );
1573 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1574 newState->strokingColor_ = color_;
1575 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1576 return;
1579 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1581 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1582 newState->strokingColor_ = color_;
1583 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1584 return;
1587 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1589 if( newState->strokingColor_ != NullPtr< const Lang::Color >( ) )
1591 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1594 newState->strokingColor_ = color_;
1595 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1598 void
1599 Lang::StrokingBinding::show( std::ostream & os ) const
1601 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1602 color_->show( os );
1605 void
1606 Lang::StrokingBinding::gcMark( Kernel::GCMarkedSet & marked )
1608 const_cast< Lang::Color * >( color_.getPtr( ) )->gcMark( marked );
1613 Kernel::StrokingDynamicVariableProperties::StrokingDynamicVariableProperties( const Ast::PlacedIdentifier * id )
1614 : Kernel::DynamicVariableProperties( id )
1617 Kernel::StrokingDynamicVariableProperties::~StrokingDynamicVariableProperties( )
1620 Kernel::VariableHandle
1621 Kernel::StrokingDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1623 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1624 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->strokingColor_ ) );
1627 void
1628 Kernel::StrokingDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1632 RefCountPtr< const Lang::Color > color = val->tryVal< const Lang::Color >( );
1633 Kernel::ContRef cont = evalState->cont_;
1634 cont->takeValue( Kernel::ValueRef( new Lang::StrokingBinding( id_, bindingExpr, color ) ),
1635 evalState );
1636 return;
1638 catch( const NonLocalExit::NotThisType & ball )
1640 /* never mind */
1645 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1646 Kernel::ContRef cont = evalState->cont_;
1647 cont->takeValue( Kernel::ValueRef( new Lang::StrokingBinding( id_, bindingExpr, RefCountPtr< const Lang::Color >( new Lang::Gray( -1 ) ) ) ),
1648 evalState );
1649 return;
1651 catch( const NonLocalExit::NotThisType & ball )
1653 /* never mind */
1656 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Color::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1660 Lang::NonStrokingBinding::NonStrokingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, RefCountPtr< const Lang::Color > color )
1661 : bindingExpr_( bindingExpr ), color_( color ), id_( id )
1664 Lang::NonStrokingBinding::~NonStrokingBinding( )
1667 void
1668 Lang::NonStrokingBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1670 if( *sysBindings == 0 )
1672 *sysBindings = new Kernel::SystemDynamicVariables( );
1673 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1674 newState->nonStrokingColor_ = color_;
1675 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1676 return;
1679 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1681 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1682 newState->nonStrokingColor_ = color_;
1683 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1684 return;
1687 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1689 if( newState->nonStrokingColor_ != NullPtr< const Lang::Color >( ) )
1691 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1694 newState->nonStrokingColor_ = color_;
1695 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1698 void
1699 Lang::NonStrokingBinding::show( std::ostream & os ) const
1701 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1702 color_->show( os );
1705 void
1706 Lang::NonStrokingBinding::gcMark( Kernel::GCMarkedSet & marked )
1708 const_cast< Lang::Color * >( color_.getPtr( ) )->gcMark( marked );
1713 Kernel::NonStrokingDynamicVariableProperties::NonStrokingDynamicVariableProperties( const Ast::PlacedIdentifier * id )
1714 : Kernel::DynamicVariableProperties( id )
1717 Kernel::NonStrokingDynamicVariableProperties::~NonStrokingDynamicVariableProperties( )
1720 Kernel::VariableHandle
1721 Kernel::NonStrokingDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1723 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1724 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->nonStrokingColor_ ) );
1727 void
1728 Kernel::NonStrokingDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1732 RefCountPtr< const Lang::Color > color = val->tryVal< const Lang::Color >( );
1733 Kernel::ContRef cont = evalState->cont_;
1734 cont->takeValue( Kernel::ValueRef( new Lang::NonStrokingBinding( id_, bindingExpr, color ) ),
1735 evalState );
1736 return;
1738 catch( const NonLocalExit::NotThisType & ball )
1740 /* never mind */
1745 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1746 Kernel::ContRef cont = evalState->cont_;
1747 cont->takeValue( Kernel::ValueRef( new Lang::NonStrokingBinding( id_, bindingExpr, RefCountPtr< const Lang::Color >( new Lang::Gray( -1 ) ) ) ),
1748 evalState );
1749 return;
1751 catch( const NonLocalExit::NotThisType & ball )
1753 /* never mind */
1756 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Color::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1760 Lang::DashBinding::DashBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, RefCountPtr< const Lang::Dash > dash )
1761 : bindingExpr_( bindingExpr ), dash_( dash ), id_( id )
1764 Lang::DashBinding::~DashBinding( )
1767 void
1768 Lang::DashBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1770 if( *sysBindings == 0 )
1772 *sysBindings = new Kernel::SystemDynamicVariables( );
1773 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1774 newState->dash_ = dash_;
1775 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1776 return;
1779 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1781 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1782 newState->dash_ = dash_;
1783 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1784 return;
1787 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1789 if( newState->dash_ != NullPtr< const Lang::Dash >( ) )
1791 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1794 newState->dash_ = dash_;
1795 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1798 void
1799 Lang::DashBinding::show( std::ostream & os ) const
1801 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":" ;
1802 dash_->show( os );
1805 void
1806 Lang::DashBinding::gcMark( Kernel::GCMarkedSet & marked )
1808 const_cast< Lang::Dash * >( dash_.getPtr( ) )->gcMark( marked );
1813 Kernel::DashDynamicVariableProperties::DashDynamicVariableProperties( const Ast::PlacedIdentifier * id )
1814 : Kernel::DynamicVariableProperties( id )
1817 Kernel::DashDynamicVariableProperties::~DashDynamicVariableProperties( )
1820 Kernel::VariableHandle
1821 Kernel::DashDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1823 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1824 return Kernel::VariableHandle( new Kernel::Variable( graphicsState->dash_ ) );
1827 void
1828 Kernel::DashDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1832 RefCountPtr< const Lang::Dash > dash = val->tryVal< const Lang::Dash >( );
1833 Kernel::ContRef cont = evalState->cont_;
1834 cont->takeValue( Kernel::ValueRef( new Lang::DashBinding( id_, bindingExpr, dash ) ),
1835 evalState );
1836 return;
1838 catch( const NonLocalExit::NotThisType & ball )
1840 /* never mind */
1845 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1846 Kernel::ContRef cont = evalState->cont_;
1847 cont->takeValue( Kernel::ValueRef( new Lang::DashBinding( id_, bindingExpr, RefCountPtr< const Lang::Dash >( new Lang::Dash( RefCountPtr< std::list< Concrete::Length > >( new std::list< Concrete::Length >( ) ), 0, -1 ) ) ) ),
1848 evalState );
1849 return;
1851 catch( const NonLocalExit::NotThisType & ball )
1853 /* never mind */
1856 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::Dash::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1861 Lang::CapStyleBinding::CapStyleBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Lang::CapStyle::ValueType & cap )
1862 : bindingExpr_( bindingExpr ), cap_( cap ), id_( id )
1865 Lang::CapStyleBinding::~CapStyleBinding( )
1868 void
1869 Lang::CapStyleBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1871 if( *sysBindings == 0 ) {
1872 *sysBindings = new Kernel::SystemDynamicVariables( );
1873 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1874 newState->cap_ = cap_;
1875 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1876 return;
1879 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1881 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1882 newState->cap_ = cap_;
1883 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1884 return;
1887 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1889 if( newState->cap_ != Lang::CapStyle::CAP_UNDEFINED )
1891 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1894 newState->cap_ = cap_;
1895 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1898 void
1899 Lang::CapStyleBinding::show( std::ostream & os ) const
1901 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
1902 << "<internal-enum>" ;
1905 void
1906 Lang::CapStyleBinding::gcMark( Kernel::GCMarkedSet & marked )
1911 Kernel::CapStyleDynamicVariableProperties::CapStyleDynamicVariableProperties( const Ast::PlacedIdentifier * id )
1912 : Kernel::DynamicVariableProperties( id )
1915 Kernel::CapStyleDynamicVariableProperties::~CapStyleDynamicVariableProperties( )
1918 Kernel::VariableHandle
1919 Kernel::CapStyleDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
1921 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
1922 return Helpers::newValHandle( new Lang::CapStyle( graphicsState->cap_ ) );
1925 void
1926 Kernel::CapStyleDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
1930 RefCountPtr< const Lang::CapStyle > cap = val->tryVal< const Lang::CapStyle >( );
1931 Kernel::ContRef cont = evalState->cont_;
1932 cont->takeValue( Kernel::ValueRef( new Lang::CapStyleBinding( id_, bindingExpr, cap->cap_ ) ),
1933 evalState );
1934 return;
1936 catch( const NonLocalExit::NotThisType & ball )
1938 /* never mind */
1943 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
1944 Kernel::ContRef cont = evalState->cont_;
1945 cont->takeValue( Kernel::ValueRef( new Lang::CapStyleBinding( id_, bindingExpr, Lang::CapStyle::CAP_SAME ) ),
1946 evalState );
1947 return;
1949 catch( const NonLocalExit::NotThisType & ball )
1951 /* never mind */
1954 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::CapStyle::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
1958 Lang::JoinStyleBinding::JoinStyleBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Lang::JoinStyle::ValueType & join )
1959 : bindingExpr_( bindingExpr ), join_( join ), id_( id )
1962 Lang::JoinStyleBinding::~JoinStyleBinding( )
1965 void
1966 Lang::JoinStyleBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
1968 if( *sysBindings == 0 ) {
1969 *sysBindings = new Kernel::SystemDynamicVariables( );
1970 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1971 newState->join_ = join_;
1972 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1973 return;
1976 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
1978 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
1979 newState->join_ = join_;
1980 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1981 return;
1984 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
1986 if( newState->join_ != Lang::JoinStyle::JOIN_UNDEFINED )
1988 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
1991 newState->join_ = join_;
1992 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
1995 void
1996 Lang::JoinStyleBinding::show( std::ostream & os ) const
1998 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
1999 << "<internal-enum>" ;
2002 void
2003 Lang::JoinStyleBinding::gcMark( Kernel::GCMarkedSet & marked )
2008 Kernel::JoinStyleDynamicVariableProperties::JoinStyleDynamicVariableProperties( const Ast::PlacedIdentifier * id )
2009 : Kernel::DynamicVariableProperties( id )
2012 Kernel::JoinStyleDynamicVariableProperties::~JoinStyleDynamicVariableProperties( )
2015 Kernel::VariableHandle
2016 Kernel::JoinStyleDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
2018 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
2019 return Helpers::newValHandle( new Lang::JoinStyle( graphicsState->join_ ) );
2022 void
2023 Kernel::JoinStyleDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
2027 RefCountPtr< const Lang::JoinStyle > join = val->tryVal< const Lang::JoinStyle >( );
2028 Kernel::ContRef cont = evalState->cont_;
2029 cont->takeValue( Kernel::ValueRef( new Lang::JoinStyleBinding( id_, bindingExpr, join->join_ ) ),
2030 evalState );
2031 return;
2033 catch( const NonLocalExit::NotThisType & ball )
2035 /* never mind */
2040 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
2041 Kernel::ContRef cont = evalState->cont_;
2042 cont->takeValue( Kernel::ValueRef( new Lang::JoinStyleBinding( id_, bindingExpr, Lang::JoinStyle::JOIN_SAME ) ),
2043 evalState );
2044 return;
2046 catch( const NonLocalExit::NotThisType & ball )
2048 /* never mind */
2051 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::JoinStyle::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
2055 Lang::BlendModeBinding::BlendModeBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Lang::BlendMode::ValueType & blend )
2056 : bindingExpr_( bindingExpr ), blend_( blend ), id_( id )
2059 Lang::BlendModeBinding::~BlendModeBinding( )
2062 void
2063 Lang::BlendModeBinding::bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const
2065 if( *sysBindings == 0 ) {
2066 *sysBindings = new Kernel::SystemDynamicVariables( );
2067 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
2068 newState->blend_ = blend_;
2069 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
2070 return;
2073 if( (*sysBindings)->graphicsState_ == NullPtr< const Kernel::GraphicsState >( ) )
2075 Kernel::GraphicsState * newState = new Kernel::GraphicsState( );
2076 newState->blend_ = blend_;
2077 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
2078 return;
2081 Kernel::GraphicsState * newState = new Kernel::GraphicsState( *((*sysBindings)->graphicsState_) );
2083 if( newState->blend_ != Lang::BlendMode::BLEND_UNDEFINED )
2085 throw Exceptions::MultipleDynamicBind( id_, bindingExpr_->idLoc( ), Ast::THE_UNKNOWN_LOCATION );
2088 newState->blend_ = blend_;
2089 (*sysBindings)->graphicsState_ = RefCountPtr< const Kernel::GraphicsState >( newState );
2092 void
2093 Lang::BlendModeBinding::show( std::ostream & os ) const
2095 os << Interaction::DYNAMIC_VARIABLE_PREFIX << id_ << ":"
2096 << "<internal-enum>" ;
2099 void
2100 Lang::BlendModeBinding::gcMark( Kernel::GCMarkedSet & marked )
2105 Kernel::BlendModeDynamicVariableProperties::BlendModeDynamicVariableProperties( const Ast::PlacedIdentifier * id )
2106 : Kernel::DynamicVariableProperties( id )
2109 Kernel::BlendModeDynamicVariableProperties::~BlendModeDynamicVariableProperties( )
2112 Kernel::VariableHandle
2113 Kernel::BlendModeDynamicVariableProperties::fetch( const Kernel::PassedDyn & dyn ) const
2115 RefCountPtr< const Kernel::GraphicsState > graphicsState = dyn->getGraphicsState( );
2116 return Helpers::newValHandle( new Lang::BlendMode( graphicsState->blend_ ) );
2119 void
2120 Kernel::BlendModeDynamicVariableProperties::makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const
2124 RefCountPtr< const Lang::BlendMode > blend = val->tryVal< const Lang::BlendMode >( );
2125 Kernel::ContRef cont = evalState->cont_;
2126 cont->takeValue( Kernel::ValueRef( new Lang::BlendModeBinding( id_, bindingExpr, blend->mode_ ) ),
2127 evalState );
2128 return;
2130 catch( const NonLocalExit::NotThisType & ball )
2132 /* never mind */
2137 RefCountPtr< const Lang::Void > dummy = val->tryVal< const Lang::Void >( );
2138 Kernel::ContRef cont = evalState->cont_;
2139 cont->takeValue( Kernel::ValueRef( new Lang::BlendModeBinding( id_, bindingExpr, Lang::BlendMode::BLEND_SAME ) ),
2140 evalState );
2141 return;
2143 catch( const NonLocalExit::NotThisType & ball )
2145 /* never mind */
2148 throw Exceptions::TypeMismatch( bindingExpr->exprLoc( ), val->getUntyped( )->getTypeName( ), Helpers::typeSetString( Lang::BlendMode::staticTypeName( ), Lang::Void::staticTypeName( ) ) );
2153 Lang::ColorSpace::ColorSpace( )
2156 Lang::ColorSpace::~ColorSpace( )
2159 RefCountPtr< const Lang::Class > Lang::ColorSpace::TypeID( new Lang::SystemFinalClass( strrefdup( "ColorSpace" ) ) );
2160 TYPEINFOIMPL( ColorSpace );
2162 void
2163 Lang::ColorSpace::show( std::ostream & os ) const
2165 os << this->name( )->name( ) ;
2169 Lang::InheritedColorSpace::InheritedColorSpace( )
2172 Lang::InheritedColorSpace::~InheritedColorSpace( )
2175 RefCountPtr< SimplePDF::PDF_Name >
2176 Lang::InheritedColorSpace::name( ) const
2178 throw Exceptions::InternalError( "InheritedColorSpace::name was invoked." );
2181 size_t
2182 Lang::InheritedColorSpace::numberOfComponents( ) const
2184 throw Exceptions::InternalError( "InheritedColorSpace::numerOfComponents was invoked." );
2187 bool
2188 Lang::InheritedColorSpace::containsColor( const Lang::Color * col ) const
2190 throw Exceptions::InternalError( "InheritedColorSpace::containsColor was invoked." );
2194 Kernel::Auto_qQ::Auto_qQ( Kernel::GraphicsState * graphicsState, Kernel::TextState * textState, std::ostream & os, bool active )
2195 : graphicsState_( graphicsState ), graphicsEnterState_( 0 ), textState_( textState ), textEnterState_( 0 ), os_( os ), activated_( false )
2197 if( active )
2199 activate( );
2203 void
2204 Kernel::Auto_qQ::activate( )
2206 if( activated_ )
2208 throw Exceptions::InternalError( "Multiple activation of Auto_qQ." );
2210 activated_ = true;
2211 graphicsEnterState_ = new Kernel::GraphicsState( *graphicsState_ );
2212 textEnterState_ = new Kernel::TextState( *textState_ );
2213 os_ << "q" << std::endl ;
2216 Kernel::Auto_qQ::~Auto_qQ( )
2218 if( activated_ )
2220 *graphicsState_ = *graphicsEnterState_;
2221 delete graphicsEnterState_;
2222 *textState_ = *textEnterState_;
2223 delete textEnterState_;
2224 os_ << "Q" << std::endl ;