use of org.apache.fontbox.cmap.CMap in project pdfbox by apache.
the class PDType0Font method fetchCMapUCS2.
/**
* Fetches the corresponding UCS2 CMap if the font's CMap is predefined.
*/
private void fetchCMapUCS2() throws IOException {
// if the font is composite and uses a predefined cmap (excluding Identity-H/V)
// or whose descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
// Adobe-Korea1 character collection:
COSName name = dict.getCOSName(COSName.ENCODING);
if (isCMapPredefined && !(name == COSName.IDENTITY_H || name == COSName.IDENTITY_V) || isDescendantCJK) {
// a) Map the character code to a CID using the font's CMap
// b) Obtain the ROS from the font's CIDSystemInfo
// c) Construct a second CMap name by concatenating the ROS in the format "R-O-UCS2"
// d) Obtain the CMap with the constructed name
// e) Map the CID according to the CMap from step d), producing a Unicode value
// todo: not sure how to interpret the PDF spec here, do we always override? or only when Identity-H/V?
String strName = null;
if (isDescendantCJK) {
strName = descendantFont.getCIDSystemInfo().getRegistry() + "-" + descendantFont.getCIDSystemInfo().getOrdering() + "-" + descendantFont.getCIDSystemInfo().getSupplement();
} else if (name != null) {
strName = name.getName();
}
// try to find the corresponding Unicode (UC2) CMap
if (strName != null) {
CMap prdCMap = CMapManager.getPredefinedCMap(strName);
String ucs2Name = prdCMap.getRegistry() + "-" + prdCMap.getOrdering() + "-UCS2";
cMapUCS2 = CMapManager.getPredefinedCMap(ucs2Name);
}
}
}
use of org.apache.fontbox.cmap.CMap in project pdfbox by apache.
the class CMapManager method parseCMap.
/**
* Parse the given CMap.
*
* @param cMapStream the CMap to be read
* @return the parsed CMap
*/
public static CMap parseCMap(InputStream cMapStream) throws IOException {
CMap targetCmap = null;
if (cMapStream != null) {
CMapParser parser = new CMapParser();
targetCmap = parser.parse(cMapStream);
}
return targetCmap;
}
use of org.apache.fontbox.cmap.CMap in project pdfbox by apache.
the class CMapManager method getPredefinedCMap.
/**
* Fetches the predefined CMap from disk (or cache).
*
* @param cMapName CMap name
* @return The predefined CMap, never null.
* @throws IOException
*/
public static CMap getPredefinedCMap(String cMapName) throws IOException {
CMap cmap = cMapCache.get(cMapName);
if (cmap != null) {
return cmap;
}
CMapParser parser = new CMapParser();
CMap targetCmap = parser.parsePredefined(cMapName);
// limit the cache to predefined CMaps
cMapCache.put(targetCmap.getName(), targetCmap);
return targetCmap;
}
use of org.apache.fontbox.cmap.CMap in project pdfbox by apache.
the class Type0FontValidator method processCMapAsStream.
/**
* This method checks mandatory fields of the CMap stream. This method also checks if the CMap
* stream is damaged using the CMapParser of the fontbox api. The standard information of a
* stream element will be checked by the StreamValidationProcess.
*
* @param aCMap the cmap stream.
*/
private void processCMapAsStream(COSStream aCMap) {
COSBase sysinfo = aCMap.getItem(COSName.CIDSYSTEMINFO);
checkCIDSystemInfo(sysinfo);
try (InputStream cmapStream = aCMap.createInputStream()) {
// extract information from the CMap stream
CMap fontboxCMap = new CMapParser().parse(cmapStream);
int wmValue = fontboxCMap.getWMode();
String cmnValue = fontboxCMap.getName();
/*
* According to the getInt javadoc, -1 is returned if there is no result. In the PDF Reference v1.7 p449,
* we can read that the default value is 0.
*/
int wmode = aCMap.getInt(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_WMODE), FONT_DICTIONARY_DEFAULT_CMAP_WMODE);
String type = aCMap.getNameAsString(COSName.TYPE);
String cmapName = aCMap.getNameAsString(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_NAME));
if (cmapName == null || "".equals(cmapName) || wmode > 1) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING, font.getName() + ": Some elements in the CMap dictionary are missing or invalid"));
} else if (!(wmValue == wmode && cmapName.equals(cmnValue))) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING, font.getName() + ": CMapName or WMode is inconsistent"));
} else if (!FONT_DICTIONARY_VALUE_TYPE_CMAP.equals(type)) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING, font.getName() + ": The CMap type is invalid"));
}
} catch (IOException e) {
this.fontContainer.push(new ValidationError(ERROR_FONTS_CID_CMAP_DAMAGED, font.getName() + ": The CMap type is damaged", e));
}
COSDictionary cmapUsed = (COSDictionary) aCMap.getDictionaryObject(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_USECMAP));
if (cmapUsed != null) {
checkCMapEncoding(cmapUsed);
}
compareCIDSystemInfo(aCMap);
}
Aggregations