Skip to content

Commit

Permalink
Merge pull request #5 from dubinsky/master
Browse files Browse the repository at this point in the history
FOP plugin
  • Loading branch information
rototor authored Feb 15, 2019
2 parents 4eb6983 + 3249f07 commit c9c8ea9
Show file tree
Hide file tree
Showing 16 changed files with 1,065 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ JEuclid
=========

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

FOP and SWT support is removed at the moment. If you need them or need any other feature
not provided with this distribution, feel free to send me a pull request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ private SingletonHolder() {
*/
@SuppressWarnings("unchecked")
protected ConverterRegistry() {
final Iterator<ConverterDetector> it = Service
final Iterator<Object> it = Service
.providers(ConverterDetector.class);
while (it.hasNext()) {
final ConverterDetector det = it.next();
final ConverterDetector det = (ConverterDetector) it.next();
det.detectConversionPlugins(this);
}
}
Expand Down
123 changes: 123 additions & 0 deletions jeuclid-fop/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>
<artifactId>jeuclid-fop</artifactId>
<name>JEuclid FOP Plugin</name>
<parent>
<groupId>de.rototor.jeuclid</groupId>
<artifactId>jeuclid-parent</artifactId>
<version>3.1.14-SNAPSHOT</version>
</parent>
<description>This module contains the FOP plugin to support MathML in FOP through JEuclid.
</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-plugin.version}</version>
<configuration>
<instructions>
<Export-Package>net.sourceforge.jeuclid.fop.plugin</Export-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
<pushChanges>false</pushChanges>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>de.rototor.jeuclid</groupId>
<artifactId>jeuclid-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>${fop.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright 2007 - 2008 JEuclid, http://jeuclid.sf.net
*
* 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.
*/

/* $Id$ */

/*
* Please note: This file was originally taken from the Apache FOP project,
* available at http://xmlgraphics.apache.org/fop/ It is therefore
* partially copyright (c) 1999-2007 The Apache Software Foundation.
*
* Parts of the contents are heavily inspired by work done for Barcode4J by
* Jeremias Maerki, available at http://barcode4j.sf.net/
*/

package net.sourceforge.jeuclid.fop;

import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;

import net.sourceforge.jeuclid.Constants;
import net.sourceforge.jeuclid.MutableLayoutContext;
import net.sourceforge.jeuclid.context.LayoutContextImpl;
import net.sourceforge.jeuclid.context.Parameter;
import net.sourceforge.jeuclid.layout.JEuclidView;
import net.sourceforge.jeuclid.xmlgraphics.PreloaderMathML;

import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.datatypes.Length;
import org.apache.fop.fo.FOEventHandler;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.fo.properties.FixedLength;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;

/**
* Defines the top-level element for MathML.
*
* @version $Revision$
*/
public class JEuclidElement extends JEuclidObj {

private Point2D size;

private Length baseline;

private final MutableLayoutContext layoutContext;

/**
* Default constructor.
*
* @param parent
* Parent Node in the FO tree.
*/
public JEuclidElement(final FONode parent) {
super(parent);
this.layoutContext = new LayoutContextImpl(LayoutContextImpl
.getDefaultLayoutContext());
}

/** {@inheritDoc} */
@Override
public void processNode(final String elementName, final Locator locator,
final Attributes attlist, final PropertyList propertyList)
throws FOPException {
super.processNode(elementName, locator, attlist, propertyList);
final Document d = this.createBasicDocument();
final Element e = d.getDocumentElement();
for (final Parameter p : Parameter.values()) {
final String localName = p.getOptionName();
final String attrName = "jeuclid:" + localName;
final String isSet = e.getAttributeNS(Constants.NS_JEUCLID_EXT,
localName);
if ((isSet == null) || (isSet.length() == 0)) {
e.setAttributeNS(Constants.NS_JEUCLID_EXT, attrName, p
.toString(this.layoutContext.getParameter(p)));
}
}
}

private void calculate() {
final JEuclidView view = new JEuclidView(this.doc, this.layoutContext,
null);
final float descent = view.getDescentHeight();
this.size = new Point2D.Float(view.getWidth(), view.getAscentHeight()
+ descent);
this.baseline = FixedLength.getInstance(-descent, "pt");
}

/** {@inheritDoc} */
@Override
public Point2D getDimension(final Point2D view) {
if (this.size == null) {
this.calculate();
}
return this.size;
}

/** {@inheritDoc} */
@Override
public Length getIntrinsicAlignmentAdjust() {
if (this.baseline == null) {
this.calculate();
}
return this.baseline;
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected PropertyList createPropertyList(final PropertyList pList,
final FOEventHandler foEventHandler) throws FOPException {
final FOUserAgent userAgent = this.getUserAgent();
final CommonFont commonFont = pList.getFontProps();
final float msize = (float) (commonFont.fontSize.getNumericValue() / PreloaderMathML.MPT_FACTOR);
final Property colorProp = pList
.get(org.apache.fop.fo.Constants.PR_COLOR);
if (colorProp != null) {
final Color color = colorProp.getColor(userAgent);
this.layoutContext.setParameter(Parameter.MATHCOLOR, color);
}
final Property bcolorProp = pList
.get(org.apache.fop.fo.Constants.PR_BACKGROUND_COLOR);
if (bcolorProp != null) {
final Color bcolor = bcolorProp.getColor(userAgent);
this.layoutContext.setParameter(Parameter.MATHBACKGROUND, bcolor);
}
final FontInfo fi = this.getFOEventHandler().getFontInfo();
final FontTriplet[] fontkeys = commonFont.getFontState(fi);

this.layoutContext.setParameter(Parameter.MATHSIZE, msize);
final List<String> defaultFonts = (List<String>) this.layoutContext
.getParameter(Parameter.FONTS_SERIF);
final List<String> newFonts = new ArrayList<String>(fontkeys.length
+ defaultFonts.size());
for (final FontTriplet t : fontkeys) {
newFonts.add(t.getName());
}
newFonts.addAll(defaultFonts);
this.layoutContext.setParameter(Parameter.FONTS_SERIF, newFonts);
return super.createPropertyList(pList, foEventHandler);
}
}
Loading

0 comments on commit c9c8ea9

Please sign in to comment.