Package org.apache.poi.hwmf.draw
Class HwmfGraphics
- java.lang.Object
-
- org.apache.poi.hwmf.draw.HwmfGraphics
-
- All Implemented Interfaces:
HwmfCharsetAware
- Direct Known Subclasses:
HemfGraphics
public class HwmfGraphics extends Object implements HwmfCharsetAware
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHwmfGraphics.FillDrawStyle
-
Field Summary
Fields Modifier and Type Field Description protected Graphics2DgraphicsCtxprotected BitSetobjectIndexesprotected TreeMap<Integer,HwmfObjectTableEntry>objectTableprotected HwmfDrawPropertiesprop
-
Constructor Summary
Constructors Constructor Description HwmfGraphics(Graphics2D graphicsCtx, Rectangle2D bbox)Initialize a graphics context for wmf rendering
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObjectTableEntry(HwmfObjectTableEntry entry)Adds an record of typeHwmfObjectTableEntryto the object table.voidapplyObjectTableEntry(int index)Applies the object table entryvoiddraw(Shape shape)voiddrawImage(BufferedImage img, Rectangle2D srcBounds, Rectangle2D dstBounds)voiddrawImage(ImageRenderer img, Rectangle2D srcBounds, Rectangle2D dstBounds)voiddrawString(byte[] text, int length, Point2D reference)voiddrawString(byte[] text, int length, Point2D reference, Dimension2D scale, Rectangle2D clip, HwmfText.WmfExtTextOutOptions opts, List<Integer> dx, boolean isUnicode)voidfill(Shape shape)protected PaintgetFill()protected PaintgetHatchedFill()ImageRenderergetImageRenderer(String contentType)AffineTransformgetInitTransform()protected PaintgetLinearGradient()static BufferedImagegetPatternFromLong(long patternLng, Color background, Color foreground, boolean hasAlpha)protected PaintgetPatternPaint()HwmfDrawPropertiesgetProperties()protected PaintgetSolidFill()protected BasicStrokegetStroke()AffineTransformgetTransform()protected HwmfDrawPropertiesnewProperties(HwmfDrawProperties oldProps)voidrestoreProperties(int index)Restores the properties from the stackvoidsaveProperties()Saves the current properties to the stackvoidsetCharsetProvider(Supplier<Charset> provider)voidsetClip(Shape clip, HwmfRegionMode regionMode, boolean useInitialAT)Set the new clipping regionvoidsetTransform(AffineTransform tx)Set the current AffineTransformvoidunsetObjectTableEntry(int index)Unsets (deletes) the object table entry for further usage When a META_DELETEOBJECT record (section 2.3.4.7) is received that specifies this object's particular index, the object's resources are released, the binding to its WMF Object Table index is ended, and the index value is returned to the pool of available indexes.voidupdateWindowMapMode()After setting various window and viewport related properties, the underlying graphics context needs to be adapted.
-
-
-
Field Detail
-
prop
protected HwmfDrawProperties prop
-
graphicsCtx
protected final Graphics2D graphicsCtx
-
objectIndexes
protected final BitSet objectIndexes
-
objectTable
protected final TreeMap<Integer,HwmfObjectTableEntry> objectTable
-
-
Constructor Detail
-
HwmfGraphics
public HwmfGraphics(Graphics2D graphicsCtx, Rectangle2D bbox)
Initialize a graphics context for wmf rendering- Parameters:
graphicsCtx- the graphics context to delegate drawing callsbbox- the bounding box of the wmf (taken from the placeable header)
-
-
Method Detail
-
getProperties
public HwmfDrawProperties getProperties()
-
newProperties
protected HwmfDrawProperties newProperties(HwmfDrawProperties oldProps)
-
draw
public void draw(Shape shape)
-
fill
public void fill(Shape shape)
-
getStroke
protected BasicStroke getStroke()
-
getFill
protected Paint getFill()
-
getLinearGradient
protected Paint getLinearGradient()
-
getSolidFill
protected Paint getSolidFill()
-
getHatchedFill
protected Paint getHatchedFill()
-
getPatternFromLong
public static BufferedImage getPatternFromLong(long patternLng, Color background, Color foreground, boolean hasAlpha)
-
getPatternPaint
protected Paint getPatternPaint()
-
addObjectTableEntry
public void addObjectTableEntry(HwmfObjectTableEntry entry)
Adds an record of typeHwmfObjectTableEntryto the object table. Every object is assigned the lowest available index-that is, the smallest numerical value-in the WMF Object Table. This binding happens at object creation, not when the object is used. Moreover, each object table index uniquely refers to an object. Indexes in the WMF Object Table always start at 0.- Parameters:
entry- the object table entry
-
applyObjectTableEntry
public void applyObjectTableEntry(int index)
Applies the object table entry- Parameters:
index- the index of the object table entry (0-based)- Throws:
IndexOutOfBoundsException- if the index is out of rangeNoSuchElementException- if the entry was deleted before
-
unsetObjectTableEntry
public void unsetObjectTableEntry(int index)
Unsets (deletes) the object table entry for further usage When a META_DELETEOBJECT record (section 2.3.4.7) is received that specifies this object's particular index, the object's resources are released, the binding to its WMF Object Table index is ended, and the index value is returned to the pool of available indexes. The index will be reused, if needed, by a subsequent object created by another Object Record Type record.- Parameters:
index- the index (0-based)- Throws:
IndexOutOfBoundsException- if the index is out of range
-
saveProperties
public void saveProperties()
Saves the current properties to the stack
-
restoreProperties
public void restoreProperties(int index)
Restores the properties from the stack- Parameters:
index- if the index is positive, the n-th element from the start is activated. If the index is negative, the n-th previous element relative to the current properties element is activated.
-
updateWindowMapMode
public void updateWindowMapMode()
After setting various window and viewport related properties, the underlying graphics context needs to be adapted. This methods gathers and sets the corresponding graphics transformations.
-
drawString
public void drawString(byte[] text, int length, Point2D reference)
-
drawString
public void drawString(byte[] text, int length, Point2D reference, Dimension2D scale, Rectangle2D clip, HwmfText.WmfExtTextOutOptions opts, List<Integer> dx, boolean isUnicode)
-
setCharsetProvider
public void setCharsetProvider(Supplier<Charset> provider)
- Specified by:
setCharsetProviderin interfaceHwmfCharsetAware
-
drawImage
public void drawImage(BufferedImage img, Rectangle2D srcBounds, Rectangle2D dstBounds)
-
drawImage
public void drawImage(ImageRenderer img, Rectangle2D srcBounds, Rectangle2D dstBounds)
-
getInitTransform
public AffineTransform getInitTransform()
- Returns:
- the initial AffineTransform, when this graphics context was created
-
getTransform
public AffineTransform getTransform()
- Returns:
- the current AffineTransform
-
setTransform
public void setTransform(AffineTransform tx)
Set the current AffineTransform- Parameters:
tx- the current AffineTransform
-
setClip
public void setClip(Shape clip, HwmfRegionMode regionMode, boolean useInitialAT)
Set the new clipping region- Parameters:
clip- the next clipping region to be processedregionMode- the mode and operation of how to apply the next clipping regionuseInitialAT- if true, the clipping is applied on the initial (world) coordinate system
-
getImageRenderer
public ImageRenderer getImageRenderer(String contentType)
-
-