]> git.lyx.org Git - lyx.git/blob - src/insets/insetlatexaccent.C
61d1b75cce43a3ec27f106e72806c3f4491a0d2d
[lyx.git] / src / insets / insetlatexaccent.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetlatexaccent.h"
18 #include "debug.h"
19 #include "lyxrc.h"
20 #ifndef USE_PAINTER
21 #include "lyxdraw.h"
22 #endif
23 #include "support/lstrings.h"
24 #include "Painter.h"
25
26 extern LyXRC * lyxrc;
27
28 /* LatexAccent. Proper handling of accented characters */
29 /* This part is done by Ivan Schreter, schreter@ccsun.tuke.sk */
30 /* Later modified by Lars G. Bjønnes, larsbj@lyx.org */
31
32 InsetLatexAccent::InsetLatexAccent()
33 {
34         candisp = false;
35 }
36
37
38 InsetLatexAccent::InsetLatexAccent(string const & string)
39         : contents(string)
40 {
41         checkContents();
42 }
43
44
45 void InsetLatexAccent::checkContents()
46         // check, if we know the modifier and can display it ok on screen
47 {
48         candisp = false;
49
50         if (contents.empty() || contents.length() < 2) return;
51
52         // REMOVE IN 0.13
53         // Dirty Hack for backward compability. remove in 0.13 (Lgb)
54         contents = frontStrip(strip(contents));
55         if (!contains(contents, "{") && !contains(contents, "}")) {
56                 if (contents.length() == 2) {
57                         string tmp;
58                         tmp += contents[0];
59                         tmp += contents[1];
60                         tmp += "{}";
61                         contents = tmp;
62                 } else if (contents.length() == 3) {
63                         string tmp;
64                         tmp += contents[0];
65                         tmp += contents[1];
66                         tmp += '{';
67                         tmp += contents[2];
68                         tmp += '}';
69                         contents = tmp;
70                 } else if (contents.length() == 4 && contents[2] == ' ') {
71                         string tmp;
72                         tmp += contents[0];
73                         tmp += contents[1];
74                         tmp += '{';
75                         tmp += contents[3];
76                         tmp += '}';
77                         contents = tmp;
78                 } else if  (contents.length() == 4 && contents[2] == '\\'
79                             && (contents[3] == 'i' || contents[3] == 'j')) {
80                         string tmp;
81                         tmp += contents[0];
82                         tmp += contents[1];
83                         tmp += '{';
84                         tmp += contents[2];
85                         tmp += contents[3];
86                         tmp += '}';
87                         contents = tmp;
88                 }
89         }
90         if (contents[0] != '\\') return; // demand that first char is a '\\'
91
92         lyxerr[Debug::KEY] << "Decode: " << contents << endl;
93
94         remdot = false; plusasc = false; plusdesc = false;
95
96         switch (contents[1]) { // second char should be one of these
97         case '\'':  // acute
98                 modtype = ACUTE;    // acute
99                 plusasc = true;    // at the top of character
100                 break;
101         case '`':   // grave
102                 modtype = GRAVE;    // grave
103                 plusasc = true;    // at the top
104                 break;
105         case '=':   // macron
106                 modtype = MACRON;    // macron
107                 plusasc = true;    // at the top
108                 break;
109         case '~':   // tilde
110                 modtype = TILDE;    // tilde
111                 plusasc = true;    // at the top
112                 break;
113         case 'b':   // underbar
114                 modtype = UNDERBAR;    // underbar
115                 plusdesc = true;   // at the bottom
116                 break;
117         case 'c':   // cedilla
118                 modtype = CEDILLA;    // cedilla
119                 plusdesc = true;   // at the bottom
120                 break;
121         case 'd':   // underdot
122                 modtype = UNDERDOT;    // underdot
123                 plusdesc = true;   // at the bottom
124                 break;
125         case 'r':   // circle
126                 modtype = CIRCLE;    // circle
127                 plusasc = true;    // at the top
128                 break;
129         case 't':   // tie
130                 modtype = TIE;    // tie
131                 plusasc = true;    // at the top
132                 break;
133         case 'u':   // breve
134                 modtype = BREVE;    // breve
135                 plusasc = true;    // at the top
136                 break;
137         case 'v':   // caron
138                 modtype = CARON;   // caron
139                 plusasc = true;    // at the top
140                 break;
141         case 'q':   // special caron
142                 modtype = SPECIAL_CARON;   // special caron
143                 plusasc = true;    // at the top
144                 break;
145         case 'H':   // hungarian umlaut
146                 modtype = HUNGARIAN_UMLAUT;   // hungarian umlaut
147                 plusasc = true;    // at the top
148                 break;
149         case '"':   // umlaut
150                 modtype = UMLAUT;   // umlaut
151                 plusasc = true;    // at the top
152                 break;
153         case '.':   // dot
154                 modtype = DOT;   // dot
155                 plusasc = true;    // at the top
156                 break;
157         case '^':   // circumflex
158                 modtype = CIRCUMFLEX;   // circumflex
159                 plusasc = true;    // at the top
160                 break;
161         case 'k':   // ogonek
162                 modtype = OGONEK;  // ogonek
163                 plusdesc = true;
164                 break;
165         case 'i': // dot-less-i
166                 modtype = DOT_LESS_I;  // dot-less-i
167                 plusasc = true; // at the top (not really needed)
168                 remdot = true;
169                 break;
170         case 'j': // dot-less-j
171                 modtype = DOT_LESS_J; // dot-less-j
172                 plusasc = true; // at the top (not really needed)
173                 remdot = true;
174                 break;
175         case 'l': // lslash
176                 modtype = lSLASH;
177                 plusasc = true; // at the top (not really needed)
178                 break;
179         case 'L': // lslash
180                 modtype = LSLASH;
181                 plusasc = true; // at the top (not really needed)
182                 break;
183         default:
184                 printf ("Default\n");
185                 // unknow accent (or something else)
186                 return;
187         }
188
189         // we demand that third char is a '{' (Lgb)
190         if (contents[2] != '{') return;
191
192         // special clause for \i{}, \j{} \l{} and \L{}
193         if ((modtype == DOT_LESS_I || modtype == DOT_LESS_J
194              || modtype == lSLASH || modtype == LSLASH)
195             && contents[3] == '}' ) {
196                 switch (modtype) {
197                 case DOT_LESS_I: ic = 'i'; break;
198                 case DOT_LESS_J: ic = 'j'; break;
199                 case lSLASH:     ic = 'l'; break;
200                 case LSLASH:     ic = 'L'; break;
201                 default:
202                         // if this happens something is really wrong
203                         lyxerr << "InsetLaTexAccent: weird error." << endl;
204                         break;
205                 }
206                 //ic = (modtype == DOT_LESS_J ? 'j' : 'i');
207                 lyxerr[Debug::KEY] << "Contents: [" << contents << "]"
208                                    << ", ic: " << ic 
209                                    << ", top: " << plusasc 
210                                    << ", bot: " << plusdesc 
211                                    << ", dot: " << remdot 
212                                    << ", mod: " << modtype << endl;
213                 // Special case for space
214         } else if (contents[3] == '}') {
215                 ic = ' ';
216         } else {
217                 int i = 3;
218                 
219                 // now get the char
220                 ic = contents[3]; // i will always be 3 here
221
222                 // ic should now be a alfa-char or '\\'
223                 if (ic == '\\') {
224                         ic = contents[++i]; // will only allow \<foo>{\i} and \<foo>{\j}
225                         if (ic == 'i' || ic == 'j')
226                                 remdot = true;
227                         else
228                                 return;
229                 } else if ( (ic == 'i'|| ic == 'j') && contents[4] == '}') {
230                         // Do a rewrite: \<foo>{i} --> \<foo>{\i}
231                         string temp = contents;
232                         temp.erase(3, string::npos);
233                         temp += '\\';
234                         temp += char(ic);
235                         for(string::size_type j = 4;
236                             j < contents.length(); ++j)
237                                 temp+= contents[j];
238                         contents= temp;
239                         ++i;
240                         remdot = true;
241                 }    
242
243                 // demand a '}' at the end
244                 if (contents[++i] != '}' && contents[++i]) return;
245                                            
246                 // fine, the char is properly decoded now (hopefully)
247                 lyxerr[Debug::KEY] << "Contents: [" << contents << "]"
248                                    << ", ic: " << ic
249                                    << ", top: " << plusasc 
250                                    << ", bot: " << plusdesc 
251                                    << ", dot: " << remdot
252                                    << ", mod: " << modtype << endl;
253         }
254         candisp = true;
255 }
256
257
258 #ifdef USE_PAINTER
259 int InsetLatexAccent::ascent(Painter &, LyXFont const & font) const
260 {
261         // This function is a bit too simplistix and is just a
262         // "try to make a fit for all accents" approach, to
263         // make it better we need to know what kind of accent is
264         // used and add to max based on that.
265         int max;
266         if (candisp) {
267                 if (ic == ' ')
268                         max = font.ascent('a');
269                 else
270                         max = font.ascent(ic);
271                 if (plusasc) 
272                         max += (font.maxAscent() + 3) / 3;
273         } else
274                 max = font.maxAscent() + 4;
275         return max;
276 }
277 #else
278 int InsetLatexAccent::Ascent(LyXFont const & font) const
279 {
280         // This function is a bit too simplistix and is just a
281         // "try to make a fit for all accents" approach, to
282         // make it better we need to know what kind of accent is
283         // used and add to max based on that.
284         int max;
285         if (candisp) {
286                 if (ic == ' ')
287                         max = font.ascent('a');
288                 else
289                         max = font.ascent(ic);
290                 if (plusasc) 
291                         max += (font.maxAscent() + 3) / 3;
292         } else
293                 max = font.maxAscent() + 4;
294         return max;
295 }
296 #endif
297
298
299 #ifdef USE_PAINTER
300 int InsetLatexAccent::descent(Painter &, LyXFont const & font) const
301 {
302         int max;
303         if (candisp) {
304                 if (ic == ' ') 
305                         max = font.descent('a');
306                 else
307                         max = font.descent(ic);
308                 if (plusdesc)
309                         max += 3;
310         } else
311                 max = font.maxDescent() + 4;
312         return max;
313 }
314 #else
315 int InsetLatexAccent::Descent(LyXFont const & font) const
316 {
317         int max;
318         if (candisp) {
319                 if (ic == ' ') 
320                         max = font.descent('a');
321                 else
322                         max = font.descent(ic);
323                 if (plusdesc)
324                         max += 3;
325         } else
326                 max = font.maxDescent() + 4;
327         return max;
328 }
329 #endif
330
331
332 #ifdef USE_PAINTER
333 int InsetLatexAccent::width(Painter &, LyXFont const & font) const
334 {
335         if (candisp)
336                 return font.textWidth(&ic, 1);
337         else
338                 return font.stringWidth(contents) + 4;
339 }
340 #else
341 int InsetLatexAccent::Width(LyXFont const & font) const
342 {
343         if (candisp)
344                 return font.textWidth(&ic, 1);
345         else
346                 return font.stringWidth(contents) + 4;
347 }
348 #endif
349
350
351 int InsetLatexAccent::Lbearing(LyXFont const & font) const
352 {
353         return font.lbearing(ic);
354 }
355
356
357 int InsetLatexAccent::Rbearing(LyXFont const & font) const
358 {
359         return font.rbearing(ic);
360 }
361
362
363 #ifdef USE_PAINTER
364 bool InsetLatexAccent::DisplayISO8859_9(Painter & pain, LyXFont const & font,
365                                         int baseline, 
366                                         float & x) const
367 {
368         unsigned char tmpic = ic;
369         
370         switch (modtype) {
371         case CEDILLA:
372         {
373                 if (ic == 'c') tmpic = 0xe7;
374                 if (ic == 'C') tmpic = 0xc7;
375                 if (ic == 's') tmpic = 0xfe;
376                 if (ic == 'S') tmpic = 0xde;
377                 break;
378         }
379         case BREVE:
380         {       if (ic == 'g') tmpic = 0xf0;
381         if (ic == 'G') tmpic = 0xd0;
382         break;
383         }
384         case UMLAUT:
385         {
386                 if (ic == 'o') tmpic = 0xf6;
387                 if (ic == 'O') tmpic = 0xd6;
388                 if (ic == 'u') tmpic = 0xfc;
389                 if (ic == 'U') tmpic = 0xdc;
390                 break;
391         }
392         case DOT:        if (ic == 'I') tmpic = 0xdd; break;
393         case DOT_LESS_I: tmpic = 0xfd; break;
394         default:         return false;
395         }
396         if (tmpic != ic) {
397                 char ch = char(tmpic);
398                 pain.text(x, baseline, ch, font);
399                 x += width(pain, font);
400                 return true;
401         }
402         else
403                 return false;
404 }
405 #else
406 bool InsetLatexAccent::DisplayISO8859_9(LyXFont font,
407                                         LyXScreen & scr,
408                                         int baseline, 
409                                         float & x)
410 {
411         unsigned char tmpic = ic;
412         
413         switch (modtype) {
414         case CEDILLA:
415         {
416                 if (ic == 'c') tmpic = 0xe7;
417                 if (ic == 'C') tmpic = 0xc7;
418                 if (ic == 's') tmpic = 0xfe;
419                 if (ic == 'S') tmpic = 0xde;
420                 break;
421         }
422         case BREVE:
423         {       if (ic == 'g') tmpic = 0xf0;
424         if (ic == 'G') tmpic = 0xd0;
425         break;
426         }
427         case UMLAUT:
428         {
429                 if (ic == 'o') tmpic = 0xf6;
430                 if (ic == 'O') tmpic = 0xd6;
431                 if (ic == 'u') tmpic = 0xfc;
432                 if (ic == 'U') tmpic = 0xdc;
433                 break;
434         }
435         case DOT:        if (ic == 'I') tmpic = 0xdd; break;
436         case DOT_LESS_I: tmpic = 0xfd; break;
437         default:         return false;
438         }
439         if (tmpic != ic) {
440                 char ch = char(tmpic);
441                 scr.drawText(font, &ch, 1, baseline, int(x));
442                 x += Width (font);
443                 return true;
444         }
445         else
446                 return false;
447 }
448 #endif
449
450
451 #ifdef USE_PAINTER
452 void InsetLatexAccent::draw(Painter & pain, LyXFont const & font,
453                             int baseline, float & x) const
454 {
455         if (lyxrc->font_norm == "iso8859-9")
456                 if (DisplayISO8859_9(pain, font, baseline, x))  
457                         return;
458         
459         /* draw it! */ 
460         // All the manually drawn accents in this function could use an
461         // overhaul. Different ways of drawing (what metrics to use)
462         // should also be considered.
463         
464         if (candisp) {
465                 int asc = ascent(pain, font);
466                 int desc = descent(pain, font);
467                 int wid = width(pain, font);
468                 float x2 = x + (Rbearing(font) - Lbearing(font)) / 2.0;
469                 float hg;
470                 int y;
471                 if (plusasc) {
472                         // mark at the top
473                         hg = font.maxDescent();
474                         y = baseline - asc;
475
476                         if (font.shape() == LyXFont::ITALIC_SHAPE)
477                                 x2 += (4.0 * hg) / 5.0; // italic
478                 } else {
479                         // at the bottom
480                         hg = desc;
481                         y = baseline;
482                 }
483
484                 float hg35 = float(hg * 3.0) / 5.0;
485
486                 // display with proper accent mark
487                 // first the letter
488                 pain.text(int(x), baseline, ic, font);
489
490 #if 0
491                 GC pgc = GetAccentGC(font, int((hg + 3.0) / 5.0));
492 #endif
493
494                 if (remdot) {
495                         int tmpvar = baseline - font.ascent('i');
496                         float tmpx = 0;
497                         if (font.shape() == LyXFont::ITALIC_SHAPE)
498                                 tmpx += (8.0 * hg) / 10.0; // italic
499                         lyxerr[Debug::KEY] << "Removing dot." << endl;
500                         // remove the dot first
501                         pain.fillRectangle(int(x + tmpx), tmpvar, wid,
502                                            font.ascent('i') -
503                                            font.ascent('x') - 1,
504                                            LColor::background);
505                         // the five lines below is a simple hack to
506                         // make the display of accent 'i' and 'j'
507                         // better. It makes the accent be written
508                         // closer to the top of the dot-less 'i' or 'j'.
509                         char tmpic = ic; // store the ic when we
510                         ic = 'x';        // calculates the ascent of
511                         asc = ascent(pain, font); // the dot-less version (here: 'x')
512                         ic = tmpic;      // set the orig ic back
513                         y = baseline - asc; // update to new y coord.
514                 }
515                 // now the rest - draw within (x, y, x+wid, y+hg)
516                 switch (modtype) {
517                 case ACUTE:     // acute
518                 {
519                         pain.line(int(x2), int(y + hg),
520                                   int(x2 + hg35), y + hg35);
521                         break;
522                 }
523                 case GRAVE:     // grave
524                 {
525                         pain.line(int(x2), int(y + hg),
526                                   int(x2 - hg35), y + hg35);
527                         break;
528                 }
529                 case MACRON:     // macron
530                 {
531                         pain.line(int(x2 - wid * 0.4),
532                                   int(y + hg),
533                                   int(x2 + wid * 0.4),
534                                   int(y + hg));
535                         break;
536                 }
537                 case TILDE:     // tilde
538                 {
539 #if 0
540                         if (hg35 > 2.0) hg35 -= 1.0;
541                         x2 += (hg35 / 2.0);
542                         int xp[4], yp[4];
543                         
544                         xp[0] = int(x2 - 2.0 * hg35);
545                         yp[0] = int(y + hg);
546                         
547                         xp[1] = int(x2 - hg35);
548                         yp[1] = int(y + hg35);
549                         
550                         xp[2] = int(x2);
551                         yp[2] = int(y + hg);
552                         
553                         xp[3] = int(x2 + hg35);
554                         yp[3] = int(y + hg35);
555                         
556                         pain.lines(xp, yp, 4);
557 #else
558                         pain.text(x2 - font.width('~') / 2,
559                                   baseline - font.ascent('~'),
560                                   "~", 1, font);
561 #endif
562                         break;
563                 }
564                 case UNDERBAR:     // underbar
565                 {
566                         pain.line(int(x2 - wid * 0.4),
567                                   y + hg / 2.0,
568                                   int(x2 + wid * 0.4),
569                                   y + hg / 2.0);
570                         break;
571                 }
572                 case CEDILLA:     // cedilla
573                 {
574                         int xp[4], yp[4];
575                         
576                         xp[0] = int(x2);
577                         yp[0] = y;
578                         
579                         xp[1] = int(x2);
580                         yp[1] = y + int(hg / 3.0);
581                         
582                         xp[2] = int(x2 + (hg / 3.0));
583                         yp[2] = y + int(hg / 2.0);
584                         
585                         xp[3] = int(x2 - (hg / 4.0));
586                         yp[3] = y + int(hg);
587
588                         pain.lines(xp, yp, 4);
589                         break;
590                 }
591                 case UNDERDOT:     // underdot
592                 {
593                         pain.arc(int(x2), y + hg35,
594                                      3, 3, 0, 360 * 64);
595                         break;
596                 }
597
598                 case DOT:    // dot
599                 {
600                         pain.arc(int(x2), y + hg * 0.5,
601                                      (hg + 3.0)/5.0,
602                                      (hg + 3.0)/5.0,
603                                      0, 360 * 64);
604                         break;
605                 }
606
607                 case CIRCLE:     // circle
608                 {
609                         pain.arc(int(x2 - (hg / 2.0)),
610                                  y + (hg / 2.0), hg, hg , 0,
611                                  360 * 64);
612                         break;
613                 }
614                 case TIE:     // tie
615                 {
616                         pain.arc(int(x2 + hg35), y + hg / 2.0,
617                                  2 * hg, hg, 0, 360 * 32);
618                         break;
619                 }
620                 case BREVE:     // breve
621                 {
622                         pain.arc(int(x2 - (hg / 2.0)), y,
623                                  hg, hg, 0, -360*32);
624                         break;
625                 }
626                 case CARON:    // caron
627                 {
628                         int xp[3], yp[3];
629                         
630                         xp[0] = int(x2 - hg35); yp[0] = int(y + hg35);
631                         xp[1] = int(x2);        yp[1] = int(y + hg);
632                         xp[2] = int(x2 + hg35); yp[2] = int(y + hg35);
633                         pain.lines(xp, yp, 3);
634                         break;
635                 }
636                 case SPECIAL_CARON:    // special caron
637                 {
638                         switch (ic) {
639                         case 'L': wid = int(4.0 * wid / 5.0); break;
640                         case 't': y -= int(hg35 / 2.0); break;
641                         }
642                         int xp[3], yp[3];
643                         xp[0] = int(x + wid);
644                         yp[0] = int(y + hg35 + hg);
645                         
646                         xp[1] = int(x + wid + (hg35 / 2.0));
647                         yp[1] = int(y + hg + (hg35 / 2.0));
648                         
649                         xp[2] = int(x + wid + (hg35 / 2.0));
650                         yp[2] = y + int(hg);
651
652                         pain.lines(xp, yp, 3);
653                         break;
654                 }
655                 case HUNGARIAN_UMLAUT:    // hung. umlaut
656                 {
657                         int xs1[2], xs2[2], ys1[2], ys2[2];
658                         
659                         xs1[0] = int(x2 - (hg / 2.0));
660                         ys1[0] = int(y + hg);
661                         
662                         xs2[0] = int(x2 + hg35 - (hg / 2.0));
663                         ys2[0] = int(y + hg35);
664                         
665                         xs1[1] = int(x2 + (hg / 2.0));
666                         ys1[1] = int(y + hg);
667                         
668                         xs2[1] = int(x2 + hg35 + (hg / 2.0));
669                         ys2[1] = int(y + hg35);
670
671                         pain.segments(xs1, ys1, xs2, ys2, 2);
672                         break;
673                 }
674                 case UMLAUT:    // umlaut
675                 {
676 #if 0
677                         float rad = hg / 2.0;
678                         if (rad <= 1.0) {
679                                 pain.point(int(x2 - 4.0 * hg / 7.0),
680                                            y + hg35);
681                                 pain.point(int(x2 + 4.0 * hg / 7.0),
682                                            y + hg35);
683                         } else {
684                                 rad += .5; // this ensures that f.ex. 1.5 will
685                                 // not be rounded down to .5 and then
686                                 // converted to int = 0
687                                 pain.arc(int(x2 - 2.0 * hg / 4.0),
688                                              y + hg35,
689                                              rad, rad,
690                                              0, 360 * 64);
691                                 pain.arc(int(x2 + 2.0 * hg / 4.0),
692                                             y + hg35,
693                                             rad, rad, 0, 360*64);
694                         }
695 #else
696                         pain.text(x2 - font.width('¨') / 2, baseline,
697                                   "¨", 1, font);
698 #endif
699                         break;
700                 }
701                 case CIRCUMFLEX:    // circumflex
702                 {
703                         int xp[3], yp[3];
704                         
705                         xp[0] = int(x2 - hg35); yp[0] = y + int(hg);
706                         xp[1] = int(x2);        yp[1] = int(y + hg35);
707                         xp[2] = int(x2 + hg35); yp[2] = y + int(hg);
708                         pain.lines(xp, yp, 3);
709                         break;
710                 }
711                 case OGONEK:    // ogonek
712                 {
713                         // this does probably not look like an ogonek, so
714                         // it should certainly be refined
715                         int xp[4], yp[4];
716                         
717                         xp[0] = int(x2);
718                         yp[0] = y;
719                         
720                         xp[1] = int(x2);
721                         yp[1] = y + int(hg35);
722                         
723                         xp[2] = int(x2 - hg35);
724                         yp[2] = y + int(hg / 2.0);
725                         
726                         xp[3] = int(x2 + hg / 4.0);
727                         yp[3] = y + int(hg);
728
729                         pain.lines(xp, yp, 4);
730                         break;
731                 }
732                 case lSLASH:
733                 case LSLASH:
734                 {
735                         int xp[2], yp[2];
736                         
737                         xp[0] = int(x);
738                         yp[0] = y + int(3.0 * hg);
739                         
740                         xp[1] = int(x + float(wid) * 0.75);
741                         yp[1] = y + int(hg);
742                         
743                         pain.lines(xp, yp, 2);
744                         break;
745                 }
746                 case DOT_LESS_I: // dotless-i
747                 case DOT_LESS_J: // dotless-j
748                 {
749                         // nothing to do for these
750                         break;
751                 }
752                 }
753         } else {
754                 pain.fillRectangle(int(x + 1),
755                                    baseline - ascent(pain, font) + 1,
756                                    width(pain, font) - 2,
757                                    ascent(pain, font)
758                                    + descent(pain, font) - 2);
759                 pain.rectangle(int(x + 1), baseline - ascent(pain, font) + 1,
760                                width(pain, font) - 2,
761                                ascent(pain, font) + descent(pain, font) - 2);
762                 pain.text(int(x + 2), baseline, contents, font);
763         }
764         x +=  width(pain, font);
765 }
766 #else
767 void InsetLatexAccent::Draw(LyXFont font,
768                             LyXScreen & scr,
769                             int baseline, 
770                             float & x)
771 {
772         if (lyxrc->font_norm == "iso8859-9")
773                 if (DisplayISO8859_9 (font, scr, baseline, x))  
774                         return;
775         
776         /* draw it! */ 
777         // All the manually drawn accents in this function could use an
778         // overhaul. Different ways of drawing (what metrics to use)
779         // should also be considered.
780         
781         if (candisp) {
782                 int asc = Ascent(font);
783                 int desc = Descent(font);
784                 int wid = Width(font);
785                 float x2 = x + (Rbearing(font) - Lbearing(font)) / 2.0;
786                 float hg;
787                 int y;
788                 if (plusasc) {
789                         // mark at the top
790                         hg = font.maxDescent();
791                         y = baseline - asc;
792
793                         if (font.shape() == LyXFont::ITALIC_SHAPE)
794                                 x2 += (4.0 * hg) / 5.0; // italic
795                 } else {
796                         // at the bottom
797                         hg = desc;
798                         y = baseline;
799                 }
800
801                 float hg35 = float(hg * 3.0) / 5.0;
802
803                 // display with proper accent mark
804                 // first the letter
805                 scr.drawText(font, &ic, 1, baseline, int(x));
806
807                 GC pgc = GetAccentGC(font, int((hg + 3.0) / 5.0));
808
809                 if (remdot) {
810                         int tmpvar = baseline - font.ascent('i');
811                         float tmpx = 0;
812                         if (font.shape() == LyXFont::ITALIC_SHAPE)
813                                 tmpx += (8.0 * hg) / 10.0; // italic
814                         lyxerr[Debug::KEY] << "Removing dot." << endl;
815                         // remove the dot first
816                         scr.fillRectangle(gc_clear, int(x + tmpx),
817                                           tmpvar, wid,
818                                           font.ascent('i') -
819                                           font.ascent('x') - 1);
820                         // the five lines below is a simple hack to
821                         // make the display of accent 'i' and 'j'
822                         // better. It makes the accent be written
823                         // closer to the top of the dot-less 'i' or 'j'.
824                         char tmpic = ic; // store the ic when we
825                         ic = 'x';        // calculates the ascent of
826                         asc = Ascent(font); // the dot-less version (here: 'x')
827                         ic = tmpic;      // set the orig ic back
828                         y = baseline - asc; // update to new y coord.
829                 }
830                 // now the rest - draw within (x, y, x+wid, y+hg)
831                 switch (modtype) {
832                 case ACUTE:     // acute
833                 {
834                         scr.drawLine(pgc, int(x2), int(y + hg),
835                                      int(x2 + hg35), y + hg35);
836                         break;
837                 }
838                 case GRAVE:     // grave
839                 {
840                         scr.drawLine(pgc, int(x2), int(y + hg),
841                                      int(x2 - hg35), y + hg35); 
842                         break;
843                 }
844                 case MACRON:     // macron
845                 {
846                         scr.drawLine(pgc,
847                                      int(x2 - wid * 0.4),
848                                      int(y + hg),
849                                      int(x2 + wid * 0.4),
850                                      int(y + hg));
851                         break;
852                 }
853                 case TILDE:     // tilde
854                 {
855                         if (hg35 > 2.0) hg35 -= 1.0;
856                         x2 += (hg35 / 2.0);
857                         XPoint p[4];
858                         p[0].x = int(x2 - 2.0 * hg35); p[0].y = int(y + hg);
859                         p[1].x = int(x2 - hg35);   p[1].y = int(y + hg35);
860                         p[2].x = int(x2);          p[2].y = int(y + hg);
861                         p[3].x = int(x2 + hg35);   p[3].y = int(y + hg35);
862                         scr.drawLines(pgc, p, 4);
863                         break;
864                 }
865                 case UNDERBAR:     // underbar
866                 {
867                         scr.drawLine(pgc,
868                                      int(x2 - wid * 0.4),
869                                      y + (hg / 2.0),
870                                      int(x2 + wid * 0.4),
871                                      y + (hg / 2.0));
872                         break;
873                 }
874                 case CEDILLA:     // cedilla
875                 {
876                         XPoint p[4];
877                         p[0].x = int(x2);          p[0].y = y;
878                         p[1].x = int(x2);          p[1].y = y + int(hg / 3.0);
879                         p[2].x = int(x2 + (hg / 3.0));
880                         p[2].y = y + int(hg / 2.0);
881                         p[3].x = int(x2 - (hg / 4.0)); p[3].y = y + int(hg);
882                         scr.drawLines(pgc, p, 4);
883                         break;
884                 }
885                 case UNDERDOT:     // underdot
886                 {
887                         scr.fillArc(pgc, int(x2), y + hg35,
888                                     3, 3, 0, 360*64);
889                         break;
890                 }
891
892                 case DOT:    // dot
893                 {
894                         scr.fillArc(pgc, int(x2), y + hg * 0.5,
895                                     (hg + 3.0)/5.0,
896                                     (hg + 3.0)/5.0, 0, 360*64);
897                         break;
898                 }
899
900                 case CIRCLE:     // circle
901                 {
902                         scr.drawArc(pgc, int(x2 - (hg / 2.0)),
903                                     y + (hg / 2.0), hg, hg, 0,
904                                     360*64);
905                         break;
906                 }
907                 case TIE:     // tie
908                 {
909                         scr.drawArc(pgc,
910                                     int(x2 + hg35), y + (hg / 2.0),
911                                     2 * hg, hg, 0, 360*32);
912                         break;
913                 }
914                 case BREVE:     // breve
915                 {
916                         scr.drawArc(pgc,
917                                     int(x2 - (hg / 2.0)), y,
918                                     hg, hg, 0, -360*32);
919                         break;
920                 }
921                 case CARON:    // caron
922                 {
923                         XPoint p[3];
924                         p[0].x = int(x2 - hg35); p[0].y = int(y + hg35);
925                         p[1].x = int(x2);        p[1].y = int(y + hg);
926                         p[2].x = int(x2 + hg35); p[2].y = int(y + hg35);
927                         scr.drawLines(pgc, p, 3);
928                         break;
929                 }
930                 case SPECIAL_CARON:    // special caron
931                 {
932                         switch (ic) {
933                         case 'L': wid = int(4.0 * wid / 5.0); break;
934                         case 't': y -= int(hg35 / 2.0); break;
935                         }
936                         XPoint p[3];
937                         p[0].x = int(x + wid);   p[0].y = int(y + hg35 + hg);
938                         p[1].x = int(x + wid + (hg35 / 2.0));
939                         p[1].y = int(y + hg + (hg35 / 2.0));
940                         p[2].x = int(x + wid + (hg35 / 2.0));
941                         p[2].y = y + int(hg);
942                         scr.drawLines(pgc, p, 3);
943                         break;
944                 }
945                 case HUNGARIAN_UMLAUT:    // hung. umlaut
946                 {
947                         XSegment s[2];
948                         s[0].x1= int(x2 - (hg / 2.0));     s[0].y1 = int(y + hg);
949                         s[0].x2 = int(x2 + hg35 - (hg / 2.0));
950                         s[0].y2 = int(y + hg35);
951                         s[1].x1 = int(x2 + (hg / 2.0));
952                         s[1].y1 = int(y + hg);
953                         s[1].x2 = int(x2 + hg35 + (hg / 2.0));
954                         s[1].y2 = int(y + hg35);
955
956                         scr.drawSegments(pgc, s, 2);
957                         break;
958                 }
959                 case UMLAUT:    // umlaut
960                 {
961                         float rad = hg / 2.0;
962                         if (rad <= 1.0) {
963                                 scr.drawPoint(pgc,
964                                               int(x2 - ((4.0 * hg) / 7.0)),
965                                               y + hg35);
966                                 scr.drawPoint(pgc,
967                                               int(x2 + ((4.0 * hg) / 7.0)),
968                                               y + hg35);
969                         } else {
970                                 rad += .5; // this ensures that f.ex. 1.5 will
971                                 // not be rounded down to .5 and then
972                                 // converted to int = 0
973                                 scr.fillArc(pgc, int(x2 - ((2.0 * hg) / 4.0)),
974                                             y + hg35,
975                                             rad, rad, 0, 360*64);
976                                 scr.fillArc(pgc, int(x2 + ((2.0 * hg) / 4.0)),
977                                             y + hg35,
978                                             rad, rad, 0, 360*64);
979                         }
980                         //scr.drawText(font, "¨", 1, baseline, x2);
981                         break;
982                 }
983                 case CIRCUMFLEX:    // circumflex
984                 {
985                         XPoint p[3];
986                         p[0].x = int(x2 - hg35); p[0].y = y + int(hg);
987                         p[1].x = int(x2);        p[1].y = int(y + hg35);
988                         p[2].x = int(x2 + hg35); p[2].y = y + int(hg);
989                         scr.drawLines(pgc, p, 3);
990                         break;
991                 }
992                 case OGONEK:    // ogonek
993                 {
994                         // this does probably not look like an ogonek, so
995                         // it should certainly be refined
996                         XPoint p[4];
997                         p[0].x = int(x2);          p[0].y = y;
998                         p[1].x = int(x2);          p[1].y = y + int(hg35);
999                         p[2].x = int(x2 - hg35);
1000                         p[2].y = y + int(hg / 2.0);
1001                         p[3].x = int(x2 + (hg / 4.0)); p[3].y = y + int(hg);
1002                         scr.drawLines(pgc, p, 4);
1003                         break;
1004                 }
1005                 case lSLASH:
1006                 case LSLASH:
1007                 {
1008                         XPoint p[2];
1009                         p[0].x = int(x);
1010                         p[0].y = y + int(3.0 * hg);
1011                         p[1].x = int(x + float(wid) * 0.75);
1012                         p[1].y = y + int(hg);
1013                         scr.drawLines(pgc, p, 2);
1014                         break;
1015                 }
1016                 case DOT_LESS_I: // dotless-i
1017                 case DOT_LESS_J: // dotless-j
1018                 {
1019                         // nothing to do for these
1020                         break;
1021                 }
1022                 }
1023         } else {
1024                 scr.fillRectangle(gc_lighted,
1025                                   int(x + 1), baseline - Ascent(font) + 1,
1026                                   Width(font) - 2,
1027                                   Ascent(font) + Descent(font) - 2);
1028                 
1029                 scr.drawRectangle(gc_lighted,
1030                                   int(x), baseline - Ascent(font),
1031                                   Width(font) - 1,
1032                                   Ascent(font) + Descent(font) - 1);
1033                 scr.drawString(font, contents, baseline, int(x + 2));
1034         }
1035         x +=  Width(font);
1036 }
1037 #endif
1038
1039
1040 void InsetLatexAccent::Write(ostream & os)
1041 {
1042         os << "\\i " << contents << "\n";
1043 }
1044
1045
1046 void InsetLatexAccent::Read(LyXLex & lex)
1047 {
1048         lex.EatLine();
1049         contents = lex.GetString();
1050         checkContents();
1051 }
1052
1053
1054 int InsetLatexAccent::Latex(ostream & os, signed char /*fragile*/)
1055 {
1056         os << contents;
1057         return 0;
1058 }
1059
1060
1061 int InsetLatexAccent::Latex(string & file, signed char /*fragile*/)
1062 {
1063         file += contents;
1064         return 0;
1065 }
1066
1067
1068 int InsetLatexAccent::Linuxdoc(string & file)
1069 {
1070         file += contents;
1071         return 0;
1072 }
1073
1074
1075 int InsetLatexAccent::DocBook(string & file)
1076 {
1077         file += contents;
1078         return 0;
1079 }
1080
1081
1082 bool InsetLatexAccent::Deletable() const
1083 {
1084         return true;
1085 }
1086
1087
1088 bool InsetLatexAccent::DirectWrite() const
1089 {
1090         return true;
1091 }
1092
1093
1094 Inset * InsetLatexAccent::Clone() const
1095 {
1096         return new InsetLatexAccent(contents);
1097 }
1098
1099
1100 Inset::Code InsetLatexAccent::LyxCode() const
1101 {
1102         return Inset::ACCENT_CODE;
1103 }
1104
1105
1106 ostream & operator<<(ostream & o, InsetLatexAccent::ACCENT_TYPES at)
1107 {
1108         return o << int(at);
1109 }