]> _ Git - cubist_pdf.git/commitdiff
wip #6188 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Sep 2023 09:48:03 +0000 (11:48 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Sep 2023 09:48:03 +0000 (11:48 +0200)
resources/tools/fwstk/.idea/workspace.xml
resources/tools/fwstk/bin/com/fluidbook/fwstk/layout/Word.class
resources/tools/fwstk/out/artifacts/fwstk_jar/fwstk.jar
resources/tools/fwstk/src/com/fluidbook/fwstk/layout/Word.java

index 3c08865693c588dba4f26f3cc40bb255be4e28ba..df6d0b0d900bc39288c75c7607b1c3af4e64c049 100644 (file)
@@ -9,9 +9,7 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="f146bc67-2578-4de3-9db2-94d2d43e9e83" name="Default" comment="wip #5410">
-      <change beforePath="$PROJECT_DIR$/../../../src/PDFTools.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../../src/PDFTools.php" afterDir="false" />
-    </list>
+    <list default="true" id="f146bc67-2578-4de3-9db2-94d2d43e9e83" name="Default" comment="wip #5410" />
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
     <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
       <workItem from="1694189811041" duration="768000" />
       <workItem from="1694545035743" duration="1398000" />
       <workItem from="1694674242867" duration="1038000" />
+      <workItem from="1694683468326" duration="1387000" />
     </task>
     <task id="LOCAL-00001" summary="wip #1111 @0.5">
       <created>1487172253077</created>
