From: Jeremias Maerki Date: Mon, 1 Nov 2004 15:04:50 +0000 (+0000) Subject: Correct handling of internal units (both twips and half-points are used) X-Git-Tag: Root_Temp_KnuthStylePageBreaking~385 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7132925bd842c0c4b6c96d0282a2b60902c1285a;p=xmlgraphics-fop.git Correct handling of internal units (both twips and half-points are used) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198122 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java b/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java index d4d80e9b2..5dea87cf5 100755 --- a/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java +++ b/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java @@ -29,13 +29,25 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfColorTable; * A RtfAttributes subclass that adds some helper set methods. */ public class FOPRtfAttributes extends RtfAttributes { + + /** + * Set an attribute that has a Length value (internal units in twips) + * @param name name of attribute + * @param value value of attribute + * @return this (which now contains the new entry) + */ + public RtfAttributes setTwips(String name, Length value) { + set(name, value.getValue() / (1000 / 20)); //Convert millipoints to twips + return this; + } + /** - * Set an attribute that has a Length value + * Set an attribute that has a Length value (internal units in half-points) * @param name name of attribute * @param value value of attribute * @return this (which now contains the new entry) */ - public RtfAttributes set(String name, Length value) { + public RtfAttributes setHalfPoints(String name, Length value) { set(name, value.getValue() / (1000 / 2)); //Convert millipoints to half-points return this; } diff --git a/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java b/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java index ec3afdacd..c050e3813 100644 --- a/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java @@ -44,8 +44,8 @@ public class ListAttributesConverter { FOPRtfAttributes attrib = new FOPRtfAttributes(); - attrib.set(RtfListTable.LIST_INDENT, fobj.getCommonMarginBlock().startIndent); - attrib.set(RtfText.LEFT_INDENT_BODY, fobj.getCommonMarginBlock().endIndent); + attrib.setTwips(RtfListTable.LIST_INDENT, fobj.getCommonMarginBlock().startIndent); + attrib.setTwips(RtfText.LEFT_INDENT_BODY, fobj.getCommonMarginBlock().endIndent); /* * set list table defaults diff --git a/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java index 00efe46b7..3947f21d9 100644 --- a/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java @@ -50,8 +50,8 @@ class PageAttributesConverter { RegionBody body = (RegionBody) pagemaster.getRegion(Constants.FO_REGION_BODY); RegionBA after = (RegionBA) pagemaster.getRegion(Constants.FO_REGION_AFTER); - attrib.set(RtfPage.PAGE_WIDTH, pagemaster.getPageWidth()); - attrib.set(RtfPage.PAGE_HEIGHT, pagemaster.getPageHeight()); + attrib.setTwips(RtfPage.PAGE_WIDTH, pagemaster.getPageWidth()); + attrib.setTwips(RtfPage.PAGE_HEIGHT, pagemaster.getPageHeight()); Length pageTop = pagemaster.getCommonMarginBlock().marginTop; Length pageBottom = pagemaster.getCommonMarginBlock().marginBottom; @@ -72,24 +72,24 @@ class PageAttributesConverter { bodyRight = (Length) NumericOp.addition(pageRight, bodyMargin.marginRight); } - attrib.set(RtfPage.MARGIN_TOP, bodyTop); - attrib.set(RtfPage.MARGIN_BOTTOM, bodyBottom); - attrib.set(RtfPage.MARGIN_LEFT, bodyLeft); - attrib.set(RtfPage.MARGIN_RIGHT, bodyRight); + attrib.setTwips(RtfPage.MARGIN_TOP, bodyTop); + attrib.setTwips(RtfPage.MARGIN_BOTTOM, bodyBottom); + attrib.setTwips(RtfPage.MARGIN_LEFT, bodyLeft); + attrib.setTwips(RtfPage.MARGIN_RIGHT, bodyRight); //region-before attributes Length beforeTop = pageTop; if (before != null) { beforeTop = (Length) NumericOp.addition(pageTop, before.getExtent()); } - attrib.set(RtfPage.HEADERY, beforeTop); + attrib.setTwips(RtfPage.HEADERY, beforeTop); //region-after attributes Length afterBottom = pageBottom; if (after != null) { afterBottom = (Length) NumericOp.addition(pageBottom, after.getExtent()); } - attrib.set(RtfPage.FOOTERY, beforeTop); + attrib.setTwips(RtfPage.FOOTERY, beforeTop); } catch (Exception e) { log.error("Exception in convertPageAttributes: " + e.getMessage() + "- page attributes ignored"); diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index 7ccc49ed5..25da7bdff 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -79,7 +79,7 @@ public class TableAttributesConverter { static RtfAttributes convertTableAttributes(Table fobj) throws FOPException { FOPRtfAttributes attrib = new FOPRtfAttributes(); - attrib.set(ITableAttributes.ATTR_ROW_LEFT_INDENT, fobj.getCommonMarginBlock().marginLeft); + attrib.setTwips(ITableAttributes.ATTR_ROW_LEFT_INDENT, fobj.getCommonMarginBlock().marginLeft); return attrib; } diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java index 5df06ed1c..a297b6425 100644 --- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java @@ -132,7 +132,7 @@ class TextAttributesConverter { private static void attrFont(CommonFont font, FOPRtfAttributes rtfAttr) { rtfAttr.set(RtfText.ATTR_FONT_FAMILY, RtfFontManager.getInstance().getFontNumber(font.fontFamily)); - rtfAttr.set(RtfText.ATTR_FONT_SIZE, font.fontSize); + rtfAttr.setHalfPoints(RtfText.ATTR_FONT_SIZE, font.fontSize); if (font.fontWeight.equals("bold") || font.fontWeight.equals("700")) { rtfAttr.set("b", 1); @@ -174,12 +174,12 @@ class TextAttributesConverter { } private static void attrBlockMargin(CommonMarginBlock cmb, FOPRtfAttributes rtfAttr) { - rtfAttr.set(RtfText.SPACE_BEFORE, + rtfAttr.setTwips(RtfText.SPACE_BEFORE, cmb.spaceBefore.getOptimum().getLength()); - rtfAttr.set(RtfText.SPACE_AFTER, + rtfAttr.setTwips(RtfText.SPACE_AFTER, cmb.spaceAfter.getOptimum().getLength()); - rtfAttr.set(RtfText.LEFT_INDENT_BODY, cmb.marginLeft); - rtfAttr.set(RtfText.RIGHT_INDENT_BODY, cmb.marginRight); + rtfAttr.setTwips(RtfText.LEFT_INDENT_BODY, cmb.marginLeft); + rtfAttr.setTwips(RtfText.RIGHT_INDENT_BODY, cmb.marginRight); }