pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1645523 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
Date Sun, 14 Dec 2014 21:10:30 GMT
Author: jahewson
Date: Sun Dec 14 21:10:30 2014
New Revision: 1645523

URL: http://svn.apache.org/r1645523
Log:
PDFBOX-2524: Added unit test for CIDFontType2 embedding

Added:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
  (with props)

Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java?rev=1645523&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
(added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
Sun Dec 14 21:10:30 2014
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+
+package org.apache.pdfbox.pdmodel.font;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import junit.framework.TestCase;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
+import org.apache.pdfbox.util.PDFTextStripper;
+
+/**
+ * Tests font embedding.
+ *
+ * @author John Hewson
+ */
+public class TestFontEmbedding extends TestCase
+{
+    private static final File OUT_DIR = new File("target/test-output");
+
+    /**
+     * Embed a TTF as CIDFontType2.
+     */
+    public void testCIDFontType2() throws Exception
+    {
+        PDDocument document = new PDDocument();
+        PDPage page = new PDPage(PDRectangle.A4);
+        document.addPage(page);
+
+        InputStream input = TestFontEmbedding.class.getClassLoader().getResourceAsStream(
+                "org/apache/pdfbox/ttf/LiberationSans-Regular.ttf");
+        PDType0Font font = PDType0Font.load(document, input);
+
+        PDPageContentStream stream = new PDPageContentStream(document, page);
+
+        stream.beginText();
+        stream.setFont(font, 12);
+
+        String text = "Unicode русский язык Tiếng Việt";
+        stream.moveTextPositionByAmount(50, 600);
+        stream.drawString(text);
+
+        stream.endText();
+        stream.close();
+
+        File file = new File(OUT_DIR, "CIDFontType2.pdf");
+        document.save(file);
+        document.close();
+
+        // check that the extracted text matches what we wrote
+        String extracted = getUnicodeText(file);
+        assertEquals(text + '\n', extracted);
+    }
+
+    private String getUnicodeText(File file) throws IOException
+    {
+        PDDocument document = PDDocument.load(file);
+        PDFTextStripper stripper = new PDFTextStripper();
+        return stripper.getText(document);
+    }
+}

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message