Skip to content

Commit f69c366

Browse files
committed
Expose TypographyUtils#isPdfCalligraphAvailable()
This allows easily checking if layout is aware of pdfCalligraph being present in classpath DEVSIX-3085
1 parent 2ec5ebc commit f69c366

File tree

3 files changed

+75
-10
lines changed

3 files changed

+75
-10
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/TextRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
568568
public void applyOtf() {
569569
updateFontAndText();
570570
Character.UnicodeScript script = this.<Character.UnicodeScript>getProperty(Property.FONT_SCRIPT);
571-
if (!otfFeaturesApplied && TypographyUtils.isTypographyModuleInitialized() && text.start < text.end) {
571+
if (!otfFeaturesApplied && TypographyUtils.isPdfCalligraphAvailable() && text.start < text.end) {
572572
if (hasOtfFont()) {
573573
Object typographyConfig = this.<Object>getProperty(Property.TYPOGRAPHY_CONFIG);
574574
Collection<Character.UnicodeScript> supportedScripts = null;

layout/src/main/java/com/itextpdf/layout/renderer/TypographyUtils.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,24 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.io.font.TrueTypeFont;
4848
import com.itextpdf.io.font.otf.Glyph;
4949
import com.itextpdf.io.font.otf.GlyphLine;
50+
import com.itextpdf.io.util.MessageFormatUtil;
5051
import com.itextpdf.kernel.font.PdfFont;
5152
import com.itextpdf.layout.property.BaseDirection;
5253
import com.itextpdf.layout.property.Property;
54+
import org.slf4j.Logger;
55+
import org.slf4j.LoggerFactory;
5356

5457
import java.lang.reflect.AccessibleObject;
5558
import java.lang.reflect.Constructor;
5659
import java.lang.reflect.Method;
57-
import com.itextpdf.io.util.MessageFormatUtil;
5860
import java.util.ArrayList;
5961
import java.util.Arrays;
6062
import java.util.Collection;
6163
import java.util.HashMap;
6264
import java.util.List;
6365
import java.util.Map;
6466

65-
import org.slf4j.Logger;
66-
import org.slf4j.LoggerFactory;
67-
68-
final class TypographyUtils {
67+
public final class TypographyUtils {
6968

7069
private static final Logger logger = LoggerFactory.getLogger(TypographyUtils.class);
7170

@@ -123,6 +122,17 @@ final class TypographyUtils {
123122
SUPPORTED_SCRIPTS = supportedScripts;
124123
}
125124

125+
private TypographyUtils() {
126+
}
127+
128+
/**
129+
* Checks if layout module can access pdfCalligraph
130+
* @return <code>true</code> if layout can access pdfCalligraph and <code>false</code> otherwise
131+
*/
132+
public static boolean isPdfCalligraphAvailable() {
133+
return TYPOGRAPHY_MODULE_INITIALIZED;
134+
}
135+
126136
static void applyOtfScript(FontProgram fontProgram, GlyphLine text, Character.UnicodeScript script, Object typographyConfig) {
127137
if (!TYPOGRAPHY_MODULE_INITIALIZED) {
128138
logger.warn(typographyNotFoundException);
@@ -247,10 +257,6 @@ static Collection<Character.UnicodeScript> getSupportedScripts(Object typography
247257
}
248258
}
249259

250-
static boolean isTypographyModuleInitialized() {
251-
return TYPOGRAPHY_MODULE_INITIALIZED;
252-
}
253-
254260
private static Object callMethod(String className, String methodName, Class[] parameterTypes, Object... args) {
255261
return callMethod(className, methodName, (Object) null, parameterTypes, args);
256262
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.layout.renderer;
44+
45+
import com.itextpdf.test.ExtendedITextTest;
46+
import com.itextpdf.test.annotations.type.UnitTest;
47+
import org.junit.Assert;
48+
import org.junit.Test;
49+
import org.junit.experimental.categories.Category;
50+
51+
@Category(UnitTest.class)
52+
public class TypographyUtilsTest extends ExtendedITextTest {
53+
54+
@Test
55+
public void verifyPdfCalligraphIsNotAvailable() {
56+
Assert.assertFalse(TypographyUtils.isPdfCalligraphAvailable());
57+
}
58+
59+
}

0 commit comments

Comments
 (0)