index 4539d3bf7ae3f3e3628c5cea31283958b054c498..b20cebd26dd496fdc90675ce3ad6f239fb8b752c 100644 (file)
Binary files a/resources/tools/fwstk/bin/com/fluidbook/fwstk/layout/Word.class and b/resources/tools/fwstk/bin/com/fluidbook/fwstk/layout/Word.class differ
index 72b59930214c8420eeaca9c6f8930bc87b4e1c20..f15916521b12eb645a6239053a0e8e554b390957 100644 (file)
Binary files a/resources/tools/fwstk/out/artifacts/fwstk_jar/fwstk.jar and b/resources/tools/fwstk/out/artifacts/fwstk_jar/fwstk.jar differ
index 080767a199fa829d43aeabab1874a79578a77341..e4e92cf299cf4a606900f0bca83889c2b2567260 100644 (file)
@@ -15,166 +15,171 @@ import java.util.LinkedList;
  */
 public class Word extends LayoutElement {
 
-       float letterspacing = 0.0f;
-       LinkedList<Letter> letters;
-
-       public Word() {
-               letters = new LinkedList<>();
-       }
-
-       public String asJSON(PDRectangle cropbox, float y, float scaleX, float scaleY, float rotation) {
-
-               if (size() == 0) {
-                       return "";
-               }
-               if (round(this.getTotalWidth()) == 0.0f) {
-                       return "";
-               }
-
-               if (startX() < 0 && this.getTotalWidth() <= startX() * -1) {
-                       return "";
-               } else if (y < 0) {
-                       return "";
-               } else if (startX() > cropbox.getWidth()) {
-                       return "";
-               }
-
-               String word = this.asText();
-
-               String rot = "";
-               if (rotation != 0.0f) {
-                       rot = ",\"rotation\":" + round(rotation);
-               }
-               String sx = "";
-               if (scaleX != 1.0f) {
-                       sx = ",\"scaleX\":" + round(scaleX);
-               }
-               String sy = "";
-               if (scaleY != 1.0f) {
-                       sy = ",\"scaleY\":" + round(scaleY);
-               }
-
-               return "{\"word\":\"" + StringUtil.removeAccents(word).toLowerCase() + "\",\"x\":" + round(startX()) + ",\"y\":" + round(letters.get(0).y) + ",\"width\":" + round(this.getTotalWidth()) + ",\"lw\":[" + String.join(",", this.getLettersWidths()) + "],\"height\":" + round(this.getHeight()) + rot + sx + sy + "}";
-       }
-
-       public String asText() {
-               String word = "";
-
-               for (int i = 0; i < letters.size(); i++) {
-                       Letter l = letters.get(i);
-                       word += l.asText();
-               }
-               return word;
-       }
-
-       public String asText(PDRectangle cropbox) {
-               if (startX() > cropbox.getWidth()) {
-                       return "";
-               }
-               return asText();
-       }
-
-       public LinkedList<String> getLettersWidths() {
-               LinkedList<String> lw = new LinkedList<>();
-               for (int i = 0; i < letters.size(); i++) {
-                       Letter l = letters.get(i);
-                       lw.add(String.valueOf(round(l.width)));
-               }
-               return lw;
-       }
-
-       public void addLetter(Letter l) {
-               letters.add(l);
-       }
-
-       public int size() {
-               return letters.size();
-       }
-
-       public float nextPosition() {
-               if (size() == 0) {
-                       return 0.0f;
-               }
-               return letters.get(size() - 1).getNextPosition();
-       }
-
-       public boolean isSpace() {
-               return size() == 1 && letters.get(0).isSpace();
-       }
-
-       public boolean isSeparator() {
-               return size() == 1 && letters.get(0).isSeparator();
-       }
-
-       public float startX() {
-               if (size() == 0) {
-                       return 0.0f;
-               }
-               return letters.get(0).x;
-       }
-
-       public float getTotalWidth() {
-               return nextPosition() - startX();
-       }
-
-       public float getHeight() {
-               float res = 0.0f;
-               for (int i = 0; i < size(); i++) {
-                       res = Math.max(letters.get(i).height, res);
-               }
-               return res;
-       }
-
-       public float getCharsWidth() {
-               float res = 0.0f;
-               for (int i = 0; i < size(); i++) {
-                       res += letters.get(i).width;
-               }
-               return res;
-       }
-
-       public float getLetterSpacing() {
-               return (getTotalWidth() - getCharsWidth()) / ((float) size());
-       }
-
-       protected float getMinWidth() {
-               float res = Float.MAX_VALUE;
-               for (int i = 0; i < size(); i++) {
-                       res = Math.min(letters.get(i).width, res);
-               }
-               return res;
-       }
-
-       public boolean goodCandidate(Letter l, float spaceWidth, float rotation) {
-               // Si le mot est vide, la nouvelle lettre est toujours une bonne candidate
-               if (size() == 0 && !l.isSeparator()) {
-                       return true;
-               }
-               // Si on tombe sur un espace, on ferme forcément le mot
-               if (l.isSeparator()) {
-                       return false;
-               }
-
-               // Sinon, on va tester la marge entre le dernier caractère est le candidat
-               float offset = round(l.x - nextPosition());
-               float minWidth = Math.min(l.width, Math.min(spaceWidth, getMinWidth()));
-
-               if (offset < 0.0f) {
-                       if (size() > 0 && l.x <= letters.getLast().x) {
-                               // Si la lettre que l'on tente d'insérer débute avant ou sur le 
-                               // caractère précédent, on change de mot pour permettre la 
-                               // superposition
-                               return false;
-                       } else {
-                               // Si la différence est négative, à priori, on a une marge plus faible.
-                               // On va ajouter cette lettre au mot, et les largeurs seront ajustées
-                               // par le letterSpacing moyen
-                               return true;
-                       }
-               } else if (offset > minWidth * 0.75f) {
-                       return false;
-               }
-
-               return true;
-       }
+    float letterspacing = 0.0f;
+    LinkedList<Letter> letters;
+
+    static int order = 0;
+
+    public Word() {
+        letters = new LinkedList<>();
+    }
+
+    public String asJSON(PDRectangle cropbox, float y, float scaleX, float scaleY, float rotation) {
+
+        if (size() == 0) {
+            return "";
+        }
+        if (round(this.getTotalWidth()) == 0.0f) {
+            return "";
+        }
+
+        if (startX() < 0 && this.getTotalWidth() <= startX() * -1) {
+            return "";
+        } else if (y < 0) {
+            return "";
+        } else if (startX() > cropbox.getWidth()) {
+            return "";
+        }
+
+        String word = this.asText();
+
+        String rot = "";
+        if (rotation != 0.0f) {
+            rot = ",\"rotation\":" + round(rotation);
+        }
+        String sx = "";
+        if (scaleX != 1.0f) {
+            sx = ",\"scaleX\":" + round(scaleX);
+        }
+        String sy = "";
+        if (scaleY != 1.0f) {
+            sy = ",\"scaleY\":" + round(scaleY);
+        }
+        String w = StringUtil.removeAccents(word).toLowerCase();
+        if (!StringUtil.removeSpaces(StringUtil.removePoints(w)).isEmpty()) {
+            order++;
+        }
+        return "{\"o\":" + order + ",\"word\":\"" + w + "\",\"x\":" + round(startX()) + ",\"y\":" + round(letters.get(0).y) + ",\"width\":" + round(this.getTotalWidth()) + ",\"lw\":[" + String.join(",", this.getLettersWidths()) + "],\"height\":" + round(this.getHeight()) + rot + sx + sy + "}";
+    }
+
+    public String asText() {
+        String word = "";
+
+        for (int i = 0; i < letters.size(); i++) {
+            Letter l = letters.get(i);
+            word += l.asText();
+        }
+        return word;
+    }
+
+    public String asText(PDRectangle cropbox) {
+        if (startX() > cropbox.getWidth()) {
+            return "";
+        }
+        return asText();
+    }
+
+    public LinkedList<String> getLettersWidths() {
+        LinkedList<String> lw = new LinkedList<>();
+        for (int i = 0; i < letters.size(); i++) {
+            Letter l = letters.get(i);
+            lw.add(String.valueOf(round(l.width)));
+        }
+        return lw;
+    }
+
+    public void addLetter(Letter l) {
+        letters.add(l);
+    }
+
+    public int size() {
+        return letters.size();
+    }
+
+    public float nextPosition() {
+        if (size() == 0) {
+            return 0.0f;
+        }
+        return letters.get(size() - 1).getNextPosition();
+    }
+
+    public boolean isSpace() {
+        return size() == 1 && letters.get(0).isSpace();
+    }
+
+    public boolean isSeparator() {
+        return size() == 1 && letters.get(0).isSeparator();
+    }
+
+    public float startX() {
+        if (size() == 0) {
+            return 0.0f;
+        }
+        return letters.get(0).x;
+    }
+
+    public float getTotalWidth() {
+        return nextPosition() - startX();
+    }
+
+    public float getHeight() {
+        float res = 0.0f;
+        for (int i = 0; i < size(); i++) {
+            res = Math.max(letters.get(i).height, res);
+        }
+        return res;
+    }
+
+    public float getCharsWidth() {
+        float res = 0.0f;
+        for (int i = 0; i < size(); i++) {
+            res += letters.get(i).width;
+        }
+        return res;
+    }
+
+    public float getLetterSpacing() {
+        return (getTotalWidth() - getCharsWidth()) / ((float) size());
+    }
+
+    protected float getMinWidth() {
+        float res = Float.MAX_VALUE;
+        for (int i = 0; i < size(); i++) {
+            res = Math.min(letters.get(i).width, res);
+        }
+        return res;
+    }
+
+    public boolean goodCandidate(Letter l, float spaceWidth, float rotation) {
+        // Si le mot est vide, la nouvelle lettre est toujours une bonne candidate
+        if (size() == 0 && !l.isSeparator()) {
+            return true;
+        }
+        // Si on tombe sur un espace, on ferme forcément le mot
+        if (l.isSeparator()) {
+            return false;
+        }
+
+        // Sinon, on va tester la marge entre le dernier caractère est le candidat
+        float offset = round(l.x - nextPosition());
+        float minWidth = Math.min(l.width, Math.min(spaceWidth, getMinWidth()));
+
+        if (offset < 0.0f) {
+            if (size() > 0 && l.x <= letters.getLast().x) {
+                // Si la lettre que l'on tente d'insérer débute avant ou sur le
+                // caractère précédent, on change de mot pour permettre la
+                // superposition
+                return false;
+            } else {
+                // Si la différence est négative, à priori, on a une marge plus faible.
+                // On va ajouter cette lettre au mot, et les largeurs seront ajustées
+                // par le letterSpacing moyen
+                return true;
+            }
+        } else if (offset > minWidth * 0.75f) {
+            return false;
+        }
+
+        return true;
+    }
 }