Hi,

I've added support for the 'letter-spacing' property. A patch to fop 
0.20.2, and a test case are added to this mail.

I would really appreciate some feedback on this, especially from one of 
the core developers.

Thanks,
-- 
Raymond Penners
<?xml version="1.0" encoding="utf-8"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>

  <fo:layout-master-set>
    <!-- layout information -->
    <fo:simple-page-master master-name="simple"
                  page-height="29.7cm" 
                  page-width="21cm"
                  margin-top="1cm" 
                  margin-bottom="2cm" 
                  margin-left="2.5cm" 
                  margin-right="2.5cm">
      <fo:region-body margin-top="3cm"/>
      <fo:region-before extent="3cm"/>
      <fo:region-after extent="1.5cm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>



  <fo:page-sequence master-name="simple">
    <fo:flow flow-name="xsl-region-body">

      <fo:table>
        <fo:table-column column-width="1cm"/>
        <fo:table-column column-width="1cm"/>
        <fo:table-column column-width="1cm"/>
        <fo:table-column column-width="1cm"/>
        <fo:table-column column-width="1cm"/>
        <fo:table-column column-width="1cm"/>
        <fo:table-column column-width="1cm"/>
        <fo:table-column column-width="1cm"/>
        <fo:table-body>
          <fo:table-row line-height="2cm">
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>0</fo:block>
            </fo:table-cell>
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>1</fo:block>
            </fo:table-cell>
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>2</fo:block>
            </fo:table-cell>
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>3</fo:block>
            </fo:table-cell>
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>4</fo:block>
            </fo:table-cell>
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>5</fo:block>
            </fo:table-cell>
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>6</fo:block>
            </fo:table-cell>
            <fo:table-cell border-width=".1pt" border-left-style="solid">
              <fo:block>7</fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>

      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify">
ABCABCABCABCABCABCABCABCDEF
      </fo:block>

      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify"
                letter-spacing=".5cm">
ABCABCABCABCABCABCABCABCDEF
      </fo:block>


      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify"
                letter-spacing="1cm">
ABCABCABCABCABCABCABCABCDEF
      </fo:block>


      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify"
                letter-spacing="2cm">
ABCABCABCABCABCABCABCABCD
      </fo:block>

      <!-- this defines normal text -->
      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify"
                letter-spacing="3cm">
ABCABCABCABCABCABCABCABCD
      </fo:block>

      <!-- this defines normal text -->
      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify"
                letter-spacing="4cm">
ABCABCABCABCABCABCABCABC
      </fo:block>

      <!-- this defines normal text -->
      <fo:block font-size="12pt" 
                font-family="sans-serif" 
                line-height="15pt"
                space-after.optimum="3pt"
                text-align="justify"
                letter-spacing="5cm">
ABCABCABCABCABCABCABCABC
      </fo:block>

      <fo:block-container background-color="blue" width="3cm" height="3cm">
        <fo:block>X
        </fo:block>
      </fo:block-container>

    </fo:flow> 
  </fo:page-sequence>
</fo:root>
diff -u -r Fop-0.20.2/src/codegen/foproperties.xml 
Fop-0.20.2.dlx/src/codegen/foproperties.xml
--- Fop-0.20.2/src/codegen/foproperties.xml     Sat Sep 29 21:28:48 2001
+++ Fop-0.20.2.dlx/src/codegen/foproperties.xml Thu Nov 29 13:33:14 2001
@@ -1190,8 +1190,8 @@
   <property>
     <name>letter-spacing</name>
     <inherited>true</inherited>
-    <datatype>ToBeImplemented</datatype>
-    <default>normal</default>
+    <datatype>Length</datatype>
+    <default>0pt</default>
   </property>
   <property>
     <name>suppress-at-line-break</name>
Only in Fop-0.20.2.dlx/src/codegen: foproperties.xml~
diff -u -r Fop-0.20.2/src/org/apache/fop/fo/FOText.java 
Fop-0.20.2.dlx/src/org/apache/fop/fo/FOText.java
--- Fop-0.20.2/src/org/apache/fop/fo/FOText.java        Sat Sep 29 21:28:31 2001
+++ Fop-0.20.2.dlx/src/org/apache/fop/fo/FOText.java    Thu Nov 29 13:34:04 2001
@@ -123,9 +123,11 @@
             int fontVariant =
                 this.parent.properties.get("font-variant").getEnum();
 
