001 /* 002 * Copyright 2007 - 2007 JEuclid, http://jeuclid.sf.net 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 /* $Id: GraphicsSupport.java,v 86b5e673f9b8 2008/06/24 08:01:00 maxberger $ */ 018 019 package net.sourceforge.jeuclid.elements.support; 020 021 import net.sourceforge.jeuclid.Constants; 022 import net.sourceforge.jeuclid.LayoutContext; 023 import net.sourceforge.jeuclid.context.Parameter; 024 025 /** 026 * This class contains helper functions for graphical calculations. 027 * 028 * @version $Revision: 86b5e673f9b8 $ 029 */ 030 public final class GraphicsSupport { 031 032 /** Minimum line width. */ 033 public static final float MIN_LINEWIDTH = 1.0f; 034 035 private GraphicsSupport() { 036 // Empty on purpose. 037 } 038 039 /** 040 * Gets the size of the actual font used (including scriptsizemultiplier). 041 * 042 * @param context 043 * Layout context to use. 044 * @return size of the current font. 045 */ 046 public static float getFontsizeInPoint(final LayoutContext context) { 047 final float scriptMultiplier = (float) Math.pow((Float) context 048 .getParameter(Parameter.SCRIPTSIZEMULTIPLIER), 049 (Integer) context.getParameter(Parameter.SCRIPTLEVEL)); 050 final float mathsize = (Float) context 051 .getParameter(Parameter.MATHSIZE); 052 final float scriptminsize = (Float) context 053 .getParameter(Parameter.SCRIPTMINSIZE); 054 055 final float scriptsize = mathsize * scriptMultiplier; 056 057 return Math.max(Math.min(scriptminsize, mathsize), scriptsize); 058 } 059 060 /** 061 * Retrieve the width of a line that would be 1pt if unscaled. 062 * 063 * @param context 064 * Layout context to use. 065 * @return line width as float, at least {@link #MIN_LINEWIDTH} 066 */ 067 public static float lineWidth(final LayoutContext context) { 068 float lineSize = GraphicsSupport.getFontsizeInPoint(context) 069 / Constants.DEFAULT_FONTSIZE; 070 if (lineSize < GraphicsSupport.MIN_LINEWIDTH) { 071 lineSize = GraphicsSupport.MIN_LINEWIDTH; 072 } 073 return lineSize; 074 } 075 076 }