~ubuntu-branches/ubuntu/utopic/libjmathtex-java/utopic

« back to all changes in this revision

Viewing changes to be/ugent/caagt/jmathtex/Dummy.java

  • Committer: Bazaar Package Importer
  • Author(s): Adriaan Peeters
  • Date: 2007-09-25 14:07:55 UTC
  • Revision ID: james.westby@ubuntu.com-20070925140755-mro37pqu4wkhqa9t
Tags: upstream-0.7~pre
ImportĀ upstreamĀ versionĀ 0.7~pre

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Dummy.java
 
2
 * =========================================================================
 
3
 * This file is part of the JMathTeX Library - http://jmathtex.sourceforge.net
 
4
 * 
 
5
 * Copyright (C) 2004-2007 Universiteit Gent
 
6
 * 
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or (at
 
10
 * your option) any later version.
 
11
 * 
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * General Public License for more details.
 
16
 * 
 
17
 * A copy of the GNU General Public License can be found in the file
 
18
 * LICENSE.txt provided with the source distribution of this program (see
 
19
 * the META-INF directory in the source jar). This license can also be
 
20
 * found on the GNU website at http://www.gnu.org/licenses/gpl.html.
 
21
 * 
 
22
 * If you did not receive a copy of the GNU General Public License along
 
23
 * with this program, contact the lead developer, or write to the Free
 
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
25
 * 02110-1301, USA.
 
26
 * 
 
27
 */
 
28
 
 
29
package be.ugent.caagt.jmathtex;
 
30
 
 
31
/**
 
32
 * Used by RowAtom. The "textSymbol"-property and the type of an atom can change 
 
33
 * (according to the TeX-algorithms used). Or this atom can be replaced by a ligature, 
 
34
 * (if it was a CharAtom). But atoms cannot be changed, otherwise 
 
35
 * different boxes could be made from the same TeXFormula, and that is not desired!
 
36
 * This "dummy atom" makes sure that changes to an atom (during the createBox-method of
 
37
 * a RowAtom) will be reset.
 
38
 */
 
39
class Dummy {
 
40
 
 
41
   private Atom el;
 
42
 
 
43
   private boolean textSymbol = false;
 
44
 
 
45
   private int type = -1;
 
46
 
 
47
   /**
 
48
    * Creates a new Dummy for the given atom.
 
49
    * 
 
50
    * @param a an atom
 
51
    */
 
52
   public Dummy(Atom a) {
 
53
      el = a;
 
54
   }
 
55
 
 
56
   /**
 
57
    * Changes the type of the atom
 
58
    * 
 
59
    * @param t the new type
 
60
    */
 
61
   public void setType(int t) {
 
62
      type = t;
 
63
   }
 
64
 
 
65
   /**
 
66
    * 
 
67
    * @return the changed type, or the old left type if it hasn't been changed
 
68
    */
 
69
   public int getLeftType() {
 
70
      return (type >= 0 ? type : el.getLeftType());
 
71
   }
 
72
 
 
73
   /**
 
74
    * 
 
75
    * @return the changed type, or the old right type if it hasn't been changed
 
76
    */
 
77
   public int getRightType() {
 
78
      return (type >= 0 ? type : el.getRightType());
 
79
   }
 
80
 
 
81
   public boolean isCharSymbol() {
 
82
      return el instanceof CharSymbol;
 
83
   }
 
84
 
 
85
   /*
 
86
    * This method will only be called if isCharSymbol returns true.
 
87
    */
 
88
   public CharFont getCharFont(TeXFont tf) {
 
89
      return ((CharSymbol) el).getCharFont(tf);
 
90
   }
 
91
 
 
92
   /**
 
93
    * Changes this atom into the given "ligature atom".
 
94
    * 
 
95
    * @param a the ligature atom
 
96
    */
 
97
   public void changeAtom(FixedCharAtom a) {
 
98
      textSymbol = false;
 
99
      type = -1;
 
100
      el = a;
 
101
   }
 
102
 
 
103
   public Box createBox(TeXEnvironment rs) {
 
104
      if (textSymbol)
 
105
         ((CharSymbol) el).markAsTextSymbol();
 
106
      Box b = el.createBox(rs);
 
107
      if (textSymbol)
 
108
         ((CharSymbol) el).removeMark(); // atom remains unchanged!
 
109
      return b;
 
110
   }
 
111
 
 
112
   public void markAsTextSymbol() {
 
113
      textSymbol = true;
 
114
   }
 
115
 
 
116
   public boolean isKern() {
 
117
      return el instanceof SpaceAtom;
 
118
   }
 
119
 
 
120
   // only for Row-elements
 
121
   public void setPreviousAtom(Dummy prev) {
 
122
      if (el instanceof Row)
 
123
         ((Row) el).setPreviousAtom(prev);
 
124
   }
 
125
}