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;
* 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.
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;
+ }
+ }
+
}
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;
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);
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 {
//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);
}
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');
+ }
}
}