1 17 18 19 20 package org.apache.fop.render.pdf; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.StringTokenizer ; 25 26 import org.apache.fop.apps.FOUserAgent; 27 28 29 public class PDFEncodingTestCase extends BasePDFTestCase { 30 private File foBaseDir = new File ("test/xml/pdf-encoding"); 31 private final boolean dumpPDF = Boolean.getBoolean("PDFEncodingTestCase.dumpPDF"); 32 static final String INPUT_FILE = "test/xml/pdf-encoding/pdf-encoding-test.xconf"; 33 static final String TEST_MARKER = "PDFE_TEST_MARK_"; 34 35 38 public PDFEncodingTestCase(String name) { 39 super(name); 40 } 41 42 46 protected FOUserAgent getUserAgent() { 47 final FOUserAgent a = fopFactory.newFOUserAgent(); 48 return a; 49 } 50 51 52 protected File getUserConfigFile() { 53 return new File (INPUT_FILE); 54 } 55 56 60 public void testPDFEncodingWithStandardFont() throws Exception { 61 62 67 final String [] testPatterns = { 68 TEST_MARKER + "1", "(Standard)", 69 TEST_MARKER + "2", "XX_\\351_XX", 70 TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX" 71 }; 72 73 runTest("test-standard-font.fo", testPatterns); 74 } 75 76 83 public void DISABLEDtestPDFEncodingWithCustomFont() throws Exception { 84 85 90 final String [] testPatterns = { 91 TEST_MARKER + "1", "(Gladiator)", 92 TEST_MARKER + "2", "XX_\\351_XX", 93 TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX" 94 }; 95 96 runTest("test-custom-font.fo", testPatterns); 97 } 98 99 100 private void runTest(String inputFile, String [] testPatterns) 101 throws Exception { 102 File foFile = new File (foBaseDir, inputFile); 103 byte[] pdfData = convertFO(foFile, getUserAgent(), dumpPDF); 104 checkEncoding(pdfData, testPatterns); 105 } 106 107 113 private void checkEncoding(byte[] pdf, String [] testPattern) 114 throws IOException { 115 116 int markersFound = 0; 117 final String input = new String (pdf); 118 int pos = 0; 119 if ((pos = input.indexOf(TEST_MARKER)) >= 0) { 120 final StringTokenizer tk = new StringTokenizer ( 121 input.substring(pos), "\n"); 122 123 while (tk.hasMoreTokens()) { 124 final String line = tk.nextToken(); 125 if (line.indexOf(TEST_MARKER) >= 0) { 126 markersFound++; 127 for (int i = 0; i < testPattern.length; i += 2) { 128 if (line.indexOf(testPattern[i]) >= 0) { 129 final String ref = testPattern[i + 1]; 130 final boolean patternFound = line.indexOf(ref) >= 0; 131 assertTrue("line containing '" + testPattern[i] 132 + "' must contain '" + ref, patternFound); 133 } 134 } 135 } 136 } 137 } 138 139 final int nMarkers = testPattern.length / 2; 140 assertEquals(nMarkers + " " + TEST_MARKER + " markers must be found", 141 nMarkers, markersFound); 142 } 143 } 144 | Popular Tags |