Skip to content

Commit c9c8ea9

Browse files
authored
Merge pull request #5 from dubinsky/master
FOP plugin
2 parents 4eb6983 + 3249f07 commit c9c8ea9

File tree

16 files changed

+1065
-4
lines changed

16 files changed

+1065
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ JEuclid
22
=========
33

44
This is a fork of http://jeuclid.sourceforge.net/ to get it working on JDK 9 and
5-
with Batik 1.9. Only the core is supported.
5+
with Batik 1.9. Only the core and the FOP plugin are supported.
66

77
FOP and SWT support is removed at the moment. If you need them or need any other feature
88
not provided with this distribution, feel free to send me a pull request.

jeuclid-core/src/main/java/net/sourceforge/jeuclid/converter/ConverterRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ private SingletonHolder() {
5252
*/
5353
@SuppressWarnings("unchecked")
5454
protected ConverterRegistry() {
55-
final Iterator<ConverterDetector> it = Service
55+
final Iterator<Object> it = Service
5656
.providers(ConverterDetector.class);
5757
while (it.hasNext()) {
58-
final ConverterDetector det = it.next();
58+
final ConverterDetector det = (ConverterDetector) it.next();
5959
det.detectConversionPlugins(this);
6060
}
6161
}

jeuclid-fop/pom.xml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>jeuclid-fop</artifactId>
5+
<name>JEuclid FOP Plugin</name>
6+
<parent>
7+
<groupId>de.rototor.jeuclid</groupId>
8+
<artifactId>jeuclid-parent</artifactId>
9+
<version>3.1.14-SNAPSHOT</version>
10+
</parent>
11+
<description>This module contains the FOP plugin to support MathML in FOP through JEuclid.
12+
</description>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<artifactId>maven-compiler-plugin</artifactId>
17+
<version>${maven-compiler-plugin.version}</version>
18+
<configuration>
19+
<source>1.6</source>
20+
<target>1.6</target>
21+
</configuration>
22+
</plugin>
23+
24+
<plugin>
25+
<groupId>org.apache.felix</groupId>
26+
<artifactId>maven-bundle-plugin</artifactId>
27+
<version>${maven-bundle-plugin.version}</version>
28+
<configuration>
29+
<instructions>
30+
<Export-Package>net.sourceforge.jeuclid.fop.plugin</Export-Package>
31+
</instructions>
32+
</configuration>
33+
<executions>
34+
<execution>
35+
<id>bundle-manifest</id>
36+
<phase>process-classes</phase>
37+
<goals>
38+
<goal>manifest</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
</plugin>
43+
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-jar-plugin</artifactId>
47+
<version>${maven-jar-plugin.version}</version>
48+
<configuration>
49+
<archive>
50+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
51+
</archive>
52+
</configuration>
53+
</plugin>
54+
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-gpg-plugin</artifactId>
58+
<version>1.6</version>
59+
<executions>
60+
<execution>
61+
<id>sign-artifacts</id>
62+
<phase>verify</phase>
63+
<goals>
64+
<goal>sign</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-source-plugin</artifactId>
73+
<version>3.0.1</version>
74+
<executions>
75+
<execution>
76+
<id>attach-sources</id>
77+
<goals>
78+
<goal>jar-no-fork</goal>
79+
</goals>
80+
</execution>
81+
</executions>
82+
</plugin>
83+
84+
<plugin>
85+
<groupId>org.sonatype.plugins</groupId>
86+
<artifactId>nexus-staging-maven-plugin</artifactId>
87+
<version>1.6.7</version>
88+
<extensions>true</extensions>
89+
<configuration>
90+
<serverId>ossrh</serverId>
91+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
92+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
93+
</configuration>
94+
</plugin>
95+
96+
<plugin>
97+
<groupId>org.apache.maven.plugins</groupId>
98+
<artifactId>maven-release-plugin</artifactId>
99+
<version>2.5.3</version>
100+
<configuration>
101+
<autoVersionSubmodules>true</autoVersionSubmodules>
102+
<useReleaseProfile>false</useReleaseProfile>
103+
<releaseProfiles>release</releaseProfiles>
104+
<goals>deploy</goals>
105+
<pushChanges>false</pushChanges>
106+
</configuration>
107+
</plugin>
108+
</plugins>
109+
</build>
110+
111+
<dependencies>
112+
<dependency>
113+
<groupId>de.rototor.jeuclid</groupId>
114+
<artifactId>jeuclid-core</artifactId>
115+
<version>${project.version}</version>
116+
</dependency>
117+
<dependency>
118+
<groupId>org.apache.xmlgraphics</groupId>
119+
<artifactId>fop</artifactId>
120+
<version>${fop.version}</version>
121+
</dependency>
122+
</dependencies>
123+
</project>
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Copyright 2007 - 2008 JEuclid, http://jeuclid.sf.net
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* $Id$ */
18+
19+
/*
20+
* Please note: This file was originally taken from the Apache FOP project,
21+
* available at http://xmlgraphics.apache.org/fop/ It is therefore
22+
* partially copyright (c) 1999-2007 The Apache Software Foundation.
23+
*
24+
* Parts of the contents are heavily inspired by work done for Barcode4J by
25+
* Jeremias Maerki, available at http://barcode4j.sf.net/
26+
*/
27+
28+
package net.sourceforge.jeuclid.fop;
29+
30+
import java.awt.Color;
31+
import java.awt.geom.Point2D;
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
35+
import net.sourceforge.jeuclid.Constants;
36+
import net.sourceforge.jeuclid.MutableLayoutContext;
37+
import net.sourceforge.jeuclid.context.LayoutContextImpl;
38+
import net.sourceforge.jeuclid.context.Parameter;
39+
import net.sourceforge.jeuclid.layout.JEuclidView;
40+
import net.sourceforge.jeuclid.xmlgraphics.PreloaderMathML;
41+
42+
import org.apache.fop.apps.FOPException;
43+
import org.apache.fop.apps.FOUserAgent;
44+
import org.apache.fop.datatypes.Length;
45+
import org.apache.fop.fo.FOEventHandler;
46+
import org.apache.fop.fo.FONode;
47+
import org.apache.fop.fo.PropertyList;
48+
import org.apache.fop.fo.properties.CommonFont;
49+
import org.apache.fop.fo.properties.FixedLength;
50+
import org.apache.fop.fo.properties.Property;
51+
import org.apache.fop.fonts.FontInfo;
52+
import org.apache.fop.fonts.FontTriplet;
53+
import org.w3c.dom.Document;
54+
import org.w3c.dom.Element;
55+
import org.xml.sax.Attributes;
56+
import org.xml.sax.Locator;
57+
58+
/**
59+
* Defines the top-level element for MathML.
60+
*
61+
* @version $Revision$
62+
*/
63+
public class JEuclidElement extends JEuclidObj {
64+
65+
private Point2D size;
66+
67+
private Length baseline;
68+
69+
private final MutableLayoutContext layoutContext;
70+
71+
/**
72+
* Default constructor.
73+
*
74+
* @param parent
75+
* Parent Node in the FO tree.
76+
*/
77+
public JEuclidElement(final FONode parent) {
78+
super(parent);
79+
this.layoutContext = new LayoutContextImpl(LayoutContextImpl
80+
.getDefaultLayoutContext());
81+
}
82+
83+
/** {@inheritDoc} */
84+
@Override
85+
public void processNode(final String elementName, final Locator locator,
86+
final Attributes attlist, final PropertyList propertyList)
87+
throws FOPException {
88+
super.processNode(elementName, locator, attlist, propertyList);
89+
final Document d = this.createBasicDocument();
90+
final Element e = d.getDocumentElement();
91+
for (final Parameter p : Parameter.values()) {
92+
final String localName = p.getOptionName();
93+
final String attrName = "jeuclid:" + localName;
94+
final String isSet = e.getAttributeNS(Constants.NS_JEUCLID_EXT,
95+
localName);
96+
if ((isSet == null) || (isSet.length() == 0)) {
97+
e.setAttributeNS(Constants.NS_JEUCLID_EXT, attrName, p
98+
.toString(this.layoutContext.getParameter(p)));
99+
}
100+
}
101+
}
102+
103+
private void calculate() {
104+
final JEuclidView view = new JEuclidView(this.doc, this.layoutContext,
105+
null);
106+
final float descent = view.getDescentHeight();
107+
this.size = new Point2D.Float(view.getWidth(), view.getAscentHeight()
108+
+ descent);
109+
this.baseline = FixedLength.getInstance(-descent, "pt");
110+
}
111+
112+
/** {@inheritDoc} */
113+
@Override
114+
public Point2D getDimension(final Point2D view) {
115+
if (this.size == null) {
116+
this.calculate();
117+
}
118+
return this.size;
119+
}
120+
121+
/** {@inheritDoc} */
122+
@Override
123+
public Length getIntrinsicAlignmentAdjust() {
124+
if (this.baseline == null) {
125+
this.calculate();
126+
}
127+
return this.baseline;
128+
}
129+
130+
/** {@inheritDoc} */
131+
@SuppressWarnings("unchecked")
132+
@Override
133+
protected PropertyList createPropertyList(final PropertyList pList,
134+
final FOEventHandler foEventHandler) throws FOPException {
135+
final FOUserAgent userAgent = this.getUserAgent();
136+
final CommonFont commonFont = pList.getFontProps();
137+
final float msize = (float) (commonFont.fontSize.getNumericValue() / PreloaderMathML.MPT_FACTOR);
138+
final Property colorProp = pList
139+
.get(org.apache.fop.fo.Constants.PR_COLOR);
140+
if (colorProp != null) {
141+
final Color color = colorProp.getColor(userAgent);
142+
this.layoutContext.setParameter(Parameter.MATHCOLOR, color);
143+
}
144+
final Property bcolorProp = pList
145+
.get(org.apache.fop.fo.Constants.PR_BACKGROUND_COLOR);
146+
if (bcolorProp != null) {
147+
final Color bcolor = bcolorProp.getColor(userAgent);
148+
this.layoutContext.setParameter(Parameter.MATHBACKGROUND, bcolor);
149+
}
150+
final FontInfo fi = this.getFOEventHandler().getFontInfo();
151+
final FontTriplet[] fontkeys = commonFont.getFontState(fi);
152+
153+
this.layoutContext.setParameter(Parameter.MATHSIZE, msize);
154+
final List<String> defaultFonts = (List<String>) this.layoutContext
155+
.getParameter(Parameter.FONTS_SERIF);
156+
final List<String> newFonts = new ArrayList<String>(fontkeys.length
157+
+ defaultFonts.size());
158+
for (final FontTriplet t : fontkeys) {
159+
newFonts.add(t.getName());
160+
}
161+
newFonts.addAll(defaultFonts);
162+
this.layoutContext.setParameter(Parameter.FONTS_SERIF, newFonts);
163+
return super.createPropertyList(pList, foEventHandler);
164+
}
165+
}

0 commit comments

Comments
 (0)