Hi,
I'm new to FOP development and tried to implement the margin shorthand
to get started (working in the fop-0_20_2-maintain branch).
- foproperties.xml is changed to reflect that margin-top etc can be set
by the margin shorthand and the margin property is changed from
ToBeImplemented to List using a new shorthand parser.
- MarginShorthandParser is new and resembles the GenericShorthandParser.
I think it implements to fo spec correctly. The spec says (in 7.29.14)
for the margin shorthand:
No. of| Set margin-* property to arg
arguments | top | right | bottom | left
--
1 |1 | 1 | 1 |1
2 |1 | 2 | 1 |2
3 |1 | 2 | 3 |2
4 |1 | 2 | 3 |4
Some remarks:
- The MarginShorthandParser could possibly be generalized to handle
other properties using the same syntax in a
shorthand-{top,right,bottom,left} context. I'm not sure whether there
are such properties (candidates are padding and border-width but these
are handled already in a specialized parser).
- Is it really sensible to have a MarginShorthandParser or could this be
handled elsewhere, e.g. directly in the MarginMaker?
- I didn't add an error message in the case of a wrong number of
parameters (eg margin=0in 5pt 5pt 5pt 24pt).
Please use the code if you think it's ok and otherwise please tell me
what's not ok with it.
Peter
Index: foproperties.xml
===
RCS file: /home/cvspublic/xml-fop/src/codegen/foproperties.xml,v
retrieving revision 1.25.2.3
diff -r1.25.2.3 foproperties.xml
831a832
shorthandmargin/shorthand
837a839
shorthandmargin/shorthand
843a846
shorthandmargin/shorthand
849a853
shorthandmargin/shorthand
2093,2094c2097,2098
datatypeToBeImplemented/datatype
default/default
---
datatypeList/datatype
datatype-parserMarginShorthandParser/datatype-parser
/*
* $Id: $
* 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 java.util.Vector;
import java.util.Enumeration;
public class MarginShorthandParser implements ShorthandParser {
protected Vector list;// Vector of Property objects
public MarginShorthandParser(ListProperty listprop) {
this.list = listprop.getList();
}
protected Property getElement(int index) {
if (list.size() index)
return (Property)list.elementAt(index);
else
return null;
}
protected int count() {
return list.size();
}
// Stores 1 to 4 values for margin-top, -right, -bottom or -left
public Property getValueForProperty(String propName,
Property.Maker maker,
PropertyList propertyList) {
Property prop = null;
// Check for keyword inherit
if (count() == 1)
{
String sval = ((Property)list.elementAt(0)).getString();
if (sval != null sval.equals(inherit))
{
return propertyList.getFromParent(propName);
}
}
return convertValueForProperty(propName, maker, propertyList);
}
protected Property convertValueForProperty(String propName,
Property.Maker maker,
PropertyList propertyList) {
Property prop = null;
int idx = 0;
switch (count())
{
case 1: //
idx = 0;
break;
case 2: // 1st value top/bottom, 2nd value left/right
if (propName.equals(margin-top) ||
propName.equals(margin-bottom))
idx = 0;
else
idx = 1;
break;
case 3: // 1st value top, 2nd left/right, 3rd bottom
if (propName == margin-top)
idx = 0;
else if (propName.equals(margin-bottom))
idx = 2;
else
idx = 1;
break;
case 4: // top, right, bottom, left
if (propName.equals(margin-top))
idx = 0;
else if (propName.equals(margin-right))
idx = 1;
else if (propName.equals(margin-bottom))
idx = 2;
else if (propName.equals(margin-left))
idx = 3;
break;
default:
// TODO Error Message: Wrong number of args
return null;
}
Property p = getElement(idx);
prop = maker.convertShorthandProperty(propertyList, p, null);
return prop;
}
}
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]