/** * Replace a tab with the effective number of white spaces. */ private String tab2space(TextRun tr) { AttributedString string = new AttributedString(" "); String fontFamily = tr.getFontFamily(); if (fontFamily == null) { fontFamily = "Lucida Sans"; } string.addAttribute(TextAttribute.FAMILY, fontFamily); Double fs = tr.getFontSize(); if (fs == null) { fs = 12d; } string.addAttribute(TextAttribute.SIZE, fs.floatValue()); TextLayout l = new TextLayout(string.getIterator(), new FontRenderContext(null, true, true)); double wspace = l.getAdvance(); Double tabSz = paragraph.getDefaultTabSize(); if (tabSz == null) { tabSz = wspace*4; } int numSpaces = (int)Math.ceil(tabSz / wspace); StringBuilder buf = new StringBuilder(); for(int i = 0; i < numSpaces; i++) { buf.append(' '); } return buf.toString(); }
/** * Replace a tab with the effective number of white spaces. */ private String tab2space(TextRun tr) { AttributedString string = new AttributedString(" "); String fontFamily = tr.getFontFamily(); if (fontFamily == null) { fontFamily = "Lucida Sans"; } string.addAttribute(TextAttribute.FAMILY, fontFamily); Double fs = tr.getFontSize(); if (fs == null) { fs = 12d; } string.addAttribute(TextAttribute.SIZE, fs.floatValue()); TextLayout l = new TextLayout(string.getIterator(), new FontRenderContext(null, true, true)); double wspace = l.getAdvance(); Double tabSz = paragraph.getDefaultTabSize(); if (tabSz == null) { tabSz = wspace*4; } int numSpaces = (int)Math.ceil(tabSz / wspace); StringBuilder buf = new StringBuilder(); for(int i = 0; i < numSpaces; i++) { buf.append(' '); } return buf.toString(); }