You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/02/15 21:49:30 UTC
svn commit: r1824374 - in /pdfbox/branches/2.0:
fontbox/src/main/java/org/apache/fontbox/ttf/
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/
Author: tilman
Date: Thu Feb 15 21:49:30 2018
New Revision: 1824374
URL: http://svn.apache.org/viewvc?rev=1824374&view=rev
Log:
PDFBOX-4106: Add factory methods for loading TTF as vertical font with vrt2/vert tables, by Aaron Madlon-Kay
Modified:
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java?rev=1824374&r1=1824373&r2=1824374&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java Thu Feb 15 21:49:30 2018
@@ -724,6 +724,15 @@ public class TrueTypeFont implements Fon
enabledGsubFeatures.remove(featureTag);
}
+ /**
+ * Enable glyph substitutions for vertical writing.
+ */
+ public void enableVerticalSubstitutions()
+ {
+ enableGsubFeature("vrt2");
+ enableGsubFeature("vert");
+ }
+
@Override
public String toString()
{
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java?rev=1824374&r1=1824373&r2=1824374&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java Thu Feb 15 21:49:30 2018
@@ -60,7 +60,7 @@ final class PDCIDFontType2Embedder exten
* @throws IOException if the TTF could not be read
*/
PDCIDFontType2Embedder(PDDocument document, COSDictionary dict, TrueTypeFont ttf,
- boolean embedSubset, PDType0Font parent) throws IOException
+ boolean embedSubset, PDType0Font parent, boolean vertical) throws IOException
{
super(document, dict, ttf, embedSubset);
this.document = document;
@@ -70,7 +70,7 @@ final class PDCIDFontType2Embedder exten
// parent Type 0 font
dict.setItem(COSName.SUBTYPE, COSName.TYPE0);
dict.setName(COSName.BASE_FONT, fontDescriptor.getFontName());
- dict.setItem(COSName.ENCODING, COSName.IDENTITY_H); // CID = GID
+ dict.setItem(COSName.ENCODING, vertical ? COSName.IDENTITY_V : COSName.IDENTITY_H); // CID = GID
// descendant CIDFont
cidFont = createCIDFont();
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1824374&r1=1824373&r2=1824374&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Thu Feb 15 21:49:30 2018
@@ -63,7 +63,7 @@ public class PDType0Font extends PDFont
*/
public static PDType0Font load(PDDocument doc, File file) throws IOException
{
- return new PDType0Font(doc, new TTFParser().parse(file), true, true);
+ return new PDType0Font(doc, new TTFParser().parse(file), true, true, false);
}
/**
@@ -76,7 +76,7 @@ public class PDType0Font extends PDFont
*/
public static PDType0Font load(PDDocument doc, InputStream input) throws IOException
{
- return new PDType0Font(doc, new TTFParser().parse(input), true, true);
+ return new PDType0Font(doc, new TTFParser().parse(input), true, true, false);
}
/**
@@ -91,7 +91,7 @@ public class PDType0Font extends PDFont
public static PDType0Font load(PDDocument doc, InputStream input, boolean embedSubset)
throws IOException
{
- return new PDType0Font(doc, new TTFParser().parse(input), embedSubset, true);
+ return new PDType0Font(doc, new TTFParser().parse(input), embedSubset, true, false);
}
/**
@@ -106,10 +106,66 @@ public class PDType0Font extends PDFont
public static PDType0Font load(PDDocument doc, TrueTypeFont ttf, boolean embedSubset)
throws IOException
{
- return new PDType0Font(doc, ttf, embedSubset, false);
+ return new PDType0Font(doc, ttf, embedSubset, false, false);
}
/**
+ * Loads a TTF to be embedded into a document as a vertical Type 0 font.
+ *
+ * @param doc The PDF document that will hold the embedded font.
+ * @param file A TrueType font.
+ * @return A Type0 font with a CIDFontType2 descendant.
+ * @throws IOException If there is an error reading the font file.
+ */
+ public static PDType0Font loadVertical(PDDocument doc, File file) throws IOException
+ {
+ return new PDType0Font(doc, new TTFParser().parse(file), true, true, true);
+ }
+
+ /**
+ * Loads a TTF to be embedded into a document as a vertical Type 0 font.
+ *
+ * @param doc The PDF document that will hold the embedded font.
+ * @param input A TrueType font.
+ * @return A Type0 font with a CIDFontType2 descendant.
+ * @throws IOException If there is an error reading the font stream.
+ */
+ public static PDType0Font loadVertical(PDDocument doc, InputStream input) throws IOException
+ {
+ return new PDType0Font(doc, new TTFParser().parse(input), true, true, true);
+ }
+
+ /**
+ * Loads a TTF to be embedded into a document as a vertical Type 0 font.
+ *
+ * @param doc The PDF document that will hold the embedded font.
+ * @param input A TrueType font.
+ * @param embedSubset True if the font will be subset before embedding
+ * @return A Type0 font with a CIDFontType2 descendant.
+ * @throws IOException If there is an error reading the font stream.
+ */
+ public static PDType0Font loadVertical(PDDocument doc, InputStream input, boolean embedSubset)
+ throws IOException
+ {
+ return new PDType0Font(doc, new TTFParser().parse(input), embedSubset, true, true);
+ }
+
+ /**
+ * Loads a TTF to be embedded into a document as a vertical Type 0 font.
+ *
+ * @param doc The PDF document that will hold the embedded font.
+ * @param ttf A TrueType font.
+ * @param embedSubset True if the font will be subset before embedding
+ * @return A Type0 font with a CIDFontType2 descendant.
+ * @throws IOException If there is an error reading the font stream.
+ */
+ public static PDType0Font loadVertical(PDDocument doc, TrueTypeFont ttf, boolean embedSubset)
+ throws IOException
+ {
+ return new PDType0Font(doc, ttf, embedSubset, false, true);
+ }
+
+ /**
* Constructor for reading a Type0 font from a PDF file.
*
* @param fontDictionary The font dictionary according to the PDF specification.
@@ -138,14 +194,14 @@ public class PDType0Font extends PDFont
fetchCMapUCS2();
}
- /**
- * Private. Creates a new TrueType font for embedding.
- */
private PDType0Font(PDDocument document, TrueTypeFont ttf, boolean embedSubset,
- boolean closeOnSubset)
- throws IOException
+ boolean closeOnSubset, boolean vertical) throws IOException
{
- embedder = new PDCIDFontType2Embedder(document, dict, ttf, embedSubset, this);
+ if (vertical)
+ {
+ ttf.enableVerticalSubstitutions();
+ }
+ embedder = new PDCIDFontType2Embedder(document, dict, ttf, embedSubset, this, vertical);
descendantFont = embedder.getCIDFont();
readEncoding();
fetchCMapUCS2();