]> git.lyx.org Git - lyx.git/blob - src/insets/insetlatexaccent.C
3e43f3c37ae4e05c21fd793e91a58b610dec4463
[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 0xB4
518                 {
519 #if 0
520                         pain.line(int(x2), int(y + hg),
521                                   int(x2 + hg35), y + hg35);
522 #else
523                         pain.text(x2 - font.width(0xB4) / 2, baseline,
524                                   char(0xB4), font);
525 #endif
526                         break;
527                 }
528                 case GRAVE:     // grave 0x60
529                 {
530 #if 0
531                         pain.line(int(x2), int(y + hg),
532                                   int(x2 - hg35), y + hg35);
533 #else
534                         pain.text(x2 - font.width(0x60) / 2, baseline,
535                                   char(0x60), font);
536 #endif
537                         break;
538                 }
539                 case MACRON:     // macron
540                 {
541 #if 0
542                         pain.line(int(x2 - wid * 0.4),
543                                   int(y + hg),
544                                   int(x2 + wid * 0.4),
545                                   int(y + hg));
546 #else
547                         pain.text(x2 - font.width(0xAF) / 2, baseline,
548                                   char(0xAF), font);
549 #endif
550                         break;
551                 }
552                 case TILDE:     // tilde
553                 {
554 #if 0
555                         if (hg35 > 2.0) hg35 -= 1.0;
556                         x2 += (hg35 / 2.0);
557                         int xp[4], yp[4];
558                         
559                         xp[0] = int(x2 - 2.0 * hg35);
560                         yp[0] = int(y + hg);
561                         
562                         xp[1] = int(x2 - hg35);
563                         yp[1] = int(y + hg35);
564                         
565                         xp[2] = int(x2);
566                         yp[2] = int(y + hg);
567                         
568                         xp[3] = int(x2 + hg35);
569                         yp[3] = int(y + hg35);
570                         
571                         pain.lines(xp, yp, 4);
572 #else
573                         pain.text(x2 - font.width('~') / 2,
574                                   baseline - font.ascent('~'),
575                                   '~', font);
576 #endif
577                         break;
578                 }
579                 case UNDERBAR:     // underbar 0x5F
580                 {
581 #if 0
582                         pain.line(int(x2 - wid * 0.4),
583                                   y + hg / 2.0,
584                                   int(x2 + wid * 0.4),
585                                   y + hg / 2.0);
586 #else
587                         pain.text(x2 - font.width(0x5F) / 2, baseline,
588                                   char(0x5F), font);
589 #endif
590                         break;
591                 }
592                 case CEDILLA:     // cedilla
593                 {
594 #if 0
595                         int xp[4], yp[4];
596                         
597                         xp[0] = int(x2);
598                         yp[0] = y;
599                         
600                         xp[1] = int(x2);
601                         yp[1] = y + int(hg / 3.0);
602                         
603                         xp[2] = int(x2 + (hg / 3.0));
604                         yp[2] = y + int(hg / 2.0);
605                         
606                         xp[3] = int(x2 - (hg / 4.0));
607                         yp[3] = y + int(hg);
608
609                         pain.lines(xp, yp, 4);
610 #else
611                         pain.text(x2 - font.width(0xB8) / 2, baseline,
612                                   char(0xB8), font);
613                         
614 #endif
615                         break;
616                 }
617                 case UNDERDOT:     // underdot
618                 {
619                         pain.arc(int(x2), y + hg35,
620                                      3, 3, 0, 360 * 64);
621                         break;
622                 }
623
624                 case DOT:    // dot
625                 {
626                         pain.arc(int(x2), y + hg * 0.5,
627                                      (hg + 3.0)/5.0,
628                                      (hg + 3.0)/5.0,
629                                      0, 360 * 64);
630                         break;
631                 }
632
633                 case CIRCLE:     // circle
634                 {
635 #if 0
636                         pain.arc(int(x2 - (hg / 2.0)),
637                                  y + (hg / 2.0), hg, hg , 0,
638                                  360 * 64);
639 #else
640                         pain.text(x2 - font.width(0xB0) / 2, baseline,
641                                   char(0xB0), font);
642 #endif
643                         break;
644                 }
645                 case TIE:     // tie
646                 {
647                         pain.arc(int(x2 + hg35), y + hg / 2.0,
648                                  2 * hg, hg, 0, 360 * 32);
649                         break;
650                 }
651                 case BREVE:     // breve
652                 {
653                         pain.arc(int(x2 - (hg / 2.0)), y,
654                                  hg, hg, 0, -360*32);
655                         break;
656                 }
657                 case CARON:    // caron
658                 {
659                         int xp[3], yp[3];
660                         
661                         xp[0] = int(x2 - hg35); yp[0] = int(y + hg35);
662                         xp[1] = int(x2);        yp[1] = int(y + hg);
663                         xp[2] = int(x2 + hg35); yp[2] = int(y + hg35);
664                         pain.lines(xp, yp, 3);
665                         break;
666                 }
667                 case SPECIAL_CARON:    // special caron
668                 {
669                         switch (ic) {
670                         case 'L': wid = int(4.0 * wid / 5.0); break;
671                         case 't': y -= int(hg35 / 2.0); break;
672                         }
673                         int xp[3], yp[3];
674                         xp[0] = int(x + wid);
675                         yp[0] = int(y + hg35 + hg);
676                         
677                         xp[1] = int(x + wid + (hg35 / 2.0));
678                         yp[1] = int(y + hg + (hg35 / 2.0));
679                         
680                         xp[2] = int(x + wid + (hg35 / 2.0));
681                         yp[2] = y + int(hg);
682
683                         pain.lines(xp, yp, 3);
684                         break;
685                 }
686                 case HUNGARIAN_UMLAUT:    // hung. umlaut
687                 {
688                         int xs1[2], xs2[2], ys1[2], ys2[2];
689                         
690                         xs1[0] = int(x2 - (hg / 2.0));
691                         ys1[0] = int(y + hg);
692                         
693                         xs2[0] = int(x2 + hg35 - (hg / 2.0));
694                         ys2[0] = int(y + hg35);
695                         
696                         xs1[1] = int(x2 + (hg / 2.0));
697                         ys1[1] = int(y + hg);
698                         
699                         xs2[1] = int(x2 + hg35 + (hg / 2.0));
700                         ys2[1] = int(y + hg35);
701
702                         pain.segments(xs1, ys1, xs2, ys2, 2);
703                         break;
704                 }
705                 case UMLAUT:    // umlaut
706                 {
707 #if 0
708                         float rad = hg / 2.0;
709                         if (rad <= 1.0) {
710                                 pain.point(int(x2 - 4.0 * hg / 7.0),
711                                            y + hg35);
712                                 pain.point(int(x2 + 4.0 * hg / 7.0),
713                                            y + hg35);
714                         } else {
715                                 rad += .5; // this ensures that f.ex. 1.5 will
716                                 // not be rounded down to .5 and then
717                                 // converted to int = 0
718                                 pain.arc(int(x2 - 2.0 * hg / 4.0),
719                                              y + hg35,
720                                              rad, rad,
721                                              0, 360 * 64);
722                                 pain.arc(int(x2 + 2.0 * hg / 4.0),
723                                             y + hg35,
724                                             rad, rad, 0, 360*64);
725                         }
726 #else
727                         pain.text(x2 - font.width('¨') / 2, baseline,
728                                   '¨', font);
729 #endif
730                         break;
731                 }
732                 case CIRCUMFLEX:    // circumflex
733                 {
734 #if 0
735                         int xp[3], yp[3];
736                         
737                         xp[0] = int(x2 - hg35); yp[0] = y + int(hg);
738                         xp[1] = int(x2);        yp[1] = int(y + hg35);
739                         xp[2] = int(x2 + hg35); yp[2] = y + int(hg);
740                         pain.lines(xp, yp, 3);
741 #else
742                         pain.text(x2 - font.width(0x5E) / 2, baseline,
743                                   char(0x5E), font);
744 #endif
745                         break;
746                 }
747                 case OGONEK:    // ogonek
748                 {
749                         // this does probably not look like an ogonek, so
750                         // it should certainly be refined
751                         int xp[4], yp[4];
752                         
753                         xp[0] = int(x2);
754                         yp[0] = y;
755                         
756                         xp[1] = int(x2);
757                         yp[1] = y + int(hg35);
758                         
759                         xp[2] = int(x2 - hg35);
760                         yp[2] = y + int(hg / 2.0);
761                         
762                         xp[3] = int(x2 + hg / 4.0);
763                         yp[3] = y + int(hg);
764
765                         pain.lines(xp, yp, 4);
766                         break;
767                 }
768                 case lSLASH:
769                 case LSLASH:
770                 {
771                         int xp[2], yp[2];
772                         
773                         xp[0] = int(x);
774                         yp[0] = y + int(3.0 * hg);
775                         
776                         xp[1] = int(x + float(wid) * 0.75);
777                         yp[1] = y + int(hg);
778                         
779                         pain.lines(xp, yp, 2);
780                         break;
781                 }
782                 case DOT_LESS_I: // dotless-i
783                 case DOT_LESS_J: // dotless-j
784                 {
785                         // nothing to do for these
786                         break;
787                 }
788                 }
789         } else {
790                 pain.fillRectangle(int(x + 1),
791                                    baseline - ascent(pain, font) + 1,
792                                    width(pain, font) - 2,
793                                    ascent(pain, font)
794                                    + descent(pain, font) - 2);
795                 pain.rectangle(int(x + 1), baseline - ascent(pain, font) + 1,
796                                width(pain, font) - 2,
797                                ascent(pain, font) + descent(pain, font) - 2);
798                 pain.text(int(x + 2), baseline, contents, font);
799         }
800         x +=  width(pain, font);
801 }
802 #else
803 void InsetLatexAccent::Draw(LyXFont font,
804                             LyXScreen & scr,
805                             int baseline, 
806                             float & x)
807 {
808         if (lyxrc->font_norm == "iso8859-9")
809                 if (DisplayISO8859_9 (font, scr, baseline, x))  
810                         return;
811         
812         /* draw it! */ 
813         // All the manually drawn accents in this function could use an
814         // overhaul. Different ways of drawing (what metrics to use)
815         // should also be considered.
816         
817         if (candisp) {
818                 int asc = Ascent(font);
819                 int desc = Descent(font);
820                 int wid = Width(font);
821                 float x2 = x + (Rbearing(font) - Lbearing(font)) / 2.0;
822                 float hg;
823                 int y;
824                 if (plusasc) {
825                         // mark at the top
826                         hg = font.maxDescent();
827                         y = baseline - asc;
828
829                         if (font.shape() == LyXFont::ITALIC_SHAPE)
830                                 x2 += (4.0 * hg) / 5.0; // italic
831                 } else {
832                         // at the bottom
833                         hg = desc;
834                         y = baseline;
835                 }
836
837                 float hg35 = float(hg * 3.0) / 5.0;
838
839                 // display with proper accent mark
840                 // first the letter
841                 scr.drawText(font, &ic, 1, baseline, int(x));
842
843                 GC pgc = GetAccentGC(font, int((hg + 3.0) / 5.0));
844
845                 if (remdot) {
846                         int tmpvar = baseline - font.ascent('i');
847                         float tmpx = 0;
848                         if (font.shape() == LyXFont::ITALIC_SHAPE)
849                                 tmpx += (8.0 * hg) / 10.0; // italic
850                         lyxerr[Debug::KEY] << "Removing dot." << endl;
851                         // remove the dot first
852                         scr.fillRectangle(gc_clear, int(x + tmpx),
853                                           tmpvar, wid,
854                                           font.ascent('i') -
855                                           font.ascent('x') - 1);
856                         // the five lines below is a simple hack to
857                         // make the display of accent 'i' and 'j'
858                         // better. It makes the accent be written
859                         // closer to the top of the dot-less 'i' or 'j'.
860                         char tmpic = ic; // store the ic when we
861                         ic = 'x';        // calculates the ascent of
862                         asc = Ascent(font); // the dot-less version (here: 'x')
863                         ic = tmpic;      // set the orig ic back
864                         y = baseline - asc; // update to new y coord.
865                 }
866                 // now the rest - draw within (x, y, x+wid, y+hg)
867                 switch (modtype) {
868                 case ACUTE:     // acute
869                 {
870                         scr.drawLine(pgc, int(x2), int(y + hg),
871                                      int(x2 + hg35), y + hg35);
872                         break;
873                 }
874                 case GRAVE:     // grave
875                 {
876                         scr.drawLine(pgc, int(x2), int(y + hg),
877                                      int(x2 - hg35), y + hg35); 
878                         break;
879                 }
880                 case MACRON:     // macron
881                 {
882                         scr.drawLine(pgc,
883                                      int(x2 - wid * 0.4),
884                                      int(y + hg),
885                                      int(x2 + wid * 0.4),
886                                      int(y + hg));
887                         break;
888                 }
889                 case TILDE:     // tilde
890                 {
891                         if (hg35 > 2.0) hg35 -= 1.0;
892                         x2 += (hg35 / 2.0);
893                         XPoint p[4];
894                         p[0].x = int(x2 - 2.0 * hg35); p[0].y = int(y + hg);
895                         p[1].x = int(x2 - hg35);   p[1].y = int(y + hg35);
896                         p[2].x = int(x2);          p[2].y = int(y + hg);
897                         p[3].x = int(x2 + hg35);   p[3].y = int(y + hg35);
898                         scr.drawLines(pgc, p, 4);
899                         break;
900                 }
901                 case UNDERBAR:     // underbar
902                 {
903                         scr.drawLine(pgc,
904                                      int(x2 - wid * 0.4),
905                                      y + (hg / 2.0),
906                                      int(x2 + wid * 0.4),
907                                      y + (hg / 2.0));
908                         break;
909                 }
910                 case CEDILLA:     // cedilla
911                 {
912                         XPoint p[4];
913                         p[0].x = int(x2);          p[0].y = y;
914                         p[1].x = int(x2);          p[1].y = y + int(hg / 3.0);
915                         p[2].x = int(x2 + (hg / 3.0));
916                         p[2].y = y + int(hg / 2.0);
917                         p[3].x = int(x2 - (hg / 4.0)); p[3].y = y + int(hg);
918                         scr.drawLines(pgc, p, 4);
919                         break;
920                 }
921                 case UNDERDOT:     // underdot
922                 {
923                         scr.fillArc(pgc, int(x2), y + hg35,
924                                     3, 3, 0, 360*64);
925                         break;
926                 }
927
928                 case DOT:    // dot
929                 {
930                         scr.fillArc(pgc, int(x2), y + hg * 0.5,
931                                     (hg + 3.0)/5.0,
932                                     (hg + 3.0)/5.0, 0, 360*64);
933                         break;
934                 }
935
936                 case CIRCLE:     // circle
937                 {
938                         scr.drawArc(pgc, int(x2 - (hg / 2.0)),
939                                     y + (hg / 2.0), hg, hg, 0,
940                                     360*64);
941                         break;
942                 }
943                 case TIE:     // tie
944                 {
945                         scr.drawArc(pgc,
946                                     int(x2 + hg35), y + (hg / 2.0),
947                                     2 * hg, hg, 0, 360*32);
948                         break;
949                 }
950                 case BREVE:     // breve
951                 {
952                         scr.drawArc(pgc,
953                                     int(x2 - (hg / 2.0)), y,
954                                     hg, hg, 0, -360*32);
955                         break;
956                 }
957                 case CARON:    // caron
958                 {
959                         XPoint p[3];
960                         p[0].x = int(x2 - hg35); p[0].y = int(y + hg35);
961                         p[1].x = int(x2);        p[1].y = int(y + hg);
962                         p[2].x = int(x2 + hg35); p[2].y = int(y + hg35);
963                         scr.drawLines(pgc, p, 3);
964                         break;
965                 }
966                 case SPECIAL_CARON:    // special caron
967                 {
968                         switch (ic) {
969                         case 'L': wid = int(4.0 * wid / 5.0); break;
970                         case 't': y -= int(hg35 / 2.0); break;
971                         }
972                         XPoint p[3];
973                         p[0].x = int(x + wid);   p[0].y = int(y + hg35 + hg);
974                         p[1].x = int(x + wid + (hg35 / 2.0));
975                         p[1].y = int(y + hg + (hg35 / 2.0));
976                         p[2].x = int(x + wid + (hg35 / 2.0));
977                         p[2].y = y + int(hg);
978                         scr.drawLines(pgc, p, 3);
979                         break;
980                 }
981                 case HUNGARIAN_UMLAUT:    // hung. umlaut
982                 {
983                         XSegment s[2];
984                         s[0].x1= int(x2 - (hg / 2.0));     s[0].y1 = int(y + hg);
985                         s[0].x2 = int(x2 + hg35 - (hg / 2.0));
986                         s[0].y2 = int(y + hg35);
987                         s[1].x1 = int(x2 + (hg / 2.0));
988                         s[1].y1 = int(y + hg);
989                         s[1].x2 = int(x2 + hg35 + (hg / 2.0));
990                         s[1].y2 = int(y + hg35);
991
992                         scr.drawSegments(pgc, s, 2);
993                         break;
994                 }
995                 case UMLAUT:    // umlaut
996                 {
997                         float rad = hg / 2.0;
998                         if (rad <= 1.0) {
999                                 scr.drawPoint(pgc,
1000                                               int(x2 - ((4.0 * hg) / 7.0)),
1001                                               y + hg35);
1002                                 scr.drawPoint(pgc,
1003                                               int(x2 + ((4.0 * hg) / 7.0)),
1004                                               y + hg35);
1005                         } else {
1006                                 rad += .5; // this ensures that f.ex. 1.5 will
1007                                 // not be rounded down to .5 and then
1008                                 // converted to int = 0
1009                                 scr.fillArc(pgc, int(x2 - ((2.0 * hg) / 4.0)),
1010                                             y + hg35,
1011                                             rad, rad, 0, 360*64);
1012                                 scr.fillArc(pgc, int(x2 + ((2.0 * hg) / 4.0)),
1013                                             y + hg35,
1014                                             rad, rad, 0, 360*64);
1015                         }
1016                         //scr.drawText(font, "¨", 1, baseline, x2);
1017                         break;
1018                 }
1019                 case CIRCUMFLEX:    // circumflex
1020                 {
1021                         XPoint p[3];
1022                         p[0].x = int(x2 - hg35); p[0].y = y + int(hg);
1023                         p[1].x = int(x2);        p[1].y = int(y + hg35);
1024                         p[2].x = int(x2 + hg35); p[2].y = y + int(hg);
1025                         scr.drawLines(pgc, p, 3);
1026                         break;
1027                 }
1028                 case OGONEK:    // ogonek
1029                 {
1030                         // this does probably not look like an ogonek, so
1031                         // it should certainly be refined
1032                         XPoint p[4];
1033                         p[0].x = int(x2);          p[0].y = y;
1034                         p[1].x = int(x2);          p[1].y = y + int(hg35);
1035                         p[2].x = int(x2 - hg35);
1036                         p[2].y = y + int(hg / 2.0);
1037                         p[3].x = int(x2 + (hg / 4.0)); p[3].y = y + int(hg);
1038                         scr.drawLines(pgc, p, 4);
1039                         break;
1040                 }
1041                 case lSLASH:
1042                 case LSLASH:
1043                 {
1044                         XPoint p[2];
1045                         p[0].x = int(x);
1046                         p[0].y = y + int(3.0 * hg);
1047                         p[1].x = int(x + float(wid) * 0.75);
1048                         p[1].y = y + int(hg);
1049                         scr.drawLines(pgc, p, 2);
1050                         break;
1051                 }
1052                 case DOT_LESS_I: // dotless-i
1053                 case DOT_LESS_J: // dotless-j
1054                 {
1055                         // nothing to do for these
1056                         break;
1057                 }
1058                 }
1059         } else {
1060                 scr.fillRectangle(gc_lighted,
1061                                   int(x + 1), baseline - Ascent(font) + 1,
1062                                   Width(font) - 2,
1063                                   Ascent(font) + Descent(font) - 2);
1064                 
1065                 scr.drawRectangle(gc_lighted,
1066                                   int(x), baseline - Ascent(font),
1067                                   Width(font) - 1,
1068                                   Ascent(font) + Descent(font) - 1);
1069                 scr.drawString(font, contents, baseline, int(x + 2));
1070         }
1071         x +=  Width(font);
1072 }
1073 #endif
1074
1075
1076 void InsetLatexAccent::Write(ostream & os)
1077 {
1078         os << "\\i " << contents << "\n";
1079 }
1080
1081
1082 void InsetLatexAccent::Read(LyXLex & lex)
1083 {
1084         lex.EatLine();
1085         contents = lex.GetString();
1086         checkContents();
1087 }
1088
1089
1090 int InsetLatexAccent::Latex(ostream & os, signed char /*fragile*/)
1091 {
1092         os << contents;
1093         return 0;
1094 }
1095
1096
1097 int InsetLatexAccent::Latex(string & file, signed char /*fragile*/)
1098 {
1099         file += contents;
1100         return 0;
1101 }
1102
1103
1104 int InsetLatexAccent::Linuxdoc(string & file)
1105 {
1106         file += contents;
1107         return 0;
1108 }
1109
1110
1111 int InsetLatexAccent::DocBook(string & file)
1112 {
1113         file += contents;
1114         return 0;
1115 }
1116
1117
1118 bool InsetLatexAccent::Deletable() const
1119 {
1120         return true;
1121 }
1122
1123
1124 bool InsetLatexAccent::DirectWrite() const
1125 {
1126         return true;
1127 }
1128
1129
1130 Inset * InsetLatexAccent::Clone() const
1131 {
1132         return new InsetLatexAccent(contents);
1133 }
1134
1135
1136 Inset::Code InsetLatexAccent::LyxCode() const
1137 {
1138         return Inset::ACCENT_CODE;
1139 }
1140
1141
1142 ostream & operator<<(ostream & o, InsetLatexAccent::ACCENT_TYPES at)
1143 {
1144         return o << int(at);
1145 }