Cadabra
Computer algebra system for field theory problems
TeXView.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <gtkmm/eventbox.h>
5 #include <gtkmm/box.h>
6 #include <gtkmm/drawingarea.h>
7 #if GTKMM_MINOR_VERSION>=10
8 #include <gtkmm/revealer.h>
9 #endif
10 
11 #include "Config.hh"
12 #include "DataCell.hh"
13 #include "../common/TeXEngine.hh"
14 
15 // MicroTeX
16 #include "microtex.h"
17 #include "utils/utf.h"
18 
19 namespace cadabra {
20 
24  //
27 
28  class TeXView : public Gtk::EventBox {
29  public:
30  TeXView(TeXEngine&, DTree::iterator, bool use_microtex_, int hmargin=25);
31  virtual ~TeXView();
32 
33  std::shared_ptr<TeXEngine::TeXRequest> content;
34 
35  sigc::signal1<bool, DTree::iterator> show_hide_requested;
36 
37  void set_use_microtex(bool);
38 
39  DTree::iterator datacell;
40  Gtk::Revealer rbox;
41  Gtk::VBox vbox;
42  Gtk::HBox hbox;
43 
44  class TeXArea : public Gtk::DrawingArea {
45  public:
46  TeXArea(bool use_microtex, TeXView *owner_);
47  ~TeXArea();
48 
49  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
50 
54 
55  void update_image(std::shared_ptr<TeXEngine::TeXRequest>, double scale);
56 
60 
61  Glib::RefPtr<Gdk::Pixbuf> pixbuf;
62  double scale_;
63  float _text_size;
64 
68  void set_latex(const std::string& latex);
69 
72  void layout_latex() const;
73 
75 
76  protected:
77  Gtk::SizeRequestMode get_request_mode_vfunc() const override;
78  void get_preferred_height_for_width_vfunc(int width, int& minimum_height,
79  int& natural_height) const override;
80  void get_preferred_width_for_height_vfunc(int height, int& minimum_width,
81  int& natural_width) const override;
82  void on_size_allocate(Gtk::Allocation& allocation) override;
83 
84  private:
86  mutable int rendering_width;
88 
89  // MicroTeX
90  mutable microtex::Render* _render;
91  std::string unfixed, fixed;
92  };
93 
95 
97  void update_image();
98 
101 
102  void dim(bool);
103 
104  sigc::signal1<bool, std::string> tex_error;
105 
106  protected:
107  virtual bool on_button_release_event(GdkEventButton *) override;
108  virtual void on_show() override;
109 
110  void convert();
111 
112  private:
115 
116  float text_size() const;
117  };
118 
119  }
120 
TeXEngine is used to convert LaTeX strings into PNG images.
Definition: TeXEngine.hh:23
Definition: TeXView.hh:44
std::string fixed
Definition: TeXView.hh:91
std::string unfixed
Definition: TeXView.hh:91
void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override
Definition: TeXView.cc:119
TeXView * owner
Definition: TeXView.hh:85
void set_latex(const std::string &latex)
MicroTeX: set the LaTeX string and replace/substitute so that MicroTeX can render it (but do not actu...
Definition: TeXView.cc:330
TeXArea(bool use_microtex, TeXView *owner_)
Definition: TeXView.cc:459
int padding_x
Definition: TeXView.hh:87
void layout_latex() const
MicroTeX: just run the LaTeX layout algorithms, do not draw.
Definition: TeXView.cc:238
double scale_
Definition: TeXView.hh:62
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &cr) override
Definition: TeXView.cc:278
microtex::Render * _render
Definition: TeXView.hh:90
bool use_microtex
Definition: TeXView.hh:74
Glib::RefPtr< Gdk::Pixbuf > pixbuf
The actual image is stored in the image referenced by pixbuf.
Definition: TeXView.hh:61
float _text_size
Definition: TeXView.hh:63
int padding_y
Definition: TeXView.hh:87
void update_image(std::shared_ptr< TeXEngine::TeXRequest >, double scale)
Update the visible image from the pixbuf.
Definition: TeXView.cc:205
int rendering_width
Definition: TeXView.hh:86
Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition: TeXView.cc:86
~TeXArea()
Definition: TeXView.cc:470
void on_size_allocate(Gtk::Allocation &allocation) override
Definition: TeXView.cc:136
void get_preferred_height_for_width_vfunc(int width, int &minimum_height, int &natural_height) const override
Definition: TeXView.cc:91
TeXView is a widget which knows how to turn a string into a LaTeX-rendered image and display that.
Definition: TeXView.hh:28
Gtk::VBox vbox
Definition: TeXView.hh:41
virtual bool on_button_release_event(GdkEventButton *) override
Definition: TeXView.cc:188
TeXEngine & engine
Definition: TeXView.hh:113
void dim(bool)
Dim the output to indicate that the result is no longer guaranteed to be correlated with the input ce...
Definition: TeXView.cc:182
Gtk::Revealer rbox
Definition: TeXView.hh:40
virtual ~TeXView()
Definition: TeXView.cc:49
float text_size() const
Definition: TeXView.cc:63
TeXArea image
Definition: TeXView.hh:94
DTree::iterator datacell
Definition: TeXView.hh:39
void update_image()
Update the TeX image.
Definition: TeXView.cc:194
virtual void on_show() override
Definition: TeXView.cc:79
std::shared_ptr< TeXEngine::TeXRequest > content
Definition: TeXView.hh:33
TeXView(TeXEngine &, DTree::iterator, bool use_microtex_, int hmargin=25)
Definition: TeXView.cc:15
Gtk::HBox hbox
Definition: TeXView.hh:42
bool use_microtex
Definition: TeXView.hh:114
void set_use_microtex(bool)
Definition: TeXView.cc:54
void convert()
Definition: TeXView.cc:159
sigc::signal1< bool, DTree::iterator > show_hide_requested
Definition: TeXView.hh:35
sigc::signal1< bool, std::string > tex_error
Definition: TeXView.hh:104
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83