View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.foRenderer.figures;
13  
14  import org.apache.fop.datatypes.ColorType;
15  import org.eclipse.draw2d.geometry.Point;
16  import org.eclipse.draw2d.geometry.Rectangle;
17  import org.eclipse.swt.graphics.Color;
18  import org.eclipse.swt.graphics.RGB;
19  
20  /***
21   * @author TV
22   * Created on 8.1.2005
23   */
24  public class FOFigureUtils {
25  
26    private static final double FOP_DPI = 72.0f;
27    private static final double SCR_DPI = 96.0f;
28    private static final double MP_MULT = 1000.0f;
29  
30    /***
31     * @param ct
32     * @return
33     */
34    public static Color getSWTColor(ColorType ct) {
35      return new Color(null, new RGB(ct.getAWTColor().getRed(), 
36        ct.getAWTColor().getGreen(), ct.getAWTColor().getBlue()));
37    }
38  
39    // Conversion method from milipoints to pixels. Works for constant DPIs 
40    // at the moment.
41    
42    public static final int mps2pxs(double mps) {
43      return (int)Math.round((mps/MP_MULT)/FOP_DPI*SCR_DPI);
44    }
45  
46    public static final Rectangle mps2pxs(int x, int y, int w, int h) {
47      return new Rectangle(mps2pxs(x), mps2pxs(y), mps2pxs(w), mps2pxs(h));
48    }
49  
50    public static final Rectangle mps2pxs(Rectangle r) {
51      return mps2pxs(r.x, r.y, r.width, r.height);
52    }
53  
54    public static final Point mps2pxs(int x, int y) {
55      return new Point(mps2pxs(x), mps2pxs(y));
56    }
57  
58  }