JRE-10 Ligatures are not working sometimes when characters from multiple scripts are present

ports commit 18b3f575 from JBR 9

port from JBR 11 to JBR 15 (cherry picked from commit c30407cb87)

cherry picked from commit 8c9402b60b
This commit is contained in:
Dmitry Batrak
2018-12-24 14:34:35 +03:00
committed by alexey.ushakov@jetbrains.com
parent 4b56a65236
commit ab4cebe42f
3 changed files with 19 additions and 5 deletions

View File

@@ -2882,6 +2882,11 @@ public class Font implements java.io.Serializable
*/
public static final int LAYOUT_NO_LIMIT_CONTEXT = 4;
/**
* A flag to layoutGlyphVector requesting to disable detection of paired characters
* when splitting text into scripts.
*/
public static final int LAYOUT_NO_PAIRED_CHARS_AT_SCRIPT_SPLIT = 8;
private static void applyTransform(AffineTransform trans, AttributeValues values) {
if (trans == null) {

View File

@@ -360,6 +360,8 @@ public final class GlyphLayout {
init(count);
boolean handlePairedChars = (flags & Font.LAYOUT_NO_PAIRED_CHARS_AT_SCRIPT_SPLIT) == 0;
// need to set after init
// go through the back door for this
if (font.hasLayoutAttributes()) {
@@ -408,7 +410,7 @@ public final class GlyphLayout {
_textRecord.init(text, offset, lim, min, max);
int start = offset;
if (font2D instanceof CompositeFont) {
_scriptRuns.init(text, offset, count); // ??? how to handle 'common' chars
_scriptRuns.init(text, offset, count, handlePairedChars); // ??? how to handle 'common' chars
_fontRuns.init((CompositeFont)font2D, text, offset, lim);
while (_scriptRuns.next()) {
int limit = _scriptRuns.getScriptLimit();
@@ -431,7 +433,7 @@ public final class GlyphLayout {
}
}
} else {
_scriptRuns.init(text, offset, count); // ??? don't worry about 'common' chars
_scriptRuns.init(text, offset, count, handlePairedChars); // ??? don't worry about 'common' chars
while (_scriptRuns.next()) {
int limit = _scriptRuns.getScriptLimit();
int script = _scriptRuns.getScriptCode();

View File

@@ -43,7 +43,7 @@ package sun.font;
* COMMON and INHERITED characters are first, they will be assigned to
* the same script as the following characters.
*
* The iterator will try to match paired punctuation. If it sees an
* The iterator will try (optionally) to match paired punctuation. If it sees an
* opening punctuation character, it will remember the script that
* was assigned to that character, and assign the same script to the
* matching closing punctuation.
@@ -83,6 +83,8 @@ public final class ScriptRun
private int[] stack; // stack used to handle paired punctuation if encountered
private int parenSP;
private boolean handlePairedChars;
public ScriptRun() {
// must call init later or we die.
}
@@ -100,7 +102,11 @@ public final class ScriptRun
init(chars, start, count);
}
public void init(char[] chars, int start, int count)
public void init(char[] chars, int start, int count) {
init(chars, start, count, true);
}
public void init(char[] chars, int start, int count, boolean pairedChars)
{
if (chars == null || start < 0 || count < 0 || count > chars.length - start) {
throw new IllegalArgumentException();
@@ -114,6 +120,7 @@ public final class ScriptRun
scriptLimit = textStart;
scriptCode = Script.INVALID_CODE;
parenSP = 0;
handlePairedChars = pairedChars;
}
/**
@@ -165,7 +172,7 @@ public final class ScriptRun
while ((ch = nextCodePoint()) != DONE) {
int sc = ScriptRunData.getScript(ch);
int pairIndex = sc == Script.COMMON ? getPairIndex(ch) : -1;
int pairIndex = handlePairedChars && sc == Script.COMMON ? getPairIndex(ch) : -1;
// Paired character handling:
//