Skip to content

Commit

Permalink
Split the transcoder module in 4 modules: api, svg, svg2svg and tosvg
Browse files Browse the repository at this point in the history
Sometimes an SVG library is embedded into an executable, and a common concern
for both EchoSVG and Batik users in those cases is to make the size of the
embedded modules as small as possible.

Notably, in the case of the Transcoder a number of unneeded classes may be
included. For an example of such concern see

eclipse-platform/eclipse.platform.swt#1438 (comment)

The current `transcoder` module was designed as a monolithic do-it-all package,
with users always carrying code that they do not intend to run. But it can be
split in several submodules, in a way that backwards compatibility is kept (the
old `transcoder` module still exists and provides all the classes), so users
willing to minimize their dependencies can choose a smaller specific sub-module.

This commit splits the transcoder in 4 modules:

- `transcoder-api` (API)
- `transcoder-svg` (SVG to image)
- `transcoder-svg2svg` (SVG to SVG)
- `transcoder-tosvg` (conversions to SVG, currently only WMF to SVG)

In the typical case of rendering SVG as a PNG, the current 2.0 transcoder with
dependencies fills a jar of 6.26 MB, while the specific SVG-to-image transcoder
becomes a bit smaller (5.98 MB).

The gains are higher for the WMF to SVG case (3.94 MB) or the SVG-to-SVG (3.60
MB). Note that there is plenty of room for improvement in conversions to SVG,
because the current code uses the SVG DOM implementation provided by the `anim`
module (with all its dependencies) but the JDK DOM implementation could be used
instead (like in the EchoSVG Wiki example for `SVGGraphics2D`).
  • Loading branch information
