/** * Guess the number of characters that can be displayed in <code>destWidth</code>. * The number is guessed as an arbitrary width per character for the font is assumed. * @param destWidth destination with * @param font to used for the text * @return number of characters that should match into <code>destWidth</code> */ public int guessNumberOfCharacters(double destWidth, Font font) { double width = computeTextWidth(font, "n", Double.MAX_VALUE); return (int) Math.floor(destWidth/(width*0.8)); } /**
/** * Calculate the dimensions of a string using the font with the number of characters. * The height and width are the maximum value, the width of a character is an average value. * @param size number of carachters for wich to calculate the dimensions * @param font to be used * @return dimensions of a String containing Tg to calculate the heigth and n for the width calculation. */ @Override public Dimension2D calculate(int size, Font font) { double height = computeTextHeight(font, "Tg", Double.MAX_VALUE); double width = computeTextWidth(font, "n", Double.MAX_VALUE); return new Dimension2D(width*size*.8, height*1.2); }
/** * Calculate the dimensions of a string using the font with the characters in the string. * The height and width are the maximum value. The text will not be wrapped. * @param text for which to calculate the dimensions * @param font to be used for the calculation * @return Bounding box for the text using font. */ @Override public Dimension2D calculate(String text, Font font) { double height = computeTextHeight(font, text, Double.MAX_VALUE); double width = computeTextWidth(font, text, Double.MAX_VALUE); return new Dimension2D(width, height*1.2); }
double lineWidth = sizing.computeTextWidth(font, oneLine.toString(), Double.MAX_VALUE); lineWidth = sizing.computeTextWidth(font, l.getLine(), Double.MAX_VALUE); if (!isLineTooLong(lineWidth)) { lineWidth = sizing.computeTextWidth(font, word, Double.MAX_VALUE); if (isLineTooLong(lineWidth)) { if (!tokenizer.hasMoreTokens()) {