1 // Copyright 2005-2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17
18 #ifndef FST_SCRIPT_DRAW_H_
19 #define FST_SCRIPT_DRAW_H_
20
21 #include <ostream>
22
23 #include <fst/script/draw-impl.h>
24 #include <fst/script/fst-class.h>
25
26 namespace fst {
27 namespace script {
28
29 // Note: it is safe to pass these strings as references because this struct is
30 // only used to pass them deeper in the call graph. Be sure you understand why
31 // this is so before using this struct for anything else!
32 struct DrawArgs {
33 const FstClass &fst;
34 const SymbolTable *isyms;
35 const SymbolTable *osyms;
36 const SymbolTable *ssyms;
37 const bool accep;
38 const std::string &title;
39 const float width;
40 const float height;
41 const bool portrait;
42 const bool vertical;
43 const float ranksep;
44 const float nodesep;
45 const int fontsize;
46 const int precision;
47 const std::string &float_format;
48 const bool show_weight_one;
49 std::ostream &ostrm;
50 const std::string &dest;
51 };
52
53 template <class Arc>
Draw(DrawArgs * args)54 void Draw(DrawArgs *args) {
55 const Fst<Arc> &fst = *args->fst.GetFst<Arc>();
56 FstDrawer<Arc> fstdrawer(fst, args->isyms, args->osyms, args->ssyms,
57 args->accep, args->title, args->width, args->height,
58 args->portrait, args->vertical, args->ranksep,
59 args->nodesep, args->fontsize, args->precision,
60 args->float_format, args->show_weight_one);
61 fstdrawer.Draw(args->ostrm, args->dest);
62 }
63
64 void Draw(const FstClass &fst, const SymbolTable *isyms,
65 const SymbolTable *osyms, const SymbolTable *ssyms, bool accep,
66 const std::string &title, float width, float height, bool portrait,
67 bool vertical, float ranksep, float nodesep, int fontsize,
68 int precision, const std::string &float_format, bool show_weight_one,
69 std::ostream &ostrm, const std::string &dest);
70
71 } // namespace script
72 } // namespace fst
73
74 #endif // FST_SCRIPT_DRAW_H_
75