Skip to content

Commit

Permalink
Add SVG benchmarks (EchoSVG vs Batik)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosame committed Sep 23, 2024
1 parent 8ddb6bf commit 70b8424
Show file tree
Hide file tree
Showing 14 changed files with 12,314 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This project contains SVG files from the EchoSVG project:

Copyright 2020-2024 Contributors to the EchoSVG project
Copyright 1999-2020 The Apache Software Foundation
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DOM / SAC / CSSOM Benchmarks
# DOM / SAC / CSSOM / SVG Benchmarks

You can build and run the benchmarks in this repository with either Maven or Gradle, Java 11 or later is required:

Expand Down
19 changes: 16 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
Copyright (c) 2019-2024, C. Amengual.
Licensed under a BSD-style License. You can find the license here:
https://css4j.github.io/LICENSE.txt
*/

// SPDX-License-Identifier: BSD-3-Clause

plugins {
id 'java'
id 'maven-publish'
Expand All @@ -13,8 +24,7 @@ repositories {
releasesOnly()
}
content {
includeGroup 'io.sf.carte'
includeGroup 'io.sf.jclf'
includeGroupByRegex 'io\\.sf\\..*'
}
}
}
Expand All @@ -26,13 +36,16 @@ dependencies {
implementation 'io.sf.carte:css4j:4.4'
implementation(group: 'io.sf.carte', name: 'css4j', version: '4.4', classifier: 'tests')
implementation 'io.sf.carte:css4j-dom4j:4.2'
implementation 'io.sf.carte:echosvg-transcoder:1.2.2'
implementation 'org.apache.xmlgraphics:batik-transcoder:1.17'
implementation 'org.apache.xmlgraphics:batik-codec:1.17'
implementation 'nu.validator:htmlparser:1.4.16'
implementation 'org.jsoup:jsoup:1.17.1'
}

group = 'io.sf.carte'
version = '0.6'
description = 'JMH benchmark for CSS4J'
description = 'JMH benchmark for CSS4J and EchoSVG'
java.sourceCompatibility = JavaVersion.VERSION_11

sourceSets {
Expand Down
32 changes: 32 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@
<type>test-jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.sf.carte</groupId>
<artifactId>echosvg-transcoder</artifactId>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-codec</artifactId>
<version>1.17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nu.validator</groupId>
<artifactId>htmlparser</artifactId>
Expand Down Expand Up @@ -122,6 +140,12 @@
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<artifactSet>
<excludes>
<exclude>*:xml-apis</exclude>
<exclude>*:xml-apis-ext</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
Expand All @@ -130,6 +154,8 @@
<exclude>overview.html</exclude>
<exclude>META-INF/*.txt</exclude>
<exclude>META-INF/*.MF</exclude>
<exclude>META-INF/LICENSE</exclude>
<exclude>META-INF/NOTICE</exclude>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
Expand All @@ -139,6 +165,12 @@
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
<filter>
<artifact>org.apache.xmlgraphics:batik-script</artifact>
<excludes>
<exclude>META-INF/imports/*.txt</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
Expand Down
32 changes: 32 additions & 0 deletions resources/io/sf/carte/mark/svg/css/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
See the NOTICE file distributed with this work for additional
information regarding copyright ownership.
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.
*/

svg {
font-family: 'Roboto';
}
.title {
font-family: 'Open Sans', 'Roboto';
font-size: 16px;
text-anchor: middle;
}
.legend {
font-family: 'Open Sans', 'Roboto';
font-size: 10px;
text-anchor: middle;
}
11,463 changes: 11,463 additions & 0 deletions resources/io/sf/carte/mark/svg/issue91.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions resources/io/sf/carte/mark/svg/pooh3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions resources/io/sf/carte/mark/svg/useMultiple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions src/io/sf/carte/mark/svg/FontDecorationPainter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright (c) 2024, contributors to EchoSVG project.
Licensed under a BSD-style License. You can find the license here:
https://css4j.github.io/LICENSE.txt
*/

/*
* SPDX-License-Identifier: BSD-3-Clause
*/
package io.sf.carte.mark.svg;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.awt.font.TextAttribute;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
* Draw text with decoration attributes.
*/
public class FontDecorationPainter {

public void paint(Graphics2D g) {
// Set anti-aliasing
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

// Set a background color
Color backgroundColor = new Color(0x08081a);
g.setBackground(backgroundColor);

// Set default font
g.setFont(new Font("sans-serif", Font.BOLD, 12));

// Create a font with the desired attributes, including STRIKETHROUGH
Map<TextAttribute, Object> attributes = new HashMap<>();
attributes.put(TextAttribute.FAMILY, "serif");
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_EXTRABOLD);
attributes.put(TextAttribute.SIZE, 20);
Font fontS = new Font(attributes);

// A similar font
Map<TextAttribute, Object> attributes2 = new HashMap<>();
attributes.put(TextAttribute.FAMILY, "sans-serif");
Font fontSS = new Font(attributes2);

// Set the font and a color
g.setFont(fontS);
g.setPaint(new Color(0x666699));
// Draw a string
g.drawString("Hello!", 10, 40);

// Embed an image
BufferedImage image = createImage();
g.drawImage(image, 25, 60, new Color(0xcccccc), null);

// Now draw with a different color and the other font
g.setPaint(Color.black);
g.setFont(fontSS);
g.translate(0, 30);
// Draw a new string
g.drawString("Hi!", 10, 70);
}

private static BufferedImage createImage() {
// Create an Image
BufferedImage image = new BufferedImage(100, 75, BufferedImage.TYPE_INT_ARGB);

Graphics2D ig = image.createGraphics();
ig.scale(.5, .5);
ig.setPaint(new Color(128, 0, 0));
ig.fillRect(0, 0, 100, 50);
ig.setPaint(Color.orange);
ig.fillRect(100, 0, 100, 50);
ig.setPaint(Color.yellow);
ig.fillRect(0, 50, 100, 50);
ig.setPaint(Color.red);
ig.fillRect(100, 50, 100, 50);
ig.setPaint(new Color(255, 127, 127));
ig.fillRect(0, 100, 100, 50);
ig.setPaint(Color.black);
ig.draw(new Rectangle2D.Double(0.5, 0.5, 199, 149));
ig.dispose();

return image;
}

}
Loading

0 comments on commit 70b8424

Please sign in to comment.