+            int letterSpacing = 
+                this.parent.properties.get("letter-spacing").getLength().mvalue();
             this.fs = new FontState(area.getFontInfo(), fontFamily,
                                     fontStyle, fontWeight, fontSize,
-                                    fontVariant);
+                                    fontVariant,letterSpacing);
 
             ColorType c = this.parent.properties.get("color").getColorType();
             this.red = c.red();
Only in Fop-0.20.2.dlx/src/org/apache/fop/fo: FOText.java~
diff -u -r Fop-0.20.2/src/org/apache/fop/layout/FontState.java 
Fop-0.20.2.dlx/src/org/apache/fop/layout/FontState.java
--- Fop-0.20.2/src/org/apache/fop/layout/FontState.java Sat Sep 29 21:28:42 2001
+++ Fop-0.20.2.dlx/src/org/apache/fop/layout/FontState.java     Thu Nov 29 13:33:54 
+2001
@@ -24,6 +24,8 @@
 
     private FontMetric _metric;
 
+    private int _letterSpacing;
+
     private static Hashtable EMPTY_HASHTABLE = new Hashtable();
 
 
@@ -38,6 +40,15 @@
         _fontName = fontInfo.fontLookup(fontFamily, fontStyle, fontWeight);
         _metric = fontInfo.getMetricsFor(_fontName);
         _fontVariant = fontVariant;
+        _letterSpacing = 0;
+    }
+
+    public FontState(FontInfo fontInfo, String fontFamily, String fontStyle,
+                     String fontWeight, int fontSize,
+                     int fontVariant, int letterSpacing) throws FOPException {
+        this(fontInfo, fontFamily, fontStyle, fontWeight, fontSize,
+             fontVariant);
+        _letterSpacing = letterSpacing;
     }
 
     public int getAscender() {
@@ -80,6 +91,10 @@
         return _fontInfo;
     }
 
+    public int getLetterSpacing() {
+        return _letterSpacing;
+    }
+
     public int getXHeight() {
         return _metric.getXHeight(_fontSize) / 1000;
     }
@@ -95,7 +110,7 @@
 
     public int width(int charnum) {
         // returns width of given character number in millipoints
-        return (_metric.width(charnum, _fontSize) / 1000);
+        return  _letterSpacing + (_metric.width(charnum, _fontSize) / 1000);
     }
 
     /**
Only in Fop-0.20.2.dlx/src/org/apache/fop/layout: FontState.java~
Only in Fop-0.20.2.dlx/src/org/apache/fop/layout: LineArea.java~
diff -u -r Fop-0.20.2/src/org/apache/fop/render/pdf/PDFRenderer.java 
Fop-0.20.2.dlx/src/org/apache/fop/render/pdf/PDFRenderer.java
--- Fop-0.20.2/src/org/apache/fop/render/pdf/PDFRenderer.java   Sat Sep 29 21:28:37 
2001
+++ Fop-0.20.2.dlx/src/org/apache/fop/render/pdf/PDFRenderer.java       Thu Nov 29 
+13:33:41 2001
@@ -618,6 +618,8 @@
                                kerning, startText, endText);
                 }
 
+                addLetterSpacing(pdf, area.getFontState().getLetterSpacing(), 
+startText, endText);
+
             }
             pdf.append(endText);
 
@@ -685,6 +687,13 @@
                 buf.append(endText).append(-(width.intValue())).append(' 
').append(startText);
             }
         }
+    }
+
+    private void addLetterSpacing(StringBuffer buf, int letterSpacing,
+                            String startText,
+                            String endText) {
+        float f = letterSpacing * 1000 / this.currentFontSize;
+        buf.append(endText).append(-f).append(' ').append(startText);
     }
 
     public void render(Page page, OutputStream outputStream)
Only in Fop-0.20.2.dlx/src/org/apache/fop/render/pdf: PDFRenderer.java~

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to