Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jpicedt/format/latex/parser/LaTeXParser.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.RootExpression;
34  import jpicedt.graphic.io.parser.Pool;
35  import jpicedt.graphic.io.parser.ExpressionConstants;
36  
37  import jpicedt.graphic.PicPoint;
38  import jpicedt.graphic.model.*;
39  
40  import java.awt.Color;
41  import java.io.*;
42  import java.util.*;
43  
44  /**
45   * Grammar rules for the LaTeX's picture environment parser
46   */
47  public class LaTeXParser extends RootExpression implements ExpressionConstants {
48  
49    /** key associated with unit-length parameter (double) */
50    public static final Pool.Key KEY_UNIT_LENGTH = new Pool.Key("latex.unit-length");
51  
52    /** key associated with the shared attribute set (PicAttributeSet) */
53    public static final Pool.Key KEY_ATTRIBUTES = new Pool.Key("latex.attributes");
54  
55    private Pool pool;
56    
57    /**
58     * Creates a new LaTeXParser, and build grammar rules
59     * @param pool a hashmap used to share variables across the grammar tree
60     */
61    public LaTeXParser(Pool pool) {
62      this.pool = pool;
63  
64      // 0°) unitlength and begin picture
65      add(new UnitLengthExpression(pool)); // \\unitlength
66      add(new BeginPictureExpression()); // not used (but otherwise, it's considered a non-parsable exp)
67      
68      // 1°) parameters
69      add(new LineThicknessExpression(pool));   // \\linethickness
70  
71      // 2°) groups
72      add(new PicGroupExpression(pool));       // %Begin|End group
73  
74      // 3°) lines & polygons
75      add(new PicLineExpression(pool));    // %PicLine
76      add(new PicPolygonExpression(pool));  // %PicPolygon
77  
78      // 4°) frames
79      add(new PicRectangleExpression(pool));  // %PicRectangle
80  
81      // 5°) ellipses and arcs
82      add(new PicEllipseExpression(pool));  // %PicEllipse
83  
84      // 6°) splines 
85      add(new PicBezierExpression(pool));  // %PicBezier (quad)
86  
87      // 6°) splines 
88      add(new LaTeXBezierExpression(pool));  // \\qbezier or \\bezier{N}
89  
90      // 7°) text and misc.
91      add(new LaTeXPutExpression(pool));  // \\put(x,y){...} -> PicText, PicPut (also support LaTeX's "\\circle" command w/o PicEdt comment line)
92      
93      // 8°) comment
94      add(new jpicedt.graphic.io.parser.CommentExpression("%"));
95  
96      // [todo] multiput
97      
98      // throw ParserException.EndOfPicture to signals that a \end{picture} was found
99      // and that the parsing process ends up here (otherwise, we stop at EOF) 
100     add(new EndPictureExpression());
101   }
102 
103 
104   /**
105    * reinit LaTeX related parameters
106    */
107   public void reinit(){
108 
109     PicAttributeSet ltxSet = new PicAttributeSet();
110     double unitLength = 1; // 1mm
111     pool.put(KEY_UNIT_LENGTH, new Double(unitLength));
112     pool.put(KEY_ATTRIBUTES, ltxSet);
113   }
114 }