use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDInlineImage method getFilters.
/**
* Returns a list of filters applied to this stream, or null if there are none.
*
* @return a list of filters applied to this stream
*/
// TODO return an empty list if there are none?
public List<String> getFilters() {
List<String> names = null;
COSBase filters = parameters.getDictionaryObject(COSName.F, COSName.FILTER);
if (filters instanceof COSName) {
COSName name = (COSName) filters;
names = new COSArrayList<String>(name.getName(), name, parameters, COSName.FILTER);
} else if (filters instanceof COSArray) {
names = COSArrayList.convertCOSNameCOSArrayToList((COSArray) filters);
}
return names;
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDOptionalContentProperties method getBaseState.
/**
* Returns the base state for optional content groups.
* @return the base state
*/
public BaseState getBaseState() {
COSDictionary d = getD();
COSName name = (COSName) d.getItem(COSName.BASE_STATE);
return BaseState.valueOf(name);
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class PDColorSpace method create.
/**
* Creates a color space given a name or array. Abbreviated device color names are not supported
* here, please replace them first. This method is for PDFBox internal use only, others should
* use {@link #create(COSBase, PDResources)}.
*
* @param colorSpace the color space COS object
* @param resources the current resources.
* @param wasDefault if current color space was used by a default color space.
* @return a new color space.
* @throws MissingResourceException if the color space is missing in the resources dictionary
* @throws IOException if the color space is unknown or cannot be created.
*/
public static PDColorSpace create(COSBase colorSpace, PDResources resources, boolean wasDefault) throws IOException {
if (colorSpace instanceof COSObject) {
return createFromCOSObject((COSObject) colorSpace, resources);
} else if (colorSpace instanceof COSName) {
COSName name = (COSName) colorSpace;
// default color spaces
if (resources != null) {
COSName defaultName = null;
if (name.equals(COSName.DEVICECMYK) && resources.hasColorSpace(COSName.DEFAULT_CMYK)) {
defaultName = COSName.DEFAULT_CMYK;
} else if (name.equals(COSName.DEVICERGB) && resources.hasColorSpace(COSName.DEFAULT_RGB)) {
defaultName = COSName.DEFAULT_RGB;
} else if (name.equals(COSName.DEVICEGRAY) && resources.hasColorSpace(COSName.DEFAULT_GRAY)) {
defaultName = COSName.DEFAULT_GRAY;
}
if (resources.hasColorSpace(defaultName) && !wasDefault) {
return resources.getColorSpace(defaultName, true);
}
}
// built-in color spaces
if (name == COSName.DEVICECMYK) {
// return PDDeviceCMYK.INSTANCE;
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.DEVICERGB) {
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.DEVICEGRAY) {
return PDDeviceGray.INSTANCE;
} else if (name == COSName.PATTERN) {
// return new PDPattern(resources);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (resources != null) {
if (!resources.hasColorSpace(name)) {
throw new MissingResourceException("Missing color space: " + name.getName());
}
return resources.getColorSpace(name);
} else {
throw new MissingResourceException("Unknown color space: " + name.getName());
}
} else if (colorSpace instanceof COSArray) {
COSArray array = (COSArray) colorSpace;
if (array.size() == 0) {
throw new IOException("Colorspace array is empty");
}
COSBase base = array.getObject(0);
if (!(base instanceof COSName)) {
throw new IOException("First element in colorspace array must be a name");
}
COSName name = (COSName) base;
if (name == COSName.CALGRAY) {
// return new PDCalGray(array); TODO: PdfBox-Android
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.CALRGB) {
// return new PDCalRGB(array);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.DEVICEN) {
// return new PDDeviceN(array);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.INDEXED) {
// return new PDIndexed(array);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.SEPARATION) {
// return new PDSeparation(array);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.ICCBASED) {
// return PDICCBased.create(array, resources);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.LAB) {
// return new PDLab(array);
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.PATTERN) {
if (array.size() == 1) {
// return new PDPattern(resources);
} else {
// return new PDPattern(resources, PDColorSpace.create(array.get(1)));
}
Log.e("PdfBox-Android", "Unsupported color space kind: " + name + ". Will try DeviceRGB instead");
return PDDeviceRGB.INSTANCE;
} else if (name == COSName.DEVICECMYK || name == COSName.DEVICERGB || name == COSName.DEVICEGRAY) {
// not allowed in an array, but we sometimes encounter these regardless
return create(name, resources, wasDefault);
} else {
throw new IOException("Invalid color space kind: " + name);
}
} else {
throw new IOException("Expected a name or array but got: " + colorSpace);
}
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class FDFFieldTest method testCOSNameValue.
@Test
public void testCOSNameValue() throws IOException {
String testString = "Yes";
COSName testCOSSName = COSName.getPDFName(testString);
FDFField field = new FDFField();
field.setValue(testCOSSName);
assertEquals(testCOSSName, (COSName) field.getCOSValue());
assertEquals(testString, field.getValue());
}
use of com.tom_roush.pdfbox.cos.COSName in project PdfBox-Android by TomRoush.
the class SetFontAndSize method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.size() < 2) {
throw new MissingOperandException(operator, arguments);
}
COSBase base0 = arguments.get(0);
COSBase base1 = arguments.get(1);
if (!(base0 instanceof COSName)) {
return;
}
if (!(base1 instanceof COSNumber)) {
return;
}
COSName fontName = (COSName) base0;
float fontSize = ((COSNumber) base1).floatValue();
context.getGraphicsState().getTextState().setFontSize(fontSize);
PDFont font = context.getResources().getFont(fontName);
if (font == null) {
Log.w("PdfBox-Android", "font '" + fontName.getName() + "' not found in resources");
}
context.getGraphicsState().getTextState().setFont(font);
}
Aggregations