home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / insetspecialchar.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  3KB  |  163 lines

  1. /* This file is part of
  2.  * ======================================================
  3.  * 
  4.  *           LyX, The Document Processor
  5.  *      
  6.  *        Copyright (C) 1997 Asger Alstrup
  7.  *
  8.  *======================================================*/
  9.  
  10. #include <config.h>
  11.  
  12. #ifdef __GNUG__
  13. #pragma implementation
  14. #endif
  15.  
  16. #include "insetspecialchar.h"
  17. #include "lyxdraw.h"
  18. #include "error.h"
  19.  
  20. //     $Id: insetspecialchar.C,v 1.1.1.1 1998/04/23 16:02:52 larsbj Exp $    
  21.  
  22. #if !defined(lint) && !defined(WITH_WARNINGS)
  23. static char vcid[] = "$Id: insetspecialchar.C,v 1.1.1.1 1998/04/23 16:02:52 larsbj Exp $";
  24. #endif /* lint */
  25.  
  26. InsetSpecialChar::InsetSpecialChar()
  27. {
  28. }
  29.  
  30.  
  31. InsetSpecialChar::InsetSpecialChar(Kind k)
  32.     : kind(k)
  33. {
  34. }
  35.  
  36.  
  37. InsetSpecialChar::~InsetSpecialChar()
  38. {
  39. }
  40.  
  41.  
  42. int InsetSpecialChar::Ascent(LyXFont const&font) const
  43. {
  44.     return font.maxAscent();
  45. }
  46.  
  47.  
  48. int InsetSpecialChar::Descent(LyXFont const&font) const
  49. {
  50.     return font.maxDescent();
  51. }
  52.  
  53.  
  54. int InsetSpecialChar::Width(LyXFont const&font) const
  55. {
  56.     LyXFont f = font;
  57.     switch (kind) {
  58.     case HYPHENATION:
  59.     {
  60.         int w = f.textWidth("-", 1);
  61.         if (w > 5) 
  62.             w -= 2; // to make it look shorter
  63.         return w;
  64.     }
  65.     case END_OF_SENTENCE:
  66.     {
  67.         return f.textWidth(".", 1);
  68.     }
  69.     case LDOTS:
  70.     {
  71.         return f.textWidth(". . .", 5);
  72.     }
  73.     }
  74.     return 1; // To shut up gcc
  75. }
  76.  
  77.  
  78. void InsetSpecialChar::Draw(LyXFont font, LyXScreen &scr,
  79.                 int baseline, float &x)
  80. {
  81.     switch (kind) {
  82.     case HYPHENATION:
  83.     {
  84.         font.setColor(LyXFont::MAGENTA);
  85.         scr.drawText(font, "-", 1, baseline, int(x));
  86.         x += Width(font);
  87.         break;
  88.     }
  89.     case END_OF_SENTENCE:
  90.     {
  91.         font.setColor(LyXFont::MAGENTA);
  92.         scr.drawText(font, ".", 1, baseline, int(x));
  93.         x += Width(font);
  94.         break;
  95.     }
  96.     case LDOTS:
  97.     {
  98.         font.setColor(LyXFont::MAGENTA);
  99.         scr.drawText(font, ". . .", 5, baseline, int(x));
  100.         x += Width(font);
  101.         break;
  102.     }
  103.     }
  104. }
  105.  
  106.  
  107. // In lyxf3 this will be just LaTeX
  108. void InsetSpecialChar::Write(FILE *file)
  109. {
  110.     LString command;
  111.     switch (kind) {
  112.     case HYPHENATION:    command = "\\-";    break;
  113.     case END_OF_SENTENCE:    command = "\\@.";    break;
  114.     case LDOTS:        command = "\\ldots{}";    break;
  115.     }
  116.     fprintf(file, "\\SpecialChar %s\n", command.c_str());
  117. }
  118.  
  119.  
  120. // This function will not be necessary when lyx3
  121. void InsetSpecialChar::Read(LyXLex &lex)
  122. {    
  123.     lex.nextToken();
  124.     LString command = lex.GetString();
  125.  
  126.     if (command=="\\-")
  127.         kind = HYPHENATION;
  128.     else if (command=="\\@.")
  129.         kind = END_OF_SENTENCE;
  130.     else if (command=="\\ldots{}")
  131.         kind = LDOTS;
  132.     else
  133.         lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
  134. }
  135.  
  136.  
  137. int InsetSpecialChar::Latex(FILE *file, signed char /*fragile*/)
  138. {
  139.     LString command;
  140.     signed char dummy = 0;
  141.     Latex(command, dummy);
  142.     fprintf(file, "%s", command.c_str());
  143.     return 0;
  144. }
  145.  
  146.  
  147. int InsetSpecialChar::Latex(LString &file, signed char /*fragile*/)
  148. {
  149.     switch (kind) {
  150.     case HYPHENATION:    file += "\\-";    break;
  151.     case END_OF_SENTENCE:    file += "\\@.";    break;
  152.     case LDOTS:        file += "\\ldots{}";    break;
  153.     }
  154.     return 0;
  155. }
  156.  
  157.  
  158. Inset* InsetSpecialChar::Clone()
  159. {
  160.     InsetSpecialChar *result = new InsetSpecialChar(kind);
  161.     return result;
  162. }
  163.