git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1495898 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_0
@@ -26,6 +26,8 @@ import java.io.InputStream; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import org.apache.fop.complexscripts.fonts.Positionable; | |||
import org.apache.fop.complexscripts.fonts.Substitutable; | |||
import org.apache.fop.fonts.CustomFont; | |||
import org.apache.fop.fonts.FontType; | |||
import org.apache.fop.fonts.LazyFont; | |||
@@ -37,7 +39,8 @@ import org.apache.fop.fonts.Typeface; | |||
* the underlying {@link Font} to be loaded from a | |||
* user-configured file not registered in the current graphics environment. | |||
*/ | |||
public class CustomFontMetricsMapper extends Typeface implements FontMetricsMapper { | |||
public class CustomFontMetricsMapper extends Typeface implements FontMetricsMapper, Substitutable, | |||
Positionable { | |||
/** | |||
* Font metrics for the font this class models. | |||
@@ -190,4 +193,70 @@ public class CustomFontMetricsMapper extends Typeface implements FontMetricsMapp | |||
return typeface.hasKerningInfo(); | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public boolean performsPositioning() { | |||
if (typeface instanceof Positionable) { | |||
return ((Positionable) typeface).performsPositioning(); | |||
} else { | |||
return false; | |||
} | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public int[][] performPositioning(CharSequence cs, String script, String language, int fontSize) { | |||
if (typeface instanceof Positionable) { | |||
return ((Positionable) typeface).performPositioning(cs, script, language, fontSize); | |||
} else { | |||
return null; | |||
} | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public int[][] performPositioning(CharSequence cs, String script, String language) { | |||
if (typeface instanceof Positionable) { | |||
return ((Positionable) typeface).performPositioning(cs, script, language); | |||
} else { | |||
return null; | |||
} | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public boolean performsSubstitution() { | |||
if (typeface instanceof Substitutable) { | |||
return ((Substitutable) typeface).performsSubstitution(); | |||
} else { | |||
return false; | |||
} | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public CharSequence performSubstitution(CharSequence cs, String script, String language) { | |||
if (typeface instanceof Substitutable) { | |||
return ((Substitutable) typeface).performSubstitution(cs, script, language); | |||
} else { | |||
return cs; | |||
} | |||
} | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public CharSequence reorderCombiningMarks(CharSequence cs, int[][] gpa, String script, String language) { | |||
if (typeface instanceof Substitutable) { | |||
return ((Substitutable) typeface).reorderCombiningMarks(cs, gpa, script, language); | |||
} else { | |||
return cs; | |||
} | |||
} | |||
} |
@@ -43,7 +43,6 @@ import org.apache.fop.render.intermediate.GraphicsPainter; | |||
import org.apache.fop.render.intermediate.IFContext; | |||
import org.apache.fop.render.intermediate.IFException; | |||
import org.apache.fop.render.intermediate.IFState; | |||
import org.apache.fop.render.intermediate.IFUtil; | |||
import org.apache.fop.traits.BorderProps; | |||
import org.apache.fop.traits.RuleStyle; | |||
import org.apache.fop.util.CharUtilities; | |||
@@ -234,27 +233,31 @@ public class Java2DPainter extends AbstractIFPainter<Java2DDocumentHandler> { | |||
Point2D cursor = new Point2D.Float(0, 0); | |||
int l = text.length(); | |||
int[] dx = IFUtil.convertDPToDX(dp); | |||
int dxl = (dx != null ? dx.length : 0); | |||
if (dx != null && dxl > 0 && dx[0] != 0) { | |||
cursor.setLocation(cursor.getX() - (dx[0] / 10f), cursor.getY()); | |||
if (dp != null && dp[0] != null && (dp[0][0] != 0 || dp[0][1] != 0)) { | |||
cursor.setLocation(cursor.getX() + dp[0][0], cursor.getY() - dp[0][1]); | |||
gv.setGlyphPosition(0, cursor); | |||
} | |||
for (int i = 0; i < l; i++) { | |||
char orgChar = text.charAt(i); | |||
float glyphAdjust = 0; | |||
float xGlyphAdjust = 0; | |||
float yGlyphAdjust = 0; | |||
int cw = font.getCharWidth(orgChar); | |||
if ((wordSpacing != 0) && CharUtilities.isAdjustableSpace(orgChar)) { | |||
glyphAdjust += wordSpacing; | |||
xGlyphAdjust += wordSpacing; | |||
} | |||
glyphAdjust += letterSpacing; | |||
if (dx != null && i < dxl - 1) { | |||
glyphAdjust += dx[i + 1]; | |||
xGlyphAdjust += letterSpacing; | |||
if (dp != null && i < dp.length && dp[i] != null) { | |||
xGlyphAdjust += dp[i][2] - dp[i][0]; | |||
yGlyphAdjust += dp[i][3] - dp[i][1]; | |||
} | |||
if (dp != null && i < dp.length - 1 && dp[i + 1] != null) { | |||
xGlyphAdjust += dp[i + 1][0]; | |||
yGlyphAdjust += dp[i + 1][1]; | |||
} | |||
cursor.setLocation(cursor.getX() + cw + glyphAdjust, cursor.getY()); | |||
cursor.setLocation(cursor.getX() + cw + xGlyphAdjust, cursor.getY() - yGlyphAdjust); | |||
gv.setGlyphPosition(i + 1, cursor); | |||
} | |||
g2d.drawGlyphVector(gv, x, y); |
@@ -346,17 +346,27 @@ public class PCLPainter extends AbstractIFPainter<PCLDocumentHandler> implements | |||
float fontSize = state.getFontSize() / 1000f; | |||
Font font = getFontInfo().getFontInstance(triplet, state.getFontSize()); | |||
int l = text.length(); | |||
int[] dx = IFUtil.convertDPToDX(dp); | |||
int dxl = (dx != null ? dx.length : 0); | |||
StringBuffer sb = new StringBuffer(Math.max(16, l)); | |||
if (dx != null && dxl > 0 && dx[0] != 0) { | |||
sb.append("\u001B&a+").append(gen.formatDouble2(dx[0] / 100.0)).append('H'); | |||
if (dp != null && dp[0] != null && dp[0][0] != 0) { | |||
if (dp[0][0] > 0) { | |||
sb.append("\u001B&a+").append(gen.formatDouble2(dp[0][0] / 100.0)).append('H'); | |||
} else { | |||
sb.append("\u001B&a-").append(gen.formatDouble2(-dp[0][0] / 100.0)).append('H'); | |||
} | |||
} | |||
if (dp != null && dp[0] != null && dp[0][1] != 0) { | |||
if (dp[0][1] > 0) { | |||
sb.append("\u001B&a-").append(gen.formatDouble2(dp[0][1] / 100.0)).append('V'); | |||
} else { | |||
sb.append("\u001B&a+").append(gen.formatDouble2(-dp[0][1] / 100.0)).append('V'); | |||
} | |||
} | |||
for (int i = 0; i < l; i++) { | |||
char orgChar = text.charAt(i); | |||
char ch; | |||
float glyphAdjust = 0; | |||
float xGlyphAdjust = 0; | |||
float yGlyphAdjust = 0; | |||
if (font.hasChar(orgChar)) { | |||
ch = font.mapChar(orgChar); | |||
} else { | |||
@@ -364,7 +374,7 @@ public class PCLPainter extends AbstractIFPainter<PCLDocumentHandler> implements | |||
//Fixed width space are rendered as spaces so copy/paste works in a reader | |||
ch = font.mapChar(CharUtilities.SPACE); | |||
int spaceDiff = font.getCharWidth(ch) - font.getCharWidth(orgChar); | |||
glyphAdjust = -(10 * spaceDiff / fontSize); | |||
xGlyphAdjust = -(10 * spaceDiff / fontSize); | |||
} else { | |||
ch = font.mapChar(orgChar); | |||
} | |||
@@ -372,15 +382,31 @@ public class PCLPainter extends AbstractIFPainter<PCLDocumentHandler> implements | |||
sb.append(ch); | |||
if ((wordSpacing != 0) && CharUtilities.isAdjustableSpace(orgChar)) { | |||
glyphAdjust += wordSpacing; | |||
xGlyphAdjust += wordSpacing; | |||
} | |||
glyphAdjust += letterSpacing; | |||
if (dx != null && i < dxl - 1) { | |||
glyphAdjust += dx[i + 1]; | |||
xGlyphAdjust += letterSpacing; | |||
if (dp != null && i < dp.length && dp[i] != null) { | |||
xGlyphAdjust += dp[i][2] - dp[i][0]; | |||
yGlyphAdjust += dp[i][3] - dp[i][1]; | |||
} | |||
if (dp != null && i < dp.length - 1 && dp[i + 1] != null) { | |||
xGlyphAdjust += dp[i + 1][0]; | |||
yGlyphAdjust += dp[i + 1][1]; | |||
} | |||
if (glyphAdjust != 0) { | |||
sb.append("\u001B&a+").append(gen.formatDouble2(glyphAdjust / 100.0)).append('H'); | |||
if (xGlyphAdjust != 0) { | |||
if (xGlyphAdjust > 0) { | |||
sb.append("\u001B&a+").append(gen.formatDouble2(xGlyphAdjust / 100.0)).append('H'); | |||
} else { | |||
sb.append("\u001B&a-").append(gen.formatDouble2(-xGlyphAdjust / 100.0)).append('H'); | |||
} | |||
} | |||
if (yGlyphAdjust != 0) { | |||
if (yGlyphAdjust > 0) { | |||
sb.append("\u001B&a-").append(gen.formatDouble2(yGlyphAdjust / 100.0)).append('V'); | |||
} else { | |||
sb.append("\u001B&a+").append(gen.formatDouble2(-yGlyphAdjust / 100.0)).append('V'); | |||
} | |||
} | |||
} |