private static Map<String, Object> readFontProperties(String name) throws java.io.IOException { InputStream resource = ResourceUtil.getResourceStream(FontResources.CMAPS + name + ".properties"); try { Properties p = new Properties(); p.load(resource); Map<String, Object> fontProperties = new HashMap<>(); for (Map.Entry<Object, Object> entry : p.entrySet()) { fontProperties.put((String) entry.getKey(), entry.getValue()); } fontProperties.put(W_PROP, createMetric((String) fontProperties.get(W_PROP))); fontProperties.put(W2_PROP, createMetric((String) fontProperties.get(W2_PROP))); return fontProperties; } finally { if (resource != null) { resource.close(); } } }
public static Set<String> getCompatibleCmaps(String fontName) { String registry = (String) FontCache.getAllPredefinedCidFonts().get(fontName).get(REGISTRY_PROP); return registryNames.get(registry); }
/** * * @param cmap CMap name. * @param uniMap CMap to convert Unicode value to CID. */ public CMapEncoding(String cmap, String uniMap) { this.cmap = cmap; this.uniMap = uniMap; if (cmap.equals(PdfEncodings.IDENTITY_H) || cmap.equals(PdfEncodings.IDENTITY_V)) { cid2Uni = FontCache.getCid2UniCmap(uniMap); isDirect = true; this.codeSpaceRanges = IDENTITY_H_V_CODESPACE_RANGES; } else { cid2Code = FontCache.getCid2Byte(cmap); code2Cid = cid2Code.getReversMap(); this.codeSpaceRanges = cid2Code.getCodeSpaceRanges(); } }
private static FontProgram createType1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb, boolean cached) throws java.io.IOException { FontProgram fontProgram; FontCacheKey fontKey = null; if (cached) { fontKey = createFontCacheKey(metricsPath, afm); fontProgram = FontCache.getFont(fontKey); if (fontProgram != null) { return fontProgram; } } fontProgram = new Type1Font(metricsPath, binaryPath, afm, pfb); return cached ? FontCache.saveFont(fontProgram, fontKey) : fontProgram; }
boolean isCidFont = !isBuiltinFonts14 && FontCache.isPredefinedCidFont(baseName); if (cached) { fontKey = createFontCacheKey(name, fontProgram); fontFound = FontCache.getFont(fontKey); if (fontFound != null) { return fontFound; fontBuilt = new Type1Font(name, null, null, null); } else if (isCidFont) { fontBuilt = new CidFont(name, FontCache.getCompatibleCmaps(baseName)); } else if (".ttf".equals(fontFileExtension) || ".otf".equals(fontFileExtension)) { if (fontProgram != null) { return cached ? FontCache.saveFont(fontBuilt, fontKey) : fontBuilt;
public static CMapUniCid getUni2CidCmap(String uniMap) { CMapUniCid uniCid = new CMapUniCid(); return parseCmap(uniMap, uniCid); }
private static FontProgramDescriptor fetchCachedDescriptor(String fontName, byte[] fontProgram) { FontProgram fontFound; FontCacheKey key; if (fontName != null) { key = FontCacheKey.create(fontName); } else { key = FontCacheKey.create(fontProgram); } fontFound = FontCache.getFont(key); return fontFound != null ? fetchDescriptorFromFontProgram(fontFound) : null; }
public static FontProgram saveFont(FontProgram font, String fontName) { return saveFont(font, FontCacheKey.create(fontName)); }
if (uniMap != null) { IntHashtable metrics = (IntHashtable) fontDesc.get("W"); CMapCidUni cid2Uni = FontCache.getCid2UniCmap(uniMap); avgWidth = 0; for (int cid : cid2Uni.getCids()) {
boolean isCidFont = !isBuiltinFonts14 && FontCache.isPredefinedCidFont(baseName);
static CMapToUnicode getToUnicodeFromUniMap(String uniMap) { if (uniMap == null) return null; synchronized (uniMaps) { if (uniMaps.containsKey(uniMap)) { return uniMaps.get(uniMap); } CMapToUnicode toUnicode; if (PdfEncodings.IDENTITY_H.equals(uniMap)) { toUnicode = CMapToUnicode.getIdentity(); } else { CMapUniCid uni = FontCache.getUni2CidCmap(uniMap); if (uni == null) { return null; } toUnicode = uni.exportToUnicode(); } uniMaps.put(uniMap, toUnicode); return toUnicode; } }
boolean isCidFont = !isBuiltinFonts14 && FontCache.isPredefinedCidFont(baseName); if (cached) { fontKey = createFontCacheKey(name, fontProgram); fontFound = FontCache.getFont(fontKey); if (fontFound != null) { return fontFound; fontBuilt = new Type1Font(name, null, null, null); } else if (isCidFont) { fontBuilt = new CidFont(name, FontCache.getCompatibleCmaps(baseName)); } else if (".ttf".equals(fontFileExtension) || ".otf".equals(fontFileExtension)) { if (fontProgram != null) { return cached ? FontCache.saveFont(fontBuilt, fontKey) : fontBuilt;
private static FontProgram createType1Font(String metricsPath, String binaryPath, byte[] afm, byte[] pfb, boolean cached) throws java.io.IOException { FontProgram fontProgram; FontCacheKey fontKey = null; if (cached) { fontKey = createFontCacheKey(metricsPath, afm); fontProgram = FontCache.getFont(fontKey); if (fontProgram != null) { return fontProgram; } } fontProgram = new Type1Font(metricsPath, binaryPath, afm, pfb); return cached ? FontCache.saveFont(fontProgram, fontKey) : fontProgram; }
public static CMapCidByte getCid2Byte(String cmap) { CMapCidByte cidByte = new CMapCidByte(); return parseCmap(cmap, cidByte); }
private static FontProgramDescriptor fetchCachedDescriptor(String fontName, byte[] fontProgram) { FontProgram fontFound; FontCacheKey key; if (fontName != null) { key = FontCacheKey.create(fontName); } else { key = FontCacheKey.create(fontProgram); } fontFound = FontCache.getFont(key); return fontFound != null ? fetchDescriptorFromFontProgram(fontFound) : null; }
public static FontProgram saveFont(FontProgram font, String fontName) { return saveFont(font, FontCacheKey.create(fontName)); }
if (uniMap != null) { IntHashtable metrics = (IntHashtable) fontDesc.get("W"); CMapCidUni cid2Uni = FontCache.getCid2UniCmap(uniMap); avgWidth = 0; for (int cid : cid2Uni.getCids()) {
boolean isCidFont = !isBuiltinFonts14 && FontCache.isPredefinedCidFont(baseName);
/** * Creates a new TrueType font program from ttc (TrueType Collection) file. * * @param ttc location of TrueType Collection file (*.ttc) * @param ttcIndex the index of the font file from the collection to be read * @param cached true if the font comes from the cache or is added to * the cache if new, false if the font is always created new * @return returns a new {@link FontProgram} instance. This font may come from the cache but only if cached * is true, otherwise it will always be created new */ public static FontProgram createFont(String ttc, int ttcIndex, boolean cached) throws java.io.IOException { FontCacheKey fontCacheKey = FontCacheKey.create(ttc, ttcIndex); if (cached) { FontProgram fontFound = FontCache.getFont(fontCacheKey); if (fontFound != null) { return fontFound; } } FontProgram fontBuilt = new TrueTypeFont(ttc, ttcIndex); return cached ? FontCache.saveFont(fontBuilt, fontCacheKey) : fontBuilt; }
public static CMapCidUni getCid2UniCmap(String uniMap) { CMapCidUni cidUni = new CMapCidUni(); return parseCmap(uniMap, cidUni); }