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

« back to all changes in this revision

Viewing changes to src/org/scilab/forge/jlatexmath/RotateBox.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
/* RotateBox.java
 
2
 * =========================================================================
 
3
 * This file is part of the JLaTeXMath Library - http://forge.scilab.org/jlatexmath
 
4
 * 
 
5
 * Copyright (C) 2009 DENIZET Calixte
 
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 org.scilab.forge.jlatexmath;
 
30
 
 
31
import java.awt.Graphics2D;
 
32
 
 
33
/**
 
34
 * A box representing a rotated box.
 
35
 */
 
36
public class RotateBox extends Box {
 
37
 
 
38
    protected double angle = 0;
 
39
    private Box box;
 
40
    private float xmax, xmin, ymax, ymin;
 
41
 
 
42
    public RotateBox(Box b, double angle) {
 
43
        this.box = b;
 
44
        angle = angle * Math.PI / 180;
 
45
        this.angle = angle;
 
46
        height = b.height;
 
47
        depth = b.depth;
 
48
        width = b.width;
 
49
        float s = (float)Math.sin(angle);
 
50
        float c = (float)Math.cos(angle);
 
51
        xmax = Math.max(-height*s, Math.max(depth*s, Math.max(width*c+depth*s,width*c-height*s)));
 
52
        xmin = Math.min(-height*s, Math.min(depth*s, Math.min(width*c+depth*s,width*c-height*s)));
 
53
        ymax = Math.max(height*c, Math.max(-depth*c, Math.max(width*s-depth*c,width*s+height*c)));
 
54
        ymin = Math.min(height*c, Math.min(-depth*c, Math.min(width*s-depth*c,width*s+height*c)));
 
55
        width = xmax - xmin;
 
56
        height = ymax;
 
57
        depth = -ymin;
 
58
    }
 
59
    
 
60
    public void draw(Graphics2D g2, float x, float y) {
 
61
        x -= xmin;
 
62
        g2.rotate(-angle, x, y);
 
63
        box.draw(g2, x, y);
 
64
        g2.rotate(angle, x, y);
 
65
    }
 
66
 
 
67
    public int getLastFontId() {
 
68
        return box.getLastFontId();
 
69
    }
 
70
}