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

« back to all changes in this revision

Viewing changes to be/ugent/caagt/jmathtex/Glue.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
/* Glue.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
 * Represents glue by its 3 components. Contains the "glue rules".
 
33
 */
 
34
class Glue {
 
35
    
 
36
    // the glue components
 
37
    private final float space;
 
38
    private final float stretch;
 
39
    private final float shrink;
 
40
    
 
41
    private final String name;
 
42
    
 
43
    // contains the different glue types
 
44
    private static Glue[] glueTypes;
 
45
    
 
46
    // the glue table representing the "glue rules" (as in TeX)
 
47
    private static final int[][][] glueTable;
 
48
    
 
49
    static {
 
50
        GlueSettingsParser parser = new GlueSettingsParser();
 
51
        glueTypes = parser.getGlueTypes();
 
52
        glueTable = parser.createGlueTable();
 
53
    }
 
54
    
 
55
    public Glue(float space, float stretch, float shrink, String name) {
 
56
        this.space = space;
 
57
        this.stretch = stretch;
 
58
        this.shrink = shrink;
 
59
        this.name = name;
 
60
    }
 
61
    
 
62
    /**
 
63
     * Name of this glue object.
 
64
     */
 
65
    public String getName () {
 
66
       return this.name; 
 
67
    }
 
68
    
 
69
    /**
 
70
     * Creates a box representing the glue type according to the "glue rules" based
 
71
     * on the atom types between which the glue must be inserted.
 
72
     *
 
73
     * @param lType left atom type
 
74
     * @param rType right atom type
 
75
     * @param env the TeXEnvironment
 
76
     * @return a box containing representing the glue
 
77
     */
 
78
    public static Box get(int lType, int rType, TeXEnvironment env) {
 
79
        // types > INNER are considered of type ORD for glue calculations
 
80
        int l = (lType > 7 ? TeXConstants.TYPE_ORDINARY : lType);
 
81
        int r = (rType > 7 ? TeXConstants.TYPE_ORDINARY : rType);
 
82
        
 
83
        // search right glue-type in "glue-table"
 
84
        int glueType = glueTable[l][r][env.getStyle() / 2];        
 
85
        return glueTypes[glueType].createBox(env);
 
86
    }
 
87
    
 
88
    private Box createBox(TeXEnvironment env) {
 
89
        TeXFont tf = env.getTeXFont();
 
90
        // use "quad" from a font marked as an "mu font"
 
91
        float quad = tf.getQuad(env.getStyle(), tf.getMuFontId());
 
92
        return new GlueBox((space / 18.0f) * quad, (stretch / 18.0f) * quad,
 
93
                (shrink / 18.0f) * quad);
 
94
    }
 
95
}