Class GroupGraphics
- java.lang.Object
-
- java.awt.Graphics
-
- java.awt.Graphics2D
-
- org.apache.pdfbox.rendering.GroupGraphics
-
class GroupGraphics extends java.awt.Graphics2DGraphics implementation for non-isolated transparency groups.Non-isolated groups require that the group backdrop (copied from parent group or page) is used as the initial contents of the image to which the group is rendered. This allows blend modes to blend the group contents with the graphics behind the group. Finally when the group rendering is done, backdrop removal must be computed (see
removeBackdrop). It ensures the backdrop is not rendered twice on the parent but it leaves the effects of blend modes.This class renders the group contents to two images.
groupImageis initialized with the backdrop and group contents are drawn over it.groupAlphaImageis initially fully transparent and it accumulates the total alpha of the group contents excluding backdrop.If a non-isolated group uses only the blend mode Normal, it can be optimized and rendered like an isolated group; backdrop usage and removal are not needed.
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Graphics2DalphaG2Dprivate java.awt.image.BufferedImagegroupAlphaImageprivate java.awt.Graphics2DgroupG2Dprivate java.awt.image.BufferedImagegroupImage
-
Constructor Summary
Constructors Modifier Constructor Description (package private)GroupGraphics(java.awt.image.BufferedImage groupImage, java.awt.Graphics2D groupGraphics)privateGroupGraphics(java.awt.image.BufferedImage groupImage, java.awt.Graphics2D groupGraphics, java.awt.image.BufferedImage groupAlphaImage, java.awt.Graphics2D alphaGraphics)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRenderingHints(java.util.Map<?,?> hints)private intbackdropRemoval(int groupRGB, int backdropRGB, int shift, float alphaFactor)Computes the backdrop removal equation.voidclearRect(int x, int y, int width, int height)voidclip(java.awt.Shape s)voidclipRect(int x, int y, int width, int height)voidcopyArea(int x, int y, int width, int height, int dx, int dy)java.awt.Graphicscreate()voiddispose()voiddraw(java.awt.Shape s)voiddrawArc(int x, int y, int width, int height, int startAngle, int arcAngle)voiddrawGlyphVector(java.awt.font.GlyphVector g, float x, float y)voiddrawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)booleandrawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)booleandrawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)booleandrawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)booleandrawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)booleandrawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)booleandrawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)booleandrawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)voiddrawLine(int x1, int y1, int x2, int y2)voiddrawOval(int x, int y, int width, int height)voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints)voiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints)voiddrawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)voiddrawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)voiddrawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)voiddrawString(java.lang.String str, float x, float y)voiddrawString(java.lang.String str, int x, int y)voiddrawString(java.text.AttributedCharacterIterator iterator, float x, float y)voiddrawString(java.text.AttributedCharacterIterator iterator, int x, int y)voidfill(java.awt.Shape s)voidfillArc(int x, int y, int width, int height, int startAngle, int arcAngle)voidfillOval(int x, int y, int width, int height)voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints)voidfillRect(int x, int y, int width, int height)voidfillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)java.awt.ColorgetBackground()java.awt.ShapegetClip()java.awt.RectanglegetClipBounds()java.awt.ColorgetColor()java.awt.CompositegetComposite()java.awt.GraphicsConfigurationgetDeviceConfiguration()java.awt.FontgetFont()java.awt.FontMetricsgetFontMetrics(java.awt.Font f)java.awt.font.FontRenderContextgetFontRenderContext()java.awt.PaintgetPaint()java.lang.ObjectgetRenderingHint(java.awt.RenderingHints.Key hintKey)java.awt.RenderingHintsgetRenderingHints()java.awt.StrokegetStroke()java.awt.geom.AffineTransformgetTransform()booleanhit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)(package private) voidremoveBackdrop(java.awt.image.BufferedImage backdrop, int offsetX, int offsetY)Computes backdrop removal.voidrotate(double theta)voidrotate(double theta, double x, double y)voidscale(double sx, double sy)voidsetBackground(java.awt.Color color)voidsetClip(int x, int y, int width, int height)voidsetClip(java.awt.Shape clip)voidsetColor(java.awt.Color c)voidsetComposite(java.awt.Composite comp)voidsetFont(java.awt.Font font)voidsetPaint(java.awt.Paint paint)voidsetPaintMode()voidsetRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)voidsetRenderingHints(java.util.Map<?,?> hints)voidsetStroke(java.awt.Stroke s)voidsetTransform(java.awt.geom.AffineTransform tx)voidsetXORMode(java.awt.Color c1)voidshear(double shx, double shy)voidtransform(java.awt.geom.AffineTransform tx)voidtranslate(double tx, double ty)voidtranslate(int x, int y)
-
-
-
Constructor Detail
-
GroupGraphics
GroupGraphics(java.awt.image.BufferedImage groupImage, java.awt.Graphics2D groupGraphics)
-
GroupGraphics
private GroupGraphics(java.awt.image.BufferedImage groupImage, java.awt.Graphics2D groupGraphics, java.awt.image.BufferedImage groupAlphaImage, java.awt.Graphics2D alphaGraphics)
-
-
Method Detail
-
clearRect
public void clearRect(int x, int y, int width, int height)- Specified by:
clearRectin classjava.awt.Graphics
-
clipRect
public void clipRect(int x, int y, int width, int height)- Specified by:
clipRectin classjava.awt.Graphics
-
copyArea
public void copyArea(int x, int y, int width, int height, int dx, int dy)- Specified by:
copyAreain classjava.awt.Graphics
-
create
public java.awt.Graphics create()
- Specified by:
createin classjava.awt.Graphics
-
dispose
public void dispose()
- Specified by:
disposein classjava.awt.Graphics
-
drawArc
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)- Specified by:
drawArcin classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)- Specified by:
drawImagein classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver observer)- Specified by:
drawImagein classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)- Specified by:
drawImagein classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int x, int y, int width, int height, java.awt.image.ImageObserver observer)- Specified by:
drawImagein classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.Color bgcolor, java.awt.image.ImageObserver observer)- Specified by:
drawImagein classjava.awt.Graphics
-
drawImage
public boolean drawImage(java.awt.Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, java.awt.image.ImageObserver observer)- Specified by:
drawImagein classjava.awt.Graphics
-
drawLine
public void drawLine(int x1, int y1, int x2, int y2)- Specified by:
drawLinein classjava.awt.Graphics
-
drawOval
public void drawOval(int x, int y, int width, int height)- Specified by:
drawOvalin classjava.awt.Graphics
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)- Specified by:
drawPolygonin classjava.awt.Graphics
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)- Specified by:
drawPolylinein classjava.awt.Graphics
-
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)- Specified by:
drawRoundRectin classjava.awt.Graphics
-
drawString
public void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)- Specified by:
drawStringin classjava.awt.Graphics2D
-
drawString
public void drawString(java.lang.String str, int x, int y)- Specified by:
drawStringin classjava.awt.Graphics2D
-
fillArc
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)- Specified by:
fillArcin classjava.awt.Graphics
-
fillOval
public void fillOval(int x, int y, int width, int height)- Specified by:
fillOvalin classjava.awt.Graphics
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)- Specified by:
fillPolygonin classjava.awt.Graphics
-
fillRect
public void fillRect(int x, int y, int width, int height)- Specified by:
fillRectin classjava.awt.Graphics
-
fillRoundRect
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)- Specified by:
fillRoundRectin classjava.awt.Graphics
-
getClip
public java.awt.Shape getClip()
- Specified by:
getClipin classjava.awt.Graphics
-
getClipBounds
public java.awt.Rectangle getClipBounds()
- Specified by:
getClipBoundsin classjava.awt.Graphics
-
getColor
public java.awt.Color getColor()
- Specified by:
getColorin classjava.awt.Graphics
-
getFont
public java.awt.Font getFont()
- Specified by:
getFontin classjava.awt.Graphics
-
getFontMetrics
public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
- Specified by:
getFontMetricsin classjava.awt.Graphics
-
setClip
public void setClip(int x, int y, int width, int height)- Specified by:
setClipin classjava.awt.Graphics
-
setClip
public void setClip(java.awt.Shape clip)
- Specified by:
setClipin classjava.awt.Graphics
-
setColor
public void setColor(java.awt.Color c)
- Specified by:
setColorin classjava.awt.Graphics
-
setFont
public void setFont(java.awt.Font font)
- Specified by:
setFontin classjava.awt.Graphics
-
setPaintMode
public void setPaintMode()
- Specified by:
setPaintModein classjava.awt.Graphics
-
setXORMode
public void setXORMode(java.awt.Color c1)
- Specified by:
setXORModein classjava.awt.Graphics
-
translate
public void translate(int x, int y)- Specified by:
translatein classjava.awt.Graphics2D
-
addRenderingHints
public void addRenderingHints(java.util.Map<?,?> hints)
- Specified by:
addRenderingHintsin classjava.awt.Graphics2D
-
clip
public void clip(java.awt.Shape s)
- Specified by:
clipin classjava.awt.Graphics2D
-
draw
public void draw(java.awt.Shape s)
- Specified by:
drawin classjava.awt.Graphics2D
-
drawGlyphVector
public void drawGlyphVector(java.awt.font.GlyphVector g, float x, float y)- Specified by:
drawGlyphVectorin classjava.awt.Graphics2D
-
drawImage
public void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)- Specified by:
drawImagein classjava.awt.Graphics2D
-
drawImage
public boolean drawImage(java.awt.Image img, java.awt.geom.AffineTransform xform, java.awt.image.ImageObserver obs)- Specified by:
drawImagein classjava.awt.Graphics2D
-
drawRenderableImage
public void drawRenderableImage(java.awt.image.renderable.RenderableImage img, java.awt.geom.AffineTransform xform)- Specified by:
drawRenderableImagein classjava.awt.Graphics2D
-
drawRenderedImage
public void drawRenderedImage(java.awt.image.RenderedImage img, java.awt.geom.AffineTransform xform)- Specified by:
drawRenderedImagein classjava.awt.Graphics2D
-
drawString
public void drawString(java.text.AttributedCharacterIterator iterator, float x, float y)- Specified by:
drawStringin classjava.awt.Graphics2D
-
drawString
public void drawString(java.lang.String str, float x, float y)- Specified by:
drawStringin classjava.awt.Graphics2D
-
fill
public void fill(java.awt.Shape s)
- Specified by:
fillin classjava.awt.Graphics2D
-
getBackground
public java.awt.Color getBackground()
- Specified by:
getBackgroundin classjava.awt.Graphics2D
-
getComposite
public java.awt.Composite getComposite()
- Specified by:
getCompositein classjava.awt.Graphics2D
-
getDeviceConfiguration
public java.awt.GraphicsConfiguration getDeviceConfiguration()
- Specified by:
getDeviceConfigurationin classjava.awt.Graphics2D
-
getFontRenderContext
public java.awt.font.FontRenderContext getFontRenderContext()
- Specified by:
getFontRenderContextin classjava.awt.Graphics2D
-
getPaint
public java.awt.Paint getPaint()
- Specified by:
getPaintin classjava.awt.Graphics2D
-
getRenderingHint
public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
- Specified by:
getRenderingHintin classjava.awt.Graphics2D
-
getRenderingHints
public java.awt.RenderingHints getRenderingHints()
- Specified by:
getRenderingHintsin classjava.awt.Graphics2D
-
getStroke
public java.awt.Stroke getStroke()
- Specified by:
getStrokein classjava.awt.Graphics2D
-
getTransform
public java.awt.geom.AffineTransform getTransform()
- Specified by:
getTransformin classjava.awt.Graphics2D
-
hit
public boolean hit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)- Specified by:
hitin classjava.awt.Graphics2D
-
rotate
public void rotate(double theta)
- Specified by:
rotatein classjava.awt.Graphics2D
-
rotate
public void rotate(double theta, double x, double y)- Specified by:
rotatein classjava.awt.Graphics2D
-
scale
public void scale(double sx, double sy)- Specified by:
scalein classjava.awt.Graphics2D
-
setBackground
public void setBackground(java.awt.Color color)
- Specified by:
setBackgroundin classjava.awt.Graphics2D
-
setComposite
public void setComposite(java.awt.Composite comp)
- Specified by:
setCompositein classjava.awt.Graphics2D
-
setPaint
public void setPaint(java.awt.Paint paint)
- Specified by:
setPaintin classjava.awt.Graphics2D
-
setRenderingHint
public void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)- Specified by:
setRenderingHintin classjava.awt.Graphics2D
-
setRenderingHints
public void setRenderingHints(java.util.Map<?,?> hints)
- Specified by:
setRenderingHintsin classjava.awt.Graphics2D
-
setStroke
public void setStroke(java.awt.Stroke s)
- Specified by:
setStrokein classjava.awt.Graphics2D
-
setTransform
public void setTransform(java.awt.geom.AffineTransform tx)
- Specified by:
setTransformin classjava.awt.Graphics2D
-
shear
public void shear(double shx, double shy)- Specified by:
shearin classjava.awt.Graphics2D
-
transform
public void transform(java.awt.geom.AffineTransform tx)
- Specified by:
transformin classjava.awt.Graphics2D
-
translate
public void translate(double tx, double ty)- Specified by:
translatein classjava.awt.Graphics2D
-
removeBackdrop
void removeBackdrop(java.awt.image.BufferedImage backdrop, int offsetX, int offsetY)Computes backdrop removal. The backdrop removal equation is given in section 11.4.4 in the PDF 32000-1:2008 standard. It returns the final colorCfor each pixel in the group:
C = Cn + (Cn - C0) * (alpha0 / alphagn - alpha0)
where
Cnis the group color including backdrop (read fromgroupImage),
C0is the backdrop color,
alpha0is the backdrop alpha,
alphagnis the group alpha excluding backdrop (read the alpha channel fromgroupAlphaImage)
The alpha of the result is equal to
alphagn, i.e., the alpha channel ofgroupAlphaImage.The
backdropimage may be much larger thangroupImageif, for example, the current page is used as the backdrop. Only a specific rectangular region ofbackdropis used in the backdrop removal: upper-left corner is at(offsetX, offsetY); width and height are equal to those ofgroupImage.- Parameters:
backdrop- group backdropoffsetX- backdrop left X coordinateoffsetY- backdrop upper Y coordinate
-
backdropRemoval
private int backdropRemoval(int groupRGB, int backdropRGB, int shift, float alphaFactor)Computes the backdrop removal equation.C = Cn + (Cn - C0) * (alpha0 / alphagn - alpha0)
-
-