[FOray-commit] SF.net SVN: foray:[12859] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-12-14 13:39:47
|
Revision: 12859
http://sourceforge.net/p/foray/code/12859
Author: victormote
Date: 2022-12-14 13:39:45 +0000 (Wed, 14 Dec 2022)
Log Message:
-----------
Remove some dependencies on getPrimaryFont().
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdAlignmentBaseline.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdDominantBaseline.java
trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTests.java
trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2022-12-14 12:30:47 UTC (rev 12858)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2022-12-14 13:39:45 UTC (rev 12859)
@@ -30,6 +30,7 @@
import org.foray.area.link.Link;
import org.foray.area.link.LinkFactory;
+import org.foray.common.FontUtil;
import org.foray.common.data.AbstractOrderedTreeNode;
import org.axsl.area.AreaNode;
@@ -46,6 +47,7 @@
import org.axsl.fotree.role.NormalBlockAreaGenerator;
import org.axsl.galley.AreaNodeG5;
import org.axsl.galley.Galley;
+import org.axsl.i18n.Script;
import org.axsl.orthography.Orthography;
import org.axsl.value.BaselineIdentifier;
import org.axsl.value.LinefeedTreatment;
@@ -821,4 +823,46 @@
}
}
+ @Override
+ public BaselineIdentifier baselineForScript(final Script script) {
+ FontUse fontUse = null;
+ if (this instanceof Area4a) {
+ final Area4a area = (Area4a) this;
+ fontUse = area.traitNominalFont();
+ }
+ if (fontUse == null) {
+ getAreaTree().logError("Unable to resolve font. Using natural baseline from script \"{}\"instead.",
+ script.getAlphaCode());
+ final Script.NaturalBaseline scriptBaseline = script.getNaturalBaseline();
+ switch (scriptBaseline) {
+ case UNKNOWN: {
+ getAreaTree().logError("Script \"{}\" has unknown baseline. Using fallback of \"alphabetic.\"",
+ script.getAlphaCode());
+ return BaselineIdentifier.ALPHABETIC;
+ }
+ case ALPHABETIC: return BaselineIdentifier.ALPHABETIC;
+ case IDEOGRAPHIC: return BaselineIdentifier.IDEOGRAPHIC;
+ case HANGING: return BaselineIdentifier.HANGING;
+ }
+ }
+
+ final Font font = fontUse.getFont();
+ final String opentypeScript = FontUtil.getOpenTypeScript(script);
+ final Font.Baseline fontBaseline = font.baseline(opentypeScript);
+ switch (fontBaseline) {
+ case ALPHABETIC: return BaselineIdentifier.ALPHABETIC;
+ case MATH: return BaselineIdentifier.MATHEMATICAL;
+ case HANGING: return BaselineIdentifier.HANGING;
+ case IDEO_BOTTOM_LEFT: return BaselineIdentifier.TEXT_AFTER_EDGE;
+ case IDEO_TOP_RIGHT: return BaselineIdentifier.TEXT_BEFORE_EDGE;
+ case ICF_BOTTOM_LEFT: return BaselineIdentifier.IDEOGRAPHIC;
+ /* TODO: There does not seem to be a good match between the font baselines provided and the
+ * XSL-FO baseline for ICF_TOP_RIGHT. */
+ case ICF_TOP_RIGHT: return BaselineIdentifier.TEXT_BEFORE_EDGE;
+ }
+
+ getAreaTree().logError("Unable to find baseline in font. Using fallback of \"alphabetic.\"");
+ return BaselineIdentifier.ALPHABETIC;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2022-12-14 12:30:47 UTC (rev 12858)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2022-12-14 13:39:45 UTC (rev 12859)
@@ -28,7 +28,6 @@
package org.foray.fotree;
-import org.foray.common.FontUtil;
import org.foray.common.data.AbstractOrderedTreeNode;
import org.foray.common.i18n.Country4a;
import org.foray.common.i18n.Language4a;
@@ -1868,7 +1867,7 @@
return BaselineIdentifier.CENTRAL;
}
} else {
- return this.getBaselineFromScript(context);
+ return context.baselineForScript(script);
}
} else {
return parent.traitDominantBaseline(context);
@@ -1875,34 +1874,6 @@
}
}
- /**
- * Returns this object's dominant-baseline, as computed from its font and script.
- * @param context An object that knows how to resolve FO Tree context issues.
- * @return This object's dominant-baseline, as computed from its font and script.
- */
- public BaselineIdentifier getBaselineFromScript(final FoContext context) {
- final FontUse fontUse = this.getPrimaryFont(context);
- if (fontUse == null) {
- throw new IllegalStateException("Unable to obtain a font for baseline computation.");
- }
- final Font font = fontUse.getFont();
- final Script script = this.traitScript(context);
- final String opentypeScript = FontUtil.getOpenTypeScript(script);
- final Font.Baseline fontBaseline = font.baseline(opentypeScript);
- switch (fontBaseline) {
- case ALPHABETIC: return BaselineIdentifier.ALPHABETIC;
- case MATH: return BaselineIdentifier.MATHEMATICAL;
- case HANGING: return BaselineIdentifier.HANGING;
- case IDEO_BOTTOM_LEFT: return BaselineIdentifier.TEXT_AFTER_EDGE;
- case IDEO_TOP_RIGHT: return BaselineIdentifier.TEXT_BEFORE_EDGE;
- case ICF_BOTTOM_LEFT: return BaselineIdentifier.IDEOGRAPHIC;
- /* TODO: There does not seem to be a good match between the font baselines provided and the
- * XSL-FO baseline for ICF_TOP_RIGHT. */
- case ICF_TOP_RIGHT: return BaselineIdentifier.TEXT_BEFORE_EDGE;
- }
- return BaselineIdentifier.ALPHABETIC;
- }
-
@Override
public int traitLastLineEndIndent(final FoContext context) {
return getPropertyList().traitLastLineEndIndent(this, context);
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdAlignmentBaseline.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdAlignmentBaseline.java 2022-12-14 12:30:47 UTC (rev 12858)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdAlignmentBaseline.java 2022-12-14 13:39:45 UTC (rev 12859)
@@ -37,6 +37,7 @@
import org.axsl.fotree.FoContext;
import org.axsl.fotree.fo.FoText;
+import org.axsl.i18n.Script;
import org.axsl.value.BaselineIdentifier;
/**
@@ -136,7 +137,8 @@
* @return The computed value from the script.
*/
private static BaselineIdentifier computeFromScript(final FoContext context, final FoObj fobj) {
- return fobj.getBaselineFromScript(context);
+ final Script script = fobj.traitScript(context);
+ return context.baselineForScript(script);
}
/**
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdDominantBaseline.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdDominantBaseline.java 2022-12-14 12:30:47 UTC (rev 12858)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/prop/PdDominantBaseline.java 2022-12-14 13:39:45 UTC (rev 12859)
@@ -36,6 +36,7 @@
import org.foray.fotree.value.PropertyValue;
import org.axsl.fotree.FoContext;
+import org.axsl.i18n.Script;
import org.axsl.value.BaselineIdentifier;
/**
@@ -165,7 +166,8 @@
return fobj.computeAutoBaseline(context);
}
case USE_SCRIPT: {
- return fobj.getBaselineFromScript(context);
+ final Script script = fobj.traitScript(context);
+ return context.baselineForScript(script);
}
case NO_CHANGE: {
return parent.traitDominantBaseline(context);
Modified: trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTests.java
===================================================================
--- trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTests.java 2022-12-14 12:30:47 UTC (rev 12858)
+++ trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTests.java 2022-12-14 13:39:45 UTC (rev 12859)
@@ -36,6 +36,7 @@
import org.axsl.fotree.FoContext;
import org.axsl.fotree.FoInlineContext;
import org.axsl.fotree.fo.GraftingPoint;
+import org.axsl.i18n.Script;
import org.axsl.value.BaselineIdentifier;
import org.axsl.value.LinefeedTreatment;
import org.axsl.value.TextTransform;
@@ -114,6 +115,10 @@
public float normalLineHeightFactor() {
return 1.2f;
}
+ @Override
+ public BaselineIdentifier baselineForScript(final Script script) {
+ return BaselineIdentifier.ALPHABETIC;
+ }
};
/** Constant providing a standard, but completely bogus context to be
Modified: trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java
===================================================================
--- trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java 2022-12-14 12:30:47 UTC (rev 12858)
+++ trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java 2022-12-14 13:39:45 UTC (rev 12859)
@@ -30,6 +30,7 @@
import org.axsl.fotree.FoContext;
import org.axsl.fotree.fo.GraftingPoint;
+import org.axsl.i18n.Script;
import org.axsl.value.BaselineIdentifier;
import org.axsl.value.LinefeedTreatment;
import org.axsl.value.TextTransform;
@@ -156,4 +157,9 @@
return this.wrappedContext.normalLineHeightFactor();
}
+ @Override
+ public BaselineIdentifier baselineForScript(final Script script) {
+ return this.wrappedContext.baselineForScript(script);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|