diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java index 0fe18b6fa1..8da953a476 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/LineArea.java @@ -81,7 +81,6 @@ public void setBaseLevel(byte baseLevel) { @Override public void addChild(IArea area) { - // FIXME ? int childHorizontalSpan = area.getX() + area.getWidth(); int childVerticalSpan = area.getY() + area.getHeight(); @@ -122,8 +121,8 @@ public void align(boolean endParagraph, LayoutContext context) { boolean isJustified = CSSValueConstants.JUSTIFY_VALUE.equals(align) && !endParagraph; // single line - int spacing = width - currentIP; - spacing -= adjustSpacingForSoftHyphen(); + int spaceRemaining = width - currentIP; + spaceRemaining -= adjustSpacingForSoftHyphen(); int adjustLeftWhiteSpace = ignoreLeftMostWhiteSpace(); int adjustRightWhiteSpace = ignoreRightMostWhiteSpace(); if ((isRightAligned)) { @@ -131,19 +130,19 @@ public void align(boolean endParagraph, LayoutContext context) { while (iter.hasNext()) { AbstractArea area = (AbstractArea) iter.next(); if (parent.content.isDirectionRTL()) { - area.setPosition(spacing + area.getX(), area.getY()); + area.setPosition(spaceRemaining + area.getX(), area.getY()); } else { - area.setPosition(spacing + area.getX() + adjustRightWhiteSpace, area.getY()); + area.setPosition(spaceRemaining + area.getX() + adjustRightWhiteSpace, area.getY()); } } } else if (isCentered) { Iterator iter = getChildren(); while (iter.hasNext()) { AbstractArea area = (AbstractArea) iter.next(); - area.setPosition(spacing / 2 + area.getX() - adjustLeftWhiteSpace + adjustRightWhiteSpace, area.getY()); + area.setPosition(spaceRemaining / 2 + area.getX() - adjustLeftWhiteSpace + adjustRightWhiteSpace, area.getY()); } } else if (isJustified) { - justify(spacing, adjustLeftWhiteSpace, adjustRightWhiteSpace); + justify(spaceRemaining, adjustLeftWhiteSpace, adjustRightWhiteSpace); } else { // is left aligned if (parent.content != null && !parent.content.isDirectionRTL()) { @@ -182,6 +181,7 @@ private int adjustSpacingForSoftHyphen() { private int ignoreRightMostWhiteSpace() { if (lastTextArea != null) { String text = lastTextArea.getText(); + int letterSpacing = lastTextArea.getTextStyle().getLetterSpacing(); if (null != text) { char[] charArray = text.toCharArray(); int len = charArray.length; @@ -189,7 +189,8 @@ private int ignoreRightMostWhiteSpace() { len--; } if (len != charArray.length) { - return lastTextArea.getTextWidth(text.substring(len)); + return (1 + charArray.length - len) * letterSpacing + + lastTextArea.getTextWidth(text.substring(len)); } } } @@ -200,6 +201,7 @@ private int ignoreLeftMostWhiteSpace() { TextArea firstTextArea = findFirstNonEmptyTextArea(this); if (firstTextArea != null) { String text = firstTextArea.getText(); + int letterSpacing = lastTextArea.getTextStyle().getLetterSpacing(); if (null != text) { char[] charArray = text.toCharArray(); int len = 0; @@ -207,7 +209,7 @@ private int ignoreLeftMostWhiteSpace() { len++; } if (len > 0) { - return firstTextArea.getTextWidth(text.substring(0, len)); + return len * letterSpacing + firstTextArea.getTextWidth(text.substring(0, len)); } } } diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextArea.java index b78d89bdb2..c94b769f2c 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextArea.java @@ -243,9 +243,9 @@ private String calculateText() { * * @since 4.14 */ - public void addWord(int textLength, WordWidth wordWidth) { + public void addWord(int textLength, WordWidth wordWidth, int letterSpacing) { this.textLength += textLength; - this.width += wordWidth.width; + this.width += wordWidth.width + textLength * letterSpacing; this.softHyphenWidth = wordWidth.softHyphenWidth; } @@ -332,13 +332,18 @@ public void accept(IAreaVisitor visitor) { visitor.visitText(this); } + /** + * Return the text width, ignoring wordSpacing and letterSpacing. + * + * @param text + * @return text width + */ public int getTextWidth(String text) { FontInfo fontInfo = style.getFontInfo(); if (null != fontInfo) { return (int) (style.getFontInfo().getWordWidth(text) * PDFConstants.LAYOUT_TO_PDF_RATIO); - } else { - return 0; } + return 0; } @Override diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextCompositor.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextCompositor.java index 9e00583aea..0ec90bf65e 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextCompositor.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TextCompositor.java @@ -358,7 +358,7 @@ private void addWordIntoTextArea(TextArea textArea, Word word) { int adjustWordSize = fontInfo.getItalicAdjust() + width; if (textArea.hasSpace(adjustWordSize + wordWidth.softHyphenWidth * letterSpacing)) { - addWord(textArea, textLength, wordWidth); + addWord(textArea, textLength, wordWidth, letterSpacing); wordVestige = null; if (remainWords.hasWord()) { // test if we can append the word spacing @@ -385,7 +385,7 @@ private void addWordIntoTextArea(TextArea textArea, Word word) { } else { // If width of a word is larger than the max line width, // add it into the line directly. - addWord(textArea, textLength, wordWidth); + addWord(textArea, textLength, wordWidth, letterSpacing); } } else { wordVestige = null; @@ -401,26 +401,27 @@ private void doWordBreak(String str, TextArea area) { IHyphenationManager hm = new DefaultHyphenationManager(); Hyphenation wb = hm.getHyphenation(str); FontInfo fi = area.getStyle().getFontInfo(); + int letterSpacing = textStyle.getLetterSpacing(); if (area.getMaxWidth() < 0) { - addWordVestige(area, 1, new WordWidth(fi, wb.getHyphenText(0, 1)), str.substring(1)); + addWordVestige(area, 1, new WordWidth(fi, wb.getHyphenText(0, 1)), str.substring(1), letterSpacing); return; } int endHyphenIndex = hyphen(0, area.getMaxWidth() - area.getWidth(), wb, fi); // current line can't even place one character. Force to add the first // character into the line. if (endHyphenIndex == 0 && area.getWidth() == 0) { - addWordVestige(area, 1, new WordWidth(fi, wb.getHyphenText(0, 1)), str.substring(1)); + addWordVestige(area, 1, new WordWidth(fi, wb.getHyphenText(0, 1)), str.substring(1), letterSpacing); } else { WordWidth wordWidth = new WordWidth(fi, wb.getHyphenText(0, endHyphenIndex)); // Take letter spacing into account wordWidth = new WordWidth(wordWidth.width + textStyle.getLetterSpacing() * (endHyphenIndex - 1), 0); - addWordVestige(area, endHyphenIndex, wordWidth, str.substring(endHyphenIndex)); + addWordVestige(area, endHyphenIndex, wordWidth, str.substring(endHyphenIndex), letterSpacing); } } private void addWordVestige(TextArea area, int vestigeTextLength, WordWidth vestigeWordWidth, - String vestigeString) { - addWord(area, vestigeTextLength, vestigeWordWidth); + String vestigeString, int letterSpacing) { + addWord(area, vestigeTextLength, vestigeWordWidth, letterSpacing); if (vestigeString.length() == 0) { wordVestige = null; } else { @@ -469,8 +470,8 @@ private WordWidth getWordWidth(FontInfo fontInfo, Word word) { return new WordWidth(fontInfo, word.getValue()); } - private void addWord(TextArea textArea, int textLength, WordWidth wordWidth) { - textArea.addWord(textLength, wordWidth); + private void addWord(TextArea textArea, int textLength, WordWidth wordWidth, int letterSpacing) { + textArea.addWord(textLength, wordWidth, letterSpacing); } private void addWord(TextArea textArea, int textLength) {