本文整理汇总了Java中org.apache.pdfbox.pdmodel.graphics.color.PDColor类的典型用法代码示例。如果您正苦于以下问题:Java PDColor类的具体用法?Java PDColor怎么用?Java PDColor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PDColor类属于org.apache.pdfbox.pdmodel.graphics.color包,在下文中一共展示了PDColor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: equals
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
@Override
public boolean equals(Object object) {
// If the object is an PDColor, compare the rgb arrays.
if (object instanceof PDColor) {
PDColor color = (PDColor) object;
float[] components = color.getComponents();
PDColorSpace colorSpace = color.getColorSpace();
if (colorSpace != null) {
try {
float[] rgb = colorSpace.toRGB(components);
return Arrays.equals(rgb, this.rgb);
} catch (IOException e) {
return false;
}
}
return false;
} else if (object instanceof PdfColor) {
return object == this;
} else {
return false;
}
}
开发者ID:ckorzen,项目名称:icecite,代码行数:23,代码来源:PdfBoxColor.java
示例2: applyTexturePaint
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private void applyTexturePaint(TexturePaint texturePaint) throws IOException {
Rectangle2D anchorRect = texturePaint.getAnchorRect();
PDTilingPattern pattern = new PDTilingPattern();
pattern.setPaintType(PDTilingPattern.PAINT_COLORED);
pattern.setTilingType(PDTilingPattern.TILING_CONSTANT_SPACING_FASTER_TILING);
pattern.setBBox(new PDRectangle((float) anchorRect.getX(), (float) anchorRect.getY(),
(float) anchorRect.getWidth(), (float) anchorRect.getHeight()));
pattern.setXStep((float) anchorRect.getWidth());
pattern.setYStep((float) anchorRect.getHeight());
AffineTransform patternTransform = new AffineTransform();
patternTransform.translate(0, anchorRect.getHeight());
patternTransform.scale(1f, -1f);
pattern.setMatrix(patternTransform);
PDAppearanceStream appearance = new PDAppearanceStream(document);
appearance.setResources(pattern.getResources());
appearance.setBBox(pattern.getBBox());
PDPageContentStream imageContentStream = new PDPageContentStream(document, appearance,
((COSStream) pattern.getCOSObject()).createOutputStream());
BufferedImage texturePaintImage = texturePaint.getImage();
PDImageXObject imageXObject = imageEncoder.encodeImage(document, imageContentStream, texturePaintImage);
float ratioW = (float) ((anchorRect.getWidth()) / texturePaintImage.getWidth());
float ratioH = (float) ((anchorRect.getHeight()) / texturePaintImage.getHeight());
float paintHeight = (texturePaintImage.getHeight()) * ratioH;
imageContentStream.drawImage(imageXObject, (float) anchorRect.getX(), (float) (paintHeight + anchorRect.getY()),
texturePaintImage.getWidth() * ratioW, -paintHeight);
imageContentStream.close();
PDColorSpace patternCS1 = new PDPattern(null, imageXObject.getColorSpace());
COSName tilingPatternName = resources.add(pattern);
PDColor patternColor = new PDColor(tilingPatternName, patternCS1);
contentStream.setNonStrokingColor(patternColor);
contentStream.setStrokingColor(patternColor);
}
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:40,代码来源:PdfBoxGraphics2DPaintApplier.java
示例3: getColorString
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private static String getColorString(PDColor c) {
String colorString = "";
//ccheck suitable for getcomponents
float[] rgb = c.getComponents();
if (rgb.length == 1) {
int grey = (int) rgb[0] * 255;
colorString = Integer.toHexString(grey);
if (colorString.length() == 1) {
colorString = "0" + colorString;
}
colorString = colorString + colorString + colorString;
} else {
for (int colorIndex=0; colorIndex<3; colorIndex++) {
int color = (int) rgb[colorIndex] * 255;
String s = Integer.toHexString(color);
if (s.length() == 1) {
s = "0" + s;
}
colorString += s;
}
}
return "#" + colorString;
}
开发者ID:TekstoSense,项目名称:pdf-segmenter,代码行数:25,代码来源:Text.java
示例4: toRGB
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
/**
* Transforms the given color to rgb array.
*/
public static float[] toRGB(PDColor color) {
try {
float[] components = color.getComponents();
PDColorSpace colorSpace = color.getColorSpace();
if (colorSpace != null) {
return colorSpace.toRGB(components);
}
} catch (Exception e) {
return null;
}
return null;
}
开发者ID:ckorzen,项目名称:icecite,代码行数:16,代码来源:PdfBoxColor.java
示例5: setStrokingColor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
/**
* Sets the stroking color and, if necessary, the stroking color space.
*
* @param color
* Color in a specific color space.
* @throws IOException
* If an IO error occurs while writing to the stream.
*/
public void setStrokingColor (final PDColor color) throws IOException
{
if (strokingColorSpaceStack.isEmpty () || strokingColorSpaceStack.peek () != color.getColorSpace ())
{
writeOperand (getName (color.getColorSpace ()));
writeOperator ((byte) 'C', (byte) 'S');
if (strokingColorSpaceStack.isEmpty ())
{
strokingColorSpaceStack.add (color.getColorSpace ());
}
else
{
strokingColorSpaceStack.set (nonStrokingColorSpaceStack.size () - 1, color.getColorSpace ());
}
}
for (final float value : color.getComponents ())
{
writeOperand (value);
}
if (color.getColorSpace () instanceof PDPattern)
{
writeOperand (color.getPatternName ());
}
if (color.getColorSpace () instanceof PDPattern ||
color.getColorSpace () instanceof PDSeparation ||
color.getColorSpace () instanceof PDDeviceN ||
color.getColorSpace () instanceof PDICCBased)
{
writeOperator ((byte) 'S', (byte) 'C', (byte) 'N');
}
else
{
writeOperator ((byte) 'S', (byte) 'C');
}
}
开发者ID:phax,项目名称:ph-pdf-layout,代码行数:48,代码来源:PDPageContentStreamExt.java
示例6: setNonStrokingColor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
/**
* Sets the non-stroking color and, if necessary, the non-stroking color
* space.
*
* @param color
* Color in a specific color space.
* @throws IOException
* If an IO error occurs while writing to the stream.
*/
public void setNonStrokingColor (final PDColor color) throws IOException
{
if (nonStrokingColorSpaceStack.isEmpty () || nonStrokingColorSpaceStack.peek () != color.getColorSpace ())
{
writeOperand (getName (color.getColorSpace ()));
writeOperator ((byte) 'c', (byte) 's');
if (nonStrokingColorSpaceStack.isEmpty ())
{
nonStrokingColorSpaceStack.add (color.getColorSpace ());
}
else
{
nonStrokingColorSpaceStack.set (nonStrokingColorSpaceStack.size () - 1, color.getColorSpace ());
}
}
for (final float value : color.getComponents ())
{
writeOperand (value);
}
if (color.getColorSpace () instanceof PDPattern)
{
writeOperand (color.getPatternName ());
}
if (color.getColorSpace () instanceof PDPattern ||
color.getColorSpace () instanceof PDSeparation ||
color.getColorSpace () instanceof PDDeviceN ||
color.getColorSpace () instanceof PDICCBased)
{
writeOperator ((byte) 's', (byte) 'c', (byte) 'n');
}
else
{
writeOperator ((byte) 's', (byte) 'c');
}
}
开发者ID:phax,项目名称:ph-pdf-layout,代码行数:49,代码来源:PDPageContentStreamExt.java
示例7: applyShadingAsColor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private void applyShadingAsColor(PDShading shading) throws IOException {
/*
* If the paint has a shading we must create a tiling pattern and set
* that as stroke color...
*/
PDTilingPattern pattern = new PDTilingPattern();
pattern.setPaintType(PDTilingPattern.PAINT_COLORED);
pattern.setTilingType(PDTilingPattern.TILING_CONSTANT_SPACING_FASTER_TILING);
PDRectangle anchorRect = bbox;
pattern.setBBox(anchorRect);
pattern.setXStep(anchorRect.getWidth());
pattern.setYStep(anchorRect.getHeight());
PDAppearanceStream appearance = new PDAppearanceStream(this.document);
appearance.setResources(pattern.getResources());
appearance.setBBox(pattern.getBBox());
PDPageContentStream imageContentStream = new PDPageContentStream(document, appearance,
((COSStream) pattern.getCOSObject()).createOutputStream());
imageContentStream.addRect(0, 0, anchorRect.getWidth(), anchorRect.getHeight());
imageContentStream.clip();
imageContentStream.shadingFill(shading);
imageContentStream.close();
PDColorSpace patternCS1 = new PDPattern(null);
COSName tilingPatternName = xFormObject.getResources().add(pattern);
PDColor patternColor = new PDColor(tilingPatternName, patternCS1);
contentStream.setNonStrokingColor(patternColor);
contentStream.setStrokingColor(patternColor);
}
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:32,代码来源:PdfBoxGraphics2D.java
示例8: mapColor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
@Override
public PDColor mapColor(PDPageContentStream contentStream, Color color) {
if (color == null)
return new PDColor(new float[] { 1f, 1f, 1f }, PDDeviceRGB.INSTANCE);
float[] components = new float[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f };
return new PDColor(components, PDDeviceRGB.INSTANCE);
}
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:8,代码来源:PdfBoxGraphics2DColorMapper.java
示例9: buildLinearGradientShading
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private PDShading buildLinearGradientShading(Paint paint, AffineTransform tf) throws IOException {
/*
* Batik has a copy of RadialGradientPaint, but it has the same structure as the
* AWT RadialGradientPaint. So we use Reflection to access the fields of both
* these classes.
*/
Color[] colors = getPropertyValue(paint, "getColors");
Color firstColor = colors[0];
PDColor firstColorMapped = colorMapper.mapColor(contentStream, firstColor);
applyAsStrokingColor(firstColor);
PDShadingType3 shading = new PDShadingType3(new COSDictionary());
shading.setShadingType(PDShading.SHADING_TYPE2);
shading.setColorSpace(firstColorMapped.getColorSpace());
float[] fractions = getPropertyValue(paint, "getFractions");
Point2D startPoint = getPropertyValue(paint, "getStartPoint");
Point2D endPoint = getPropertyValue(paint, "getEndPoint");
AffineTransform gradientTransform = getPropertyValue(paint, "getTransform");
tf.concatenate(gradientTransform);
tf.transform(startPoint, startPoint);
tf.transform(endPoint, endPoint);
COSArray coords = new COSArray();
coords.add(new COSFloat((float) startPoint.getX()));
coords.add(new COSFloat((float) startPoint.getY()));
coords.add(new COSFloat((float) endPoint.getX()));
coords.add(new COSFloat((float) endPoint.getY()));
shading.setCoords(coords);
PDFunctionType3 type3 = buildType3Function(colors, fractions);
COSArray extend = new COSArray();
extend.add(COSBoolean.TRUE);
extend.add(COSBoolean.TRUE);
shading.setFunction(type3);
shading.setExtend(extend);
return shading;
}
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:40,代码来源:PdfBoxGraphics2DPaintApplier.java
示例10: buildGradientShading
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private PDShading buildGradientShading(AffineTransform tf, GradientPaint gradientPaint) throws IOException {
Color[] colors = new Color[] { gradientPaint.getColor1(), gradientPaint.getColor2() };
Color firstColor = colors[0];
PDColor firstColorMapped = colorMapper.mapColor(contentStream, firstColor);
applyAsStrokingColor(firstColor);
PDShadingType3 shading = new PDShadingType3(new COSDictionary());
shading.setShadingType(PDShading.SHADING_TYPE2);
shading.setColorSpace(firstColorMapped.getColorSpace());
float[] fractions = new float[] { 0, 1 };
Point2D startPoint = gradientPaint.getPoint1();
Point2D endPoint = gradientPaint.getPoint2();
tf.transform(startPoint, startPoint);
tf.transform(endPoint, endPoint);
COSArray coords = new COSArray();
coords.add(new COSFloat((float) startPoint.getX()));
coords.add(new COSFloat((float) startPoint.getY()));
coords.add(new COSFloat((float) endPoint.getX()));
coords.add(new COSFloat((float) endPoint.getY()));
shading.setCoords(coords);
PDFunctionType3 type3 = buildType3Function(colors, fractions);
COSArray extend = new COSArray();
extend.add(COSBoolean.TRUE);
extend.add(COSBoolean.TRUE);
shading.setFunction(type3);
shading.setExtend(extend);
return shading;
}
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:35,代码来源:PdfBoxGraphics2DPaintApplier.java
示例11: PdfTextStyle
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
/**
* This constructor is used by spring when creating a font from properties.
*
* @param config e.g. 10,Times-Roman,#000000
*/
public PdfTextStyle(String config) {
Assert.hasText(config);
String[] split = config.split(",");
Assert.isTrue(split.length == 3, "config must look like: 10,Times-Roman,#000000");
fontSize = Float.parseFloat(split[0]);
font = PdfFont.getFont(split[1]);
Color tempColor = new Color(Integer.valueOf(split[2].substring(1), 16));
float[] components = {tempColor.getRed(), tempColor.getGreen(), tempColor.getBlue()};
color = new PDColor(components, PDDeviceRGB.INSTANCE);
}
开发者ID:Catalysts,项目名称:cat-boot,代码行数:16,代码来源:PdfTextStyle.java
示例12: fromConstructor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
@Test
public void fromConstructor() {
PdfTextStyle config = new PdfTextStyle("10.5,Times-Roman,#000000");
PDColor black = new PDColor(new float[] {0.0f, 0.0f, 0.0f}, PDDeviceRGB.INSTANCE);
Assert.assertEquals(10.5, config.getFontSize(), delta);
Assert.assertEquals("Times-Roman", config.getFont().getBasename());
Assert.assertEquals(black.getColorSpace(), config.getColor().getColorSpace());
}
开发者ID:Catalysts,项目名称:cat-boot,代码行数:11,代码来源:PdfTextStyleTest.java
示例13: testFloatSize
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
@Test
public void testFloatSize() {
float fontSize = 10.5f;
PDColor red = new PDColor(new float[] {1.0f, 0.0f, 0.0f}, PDDeviceRGB.INSTANCE);
PdfTextStyle config = new PdfTextStyle(fontSize, PdfFont.TIMES_ROMAN, red, "regular");
Assert.assertEquals(fontSize, config.getFontSize(), delta);
}
开发者ID:Catalysts,项目名称:cat-boot,代码行数:9,代码来源:PdfTextStyleTest.java
示例14: testTextWidth
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
@Test
public void testTextWidth() {
float fontSize = 0.5f;
PDColor black = new PDColor(new float[] {0.0f, 0.0f, 0.0f}, PDDeviceRGB.INSTANCE);
PdfTextStyle config = new PdfTextStyle(fontSize, PdfFont.COURIER, black, "bold");
Float textWidth = PdfBoxHelper.getTextWidth(config.getCurrentFontStyle(), config.getFontSize(), "Some text");
Assert.assertTrue(textWidth > 0);
}
开发者ID:Catalysts,项目名称:cat-boot,代码行数:11,代码来源:PdfTextStyleTest.java
示例15: process
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
@Override
public void process(Operator operator, List<COSBase> arguments)
throws IOException {
PDColorSpace colorSpace = getColorSpace();
if (colorSpace instanceof PDDeviceColorSpace
&& arguments.size() < colorSpace.getNumberOfComponents()) {
throw new MissingOperandException(operator, arguments);
}
COSArray array = new COSArray();
array.addAll(arguments);
setColor(new PDColor(array, colorSpace));
}
开发者ID:ckorzen,项目名称:icecite,代码行数:13,代码来源:SetColor.java
示例16: buildRadialGradientShading
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private PDShading buildRadialGradientShading(Paint paint, AffineTransform tf) throws IOException {
/*
* Batik has a copy of RadialGradientPaint, but it has the same structure as the
* AWT RadialGradientPaint. So we use Reflection to access the fields of both
* these classes.
*/
Color[] colors = getPropertyValue(paint, "getColors");
Color firstColor = colors[0];
PDColor firstColorMapped = colorMapper.mapColor(contentStream, firstColor);
applyAsStrokingColor(firstColor);
PDShadingType3 shading = new PDShadingType3(new COSDictionary());
shading.setShadingType(PDShading.SHADING_TYPE3);
shading.setColorSpace(firstColorMapped.getColorSpace());
float[] fractions = getPropertyValue(paint, "getFractions");
Point2D centerPoint = getPropertyValue(paint, "getCenterPoint");
Point2D focusPoint = getPropertyValue(paint, "getFocusPoint");
AffineTransform gradientTransform = getPropertyValue(paint, "getTransform");
tf.concatenate(gradientTransform);
tf.transform(centerPoint, centerPoint);
tf.transform(focusPoint, focusPoint);
@SuppressWarnings("ConstantConditions")
float radius = getPropertyValue(paint, "getRadius");
radius = (float) Math.abs(radius * tf.getScaleX());
COSArray coords = new COSArray();
coords.add(new COSFloat((float) centerPoint.getX()));
coords.add(new COSFloat((float) centerPoint.getY()));
coords.add(new COSFloat(0));
coords.add(new COSFloat((float) focusPoint.getX()));
coords.add(new COSFloat((float) focusPoint.getY()));
coords.add(new COSFloat(radius));
shading.setCoords(coords);
PDFunctionType3 type3 = buildType3Function(colors, fractions);
COSArray extend = new COSArray();
extend.add(COSBoolean.TRUE);
extend.add(COSBoolean.TRUE);
shading.setFunction(type3);
shading.setExtend(extend);
return shading;
}
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:46,代码来源:PdfBoxGraphics2DPaintApplier.java
示例17: getColor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
public PDColor getColor() {
return color;
}
开发者ID:Catalysts,项目名称:cat-boot,代码行数:4,代码来源:PdfTextStyle.java
示例18: toPDColor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private static PDColor toPDColor(final Color color) {
float[] components = new float[] {
color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f };
return new PDColor(components, PDDeviceRGB.INSTANCE);
}
开发者ID:ralfstuckert,项目名称:pdfbox-layout,代码行数:6,代码来源:CompatibilityHelper.java
示例19: showLigature
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
@Override
public void showLigature(String[] unicodes, int code, PDFont font,
Matrix trm) throws IOException {
super.showLigature(unicodes, code, font, trm);
float size = getGraphicsState().getTextState().getFontSize();
PDColor nonStrokingColor = getGraphicsState().getNonStrokingColor();
PdfBoxColor color = PdfBoxColor.create(nonStrokingColor);
PdfBoxFont pdfFont = PdfBoxFont.create(font);
Rectangle boundingBox = null;
if (font instanceof PDType3Font) {
processType3Stream(((PDType3Font) font).getCharProc(code), trm);
boundingBox = getCurrentType3GlyphBoundingBox();
} else {
boundingBox = getFontGlyphBoundingBox(code, font, trm);
}
if (boundingBox == null) {
boundingBox = getDefaultBoundingBox(code, font, trm);
} else {
Rectangle defaultBoundingBox = getDefaultBoundingBox(code, font, trm);
boundingBox.setMinX(defaultBoundingBox.getMinX());
boundingBox.setMaxX(defaultBoundingBox.getMaxX());
}
float widthPerUnicode = boundingBox.getWidth() / (float) unicodes.length;
for (int i = 0; i < unicodes.length; i++) {
float minX = boundingBox.getMinX() + i * widthPerUnicode;
float maxX = minX + widthPerUnicode;
float minY = boundingBox.getMinY();
float maxY = boundingBox.getMaxY();
Rectangle newBoundBox = new SimpleRectangle(minX, minY, maxX, maxY);
PdfBoxCharacter character = new PdfBoxCharacter(currentPage, unicodes[i]);
character.setCharCode(code);
character.setRectangle(newBoundBox);
character.setTextRenderingMatrix(trm);
character.setFont(pdfFont);
character.setFontsize(size);
character.setColor(color);
showPdfTextCharacter(character);
}
}
开发者ID:ckorzen,项目名称:icecite,代码行数:47,代码来源:PdfTextStreamEngine.java
示例20: pdfColorToColor
import org.apache.pdfbox.pdmodel.graphics.color.PDColor; //导入依赖的package包/类
private Color pdfColorToColor(PDColor color) throws IOException
{
float[] rgb = color.getColorSpace().toRGB(color.getComponents());
return new Color(rgb[0], rgb[1], rgb[2]);
}
开发者ID:radkovo,项目名称:Pdf2Dom,代码行数:7,代码来源:PathDrawer.java
注:本文中的org.apache.pdfbox.pdmodel.graphics.color.PDColor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论