View | Details | Raw Unified | Return to bug 51209
Collapse All | Expand All

(-)src/java/org/apache/fop/afp/svg/AFPTextHandler.java (-2 / +7 lines)
Lines 147-156 Link Here
147
            fontSize = (int)Math.round(
147
            fontSize = (int)Math.round(
148
                    g2d.convertToAbsoluteLength(fontSize));
148
                    g2d.convertToAbsoluteLength(fontSize));
149
            fontReference = registerPageFont(pageFonts, internalFontName, fontSize);
149
            fontReference = registerPageFont(pageFonts, internalFontName, fontSize);
150
            // TODO: re-think above registerPageFont code...
151
            AFPFont afpFont = (AFPFont) fontInfo.getFonts().get(internalFontName);
152
            final CharacterSet charSet = afpFont.getCharacterSet(fontSize);
153
            // Work-around for InfoPrint's AFP which loses character set state
154
            // over Graphics Data
155
            // boundaries.
150
            graphicsObj.setCharacterSet(fontReference);
156
            graphicsObj.setCharacterSet(fontReference);
151
152
            // add the character string
157
            // add the character string
153
            graphicsObj.addString(str, Math.round(x), Math.round(y));
158
            graphicsObj.addString(str, Math.round(x), Math.round(y), charSet);
154
        } else {
159
        } else {
155
            //Inside Batik's SVG filter operations, you won't get an AFPGraphics2D
160
            //Inside Batik's SVG filter operations, you won't get an AFPGraphics2D
156
            g.drawString(str, x, y);
161
            g.drawString(str, x, y);
(-)src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java (+12 lines)
Lines 209-213 Link Here
209
        public int getLength() {
209
        public int getLength() {
210
            return length;
210
            return length;
211
        }
211
        }
212
213
        /**
214
         * The bytes
215
         * 
216
         * @return the bytes
217
         */
218
        public byte[] getBytes() {
219
            // return copy just in case
220
            byte[] copy = new byte[bytes.length];
221
            System.arraycopy(bytes, 0, copy, 0, bytes.length);
222
            return copy;
223
        }
212
    }
224
    }
213
}
225
}
(-)src/java/org/apache/fop/afp/modca/GraphicsObject.java (-7 / +4 lines)
Lines 33-38 Link Here
33
import org.apache.fop.afp.Completable;
33
import org.apache.fop.afp.Completable;
34
import org.apache.fop.afp.Factory;
34
import org.apache.fop.afp.Factory;
35
import org.apache.fop.afp.StructuredData;
35
import org.apache.fop.afp.StructuredData;
36
import org.apache.fop.afp.fonts.CharacterSet;
36
import org.apache.fop.afp.goca.GraphicsAreaBegin;
37
import org.apache.fop.afp.goca.GraphicsAreaBegin;
37
import org.apache.fop.afp.goca.GraphicsAreaEnd;
38
import org.apache.fop.afp.goca.GraphicsAreaEnd;
38
import org.apache.fop.afp.goca.GraphicsBox;
39
import org.apache.fop.afp.goca.GraphicsBox;
Lines 229-237 Link Here
229
     */
230
     */
230
    public void setCharacterSet(int characterSet) {
231
    public void setCharacterSet(int characterSet) {
231
        if (characterSet != graphicsState.characterSet) {
232
        if (characterSet != graphicsState.characterSet) {
232
            addObject(new GraphicsSetCharacterSet(characterSet));
233
            graphicsState.characterSet = characterSet;
233
            graphicsState.characterSet = characterSet;
234
        }
234
        }
235
        addObject(new GraphicsSetCharacterSet(characterSet));
235
    }
236
    }
236
237
237
    /**
238
    /**
Lines 325-336 Link Here
325
     * @param x the x coordinate
326
     * @param x the x coordinate
326
     * @param y the y coordinate
327
     * @param y the y coordinate
327
     */
328
     */
328
    public void addString(String str, int x, int y) {
329
    public void addString(String str, int x, int y, CharacterSet charSet) {
329
        //Work-around for InfoPrint's AFP which loses character set state over Graphics Data
330
        addObject(new GraphicsCharacterString(str, x, y, charSet));
330
        //boundaries.
331
        addObject(new GraphicsSetCharacterSet(graphicsState.characterSet));
332
333
        addObject(new GraphicsCharacterString(str, x, y));
334
    }
331
    }
335
332
336
    /**
333
    /**
(-)src/java/org/apache/fop/afp/goca/GraphicsCharacterString.java (-15 / +15 lines)
Lines 22-29 Link Here
22
import java.io.IOException;
22
import java.io.IOException;
23
import java.io.OutputStream;
23
import java.io.OutputStream;
24
import java.io.UnsupportedEncodingException;
24
import java.io.UnsupportedEncodingException;
25
import java.nio.charset.CharacterCodingException;
25
26
26
import org.apache.fop.afp.AFPConstants;
27
import org.apache.fop.afp.fonts.CharacterSet;
27
28
28
/**
29
/**
29
 * A GOCA graphics string
30
 * A GOCA graphics string
Lines 34-40 Link Here
34
    protected static final int MAX_STR_LEN = 255;
35
    protected static final int MAX_STR_LEN = 255;
35
36
36
    /** the string to draw */
