/** * Gets the width of a <CODE>char</CODE> in points. * @param char1 the <CODE>char</CODE> to get the width of * @param fontSize the font size * @return the width in points */ public float getWidthPoint(int char1, float fontSize) { return getWidth(char1) * 0.001f * fontSize; }
/** * Gets the width of a <CODE>char</CODE> in points. * @param char1 the <CODE>char</CODE> to get the width of * @param fontSize the font size * @return the width in points */ public float getWidthPoint(int char1, float fontSize) { return getWidth(char1) * 0.001f * fontSize; }
/** * Gets the width of a <CODE>String</CODE> in points. * @param text the <CODE>String</CODE> to get the width of * @param fontSize the font size * @return the width in points */ public float getWidthPoint(String text, float fontSize) { return getWidth(text) * 0.001f * fontSize; }
private static float getMaxFontSize(BaseFont bf, String text, int width) { int textWidth = bf.getWidth(text); return (1000 * width) / textWidth; }
/** * Gets the width of a <CODE>String</CODE> in points. * @param text the <CODE>String</CODE> to get the width of * @param fontSize the font size * @return the width in points */ public float getWidthPoint(String text, float fontSize) { return getWidth(text) * 0.001f * fontSize; }
BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float charWidth = bf.getWidth(" "); int charactersPerLine = 101; float pageWidth = document.right() - document.left(); float fontSize = (1000 * (pageWidth / (charWidth * charactersPerLine))); fontSize = ((int)(fontSize * 100)) / 100f; Font font = new Font(bf, fontSize);
/** * Gets the width of a <CODE>String</CODE> in points taking kerning * into account. * @param text the <CODE>String</CODE> to get the width of * @param fontSize the font size * @return the width in points */ public float getWidthPointKerned(String text, float fontSize) { float size = getWidth(text) * 0.001f * fontSize; if (!hasKernPairs()) return size; int len = text.length() - 1; int kern = 0; char c[] = text.toCharArray(); for (int k = 0; k < len; ++k) { kern += getKerning(c[k], c[k + 1]); } return size + kern * 0.001f * fontSize; }
/** * Gets the width of a <CODE>char</CODE> in normalized 1000 units. * @param char1 the unicode <CODE>char</CODE> to get the width of * @return the width in normalized 1000 units */ @Override public int getWidth(int char1) { if (isType0) { if(hMetrics != null && cjkMirror != null && !cjkMirror.isVertical()) { int c = cjkMirror.getCidCode(char1); int v = hMetrics.get(c); if (v > 0) return v; else return defaultWidth; } else { int[] ws = metrics.get(Integer.valueOf(char1)); if (ws != null) return ws[1]; else return 0; } } if (cjkMirror != null) return cjkMirror.getWidth(char1); return super.getWidth(char1); }
/** * Gets the width of a <CODE>String</CODE> in points taking kerning * into account. * @param text the <CODE>String</CODE> to get the width of * @param fontSize the font size * @return the width in points */ public float getWidthPointKerned(String text, float fontSize) { float size = getWidth(text) * 0.001f * fontSize; if (!hasKernPairs()) return size; int len = text.length() - 1; int kern = 0; char c[] = text.toCharArray(); for (int k = 0; k < len; ++k) { kern += getKerning(c[k], c[k + 1]); } return size + kern * 0.001f * fontSize; }
/** * Gets the width of a <CODE>char</CODE> in normalized 1000 units. * @param char1 the unicode <CODE>char</CODE> to get the width of * @return the width in normalized 1000 units */ @Override public int getWidth(int char1) { if (isType0) { if(hMetrics != null && cjkMirror != null && !cjkMirror.isVertical()) { int c = cjkMirror.getCidCode(char1); int v = hMetrics.get(c); if (v > 0) return v; else return defaultWidth; } else { int[] ws = metrics.get(Integer.valueOf(char1)); if (ws != null) return ws[1]; else return 0; } } if (cjkMirror != null) return cjkMirror.getWidth(char1); return super.getWidth(char1); }