draw something like 1.2 10^-9; returns the width of the string drawn. 'Digits' should be >=0 for drawing the mantissa (=1.38 in this example), negative to draw only 10^exponent Currently only supports center justification and right justification (y of center line) Fonts baseFont, smallFont should be
(double value, int digits, int x, int y, int justification, int fontAscent, Font baseFont, Font smallFont, String multiplySymbol)
| 3034 | * Fonts baseFont, smallFont should be scaled already |
| 3035 | * Returns the width of the String */ |
| 3036 | int drawExpString(double value, int digits, int x, int y, int justification, |
| 3037 | int fontAscent, Font baseFont, Font smallFont, String multiplySymbol) { |
| 3038 | String base = "10"; |
| 3039 | String exponent = null; |
| 3040 | String s = IJ.d2s(value, digits<=0 ? -1 : -digits); |
| 3041 | if (Tools.parseDouble(s) == 0) s = "0"; //don't write 0 as 0*10^0 |
| 3042 | int ePos = s.indexOf('E'); |
| 3043 | if (ePos < 0) |
| 3044 | base = s; //can't have exponential format, e.g. NaN |
| 3045 | else { |
| 3046 | if (digits>=0) { |
| 3047 | base = s.substring(0,ePos); |
| 3048 | if (digits == 0) |
| 3049 | base = Integer.toString((int)Math.round(Tools.parseDouble(base))); |
| 3050 | base += multiplySymbol+"10"; |
| 3051 | } |
| 3052 | exponent = s.substring(ePos+1); |
| 3053 | } |
| 3054 | //IJ.log(s+" -> "+base+"^"+exponent+" maxAsc="+fontAscent+" font="+baseFont); |
| 3055 | ip.setJustification(RIGHT); |
| 3056 | int width = ip.getStringWidth(base); |
| 3057 | if (exponent != null) { |
| 3058 | ip.setFont(smallFont); |
| 3059 | int wExponent = ip.getStringWidth(exponent); |
| 3060 | width += wExponent; |
| 3061 | if (justification == CENTER) x += width/2; |
| 3062 | ip.drawString(exponent, x, y+fontAscent*3/10); |
| 3063 | x -= wExponent; |
| 3064 | ip.setFont(baseFont); |
| 3065 | } |
| 3066 | ip.drawString(base, x, y+fontAscent*7/10); |
| 3067 | return width; |
| 3068 | } |
| 3069 | |
| 3070 | /** Returns the user-supplied (via setOptions) or default multiplication symbol (middot) */ |
| 3071 | @AstroImageJ(reason = "Access widen for Vector Plot saving", modified = true) |
no test coverage detected