Source code: jpicedt/format/latex/parser/LineThicknessExpression.java
1 /* jPicEdt version 1.3.2, a picture editor for LaTeX.
2 Copyright (C) 1999-2002 Sylvain Reynal
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 Sylvain Reynal
19 Département de Physique
20 Ecole Nationale Supérieure de l'Electronique et de ses Applications (ENSEA)
21 6, avenue du Ponceau
22 95014 CERGY CEDEX
23 FRANCE
24
25 Tel : 00 +33 130 736 245
26 Fax : 00 +33 130 736 667
27 e-mail : reynal@ensea.fr
28 jPicEdt web page : http://www.jpicedt.org
29 */
30
31 package jpicedt.format.latex.parser;
32
33 import jpicedt.graphic.io.parser.*;
34 import jpicedt.graphic.model.*;
35
36 /**
37 * Legal syntax :
38 * \linethickness{0.4pt}
39 * \linethickness{0.4mm}
40 * \linethickness{0.4cm}
41 * \linethickness{0.4} // en mm par défaut
42 * note : 1pt = 1/72.27 inch = 0.3515 mm cf. LaTeX Book (Leslie Lamport) p.192
43 */
44 public class LineThicknessExpression extends SequenceExpression implements ExpressionConstants,PicObjectConstants {
45
46 private Pool pool;
47 private double lineWidth;
48
49 public LineThicknessExpression(Pool pl){
50
51 super(true); // throw IncompleteSequence Exception
52 pool = pl;
53
54 // \\linethickness{val}
55 add(new LiteralExpression("\\linethickness{"));
56 add(WHITE_SPACES_OR_EOL);
57 add(new NumericalExpression(DOUBLE, POSITIVE, null, false){
58 public void action(ParserEvent e){
59 if (DEBUG) System.out.println(e);
60 lineWidth = ((Number)e.getValue()).doubleValue();
61 pool.getAttributeSet(LaTeXParser.KEY_ATTRIBUTES).setAttribute(LINE_WIDTH,e.getValue());
62 }});
63 // no white-space here !
64 add(new WordExpression("}", true){ // postfix="}", swallow
65 public void action(ParserEvent e){
66 if (DEBUG) System.out.println(e);
67 String s= (String)e.getValue();
68 if (s.equals("pt")) {
69 lineWidth *= PS_POINT;
70 pool.getAttributeSet(LaTeXParser.KEY_ATTRIBUTES).setAttribute(LINE_WIDTH,new Double(lineWidth));
71 return;
72 }
73 if (s.equals("cm")) {
74 lineWidth *= 10;
75 pool.getAttributeSet(LaTeXParser.KEY_ATTRIBUTES).setAttribute(LINE_WIDTH,new Double(lineWidth));
76 return;
77 }
78 // "mm" ? -> unchanged
79 }});
80 }
81
82 public String toString(){
83 return "[LineThicknessExpression]";
84 }
85
86 } // LineThicknessExpression