@Override public int getWidthOfString(String string, int fontSize, boolean kerning) { int width = 0; char[] chars = string.toCharArray(); for (int i = 0; i < chars.length; ++i) { width += this.getWidth(UnicodeConverter.getPostscriptForUnicode((int) chars[i])); if (kerning && (i + 1 != chars.length)) { width -= this.getKerning((int) chars[i], (int) chars[i + 1]); } } return width * fontSize; }
@Override public List<Integer> getWidths(int firstCharCode, int lastCharCode) { List<Integer> widths = new ArrayList<Integer>(); for (int i = firstCharCode; i < lastCharCode + 1; ++i) { Type1CharacterMetric cm = afm.getCharacterMetric(UnicodeConverter.getPostscriptForUnicode(i)); if (cm != null) { widths.add(cm.getWx()); } else { widths.add(0); } } return widths; }
/** * Returns either the lowest or highset bounding box value found within the text on the given * bounding box index (e.g. the first bbox value is for descent so that means passing 1) * * @param text Text to check the highest value for * @param bbIndex the index to check on * @param highest if true the method will return the highest value, if false the method will * return the lowest value found * @return int containing the value */ private int getBoundingBoxValueForTextOnIndex(String text, int bbIndex, boolean highest) { int value = 0; char[] chars = text.toCharArray(); for (char aChar : chars) { int[] boundingBox = this.getBoundingBoxForCharacter(UnicodeConverter.getPostscriptForUnicode((int) aChar)); if (boundingBox != null) { int bBoxValue = boundingBox[bbIndex]; value = highest ? Math.max(value, bBoxValue) : Math.min(value, bBoxValue); } } return value; }
@Override public double getWidthPoint(int charCode) { return this.getWidthPoint(UnicodeConverter.getPostscriptForUnicode(charCode)); }
@Override public int getKerning(int characterCode, int secondCharacterCode) { return this.getKerning( UnicodeConverter.getPostscriptForUnicode(characterCode), UnicodeConverter.getPostscriptForUnicode(secondCharacterCode)); }
@Override public int getWidth(int characterCode) { return this.getWidth(UnicodeConverter.getPostscriptForUnicode(characterCode)); }