FontServiceImpl.java
4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.dor.FontService
* com.adobe.fontengine.font.Font
* com.adobe.fontengine.font.FontLoadingException
* com.adobe.fontengine.font.InvalidFontException
* com.adobe.fontengine.font.PDFFontDescription
* com.adobe.fontengine.font.UnsupportedFontException
* com.adobe.fontengine.fontmanagement.FontLoader
* com.day.cq.dam.handler.gibson.fontmanager.FontManagerService
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.addon.dor.service.impl;
import com.adobe.aemds.guide.dor.FontService;
import com.adobe.fontengine.font.Font;
import com.adobe.fontengine.font.FontLoadingException;
import com.adobe.fontengine.font.InvalidFontException;
import com.adobe.fontengine.font.PDFFontDescription;
import com.adobe.fontengine.font.UnsupportedFontException;
import com.adobe.fontengine.fontmanagement.FontLoader;
import com.day.cq.dam.handler.gibson.fontmanager.FontManagerService;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={FontService.class})
public class FontServiceImpl
implements FontService {
private static final Logger logger = LoggerFactory.getLogger(FontServiceImpl.class);
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
FontManagerService fontManagerService;
public ArrayList<String> getFontList() {
if (this.fontManagerService == null) {
logger.error("FontManagerService not found");
return new ArrayList<String>(0);
}
return this.getAllAvailableFonts();
}
private ArrayList<String> getAllAvailableFonts() {
String[] directories;
ArrayList<String> fontList = new ArrayList<String>();
String systemFontDirectoryPath = this.fontManagerService.getSystemFontDirectory();
String customerFontDirectoryPath = this.fontManagerService.getCustomerFontDirectory();
String adobeServerFontDirectoryPath = this.fontManagerService.getAdobeServerFontDirectory();
for (String directory : directories = new String[]{systemFontDirectoryPath, customerFontDirectoryPath, adobeServerFontDirectoryPath}) {
if (!StringUtils.isNotEmpty((CharSequence)directory)) continue;
File fontDirectory = new File(directory);
fontList.addAll(this.loadFontInfoFromDirectory(fontDirectory));
}
return fontList;
}
private ArrayList<String> loadFontInfoFromDirectory(File fontDirectory) {
Font[] fonts;
ArrayList<String> fontList = new ArrayList<String>();
FontLoader fontLoader = new FontLoader();
for (Font font : fonts = fontLoader.load(fontDirectory, true, null)) {
try {
PDFFontDescription pdfFontDescription = font.getPDFFontDescription();
fontList.add(pdfFontDescription.getFontFamily());
continue;
}
catch (FontLoadingException | InvalidFontException | UnsupportedFontException e) {
logger.error("Error while getting font", (Throwable)e);
}
}
return fontList;
}
protected void bindFontManagerService(FontManagerService fontManagerService) {
this.fontManagerService = fontManagerService;
}
protected void unbindFontManagerService(FontManagerService fontManagerService) {
if (this.fontManagerService == fontManagerService) {
this.fontManagerService = null;
}
}
}