aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2011-02-10 17:19:54 +0000
committerVincent Hennebert <vhennebert@apache.org>2011-02-10 17:19:54 +0000
commitfaefb6aa9d051948ed8d6aa592694f5cedfb2239 (patch)
treea3f5f84d02725a9f2aff593db3497349103266d0 /src
parentb04f84c5de84abe83705ade525f7ba1d5c9c5a5b (diff)
downloadxmlgraphics-fop-faefb6aa9d051948ed8d6aa592694f5cedfb2239.tar.gz
xmlgraphics-fop-faefb6aa9d051948ed8d6aa592694f5cedfb2239.zip
Clean-ups, simplifications and improvements of AlignmentContext and ScaledBaselineTable
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1069474 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java201
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/BasicScaledBaselineTable.java198
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java161
-rw-r--r--src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java78
4 files changed, 243 insertions, 395 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java b/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java
index 2e8a3aca7..5cfe72fa2 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/AlignmentContext.java
@@ -32,21 +32,27 @@ import org.apache.fop.fonts.Font;
*/
public class AlignmentContext implements Constants {
- /** The height or BPD of this context */
+ /** The height or BPD of this context. */
private int areaHeight;
- /** The computed line-height property value applicable */
+
+ /** The computed line-height property value applicable. */
private int lineHeight;
- /** The distance in BPD from the top of the box to the alignmentPoint */
+
+ /** The distance in BPD from the top of the box to the alignmentPoint. */
private int alignmentPoint;
- /** The baseline shift value in effect */
+
+ /** The baseline shift value in effect. */
private int baselineShiftValue;
- /** The computed alignment baseline identifier */
+
+ /** The computed alignment baseline identifier. */
private int alignmentBaselineIdentifier;
- /** The x height */
+
+ /** The x height. */
private int xHeight;
- private ScaledBaselineTable scaledBaselineTable = null;
- private ScaledBaselineTable actualBaselineTable = null;
- private AlignmentContext parentAlignmentContext = null;
+
+ private ScaledBaselineTable scaledBaselineTable;
+ private ScaledBaselineTable actualBaselineTable;
+ private AlignmentContext parentAlignmentContext;
/**
* Creates a new instance of AlignmentContext
@@ -58,57 +64,20 @@ public class AlignmentContext implements Constants {
* @param dominantBaseline the dominant-baseline property
* @param parentAlignmentContext the parent alignment context
*/
- public AlignmentContext(int height
- , Length alignmentAdjust
- , int alignmentBaseline
- , Length baselineShift
- , int dominantBaseline
- , AlignmentContext parentAlignmentContext) {
-
- this.areaHeight = height;
- this.lineHeight = height;
- this.xHeight = height;
- this.parentAlignmentContext = parentAlignmentContext;
- this.scaledBaselineTable = parentAlignmentContext.getScaledBaselineTable();
- setAlignmentBaselineIdentifier(alignmentBaseline
- , parentAlignmentContext.getDominantBaselineIdentifier());
- setBaselineShift(baselineShift);
- int dominantBaselineIdentifier = parentAlignmentContext.getDominantBaselineIdentifier();
- boolean newScaledBaselineTableRequired = false;
- if (baselineShiftValue != 0) {
- newScaledBaselineTableRequired = true;
- }
- switch (dominantBaseline) {
- case EN_AUTO:
- newScaledBaselineTableRequired = baselineShiftValue != 0;
- break;
- case EN_USE_SCRIPT: // TODO
- break;
- case EN_NO_CHANGE:
- break;
- case EN_RESET_SIZE:
- newScaledBaselineTableRequired = true;
- break;
- default:
- newScaledBaselineTableRequired = true;
- dominantBaselineIdentifier = dominantBaseline;
- break;
- }
- actualBaselineTable = ScaledBaselineTableFactory.makeGraphicsScaledBaselineTable(
- height,
- dominantBaselineIdentifier,
- scaledBaselineTable.getWritingMode());
- if (newScaledBaselineTableRequired) {
- scaledBaselineTable = ScaledBaselineTableFactory.makeGraphicsScaledBaselineTable(
- height,
- dominantBaselineIdentifier,
- scaledBaselineTable.getWritingMode());
- }
- setAlignmentAdjust(alignmentAdjust);
+ AlignmentContext(int height,
+ Length alignmentAdjust,
+ int alignmentBaseline,
+ Length baselineShift,
+ int dominantBaseline,
+ AlignmentContext parentAlignmentContext) {
+
+ this(height, 0, height, height, alignmentAdjust, alignmentBaseline, baselineShift,
+ dominantBaseline, parentAlignmentContext);
}
/**
- * Creates a new instance of AlignmentContext
+ * Creates a new instance.
+ *
* @param font the font
* @param lineHeight the computed value of the lineHeight property
* @param alignmentAdjust the alignment-adjust property
@@ -117,18 +86,45 @@ public class AlignmentContext implements Constants {
* @param dominantBaseline the dominant-baseline property
* @param parentAlignmentContext the parent alignment context
*/
- public AlignmentContext(Font font
- , int lineHeight
- , Length alignmentAdjust
- , int alignmentBaseline
- , Length baselineShift
- , int dominantBaseline
- , AlignmentContext parentAlignmentContext) {
- this.areaHeight = font.getAscender() - font.getDescender();
+ AlignmentContext(Font font,
+ int lineHeight,
+ Length alignmentAdjust,
+ int alignmentBaseline,
+ Length baselineShift,
+ int dominantBaseline,
+ AlignmentContext parentAlignmentContext) {
+ this(font.getAscender(), font.getDescender(), lineHeight, font.getXHeight(),
+ alignmentAdjust, alignmentBaseline, baselineShift, dominantBaseline,
+ parentAlignmentContext);
+ }
+
+ /**
+ * Creates a new instance of AlignmentContext.
+ * @param altitude the altitude of the area
+ * @param depth the depth of the area
+ * @param lineHeight the line height
+ * @param xHeight the xHeight
+ * @param alignmentAdjust the alignment-adjust property
+ * @param alignmentBaseline the alignment-baseline property
+ * @param baselineShift the baseline-shift property
+ * @param dominantBaseline the dominant-baseline property
+ * @param parentAlignmentContext the parent alignment context
+ */
+ private AlignmentContext(int altitude,
+ int depth,
+ int lineHeight,
+ int xHeight,
+ Length alignmentAdjust,
+ int alignmentBaseline,
+ Length baselineShift,
+ int dominantBaseline,
+ AlignmentContext parentAlignmentContext) {
+
+ this.areaHeight = altitude - depth;
this.lineHeight = lineHeight;
+ this.xHeight = xHeight;
this.parentAlignmentContext = parentAlignmentContext;
this.scaledBaselineTable = parentAlignmentContext.getScaledBaselineTable();
- this.xHeight = font.getXHeight();
setAlignmentBaselineIdentifier(alignmentBaseline
, parentAlignmentContext.getDominantBaselineIdentifier());
setBaselineShift(baselineShift);
@@ -153,13 +149,19 @@ public class AlignmentContext implements Constants {
dominantBaselineIdentifier = dominantBaseline;
break;
}
- actualBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
- dominantBaselineIdentifier,
- scaledBaselineTable.getWritingMode());
+ actualBaselineTable = new ScaledBaselineTable(
+ altitude,
+ depth,
+ xHeight,
+ dominantBaselineIdentifier,
+ scaledBaselineTable.getWritingMode());
if (newScaledBaselineTableRequired) {
- scaledBaselineTable = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font,
- dominantBaselineIdentifier,
- scaledBaselineTable.getWritingMode());
+ scaledBaselineTable = new ScaledBaselineTable(
+ altitude,
+ depth,
+ xHeight,
+ dominantBaselineIdentifier,
+ scaledBaselineTable.getWritingMode());
}
setAlignmentAdjust(alignmentAdjust);
}
@@ -171,13 +173,12 @@ public class AlignmentContext implements Constants {
* @param lineHeight the computed value of the lineHeight property
* @param writingMode the current writing mode
*/
- public AlignmentContext(Font font, int lineHeight, int writingMode) {
+ AlignmentContext(Font font, int lineHeight, int writingMode) {
this.areaHeight = font.getAscender() - font.getDescender();
this.lineHeight = lineHeight;
this.xHeight = font.getXHeight();
- this.parentAlignmentContext = null;
- this.scaledBaselineTable
- = ScaledBaselineTableFactory.makeFontScaledBaselineTable(font, writingMode);
+ this.scaledBaselineTable = new ScaledBaselineTable(font.getAscender(), font.getDescender(),
+ font.getXHeight(), Constants.EN_ALPHABETIC, writingMode);
this.actualBaselineTable = scaledBaselineTable;
this.alignmentBaselineIdentifier = getDominantBaselineIdentifier();
this.alignmentPoint = font.getAscender();
@@ -203,7 +204,8 @@ public class AlignmentContext implements Constants {
}
/**
- * Returns the current alignment baseline identifier
+ * Returns the current alignment baseline identifier.
+ *
* @return the alignment baseline identifier
*/
public int getAlignmentBaselineIdentifier() {
@@ -211,7 +213,7 @@ public class AlignmentContext implements Constants {
}
/**
- * Sets the current alignment baseline identifer. For
+ * Sets the current alignment baseline identifier. For
* alignment-baseline values of "auto" and "baseline" this
* method does the conversion into the appropriate computed
* value assuming script is "auto" and the fo is not fo:character.
@@ -237,8 +239,7 @@ public class AlignmentContext implements Constants {
case EN_MATHEMATICAL:
this.alignmentBaselineIdentifier = alignmentBaseline;
break;
- default:
- break;
+ default: throw new IllegalArgumentException(String.valueOf(alignmentBaseline));
}
}
@@ -285,7 +286,7 @@ public class AlignmentContext implements Constants {
* Return the scaled baseline table for this context.
* @return the scaled baseline table
*/
- public ScaledBaselineTable getScaledBaselineTable() {
+ private ScaledBaselineTable getScaledBaselineTable() {
return this.scaledBaselineTable;
}
@@ -293,16 +294,8 @@ public class AlignmentContext implements Constants {
* Return the dominant baseline identifier.
* @return the dominant baseline identifier
*/
- public int getDominantBaselineIdentifier() {
- return scaledBaselineTable.getDominantBaselineIdentifier();
- }
-
- /**
- * Return the writing mode.
- * @return the writing mode
- */
- public int getWritingMode() {
- return scaledBaselineTable.getWritingMode();
+ private int getDominantBaselineIdentifier() {
+ return actualBaselineTable.getDominantBaselineIdentifier();
}
/**
@@ -312,7 +305,6 @@ public class AlignmentContext implements Constants {
*/
private void setBaselineShift(Length baselineShift) {
baselineShiftValue = 0;
- ScaledBaselineTable sbt = null;
switch (baselineShift.getEnum()) {
case EN_BASELINE: //Nothing to do
break;
@@ -332,9 +324,7 @@ public class AlignmentContext implements Constants {
, LengthBase.CUSTOM_BASE
, parentAlignmentContext.getLineHeight()));
break;
- default:
- break;
-
+ default: throw new IllegalArgumentException(String.valueOf(baselineShift.getEnum()));
}
}
@@ -351,7 +341,7 @@ public class AlignmentContext implements Constants {
* the parent dominant baseline.
* @return the offset in shift direction
*/
- public int getBaselineOffset() {
+ private int getBaselineOffset() {
if (parentAlignmentContext == null) {
return 0;
}
@@ -370,9 +360,9 @@ public class AlignmentContext implements Constants {
/**
* Return the offset between the current dominant baseline and
* the outermost parent dominant baseline.
- * @return the offet in shift direction
+ * @return the offset in shift direction
*/
- public int getTotalBaselineOffset() {
+ private int getTotalBaselineOffset() {
int offset = 0;
if (parentAlignmentContext != null) {
offset = getBaselineOffset() + parentAlignmentContext.getTotalBaselineOffset();
@@ -395,7 +385,7 @@ public class AlignmentContext implements Constants {
* @param alignmentBaselineId the alignment baseline
* @return the offset
*/
- public int getTotalAlignmentBaselineOffset(int alignmentBaselineId) {
+ private int getTotalAlignmentBaselineOffset(int alignmentBaselineId) {
int offset = baselineShiftValue;
if (parentAlignmentContext != null) {
offset = parentAlignmentContext.getTotalBaselineOffset()
@@ -408,11 +398,12 @@ public class AlignmentContext implements Constants {
/**
* Return the offset between the dominant baseline and
- * the given actual baseline
+ * the given actual baseline.
+ *
* @param baselineIdentifier the baseline
* @return the offset
*/
- public int getActualBaselineOffset(int baselineIdentifier) {
+ private int getActualBaselineOffset(int baselineIdentifier) {
// This is the offset from the dominant baseline to the alignment baseline
int offset = getTotalAlignmentBaselineOffset() - getTotalBaselineOffset();
// Add the offset to the actual baseline we want
@@ -443,7 +434,7 @@ public class AlignmentContext implements Constants {
* Return the line height of the context.
* @return the height
*/
- public int getLineHeight() {
+ private int getLineHeight() {
return lineHeight;
}
@@ -469,7 +460,7 @@ public class AlignmentContext implements Constants {
* The x height of the context.
* @return the x height
*/
- public int getXHeight() {
+ private int getXHeight() {
return this.xHeight;
}
@@ -513,10 +504,6 @@ public class AlignmentContext implements Constants {
&& parentAlignmentContext.usesInitialBaselineTable());
}
- private boolean isHorizontalWritingMode() {
- return (getWritingMode() == EN_LR_TB || getWritingMode() == EN_RL_TB);
- }
-
/** {@inheritDoc} */
public String toString() {
StringBuffer sb = new StringBuffer(64);
diff --git a/src/java/org/apache/fop/layoutmgr/inline/BasicScaledBaselineTable.java b/src/java/org/apache/fop/layoutmgr/inline/BasicScaledBaselineTable.java
deleted file mode 100644
index 467f2e154..000000000
--- a/src/java/org/apache/fop/layoutmgr/inline/BasicScaledBaselineTable.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * 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.layoutmgr.inline;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.fop.fo.Constants;
-
-
-/**
- * An implementation of the ScaledBaselineTable interface which calculates
- * all baselines given the height above and below the dominant baseline.
- */
-public class BasicScaledBaselineTable implements ScaledBaselineTable, Constants {
-
- /** A logger for this class */
- protected Log log = LogFactory.getLog(BasicScaledBaselineTable.class);
-
- private int altitude;
- private int depth;
- private int xHeight;
- private int dominantBaselineIdentifier;
- private int writingMode;
- private int dominantBaselineOffset;
- private int beforeEdgeOffset;
- private int afterEdgeOffset;
-
- private static final float HANGING_BASELINE_FACTOR = 0.8f;
- private static final float MATHEMATICAL_BASELINE_FACTOR = 0.5f;
-
- /**
- *
- * Creates a new instance of BasicScaledBaselineTable for the given
- * altitude, depth, xHeight, baseline and writingmode.
- * @param altitude the height of the box or the font ascender
- * @param depth the font descender or 0
- * @param xHeight the font xHeight
- * @param dominantBaselineIdentifier the dominant baseline given as an integer constant
- * @param writingMode the writing mode given as an integer constant
- */
- public BasicScaledBaselineTable(int altitude
- , int depth
- , int xHeight
- , int dominantBaselineIdentifier
- , int writingMode) {
- this.altitude = altitude;
- this.depth = depth;
- this.xHeight = xHeight;
- this.dominantBaselineIdentifier = dominantBaselineIdentifier;
- this.writingMode = writingMode;
- this.dominantBaselineOffset = getBaselineDefaultOffset(this.dominantBaselineIdentifier);
- this.beforeEdgeOffset = altitude - dominantBaselineOffset;
- this.afterEdgeOffset = depth - dominantBaselineOffset;
- }
-
- /**
- * Return the dominant baseline for this baseline table.
- * @return the dominant baseline
- */
- public int getDominantBaselineIdentifier() {
- return this.dominantBaselineIdentifier;
- }
-
- /**
- * Return the writing mode for this baseline table.
- * @return the writing mode
- */
- public int getWritingMode() {
- return this.writingMode;
- }
-
- /**
- * Return the baseline offset measured from the dominant
- * baseline for the given baseline.
- * @param baselineIdentifier the baseline identifier
- * @return the baseline offset
- */
- public int getBaseline(int baselineIdentifier) {
- int offset;
- if (!isHorizontalWritingMode()) {
- switch (baselineIdentifier) {
- default:
- case EN_TOP:
- case EN_TEXT_TOP:
- case EN_TEXT_BOTTOM:
- case EN_BOTTOM:
- log.warn("The given baseline is only supported for horizontal"
- + " writing modes");
- offset = 0;
- }
- } else {
- switch (baselineIdentifier) {
- case EN_TOP: // fall through
- case EN_BEFORE_EDGE:
- offset = beforeEdgeOffset;
- break;
- case EN_TEXT_TOP:
- case EN_TEXT_BEFORE_EDGE:
- case EN_HANGING:
- case EN_CENTRAL:
- case EN_MIDDLE:
- case EN_MATHEMATICAL:
- case EN_ALPHABETIC:
- case EN_IDEOGRAPHIC:
- case EN_TEXT_BOTTOM:
- case EN_TEXT_AFTER_EDGE:
- offset = getBaselineDefaultOffset(baselineIdentifier) - dominantBaselineOffset;
- break;
- case EN_BOTTOM: // fall through
- case EN_AFTER_EDGE:
- offset = afterEdgeOffset;
- break;
- default:
- offset = 0;
- break;
- }
- }
- return offset;
- }
-
- private boolean isHorizontalWritingMode() {
- return writingMode == EN_LR_TB || writingMode == EN_RL_TB;
- }
-
- /**
- * Return the baseline offset measured from the font's default
- * baseline for the given baseline.
- * @param baselineIdentifier the baseline identifier
- * @return the baseline offset
- */
- private int getBaselineDefaultOffset(int baselineIdentifier) {
- int offset = 0;
- switch (baselineIdentifier) {
- case EN_TEXT_BEFORE_EDGE:
- offset = altitude;
- break;
- case EN_HANGING:
- offset = (int)Math.round(altitude * HANGING_BASELINE_FACTOR);
- break;
- case EN_CENTRAL:
- offset = (altitude - depth) / 2 + depth;
- break;
- case EN_MIDDLE:
- offset = xHeight / 2;
- break;
- case EN_MATHEMATICAL:
- offset = (int)Math.round(altitude * MATHEMATICAL_BASELINE_FACTOR);
- break;
- case EN_ALPHABETIC:
- offset = 0;
- break;
- case EN_IDEOGRAPHIC: // Fall through
- case EN_TEXT_AFTER_EDGE:
- offset = depth;
- break;
- default:
- break;
- }
- return offset;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setBeforeAndAfterBaselines(int beforeBaseline, int afterBaseline) {
- beforeEdgeOffset = beforeBaseline;
- afterEdgeOffset = afterBaseline;
- }
-
- /**
- * {@inheritDoc}
- */
- public ScaledBaselineTable deriveScaledBaselineTable(int baselineIdentifier) {
- BasicScaledBaselineTable bac
- = new BasicScaledBaselineTable(altitude, depth, xHeight
- , baselineIdentifier, this.writingMode);
- return bac;
- }
-
-}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java b/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java
index 19a1a1f8a..d5d3e5edb 100644
--- a/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java
+++ b/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java
@@ -19,34 +19,164 @@
package org.apache.fop.layoutmgr.inline;
+import org.apache.fop.fo.Constants;
+
+
/**
* The FOP specific incarnation of the XSL-FO scaled baseline table.
* All baseline tables are scaled to the font size of the font they
- * apply to. This interface uses a coordinate system with its origin
+ * apply to. This class uses a coordinate system with its origin
* where the dominant baseline intersects the start edge of the box.
* All measurements are in mpt.
*/
-public interface ScaledBaselineTable {
+final class ScaledBaselineTable {
+
+ private static final float HANGING_BASELINE_FACTOR = 0.8f;
+
+ private static final float MATHEMATICAL_BASELINE_FACTOR = 0.5f;
+
+ private final int altitude;
+
+ private final int depth;
+
+ private final int xHeight;
+
+ private final int dominantBaselineIdentifier;
+
+ private final int writingMode;
+
+ private final int dominantBaselineOffset;
+
+ private int beforeEdgeOffset;
+
+ private int afterEdgeOffset;
+
+
+ /**
+ *
+ * Creates a new instance of BasicScaledBaselineTable for the given
+ * altitude, depth, xHeight, baseline and writing mode.
+ * @param altitude the height of the box or the font ascender
+ * @param depth the font descender or 0
+ * @param xHeight the font xHeight
+ * @param dominantBaselineIdentifier the dominant baseline given as an integer constant
+ * @param writingMode the writing mode given as an integer constant
+ */
+ ScaledBaselineTable(int altitude,
+ int depth,
+ int xHeight,
+ int dominantBaselineIdentifier,
+ int writingMode) {
+ this.altitude = altitude;
+ this.depth = depth;
+ this.xHeight = xHeight;
+ this.dominantBaselineIdentifier = dominantBaselineIdentifier;
+ this.writingMode = writingMode;
+ this.dominantBaselineOffset = getBaselineDefaultOffset(this.dominantBaselineIdentifier);
+ this.beforeEdgeOffset = altitude - dominantBaselineOffset;
+ this.afterEdgeOffset = depth - dominantBaselineOffset;
+ }
/**
- * Return the dominant baseline identifer for this alignment context.
- * @return the dominant baseline identifier
+ * Return the dominant baseline for this baseline table.
+ * @return the dominant baseline
*/
- int getDominantBaselineIdentifier();
+ int getDominantBaselineIdentifier() {
+ return this.dominantBaselineIdentifier;
+ }
/**
- * Return the writing mode for this aligment context.
+ * Return the writing mode for this baseline table.
* @return the writing mode
*/
- int getWritingMode();
+ int getWritingMode() {
+ return this.writingMode;
+ }
+
+ /**
+ * Return the offset of the given baseline from the dominant baseline.
+ *
+ * @param baselineIdentifier a baseline identifier
+ * @return the offset from the dominant baseline
+ */
+ int getBaseline(int baselineIdentifier) {
+ int offset = 0;
+ if (!isHorizontalWritingMode()) {
+ switch (baselineIdentifier) {
+ case Constants.EN_TOP:
+ case Constants.EN_TEXT_TOP:
+ case Constants.EN_TEXT_BOTTOM:
+ case Constants.EN_BOTTOM:
+ throw new IllegalArgumentException("Baseline " + baselineIdentifier
+ + " only supported for horizontal writing modes");
+ default: // TODO
+ }
+ }
+ switch (baselineIdentifier) {
+ case Constants.EN_TOP: // fall through
+ case Constants.EN_BEFORE_EDGE:
+ offset = beforeEdgeOffset;
+ break;
+ case Constants.EN_TEXT_TOP:
+ case Constants.EN_TEXT_BEFORE_EDGE:
+ case Constants.EN_HANGING:
+ case Constants.EN_CENTRAL:
+ case Constants.EN_MIDDLE:
+ case Constants.EN_MATHEMATICAL:
+ case Constants.EN_ALPHABETIC:
+ case Constants.EN_IDEOGRAPHIC:
+ case Constants.EN_TEXT_BOTTOM:
+ case Constants.EN_TEXT_AFTER_EDGE:
+ offset = getBaselineDefaultOffset(baselineIdentifier) - dominantBaselineOffset;
+ break;
+ case Constants.EN_BOTTOM: // fall through
+ case Constants.EN_AFTER_EDGE:
+ offset = afterEdgeOffset;
+ break;
+ default: throw new IllegalArgumentException(String.valueOf(baselineIdentifier));
+ }
+ return offset;
+ }
+
+ private boolean isHorizontalWritingMode() {
+ return writingMode == Constants.EN_LR_TB || writingMode == Constants.EN_RL_TB;
+ }
/**
- * Return the offset measured from the dominant
- * baseline for the given baseline identifier.
+ * Return the baseline offset measured from the font's default
+ * baseline for the given baseline.
* @param baselineIdentifier the baseline identifier
* @return the baseline offset
*/
- int getBaseline(int baselineIdentifier);
+ private int getBaselineDefaultOffset(int baselineIdentifier) {
+ int offset = 0;
+ switch (baselineIdentifier) {
+ case Constants.EN_TEXT_BEFORE_EDGE:
+ offset = altitude;
+ break;
+ case Constants.EN_HANGING:
+ offset = Math.round(altitude * HANGING_BASELINE_FACTOR);
+ break;
+ case Constants.EN_CENTRAL:
+ offset = (altitude - depth) / 2 + depth;
+ break;
+ case Constants.EN_MIDDLE:
+ offset = xHeight / 2;
+ break;
+ case Constants.EN_MATHEMATICAL:
+ offset = Math.round(altitude * MATHEMATICAL_BASELINE_FACTOR);
+ break;
+ case Constants.EN_ALPHABETIC:
+ offset = 0;
+ break;
+ case Constants.EN_IDEOGRAPHIC: // Fall through
+ case Constants.EN_TEXT_AFTER_EDGE:
+ offset = depth;
+ break;
+ default: throw new IllegalArgumentException(String.valueOf(baselineIdentifier));
+ }
+ return offset;
+ }
/**
* Sets the position of the before and after baselines.
@@ -56,7 +186,10 @@ public interface ScaledBaselineTable {
* @param beforeBaseline the offset of the before-edge baseline from the dominant baseline
* @param afterBaseline the offset of the after-edge baseline from the dominant baseline
*/
- void setBeforeAndAfterBaselines(int beforeBaseline, int afterBaseline);
+ void setBeforeAndAfterBaselines(int beforeBaseline, int afterBaseline) {
+ beforeEdgeOffset = beforeBaseline;
+ afterEdgeOffset = afterBaseline;
+ }
/**
* Return a new baseline table for the given baseline based
@@ -64,6 +197,10 @@ public interface ScaledBaselineTable {
* @param baselineIdentifier the baseline identifer
* @return a new baseline with the new baseline
*/
- ScaledBaselineTable deriveScaledBaselineTable(int baselineIdentifier);
+ ScaledBaselineTable deriveScaledBaselineTable(int baselineIdentifier) {
+ ScaledBaselineTable bac = new ScaledBaselineTable(altitude, depth, xHeight,
+ baselineIdentifier, this.writingMode);
+ return bac;
+ }
}
diff --git a/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java b/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java
deleted file mode 100644
index 0d48ccbfe..000000000
--- a/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTableFactory.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.layoutmgr.inline;
-
-import org.apache.fop.fo.Constants;
-import org.apache.fop.fonts.Font;
-
-
-/**
- * A factory class for making alignment contexts.
- * Currently supports alignment contexts for basic fonts
- * and graphic inlines.
- */
-public final class ScaledBaselineTableFactory implements Constants {
-
- private ScaledBaselineTableFactory() {
- }
-
- /**
- * Creates a new instance of BasicScaledBaselineTable for the given
- * font, baseline and writingmode.
- * @param font the font for which a baseline table is requested
- * @param dominantBaselineIdentifier the dominant baseline given as an integer constant
- * @param writingMode the writing mode given as an integer constant
- * @return a scaled baseline table for the given font
- */
- public static ScaledBaselineTable makeFontScaledBaselineTable(Font font
- , int dominantBaselineIdentifier
- , int writingMode) {
- return new BasicScaledBaselineTable(font.getAscender(), font.getDescender()
- , font.getXHeight(), dominantBaselineIdentifier, writingMode);
- }
-
- /**
- * Creates a new instance of BasicScaledBaselineTable for the given
- * font and writingmode. It assumes an alphabetic baseline.
- * @param font the font for which a baseline table is requested
- * @param writingMode the writing mode given as an integer constant
- * @return a scaled baseline table for the given font
- */
- public static ScaledBaselineTable makeFontScaledBaselineTable(Font font, int writingMode) {
- return makeFontScaledBaselineTable(font, EN_ALPHABETIC, writingMode);
- }
-
- /**
- * Creates a new instance of BasicScaledBaselineTable for the given
- * height, baseline and writingmode. This is used for non font based areas like
- * external graphic or inline foreign object.
- * @param height the height for which a baseline table is requested
- * @param dominantBaselineIdentifier the dominant baseline given as an integer constant
- * @param writingMode the writing mode given as an integer constant
- * @return a scaled baseline table for the given dimensions
- */
- public static ScaledBaselineTable makeGraphicsScaledBaselineTable(int height
- , int dominantBaselineIdentifier
- , int writingMode) {
- return new BasicScaledBaselineTable(height, 0, height
- , dominantBaselineIdentifier, writingMode);
- }
-
-}