carlosame committed Dec 19, 2024
1 parent 8f457be commit e1eea74
Show file tree
Hide file tree
Showing 92 changed files with 317 additions and 55 deletions.
29 changes: 29 additions & 0 deletions echosvg-all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ dependencies {
api project(':echosvg-swing')
api project(':echosvg-slideshow')
api project(':echosvg-svgpp')
api project(':echosvg-transcoder')
api project(':echosvg-transcoder-api')
api project(':echosvg-transcoder-svg')
api project(':echosvg-transcoder-svg2svg')
api project(':echosvg-transcoder-tosvg')
api project(':echosvg-ttf2svg')
api project(':echosvg-svgrasterizer')

Expand All @@ -40,6 +45,10 @@ dependencies {
jacocoAggregation project(':echosvg-swing')
jacocoAggregation project(':echosvg-test')
jacocoAggregation project(':echosvg-transcoder')
jacocoAggregation project(':echosvg-transcoder-api')
jacocoAggregation project(':echosvg-transcoder-svg')
jacocoAggregation project(':echosvg-transcoder-svg2svg')
jacocoAggregation project(':echosvg-transcoder-tosvg')
jacocoAggregation project(':echosvg-ttf2svg')
jacocoAggregation project(':echosvg-util')
jacocoAggregation project(':echosvg-xml')
Expand Down Expand Up @@ -207,6 +216,26 @@ tasks.register('prepareModularSources') {
include(name: '**/*')
}
}
ant.copy(todir: "$buildDir/src/io.sf.carte.echosvg.transcoder.api") {
fileset(dir: "$rootDir/echosvg-transcoder-api/src/main/java") {
include(name: '**/*')
}
}
ant.copy(todir: "$buildDir/src/io.sf.carte.echosvg.transcoder.svg") {
fileset(dir: "$rootDir/echosvg-transcoder-svg/src/main/java") {
include(name: '**/*')
}
}
ant.copy(todir: "$buildDir/src/io.sf.carte.echosvg.transcoder.svg2svg") {
fileset(dir: "$rootDir/echosvg-transcoder-svg2svg/src/main/java") {
include(name: '**/*')
}
}
ant.copy(todir: "$buildDir/src/io.sf.carte.echosvg.transcoder.tosvg") {
fileset(dir: "$rootDir/echosvg-transcoder-tosvg/src/main/java") {
include(name: '**/*')
}
}
ant.copy(todir: "$buildDir/src/io.sf.carte.echosvg.ttf2svg") {
fileset(dir: "$rootDir/echosvg-ttf2svg/src/main/java") {
include(name: '**/*')
Expand Down
4 changes: 4 additions & 0 deletions echosvg-all/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
requires transitive io.sf.carte.echosvg.svgpp;
requires transitive io.sf.carte.echosvg.swing;
requires transitive io.sf.carte.echosvg.transcoder;
requires transitive io.sf.carte.echosvg.transcoder.api;
requires transitive io.sf.carte.echosvg.transcoder.svg;
requires transitive io.sf.carte.echosvg.transcoder.svg2svg;
requires transitive io.sf.carte.echosvg.transcoder.tosvg;
requires transitive io.sf.carte.echosvg.ttf2svg;
requires transitive io.sf.carte.echosvg.util;
requires transitive io.sf.carte.echosvg.util.gui;
Expand Down
3 changes: 2 additions & 1 deletion echosvg-svgpp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ plugins {
}

dependencies {
implementation project(':echosvg-transcoder')
implementation project(':echosvg-transcoder-svg2svg')
implementation project(':echosvg-i18n')
}

description = 'io.sf.carte:echosvg-svgpp'
Expand Down
3 changes: 2 additions & 1 deletion echosvg-svgpp/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*
*/

/**
* SVG Pretty Printer Application.
*/
Expand All @@ -24,7 +25,7 @@
exports io.sf.carte.echosvg.apps.svgpp;

requires io.sf.carte.echosvg.i18n;
requires io.sf.carte.echosvg.transcoder;
requires io.sf.carte.echosvg.transcoder.svg2svg;

requires java.xml;

Expand Down
2 changes: 1 addition & 1 deletion echosvg-svgrasterizer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sourceSets {
}

dependencies {
api project(':echosvg-transcoder')
api project(':echosvg-transcoder-svg')
testImplementation project(':echosvg-test')
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.List;
import java.util.Map;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.Transcoder;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscoderOutput;
Expand All @@ -42,6 +41,7 @@
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.image.JPEGTranscoder;
import io.sf.carte.echosvg.transcoder.image.PNGTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;
import io.sf.carte.echosvg.util.ParsedURL;

/**
Expand Down
2 changes: 1 addition & 1 deletion echosvg-svgrasterizer/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
module io.sf.carte.echosvg.svgrasterizer {
exports io.sf.carte.echosvg.apps.rasterizer;

requires transitive io.sf.carte.echosvg.transcoder;
requires transitive io.sf.carte.echosvg.transcoder.svg;
requires io.sf.carte.echosvg.i18n;

requires transitive java.desktop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
import io.sf.carte.echosvg.test.TestUtil;
import io.sf.carte.echosvg.test.image.ImageCompareUtil;
import io.sf.carte.echosvg.test.image.TempImageFiles;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.Transcoder;
import io.sf.carte.echosvg.transcoder.TranscodingHints;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.XMLAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.image.JPEGTranscoder;
import io.sf.carte.echosvg.transcoder.image.PNGTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Validates the operation of the <code>SVGRasterizer</code>. It validates the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

import org.w3c.dom.Document;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscoderOutput;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.test.DummyErrorHandler;
import io.sf.carte.echosvg.transcoder.util.CSSTranscodingHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.net.URL;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Checks for regressions in rendering of SVG with alternate style sheets and/or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package io.sf.carte.echosvg.test.svg;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Checks for regressions in rendering of SVG with varying resolution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Checks for regressions in rendering of a document with a given alternate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package io.sf.carte.echosvg.test.svg;

import io.sf.carte.echosvg.transcoder.ErrorHandler;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.test.DummyErrorHandler;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Checks for regressions in rendering of a document with a given media.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import io.sf.carte.echosvg.test.TestLocations;
import io.sf.carte.echosvg.test.image.ImageComparator;
import io.sf.carte.echosvg.transcoder.ErrorHandler;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscoderOutput;
import io.sf.carte.echosvg.transcoder.XMLAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.image.PNGTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;
import io.sf.carte.echosvg.util.SVGConstants;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import java.io.InputStream;

import io.sf.carte.echosvg.transcoder.ErrorHandler;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscoderOutput;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.image.PNGTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.test.DummyErrorHandler;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package io.sf.carte.echosvg.test.svg;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.XMLAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Checks for regressions in rendering of SVG inside an XHTML document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_AOI transcoding hint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.test.TestFonts;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_ALTERNATE_STYLESHEET transcoding hint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.test.TestFonts;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_DEFAULT_FONT_FAMILY transcoding hint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_WIDTH and/or the KEY_HEIGHT transcoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_LANGUAGE transcoding hint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_MAX_WIDTH and/or the KEY_MAX_HEIGHT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.test.TestFonts;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_MEDIA transcoding hint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

import org.junit.jupiter.api.Test;

import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.TranscoderException;
import io.sf.carte.echosvg.transcoder.TranscoderInput;
import io.sf.carte.echosvg.transcoder.TranscodingHints.Key;
import io.sf.carte.echosvg.transcoder.svg.SVGAbstractTranscoder;

/**
* Test the ImageTranscoder with the KEY_RESOLUTION_DPI transcoding hint.
Expand Down
13 changes: 13 additions & 0 deletions echosvg-transcoder-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id 'echosvg.java-conventions'
}

dependencies {
implementation project(':echosvg-anim')
}

description = 'io.sf.carte:echosvg-transcoder-api'

publishing.publications.maven(MavenPublication).pom {
description = "EchoSVG SVG transcoder API"
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public abstract class AbstractTranscoder extends TranscoderSupport implements Tr
*/
protected AbstractTranscoder() {
}

}
29 changes: 29 additions & 0 deletions echosvg-transcoder-api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2020-2024 Carlos Amengual
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Transcoder API.
*/
module io.sf.carte.echosvg.transcoder.api {

exports io.sf.carte.echosvg.transcoder;
exports io.sf.carte.echosvg.transcoder.keys;

requires io.sf.carte.echosvg.anim;

requires transitive java.desktop;

}
Loading

0 comments on commit e1eea74

Please sign in to comment.