You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by bc...@apache.org on 2004/10/18 22:16:54 UTC
cvs commit: xml-fop/src/java/org/apache/fop/fo/properties CommonBorderPaddingBackground.java CommonFont.java
bckfnn 2004/10/18 13:16:54
Added: src/java/org/apache/fop/fo/properties
CommonBorderPaddingBackground.java CommonFont.java
Log:
Initial version.
PR: 31699
Revision Changes Path
1.1 xml-fop/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java
Index: CommonBorderPaddingBackground.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* 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.
*/
/* $Id: CommonBorderPaddingBackground.java,v 1.1 2004/10/18 20:16:54 bckfnn Exp $ */
package org.apache.fop.fo.properties;
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.datatypes.Length;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.PropertyList;
/**
* Stores all common border and padding properties.
* See Sec. 7.7 of the XSL-FO Standard.
*/
public class CommonBorderPaddingBackground implements Cloneable {
/**
* The "background-attachment" property.
*/
public int backgroundAttachment;
/**
* The "background-color" property.
*/
public ColorType backgroundColor;
/**
* The "background-image" property.
*/
public String backgroundImage;
/**
* The "background-repeat" property.
*/
public int backgroundRepeat;
/**
* The "background-position-horizontal" property.
*/
public Length backgroundPositionHorizontal;
/**
* The "background-position-vertical" property.
*/
public Length backgroundPositionVertical;
public static final int BEFORE = 0;
public static final int AFTER = 1;
public static final int START = 2;
public static final int END = 3;
private static class BorderInfo implements Cloneable {
private int mStyle; // Enum for border style
private ColorType mColor; // Border color
private CondLengthProperty mWidth;
BorderInfo(int style, CondLengthProperty width, ColorType color) {
mStyle = style;
mWidth = width;
mColor = color;
}
}
private BorderInfo[] borderInfo = new BorderInfo[4];
private CondLengthProperty[] padding = new CondLengthProperty[4];
/**
* Construct a CommonBorderAndPadding object.
* @param pList The PropertyList to get properties from.
*/
public CommonBorderPaddingBackground(PropertyList pList) {
backgroundAttachment = pList.get(Constants.PR_BACKGROUND_ATTACHMENT).getEnum();
backgroundColor = pList.get(Constants.PR_BACKGROUND_COLOR).getColorType();
if (backgroundColor.getAlpha() == 0) {
backgroundColor = null;
}
backgroundImage = pList.get(Constants.PR_BACKGROUND_IMAGE).getString();
if (backgroundImage == null || "none".equals(backgroundImage)) {
backgroundImage = null;
} else {
backgroundRepeat = pList.get(Constants.PR_BACKGROUND_REPEAT).getEnum();
backgroundPositionHorizontal = pList.get(Constants.PR_BACKGROUND_POSITION_HORIZONTAL).getLength();
backgroundPositionVertical = pList.get(Constants.PR_BACKGROUND_POSITION_VERTICAL).getLength();
}
initBorderInfo(pList, BEFORE,
Constants.PR_BORDER_BEFORE_COLOR,
Constants.PR_BORDER_BEFORE_STYLE,
Constants.PR_BORDER_BEFORE_WIDTH,
Constants.PR_PADDING_BEFORE);
initBorderInfo(pList, AFTER,
Constants.PR_BORDER_AFTER_COLOR,
Constants.PR_BORDER_AFTER_STYLE,
Constants.PR_BORDER_AFTER_WIDTH,
Constants.PR_PADDING_AFTER);
initBorderInfo(pList, START,
Constants.PR_BORDER_START_COLOR,
Constants.PR_BORDER_START_STYLE,
Constants.PR_BORDER_START_WIDTH,
Constants.PR_PADDING_START);
initBorderInfo(pList, END,
Constants.PR_BORDER_END_COLOR,
Constants.PR_BORDER_END_STYLE,
Constants.PR_BORDER_END_WIDTH,
Constants.PR_PADDING_END);
}
private void initBorderInfo(PropertyList pList, int side,
int colorProp, int styleProp, int widthProp, int paddingProp)
{
padding[side] = pList.get(paddingProp).getCondLength();
// If style = none, force width to 0, don't get Color (spec 7.7.20)
int style = pList.get(styleProp).getEnum();
if (style != Constants.NONE) {
borderInfo[side] = new BorderInfo(style,
pList.get(widthProp).getCondLength(),
pList.get(colorProp).getColorType());
}
}
public int getBorderStartWidth(boolean bDiscard) {
return getBorderWidth(START, bDiscard);
}
public int getBorderEndWidth(boolean bDiscard) {
return getBorderWidth(END, bDiscard);
}
public int getBorderBeforeWidth(boolean bDiscard) {
return getBorderWidth(BEFORE, bDiscard);
}
public int getBorderAfterWidth(boolean bDiscard) {
return getBorderWidth(AFTER, bDiscard);
}
public int getPaddingStart(boolean bDiscard) {
return getPadding(START, bDiscard);
}
public int getPaddingEnd(boolean bDiscard) {
return getPadding(END, bDiscard);
}
public int getPaddingBefore(boolean bDiscard) {
return getPadding(BEFORE, bDiscard);
}
public int getPaddingAfter(boolean bDiscard) {
return getPadding(AFTER, bDiscard);
}
public int getBorderWidth(int side, boolean bDiscard) {
if ((borderInfo[side] == null)
|| (borderInfo[side].mStyle == Constants.NONE)
|| (bDiscard && borderInfo[side].mWidth.isDiscard())) {
return 0;
} else {
return borderInfo[side].mWidth.getLengthValue();
}
}
public ColorType getBorderColor(int side) {
if (borderInfo[side] != null) {
return borderInfo[side].mColor;
} else {
return null;
}
}
public int getBorderStyle(int side) {
if (borderInfo[side] != null) {
return borderInfo[side].mStyle;
} else {
return 0;
}
}
public int getPadding(int side, boolean bDiscard) {
if ((padding[side] == null) || (bDiscard && padding[side].isDiscard())) {
return 0;
} else {
return padding[side].getLengthValue();
}
}
/**
* Return all the border and padding height in the block progression
* dimension.
* @param bDiscard the discard flag.
* @return all the padding and border height.
*/
public int getBPPaddingAndBorder(boolean bDiscard) {
return getPaddingBefore(bDiscard) + getPaddingAfter(bDiscard) +
getBorderBeforeWidth(bDiscard) + getBorderAfterWidth(bDiscard);
}
public String toString() {
return "CommonBordersAndPadding (Before, After, Start, End):\n" +
"Borders: (" + getBorderBeforeWidth(false) + ", " + getBorderAfterWidth(false) + ", " +
getBorderStartWidth(false) + ", " + getBorderEndWidth(false) + ")\n" +
"Border Colors: (" + getBorderColor(BEFORE) + ", " + getBorderColor(AFTER) + ", " +
getBorderColor(START) + ", " + getBorderColor(END) + ")\n" +
"Padding: (" + getPaddingBefore(false) + ", " + getPaddingAfter(false) + ", " +
getPaddingStart(false) + ", " + getPaddingEnd(false) + ")\n";
}
}
1.1 xml-fop/src/java/org/apache/fop/fo/properties/CommonFont.java
Index: CommonFont.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* 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.
*/
/* $Id: CommonFont.java,v 1.1 2004/10/18 20:16:54 bckfnn Exp $ */
package org.apache.fop.fo.properties;
// FOP
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.Numeric;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontMetrics;
/**
* Collection of properties used in
*/
public class CommonFont {
/**
* The "font-family" property.
*/
public String fontFamily;
/**
* The "font-selection-strategy" property.
*/
public int fontSelectionStrategy;
/**
* The "font-size" property.
*/
public Length fontSize;
/**
* The "font-stretch" property.
*/
public int fontStretch;
/**
* The "font-size-adjust" property.
*/
public Numeric fontSizeAdjust;
/**
* The "font-style" property.
*/
public String fontStyle;
/**
* The "font-variant" property.
*/
public int fontVariant;
/**
* The "font-weight" property.
*/
public String fontWeight;
private Font fontState;
/**
* Create a CommonFont object.
* @param pList The PropertyList to get properties from.
*/
public CommonFont(PropertyList pList) {
fontFamily = pList.get(Constants.PR_FONT_FAMILY).getString();
fontSelectionStrategy = pList.get(Constants.PR_FONT_SELECTION_STRATEGY).getEnum();
fontSize = pList.get(Constants.PR_FONT_SIZE).getLength();
fontStretch = pList.get(Constants.PR_FONT_STRETCH).getEnum();
fontSizeAdjust = pList.get(Constants.PR_FONT_SIZE_ADJUST).getNumeric();
fontStyle = pList.get(Constants.PR_FONT_STYLE).getString();
fontVariant = pList.get(Constants.PR_FONT_VARIANT).getEnum();
fontWeight = pList.get(Constants.PR_FONT_WEIGHT).getString();
}
/**
* Create and return a Font object based on the properties.
*
* @param fontInfo
* @return a Font object.
*/
public Font getFontState(FontInfo fontInfo) {
if (fontState == null) {
/**@todo this is ugly. need to improve. */
int font_weight = 400;
if (fontWeight.equals("bolder")) {
// +100 from inherited
} else if (fontWeight.equals("lighter")) {
// -100 from inherited
} else {
try {
font_weight = Integer.parseInt(fontWeight);
} catch (NumberFormatException nfe) {
} /** TODO: log that exception */
}
font_weight = ((int) font_weight / 100) * 100;
if (font_weight < 100) {
font_weight = 100;
} else if (font_weight > 900) {
font_weight = 900;
}
// NOTE: this is incomplete. font-size may be specified with
// various kinds of keywords too
//int fontVariant = propertyList.get("font-variant").getEnum();
String fname = fontInfo.fontLookup(fontFamily, fontStyle,
font_weight);
FontMetrics metrics = fontInfo.getMetricsFor(fname);
fontState = new Font(fname, metrics, fontSize.getValue());
}
return fontState;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org