From 4e974a863decbcfbfa2007676e27062136b5a5b9 Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Fri, 6 Jul 2007 23:30:14 +0000 Subject: [PATCH] Improvement in handling relative font-weights git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@554088 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/fo/properties/CommonFont.java | 29 ++-- .../properties/FontWeightPropertyMaker.java | 129 ++++++++++++++++++ .../fotree/testcases/font-weight_relative2.fo | 90 ++++++++++++ .../standard-testcases/block_font-weight.xml | 30 ++-- 4 files changed, 246 insertions(+), 32 deletions(-) create mode 100644 src/java/org/apache/fop/fo/properties/FontWeightPropertyMaker.java create mode 100644 test/fotree/testcases/font-weight_relative2.fo diff --git a/src/java/org/apache/fop/fo/properties/CommonFont.java b/src/java/org/apache/fop/fo/properties/CommonFont.java index 11c53ad30..a131bf45f 100755 --- a/src/java/org/apache/fop/fo/properties/CommonFont.java +++ b/src/java/org/apache/fop/fo/properties/CommonFont.java @@ -132,23 +132,18 @@ public class CommonFont { if (fontState == null) { /**@todo this is ugly. need to improve. */ - int font_weight = 400; - if (fontWeight == Constants.EN_BOLDER) { - // +100 from inherited - } else if (fontWeight == Constants.EN_LIGHTER) { - // -100 from inherited - } else { - switch (fontWeight) { - case Constants.EN_100: font_weight = 100; break; - case Constants.EN_200: font_weight = 200; break; - case Constants.EN_300: font_weight = 300; break; - case Constants.EN_400: font_weight = 400; break; - case Constants.EN_500: font_weight = 500; break; - case Constants.EN_600: font_weight = 600; break; - case Constants.EN_700: font_weight = 700; break; - case Constants.EN_800: font_weight = 800; break; - case Constants.EN_900: font_weight = 900; break; - } + int font_weight; + switch (fontWeight) { + case Constants.EN_100: font_weight = 100; break; + case Constants.EN_200: font_weight = 200; break; + case Constants.EN_300: font_weight = 300; break; + case Constants.EN_400: font_weight = 400; break; + case Constants.EN_500: font_weight = 500; break; + case Constants.EN_600: font_weight = 600; break; + case Constants.EN_700: font_weight = 700; break; + case Constants.EN_800: font_weight = 800; break; + case Constants.EN_900: font_weight = 900; break; + default: font_weight = 400; } String style; diff --git a/src/java/org/apache/fop/fo/properties/FontWeightPropertyMaker.java b/src/java/org/apache/fop/fo/properties/FontWeightPropertyMaker.java new file mode 100644 index 000000000..64155e14c --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/FontWeightPropertyMaker.java @@ -0,0 +1,129 @@ +/* + * 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.fo.properties; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.PropertyInfo; +import org.apache.fop.fo.expr.PropertyParser; + +public class FontWeightPropertyMaker extends EnumProperty.Maker { + + /** + * Main constructor + * @param propId the property id + */ + public FontWeightPropertyMaker(int propId) { + super(propId); + } + + /** + * @see org.apache.fop.fo.properties.PropertyMaker#make(PropertyList, String, FObj) + */ + public Property make(PropertyList pList, String value, FObj fo) + throws PropertyException { + if ("inherit".equals(value)) { + return super.make(pList, value, fo); + } else { + String pValue = checkValueKeywords(value); + Property newProp = checkEnumValues(pValue); + int enumValue = -1; + if (newProp != null + && ((enumValue = newProp.getEnum()) == Constants.EN_BOLDER + || enumValue == Constants.EN_LIGHTER)) { + /* check for relative enum values, compute in relation to parent */ + Property parentProp = pList.getInherited(Constants.PR_FONT_WEIGHT); + if (enumValue == Constants.EN_BOLDER) { + enumValue = parentProp.getEnum(); + switch (enumValue) { + case Constants.EN_100: + newProp = EnumProperty.getInstance(Constants.EN_200, "200"); + break; + case Constants.EN_200: + newProp = EnumProperty.getInstance(Constants.EN_300, "300"); + break; + case Constants.EN_300: + newProp = EnumProperty.getInstance(Constants.EN_400, "400"); + break; + case Constants.EN_400: + newProp = EnumProperty.getInstance(Constants.EN_500, "500"); + break; + case Constants.EN_500: + newProp = EnumProperty.getInstance(Constants.EN_600, "600"); + break; + case Constants.EN_600: + newProp = EnumProperty.getInstance(Constants.EN_700, "700"); + break; + case Constants.EN_700: + newProp = EnumProperty.getInstance(Constants.EN_800, "800"); + break; + case Constants.EN_800: + case Constants.EN_900: + newProp = EnumProperty.getInstance(Constants.EN_900, "900"); + break; + default: + //nop + } + } else { + enumValue = parentProp.getEnum(); + switch (enumValue) { + case Constants.EN_100: + case Constants.EN_200: + newProp = EnumProperty.getInstance(Constants.EN_100, "100"); + break; + case Constants.EN_300: + newProp = EnumProperty.getInstance(Constants.EN_200, "200"); + break; + case Constants.EN_400: + newProp = EnumProperty.getInstance(Constants.EN_300, "300"); + break; + case Constants.EN_500: + newProp = EnumProperty.getInstance(Constants.EN_400, "400"); + break; + case Constants.EN_600: + newProp = EnumProperty.getInstance(Constants.EN_500, "500"); + break; + case Constants.EN_700: + newProp = EnumProperty.getInstance(Constants.EN_600, "600"); + break; + case Constants.EN_800: + newProp = EnumProperty.getInstance(Constants.EN_700, "700"); + break; + case Constants.EN_900: + newProp = EnumProperty.getInstance(Constants.EN_800, "800"); + break; + default: + //nop + } + } + } else if (enumValue == -1) { + /* neither a keyword, nor an enum + * still maybe a valid expression, so send it through the parser... */ + newProp = PropertyParser.parse(value, new PropertyInfo(this, pList)); + } + if (newProp != null) { + newProp = convertProperty(newProp, pList, fo); + } + return newProp; + } + } + +} diff --git a/test/fotree/testcases/font-weight_relative2.fo b/test/fotree/testcases/font-weight_relative2.fo new file mode 100644 index 000000000..530c9afe7 --- /dev/null +++ b/test/fotree/testcases/font-weight_relative2.fo @@ -0,0 +1,90 @@ + + + + + + + + + + + + font-weight="900" + + font-weight="lighter" + + font-weight="lighter" + + font-weight="lighter" + + font-weight="lighter" + + font-weight="lighter" + + font-weight="lighter" + + font-weight="lighter" + + font-weight="lighter" + + font-weight="lighter" + + + + + + + + + + + + font-weight="100" + + font-weight="bolder" + + font-weight="bolder" + + font-weight="bolder" + + font-weight="bolder" + + font-weight="bolder" + + font-weight="bolder" + + font-weight="bolder" + + font-weight="bolder" + + font-weight="bolder" + + + + + + + + + + + + + + + diff --git a/test/layoutengine/standard-testcases/block_font-weight.xml b/test/layoutengine/standard-testcases/block_font-weight.xml index b9907ebc2..743aa69e7 100644 --- a/test/layoutengine/standard-testcases/block_font-weight.xml +++ b/test/layoutengine/standard-testcases/block_font-weight.xml @@ -86,7 +86,7 @@ - + @@ -99,24 +99,24 @@ - - - - - - - - - + + + + + + + + + - - - - - + + + + + -- 2.39.5