Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
4df9708d
Commit
4df9708d
authored
Feb 21, 2019
by
Piotr Gawron
Browse files
export to svg contains viewBox information
parent
a5d9331e
Pipeline
#8914
passed with stage
in 10 minutes and 30 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
4df9708d
minerva
(
12.2.0
~
beta
.2
)
unstable
;
urgency
=
medium
*
Bug
fix
:
export
to
svg
contains
viewBox
info
(#
716
)
*
Bug
fix
:
import
from
sbml
with
layout
could
crash
when
two
elements
occupied
the
exact
same
position
(#
717
)
*
Bug
fix
:
overlays
added
via
API
couldn
't be visualized after refresh (#718)
...
...
converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/SvgImageGenerator.java
View file @
4df9708d
package
lcsb.mapviewer.converter.graphics
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
lcsb.mapviewer.common.MimeType
;
import
lcsb.mapviewer.common.exception.NotImplementedException
;
import
org.apache.batik.dom.GenericDOMImplementation
;
import
org.apache.batik.svggen.SVGGraphics2D
;
import
org.apache.batik.svggen.SVGGraphics2DIOException
;
import
org.w3c.dom.DOMImplementation
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
lcsb.mapviewer.common.MimeType
;
import
lcsb.mapviewer.common.exception.NotImplementedException
;
/**
* This class implements SVG generator for the image object.This class uses
...
...
@@ -21,6 +24,11 @@ import org.w3c.dom.Document;
*
*/
public
class
SvgImageGenerator
extends
AbstractImageGenerator
{
/**
* Root dom element. We need it to be able to provide viewBox.
*/
private
Element
root
;
@Override
protected
void
createImageObject
(
final
double
width
,
final
double
height
)
{
...
...
@@ -32,14 +40,17 @@ public class SvgImageGenerator extends AbstractImageGenerator {
String
svgNS
=
"http://www.w3.org/2000/svg"
;
Document
document
=
domImpl
.
createDocument
(
svgNS
,
"svg"
,
null
);
// Create an instance of the SVG Generator.
setGraphics
(
new
SVGGraphics2D
(
document
));
// Create an instance of the SVG Generator.
SVGGraphics2D
graphics
=
new
SVGGraphics2D
(
document
);
root
=
graphics
.
getRoot
();
root
.
setAttributeNS
(
null
,
"viewBox"
,
"0 0 "
+(
int
)
width
+
" "
+(
int
)
height
);
setGraphics
(
graphics
);
}
@Override
public
void
saveToFileImplementation
(
final
String
fileName
)
throws
SVGGraphics2D
IOException
{
((
SVGGraphics2D
)
getGraphics
()).
s
tream
(
fileName
);
public
void
saveToFileImplementation
(
final
String
fileName
)
throws
IOException
{
saveToOutputStreamImplementation
(
new
FileOutputS
tream
(
fileName
)
)
;
}
/**
...
...
@@ -63,8 +74,9 @@ public class SvgImageGenerator extends AbstractImageGenerator {
@Override
public
void
saveToOutputStreamImplementation
(
OutputStream
os
)
throws
IOException
{
((
SVGGraphics2D
)
getGraphics
()).
stream
(
new
OutputStreamWriter
(
os
));
//for some reason if you remove this line either viewbox is not define or content is not there
((
SVGGraphics2D
)
getGraphics
()).
getRoot
(
root
);
((
SVGGraphics2D
)
getGraphics
()).
stream
(
root
,
new
OutputStreamWriter
(
os
));
}
@Override
...
...
converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java
View file @
4df9708d
...
...
@@ -19,6 +19,7 @@ import lcsb.mapviewer.converter.graphics.placefinder.AllPlaceFinderTest;
MapGeneratorTest
.
class
,
NormalImageGeneratorTest
.
class
,
PdfImageGeneratorTest
.
class
,
SvgImageGeneratorTest
.
class
})
public
class
AllGraphicsTests
{
...
...
converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/SvgImageGeneratorTest.java
0 → 100644
View file @
4df9708d
package
lcsb.mapviewer.converter.graphics
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.ByteArrayOutputStream
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.model.map.model.ModelFullIndexed
;
import
lcsb.mapviewer.model.map.species.Complex
;
public
class
SvgImageGeneratorTest
extends
GraphicsTestFunctions
{
@Before
public
void
setUp
()
throws
Exception
{
}
@After
public
void
tearDown
()
throws
Exception
{
}
@Test
public
void
testSaveToFile
()
throws
Exception
{
try
{
Model
model
=
createCompartmentModel
();
SvgImageGenerator
sig
=
new
SvgImageGenerator
(
new
AbstractImageGenerator
.
Params
().
model
(
model
));
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
sig
.
saveToOutputStream
(
output
);
assertTrue
(
output
.
toString
().
contains
(
"viewBox"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
}
private
Model
createCompartmentModel
()
{
Model
model
=
new
ModelFullIndexed
(
null
);
model
.
setWidth
(
526
);
model
.
setHeight
(
346
);
Complex
alias
=
new
Complex
(
"1"
);
alias
.
setName
(
"a"
);
alias
.
setX
(
300
);
alias
.
setY
(
90
);
alias
.
setWidth
(
100
);
alias
.
setHeight
(
50
);
model
.
addElement
(
alias
);
return
model
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment