Package com.teamten.typeset.element
Class Image
java.lang.Object
com.teamten.typeset.element.Element
com.teamten.typeset.element.NonDiscardableElement
com.teamten.typeset.element.Box
com.teamten.typeset.element.Image
- All Implemented Interfaces:
Dimensions
Represents an image to be inserted into the document.
-
Field Summary
Fields inherited from class com.teamten.typeset.element.Element
DRAW_DEBUG
-
Method Summary
Modifier and TypeMethodDescriptionThe caption as a box, or null if there's no caption.long
layOutHorizontally
(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) Add the element to the contents as part of a horizontal sequence.long
layOutVertically
(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) Add the element to the contents as part of a vertical sequence.static Image
load
(Path imagePath, long maxWidth, long maxHeight, @Nullable Block block, Config config, FontManager fontManager, Bookmarks bookmarks, Sections sections, HyphenDictionary hyphenDictionary, org.apache.pdfbox.pdmodel.PDDocument pdDoc) Loads an image as a new element.static Path
preprocessImage
(Path origPath, long maxWidth, long maxHeight) Make a copy of this image, ensuring that its resolution is not unnecessarily high.toString()
Methods inherited from class com.teamten.typeset.element.Box
drawDebugRectangle, getDepth, getDimensionString, getHeight, getShift, getWidth
Methods inherited from class com.teamten.typeset.element.Element
getVerticalSize, println, println, shouldSkipElementAtStart, toTextString, toTextString, visit
-
Method Details
-
getCaption
The caption as a box, or null if there's no caption. -
load
public static Image load(Path imagePath, long maxWidth, long maxHeight, @Nullable @Nullable Block block, Config config, FontManager fontManager, Bookmarks bookmarks, Sections sections, HyphenDictionary hyphenDictionary, org.apache.pdfbox.pdmodel.PDDocument pdDoc) throws IOException Loads an image as a new element. The size of the box is the aspect ratio of the image zoomed to fit in the specified max width and height. The image is entirely height (no depth). In other words, the baseline is at the bottom of the image.- Throws:
IOException
-
layOutHorizontally
public long layOutHorizontally(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException Description copied from class:Element
Add the element to the contents as part of a horizontal sequence.- Overrides:
layOutHorizontally
in classBox
- Parameters:
x
- the left-most point of the element.y
- the baseline of the element.contents
- the stream to add the element to.- Returns:
- how much to move right afterward.
- Throws:
IOException
-
layOutVertically
public long layOutVertically(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException Description copied from class:Element
Add the element to the contents as part of a vertical sequence.- Overrides:
layOutVertically
in classBox
- Parameters:
x
- the left-most point of the element.y
- the upper-left point of the element.contents
- the stream to add the element to.- Returns:
- how much to move down afterward.
- Throws:
IOException
-
toString
-
preprocessImage
Make a copy of this image, ensuring that its resolution is not unnecessarily high. Note that the cached file will be recomputed if it's missing or old, but not if the resolution (width or height) change. In that case the cache directory should be deleted. The cache is based on the filename. Two different files with the same filename will clash.- Parameters:
origPath
- the path of the original (possibly high-res) image.maxWidth
- the width of the space this image will fit in.maxHeight
- the height of the space this image will fit in.- Returns:
- a path to the image to load instead (possibly equal to origPath).
- Throws:
IOException
- if something goes wrong with processing the image.
-