[FOray-commit] SF.net SVN: foray:[13080] trunk/foray/foray-font/src/main/java/org/foray/ font
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2023-01-22 22:21:23
|
Revision: 13080
http://sourceforge.net/p/foray/code/13080
Author: victormote
Date: 2023-01-22 22:21:20 +0000 (Sun, 22 Jan 2023)
Log Message:
-----------
Clean up parsing/computation of units-per-em.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java
trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1Metrics.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserPfm.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java 2023-01-22 17:28:41 UTC (rev 13079)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java 2023-01-22 22:21:20 UTC (rev 13080)
@@ -224,12 +224,11 @@
final int metricIndex1 = this.metricIndex(codePoint1);
final int metricIndex2 = this.metricIndex(codePoint2);
final int rawKerning = getKerning().kern(metricIndex1, metricIndex2);
- if (TypographicConstants.MILLIPOINTS_PER_POINT == this.getUnitsPerTextSpaceUnit()) {
+ if (TypographicConstants.MILLIPOINTS_PER_POINT == this.getUnitsPerEm()) {
/* Avoid the potential loss of precision. */
return rawKerning;
}
- return Math.round(rawKerning * TypographicConstants.MILLIPOINTS_PER_POINT
- / this.getUnitsPerTextSpaceUnit());
+ return Math.round(rawKerning * TypographicConstants.MILLIPOINTS_PER_POINT / getUnitsPerEm());
}
@@ -442,13 +441,12 @@
}
/**
- * Returns the units per text-space unit that is used in this font for internal font
- * measurements.
- * For PostScript Type 1 fonts, this is 1000.
+ * Returns the number of units per em that is used in this font for internal font measurements.
+ * For PostScript Type 1 fonts, this is usually 1000.
* For TrueType fonts, it is usually 2048, but can be specified in the font itself.
* @return The units per text-space unit used by this font.
*/
- public abstract int getUnitsPerTextSpaceUnit();
+ public abstract int getUnitsPerEm();
/**
* Indicates whether this font has the ability to map Unicode characters to font glyphs.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2023-01-22 17:28:41 UTC (rev 13079)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2023-01-22 22:21:20 UTC (rev 13080)
@@ -242,9 +242,8 @@
}
@Override
- public int getUnitsPerTextSpaceUnit() {
- /* TODO: Add logic to get the actual value out of the font. */
- return FsTrueTypeFont.DEFAULT_UNITS_PER_TEXT_SPACE;
+ public int getUnitsPerEm() {
+ return this.ttf.getHeadTable().unitsPerEm();
}
@Override
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java 2023-01-22 17:28:41 UTC (rev 13079)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java 2023-01-22 22:21:20 UTC (rev 13080)
@@ -398,9 +398,8 @@
}
@Override
- public int getUnitsPerTextSpaceUnit() {
- /* Type 1 fonts always use 1000 units per text-space unit. */
- return TypographicConstants.MILLIPOINTS_PER_POINT;
+ public int getUnitsPerEm() {
+ return this.metricsFile.getMasterUnits();
}
@Override
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java 2023-01-22 17:28:41 UTC (rev 13079)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java 2023-01-22 22:21:20 UTC (rev 13080)
@@ -543,13 +543,13 @@
}
@Override
- public int getUnitsPerTextSpaceUnit() {
+ public int getUnitsPerEm() {
final FreeStandingFont relatedFSFont = this.freeStandingFontManifestation();
if (relatedFSFont == null) {
/* SystemFont is usually created from a TrueType font, so use its default. */
return FsTrueTypeFont.DEFAULT_UNITS_PER_TEXT_SPACE;
}
- return relatedFSFont.getUnitsPerTextSpaceUnit();
+ return relatedFSFont.getUnitsPerEm();
}
@Override
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1Metrics.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1Metrics.java 2023-01-22 17:28:41 UTC (rev 13079)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1Metrics.java 2023-01-22 22:21:20 UTC (rev 13080)
@@ -33,6 +33,7 @@
import org.foray.font.output.FontPdfUtilities;
import org.foray.primitive.BitUtils;
+import org.axsl.constants.TypographicConstants;
import org.axsl.primitive.sequence.ShortSequence;
import org.axsl.ps.BoundingBox;
import org.axsl.ps.CharSet;
@@ -137,6 +138,10 @@
/** The parsed bounding box. */
private BoundingBox fontBBox = BoundingBoxUtils.ZEROES;
+ /** The parsed master units (units per em) value for this font. This is only used for PFM metrics files, because
+ * AFM files are always a constant. */
+ private int etmMasterUnits;
+
/** The parsed cap height. */
private int etmCapHeight;
@@ -291,6 +296,28 @@
}
/**
+ * Sets the master units (unts per em).
+ * @param masterUnits The master units to set.
+ */
+ public void setMasterUnits(final int masterUnits) {
+ this.etmMasterUnits = masterUnits;
+ }
+
+ /**
+ * Returns the master units (units per em).
+ * @return The master units value.
+ */
+ public int getMasterUnits() {
+ if (this.format == Format.AFM) {
+ /* See "Adobe Font Metrics File Format Specification," Section 3.2 "Units of Measurement," which states "All
+ * measurements in AFM, AMFM, and ACFM files are given in terms of units equal to 1/1000 of the scale factor
+ * (point size) of the font being used." */
+ return TypographicConstants.MILLIPOINTS_PER_POINT;
+ }
+ return this.etmMasterUnits;
+ }
+
+ /**
* Sets the cap height.
* @param capHeight The capHeight to set.
*/
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserPfm.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserPfm.java 2023-01-22 17:28:41 UTC (rev 13079)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserPfm.java 2023-01-22 22:21:20 UTC (rev 13080)
@@ -296,8 +296,11 @@
this.input.skipBytes(PrimitiveConstants.BYTES_PER_SHORT);
/* Skip the etmMaxScale field. */
this.input.skipBytes(PrimitiveConstants.BYTES_PER_SHORT);
- /* Skip the etmMasterUnits field. */
- this.input.skipBytes(PrimitiveConstants.BYTES_PER_SHORT);
+
+ /* Adobe Technical Note #5178 "Building PFM Files for PostScript-Language CJK Fonts," Section 5, indicates that
+ * the master units value is always 1000. Some other sources seem to indicate that this is "usually" true. We
+ * read it anyway to be sure. */
+ this.metrics.setMasterUnits(this.input.readShortLoHi());
this.metrics.setCapHeight(this.input.readUnsignedShortLoHi());
this.metrics.setXHeight(this.input.readUnsignedShortLoHi());
this.metrics.setLowerCaseAscent(this.input.readUnsignedShortLoHi());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|