Re: [FOray-developer] ant font - currently fails for SVN head?
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
From: Jason H. <ja...@pl...> - 2008-03-09 01:40:59
|
> I have just committed and published some improvements to the "build" > documentation that should help clear this up, making the aXSL dependency > more clear. I apologize for the inconvenience. Please let me know if the > build still does not work after including an up-to-date aXSL build. Dear Victor Thanks very much for you quick reply to my post. I can confirm that the build works now following your instructions to use an interim aXSL build. I initially came across foray looking to use the Panose information in a true type file to find an appropriate substitute for fonts specified in the font table part of a Microsoft OpenXML WordprocessingML docx document. I want to use the substitute font via AWT in docx4all's user interface, and also for XHTML/PDF output as per https://xhtmlrenderer.dev.java.net/r7/users-guide-r7.html#xil_32 I've been using FOP's org.apache.fop.fonts.autodetect package (added May 2007, see https://issues.apache.org/bugzilla/show_bug.cgi?id=41831 ) to identify locally installed fonts. Maybe you'd like to add that to foray? Anyway, for now I'm using your Panose.java with the fop fonts package. I've made a few changes to Panose.java, including: - difference method squares individual values - validPanose accepts higher max values where appropriate (see new field validMaxValues) Code is below. kind regards Jason /** * A PANOSE classification number. */ public class Panose { /** Constant indicating the size of the "panose" field, in bytes. */ public static final byte ARRAY_SIZE = 10; /** Max difference for it to be considered an acceptable match. * Note that this value will depend on the weights in the * difference function. */ public static final int MATCH_THRESHOLD = 30; /** The array of PANOSE numbers. */ private byte[] panoseArray; // bFamilyType 5 // bSerifStyle 15 // bWeight 11 // bProportion 9 // bContrast 9 // bStrokeVariatoon 8 // bArmStyle 11 // bLetterform 15 // bMidline 13 // bXHeight 7 // See http://fonts.apple.com/TTRefMan/RM06/Chap6OS2.html private final static int[] validMaxValues = { 5, 15, 11, 9, 9, 8, 11, 15, 13, 7 }; /** * Creates a new Panose instance. * @param panoseArray The array of bytes recording the PANOSE * classification. */ public Panose(final byte[] panoseArray) { this.panoseArray = panoseArray; } /** * Returns the array of bytes representing the PANOSE number. * @return The PANOSE array. */ public byte[] getPanoseArray() { return this.panoseArray; } /** * Computes the weighted "closeness" of another Panose to this value. * @param panoseDescription An array of Panose values to compare to this. * @return The weighted difference between the two Panose values. * A smaller value indicates that the two values are closer, and a larger * value indicates that they are farther apart. * A return value of {@link Long#MAX_VALUE} indicates that the input was * invalid or that some other aspect of the comparison was invalid. */ public long difference(final byte[] panoseDescription) { if (! validPanose(panoseDescription)) { return Long.MAX_VALUE; } /* We don't really know how to do this. Each byte is supposed to have * a weight, and those weights do not appear to be documented anywhere. * * Called "Panose match value" or "PANOSE Matching Heuristic" * - see http://www.w3.org/Fonts/Panose/pan2.html#Heuristic **/ long difference = 0; for (int i = 0; i < panoseDescription.length; i++) { // final int digit = panoseDescription.length - i; // final int weight = (int) Math.round(Math.pow(2, digit - 1)); final int weight = 1; final int thisDifference = (this.panoseArray[i] - panoseDescription[i]); difference += weight * thisDifference * thisDifference; } return difference; } /** * Tests the validity of a panose description. * @param panoseDescription The panose values to be tested. * @return True for a valid PANOSE description, or false if the input is * null, does not have 10 elements, or any of the elements do not contain * valid ASCII numerals (0 through 9). */ public static boolean validPanose(final byte[] panoseDescription) { if (panoseDescription == null) { System.out.println("null byte[]" ); return false; } if (panoseDescription.length != Panose.ARRAY_SIZE) { System.out.println("Invalid length " + panoseDescription.length ); return false; } for (int i = 0; i < panoseDescription.length; i++) { final byte theByte = panoseDescription[i]; String s = Byte.toString(theByte); int n = Integer.parseInt(s); if (n < 0) { //System.out.println("Invalid value (too small) " + theByte + " in position " + i + " of " + toString(panoseDescription) ); return false; } if (n > validMaxValues[i]) { System.out.println("Invalid value " + n + " > " + validMaxValues[i] + " in position " + i + " of " + toString(panoseDescription) ); return false; } } return true; } public String toString() { return toString(this.panoseArray); } public static String toString(byte[] panoseArray) { if (panoseArray.length != Panose.ARRAY_SIZE) { System.out.println("Unexpected length: " + panoseArray.length); } StringBuilder sb = new StringBuilder(20); for (int i = 0; i < panoseArray.length; i++) { final byte theByte = panoseArray[i]; sb.append(theByte + " "); } return sb.toString(); } } |