You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2017/02/12 17:32:32 UTC
svn commit: r1782684 -
/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
Author: lehmi
Date: Sun Feb 12 17:32:32 2017
New Revision: 1782684
URL: http://svn.apache.org/viewvc?rev=1782684&view=rev
Log:
PDFBOX-3579: concatenate font matrix from top dictionary with font matrix from private dictionary to get the right scaling
Modified:
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java?rev=1782684&r1=1782683&r2=1782684&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java Sun Feb 12 17:32:32 2017
@@ -501,14 +501,19 @@ public class CFFParser
{
parseCIDFontDicts(input, topDict, (CFFCIDFont) font, charStringsIndex.length);
+ List<Number> privMatrix = null;
+ List<Map<String, Object>> fontDicts = ((CFFCIDFont) font).getFontDicts();
+ if (fontDicts.size() > 0 && fontDicts.get(0).containsKey("FontMatrix"))
+ {
+ privMatrix = (List<Number>) fontDicts.get(0).get("FontMatrix");
+ }
// some malformed fonts have FontMatrix in their Font DICT, see PDFBOX-2495
- if (topDict.getEntry("FontMatrix") == null)
+ List<Number> matrix = topDict.getArray("FontMatrix", null);
+ if (matrix == null)
{
- List<Map<String, Object>> fontDicts = ((CFFCIDFont) font).getFontDicts();
- if (fontDicts.size() > 0 && fontDicts.get(0).containsKey("FontMatrix"))
+ if (privMatrix != null)
{
- List<Number> matrix = (List<Number>)fontDicts.get(0).get("FontMatrix");
- font.addValueToTopDict("FontMatrix", matrix);
+ font.addValueToTopDict("FontMatrix", privMatrix);
}
else
{
@@ -518,6 +523,14 @@ public class CFFParser
(double) 0, (double) 0)));
}
}
+ else if (privMatrix != null)
+ {
+ // we have to multiply the font matrix from the top directory with the font matrix
+ // from the private directory. This should be done for synthetic fonts only but in
+ // case of PDFBOX-3579 it's needed as well to get the right scaling
+ concatenateMatrix(matrix, privMatrix);
+ }
+
}
else
{
@@ -527,6 +540,34 @@ public class CFFParser
return font;
}
+ private void concatenateMatrix(List<Number> matrixDest, List<Number> matrixConcat)
+ {
+ // concatenate matrices
+ // (a b 0)
+ // (c d 0)
+ // (x y 1)
+ double a1 = matrixDest.get(0).doubleValue();
+ double b1 = matrixDest.get(1).doubleValue();
+ double c1 = matrixDest.get(2).doubleValue();
+ double d1 = matrixDest.get(3).doubleValue();
+ double x1 = matrixDest.get(4).doubleValue();
+ double y1 = matrixDest.get(5).doubleValue();
+
+ double a2 = matrixConcat.get(0).doubleValue();
+ double b2 = matrixConcat.get(1).doubleValue();
+ double c2 = matrixConcat.get(2).doubleValue();
+ double d2 = matrixConcat.get(3).doubleValue();
+ double x2 = matrixConcat.get(4).doubleValue();
+ double y2 = matrixConcat.get(5).doubleValue();
+
+ matrixDest.set(0, a1 * a2 + b1 * c2);
+ matrixDest.set(1, a1 * b2 + b1 * d1);
+ matrixDest.set(2, c1 * a2 + d1 * c2);
+ matrixDest.set(3, c1 * b2 + d1 * d2);
+ matrixDest.set(4, x1 * a2 + y1 * c2 + x2);
+ matrixDest.set(5, x1 * b2 + y1 * d2 + y2);
+ }
+
/**
* Parse dictionaries specific to a CIDFont.
*/