Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ps/PSPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ps/PSPainter.java?rev=741165&r1=741164&r2=741165&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ps/PSPainter.java (original) +++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/java/org/apache/fop/render/ps/PSPainter.java Thu Feb 5 16:27:08 2009 @@ -312,8 +312,33 @@ } } + private String formatMptAsPt(PSGenerator gen, int value) { + return gen.formatDouble(value / 1000.0); + } + + /* Disabled: performance experiment (incomplete) + + private static final String ZEROS = "0.00"; + + private String formatMptAsPt1(int value) { + String s = Integer.toString(value); + int len = s.length(); + StringBuffer sb = new StringBuffer(); + if (len < 4) { + sb.append(ZEROS.substring(0, 5 - len)); + sb.append(s); + } else { + int dec = len - 3; + sb.append(s.substring(0, dec)); + sb.append('.'); + sb.append(s.substring(dec)); + } + return sb.toString(); + }*/ + /** {...@inheritdoc} */ - public void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException { + public void drawText(int x, int y, int letterSpacing, int wordSpacing, + int[] dx, String text) throws IFException { try { //Note: dy is currently ignored PSGenerator generator = getGenerator(); @@ -334,16 +359,13 @@ singleByteFont = (SingleByteFont)tf; } Font font = getFontInfo().getFontInstance(triplet, sizeMillipoints); - //String fontName = font.getFontName(); PSResource res = this.documentHandler.getPSResourceForFontKey(fontKey); generator.useFont("/" + res.getName(), fontSize); generator.getResourceTracker().notifyResourceUsageOnPage(res); - //textutil.updateTf(fontKey, fontSize, tf.isMultiByte()); - generator.writeln("1 0 0 -1 " + generator.formatDouble(x / 1000.0) - + " " + generator.formatDouble(y / 1000.0) + " Tm"); - //textutil.writeTextMatrix(new AffineTransform(1, 0, 0, -1, x / 1000f, y / 1000f)); + generator.writeln("1 0 0 -1 " + formatMptAsPt(generator, x) + + " " + formatMptAsPt(generator, y) + " Tm"); int textLen = text.length(); if (singleByteFont != null && singleByteFont.hasAdditionalEncodings()) { @@ -356,7 +378,8 @@ int encoding = mapped / 256; if (currentEncoding != encoding) { if (i > 0) { - writeText(text, start, i - start, dx, dy, font, tf); + writeText(text, start, i - start, + letterSpacing, wordSpacing, dx, font, tf); } if (encoding == 0) { useFont(fontKey, sizeMillipoints); @@ -367,62 +390,98 @@ start = i; } } - writeText(text, start, textLen - start, dx, dy, font, tf); + writeText(text, start, textLen - start, + letterSpacing, wordSpacing, dx, font, tf); } else { //Simple single-font painting useFont(fontKey, sizeMillipoints); - writeText(text, 0, textLen, dx, dy, font, tf); + writeText(text, 0, textLen, + letterSpacing, wordSpacing, dx, font, tf); } } catch (IOException ioe) { throw new IFException("I/O error in drawText()", ioe); } } - private void writeText(String text, int start, int len, int[] dx, int[] dy, + private void writeText(String text, int start, int len, + int letterSpacing, int wordSpacing, int[] dx, Font font, Typeface tf) throws IOException { PSGenerator generator = getGenerator(); int end = start + len; int initialSize = len; initialSize += initialSize / 2; + + boolean hasLetterSpacing = (letterSpacing != 0); + boolean needTJ = false; + + int lineStart = 0; + StringBuffer accText = new StringBuffer(initialSize); StringBuffer sb = new StringBuffer(initialSize); - sb.append("("); - int[] offsets = new int[len]; int dxl = (dx != null ? dx.length : 0); for (int i = start; i < end; i++) { char orgChar = text.charAt(i); char ch; int cw; + int glyphAdjust = 0; if (CharUtilities.isFixedWidthSpace(orgChar)) { //Fixed width space are rendered as spaces so copy/paste works in a reader ch = font.mapChar(CharUtilities.SPACE); - //int spaceDiff = font.getCharWidth(ch) - font.getCharWidth(orgChar); - //glyphAdjust = -(spaceDiff); + cw = font.getCharWidth(orgChar); + glyphAdjust = font.getCharWidth(ch) - cw; } else { + if ((wordSpacing != 0) && CharUtilities.isAdjustableSpace(orgChar)) { + glyphAdjust -= wordSpacing; + } ch = font.mapChar(orgChar); - //cw = tf.getWidth(ch, font.getFontSize()) / 1000; + cw = font.getCharWidth(orgChar); } - cw = font.getCharWidth(orgChar); - int glyphAdjust = 0; if (dx != null && i < dxl - 1) { - glyphAdjust += dx[i + 1]; + glyphAdjust -= dx[i + 1]; } - offsets[i - start] = cw + glyphAdjust; char codepoint = (char)(ch % 256); - PSGenerator.escapeChar(codepoint, sb); - } - sb.append(")" + PSGenerator.LF + "["); - for (int i = 0; i < len; i++) { - if (i > 0) { - if (i % 8 == 0) { - sb.append(PSGenerator.LF); - } else { - sb.append(" "); + PSGenerator.escapeChar(codepoint, accText); //add character to accumulated text + if (glyphAdjust != 0) { + needTJ = true; + if (sb.length() == 0) { + sb.append('['); //Need to start TJ } + if (accText.length() > 0) { + if ((sb.length() - lineStart + accText.length()) > 200) { + sb.append(PSGenerator.LF); + lineStart = sb.length(); + } + sb.append('('); + sb.append(accText); + sb.append(") "); + accText.setLength(0); //reset accumulated text + } + sb.append(Integer.toString(glyphAdjust)).append(' '); + } + } + if (needTJ) { + if (accText.length() > 0) { + sb.append('('); + sb.append(accText); + sb.append(')'); + } + if (hasLetterSpacing) { + sb.append("] " + formatMptAsPt(generator, letterSpacing) + " ATJ"); + } else { + sb.append("] TJ"); + } + } else { + sb.append('(').append(accText).append(")"); + if (hasLetterSpacing) { + StringBuffer spb = new StringBuffer(); + spb.append(formatMptAsPt(generator, letterSpacing)) + .append(" 0 "); + sb.insert(0, spb.toString()); + sb.append(" ashow"); + } else { + sb.append(" show"); } - sb.append(generator.formatDouble(offsets[i] / 1000f)); } - sb.append("]" + PSGenerator.LF + "xshow"); generator.writeln(sb.toString()); }
Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java?rev=741165&r1=741164&r2=741165&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java (original) +++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/src/sandbox/org/apache/fop/render/svg/SVGPainter.java Thu Feb 5 16:27:08 2009 @@ -325,19 +325,23 @@ } /** {...@inheritdoc} */ - public void drawText(int x, int y, int[] dx, int[] dy, String text) throws IFException { + public void drawText(int x, int y, int letterSpacing, int wordSpacing, int[] dx, String text) + throws IFException { try { establish(MODE_TEXT); AttributesImpl atts = new AttributesImpl(); XMLUtil.addAttribute(atts, XMLConstants.XML_SPACE, "preserve"); XMLUtil.addAttribute(atts, "x", Integer.toString(x)); XMLUtil.addAttribute(atts, "y", Integer.toString(y)); + if (letterSpacing != 0) { + XMLUtil.addAttribute(atts, "letter-spacing", Integer.toString(letterSpacing)); + } + if (wordSpacing != 0) { + XMLUtil.addAttribute(atts, "word-spacing", Integer.toString(wordSpacing)); + } if (dx != null) { XMLUtil.addAttribute(atts, "dx", IFUtil.toString(dx)); } - if (dy != null) { - XMLUtil.addAttribute(atts, "dy", IFUtil.toString(dy)); - } handler.startElement("text", atts); char[] chars = text.toCharArray(); handler.characters(chars, 0, chars.length); Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/block_letter-spacing.xml URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/block_letter-spacing.xml?rev=741165&r1=741164&r2=741165&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/block_letter-spacing.xml (original) +++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/block_letter-spacing.xml Thu Feb 5 16:27:08 2009 @@ -71,11 +71,23 @@ <eval expected="Default space between characters is defined to" xpath="//if:text[14]"/> <eval expected="0" xpath="//if:text[14]/@x"/> <eval expected="197466" xpath="//if:text[14]/@y"/> - <eval expected="0 2000 2000 2000 2000 2000 2000 0 4000 2000 2000 2000 2000 0 4000 2000 2000 2000 2000 2000 2000 0 4000 2000 2000 2000 2000 2000 2000 2000 2000 2000 0 4000 2000 0 4000 2000 2000 2000 2000 2000 2000 0 4000 2000" xpath="//if:text[14]/@dx"/> + <eval expected="2000" xpath="//if:text[14]/@letter-spacing"/> + <true xpath="not(//if:text[14]/@word-spacing)"/> + <true xpath="not(//if:text[14]/@dx)"/> <eval expected="Default space between characters is defined to be" xpath="//if:text[20]"/> <eval expected="0" xpath="//if:text[20]/@x"/> <eval expected="283866" xpath="//if:text[20]/@y"/> - <eval expected="0 1938 1938 1938 1938 1938 1938 0 3836 1938 1938 1938 1938 0 3836 1938 1938 1938 1938 1938 1938 0 3836 1938 1938 1938 1938 1938 1938 1938 1938 1938 0 3836 1938 0 3836 1938 1938 1938 1938 1938 1938 0 3836 1938 0 3836 1938" xpath="//if:text[20]/@dx"/> + <eval expected="1938" xpath="//if:text[20]/@letter-spacing"/> + <eval expected="-40" xpath="//if:text[20]/@word-spacing"/> + <true xpath="not(//if:text[20]/@dx)"/> + + <eval expected="2000" xpath="//if:text[21]/@letter-spacing"/> + <true xpath="not(//if:text[21]/@word-spacing)"/> + <true xpath="not(//if:text[21]/@dx)"/> + + <eval expected="1364" xpath="//if:text[22]/@letter-spacing"/> + <eval expected="-362" xpath="//if:text[22]/@word-spacing"/> + <true xpath="not(//if:text[22]/@dx)"/> </if-checks> </testcase> Modified: xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/kerning_1_on.xml URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/kerning_1_on.xml?rev=741165&r1=741164&r2=741165&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/kerning_1_on.xml (original) +++ xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/layoutengine/standard-testcases/kerning_1_on.xml Thu Feb 5 16:27:08 2009 @@ -69,37 +69,51 @@ <eval expected=" text-text Hello World." xpath="//if:text[2]"/> <eval expected="36420" xpath="//if:text[2]/@x"/> <eval expected="10266" xpath="//if:text[2]/@y"/> + <true xpath="not(//if:text[2]/@letter-spacing)"/> + <true xpath="not(//if:text[2]/@word-spacing)"/> <eval expected="0 0 0 -360 0 0 0 0 -360 0 0 0 0 0 0 0 0 0 -360 0 180" xpath="//if:text[2]/@dx"/> <eval expected="VAVAV" xpath="//if:text[3]"/> <eval expected="0" xpath="//if:text[3]/@x"/> <eval expected="24666" xpath="//if:text[3]/@y"/> - <eval expected="0 40 160 40 160" xpath="//if:text[3]/@dx"/> + <eval expected="1000" xpath="//if:text[3]/@letter-spacing"/> + <true xpath="not(//if:text[3]/@word-spacing)"/> + <eval expected="0 -960 -840 -960 -840" xpath="//if:text[3]/@dx"/> <eval expected=" text-text Hello World." xpath="//if:text[4]"/> <eval expected="40420" xpath="//if:text[4]/@x"/> <eval expected="24666" xpath="//if:text[4]/@y"/> - <eval expected="0 2000 1000 640 1000 1000 1000 1000 640 1000 0 2000 1000 1000 1000 1000 0 2000 640 1000 1180 1000 1000" xpath="//if:text[4]/@dx"/> - + <eval expected="1000" xpath="//if:text[4]/@letter-spacing"/> + <true xpath="not(//if:text[3]/@word-spacing)"/> + <eval expected="0 0 0 -360 0 0 0 0 -360 0 0 0 0 0 0 0 0 0 -360 0 180" xpath="//if:text[4]/@dx"/> + <eval expected="VAVAV" xpath="//if:text[5]"/> <eval expected="0" xpath="//if:text[5]/@x"/> <eval expected="39066" xpath="//if:text[5]/@y"/> + <true xpath="not(//if:text[5]/@letter-spacing)"/> + <eval expected="5000" xpath="//if:text[5]/@word-spacing"/> <eval expected="0 -960 -840 -960 -840" xpath="//if:text[5]/@dx"/> <eval expected=" text-text Hello World." xpath="//if:text[6]"/> <eval expected="36420" xpath="//if:text[6]/@x"/> <eval expected="39066" xpath="//if:text[6]/@y"/> - <eval expected="0 5000 0 -360 0 0 0 0 -360 0 0 5000 0 0 0 0 0 5000 -360 0 180" xpath="//if:text[6]/@dx"/> - + <true xpath="not(//if:text[5]/@letter-spacing)"/> + <eval expected="5000" xpath="//if:text[6]/@word-spacing"/> + <eval expected="0 0 0 -360 0 0 0 0 -360 0 0 0 0 0 0 0 0 0 -360 0 180" xpath="//if:text[4]/@dx"/> + <eval expected="VAVAV" xpath="//if:text[7]"/> <eval expected="0" xpath="//if:text[7]/@x"/> <eval expected="53466" xpath="//if:text[7]/@y"/> - <eval expected="0 40 160 40 160" xpath="//if:text[7]/@dx"/> + <eval expected="1000" xpath="//if:text[7]/@letter-spacing"/> + <eval expected="3000" xpath="//if:text[7]/@word-spacing"/> <!-- TODO Not sure that's correct! --> + <eval expected="0 -960 -840 -960 -840" xpath="//if:text[7]/@dx"/> <eval expected=" text-text Hello World." xpath="//if:text[8]"/> <eval expected="40420" xpath="//if:text[8]/@x"/> <eval expected="53466" xpath="//if:text[8]/@y"/> - <eval expected="0 5000 1000 640 1000 1000 1000 1000 640 1000 0 5000 1000 1000 1000 1000 0 5000 640 1000 1180 1000 1000" xpath="//if:text[8]/@dx"/> + <eval expected="1000" xpath="//if:text[8]/@letter-spacing"/> + <eval expected="3000" xpath="//if:text[8]/@word-spacing"/> <!-- TODO Not sure that's correct! --> + <eval expected="0 0 0 -360 0 0 0 0 -360 0 0 0 0 0 0 0 0 0 -360 0 180" xpath="//if:text[8]/@dx"/> </if-checks> </testcase> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
