source:
trunk/docx4j/etc/fop-fonts.patch
@
691
| Revision 691, 36.3 KB checked in by jharrop, 3 years ago (diff) |
|---|
-
home/dev/workspace/fop/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
151 151 } 152 152 EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(), 153 153 fontTripletList, embedUrl, subFontName); 154 fontInfo.setPanose(customFont.getPanose()); 154 155 fontInfo.setPostScriptName(customFont.getFontName()); 156 fontInfo.setEmbeddable(customFont.isEmbeddable()); 157 155 158 if (fontCache != null) { 156 159 fontCache.addFont(fontInfo); 157 160 } -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/CIDFontType.java
19 19 20 20 package org.apache.fop.fonts; 21 21 22 import org.apache.avalon.framework.ValuedEnum; 22 //import org.apache.avalon.framework.ValuedEnum; 23 import org.apache.fop.fonts.ValuedEnum; 23 24 24 25 /** 25 26 * This class enumerates all supported CID font types. -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/CustomFont.java
17 17 18 18 /* $Id$ */ 19 19 20 /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j. 21 * 22 * This notice is included to meet the condition in clause 4(b) of the License. 23 */ 24 20 25 package org.apache.fop.fonts; 21 26 22 27 import java.io.IOException; … … 58 63 59 64 private boolean useKerning = true; 60 65 66 private boolean isEmbeddable = true; 67 68 public boolean isEmbeddable() { 69 return isEmbeddable; 70 } 71 72 public void setEmbeddable(boolean isEmbeddable) { 73 this.isEmbeddable = isEmbeddable; 74 } 75 76 private Panose panose = null; 77 78 public Panose getPanose() { 79 return panose; 80 } 81 82 public void setPanose(Panose panose) { 83 this.panose = panose; 84 } 85 61 86 /** {@inheritDoc} */ 62 87 public String getFontName() { 63 88 return fontName; -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/EmbedFontInfo.java
17 17 18 18 /* $Id$ */ 19 19 20 /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j. 21 * 22 * This notice is included to meet the condition in clause 4(b) of the License. 23 */ 24 20 25 package org.apache.fop.fonts; 21 26 22 27 import java.io.IOException; … … 48 53 49 54 private transient boolean embedded = true; 50 55 56 private boolean isEmbeddable = true; 57 58 public boolean isEmbeddable() { 59 return isEmbeddable; 60 } 61 62 public void setEmbeddable(boolean isEmbeddable) { 63 this.isEmbeddable = isEmbeddable; 64 } 65 66 protected Panose panose = null; 67 68 public Panose getPanose() { 69 return panose; 70 } 71 72 public void setPanose(Panose panose) { 73 this.panose = panose; 74 } 75 51 76 /** 52 * Main constructor 53 * @param metricsFile Path to the xml file containing font metrics 54 * @param kerning True if kerning should be enabled 55 * @param fontTriplets List of font triplets to associate with this font 56 * @param embedFile Path to the embeddable font file (may be null) 57 * @param subFontName the sub-fontname used for TrueType Collections (null otherwise) 58 */ 77 * Main constructor 78 * 79 * @param metricsFile 80 * Path to the xml file containing font metrics 81 * @param kerning 82 * True if kerning should be enabled 83 * @param fontTriplets 84 * List of font triplets to associate with this font 85 * @param embedFile 86 * Path to the embeddable font file (may be null) 87 * @param subFontName 88 * the sub-fontname used for TrueType Collections (null 89 * otherwise) 90 */ 59 91 public EmbedFontInfo(String metricsFile, boolean kerning, 60 92 List/*<FontTriplet>*/ fontTriplets, String embedFile, String subFontName) { 61 93 this.metricsFile = metricsFile; -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/Enum.java
1 /* 2 * Copyright 1997-2004 The Apache Software Foundation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j. 18 * 19 * This notice is included to meet the condition in clause 4(b) of the License. 20 */ 21 22 //package org.apache.avalon.framework; 23 package org.apache.fop.fonts; 24 25 import java.util.Map; 26 27 /** 28 * Basic enum class for type-safe enums. Should be used as an abstract base. For example: 29 * 30 * <pre> 31 * import org.apache.avalon.framework.Enum; 32 * 33 * public final class Color extends Enum { 34 * public static final Color RED = new Color( "Red" ); 35 * public static final Color GREEN = new Color( "Green" ); 36 * public static final Color BLUE = new Color( "Blue" ); 37 * 38 * private Color( final String color ) 39 * { 40 * super( color ); 41 * } 42 * } 43 * </pre> 44 * 45 * If further operations, such as iterating over all items, are required, the 46 * {@link #Enum(String, Map)} constructor can be used to populate a <code>Map</code>, from which 47 * further functionality can be derived: 48 * <pre> 49 * public final class Color extends Enum { 50 * static final Map map = new HashMap(); 51 * 52 * public static final Color RED = new Color( "Red", map ); 53 * public static final Color GREEN = new Color( "Green", map ); 54 * public static final Color BLUE = new Color( "Blue", map ); 55 * 56 * private Color( final String color, final Map map ) 57 * { 58 * super( color, map ); 59 * } 60 * 61 * public static Iterator iterator() 62 * { 63 * return map.values().iterator(); 64 * } 65 * } 66 * </pre> 67 * 68 * <p> 69 * <em>NOTE:</em> between 4.0 and 4.1, the constructors' access has been changed 70 * from <code>public</code> to <code>protected</code>. This is to prevent users 71 * of the Enum breaking type-safety by defining new Enum items. All Enum items 72 * should be defined in the Enum class, as shown above. 73 * </p> 74 * 75 * 76 * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a> 77 * @version $Id$ 78 */ 79 public abstract class Enum 80 { 81 /** 82 * The string representation of the Enum. 83 */ 84 private final String m_name; 85 86 /** 87 * Constructor to add a new named item. 88 * <p> 89 * <em>Note:</em> access changed from <code>public</code> to 90 * <code>protected</code> after 4.0. See class description. 91 * </p> 92 * 93 * @param name Name of the item. 94 */ 95 protected Enum( final String name ) 96 { 97 this( name, null ); 98 } 99 100 /** 101 * Constructor to add a new named item. 102 * <p> 103 * <em>Note:</em> access changed from <code>public</code> to 104 * <code>protected</code> after 4.0. See class description. 105 * </p> 106 * 107 * @param name Name of the item. 108 * @param map A <code>Map</code>, to which will be added a pointer to the newly constructed 109 * object. 110 */ 111 protected Enum( final String name, final Map map ) 112 { 113 m_name = name; 114 if( null != map ) 115 { 116 map.put( name, this ); 117 } 118 } 119 120 /** 121 * Tests for equality. Two Enum:s are considered equal 122 * if they are of the same class and have the same names. 123 * The method is also declared final - I (LSutic) did this to 124 * allow the JIT to inline it easily. 125 * 126 * @param o the other object 127 * @return the equality status 128 */ 129 public boolean equals( Object o ) 130 { 131 if( this == o ) 132 return true; 133 if( !(o instanceof Enum) ) 134 return false; 135 136 final Enum enumerated = (Enum)o; 137 138 if( !getClass().equals( enumerated.getClass() ) ) 139 return false; 140 if( m_name != null ? !m_name.equals( enumerated.m_name ) : enumerated.m_name != null ) 141 return false; 142 143 return true; 144 } 145 146 public int hashCode() 147 { 148 int result; 149 result = (m_name != null ? m_name.hashCode() : 0); 150 result = 29 * result + getClass().hashCode(); 151 return result; 152 } 153 154 /** 155 * Returns a hash code value for the object. 156 * 157 * @return a hash code value for this object 158 */ 159 /*public int hashCode() 160 { 161 return m_name.hashCode() ^ this.getClass().getName().hashCode(); 162 }*/ 163 164 /** 165 * Retrieve the name of this Enum item, set in the constructor. 166 * @return the name <code>String</code> of this Enum item 167 */ 168 public final String getName() 169 { 170 return m_name; 171 } 172 173 /** 174 * Human readable description of this Enum item. For use when debugging. 175 * @return String in the form <code>type[name]</code>, eg.: 176 * <code>Color[Red]</code>. 177 */ 178 public String toString() 179 { 180 return getClass().getName() + "[" + m_name + "]"; 181 } 182 } -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/FontType.java
19 19 20 20 package org.apache.fop.fonts; 21 21 22 import org.apache.avalon.framework.ValuedEnum; 22 //import org.apache.avalon.framework.ValuedEnum; 23 import org.apache.fop.fonts.ValuedEnum; 23 24 24 25 /** 25 26 * This class enumerates all supported font types. -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/MultiByteFont.java
17 17 18 18 /* $Id$ */ 19 19 20 /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j. 21 * 22 * This notice is included to meet the condition in clause 4(b) of the License. 23 */ 24 20 25 package org.apache.fop.fonts; 21 26 22 27 //Java … … 118 123 } 119 124 } 120 125 121 /** {@inheritDoc} */ 122 public boolean isEmbeddable() { 123 return !(getEmbedFileName() == null && getEmbedResourceName() == null); 124 } 126 // Comment out - this overrides the value derived by TTFFile, which 127 // is not what we want. 128 129 // /** {@inheritDoc} */ 130 // public boolean isEmbeddable() { 131 // return !(getEmbedFileName() == null && getEmbedResourceName() == null); 132 // } 125 133 126 134 /** {@inheritDoc} */ 127 135 public CIDSubset getCIDSubset() { -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/Panose.java
1 /* 2 * Copyright 2006 The FOray Project. 3 * http://www.foray.org 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * This work is in part derived from the following work(s), used with the 18 * permission of the licensor: 19 * Apache FOP, licensed by the Apache Software Foundation 20 * 21 */ 22 23 /* 24 * $LastChangedRevision: 10482 $ 25 * $LastChangedDate: 2008-03-23 02:59:39 +1100 (Sun, 23 Mar 2008) $ 26 * $LastChangedBy$ 27 */ 28 29 /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j. 30 * 31 * This notice is included to meet the condition in clause 4(b) of the License. 32 */ 33 34 //package org.foray.font.format; 35 package org.apache.fop.fonts; 36 37 38 39 /** 40 * A PANOSE-1 classification number. 41 * 42 * <p>References:</p> 43 * <ul> 44 * <li><a href="http://fonts.apple.com/TTRefMan/RM06/Chap6OS2.html">The TTF OS/2 Table 45 * doc</a></li> 46 * <li><a href="http://www.w3.org/Fonts/Panose/pan2.html#StaticDigits">Panose 2.0 White 47 * Paper</a></li> 48 * <li><a href="http://www.byte.com/art/9405/sec12/art1.htm">The Panose Typeface-Matching 49 * System</a></li> 50 * <li>Michael S. De Laurentis, PANOSE 1.0 Core Mapper Services, Hewlett-Packard Document 51 * EWC-93-0023b, Hewlett-Packard Corporation, 101 Stewart, Suite 700, Seattle, WA 98101 (1993).</li> 52 * <li><a href="www.fonts.com/hp/panose/greybook">The "Grey Book"</a></li> 53 * </ul> 54 */ 55 public final class Panose { 56 57 /** 58 * Enumeration of the fields that comprise a PANOSE description. 59 * @see "http://fonts.apple.com/TTRefMan/RM06/Chap6OS2.html" 60 */ 61 public enum Field { 62 /** The bFamilyType field. */ 63 FAMILY_TYPE ((byte) 0, (byte) 5), 64 65 /** The bSerifStyle field. */ 66 SERIF_STYLE ((byte) 1, (byte) 15), 67 68 /** The bWeight field. */ 69 WEIGHT ((byte) 2, (byte) 11), 70 71 /** The bProportion field. */ 72 PROPORTION ((byte) 3, (byte) 9), 73 74 /** The bContrast field. */ 75 CONTRAST ((byte) 4, (byte) 9), 76 77 /** The bStrokeVariatoon field. */ 78 STROKE_VARIATION ((byte) 5, (byte) 8), 79 80 /** The bArmStyle field. */ 81 ARM_STYLE ((byte) 6, (byte) 11), 82 83 /** The bLetterform field. */ 84 LETTERFORM ((byte) 7, (byte) 15), 85 86 /** The bMidline field. */ 87 MIDLINE ((byte) 8, (byte) 13), 88 89 /** The bXHeight field. */ 90 X_HEIGHT ((byte) 9, (byte) 7); 91 92 /** The 0-based index of this element in the PANOSE array. */ 93 private byte index; 94 95 /** The maximum value that is permissible for this element. */ 96 private byte maxValue; 97 98 /** 99 * Private Constructor. 100 * @param index The 0-based index of this element in the PANOSE array. 101 * @param maxValue The maximum value that is permissible for this element. 102 */ 103 private Field(final byte index, final byte maxValue) { 104 this.index = index; 105 this.maxValue = maxValue; 106 } 107 108 /** 109 * Returns the 0-based index of this element in the PANOSE array. 110 * @return The 0-based index of this element in the PANOSE array. 111 */ 112 public byte getIndex() { 113 return this.index; 114 } 115 116 /** 117 * Returns the maximum valid value for this field. 118 * @return The maximum valid value for this field. 119 */ 120 public byte getMaxValue() { 121 return this.maxValue; 122 } 123 124 } 125 126 /** 127 * Constant indicating the minimum italic value for the letterform field. 128 * This is based on an analysis of the MS ClearType Collection fonts: 129 * <ul> 130 * <li>consolas [ 2 11 6 9 2 2 4 3 2 4 ] bold 6 ital 3</li> 131 * <li>consolas-bold [ 2 11 7 9 2 2 4 3 2 4 ] bold 7 ital 3</li> 132 * <li>consolas-italic [ 2 11 6 9 2 2 4 10 2 4 ] bold 6 ital 10</li> 133 * <li>consolas-bolditalic [ 2 11 7 9 2 2 4 10 2 4 ] bold 7 ital 10</li> 134 * 135 * <li>cordianew [ 2 11 3 4 2 2 2 2 2 4 ] bold 3 ital 2</li> 136 * <li>cordianew-bolditalic [ 2 11 6 4 2 2 2 9 2 4 ] bold 6 ital 9</li> 137 * 138 * <li>calibri [ 2 15 5 2 2 2 4 3 2 4 ] bold 5 ital 3</li> 139 * <li>calibri-bold [ 2 15 7 2 3 4 4 3 2 4 ] bold 7 ital 3</li> 140 * <li>calibri-bolditalic [ 2 15 7 2 3 4 4 10 2 4 ] bold 7 ital 10</li> 141 * 142 * <li>constantia [ 2 3 6 2 5 3 6 3 3 3 ] bold 6 ital 3</li> 143 * <li>constantia-bold [ 2 3 7 2 6 3 6 3 3 3 ] bold 7 ital 3 (note the 6 at index 4)</li> 144 * <li>constantia-italic [ 2 3 6 2 5 3 6 10 3 3 ] bold 6 ital 10</li> 145 * 146 * <li>candara-bold [ 2 14 7 2 3 3 3 2 2 4 ] bold 7 ital 2</li> 147 * <li>candara-italic [ 2 14 5 2 3 3 3 9 2 4 ] bold 5 ital 9</li> 148 * <li>candara-bolditalic [ 2 14 7 2 3 3 3 9 2 4 ] bold 7 ital 9</li> 149 * 150 * <li>cambria-bold [ 2 4 8 3 5 4 6 3 2 4 ] bold 8 ital 3</li> 151 * <li>cambria-italic [ 2 4 5 3 5 4 6 10 2 4 ] bold 5 ital 10</li> 152 * </ul> 153 */ 154 private static final byte LETTERFORM_MIN_ITALIC = 9; 155 156 /** 157 * Constant indicating the minimum bold value for the weight field. 158 * This is based on an analysis of the MS ClearType Collection fonts, which can be found at 159 * {@link #LETTERFORM_MIN_ITALIC}. 160 */ 161 private static final byte WEIGHT_MIN_BOLD = 7; 162 163 /** An array of weights indicating that all elements in a comparison between two PANOSE values 164 * shall be considered to be of the same weight. */ 165 private static final byte[] NEUTRAL_WEIGHTS = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 166 /* Caveat: It is tempting to make NEUTRAL_WEIGHTS public and allow client apps to use it as a 167 * parameter. However, there is no way to protect the data inside it from corruption, so we 168 * have elected to keep it private and to allow "null" to be interpreted as the same value. */ 169 170 /** The encapsulated array of PANOSE numbers. */ 171 private byte[] panoseArray; 172 173 /** 174 * Private Constructor. Use {@link #makeInstance(byte[])} to create an instance of this class. 175 * @param panoseArray The array of bytes recording the PANOSE classification. 176 */ 177 private Panose(final byte[] panoseArray) { 178 /* Clone the incoming array to protect our data from subsequent changes made to the original 179 * array. */ 180 this.panoseArray = panoseArray.clone(); 181 } 182 183 /** 184 * Creates a new Panose instance, first checking it for validity. 185 * @param panoseArray The array of bytes recording the PANOSE 186 * classification. 187 * @return The newly-created instance. 188 * @throws FontException If <code>panoseArray</code> contains an illegal value. 189 * @see #forceInstance(byte[]) 190 */ 191 public static Panose makeInstance(final byte[] panoseArray) { 192 final String panoseValidationMessage = Panose.validPanose(panoseArray); 193 if (panoseValidationMessage != null) { 194 throw new IllegalArgumentException("Illegal Panose Array: " + panoseValidationMessage); 195 } 196 return new Panose(panoseArray); 197 } 198 199 /** 200 * Creates a new Panose instance without any error checking. 201 * @param panoseArray The array of bytes recording the PANOSE classification. 202 * @return The newly-created instance. 203 * @see #makeInstance(byte[]) 204 */ 205 public static Panose forceInstance(final byte[] panoseArray) { 206 return new Panose(panoseArray); 207 } 208 209 /** 210 * Returns a clone of the the array of bytes representing the PANOSE number. 211 * To avoid the cost of this cloning operation, use {@link #getElement(int)} to obtain the 212 * value of individual elements in the array. 213 * @return The PANOSE array. 214 */ 215 public byte[] getPanoseArray() { 216 return this.panoseArray.clone(); 217 } 218 219 /** 220 * Returns a given element from the underlying Panose array. 221 * @param index The index to the element desired. 222 * @return The value of the element at <code>index</code>. 223 */ 224 public byte getElement(final int index) { 225 return this.panoseArray[index]; 226 } 227 228 /** 229 * Returns a given element from the underlying Panose array. 230 * @param field The field for which the value is desired. 231 * @return The value of the element at <code>field</code>. 232 */ 233 public byte getElement(final Panose.Field field) { 234 final int index = field.getIndex(); 235 return getElement(index); 236 } 237 238 /** 239 * Computes the weighted "closeness" of another Panose to this value. 240 * @param otherPanose Another Panose instance which is being compared to this. 241 * @param weights 10-element byte array of weights that should be used for each of the elements 242 * in the comparison. 243 * Values in this array must be between 0 and 127 inclusive. 244 * (This constant is documented at http://www.w3.org/Fonts/Panose/pan2.html#StaticDigits). 245 * Use null if all elements are to be weighted equally. 246 * @return The weighted difference between the two Panose values. 247 * A smaller value indicates that the two values are closer, and a larger 248 * value indicates that they are farther apart. 249 */ 250 public long difference(final Panose otherPanose, final byte[] weights) { 251 /* This is a partial implementation of the "PANOSE Matching Heuristic" documented at: 252 * http://www.w3.org/Fonts/Panose/pan2.html#Heuristic. **/ 253 byte[] weightsToUse = null; 254 if (weights == null) { 255 weightsToUse = Panose.NEUTRAL_WEIGHTS; 256 } else { 257 validateWeights(weights); 258 weightsToUse = weights; 259 } 260 long difference = 0; 261 for (int i = 0; i < Panose.Field.values().length; i++) { 262 // final int digit = panoseDescription.length - i; 263 // final int weight = (int) Math.round(Math.pow(2, digit - 1)); 264 final int weight = weightsToUse[i]; 265 266 final int thisDifference = this.getElement(i) - otherPanose.getElement(i); 267 difference += weight * thisDifference * thisDifference; 268 } 269 return difference; 270 } 271 272 /** 273 * Examines an array of weights, throwing various unchecked exceptions if the data is not valid. 274 * @param weights The array of weights to be tested. 275 */ 276 private static void validateWeights(final byte[] weights) { 277 if (weights == null) { 278 throw new NullPointerException("Weights may not be null"); 279 } 280 if (weights.length != Panose.Field.values().length) { 281 throw new IllegalArgumentException("Weights size expected: " 282 + Panose.Field.values().length + ", actual: " + weights.length); 283 } 284 for (int i = 0; i < weights.length; i++) { 285 final byte weight = weights[i]; 286 if (weight < 0 287 || weight > Byte.MAX_VALUE) { 288 throw new IllegalArgumentException("Weight element " + i + " is outside the range " 289 + "of 0 thru 127."); 290 } 291 } 292 } 293 294 /** 295 * Tests the validity of a panose description. 296 * @param panoseDescription The panose values to be tested. 297 * @return Null for a valid PANOSE description. For an invalid PANOSE description, returns a 298 * descriptive message indicating which element is invalid. 299 */ 300 public static String validPanose(final byte[] panoseDescription) { 301 if (panoseDescription == null) { 302 return "Panose description cannot be null."; 303 } 304 if (panoseDescription.length != Panose.Field.values().length) { 305 return "Illegal Panose description size: " + panoseDescription.length; 306 } 307 for (int i = 0; i < panoseDescription.length; i++) { 308 final byte theByte = panoseDescription[i]; 309 final Panose.Field panoseField = Panose.Field.values()[i]; 310 final byte maxValue = panoseField.getMaxValue(); 311 if (theByte < 0 312 || theByte > maxValue) { 313 return "Invalid value " + theByte + " > " + maxValue + " in position " + i 314 + " of " + toString(panoseDescription); 315 } 316 } 317 return null; 318 } 319 320 /** 321 * {@inheritDoc} 322 */ 323 public String toString() { 324 return toString(this.panoseArray); 325 } 326 327 /** 328 * Returns a String representation of a Panose array. 329 * @param panoseArray The Panose array to be expressed as a String. 330 * @return The String representation of <code>panoseArray</code>. 331 */ 332 private static String toString(final byte[] panoseArray) { 333 final StringBuilder sb = new StringBuilder(30); 334 sb.append("[ "); 335 for (int i = 0; i < panoseArray.length; i++) { 336 final byte theByte = panoseArray[i]; 337 sb.append(theByte + " "); 338 } 339 sb.append("]"); 340 return sb.toString(); 341 } 342 343 /** 344 * Returns the bold version of this Panose instance. 345 * @return If this already describes a bold font, returns this. Otherwise, returns a new 346 * Panose instance that is identical to this, except describing a bold font. 347 */ 348 public Panose getBold() { 349 final byte weightValue = this.getElement(Panose.Field.WEIGHT); 350 if (weightValue >= Panose.WEIGHT_MIN_BOLD) { 351 /* This Panose value is already bold. */ 352 return this; 353 } 354 final byte[] newArray = this.panoseArray.clone(); 355 newArray[Panose.Field.WEIGHT.getIndex()] = Panose.WEIGHT_MIN_BOLD; 356 return Panose.forceInstance(newArray); 357 } 358 359 /** 360 * Returns the italic version of this Panose instance. 361 * @return If this already describes an italic font, returns this. Otherwise, returns a new 362 * Panose instance that is identical to this, except describing an italic font. 363 */ 364 public Panose getItalic() { 365 final byte letterformValue = this.getElement(Panose.Field.LETTERFORM); 366 if (letterformValue >= Panose.LETTERFORM_MIN_ITALIC) { 367 /* This Panose value is already italic. */ 368 return this; 369 } 370 final byte[] newArray = this.panoseArray.clone(); 371 newArray[Panose.Field.LETTERFORM.getIndex()] = Panose.LETTERFORM_MIN_ITALIC; 372 return Panose.forceInstance(newArray); 373 } 374 375 376 } -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/truetype/TTFFile.java
31 31 import org.apache.xmlgraphics.fonts.Glyphs; 32 32 33 33 import org.apache.fop.fonts.FontUtil; 34 import org.apache.fop.fonts.Panose; 34 35 35 36 /** 36 37 * Reads a TrueType file or a TrueType Collection. … … 49 50 50 51 private String encoding = "WinAnsiEncoding"; // Default encoding 51 52 53 /** Array containing the Panose information. */ 54 private Panose panose; 55 52 56 private short firstChar = 0; 53 57 private boolean isEmbeddable = true; 54 58 private boolean hasSerifs = true; … … 1006 1010 isEmbeddable = true; 1007 1011 } 1008 1012 in.skip(11 * 2); 1009 in.skip(10); //panose array 1010 in.skip(4 * 4); //unicode ranges 1013 1014 //in.skip(10); //panose array 1015 final byte[] panoseArray = new byte[10]; 1016 for (int i = 0; i < panoseArray.length; i++) { 1017 panoseArray[i] = in.read(); 1018 } 1019 this.panose = Panose.makeInstance(panoseArray); 1020 1021 in.skip(4 * 4); // unicode ranges 1011 1022 in.skip(4); 1012 1023 in.skip(3 * 2); 1013 1024 int v; … … 1549 1560 return null; 1550 1561 } 1551 1562 } 1563 1564 public Panose getPanose() { 1565 return panose; 1566 } 1552 1567 1553 1568 /* 1554 1569 * Helper classes, they are not very efficient, but that really -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
130 130 returnFont.setItalicAngle(Integer.parseInt(ttf.getItalicAngle())); 131 131 returnFont.setMissingWidth(0); 132 132 returnFont.setWeight(ttf.getWeightClass()); 133 134 returnFont.setPanose(ttf.getPanose() ); 135 returnFont.setEmbeddable(ttf.isEmbeddable() ); 133 136 134 137 if (isCid) { 135 138 multiFont.setCIDType(CIDFontType.CIDTYPE2); -
home/dev/workspace/fop/src/java/org/apache/fop/fonts/ValuedEnum.java
1 /* 2 * Copyright 1997-2004 The Apache Software Foundation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j. 18 * 19 * This notice is included to meet the condition in clause 4(b) of the License. 20 */ 21 22 //package org.apache.avalon.framework; 23 package org.apache.fop.fonts; 24 25 import java.util.Map; 26 27 /** 28 * Basic enum class for type-safe enums with values. Valued enum items can be compared and ordered 29 * with the provided methods. Should be used as an abstract base. For example: 30 * 31 * <pre> 32 * import org.apache.avalon.framework.ValuedEnum; 33 * 34 * public final class JavaVersion 35 * extends ValuedEnum 36 * { 37 * //standard enums for version of JVM 38 * public static final JavaVersion JAVA1_0 = new JavaVersion( "Java 1.0", 100 ); 39 * public static final JavaVersion JAVA1_1 = new JavaVersion( "Java 1.1", 110 ); 40 * public static final JavaVersion JAVA1_2 = new JavaVersion( "Java 1.2", 120 ); 41 * public static final JavaVersion JAVA1_3 = new JavaVersion( "Java 1.3", 130 ); 42 * 43 * private JavaVersion( final String name, final int value ) 44 * { 45 * super( name, value ); 46 * } 47 * } 48 * </pre> 49 * 50 * The above class could then be used as follows: 51 * <pre> 52 * import org.apache.avalon.framework.context.Context; 53 * import org.apache.avalon.framework.context.Contextualizable; 54 * import org.apache.avalon.framework.context.ContextException; 55 * 56 * public class MyComponent implements Contextualizable 57 * { 58 * JavaVersion requiredVer = JavaVersion.JAVA1_2; 59 * 60 * public void contextualize(Context context) 61 * throws ContextException 62 * { 63 * JavaVersion ver = (JavaVersion)context.get("java.version"); 64 * if ( ver.isLessThan( requiredVer ) ) 65 * { 66 * throw new RuntimeException( requiredVer.getName()+" or higher required" ); 67 * } 68 * } 69 * } 70 * </pre> 71 * 72 * As with <code>Enum</code>, the {@link #ValuedEnum(String, int, Map)} constructor can be used to 73 * populate a <code>Map</code>, from which further functionality can be derived. 74 * 75 * <p> 76 * <em>NOTE:</em> between 4.0 and 4.1, the constructors' access has been changed 77 * from <code>public</code> to <code>protected</code>. This is to prevent users 78 * of the Enum breaking type-safety by defining new Enum items. All Enum items 79 * should be defined in the Enum class, as shown above. 80 * </p> 81 * 82 * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a> 83 * @version $Id$ 84 */ 85 public abstract class ValuedEnum 86 extends Enum 87 { 88 /** 89 * The value contained in enum. 90 */ 91 private final int m_value; 92 93 /** 94 * Constructor for enum item. 95 * 96 * <p> 97 * <em>Note:</em> access changed from <code>public</code> to 98 * <code>protected</code> after 4.0. See class description. 99 * </p> 100 * 101 * 102 * @param name the name of enum item. 103 * @param value the value of enum item. 104 */ 105 protected ValuedEnum( final String name, final int value ) 106 { 107 this( name, value, null ); 108 } 109 110 /** 111 * Constructor for enum item so that it gets added to Map at creation. 112 * Adding to a map is useful for implementing find...() style methods. 113 * 114 * </p> 115 * <em>Note:</em> access changed from <code>public</code> to 116 * <code>protected</code> after 4.0. See class description. 117 * </p> 118 * 119 * @param name the name of enum item. 120 * @param value the value of enum item. 121 * @param map the <code>Map</code> to add enum item to. 122 */ 123 protected ValuedEnum( final String name, final int value, final Map map ) 124 { 125 super( name, map ); 126 m_value = value; 127 } 128 129 /** 130 * Get value of enum item. 131 * 132 * @return the enum item's value. 133 */ 134 public final int getValue() 135 { 136 return m_value; 137 } 138 139 /** 140 * Test if enum item is equal in value to other enum. 141 * 142 * @param other the other enum 143 * @return true if equal 144 */ 145 public final boolean isEqualTo( final ValuedEnum other ) 146 { 147 return m_value == other.m_value; 148 } 149 150 /** 151 * Test if enum item is greater than in value to other enum. 152 * 153 * @param other the other enum 154 * @return true if greater than 155 */ 156 public final boolean isGreaterThan( final ValuedEnum other ) 157 { 158 return m_value > other.m_value; 159 } 160 161 /** 162 * Test if enum item is greater than or equal in value to other enum. 163 * 164 * @param other the other enum 165 * @return true if greater than or equal 166 */ 167 public final boolean isGreaterThanOrEqual( final ValuedEnum other ) 168 { 169 return m_value >= other.m_value; 170 } 171 172 /** 173 * Test if enum item is less than in value to other enum. 174 * 175 * @param other the other enum 176 * @return true if less than 177 */ 178 public final boolean isLessThan( final ValuedEnum other ) 179 { 180 return m_value < other.m_value; 181 } 182 183 /** 184 * Test if enum item is less than or equal in value to other enum. 185 * 186 * @param other the other enum 187 * @return true if less than or equal 188 */ 189 public final boolean isLessThanOrEqual( final ValuedEnum other ) 190 { 191 return m_value <= other.m_value; 192 } 193 194 /** 195 * Tests for equality. Two Enum:s are considered equal 196 * if they are of the same class, have the same name, and same value. 197 * 198 * @param o the other object 199 * @return the equality status 200 */ 201 public boolean equals( Object o ) 202 { 203 boolean prelim = super.equals( o ); 204 if( ! prelim ) 205 return false; 206 207 if( !(o instanceof ValuedEnum) ) 208 return false; 209 210 final ValuedEnum enumerated = (ValuedEnum) o; 211 return m_value == enumerated.m_value; 212 } 213 214 public int hashCode() 215 { 216 int hash = super.hashCode(); 217 hash ^= m_value; 218 hash >>>= (m_value & 31 ); 219 return hash; 220 } 221 222 223 /** 224 * Override toString method to produce human readable description. 225 * 226 * @return String in the form <code>type[name=value]</code>, eg.: 227 * <code>JavaVersion[Java 1.0=100]</code>. 228 */ 229 public String toString() 230 { 231 return getClass().getName() + "[" + getName() + "=" + m_value + "]"; 232 } 233 } 234
Note: See TracBrowser
for help on using the repository browser.
