You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/04/29 09:50:52 UTC
svn commit: r1830499 - in /pdfbox/trunk:
examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
examples/src/main/resources/org/apache/pdfbox/resources/ttf/
fontbox/src/main/java/org/apache/fontbox/ttf/gsub/
fontbox/src/test/java/org/apache/fontbox...
Author: tilman
Date: Sun Apr 29 09:50:52 2018
New Revision: 1830499
URL: http://svn.apache.org/viewvc?rev=1830499&view=rev
Log:
PDFBOX-4189: Bengali fix for GSUB: ja phala not rendering properly, by Palash Ray
Added:
pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/ttf/bengali-samples.txt (with props)
pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GSUBTableDebugger.java (with props)
pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/gsub/GSUBTablePrintUtil.java (with props)
Modified:
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/BengaliPdfGenerationHelloWorld.java
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GlyphSubstitutionDataExtractor.java
pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GsubWorkerForBengali.java
pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyphSubstitutionTableTest.java
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/BengaliPdfGenerationHelloWorld.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/BengaliPdfGenerationHelloWorld.java?rev=1830499&r1=1830498&r2=1830499&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/BengaliPdfGenerationHelloWorld.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/BengaliPdfGenerationHelloWorld.java Sun Apr 29 09:50:52 2018
@@ -17,39 +17,37 @@
package org.apache.pdfbox.examples.pdmodel;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
-import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
/**
* Inspired from <a href=
* "https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java?view=markup">PdfBox
- * Example</a>. This attempts to correctly demonstrate to what extent Bengali text rendering is
- * supported. First, we render some text, and then embed an image with the correct text displayed on
- * the next page.
+ * Example</a>. This attempts to correctly demonstrate to what extent Bengali text rendering is supported. First, we
+ * render some text, and then embed an image with the correct text displayed on the next page.
*
* @author Palash Ray
*
*/
public class BengaliPdfGenerationHelloWorld
{
- /**
- * The unicode of this is given below:
- *
- * <pre>
- * \u0986\u09ae\u09bf \u0995\u09cb\u09a8 \u09aa\u09a5\u09c7 \u0995\u09cd\u09b7\u09c0\u09b0\u09c7\u09b0 \u09b7\u09a8\u09cd\u09a1 \u09aa\u09c1\u09a4\u09c1\u09b2 \u09b0\u09c1\u09aa\u09cb \u0997\u0999\u09cd\u0997\u09be \u098b\u09b7\u09bf
- * </pre>
- *
- */
- private static final String BANGLA_TEXT_1 = "à¦à¦®à¦¿ à¦à§à¦¨ পথৠà¦à§à¦·à§à¦°à§à¦° লà¦à§à¦·à§à¦®à§ ষনà§à¦¡ পà§à¦¤à§à¦² রà§à¦ªà§ à¦à¦à§à¦à¦¾ à¦à¦·à¦¿";
- private static final String BANGLA_TEXT_2 = "দà§à¦°à§à¦¤ à¦à¦¾à¦¢à¦¼ শà§à¦¯à¦¼à¦¾à¦² à¦
লস à¦à§à¦à§à¦° à¦à§à¦¡à¦¼à§ à¦à¦¾à¦®à§à¦ª ধà§à¦°à§à¦¤ হঠাৠà¦à¦¾à¦à§à¦¨à¦¿ মà§à¦²à¦¿à¦ à¦à¦¶à¦¿ দà§";
- private static final String BANGLA_TEXT_3 = "à¦à¦·à¦¿ à¦à¦²à§à¦²à§à¦² বà§à¦¯à¦¾à¦¸ নিরà§à¦à§ ";
+ private static final int LINE_GAP = 5;
+ private static final String LOHIT_BENGALI_TTF = "/org/apache/pdfbox/resources/ttf/Lohit-Bengali.ttf";
+ private static final String TEXT_SOURCE_FILE = "/org/apache/pdfbox/resources/ttf/bengali-samples.txt";
+ private static final int FONT_SIZE = 20;
+ private static final int MARGIN = 20;
static
{
@@ -66,7 +64,7 @@ public class BengaliPdfGenerationHelloWo
}
private BengaliPdfGenerationHelloWorld()
- {
+ {
}
public static void main(String[] args) throws IOException, URISyntaxException
@@ -84,36 +82,139 @@ public class BengaliPdfGenerationHelloWo
try (PDDocument doc = new PDDocument())
{
- PDPage page1 = new PDPage();
- doc.addPage(page1);
-
- PDFont font = PDType0Font.load(doc, BengaliPdfGenerationHelloWorld.class
- .getResourceAsStream("/org/apache/pdfbox/resources/ttf/Lohit-Bengali.ttf"),
+ PDFont font = PDType0Font.load(doc,
+ BengaliPdfGenerationHelloWorld.class.getResourceAsStream(LOHIT_BENGALI_TTF),
true);
+ PDRectangle rectangle = getPageSize();
+ float workablePageWidth = rectangle.getWidth() - 2 * MARGIN;
+ float workablePageHeight = rectangle.getHeight() - 2 * MARGIN;
+
+ List<List<String>> pagedTexts = getReAlignedTextBasedOnPageHeight(
+ getReAlignedTextBasedOnPageWidth(getBengaliTextFromFile(), font,
+ workablePageWidth),
+ font, workablePageHeight);
- try (PDPageContentStream contents = new PDPageContentStream(doc, page1))
+ for (List<String> linesForPage : pagedTexts)
{
- contents.beginText();
- contents.setFont(font, 12);
- contents.newLineAtOffset(10, 750);
- contents.showText(BANGLA_TEXT_1);
- contents.newLineAtOffset(0, -50);
- contents.showText(BANGLA_TEXT_2);
- contents.newLineAtOffset(0, -30);
- contents.showText(BANGLA_TEXT_3);
- contents.endText();
-
- PDImageXObject pdImage = PDImageXObject
- .createFromFile(BengaliPdfGenerationHelloWorld.class
- .getResource(
- "/org/apache/pdfbox/resources/ttf/bengali-correct-text.png")
- // getFile() doesn't work if there is a space in the path
- .toURI().getPath(), doc);
- contents.drawImage(pdImage, 0, 300, pdImage.getWidth(), pdImage.getHeight());
+ PDPage page = new PDPage(getPageSize());
+ doc.addPage(page);
+
+ try (PDPageContentStream contents = new PDPageContentStream(doc, page))
+ {
+ contents.beginText();
+ contents.setFont(font, FONT_SIZE);
+ contents.newLineAtOffset(rectangle.getLowerLeftX() + MARGIN,
+ rectangle.getUpperRightY() - MARGIN);
+
+ for (String line : linesForPage)
+ {
+ contents.showText(line);
+ contents.newLineAtOffset(0, -(FONT_SIZE + LINE_GAP));
+ }
+
+ contents.endText();
+
+ }
}
doc.save(filename);
}
}
+ private static List<List<String>> getReAlignedTextBasedOnPageHeight(List<String> originalLines,
+ PDFont font, float workablePageHeight)
+ {
+ final float newLineHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000
+ * FONT_SIZE + LINE_GAP;
+ List<List<String>> realignedTexts = new ArrayList<>();
+ float consumedHeight = 0;
+ List<String> linesInAPage = new ArrayList<>();
+ for (String line : originalLines)
+ {
+ if (newLineHeight + consumedHeight < workablePageHeight)
+ {
+ consumedHeight += newLineHeight;
+ }
+ else
+ {
+ consumedHeight = newLineHeight;
+ realignedTexts.add(linesInAPage);
+ linesInAPage = new ArrayList<>();
+ }
+
+ linesInAPage.add(line);
+ }
+ return realignedTexts;
+ }
+
+ private static List<String> getReAlignedTextBasedOnPageWidth(List<String> originalLines,
+ PDFont font, float workablePageWidth) throws IOException
+ {
+ List<String> uniformlyWideTexts = new ArrayList<>();
+ float consumedWidth = 0;
+ StringBuilder sb = new StringBuilder();
+ for (String line : originalLines)
+ {
+ float newTokenWidth = 0;
+ StringTokenizer st = new StringTokenizer(line, " ", true);
+ while (st.hasMoreElements())
+ {
+ String token = st.nextToken();
+ newTokenWidth = font.getStringWidth(token) / 1000 * FONT_SIZE;
+ if (newTokenWidth + consumedWidth < workablePageWidth)
+ {
+ consumedWidth += newTokenWidth;
+ }
+ else
+ {
+ // add a new text chunk
+ uniformlyWideTexts.add(sb.toString());
+ consumedWidth = newTokenWidth;
+ sb = new StringBuilder();
+ }
+
+ sb.append(token);
+ }
+
+ // add a new text chunk
+ uniformlyWideTexts.add(sb.toString());
+ consumedWidth = newTokenWidth;
+ sb = new StringBuilder();
+ }
+
+ return uniformlyWideTexts;
+ }
+
+ private static PDRectangle getPageSize()
+ {
+ return PDRectangle.A4;
+ }
+
+ private static List<String> getBengaliTextFromFile() throws IOException
+ {
+ List<String> lines = new ArrayList<>();
+
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(
+ BengaliPdfGenerationHelloWorld.class.getResourceAsStream(TEXT_SOURCE_FILE)));)
+ {
+ while (true)
+ {
+ String line = br.readLine();
+
+ if (line == null)
+ {
+ break;
+ }
+
+ if (line.startsWith("#"))
+ {
+ continue;
+ }
+ lines.add(line);
+ }
+ }
+
+ return lines;
+ }
+
}
Added: pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/ttf/bengali-samples.txt
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/ttf/bengali-samples.txt?rev=1830499&view=auto
==============================================================================
--- pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/ttf/bengali-samples.txt (added)
+++ pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/ttf/bengali-samples.txt Sun Apr 29 09:50:52 2018
@@ -0,0 +1,105 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# NOTE: This file contains bengali text, and is used for testing the correctness of PDF generation
+# using the Gsub system, specially rendering of compound characters
+#
+
+
+দà§à¦ বিà¦à¦¾ à¦à¦®à¦¿
+
+শà§à¦§à§ বিà¦à§ দà§à¦ à¦à¦¿à¦² মà§à¦° à¦à§à¦à¦ à¦à¦° সবঠà¦à§à¦à§ à¦à¦£à§à¥¤
+বাবৠবলিলà§à¦¨ , â বà§à¦à§à¦ à¦à¦ªà§à¦¨ , ঠà¦à¦®à¦¿ লà¦à¦¬ à¦à¦¿à¦¨à§à¥¤ '
+à¦à¦¹à¦¿à¦²à¦¾à¦® à¦à¦®à¦¿ , â তà§à¦®à¦¿ à¦à§à¦¸à§à¦¬à¦¾à¦®à§ , à¦à§à¦®à¦¿à¦° à¦
নà§à¦¤ নাà¦à¥¤
+à¦à§à§à§ দà§à¦à§ মà§à¦° à¦à¦à§ বà§à§ - à¦à§à¦° মরিবার মতৠঠাà¦à¦à¥¤ '
+শà§à¦¨à¦¿ রাà¦à¦¾ à¦à¦¹à§ , â বাপৠ, à¦à¦¾à¦¨à§ তৠহৠ, à¦à¦°à§à¦à¦¿ বাà¦à¦¾à¦¨à¦à¦¾à¦¨à¦¾
+পà§à¦²à§ দà§à¦ বিà¦à§ পà§à¦°à¦¸à§à¦¥ ঠদিà¦à§ সমান হà¦à¦¬à§ à¦à¦¾à¦¨à¦¾ â
+à¦à¦à¦¾ দিতৠহবà§à¥¤ ' à¦à¦¹à¦¿à¦²à¦¾à¦® তবৠবà¦à§à¦·à§ à¦à§à§à¦¿à§à¦¾ পাণি
+সà¦à¦² à¦à¦à§à¦·à§ , â à¦à¦°à§à¦£ রà¦à§à¦·à§ à¦à¦°à¦¿à¦¬à§à¦° à¦à¦¿à¦à§à¦à¦¾à¦¨à¦¿ ।
+সপà§à¦¤ পà§à¦°à§à¦· যà§à¦¥à¦¾à§ মানà§à¦· সৠমাà¦à¦¿ সà§à¦¨à¦¾à¦° বাà§à¦¾ ,
+দà§à¦¨à§à¦¯à§à¦° দাà§à§ বà§à¦à¦¿à¦¬ সৠমাà§à§ à¦à¦®à¦¨à¦¿ লà¦à§à¦·à§à¦®à§à¦à¦¾à§à¦¾ ! '
+à¦à¦à¦à¦¿ à¦à¦°à¦¿ লাল রাà¦à¦¾ à¦à§à¦·à¦£à¦à¦¾à¦² রহিল মà§à¦¨à¦à¦¾à¦¬à§ ,
+à¦à¦¹à¦¿à¦²à§à¦¨ শà§à¦·à§ à¦à§à¦°à§à¦° হাসি হà§à¦¸à§ , â à¦à¦à§à¦à¦¾ , সৠদà§à¦à¦¾ যাবà§à¥¤ '
+
+পরৠমাস দà§à§à§ à¦à¦¿à¦à§ মাà¦à¦¿ à¦à§à§à§ বাহির হà¦à¦¨à§ পথৠâ
+à¦à¦°à¦¿à¦² ডিà¦à§à¦°à¦¿ , সà¦à¦²à¦ বিà¦à§à¦°à¦¿ মিথà§à¦¯à¦¾ দà§à¦¨à¦¾à¦° à¦à¦¤à§à¥¤
+ঠà¦à¦à¦¤à§ , হাৠ, সà§à¦ বà§à¦¶à¦¿ à¦à¦¾à§ à¦à¦à§ যার à¦à§à¦°à¦¿ à¦à§à¦°à¦¿ â
+রাà¦à¦¾à¦° হসà§à¦¤ à¦à¦°à§ সমসà§à¦¤ à¦à¦¾à¦à¦¾à¦²à§à¦° ধন à¦à§à¦°à¦¿à¥¤
+মনৠà¦à¦¾à¦¬à¦¿à¦²à¦¾à¦® মà§à¦°à§ à¦à¦à¦¬à¦¾à¦¨ রাà¦à¦¿à¦¬à§ না মà§à¦¹à¦à¦°à§à¦¤à§ ,
+তাঠলিà¦à¦¿ দিল বিশà§à¦¬à¦¨à¦¿à¦à¦¿à¦² দৠবিà¦à¦¾à¦° পরিবরà§à¦¤à§ ।
+সনà§à¦¨à§à¦¯à¦¾à¦¸à§à¦¬à§à¦¶à§ ফিরি দà§à¦¶à§ দà§à¦¶à§ হà¦à§à¦¾ সাধà§à¦° শিষà§à¦¯
+à¦à¦¤ হà§à¦°à¦¿à¦²à¦¾à¦® মনà§à¦¹à¦° ধাম , à¦à¦¤ মনà§à¦°à¦® দà§à¦¶à§à¦¯ !
+à¦à§à¦§à¦°à§ সাà¦à¦°à§ বিà¦à¦¨à§ নà¦à¦°à§ যà¦à¦¨ যà§à¦à¦¾à¦¨à§ à¦à§à¦°à¦®à¦¿
+তবৠনিশিদিনৠà¦à§à¦²à¦¿à¦¤à§ পারি নৠসà§à¦ দà§à¦ বিà¦à¦¾ à¦à¦®à¦¿à¥¤
+হাà¦à§ মাঠৠবাà¦à§ à¦à¦ মতৠà¦à¦¾à¦à§ বà¦à¦° পনà§à¦°à§ - ষà§à¦²à§ â
+à¦à¦à¦¦à¦¿à¦¨ শà§à¦·à§ ফিরিবারৠদà§à¦¶à§ বà§à¦ বাসনা হল।
+
+নমà§à¦¨à¦®à§ নম সà§à¦¨à§à¦¦à¦°à§ মম à¦à¦¨à¦¨à§ বà¦à§à¦à¦à§à¦®à¦¿ !
+à¦à¦à§à¦à¦¾à¦° তà§à¦° সà§à¦¨à¦¿à¦à§à¦§ সমà§à¦° , à¦à§à¦¬à¦¨ à¦à§à§à¦¾à¦²à§ তà§à¦®à¦¿à¥¤
+à¦
বারিত মাঠ, à¦à¦à¦¨à¦²à¦²à¦¾à¦ à¦à§à¦®à§ তব পদধà§à¦²à¦¿ ,
+à¦à¦¾à§à¦¾à¦¸à§à¦¨à¦¿à¦¬à¦¿à§ শানà§à¦¤à¦¿à¦° নà§à§ à¦à§à¦à§ à¦à§à¦à§ à¦à§à¦°à¦¾à¦®à¦à§à¦²à¦¿à¥¤
+
+পলà§à¦²à¦¬à¦à¦¨ à¦à¦®à§à¦°à¦à¦¾à¦¨à¦¨ রাà¦à¦¾à¦²à§à¦° à¦à§à¦²à¦¾à¦à§à¦¹ ,
+সà§à¦¤à¦¬à§à¦§ à¦
তল দিà¦à¦¿ à¦à¦¾à¦²à§à¦à¦² â নিশà§à¦¥à¦¶à§à¦¤à¦² সà§à¦¨à§à¦¹à¥¤
+বà§à¦à¦à¦°à¦¾ মধৠবà¦à§à¦à§à¦° বধৠà¦à¦² লà§à§ যাৠà¦à¦°à§ â
+
+মা বলিতৠপà§à¦°à¦¾à¦£ à¦à¦°à§ à¦à¦¨à¦à¦¾à¦¨ , à¦à§à¦à§ à¦à¦¸à§ à¦à¦² à¦à¦°à§à¥¤
+দà§à¦ দিন পরৠদà§à¦¬à¦¿à¦¤à§à§ পà§à¦°à¦¹à¦°à§ পà§à¦°à¦¬à§à¦¶à¦¿à¦¨à§ নিà¦à¦à§à¦°à¦¾à¦®à§ â
+à¦à§à¦®à§à¦°à§à¦° বাà§à¦¿ দà¦à§à¦·à¦¿à¦£à§ à¦à¦¾à§à¦¿ রথতলা à¦à¦°à¦¿ বামৠ,
+রাà¦à¦¿ হাà¦à¦à§à¦²à¦¾ , ননà§à¦¦à§à¦° à¦à§à¦²à¦¾ , মনà§à¦¦à¦¿à¦° à¦à¦°à¦¿ পাà¦à§
+তà§à¦·à¦¾à¦¤à§à¦° শà§à¦·à§ পà¦à¦¹à§à¦à¦¿à¦¨à§ à¦à¦¸à§ à¦à¦®à¦¾à¦° বাà§à¦¿à¦° à¦à¦¾à¦à§ ।
+
+ধিà¦à§â ধিà¦à§â à¦à¦°à§ , শতধিà¦à§â তà§à¦°à§ , নিলাঠà¦à§à¦²à¦à¦¾ à¦à§à¦®à¦¿ !
+যà¦à¦¨à¦¿ যাহার তà¦à¦¨à¦¿ তাহার , à¦à¦ à¦à¦¿ à¦à¦¨à¦¨à§ তà§à¦®à¦¿ !
+সৠà¦à¦¿ মনৠহবৠà¦à¦à¦¦à¦¿à¦¨ যবৠà¦à¦¿à¦²à§ দরিদà§à¦°à¦®à¦¾à¦¤à¦¾
+à¦à¦à¦à¦² à¦à¦°à¦¿à§à¦¾ রাà¦à¦¿à¦¤à§ ধরিà§à¦¾ ফল ফà§à¦² শাঠপাতা !
+à¦à¦ à¦à§à¦¨à§â রà§à¦¤à§ à¦à¦¾à¦°à§ à¦à§à¦²à¦¾à¦à¦¤à§ ধরà§à¦ বিলাসবà§à¦¶ â
+পাà¦à¦à¦°à¦à¦¾ পাতা à¦
à¦à§à¦à¦²à§ à¦à¦¾à¦à¦¥à¦¾ , পà§à¦·à§à¦ªà§ à¦à¦à¦¿à¦¤ à¦à§à¦¶ !
+à¦à¦®à¦¿ তà§à¦° লাà¦à¦¿ ফিরà§à¦à¦¿ বিবাà¦à¦¿ à¦à§à¦¹à¦¹à¦¾à¦°à¦¾ সà§à¦à¦¹à§à¦¨ â
+তà§à¦ হà§à¦¥à¦¾ বসি à¦à¦°à§ রাà¦à§à¦·à¦¸à§ , হাসিà§à¦¾ à¦à¦¾à¦à¦¾à¦¸ দিন !
+ধনà§à¦° à¦à¦¦à¦°à§ à¦à¦°à¦¬ না ধরà§! à¦à¦¤à¦ হà§à§à¦ à¦à¦¿à¦¨à§à¦¨
+à¦à§à¦¨à§à¦à¦¾à¦¨à§ লà§à¦¶ নাহি à¦
বশà§à¦· সà§à¦¦à¦¿à¦¨à§à¦° à¦à§à¦¨à§ à¦à¦¿à¦¹à§à¦¨ !
+à¦à¦²à§à¦¯à¦¾à¦£à¦®à§à§ à¦à¦¿à¦²à§ তà§à¦®à¦¿ à¦
à§à¦¿ , à¦à§à¦·à§à¦§à¦¾à¦¹à¦°à¦¾ সà§à¦§à¦¾à¦°à¦¾à¦¶à¦¿ !
+যত হাসৠà¦à¦ যত à¦à¦°à§ সাঠà¦à¦¿à¦²à§ দà§à¦¬à§ , হলৠদাসà§à¥¤
+
+বিদà§à¦°à§à¦£ হিà§à¦¾ ফিরিà§à¦¾ ফিরিà§à¦¾ à¦à¦¾à¦°à¦¿ দিà¦à§ à¦à§à§à§ দà§à¦à¦¿ â
+পà§à¦°à¦¾à¦à§à¦°à§à¦° à¦à¦¾à¦à§ à¦à¦à¦¨à§ যৠà¦à¦à§ , সà§à¦ à¦à¦®à¦à¦¾à¦ à¦à¦à¦¿ !
+বসি তার তলৠনà§à¦¨à§à¦° à¦à¦²à§ শানà§à¦¤ হà¦à¦² বà§à¦¯à¦¥à¦¾ ,
+à¦à¦à§ à¦à¦à§ মনৠà¦à¦¦à¦¿à¦² সà§à¦®à¦°à¦£à§ বালঠ- à¦à¦¾à¦²à§à¦° à¦à¦¥à¦¾ ।
+সà§à¦ মনৠপà§à§ à¦à§à¦¯à§à¦·à§à¦ à§à¦° à¦à§à§ রাতà§à¦°à§ নাহিà¦à§ à¦à§à¦® ,
+à¦
তি à¦à§à¦°à§ à¦à¦ ি তাà§à¦¾à¦¤à¦¾à§à¦¿ à¦à§à¦à¦¿ à¦à¦® à¦à§à§à¦¾à¦¬à¦¾à¦° ধà§à¦® ।
+সà§à¦ সà§à¦®à¦§à§à¦° সà§à¦¤à¦¬à§à¦§ দà§à¦ªà§à¦° , পাঠশালা - পলাà§à¦¨ â
+à¦à¦¾à¦¬à¦¿à¦²à¦¾à¦® হাৠà¦à¦° à¦à¦¿ à¦à§à¦¥à¦¾à§ ফিরৠপাব সৠà¦à§à¦¬à¦¨ !
+সহসা বাতাস ফà§à¦²à¦¿ à¦à§à¦² শà§à¦¬à¦¾à¦¸ শাà¦à¦¾ দà§à¦²à¦¾à¦à§à¦¾ à¦à¦¾à¦à§ ,
+
+দà§à¦à¦¿ পাà¦à¦¾ ফল লà¦à¦¿à¦² à¦à§à¦¤à¦² à¦à¦®à¦¾à¦° à¦à§à¦²à§à¦° à¦à¦¾à¦à§à¥¤
+à¦à¦¾à¦¬à¦¿à¦²à¦¾à¦® মনৠবà§à¦à¦¿ à¦à¦¤à¦à¦¨à§ à¦à¦®à¦¾à¦°à§ à¦à¦¿à¦¨à¦¿à¦² মাতা ,
+সà§à¦¨à§à¦¹à§à¦° সৠদানৠবহৠসমà§à¦®à¦¾à¦¨à§ বারà§à¦ ঠà§à¦à¦¾à¦¨à§ মাথা।
+
+হà§à¦¨à¦à¦¾à¦²à§ হাৠযমদà§à¦¤ - পà§à¦°à¦¾à§ à¦à§à¦¥à¦¾ হতৠà¦à¦² মালৠ,
+à¦à§à¦à¦à¦¿ - বাà¦à¦§à¦¾ à¦à§à§ সপà§à¦¤à¦® সà§à¦°à§ পাà§à¦¿à¦¤à§ লাà¦à¦¿à¦² à¦à¦¾à¦²à¦¿à¥¤
+à¦à¦¹à¦¿à¦²à¦¾à¦® তবৠ, â à¦à¦®à¦¿ তৠনà§à¦°à¦¬à§ দিà§à§à¦à¦¿ à¦à¦®à¦¾à¦° সব â
+ দà§à¦à¦¿ ফল তার à¦à¦°à¦¿ à¦
ধিà¦à¦¾à¦° , à¦à¦¤ তারি à¦à¦²à¦°à¦¬ ! '
+à¦à¦¿à¦¨à¦¿à¦² না মà§à¦°à§ , নিà§à§ à¦à§à¦² ধরৠà¦à¦¾à¦à¦§à§ তà§à¦²à¦¿ লাঠিà¦à¦¾à¦ â
+বাবৠà¦à¦¿à¦ª হাতৠপারিষদ - সাথৠধরিতà§à¦à¦¿à¦²à§à¦¨ মাà¦à¥¤
+শà§à¦¨à¦¿ বিবরণ à¦à§à¦°à§à¦§à§ তিনি à¦à¦¨ , â মারিà§à¦¾ à¦à¦°à¦¿à¦¬ à¦à§à¦¨ ! '
+বাবৠযত বলৠপারিষদ - দলৠবলৠতার শতà¦à§à¦£à¥¤
+à¦à¦®à¦¿ à¦à¦¹à¦¿à¦²à¦¾à¦® , â শà§à¦§à§ দà§à¦à¦¿ à¦à¦® à¦à¦¿à¦ মাà¦à¦¿ মহাশৠ! '
+বাবৠà¦à¦¹à§ হà§à¦¸à§ , â বà§à¦à¦¾ সাধà§à¦¬à§à¦¶à§ পাà¦à¦¾ à¦à§à¦° à¦
তিশà§à¥¤ '
+à¦à¦®à¦¿ শà§à¦¨à§ হাসি à¦à¦à¦à¦¿à¦à¦²à§ à¦à¦¾à¦¸à¦¿ , à¦à¦ à¦à¦¿à¦² মà§à¦° à¦à¦à§ â
+তà§à¦®à¦¿ মহারাঠসাধৠহলৠà¦à¦ , à¦à¦®à¦¿ à¦à¦ à¦à§à¦° বà¦à§ !
+
Propchange: pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/ttf/bengali-samples.txt
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GlyphSubstitutionDataExtractor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GlyphSubstitutionDataExtractor.java?rev=1830499&r1=1830498&r2=1830499&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GlyphSubstitutionDataExtractor.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GlyphSubstitutionDataExtractor.java Sun Apr 29 09:50:52 2018
@@ -114,15 +114,17 @@ public class GlyphSubstitutionDataExtrac
FeatureRecord featureRecord, LookupListTable lookupListTable)
{
- LOG.debug("*********** extracting GSUB data for the feature: "
- + featureRecord.getFeatureTag());
-
Map<List<Integer>, Integer> glyphSubstitutionMap = new LinkedHashMap<>();
for (int lookupIndex : featureRecord.getFeatureTable().getLookupListIndices())
{
LookupTable lookupTable = lookupListTable.getLookups()[lookupIndex];
extractData(glyphSubstitutionMap, lookupTable);
}
+
+ LOG.debug("*********** extracting GSUB data for the feature: "
+ + featureRecord.getFeatureTag() + ", glyphSubstitutionMap: "
+ + glyphSubstitutionMap);
+
gsubData.put(featureRecord.getFeatureTag(),
Collections.unmodifiableMap(glyphSubstitutionMap));
}
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GsubWorkerForBengali.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GsubWorkerForBengali.java?rev=1830499&r1=1830498&r2=1830499&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GsubWorkerForBengali.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/gsub/GsubWorkerForBengali.java Sun Apr 29 09:50:52 2018
@@ -49,7 +49,7 @@ public class GsubWorkerForBengali implem
* "https://docs.microsoft.com/en-us/typography/script-development/bengali">https://docs.microsoft.com/en-us/typography/script-development/bengali</a>
*/
private static final List<String> FEATURES_IN_ORDER = Arrays.asList("locl", "nukt", "akhn",
- "rphf", "blwf", "half", "pstf", "vatu", "cjct", INIT_FEATURE, "pres", "abvs", "blws",
+ "rphf", "blwf", "pstf", "half", "vatu", "cjct", INIT_FEATURE, "pres", "abvs", "blws",
"psts", "haln", "calt");
private static final char[] BEFORE_HALF_CHARS = new char[] { '\u09BF', '\u09C7', '\u09C8' };
Added: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GSUBTableDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GSUBTableDebugger.java?rev=1830499&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GSUBTableDebugger.java (added)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GSUBTableDebugger.java Sun Apr 29 09:50:52 2018
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fontbox.ttf;
+
+import java.io.IOException;
+
+import org.apache.fontbox.ttf.gsub.GSUBTablePrintUtil;
+import org.apache.fontbox.ttf.model.GsubData;
+import org.junit.Test;
+
+/**
+ * This class is to be used mainly for debugging purposes. Prints the GSUB Feature table for debugging.
+ *
+ * @author Palash Ray
+ */
+public class GSUBTableDebugger
+{
+
+ private static final String LOHIT_BENGALI_FONT_FILE = "/ttf/Lohit-Bengali.ttf";
+
+ @Test
+ public void printLohitBengaliTTF() throws IOException
+ {
+ MemoryTTFDataStream memoryTTFDataStream = new MemoryTTFDataStream(
+ GSUBTableDebugger.class.getResourceAsStream(LOHIT_BENGALI_FONT_FILE));
+
+ memoryTTFDataStream.seek(GlyphSubstitutionTableTest.DATA_POSITION_FOR_GSUB_TABLE);
+
+ GlyphSubstitutionTable glyphSubstitutionTable = new GlyphSubstitutionTable(null);
+
+ glyphSubstitutionTable.read(null, memoryTTFDataStream);
+
+ TrueTypeFont trueTypeFont = new TTFParser()
+ .parse(GSUBTableDebugger.class.getResourceAsStream(LOHIT_BENGALI_FONT_FILE));
+
+ GsubData gsubData = glyphSubstitutionTable.getGsubData();
+ new GSUBTablePrintUtil().printCharacterToGlyph(gsubData,
+ trueTypeFont.getUnicodeCmapLookup());
+ }
+
+}
Propchange: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GSUBTableDebugger.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyphSubstitutionTableTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyphSubstitutionTableTest.java?rev=1830499&r1=1830498&r2=1830499&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyphSubstitutionTableTest.java (original)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/GlyphSubstitutionTableTest.java Sun Apr 29 09:50:52 2018
@@ -40,7 +40,7 @@ import org.junit.Test;
public class GlyphSubstitutionTableTest
{
- private static final int DATA_POSITION_FOR_GSUB_TABLE = 120544;
+ static final int DATA_POSITION_FOR_GSUB_TABLE = 120544;
private static final Collection<String> EXPECTED_FEATURE_NAMES = Arrays.asList("abvs", "akhn",
"blwf", "blws", "half", "haln", "init", "nukt", "pres", "pstf", "rphf", "vatu");
Added: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/gsub/GSUBTablePrintUtil.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/gsub/GSUBTablePrintUtil.java?rev=1830499&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/gsub/GSUBTablePrintUtil.java (added)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/gsub/GSUBTablePrintUtil.java Sun Apr 29 09:50:52 2018
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fontbox.ttf.gsub;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.fontbox.ttf.CmapLookup;
+import org.apache.fontbox.ttf.GSUBTableDebugger;
+import org.apache.fontbox.ttf.model.GsubData;
+import org.apache.fontbox.ttf.model.ScriptFeature;
+
+/**
+ * This class is to be used mainly for debugging purposes. It is used in {@link GSUBTableDebugger}. It is used to print
+ * all the GSUB Glyphs to characters. The format is: <br>
+ *
+ * <Serial no.>.) <Space separated characters to be replaced> : RawUnicode: [<Space separated unicode
+ * representation of each character to be replaced in hexadecimal>] : <The compound character> : <The
+ * GlyphId with which these characters are replaced>
+ *
+ * @author Palash Ray
+ *
+ */
+public class GSUBTablePrintUtil
+{
+
+ public void printCharacterToGlyph(GsubData gsubData, CmapLookup cmap)
+ {
+ System.err.println(
+ "Format:\n<Serial no.>.) <Space separated characters to be replaced> : RawUnicode: [<Space separated unicode representation of each character to be replaced in hexadecimal>] : <The compound character> : <The GlyphId with which these characters are replaced>");
+ Map<Integer, List<Integer>> rawGSubTableData = new HashMap<>();
+
+ for (String featureName : gsubData.getSupportedFeatures())
+ {
+ ScriptFeature scriptFeature = gsubData.getFeature(featureName);
+ for (List<Integer> glyphsToBeReplaced : scriptFeature.getAllGlyphIdsForSubstitution())
+ {
+ rawGSubTableData.put(scriptFeature.getReplacementForGlyphs(glyphsToBeReplaced),
+ glyphsToBeReplaced);
+ }
+
+ }
+
+ for (String featureName : gsubData.getSupportedFeatures())
+ {
+ System.out
+ .println("****************** " + featureName + " ******************");
+ ScriptFeature scriptFeature = gsubData.getFeature(featureName);
+ int index = 0;
+ for (List<Integer> glyphsToBeReplaced : scriptFeature.getAllGlyphIdsForSubstitution())
+ {
+ String unicodeText = getUnicodeString(rawGSubTableData, cmap, glyphsToBeReplaced);
+ System.out.println(++index + ".) " + getExplainedUnicodeText(unicodeText) + " : "
+ + scriptFeature.getReplacementForGlyphs(glyphsToBeReplaced));
+ }
+
+ }
+
+ }
+
+ private String getUnicodeChar(Map<Integer, List<Integer>> rawGSubTableData, CmapLookup cmap,
+ Integer glyphId)
+ {
+ List<Integer> keyChars = cmap.getCharCodes(glyphId);
+
+ // its a compound glyph
+ if (keyChars == null)
+ {
+ List<Integer> constituentGlyphs = rawGSubTableData.get(glyphId);
+
+ if (constituentGlyphs == null || constituentGlyphs.isEmpty())
+ {
+ String message = "lookup for the glyphId: " + glyphId
+ + " failed, as no corresponding Unicode char found mapped to it";
+ throw new IllegalStateException(message);
+ }
+ else
+ {
+ return getUnicodeString(rawGSubTableData, cmap, constituentGlyphs);
+ }
+ }
+ else
+ {
+ StringBuilder sb = new StringBuilder();
+ for (int unicodeChar : keyChars)
+ {
+ sb.append((char) unicodeChar);
+ }
+ return sb.toString();
+ }
+
+ }
+
+ private String getUnicodeString(Map<Integer, List<Integer>> rawGSubTableData, CmapLookup cmap,
+ List<Integer> glyphIDs)
+ {
+ StringBuilder sb = new StringBuilder();
+ for (Integer glyphId : glyphIDs)
+ {
+ sb.append(getUnicodeChar(rawGSubTableData, cmap, glyphId));
+ }
+ return sb.toString();
+ }
+
+ private String getExplainedUnicodeText(String unicodeText)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ for (char unicode : unicodeText.toCharArray())
+ {
+ sb.append(unicode).append(" ");
+ }
+ sb.append(":");
+
+ sb.append(" RawUnicode: [");
+ for (char unicode : unicodeText.toCharArray())
+ {
+ sb.append("\\u0").append(Integer.toHexString(unicode).toUpperCase()).append(" ");
+ }
+ sb.append("] : ");
+
+ sb.append(unicodeText);
+
+ return sb.toString();
+ }
+
+}
Propchange: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/ttf/gsub/GSUBTablePrintUtil.java
------------------------------------------------------------------------------
svn:eol-style = native