-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PDFBOX-5729: add test for Devanagari GSUB worker, by JAVAUSER
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1914528 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
1 changed file
with
285 additions
and
0 deletions.
There are no files selected for viewing
285 changes: 285 additions & 0 deletions
285
pdfbox/src/test/java/org/apache/pdfbox/it/gsub/GsubWorkerForDevanagariTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
/* | ||
* 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.pdfbox.it.gsub; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.fontbox.ttf.CmapLookup; | ||
import org.apache.fontbox.ttf.gsub.GsubWorker; | ||
import org.apache.fontbox.ttf.gsub.GsubWorkerFactory; | ||
import org.apache.fontbox.ttf.gsub.GsubWorkerForDevanagari; | ||
import org.apache.pdfbox.pdmodel.PDDocument; | ||
import org.apache.pdfbox.pdmodel.font.PDType0Font; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Integration test for {@link GsubWorkerForDevanagari}. Has various combinations of glyphs to test | ||
* proper working of the GSUB system. | ||
* <p> | ||
* Not all tests are enabled at this time (12/2023). Please read the comment of 10/Dec/23 in | ||
* PDFBOX-5729. | ||
* | ||
* @author JAVAUSER | ||
* | ||
*/ | ||
class GsubWorkerForDevanagariTest | ||
{ | ||
|
||
private static final String LOHIT_DEVANAGARI_TTF = "/org/apache/pdfbox/ttf/Lohit-Devanagari.ttf"; | ||
|
||
private CmapLookup cmapLookup; | ||
private GsubWorker gsubWorkerForDevanagari; | ||
|
||
@BeforeEach | ||
public void init() throws IOException | ||
{ | ||
try (PDDocument doc = new PDDocument()) | ||
{ | ||
PDType0Font font = PDType0Font.load(doc, | ||
GsubWorkerForDevanagariTest.class.getResourceAsStream(LOHIT_DEVANAGARI_TTF), true); | ||
|
||
cmapLookup = font.getCmapLookup(); | ||
gsubWorkerForDevanagari = new GsubWorkerFactory().getGsubWorker(cmapLookup, font.getGsubData()); | ||
System.out.println("worker: " + gsubWorkerForDevanagari); | ||
} | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_locl() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(642); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("प्त")); | ||
System.out.println("result: " + result); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_nukt() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(400,396,393); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("य़ज़क़")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_akhn() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(520,521); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("क्षज्ञ")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_rphf() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(513); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("र्")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Disabled | ||
@Test | ||
void testApplyTransforms_rkrf() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(588,597,595,602); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("क्रब्रप्रह्र")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_blwf() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(602,336,516); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("ह्रट्र")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_half() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(558,557,546,537); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("ह्स्भ्त्")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_vatu() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(517,593,601,665); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("श्रत्रस्रघ्र")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Disabled | ||
@Test | ||
void testApplyTransforms_cjct() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(638,688,636,640,639); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("द्मद्ध्र्यब्दद्वद्य")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_pres() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(603,605,617,652); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("शृक्तज्जह्ण")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Disabled | ||
@Test | ||
void testApplyTransforms_abvs() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(353,512,353,675,353,673); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("र्रैंरौंर्रो")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Disabled | ||
@Test | ||
void testApplyTransforms_blws() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(660,663,336,584,336,583); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("दृहृट्रूट्रु")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Disabled | ||
@Test | ||
void testApplyTransforms_psts() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(326,704,326,582,661,662); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("किंर्कींरुरू")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Test | ||
void testApplyTransforms_haln() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(539); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("द्")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
@Disabled | ||
void testApplyTransforms_calt() | ||
{ | ||
// given | ||
List<Integer> glyphsAfterGsub = Arrays.asList(); | ||
|
||
// when | ||
List<Integer> result = gsubWorkerForDevanagari.applyTransforms(getGlyphIds("")); | ||
|
||
// then | ||
assertEquals(glyphsAfterGsub, result); | ||
} | ||
|
||
private List<Integer> getGlyphIds(String word) | ||
{ | ||
List<Integer> originalGlyphIds = new ArrayList<>(); | ||
|
||
for (char unicodeChar : word.toCharArray()) | ||
{ | ||
int glyphId = cmapLookup.getGlyphId(unicodeChar); | ||
assertTrue(glyphId > 0); | ||
originalGlyphIds.add(glyphId); | ||
} | ||
|
||
return originalGlyphIds; | ||
} | ||
|
||
} |