1 
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 //
14 // Copyright 2005-2010 Google, Inc.
15 // Author: jpr@google.com (Jake Ratkiewicz)
16 
17 #ifndef FST_SCRIPT_DRAW_H_
18 #define FST_SCRIPT_DRAW_H_
19 
20 #include <fst/script/arg-packs.h>
21 #include <fst/script/fst-class.h>
22 #include <fst/script/draw-impl.h>
23 #include <iostream>
24 #include <fstream>
25 #include <sstream>
26 
27 namespace fst {
28 namespace script {
29 
30 // Note: it is safe to pass these strings as references because
31 // this struct is only used to pass them deeper in the call graph.
32 // Be sure you understand why this is so before using this struct
33 // for anything else!
34 struct FstDrawerArgs {
35   const FstClass &fst;
36   const SymbolTable *isyms;
37   const SymbolTable *osyms;
38   const SymbolTable *ssyms;
39   const bool accep;
40   const string& title;
41   const float width;
42   const float height;
43   const bool portrait;
44   const bool vertical;
45   const float ranksep;
46   const float nodesep;
47   const int fontsize;
48   const int precision;
49   const bool show_weight_one;
50   ostream *ostrm;
51   const string &dest;
52 
FstDrawerArgsFstDrawerArgs53   FstDrawerArgs(const FstClass &fst,
54                 const SymbolTable *isyms,
55                 const SymbolTable *osyms,
56                 const SymbolTable *ssyms,
57                 bool accep,
58                 const string &title,
59                 float width,
60                 float height,
61                 bool portrait,
62                 bool vertical,
63                 float ranksep,
64                 float nodesep,
65                 int fontsize,
66                 int precision,
67                 bool show_weight_one,
68                 ostream *ostrm,
69                 const string &dest) :
70       fst(fst), isyms(isyms), osyms(osyms), ssyms(ssyms), accep(accep),
71       title(title), width(width), height(height), portrait(portrait),
72       vertical(vertical), ranksep(ranksep), nodesep(nodesep),
73       fontsize(fontsize), precision(precision),
74       show_weight_one(show_weight_one), ostrm(ostrm), dest(dest) { }
75 };
76 
77 
78 template<class Arc>
DrawFst(FstDrawerArgs * args)79 void DrawFst(FstDrawerArgs *args) {
80   const Fst<Arc> &fst = *(args->fst.GetFst<Arc>());
81 
82   FstDrawer<Arc> fstdrawer(fst, args->isyms, args->osyms, args->ssyms,
83                            args->accep, args->title, args->width,
84                            args->height, args->portrait,
85                            args->vertical, args->ranksep,
86                            args->nodesep, args->fontsize,
87                            args->precision, args->show_weight_one);
88   fstdrawer.Draw(args->ostrm, args->dest);
89 }
90 
91 void DrawFst(const FstClass &fst,
92              const SymbolTable *isyms,
93              const SymbolTable *osyms,
94              const SymbolTable *ssyms,
95              bool accep,
96              const string &title,
97              float width,
98              float height,
99              bool portrait,
100              bool vertical,
101              float ranksep,
102              float nodesep,
103              int fontsize,
104              int precision,
105              bool show_weight_one,
106              ostream *ostrm,
107              const string &dest);
108 
109 }  // namespace script
110 }  // namespace fst
111 
112 
113 
114 #endif  // FST_SCRIPT_DRAW_H_
115