Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…gsaucer into readme_update
  • Loading branch information
Gaboso committed Aug 13, 2018
2 parents 8f2eac4 + 080e898 commit 3d007f8
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 86 deletions.
2 changes: 1 addition & 1 deletion flying-saucer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-parent</artifactId>
<version>9.1.14</version>
<version>9.1.15</version>
</parent>

<artifactId>flying-saucer-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion flying-saucer-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-parent</artifactId>
<version>9.1.14</version>
<version>9.1.15</version>
</parent>

<artifactId>flying-saucer-examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion flying-saucer-fop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-parent</artifactId>
<version>9.1.14</version>
<version>9.1.15</version>
</parent>

<artifactId>flying-saucer-fop</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion flying-saucer-log4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-parent</artifactId>
<version>9.1.14</version>
<version>9.1.15</version>
</parent>

<artifactId>flying-saucer-log4j</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion flying-saucer-pdf-itext5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-parent</artifactId>
<version>9.1.14</version>
<version>9.1.15</version>
</parent>

<artifactId>flying-saucer-pdf-itext5</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public void drawString(String s, float x, float y, JustificationInfo info) {
resetMode = true;
ensureStrokeColor();
}
if ((fontSpec.fontStyle == IdentValue.ITALIC) && (desc.getStyle() != IdentValue.ITALIC)) {
if ((fontSpec.fontStyle == IdentValue.ITALIC) && (desc.getStyle() != IdentValue.ITALIC) && (desc.getStyle() != IdentValue.OBLIQUE)) {
b = 0f;
c = 0.21256f;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package org.xhtmlrenderer.pdf;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.RandomAccessFileOrArray;
import org.xhtmlrenderer.css.constants.IdentValue;
import org.xhtmlrenderer.pdf.ITextFontResolver.FontDescription;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.xhtmlrenderer.css.constants.IdentValue;
import org.xhtmlrenderer.pdf.ITextFontResolver.FontDescription;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.RandomAccessFileOrArray;

/**
* Uses code from iText's DefaultFontMapper and TrueTypeFont classes. See
* <a href="http://sourceforge.net/projects/itext/">http://sourceforge.net/projects/itext/</a> for license information.
*/
public class TrueTypeUtil {

private static IdentValue guessStyle(BaseFont font) {
String[][] names = font.getFullFontName();
for (int i = 0; i < names.length; i++) {
String name[] = names[i];

for (String[] name : names) {
String lower = name[3].toLowerCase();
if (lower.indexOf("italic") != -1) {
if (lower.contains("italic")) {
return IdentValue.ITALIC;
} else if (lower.indexOf("oblique") != -1) {
} else if (lower.contains("oblique")) {
return IdentValue.OBLIQUE;
}
}
Expand All @@ -34,32 +34,32 @@ private static IdentValue guessStyle(BaseFont font) {
}

public static String[] getFamilyNames(BaseFont font) {
String names[][] = font.getFamilyFontName();
String[][] names = font.getFamilyFontName();

if (names.length == 1) {
return new String[] { names[0][3] };
return new String[]{names[0][3]};
}

List result = new ArrayList();
for (int k = 0; k < names.length; ++k) {
String name[] = names[k];
if ((name[0].equals("1") && name[1].equals("0")) ||
name[2].equals("1033")) {
List<String> result = new ArrayList<String>();
for (String[] name : names) {
if ((name[0].equals("1") && name[1].equals("0")) || name[2].equals("1033")) {
result.add(name[3]);
}
}
return (String[]) result.toArray(new String[result.size()]);

return result.toArray(new String[result.size()]);
}

// HACK No accessor
private static Map extractTables(BaseFont font)
throws SecurityException, NoSuchFieldException, IllegalArgumentException,
IllegalAccessException {
private static Map<String, int[]> extractTables(BaseFont font)
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Class current = font.getClass();

while (current != null) {
if (current.getName().endsWith(".TrueTypeFont")) {
Field f = current.getDeclaredField("tables");
f.setAccessible(true);
return (Map)f.get(font);
Field field = current.getDeclaredField("tables");
field.setAccessible(true);
return (Map) field.get(font);
}

current = current.getSuperclass();
Expand All @@ -69,12 +69,9 @@ private static Map extractTables(BaseFont font)
}

private static String getTTCName(String name) {
int idx = name.toLowerCase().indexOf(".ttc,");
if (idx < 0) {
return name;
} else {
return name.substring(0, idx + 4);
}
int index = name.toLowerCase().indexOf(".ttc,");

return index < 0 ? name : name.substring(0, index + 4);
}

public static void populateDescription(String path, BaseFont font, FontDescription descr)
Expand Down Expand Up @@ -114,32 +111,35 @@ public static void populateDescription(String path, byte[] contents, BaseFont fo
}

private static RandomAccessFileOrArray populateDescription0(String path,
BaseFont font, FontDescription descr, RandomAccessFileOrArray rf)
throws NoSuchFieldException, IllegalAccessException, DocumentException, IOException {
Map tables = extractTables(font);
BaseFont font, FontDescription descr, RandomAccessFileOrArray rf)
throws NoSuchFieldException, IllegalAccessException, DocumentException, IOException {
Map<String, int[]> tables = extractTables(font);

descr.setStyle(guessStyle(font));

int[] location = (int[])tables.get("OS/2");
int[] location = tables.get("OS/2");
if (location == null) {
throw new DocumentException("Table 'OS/2' does not exist in " + path);
}

rf.seek(location[0]);
int want = 4;
long got = rf.skip(want);
if (got < want) {
throw new DocumentException("Skip TT font weight, expect read " + want + " bytes, but only got " + got);
}

descr.setWeight(rf.readUnsignedShort());
want = 20;
got = rf.skip(want);
if (got < want) {
throw new DocumentException("Skip TT font strikeout, expect read " + want + " bytes, but only got " + got);
}

descr.setYStrikeoutSize(rf.readShort());
descr.setYStrikeoutPosition(rf.readShort());

location = (int[])tables.get("post");
location = tables.get("post");

if (location != null) {
rf.seek(location[0]);
Expand All @@ -156,4 +156,5 @@ private static RandomAccessFileOrArray populateDescription0(String path,
rf = null;
return rf;
}

}
2 changes: 1 addition & 1 deletion flying-saucer-pdf-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-parent</artifactId>
<version>9.1.14</version>
<version>9.1.15</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
6 changes: 3 additions & 3 deletions flying-saucer-pdf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-parent</artifactId>
<version>9.1.14</version>
<version>9.1.15</version>
</parent>

<artifactId>flying-saucer-pdf</artifactId>
Expand All @@ -17,9 +17,9 @@
<description>Flying Saucer is a CSS 2.1 renderer written in Java. This artifact supports PDF output.</description>

<properties>
<bouncycastle.version>1.59</bouncycastle.version>
<bouncycastle.version>1.60</bouncycastle.version>
<junit.version>4.12</junit.version>
<openpdf.version>1.0.1</openpdf.version>
<openpdf.version>1.2.0</openpdf.version>
<itext.version>2.1.7</itext.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public void drawString(String s, float x, float y, JustificationInfo info) {
resetMode = true;
ensureStrokeColor();
}
if ((fontSpec.fontStyle == IdentValue.ITALIC) && (desc.getStyle() != IdentValue.ITALIC)) {
if ((fontSpec.fontStyle == IdentValue.ITALIC) && (desc.getStyle() != IdentValue.ITALIC) && (desc.getStyle() != IdentValue.OBLIQUE)) {
b = 0f;
c = 0.21256f;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package org.xhtmlrenderer.pdf;

import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.RandomAccessFileOrArray;
import org.xhtmlrenderer.css.constants.IdentValue;
import org.xhtmlrenderer.pdf.ITextFontResolver.FontDescription;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.xhtmlrenderer.css.constants.IdentValue;
import org.xhtmlrenderer.pdf.ITextFontResolver.FontDescription;

import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.RandomAccessFileOrArray;

/**
* Uses code from iText's DefaultFontMapper and TrueTypeFont classes. See
* <a href="http://sourceforge.net/projects/itext/">http://sourceforge.net/projects/itext/</a> for license information.
*/
public class TrueTypeUtil {

private static IdentValue guessStyle(BaseFont font) {
String[][] names = font.getFullFontName();
for (int i = 0; i < names.length; i++) {
String name[] = names[i];

for (String[] name : names) {
String lower = name[3].toLowerCase();
if (lower.indexOf("italic") != -1) {
if (lower.contains("italic")) {
return IdentValue.ITALIC;
} else if (lower.indexOf("oblique") != -1) {
} else if (lower.contains("oblique")) {
return IdentValue.OBLIQUE;
}
}
Expand All @@ -34,32 +34,32 @@ private static IdentValue guessStyle(BaseFont font) {
}

public static String[] getFamilyNames(BaseFont font) {
String names[][] = font.getFamilyFontName();
String[][] names = font.getFamilyFontName();

if (names.length == 1) {
return new String[] { names[0][3] };
return new String[]{names[0][3]};
}

List result = new ArrayList();
for (int k = 0; k < names.length; ++k) {
String name[] = names[k];
if ((name[0].equals("1") && name[1].equals("0")) ||
name[2].equals("1033")) {
List<String> result = new ArrayList<String>();
for (String[] name : names) {
if ((name[0].equals("1") && name[1].equals("0")) || name[2].equals("1033")) {
result.add(name[3]);
}
}
return (String[]) result.toArray(new String[result.size()]);

return result.toArray(new String[result.size()]);
}

// HACK No accessor
private static Map extractTables(BaseFont font)
throws SecurityException, NoSuchFieldException, IllegalArgumentException,
IllegalAccessException {
private static Map<String, int[]> extractTables(BaseFont font)
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Class current = font.getClass();

while (current != null) {
if (current.getName().endsWith(".TrueTypeFont")) {
Field f = current.getDeclaredField("tables");
f.setAccessible(true);
return (Map)f.get(font);
Field field = current.getDeclaredField("tables");
field.setAccessible(true);
return (Map) field.get(font);
}

current = current.getSuperclass();
Expand All @@ -69,12 +69,9 @@ private static Map extractTables(BaseFont font)
}

private static String getTTCName(String name) {
int idx = name.toLowerCase().indexOf(".ttc,");
if (idx < 0) {
return name;
} else {
return name.substring(0, idx + 4);
}
int index = name.toLowerCase().indexOf(".ttc,");

return index < 0 ? name : name.substring(0, index + 4);
}

public static void populateDescription(String path, BaseFont font, FontDescription descr)
Expand Down Expand Up @@ -114,32 +111,35 @@ public static void populateDescription(String path, byte[] contents, BaseFont fo
}

private static RandomAccessFileOrArray populateDescription0(String path,
BaseFont font, FontDescription descr, RandomAccessFileOrArray rf)
throws NoSuchFieldException, IllegalAccessException, DocumentException, IOException {
Map tables = extractTables(font);
BaseFont font, FontDescription descr, RandomAccessFileOrArray rf)
throws NoSuchFieldException, IllegalAccessException, DocumentException, IOException {
Map<String, int[]> tables = extractTables(font);

descr.setStyle(guessStyle(font));

int[] location = (int[])tables.get("OS/2");
int[] location = tables.get("OS/2");
if (location == null) {
throw new DocumentException("Table 'OS/2' does not exist in " + path);
}

rf.seek(location[0]);
int want = 4;
long got = rf.skip(want);
if (got < want) {
throw new DocumentException("Skip TT font weight, expect read " + want + " bytes, but only got " + got);
}

descr.setWeight(rf.readUnsignedShort());
want = 20;
got = rf.skip(want);
if (got < want) {
throw new DocumentException("Skip TT font strikeout, expect read " + want + " bytes, but only got " + got);
}

descr.setYStrikeoutSize(rf.readShort());
descr.setYStrikeoutPosition(rf.readShort());

location = (int[])tables.get("post");
location = tables.get("post");

if (location != null) {
rf.seek(location[0]);
Expand All @@ -156,4 +156,5 @@ private static RandomAccessFileOrArray populateDescription0(String path,
rf = null;
return rf;
}

}
Loading

0 comments on commit 3d007f8

Please sign in to comment.