|
| 1 | +/* |
| 2 | + * FontconfigInstrumentedTests.java |
| 3 | + * |
| 4 | + * Copyright (C) 2019 Vilius Sutkus'89 |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package com.viliussutkus89.android.pdf2htmlex; |
| 21 | + |
| 22 | +import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 23 | +import androidx.test.platform.app.InstrumentationRegistry; |
| 24 | + |
| 25 | +import org.junit.Test; |
| 26 | +import org.junit.runner.RunWith; |
| 27 | + |
| 28 | +import static org.junit.Assert.assertEquals; |
| 29 | +import static org.junit.Assert.assertTrue; |
| 30 | + |
| 31 | +import java.util.Arrays; |
| 32 | +import java.util.HashSet; |
| 33 | +import java.util.Set; |
| 34 | + |
| 35 | +@RunWith(AndroidJUnit4.class) |
| 36 | +public class FontconfigInstrumentedTests { |
| 37 | + static { |
| 38 | + System.loadLibrary("nativeFontconfigInstrumentedTests"); |
| 39 | + } |
| 40 | + |
| 41 | + //pdf base14 fonts: |
| 42 | + //Courier, Courier Bold, Courier Oblique, Courier Bold-Oblique |
| 43 | + //Helvetica, Helvetica Bold, Helvetica Oblique, Helvetica Bold-Oblique |
| 44 | + //Times Roman, Times Bold, Times Italic, Times Bold-Italic |
| 45 | + //Symbol |
| 46 | + //Zapf Dingbats |
| 47 | + |
| 48 | + @Test |
| 49 | + public synchronized void matchCourierTest() { |
| 50 | + Set<String> acceptedValues = new HashSet<>(Arrays.asList("CutiveMono.ttf", "DroidSansMono.ttf")); |
| 51 | + |
| 52 | + // @TODO: init only FontconfigAndroid, not the whole pdf2htmlEX |
| 53 | + new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 54 | + assertTrue(acceptedValues.contains(getFontFilenameFromFontconfig("Courier"))); |
| 55 | + |
| 56 | + // @TODO: these should be downloaded at run time |
| 57 | + assertTrue(acceptedValues.contains(getFontFilenameFromFontconfig("Courier:Bold"))); |
| 58 | + assertTrue(acceptedValues.contains(getFontFilenameFromFontconfig("Courier:Oblique"))); |
| 59 | + assertTrue(acceptedValues.contains(getFontFilenameFromFontconfig("Courier:Bold:Oblique"))); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public synchronized void matchHelveticaTest() { |
| 64 | + // @TODO: init only FontconfigAndroid, not the whole pdf2htmlEX |
| 65 | + new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 66 | + |
| 67 | + // /system/fonts/DroidSans.ttf symlinked to Roboto-Regular.ttf |
| 68 | + assertTrue(new HashSet<>(Arrays.asList("Roboto-Regular.ttf", "DroidSans.ttf")) |
| 69 | + .contains(getFontFilenameFromFontconfig("Helvetica"))); |
| 70 | + |
| 71 | + // /system/fonts/DroidSans-Bold.ttf symlinked to Roboto-Bold.ttf |
| 72 | + assertTrue(new HashSet<>(Arrays.asList("Roboto-Bold.ttf", "DroidSans-Bold.ttf")) |
| 73 | + .contains(getFontFilenameFromFontconfig("Helvetica:Bold"))); |
| 74 | + |
| 75 | + assertEquals("Roboto-Italic.ttf", getFontFilenameFromFontconfig("Helvetica:Oblique")); |
| 76 | + assertEquals("Roboto-BoldItalic.ttf", getFontFilenameFromFontconfig("Helvetica:Bold:Oblique")); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public synchronized void matchTimesTest() { |
| 81 | + // @TODO: init only FontconfigAndroid, not the whole pdf2htmlEX |
| 82 | + new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
| 83 | + |
| 84 | + assertTrue(new HashSet<>(Arrays.asList("NotoSerif-Regular.ttf", "DroidSerif-Regular.ttf")) |
| 85 | + .contains(getFontFilenameFromFontconfig("Times"))); |
| 86 | + |
| 87 | + assertTrue(new HashSet<>(Arrays.asList("NotoSerif-Bold.ttf", "DroidSerif-Bold.ttf")) |
| 88 | + .contains(getFontFilenameFromFontconfig("Times:Bold"))); |
| 89 | + |
| 90 | + assertTrue(new HashSet<>(Arrays.asList("NotoSerif-Italic.ttf", "DroidSerif-Italic.ttf")) |
| 91 | + .contains(getFontFilenameFromFontconfig("Times:Italic"))); |
| 92 | + |
| 93 | + assertTrue(new HashSet<>(Arrays.asList("NotoSerif-BoldItalic.ttf", "DroidSerif-BoldItalic.ttf")) |
| 94 | + .contains(getFontFilenameFromFontconfig("Times:Bold:Italic"))); |
| 95 | + } |
| 96 | + |
| 97 | + private native String getFontFilenameFromFontconfig(String pattern); |
| 98 | +} |
0 commit comments