* @param lineHeight the computed value of the lineHeight property
* @param writingMode the current writing mode
*/
- public AlignmentContext(Font font, int lineHeight, WritingMode writingMode) {
- AlignmentContext(Font font, int lineHeight, int writingMode) {
++ AlignmentContext(Font font, int lineHeight, WritingMode writingMode) {
this.areaHeight = font.getAscender() - font.getDescender();
this.lineHeight = lineHeight;
this.xHeight = font.getXHeight();
* Return the dominant baseline identifier.
* @return the dominant baseline identifier
*/
- public int getDominantBaselineIdentifier() {
- return scaledBaselineTable.getDominantBaselineIdentifier();
+ private int getDominantBaselineIdentifier() {
+ return actualBaselineTable.getDominantBaselineIdentifier();
}
- public WritingMode getWritingMode() {
+ /**
+ * Return the writing mode.
+ * @return the writing mode
+ */
- }
++/* public WritingMode getWritingMode() {
+ return scaledBaselineTable.getWritingMode();
++ }*/
+
/**
* Calculates the baseline shift value based on the baseline-shift
* property value.
&& parentAlignmentContext.usesInitialBaselineTable());
}
- private boolean isHorizontalWritingMode() {
++ /* private boolean isHorizontalWritingMode() {
+ return (getWritingMode() == WritingMode.LR_TB || getWritingMode() == WritingMode.RL_TB);
- }
++ }*/
+
/** {@inheritDoc} */
public String toString() {
StringBuffer sb = new StringBuffer(64);
package org.apache.fop.layoutmgr.inline;
+ import org.apache.fop.fo.Constants;
+import org.apache.fop.traits.WritingMode;
+
/**
* The FOP specific incarnation of the XSL-FO scaled baseline table.
* All baseline tables are scaled to the font size of the font they
* 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 WritingMode 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) {
++ WritingMode 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
*/
- WritingMode getWritingMode();
- int getWritingMode() {
++ WritingMode 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 writingMode == WritingMode.LR_TB || writingMode == WritingMode.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
*/