37
    /** the string to draw */
37
    protected final String str;
38
    private final String str;
39
40
    /**
41
     * The character set encoding to use
42
     */
43
    private final CharacterSet charSet;
38
44
39
    /**
45
    /**
40
     * Constructor (absolute positioning)
46
     * Constructor (absolute positioning)
Lines 42-61 Link Here
42
     * @param str the character string
48
     * @param str the character string
43
     * @param x the x coordinate
49
     * @param x the x coordinate
44
     * @param y the y coordinate
50
     * @param y the y coordinate
51
     * @param charSet the character set
45
     */
52
     */
46
    public GraphicsCharacterString(String str, int x, int y) {
53
    public GraphicsCharacterString(String str, int x, int y, CharacterSet charSet) {
47
        super(x, y);
54
        super(x, y);
48
        this.str = truncate(str, MAX_STR_LEN);
55
        this.str = truncate(str, MAX_STR_LEN);
49
    }
56
        this.charSet = charSet;
50
51
    /**
52
     * Constructor (relative positioning)
53
     *
54
     * @param str the character string
55
     */
56
    public GraphicsCharacterString(String str) {
57
        super(null);
58
        this.str = truncate(str, MAX_STR_LEN);
59
    }
57
    }
60
58
61
    /** {@inheritDoc} */
59
    /** {@inheritDoc} */
Lines 84-92 Link Here
84
     * Returns the text string as an encoded byte array
82
     * Returns the text string as an encoded byte array
85
     *
83
     *
86
     * @return the text string as an encoded byte array
84
     * @return the text string as an encoded byte array
85
     * @throws UnsupportedEncodingException, CharacterCodingException
87
     */
86
     */
88
    private byte[] getStringAsBytes() throws UnsupportedEncodingException {
87
    private byte[] getStringAsBytes() throws UnsupportedEncodingException, 
89
        return str.getBytes(AFPConstants.EBCIDIC_ENCODING);
88
            CharacterCodingException {
89
        return charSet.encodeChars(str).getBytes();
90
    }
90
    }
91
91
92
    /** {@inheritDoc} */
92
    /** {@inheritDoc} */
(-)test/java/org/apache/fop/afp/goca/GraphicsCharacterStringTestCase.java (+72 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.fop.afp.goca;
18
19
import static org.junit.Assert.assertEquals;
20
21
import java.io.ByteArrayOutputStream;
22
import java.io.IOException;
23
24
import org.apache.fop.afp.fonts.CharacterSet;
25
import org.apache.fop.afp.fonts.CharacterSetBuilder;
26
import org.apache.fop.fonts.Typeface;
27
import org.junit.Before;
28
import org.junit.Test;
29
30
public class GraphicsCharacterStringTestCase {
31
    private GraphicsCharacterString gcsCp500;
32
    private GraphicsCharacterString gcsCp1146;
33
    // consider the EBCDIC code page variants Cp500 and Cp1146
34
    // the £ corresponds to byte 5B (position 91) in the CCSID 285 and CCSID 1146
35
    // the $ corresponds to byte 5B (position 91) in the CCSID 500
36
    private final String poundsText = "££££";
37
    private final String dollarsText = "$$$$";
38
    private final byte[] bytesToCheck = {(byte) 0x5b, (byte) 0x5b, (byte) 0x5b, (byte) 0x5b};
39
40
    @Before
41
    public void setUp() throws Exception {
42
        CharacterSetBuilder csb = CharacterSetBuilder.getSingleByteInstance();
43
        CharacterSet cs1146 = csb.build("C0H200B0", "T1V10500", "Cp1146",
44
                Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
45
                .newInstance(), null);
46
        gcsCp1146 = new GraphicsCharacterString(poundsText, 0, 0, cs1146);
47
        CharacterSet cs500 = csb.build("C0H200B0", "T1V10500", "Cp500",
48
                Class.forName("org.apache.fop.fonts.base14.Helvetica").asSubclass(Typeface.class)
49
                .newInstance(), null);
50
        gcsCp500 = new GraphicsCharacterString(dollarsText, 0, 0, cs500);
51
    }
52
53
    @Test
54
    public void testWriteToStream() throws IOException {
55
        // check pounds
56
        ByteArrayOutputStream baos1146 = new ByteArrayOutputStream();
57
        gcsCp1146.writeToStream(baos1146);
58
        byte[] bytes1146 = baos1146.toByteArray();
59
        for (int i = 0; i < bytesToCheck.length; i++) {
60
            assertEquals(bytesToCheck[i], bytes1146[6 + i]);
61
        }
62
        assertEquals(bytesToCheck.length + 6, bytes1146.length);
63
        // check dollars
64
        ByteArrayOutputStream baos500 = new ByteArrayOutputStream();
65
        gcsCp500.writeToStream(baos500);
66
        byte[] bytes500 = baos500.toByteArray();
67
        for (int i = 0; i < bytesToCheck.length; i++) {
68
            assertEquals(bytesToCheck[i], bytes500[6 + i]);
69
        }
70
        assertEquals(bytesToCheck.length + 6, bytes500.length);
71
    }
72
}

Return to bug 51209