aboutsummaryrefslogtreecommitdiffstats
path: root/include/lengths
blob: 2c1d447de527cd98ce85520117269e1e8b8821ac (plain) (blame)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

###########################################################################
#                                                                         #
#   lengths                                                               #
#                                                                         #
#   Jeffrey H. Kingston                                                   #
#   30 October 2002                                                       #
#                                                                         #
#   This file offers two symbols for converting between PostScript        #
#   lengths and Lout lengths.  This has been a messy area and the two     #
#   symbols in this file, @LoutLengths and @PSLengths, are my attempt     #
#   to put a final end to the mess.                                       #
#                                                                         #
#   A Lout length is, and has always been, a number followed by           #
#   a one-letter unit of measurement: i c p m s v f d.                    #
#                                                                         #
#   A PostScript length is, and has always been, a number followed        #
#   by a space followed by a two-letter unit of measurement, one of       #
#   in cm pt em sp vs ft dg.                                              #
#                                                                         #
#   To the ordinary user who reads the User's Guide, all lengths          #
#   now look like Lout lengths.  However, internally some of these        #
#   lengths are used by Lout and others are passed to PostScript.         #
#   Based on the two symbols @PSLengths and @LoutLengths defined          #
#   below, an option x which could contain a length of either kind        #
#   can be classified as one of three types:                              #
#                                                                         #
#   Type of option                  How to handle it                      #
#   -------------------------------------------------------------------   #
#   Option was never advertised     named x { ... }                       #
#   as taking a PostScript length                                         #
#                                                                         #
#   Option was advertised as        import @LoutLengths named x { ... }   #
#   possibly taking a PostScript                                          #
#   length, but its value is used                                         #
#   by Lout                                                               #
#                                                                         #
#   Option whose value has to be    import @PSLengths named x { ... }     #
#   passed to PostScript                                                  #
#   -------------------------------------------------------------------   #
#                                                                         #
#   Either kind of import allows either kind of length to be given;       #
#   @LoutLengths makes sure the final result is suitable for passing      #
#   to Lout, while @PSLengths makes sure the final result is suitable     #
#   for passing to PostScript.  If things had been done right from the    #
#   start, there would be no need for @LoutLengths, but for backward      #
#   compatibility we will continue to use it basically forever.           #
#                                                                         #
###########################################################################


###########################################################################
#                                                                         #
#   @LoutLengths                                                          #
#                                                                         #
#   Convert PostScript lengths into Lout lengths.                         #
#                                                                         #
###########################################################################

export in cm pt em sp vs ft dg
def @LoutLengths
{
    def in left x { x"i" }
    def cm left x { x"c" }
    def pt left x { x"p" }
    def em left x { x"m" }
    def sp left x { x"s" }
    def vs left x { x"b" }
    def ft left x { x"f" }
    def dg left x { x"d" }
}


###########################################################################
#                                                                         #
#   @PSLengths                                                            #
#                                                                         #
#   Convert Lout lengths into PostScript (also PDF) lengths.              #
#   PDF is no longer supported but this code was there already so         #
#   it's been carried over.                                               #
#                                                                         #
###########################################################################

export i c p m s v f d
def @PSLengths
{
    def i left x {
	@BackEnd @Case {
	    PostScript @Yield { x" in" }
	    PDF        @Yield { "__mul(__in, "x")" }
	    PlainText  @Yield ""
	}
    }

    def c left x {
	@BackEnd @Case {
	    PostScript @Yield { x" cm" }
	    PDF        @Yield { "__mul(__cm, "x")" }
	    PlainText  @Yield ""
	}
    }

    def p left x {
	@BackEnd @Case {
	    PostScript @Yield { x" pt" }
	    PDF        @Yield { "__mul(__pt, "x")" }
	    PlainText  @Yield ""
	}
    }

    def m left x {
	@BackEnd @Case {
	    PostScript @Yield { x" em" }
	    PDF        @Yield { "__mul(__em, "x")" }
	    PlainText  @Yield ""
	}
    }

    def s left x {
	@BackEnd @Case {
	    PostScript @Yield { x" sp" }
	    PDF        @Yield { "__mul(__louts, "x")" }
	    PlainText  @Yield ""
	}
    }

    def v left x {
	@BackEnd @Case {
	    PostScript @Yield { x" vs" }
	    PDF        @Yield { "__mul(__loutv, "x")" }
	    PlainText  @Yield ""
	}
    }

    def f left x {
	@BackEnd @Case {
	    PostScript @Yield { x" ft" }
	    PDF        @Yield { "__mul(__loutf, "x")" }
	    PlainText  @Yield ""
	}
    }

    def d left x {
	@BackEnd @Case {
	    PostScript @Yield { x" dg" }
	    PDF        @Yield { "__mul(__loutd, "x")" }
	    PlainText  @Yield ""
	}
    }
}