From: Andreas Beeker Date: Fri, 10 May 2019 20:55:24 +0000 (+0000) Subject: #59004 - HSLF rendering - adjust values for presetShapeDefinition differs in HSLF... X-Git-Tag: REL_4_1_1~110 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=049baa86d7509e05d27b17342eddb30d727d7c02;p=poi.git #59004 - HSLF rendering - adjust values for presetShapeDefinition differs in HSLF/XSLF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859102 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java index eacc6ed806..d535d71fa6 100644 --- a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java @@ -307,98 +307,39 @@ public class DrawSimpleShape extends DrawShape { , Paint fill , Paint line ) { - Shadow shadow = getShape().getShadow(); - if (shadow == null || (fill == null && line == null)) { - return; - } - - SolidPaint shadowPaint = shadow.getFillStyle(); - Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor()); - - double shapeRotation = getShape().getRotation(); - if(getShape().getFlipVertical()) { - shapeRotation += 180; - } - double angle = shadow.getAngle() - shapeRotation; - double dist = shadow.getDistance(); - double dx = dist * Math.cos(Math.toRadians(angle)); - double dy = dist * Math.sin(Math.toRadians(angle)); - - graphics.translate(dx, dy); - - for(Outline o : outlines){ - java.awt.Shape s = o.getOutline(); - Path p = o.getPath(); - graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s); - graphics.setPaint(shadowColor); - - if(fill != null && p.isFilled()){ - fillPaintWorkaround(graphics, s); - } else if (line != null && p.isStroked()) { - graphics.draw(s); - } - } - - graphics.translate(-dx, -dy); - } - - protected static CustomGeometry getCustomGeometry(String name) { - return getCustomGeometry(name, null); - } + Shadow shadow = getShape().getShadow(); + if (shadow == null || (fill == null && line == null)) { + return; + } - protected static CustomGeometry getCustomGeometry(String name, Graphics2D graphics) { - @SuppressWarnings("unchecked") - Map presets = (graphics == null) - ? null - : (Map)graphics.getRenderingHint(Drawable.PRESET_GEOMETRY_CACHE); + SolidPaint shadowPaint = shadow.getFillStyle(); + Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor()); - if (presets == null) { - presets = new HashMap<>(); - if (graphics != null) { - graphics.setRenderingHint(Drawable.PRESET_GEOMETRY_CACHE, presets); - } + double shapeRotation = getShape().getRotation(); + if (getShape().getFlipVertical()) { + shapeRotation += 180; + } + double angle = shadow.getAngle() - shapeRotation; + double dist = shadow.getDistance(); + double dx = dist * Math.cos(Math.toRadians(angle)); + double dy = dist * Math.sin(Math.toRadians(angle)); - String packageName = "org.apache.poi.sl.draw.binding"; - InputStream presetIS = Drawable.class.getResourceAsStream("presetShapeDefinitions.xml"); + graphics.translate(dx, dy); - // StAX: - EventFilter startElementFilter = new EventFilter() { - @Override - public boolean accept(XMLEvent event) { - return event.isStartElement(); - } - }; - - try { - XMLInputFactory staxFactory = StaxHelper.newXMLInputFactory(); - XMLEventReader staxReader = staxFactory.createXMLEventReader(presetIS); - XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter); - // Ignore StartElement: - staxFiltRd.nextEvent(); - // JAXB: - JAXBContext jaxbContext = JAXBContext.newInstance(packageName); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - - while (staxFiltRd.peek() != null) { - StartElement evRoot = (StartElement)staxFiltRd.peek(); - String cusName = evRoot.getName().getLocalPart(); - // XMLEvent ev = staxReader.nextEvent(); - JAXBElement el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class); - CTCustomGeometry2D cusGeom = el.getValue(); - - presets.put(cusName, new CustomGeometry(cusGeom)); - } + for (Outline o : outlines) { + java.awt.Shape s = o.getOutline(); + Path p = o.getPath(); + graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s); + graphics.setPaint(shadowColor); - staxFiltRd.close(); - staxReader.close(); - } catch (Exception e) { - throw new RuntimeException("Unable to load preset geometries.", e); - } finally { - IOUtils.closeQuietly(presetIS); + if (fill != null && p.isFilled()) { + fillPaintWorkaround(graphics, s); + } else if (line != null && p.isStroked()) { + graphics.draw(s); } } - return presets.get(name); + graphics.translate(-dx, -dy); } protected Collection computeOutlines(Graphics2D graphics) { diff --git a/src/java/org/apache/poi/sl/draw/geom/Context.java b/src/java/org/apache/poi/sl/draw/geom/Context.java index 3ed84b3d18..3ac4495929 100644 --- a/src/java/org/apache/poi/sl/draw/geom/Context.java +++ b/src/java/org/apache/poi/sl/draw/geom/Context.java @@ -51,8 +51,7 @@ public class Context { } Guide getAdjustValue(String name){ - // ignore HSLF props for now ... the results with default value are usually better - see #59004 - return (_props.getClass().getName().contains("hslf")) ? null : _props.getAdjustValue(name); + return _props.getAdjustValue(name); } public double getValue(String key){ diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java index acabc68715..55d3932d02 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java @@ -321,8 +321,10 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape