/*-- $Id: PropertyManager.java,v 1.1 2001/03/04 21:29:46 klease Exp $ -- */
/*
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.fo;
import org.apache.fop.layout.FontState;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.layout.BorderAndPadding;
import org.apache.fop.fo.properties.BreakBefore;
import org.apache.fop.fo.properties.Constants;
import org.apache.fop.layout.HyphenationProps;
import org.apache.fop.apps.FOPException;
import java.text.MessageFormat;
import java.text.FieldPosition;
public class PropertyManager {
private PropertyList properties;
private FontState fontState=null;
private BorderAndPadding borderAndPadding = null;
private HyphenationProps hyphProps = null;
private String[] saLeft ;
private String[] saRight;
private String[] saTop ;
private String[] saBottom ;
private static MessageFormat msgColorFmt = new MessageFormat("border-{0}-color");
private static MessageFormat msgStyleFmt = new MessageFormat("border-{0}-style");
private static MessageFormat msgWidthFmt = new MessageFormat("border-{0}-width");
private static MessageFormat msgPaddingFmt = new MessageFormat("padding-{0}");
public PropertyManager(PropertyList pList) {
this.properties = pList;
}
private void initDirections() {
saLeft = new String[1];
saRight = new String[1];
saTop = new String[1];
saBottom = new String[1];
saTop[0] = properties.wmAbsToRel(PropertyList.TOP);
saBottom[0] = properties.wmAbsToRel(PropertyList.BOTTOM);
saLeft[0] = properties.wmAbsToRel(PropertyList.LEFT);
saRight[0] = properties.wmAbsToRel(PropertyList.RIGHT);
}
public FontState getFontState(FontInfo fontInfo) throws FOPException {
if (fontState == null) {
String fontFamily = properties.get("font-family").getString();
String fontStyle =properties.get("font-style").getString();
String fontWeight =properties.get("font-weight").getString();
// NOTE: this is incomplete. font-size may be specified with
// various kinds of keywords too
int fontSize =properties.get("font-size").getLength().mvalue();
int fontVariant =properties.get("font-variant").getEnum();
// fontInfo is same for the whole FOP run but set in all FontState
fontState = new FontState(fontInfo, fontFamily,
fontStyle, fontWeight, fontSize, fontVariant);
}
return fontState ;
}
public BorderAndPadding getBorderAndPadding() {
if (borderAndPadding == null) {
this.borderAndPadding = new BorderAndPadding();
initDirections();
initBorderInfo(BorderAndPadding.TOP, saTop);
initBorderInfo(BorderAndPadding.BOTTOM, saBottom);
initBorderInfo(BorderAndPadding.LEFT, saLeft);
initBorderInfo(BorderAndPadding.RIGHT, saRight);
/****
// Border color
this.borderAndPadding.borderTopColor =
properties.get(msgFmt.format(saTop)).getColorType();
this.borderAndPadding.borderBottomColor =
properties.get(msgFmt.format(saBottom)).getColorType();
this.borderAndPadding.borderLeftColor =
properties.get(msgFmt.format(saLeft)).getColorType();
this.borderAndPadding.borderRightColor =
properties.get(msgFmt.format(saRight)).getColorType();
// Border style
this.borderAndPadding.borderTopStyle =
properties.get(msgFmt.format(saTop)).getEnum();
this.borderAndPadding.borderBottomStyle =
properties.get(msgFmt.format(saBottom)).getEnum();
this.borderAndPadding.borderLeftStyle =
properties.get(msgFmt.format(saLeft)).getEnum();
this.borderAndPadding.borderRightStyle =
properties.get(msgFmt.format(saRight)).getEnum();
// Border width
this.borderAndPadding.borderTopWidth =
properties.get(msgFmt.format(saTop)).getCondLength();
this.borderAndPadding.borderBottomWidth =
properties.get(msgFmt.format(saBottom)).getCondLength();
this.borderAndPadding.borderLeftWidth =
properties.get(msgFmt.format(saLeft)).getCondLength();
this.borderAndPadding.borderRightWidth =
properties.get(msgFmt.format(saRight)).getCondLength();
****/
}
return borderAndPadding;
}
private void initBorderInfo(int whichSide, String[] saSide) {
borderAndPadding.setPadding(whichSide,
properties.get(msgPaddingFmt.format(saSide)).getCondLength());
// If style = none, force width to 0, don't get Color
int style = properties.get(msgStyleFmt.format(saSide)).getEnum();
if (style != Constants.NONE) {
borderAndPadding.setBorder(whichSide, style,
properties.get(msgWidthFmt.format(saSide)).getCondLength(),
properties.get(msgColorFmt.format(saSide)).getColorType());
}
}
public HyphenationProps getHyphenationProps() {
if (hyphProps == null) {
this.hyphProps = new HyphenationProps();
hyphProps.hyphenate = this.properties.get("hyphenate").getEnum();
hyphProps.hyphenationChar = this.properties.get("hyphenation-character").getCharacter();
hyphProps.hyphenationPushCharacterCount = this.properties.get( "hyphenation-push-character-count").getNumber().intValue();
hyphProps.hyphenationRemainCharacterCount = this.properties.get( "hyphenation-remain-character-count").getNumber().intValue();
hyphProps.language = this.properties.get("language").getString();
hyphProps.country = this.properties.get("country").getString();
}
return hyphProps;
}
public int checkBreakBefore() {
switch(properties.get("break-before").getEnum()) {
case BreakBefore.PAGE:
return Status.FORCE_PAGE_BREAK;
case BreakBefore.ODD_PAGE:
return Status.FORCE_PAGE_BREAK_ODD;
case BreakBefore.EVEN_PAGE:
return Status.FORCE_PAGE_BREAK_EVEN;
case BreakBefore.COLUMN:
return Status.FORCE_COLUMN_BREAK;
default:
return Status.OK;
}
}
}