private int firstChar = 0;
private int lastChar = 255;
- private Map kerning;
+ private Map<Integer, Map<Integer, Integer>> kerning;
private boolean useKerning = true;
+ private boolean useAdvanced = true;
/** {@inheritDoc} */
public String getFontName() {
/**
* Main constructor
- * @param metricsFile Path to the xml file containing font metrics
- * @param kerning True if kerning should be enabled
- * @param fontTriplets List of font triplets to associate with this font
- * @param embedFile Path to the embeddable font file (may be null)
+ * @param metricsFile path to the xml file containing font metrics
+ * @param kerning true if kerning should be enabled
+ * @param advanced true if advanced typography features should be enabled
+ * @param fontTriplets list of font triplets to associate with this font
+ * @param embedFile path to the embeddable font file (may be null)
* @param subFontName the sub-fontname used for TrueType Collections (null otherwise)
*/
- public EmbedFontInfo(String metricsFile, boolean kerning,
+ public EmbedFontInfo(String metricsFile, boolean kerning, boolean advanced,
- List/*<FontTriplet>*/ fontTriplets, String embedFile, String subFontName) {
+ List<FontTriplet> fontTriplets, String embedFile, String subFontName) {
this.metricsFile = metricsFile;
this.embedFile = embedFile;
this.kerning = kerning;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
- import org.apache.fop.fonts.CodePointMapping;
+// CSOFF: LineLengthCheck
+
/**
* This class holds font state information and provides access to the font
* metrics.
/**
* {@inheritDoc}
*/
+ @Override
public String toString() {
- StringBuffer sbuf = new StringBuffer();
- sbuf.append('(');
+ StringBuffer sbuf = new StringBuffer(super.toString());
+ sbuf.append('{');
/*
sbuf.append(fontFamily);
sbuf.append(',');*/
if (log.isDebugEnabled()) {
String embedFile = embedFontInfo.getEmbedFile();
- log.debug("Adding font " + (embedFile != null ? embedFile + ", " : "")
+ log.debug( ( skipCachedFont ? "Skipping (cached) font " : "Adding font " )
+ + (embedFile != null ? embedFile + ", " : "")
+ "metric file " + embedFontInfo.getMetricsFile());
for (int j = 0; j < tripletList.size(); ++j) {
- FontTriplet triplet = (FontTriplet) tripletList.get(j);
+ FontTriplet triplet = tripletList.get(j);
log.debug(" Font triplet "
+ triplet.getName() + ", "
+ triplet.getStyle() + ", "
}
try {
TTFFontLoader ttfLoader = new TTFFontLoader(
- fontFileURI, fontName, true, EncodingMode.AUTO, true, true, resolver);
- fontFileURL, fontName, true, EncodingMode.AUTO, true, resolver);
++ fontFileURL, fontName, true, EncodingMode.AUTO, true, true, resolver);
customFont = ttfLoader.getFont();
if (this.eventListener != null) {
customFont.setEventListener(this.eventListener);
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
-import org.apache.fop.fonts.FontUtil;
import org.apache.xmlgraphics.fonts.Glyphs;
-
+import org.apache.fop.fonts.FontUtil;
+import org.apache.fop.fonts.GlyphClassTable;
+import org.apache.fop.fonts.GlyphCoverageTable;
+import org.apache.fop.fonts.GlyphDefinitionSubtable;
+import org.apache.fop.fonts.GlyphDefinitionTable;
+import org.apache.fop.fonts.GlyphMappingTable;
+import org.apache.fop.fonts.GlyphPositioningSubtable;
+import org.apache.fop.fonts.GlyphPositioningTable;
+import org.apache.fop.fonts.GlyphSubstitutionSubtable;
+import org.apache.fop.fonts.GlyphSubstitutionTable;
+import org.apache.fop.fonts.GlyphSubtable;
+import org.apache.fop.fonts.GlyphTable;
+
+import org.apache.fop.util.CharUtilities;
+
+// CSOFF: AvoidNestedBlocksCheck
+// CSOFF: NoWhitespaceAfterCheck
+// CSOFF: InnerAssignmentCheck
+// CSOFF: SimplifyBooleanReturnCheck
+// CSOFF: LineLengthCheck
+
/**
* Reads a TrueType file or a TrueType Collection.
* The TrueType spec can be found at the Microsoft.
static final int MAX_CHAR_CODE = 255;
static final int ENC_BUF_SIZE = 1024;
- private String encoding = "WinAnsiEncoding"; // Default encoding
- /** Set to true to get even more debug output than with level DEBUG */
- public static final boolean TRACE_ENABLED = false;
-
+ private final String encoding = "WinAnsiEncoding"; // Default encoding
- private short firstChar = 0;
+ private final short firstChar = 0;
private boolean isEmbeddable = true;
private boolean hasSerifs = true;
/**
* Table directory
*/
protected Map dirTabs;
- private Map kerningTab; // for CIDs
- private Map ansiKerningTab; // For winAnsiEncoding
+ private Map<Integer, Map<Integer, Integer>> kerningTab; // for CIDs
+ private Map<Integer, Map<Integer, Integer>> ansiKerningTab; // For winAnsiEncoding
private List cmaps;
- private List unicodeMapping;
+ private Set unicodeMappings;
private int upem; // unitsPerEm from "head" table
private int nhmtx; // Number of horizontal metrics
/**
* Key-value helper class
*/
- class UnicodeMapping {
+ class UnicodeMapping implements Comparable {
- private int unicodeIndex;
- private int glyphIndex;
+ private final int unicodeIndex;
+ private final int glyphIndex;
UnicodeMapping(int glyphIndex, int unicodeIndex) {
this.unicodeIndex = unicodeIndex;
}
/** {@inheritDoc} */
+ @Override
public void initialize() {
+ bidiLevel = fobj.getBidiLevel();
textAlignment = fobj.getTextAlign();
textAlignmentLast = fobj.getTextAlignLast();
textIndent = fobj.getTextIndent();
//TODO: add kern to wordIPD?
}
}
- int iLetterSpaces = wordLength - 1;
+ int letterSpaces = wordLength - 1;
- // if there is a break opportunity and the next one
+ // if there is a break opportunity and the next one (break character)
// is not a space, it could be used as a line end;
// add one more letter space, in case other text follows
- if (breakOpportunity && !TextLayoutManager.isSpace(ch)) {
+ if (( breakOpportunityChar != 0 ) && !TextLayoutManager.isSpace(breakOpportunityChar)) {
- iLetterSpaces++;
+ letterSpaces++;
}
- assert iLetterSpaces >= 0;
- wordIPD = wordIPD.plus(letterSpaceIPD.mult(iLetterSpaces));
+ assert letterSpaces >= 0;
+ wordIPD = wordIPD.plus(letterSpaceIPD.mult(letterSpaces));
- // create the AreaInfo object
- AreaInfo areaInfo = new AreaInfo(thisStart, lastIndex, 0,
- letterSpaces, wordIPD,
- endsWithHyphen,
- false, breakOpportunity, font);
+ // create and return the AreaInfo object
+ return new AreaInfo(thisStart, lastIndex, 0,
- iLetterSpaces, wordIPD,
++ letterSpaces, wordIPD,
+ endsWithHyphen,
+ false, breakOpportunityChar != 0, font, level, null);
+ }
+
+ private AreaInfo processWord(final int alignment, final KnuthSequence sequence,
+ AreaInfo prevAreaInfo, final char ch, final boolean breakOpportunity,
+ final boolean checkEndsWithHyphen, int level) {
+
+ //Word boundary found, process widths and kerning
+ int lastIndex = nextStart;
+ while (lastIndex > 0 && foText.charAt(lastIndex - 1) == CharUtilities.SOFT_HYPHEN) {
+ lastIndex--;
+ }
+ final boolean endsWithHyphen = checkEndsWithHyphen
+ && foText.charAt(lastIndex) == CharUtilities.SOFT_HYPHEN;
+ Font font = FontSelector.selectFontForCharactersInText
+ ( foText, thisStart, lastIndex, foText, this );
+ AreaInfo areaInfo;
+ if ( font.performsSubstitution() ) {
+ areaInfo = processWordMapping
+ ( lastIndex, font, prevAreaInfo, breakOpportunity ? ch : 0, endsWithHyphen, level );
+ } else {
+ areaInfo = processWordNoMapping
+ ( lastIndex, font, prevAreaInfo, breakOpportunity ? ch : 0, endsWithHyphen, level );
+ }
prevAreaInfo = areaInfo;
- areaInfos.add(areaInfo);
+ addAreaInfo(areaInfo);
tempStart = nextStart;
//add the elements
if (!(nothingChanged && stopIndex == areaInfo.breakIndex && !hyphenFollows)) {
// the new AreaInfo object is not equal to the old one
- changeList.add(new PendingChange(new AreaInfo(startIndex, stopIndex, 0,
- letterSpaceCount, newIPD, hyphenFollows, false, false, font),
+ changeList.add
+ ( new PendingChange
+ ( new AreaInfo(startIndex, stopIndex, 0,
+ letterSpaceCount, newIPD, hyphenFollows,
+ false, false, font, -1, null),
- ((LeafPosition) pos).getLeafPos()));
+ ((LeafPosition) pos).getLeafPos() + changeOffset));
nothingChanged = false;
}
startIndex = stopIndex;