Skip to content

Commit

Permalink
Merge pull request #195 from metanorma/fop_config_path
Browse files Browse the repository at this point in the history
Fop config path
  • Loading branch information
Intelligent2013 authored Apr 18, 2023
2 parents 1d26435 + 6401989 commit a0dc7db
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL ?= /bin/bash
endif

#JAR_VERSION := $(shell mvn -q -Dexec.executable="echo" -Dexec.args='$${project.version}' --non-recursive exec:exec -DforceStdout)
JAR_VERSION := 1.67
JAR_VERSION := 1.68
JAR_FILE := mn2pdf-$(JAR_VERSION).jar

all: target/$(JAR_FILE)
Expand Down
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>1.67</version>
<version>1.68</version>
<name>Metanorma XML to PDF converter</name>
----

Expand All @@ -111,8 +111,8 @@ Tag the same version in Git:

[source,xml]
----
git tag v1.67
git push origin v1.67
git tag v1.68
git push origin v1.68
----

Then the corresponding GitHub release will be automatically created at:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.metanorma.fop</groupId>
<artifactId>mn2pdf</artifactId>
<version>1.67</version>
<version>1.68</version>
<name>Metanorma XML to PDF converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
279 changes: 279 additions & 0 deletions src/main/java/org/apache/fop/complexscripts/fonts/GlyphClassTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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$ */

package org.apache.fop.complexscripts.fonts;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

// CSOFF: LineLengthCheck

/**
* <p>Base class implementation of glyph class table.</p>
*
* <p>This work was originally authored by Glenn Adams ([email protected]).</p>
*/
public final class GlyphClassTable extends GlyphMappingTable implements GlyphClassMapping {

/** empty mapping table */
public static final int GLYPH_CLASS_TYPE_EMPTY = GLYPH_MAPPING_TYPE_EMPTY;

/** mapped mapping table */
public static final int GLYPH_CLASS_TYPE_MAPPED = GLYPH_MAPPING_TYPE_MAPPED;

/** range based mapping table */
public static final int GLYPH_CLASS_TYPE_RANGE = GLYPH_MAPPING_TYPE_RANGE;

/** empty mapping table */
public static final int GLYPH_CLASS_TYPE_COVERAGE_SET = 3;

private GlyphClassMapping cm;

private GlyphClassTable(GlyphClassMapping cm) {
assert cm != null;
assert cm instanceof GlyphMappingTable;
this.cm = cm;
}

/** {@inheritDoc} */
public int getType() {
return ((GlyphMappingTable) cm) .getType();
}

/** {@inheritDoc} */
public List getEntries() {
return ((GlyphMappingTable) cm) .getEntries();
}

/** {@inheritDoc} */
public int getClassSize(int set) {
return cm.getClassSize(set);
}

/** {@inheritDoc} */
public int getClassIndex(int gid, int set) {
return cm.getClassIndex(gid, set);
}

/**
* Create glyph class table.
* @param entries list of mapped or ranged class entries, or null or empty list
* @return a new covera table instance
*/
public static GlyphClassTable createClassTable(List entries) {
GlyphClassMapping cm;
if ((entries == null) || (entries.size() == 0)) {
cm = new EmptyClassTable(entries);
} else if (isMappedClass(entries)) {
cm = new MappedClassTable(entries);
} else if (isRangeClass(entries)) {
cm = new RangeClassTable(entries);
} else if (isCoverageSetClass(entries)) {
cm = new CoverageSetClassTable(entries);
} else {
cm = null;
}
assert cm != null : "unknown class type";
return new GlyphClassTable(cm);
}

private static boolean isMappedClass(List entries) {
if ((entries == null) || (entries.size() == 0)) {
return false;
} else {
for (Object o : entries) {
if (!(o instanceof Integer)) {
return false;
}
}
return true;
}
}

private static boolean isRangeClass(List entries) {
if ((entries == null) || (entries.size() == 0)) {
return false;
} else {
for (Object o : entries) {
if (!(o instanceof MappingRange)) {
return false;
}
}
return true;
}
}

private static boolean isCoverageSetClass(List entries) {
if ((entries == null) || (entries.size() == 0)) {
return false;
} else {
for (Object o : entries) {
if (!(o instanceof GlyphCoverageTable)) {
return false;
}
}
return true;
}
}

private static class EmptyClassTable extends GlyphMappingTable.EmptyMappingTable implements GlyphClassMapping {
public EmptyClassTable(List entries) {
super(entries);
}
/** {@inheritDoc} */
public int getClassSize(int set) {
return 0;
}
/** {@inheritDoc} */
public int getClassIndex(int gid, int set) {
return -1;
}
}

private static class MappedClassTable extends GlyphMappingTable.MappedMappingTable implements GlyphClassMapping {
private int firstGlyph;
private int[] gca;
private int gcMax = -1;
public MappedClassTable(List entries) {
populate(entries);
}
/** {@inheritDoc} */
public List getEntries() {
List entries = new java.util.ArrayList();
entries.add(firstGlyph);
if (gca != null) {
for (int aGca : gca) {
entries.add(aGca);
}
}
return entries;
}
/** {@inheritDoc} */
public int getMappingSize() {
return gcMax + 1;
}
/** {@inheritDoc} */
public int getMappedIndex(int gid) {
int i = gid - firstGlyph;
if ((i >= 0) && (i < gca.length)) {
return gca [ i ];
} else {
return -1;
}
}
/** {@inheritDoc} */
public int getClassSize(int set) {
return getMappingSize();
}
/** {@inheritDoc} */
public int getClassIndex(int gid, int set) {
return getMappedIndex(gid);
}
private void populate(List entries) {
// obtain entries iterator
Iterator it = entries.iterator();
// extract first glyph
int firstGlyph = 0;
if (it.hasNext()) {
Object o = it.next();
if (o instanceof Integer) {
firstGlyph = (Integer) o;
} else {
throw new AdvancedTypographicTableFormatException("illegal entry, first entry must be Integer denoting first glyph value, but is: " + o);
}
}
// extract glyph class array
int i = 0;
int n = entries.size() - 1;
int gcMax = -1;
int[] gca = new int [ n ];
while (it.hasNext()) {
Object o = it.next();
if (o instanceof Integer) {
int gc = (Integer) o;
gca [ i++ ] = gc;
if (gc > gcMax) {
gcMax = gc;
}
} else {
throw new AdvancedTypographicTableFormatException("illegal mapping entry, must be Integer: " + o);
}
}
assert i == n;
assert this.gca == null;
this.firstGlyph = firstGlyph;
this.gca = gca;
this.gcMax = gcMax;
}
/** {@inheritDoc} */
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("{ firstGlyph = " + firstGlyph + ", classes = {");
for (int i = 0, n = gca.length; i < n; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(Integer.toString(gca [ i ]));
}
sb.append("} }");
return sb.toString();
}
}

