aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-08-30 11:18:21 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-08-30 11:18:21 +0000
commitb00ca445b2eee110df17fba5f8afd64260c16174 (patch)
tree049f6ecfd3b8dd02bc15f53b04679b7210c8a295 /src/java/org/apache/poi
parentf89528addc51729a438eb5732129b87c2d87b4b9 (diff)
downloadpoi-b00ca445b2eee110df17fba5f8afd64260c16174.tar.gz
poi-b00ca445b2eee110df17fba5f8afd64260c16174.zip
#64693 - POI HwmfGraphics cannot read the embedded document title
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881322 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r--src/java/org/apache/poi/sl/draw/Drawable.java33
-rw-r--r--src/java/org/apache/poi/sl/draw/ImageRenderer.java8
-rw-r--r--src/java/org/apache/poi/util/GenericRecordJsonWriter.java42
3 files changed, 71 insertions, 12 deletions
diff --git a/src/java/org/apache/poi/sl/draw/Drawable.java b/src/java/org/apache/poi/sl/draw/Drawable.java
index fd0ea1b6fa..919e1a6f25 100644
--- a/src/java/org/apache/poi/sl/draw/Drawable.java
+++ b/src/java/org/apache/poi/sl/draw/Drawable.java
@@ -28,11 +28,11 @@ public interface Drawable {
protected DrawableHint(int id) {
super(id);
}
-
+
public boolean isCompatibleValue(Object val) {
return true;
}
-
+
public String toString() {
switch (intKey()) {
case 1: return "DRAW_FACTORY";
@@ -48,11 +48,12 @@ public interface Drawable {
case 11: return "GRESTORE";
case 12: return "CURRENT_SLIDE";
case 13: return "BUFFERED_IMAGE";
+ case 14: return "DEFAULT_CHARSET";
default: return "UNKNOWN_ID "+intKey();
}
}
}
-
+
/**
* {@link DrawFactory} which will be used to draw objects into this graphics context
*/
@@ -96,7 +97,7 @@ public interface Drawable {
* Internal key for caching the preset geometries
*/
DrawableHint PRESET_GEOMETRY_CACHE = new DrawableHint(6);
-
+
/**
* draw text via {@link java.awt.Graphics2D#drawString(java.text.AttributedCharacterIterator, float, float)}
*/
@@ -110,11 +111,11 @@ public interface Drawable {
/**
* Use this object to resolve unknown / missing fonts when rendering slides.
* The font handler must be of type {@link DrawFontManager}.<p>
- *
- * In case a {@code FONT_HANDLER} is register, {@code FONT_FALLBACK} and {@code FONT_MAP} are ignored
+ *
+ * In case a {@code FONT_HANDLER} is register, {@code FONT_FALLBACK} and {@code FONT_MAP} are ignored
*/
DrawableHint FONT_HANDLER = new DrawableHint(7);
-
+
/**
* Key for a font fallback map of type {@code Map<String,String>} which maps
* the original font family (key) to the fallback font family (value).
@@ -128,10 +129,10 @@ public interface Drawable {
* the original font family (key) to the mapped font family (value)
*/
DrawableHint FONT_MAP = new DrawableHint(9);
-
+
DrawableHint GSAVE = new DrawableHint(10);
DrawableHint GRESTORE = new DrawableHint(11);
-
+
/**
* The Common SL Draw API works sometimes cascading, but there are places
* where the current slide context need to be evaluated, e.g. when slide numbers
@@ -146,23 +147,31 @@ public interface Drawable {
DrawableHint BUFFERED_IMAGE = new DrawableHint(13);
/**
+ * Sets the default charset to render text elements.
+ * Opposed to other windows libraries in POI this simply defaults to Windows-1252.
+ * The rendering value is of type {@link java.nio.charset.Charset}
+ */
+ DrawableHint DEFAULT_CHARSET = new DrawableHint(14);
+
+
+ /**
* Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
*
* @param graphics the graphics whos transform matrix will be modified
*/
void applyTransform(Graphics2D graphics);
-
+
/**
* Draw this shape into the supplied canvas
*
* @param graphics the graphics to draw into
*/
void draw(Graphics2D graphics);
-
+
/**
* draw any content within this shape (image, text, etc.).
*
* @param graphics the graphics to draw into
*/
- void drawContent(Graphics2D graphics);
+ void drawContent(Graphics2D graphics);
}
diff --git a/src/java/org/apache/poi/sl/draw/ImageRenderer.java b/src/java/org/apache/poi/sl/draw/ImageRenderer.java
index 5051d4593b..6f255c72d0 100644
--- a/src/java/org/apache/poi/sl/draw/ImageRenderer.java
+++ b/src/java/org/apache/poi/sl/draw/ImageRenderer.java
@@ -25,6 +25,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.util.Dimension2DDouble;
@@ -154,4 +155,11 @@ public interface ImageRenderer {
default GenericRecord getGenericRecord() { return null; }
+ /**
+ * Sets the default charset to render text elements.
+ * Opposed to other windows libraries in POI this simply defaults to Windows-1252.
+ *
+ * @param defaultCharset the default charset
+ */
+ default void setDefaultCharset(Charset defaultCharset) {}
} \ No newline at end of file
diff --git a/src/java/org/apache/poi/util/GenericRecordJsonWriter.java b/src/java/org/apache/poi/util/GenericRecordJsonWriter.java
index 32a43c3a5e..c46a535a0b 100644
--- a/src/java/org/apache/poi/util/GenericRecordJsonWriter.java
+++ b/src/java/org/apache/poi/util/GenericRecordJsonWriter.java
@@ -26,6 +26,12 @@ import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DirectColorModel;
+import java.awt.image.IndexColorModel;
+import java.awt.image.PackedColorModel;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
@@ -58,6 +64,7 @@ public class GenericRecordJsonWriter implements Closeable {
private static final Pattern ESC_CHARS = Pattern.compile("[\"\\p{Cntrl}\\\\]");
private static final String NL = System.getProperty("line.separator");
+
@FunctionalInterface
protected interface GenericRecordHandler {
/**
@@ -92,6 +99,7 @@ public class GenericRecordJsonWriter implements Closeable {
handler(Path2D.class, GenericRecordJsonWriter::printPath);
handler(AffineTransform.class, GenericRecordJsonWriter::printAffineTransform);
handler(Color.class, GenericRecordJsonWriter::printColor);
+ handler(BufferedImage.class, GenericRecordJsonWriter::printImage);
handler(Array.class, GenericRecordJsonWriter::printArray);
handler(Object.class, GenericRecordJsonWriter::printObject);
}
@@ -483,6 +491,40 @@ public class GenericRecordJsonWriter implements Closeable {
return true;
}
+ protected boolean printImage(String name, Object o) {
+ BufferedImage img = (BufferedImage)o;
+
+ final String[] COLOR_SPACES = {
+ "XYZ","Lab","Luv","YCbCr","Yxy","RGB","GRAY","HSV","HLS","CMYK","Unknown","CMY","Unknown"
+ };
+
+ final String[] IMAGE_TYPES = {
+ "CUSTOM","INT_RGB","INT_ARGB","INT_ARGB_PRE","INT_BGR","3BYTE_BGR","4BYTE_ABGR","4BYTE_ABGR_PRE",
+ "USHORT_565_RGB","USHORT_555_RGB","BYTE_GRAY","USHORT_GRAY","BYTE_BINARY","BYTE_INDEXED"
+ };
+
+ printName(name);
+ ColorModel cm = img.getColorModel();
+ String colorType =
+ (cm instanceof IndexColorModel) ? "indexed" :
+ (cm instanceof ComponentColorModel) ? "component" :
+ (cm instanceof DirectColorModel) ? "direct" :
+ (cm instanceof PackedColorModel) ? "packed" : "unknown";
+ fw.write(
+ "{ \"width\": "+img.getWidth()+
+ ", \"height\": "+img.getHeight()+
+ ", \"type\": \""+IMAGE_TYPES[img.getType()]+"\""+
+ ", \"colormodel\": \""+colorType+"\""+
+ ", \"pixelBits\": "+cm.getPixelSize()+
+ ", \"numComponents\": "+cm.getNumComponents()+
+ ", \"colorSpace\": \""+COLOR_SPACES[Math.min(cm.getColorSpace().getType(),12)]+"\""+
+ ", \"transparency\": "+cm.getTransparency()+
+ ", \"alpha\": "+cm.hasAlpha()+
+ "}"
+ );
+ return true;
+ }
+
static String trimHex(final long l, final int size) {
final String b = Long.toHexString(l);
int len = b.length();