aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2012-05-30 13:32:35 +0000
committerVincent Hennebert <vhennebert@apache.org>2012-05-30 13:32:35 +0000
commita5c4a9c5d50b8766015e74046be3baeb34916205 (patch)
treef4f85886e1a54bb64f2df8e93ead9dac0f924045 /src/java/org/apache
parent28397e02f096c91109b9d5f71a69e01becef5a60 (diff)
downloadxmlgraphics-fop-a5c4a9c5d50b8766015e74046be3baeb34916205.tar.gz
xmlgraphics-fop-a5c4a9c5d50b8766015e74046be3baeb34916205.zip
Renamed BFEntry into CMapSegment
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript@1344251 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/fonts/CMapSegment.java (renamed from src/java/org/apache/fop/fonts/BFEntry.java)25
-rw-r--r--src/java/org/apache/fop/fonts/CustomFont.java10
-rw-r--r--src/java/org/apache/fop/fonts/FontReader.java8
-rw-r--r--src/java/org/apache/fop/fonts/MultiByteFont.java26
-rw-r--r--src/java/org/apache/fop/fonts/apps/TTFReader.java4
-rw-r--r--src/java/org/apache/fop/fonts/truetype/TTFFile.java17
-rw-r--r--src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java14
-rw-r--r--src/java/org/apache/fop/render/ps/PSFontUtils.java28
8 files changed, 64 insertions, 68 deletions
diff --git a/src/java/org/apache/fop/fonts/BFEntry.java b/src/java/org/apache/fop/fonts/CMapSegment.java
index 0841f36c8..816df2ca0 100644
--- a/src/java/org/apache/fop/fonts/BFEntry.java
+++ b/src/java/org/apache/fop/fonts/CMapSegment.java
@@ -20,31 +20,29 @@
package org.apache.fop.fonts;
/**
- * This is just a holder class for bfentries, groups of characters of a base font (bf).
+ * A segment in a cmap table of format 4. Unicode code points between
+ * {@link #getUnicodeStart()} and {@link #getUnicodeEnd()} map to contiguous glyph indices
+ * starting from {@link #getGlyphStartIndex()}.
*/
-public final class BFEntry {
-
- //TODO Think about renaming this class to CMapRange or something.
+public final class CMapSegment {
private final int unicodeStart;
private final int unicodeEnd;
private final int glyphStartIndex;
/**
- * Main constructor.
+ * Creates a new segment.
+ *
* @param unicodeStart Unicode start index
* @param unicodeEnd Unicode end index
* @param glyphStartIndex glyph start index
*/
- public BFEntry(int unicodeStart, int unicodeEnd, int glyphStartIndex) {
+ public CMapSegment(int unicodeStart, int unicodeEnd, int glyphStartIndex) {
this.unicodeStart = unicodeStart;
this.unicodeEnd = unicodeEnd;
this.glyphStartIndex = glyphStartIndex;
}
- /**
- * {@inheritDoc}
- */
@Override
public int hashCode() {
int hc = 17;
@@ -54,13 +52,10 @@ public final class BFEntry {
return hc;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object o) {
- if (o instanceof BFEntry) {
- BFEntry ce = (BFEntry) o;
+ if (o instanceof CMapSegment) {
+ CMapSegment ce = (CMapSegment) o;
return ce.unicodeStart == this.unicodeStart
&& ce.unicodeEnd == this.unicodeEnd
&& ce.glyphStartIndex == this.glyphStartIndex;
@@ -95,7 +90,7 @@ public final class BFEntry {
/** {@inheritDoc} */
@Override
public String toString() {
- StringBuilder sb = new StringBuilder("BFEntry: ");
+ StringBuilder sb = new StringBuilder("CMapSegment: ");
sb.append ( "{ UC[" );
sb.append ( unicodeStart );
sb.append ( ',' );
diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java
index 7386b7341..b506393a6 100644
--- a/src/java/org/apache/fop/fonts/CustomFont.java
+++ b/src/java/org/apache/fop/fonts/CustomFont.java
@@ -64,7 +64,7 @@ public abstract class CustomFont extends Typeface
private boolean useAdvanced = true;
/** the character map, mapping Unicode ranges to glyph indices. */
- protected BFEntry[] cmap;
+ protected CMapSegment[] cmap;
/** {@inheritDoc} */
public String getFontName() {
@@ -497,8 +497,8 @@ public abstract class CustomFont extends Typeface
* to their glyph indices inside the font.
* @param cmap the identity character map
*/
- public void setCMap(BFEntry[] cmap) {
- this.cmap = new BFEntry[cmap.length];
+ public void setCMap(CMapSegment[] cmap) {
+ this.cmap = new CMapSegment[cmap.length];
System.arraycopy(cmap, 0, this.cmap, 0, cmap.length);
}
@@ -507,8 +507,8 @@ public abstract class CustomFont extends Typeface
* to their glyph indices inside the font.
* @return the identity character map
*/
- public BFEntry[] getCMap() {
- BFEntry[] copy = new BFEntry[cmap.length];
+ public CMapSegment[] getCMap() {
+ CMapSegment[] copy = new CMapSegment[cmap.length];
System.arraycopy(this.cmap, 0, copy, 0, this.cmap.length);
return copy;
}
diff --git a/src/java/org/apache/fop/fonts/FontReader.java b/src/java/org/apache/fop/fonts/FontReader.java
index 381eec7f4..46ea9123d 100644
--- a/src/java/org/apache/fop/fonts/FontReader.java
+++ b/src/java/org/apache/fop/fonts/FontReader.java
@@ -64,7 +64,7 @@ public class FontReader extends DefaultHandler {
private Map<Integer, Integer> currentKerning = null;
- private List<BFEntry> bfranges = null;
+ private List<CMapSegment> bfranges = null;
private void createFont(InputSource source) throws FOPException {
XMLReader parser = null;
@@ -201,9 +201,9 @@ public class FontReader extends DefaultHandler {
returnFont.putKerningEntry(new Integer(attributes.getValue("kpx1")),
currentKerning);
} else if ("bfranges".equals(localName)) {
- bfranges = new ArrayList<BFEntry>();
+ bfranges = new ArrayList<CMapSegment>();
} else if ("bf".equals(localName)) {
- BFEntry entry = new BFEntry(getInt(attributes.getValue("us")),
+ CMapSegment entry = new CMapSegment(getInt(attributes.getValue("us")),
getInt(attributes.getValue("ue")),
getInt(attributes.getValue("gi")));
bfranges.add(entry);
@@ -307,7 +307,7 @@ public class FontReader extends DefaultHandler {
multiFont.setWidthArray(wds);
} else if ("bfranges".equals(localName)) {
- multiFont.setCMap(bfranges.toArray(new BFEntry[0]));
+ multiFont.setCMap(bfranges.toArray(new CMapSegment[0]));
}
text.setLength(0); //Reset text buffer (see characters())
}
diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java
index c249c4d19..4db5ece84 100644
--- a/src/java/org/apache/fop/fonts/MultiByteFont.java
+++ b/src/java/org/apache/fop/fonts/MultiByteFont.java
@@ -183,17 +183,17 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl
}
/**
- * Add a private use mapping {PU,GI} to the existing BFENTRIES map.
+ * Add a private use mapping {PU,GI} to the existing character map.
* N.B. Does not insert in order, merely appends to end of existing map.
*/
private synchronized void addPrivateUseMapping ( int pu, int gi ) {
assert findGlyphIndex ( pu ) == SingleByteEncoding.NOT_FOUND_CODE_POINT;
- BFEntry[] bfeOld = cmap;
- int bfeCnt = bfeOld.length;
- BFEntry[] bfeNew = new BFEntry [ bfeCnt + 1 ];
- System.arraycopy ( bfeOld, 0, bfeNew, 0, bfeCnt );
- bfeNew [ bfeCnt ] = new BFEntry ( pu, pu, gi );
- cmap = bfeNew;
+ CMapSegment[] oldCmap = cmap;
+ int cmapLength = oldCmap.length;
+ CMapSegment[] newCmap = new CMapSegment [ cmapLength + 1 ];
+ System.arraycopy ( oldCmap, 0, newCmap, 0, cmapLength );
+ newCmap [ cmapLength ] = new CMapSegment ( pu, pu, gi );
+ cmap = newCmap;
}
/**
@@ -252,11 +252,11 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl
private int findCharacterFromGlyphIndex ( int gi, boolean augment ) {
int cc = 0;
for ( int i = 0, n = cmap.length; i < n; i++ ) {
- BFEntry be = cmap [ i ];
- int s = be.getGlyphStartIndex();
- int e = s + ( be.getUnicodeEnd() - be.getUnicodeStart() );
+ CMapSegment segment = cmap [ i ];
+ int s = segment.getGlyphStartIndex();
+ int e = s + ( segment.getUnicodeEnd() - segment.getUnicodeStart() );
if ( ( gi >= s ) && ( gi <= e ) ) {
- cc = be.getUnicodeStart() + ( gi - s );
+ cc = segment.getUnicodeStart() + ( gi - s );
break;
}
}
@@ -296,10 +296,10 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl
* Sets the array of BFEntry instances which constitutes the Unicode to glyph index map for
* a font. ("BF" means "base font")
* @param entries the Unicode to glyph index map
- * @deprecated use {@link #setCMap(BFEntry[])} instead
+ * @deprecated use {@link #setCMap(CMapSegment[])} instead
*/
@Deprecated
- public void setBFEntries(BFEntry[] entries) {
+ public void setBFEntries(CMapSegment[] entries) {
setCMap(entries);
}
diff --git a/src/java/org/apache/fop/fonts/apps/TTFReader.java b/src/java/org/apache/fop/fonts/apps/TTFReader.java
index 59a5c47bb..224c8de2f 100644
--- a/src/java/org/apache/fop/fonts/apps/TTFReader.java
+++ b/src/java/org/apache/fop/fonts/apps/TTFReader.java
@@ -33,7 +33,7 @@ import org.xml.sax.SAXException;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.Version;
-import org.apache.fop.fonts.BFEntry;
+import org.apache.fop.fonts.CMapSegment;
import org.apache.fop.fonts.FontUtil;
import org.apache.fop.fonts.truetype.FontFileReader;
import org.apache.fop.fonts.truetype.TTFFile;
@@ -385,7 +385,7 @@ public class TTFReader extends AbstractFontReader {
el = doc.createElement("bfranges");
mel.appendChild(el);
- for (BFEntry ce : ttf.getCMaps()) {
+ for (CMapSegment ce : ttf.getCMaps()) {
Element el2 = doc.createElement("bf");
el.appendChild(el2);
el2.setAttribute("us", String.valueOf(ce.getUnicodeStart()));
diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFile.java b/src/java/org/apache/fop/fonts/truetype/TTFFile.java
index 168b49482..77cdddcdd 100644
--- a/src/java/org/apache/fop/fonts/truetype/TTFFile.java
+++ b/src/java/org/apache/fop/fonts/truetype/TTFFile.java
@@ -43,7 +43,7 @@ import org.apache.fop.complexscripts.fonts.GlyphDefinitionTable;
import org.apache.fop.complexscripts.fonts.GlyphPositioningTable;
import org.apache.fop.complexscripts.fonts.GlyphSubstitutionTable;
import org.apache.fop.complexscripts.fonts.OTFAdvancedTypographicTableReader;
-import org.apache.fop.fonts.BFEntry;
+import org.apache.fop.fonts.CMapSegment;
import org.apache.fop.fonts.FontUtil;
/**
@@ -161,7 +161,7 @@ public class TTFFile {
protected Map<TTFTableName, TTFDirTabEntry> dirTabs;
private Map<Integer, Map<Integer, Integer>> kerningTab; // for CIDs
private Map<Integer, Map<Integer, Integer>> ansiKerningTab; // For winAnsiEncoding
- private List<BFEntry> cmaps;
+ private List<CMapSegment> cmaps;
private Set<UnicodeMapping> unicodeMappings;
private int upem; // unitsPerEm from "head" table
@@ -764,7 +764,7 @@ public class TTFFile {
}
private void createCMaps() {
- cmaps = new ArrayList<BFEntry>();
+ cmaps = new ArrayList<CMapSegment>();
int unicodeStart;
int glyphStart;
int unicodeEnd;
@@ -781,7 +781,7 @@ public class TTFFile {
if (((lastMapping.getUnicodeIndex() + 1) != um.getUnicodeIndex())
|| ((lastMapping.getGlyphIndex() + 1) != um.getGlyphIndex())) {
unicodeEnd = lastMapping.getUnicodeIndex();
- cmaps.add(new BFEntry(unicodeStart, unicodeEnd, glyphStart));
+ cmaps.add(new CMapSegment(unicodeStart, unicodeEnd, glyphStart));
unicodeStart = um.getUnicodeIndex();
glyphStart = um.getGlyphIndex();
}
@@ -789,7 +789,7 @@ public class TTFFile {
}
unicodeEnd = lastMapping.getUnicodeIndex();
- cmaps.add(new BFEntry(unicodeStart, unicodeEnd, glyphStart));
+ cmaps.add(new CMapSegment(unicodeStart, unicodeEnd, glyphStart));
}
/**
@@ -1758,10 +1758,11 @@ public class TTFFile {
}
/**
- * Return a List with TTFCmapEntry.
- * @return A list of TTFCmapEntry objects
+ * Returns this font's character to glyph mapping.
+ *
+ * @return the font's cmap
*/
- public List<BFEntry> getCMaps() {
+ public List<CMapSegment> getCMaps() {
return cmaps;
}
diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
index 9a19f287b..9c6098de2 100644
--- a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
+++ b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
@@ -26,7 +26,7 @@ import java.util.Set;
import org.apache.commons.io.IOUtils;
-import org.apache.fop.fonts.BFEntry;
+import org.apache.fop.fonts.CMapSegment;
import org.apache.fop.fonts.CIDFontType;
import org.apache.fop.fonts.EmbeddingMode;
import org.apache.fop.fonts.EncodingMode;
@@ -181,8 +181,8 @@ public class TTFFontLoader extends FontLoader {
}
}
- private BFEntry[] getCMap(TTFFile ttf) {
- BFEntry[] array = new BFEntry[ttf.getCMaps().size()];
+ private CMapSegment[] getCMap(TTFFile ttf) {
+ CMapSegment[] array = new CMapSegment[ttf.getCMaps().size()];
return ttf.getCMaps().toArray(array);
}
@@ -192,12 +192,12 @@ public class TTFFontLoader extends FontLoader {
singleFont.setWidth(i, ttf.getCharWidth(i));
}
- for (BFEntry ce : ttf.getCMaps()) {
- if (ce.getUnicodeStart() < 0xFFFE) {
- for (char u = (char)ce.getUnicodeStart(); u <= ce.getUnicodeEnd(); u++) {
+ for (CMapSegment segment : ttf.getCMaps()) {
+ if (segment.getUnicodeStart() < 0xFFFE) {
+ for (char u = (char)segment.getUnicodeStart(); u <= segment.getUnicodeEnd(); u++) {
int codePoint = singleFont.getEncoding().mapChar(u);
if (codePoint <= 0) {
- int glyphIndex = ce.getGlyphStartIndex() + u - ce.getUnicodeStart();
+ int glyphIndex = segment.getGlyphStartIndex() + u - segment.getUnicodeStart();
String glyphName = ttf.getGlyphName(glyphIndex);
if (glyphName == "" && ttf.getPostScriptVersion() != PostScriptVersion.V2) {
glyphName = "u" + HexEncoder.encode(u);
diff --git a/src/java/org/apache/fop/render/ps/PSFontUtils.java b/src/java/org/apache/fop/render/ps/PSFontUtils.java
index 157f4f419..53ceff53e 100644
--- a/src/java/org/apache/fop/render/ps/PSFontUtils.java
+++ b/src/java/org/apache/fop/render/ps/PSFontUtils.java
@@ -40,7 +40,7 @@ import org.apache.xmlgraphics.ps.PSGenerator;
import org.apache.xmlgraphics.ps.PSResource;
import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
-import org.apache.fop.fonts.BFEntry;
+import org.apache.fop.fonts.CMapSegment;
import org.apache.fop.fonts.Base14Font;
import org.apache.fop.fonts.CIDFontType;
import org.apache.fop.fonts.CIDSubset;
@@ -314,7 +314,7 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
}
private static void createType42DictionaryEntries(PSGenerator gen, CustomFont font,
- BFEntry[] cmap, TTFFile ttfFile) throws IOException {
+ CMapSegment[] cmap, TTFFile ttfFile) throws IOException {
gen.write("/FontName /");
gen.write(font.getEmbedFontName());
gen.writeln(" def");
@@ -354,14 +354,14 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
}
private static void buildCharStrings(PSGenerator gen, boolean buildCharStrings,
- BFEntry[] cmap, Set<String> glyphNames, CustomFont font) throws IOException {
+ CMapSegment[] cmap, Set<String> glyphNames, CustomFont font) throws IOException {
gen.write("/CharStrings ");
if (!buildCharStrings) {
gen.write(1);
} else if (font.getEmbeddingMode() != EmbeddingMode.FULL) {
int charCount = 1; //1 for .notdef
- for (BFEntry entry : cmap) {
- charCount += entry.getUnicodeEnd() - entry.getUnicodeStart() + 1;
+ for (CMapSegment segment : cmap) {
+ charCount += segment.getUnicodeEnd() - segment.getUnicodeStart() + 1;
}
gen.write(charCount);
} else {
@@ -378,9 +378,9 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
}
if (font.getEmbeddingMode() != EmbeddingMode.FULL) {
//Only performed in singly-byte mode, ignored for CID fonts
- for (BFEntry entry : cmap) {
- int glyphIndex = entry.getGlyphStartIndex();
- for (int ch = entry.getUnicodeStart(); ch <= entry.getUnicodeEnd(); ch++) {
+ for (CMapSegment segment : cmap) {
+ int glyphIndex = segment.getGlyphStartIndex();
+ for (int ch = segment.getUnicodeStart(); ch <= segment.getUnicodeEnd(); ch++) {
char ch16 = (char)ch; //TODO Handle Unicode characters beyond 16bit
String glyphName = Glyphs.charToGlyphName(ch16);
if ("".equals(glyphName)) {
@@ -410,10 +410,10 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
gen.writeln(" def");
}
- private static int getGlyphIndex(char c, BFEntry[] cmap) {
- for (BFEntry entry : cmap) {
- if (entry.getUnicodeStart() <= c && c <= entry.getUnicodeEnd()) {
- return entry.getGlyphStartIndex() + c - entry.getUnicodeStart();
+ private static int getGlyphIndex(char c, CMapSegment[] cmap) {
+ for (CMapSegment segment : cmap) {
+ if (segment.getUnicodeStart() <= c && c <= segment.getUnicodeEnd()) {
+ return segment.getGlyphStartIndex() + c - segment.getUnicodeStart();
}
}
return 0;
@@ -509,7 +509,7 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
}
- createType42DictionaryEntries(gen, font, new BFEntry[0], ttfFile);
+ createType42DictionaryEntries(gen, font, new CMapSegment[0], ttfFile);
gen.writeln("CIDFontName currentdict end /CIDFont defineresource pop");
gen.writeln("end");
gen.writeln("%%EndResource");
@@ -685,7 +685,7 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
private static PSResource defineDerivedTrueTypeFont(PSGenerator gen,
PSEventProducer eventProducer, String baseFontName, String fontName,
- SingleByteEncoding encoding, BFEntry[] cmap) throws IOException {
+ SingleByteEncoding encoding, CMapSegment[] cmap) throws IOException {
checkPostScriptLevel3(gen, eventProducer);
PSResource res = new PSResource(PSResource.TYPE_FONT, fontName);
gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, res);