summaryrefslogtreecommitdiff
path: root/support/lametex/src/Justify.C
blob: 7f71ff15de1ce1a38e66531d5861ed1d0ec618d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Justify.C
 *
 * When the user wants flushright, flushleft, centered, or the normal
 * full justification, this class is used.
 *
 * Copyright 1992 Jonathan Monsarrat. Permission given to freely distribute,
 * edit and use as long as this copyright statement remains intact.
 *
 */

#include "Global.h"
#include "Justify.h"
#include "Document.h"
#include <fstream.h>

Justify::Justify()
{
   justifytype = Normal;
   postscript_set(-justifytype);
}

Justify::Justify(Justify *base)
{
   justifytype = base->justifytype;
}

Param *Justify::copy()
{
   return new Justify(this);
}

/* What kind of justification will the following text in this environment
 * have? Set the justifytype variable as appropriate.
 */
int Justify::set(int subtype, float, char *)
{
   if(justifytype != subtype) {
      justifytype = subtype;      // Set the internal placeholder for reference
        // Print the postscript command for this.
      postscript_set(subtype);
   }
   return TRUE;
}

float Justify::get(int, char *)
{
   return (float)justifytype;
}

void Justify::postscript_set(int subtype)
{
   if(subtype>0 && Stack::get(Environment::PDocument,Document::StartPage, ""))
      Global::files->outfile << endl << "NEWPARA ";
   else
      subtype = -subtype;
   switch(subtype) {
   case Center:
      Global::files->outfile << "/justify " << (int)'c' << " def";
      break;
   case FlushLeft:
      Global::files->outfile << "/justify " << (int)'l' << " def";
      break;
   case FlushRight:
      Global::files->outfile << "/justify " << (int)'r' << " def";
      break;
   case Normal:
      Global::files->outfile << "/justify " << (int)'f' << " def";
      break;
   }
   Global::files->outfile << endl;
}

void Justify::revert(Param *from)
{
   int subtype = (int)from->get(0,"");
   if(subtype != justifytype)
      postscript_set(justifytype);
}