Update procedures
[shapes.git] / source / fonttypes.cc
bloba4cac718bb9fe5e5a596ffc76b407bc3bc4f8e61
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 "fonttypes.h"
20 #include "classtypes.h"
21 #include "strrefdup.h"
22 #include "fontmetrics.h"
23 #include "pagecontentstates.h"
24 #include "globals.h"
26 using namespace Shapes;
29 Lang::Type3Glyph::Type3Glyph( Kind kind, CodeType code, const RefCountPtr< const char > & name, const RefCountPtr< const Lang::Drawable2D > & glyph, Concrete::Length widthX, Concrete::Length xmin, Concrete::Length ymin, Concrete::Length xmax, Concrete::Length ymax )
30 : kind_( kind ), code_( code ), name_( name ), glyph_( glyph ),
31 widthX_( widthX ), xmin_( xmin ), ymin_( ymin ), xmax_( xmax ), ymax_( ymax )
32 { }
34 Lang::Type3Glyph::~Type3Glyph( )
35 { }
37 RefCountPtr< const Lang::Class > Lang::Type3Glyph::TypeID( new Lang::SystemFinalClass( strrefdup( "Glyph" ) ) );
38 TYPEINFOIMPL( Type3Glyph );
40 RefCountPtr< const char >
41 Lang::Type3Glyph::name( ) const
43 return name_;
46 void
47 Lang::Type3Glyph::enlargeBBox( double * dstXMin, double * dstYMin, double * dstXMax, double * dstYMax ) const
49 *dstXMin = std::min( *dstXMin, static_cast< double >( Concrete::Length::offtype( xmin_ ) ) );
50 *dstYMin = std::min( *dstYMin, static_cast< double >( Concrete::Length::offtype( ymin_ ) ) );
51 *dstXMax = std::max( *dstXMax, static_cast< double >( Concrete::Length::offtype( xmax_ ) ) );
52 *dstYMax = std::max( *dstYMax, static_cast< double >( Concrete::Length::offtype( ymax_ ) ) );
55 void
56 Lang::Type3Glyph::setupMetric( FontMetrics::CharacterMetrics * metric, Physical< -1, 0 > invSize ) const
59 // I need to do a trick here to avoid a compiler tautology warning in case CodeType is unsigned char.
60 size_t dummy = code_;
61 if( dummy < 256 )
63 metric->characterCode_ = code_;
66 metric->horizontalCharWidthX_ = widthX_ * invSize;
67 metric->xmin_ = xmin_ * invSize;
68 metric->ymin_ = ymin_ * invSize;
69 metric->xmax_ = xmax_ * invSize;
70 metric->ymax_ = ymax_ * invSize;
73 void
74 Lang::Type3Glyph::shipout( std::ostream & os, RefCountPtr< SimplePDF::PDF_Resources > resources ) const
76 if( kind_ == BASIC )
78 os << Concrete::Length::offtype( widthX_ ) << " 0 d0" << std::endl ;
80 else
82 os << Concrete::Length::offtype( widthX_ ) << " 0 "
83 << Concrete::Length::offtype( xmin_ ) << " " << Concrete::Length::offtype( ymin_ )
84 << " " << Concrete::Length::offtype( xmax_ ) << " " << Concrete::Length::offtype( ymax_ ) << " d1" << std::endl ;
87 Concrete::Length the1bp( 1 );
89 Kernel::PageContentStates pdfState( resources );
90 glyph_->shipout( os, & pdfState, Lang::THE_2D_IDENTITY );
93 void
94 Lang::Type3Glyph::gcMark( Kernel::GCMarkedSet & marked )
96 const_cast< Lang::Drawable2D * >( glyph_.getPtr( ) )->gcMark( marked );