Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of dashed polygons #1194

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ Occam Labs UG (haftungsbeschränkt)
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.apache.batik.transcoder.TranscoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.xerces.parsers.SAXParser;
Copy link
Member

@tfr42 tfr42 Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xerces has been removed from some modules from the compile time dependencies with PR #999. The direct import should be avoided. If possible any use of Xerces should be avoided.

import org.deegree.commons.utils.Pair;
import org.deegree.commons.utils.Triple;
import org.deegree.feature.Feature;
Expand All @@ -83,6 +85,8 @@ Occam Labs UG (haftungsbeschränkt)
import org.deegree.style.styling.components.Mark.SimpleMark;
import org.deegree.style.styling.components.Stroke;
import org.deegree.style.utils.ShapeHelper;
import org.deegree.style.utils.SvgImageTranscoder;
import org.deegree.style.utils.SvgImageTranscoder.SvgImageOutput;
import org.slf4j.Logger;

/**
Expand Down Expand Up @@ -372,6 +376,17 @@ private Triple<BufferedImage, String, Continuation<List<Pair<BufferedImage, Stri
if ( pair != null ) {
if ( pair.first != null && format != null && ( format.toLowerCase().indexOf( "svg" ) == -1 ) ) {
img = ImageIO.read( pair.first );
} else if ( pair.first != null && format != null && ( format.toLowerCase().indexOf( "svg" ) != -1 ) ) {
try {
SvgImageTranscoder trans = new SvgImageTranscoder();
SvgImageOutput tcOutput = trans.createOutput();
trans.setXmlParserClass(SAXParser.class.getName() );
trans.transcode( pair.first, pair.second, tcOutput );
img = tcOutput.getBufferedImage();
} catch ( TranscoderException te ) {
LOG.warn( "Failed reading external SVG-Graphic: {}", te.getMessage() );
LOG.trace("TranscoderException", te);
}
}
url = pair.second;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2010 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
and
- grit graphische Informationstechnik Beratungsgesellschaft mbH -

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contact information:

grit graphische Informationstechnik Beratungsgesellschaft mbH
Landwehrstr. 143, 59368 Werne
Germany
http://www.grit.de/

lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/

Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/

e-mail: [email protected]
----------------------------------------------------------------------------*/
package org.deegree.style.utils;

import java.awt.image.BufferedImage;
import java.io.InputStream;

import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.XMLAbstractTranscoder;
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SvgImageTranscoder extends ImageTranscoder {

public class SvgImageOutput extends TranscoderOutput {

private BufferedImage image;

public SvgImageOutput() {
}

public BufferedImage getBufferedImage() {
return this.image;
}

public void setImage( BufferedImage image ) {
this.image = image;
}
}

static final Logger LOG = LoggerFactory.getLogger( SvgImageTranscoder.class );

public SvgImageTranscoder() {
super();
}

public void setXmlParserClass( String clsName ) {
addTranscodingHint( XMLAbstractTranscoder.KEY_XML_PARSER_CLASSNAME, clsName );
}

@Override
public BufferedImage createImage( int w, int h ) {
return new BufferedImage( w, h, BufferedImage.TYPE_INT_ARGB );
}

@Override
public void writeImage( BufferedImage image, TranscoderOutput output )
throws TranscoderException {
if ( !( output instanceof SvgImageOutput ) ) {
throw new TranscoderException( "TranscoderOutput has to be of type BuffferedImageOutput" );
}

( (SvgImageOutput) output ).setImage( image );
}

public void transcode( InputStream input, String fileName, SvgImageOutput output )
throws TranscoderException {
long ts, te;
ts = System.currentTimeMillis();

super.transcode( new org.apache.batik.transcoder.TranscoderInput( input ), output );

te = System.currentTimeMillis();
LOG.info( "Loaded svg '{}' in {} ms", fileName, ( te - ts ) );
}

public SvgImageOutput createOutput() {
return new SvgImageOutput();
}
}