[FOray-commit] SF.net SVN: foray:[11314] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2017-01-14 03:08:21
|
Revision: 11314
http://sourceforge.net/p/foray/code/11314
Author: victormote
Date: 2017-01-14 03:08:18 +0000 (Sat, 14 Jan 2017)
Log Message:
-----------
Conform to axsl changes -- Convert uses of ULocale to new Orthography interface for the same purpose, but allowing client code to provide the information through an interface.
Modified Paths:
--------------
trunk/foray/foray-all/pom.xml
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationLastArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TTFTableGSUB.java
trunk/foray/foray-font/src/main/java/org/foray/font/output/FontPdf4a.java
trunk/foray/foray-font/src/test/java/org/foray/font/TestFont4a.java
trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OTFLookupGSUBTests.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FOLineText.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Character.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFGraphics2D.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFTextPainter.java
trunk/foray/foray-hyphen/pom.xml
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationConsumer4a.java
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationServer4a.java
trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationConsumer4aTests.java
trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationServer4aTests.java
trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java
trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/solitary/SolitaryLineBreaker.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PDFContentStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PDFString.java
trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PDFRenderer.java
trunk/foray/foray-render/src/main/java/org/foray/render/ps/PSRenderer.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Orthography4a.java
Modified: trunk/foray/foray-all/pom.xml
===================================================================
--- trunk/foray/foray-all/pom.xml 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-all/pom.xml 2017-01-14 03:08:18 UTC (rev 11314)
@@ -241,6 +241,14 @@
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.ibm.icu</groupId>
+ <artifactId>icu4j</artifactId>
+ <version>58.2</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+
<!-- aXSL dependencies. -->
<dependency>
<groupId>org.axsl</groupId>
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestBlock.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -39,6 +39,7 @@
import org.foray.area.PageCollection;
import org.foray.area.TextArea;
import org.foray.common.FontOptions4a;
+import org.foray.common.i18n.Orthography4a;
import org.foray.core.FOrayException;
import org.axsl.font.FontException;
@@ -47,8 +48,6 @@
import org.junit.Before;
import org.junit.Test;
-import com.ibm.icu.util.ULocale;
-
/**
* Tests of various block-related concepts at the Area Tree level.
*/
@@ -290,7 +289,7 @@
/* The following computation is tested in {@link TestFont4a#testWidth()}. */
final String testString = "Test of Centering";
final int textWidth = fontUse.width(
- testString, 0, testString.length(), 12000, 0, 0, this.fontOptionsWithKerning, ULocale.US);
+ testString, 0, testString.length(), 12000, 0, 0, this.fontOptionsWithKerning, Orthography4a.USA);
assertEquals(textWidth, textArea.crIpd());
/* The x value of the text area content rectangle should be at the x
@@ -354,7 +353,7 @@
* The extra word spacing is .3em = .3 * 12000 = 3600. */
final String testString = "Centered with Word Spacing";
final int textWidth = fontUse.width(testString, 0, testString.length(), 12000, 0, 3600,
- this.fontOptionsWithKerning, ULocale.US);
+ this.fontOptionsWithKerning, Orthography4a.USA);
assertEquals(textWidth, textArea.crIpd());
/* The x value of the text area content rectangle should be at the x
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,7 +28,10 @@
package org.foray.area;
+import org.foray.common.i18n.Orthography4a;
+
import org.axsl.area.AreaTreeException;
+import org.axsl.common.i18n.Orthography;
import org.axsl.fo.fo.BasicLink;
import org.axsl.fo.fo.BidiOverride;
import org.axsl.fo.fo.CharacterSequence;
@@ -45,8 +48,6 @@
import org.axsl.fo.fo.ScalingValueCitation;
import org.axsl.font.FontOptions;
-import com.ibm.icu.util.ULocale;
-
import java.util.ArrayList;
import java.util.List;
@@ -219,12 +220,12 @@
}
/**
- * Returns the locale.
- * @return The locale.
+ * Returns the orthography.
+ * @return The orthography.
*/
- public ULocale locale() {
+ public Orthography orthography() {
/* TODO: Get this from the FOTree. */
- return ULocale.US;
+ return Orthography4a.USA;
}
}
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberArea.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberArea.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -239,7 +239,7 @@
final FontUse fontUse = getPrimaryFont();
fontUse.registerCharsUsed(word);
return fontUse.width(word, 0, word.length(), traitFontSize(), traitGeneratedBy().traitLetterSpacingOpt(this),
- traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), locale());
+ traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), orthography());
}
@Override
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationArea.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationArea.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -266,7 +266,7 @@
final FontUse fontUse = getPrimaryFont();
fontUse.registerCharsUsed(word);
return fontUse.width(word, 0, word.length(), traitFontSize(), traitGeneratedBy().traitLetterSpacingOpt(this),
- traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), locale());
+ traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), orthography());
}
@Override
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationLastArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationLastArea.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/PageNumberCitationLastArea.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -267,7 +267,7 @@
final FontUse fontUse = getPrimaryFont();
fontUse.registerCharsUsed(word);
return fontUse.width(word, 0, word.length(), traitFontSize(), traitGeneratedBy().traitLetterSpacingOpt(this),
- traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), locale());
+ traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), orthography());
}
@Override
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/ScalingValueCitationArea.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,7 +28,10 @@
package org.foray.area;
+import org.foray.common.i18n.Orthography4a;
+
import org.axsl.area.AreaTreeException;
+import org.axsl.common.i18n.Orthography;
import org.axsl.fo.Fo;
import org.axsl.fo.fo.GraftingPoint;
import org.axsl.fo.fo.ScalingValueCitation;
@@ -37,8 +40,6 @@
import org.axsl.galley.GalleyVisitorException;
import org.axsl.galley.RenderVisitor;
-import com.ibm.icu.util.ULocale;
-
import java.awt.Color;
import java.util.Collections;
import java.util.List;
@@ -252,7 +253,7 @@
final FontUse fontUse = getPrimaryFont();
fontUse.registerCharsUsed(word);
return fontUse.width(word, 0, word.length(), traitFontSize(), traitGeneratedBy().traitLetterSpacingOpt(this),
- traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), locale());
+ traitGeneratedBy().traitWordSpacingOpt(this), fontOptions(), orthography());
}
@Override
@@ -321,12 +322,12 @@
}
/**
- * Returns the locale.
- * @return The locale.
+ * Returns the orthography.
+ * @return The orthography.
*/
- public ULocale locale() {
+ public Orthography orthography() {
/* TODO: Get this from the FOTree. */
- return ULocale.US;
+ return Orthography4a.USA;
}
}
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -31,8 +31,10 @@
import org.foray.common.CharSequenceSubset;
import org.foray.common.WKConstants;
import org.foray.common.XMLCharacter;
+import org.foray.common.i18n.Orthography4a;
import org.axsl.area.AreaTreeException;
+import org.axsl.common.i18n.Orthography;
import org.axsl.common.value.WhiteSpaceTreatment;
import org.axsl.fo.Fo;
import org.axsl.fo.fo.Block;
@@ -43,8 +45,6 @@
import org.axsl.galley.GalleyVisitorException;
import org.axsl.galley.RenderVisitor;
-import com.ibm.icu.util.ULocale;
-
import java.awt.Color;
import java.io.Serializable;
import java.util.Collections;
@@ -612,7 +612,7 @@
private int recomputeProgressionDimension() {
final CharSequence text = getText();
final int pd = getPrimaryFont().width(text, 0, text.length(), traitFontSize(), traitLetterSpacingOpt(),
- traitWordSpacingOpt(), fontOptions(), locale());
+ traitWordSpacingOpt(), fontOptions(), orthography());
return pd;
}
@@ -678,9 +678,9 @@
}
@Override
- public ULocale locale() {
+ public Orthography orthography() {
/* TODO: Get this from the FOTree. */
- return ULocale.US;
+ return Orthography4a.USA;
}
@Override
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -38,6 +38,30 @@
*/
public final class Country4a implements Country {
+ /** The United States of America. */
+ public static final Country4a USA;
+
+ /** Finland. */
+ public static final Country4a FINLAND;
+
+ /** Hungary. */
+ public static final Country4a HUNGARY;
+
+ /** Italy. */
+ public static final Country4a ITALY;
+
+ /** Poland. */
+ public static final Country4a POLAND;
+
+ /** Portugal. */
+ public static final Country4a PORTUGAL;
+
+ /** Russia. */
+ public static final Country4a RUSSIA;
+
+ /** Spain. */
+ public static final Country4a SPAIN;
+
/** A country code suitable for cases where one is not known. */
private static final Country4a NULL_COUNTRY = new Country4a("NULL", "", "", (short) 0);
@@ -300,6 +324,15 @@
Country4a.registerCountry(new Country4a("YEMEN", "YE", "YEM", (short) 887));
Country4a.registerCountry(new Country4a("ZAMBIA", "ZM", "ZMB", (short) 894));
Country4a.registerCountry(new Country4a("ZIMBABWE", "ZW", "ZWE", (short) 716));
+
+ USA = Country4a.findFrom3Char("USA");
+ FINLAND = Country4a.findFrom3Char("FIN");
+ HUNGARY = Country4a.findFrom3Char("HUN");
+ ITALY = Country4a.findFrom3Char("ITA");
+ POLAND = Country4a.findFrom3Char("POL");
+ PORTUGAL = Country4a.findFrom3Char("PRT");
+ RUSSIA = Country4a.findFrom3Char("RUS");
+ SPAIN = Country4a.findFrom3Char("ESP");
}
/* Turn checkstyle check for magic numbers back on. Checkstyle-MagicNumber-On. */
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -42,6 +42,30 @@
/** The "undetermined" code. */
public static final Language4a UNDETERMINED = new Language4a("und", null, "Undetermined", "indéterminée");
+ /** The English language. */
+ public static final Language4a ENGLISH;
+
+ /** The Finnish language. */
+ public static final Language4a FINNISH;
+
+ /** The Hungarian language. */
+ public static final Language4a HUNGARIAN;
+
+ /** The Italian language. */
+ public static final Language4a ITALIAN;
+
+ /** The Polish language. */
+ public static final Language4a POLISH;
+
+ /** The Portuguese language. */
+ public static final Language4a PORTUGUESE;
+
+ /** The Russian language. */
+ public static final Language4a RUSSIAN;
+
+ /** The Spanish language. */
+ public static final Language4a SPANISH;
+
/** Constant indicating the number of terminology entries. */
private static final short QTY_TERMINOLOGY_ENTRIES = 22;
@@ -625,6 +649,17 @@
Language4a.terminologyMap.put("srp", Language4a.findFrom3Char("scc"));
}
+ static {
+ ENGLISH = Language4a.findFrom3Char("eng");
+ FINNISH = Language4a.findFrom3Char("fin");
+ HUNGARIAN = Language4a.findFrom3Char("hun");
+ ITALIAN = Language4a.findFrom3Char("ita");
+ POLISH = Language4a.findFrom3Char("pol");
+ PORTUGUESE = Language4a.findFrom3Char("por");
+ RUSSIAN = Language4a.findFrom3Char("rus");
+ SPANISH = Language4a.findFrom3Char("spa");
+ }
+
/** The English name of this language. */
private String englishName;
Added: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Orthography4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Orthography4a.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Orthography4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2017 The FOray Project.
+ * http://www.foray.org
+ *
+ * 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.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.i18n;
+
+import org.axsl.common.i18n.Country;
+import org.axsl.common.i18n.Language;
+import org.axsl.common.i18n.Orthography;
+import org.axsl.common.i18n.Script;
+
+/**
+ * FOray implementation of {@link Orthography}.
+ */
+public class Orthography4a implements Orthography {
+
+ /** The orthograpy for the United States. */
+ public static final Orthography4a USA = new Orthography4a(Language4a.ENGLISH, Country4a.USA, Script4a.LATIN);
+
+ /** The orthograpy for Finland. */
+ public static final Orthography4a FINLAND =
+ new Orthography4a(Language4a.FINNISH, Country4a.FINLAND, Script4a.LATIN);
+
+ /** The orthograpy for Hungary. */
+ public static final Orthography4a HUNGARY =
+ new Orthography4a(Language4a.HUNGARIAN, Country4a.HUNGARY, Script4a.LATIN);
+
+ /** The orthograpy for Italy. */
+ public static final Orthography4a ITALY =
+ new Orthography4a(Language4a.ITALIAN, Country4a.ITALY, Script4a.LATIN);
+
+ /** The orthograpy for Poland. */
+ public static final Orthography4a POLAND =
+ new Orthography4a(Language4a.POLISH, Country4a.POLAND, Script4a.LATIN);
+
+ /** The orthograpy for Portugal. */
+ public static final Orthography4a PORTUGAL =
+ new Orthography4a(Language4a.PORTUGUESE, Country4a.PORTUGAL, Script4a.LATIN);
+
+ /** The orthograpy for Russia. */
+ public static final Orthography4a RUSSIA =
+ new Orthography4a(Language4a.RUSSIAN, Country4a.RUSSIA, Script4a.CYRILLIC);
+
+ /** The orthograpy for Spain. */
+ public static final Orthography4a SPAIN =
+ new Orthography4a(Language4a.SPANISH, Country4a.SPAIN, Script4a.LATIN);
+
+ /** The language. */
+ private Language language;
+
+ /** The country. */
+ private Country country;
+
+ /** The script. */
+ private Script script;
+
+ /**
+ * Constructor.
+ * @param language The language.
+ * @param country The country.
+ * @param script The script.
+ */
+ public Orthography4a(final Language language, final Country country, final Script script) {
+ this.language = language;
+ this.country = country;
+ this.script = script;
+ }
+
+ @Override
+ public Language getLanguage() {
+ return this.language;
+ }
+
+ @Override
+ public Country getCountry() {
+ return this.country;
+ }
+
+ @Override
+ public Script getScript() {
+ return this.script;
+ }
+
+}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -44,6 +44,12 @@
public static final Script4a UNDETERMINED = new Script4a("Zyyy", (short) 998, "Code for undetermined script",
"codet pour écriture indéterminée");
+ /** The Latin script. */
+ public static final Script4a LATIN;
+
+ /** The Cyrillic script. */
+ public static final Script4a CYRILLIC;
+
/** String constant used to eliminate duplicates. */
private static final String STRING_CHAM = "Cham";
@@ -194,6 +200,9 @@
Script4a.register(Script4a.UNDETERMINED);
Script4a.register(new Script4a(
"Zzzz", (short) 999, "Code for uncoded script", "codet pour écriture non codée"));
+
+ LATIN = Script4a.findFromAlpha("Latn");
+ CYRILLIC = Script4a.findFromAlpha("Cyrl");
}
/* Turn checkstyle check for magic numbers back on. Checkstyle-MagicNumber-On. */
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -32,14 +32,13 @@
import org.foray.font.format.Kerning;
import org.axsl.common.IntSequence;
+import org.axsl.common.i18n.Orthography;
import org.axsl.font.Font;
import org.axsl.font.FontOptions;
import org.axsl.ps.CharSet;
import org.apache.commons.logging.Log;
-import com.ibm.icu.util.ULocale;
-
/**
* An implementation of the aXSL {@link Font4a} interface.
*/
@@ -178,7 +177,7 @@
@Override
public int width(final IntSequence word, final int offset, final int length, final int fontSize,
final int letterSpacing, final int wordSpacing, final FontOptions requestedFontOptions,
- final ULocale locale) {
+ final Orthography orthography) {
final FontOptions fontOptions = requestedFontOptions == null ? FontOptions.DEFAULT : requestedFontOptions;
if (word == null) {
return 0;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -37,6 +37,7 @@
import org.foray.font.format.ttf.TrueTypeFont;
import org.foray.font.output.FontOutputFactory4a;
+import org.axsl.common.i18n.Orthography;
import org.axsl.font.Font;
import org.axsl.font.FontConsumer;
import org.axsl.font.FontException;
@@ -48,8 +49,6 @@
import org.apache.commons.logging.Log;
-import com.ibm.icu.util.ULocale;
-
import java.util.HashMap;
import java.util.Map;
@@ -137,7 +136,7 @@
@Override
public IntArrayBuilder encode(final CharSequence chars, final int offset, final int length,
- final FontOptions options, final ULocale locale) {
+ final FontOptions options, final Orthography orthography) {
/* Convert the chars to code points. */
/* Some substitutions add glyphs, so make the output a bit bigger than the input to avoid array copying. */
final IntArrayBuilder codePoints = CharSequenceUtils.toCodepoints(chars, offset, length, 2);
@@ -171,7 +170,7 @@
return glyphIndexes;
}
- gsub.makeSubstitutions(glyphIndexes, options, locale);
+ gsub.makeSubstitutions(glyphIndexes, options, orthography);
return glyphIndexes;
}
@@ -191,7 +190,7 @@
@Override
public int width(final CharSequence chars, final int offset, final int length, final int fontSize,
- final int letterSpacing, final int wordSpacing, final FontOptions options, final ULocale locale) {
+ final int letterSpacing, final int wordSpacing, final FontOptions options, final Orthography orthography) {
final IntArrayBuilder metricIndexes = new IntArrayBuilder(chars.length());
for (int i = 0; i < chars.length(); i ++) {
final int metricIndex = getFont().metricIndex(chars.charAt(i));
@@ -201,7 +200,8 @@
metricIndexes.append(metricIndex);
}
}
- return getFont().width(metricIndexes, offset, length, fontSize, letterSpacing, wordSpacing, options, locale);
+ return getFont().width(metricIndexes, offset, length, fontSize, letterSpacing, wordSpacing, options,
+ orthography);
}
@Override
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TTFTableGSUB.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TTFTableGSUB.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TTFTableGSUB.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -31,10 +31,9 @@
import org.foray.common.io.RandomAccessInput;
import org.foray.common.util.IntArrayBuilder;
+import org.axsl.common.i18n.Orthography;
import org.axsl.font.FontOptions;
-import com.ibm.icu.util.ULocale;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -138,9 +137,10 @@
* @param glyphIndexes The glyph indexes for which substitutions are being considered.
* @param options The font options, such as ligatures and small-caps that should be used when computing the glyphs
* for this word.
- * @param locale The locale that should be used when applying subsitutions.
+ * @param orthography The orthography that should be used when applying subsitutions.
*/
- public void makeSubstitutions(final IntArrayBuilder glyphIndexes, final FontOptions options, final ULocale locale) {
+ public void makeSubstitutions(final IntArrayBuilder glyphIndexes, final FontOptions options,
+ final Orthography orthography) {
/* "To implement features, a client applies the lookups in the order the lookup definitions occur in the
* LookupList. As a result, within the GSUB or GPOS table, lookups from several different features may be
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/output/FontPdf4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/output/FontPdf4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/output/FontPdf4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -36,14 +36,13 @@
import org.foray.font.format.type1.Type1Font;
import org.axsl.common.IntSequence;
+import org.axsl.common.i18n.Orthography;
import org.axsl.font.Font;
import org.axsl.font.FontException;
import org.axsl.font.FontOptions;
import org.axsl.font.FontUse;
import org.axsl.font.output.FontPdf;
-import com.ibm.icu.util.ULocale;
-
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
@@ -430,10 +429,11 @@
}
@Override
- public String textToPdf(final CharSequence theString, final FontOptions fontOptions, final ULocale locale) {
+ public String textToPdf(final CharSequence theString, final FontOptions fontOptions,
+ final Orthography orthography) {
final Font font = getFOrayFont();
final FontUse fontUse = getFontUse();
- final IntSequence glyphIndexes = fontUse.encode(theString, 0, theString.length(), fontOptions, locale);
+ final IntSequence glyphIndexes = fontUse.encode(theString, 0, theString.length(), fontOptions, orthography);
final StringBuilder buffer = new StringBuilder();
buffer.append("[");
buffer.append(startTextDelimiter(font));
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/TestFont4a.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/TestFont4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/TestFont4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -32,6 +32,7 @@
import static org.junit.Assert.assertNotNull;
import org.foray.common.FontOptions4a;
+import org.foray.common.i18n.Orthography4a;
import org.foray.font.config.RegisteredFont;
import org.axsl.font.FontException;
@@ -40,8 +41,6 @@
import org.junit.Test;
-import com.ibm.icu.util.ULocale;
-
import junit.framework.Assert;
/**
@@ -116,14 +115,14 @@
* If these are scaled to 12 points, the millipoints used are 7565 * 12
* = 90,780. */
assertEquals(90780, fontUse.width(
- testString, 0, testString.length(), 12000, 0, 0, fontOptionsWithKerning, ULocale.US));
+ testString, 0, testString.length(), 12000, 0, 0, fontOptionsWithKerning, Orthography4a.USA));
/* Test without kerning.
* Total kerning = -105.
* Adjusted text space units = 7,565 + 105 = 7,670.
* When scaled to 12 points, the millipoints used are 7670 * 12 = 92,040. */
assertEquals(92040, fontUse.width(
- testString, 0, testString.length(), 12000, 0, 0, fontOptionsWithoutKerning, ULocale.US));
+ testString, 0, testString.length(), 12000, 0, 0, fontOptionsWithoutKerning, Orthography4a.USA));
/* Test with word spacing.
* Word spacing = 300.
@@ -131,7 +130,7 @@
* Total word spacing = 600.
* Total space (kerning on) = 90,780 + 600 = 91,380. */
assertEquals(91380, fontUse.width(
- testString, 0, testString.length(), 12000, 0, 300, fontOptionsWithKerning, ULocale.US));
+ testString, 0, testString.length(), 12000, 0, 300, fontOptionsWithKerning, Orthography4a.USA));
/* Test with letter spacing.
* Letter spacing = 5.
@@ -139,12 +138,12 @@
* Total word spacing = 80.
* Total space (kerning on) = 90,780 + 80 = 90,860. */
assertEquals(90860, fontUse.width(
- testString, 0, testString.length(), 12000, 5, 0, fontOptionsWithKerning, ULocale.US));
+ testString, 0, testString.length(), 12000, 5, 0, fontOptionsWithKerning, Orthography4a.USA));
/* Test with both word spacing and letter spacing, using same parameters as above.
* Total space (kerning on) = 90,780 + 600 + 80 = 91,460. */
assertEquals(91460, fontUse.width(
- testString, 0, testString.length(), 12000, 5, 300, fontOptionsWithKerning, ULocale.US));
+ testString, 0, testString.length(), 12000, 5, 300, fontOptionsWithKerning, Orthography4a.USA));
}
}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OTFLookupGSUBTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OTFLookupGSUBTests.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OTFLookupGSUBTests.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,6 +28,7 @@
package org.foray.font.format.ttf;
+import org.foray.common.i18n.Orthography4a;
import org.foray.common.io.SimpleDataSource;
import org.foray.common.util.CharSequenceUtils;
import org.foray.common.util.IntArrayBuilder;
@@ -37,6 +38,7 @@
import org.foray.font.format.ttf.OTFLookupGSUBx04x01.Ligature;
import org.foray.font.format.ttf.OTFLookupGSUBx04x01.LigatureSet;
+import org.axsl.common.i18n.Orthography;
import org.axsl.font.FontException;
import org.axsl.font.FontOptions;
import org.axsl.ps.Encoding;
@@ -45,8 +47,6 @@
import org.junit.BeforeClass;
import org.junit.Test;
-import com.ibm.icu.util.ULocale;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@@ -62,8 +62,8 @@
/** The font being tested. */
private static TrueTypeFont ttfFont;
- /** The locale that should be used when applying font features like subsitutions. */
- private static ULocale locale;
+ /** The orthography that should be used when applying font features like subsitutions. */
+ private static Orthography orthography;
/**
* Setup this class for testing.
@@ -85,7 +85,7 @@
OTFLookupGSUBTests.ttfFont = ttfSingle.getTTFFont(null);
Assert.assertNotNull(ttfFont);
- OTFLookupGSUBTests.locale = ULocale.US;
+ OTFLookupGSUBTests.orthography = Orthography4a.USA;
}
/**
@@ -267,7 +267,7 @@
Assert.assertArrayEquals(expectedInitialGlyphIndexes, glyphIndexes.toArray());
final TTFTableGSUB gsub = ttfFont.getGsubTable();
- gsub.makeSubstitutions(glyphIndexes, FontOptions.DEFAULT, locale);
+ gsub.makeSubstitutions(glyphIndexes, FontOptions.DEFAULT, orthography);
final int[] expectedFinalGlyphIndexes = new int[] {68, 2249, 81, 76, 87, 92};
Assert.assertArrayEquals(expectedFinalGlyphIndexes, glyphIndexes.toArray());
}
@@ -288,7 +288,7 @@
Assert.assertArrayEquals(expectedInitialGlyphIndexes, glyphIndexes.toArray());
final TTFTableGSUB gsub = ttfFont.getGsubTable();
- gsub.makeSubstitutions(glyphIndexes, FontOptions.DEFAULT, locale);
+ gsub.makeSubstitutions(glyphIndexes, FontOptions.DEFAULT, orthography);
final int[] expectedFinalGlyphIndexes = new int[] {68, 2249};
Assert.assertArrayEquals(expectedFinalGlyphIndexes, glyphIndexes.toArray());
}
@@ -320,7 +320,7 @@
Assert.assertArrayEquals(expectedInitialGlyphIndexes, glyphIndexes.toArray());
final TTFTableGSUB gsub = ttfFont.getGsubTable();
- gsub.makeSubstitutions(glyphIndexes, FontOptions.DEFAULT, locale);
+ gsub.makeSubstitutions(glyphIndexes, FontOptions.DEFAULT, orthography);
final int[] expectedFinalGlyphIndexes = new int[] {
36, 2250, 72, 70, 78, 3, // "Affleck "
68, 2249, 81, 76, 87, 92, 3, // "affinity "
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FOLineText.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FOLineText.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FOLineText.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,14 +28,13 @@
package org.foray.fotree;
+import org.axsl.common.i18n.Orthography;
import org.axsl.fo.FoContext;
import org.axsl.fo.fo.GraftingPoint;
import org.axsl.font.FontOptions;
import org.axsl.font.FontUse;
import org.axsl.text.line.LineText;
-import com.ibm.icu.util.ULocale;
-
/**
* Wraps an underlying "real" FOLineText along with the context to be used by
* that item for trait resolution.
@@ -140,8 +139,8 @@
}
@Override
- public ULocale inlineLocale() {
- return this.realLineText.inlineLocale();
+ public Orthography inlineOrthography() {
+ return this.realLineText.inlineOrthography();
}
@Override
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -30,6 +30,7 @@
import org.foray.common.WKConstants;
import org.foray.common.XMLCharacter;
+import org.foray.common.i18n.Orthography4a;
import org.foray.fotree.FObj;
import org.foray.fotree.Namespace;
import org.foray.fotree.PropertyList;
@@ -37,6 +38,7 @@
import org.axsl.common.i18n.Country;
import org.axsl.common.i18n.Language;
+import org.axsl.common.i18n.Orthography;
import org.axsl.common.value.LinefeedTreatment;
import org.axsl.common.value.TextTransform;
import org.axsl.common.value.WhiteSpaceTreatment;
@@ -52,8 +54,6 @@
import org.axsl.font.FontUse;
import org.axsl.text.line.LineText;
-import com.ibm.icu.util.ULocale;
-
import java.util.List;
/**
@@ -215,10 +215,10 @@
}
@Override
- public ULocale inlineLocale() {
+ public Orthography inlineOrthography() {
final Language language = inlineLanguage();
final Country country = inlineCountry();
- return new ULocale(language.getAlpha2Code(), country.getAlpha2Code(), null);
+ return new Orthography4a(language, country, null);
}
@Override
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Character.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Character.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Character.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,12 +28,14 @@
package org.foray.fotree.fo.obj;
+import org.foray.common.i18n.Orthography4a;
import org.foray.fotree.FObj;
import org.foray.fotree.Namespace;
import org.foray.fotree.PropertyList;
import org.axsl.common.i18n.Country;
import org.axsl.common.i18n.Language;
+import org.axsl.common.i18n.Orthography;
import org.axsl.common.value.WrapOption;
import org.axsl.fo.FoContext;
import org.axsl.fo.FoTreeException;
@@ -44,8 +46,6 @@
import org.axsl.font.FontUse;
import org.axsl.text.line.LineText;
-import com.ibm.icu.util.ULocale;
-
import java.util.List;
/**
@@ -272,10 +272,10 @@
}
@Override
- public ULocale inlineLocale() {
+ public Orthography inlineOrthography() {
final Language language = inlineLanguage();
final Country country = inlineCountry();
- return new ULocale(language.getAlpha2Code(), country.getAlpha2Code(), null);
+ return new Orthography4a(language, country, null);
}
@Override
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoWordSequence.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -58,7 +58,7 @@
super(parent);
final HyphenationConsumer hyphenationConsumer = getHyphenationConsumer();
final WordSequence wordSequence =
- hyphenationConsumer.parseWordSequence(content, 0, content.length(), this.inlineLocale());
+ hyphenationConsumer.parseWordSequence(content, 0, content.length(), this.inlineOrthography());
this.content = new ArrayList<FoWordSequenceContent>(wordSequence.getQtyElements());
for (int index = 0; index < wordSequence.getQtyElements(); index ++) {
final WordSequenceContent wordSequenceContent = wordSequence.getElement(index);
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFGraphics2D.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFGraphics2D.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFGraphics2D.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -37,6 +37,7 @@
import org.foray.common.Gradient4a;
import org.foray.common.Mime;
import org.foray.common.WKConstants;
+import org.foray.common.i18n.Orthography4a;
import org.foray.common.ps.PsColor;
import org.foray.common.ps.PsUtil;
@@ -54,8 +55,6 @@
import org.w3c.dom.svg.SVGDocument;
-import com.ibm.icu.util.ULocale;
-
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
@@ -705,7 +704,7 @@
this.write(matrixString + "cm");
this.write("1 0 0 -1 0 0 Tm ");
- final String outputString = font.textToPdf(s, FontOptions.DEFAULT, ULocale.US);
+ final String outputString = font.textToPdf(s, FontOptions.DEFAULT, Orthography4a.USA);
this.write(outputString);
this.write("ET");
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFTextPainter.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFTextPainter.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PDFTextPainter.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -35,6 +35,7 @@
import org.foray.common.Mime;
import org.foray.common.WKConstants;
+import org.foray.common.i18n.Orthography4a;
import org.axsl.font.Font;
import org.axsl.font.FontConsumer;
@@ -52,8 +53,6 @@
import org.apache.batik.gvt.text.TextPaintInfo;
import org.apache.commons.logging.Log;
-import com.ibm.icu.util.ULocale;
-
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
@@ -281,9 +280,10 @@
fontToUse.registerCharsUsed(txt);
/* TODO: If letter-spacing is used, it needs to come from the SVG. */
final int letterSpacing = 0;
- /* TODO: Pass the font options and locale below instead of hard-coding them. */
+ /* TODO: Pass the font options and orthography below instead of hard-coding them. */
final int width = fontToUse.width(txt, 0, txt.length(),
- awtFontSize * WKConstants.MILLIPOINTS_PER_POINT, letterSpacing, 0, FontOptions.DEFAULT, ULocale.US);
+ awtFontSize * WKConstants.MILLIPOINTS_PER_POINT, letterSpacing, 0, FontOptions.DEFAULT,
+ Orthography4a.USA);
final float advance = WKConstants.millipointsToPoints(width);
float tx = 0;
if (anchor != null) {
Modified: trunk/foray/foray-hyphen/pom.xml
===================================================================
--- trunk/foray/foray-hyphen/pom.xml 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-hyphen/pom.xml 2017-01-14 03:08:18 UTC (rev 11314)
@@ -54,6 +54,12 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>com.ibm.icu</groupId>
+ <artifactId>icu4j</artifactId>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>org.axsl</groupId>
<artifactId>axsl-hyphen</artifactId>
<type>jar</type>
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationConsumer4a.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationConsumer4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationConsumer4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,12 +28,11 @@
package org.foray.hyphen;
+import org.axsl.common.i18n.Orthography;
import org.axsl.hyphen.HyphenationConsumer;
import org.axsl.hyphen.HyphenationException;
import org.axsl.hyphen.Word;
-import com.ibm.icu.util.ULocale;
-
import java.util.List;
/**
@@ -53,9 +52,9 @@
}
@Override
- public Word hyphenate(final CharSequence word, final int offset, final int len, final ULocale locale)
+ public Word hyphenate(final CharSequence word, final int offset, final int len, final Orthography orthography)
throws HyphenationException {
- final Word parsedWord = this.server.hyphenate(word, offset, len, locale);
+ final Word parsedWord = this.server.hyphenate(word, offset, len, orthography);
return parsedWord;
}
@@ -74,12 +73,12 @@
@Override
public WordSequence4a parseWordSequence(final CharSequence characters, final int startIndex, final int length,
- final ULocale locale) {
+ final Orthography orthography) {
final WordSequence4a wordSequence = new WordSequence4a();
final int endIndex = startIndex + length;
int currentIndex = startIndex;
while (currentIndex < endIndex) {
- final int wordStart = this.server.wordStarts(characters, currentIndex, locale);
+ final int wordStart = this.server.wordStarts(characters, currentIndex, orthography);
if (wordStart < 0) {
/* A word was not found. What is left is interword content after the last word. */
final CharSequence interwordContent = characters.subSequence(currentIndex, endIndex);
@@ -87,7 +86,7 @@
wordSequence.addContent(interword);
break;
}
- final int wordSize = this.server.wordSize(characters, wordStart, locale);
+ final int wordSize = this.server.wordSize(characters, wordStart, orthography);
/* Is there any interword content before the word? */
if (wordStart > currentIndex) {
@@ -99,7 +98,7 @@
/* Create the word. */
Word word = null;
try {
- word = this.server.hyphenate(characters, wordStart, wordSize, locale);
+ word = this.server.hyphenate(characters, wordStart, wordSize, orthography);
} catch (final HyphenationException e) {
/* Not a big problem. We carry on by creating a word anyway. */
}
Modified: trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationServer4a.java
===================================================================
--- trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationServer4a.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/HyphenationServer4a.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -44,6 +44,7 @@
import org.axsl.common.i18n.Country;
import org.axsl.common.i18n.Language;
+import org.axsl.common.i18n.Orthography;
import org.axsl.hyphen.HyphenationConsumer;
import org.axsl.hyphen.HyphenationException;
import org.axsl.hyphen.HyphenationServer;
@@ -51,8 +52,6 @@
import org.apache.commons.logging.Log;
-import com.ibm.icu.util.ULocale;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
@@ -119,38 +118,38 @@
/**
* The main search algorithm.
- * @param locale The locale for which a hyphenation tree is needed.
+ * @param orthography The orthography for which a hyphenation tree is needed.
* @return The hyphenation tree if it exists, or null otherwise.
* @throws HyphenationException For errors retrieving the hyphenation tree.
*/
- PatternTree getHyphenationTree(final ULocale locale) throws HyphenationException {
+ PatternTree getHyphenationTree(final Orthography orthography) throws HyphenationException {
/* Bail out if the language code is null. */
- if (locale == null
- || locale.getLanguage().equals(Language4a.UNDETERMINED.getAlpha2Code())) {
+ if (orthography == null
+ || orthography.getLanguage().equals(Language4a.UNDETERMINED.getAlpha2Code())) {
return null;
}
/* Look for the countryKey in all possible locations before looking
* for the languageKey, because the countryKey is more specific. */
- PatternTree tree = this.findTreeForKey(locale);
+ PatternTree tree = this.findTreeForKey(orthography);
if (tree != null) {
return tree;
}
- tree = this.findTreeForKey(locale);
+ tree = this.findTreeForKey(orthography);
return tree;
}
/**
* Tries to find a hyphenation tree for a specific key in all possible
* locations.
- * @param locale The language, country, and script information for which the tree is sought.
+ * @param orthography The language, country, and script information for which the tree is sought.
* @return The HyphenationTree if it is found, or null if it is not found.
* @throws HyphenationException For errors retrieving the hyphenation tree.
*/
- private PatternTree findTreeForKey(final ULocale locale)
+ private PatternTree findTreeForKey(final Orthography orthography)
throws HyphenationException {
- final String key = locale.getISO3Language();
+ final String key = orthography.getLanguage().getAlpha3Code();
if (key == null) {
return null;
}
@@ -187,7 +186,15 @@
final StringBuilder warningMessage = new StringBuilder(HyphenationServer4a.PATTERN_MISSING_TEXT);
warningMessage.append(key);
warningMessage.append(" (");
- warningMessage.append(locale.toLanguageTag());
+ /* TODO: Treat these internally as separate components, looking for them one at a time to get the file name
+ * and parsed dictionary.*/
+ if (orthography.getLanguage() != null) {
+ warningMessage.append(orthography.getLanguage().getAlpha3Code());
+ }
+ if (orthography.getCountry() != null) {
+ warningMessage.append("-");
+ warningMessage.append(orthography.getCountry().getAlpha3Code());
+ }
warningMessage.append(")");
/* Log a warning and add it to the list of not found keys. */
getLogger().warn(warningMessage);
@@ -361,7 +368,7 @@
}
@Override
- public Word hyphenate(final CharSequence word, final int offset, final int length, final ULocale locale)
+ public Word hyphenate(final CharSequence word, final int offset, final int length, final Orthography orthography)
throws HyphenationException {
final int adjustedOffset = offset;
int adjustedLength = length;
@@ -375,7 +382,7 @@
}
final CharSequence chars = word.subSequence(adjustedOffset, adjustedOffset + adjustedLength);
- final PatternTree hTree = getHyphenationTree(locale);
+ final PatternTree hTree = getHyphenationTree(orthography);
if (hTree == null) {
return null;
}
@@ -410,7 +417,7 @@
}
@Override
- public int wordSize(final CharSequence characters, final int wordStart, final ULocale locale) {
+ public int wordSize(final CharSequence characters, final int wordStart, final Orthography orthography) {
if (characters == null) {
return 0;
}
@@ -431,7 +438,7 @@
}
@Override
- public int wordStarts(final CharSequence characters, final int startIndex, final ULocale locale) {
+ public int wordStarts(final CharSequence characters, final int startIndex, final Orthography orthography) {
if (characters == null) {
return -1;
}
Modified: trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationConsumer4aTests.java
===================================================================
--- trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationConsumer4aTests.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationConsumer4aTests.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,13 +28,15 @@
package org.foray.hyphen;
+import org.foray.common.i18n.Orthography4a;
+
+import org.axsl.common.i18n.Orthography;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import com.ibm.icu.util.ULocale;
-
import java.net.MalformedURLException;
import java.net.URL;
@@ -47,7 +49,7 @@
private static HyphenationServer4a server;
/** The language and country used in these tests. */
- private static ULocale locale = ULocale.US;
+ private static Orthography orthography = Orthography4a.USA;
/** The object under test. */
private HyphenationConsumer4a consumer;
@@ -73,13 +75,13 @@
}
/**
- * Test of {@link HyphenationConsumer4a#parseWordSequence(CharSequence, int, int, ULocale)}.
+ * Test of {@link HyphenationConsumer4a#parseWordSequence(CharSequence, int, int, Orthography)}.
*/
@Test
public void parseWordSequenceTest() {
final String testString = "39. It was the best of times. It was the worst of times. <----";
final WordSequence4a wordSequence =
- this.consumer.parseWordSequence(testString, 0, testString.length(), locale);
+ this.consumer.parseWordSequence(testString, 0, testString.length(), orthography);
Assert.assertEquals(27, wordSequence.getQtyElements());
Assert.assertEquals("39.", wordSequence.getElement(0).toString());
Assert.assertEquals(" ", wordSequence.getElement(1).toString());
Modified: trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationServer4aTests.java
===================================================================
--- trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationServer4aTests.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-hyphen/src/test/java/org/foray/hyphen/HyphenationServer4aTests.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -34,8 +34,10 @@
import org.foray.common.Environment;
import org.foray.common.Logging;
import org.foray.common.i18n.Language4a;
+import org.foray.common.i18n.Orthography4a;
import org.axsl.common.i18n.Language;
+import org.axsl.common.i18n.Orthography;
import org.axsl.hyphen.AbstractHyphenationServerTests;
import org.axsl.hyphen.HyphenationException;
@@ -44,14 +46,10 @@
import org.junit.Ignore;
import org.junit.Test;
-import com.ibm.icu.util.ULocale;
-
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
-import junit.framework.Assert;
-
/**
* Runs the standard aXSL hyphenation tests against the FOray hyphenation
* server.
@@ -96,74 +94,58 @@
final HyphenationServer4a server = makeHyphenationServer();
/* English, U.S. */
- ULocale locale = ULocale.US;
- Assert.assertEquals("en-US", locale.toLanguageTag());
- PatternTree tree = server.getHyphenationTree(locale);
+ Orthography orthography = Orthography4a.USA;
+ PatternTree tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Finnish. */
- Language language = Language4a.findFromAlpha("fin");
- locale = ULocale.forLanguageTag(language.getAlpha2Code());
- Assert.assertEquals("fi", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ orthography = Orthography4a.FINLAND;
+ tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Hungarian. */
- language = Language4a.findFromAlpha("hun");
- locale = ULocale.forLanguageTag(language.getAlpha2Code());
- Assert.assertEquals("hu", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ orthography = Orthography4a.HUNGARY;
+ tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Italian. */
- language = Language4a.findFromAlpha("ita");
- locale = ULocale.forLanguageTag(language.getAlpha2Code());
- Assert.assertEquals("it", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ orthography = Orthography4a.ITALY;
+ tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Polish. */
- language = Language4a.findFromAlpha("pol");
- locale = ULocale.forLanguageTag(language.getAlpha2Code());
- Assert.assertEquals("pl", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ orthography = Orthography4a.POLAND;
+ tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Portuguese. */
- language = Language4a.findFromAlpha("por");
- locale = ULocale.forLanguageTag(language.getAlpha2Code());
- Assert.assertEquals("pt", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ orthography = Orthography4a.PORTUGAL;
+ tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Russian. */
- language = Language4a.findFromAlpha("rus");
- locale = ULocale.forLanguageTag(language.getAlpha2Code());
- Assert.assertEquals("ru", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ orthography = Orthography4a.RUSSIA;
+ tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Spanish. */
- language = Language4a.findFromAlpha("spa");
- locale = ULocale.forLanguageTag(language.getAlpha2Code());
- Assert.assertEquals("es", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ orthography = Orthography4a.SPAIN;
+ tree = server.getHyphenationTree(orthography);
assertNotNull(tree);
// assertEquals(HyphenationTree.Source.RESOURCES, tree.getSource());
/* Try one that we know we don't have, Klingon. */
- language = Language4a.findFromAlpha("tlh");
+ final Language language = Language4a.findFromAlpha("tlh");
+ orthography = new Orthography4a(language, null, null);
/* Klingon doesn't have an alpha2 code, so use alpha3. */
- locale = ULocale.forLanguageTag(language.getAlpha3Code());
- Assert.assertEquals("tlh", locale.toLanguageTag());
- tree = server.getHyphenationTree(locale);
+ tree = server.getHyphenationTree(orthography);
assertNull(tree);
}
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java 2017-01-12 06:21:21 UTC (rev 11313)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/text/line/LineBreaker.java 2017-01-14 03:08:18 UTC (rev 11314)
@@ -28,6 +28,7 @@
package org.foray.text.line;
+import org.foray.common.i18n.Orthography4a;
import org.foray.text.TextServer4a;
import org.axsl.font.FontConsumer;
@@ -38,8 +39,6 @@
import org.apache.commons.logging.Log;
-import com.ibm.icu.util.ULocale;
-
/**
* Abstract superclass for all line breakers.
*/
@@ -333,9 +332,9 @@
public int getWordWidth(final LineText lineText, final CharSequence word, final int offset, final int length) {
final FontUse fontUse = lineText.inlinePrimaryFont();
fontUse.registerCharsUsed(word);
- /* TODO: Pass the locale below instead of hard-coding it. */
+ /* TODO: Pass the orthography below instead of hard-coding it. */
return fontUse.width(word, offset, length, lineText.inlineFontSize(), lineText.inlineLetterSpacingOptimum(), 0,
- lineText.inlineFontOptions(), ULocale.US);
+ lineText.inlineFontOptions(), Orthography4a.USA);
}
...
[truncated message content] |