11
2- #include " TeXView.hh"
3- #include < iostream>
2+ #include " TeXView.hh"
3+ #include < iostream>
4+ #include < cairo/cairo.h>
5+ #include < cairomm/context.h>
6+ #include < giomm/resource.h>
7+ #include < gdkmm/general.h> // set_source_pixbuf()
48
5- using namespace cadabra ;
9+ using namespace cadabra ;
610
7- TeXView::TeXView (TeXEngine& eng, DTree::iterator it, int hmargin)
8- : content(0 ), datacell(it), vbox(false , 10 ), hbox(false , hmargin), engine(eng)
9- {
10- content = engine.checkin (datacell->textbuf , " " , " " );
11+ TeXView::TeXView (TeXEngine& eng, DTree::iterator it, int hmargin)
12+ : content(0 ), datacell(it), vbox(false , 10 ), hbox(false , hmargin), engine(eng)
13+ {
14+ content = engine.checkin (datacell->textbuf , " " , " " );
1115
1216#if GTKMM_MINOR_VERSION>=10
13- add (rbox);
14- rbox.add (vbox);
15- rbox.set_reveal_child (false );
16- rbox.set_transition_duration (1000 );
17- rbox.set_transition_type (Gtk::REVEALER_TRANSITION_TYPE_CROSSFADE); // SLIDE_DOWN);
17+ add (rbox);
18+ rbox.add (vbox);
19+ rbox.set_reveal_child (false );
20+ rbox.set_transition_duration (1000 );
21+ rbox.set_transition_type (Gtk::REVEALER_TRANSITION_TYPE_CROSSFADE); // SLIDE_DOWN);
1822#else
19- add (vbox);
23+ add (vbox);
2024#endif
21- vbox.set_margin_top (10 );
22- vbox.set_margin_bottom (0 );
23- vbox.pack_start (hbox, Gtk::PACK_SHRINK, 0 );
24- hbox.pack_start (image, Gtk::PACK_SHRINK, hmargin);
25+ vbox.set_margin_top (10 );
26+ vbox.set_margin_bottom (0 );
27+ vbox.pack_start (hbox, Gtk::PACK_SHRINK, 0 );
28+ hbox.pack_start (image, Gtk::PACK_SHRINK, hmargin);
2529// add(image);
26- override_background_color (Gdk::RGBA (" white" ));
27- add_events ( Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK );
28- }
30+ override_background_color (Gdk::RGBA (" white" ));
31+ add_events ( Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK );
32+ }
2933
30- TeXView::~TeXView ()
31- {
32- engine.checkout (content);
33- }
34+ TeXView::~TeXView ()
35+ {
36+ engine.checkout (content);
37+ }
3438
3539void TeXView::on_show ()
3640 {
@@ -60,14 +64,7 @@ void TeXView::convert()
6064
6165 if (content->image ().data ()!=0 ) {
6266 // std::cerr << "SHOULD NOT HAPPEN" << std::endl;
63- Glib::RefPtr<Gdk::Pixbuf> pixbuf =
64- Gdk::Pixbuf::create_from_data (content->image ().data (), Gdk::COLORSPACE_RGB,
65- true ,
66- 8 ,
67- content->width (), content->height (),
68- 4 *content->width ());
69-
70- image.set (pixbuf);
67+ image.update_image (content, engine.get_scale ());
7168 }
7269 }
7370 catch (TeXEngine::TeXException& ex) {
@@ -77,27 +74,58 @@ void TeXView::convert()
7774
7875
7976void TeXView::dim (bool d)
80- {
81- if (d) image.set_opacity (0.3 );
82- else image.set_opacity (1.0 );
83- }
84-
85- bool TeXView::on_button_release_event (GdkEventButton *ev)
86- {
87- show_hide_requested.emit (datacell);
88- return true ;
89- }
90-
91- void TeXView::update_image ()
92- {
93- Glib::RefPtr<Gdk::Pixbuf> pixbuf =
77+ {
78+ if (d) image.set_opacity (0.3 );
79+ else image.set_opacity (1.0 );
80+ }
81+
82+ bool TeXView::on_button_release_event (GdkEventButton *ev)
83+ {
84+ show_hide_requested.emit (datacell);
85+ return true ;
86+ }
87+
88+ void TeXView::update_image ()
89+ {
90+ image.update_image (content, engine.get_scale ());
91+ }
92+
93+ void TeXView::TeXArea::update_image (std::shared_ptr<TeXEngine::TeXRequest> content, double scale)
94+ {
95+ pixbuf =
9496 Gdk::Pixbuf::create_from_data (content->image ().data (), Gdk::COLORSPACE_RGB,
9597 true ,
9698 8 ,
9799 content->width (), content->height (),
98100 4 *content->width ());
99101
100- image.set (pixbuf);
102+ set_size_request (pixbuf->get_width (), pixbuf->get_height ());
103+ // update=true;
104+ scale_=scale;
105+ // HERE
106+ // image.set(pixbuf);
101107 }
102108
103109
110+ bool TeXView::TeXArea::on_draw (const Cairo::RefPtr<Cairo::Context>& cr)
111+ {
112+ if (!pixbuf) return false ;
113+
114+ // Gtk::Allocation allocation = get_allocation();
115+ // const int width = allocation.get_width();
116+ // const int height = allocation.get_height();
117+ auto surface = cr->get_target ();
118+ auto csurface = surface->cobj ();
119+ // cairo_surface_set_device_scale(csurface, 1.0, 1.0);
120+ // cairo_surface_mark_dirty(csurface);
121+ double device_scale_x, device_scale_y;
122+ cairo_surface_get_device_scale (csurface, &device_scale_x, &device_scale_y);
123+ // std::cerr << device_scale_x << std::endl;
124+ set_size_request (pixbuf->get_width ()/device_scale_x, pixbuf->get_height ()/device_scale_y);
125+ cr->scale (1.0 /device_scale_x, 1.0 /device_scale_y);
126+ Gdk::Cairo::set_source_pixbuf (cr, pixbuf, 0 , 0 );
127+ cr->paint ();
128+ cr->scale (1.0 , 1.0 );
129+
130+ return true ;
131+ }
0 commit comments