aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-02-19 15:47:48 +0000
committerJeremias Maerki <jeremias@apache.org>2008-02-19 15:47:48 +0000
commit56387de039f142b731d6ced52db6c79cb422824b (patch)
treef4339ed24f0bdea5c279c83009f97b393d91cceb
parente4cc262c1fac77fc38286b412b6293f1f1767ec8 (diff)
downloadxmlgraphics-fop-56387de039f142b731d6ced52db6c79cb422824b.tar.gz
xmlgraphics-fop-56387de039f142b731d6ced52db6c79cb422824b.zip
Added support for reading the OS/2 table's usWeightClass value which supports the same font weight values as we use in XSL-FO.
However, in my tests these values proved to be unreliable (like ExtraBlack fonts returning 400). I just hooked the whole thing in so this work isn't lost if anyone has an idea to make it work. The FontInfoFinder will continue to only use guessed font weights for now. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@629131 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/fonts/CustomFont.java21
-rw-r--r--src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java6
-rw-r--r--src/java/org/apache/fop/fonts/truetype/TTFFile.java12
-rw-r--r--src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java1
4 files changed, 38 insertions, 2 deletions
diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java
index 0ac3b80bc..f6bb52cb3 100644
--- a/src/java/org/apache/fop/fonts/CustomFont.java
+++ b/src/java/org/apache/fop/fonts/CustomFont.java
@@ -46,6 +46,7 @@ public abstract class CustomFont extends Typeface
private int descender = 0;
private int[] fontBBox = {0, 0, 0, 0};
private int flags = 4;
+ private int weight = 0; //0 means unknown weight
private int stemV = 0;
private int italicAngle = 0;
private int missingWidth = 0;
@@ -197,6 +198,15 @@ public abstract class CustomFont extends Typeface
}
/**
+ * Returns the font weight (100, 200...800, 900). This value may be different from the
+ * one that was actually used to register the font.
+ * @return the font weight (or 0 if the font weight is unknown)
+ */
+ public int getWeight() {
+ return this.weight;
+ }
+
+ /**
* {@inheritDoc}
*/
public int getStemV() {
@@ -350,6 +360,17 @@ public abstract class CustomFont extends Typeface
}
/**
+ * Sets the font weight. Valid values are 100, 200...800, 900.
+ * @param weight the font weight
+ */
+ public void setWeight(int weight) {
+ weight = (weight / 100) * 100;
+ weight = Math.max(100, weight);
+ weight = Math.min(900, weight);
+ this.weight = weight;
+ }
+
+ /**
* {@inheritDoc}
*/
public void setStemV(int stemV) {
diff --git a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
index 1ec8a5528..5fc0525c3 100644
--- a/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
+++ b/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
@@ -72,7 +72,11 @@ public class FontInfoFinder {
String searchName = fullName.toLowerCase();
String style = guessStyle(customFont, searchName);
- int weight = FontUtil.guessWeight(searchName);
+ int weight; //= customFont.getWeight();
+ int guessedWeight = FontUtil.guessWeight(searchName);
+ //We always take the guessed weight for now since it yield much better results.
+ //OpenType's OS/2 usWeightClass value proves to be unreliable.
+ weight = guessedWeight;
//Full Name usually includes style/weight info so don't use these traits
//If we still want to use these traits, we have to make FontInfo.fontLookup() smarter
diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFile.java b/src/java/org/apache/fop/fonts/truetype/TTFFile.java
index 86a1d75e2..e60722331 100644
--- a/src/java/org/apache/fop/fonts/truetype/TTFFile.java
+++ b/src/java/org/apache/fop/fonts/truetype/TTFFile.java
@@ -105,6 +105,7 @@ public class TTFFile {
//Ascender/descender from OS/2 table
private int os2Ascender = 0;
private int os2Descender = 0;
+ private int usWeightClass = 0;
private short lastChar = 0;
@@ -620,6 +621,13 @@ public class TTFFile {
return flags;
}
+ /**
+ * Returns the weight class of this font. Valid values are 100, 200....,800, 900.
+ * @return the weight class value (or 0 if there was no OS/2 table in the font)
+ */
+ public int getWeightClass() {
+ return this.usWeightClass;
+ }
/**
* Returns the StemV attribute of the font.
@@ -978,7 +986,9 @@ public class TTFFile {
private final void readOS2(FontFileReader in) throws IOException {
// Check if font is embeddable
if (dirTabs.get("OS/2") != null) {
- seekTab(in, "OS/2", 2 * 4);
+ seekTab(in, "OS/2", 2 * 2);
+ this.usWeightClass = in.readTTFUShort();
+ in.skip(2);
int fsType = in.readTTFUShort();
if (fsType == 2) {
isEmbeddable = false;
diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
index b29aff808..60a6948fc 100644
--- a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
+++ b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
@@ -90,6 +90,7 @@ public class TTFFontLoader extends FontLoader {
returnFont.setStemV(Integer.parseInt(ttf.getStemV())); //not used for TTF
returnFont.setItalicAngle(Integer.parseInt(ttf.getItalicAngle()));
returnFont.setMissingWidth(0);
+ returnFont.setWeight(ttf.getWeightClass());
multiFont.setCIDType(CIDFontType.CIDTYPE2);
int[] wx = ttf.getWidths();