Update suitable examples and tests to use blank mode
[shapes.git] / source / texttypes.h
blob42af40ecac8cd470fd3de0c319420eb6d6d57ac1
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 #pragma once
21 #include "Shapes_Ast_decls.h"
22 #include "Shapes_Kernel_decls.h"
23 #include "Shapes_Lang_decls.h"
24 #include "Shapes_Lang_decls.h"
26 #include "ptrowner.h"
27 #include "refcount.h"
28 #include "environment.h"
29 #include "statetypes.h"
30 #include "elementarylength.h"
31 #include "concretecolors.h"
32 #include "elementarycoords.h"
33 #include "fontmetrics.h"
34 #include "pdfstructure.h"
35 #include "config.h"
37 #include <list>
38 #include <iostream>
39 #include <stack>
40 #include <set>
41 #include <vector>
42 #include <iconv.h>
45 namespace SimplePDF
47 class PDF_ToUnicode : public PDF_Stream_out
49 public:
50 typedef std::set< Shapes::Kernel::UnicodeCodePoint > CharSet;
51 protected:
52 RefCountPtr< CharSet > charSet_;
53 RefCountPtr< const Shapes::Lang::Font > font_; /* Used to determine the encoding. */
54 public:
55 PDF_ToUnicode( RefCountPtr< CharSet > charSet, const RefCountPtr< const Shapes::Lang::Font > & font );
56 virtual ~PDF_ToUnicode( );
58 virtual void writeTo( std::ostream & os, SimplePDF::PDF_xref * xref, const RefCountPtr< const PDF_Object > & self ) const;
61 class PDF_Widths : public PDF_Vector
63 public:
64 typedef std::set< Shapes::Kernel::UnicodeCodePoint > CharSet;
65 protected:
66 RefCountPtr< CharSet > charSet_;
67 RefCountPtr< const Shapes::Lang::Font > font_; /* Used to determine the encoding as well as the metrics. */
68 public:
69 PDF_Widths( RefCountPtr< CharSet > charSet, const RefCountPtr< const Shapes::Lang::Font > & font );
70 virtual ~PDF_Widths( );
72 virtual void writeTo( std::ostream & os, SimplePDF::PDF_xref * xref, const RefCountPtr< const PDF_Object > & self ) const;
77 namespace Shapes
79 namespace Lang
81 class FontMethod_glyph;
83 class Font : public Lang::NoOperatorOverloadValue
85 private:
86 static std::map< RefCountPtr< const char >, RefCountPtr< SimplePDF::PDF_Object >, charRefPtrLess > theFontResourceMap_;
87 static std::map< RefCountPtr< const char >, RefCountPtr< const FontMetrics::FontMetric >, charRefPtrLess > theFontMetricsMap_;
88 static std::list< std::string > theFontMetricsSearchPath_;
90 public:
91 static void push_backFontMetricsPath( const std::string & path );
92 static std::string searchGlyphList( );
93 static std::string searchCharacterEncoding( const char * encodingName );
94 private:
95 static std::string searchFontMetrics( RefCountPtr< const char > fontName );
96 protected:
97 RefCountPtr< const char > fontName_;
98 bool outline_;
99 private:
100 mutable RefCountPtr< SimplePDF::PDF_Object > resource_;
101 mutable RefCountPtr< const FontMetrics::FontMetric > metrics_;
102 public:
103 Font( const RefCountPtr< const char > fontName, bool outline, RefCountPtr< SimplePDF::PDF_Object > & resource, RefCountPtr< const FontMetrics::FontMetric > metrics = NullPtr< const FontMetrics::FontMetric >( ) );
104 Font( const RefCountPtr< const char > builtInFontName ); // It is important that this is not used with fonts that aren't built in.
105 virtual ~Font( );
106 virtual Kernel::VariableHandle getField( const char * fieldID, const RefCountPtr< const Lang::Value > & selfRef ) const;
107 virtual void show( std::ostream & os ) const;
108 virtual void gcMark( Kernel::GCMarkedSet & marked );
109 const RefCountPtr< SimplePDF::PDF_Object > & resource( ) const;
110 RefCountPtr< const char > fontName( ) const;
111 bool outline( ) const;
112 RefCountPtr< const FontMetrics::FontMetric > metrics( ) const;
113 virtual void encode( const char ** text_UTF8, size_t * in_avail, char ** dst_PDF, size_t * out_avail ) const = 0;
114 virtual void encode( Kernel::UnicodeCodePoint c, char ** dst_PDF, size_t * out_avail ) const = 0;
116 TYPEINFODECL;
117 protected:
118 /* These member functions are only here to support getField. */
119 virtual RefCountPtr< const Lang::String > family_name( ) const;
120 virtual RefCountPtr< const Lang::String > style_name( ) const;
121 virtual RefCountPtr< const Lang::Symbol > PostScript_name( ) const;
122 virtual RefCountPtr< const Lang::Value > getGlyph( Kernel::UnicodeCodePoint c, Concrete::Length size ) const;
123 friend class Lang::FontMethod_glyph;
126 class PDFStandardFont : public Lang::Font
128 public:
129 // It is important that this is not used with fonts that aren't built in.
130 PDFStandardFont( const RefCountPtr< const char > builtInFontName );
131 virtual ~PDFStandardFont( );
132 virtual void encode( const char ** text_UTF8, size_t * in_avail, char ** dst_PDF, size_t * out_avail ) const;
133 virtual void encode( Kernel::UnicodeCodePoint c, char ** dst_PDF, size_t * out_avail ) const;
135 /* This is the implementation of the encode method. By providing it as a static member function, it may be used by Type3Font as well. */
136 static void encode_MacRoman( const char ** text_UTF8, size_t * in_avail, char ** dst_PDF, size_t * out_avail );
137 static void encode_MacRoman( Kernel::UnicodeCodePoint c, char ** dst_PDF, size_t * out_avail );
140 class Type3Font : public Lang::Font
142 public:
143 Type3Font( const RefCountPtr< const char > fontName, RefCountPtr< SimplePDF::PDF_Object > & resource, RefCountPtr< const FontMetrics::FontMetric > metrics );
144 virtual ~Type3Font( );
145 virtual void encode( const char ** text_UTF8, size_t * in_avail, char ** dst_PDF, size_t * out_avail ) const;
146 virtual void encode( Kernel::UnicodeCodePoint c, char ** dst_PDF, size_t * out_avail ) const;
149 #ifdef HAVE_FT2
150 class FreeTypeFont : public Lang::Font
152 FT_Face face_;
153 mutable RefCountPtr< SimplePDF::PDF_ToUnicode::CharSet > usedChars_;
154 public:
155 FreeTypeFont( FT_Face face, const RefCountPtr< const char > fontName, bool outline, RefCountPtr< SimplePDF::PDF_Object > & resource, RefCountPtr< const FontMetrics::FontMetric > metrics, RefCountPtr< SimplePDF::PDF_ToUnicode::CharSet > & usedChars );
156 virtual ~FreeTypeFont( );
157 virtual void encode( const char ** text_UTF8, size_t * in_avail, char ** dst_PDF, size_t * out_avail ) const;
158 virtual void encode( Kernel::UnicodeCodePoint c, char ** dst_PDF, size_t * out_avail ) const;
160 void shipout_glyph( Kernel::UnicodeCodePoint c, Concrete::Length size, const Lang::Transform2D & tf, std::ostream & os, bool * dstIsOdd, Concrete::Length * dstAdvance ) const; /* The value stored in *dstAdvance accounts for <size>, but not for <tf>. Hence, it typically needs to be scaled by the current horizontal scaling. */
162 protected:
163 virtual RefCountPtr< const Lang::String > family_name( ) const;
164 virtual RefCountPtr< const Lang::String > style_name( ) const;
165 virtual RefCountPtr< const Lang::Symbol > PostScript_name( ) const;
166 virtual RefCountPtr< const Lang::Value > getGlyph( Kernel::UnicodeCodePoint c, Concrete::Length size ) const;
168 const FT_Outline & getGlyphOutline( Kernel::UnicodeCodePoint c ) const; /* Note! Result is only valid until a different glyph is loaded in the glyph slot. */
170 #endif
172 class TextRenderingMode : public Lang::NoOperatorOverloadValue
174 public:
175 typedef enum { FILL = 0, STROKE, FILLSTROKE, INVISIBLE, FILLCLIP, STROKECLIP, FILLSTROKECLIP, CLIP, UNDEFINED } ValueType;
176 ValueType mode_;
177 TextRenderingMode( const ValueType & mode );
178 TextRenderingMode( bool fill, bool stroke, bool clip );
179 virtual ~TextRenderingMode( );
180 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
181 TYPEINFODECL;
183 static ValueType clipMode( ValueType mode );
186 class TextOperation : public Lang::NoOperatorOverloadValue
188 public:
189 TextOperation();
190 virtual ~TextOperation( );
192 virtual void shipout( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, bool clip = false ) const = 0;
193 virtual void shipout_outlined( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, Lang::Transform2D * textMatrix, Lang::Transform2D * lineMatrix, const SimplePDF::PDF_Name * clipContent = 0 ) const = 0; /* clipContent == 0 means that the text shall be used for painting, not clipping. */
194 virtual void measure( Lang::Transform2D * textMatrix, Lang::Transform2D * textLineMatrix, Concrete::Length * xmin, Concrete::Length * ymin, Concrete::Length * xmax, Concrete::Length * ymax ) const = 0;
196 TYPEINFODECL;
199 class KernedText : public Lang::TextOperation
201 RefCountPtr< const Kernel::TextState > textState_;
202 RefCountPtr< const Kernel::GraphicsState > metaState_;
204 // The representation is a bit artificial to be efficient: NullPtr objects in
205 // strings_ mark where kerning values are to be taken from kernings_. Hence,
206 // The number of NullPtr objects in strings_ must match the length of kernings_.
207 std::list< RefCountPtr< const Lang::String > > strings_;
208 std::list< double > kernings_;
209 size_t maxLength_;
210 public:
211 KernedText( const RefCountPtr< const Kernel::TextState > & textState, const RefCountPtr< const Kernel::GraphicsState > & metaState );
212 KernedText( const RefCountPtr< const Kernel::TextState > & textState, const RefCountPtr< const Kernel::GraphicsState > & metaState, const RefCountPtr< const Lang::String > & str);
213 virtual ~KernedText( );
214 virtual Kernel::VariableHandle getField( const char * fieldID, const RefCountPtr< const Lang::Value > & selfRef ) const;
215 void pushString( const RefCountPtr< const Lang::String > & str );
216 void pushKerning( double kerning );
218 virtual void show( std::ostream & os ) const;
219 virtual void shipout( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, bool clip ) const;
220 virtual void shipout_outlined( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, Lang::Transform2D * textMatrix, Lang::Transform2D * lineMatrix, const SimplePDF::PDF_Name * clipContent ) const;
221 virtual void measure( Lang::Transform2D * textMatrix, Lang::Transform2D * textLineMatrix, Concrete::Length * xmin, Concrete::Length * ymin, Concrete::Length * xmax, Concrete::Length * ymax ) const;
223 void push( Lang::KernedText * dst ) const;
225 virtual void gcMark( Kernel::GCMarkedSet & marked );
227 private:
228 RefCountPtr< const Lang::SingleList > makeList( ) const;
229 static RefCountPtr< const Lang::String > oneUCS4ToUTF8( const char * c );
232 class TextNewline : public Lang::TextOperation
234 Concrete::Coords2D t_;
235 public:
236 TextNewline( const Concrete::Length tx, const Concrete::Length ty );
237 virtual ~TextNewline( );
239 virtual void show( std::ostream & os ) const;
240 virtual void shipout( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, bool clip ) const;
241 virtual void shipout_outlined( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, Lang::Transform2D * textMatrix, Lang::Transform2D * lineMatrix, const SimplePDF::PDF_Name * clipContent ) const;
242 virtual void measure( Lang::Transform2D * textMatrix, Lang::Transform2D * textLineMatrix, Concrete::Length * xmin, Concrete::Length * ymin, Concrete::Length * xmax, Concrete::Length * ymax ) const;
244 virtual void gcMark( Kernel::GCMarkedSet & marked );
247 class TextMoveto : public Lang::TextOperation
249 RefCountPtr< const Lang::Transform2D > tf_;
250 public:
251 TextMoveto( const RefCountPtr< const Lang::Transform2D > & tf );
252 virtual ~TextMoveto( );
254 virtual void show( std::ostream & os ) const;
255 virtual void shipout( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, bool clip ) const;
256 virtual void shipout_outlined( std::ostream & os, Kernel::PageContentStates * pdfState, const Lang::Transform2D & tf, Lang::Transform2D * textMatrix, Lang::Transform2D * lineMatrix, const SimplePDF::PDF_Name * clipContent ) const;
257 virtual void measure( Lang::Transform2D * textMatrix, Lang::Transform2D * textLineMatrix, Concrete::Length * xmin, Concrete::Length * ymin, Concrete::Length * xmax, Concrete::Length * ymax ) const;
259 virtual void gcMark( Kernel::GCMarkedSet & marked );
264 namespace Lang
267 class CharacterSpacingBinding : public DynamicBindings
269 const Ast::DynamicBindingExpression * bindingExpr_;
270 Concrete::Length spacing_;
271 bool isRelative_;
272 const Ast::PlacedIdentifier * id_;
273 public:
274 CharacterSpacingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Concrete::Length spacing );
275 CharacterSpacingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const double r );
276 virtual ~CharacterSpacingBinding( );
277 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
278 virtual void show( std::ostream & os ) const;
279 virtual void gcMark( Kernel::GCMarkedSet & marked );
282 class WordSpacingBinding : public DynamicBindings
284 const Ast::DynamicBindingExpression * bindingExpr_;
285 Concrete::Length spacing_;
286 bool isRelative_;
287 const Ast::PlacedIdentifier * id_;
288 public:
289 WordSpacingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Concrete::Length spacing );
290 WordSpacingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const double r );
291 virtual ~WordSpacingBinding( );
292 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
293 virtual void show( std::ostream & os ) const;
294 virtual void gcMark( Kernel::GCMarkedSet & marked );
297 class HorizontalScalingBinding : public DynamicBindings
299 const Ast::DynamicBindingExpression * bindingExpr_;
300 double scaling_;
301 const Ast::PlacedIdentifier * id_;
302 public:
303 HorizontalScalingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const double scaling );
304 virtual ~HorizontalScalingBinding( );
305 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
306 virtual void show( std::ostream & os ) const;
307 virtual void gcMark( Kernel::GCMarkedSet & marked );
310 class LeadingBinding : public DynamicBindings
312 const Ast::DynamicBindingExpression * bindingExpr_;
313 Concrete::Length ty_;
314 bool isRelative_;
315 const Ast::PlacedIdentifier * id_;
316 public:
317 LeadingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Concrete::Length ty );
318 LeadingBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const double r );
319 virtual ~LeadingBinding( );
320 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
321 virtual void show( std::ostream & os ) const;
322 virtual void gcMark( Kernel::GCMarkedSet & marked );
325 class FontBinding : public DynamicBindings
327 const Ast::DynamicBindingExpression * bindingExpr_;
328 RefCountPtr< const Lang::Font > font_;
329 const Ast::PlacedIdentifier * id_;
330 public:
331 FontBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const RefCountPtr< const Lang::Font > & font );
332 virtual ~FontBinding( );
333 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
334 virtual void show( std::ostream & os ) const;
335 virtual void gcMark( Kernel::GCMarkedSet & marked );
338 class TextSizeBinding : public DynamicBindings
340 const Ast::DynamicBindingExpression * bindingExpr_;
341 Concrete::Length size_;
342 const Ast::PlacedIdentifier * id_;
343 public:
344 TextSizeBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Concrete::Length size );
345 virtual ~TextSizeBinding( );
346 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
347 virtual void show( std::ostream & os ) const;
348 virtual void gcMark( Kernel::GCMarkedSet & marked );
351 class TextRenderingModeBinding : public DynamicBindings
353 const Ast::DynamicBindingExpression * bindingExpr_;
354 Lang::TextRenderingMode::ValueType mode_;
355 const Ast::PlacedIdentifier * id_;
356 public:
357 TextRenderingModeBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Lang::TextRenderingMode::ValueType mode );
358 virtual ~TextRenderingModeBinding( );
359 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
360 virtual void show( std::ostream & os ) const;
361 virtual void gcMark( Kernel::GCMarkedSet & marked );
364 class TextRiseBinding : public DynamicBindings
366 const Ast::DynamicBindingExpression * bindingExpr_;
367 Concrete::Length ty_;
368 bool isRelative_;
369 const Ast::PlacedIdentifier * id_;
370 public:
371 TextRiseBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const Concrete::Length ty );
372 TextRiseBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const double r );
373 virtual ~TextRiseBinding( );
374 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
375 virtual void show( std::ostream & os ) const;
376 virtual void gcMark( Kernel::GCMarkedSet & marked );
379 class TextKnockoutBinding : public DynamicBindings
381 const Ast::DynamicBindingExpression * bindingExpr_;
382 bool knockout_;
383 const Ast::PlacedIdentifier * id_;
384 public:
385 TextKnockoutBinding( const Ast::PlacedIdentifier * id, const Ast::DynamicBindingExpression * bindingExpr, const bool knockout );
386 virtual ~TextKnockoutBinding( );
387 virtual void bind( MapType & bindings, Kernel::SystemDynamicVariables ** sysBindings ) const;
388 virtual void show( std::ostream & os ) const;
389 virtual void gcMark( Kernel::GCMarkedSet & marked );
394 namespace Kernel
397 class CharacterSpacingDynamicVariableProperties : public Kernel::DynamicVariableProperties
399 public:
400 CharacterSpacingDynamicVariableProperties( const Ast::PlacedIdentifier * id );
401 virtual ~CharacterSpacingDynamicVariableProperties( );
402 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
403 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
406 class WordSpacingDynamicVariableProperties : public Kernel::DynamicVariableProperties
408 public:
409 WordSpacingDynamicVariableProperties( const Ast::PlacedIdentifier * id );
410 virtual ~WordSpacingDynamicVariableProperties( );
411 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
412 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
415 class HorizontalScalingDynamicVariableProperties : public Kernel::DynamicVariableProperties
417 public:
418 HorizontalScalingDynamicVariableProperties( const Ast::PlacedIdentifier * id );
419 virtual ~HorizontalScalingDynamicVariableProperties( );
420 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
421 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
424 class LeadingDynamicVariableProperties : public Kernel::DynamicVariableProperties
426 public:
427 LeadingDynamicVariableProperties( const Ast::PlacedIdentifier * id );
428 virtual ~LeadingDynamicVariableProperties( );
429 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
430 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
433 class FontDynamicVariableProperties : public Kernel::DynamicVariableProperties
435 public:
436 FontDynamicVariableProperties( const Ast::PlacedIdentifier * id );
437 virtual ~FontDynamicVariableProperties( );
438 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
439 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
442 class TextSizeDynamicVariableProperties : public Kernel::DynamicVariableProperties
444 public:
445 TextSizeDynamicVariableProperties( const Ast::PlacedIdentifier * id );
446 virtual ~TextSizeDynamicVariableProperties( );
447 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
448 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
451 class TextRenderingModeDynamicVariableProperties : public Kernel::DynamicVariableProperties
453 public:
454 TextRenderingModeDynamicVariableProperties( const Ast::PlacedIdentifier * id );
455 virtual ~TextRenderingModeDynamicVariableProperties( );
456 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
457 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
460 class TextRiseDynamicVariableProperties : public Kernel::DynamicVariableProperties
462 public:
463 TextRiseDynamicVariableProperties( const Ast::PlacedIdentifier * id );
464 virtual ~TextRiseDynamicVariableProperties( );
465 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
466 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
469 class TextKnockoutDynamicVariableProperties : public Kernel::DynamicVariableProperties
471 public:
472 TextKnockoutDynamicVariableProperties( const Ast::PlacedIdentifier * id );
473 virtual ~TextKnockoutDynamicVariableProperties( );
474 virtual Kernel::VariableHandle fetch( const Kernel::PassedDyn & dyn ) const;
475 virtual void makeBinding( Kernel::VariableHandle val, const Ast::DynamicBindingExpression * bindingExpr, Kernel::EvalState * evalState ) const;
478 class TextState
480 private:
481 static const char RELATIVE_LEADING = 0x01;
482 static const char RELATIVE_RISE = 0x02;
483 static const char RELATIVE_CHARACTER_SPACING = 0x04;
484 static const char RELATIVE_WORD_SPACING = 0x08;
485 public:
486 unsigned char relativeFlags_;
488 public:
489 static const char KNOCKOUT_FLAG_BIT = 0x01;
490 static const char KNOCKOUT_UNDEFINED_BIT = 0x02;
491 private:
492 Concrete::Length characterSpacing_; // Use NaN for undefined.
493 Concrete::Length wordSpacing_; // Use NaN for undefined.
494 public:
495 double horizontalScaling_; // Use NaN for undefined.
496 private:
497 Concrete::Length leading_; // Use NaN for undefined. Offtype in case leadingIsRelative_.
498 Concrete::Length rise_; // Use NaN for undefined. Offtype in case riseIsRelative_.
499 public:
500 RefCountPtr< const Lang::Font > font_; // Use NullPtr for undefined.
501 Concrete::Length size_; // Use NaN for undefined.
502 Lang::TextRenderingMode::ValueType mode_; // Use UNDEFINED for undefined.
503 char knockout_; // Set the bit KNOCKOUT_UNDEFINED for undefined.
504 public:
505 TextState( );
506 explicit TextState( const Kernel::TextState & orig ); // explicit, since reference counting shall be used in most cases
507 TextState( const Kernel::TextState & newValues, const Kernel::TextState & oldValues );
508 TextState( bool setDefaults );
509 ~TextState( );
511 void setLeading( const Concrete::Length leading );
512 void setLeading( const double relativeLeading );
513 bool hasLeading( ) const;
514 inline bool leadingIsRelative( ) const;
515 Concrete::Length leadingConcrete( ) const;
516 RefCountPtr< const Lang::Value > leading( ) const;
518 void setRise( const Concrete::Length rise );
519 void setRise( const double relativeRise );
520 bool hasRise( ) const;
521 bool riseIsRelative( ) const;
522 Concrete::Length riseConcrete( ) const;
523 RefCountPtr< const Lang::Value > rise( ) const;
525 void setCharacterSpacing( const Concrete::Length spacing );
526 void setCharacterSpacing( const double relativeSpacing );
527 bool hasCharacterSpacing( ) const;
528 bool characterSpacingIsRelative( ) const;
529 Concrete::Length characterSpacingConcrete( ) const;
530 RefCountPtr< const Lang::Value > characterSpacing( ) const;
532 void setWordSpacing( const Concrete::Length spacing );
533 void setWordSpacing( const double relativeSpacing );
534 bool hasWordSpacing( ) const;
535 bool wordSpacingIsRelative( ) const;
536 Concrete::Length wordSpacingConcrete( ) const;
537 RefCountPtr< const Lang::Value > wordSpacing( ) const;
539 bool synchKnockout( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool force = false );
540 bool synchAssertKnockout( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool clip, bool force = false );
542 void print( std::ostream & os, const std::string & indentation ) const;
544 private:
545 static std::map< bool, RefCountPtr< SimplePDF::PDF_Object > > knockoutNameMap_;
547 bool synchCharacterSpacing( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool force = false );
548 bool synchWordSpacing( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool force = false );
549 bool synchHorizontalScaling( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool force = false );
550 bool synchLeading( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool force = false );
551 bool synchFontAndSize( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool force = false );
552 bool synchMode( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool clip, bool force = false );
553 bool synchRise( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool force = false );
555 void assertKnockout( const Kernel::TextState * ref );
557 bool synchButKnockout( std::ostream & os, const Kernel::TextState * ref, SimplePDF::PDF_Resources * resources, bool clip, bool force = false );