Browse Source

FOP-2742: SVG to PS NPE/text missing when using PFM file

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1809748 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_3
Simon Steiner 6 years ago
parent
commit
991b446034

+ 5
- 1
fop-core/src/main/java/org/apache/fop/fonts/type1/Type1FontLoader.java View File

@@ -19,6 +19,7 @@

package org.apache.fop.fonts.type1;

import java.awt.Rectangle;
import java.awt.geom.RectangularShape;
import java.io.IOException;
import java.io.InputStream;
@@ -415,7 +416,10 @@ public class Type1FontLoader extends FontLoader {
returnFont.setFirstChar(pfm.getFirstChar());
returnFont.setLastChar(pfm.getLastChar());
for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
singleFont.setWidth(i, pfm.getCharWidth(i));
int cw = pfm.getCharWidth(i);
singleFont.setWidth(i, cw);
int[] bbox = pfm.getFontBBox();
singleFont.setBoundingBox(i, new Rectangle(bbox[0], bbox[1], cw, bbox[3]));
}
if (useKerning) {
returnFont.replaceKerningMap(pfm.getKerning());

+ 61
- 0
fop-core/src/test/java/org/apache/fop/fonts/type1/Type1FontLoaderTestCase.java View File

@@ -0,0 +1,61 @@
/*
* 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.fonts.type1;

import java.awt.Rectangle;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;

import org.apache.commons.io.IOUtils;

import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.fonts.CustomFont;
import org.apache.fop.fonts.EmbeddingMode;
import org.apache.fop.fonts.EncodingMode;
import org.apache.fop.fonts.FontLoader;
import org.apache.fop.fonts.FontUris;

public class Type1FontLoaderTestCase {
@Test
public void testBoundingBox() throws IOException {
File pfb = new File("test/resources/fonts/type1/c0419bt_.pfb");
File pfbNoAFM = File.createTempFile("fop", "pfb");
File pfm = File.createTempFile("fop", "pfm");
try {
IOUtils.copy(new FileInputStream(pfb), new FileOutputStream(pfbNoAFM));

FileOutputStream fos = new FileOutputStream(pfm);
fos.write(new byte[512]);
fos.close();

FontUris fontUris = new FontUris(pfbNoAFM.toURI(), null, null, pfm.toURI());
CustomFont x = FontLoader.loadFont(fontUris, null, true, EmbeddingMode.AUTO, EncodingMode.AUTO, true, true,
ResourceResolverFactory.createDefaultInternalResourceResolver(new File(".").toURI()), false, false);
Assert.assertEquals(x.getBoundingBox(0, 12).getBounds(), new Rectangle(-240, -60, 0, 60));
} finally {
pfbNoAFM.delete();
pfm.delete();
}
}
}

Loading…
Cancel
Save