2 * figinset.C - part of LyX project
5 /* Rework of path-handling (Matthias 04.07.1996 )
6 * ------------------------------------------------
7 * figinsets keep an absolute path to the eps-file.
8 * For the user alway a relative path appears
9 * (in lyx-file, latex-file and edit-popup).
10 * To calculate this relative path the path to the
11 * document where the figinset is in is needed.
12 * This is done by a reference to the buffer, called
13 * figinset::cbuffer. To be up to date the cbuffer
14 * is sometimes set to the current buffer
15 * bufferlist.current(), when it can be assumed that
16 * this operation happens in the current buffer.
17 * This is true for InsetFig::Edit(...),
18 * InsetFig::InsetFig(...), InsetFig::Read(...),
19 * InsetFig::Write and InsetFig::Latex(...).
20 * Therefore the bufferlist has to make sure that
21 * during these operations bufferlist.current()
22 * returns the buffer where the figinsets are in.
23 * This made few changes in buffer.C necessary.
25 * The above is not totally valid anymore. (Lgb)
41 #include FORMS_H_LOCATION
51 #include "support/filetools.h"
52 #include "LyXView.h" // just because of form_main
54 #include "LaTeXFeatures.h"
57 #include "lyx_gui_misc.h" // CancelCloseBoxCB
58 #include "support/FileInfo.h"
59 #include "support/lyxlib.h"
62 #include "bufferview_funcs.h"
63 #include "ColorHandler.h"
76 using std::ostringstream;
79 extern BufferView * current_view;
80 extern FL_OBJECT * figinset_canvas;
82 extern char ** environ; // is this only redundtant on linux systems? Lgb.
84 static float const DEG2PI = 57.295779513;
86 struct queue_element {
87 float rx, ry; // resolution x and y
88 int ofsx, ofsy; // x and y translation
89 figdata * data; // we are doing it for this data
92 static int const MAXGS = 3; /* maximum 3 gs's at a time */
94 typedef vector<Figref *> figures_type;
95 typedef vector<figdata *> bitmaps_type;
96 static figures_type figures; // all figures
97 static bitmaps_type bitmaps; // all bitmaps
99 static queue<queue_element> gsqueue; // queue for ghostscripting
101 static int gsrunning = 0; /* currently so many gs's are running */
102 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
103 static char bittable[256]; /* bit reversion table */
105 static bool gs_color; // do we allocate colors for gs?
106 static bool color_visual; // is the visual color?
107 static bool gs_xcolor = false; // allocated extended colors
108 static unsigned long gs_pixels[128]; // allocated pixels
109 static int gs_num_pixels; // number of pixels allocated
110 static int gs_spc; // shades per color
111 static bool gs_gray; // is grayscale?
112 static int gs_allcolors; // number of all colors
114 static list<int> pidwaitlist; // pid wait list
120 val.foreground = BlackPixel(fl_display,
121 DefaultScreen(fl_display));
124 val.graphics_exposures = false;
125 val.line_style = LineSolid;
127 return XCreateGC(fl_display, RootWindow(fl_display, 0),
128 GCForeground | GCFunction | GCGraphicsExposures
129 | GCLineWidth | GCLineStyle , &val);
137 void addpidwait(int pid)
139 // adds pid to pid wait list
140 pidwaitlist.push_back(pid);
142 if (lyxerr.debugging()) {
143 lyxerr << "Pids to wait for: \n";
144 for (list<int>::const_iterator cit = pidwaitlist.begin();
145 cit != pidwaitlist.end(); ++cit) {
146 lyxerr << (*cit) << '\n';
154 string make_tmp(int pid)
156 return system_tempdir + "/~lyxgs" + tostr(pid) + ".ps";
161 void kill_gs(int pid, int sig)
163 if (lyxerr.debugging())
164 lyxerr << "Killing gs " << pid << endl;
166 unlink(make_tmp(pid).c_str());
171 int GhostscriptMsg(FL_OBJECT *, Window, int, int,
174 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
176 if(lyxerr.debugging()) {
177 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
178 << "] pm:[" << e->data.l[1] << "]" << endl;
181 // just kill gs, that way it will work for sure
182 // This loop looks like S**T so it probably is...
183 for (bitmaps_type::iterator it = bitmaps.begin();
184 it != bitmaps.end(); ++it)
185 if (static_cast<long>((*it)->bitmap) ==
186 static_cast<long>(e->data.l[1])) {
191 // first update p->bitmap, if necessary
192 if (p->bitmap != None
193 && p->flags > (1|8) && gs_color && p->wid) {
194 // query current colormap and re-render
195 // the pixmap with proper colors
196 XWindowAttributes wa;
197 register XImage * im;
201 int spc1 = gs_spc - 1;
202 int spc2 = gs_spc * gs_spc;
206 GC gc = local_gc_copy;
208 XGetWindowAttributes(fl_display,
213 if (lyxerr.debugging()) {
214 lyxerr << "Starting image translation "
217 << p->wid << "x" << p->hgh
219 << " " << XYPixmap << endl;
221 // now fork rendering process
223 if (forkstat == -1) {
225 << "Cannot fork, using slow "
226 "method for pixmap translation." << endl;
227 tmpdisp = fl_display;
228 } else if (forkstat > 0) { // parent
230 if (lyxerr.debugging()) {
231 lyxerr << "Spawned child "
234 addpidwait(forkstat);
237 tmpdisp = XOpenDisplay(XDisplayName(0));
240 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
241 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
243 if (lyxerr.debugging()) {
244 lyxerr << "Got the image" << endl;
247 if (lyxerr.debugging()) {
248 lyxerr << "Error getting the image" << endl;
253 // query current colormap
254 XColor * cmap = new XColor[gs_allcolors];
255 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
256 XQueryColors(tmpdisp,
257 fl_state[fl_get_vclass()]
262 // now we process all the image
263 for (y = 0; y < p->hgh; ++y) {
264 for (int x = 0; x < wid; ++x) {
269 gs_pixels[((pc->red+6553)*
270 spc1/65535)*spc2+((pc->green+6553)*
271 spc1/65535)*gs_spc+((pc->blue+6553)*
276 // This must be correct.
278 if (lyxerr.debugging()) {
279 lyxerr << "Putting image back"
282 XPutImage(tmpdisp, p->bitmap,
284 0, 0, p->wid, p->hgh);
286 if (lyxerr.debugging()) {
287 lyxerr << "Done translation"
292 kill_gs(p->gspid, SIGHUP);
294 XCloseDisplay(tmpdisp);
298 kill_gs(p->gspid, SIGHUP);
307 void AllocColors(int num)
308 // allocate color cube numxnumxnum, if possible
310 if (lyxerr.debugging()) {
311 lyxerr << "Allocating color cube " << num
312 << 'x' << num << 'x' << num << endl;
316 lyxerr << "Error allocating color colormap." << endl;
320 if (num > 5) num = 5;
322 for (int i = 0; i < num * num * num; ++i) {
323 xcol.red = 65535 * (i / (num * num)) / (num - 1);
324 xcol.green = 65535 * ((i / num) % num) / (num - 1);
325 xcol.blue = 65535 * (i % num) / (num - 1);
326 xcol.flags = DoRed | DoGreen | DoBlue;
327 if (!XAllocColor(fl_display,
328 fl_state[fl_get_vclass()].colormap, &xcol)) {
329 if (i) XFreeColors(fl_display,
330 fl_state[fl_get_vclass()].colormap,
332 if(lyxerr.debugging()) {
333 lyxerr << "Cannot allocate color cube "
336 AllocColors(num - 1);
339 gs_pixels[i] = xcol.pixel;
344 gs_num_pixels = num * num * num;
348 // allocate grayscale ramp
350 void AllocGrays(int num)
352 if (lyxerr.debugging()) {
353 lyxerr << "Allocating grayscale colormap "
358 lyxerr << "Error allocating grayscale colormap." << endl;
362 if (num > 128) num = 128;
364 for (int i = 0; i < num; ++i) {
365 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
366 xcol.flags = DoRed | DoGreen | DoBlue;
367 if (!XAllocColor(fl_display,
368 fl_state[fl_get_vclass()].colormap, &xcol)) {
369 if (i) XFreeColors(fl_display,
370 fl_state[fl_get_vclass()].colormap,
372 if (lyxerr.debugging()) {
373 lyxerr << "Cannot allocate grayscale "
379 gs_pixels[i] = xcol.pixel;
390 // if bitmaps and figures are not empty we will leak mem
395 for (unsigned int i = 0; i < 256; ++i) {
397 for (unsigned int j = 0; j < 8; ++j)
398 if (i & (1 << (7-j))) k |= 1 << j;
399 bittable[i] = char(~k);
402 // allocate color cube on pseudo-color display
406 fl_add_canvas_handler(figinset_canvas, ClientMessage,
408 current_view->owner()->getForm());
410 local_gc_copy = createGC();
412 Visual * vi = DefaultVisual(fl_display,
413 DefaultScreen(fl_display));
414 if (lyxerr.debugging()) {
415 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
416 vi->visualid, vi->c_class,
417 vi->bits_per_rgb, vi->map_entries);
419 color_visual = ( (vi->c_class == StaticColor) ||
420 (vi->c_class == PseudoColor) ||
421 (vi->c_class == TrueColor) ||
422 (vi->c_class == DirectColor) );
423 if ((vi->c_class & 1) == 0) return;
424 // now allocate colors
425 if (vi->c_class == GrayScale) {
426 // allocate grayscale
427 AllocGrays(vi->map_entries/2);
429 // allocate normal color
431 while (i * i * i * 2 > vi->map_entries) --i;
434 gs_allcolors = vi->map_entries;
442 // if bitmaps and figures are not empty we will leak mem
446 lyxerr.debug() << "Unregistering figures..." << endl;
448 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
454 void freefigdata(figdata * tmpdata)
457 if (tmpdata->ref) return;
459 if (tmpdata->gspid > 0) {
460 int pid = tmpdata->gspid;
461 // kill ghostscript and unlink it's files
463 kill_gs(pid, SIGKILL);
466 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
467 bitmaps.erase(find(bitmaps.begin(), bitmaps.end(), tmpdata));
475 // This _have_ to be set before the fork!
476 unsigned long background_pixel =
477 lyxColorHandler->colorPixel(LColor::background);
479 // run queued requests for ghostscript, if any
480 if (!gsrunning && gs_color && !gs_xcolor) {
481 // here alloc all colors, so that gs will use only
482 // those we allocated for it
487 while (gsrunning < MAXGS) {
488 //char tbuf[384]; //, tbuf2[80];
492 if (gsqueue.empty()) {
493 if (!gsrunning && gs_xcolor) {
494 // de-allocate rest of colors
500 queue_element * p = &gsqueue.front();
509 if (lyxerr.debugging()) {
510 lyxerr << "GS start error! Cannot fork."
513 p->data->broken = true;
514 p->data->reading = false;
517 if (pid == 0) { // child
520 Display * tempdisp = XOpenDisplay(XDisplayName(0));
522 // create translation file
524 ofs.open(make_tmp(getpid()).c_str());
525 ofs << "gsave clippath pathbbox grestore\n"
527 << "/ury exch def /urx exch def /lly exch def "
529 << p->data->wid / 2.0 << " "
530 << p->data->hgh / 2.0 << " translate\n"
531 << p->data->angle << " rotate\n"
532 << -(p->data->raw_wid / 2.0) << " "
533 << -(p->data->raw_hgh / 2.0) << " translate\n"
534 << p->rx / 72.0 << " " << p->ry / 72.0
536 << -p->ofsx << " " << -p->ofsy << " translate\n"
538 ofs.close(); // Don't remove this.
540 // gs process - set ghostview environment first
545 ostrstream t2(tbuf2, sizeof(tbuf2));
547 t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
548 << ' ' << p->data->bitmap;
552 // now set up ghostview property on a window
553 // #warning BUG seems that the only bug here
554 // might be the hardcoded dpi.. Bummer!
559 ostrstream t1(tbuf, sizeof(tbuf));
561 t1 << "0 0 0 0 " << p->data->wid << ' '
562 << p->data->hgh << " 72 72 0 0 0 0";
567 if (lyxerr.debugging()) {
568 lyxerr << "Will set GHOSTVIEW property to ["
569 << t1.str() << "]" << endl;
571 // wait until property is deleted if executing multiple
573 XGrabServer(tempdisp);
575 // grab server to prevent other child
576 // interfering with setting GHOSTVIEW property
577 // The grabbing goes on for too long, is it
578 // really needed? (Lgb)
579 // I moved most of the grabs... (Lgb)
580 if (lyxerr.debugging()) {
581 lyxerr << "Grabbing the server"
584 prop = XListProperties(tempdisp,
586 figinset_canvas), &nprop);
590 for (i = 0; i < nprop; ++i) {
591 char * p = XGetAtomName(tempdisp,
593 if (strcmp(p, "GHOSTVIEW") == 0) {
599 XFree(reinterpret_cast<char *>(prop)); // jc:
601 // ok, property found, we must wait until
602 // ghostscript deletes it
603 if (lyxerr.debugging()) {
604 lyxerr << "Releasing the server\n["
606 << "] GHOSTVIEW property"
607 " found. Waiting." << endl;
609 XUngrabServer(tempdisp);
612 XGrabServer(tempdisp);
615 XChangeProperty(tempdisp,
616 fl_get_canvas_id(figinset_canvas),
617 XInternAtom(tempdisp, "GHOSTVIEW", false),
618 XInternAtom(tempdisp, "STRING", false),
620 reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str().c_str())),
624 XChangeProperty(tempdisp,
625 fl_get_canvas_id(figinset_canvas),
626 XInternAtom(tempdisp, "GHOSTVIEW", false),
627 XInternAtom(tempdisp, "STRING", false),
629 reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str())),
632 XUngrabServer(tempdisp);
639 ostrstream t3(tbuf, sizeof(tbuf));
641 switch (p->data->flags & 3) {
642 case 0: t3 << 'H'; break; // Hidden
643 case 1: t3 << 'M'; break; // Mono
644 case 2: t3 << 'G'; break; // Gray
653 t3 << ' ' << BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp))
654 << ' ' << background_pixel;
659 XGrabServer(tempdisp);
661 XChangeProperty(tempdisp,
662 fl_get_canvas_id(figinset_canvas),
663 XInternAtom(tempdisp,
664 "GHOSTVIEW_COLORS", false),
665 XInternAtom(tempdisp, "STRING", false),
667 reinterpret_cast<unsigned char*>(const_cast<char*>(t3.str().c_str())),
670 XChangeProperty(tempdisp,
671 fl_get_canvas_id(figinset_canvas),
672 XInternAtom(tempdisp,
673 "GHOSTVIEW_COLORS", false),
674 XInternAtom(tempdisp, "STRING", false),
676 reinterpret_cast<unsigned char*>(const_cast<char*>(t3.str())),
679 XUngrabServer(tempdisp);
682 if (lyxerr.debugging()) {
683 lyxerr << "Releasing the server" << endl;
685 XCloseDisplay(tempdisp);
687 // set up environment
690 typedef char * char_p;
691 env = new char_p[ne + 2];
693 string tmp = t2.str().c_str();
694 env[0] = new char[tmp.size() + 1];
695 std::copy(tmp.begin(), tmp.end(), env[0]);
696 env[0][tmp.size()] = '\0';
700 ::memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
703 // now make gs command
705 // close(1); do NOT close. If GS writes out
706 // errors it would hang. (Matthias 290596)
708 string rbuf = "-r" + tostr(p->rx) + "x" + tostr(p->ry);
709 string gbuf = "-g" + tostr(p->data->wid) + "x" + tostr(p->data->hgh);
711 // now chdir into dir with .eps file, to be on the safe
713 ::chdir(OnlyPath(p->data->fname).c_str());
714 // make temp file name
715 string tmpf = make_tmp(getpid());
716 if (lyxerr.debugging()) {
717 lyxerr << "starting gs " << tmpf << " "
719 << ", pid: " << getpid() << endl;
722 int err = ::execlp(lyxrc.ps_command.c_str(),
723 lyxrc.ps_command.c_str(),
725 "-dNOPAUSE", "-dQUIET",
727 rbuf.c_str(), gbuf.c_str(), tmpf.c_str(),
728 p->data->fname.c_str(),
729 "showpage.ps", "quit.ps", "-", 0);
730 // if we are still there, an error occurred.
731 lyxerr << "Error executing ghostscript. "
732 << "Code: " << err << endl;
733 lyxerr.debug() << "Cmd: "
736 << tmpf.c_str() << ' '
737 << p->data->fname << endl;
740 // normal process (parent)
741 if (lyxerr.debugging()) {
742 lyxerr << "GS [" << pid << "] started" << endl;
745 p->data->gspid = pid;
753 void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
755 // recompute the stuff and put in the queue
759 p.rx = (float(data->raw_wid) * 72.0) / pswid;
760 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
766 // if possible, run the queue
772 figdata * getfigdata(int wid, int hgh, string const & fname,
773 int psx, int psy, int pswid, int pshgh,
774 int raw_wid, int raw_hgh, float angle, char flags)
776 /* first search for an exact match with fname and width/height */
778 if (fname.empty() || !IsFileReadable(fname))
781 for (bitmaps_type::iterator it = bitmaps.begin();
782 it != bitmaps.end(); ++it) {
783 if ((*it)->wid == wid && (*it)->hgh == hgh &&
784 (*it)->flags == flags && (*it)->fname == fname &&
785 (*it)->angle == angle) {
790 figdata * p = new figdata;
793 p->raw_wid = raw_wid;
794 p->raw_hgh = raw_hgh;
798 bitmaps.push_back(p);
799 XWindowAttributes wa;
800 XGetWindowAttributes(fl_display, fl_get_canvas_id(
801 figinset_canvas), &wa);
803 if (lyxerr.debugging()) {
804 lyxerr << "Create pixmap disp:" << fl_display
805 << " scr:" << DefaultScreen(fl_display)
808 << " depth:" << wa.depth << endl;
816 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
817 figinset_canvas), wid, hgh, wa.depth);
819 // initialize reading of .eps file with correct sizes and stuff
820 addwait(psx, psy, pswid, pshgh, p);
832 void getbitmap(figdata * p)
839 void makeupdatelist(figdata * p)
841 for(figures_type::iterator it = figures.begin();
842 it != figures.end(); ++it)
843 if ((*it)->data == p) {
844 if (lyxerr.debugging()) {
845 lyxerr << "Updating inset "
849 // add inset figures[i]->inset into to_update list
850 current_view->pushIntoUpdateList((*it)->inset);
855 // this func is only "called" in spellchecker.C
856 void sigchldchecker(pid_t pid, int * status)
858 lyxerr.debug() << "Got pid = " << pid << endl;
859 bool pid_handled = false;
860 for (bitmaps_type::iterator it = bitmaps.begin();
861 it != bitmaps.end(); ++it) {
862 if ((*it)->reading && pid == (*it)->gspid) {
863 lyxerr.debug() << "Found pid in bitmaps" << endl;
864 // now read the file and remove it from disk
867 if ((*it)->gsdone) *status = 0;
869 lyxerr.debug() << "GS [" << pid
870 << "] exit OK." << endl;
872 lyxerr << "GS [" << pid << "] error "
874 << WIFEXITED(*status)
875 << " " << WEXITSTATUS(*status)
876 << " S:" << WIFSIGNALED(*status)
877 << " " << WTERMSIG(*status) << endl;
880 bitmap_waiting = true;
883 // remove temporary files
884 unlink(make_tmp(p->gspid).c_str());
888 makeupdatelist((*it));
895 lyxerr.debug() << "Checking pid in pidwait" << endl;
896 list<int>::iterator it = find(pidwaitlist.begin(),
897 pidwaitlist.end(), pid);
898 if (it != pidwaitlist.end()) {
899 lyxerr.debug() << "Found pid in pidwait\n"
900 << "Caught child pid of recompute "
901 "routine" << pid << endl;
902 pidwaitlist.erase(it);
906 lyxerr.debug() << "waitpid error" << endl;
909 lyxerr << "The process or process group specified by "
910 "pid does not exist or is not a child of "
911 "the calling process or can never be in the "
912 "states specified by options." << endl;
915 lyxerr << "waitpid() was interrupted due to the "
916 "receipt of a signal sent by the calling "
920 lyxerr << "An invalid value was specified for "
924 lyxerr << "Unknown error from waitpid" << endl;
927 } else if (pid == 0) {
928 lyxerr << "waitpid nohang" << endl;;
930 lyxerr.debug() << "normal exit from childhandler" << endl;
938 bitmap_waiting = false;
939 for (bitmaps_type::iterator it = bitmaps.begin();
940 it != bitmaps.end(); ++it)
941 if ((*it)->gspid > 0 && !(*it)->reading)
947 void RegisterFigure(InsetFig * fi)
949 if (figures.empty()) InitFigures();
951 Figref * tmpfig = new Figref;
954 figures.push_back(tmpfig);
957 if (lyxerr.debugging()) {
958 lyxerr << "Register Figure: buffer:["
959 << current_view->buffer() << "]" << endl;
965 void UnregisterFigure(InsetFig * fi)
967 Figref * tmpfig = fi->figure;
969 if (tmpfig->data) freefigdata(tmpfig->data);
970 if (tmpfig->inset->form) {
971 if (tmpfig->inset->form->Figure->visible) {
972 fl_set_focus_object(tmpfig->inset->form->Figure,
973 tmpfig->inset->form->OkBtn);
974 fl_hide_form(tmpfig->inset->form->Figure);
976 #if FL_REVISION == 89
977 // CHECK Reactivate this free_form calls
979 fl_free_form(tmpfig->inset->form->Figure);
980 free(tmpfig->inset->form); // Why free?
981 tmpfig->inset->form = 0;
984 figures.erase(find(figures.begin(), figures.end(), tmpfig));
987 if (figures.empty()) DoneFigures();
991 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1001 psubfigure = subfigure = false;
1002 xwid = xhgh = angle = 0;
1004 raw_wid = raw_hgh = 0;
1005 changedfname = false;
1006 RegisterFigure(this);
1010 InsetFig::~InsetFig()
1012 if (lyxerr.debugging()) {
1013 lyxerr << "Figure destructor called" << endl;
1015 UnregisterFigure(this);
1019 int InsetFig::ascent(Painter &, LyXFont const &) const
1025 int InsetFig::descent(Painter &, LyXFont const &) const
1031 int InsetFig::width(Painter &, LyXFont const &) const
1037 void InsetFig::draw(BufferView * bv, LyXFont const & f,
1038 int baseline, float & x, bool) const
1041 Painter & pain = bv->painter();
1043 if (bitmap_waiting) getbitmaps();
1045 // I wish that I didn't have to use this
1046 // but the figinset code is so complicated so
1047 // I don't want to fiddle with it now.
1049 if (figure && figure->data && figure->data->bitmap &&
1050 !figure->data->reading && !figure->data->broken) {
1052 pain.pixmap(int(x + 1), baseline - hgh,
1053 wid, hgh, figure->data->bitmap);
1056 pain.rectangle(int(x), baseline - hgh - 1,
1062 pain.rectangle(int(x), baseline - hgh - 1, wid + 1, hgh + 1);
1064 if (figure && figure->data) {
1065 if (figure->data->broken) msg = _("[render error]");
1066 else if (figure->data->reading) msg = _("[rendering ... ]");
1068 else if (fname.empty())
1069 msg = _("[no file]");
1070 else if (!IsFileReadable(fname))
1071 msg = _("[bad file name]");
1072 else if ((flags & 3) == 0)
1073 msg = _("[not displayed]");
1074 else if (lyxrc.ps_command.empty())
1075 msg = _("[no ghostscript]");
1077 if (!msg) msg = _("[unknown error]");
1079 font.setFamily(LyXFont::SANS_FAMILY);
1080 font.setSize(LyXFont::SIZE_FOOTNOTE);
1081 string justname = OnlyFilename (fname);
1082 pain.text(int(x + 8), baseline - lyxfont::maxAscent(font) - 4,
1085 font.setSize(LyXFont::SIZE_TINY);
1086 pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
1088 x += width(pain, font); // ?
1092 void InsetFig::Write(Buffer const *, ostream & os) const
1095 os << "Figure size " << wid << " " << hgh << "\n";
1096 if (!fname.empty()) {
1097 string buf1 = OnlyPath(owner->fileName());
1098 string fname2 = MakeRelPath(fname, buf1);
1099 os << "file " << fname2 << "\n";
1101 if (!subcaption.empty())
1102 os << "subcaption " << subcaption << "\n";
1103 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1104 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1105 if (angle != 0) os << "angle " << angle << "\n";
1106 os << "flags " << flags << "\n";
1107 if (subfigure) os << "subfigure\n";
1111 void InsetFig::Read(Buffer const *, LyXLex & lex)
1114 bool finished = false;
1116 while (lex.IsOK() && !finished) {
1119 string const token = lex.GetString();
1120 lyxerr.debug() << "Token: " << token << endl;
1124 else if (token == "\\end_inset") {
1126 } else if (token == "file") {
1128 buf = lex.GetString();
1129 string buf1 = OnlyPath(owner->fileName());
1130 fname = MakeAbsPath(buf, buf1);
1131 changedfname = true;
1133 } else if (token == "extra") {
1135 // kept for backwards compability. Delete in 0.13.x
1136 } else if (token == "subcaption") {
1138 subcaption = lex.GetString();
1139 } else if (token == "label") {
1141 // kept for backwards compability. Delete in 0.13.x
1142 } else if (token == "angle") {
1144 angle = lex.GetFloat();
1145 } else if (token == "size") {
1147 wid = lex.GetInteger();
1149 hgh = lex.GetInteger();
1150 } else if (token == "flags") {
1152 flags = pflags = lex.GetInteger();
1153 } else if (token == "subfigure") {
1154 subfigure = psubfigure = true;
1155 } else if (token == "width") {
1158 typ = lex.GetInteger();
1160 xwid = lex.GetFloat();
1162 case DEF: wtype = DEF; break;
1163 case CM: wtype = CM; break;
1164 case IN: wtype = IN; break;
1165 case PER_PAGE: wtype = PER_PAGE; break;
1166 case PER_COL: wtype = PER_COL; break;
1168 lyxerr.debug() << "Unknown type!" << endl;
1172 } else if (token == "height") {
1175 typ = lex.GetInteger();
1177 xhgh = lex.GetFloat();
1179 case DEF: htype = DEF; break;
1180 case CM: htype = CM; break;
1181 case IN: htype = IN; break;
1182 case PER_PAGE: htype = PER_PAGE; break;
1184 lyxerr.debug() << "Unknown type!" << endl;
1195 int InsetFig::Latex(Buffer const *, ostream & os,
1196 bool /* fragile*/, bool /* fs*/) const
1199 if (!cmd.empty()) os << cmd << " ";
1204 int InsetFig::Ascii(Buffer const *, ostream &) const
1210 int InsetFig::Linuxdoc(Buffer const *, ostream &) const
1216 int InsetFig::DocBook(Buffer const *, ostream & os) const
1218 string buf1 = OnlyPath(owner->fileName());
1219 string figurename = MakeRelPath(fname, buf1);
1221 if(suffixIs(figurename, ".eps"))
1222 figurename.erase(fname.length() - 4);
1224 os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
1229 void InsetFig::Validate(LaTeXFeatures & features) const
1231 features.graphics = true;
1232 if (subfigure) features.subfigure = true;
1236 Inset::EDITABLE InsetFig::Editable() const
1242 bool InsetFig::Deletable() const
1248 char const * InsetFig::EditMessage() const
1250 return _("Opened figure");
1254 void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
1256 lyxerr.debug() << "Editing InsetFig." << endl;
1259 // We should have RO-versions of the form instead.
1260 // The actual prevention of altering a readonly doc
1261 // is done in CallbackFig()
1262 if(bv->buffer()->isReadonly())
1263 WarnReadonly(bv->buffer()->fileName());
1266 form = create_form_Figure();
1267 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1268 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1269 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1270 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1273 if (form->Figure->visible) {
1274 fl_raise_form(form->Figure);
1276 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1277 FL_FULLBORDER, _("Figure"));
1282 Inset * InsetFig::Clone() const
1284 InsetFig * tmp = new InsetFig(100, 100, owner);
1286 if (lyxerr.debugging()) {
1287 lyxerr << "Clone Figure: buffer:["
1288 << current_view->buffer()
1289 << "], cbuffer:[xx]" << endl;
1294 tmp->raw_wid = raw_wid;
1295 tmp->raw_hgh = raw_hgh;
1300 tmp->pflags = pflags;
1301 tmp->subfigure = subfigure;
1302 tmp->psubfigure = psubfigure;
1310 if (!fname.empty() && IsFileReadable(fname)
1311 && (flags & 3) && !lyxrc.ps_command.empty()
1313 // do not display if there is
1314 // "do not display" chosen (Matthias 260696)
1315 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1316 pswid, pshgh, raw_wid, raw_hgh,
1317 angle, flags & (3|8));
1318 } else tmp->figure->data = 0;
1319 tmp->subcaption = subcaption;
1320 tmp->changedfname = false;
1327 Inset::Code InsetFig::LyxCode() const
1329 return Inset::GRAPHICS_CODE;
1334 string stringify(InsetFig::HWTYPE hw, float f, string suffix)
1340 case InsetFig::CM:// \resizebox*{h-length}{v-length}{text}
1341 res = tostr(f) + "cm";
1344 res = tostr(f) + "in";
1346 case InsetFig::PER_PAGE:
1347 res = tostr(f/100) + "\\text" + suffix;
1349 case InsetFig::PER_COL:
1350 // Doesn't occur for htype...
1351 res = tostr(f/100) + "\\column" + suffix;
1358 void InsetFig::Regenerate() const
1361 string resizeW, resizeH;
1362 string rotate, recmd;
1364 if (fname.empty()) {
1365 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1366 cmd += _("empty figure path");
1371 string buf1 = OnlyPath(owner->fileName());
1372 string fname2 = MakeRelPath(fname, buf1);
1374 string gcmd = "\\includegraphics{" + fname2 + '}';
1375 resizeW = stringify(wtype, xwid, "width");
1376 resizeH = stringify(htype, xhgh, "height");
1378 if (!resizeW.empty() || !resizeH.empty()) {
1379 recmd = "\\resizebox*{";
1380 if (!resizeW.empty())
1385 if (!resizeH.empty())
1394 // \rotatebox{angle}{text}
1395 rotate = "\\rotatebox{" + tostr(angle) + "}{";
1401 if (!rotate.empty()) cmdbuf += '}';
1402 if (!recmd.empty()) cmdbuf += '}';
1404 if (!subcaption.empty())
1405 cmdbuf = "\\subfigure[" + subcaption +
1406 "]{" + cmdbuf + "}";
1408 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1415 void InsetFig::TempRegenerate()
1418 string resizeW, resizeH;
1419 string rotate, recmd;
1421 char const * tfname = fl_get_input(form->EpsFile);
1422 string tsubcap = fl_get_input(form->Subcaption);
1423 float tangle = atof(fl_get_input(form->Angle));
1424 float txwid = atof(fl_get_input(form->Width));
1425 float txhgh = atof(fl_get_input(form->Height));
1427 if (!tfname || !*tfname) {
1428 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1429 cmd += _("empty figure path");
1434 string buf1 = OnlyPath(owner->fileName());
1435 string fname2 = MakeRelPath(tfname, buf1);
1436 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1437 string gcmd = "\\includegraphics{" + fname2 + '}';
1439 resizeW = stringify(twtype, txwid, "width");
1440 resizeH = stringify(thtype, txhgh, "height");
1442 // \resizebox*{h-length}{v-length}{text}
1443 if (!resizeW.empty() || !resizeH.empty()) {
1444 recmd = "\\resizebox*{";
1445 if (!resizeW.empty())
1450 if (!resizeH.empty())
1458 // \rotatebox{angle}{text}
1459 rotate = "\\rotatebox{" + tostr(tangle) + "}{";
1462 cmdbuf = recmd + rotate + gcmd;
1463 if (!rotate.empty()) cmdbuf += '}';
1464 if (!recmd.empty()) cmdbuf += '}';
1465 if (psubfigure && !tsubcap.empty()) {
1466 cmdbuf = string("\\subfigure{") + tsubcap
1467 + string("}{") + cmdbuf + "}";
1472 void InsetFig::Recompute()
1474 bool changed = changedfname;
1475 int newx, newy, nraw_x, nraw_y;
1477 if (changed) GetPSSizes();
1479 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1480 float cos_a = cos (angle / DEG2PI);
1481 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1482 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1484 /* now recompute wid and hgh, and if that is changed, set changed */
1485 /* this depends on chosen size of the picture and its bbox */
1486 // This will be redone in 0.13 ... (hen)
1487 if (!fname.empty() && IsFileReadable(fname)) {
1488 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1496 newx = int(28.346 * xwid);
1499 newx = int(72 * xwid);
1501 case PER_PAGE: /* % of page */
1502 newx = int(5.95 * xwid);
1504 case PER_COL: /* % of col */
1505 newx = int(2.975 * xwid);
1509 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1513 //lyxerr << "This should not happen!" << endl;
1516 newy = int(28.346 * xhgh);
1519 newy = int(72 * xhgh);
1521 case PER_PAGE: /* % of page */
1522 newy = int(8.42 * xhgh);
1525 // Doesn't occur; case exists to suppress
1526 // compiler warnings.
1529 if (htype && !wtype && frame_hgh)
1530 newx = newy*frame_wid/frame_hgh;
1539 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1544 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1546 // cannot be zero, actually, set it to some minimum, so its clickable
1547 if (newx < 5) newx = 5;
1548 if (newy < 5) newy = 5;
1550 if (newx != wid || newy != hgh ||
1551 nraw_x != raw_wid || nraw_y != raw_hgh ||
1552 flags != pflags || subfigure != psubfigure)
1560 subfigure = psubfigure;
1563 figdata * pf = figure->data;
1566 if (!fname.empty() && IsFileReadable(fname) && (flags & 3)
1567 && !lyxrc.ps_command.empty()) {
1568 // do not display if there is "do not display"
1569 // chosen (Matthias 260696)
1570 figure->data = getfigdata(wid, hgh, fname,
1571 psx, psy, pswid, pshgh,
1573 angle, flags & (3|8));
1574 } else figure->data = 0;
1576 // free the old data
1577 if (pf) freefigdata(pf);
1580 changedfname = false;
1584 void InsetFig::GetPSSizes()
1586 /* get %%BoundingBox: from postscript file */
1588 /* defaults to associated size
1589 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1596 if (fname.empty()) return;
1598 ifstream ifs(fname.c_str());
1600 if (!ifs) return; // file not found !!!!
1602 /* defaults to A4 page */
1608 char lastchar = 0; ifs.get(lastchar);
1610 char c = 0; ifs.get(c);
1612 lyxerr.debug() << "End of (E)PS file reached and"
1613 " no BoundingBox!" << endl;
1616 if (c == '%' && lastchar == '%') {
1618 if (p.empty()) break;
1619 lyxerr.debug() << "Token: `" << p << "'" << endl;
1620 if (p == "BoundingBox:") {
1621 float fpsx, fpsy, fpswid, fpshgh;
1622 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1625 pswid = int(fpswid);
1626 pshgh = int(fpshgh);
1628 if (lyxerr.debugging()) {
1629 lyxerr << "%%%%BoundingBox:"
1647 void InsetFig::CallbackFig(long arg)
1652 if (lyxerr.debugging()) {
1653 lyxerr << "Figure callback, arg " << arg << endl;
1659 case 12: /* width type */
1666 fl_deactivate_object(form->Width);
1671 fl_activate_object(form->Width);
1676 fl_activate_object(form->Width);
1681 fl_activate_object(form->Width);
1686 fl_activate_object(form->Width);
1689 lyxerr.debug() << "Unknown type!" << endl;
1696 case 22: /* height type */
1702 fl_deactivate_object(form->Height);
1707 fl_activate_object(form->Height);
1712 fl_activate_object(form->Height);
1717 fl_activate_object(form->Height);
1720 lyxerr.debug() << "Unknown type!" << endl;
1726 pflags = pflags & ~3; /* wysiwyg0 */
1729 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1732 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1735 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1738 pflags ^= 4; /* frame */
1741 pflags ^= 8; /* do translations */
1744 psubfigure = !psubfigure; /* This is a subfigure */
1747 regen = true; /* regenerate command */
1749 case 0: /* browse file */
1753 case 1: /* preview */
1754 p = fl_get_input(form->EpsFile);
1758 case 8: /* ok (apply and close) */
1759 if(!current_view->buffer()->isReadonly()) {
1762 xwid = atof(fl_get_input(form->Width));
1763 xhgh = atof(fl_get_input(form->Height));
1764 angle = atof(fl_get_input(form->Angle));
1765 p = fl_get_input(form->EpsFile);
1767 string buf1 = OnlyPath(owner->fileName());
1768 fname = MakeAbsPath(p, buf1);
1769 changedfname = true;
1771 if (!fname.empty()) {
1772 changedfname = true;
1776 subcaption = fl_get_input(form->Subcaption);
1780 /* now update inset */
1781 if (lyxerr.debugging()) {
1782 lyxerr << "Update: ["
1783 << wid << 'x' << hgh << ']' << endl;
1785 current_view->updateInset(this, true);
1787 fl_set_focus_object(form->Figure, form->OkBtn);
1788 fl_hide_form(form->Figure);
1789 #if FL_REVISION == 89
1790 // CHECK Reactivate this free_form calls
1792 fl_free_form(form->Figure);
1793 free(form); // Why free?
1799 // The user has already been informed about RO in ::Edit
1800 if(arg == 7) // if 'Apply'
1803 case 9: /* cancel = restore and close */
1804 fl_set_focus_object(form->Figure, form->OkBtn);
1805 fl_hide_form(form->Figure);
1806 #if FL_REVISION == 89
1807 // CHECK Reactivate this free_form calls
1808 // Jug, is this still a problem?
1810 fl_free_form(form->Figure);
1811 free(form); // Why free?
1817 if (regen) TempRegenerate();
1822 void DisableFigurePanel(FD_Figure * const form)
1824 fl_deactivate_object(form->EpsFile);
1825 fl_deactivate_object(form->Browse);
1826 fl_deactivate_object(form->Width);
1827 fl_deactivate_object(form->Height);
1828 fl_deactivate_object(form->Frame);
1829 fl_deactivate_object(form->Translations);
1830 fl_deactivate_object(form->Angle);
1831 fl_deactivate_object(form->HeightGrp);
1832 fl_deactivate_object(form->page2);
1833 fl_deactivate_object(form->Default2);
1834 fl_deactivate_object(form->cm2);
1835 fl_deactivate_object(form->in2);
1836 fl_deactivate_object(form->HeightLabel);
1837 fl_deactivate_object(form->WidthLabel);
1838 fl_deactivate_object(form->DisplayGrp);
1839 fl_deactivate_object(form->Wysiwyg3);
1840 fl_deactivate_object(form->Wysiwyg0);
1841 fl_deactivate_object(form->Wysiwyg2);
1842 fl_deactivate_object(form->Wysiwyg1);
1843 fl_deactivate_object(form->WidthGrp);
1844 fl_deactivate_object(form->Default1);
1845 fl_deactivate_object(form->cm1);
1846 fl_deactivate_object(form->in1);
1847 fl_deactivate_object(form->page1);
1848 fl_deactivate_object(form->column1);
1849 fl_deactivate_object(form->Subcaption);
1850 fl_deactivate_object(form->Subfigure);
1851 fl_deactivate_object (form->OkBtn);
1852 fl_deactivate_object (form->ApplyBtn);
1853 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1854 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1859 void EnableFigurePanel(FD_Figure * const form)
1861 fl_activate_object(form->EpsFile);
1862 fl_activate_object(form->Browse);
1863 fl_activate_object(form->Width);
1864 fl_activate_object(form->Height);
1865 fl_activate_object(form->Frame);
1866 fl_activate_object(form->Translations);
1867 fl_activate_object(form->Angle);
1868 fl_activate_object(form->HeightGrp);
1869 fl_activate_object(form->page2);
1870 fl_activate_object(form->Default2);
1871 fl_activate_object(form->cm2);
1872 fl_activate_object(form->in2);
1873 fl_activate_object(form->HeightLabel);
1874 fl_activate_object(form->WidthLabel);
1875 fl_activate_object(form->DisplayGrp);
1876 fl_activate_object(form->Wysiwyg3);
1877 fl_activate_object(form->Wysiwyg0);
1878 fl_activate_object(form->Wysiwyg2);
1879 fl_activate_object(form->Wysiwyg1);
1880 fl_activate_object(form->WidthGrp);
1881 fl_activate_object(form->Default1);
1882 fl_activate_object(form->cm1);
1883 fl_activate_object(form->in1);
1884 fl_activate_object(form->page1);
1885 fl_activate_object(form->column1);
1886 fl_activate_object(form->Subcaption);
1887 fl_activate_object(form->Subfigure);
1888 fl_activate_object (form->OkBtn);
1889 fl_activate_object (form->ApplyBtn);
1890 fl_set_object_lcol (form->OkBtn, FL_BLACK);
1891 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
1895 void InsetFig::RestoreForm()
1897 EnableFigurePanel(form);
1900 fl_set_button(form->Default1, (wtype == 0));
1901 fl_set_button(form->cm1, (wtype == 1));
1902 fl_set_button(form->in1, (wtype == 2));
1903 fl_set_button(form->page1, (wtype == 3));
1904 fl_set_button(form->column1, (wtype == 4));
1906 fl_deactivate_object(form->Width);
1908 fl_activate_object(form->Width);
1911 // enable and disable should be put here.
1913 fl_set_button(form->Default2, (htype == 0));
1914 fl_set_button(form->cm2, (htype == 1));
1915 fl_set_button(form->in2, (htype == 2));
1916 fl_set_button(form->page2, (htype == 3));
1917 // enable and disable should be put here.
1919 fl_deactivate_object(form->Height);
1921 fl_activate_object(form->Height);
1924 int piflags = flags & 3;
1925 fl_set_button(form->Wysiwyg0, (piflags == 0));
1926 fl_set_button(form->Wysiwyg1, (piflags == 1));
1927 fl_set_button(form->Wysiwyg2, (piflags == 2));
1928 fl_set_button(form->Wysiwyg3, (piflags == 3));
1929 fl_set_button(form->Frame, ((flags & 4) != 0));
1930 fl_set_button(form->Translations, ((flags & 8) != 0));
1931 fl_set_button(form->Subfigure, (subfigure != 0));
1933 psubfigure = subfigure;
1934 fl_set_input(form->Width, tostr(xwid).c_str());
1935 fl_set_input(form->Height, tostr(xhgh).c_str());
1936 fl_set_input(form->Angle, tostr(angle).c_str());
1937 if (!fname.empty()){
1938 string buf1 = OnlyPath(owner->fileName());
1939 string fname2 = MakeRelPath(fname, buf1);
1940 fl_set_input(form->EpsFile, fname2.c_str());
1942 else fl_set_input(form->EpsFile, "");
1943 fl_set_input(form->Subcaption, subcaption.c_str());
1944 if(current_view->buffer()->isReadonly())
1945 DisableFigurePanel(form);
1951 void InsetFig::Preview(char const * p)
1956 lyxerr << "Cannot fork process!" << endl;
1961 return; // parent process
1964 string buf1 = OnlyPath(owner->fileName());
1965 string buf2 = MakeAbsPath(p, buf1);
1967 lyxerr << "Error during rendering "
1968 << execlp(lyxrc.view_pspic_command.c_str(),
1969 lyxrc.view_pspic_command.c_str(),
1976 void InsetFig::BrowseFile()
1978 static string current_figure_path;
1979 static int once = 0;
1982 if (lyxerr.debugging()) {
1983 lyxerr << "Filename: "
1984 << owner->fileName() << endl;
1986 string p = fl_get_input(form->EpsFile);
1988 string buf = MakeAbsPath(owner->fileName());
1989 string buf2 = OnlyPath(buf);
1991 buf = MakeAbsPath(p, buf2);
1992 buf = OnlyPath(buf);
1994 buf = OnlyPath(owner->fileName().c_str());
1997 // Does user clipart directory exist?
1998 string bufclip = AddName (user_lyxdir, "clipart");
1999 FileInfo fileInfo(bufclip);
2000 if (!(fileInfo.isOK() && fileInfo.isDir()))
2001 // No - bail out to system clipart directory
2002 bufclip = AddName (system_lyxdir, "clipart");
2005 fileDlg.SetButton(0, _("Clipart"), bufclip);
2006 fileDlg.SetButton(1, _("Document"), buf);
2010 ProhibitInput(current_view);
2012 p = fileDlg.Select(_("EPS Figure"),
2013 current_figure_path,
2016 p = fileDlg.Select(_("EPS Figure"), buf,
2019 AllowInput(current_view);
2021 if (p.empty()) return;
2023 buf = MakeRelPath(p, buf2);
2024 current_figure_path = OnlyPath(p);
2027 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2028 || contains(p, "%") || contains(p, " ")) {
2029 WriteAlert(_("Filename can't contain any "
2030 "of these characters:"),
2031 // xgettext:no-c-format
2032 _("space, '#', '~', '$' or '%'."));
2037 if (form) fl_set_input(form->EpsFile, buf.c_str());
2041 void GraphicsCB(FL_OBJECT * obj, long arg)
2043 /* obj->form contains the form */
2045 if (lyxerr.debugging()) {
2046 lyxerr << "GraphicsCB callback: " << arg << endl;
2049 /* find inset we were reacting to */
2050 for (figures_type::iterator it = figures.begin();
2051 it != figures.end(); ++it)
2052 if ((*it)->inset->form && (*it)->inset->form->Figure
2054 if (lyxerr.debugging()) {
2055 lyxerr << "Calling back figure "
2058 (*it)->inset->CallbackFig(arg);
2064 void HideFiguresPopups()
2066 for (figures_type::iterator it = figures.begin();
2067 it != figures.end(); ++it)
2068 if ((*it)->inset->form
2069 && (*it)->inset->form->Figure->visible) {
2070 if (lyxerr.debugging()) {
2071 lyxerr << "Hiding figure " << (*it) << endl;
2073 // hide and free the form
2074 (*it)->inset->CallbackFig(9);