~ubuntu-branches/ubuntu/oneiric/libjlatexmath-java/oneiric

« back to all changes in this revision

Viewing changes to src/org/scilab/forge/jlatexmath/CharAtom.java

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru
  • Date: 2009-09-29 11:14:53 UTC
  • Revision ID: james.westby@ubuntu.com-20090929111453-0pmbj5as45odpxei
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* CharAtom.java
 
2
 * =========================================================================
 
3
 * This file is originally part of the JMathTeX Library - http://jmathtex.sourceforge.net
 
4
 * 
 
5
 * Copyright (C) 2004-2007 Universiteit Gent
 
6
 * Copyright (C) 2009 DENIZET Calixte
 
7
 * 
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or (at
 
11
 * your option) any later version.
 
12
 * 
 
13
 * This program is distributed in the hope that it will be useful, but
 
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 * 
 
18
 * A copy of the GNU General Public License can be found in the file
 
19
 * LICENSE.txt provided with the source distribution of this program (see
 
20
 * the META-INF directory in the source jar). This license can also be
 
21
 * found on the GNU website at http://www.gnu.org/licenses/gpl.html.
 
22
 * 
 
23
 * If you did not receive a copy of the GNU General Public License along
 
24
 * with this program, contact the lead developer, or write to the Free
 
25
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
26
 * 02110-1301, USA.
 
27
 * 
 
28
 */
 
29
 
 
30
package org.scilab.forge.jlatexmath;
 
31
 
 
32
/**
 
33
 * An atom representing exactly one alphanumeric character and the text style in which 
 
34
 * it should be drawn. 
 
35
 */
 
36
public class CharAtom extends CharSymbol {
 
37
 
 
38
   // alphanumeric character
 
39
   private final char c;
 
40
 
 
41
   // text style (null means the default text style)
 
42
   private final String textStyle;
 
43
 
 
44
   /**
 
45
    * Creates a CharAtom that will represent the given character in the given text style.
 
46
    * Null for the text style means the default text style.
 
47
    * 
 
48
    * @param c the alphanumeric character
 
49
    * @param textStyle the text style in which the character should be drawn
 
50
    */
 
51
   public CharAtom(char c, String textStyle) {
 
52
      this.c = c;
 
53
      this.textStyle = textStyle;
 
54
   }
 
55
 
 
56
   public Box createBox(TeXEnvironment env) {
 
57
      Char ch = getChar(env.getTeXFont(), env.getStyle());
 
58
      return new CharBox(ch);
 
59
   }
 
60
 
 
61
   /*
 
62
    * Get the Char-object representing this character ("c") in the right text style
 
63
    */
 
64
   private Char getChar(TeXFont tf, int style) {
 
65
      if (textStyle == null) // default text style
 
66
         return tf.getDefaultChar(c, style);
 
67
      else
 
68
         return tf.getChar(c, textStyle, style);
 
69
   }
 
70
 
 
71
   public CharFont getCharFont(TeXFont tf) {
 
72
      // style doesn't matter here 
 
73
      return getChar(tf, TeXConstants.STYLE_DISPLAY).getCharFont();
 
74
   }
 
75
 
 
76
}