private static class RangeClassTable extends GlyphMappingTable.RangeMappingTable implements GlyphClassMapping {
public RangeClassTable(List entries) {
super(entries);
}
/** {@inheritDoc} */
public int getMappedIndex(int gid, int s, int m) {
return m;
}
/** {@inheritDoc} */
public int getClassSize(int set) {
return getMappingSize();
}
/** {@inheritDoc} */
public int getClassIndex(int gid, int set) {
return getMappedIndex(gid);
}
}

private static class CoverageSetClassTable extends GlyphMappingTable.EmptyMappingTable implements GlyphClassMapping {
private static final Log LOG = LogFactory.getLog(CoverageSetClassTable.class);
public CoverageSetClassTable(List entries) {
//LOG.warn("coverage set class table not yet supported");
}
/** {@inheritDoc} */
public int getType() {
return GLYPH_CLASS_TYPE_COVERAGE_SET;
}
/** {@inheritDoc} */
public int getClassSize(int set) {
return 0;
}
/** {@inheritDoc} */
public int getClassIndex(int gid, int set) {
return -1;
}
}

}
7 changes: 6 additions & 1 deletion src/main/java/org/apache/fop/fo/PropertyList.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.fop.fo.properties.CommonTextDecoration;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.PropertyMaker;
import org.apache.fop.fo.properties.StringProperty;

/**
* Class containing the collection of properties for a given FObj.
Expand Down Expand Up @@ -496,7 +497,11 @@ private void convertAttributeToProperty(Attributes attributes,
if (getExplicit(propId) != null) {
return;
}
prop = propertyMaker.make(this, attributeValue, parentFO);
if (attributeName.equals("fox:alt-text")) { //to prevent warning "String-valued property starts with quot..." for mathml fox:alt-text
prop = StringProperty.getInstance(attributeValue);
} else {
prop = propertyMaker.make(this, attributeValue, parentFO);
}
} else { // e.g. "leader-length.maximum"
Property baseProperty
= findBaseProperty(attributes, parentFO, propId,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/metanorma/fop/PDFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public boolean process() {

fontConfig fontcfg = new fontConfig();
fontcfg.setFontPath(fontsPath);
fontcfg.setFontConfigPath(fPDF.getAbsolutePath());

fontcfg.setFontManifest(fFontsManifest);

Expand Down Expand Up @@ -333,6 +334,7 @@ public boolean process() {
if (!DEBUG) {
sourceXMLDocument.flushTempPath();
xsltConverter.deleteTmpXSL();
fontcfg.deleteConfigFile();
}

logger.info("Success!");
Expand Down
Loading

0 comments on commit a0dc7db

Please sign in to comment.