You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Toparvion (via GitHub)" <gi...@apache.org> on 2023/01/23 00:56:57 UTC

[GitHub] [pdfbox] Toparvion commented on a diff in pull request #153: PDFBOX-4189: Add a method to get GSUB data for specific script tag

Toparvion commented on code in PR #153:
URL: https://github.com/apache/pdfbox/pull/153#discussion_r1083583024


##########
fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java:
##########
@@ -701,6 +703,42 @@ public GsubData getGsubData()
         return gsubData;
     }
 
+    /**
+     * Builds a new {@link GsubData} instance for given script tag. In contrast to neighbour
+     * {@link #getGsubData()} method, this one does not try to find the first supported language
+     * and load GSUB data for it. Instead, it fetches the data for the given {@code scriptTag} (if
+     * it's supported by the font) leaving the language unspecified. It means that even after
+     * successful reading of GSUB data, the actual glyph substitution may not work if there is no
+     * corresponding {@link GsubWorker} implementation for it.
+     *
+     * @implNote This method performs searching on every invocation (no results are cached)
+     * @param scriptTag
+     * a <a href="https://learn.microsoft.com/en-us/typography/opentype/spec/scripttags">script
+     * tag</a> for which the data is needed
+     * @return GSUB data for the given script or {@code null} if no such script in the font
+     */
+    public GsubData getGsubData(String scriptTag)
+    {
+        ScriptTable scriptTable = scriptList.get(scriptTag);
+        if (scriptTable == null)
+        {
+            return null;

Review Comment:
   It could seem reasonable to align this behavior with the sibling method and return `GsubData.NO_DATA_FOUND` from here, but I find it confusable for the user because without thorough reading of JavaDoc (which is normal) it would be hard to understand than the returned result is actually "no result", while with `null` it is definitely clear.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org