]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3078: Fix position of macron glyph
authorSimon Steiner <ssteiner@apache.org>
Thu, 16 Jun 2022 15:38:26 +0000 (15:38 +0000)
committerSimon Steiner <ssteiner@apache.org>
Thu, 16 Jun 2022 15:38:26 +0000 (15:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1901980 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/complexscripts/scripts/DefaultScriptProcessor.java
fop-core/src/test/java/org/apache/fop/complexscripts/scripts/DefaultScriptTestCase.java

index 0de1a2058c7566cac51d0d10f71a1a227a006625..0dcde599b2e086ed61fc31374f9e20333d5137a6 100644 (file)
@@ -103,45 +103,29 @@ public class DefaultScriptProcessor extends ScriptProcessor {
             CharAssociation ba = null;
             int bg = -1;
             int[] bpa = null;
+            int[] order = new int[ng];
             for (int i = 0; i < ng; i++) {
-                int gid = ga [ i ];
-                int[] pa = (gpa != null) ? gpa [ i ] : null;
-                CharAssociation ca = aa [ i ];
+                order[i] = i;
+            }
+            for (int i = 1; i < ng; i++) {
+                int[] pa = (gpa != null) ? gpa[i] : null;
                 if (isReorderedMark(gdef, ga, unscaledWidths, i, pa)) {
-                    nga [ k ] = gid;
-                    naa [ k ] = ca;
-                    if (npa != null) {
-                        npa [ k ] = pa;
-                    }
-                    k++;
-                } else {
-                    if (bg != -1) {
-                        nga [ k ] = bg;
-                        naa [ k ] = ba;
-                        if (npa != null) {
-                            npa [ k ] = bpa;
+                    for (int j = i; j > 0; j--) {
+                        switchGlyphs(order, j);
+                        int[] paj = (gpa != null) ? gpa[order[j]] : null;
+                        if (!isMarkNotReordered(gdef, ga, order[j], paj)) {
+                            break;
                         }
-                        k++;
-                        bg = -1;
-                        ba = null;
-                        bpa = null;
-                    }
-                    if (bg == -1) {
-                        bg = gid;
-                        ba = ca;
-                        bpa = pa;
                     }
                 }
             }
-            if (bg != -1) {
-                nga [ k ] = bg;
-                naa [ k ] = ba;
-                if (npa != null) {
-                    npa [ k ] = bpa;
+            for (int i = 0; i < ng; i++) {
+                nga[i] = ga[order[i]];
+                naa[i] = aa[order[i]];
+                if (gpa != null) {
+                    npa[i] = gpa[order[i]];
                 }
-                k++;
             }
-            assert k == ng;
             if (npa != null) {
                 System.arraycopy(npa, 0, gpa, 0, ng);
             }
@@ -151,9 +135,22 @@ public class DefaultScriptProcessor extends ScriptProcessor {
         }
     }
 
+    private static void switchGlyphs(int[] order, int i) {
+        if (i < 1) {
+            throw new IllegalArgumentException(i + " must be > 0");
+        }
+        int oi = order[i];
+        order[i] = order[i - 1];
+        order[i - 1] = oi;
+    }
+
     protected boolean isReorderedMark(GlyphDefinitionTable gdef, int[] glyphs, int[] unscaledWidths, int index, int[] pa) {
         pa = (pa != null) ? pa : new int[1];
         return gdef.isGlyphClass(glyphs[index], GlyphDefinitionTable.GLYPH_CLASS_MARK) && pa[0] != 0;
     }
 
+    private boolean isMarkNotReordered(GlyphDefinitionTable gdef, int[] glyphs, int index, int[] pa) {
+        pa = (pa != null) ? pa : new int[1];
+        return gdef.isGlyphClass(glyphs[index], GlyphDefinitionTable.GLYPH_CLASS_MARK) && pa[0] == 0;
+    }
 }
index ba4ddf5549b7325f0e6e56a5793e105750eb4e9d..a7fec3b4eb02d3e7c3d129d135445cfc3b3e190b 100644 (file)
@@ -54,11 +54,14 @@ public class DefaultScriptTestCase {
 
     @Test
     public void testProcessorReorder2() {
-        String in = "\u00F6\u0323";
-        int[][] gpa = new int[2][2];
-        gpa[1][1] = 1;
+        String in = "S\u0323\u0323;";
+        int[][] gpa = new int[4][1];
+        gpa[2][0] = 1;
         String actual = getFont().reorderCombiningMarks(in, gpa, OTFScript.DEFAULT, null, null).toString();
-        Assert.assertEquals(actual.charAt(0), 57344);
+        Assert.assertEquals(actual.charAt(0), 803);
+        Assert.assertEquals(actual.charAt(1), 57344);
+        Assert.assertEquals(actual.charAt(2), 803);
+        Assert.assertEquals(actual.charAt(3), 57344);
     }
 
     private MultiByteFont getFont() {