From: Simon Steiner Date: Thu, 20 Jul 2023 09:24:41 +0000 (+0100) Subject: FOP-3139: Add support for font-selection-strategy=character-by-character X-Git-Tag: 2_9~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b16022ece329197f72f47943085d45b56e26806e;p=xmlgraphics-fop.git FOP-3139: Add support for font-selection-strategy=character-by-character --- diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java index 57f790912..f44bd7bc0 100644 --- a/fop-core/src/main/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java +++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java @@ -781,6 +781,8 @@ public class TextLayoutManager extends LeafNodeLayoutManager { int level = -1; int prevLevel = -1; boolean retainControls = false; + Font lastFont = null; + int lastFontPos = -1; while (nextStart < foText.length()) { ch = foText.charAt(nextStart); level = foText.bidiLevelAt(nextStart); @@ -813,10 +815,22 @@ public class TextLayoutManager extends LeafNodeLayoutManager { + "}"); } if (inWord) { - if (breakOpportunity - || GlyphMapping.isSpace(ch) - || CharUtilities.isExplicitBreak(ch) - || ((prevLevel != -1) && (level != prevLevel))) { + boolean processWord = breakOpportunity + || GlyphMapping.isSpace(ch) + || CharUtilities.isExplicitBreak(ch) + || ((prevLevel != -1) && (level != prevLevel)); + if (!processWord && foText.getCommonFont().getFontSelectionStrategy() == EN_CHARACTER_BY_CHARACTER) { + if (lastFont == null || lastFontPos != nextStart - 1) { + lastFont = FontSelector.selectFontForCharactersInText( + foText, nextStart - 1, nextStart, foText, this); + } + Font font = FontSelector.selectFontForCharactersInText( + foText, nextStart, nextStart + 1, foText, this); + processWord = font != lastFont; + lastFont = font; + lastFontPos = nextStart; + } + if (processWord) { // this.foText.charAt(lastIndex) == CharUtilities.SOFT_HYPHEN prevMapping = processWord(alignment, sequence, prevMapping, ch, breakOpportunity, true, prevLevel, retainControls); diff --git a/fop/test/layoutengine/standard-testcases/block_font-character-by-character.xml b/fop/test/layoutengine/standard-testcases/block_font-character-by-character.xml new file mode 100644 index 000000000..507a98975 --- /dev/null +++ b/fop/test/layoutengine/standard-testcases/block_font-character-by-character.xml @@ -0,0 +1,57 @@ + + + + + +

+ This test checks the font character-by-character selection. +

+
+ + + + + + + + + + font-family not given + this text contains a ∑ symbol in the middle + mixed contents should be + ∑∑text + ∑∑∑∑text + ∑∑∑∑sym + + + + + + + + + + + + + + + + + +