-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDF: Bold MathML not rendering #910
Comments
I can't repeat. This XML: <p id="_test">
Bold math test:
<stem type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi>
<mstyle mathvariant="bold">
<mi>b</mi>
</mstyle>
</math><!-- a b -->
<asciimath>a bb(b)</asciimath>
</stem>
</p> @opoudjis could you attach the full xml fragment? |
The mstyle is at the root of the MathML, and is still failing in PDF with mathvariant. Attached. |
In my environment PDF looks so: vs. from Αρχειοθήκη 2.zip: I don't figure out the reason. I'll investigate. |
The document from mn-samples-iso repo | Position vector | stem:[bb(r)]
| Displacement | stem:[bb(Delta r)] <tr><td valign="top" align="left">Position vector</td>
<td valign="top" align="left"><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="bold"><mi>r</mi></mstyle></math><asciimath>bb(r)</asciimath></stem></td>
</tr><tr><td valign="top" align="left">Displacement</td>
<td valign="top" align="left"><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="bold"><mrow><mo>Δ</mo><mi>r</mi></mrow></mstyle></math><asciimath>bb(Delta r)</asciimath></stem></td>
</tr> and math in PDF rendered in bold on Win, Ubuntu and Mac (metanorma/mn-native-pdf#488), Table 10 on the page 53: Ubuntu (https://github.com/metanorma/mn-native-pdf/actions/runs/4073826407): MacOS (https://github.com/metanorma/mn-native-pdf/actions/runs/4073826414): Will investigate further... |
I assume that wrong (old?) Cambria font without Math sub-font is using. @opoudjis could you help make some actions?
<font embed-url="file:/C:/Windows/FONTS/cambria.ttc" kerning="yes" mn_default="false" sub-font="Cambria Math">
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria Math" style="normal" weight="normal"/>
</font>
<font embed-url="file:/C:/Windows/FONTS/cambria.ttc" kerning="yes" mn_default="false" simulate-style="true" sub-font="Cambria Math">
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria Math" style="normal" weight="bold"/>
</font>
Thanks. |
@opoudjis thanks. From
But on the disk there is the font |
I'm trying to generate PDF for a.doc on MacOS and get the error:
Will try to re-install metanorma. |
|
Issue with New error occurs:
|
... replicated error. Aha. Please use Ruby 3.1.3 until we've worked this out. |
@opoudjis thank you, it's working. I've repeated the wrong PDF rendering with non-bold math on MacOS. I've installed these fonts
Fontist manifest looks correctly: ---
Cambria:
Bold:
full_name: Cambria Bold
paths:
- "/Library/Fonts/Cambria Bold.ttf"
Regular:
full_name: Cambria
paths:
- "/Library/Fonts/Cambria.ttf"
Cambria Math:
Regular:
full_name: Cambria Math
paths:
- "/Library/Fonts/Cambria Math.ttf"
... In the FOP font config (parsed from fontist manifest): <fonts>
<font embed-url="file:/Library/Fonts/Cambria.ttf" kerning="yes" mn_default="false" sub-font="Cambria">
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria" style="normal" weight="normal"/>
</font>
<font embed-url="file:/Library/Fonts/Cambria%20Math.ttf" kerning="yes" mn_default="false" sub-font="Cambria Math">
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria Math" style="normal" weight="normal"/>
</font>
<font embed-url="file:/Library/Fonts/Cambria.ttf" kerning="yes" mn_default="false">
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria Math" style="normal" weight="bold"/>
</font>
<font embed-url="file:/Library/Fonts/Cambria%20Bold.ttf" kerning="yes" mn_default="false">
<alternate embed-url="Cambria Bold.ttf"/>
<font-triplet name="Cambria" style="normal" weight="bold"/>
</font> there are a few wrong items:
There is a differences between my FOP font config (left panel) and provided by @opoudjis (right panel):
I don't figure out why At this moment I see two issues:
@opoudjis to make sure that fontist manifest is correctly, could you make some actions. please? In the log, before the line
Please attach this The process ends with error due missing mn2pdf.jar, so ignore it. I need just fontist manifest yml. Thanks. |
I'll make one more attempts to fix this issue... |
I've spent a day, but didn't find the reason yet... |
OK, I've already completely forgotten where this came from, and I don't want to add a never ending ticket to your workload, so... Is this a font issue, specific to Cambria Math Bold? Is there something I can do in markup to push it along? I'm confused that you are getting boldface and I'm not; this looks like something that can be gotten around, but it also sounds like it needs explicit invocation of the distinct Cambria Bold. Does this issue generalise to other bold math fonts? I know we've had problems with boldface maths in the past—incomplete coverage of maths symbols in fonts. |
@opoudjis I assume that the reason in jEuclid. |
For further investigation, example XML: <clause id="id1" displayorder="1">
<title depth="1">1<tab/>Math bold test</title>
<p>Cambria math: <font font-family="Cambria Math">[a,b], <strong>[a,b]</strong>
</font>
<stem type="MathML" font-family="Cambria Math">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle mathvariant="bold">
<mfenced open="[" close="]">
<mrow>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
</mrow>
</mfenced>
</mstyle>
</math>
<!-- [a , b] -->
<asciimath>[a,b]</asciimath>
</stem>
</p>
<p>STIX Two Math: <font font-family="STIX Two Math">[a,b], <strong>[a,b]</strong>
</font>
<stem type="MathML" font-family="STIX Two Math">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle mathvariant="bold">
<mfenced open="[" close="]">
<mrow>
<mi>a</mi>
<mo>,</mo>
<mi>b</mi>
</mrow>
</mfenced>
</mstyle>
</math>
<!-- [a , b] -->
<asciimath>[a,b]</asciimath>
</stem>
</p>
</clause> XSLT updated for new tags (for testing only): <xsl:template match="*[local-name() = 'font']">
<fo:inline font-family="{@font-family}"><xsl:apply-templates /></fo:inline>
</xsl:template>
<xsl:template match="mathml:math">
...
<fo:inline xsl:use-attribute-sets="mathml-style">
<xsl:copy-of select="ancestor::*[local-name() = 'stem']/@font-family"/>
... Fontist manifest fragment (Cambria fonts from Mac machine specially for testing): ---
Cambria:
Regular:
full_name: Cambria
paths:
-"D:/Work/Metanorma/Mac_fonts/Cambria.ttf"
Bold:
full_name: Cambria Bold
paths:
- "D:/Work/Metanorma/Mac_fonts/Cambria Bold.ttf"
...
Cambria Math:
Regular:
full_name: Cambria Math
paths:
- "D:/Work/Metanorma/Mac_fonts/Cambria Math.ttf"
STIX Two Math:
Regular:
full_name: STIX Two Math Regular
paths:
- C:/Users/TestUser/.fontist/fonts/STIXTwoMath-Regular.otf Note: first I'll try on Mac tomorrow, something wrong with VirtualBox. |
jEuclid renders bold in STIX Two Math, but doesn't in Cambria Math. Very uncertain result... Further actions:
|
The same result - no bold. |
It's the Java issue.
JLabel label1 = new JLabel("Cambria Math: [a, b]");
label1.setBounds(50, 50, 400, 30);
label1.setFont(new Font("Cambria Math", Font.PLAIN, 30));
JLabel label2 = new JLabel("Cambria Math: [a, b]");
label2.setBounds(50, 100, 400, 30);
label2.setFont(new Font("Cambria Math", Font.BOLD, 30));
JLabel label3 = new JLabel("STIX Two Math: [a, b]");
label3.setBounds(50, 150, 400, 30);
label3.setFont(new Font("STIX Two Math", Font.PLAIN, 30));
JLabel label4 = new JLabel("STIX Two Math: [a, b]");
label4.setBounds(50, 200, 400, 30);
label4.setFont(new Font("STIX Two Math", Font.BOLD, 30)); On Mac - no differences between 1st and 2nd lines: And I don't figure out why |
There are the similar issue on the openjdk bug tracker:
|
Previously, I've installed the font Note: now, 'normal' renders as normal font, not 'bold' as in #910 (comment) I'll test the PDF rendering and will think about one more workaround solution, specially for MacOs. |
Current FOP config: <fonts>
<font embed-url="file:/var/folders/vn/4jyz_ysn61lbh37__jrqsx1c0000gn/T/3e1e15c6-5e2b-40e8-93eb-48996f722bfc/Cambria.ttf" kerning="yes" mn_default="false">
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria" style="normal" weight="normal"/>
</font>
<font embed-url="file:/var/folders/vn/4jyz_ysn61lbh37__jrqsx1c0000gn/T/3e1e15c6-5e2b-40e8-93eb-48996f722bfc/Cambria%20Math.ttf" kerning="yes" mn_default="false">
<alternate embed-url="Cambria Math.ttf"/>
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria Math" style="normal" weight="normal"/>
</font>
<font embed-url="file:/Library/Fonts/Cambria Math.ttf" kerning="yes" mn_default="false" simulate-style="true">
<alternate embed-url="Cambria Math.ttf" simulate-style="true"/>
<alternate embed-url="cambria.ttf" simulate-style="true"/>
<font-triplet name="Cambria Math" style="normal" weight="bold"/>
</font>
<font embed-url="file:/var/folders/vn/4jyz_ysn61lbh37__jrqsx1c0000gn/T/3e1e15c6-5e2b-40e8-93eb-48996f722bfc/Cambria%20Bold.ttf" kerning="yes" mn_default="false">
<alternate embed-url="Cambria Bold.ttf"/>
<font-triplet name="Cambria" style="normal" weight="bold"/>
</font> There is |
@Intelligent2013 is there something that Fontist can do here? I don't like the idea of mn2pdf moving fonts around. |
For FOP font config: <fonts>
<font embed-url="file:/var/folders/vn/4jyz_ysn61lbh37__jrqsx1c0000gn/T/8a88be7d-05a5-4ed7-9b34-f9184598daef/Cambria.ttf" kerning="yes" mn_default="false">
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria" style="normal" weight="normal"/>
</font>
<font embed-url="file:/var/folders/vn/4jyz_ysn61lbh37__jrqsx1c0000gn/T/8a88be7d-05a5-4ed7-9b34-f9184598daef/Cambria%20Math.ttf" kerning="yes" mn_default="false">
<alternate embed-url="Cambria Math.ttf"/>
<alternate embed-url="cambria.ttf"/>
<font-triplet name="Cambria Math" style="normal" weight="normal"/>
</font>
<font embed-url="file:/var/folders/vn/4jyz_ysn61lbh37__jrqsx1c0000gn/T/8a88be7d-05a5-4ed7-9b34-f9184598daef/Cambria%20Math.ttf" kerning="yes" mn_default="false" simulate-style="true">
<alternate embed-url="Cambria Math.ttf" simulate-style="true"/>
<alternate embed-url="cambria.ttf" simulate-style="true"/>
<font-triplet name="Cambria Math" style="normal" weight="bold"/>
</font>
<font embed-url="file:/var/folders/vn/4jyz_ysn61lbh37__jrqsx1c0000gn/T/8a88be7d-05a5-4ed7-9b34-f9184598daef/Cambria%20Bold.ttf" kerning="yes" mn_default="false">
<alternate embed-url="Cambria Bold.ttf"/>
<font-triplet name="Cambria" style="normal" weight="bold"/>
</font> Looks like JEuclid uses the system information about registered fonts, and therefore uses the font from |
@ronaldtse we need to isolate system fonts from Java somehow, but I don't know how yet. |
I've asked about this issue here https://stackoverflow.com/questions/76185073/java-how-to-render-system-font-in-bold-on-macos. |
Actually, the right class is @Override
public String getFontName(Locale locale) {
if (locale == null) {
return fullName;
} else if (locale.equals(nameLocale) && localeFullName != null) {
return localeFullName;
} else {
short localeID = getLCIDFromLocale(locale);
String name = lookupName(localeID, FULL_NAME_ID);
if (name == null) {
return fullName;
} else {
return name;
}
}
} The font's name depends on locale and stores very deep into the byte array: public static final int nameTag = 0x6E616D65; // 'name'
...
/* Return the requested name in the requested locale, for the
* MS platform ID. If the requested locale isn't found, return US
* English, if that isn't found, return null and let the caller
* figure out how to handle that.
*/
protected String lookupName(short findLocaleID, int findNameID) {
String foundName = null;
byte[] name = new byte[1024];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i=0; i<numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position()+5);
continue; // skip over this record.
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == findNameID &&
((foundName == null && langID == ENGLISH_LOCALE_ID)
|| langID == findLocaleID)) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);
foundName = makeString(name, nameLen, encodingID);
if (langID == findLocaleID) {
return foundName;
}
}
}
}
return foundName;
} So, it's very hard to change it. |
No, this approach isn't working, because 'locale' determines via the system properties:
nameLocale = sun.awt.SunToolkit.getStartupLocale();
...
} else if (locale.equals(nameLocale) && localeFullName != null) {
return localeFullName; where String fileEncoding = System.getProperty("file.encoding", "");
String sysEncoding = System.getProperty("sun.jnu.encoding");
if (sysEncoding != null && !sysEncoding.equals(fileEncoding)) {
return Locale.ROOT;
}
String language = System.getProperty("user.language", "en");
String country = System.getProperty("user.country","");
String variant = System.getProperty("user.variant","");
return new Locale(language, country, variant);
public static Locale getStartupLocale() {
if (startupLocale == null) {
String language, region, country, variant;
language = AccessController.doPrivileged(
new GetPropertyAction("user.language", "en"));
// for compatibility, check for old user.region property
region = AccessController.doPrivileged(
new GetPropertyAction("user.region"));
if (region != null) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
if (i >= 0) {
country = region.substring(0, i);
variant = region.substring(i + 1);
} else {
country = region;
variant = "";
}
} else {
country = AccessController.doPrivileged(
new GetPropertyAction("user.country", ""));
variant = AccessController.doPrivileged(
new GetPropertyAction("user.variant", ""));
}
startupLocale = new Locale(language, country, variant);
}
return startupLocale;
} Need find the another way for the workaround solution. |
Follow on from #876
I have introduced code to insert
<mstyle fontweight="bold">
into MathML if its ancestor is<strong>
. However, I have discovered that style directives to render MathML in boldface are being ignored in PDF, whether they are the older<mstyle fontweight="bold">
, or the newer<mstyle style="font-weight:bold">
, or the native<mstyle mathvariant="bold">
.So the following snippet renders the
b
in boldface (non-italic) as expected in HTML and DOC, but as plain style in PDF:And it renders the same whether the
mstyle
hasmathvariant="bold"
,style="font-weight:bold"
, orfontweight="bold"
.The text was updated successfully, but these errors were encountered: