diff --git a/src/hotspot/cpu/ppc/ppc.ad b/src/hotspot/cpu/ppc/ppc.ad
index 1a3013d3233b..05629c23002e 100644
--- a/src/hotspot/cpu/ppc/ppc.ad
+++ b/src/hotspot/cpu/ppc/ppc.ad
@@ -9163,9 +9163,11 @@ instruct lShiftL_regI_immGE32(iRegLdst dst, iRegIsrc src1, uimmI6_ge32 src2) %{
ins_pipe(pipe_class_default);
%}
-// Shift a postivie int to the left.
+// Shift a positive int to the left.
// Clrlsldi clears the upper 32 bits and shifts.
-instruct scaledPositiveI2L_lShiftL_convI2L_reg_imm6(iRegLdst dst, iRegIsrc src1, uimmI6 src2) %{
+// Only valid for shift amounts < 32.
+// Shift amounts >= 32 are handled by lShiftL_regI_immGE32.
+instruct scaledPositiveI2L_lShiftL_convI2L_reg_imm6(iRegLdst dst, iRegIsrc src1, uimmI5 src2) %{
match(Set dst (LShiftL (ConvI2L src1) src2));
predicate(((ConvI2LNode*)(_kids[0]->_leaf))->type()->is_long()->is_positive_int());
diff --git a/src/java.base/share/classes/com/sun/crypto/provider/PBES2Parameters.java b/src/java.base/share/classes/com/sun/crypto/provider/PBES2Parameters.java
index ba7b4604daf9..2f5f64ab3e11 100644
--- a/src/java.base/share/classes/com/sun/crypto/provider/PBES2Parameters.java
+++ b/src/java.base/share/classes/com/sun/crypto/provider/PBES2Parameters.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
import java.security.spec.InvalidParameterSpecException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEParameterSpec;
+import sun.security.util.PBKDF2Parameters;
import sun.security.util.*;
/**
@@ -93,7 +94,7 @@
abstract class PBES2Parameters extends AlgorithmParametersSpi {
private static ObjectIdentifier pkcs5PBKDF2_OID =
- ObjectIdentifier.of(KnownOIDs.PBKDF2WithHmacSHA1);
+ ObjectIdentifier.of(KnownOIDs.PBKDF2);
private static ObjectIdentifier pkcs5PBES2_OID =
ObjectIdentifier.of(KnownOIDs.PBES2);
private static ObjectIdentifier aes128CBC_OID =
@@ -208,9 +209,6 @@ protected void engineInit(AlgorithmParameterSpec paramSpec)
protected void engineInit(byte[] encoded)
throws IOException
{
- String kdfAlgo = null;
- String cipherAlgo = null;
-
DerValue pBES2_params = new DerValue(encoded);
if (pBES2_params.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: "
@@ -226,91 +224,32 @@ protected void engineInit(byte[] encoded)
// next DerValue as the real PBES2-params.
if (kdf.getTag() == DerValue.tag_ObjectId) {
pBES2_params = pBES2_params.data.getDerValue();
+ if (pBES2_params.tag != DerValue.tag_Sequence) {
+ throw new IOException("PBE parameter parsing error: "
+ + "not an ASN.1 SEQUENCE tag");
+ }
kdf = pBES2_params.data.getDerValue();
}
- kdfAlgo = parseKDF(kdf);
-
- if (pBES2_params.tag != DerValue.tag_Sequence) {
- throw new IOException("PBE parameter parsing error: "
- + "not an ASN.1 SEQUENCE tag");
- }
- cipherAlgo = parseES(pBES2_params.data.getDerValue());
-
- this.pbes2AlgorithmName = new StringBuilder().append("PBEWith")
- .append(kdfAlgo).append("And").append(cipherAlgo).toString();
- }
-
- @SuppressWarnings("deprecation")
- private String parseKDF(DerValue keyDerivationFunc) throws IOException {
-
- if (!pkcs5PBKDF2_OID.equals(keyDerivationFunc.data.getOID())) {
+ if (!pkcs5PBKDF2_OID.equals(kdf.data.getOID())) {
throw new IOException("PBE parameter parsing error: "
+ "expecting the object identifier for PBKDF2");
}
- if (keyDerivationFunc.tag != DerValue.tag_Sequence) {
+ if (kdf.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: "
+ "not an ASN.1 SEQUENCE tag");
}
- DerValue pBKDF2_params = keyDerivationFunc.data.getDerValue();
- if (pBKDF2_params.tag != DerValue.tag_Sequence) {
- throw new IOException("PBE parameter parsing error: "
- + "not an ASN.1 SEQUENCE tag");
- }
- DerValue specified = pBKDF2_params.data.getDerValue();
- // the 'specified' ASN.1 CHOICE for 'salt' is supported
- if (specified.tag == DerValue.tag_OctetString) {
- salt = specified.getOctetString();
- } else {
- // the 'otherSource' ASN.1 CHOICE for 'salt' is not supported
- throw new IOException("PBE parameter parsing error: "
- + "not an ASN.1 OCTET STRING tag");
- }
- iCount = pBKDF2_params.data.getInteger();
-
- DerValue prf = null;
- // keyLength INTEGER (1..MAX) OPTIONAL,
- if (pBKDF2_params.data.available() > 0) {
- DerValue keyLength = pBKDF2_params.data.getDerValue();
- if (keyLength.tag == DerValue.tag_Integer) {
- keysize = keyLength.getInteger() * 8; // keysize (in bits)
- } else {
- // Should be the prf
- prf = keyLength;
- }
- }
- // prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1
- String kdfAlgo = "HmacSHA1";
- if (prf == null) {
- if (pBKDF2_params.data.available() > 0) {
- prf = pBKDF2_params.data.getDerValue();
- }
- }
- if (prf != null) {
- kdfAlgo_OID = prf.data.getOID();
- KnownOIDs o = KnownOIDs.findMatch(kdfAlgo_OID.toString());
- if (o == null || (!o.stdName().equals("HmacSHA1") &&
- !o.stdName().equals("HmacSHA224") &&
- !o.stdName().equals("HmacSHA256") &&
- !o.stdName().equals("HmacSHA384") &&
- !o.stdName().equals("HmacSHA512"))) {
- throw new IOException("PBE parameter parsing error: "
- + "expecting the object identifier for a HmacSHA key "
- + "derivation function");
- }
- kdfAlgo = o.stdName();
-
- if (prf.data.available() != 0) {
- // parameter is 'NULL' for all HmacSHA KDFs
- DerValue parameter = prf.data.getDerValue();
- if (parameter.tag != DerValue.tag_Null) {
- throw new IOException("PBE parameter parsing error: "
- + "not an ASN.1 NULL tag");
- }
- }
- }
+ DerValue pBKDF2_params = kdf.data.getDerValue();
+
+ var kdfParams = new PBKDF2Parameters(pBKDF2_params);
+ String kdfAlgo = kdfParams.getPrfAlgo();
+ salt = kdfParams.getSalt();
+ iCount = kdfParams.getIterationCount();
+ keysize = kdfParams.getKeyLength();
- return kdfAlgo;
+ String cipherAlgo = parseES(pBES2_params.data.getDerValue());
+
+ this.pbes2AlgorithmName = "PBEWith" + kdfAlgo + "And" + cipherAlgo;
}
@SuppressWarnings("deprecation")
@@ -362,26 +301,9 @@ protected byte[] engineGetEncoded() throws IOException {
DerOutputStream pBES2_params = new DerOutputStream();
- DerOutputStream keyDerivationFunc = new DerOutputStream();
- keyDerivationFunc.putOID(pkcs5PBKDF2_OID);
-
- DerOutputStream pBKDF2_params = new DerOutputStream();
- pBKDF2_params.putOctetString(salt); // choice: 'specified OCTET STRING'
- pBKDF2_params.putInteger(iCount);
-
- if (keysize > 0) {
- pBKDF2_params.putInteger(keysize / 8); // derived key length (in octets)
- }
-
- DerOutputStream prf = new DerOutputStream();
- // algorithm is id-hmacWithSHA1/SHA224/SHA256/SHA384/SHA512
- prf.putOID(kdfAlgo_OID);
- // parameters is 'NULL'
- prf.putNull();
- pBKDF2_params.write(DerValue.tag_Sequence, prf);
-
- keyDerivationFunc.write(DerValue.tag_Sequence, pBKDF2_params);
- pBES2_params.write(DerValue.tag_Sequence, keyDerivationFunc);
+ // keysize encoded as octets
+ pBES2_params.writeBytes(PBKDF2Parameters.encode(salt, iCount,
+ keysize/8, kdfAlgo_OID));
DerOutputStream encryptionScheme = new DerOutputStream();
// algorithm is id-aes128-CBC or id-aes256-CBC
diff --git a/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java b/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
index 29e331b944a4..70b26b5dd8a4 100644
--- a/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
+++ b/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
@@ -54,7 +54,7 @@
* @author Valerie Peng
*
*/
-final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
+public final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
@java.io.Serial
private static final long serialVersionUID = -2234868909660948157L;
diff --git a/src/java.base/share/classes/sun/security/pkcs12/MacData.java b/src/java.base/share/classes/sun/security/pkcs12/MacData.java
index dc5716ff558b..06ef6d3c4b27 100644
--- a/src/java.base/share/classes/sun/security/pkcs12/MacData.java
+++ b/src/java.base/share/classes/sun/security/pkcs12/MacData.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,32 +25,58 @@
package sun.security.pkcs12;
-import java.io.*;
+import java.io.IOException;
import java.security.*;
+import java.security.spec.InvalidKeySpecException;
+import static java.util.Locale.ENGLISH;
+import javax.crypto.Mac;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
-import sun.security.util.DerInputStream;
-import sun.security.util.DerOutputStream;
-import sun.security.util.DerValue;
-import sun.security.x509.AlgorithmId;
import sun.security.pkcs.ParsingException;
+import sun.security.util.*;
+import sun.security.x509.AlgorithmId;
/**
- * A MacData type, as defined in PKCS#12.
+ * The MacData type, as defined in PKCS#12.
+ *
+ * The ASN.1 definition is as follows:
+ *
+ *
+ *
+ * MacData ::= SEQUENCE {
+ * mac DigestInfo,
+ * macSalt OCTET STRING,
+ * iterations INTEGER DEFAULT 1
+ * -- Note: The default is for historical reasons and its use is
+ * -- deprecated.
+ * }
+ *
+ * DigestInfo ::= SEQUENCE {
+ * digestAlgorithm DigestAlgorithmIdentifier,
+ * digest OCTET STRING
+ * }
+ *
+ *
*
* @author Sharon Liu
*/
class MacData {
- private String digestAlgorithmName;
- private AlgorithmParameters digestAlgorithmParams;
+ private static final Debug debug = Debug.getInstance("pkcs12");
+ private final String macAlgorithm;
private byte[] digest;
private byte[] macSalt;
private int iterations;
- // the ASN.1 encoded contents of this class
- private byte[] encoded = null;
+ // The following three fields are for PBMAC1.
+ private final int keyLength;
+ private final String kdfHmac;
+ private final String hmac;
/**
* Parses a PKCS#12 MAC data.
@@ -72,133 +98,276 @@ class MacData {
// Parse the DigestAlgorithmIdentifier.
AlgorithmId digestAlgorithmId = AlgorithmId.parse(digestInfo[0]);
- this.digestAlgorithmName = digestAlgorithmId.getName();
- this.digestAlgorithmParams = digestAlgorithmId.getParameters();
+ String digestAlgorithmName = digestAlgorithmId.getName();
+
// Get the digest.
this.digest = digestInfo[1].getOctetString();
- // Get the salt.
- this.macSalt = macData[1].getOctetString();
+ if (digestAlgorithmName.equals("PBMAC1")) {
+ PBMAC1Parameters algParams;
+
+ algParams = new PBMAC1Parameters(digestAlgorithmId
+ .getEncodedParams());
+
+ this.iterations = algParams.getKdfParams().getIterationCount();
+ this.macSalt = algParams.getKdfParams().getSalt();
+ this.kdfHmac = algParams.getKdfParams().getPrfAlgo();
+ this.keyLength = algParams.getKdfParams().getKeyLength();
- // Iterations is optional. The default value is 1.
- if (macData.length > 2) {
- this.iterations = macData[2].getInteger();
+ // Implementations MUST NOT accept params that omit keyLength.
+ if (this.keyLength == -1) {
+ throw new IOException("error: missing keyLength field");
+ }
+ this.hmac = algParams.getHmac();
+ this.macAlgorithm = "pbewith" + this.kdfHmac + "and" + this.hmac;
} else {
- this.iterations = 1;
+ this.kdfHmac = null;
+ this.hmac = null;
+ this.keyLength = -1;
+ this.macSalt = macData[1].getOctetString();
+ if (macData.length > 2) {
+ this.iterations = macData[2].getInteger();
+ } else {
+ this.iterations = 1;
+ }
+ // Remove "-" from digest algorithm names
+ this.macAlgorithm = "hmacpbe"
+ + digestAlgorithmName.replace("-", "");
}
}
- MacData(String algName, byte[] digest, byte[] salt, int iterations)
- throws NoSuchAlgorithmException
- {
- if (algName == null)
- throw new NullPointerException("the algName parameter " +
- "must be non-null");
-
- AlgorithmId algid = AlgorithmId.get(algName);
- this.digestAlgorithmName = algid.getName();
- this.digestAlgorithmParams = algid.getParameters();
-
- if (digest == null) {
- throw new NullPointerException("the digest " +
- "parameter must be non-null");
- } else if (digest.length == 0) {
- throw new IllegalArgumentException("the digest " +
- "parameter must not be empty");
+ /**
+ * Computes a MAC on the data.
+ *
+ * This is a two-step process: first generate a key and then use the
+ * key to generate the MAC. PBMAC1 and non-PBMAC1 keys use different
+ * key factories. PBMAC1 uses a pseudorandom function (kdfHmac)
+ * to generate keys while non-PBMAC1 does not. The MAC is computed
+ * according to the specified hmac algorithm.
+ *
+ * @param macAlgorithm the algorithm used to compute the MAC
+ * @param password the password used to generate the key
+ * @param params a PBEParameterSpec object
+ * @param data the data on which the MAC is computed
+ * @param kdfHmac the pseudorandom function used to compute the key
+ * for PBMAC1
+ * @param hmac the algorithm used to compute the MAC
+ * @param keyLength the length of the key generated by the pseudorandom
+ * function
+ *
+ * @return the computed MAC as a byte array
+ *
+ * @exception NoSuchAlgorithmException if either kdfHmac or hmac is
+ * unknown to the Mac or SecretKeyFactory
+ */
+ private static byte[] calculateMac(String macAlgorithm, char[] password,
+ PBEParameterSpec params, byte[] data,
+ String kdfHmac, String hmac, int keyLength)
+ throws InvalidAlgorithmParameterException, InvalidKeyException,
+ InvalidKeySpecException, NoSuchAlgorithmException {
+ SecretKeyFactory skf;
+ SecretKey pbeKey = null;
+ Mac m;
+
+ PBEKeySpec keySpec;
+
+ /*
+ * The Hmac has to be extracted from the algorithm name for
+ * PBMAC1 algorithms. For non-PBMAC1 macAlgorithms, the name
+ * and Hmac are the same.
+ *
+ * The prefix used in Algorithm names is guaranteed to be lowercase.
+ */
+ if (macAlgorithm.startsWith("pbewith")) {
+ m = Mac.getInstance(hmac);
+ int len = keyLength == -1 ? m.getMacLength()*8 : keyLength;
+ skf = SecretKeyFactory.getInstance("PBKDF2With" +kdfHmac);
+ keySpec = new PBEKeySpec(password, params.getSalt(),
+ params.getIterationCount(), len);
} else {
- this.digest = digest.clone();
+ m = Mac.getInstance(macAlgorithm);
+ skf = SecretKeyFactory.getInstance("PBE");
+ keySpec = new PBEKeySpec(password);
}
- this.macSalt = salt;
- this.iterations = iterations;
+ try {
+ pbeKey = skf.generateSecret(keySpec);
+ if (macAlgorithm.startsWith("pbewith")) {
+ m.init(pbeKey);
+ } else {
+ m.init(pbeKey, params);
+ }
+ m.update(data);
+ return m.doFinal();
+ } finally {
+ keySpec.clearPassword();
+ KeyUtil.destroySecretKeys(pbeKey);
+ }
+ }
- // delay the generation of ASN.1 encoding until
- // getEncoded() is called
- this.encoded = null;
+ /**
+ * Verify Mac on the data.
+ *
+ * Calculate Mac on the data and compare with Mac found in input stream.
+ *
+ * @param password the password used to generate the key
+ * @param data the data on which the MAC is computed
+ *
+ * @exception UnrecoverableKeyException if calculated Mac and
+ * Mac found in input stream are different
+ */
+ void verifyMac(char[] password, byte[] data)
+ throws InvalidAlgorithmParameterException, InvalidKeyException,
+ InvalidKeySpecException, NoSuchAlgorithmException,
+ UnrecoverableKeyException {
+
+ byte[] macResult = calculateMac(this.macAlgorithm, password,
+ new PBEParameterSpec(this.macSalt, this.iterations),
+ data, this.kdfHmac, this.hmac, this.keyLength);
+
+ if (debug != null) {
+ debug.println("Checking keystore integrity " +
+ "(" + this.macAlgorithm + " iterations: "
+ + this.iterations + ")");
+ }
+ if (!MessageDigest.isEqual(this.digest, macResult)) {
+ throw new UnrecoverableKeyException("Failed PKCS12" +
+ " integrity checking");
+ }
}
- MacData(AlgorithmParameters algParams, byte[] digest,
- byte[] salt, int iterations) throws NoSuchAlgorithmException
- {
- if (algParams == null)
- throw new NullPointerException("the algParams parameter " +
- "must be non-null");
-
- AlgorithmId algid = AlgorithmId.get(algParams);
- this.digestAlgorithmName = algid.getName();
- this.digestAlgorithmParams = algid.getParameters();
-
- if (digest == null) {
- throw new NullPointerException("the digest " +
- "parameter must be non-null");
- } else if (digest.length == 0) {
- throw new IllegalArgumentException("the digest " +
- "parameter must not be empty");
+ /*
+ * Gathers parameters and generates a MAC of the data
+ *
+ * @param password the password used to generate the key
+ * @param data the data on which the MAC is computed
+ * @param macAlgorithm the algorithm used to compute the MAC
+ * @param macIterationCount the iteration count
+ * @param salt the salt
+ *
+ * @exception IOException if the MAC cannot be calculated
+ *
+ * @return the computed MAC as a byte array
+ */
+ static byte[] generateMac(char[] passwd, byte[] data,
+ String macAlgorithm, int macIterationCount, byte[] salt)
+ throws IOException, NoSuchAlgorithmException {
+ final PBEParameterSpec params;
+ String algName;
+ String kdfHmac;
+ String hmac;
+
+ macAlgorithm = macAlgorithm.toLowerCase(ENGLISH);
+ // The prefix used in Algorithm names is guaranteed to be lowercase.
+ if (macAlgorithm.startsWith("pbewith")) {
+ algName = "PBMAC1";
+ kdfHmac = MacData.parseKdfHmac(macAlgorithm);
+ hmac = MacData.parseHmac(macAlgorithm);
+ if (hmac == null) {
+ hmac = kdfHmac;
+ }
+ } else if (macAlgorithm.startsWith("hmacpbe")) {
+ algName = macAlgorithm.substring(7);
+ kdfHmac = null;
+ hmac = macAlgorithm;
} else {
- this.digest = digest.clone();
+ throw new ParsingException("unexpected algorithm '"
+ + macAlgorithm + "'");
}
- this.macSalt = salt;
- this.iterations = iterations;
+ params = new PBEParameterSpec(salt, macIterationCount);
- // delay the generation of ASN.1 encoding until
- // getEncoded() is called
- this.encoded = null;
+ try {
+ byte[] macResult = calculateMac(macAlgorithm, passwd, params, data,
+ kdfHmac, hmac, -1);
+ DerOutputStream bytes = new DerOutputStream();
+ bytes.write(encode(algName, macResult, params, kdfHmac, hmac,
+ macResult.length));
+ return bytes.toByteArray();
+ } catch (InvalidKeySpecException | InvalidKeyException |
+ InvalidAlgorithmParameterException e) {
+ throw new IOException("calculateMac failed: " + e, e);
+ }
}
- String getDigestAlgName() {
- return digestAlgorithmName;
- }
-
- byte[] getSalt() {
- return macSalt;
+ String getMacAlgorithm() {
+ return this.macAlgorithm;
}
int getIterations() {
- return iterations;
- }
-
- byte[] getDigest() {
- return digest;
+ return this.iterations;
}
/**
- * Returns the ASN.1 encoding of this object.
- * @return the ASN.1 encoding.
- * @exception IOException if error occurs when constructing its
+ * Returns the ASN.1 encoding.
+ * @return the ASN.1 encoding
+ * @exception NoSuchAlgorithmException if error occurs when constructing its
* ASN.1 encoding.
*/
- public byte[] getEncoded() throws NoSuchAlgorithmException, IOException
- {
- if (this.encoded != null)
- return this.encoded.clone();
+ static byte[] encode(String algName, byte[] digest, PBEParameterSpec p,
+ String kdfHmac, String hmac, int keyLength)
+ throws IOException, NoSuchAlgorithmException {
+
+ final int iterations = p.getIterationCount();
+ final byte[] macSalt = p.getSalt();
- DerOutputStream out = new DerOutputStream();
DerOutputStream tmp = new DerOutputStream();
+ DerOutputStream out = new DerOutputStream();
- DerOutputStream tmp2 = new DerOutputStream();
- // encode encryption algorithm
- AlgorithmId algid = AlgorithmId.get(digestAlgorithmName);
- algid.encode(tmp2);
+ if (algName.equals("PBMAC1")) {
+ DerOutputStream tmp1 = new DerOutputStream();
+ DerOutputStream tmp2 = new DerOutputStream();
- // encode digest data
- tmp2.putOctetString(digest);
+ // id-PBMAC1 OBJECT IDENTIFIER ::= { pkcs-5 14 }
+ tmp2.putOID(ObjectIdentifier.of(KnownOIDs.PBMAC1));
+ tmp2.writeBytes(PBMAC1Parameters.encode(macSalt, iterations,
+ keyLength, kdfHmac, hmac));
- tmp.write(DerValue.tag_Sequence, tmp2);
+ tmp1.write(DerValue.tag_Sequence, tmp2);
+ tmp1.putOctetString(digest);
- // encode salt
- tmp.putOctetString(macSalt);
+ tmp.write(DerValue.tag_Sequence, tmp1);
+ tmp.putOctetString(
+ new byte[]{ 'N', 'O', 'T', ' ', 'U', 'S', 'E', 'D' });
+ // Unused, but must have non-zero positive value.
+ tmp.putInteger(1);
+ } else {
+ final AlgorithmId digestAlgorithm = AlgorithmId.get(algName);
+ DerOutputStream tmp2 = new DerOutputStream();
- // encode iterations
- tmp.putInteger(iterations);
+ digestAlgorithm.encode(tmp2);
+ tmp2.putOctetString(digest);
+ // wrap into a SEQUENCE
+ tmp.write(DerValue.tag_Sequence, tmp2);
+ tmp.putOctetString(macSalt);
+ tmp.putInteger(iterations);
+ }
// wrap everything into a SEQUENCE
out.write(DerValue.tag_Sequence, tmp);
- this.encoded = out.toByteArray();
+ return out.toByteArray();
+ }
- return this.encoded.clone();
+ private static String parseKdfHmac(String text) {
+ int index1 = text.indexOf("with") + 4;
+ int index2 = text.indexOf("and");
+ if (index1 == 3) { // -1 + 4
+ return null;
+ } else if (index2 == -1) {
+ return text.substring(index1);
+ } else {
+ return text.substring(index1, index2);
+ }
}
+ private static String parseHmac(String text) {
+ int index1 = text.indexOf("and") + 3;
+ if (index1 == 2) { // -1 + 3
+ return null;
+ } else {
+ return text.substring(index1);
+ }
+ }
}
diff --git a/src/java.base/share/classes/sun/security/pkcs12/PBMAC1Parameters.java b/src/java.base/share/classes/sun/security/pkcs12/PBMAC1Parameters.java
new file mode 100644
index 000000000000..634d980b0ccd
--- /dev/null
+++ b/src/java.base/share/classes/sun/security/pkcs12/PBMAC1Parameters.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.pkcs12;
+
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+
+import sun.security.util.*;
+import sun.security.x509.AlgorithmId;
+
+/**
+ * This class implements the parameter set used with password-based
+ * mac scheme 1 (PBMAC1), which is defined in PKCS#5 as follows:
+ *
+ *
+ * -- PBMAC1
+ *
+ * PBMAC1Algorithms ALGORITHM-IDENTIFIER ::=
+ * { {PBMAC1-params IDENTIFIED BY id-PBMAC1}, ...}
+ *
+ * id-PBMAC1 OBJECT IDENTIFIER ::= {pkcs-5 14}
+ *
+ * PBMAC1-params ::= SEQUENCE {
+ * keyDerivationFunc AlgorithmIdentifier {{PBMAC1-KDFs}},
+ * messageAuthScheme AlgorithmIdentifier {{PBMAC1-MACs}} }
+ *
+ * PBMAC1-KDFs ALGORITHM-IDENTIFIER ::=
+ * { {PBKDF2-params IDENTIFIED BY id-PBKDF2}, ... }
+ *
+ * PBMAC1-MACs ALGORITHM-IDENTIFIER ::= { ... }
+ *
+ * -- PBKDF2
+ *
+ * See sun.security.util.PBKDF2Parameters.
+ *
+ *
+ *
+ * @since 26
+ */
+final class PBMAC1Parameters {
+
+ static final ObjectIdentifier pkcs5PBKDF2_OID =
+ ObjectIdentifier.of(KnownOIDs.PBKDF2);
+
+ private final String hmacAlgo;
+ private final PBKDF2Parameters kdfParams;
+
+ PBMAC1Parameters(byte[] encoded) throws IOException {
+ DerValue pBMAC1_params = new DerValue(encoded);
+ if (pBMAC1_params.tag != DerValue.tag_Sequence) {
+ throw new IOException("PBMAC1 parameter parsing error: "
+ + "not an ASN.1 SEQUENCE tag");
+ }
+ DerValue[] info = new DerInputStream(pBMAC1_params.toByteArray())
+ .getSequence(2);
+ if (info.length != 2) {
+ throw new IOException("PBMAC1 parameter parsing error: "
+ + "expected length not 2");
+ }
+ ObjectIdentifier OID = info[1].data.getOID();
+ KnownOIDs o = KnownOIDs.findMatch(OID.toString());
+ if (o == null || (!o.stdName().equals("HmacSHA1") &&
+ !o.stdName().equals("HmacSHA224") &&
+ !o.stdName().equals("HmacSHA256") &&
+ !o.stdName().equals("HmacSHA384") &&
+ !o.stdName().equals("HmacSHA512") &&
+ !o.stdName().equals("HmacSHA512/224") &&
+ !o.stdName().equals("HmacSHA512/256"))) {
+ throw new IOException("PBMAC1 parameter parsing error: "
+ + "expecting the object identifier for a HmacSHA key "
+ + "derivation function");
+ }
+ // Hmac function used to compute the MAC
+ this.hmacAlgo = o.stdName();
+
+ //DerValue kdf = pBMAC1_params.data.getDerValue();
+ DerValue kdf = info[0];
+
+ if (!pkcs5PBKDF2_OID.equals(kdf.data.getOID())) {
+ throw new IOException("PBKDF2 parameter parsing error: "
+ + "expecting the object identifier for PBKDF2");
+ }
+ if (kdf.tag != DerValue.tag_Sequence) {
+ throw new IOException("PBKDF2 parameter parsing error: "
+ + "not an ASN.1 SEQUENCE tag");
+ }
+ DerValue pBKDF2_params = kdf.data.getDerValue();
+
+ this.kdfParams = new PBKDF2Parameters(pBKDF2_params);
+ }
+
+ /*
+ * Encode PBMAC1 parameters from components.
+ */
+ static byte[] encode(byte[] salt, int iterationCount, int keyLength,
+ String kdfHmac, String hmac) throws NoSuchAlgorithmException {
+
+ DerOutputStream out = new DerOutputStream();
+
+ // keyDerivationFunc AlgorithmIdentifier {{PBMAC1-KDFs}}
+ out.writeBytes(PBKDF2Parameters.encode(salt,
+ iterationCount, keyLength, kdfHmac));
+
+ // messageAuthScheme AlgorithmIdentifier {{PBMAC1-MACs}}
+ DerOutputStream dos = new DerOutputStream();
+ try {
+ AlgorithmId.get(hmac).encode(out);
+ dos.write(DerValue.tag_Sequence, out);
+ } catch (IOException e) {
+ // ignore
+ }
+ return dos.toByteArray();
+ }
+
+ PBKDF2Parameters getKdfParams() {
+ return this.kdfParams;
+ }
+
+ String getHmac() {
+ return this.hmacAlgo;
+ }
+}
diff --git a/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java b/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
index fc44de73f8ee..cea0dcc489fc 100644
--- a/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
+++ b/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,55 +26,37 @@
package sun.security.pkcs12;
import java.io.*;
-import java.security.AccessController;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.Key;
-import java.security.KeyFactory;
-import java.security.KeyStore;
-import java.security.KeyStoreSpi;
-import java.security.KeyStoreException;
-import java.security.PKCS12Attribute;
-import java.security.PrivateKey;
-import java.security.PrivilegedAction;
-import java.security.UnrecoverableEntryException;
-import java.security.UnrecoverableKeyException;
-import java.security.SecureRandom;
-import java.security.Security;
+import java.security.*;
import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-import java.security.cert.CertificateException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.*;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import java.security.AlgorithmParameters;
-import java.security.InvalidAlgorithmParameterException;
-import javax.crypto.spec.PBEParameterSpec;
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
import javax.crypto.spec.SecretKeySpec;
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.SecretKey;
-import javax.crypto.Cipher;
-import javax.crypto.Mac;
import javax.security.auth.DestroyFailedException;
import javax.security.auth.x500.X500Principal;
import jdk.internal.access.SharedSecrets;
import sun.security.action.GetPropertyAction;
-import sun.security.tools.KeyStoreUtil;
-import sun.security.util.*;
import sun.security.pkcs.ContentInfo;
-import sun.security.x509.AlgorithmId;
import sun.security.pkcs.EncryptedPrivateKeyInfo;
import sun.security.provider.JavaKeyStore.JKS;
+import sun.security.tools.KeyStoreUtil;
+import sun.security.util.*;
+import sun.security.x509.AlgorithmId;
import sun.security.x509.AuthorityKeyIdentifierExtension;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
/**
* This class provides the keystore implementation referred to as "PKCS12".
@@ -366,7 +348,7 @@ public Key engineGetKey(String alias, char[] password)
try {
cipher.init(Cipher.DECRYPT_MODE, skey, algParams);
} finally {
- destroyPBEKey(skey);
+ KeyUtil.destroySecretKeys(skey);
}
byte[] keyInfo = cipher.doFinal(encryptedKey);
/*
@@ -878,17 +860,6 @@ private SecretKey getPBEKey(char[] password) throws IOException
return skey;
}
- /*
- * Destroy the key obtained from getPBEKey().
- */
- private void destroyPBEKey(SecretKey key) {
- try {
- key.destroy();
- } catch (DestroyFailedException e) {
- // Accept this
- }
- }
-
/*
* Encrypt private key or secret key using Password-based encryption (PBE)
* as defined in PKCS#5.
@@ -938,7 +909,7 @@ private byte[] encryptPrivateKey(byte[] data,
try {
cipher.init(Cipher.ENCRYPT_MODE, skey, algParams);
} finally {
- destroyPBEKey(skey);
+ KeyUtil.destroySecretKeys(skey);
}
byte[] encryptedKey = cipher.doFinal(data);
algid = new AlgorithmId(pbeOID, cipher.getParameters());
@@ -1293,7 +1264,8 @@ public synchronized void engineStore(OutputStream stream, char[] password)
macIterationCount = defaultMacIterationCount();
}
if (!macAlgorithm.equalsIgnoreCase("NONE")) {
- byte[] macData = calculateMac(password, authenticatedSafe);
+ byte[] macData = MacData.generateMac(password, authenticatedSafe,
+ macAlgorithm, macIterationCount, getSalt());
pfx.write(macData);
}
// write PFX to output stream
@@ -1503,48 +1475,6 @@ private void populateAttributes(Entry entry) {
}
}
- /*
- * Calculate MAC using HMAC algorithm (required for password integrity)
- *
- * Hash-based MAC algorithm combines secret key with message digest to
- * create a message authentication code (MAC)
- */
- private byte[] calculateMac(char[] passwd, byte[] data)
- throws IOException
- {
- byte[] mData = null;
- String algName = macAlgorithm.substring(7);
-
- try {
- // Generate a random salt.
- byte[] salt = getSalt();
-
- // generate MAC (MAC key is generated within JCE)
- Mac m = Mac.getInstance(macAlgorithm);
- PBEParameterSpec params =
- new PBEParameterSpec(salt, macIterationCount);
- SecretKey key = getPBEKey(passwd);
- try {
- m.init(key, params);
- } finally {
- destroyPBEKey(key);
- }
- m.update(data);
- byte[] macResult = m.doFinal();
-
- // encode as MacData
- MacData macData = new MacData(algName, macResult, salt,
- macIterationCount);
- DerOutputStream bytes = new DerOutputStream();
- bytes.write(macData.getEncoded());
- mData = bytes.toByteArray();
- } catch (Exception e) {
- throw new IOException("calculateMac failed: " + e, e);
- }
- return mData;
- }
-
-
/*
* Validate Certificate Chain
*/
@@ -1938,7 +1868,7 @@ private byte[] encryptContent(byte[] data, char[] password)
try {
cipher.init(Cipher.ENCRYPT_MODE, skey, algParams);
} finally {
- destroyPBEKey(skey);
+ KeyUtil.destroySecretKeys(skey);
}
encryptedData = cipher.doFinal(data);
@@ -2151,7 +2081,7 @@ public synchronized void engineLoad(InputStream stream, char[] password)
try {
cipher.init(Cipher.DECRYPT_MODE, skey, algParams);
} finally {
- destroyPBEKey(skey);
+ KeyUtil.destroySecretKeys(skey);
}
loadSafeContents(new DerInputStream(cipher.doFinal(rawData)));
return null;
@@ -2186,39 +2116,11 @@ public synchronized void engineLoad(InputStream stream, char[] password)
"MAC iteration count too large: " + ic);
}
- String algName =
- macData.getDigestAlgName().toUpperCase(Locale.ENGLISH);
-
- // Change SHA-1 to SHA1
- algName = algName.replace("-", "");
-
- macAlgorithm = "HmacPBE" + algName;
+ // Store MAC algorithm of keystore that was just loaded.
+ macAlgorithm = macData.getMacAlgorithm();
macIterationCount = ic;
-
- // generate MAC (MAC key is created within JCE)
- Mac m = Mac.getInstance(macAlgorithm);
- PBEParameterSpec params =
- new PBEParameterSpec(macData.getSalt(), ic);
-
RetryWithZero.run(pass -> {
- SecretKey key = getPBEKey(pass);
- try {
- m.init(key, params);
- } finally {
- destroyPBEKey(key);
- }
- m.update(authSafeData);
- byte[] macResult = m.doFinal();
-
- if (debug != null) {
- debug.println("Checking keystore integrity " +
- "(" + m.getAlgorithm() + " iterations: " + ic + ")");
- }
-
- if (!MessageDigest.isEqual(macData.getDigest(), macResult)) {
- throw new UnrecoverableKeyException("Failed PKCS12" +
- " integrity checking");
- }
+ macData.verifyMac(pass, authSafeData);
return (Void) null;
}, password);
} catch (Exception e) {
diff --git a/src/java.base/share/classes/sun/security/util/KeyUtil.java b/src/java.base/share/classes/sun/security/util/KeyUtil.java
index 49cdcc518656..f9ac149ee4b7 100644
--- a/src/java.base/share/classes/sun/security/util/KeyUtil.java
+++ b/src/java.base/share/classes/sun/security/util/KeyUtil.java
@@ -49,6 +49,11 @@
import javax.crypto.interfaces.DHPublicKey;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.DHPublicKeySpec;
+import javax.crypto.spec.SecretKeySpec;
+import javax.security.auth.DestroyFailedException;
+import jdk.internal.access.SharedSecrets;
+
+import com.sun.crypto.provider.PBKDF2KeyImpl;
import java.math.BigInteger;
import java.security.spec.NamedParameterSpec;
import java.util.Arrays;
@@ -450,5 +455,25 @@ public static boolean isSupportedKeyAgreementOutputAlgorithm(String alg) {
return alg.equalsIgnoreCase("TlsPremasterSecret")
|| alg.equalsIgnoreCase("Generic");
}
+
+ // destroy secret keys in a best-effort way
+ public static void destroySecretKeys(SecretKey... keys) {
+ for (SecretKey k : keys) {
+ if (k != null) {
+ if (k instanceof SecretKeySpec sk) {
+ SharedSecrets.getJavaxCryptoSpecAccess()
+ .clearSecretKeySpec(sk);
+ } else if (k instanceof PBKDF2KeyImpl p2k) {
+ p2k.clearPassword();
+ } else {
+ try {
+ k.destroy();
+ } catch (DestroyFailedException e) {
+ // swallow
+ }
+ }
+ }
+ }
+ }
}
diff --git a/src/java.base/share/classes/sun/security/util/KnownOIDs.java b/src/java.base/share/classes/sun/security/util/KnownOIDs.java
index e305982f02c3..c4a92e1056e6 100644
--- a/src/java.base/share/classes/sun/security/util/KnownOIDs.java
+++ b/src/java.base/share/classes/sun/security/util/KnownOIDs.java
@@ -218,8 +218,9 @@ public enum KnownOIDs {
PBEWithMD5AndRC2("1.2.840.113549.1.5.6"),
PBEWithSHA1AndDES("1.2.840.113549.1.5.10"),
PBEWithSHA1AndRC2("1.2.840.113549.1.5.11"),
- PBKDF2WithHmacSHA1("1.2.840.113549.1.5.12"),
+ PBKDF2("1.2.840.113549.1.5.12", "PBKDF2WithHmacSHA1"),
PBES2("1.2.840.113549.1.5.13"),
+ PBMAC1("1.2.840.113549.1.5.14"),
// PKCS7 1.2.840.113549.1.7.*
PKCS7("1.2.840.113549.1.7"),
diff --git a/src/java.base/share/classes/sun/security/util/PBKDF2Parameters.java b/src/java.base/share/classes/sun/security/util/PBKDF2Parameters.java
new file mode 100644
index 000000000000..d13974eb98f7
--- /dev/null
+++ b/src/java.base/share/classes/sun/security/util/PBKDF2Parameters.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.util;
+
+import java.io.IOException;
+
+import sun.security.util.KnownOIDs;
+import sun.security.x509.AlgorithmId;
+
+/**
+ * This class implements the parameter set used with password-based
+ * key derivation function 2 (PBKDF2), which is defined in PKCS#5 as follows:
+ *
+ *
+ *
+ * PBKDF2Algorithms ALGORITHM-IDENTIFIER ::=
+ * { {PBKDF2-params IDENTIFIED BY id-PBKDF2}, ...}
+ *
+ * id-PBKDF2 OBJECT IDENTIFIER ::= {pkcs-5 12}
+ *
+ * PBKDF2-params ::= SEQUENCE {
+ * salt CHOICE {
+ * specified OCTET STRING,
+ * otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
+ * },
+ * iterationCount INTEGER (1..MAX),
+ * keyLength INTEGER (1..MAX) OPTIONAL,
+ * prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1
+ * }
+ *
+ * PBKDF2-SaltSources ALGORITHM-IDENTIFIER ::= { ... }
+ *
+ * PBKDF2-PRFs ALGORITHM-IDENTIFIER ::= {
+ * {NULL IDENTIFIED BY id-hmacWithSHA1} |
+ * {NULL IDENTIFIED BY id-hmacWithSHA224} |
+ * {NULL IDENTIFIED BY id-hmacWithSHA256} |
+ * {NULL IDENTIFIED BY id-hmacWithSHA384} |
+ * {NULL IDENTIFIED BY id-hmacWithSHA512}, ... }
+ *
+ * algid-hmacWithSHA1 AlgorithmIdentifier {{PBKDF2-PRFs}} ::=
+ * {algorithm id-hmacWithSHA1, parameters NULL : NULL}
+ *
+ * id-hmacWithSHA1 OBJECT IDENTIFIER ::= {digestAlgorithm 7}
+ *
+ * For more information, see
+ * RFC 8018:
+ * PKCS #5: Password-Based Cryptography Specification.
+ *
+ *
+ */
+public final class PBKDF2Parameters {
+
+ private final byte[] salt;
+
+ private final int iterationCount;
+
+ // keyLength in bits, or -1 if not present
+ private final int keyLength;
+
+ private final String prfAlgo;
+
+ /**
+ * Initialize PBKDF2Parameters from a DER encoded
+ * parameter block.
+ *
+ * @param pBKDF2_params the DER encoding of the parameter block
+ *
+ * @throws IOException for parsing errors in the input stream
+ */
+ public PBKDF2Parameters(DerValue pBKDF2_params) throws IOException {
+
+ if (pBKDF2_params.tag != DerValue.tag_Sequence) {
+ throw new IOException("PBKDF2 parameter parsing error: "
+ + "not an ASN.1 SEQUENCE tag");
+ }
+ DerValue specified = pBKDF2_params.data.getDerValue();
+ // the 'specified' ASN.1 CHOICE for 'salt' is supported
+ if (specified.tag == DerValue.tag_OctetString) {
+ salt = specified.getOctetString();
+ } else {
+ // the 'otherSource' ASN.1 CHOICE for 'salt' is not supported
+ throw new IOException("PBKDF2 parameter parsing error: "
+ + "not an ASN.1 OCTET STRING tag");
+ }
+ iterationCount = pBKDF2_params.data.getInteger();
+
+ // keyLength INTEGER (1..MAX) OPTIONAL,
+ DerInputStream ksData = pBKDF2_params.data;
+ if (ksData.available() > 0 &&
+ ksData.data[ksData.pos] == DerValue.tag_Integer) {
+ keyLength = ksData.getInteger() * 8; // keyLength (in bits)
+ } else {
+ keyLength = -1;
+ }
+
+ // prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1
+ DerInputStream prfData = pBKDF2_params.data;
+ if (prfData.available() > 0 &&
+ prfData.data[prfData.pos] == DerValue.tag_Sequence) {
+ DerValue prf = prfData.getDerValue();
+ // the pseudorandom function (default is HmacSHA1)
+ ObjectIdentifier kdfAlgo_OID = prf.data.getOID();
+ KnownOIDs o = KnownOIDs.findMatch(kdfAlgo_OID.toString());
+ if (o == null || (!o.stdName().equals("HmacSHA1") &&
+ !o.stdName().equals("HmacSHA224") &&
+ !o.stdName().equals("HmacSHA256") &&
+ !o.stdName().equals("HmacSHA384") &&
+ !o.stdName().equals("HmacSHA512"))) {
+ throw new IOException("PBKDF2 parameter parsing error: "
+ + "expecting the object identifier for a HmacSHA "
+ + "pseudorandom function");
+ }
+ prfAlgo = o.stdName();
+ if (prf.data.available() > 0 &&
+ prf.data.data[prf.data.pos] == DerValue.tag_Null) {
+ prf.data.getDerValue();
+ }
+ if (prf.data.available() != 0) {
+ throw new IOException("Extra unused bytes");
+ }
+ } else {
+ prfAlgo = "HmacSHA1";
+ }
+ }
+
+ public static byte[] encode(byte[] salt, int iterationCount,
+ int keyLength, String kdfHmac) {
+ ObjectIdentifier prf =
+ ObjectIdentifier.of(KnownOIDs.findMatch(kdfHmac));
+ return PBKDF2Parameters.encode(salt, iterationCount, keyLength, prf);
+ }
+
+ /*
+ * Encode PBKDF2 parameters from components.
+ * The outer algorithm ID is also encoded in addition to the parameters.
+ */
+ public static byte[] encode(byte[] salt, int iterationCount,
+ int keyLength, ObjectIdentifier prf) {
+ assert keyLength != -1;
+
+ DerOutputStream out = new DerOutputStream();
+ DerOutputStream tmp0 = new DerOutputStream();
+ DerOutputStream dos = new DerOutputStream();
+
+ try {
+ tmp0.putOctetString(salt);
+ tmp0.putInteger(iterationCount);
+ tmp0.putInteger(keyLength);
+
+ // prf AlgorithmIdentifier {{PBKDF2-PRFs}}
+ new AlgorithmId(prf).encode(tmp0);
+
+ // id-PBKDF2 OBJECT IDENTIFIER ::= {pkcs-5 12}
+ out.putOID(ObjectIdentifier.of(KnownOIDs.PBKDF2));
+ out.write(DerValue.tag_Sequence, tmp0);
+
+ dos.write(DerValue.tag_Sequence, out);
+ } catch (IOException e) {
+ // ignore
+ }
+ return dos.toByteArray();
+ }
+
+ /**
+ * Returns the salt.
+ *
+ * @return the salt
+ */
+ public byte[] getSalt() {
+ return this.salt;
+ }
+
+ /**
+ * Returns the iteration count.
+ *
+ * @return the iteration count
+ */
+ public int getIterationCount() {
+ return this.iterationCount;
+ }
+
+ /**
+ * Returns size of key generated by PBKDF2, or -1 if not found/set.
+ *
+ * @return size of key generated by PBKDF2, or -1 if not found/set
+ */
+ public int getKeyLength() {
+ return this.keyLength;
+ }
+
+ /**
+ * Returns name of Hmac.
+ *
+ * @return name of Hmac
+ */
+ public String getPrfAlgo() {
+ return this.prfAlgo;
+ }
+}
diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security
index 6507dac47357..81d36db0e00e 100644
--- a/src/java.base/share/conf/security/java.security
+++ b/src/java.base/share/conf/security/java.security
@@ -1280,8 +1280,9 @@ jceks.key.serialFilter = java.base/java.lang.Enum;java.base/java.security.KeyRep
#keystore.pkcs12.keyPbeIterationCount = 10000
# The algorithm used to calculate the optional MacData at the end of a PKCS12
-# file. This can be any HmacPBE algorithm defined in the Mac section of the
-# Java Security Standard Algorithm Names Specification. When set to "NONE",
+# file. This can be any HmacPBE or PBEWith algorithm defined in
+# the Mac section of the Java Security Standard Algorithm Names Specification,
+# for example, HmacPBESHA256 or PBEWithHmacSHA256. When set to "NONE",
# no Mac is generated. The default value is "HmacPBESHA256".
#keystore.pkcs12.macAlgorithm = HmacPBESHA256
diff --git a/src/java.desktop/share/legal/harfbuzz.md b/src/java.desktop/share/legal/harfbuzz.md
index 448de3faee1a..e0df8484f402 100644
--- a/src/java.desktop/share/legal/harfbuzz.md
+++ b/src/java.desktop/share/legal/harfbuzz.md
@@ -1,4 +1,4 @@
-## Harfbuzz v14.2.0
+## Harfbuzz v15.0.0
### Harfbuzz License
@@ -9,16 +9,16 @@ For parts of HarfBuzz that are licensed under different licenses see individual
files names COPYING in subdirectories where applicable.
Copyright © 2010-2024 Google, Inc.
-Copyright © 2018-2020 Ebrahim Byagowi
+Copyright © 2018-2026 Ebrahim Byagowi
Copyright © 2004-2013 Red Hat, Inc.
Copyright © 2019 Facebook, Inc.
Copyright (C) 2012 Zilong Tan (eric.zltan@gmail.com)
Copyright © 2007 Chris Wilson
-Copyright © 2018-2019 Adobe Inc.
+Copyright © 2018-2024 Adobe Inc.
Copyright © 2006-2025 Behdad Esfahbod
Copyright © 1998-2004 David Turner and Werner Lemberg
Copyright © 2009 Keith Stribley
-Copyright © 2018 Khaled Hosny
+Copyright © 2018-2026 Khaled Hosny
Copyright © 2016 Elie Roux
Copyright © 2016 Igalia S.L.
Copyright © 2015 Mozilla Foundation.
@@ -75,10 +75,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
The below applies to the following file(s):
libharfbuzz/hb-unicode-emoji-table.hh
-© 2025 Unicode®, Inc.
+© 2026 Unicode®, Inc.
-Unicode and the Unicode Logo are registered trademarks of Unicode, Inc.
-in the U.S. and other countries.
+Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the U.S. and other countries.
For terms of use and license, see https://www.unicode.org/terms_of_use.html
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Color/CBDT/CBDT.hh b/src/java.desktop/share/native/libharfbuzz/OT/Color/CBDT/CBDT.hh
index b8f6fa4054b6..8e395bb7020e 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Color/CBDT/CBDT.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Color/CBDT/CBDT.hh
@@ -44,6 +44,67 @@
namespace OT {
+/* Tracks image data blocks emitted into the subset CBDT table so that
+ * identical subtables (for example the same bitmaps used by several strikes)
+ * can share a single copy. */
+struct cbdt_dedup_context_t
+{
+ struct entry_t
+ {
+ unsigned int base; /* Offset of the data in cbdt_prime. */
+ unsigned int lstart; /* Start index in lengths. */
+ unsigned int lcount; /* Number of length entries. */
+ };
+
+ static uint64_t hash (unsigned int image_format,
+ const hb_vector_t &data,
+ const hb_vector_t &lengths)
+ {
+ uint32_t h = hb_hash (hb_bytes_t (data.arrayZ, data.length));
+ h = h * 31 + hb_hash (hb_bytes_t ((const char *) lengths.arrayZ,
+ lengths.length * sizeof (unsigned int)));
+ return ((uint64_t) image_format << 32) | h;
+ }
+
+ bool find (uint64_t key,
+ const hb_vector_t &data,
+ const hb_vector_t &lengths,
+ const hb_vector_t &cbdt_prime,
+ unsigned int *base /* OUT */) const
+ {
+ unsigned int *idx_p = nullptr;
+ if (!map.has (key, &idx_p)) return false;
+ const entry_t &e = entries[*idx_p];
+ /* The data and the per-glyph lengths must both match, otherwise the
+ * glyph extents implied by the offset array would differ. */
+ if (e.lcount != lengths.length) return false;
+ if (unlikely (e.base + data.length > (unsigned int) cbdt_prime.length)) return false;
+ if (hb_memcmp (cbdt_prime.arrayZ + e.base, data.arrayZ, data.length)) return false;
+ if (hb_memcmp (this->lengths.arrayZ + e.lstart,
+ lengths.arrayZ, lengths.length * sizeof (unsigned int)))
+ return false;
+ *base = e.base;
+ return true;
+ }
+
+ bool add (uint64_t key,
+ unsigned int base,
+ const hb_vector_t &lengths)
+ {
+ if (unlikely (entries.in_error () || this->lengths.in_error () || map.in_error ()))
+ return false;
+ entry_t e = {base, this->lengths.length, lengths.length};
+ if (unlikely (!entries.push_or_fail (e))) return false;
+ for (unsigned int length : lengths)
+ if (unlikely (!this->lengths.push_or_fail (length))) return false;
+ return map.set (key, entries.length - 1);
+ }
+
+ hb_hashmap_t map;
+ hb_vector_t entries;
+ hb_vector_t lengths; /* Concatenated per-entry lengths. */
+};
+
struct cblc_bitmap_size_subset_context_t
{
const char *cbdt;
@@ -59,6 +120,7 @@ struct cblc_bitmap_size_subset_context_t
*/
hb_codepoint_t start_glyph; /* OUT */
hb_codepoint_t end_glyph; /* OUT */
+ cbdt_dedup_context_t *dedup; /* Shared across strikes; may be null. */
};
static inline bool
@@ -207,26 +269,26 @@ struct IndexSubtable
hb_barrier ();
switch (u.header.indexFormat)
{
- case 1: return_trace (u.format1.sanitize (c, glyph_count));
- case 3: return_trace (u.format3.sanitize (c, glyph_count));
+ case 1: hb_barrier (); return_trace (u.format1.sanitize (c, glyph_count));
+ case 3: hb_barrier (); return_trace (u.format3.sanitize (c, glyph_count));
default:return_trace (true);
}
}
bool
finish_subtable (hb_serialize_context_t *c,
- unsigned int cbdt_prime_len,
+ unsigned int end_offset,
unsigned int num_glyphs,
unsigned int *size /* OUT (accumulated) */)
{
TRACE_SERIALIZE (this);
- unsigned int local_offset = cbdt_prime_len - u.header.imageDataOffset;
switch (u.header.indexFormat)
{
- case 1: return_trace (u.format1.add_offset (c, local_offset, size));
+ case 1: hb_barrier (); return_trace (u.format1.add_offset (c, end_offset, size));
case 3: {
- if (!u.format3.add_offset (c, local_offset, size))
+ hb_barrier ();
+ if (!u.format3.add_offset (c, end_offset, size))
return_trace (false);
if (!(num_glyphs & 0x01)) // Pad to 32-bit alignment if needed.
return_trace (u.format3.add_offset (c, 0, size));
@@ -239,63 +301,6 @@ struct IndexSubtable
}
}
- bool
- fill_missing_glyphs (hb_serialize_context_t *c,
- unsigned int cbdt_prime_len,
- unsigned int num_missing,
- unsigned int *size /* OUT (accumulated) */,
- unsigned int *num_glyphs /* OUT (accumulated) */)
- {
- TRACE_SERIALIZE (this);
-
- unsigned int local_offset = cbdt_prime_len - u.header.imageDataOffset;
- switch (u.header.indexFormat)
- {
- case 1: {
- for (unsigned int i = 0; i < num_missing; i++)
- {
- if (unlikely (!u.format1.add_offset (c, local_offset, size)))
- return_trace (false);
- *num_glyphs += 1;
- }
- return_trace (true);
- }
- case 3: {
- for (unsigned int i = 0; i < num_missing; i++)
- {
- if (unlikely (!u.format3.add_offset (c, local_offset, size)))
- return_trace (false);
- *num_glyphs += 1;
- }
- return_trace (true);
- }
- // TODO: implement 2, 4, 5.
- case 2: // Add empty space in cbdt_prime?.
- case 4: case 5: // No-op as sparse is supported.
- default: return_trace (false);
- }
- }
-
- bool
- copy_glyph_at_idx (hb_serialize_context_t *c, unsigned int idx,
- const char *cbdt, unsigned int cbdt_length,
- hb_vector_t *cbdt_prime /* INOUT */,
- IndexSubtable *subtable_prime /* INOUT */,
- unsigned int *size /* OUT (accumulated) */) const
- {
- TRACE_SERIALIZE (this);
-
- unsigned int offset, length, format;
- if (unlikely (!get_image_data (idx, &offset, &length, &format))) return_trace (false);
- if (unlikely (offset > cbdt_length || cbdt_length - offset < length)) return_trace (false);
-
- auto *header_prime = subtable_prime->get_header ();
- unsigned int new_local_offset = cbdt_prime->length - (unsigned int) header_prime->imageDataOffset;
- if (unlikely (!_copy_data_to_cbdt (cbdt_prime, cbdt + offset, length))) return_trace (false);
-
- return_trace (subtable_prime->add_offset (c, new_local_offset, size));
- }
-
bool
add_offset (hb_serialize_context_t *c, unsigned int local_offset,
unsigned int *size /* OUT (accumulated) */)
@@ -303,8 +308,8 @@ struct IndexSubtable
TRACE_SERIALIZE (this);
switch (u.header.indexFormat)
{
- case 1: return_trace (u.format1.add_offset (c, local_offset, size));
- case 3: return_trace (u.format3.add_offset (c, local_offset, size));
+ case 1: hb_barrier (); return_trace (u.format1.add_offset (c, local_offset, size));
+ case 3: hb_barrier (); return_trace (u.format3.add_offset (c, local_offset, size));
// TODO: Implement tables 2, 4, 5
case 2: // Should be a no-op.
case 4: case 5: // Handle sparse cases.
@@ -329,8 +334,8 @@ struct IndexSubtable
*format = u.header.imageFormat;
switch (u.header.indexFormat)
{
- case 1: return u.format1.get_image_data (idx, offset, length);
- case 3: return u.format3.get_image_data (idx, offset, length);
+ case 1: hb_barrier (); return u.format1.get_image_data (idx, offset, length);
+ case 3: hb_barrier (); return u.format3.get_image_data (idx, offset, length);
default: return false;
}
}
@@ -403,12 +408,13 @@ struct IndexSubtableRecord
auto *old_subtable = get_subtable (base);
auto *old_header = old_subtable->get_header ();
+ unsigned int image_format = old_header->imageFormat;
- subtable->populate_header (old_header->indexFormat,
- old_header->imageFormat,
- bitmap_size_context->cbdt_prime->length,
- &bitmap_size_context->size);
-
+ /* Collect this subtable's image data and the length of each glyph's block
+ * (zero for glyphs without data). This allows an earlier identical
+ * subtable to share the same data. */
+ hb_vector_t data;
+ hb_vector_t lengths;
unsigned int num_glyphs = 0;
bool early_exit = false;
for (unsigned int i = *start; i < lookup->length; i++)
@@ -424,12 +430,9 @@ struct IndexSubtableRecord
break;
}
unsigned int num_missing = record->add_glyph_for_subset (new_gid);
- if (unlikely (!subtable->fill_missing_glyphs (c->serializer,
- bitmap_size_context->cbdt_prime->length,
- num_missing,
- &bitmap_size_context->size,
- &num_glyphs)))
- return_trace (false);
+ for (unsigned int j = 0; j < num_missing; j++)
+ if (unlikely (!c->serializer->check_success (lengths.push_or_fail (0))))
+ return_trace (false);
hb_codepoint_t old_gid = 0;
c->plan->old_gid_for_new_gid (new_gid, &old_gid);
@@ -437,20 +440,65 @@ struct IndexSubtableRecord
return_trace (false);
unsigned int old_idx = (unsigned int) old_gid - next_record->firstGlyphIndex;
- if (unlikely (!next_subtable->copy_glyph_at_idx (c->serializer,
- old_idx,
- bitmap_size_context->cbdt,
- bitmap_size_context->cbdt_length,
- bitmap_size_context->cbdt_prime,
- subtable,
- &bitmap_size_context->size)))
+ unsigned int offset, length, format;
+ if (unlikely (!next_subtable->get_image_data (old_idx, &offset, &length, &format)))
+ return_trace (false);
+ if (unlikely (offset > bitmap_size_context->cbdt_length ||
+ bitmap_size_context->cbdt_length - offset < length))
+ return_trace (false);
+ if (unlikely (!c->serializer->check_success (
+ _copy_data_to_cbdt (&data,
+ bitmap_size_context->cbdt + offset,
+ length))))
return_trace (false);
- num_glyphs += 1;
+ if (unlikely (!c->serializer->check_success (lengths.push_or_fail (length))))
+ return_trace (false);
+ num_glyphs += 1 + num_missing;
}
if (!early_exit)
*start = lookup->length;
+
+ /* Find or append the data block for this subtable. */
+ unsigned int image_data_offset;
+ cbdt_dedup_context_t *dedup = bitmap_size_context->dedup;
+ bool shared = false;
+ uint64_t key = 0;
+ if (dedup && data.length)
+ {
+ key = cbdt_dedup_context_t::hash (image_format, data, lengths);
+ shared = dedup->find (key, data, lengths,
+ *bitmap_size_context->cbdt_prime,
+ &image_data_offset);
+ }
+ if (!shared)
+ {
+ image_data_offset = bitmap_size_context->cbdt_prime->length;
+ if (unlikely (!c->serializer->check_success (
+ _copy_data_to_cbdt (bitmap_size_context->cbdt_prime,
+ data.arrayZ, data.length))))
+ return_trace (false);
+ if (dedup && data.length)
+ /* The bitmap data is already copied; caching is best-effort. */
+ (void) dedup->add (key, image_data_offset, lengths);
+ }
+
+ subtable->populate_header (old_header->indexFormat,
+ image_format,
+ image_data_offset,
+ &bitmap_size_context->size);
+
+ /* Glyphs without data use the offset of the following block's start,
+ * which yields a zero length span, matching the old behavior. */
+ unsigned int cumulative = 0;
+ for (unsigned int length : lengths)
+ {
+ if (unlikely (!subtable->add_offset (c->serializer, cumulative,
+ &bitmap_size_context->size)))
+ return_trace (false);
+ cumulative += length;
+ }
if (unlikely (!subtable->finish_subtable (c->serializer,
- bitmap_size_context->cbdt_prime->length,
+ cumulative,
num_glyphs,
&bitmap_size_context->size)))
return_trace (false);
@@ -653,7 +701,8 @@ struct BitmapSizeTable
bool
subset (hb_subset_context_t *c, const void *base,
const char *cbdt, unsigned int cbdt_length,
- hb_vector_t *cbdt_prime /* INOUT */) const
+ hb_vector_t *cbdt_prime /* INOUT */,
+ cbdt_dedup_context_t *dedup /* INOUT */) const
{
TRACE_SUBSET (this);
auto *out_table = c->serializer->embed (this);
@@ -667,6 +716,7 @@ struct BitmapSizeTable
bitmap_size_context.num_tables = numberOfIndexSubtables;
bitmap_size_context.start_glyph = 1;
bitmap_size_context.end_glyph = 0;
+ bitmap_size_context.dedup = dedup;
if (!out_table->indexSubtableArrayOffset.serialize_subset (c,
indexSubtableArrayOffset,
@@ -764,7 +814,8 @@ struct CBLC
bool
subset_size_table (hb_subset_context_t *c, const BitmapSizeTable& table,
const char *cbdt /* IN */, unsigned int cbdt_length,
- CBLC *cblc_prime /* INOUT */, hb_vector_t *cbdt_prime /* INOUT */) const
+ CBLC *cblc_prime /* INOUT */, hb_vector_t *cbdt_prime /* INOUT */,
+ cbdt_dedup_context_t *dedup /* INOUT */) const
{
TRACE_SUBSET (this);
cblc_prime->sizeTables.len++;
@@ -772,7 +823,7 @@ struct CBLC
auto snap = c->serializer->snapshot ();
auto cbdt_prime_len = cbdt_prime->length;
- if (!table.subset (c, this, cbdt, cbdt_length, cbdt_prime))
+ if (!table.subset (c, this, cbdt, cbdt_length, cbdt_prime, dedup))
{
cblc_prime->sizeTables.len--;
c->serializer->revert (snap);
@@ -882,10 +933,10 @@ struct CBDT
{
float x_scale = upem / (float) strike.ppemX;
float y_scale = upem / (float) strike.ppemY;
- extents->x_bearing = roundf (extents->x_bearing * x_scale);
- extents->y_bearing = roundf (extents->y_bearing * y_scale);
- extents->width = roundf (extents->width * x_scale);
- extents->height = roundf (extents->height * y_scale);
+ extents->x_bearing = hb_clamp_to (roundf (extents->x_bearing * x_scale));
+ extents->y_bearing = hb_clamp_to (roundf (extents->y_bearing * y_scale));
+ extents->width = hb_clamp_to (roundf (extents->width * x_scale));
+ extents->height = hb_clamp_to (roundf (extents->height * y_scale));
}
return true;
@@ -1015,8 +1066,9 @@ CBLC::subset (hb_subset_context_t *c) const
}
_copy_data_to_cbdt (&cbdt_prime, cbdt, CBDT::min_size);
+ cbdt_dedup_context_t dedup;
for (const BitmapSizeTable& table : + sizeTables.iter ())
- subset_size_table (c, table, (const char *) cbdt, cbdt_length, cblc_prime, &cbdt_prime);
+ subset_size_table (c, table, (const char *) cbdt, cbdt_length, cblc_prime, &cbdt_prime, &dedup);
hb_blob_destroy (cbdt_blob);
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/COLR.hh b/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/COLR.hh
index 37bb8a8f9458..b62d63a478f6 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/COLR.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/COLR.hh
@@ -35,7 +35,9 @@
#include "../../../hb-paint.hh"
#include "../../../hb-paint-bounded.hh"
#include "../../../hb-paint-extents.hh"
+#include "../../../hb-depend-data.hh"
+#include "../../../hb-ot-dual.hh"
#include "../CPAL/CPAL.hh"
/*
@@ -119,6 +121,14 @@ public:
hb_font_destroy (font);
}
+ static unsigned
+ color_alpha (hb_color_t color, float alpha)
+ {
+ /* Font-supplied alpha is F2DOT14 plus variation deltas, so it can be
+ * negative or greater than one; converting that to unsigned is UB. */
+ return roundf (hb_color_get_alpha (color) * hb_clamp (alpha, 0.f, 1.f));
+ }
+
hb_color_t get_color (unsigned int color_index, float alpha, hb_bool_t *is_foreground)
{
hb_color_t color = foreground;
@@ -136,7 +146,7 @@ public:
return HB_COLOR (hb_color_get_blue (color),
hb_color_get_green (color),
hb_color_get_red (color),
- hb_color_get_alpha (color) * alpha);
+ color_alpha (color, alpha));
}
inline void recurse (const Paint &paint);
@@ -219,6 +229,58 @@ struct hb_colrv1_closure_context_t :
{}
};
+
+struct hb_colrv1_depend_context_t :
+ hb_dispatch_context_t
+{
+ template
+ return_t dispatch (const T &obj)
+ {
+ if (unlikely (nesting_level_left == 0))
+ return hb_empty_t ();
+
+ if (paint_visited (&obj))
+ return hb_empty_t ();
+
+ nesting_level_left--;
+ obj.dependv1 (this);
+ nesting_level_left++;
+ return hb_empty_t ();
+ }
+ static return_t default_return_value () { return hb_empty_t (); }
+
+ bool paint_visited (const void *paint)
+ {
+ hb_codepoint_t delta = (hb_codepoint_t) ((uintptr_t) paint - (uintptr_t) colr);
+ if (visited_paint.in_error() || visited_paint.has (delta))
+ return true;
+
+ visited_paint.add (delta);
+ if (unlikely (visited_paint.in_error ()))
+ depend_data->fail ();
+ return false;
+ }
+
+ const COLR* get_colr_table () const
+ { return colr; }
+
+ public:
+ const COLR *colr;
+ hb_depend_data_builder_t *depend_data;
+ hb_set_t visited_paint;
+ unsigned nesting_level_left;
+ hb_codepoint_t source_gid;
+
+ hb_colrv1_depend_context_t (const COLR *colr_,
+ hb_depend_data_builder_t *depend_data_,
+ unsigned nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
+ colr (colr_),
+ depend_data (depend_data_),
+ nesting_level_left (nesting_level_left_),
+ source_gid (0)
+ {}
+};
+
struct LayerRecord
{
operator hb_ot_color_layer_t () const { return {glyphId, colorIdx}; }
@@ -274,12 +336,17 @@ struct Variable
{
static constexpr bool is_variable = true;
+ const T& get_value () const { return value; }
+
Variable* copy (hb_serialize_context_t *c) const
{
TRACE_SERIALIZE (this);
return_trace (c->embed (this));
}
+ void dependv1 (hb_colrv1_depend_context_t* c) const
+ { value.dependv1 (c); }
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{
c->num_var_idxes = 0;
@@ -329,6 +396,12 @@ struct Variable
value.get_color_stop (c, stop, varIdxBase, instancer);
}
+ void get_solid_color (hb_paint_context_t *c,
+ hb_bool_t *is_foreground, hb_color_t *color) const
+ {
+ value.get_solid_color (c, varIdxBase, is_foreground, color);
+ }
+
hb_paint_extend_t get_extend () const
{
return value.get_extend ();
@@ -347,6 +420,8 @@ struct NoVariable
{
static constexpr bool is_variable = false;
+ const T& get_value () const { return value; }
+
static constexpr uint32_t varIdxBase = VarIdx::NO_VARIATION;
NoVariable* copy (hb_serialize_context_t *c) const
@@ -355,6 +430,9 @@ struct NoVariable
return_trace (c->embed (this));
}
+ void dependv1 (hb_colrv1_depend_context_t* c) const
+ { value.dependv1 (c); }
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{ value.closurev1 (c); }
@@ -384,6 +462,12 @@ struct NoVariable
value.get_color_stop (c, stop, VarIdx::NO_VARIATION, instancer);
}
+ void get_solid_color (hb_paint_context_t *c,
+ hb_bool_t *is_foreground, hb_color_t *color) const
+ {
+ value.get_solid_color (c, VarIdx::NO_VARIATION, is_foreground, color);
+ }
+
hb_paint_extend_t get_extend () const
{
return value.get_extend ();
@@ -396,8 +480,18 @@ struct NoVariable
// Color structures
+template
+static void
+set_fixed_clamped (HBFixed &out, float value)
+{
+ // Variation deltas are unbounded; clamp before the implicit integer cast.
+ out.set_int (hb_clamp_to (roundf ((value / HBFixed::mult))));
+}
+
struct ColorStop
{
+ void dependv1 (hb_colrv1_depend_context_t * c) const {}
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{
c->add_palette_index (paletteIndex);
@@ -414,8 +508,12 @@ struct ColorStop
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->stopOffset.set_float (stopOffset.to_float(instancer (varIdxBase, 0)));
- out->alpha.set_float (alpha.to_float (instancer (varIdxBase, 1)));
+ set_fixed_clamped (out->stopOffset, stopOffset.to_float(instancer (varIdxBase, 0)));
+ float a = alpha.to_float (instancer (varIdxBase, 1));
+ /* Partial instances must keep the unclamped base: retained axes can
+ * bring the alpha back into range. Clamp before narrowing a full
+ * instance so overflow cannot wrap an opaque alpha to transparent. */
+ set_fixed_clamped (out->alpha, c->plan->all_axes_pinned ? hb_clamp (a, 0.f, 1.f) : a);
}
return_trace (c->serializer->check_assign (out->paletteIndex, c->plan->colr_palettes.get (paletteIndex),
@@ -460,6 +558,8 @@ struct Extend : HBUINT8
template class Var>
struct ColorLine
{
+ void dependv1 (hb_colrv1_depend_context_t * c) const {}
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{
for (const auto &stop : stops.iter ())
@@ -555,44 +655,6 @@ struct ColorLine
// or all of the specified modes.
struct CompositeMode : HBUINT8
{
- enum {
- // Porter-Duff modes
- // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators
- COMPOSITE_CLEAR = 0, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_clear
- COMPOSITE_SRC = 1, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_src
- COMPOSITE_DEST = 2, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dst
- COMPOSITE_SRC_OVER = 3, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcover
- COMPOSITE_DEST_OVER = 4, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstover
- COMPOSITE_SRC_IN = 5, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcin
- COMPOSITE_DEST_IN = 6, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstin
- COMPOSITE_SRC_OUT = 7, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcout
- COMPOSITE_DEST_OUT = 8, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstout
- COMPOSITE_SRC_ATOP = 9, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcatop
- COMPOSITE_DEST_ATOP = 10, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_dstatop
- COMPOSITE_XOR = 11, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_xor
- COMPOSITE_PLUS = 12, // https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_plus
-
- // Blend modes
- // https://www.w3.org/TR/compositing-1/#blending
- COMPOSITE_SCREEN = 13, // https://www.w3.org/TR/compositing-1/#blendingscreen
- COMPOSITE_OVERLAY = 14, // https://www.w3.org/TR/compositing-1/#blendingoverlay
- COMPOSITE_DARKEN = 15, // https://www.w3.org/TR/compositing-1/#blendingdarken
- COMPOSITE_LIGHTEN = 16, // https://www.w3.org/TR/compositing-1/#blendinglighten
- COMPOSITE_COLOR_DODGE = 17, // https://www.w3.org/TR/compositing-1/#blendingcolordodge
- COMPOSITE_COLOR_BURN = 18, // https://www.w3.org/TR/compositing-1/#blendingcolorburn
- COMPOSITE_HARD_LIGHT = 19, // https://www.w3.org/TR/compositing-1/#blendinghardlight
- COMPOSITE_SOFT_LIGHT = 20, // https://www.w3.org/TR/compositing-1/#blendingsoftlight
- COMPOSITE_DIFFERENCE = 21, // https://www.w3.org/TR/compositing-1/#blendingdifference
- COMPOSITE_EXCLUSION = 22, // https://www.w3.org/TR/compositing-1/#blendingexclusion
- COMPOSITE_MULTIPLY = 23, // https://www.w3.org/TR/compositing-1/#blendingmultiply
-
- // Modes that, uniquely, do not operate on components
- // https://www.w3.org/TR/compositing-1/#blendingnonseparable
- COMPOSITE_HSL_HUE = 24, // https://www.w3.org/TR/compositing-1/#blendinghue
- COMPOSITE_HSL_SATURATION = 25, // https://www.w3.org/TR/compositing-1/#blendingsaturation
- COMPOSITE_HSL_COLOR = 26, // https://www.w3.org/TR/compositing-1/#blendingcolor
- COMPOSITE_HSL_LUMINOSITY = 27, // https://www.w3.org/TR/compositing-1/#blendingluminosity
- };
public:
DEFINE_SIZE_STATIC (1);
};
@@ -605,6 +667,8 @@ struct Affine2x3
return_trace (c->check_struct (this));
}
+ void dependv1 (hb_colrv1_depend_context_t* c) const {}
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{ c->num_var_idxes = 6; }
@@ -617,12 +681,17 @@ struct Affine2x3
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->xx.set_float (xx.to_float(instancer (varIdxBase, 0)));
- out->yx.set_float (yx.to_float(instancer (varIdxBase, 1)));
- out->xy.set_float (xy.to_float(instancer (varIdxBase, 2)));
- out->yy.set_float (yy.to_float(instancer (varIdxBase, 3)));
- out->dx.set_float (dx.to_float(instancer (varIdxBase, 4)));
- out->dy.set_float (dy.to_float(instancer (varIdxBase, 5)));
+ auto fold = [&] (F16DOT16 &target, F16DOT16 source, unsigned offset) {
+ // Keep the stored integer precise while applying the float delta.
+ target.set_int (hb_clamp_to (roundf ((double) source.to_int () +
+ (double) instancer (varIdxBase, offset))));
+ };
+ fold (out->xx, xx, 0);
+ fold (out->yx, yx, 1);
+ fold (out->xy, xy, 2);
+ fold (out->yy, yy, 3);
+ fold (out->dx, dx, 4);
+ fold (out->dy, dy, 5);
}
return_trace (true);
}
@@ -651,7 +720,8 @@ struct Affine2x3
struct PaintColrLayers
{
- void closurev1 (hb_colrv1_closure_context_t* c) const;
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
+ HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
const ItemVarStoreInstancer &instancer HB_UNUSED) const
@@ -682,6 +752,7 @@ struct PaintColrLayers
struct PaintSolid
{
+ void dependv1 (hb_colrv1_depend_context_t* c) const {}
void closurev1 (hb_colrv1_closure_context_t* c) const
{
c->add_palette_index (paletteIndex);
@@ -697,7 +768,10 @@ struct PaintSolid
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
- out->alpha.set_float (alpha.to_float (instancer (varIdxBase, 0)));
+ {
+ float a = alpha.to_float (instancer (varIdxBase, 0));
+ set_fixed_clamped (out->alpha, c->plan->all_axes_pinned ? hb_clamp (a, 0.f, 1.f) : a);
+ }
if (format == 3 && c->plan->all_axes_pinned)
out->format = 2;
@@ -712,15 +786,21 @@ struct PaintSolid
return_trace (c->check_struct (this));
}
+ void get_solid_color (hb_paint_context_t *c, uint32_t varIdxBase,
+ hb_bool_t *is_foreground, hb_color_t *color) const
+ {
+ *color = c->get_color (paletteIndex,
+ alpha.to_float (c->instancer (varIdxBase, 0)),
+ is_foreground);
+ }
+
void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const
{
TRACE_PAINT (this);
hb_bool_t is_foreground;
hb_color_t color;
- color = c->get_color (paletteIndex,
- alpha.to_float (c->instancer (varIdxBase, 0)),
- &is_foreground);
+ get_solid_color (c, varIdxBase, &is_foreground, &color);
c->funcs->color (c->data, is_foreground, color);
}
@@ -734,6 +814,8 @@ struct PaintSolid
template class Var>
struct PaintLinearGradient
{
+ void dependv1 (hb_colrv1_depend_context_t* c) const {}
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{
(this+colorLine).closurev1 (c);
@@ -750,12 +832,12 @@ struct PaintLinearGradient
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->x0 = x0 + (int) roundf (instancer (varIdxBase, 0));
- out->y0 = y0 + (int) roundf (instancer (varIdxBase, 1));
- out->x1 = x1 + (int) roundf (instancer (varIdxBase, 2));
- out->y1 = y1 + (int) roundf (instancer (varIdxBase, 3));
- out->x2 = x2 + (int) roundf (instancer (varIdxBase, 4));
- out->y2 = y2 + (int) roundf (instancer (varIdxBase, 5));
+ out->x0 = hb_clamp_to ((double) x0 + (double) roundf (instancer (varIdxBase, 0)));
+ out->y0 = hb_clamp_to ((double) y0 + (double) roundf (instancer (varIdxBase, 1)));
+ out->x1 = hb_clamp_to ((double) x1 + (double) roundf (instancer (varIdxBase, 2)));
+ out->y1 = hb_clamp_to ((double) y1 + (double) roundf (instancer (varIdxBase, 3)));
+ out->x2 = hb_clamp_to ((double) x2 + (double) roundf (instancer (varIdxBase, 4)));
+ out->y2 = hb_clamp_to ((double) y2 + (double) roundf (instancer (varIdxBase, 5)));
}
if (format == 5 && c->plan->all_axes_pinned)
@@ -804,28 +886,189 @@ struct PaintLinearGradient
template class Var>
struct PaintRadialGradient
{
+ bool constant_after_pinning (hb_subset_context_t *c,
+ const ItemVarStoreInstancer &instancer) const
+ {
+ if (c->plan->has_avar2) return false;
+ const auto ®ions = instancer.varStore->get_region_list ();
+ for (unsigned i = 0; i < regions.regionCount; i++)
+ {
+ hb_hashmap_t axes;
+ if (!regions.get_var_region (i, c->plan->axes_old_index_tag_map, axes))
+ {
+ c->serializer->err (HB_SERIALIZE_ERROR_OUT_OF_ROOM);
+ return false;
+ }
+ for (auto axis : axes)
+ {
+ Triple *limit;
+ if (!c->plan->user_axes_location.has (axis.first, &limit) ||
+ limit->minimum != limit->maximum)
+ return false;
+ }
+ }
+ return true;
+ }
+
+ void dependv1 (hb_colrv1_depend_context_t* c) const {}
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{
(this+colorLine).closurev1 (c);
c->num_var_idxes = 6;
}
+ bool subset_nonnegative (hb_subset_context_t *c,
+ const ItemVarStoreInstancer &instancer,
+ uint32_t varIdxBase) const
+ {
+ double source[6] = {
+ x0 + (double) roundf (instancer (varIdxBase, 0)),
+ y0 + (double) roundf (instancer (varIdxBase, 1)),
+ radius0 + (double) roundf (instancer (varIdxBase, 2)),
+ x1 + (double) roundf (instancer (varIdxBase, 3)),
+ y1 + (double) roundf (instancer (varIdxBase, 4)),
+ radius1 + (double) roundf (instancer (varIdxBase, 5))
+ };
+ auto transparent = [&] {
+ auto *out = c->serializer->allocate_size (5);
+ if (!out) return false;
+ out->format = 2; out->paletteIndex = 0xFFFF; out->alpha.set_float (0);
+ return true;
+ };
+ const auto &line = this+colorLine;
+ if (source[2] == source[5] || !line.stops.len) return transparent ();
+ struct stop_t { double offset, alpha; unsigned palette, order; };
+ hb_vector_t stops;
+ if (!stops.alloc (line.stops.len)) return false;
+ unsigned order = 0;
+ for (const auto &entry : line.stops.iter ())
+ {
+ const auto &stop = entry.get_value ();
+ stops.push (stop_t {(double) roundf (stop.stopOffset.to_float (instancer (entry.varIdxBase, 0)) * 16384.f) / 16384.,
+ (double) hb_clamp (stop.alpha.to_float (instancer (entry.varIdxBase, 1)), 0.f, 1.f),
+ stop.paletteIndex, order++});
+ }
+ if (stops.in_error ()) return false;
+ stops.qsort ([] (const stop_t &a, const stop_t &b) {
+ return a.offset < b.offset ? -1 : a.offset > b.offset ? 1 :
+ a.order < b.order ? -1 : a.order > b.order ? 1 : 0;
+ });
+ double dr = source[5] - source[2];
+ // Fractional shifts must preserve both integer circles and F2Dot14 stops.
+ unsigned lattice = 16384;
+ for (unsigned j = 0; j < 3; j++)
+ {
+ double remainder = fmod (fabs (source[j + 3] - source[j]), 16384.);
+ if (!(remainder >= 0 && remainder < 16384))
+ {
+ c->serializer->err (HB_SERIALIZE_ERROR_INT_OVERFLOW);
+ return false;
+ }
+ unsigned right = (unsigned) remainder;
+ while (right) { unsigned r = lattice % right; lattice = right; right = r; }
+ }
+ for (unsigned shift = 0; shift < 16; shift++)
+ {
+ double b = 1u << shift;
+ double coarse = dr > 0 ? ceil (-source[2] / dr) : floor (source[2] / -dr) - b;
+ double fine = dr > 0 ? ceil (-source[2] / dr * lattice) / lattice :
+ floor (source[2] / -dr * lattice) / lattice - b;
+ double candidates[] = {coarse, fine};
+ for (double a : candidates)
+ {
+ // omega = a + b*q. Positive b preserves the largest valid root.
+ double geometry[6];
+ bool fits = true;
+ for (unsigned j = 0; j < 3; j++)
+ {
+ double difference = source[j + 3] - source[j];
+ geometry[j] = source[j] + a * difference;
+ geometry[j + 3] = source[j] + (a + b) * difference;
+ double low = j == 2 ? 0 : -32768, high = j == 2 ? 65535 : 32767;
+ fits &= geometry[j] >= low && geometry[j] <= high &&
+ geometry[j + 3] >= low && geometry[j + 3] <= high;
+ }
+ if (!fits) continue;
+ unsigned first = 0, count = stops.length;
+ double min = (stops[0].offset - a) / b, max = (stops.tail ().offset - a) / b;
+ double bias = 0;
+ bool constant = false;
+ if (line.extend == Extend::EXTEND_PAD)
+ {
+ double tip = -geometry[2] / (b * dr);
+ if ((dr > 0 && max <= tip) || (dr < 0 && min > tip))
+ {
+ first = dr > 0 ? stops.length - 1 : 0;
+ count = 1; constant = true;
+ }
+ }
+ else
+ {
+ double period = max - min;
+ if (line.extend == Extend::EXTEND_REFLECT) period *= 2;
+ if (period <= 0) return transparent ();
+ double n = ceil ((-2 - min) / period);
+ if (n > floor ((32767. / 16384. - max) / period)) continue;
+ bias = n * period;
+ }
+ for (unsigned j = 0; j < count; j++)
+ {
+ double bits = constant ? 0 : ((stops[first + j].offset - a) / b + bias) * 16384;
+ fits &= bits >= -32768 && bits <= 32767 && bits == round (bits);
+ }
+ if (!fits) continue;
+ auto *out = c->serializer->allocate_size> (16);
+ if (!out) return false;
+ out->format = 6;
+ out->x0 = (int) geometry[0]; out->y0 = (int) geometry[1]; out->radius0 = (unsigned) geometry[2];
+ out->x1 = (int) geometry[3]; out->y1 = (int) geometry[4]; out->radius1 = (unsigned) geometry[5];
+ c->serializer->push ();
+ auto *out_line = c->serializer->allocate_size> (3 + count * ColorStop::static_size);
+ if (!out_line) { c->serializer->pop_discard (); return false; }
+ out_line->extend = line.extend;
+ out_line->stops.len = count;
+ for (unsigned j = 0; j < count; j++)
+ {
+ const auto &stop = stops[first + j];
+ auto &out_stop = out_line->stops[j].value;
+ out_stop.stopOffset.set_float ((float) (constant ? 0 : (stop.offset - a) / b + bias));
+ out_stop.alpha.set_float ((float) stop.alpha);
+ if (!c->serializer->check_assign (out_stop.paletteIndex, c->plan->colr_palettes.get (stop.palette),
+ HB_SERIALIZE_ERROR_INT_OVERFLOW))
+ { c->serializer->pop_discard (); return false; }
+ }
+ c->serializer->add_link (out->colorLine, c->serializer->pop_pack ());
+ return !c->serializer->in_error ();
+ }
+ }
+ // Reject an unrepresentable static result instead of changing its colors.
+ c->serializer->err (HB_SERIALIZE_ERROR_INT_OVERFLOW);
+ return false;
+ }
+
bool subset (hb_subset_context_t *c,
const ItemVarStoreInstancer &instancer,
uint32_t varIdxBase) const
{
TRACE_SUBSET (this);
+ if (instancer && !c->plan->pinned_at_default &&
+ (c->plan->all_axes_pinned || constant_after_pinning (c, instancer)) &&
+ varIdxBase != VarIdx::NO_VARIATION &&
+ (radius0 + (double) roundf (instancer (varIdxBase, 2)) < 0 ||
+ radius1 + (double) roundf (instancer (varIdxBase, 5)) < 0))
+ return_trace (subset_nonnegative (c, instancer, varIdxBase));
auto *out = c->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->x0 = x0 + (int) roundf (instancer (varIdxBase, 0));
- out->y0 = y0 + (int) roundf (instancer (varIdxBase, 1));
- out->radius0 = radius0 + (unsigned) roundf (instancer (varIdxBase, 2));
- out->x1 = x1 + (int) roundf (instancer (varIdxBase, 3));
- out->y1 = y1 + (int) roundf (instancer (varIdxBase, 4));
- out->radius1 = radius1 + (unsigned) roundf (instancer (varIdxBase, 5));
+ out->x0 = hb_clamp_to ((double) x0 + (double) roundf (instancer (varIdxBase, 0)));
+ out->y0 = hb_clamp_to ((double) y0 + (double) roundf (instancer (varIdxBase, 1)));
+ out->radius0 = hb_clamp_to ((double) radius0 + (double) roundf (instancer (varIdxBase, 2)));
+ out->x1 = hb_clamp_to ((double) x1 + (double) roundf (instancer (varIdxBase, 3)));
+ out->y1 = hb_clamp_to ((double) y1 + (double) roundf (instancer (varIdxBase, 4)));
+ out->radius1 = hb_clamp_to ((double) radius1 + (double) roundf (instancer (varIdxBase, 5)));
}
if (format == 7 && c->plan->all_axes_pinned)
@@ -874,6 +1117,8 @@ struct PaintRadialGradient
template class Var>
struct PaintSweepGradient
{
+ void dependv1 (hb_colrv1_depend_context_t* c) const {}
+
void closurev1 (hb_colrv1_closure_context_t* c) const
{
(this+colorLine).closurev1 (c);
@@ -890,10 +1135,10 @@ struct PaintSweepGradient
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->centerX = centerX + (int) roundf (instancer (varIdxBase, 0));
- out->centerY = centerY + (int) roundf (instancer (varIdxBase, 1));
- out->startAngle.set_float (startAngle.to_float (instancer (varIdxBase, 2)));
- out->endAngle.set_float (endAngle.to_float (instancer (varIdxBase, 3)));
+ out->centerX = hb_clamp_to ((double) centerX + (double) roundf (instancer (varIdxBase, 0)));
+ out->centerY = hb_clamp_to ((double) centerY + (double) roundf (instancer (varIdxBase, 1)));
+ set_fixed_clamped (out->startAngle, startAngle.to_float (instancer (varIdxBase, 2)));
+ set_fixed_clamped (out->endAngle, endAngle.to_float (instancer (varIdxBase, 3)));
}
if (format == 9 && c->plan->all_axes_pinned)
@@ -936,9 +1181,13 @@ struct PaintSweepGradient
};
// Paint a non-COLR glyph, filled as indicated by paint.
+template
struct PaintGlyph
{
- void closurev1 (hb_colrv1_closure_context_t* c) const;
+ using HBGlyphID = typename Types::HBGlyphID;
+
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
+ HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
const ItemVarStoreInstancer &instancer) const
@@ -960,28 +1209,19 @@ struct PaintGlyph
return_trace (c->check_struct (this) && paint.sanitize (c, this));
}
- void paint_glyph (hb_paint_context_t *c) const
- {
- TRACE_PAINT (this);
- c->funcs->push_inverse_font_transform (c->data, c->font);
- c->funcs->push_clip_glyph (c->data, gid, c->font);
- c->funcs->push_font_transform (c->data, c->font);
- c->recurse (this+paint);
- c->funcs->pop_transform (c->data);
- c->funcs->pop_clip (c->data);
- c->funcs->pop_transform (c->data);
- }
+ inline void paint_glyph (hb_paint_context_t *c) const;
- HBUINT8 format; /* format = 10 */
+ HBUINT8 format; /* format = 10 or 33 */
Offset24To paint; /* Offset (from beginning of PaintGlyph table) to Paint subtable. */
- HBUINT16 gid;
+ HBGlyphID gid;
public:
- DEFINE_SIZE_STATIC (6);
+ DEFINE_SIZE_STATIC (4 + HBGlyphID::static_size);
};
struct PaintColrGlyph
{
- void closurev1 (hb_colrv1_closure_context_t* c) const;
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
+ HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
const ItemVarStoreInstancer &instancer HB_UNUSED) const
@@ -1011,6 +1251,7 @@ struct PaintColrGlyph
template class Var>
struct PaintTransform
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1050,6 +1291,7 @@ struct PaintTransform
struct PaintTranslate
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1062,8 +1304,8 @@ struct PaintTranslate
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->dx = dx + (int) roundf (instancer (varIdxBase, 0));
- out->dy = dy + (int) roundf (instancer (varIdxBase, 1));
+ out->dx = hb_clamp_to ((double) dx + (double) roundf (instancer (varIdxBase, 0)));
+ out->dy = hb_clamp_to ((double) dy + (double) roundf (instancer (varIdxBase, 1)));
}
if (format == 15 && c->plan->all_axes_pinned)
@@ -1097,8 +1339,73 @@ struct PaintTranslate
DEFINE_SIZE_STATIC (4 + 2 * FWORD::static_size);
};
+template
+static bool serialize_scale_transform (hb_subset_context_t *c,
+ float sx, float sy, float dx, float dy,
+ const Source &source)
+{
+ auto *out = c->serializer->allocate_size> (7);
+ if (unlikely (!out)) return false;
+ out->format = 12;
+
+ c->serializer->push ();
+ auto *transform = c->serializer->allocate_size (Affine2x3::static_size);
+ if (unlikely (!transform))
+ {
+ c->serializer->pop_discard ();
+ return false;
+ }
+ set_fixed_clamped (transform->xx, sx);
+ transform->yx.set_float (0);
+ transform->xy.set_float (0);
+ set_fixed_clamped (transform->yy, sy);
+ set_fixed_clamped (transform->dx, dx);
+ set_fixed_clamped (transform->dy, dy);
+ c->serializer->add_link (out->transform, c->serializer->pop_pack ());
+
+ c->serializer->push ();
+ bool ret = source ();
+ if (ret)
+ c->serializer->add_link (out->src, c->serializer->pop_pack ());
+ else
+ c->serializer->pop_discard ();
+ return ret;
+}
+
+template
+static bool subset_scale_as_transform (hb_subset_context_t *c,
+ const Base *base,
+ const Offset24To &src,
+ const ItemVarStoreInstancer &instancer,
+ float sx, float sy,
+ float cx = 0, float cy = 0)
+{
+ if (src.is_null ()) return false;
+ auto source = [&] { return c->dispatch (base+src, instancer); };
+ float dx = cx * (1 - sx), dy = cy * (1 - sy);
+ if (dx >= -32768 && dx < 32768 && dy >= -32768 && dy < 32768)
+ return serialize_scale_transform (c, sx, sy, dx, dy, source);
+
+ // Preserve the center as separate translations when the combined matrix
+ // exceeds Fixed. Splitting also makes the inverse of -32768 representable.
+ auto inner = [&] {
+ return serialize_scale_transform (c, 1, 1, -cx / 2, -cy / 2, source);
+ };
+ auto inverse = [&] {
+ return serialize_scale_transform (c, 1, 1, -cx / 2, -cy / 2, inner);
+ };
+ auto scale = [&] {
+ return serialize_scale_transform (c, sx, sy, 0, 0, inverse);
+ };
+ auto outer = [&] {
+ return serialize_scale_transform (c, 1, 1, cx / 2, cy / 2, scale);
+ };
+ return serialize_scale_transform (c, 1, 1, cx / 2, cy / 2, outer);
+}
+
struct PaintScale
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1106,13 +1413,21 @@ struct PaintScale
uint32_t varIdxBase) const
{
TRACE_SUBSET (this);
+ if (c->plan->all_axes_pinned && instancer &&
+ !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
+ {
+ float sx = roundf (scaleX.to_float (instancer (varIdxBase, 0)) * 16384) / 16384;
+ float sy = roundf (scaleY.to_float (instancer (varIdxBase, 1)) * 16384) / 16384;
+ if (sx < -2 || sx >= 2 || sy < -2 || sy >= 2)
+ return_trace (subset_scale_as_transform (c, this, src, instancer, sx, sy));
+ }
auto *out = c->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->scaleX.set_float (scaleX.to_float (instancer (varIdxBase, 0)));
- out->scaleY.set_float (scaleY.to_float (instancer (varIdxBase, 1)));
+ set_fixed_clamped (out->scaleX, scaleX.to_float (instancer (varIdxBase, 0)));
+ set_fixed_clamped (out->scaleY, scaleY.to_float (instancer (varIdxBase, 1)));
}
if (format == 17 && c->plan->all_axes_pinned)
@@ -1148,6 +1463,7 @@ struct PaintScale
struct PaintScaleAroundCenter
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1155,15 +1471,26 @@ struct PaintScaleAroundCenter
uint32_t varIdxBase) const
{
TRACE_SUBSET (this);
+ if (c->plan->all_axes_pinned && instancer &&
+ !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
+ {
+ float sx = roundf (scaleX.to_float (instancer (varIdxBase, 0)) * 16384) / 16384;
+ float sy = roundf (scaleY.to_float (instancer (varIdxBase, 1)) * 16384) / 16384;
+ if (sx < -2 || sx >= 2 || sy < -2 || sy >= 2)
+ return_trace (subset_scale_as_transform (
+ c, this, src, instancer, sx, sy,
+ centerX + roundf (instancer (varIdxBase, 2)),
+ centerY + roundf (instancer (varIdxBase, 3))));
+ }
auto *out = c->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->scaleX.set_float (scaleX.to_float (instancer (varIdxBase, 0)));
- out->scaleY.set_float (scaleY.to_float (instancer (varIdxBase, 1)));
- out->centerX = centerX + (int) roundf (instancer (varIdxBase, 2));
- out->centerY = centerY + (int) roundf (instancer (varIdxBase, 3));
+ set_fixed_clamped (out->scaleX, scaleX.to_float (instancer (varIdxBase, 0)));
+ set_fixed_clamped (out->scaleY, scaleY.to_float (instancer (varIdxBase, 1)));
+ out->centerX = hb_clamp_to ((double) centerX + (double) roundf (instancer (varIdxBase, 2)));
+ out->centerY = hb_clamp_to ((double) centerY + (double) roundf (instancer (varIdxBase, 3)));
}
if (format == 19 && c->plan->all_axes_pinned)
@@ -1203,6 +1530,7 @@ struct PaintScaleAroundCenter
struct PaintScaleUniform
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1210,11 +1538,18 @@ struct PaintScaleUniform
uint32_t varIdxBase) const
{
TRACE_SUBSET (this);
+ if (c->plan->all_axes_pinned && instancer &&
+ !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
+ {
+ float s = roundf (scale.to_float (instancer (varIdxBase, 0)) * 16384) / 16384;
+ if (s < -2 || s >= 2)
+ return_trace (subset_scale_as_transform (c, this, src, instancer, s, s));
+ }
auto *out = c->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
- out->scale.set_float (scale.to_float (instancer (varIdxBase, 0)));
+ set_fixed_clamped (out->scale, scale.to_float (instancer (varIdxBase, 0)));
if (format == 21 && c->plan->all_axes_pinned)
out->format = 20;
@@ -1247,6 +1582,7 @@ struct PaintScaleUniform
struct PaintScaleUniformAroundCenter
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1254,14 +1590,24 @@ struct PaintScaleUniformAroundCenter
uint32_t varIdxBase) const
{
TRACE_SUBSET (this);
+ if (c->plan->all_axes_pinned && instancer &&
+ !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
+ {
+ float s = roundf (scale.to_float (instancer (varIdxBase, 0)) * 16384) / 16384;
+ if (s < -2 || s >= 2)
+ return_trace (subset_scale_as_transform (
+ c, this, src, instancer, s, s,
+ centerX + roundf (instancer (varIdxBase, 1)),
+ centerY + roundf (instancer (varIdxBase, 2))));
+ }
auto *out = c->serializer->embed (this);
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->scale.set_float (scale.to_float (instancer (varIdxBase, 0)));
- out->centerX = centerX + (int) roundf (instancer (varIdxBase, 1));
- out->centerY = centerY + (int) roundf (instancer (varIdxBase, 2));
+ set_fixed_clamped (out->scale, scale.to_float (instancer (varIdxBase, 0)));
+ out->centerX = hb_clamp_to ((double) centerX + (double) roundf (instancer (varIdxBase, 1)));
+ out->centerY = hb_clamp_to ((double) centerY + (double) roundf (instancer (varIdxBase, 2)));
}
if (format == 23 && c->plan->all_axes_pinned)
@@ -1299,6 +1645,7 @@ struct PaintScaleUniformAroundCenter
struct PaintRotate
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1310,7 +1657,7 @@ struct PaintRotate
if (unlikely (!out)) return_trace (false);
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
- out->angle.set_float (angle.to_float (instancer (varIdxBase, 0)));
+ set_fixed_clamped (out->angle, angle.to_float (instancer (varIdxBase, 0)));
if (format == 25 && c->plan->all_axes_pinned)
out->format = 24;
@@ -1343,6 +1690,7 @@ struct PaintRotate
struct PaintRotateAroundCenter
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1355,9 +1703,9 @@ struct PaintRotateAroundCenter
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->angle.set_float (angle.to_float (instancer (varIdxBase, 0)));
- out->centerX = centerX + (int) roundf (instancer (varIdxBase, 1));
- out->centerY = centerY + (int) roundf (instancer (varIdxBase, 2));
+ set_fixed_clamped (out->angle, angle.to_float (instancer (varIdxBase, 0)));
+ out->centerX = hb_clamp_to ((double) centerX + (double) roundf (instancer (varIdxBase, 1)));
+ out->centerY = hb_clamp_to ((double) centerY + (double) roundf (instancer (varIdxBase, 2)));
}
if (format ==27 && c->plan->all_axes_pinned)
@@ -1395,6 +1743,7 @@ struct PaintRotateAroundCenter
struct PaintSkew
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1407,8 +1756,8 @@ struct PaintSkew
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->xSkewAngle.set_float (xSkewAngle.to_float (instancer (varIdxBase, 0)));
- out->ySkewAngle.set_float (ySkewAngle.to_float (instancer (varIdxBase, 1)));
+ set_fixed_clamped (out->xSkewAngle, xSkewAngle.to_float (instancer (varIdxBase, 0)));
+ set_fixed_clamped (out->ySkewAngle, ySkewAngle.to_float (instancer (varIdxBase, 1)));
}
if (format == 29 && c->plan->all_axes_pinned)
@@ -1444,6 +1793,7 @@ struct PaintSkew
struct PaintSkewAroundCenter
{
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
@@ -1456,10 +1806,10 @@ struct PaintSkewAroundCenter
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->xSkewAngle.set_float (xSkewAngle.to_float (instancer (varIdxBase, 0)));
- out->ySkewAngle.set_float (ySkewAngle.to_float (instancer (varIdxBase, 1)));
- out->centerX = centerX + (int) roundf (instancer (varIdxBase, 2));
- out->centerY = centerY + (int) roundf (instancer (varIdxBase, 3));
+ set_fixed_clamped (out->xSkewAngle, xSkewAngle.to_float (instancer (varIdxBase, 0)));
+ set_fixed_clamped (out->ySkewAngle, ySkewAngle.to_float (instancer (varIdxBase, 1)));
+ out->centerX = hb_clamp_to ((double) centerX + (double) roundf (instancer (varIdxBase, 2)));
+ out->centerY = hb_clamp_to ((double) centerY + (double) roundf (instancer (varIdxBase, 3)));
}
if (format == 31 && c->plan->all_axes_pinned)
@@ -1499,7 +1849,8 @@ struct PaintSkewAroundCenter
struct PaintComposite
{
- void closurev1 (hb_colrv1_closure_context_t* c) const;
+ HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
+ HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
bool subset (hb_subset_context_t *c,
const ItemVarStoreInstancer &instancer) const
@@ -1526,11 +1877,49 @@ struct PaintComposite
void paint_glyph (hb_paint_context_t *c) const
{
TRACE_PAINT (this);
+ hb_paint_composite_mode_t composite_mode;
+ switch ((unsigned int) mode)
+ {
+ case HB_PAINT_COMPOSITE_MODE_CLEAR:
+ case HB_PAINT_COMPOSITE_MODE_SRC:
+ case HB_PAINT_COMPOSITE_MODE_DEST:
+ case HB_PAINT_COMPOSITE_MODE_SRC_OVER:
+ case HB_PAINT_COMPOSITE_MODE_DEST_OVER:
+ case HB_PAINT_COMPOSITE_MODE_SRC_IN:
+ case HB_PAINT_COMPOSITE_MODE_DEST_IN:
+ case HB_PAINT_COMPOSITE_MODE_SRC_OUT:
+ case HB_PAINT_COMPOSITE_MODE_DEST_OUT:
+ case HB_PAINT_COMPOSITE_MODE_SRC_ATOP:
+ case HB_PAINT_COMPOSITE_MODE_DEST_ATOP:
+ case HB_PAINT_COMPOSITE_MODE_XOR:
+ case HB_PAINT_COMPOSITE_MODE_PLUS:
+ case HB_PAINT_COMPOSITE_MODE_SCREEN:
+ case HB_PAINT_COMPOSITE_MODE_OVERLAY:
+ case HB_PAINT_COMPOSITE_MODE_DARKEN:
+ case HB_PAINT_COMPOSITE_MODE_LIGHTEN:
+ case HB_PAINT_COMPOSITE_MODE_COLOR_DODGE:
+ case HB_PAINT_COMPOSITE_MODE_COLOR_BURN:
+ case HB_PAINT_COMPOSITE_MODE_HARD_LIGHT:
+ case HB_PAINT_COMPOSITE_MODE_SOFT_LIGHT:
+ case HB_PAINT_COMPOSITE_MODE_DIFFERENCE:
+ case HB_PAINT_COMPOSITE_MODE_EXCLUSION:
+ case HB_PAINT_COMPOSITE_MODE_MULTIPLY:
+ case HB_PAINT_COMPOSITE_MODE_HSL_HUE:
+ case HB_PAINT_COMPOSITE_MODE_HSL_SATURATION:
+ case HB_PAINT_COMPOSITE_MODE_HSL_COLOR:
+ case HB_PAINT_COMPOSITE_MODE_HSL_LUMINOSITY:
+ composite_mode = (hb_paint_composite_mode_t) (unsigned int) mode;
+ break;
+ default:
+ composite_mode = HB_PAINT_COMPOSITE_MODE_CLEAR;
+ break;
+ }
+
c->funcs->push_group_for (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER);
c->recurse (this+backdrop);
- c->funcs->push_group_for (c->data, (hb_paint_composite_mode_t) (int) mode);
+ c->funcs->push_group_for (c->data, composite_mode);
c->recurse (this+src);
- c->funcs->pop_group (c->data, (hb_paint_composite_mode_t) (int) mode);
+ c->funcs->pop_group (c->data, composite_mode);
c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER);
}
@@ -1573,10 +1962,10 @@ struct ClipBoxFormat1
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION)
{
- out->xMin = xMin + (int) roundf (instancer (varIdxBase, 0));
- out->yMin = yMin + (int) roundf (instancer (varIdxBase, 1));
- out->xMax = xMax + (int) roundf (instancer (varIdxBase, 2));
- out->yMax = yMax + (int) roundf (instancer (varIdxBase, 3));
+ out->xMin = hb_clamp_to ((double) xMin + (double) floorf (instancer (varIdxBase, 0)));
+ out->yMin = hb_clamp_to ((double) yMin + (double) floorf (instancer (varIdxBase, 1)));
+ out->xMax = hb_clamp_to ((double) xMax + (double) ceilf (instancer (varIdxBase, 2)));
+ out->yMax = hb_clamp_to ((double) yMax + (double) ceilf (instancer (varIdxBase, 3)));
}
if (format == 2 && c->plan->all_axes_pinned)
@@ -1602,10 +1991,10 @@ struct ClipBoxFormat2 : Variable
value.get_clip_box(clip_box, instancer);
if (instancer)
{
- clip_box.xMin += roundf (instancer (varIdxBase, 0));
- clip_box.yMin += roundf (instancer (varIdxBase, 1));
- clip_box.xMax += roundf (instancer (varIdxBase, 2));
- clip_box.yMax += roundf (instancer (varIdxBase, 3));
+ clip_box.xMin = hb_saturate_add (clip_box.xMin, hb_clamp_to (floorf (instancer (varIdxBase, 0))));
+ clip_box.yMin = hb_saturate_add (clip_box.yMin, hb_clamp_to (floorf (instancer (varIdxBase, 1))));
+ clip_box.xMax = hb_saturate_add (clip_box.xMax, hb_clamp_to (ceilf (instancer (varIdxBase, 2))));
+ clip_box.yMax = hb_saturate_add (clip_box.yMax, hb_clamp_to (ceilf (instancer (varIdxBase, 3))));
}
}
@@ -1620,8 +2009,8 @@ struct ClipBox
{
TRACE_SUBSET (this);
switch (u.format.v) {
- case 1: return_trace (u.format1.subset (c, instancer, VarIdx::NO_VARIATION));
- case 2: return_trace (u.format2.subset (c, instancer));
+ case 1: hb_barrier (); return_trace (u.format1.subset (c, instancer, VarIdx::NO_VARIATION));
+ case 2: hb_barrier (); return_trace (u.format2.subset (c, instancer));
default:return_trace (c->default_return_value ());
}
}
@@ -1629,7 +2018,7 @@ struct ClipBox
void closurev1 (hb_colrv1_closure_context_t* c) const
{
switch (u.format.v) {
- case 2: u.format2.closurev1 (c); return;
+ case 2: hb_barrier (); u.format2.closurev1 (c); return;
default:return;
}
}
@@ -1640,8 +2029,8 @@ struct ClipBox
if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value ();
TRACE_DISPATCH (this, u.format.v);
switch (u.format.v) {
- case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...));
- case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...));
+ case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...));
+ case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...));
default:return_trace (c->default_return_value ());
}
}
@@ -1652,9 +2041,11 @@ struct ClipBox
ClipBoxData clip_box;
switch (u.format.v) {
case 1:
+ hb_barrier ();
u.format1.get_clip_box (clip_box, instancer);
break;
case 2:
+ hb_barrier ();
u.format2.get_clip_box (clip_box, instancer);
break;
default:
@@ -1663,8 +2054,8 @@ struct ClipBox
extents->x_bearing = clip_box.xMin;
extents->y_bearing = clip_box.yMax;
- extents->width = clip_box.xMax - clip_box.xMin;
- extents->height = clip_box.yMin - clip_box.yMax;
+ extents->width = hb_saturate_sub (clip_box.xMax, clip_box.xMin);
+ extents->height = hb_saturate_sub (clip_box.yMin, clip_box.yMax);
return true;
}
@@ -1850,42 +2241,55 @@ struct Paint
if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value ();
TRACE_DISPATCH (this, u.format.v);
switch (u.format.v) {
- case 1: return_trace (c->dispatch (u.paintformat1, std::forward (ds)...));
- case 2: return_trace (c->dispatch (u.paintformat2, std::forward (ds)...));
- case 3: return_trace (c->dispatch (u.paintformat3, std::forward (ds)...));
- case 4: return_trace (c->dispatch (u.paintformat4, std::forward (ds)...));
- case 5: return_trace (c->dispatch (u.paintformat5, std::forward (ds)...));
- case 6: return_trace (c->dispatch (u.paintformat6, std::forward (ds)...));
- case 7: return_trace (c->dispatch (u.paintformat7, std::forward (ds)...));
- case 8: return_trace (c->dispatch (u.paintformat8, std::forward (ds)...));
- case 9: return_trace (c->dispatch (u.paintformat9, std::forward (ds)...));
- case 10: return_trace (c->dispatch (u.paintformat10, std::forward (ds)...));
- case 11: return_trace (c->dispatch (u.paintformat11, std::forward (ds)...));
- case 12: return_trace (c->dispatch (u.paintformat12, std::forward (ds)...));
- case 13: return_trace (c->dispatch (u.paintformat13, std::forward (ds)...));
- case 14: return_trace (c->dispatch (u.paintformat14, std::forward (ds)...));
- case 15: return_trace (c->dispatch (u.paintformat15, std::forward (ds)...));
- case 16: return_trace (c->dispatch (u.paintformat16, std::forward (ds)...));
- case 17: return_trace (c->dispatch (u.paintformat17, std::forward (ds)...));
- case 18: return_trace (c->dispatch (u.paintformat18, std::forward (ds)...));
- case 19: return_trace (c->dispatch (u.paintformat19, std::forward (ds)...));
- case 20: return_trace (c->dispatch (u.paintformat20, std::forward (ds)...));
- case 21: return_trace (c->dispatch (u.paintformat21, std::forward (ds)...));
- case 22: return_trace (c->dispatch (u.paintformat22, std::forward (ds)...));
- case 23: return_trace (c->dispatch (u.paintformat23, std::forward (ds)...));
- case 24: return_trace (c->dispatch (u.paintformat24, std::forward (ds)...));
- case 25: return_trace (c->dispatch (u.paintformat25, std::forward (ds)...));
- case 26: return_trace (c->dispatch (u.paintformat26, std::forward (ds)...));
- case 27: return_trace (c->dispatch (u.paintformat27, std::forward (ds)...));
- case 28: return_trace (c->dispatch (u.paintformat28, std::forward (ds)...));
- case 29: return_trace (c->dispatch (u.paintformat29, std::forward (ds)...));
- case 30: return_trace (c->dispatch (u.paintformat30, std::forward (ds)...));
- case 31: return_trace (c->dispatch (u.paintformat31, std::forward (ds)...));
- case 32: return_trace (c->dispatch (u.paintformat32, std::forward (ds)...));
+ case 1: hb_barrier (); return_trace (c->dispatch (u.paintformat1, std::forward (ds)...));
+ case 2: hb_barrier (); return_trace (c->dispatch (u.paintformat2, std::forward (ds)...));
+ case 3: hb_barrier (); return_trace (c->dispatch (u.paintformat3, std::forward (ds)...));
+ case 4: hb_barrier (); return_trace (c->dispatch (u.paintformat4, std::forward (ds)...));
+ case 5: hb_barrier (); return_trace (c->dispatch (u.paintformat5, std::forward (ds)...));
+ case 6: hb_barrier (); return_trace (c->dispatch (u.paintformat6, std::forward (ds)...));
+ case 7: hb_barrier (); return_trace (c->dispatch (u.paintformat7, std::forward (ds)...));
+ case 8: hb_barrier (); return_trace (c->dispatch (u.paintformat8, std::forward (ds)...));
+ case 9: hb_barrier (); return_trace (c->dispatch (u.paintformat9, std::forward (ds)...));
+ case 10: hb_barrier (); return_trace (c->dispatch (u.paintformat10, std::forward (ds)...));
+ case 11: hb_barrier (); return_trace (c->dispatch (u.paintformat11, std::forward (ds)...));
+ case 12: hb_barrier (); return_trace (c->dispatch (u.paintformat12, std::forward (ds)...));
+ case 13: hb_barrier (); return_trace (c->dispatch (u.paintformat13, std::forward (ds)...));
+ case 14: hb_barrier (); return_trace (c->dispatch (u.paintformat14, std::forward (ds)...));
+ case 15: hb_barrier (); return_trace (c->dispatch (u.paintformat15, std::forward (ds)...));
+ case 16: hb_barrier (); return_trace (c->dispatch (u.paintformat16, std::forward (ds)...));
+ case 17: hb_barrier (); return_trace (c->dispatch (u.paintformat17, std::forward (ds)...));
+ case 18: hb_barrier (); return_trace (c->dispatch (u.paintformat18, std::forward (ds)...));
+ case 19: hb_barrier (); return_trace (c->dispatch (u.paintformat19, std::forward (ds)...));
+ case 20: hb_barrier (); return_trace (c->dispatch (u.paintformat20, std::forward (ds)...));
+ case 21: hb_barrier (); return_trace (c->dispatch (u.paintformat21, std::forward (ds)...));
+ case 22: hb_barrier (); return_trace (c->dispatch (u.paintformat22, std::forward (ds)...));
+ case 23: hb_barrier (); return_trace (c->dispatch (u.paintformat23, std::forward (ds)...));
+ case 24: hb_barrier (); return_trace (c->dispatch (u.paintformat24, std::forward (ds)...));
+ case 25: hb_barrier (); return_trace (c->dispatch (u.paintformat25, std::forward (ds)...));
+ case 26: hb_barrier (); return_trace (c->dispatch (u.paintformat26, std::forward (ds)...));
+ case 27: hb_barrier (); return_trace (c->dispatch (u.paintformat27, std::forward (ds)...));
+ case 28: hb_barrier (); return_trace (c->dispatch (u.paintformat28, std::forward (ds)...));
+ case 29: hb_barrier (); return_trace (c->dispatch (u.paintformat29, std::forward (ds)...));
+ case 30: hb_barrier (); return_trace (c->dispatch (u.paintformat30, std::forward (ds)...));
+ case 31: hb_barrier (); return_trace (c->dispatch (u.paintformat31, std::forward (ds)...));
+ case 32: hb_barrier (); return_trace (c->dispatch (u.paintformat32, std::forward (ds)...));
+#ifndef HB_NO_BEYOND_64K
+ case 33: hb_barrier (); return_trace (c->dispatch (u.paintformat33, std::forward (ds)...));
+#endif
default:return_trace (c->default_return_value ());
}
}
+ bool get_solid_color (hb_paint_context_t *c,
+ hb_bool_t *is_foreground, hb_color_t *color) const
+ {
+ switch (u.format.v) {
+ case 2: hb_barrier (); u.paintformat2.get_solid_color (c, is_foreground, color); return true;
+ case 3: hb_barrier (); u.paintformat3.get_solid_color (c, is_foreground, color); return true;
+ default: return false;
+ }
+ }
+
protected:
union {
struct { HBUINT8 v; } format;
@@ -1898,7 +2302,7 @@ struct Paint
Variable> paintformat7;
NoVariable> paintformat8;
Variable> paintformat9;
- PaintGlyph paintformat10;
+ PaintGlyph paintformat10;
PaintColrGlyph paintformat11;
PaintTransform paintformat12;
PaintTransform paintformat13;
@@ -1921,6 +2325,9 @@ struct Paint
NoVariable paintformat30;
Variable paintformat31;
PaintComposite paintformat32;
+#ifndef HB_NO_BEYOND_64K
+ PaintGlyph paintformat33;
+#endif
} u;
public:
DEFINE_SIZE_MIN (2);
@@ -2115,7 +2522,7 @@ struct COLR
hb_array_t all_layers = (this+layersZ).as_array (numLayers);
hb_array_t glyph_layers = all_layers.sub_array (record.firstLayerIdx,
record.numLayers);
- if (count)
+ if (count && layers)
{
+ glyph_layers.sub_array (start_offset, count)
| hb_sink (hb_array (layers, *count))
@@ -2178,6 +2585,12 @@ struct COLR
bool is_valid () { return colr.get_blob ()->length; }
+ void depend (hb_depend_data_builder_t *depend_data) const
+ {
+ if (!has_data ()) return;
+ colr->depend (depend_data);
+ }
+
void closure_glyphs (hb_codepoint_t glyph,
hb_set_t *related_ids /* OUT */) const
{ colr->closure_glyphs (glyph, related_ids); }
@@ -2239,6 +2652,35 @@ struct COLR
mutable hb_atomic_t cached_scratch;
};
+ void depend (hb_depend_data_builder_t *depend_data) const
+ {
+ // v0
+ hb_array_t baseGlyphs = (this+baseGlyphsZ).as_array (numBaseGlyphs);
+ for (const BaseGlyphRecord &record : baseGlyphs)
+ {
+ auto glyph_layers = (this+layersZ).as_array (numLayers).sub_array (record.firstLayerIdx,
+ record.numLayers);
+ for (const LayerRecord layer : glyph_layers)
+ depend_data->add_depend(record.glyphId, HB_OT_TAG_COLR, layer.glyphId);
+ }
+
+ if (!has_v1_data())
+ return;
+
+ // v1
+ hb_colrv1_depend_context_t c (this, depend_data);
+ const BaseGlyphList &baseglyph_paintrecords = this+baseGlyphList;
+
+ for (const BaseGlyphPaintRecord &baseglyph_paintrecord: baseglyph_paintrecords.iter ())
+ {
+ c.source_gid = baseglyph_paintrecord.glyphId;
+ c.visited_paint.clear ();
+
+ const Paint &paint = &baseglyph_paintrecords+baseglyph_paintrecord.paint;
+ paint.dispatch (&c);
+ }
+ }
+
void closure_glyphs (hb_codepoint_t glyph,
hb_set_t *related_ids /* OUT */) const
{
@@ -2405,10 +2847,11 @@ struct COLR
const BaseGlyphPaintRecord* get_base_glyph_paintrecord (hb_codepoint_t gid) const
{
- const BaseGlyphPaintRecord* record = &(this+baseGlyphList).bsearch ((unsigned) gid);
- if ((record && (hb_codepoint_t) record->glyphId != gid))
- record = nullptr;
- return record;
+ const BaseGlyphList &list = this+baseGlyphList;
+ unsigned int i;
+ if (!list.bfind ((unsigned) gid, &i))
+ return nullptr;
+ return &list[i];
}
bool downgrade_to_V0 (const hb_set_t &glyphset) const
@@ -2473,9 +2916,17 @@ struct COLR
}
else
{
+ /* avar2 partial instancing: cull unreachable regions. */
+ hb_set_t dead_regions;
+ if (c->plan->has_avar2)
+ var_store.collect_dead_regions (c->plan->axes_old_index_tag_map,
+ c->plan->avar2_reachable_ranges,
+ dead_regions);
+
if (unlikely (!out->varStore.serialize_serialize (c->serializer,
&var_store,
- c->plan->colrv1_varstore_inner_maps.as_array ())))
+ c->plan->colrv1_varstore_inner_maps.as_array (),
+ dead_regions.get_population () ? &dead_regions : nullptr)))
return_trace (false);
}
@@ -2580,8 +3031,8 @@ struct COLR
* after instancing */
if (!subset_varstore (c, colr_prime)) return_trace (false);
- ItemVarStoreInstancer instancer (get_var_store_ptr (),
- get_delta_set_index_map_ptr (),
+ ItemVarStoreInstancer instancer (c->plan->normalized_coords ? get_var_store_ptr () : nullptr,
+ c->plan->normalized_coords ? get_delta_set_index_map_ptr () : nullptr,
c->plan->normalized_coords.as_array ());
if (!colr_prime->baseGlyphList.serialize_subset (c, baseGlyphList, this, instancer))
@@ -2637,12 +3088,7 @@ struct COLR
extents->height = 0;
}
else
- {
- extents->x_bearing = e.xmin;
- extents->y_bearing = e.ymax;
- extents->width = e.xmax - e.xmin;
- extents->height = e.ymin - e.ymax;
- }
+ *extents = e.to_glyph_extents ();
return ret;
}
@@ -2700,19 +3146,10 @@ struct COLR
// COLRv1 glyph
bool is_bounded = true;
+ hb_glyph_extents_t extents = {};
if (clip)
{
- hb_glyph_extents_t extents;
- if (get_clip (glyph, &extents, instancer))
- {
- font->scale_glyph_extents (&extents);
- c.funcs->push_clip_rectangle (c.data,
- extents.x_bearing,
- extents.y_bearing + extents.height,
- extents.x_bearing + extents.width,
- extents.y_bearing);
- }
- else
+ if (!get_clip (glyph, &extents, instancer))
{
clip = false;
is_bounded = false;
@@ -2735,14 +3172,21 @@ struct COLR
c.funcs->push_font_transform (c.data, font);
+ if (clip)
+ c.funcs->push_clip_rectangle (c.data,
+ (float) extents.x_bearing,
+ (float) extents.y_bearing + extents.height,
+ (float) extents.x_bearing + extents.width,
+ (float) extents.y_bearing);
+
if (is_bounded)
c.recurse (*paint);
- c.funcs->pop_transform (c.data);
-
if (clip)
c.funcs->pop_clip (c.data);
+ c.funcs->pop_transform (c.data);
+
return true;
}
}
@@ -2756,9 +3200,7 @@ struct COLR
{
hb_bool_t is_foreground;
hb_color_t color = c.get_color (r.colorIdx, 1., &is_foreground);
- c.funcs->push_clip_glyph (c.data, r.glyphId, c.font);
- c.funcs->color (c.data, is_foreground, color);
- c.funcs->pop_clip (c.data);
+ c.funcs->fill_glyph (c.data, r.glyphId, c.font, is_foreground, color);
}
return true;
@@ -2800,6 +3242,33 @@ hb_paint_context_t::recurse (const Paint &paint)
depth_left++;
}
+template
+void PaintGlyph::paint_glyph (hb_paint_context_t *c) const
+{
+ TRACE_PAINT (this);
+
+ hb_bool_t is_foreground;
+ hb_color_t color;
+ /* Optimize cases that can use a simple fill-glyph operation. */
+ if (likely (c->depth_left > 0 && c->edge_count > 0) &&
+ (this+paint).get_solid_color (c, &is_foreground, &color))
+ {
+ c->edge_count--;
+ c->funcs->push_inverse_font_transform (c->data, c->font);
+ c->funcs->fill_glyph (c->data, gid, c->font, is_foreground, color);
+ c->funcs->pop_transform (c->data);
+ return;
+ }
+
+ c->funcs->push_inverse_font_transform (c->data, c->font);
+ c->funcs->push_clip_glyph (c->data, gid, c->font);
+ c->funcs->push_font_transform (c->data, c->font);
+ c->recurse (this+paint);
+ c->funcs->pop_transform (c->data);
+ c->funcs->pop_clip (c->data);
+ c->funcs->pop_transform (c->data);
+}
+
void PaintColrLayers::paint_glyph (hb_paint_context_t *c) const
{
TRACE_PAINT (this);
@@ -2839,10 +3308,10 @@ void PaintColrGlyph::paint_glyph (hb_paint_context_t *c) const
if (has_clip_box)
c->funcs->push_clip_rectangle (c->data,
- extents.x_bearing,
- extents.y_bearing + extents.height,
- extents.x_bearing + extents.width,
- extents.y_bearing);
+ (float) extents.x_bearing,
+ (float) extents.y_bearing + extents.height,
+ (float) extents.x_bearing + extents.width,
+ (float) extents.y_bearing);
if (paint)
c->recurse (*paint);
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/colrv1-closure.hh b/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/colrv1-closure.hh
index 9ed0aa5632ae..f94ce070cf00 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/colrv1-closure.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/colrv1-closure.hh
@@ -42,12 +42,13 @@ HB_INTERNAL void PaintColrLayers::closurev1 (hb_colrv1_closure_context_t* c) con
const LayerList &paint_offset_lists = c->get_colr_table ()->get_layerList ();
for (unsigned i = firstLayerIndex; i < firstLayerIndex + numLayers; i++)
{
- const Paint &paint = std::addressof (paint_offset_lists) + paint_offset_lists[i];
+ const Paint &paint = paint_offset_lists.get_paint (i);
paint.dispatch (c);
}
}
-HB_INTERNAL void PaintGlyph::closurev1 (hb_colrv1_closure_context_t* c) const
+template
+HB_INTERNAL void PaintGlyph::closurev1 (hb_colrv1_closure_context_t* c) const
{
c->add_glyph (gid);
(this+paint).dispatch (c);
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Color/CPAL/CPAL.hh b/src/java.desktop/share/native/libharfbuzz/OT/Color/CPAL/CPAL.hh
index f79e236bce91..b0c91ab3f3ab 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Color/CPAL/CPAL.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Color/CPAL/CPAL.hh
@@ -209,7 +209,7 @@ struct CPAL
hb_array_t all_colors ((this+colorRecordsZ).arrayZ, numColorRecords);
hb_array_t palette_colors = all_colors.sub_array (start_index,
numColors);
- if (color_count)
+ if (color_count && colors)
{
+ palette_colors.sub_array (start_offset, color_count)
| hb_sink (hb_array (colors, *color_count))
@@ -300,25 +300,50 @@ struct CPAL
hb_vector_t first_color_index_for_layer;
hb_map_t first_color_to_layer_index;
+ /* Two palettes that retain exactly the same color records can share the
+ * same block of color records. This commonly happens after subsetting
+ * when the colors that distinguished the palettes are dropped. Map from
+ * a layer's retained colors to its index to find equal layers without
+ * scanning all of them. The keys point into layer_retained_colors,
+ * which keeps them alive. */
+ hb_hashmap_t, unsigned> retained_colors_to_layer_index;
+ hb_vector_t> layer_retained_colors;
+
+ const hb_array_t all_color_records = (this+colorRecordsZ).as_array (numColorRecords);
const hb_array_t colorRecordIndices = colorRecordIndicesZ.as_array (numPalettes);
for (const auto first_color_record_idx : colorRecordIndices)
{
if (first_color_to_layer_index.has (first_color_record_idx)) continue;
- first_color_index_for_layer.push (first_color_record_idx);
- if (unlikely (!c->serializer->propagate_error (first_color_index_for_layer))) return_trace (false);
- first_color_to_layer_index.set (first_color_record_idx,
- first_color_index_for_layer.length - 1);
+ hb_vector_t retained_colors;
+ if (unlikely (!retained_colors.alloc (retained_color_indices.get_population ()))) return_trace (false);
+ for (hb_codepoint_t color_index : retained_color_indices)
+ retained_colors.push (all_color_records[first_color_record_idx + color_index]);
+
+ unsigned layer_index = first_color_index_for_layer.length;
+ unsigned *candidate_layer_index = nullptr;
+ if (retained_colors_to_layer_index.has (retained_colors.as_array (), &candidate_layer_index))
+ layer_index = *candidate_layer_index;
+ else
+ {
+ first_color_index_for_layer.push (first_color_record_idx);
+ if (unlikely (!c->serializer->propagate_error (first_color_index_for_layer))) return_trace (false);
+
+ if (unlikely (!layer_retained_colors.push_or_fail (std::move (retained_colors)))) return_trace (false);
+ if (unlikely (!retained_colors_to_layer_index.set (layer_retained_colors.tail ().as_array (), layer_index)))
+ return_trace (false);
+ }
+ first_color_to_layer_index.set (first_color_record_idx, layer_index);
+ if (unlikely (!c->serializer->propagate_error (first_color_to_layer_index))) return_trace (false);
}
out->numColorRecords = first_color_index_for_layer.length
* retained_color_indices.get_population ();
- const hb_array_t color_records = (this+colorRecordsZ).as_array (numColorRecords);
if (!out->serialize (c->serializer,
colorRecordIndices,
- color_records,
+ all_color_records,
first_color_index_for_layer,
first_color_to_layer_index,
retained_color_indices))
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Color/sbix/sbix.hh b/src/java.desktop/share/native/libharfbuzz/OT/Color/sbix/sbix.hh
index f6e6c5e3a9d8..0eefe9cada96 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Color/sbix/sbix.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Color/sbix/sbix.hh
@@ -337,18 +337,18 @@ struct sbix
}
extents->x_bearing = x_offset;
- extents->y_bearing = png.IHDR.height + y_offset;
- extents->width = png.IHDR.width;
- extents->height = -1 * png.IHDR.height;
+ extents->y_bearing = hb_clamp_to ((int64_t) (unsigned int) png.IHDR.height + y_offset);
+ extents->width = (hb_position_t) (unsigned int) png.IHDR.width;
+ extents->height = -(hb_position_t) (unsigned int) png.IHDR.height;
/* Convert to font units. */
if (strike_ppem && scale)
{
float scale = font->face->get_upem () / (float) strike_ppem;
- extents->x_bearing = roundf (extents->x_bearing * scale);
- extents->y_bearing = roundf (extents->y_bearing * scale);
- extents->width = roundf (extents->width * scale);
- extents->height = roundf (extents->height * scale);
+ extents->x_bearing = hb_clamp_to (roundf (extents->x_bearing * scale));
+ extents->y_bearing = hb_clamp_to (roundf (extents->y_bearing * scale));
+ extents->width = hb_clamp_to (roundf (extents->width * scale));
+ extents->height = hb_clamp_to (roundf (extents->height * scale));
}
if (scale)
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Color/svg/svg.hh b/src/java.desktop/share/native/libharfbuzz/OT/Color/svg/svg.hh
index a0fd2c88d0a4..6be0bc85706d 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Color/svg/svg.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Color/svg/svg.hh
@@ -499,7 +499,7 @@ parse_cache_entries_linear (const char *svg,
while (p + name_len < gt)
{
unsigned char c = (unsigned char) name[name_len];
- if (!(isalnum (c) || c == '_' || c == '-' || c == ':'))
+ if (!(ISALNUM (c) || c == '_' || c == '-' || c == ':'))
break;
name_len++;
}
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/Coverage.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/Coverage.hh
index 286788563733..80be33390994 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/Coverage.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/Coverage.hh
@@ -29,7 +29,7 @@
#ifndef OT_LAYOUT_COMMON_COVERAGE_HH
#define OT_LAYOUT_COMMON_COVERAGE_HH
-#include "../types.hh"
+#include "../../../hb-ot-dual.hh"
#include "CoverageFormat1.hh"
#include "CoverageFormat2.hh"
@@ -67,11 +67,11 @@ struct Coverage
hb_barrier ();
switch (u.format.v)
{
- case 1: return_trace (u.format1.sanitize (c));
- case 2: return_trace (u.format2.sanitize (c));
+ case 1: hb_barrier (); return_trace (u.format1.sanitize (c));
+ case 2: hb_barrier (); return_trace (u.format2.sanitize (c));
#ifndef HB_NO_BEYOND_64K
- case 3: return_trace (u.format3.sanitize (c));
- case 4: return_trace (u.format4.sanitize (c));
+ case 3: hb_barrier (); return_trace (u.format3.sanitize (c));
+ case 4: hb_barrier (); return_trace (u.format4.sanitize (c));
#endif
default:return_trace (true);
}
@@ -87,11 +87,11 @@ struct Coverage
unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
switch (u.format.v) {
- case 1: return u.format1.get_coverage (glyph_id);
- case 2: return u.format2.get_coverage (glyph_id);
+ case 1: hb_barrier (); return u.format1.get_coverage (glyph_id);
+ case 2: hb_barrier (); return u.format2.get_coverage (glyph_id);
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.get_coverage (glyph_id);
- case 4: return u.format4.get_coverage (glyph_id);
+ case 3: hb_barrier (); return u.format3.get_coverage (glyph_id);
+ case 4: hb_barrier (); return u.format4.get_coverage (glyph_id);
#endif
default:return NOT_COVERED;
}
@@ -104,9 +104,9 @@ struct Coverage
coverage = get_coverage (glyph_id);
if (cache) {
if (coverage == NOT_COVERED)
- cache->set_unchecked (glyph_id, cache->MAX_VALUE);
+ cache->set (glyph_id, cache->MAX_VALUE);
else if (likely (coverage < cache->MAX_VALUE))
- cache->set_unchecked (glyph_id, coverage);
+ cache->set (glyph_id, coverage);
}
return coverage;
}
@@ -119,9 +119,9 @@ struct Coverage
coverage = get_coverage (glyph_id);
if (cache) {
if (coverage == NOT_COVERED)
- cache->set_unchecked (glyph_id, cache->MAX_VALUE);
+ cache->set (glyph_id, cache->MAX_VALUE);
else
- cache->set_unchecked (glyph_id, 0);
+ cache->set (glyph_id, 0);
}
return coverage;
}
@@ -129,11 +129,11 @@ struct Coverage
unsigned get_population () const
{
switch (u.format.v) {
- case 1: return u.format1.get_population ();
- case 2: return u.format2.get_population ();
+ case 1: hb_barrier (); return u.format1.get_population ();
+ case 2: hb_barrier (); return u.format2.get_population ();
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.get_population ();
- case 4: return u.format4.get_population ();
+ case 3: hb_barrier (); return u.format3.get_population ();
+ case 4: hb_barrier (); return u.format4.get_population ();
#endif
default:return NOT_COVERED;
}
@@ -146,12 +146,12 @@ struct Coverage
TRACE_SERIALIZE (this);
if (unlikely (!c->extend_min (this))) return_trace (false);
- unsigned count = hb_len (glyphs);
+ unsigned count = hb_len (+ glyphs);
unsigned num_ranges = 0;
hb_codepoint_t last = (hb_codepoint_t) -2;
hb_codepoint_t max = 0;
bool unsorted = false;
- for (auto g: glyphs)
+ for (auto g: + glyphs)
{
if (last != (hb_codepoint_t) -2 && g < last)
unsorted = true;
@@ -176,11 +176,11 @@ struct Coverage
switch (u.format.v)
{
- case 1: return_trace (u.format1.serialize (c, glyphs));
- case 2: return_trace (u.format2.serialize (c, glyphs));
+ case 1: hb_barrier (); return_trace (u.format1.serialize (c, glyphs));
+ case 2: hb_barrier (); return_trace (u.format2.serialize (c, glyphs));
#ifndef HB_NO_BEYOND_64K
- case 3: return_trace (u.format3.serialize (c, glyphs));
- case 4: return_trace (u.format4.serialize (c, glyphs));
+ case 3: hb_barrier (); return_trace (u.format3.serialize (c, glyphs));
+ case 4: hb_barrier (); return_trace (u.format4.serialize (c, glyphs));
#endif
default:return_trace (false);
}
@@ -189,10 +189,13 @@ struct Coverage
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
+ const hb_subset_plan_t *plan = c->plan;
auto it =
+ iter ()
- | hb_take (c->plan->source->get_num_glyphs ())
- | hb_map_retains_sorting (c->plan->glyph_map_gsub)
+ | hb_take (plan->source->get_num_glyphs ())
+ | hb_map_retains_sorting ([plan] (hb_codepoint_t g) {
+ return plan->map_gsub_glyph (g);
+ })
| hb_filter ([] (hb_codepoint_t glyph) { return glyph != HB_MAP_VALUE_INVALID; })
;
@@ -207,11 +210,11 @@ struct Coverage
{
switch (u.format.v)
{
- case 1: return u.format1.intersects (glyphs);
- case 2: return u.format2.intersects (glyphs);
+ case 1: hb_barrier (); return u.format1.intersects (glyphs);
+ case 2: hb_barrier (); return u.format2.intersects (glyphs);
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.intersects (glyphs);
- case 4: return u.format4.intersects (glyphs);
+ case 3: hb_barrier (); return u.format3.intersects (glyphs);
+ case 4: hb_barrier (); return u.format4.intersects (glyphs);
#endif
default:return false;
}
@@ -220,11 +223,11 @@ struct Coverage
{
switch (u.format.v)
{
- case 1: return u.format1.intersects_coverage (glyphs, index);
- case 2: return u.format2.intersects_coverage (glyphs, index);
+ case 1: hb_barrier (); return u.format1.intersects_coverage (glyphs, index);
+ case 2: hb_barrier (); return u.format2.intersects_coverage (glyphs, index);
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.intersects_coverage (glyphs, index);
- case 4: return u.format4.intersects_coverage (glyphs, index);
+ case 3: hb_barrier (); return u.format3.intersects_coverage (glyphs, index);
+ case 4: hb_barrier (); return u.format4.intersects_coverage (glyphs, index);
#endif
default:return false;
}
@@ -250,11 +253,11 @@ struct Coverage
{
switch (u.format.v)
{
- case 1: return u.format1.collect_coverage (glyphs);
- case 2: return u.format2.collect_coverage (glyphs);
+ case 1: hb_barrier (); return u.format1.collect_coverage (glyphs);
+ case 2: hb_barrier (); return u.format2.collect_coverage (glyphs);
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.collect_coverage (glyphs);
- case 4: return u.format4.collect_coverage (glyphs);
+ case 3: hb_barrier (); return u.format3.collect_coverage (glyphs);
+ case 4: hb_barrier (); return u.format4.collect_coverage (glyphs);
#endif
default:return false;
}
@@ -266,11 +269,11 @@ struct Coverage
{
switch (u.format.v)
{
- case 1: return u.format1.intersect_set (glyphs, intersect_glyphs);
- case 2: return u.format2.intersect_set (glyphs, intersect_glyphs);
+ case 1: hb_barrier (); return u.format1.intersect_set (glyphs, intersect_glyphs);
+ case 2: hb_barrier (); return u.format2.intersect_set (glyphs, intersect_glyphs);
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.intersect_set (glyphs, intersect_glyphs);
- case 4: return u.format4.intersect_set (glyphs, intersect_glyphs);
+ case 3: hb_barrier (); return u.format3.intersect_set (glyphs, intersect_glyphs);
+ case 4: hb_barrier (); return u.format4.intersect_set (glyphs, intersect_glyphs);
#endif
default:return ;
}
@@ -285,11 +288,11 @@ struct Coverage
format = c_.u.format.v;
switch (format)
{
- case 1: u.format1.init (c_.u.format1); return;
- case 2: u.format2.init (c_.u.format2); return;
+ case 1: hb_barrier (); u.format1.init (c_.u.format1); return;
+ case 2: hb_barrier (); u.format2.init (c_.u.format2); return;
#ifndef HB_NO_BEYOND_64K
- case 3: u.format3.init (c_.u.format3); return;
- case 4: u.format4.init (c_.u.format4); return;
+ case 3: hb_barrier (); u.format3.init (c_.u.format3); return;
+ case 4: hb_barrier (); u.format4.init (c_.u.format4); return;
#endif
default: return;
}
@@ -298,11 +301,11 @@ struct Coverage
{
switch (format)
{
- case 1: return u.format1.__more__ ();
- case 2: return u.format2.__more__ ();
+ case 1: hb_barrier (); return u.format1.__more__ ();
+ case 2: hb_barrier (); return u.format2.__more__ ();
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.__more__ ();
- case 4: return u.format4.__more__ ();
+ case 3: hb_barrier (); return u.format3.__more__ ();
+ case 4: hb_barrier (); return u.format4.__more__ ();
#endif
default:return false;
}
@@ -311,11 +314,11 @@ struct Coverage
{
switch (format)
{
- case 1: u.format1.__next__ (); break;
- case 2: u.format2.__next__ (); break;
+ case 1: hb_barrier (); u.format1.__next__ (); break;
+ case 2: hb_barrier (); u.format2.__next__ (); break;
#ifndef HB_NO_BEYOND_64K
- case 3: u.format3.__next__ (); break;
- case 4: u.format4.__next__ (); break;
+ case 3: hb_barrier (); u.format3.__next__ (); break;
+ case 4: hb_barrier (); u.format4.__next__ (); break;
#endif
default: break;
}
@@ -327,11 +330,11 @@ struct Coverage
{
switch (format)
{
- case 1: return u.format1.get_glyph ();
- case 2: return u.format2.get_glyph ();
+ case 1: hb_barrier (); return u.format1.get_glyph ();
+ case 2: hb_barrier (); return u.format2.get_glyph ();
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3.get_glyph ();
- case 4: return u.format4.get_glyph ();
+ case 3: hb_barrier (); return u.format3.get_glyph ();
+ case 4: hb_barrier (); return u.format4.get_glyph ();
#endif
default:return 0;
}
@@ -341,11 +344,11 @@ struct Coverage
if (unlikely (format != o.format)) return true;
switch (format)
{
- case 1: return u.format1 != o.u.format1;
- case 2: return u.format2 != o.u.format2;
+ case 1: hb_barrier (); return u.format1 != o.u.format1;
+ case 2: hb_barrier (); return u.format2 != o.u.format2;
#ifndef HB_NO_BEYOND_64K
- case 3: return u.format3 != o.u.format3;
- case 4: return u.format4 != o.u.format4;
+ case 3: hb_barrier (); return u.format3 != o.u.format3;
+ case 4: hb_barrier (); return u.format4 != o.u.format4;
#endif
default:return false;
}
@@ -356,11 +359,11 @@ struct Coverage
it.format = format;
switch (format)
{
- case 1: it.u.format1 = u.format1.__end__ (); break;
- case 2: it.u.format2 = u.format2.__end__ (); break;
+ case 1: hb_barrier (); it.u.format1 = u.format1.__end__ (); break;
+ case 2: hb_barrier (); it.u.format2 = u.format2.__end__ (); break;
#ifndef HB_NO_BEYOND_64K
- case 3: it.u.format3 = u.format3.__end__ (); break;
- case 4: it.u.format4 = u.format4.__end__ (); break;
+ case 3: hb_barrier (); it.u.format3 = u.format3.__end__ (); break;
+ case 4: hb_barrier (); it.u.format4 = u.format4.__end__ (); break;
#endif
default: break;
}
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat1.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat1.hh
index 122326e3024b..addce14ce7ad 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat1.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat1.hh
@@ -43,10 +43,10 @@ struct CoverageFormat1_3
public:
HBUINT16 coverageFormat; /* Format identifier--format = 1 */
- SortedArray16Of
+ typename Types::template SortedArrayOf
glyphArray; /* Array of GlyphIDs--in numerical order */
- DEFINE_SIZE_ARRAY (4, glyphArray);
+ DEFINE_SIZE_ARRAY (2 + Types::HBUINT::static_size, glyphArray);
private:
bool sanitize (hb_sanitize_context_t *c) const
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat2.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat2.hh
index 8287c8d4d4d4..51360f855750 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat2.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/CoverageFormat2.hh
@@ -39,15 +39,16 @@ template
struct CoverageFormat2_4
{
friend struct Coverage;
+ using CoverageRangeRecord = RangeRecord;
public:
HBUINT16 coverageFormat; /* Format identifier--format = 2 */
- SortedArray16Of>
+ typename Types::template SortedArrayOf
rangeRecord; /* Array of glyph ranges--ordered by
* Start GlyphID. rangeCount entries
* long */
public:
- DEFINE_SIZE_ARRAY (4, rangeRecord);
+ DEFINE_SIZE_ARRAY (2 + Types::HBUINT::static_size, rangeRecord);
private:
@@ -59,7 +60,7 @@ struct CoverageFormat2_4
unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
- const RangeRecord &range = rangeRecord.bsearch (glyph_id);
+ const CoverageRangeRecord &range = rangeRecord.bsearch (glyph_id);
return likely (range.first <= range.last)
? (unsigned int) range.value + (glyph_id - range.first)
: NOT_COVERED;
@@ -113,7 +114,7 @@ struct CoverageFormat2_4
}
if (unlikely (unsorted))
- rangeRecord.as_array ().qsort (RangeRecord::cmp_range);
+ rangeRecord.as_array ().qsort (CoverageRangeRecord::cmp_range);
return_trace (true);
}
@@ -129,7 +130,7 @@ struct CoverageFormat2_4
}
return hb_any (+ hb_iter (rangeRecord)
- | hb_map ([glyphs] (const RangeRecord &range) { return range.intersects (*glyphs); }));
+ | hb_map ([glyphs] (const CoverageRangeRecord &range) { return range.intersects (*glyphs); }));
}
bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
{
@@ -139,6 +140,19 @@ struct CoverageFormat2_4
return false;
}
+ static void add_intersected_bits (hb_set_t &set, hb_codepoint_t base, uint64_t bits)
+ { set.add_bits (base, bits); }
+
+ template
+ static void add_intersected_bits (IterableOut&& out, hb_codepoint_t base, uint64_t bits)
+ {
+ while (bits)
+ {
+ out << base + hb_ctz (bits);
+ bits &= bits - 1;
+ }
+ }
+
template
void intersect_set (const hb_set_t &glyphs, IterableOut&& intersect_glyphs) const
@@ -151,9 +165,18 @@ struct CoverageFormat2_4
if (unlikely (range.first < last))
break;
last = range.last;
- for (hb_codepoint_t g = range.first - 1;
- glyphs.next (&g) && g <= last;)
- intersect_glyphs << g;
+ hb_codepoint_t cursor = range.first & ~hb_bit_page_t::ELT_MASK;
+ cursor = cursor ? cursor - 1 : HB_SET_VALUE_INVALID;
+ uint64_t bits;
+ while (glyphs.next_bits (&cursor, &bits) && cursor <= last)
+ {
+ if (range.first > cursor)
+ bits &= UINT64_MAX << (range.first - cursor);
+ unsigned int end = last - cursor;
+ if (end < hb_bit_page_t::ELT_BITS - 1)
+ bits &= (uint64_t (1) << (end + 1)) - 1;
+ add_intersected_bits (intersect_glyphs, cursor, bits);
+ }
}
}
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/RangeRecord.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/RangeRecord.hh
index 85aacace9a76..ad9a637d6a08 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/RangeRecord.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/Common/RangeRecord.hh
@@ -33,14 +33,14 @@ namespace OT {
namespace Layout {
namespace Common {
-template
+template
struct RangeRecord
{
typename Types::HBGlyphID first; /* First GlyphID in the range */
typename Types::HBGlyphID last; /* Last GlyphID in the range */
- HBUINT16 value; /* Value */
+ Value value; /* Value */
- DEFINE_SIZE_STATIC (2 + 2 * Types::size);
+ DEFINE_SIZE_STATIC (2 * Types::size + Value::static_size);
bool sanitize (hb_sanitize_context_t *c) const
{
@@ -86,10 +86,10 @@ struct RangeRecord
// but that only works when there is only a single namespace level.
// The macro should probably be fixed so it can work in this situation.
extern HB_INTERNAL const unsigned char _hb_Null_OT_RangeRecord[9];
-template
-struct Null> {
- static OT::Layout::Common::RangeRecord const & get_null () {
- return *reinterpret_cast *> (_hb_Null_OT_RangeRecord);
+template
+struct Null> {
+ static OT::Layout::Common::RangeRecord const & get_null () {
+ return *reinterpret_cast *> (_hb_Null_OT_RangeRecord);
}
};
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GDEF/GDEF.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GDEF/GDEF.hh
index 23412914feb5..c6dbceef8bbe 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GDEF/GDEF.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GDEF/GDEF.hh
@@ -53,6 +53,9 @@ struct AttachPoint : Array16Of
}
};
+/* AttachList is referenced by both GDEF attachListOffset and
+ * attachListOffset2. The v1.4 top-level offset widens, but the
+ * AttachList table itself keeps Offset16 internals. */
struct AttachList
{
unsigned int get_attach_points (hb_codepoint_t glyph_id,
@@ -70,7 +73,7 @@ struct AttachList
const AttachPoint &points = this+attachPoint[index];
- if (point_count)
+ if (point_count && point_array)
{
+ points.as_array ().sub_array (start_offset, point_count)
| hb_sink (hb_array (point_array, *point_count))
@@ -192,8 +195,8 @@ struct CaretValueFormat3
const ItemVariationStore &var_store) const
{
return HB_DIRECTION_IS_HORIZONTAL (direction) ?
- font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font, var_store) :
- font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font, var_store);
+ hb_saturate_add (font->em_scale_x (coordinate), (this+deviceTable).get_x_delta (font, var_store)) :
+ hb_saturate_add (font->em_scale_y (coordinate), (this+deviceTable).get_y_delta (font, var_store));
}
bool subset (hb_subset_context_t *c) const
@@ -253,9 +256,9 @@ struct CaretValue
const ItemVariationStore &var_store) const
{
switch (u.format.v) {
- case 1: return u.format1.get_caret_value (font, direction);
- case 2: return u.format2.get_caret_value (font, direction, glyph_id);
- case 3: return u.format3.get_caret_value (font, direction, var_store);
+ case 1: hb_barrier (); return u.format1.get_caret_value (font, direction);
+ case 2: hb_barrier (); return u.format2.get_caret_value (font, direction, glyph_id);
+ case 3: hb_barrier (); return u.format3.get_caret_value (font, direction, var_store);
default:return 0;
}
}
@@ -266,9 +269,9 @@ struct CaretValue
if (unlikely (!c->may_dispatch (this, &u.format.v))) return c->no_dispatch_return_value ();
TRACE_DISPATCH (this, u.format.v);
switch (u.format.v) {
- case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...));
- case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...));
- case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...));
+ case 1: hb_barrier (); return_trace (c->dispatch (u.format1, std::forward (ds)...));
+ case 2: hb_barrier (); return_trace (c->dispatch (u.format2, std::forward (ds)...));
+ case 3: hb_barrier (); return_trace (c->dispatch (u.format3, std::forward (ds)...));
default:return_trace (c->default_return_value ());
}
}
@@ -280,6 +283,7 @@ struct CaretValue
case 2:
return;
case 3:
+ hb_barrier ();
u.format3.collect_variation_indices (c);
return;
default: return;
@@ -292,9 +296,9 @@ struct CaretValue
if (!u.format.v.sanitize (c)) return_trace (false);
hb_barrier ();
switch (u.format.v) {
- case 1: return_trace (u.format1.sanitize (c));
- case 2: return_trace (u.format2.sanitize (c));
- case 3: return_trace (u.format3.sanitize (c));
+ case 1: hb_barrier (); return_trace (u.format1.sanitize (c));
+ case 2: hb_barrier (); return_trace (u.format2.sanitize (c));
+ case 3: hb_barrier (); return_trace (u.format3.sanitize (c));
default:return_trace (true);
}
}
@@ -320,7 +324,7 @@ struct LigGlyph
unsigned *caret_count /* IN/OUT */,
hb_position_t *caret_array /* OUT */) const
{
- if (caret_count)
+ if (caret_count && caret_array)
{
+ carets.as_array ().sub_array (start_offset, caret_count)
| hb_map (hb_add (this))
@@ -366,6 +370,9 @@ struct LigGlyph
DEFINE_SIZE_ARRAY (2, carets);
};
+/* LigCaretList2 widens the LigCaretList coverage, count, and LigGlyph
+ * offsets. The LigGlyph table itself keeps Offset16 caretValueOffsets. */
+template
struct LigCaretList
{
unsigned int get_lig_carets (hb_font_t *font,
@@ -425,16 +432,21 @@ struct LigCaretList
}
protected:
- Offset16To
+ typename Types::template LOffsetTo
coverage; /* Offset to Coverage table--from
* beginning of LigCaretList table */
- Array16OfOffset16To
+ typename Types::template ArrayOf>
ligGlyph; /* Array of LigGlyph tables
* in Coverage Index order */
public:
- DEFINE_SIZE_ARRAY (4, ligGlyph);
+ DEFINE_SIZE_ARRAY (Types::LOffset::static_size + Types::HBUINT::static_size, ligGlyph);
};
+#ifndef HB_NO_BEYOND_64K
+static_assert (LigCaretList::min_size ==
+ Offset32::static_size + HBUINT24::static_size, "");
+#endif
+
struct MarkGlyphSetsFormat1
{
@@ -520,7 +532,7 @@ struct MarkGlyphSets
bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const
{
switch (u.format.v) {
- case 1: return u.format1.covers (set_index, glyph_id);
+ case 1: hb_barrier (); return u.format1.covers (set_index, glyph_id);
default:return false;
}
}
@@ -529,7 +541,7 @@ struct MarkGlyphSets
void collect_coverage (hb_vector_t &sets) const
{
switch (u.format.v) {
- case 1: u.format1.collect_coverage (sets); return;
+ case 1: hb_barrier (); u.format1.collect_coverage (sets); return;
default:return;
}
}
@@ -538,7 +550,7 @@ struct MarkGlyphSets
hb_set_t& used_mark_sets /* OUT */) const
{
switch (u.format.v) {
- case 1: u.format1.collect_used_mark_sets (glyph_set, used_mark_sets); return;
+ case 1: hb_barrier (); u.format1.collect_used_mark_sets (glyph_set, used_mark_sets); return;
default:return;
}
}
@@ -547,7 +559,7 @@ struct MarkGlyphSets
{
TRACE_SUBSET (this);
switch (u.format.v) {
- case 1: return_trace (u.format1.subset (c));
+ case 1: hb_barrier (); return_trace (u.format1.subset (c));
default:return_trace (false);
}
}
@@ -558,7 +570,7 @@ struct MarkGlyphSets
if (!u.format.v.sanitize (c)) return_trace (false);
hb_barrier ();
switch (u.format.v) {
- case 1: return_trace (u.format1.sanitize (c));
+ case 1: hb_barrier (); return_trace (u.format1.sanitize (c));
default:return_trace (true);
}
}
@@ -579,86 +591,73 @@ struct MarkGlyphSets
*/
-template
-struct GDEFVersion1_2
+struct GDEF
{
- friend struct GDEF;
+ static constexpr hb_tag_t tableTag = HB_OT_TAG_GDEF;
- protected:
- FixedVersion<>version; /* Version of the GDEF table--currently
- * 0x00010003u */
- typename Types::template OffsetTo
- glyphClassDef; /* Offset to class definition table
- * for glyph type--from beginning of
- * GDEF header (may be Null) */
- typename Types::template OffsetTo
- attachList; /* Offset to list of glyphs with
- * attachment points--from beginning
- * of GDEF header (may be Null) */
- typename Types::template OffsetTo
- ligCaretList; /* Offset to list of positioning points
- * for ligature carets--from beginning
- * of GDEF header (may be Null) */
- typename Types::template OffsetTo
- markAttachClassDef; /* Offset to class definition table for
- * mark attachment type--from beginning
- * of GDEF header (may be Null) */
- typename Types::template OffsetTo
- markGlyphSetsDef; /* Offset to the table of mark set
- * definitions--from beginning of GDEF
- * header (may be NULL). Introduced
- * in version 0x00010002. */
- Offset32To
- varStore; /* Offset to the table of Item Variation
- * Store--from beginning of GDEF
- * header (may be NULL). Introduced
- * in version 0x00010003. */
- public:
- DEFINE_SIZE_MIN (4 + 4 * Types::size);
+ enum GlyphClasses {
+ UnclassifiedGlyph = 0,
+ BaseGlyph = 1,
+ LigatureGlyph = 2,
+ MarkGlyph = 3,
+ ComponentGlyph = 4
+ };
size_t get_size () const
{
+ if (version.major != 1) return version.static_size;
+
return min_size +
(version.to_int () >= 0x00010002u ? markGlyphSetsDef.static_size : 0) +
- (version.to_int () >= 0x00010003u ? varStore.static_size : 0);
+ (version.to_int () >= 0x00010003u ? varStore.static_size : 0) +
+#ifndef HB_NO_BEYOND_64K
+ (version.to_int () >= 0x00010004u ? 5 * Offset32::static_size : 0)
+#else
+ 0
+#endif
+ ;
}
bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
- return_trace (version.sanitize (c) &&
- glyphClassDef.sanitize (c, this) &&
- attachList.sanitize (c, this) &&
- ligCaretList.sanitize (c, this) &&
- markAttachClassDef.sanitize (c, this) &&
- hb_barrier () &&
- ((version.to_int () < 0x00010002u && hb_barrier ()) || markGlyphSetsDef.sanitize (c, this)) &&
- ((version.to_int () < 0x00010003u && hb_barrier ()) || varStore.sanitize (c, this)));
- }
+ if (unlikely (!version.sanitize (c) ||
+ version.major != 1 ||
+ !c->check_range (this, get_size ())))
+ return_trace (false);
+ hb_barrier ();
- static void remap_varidx_after_instantiation (const hb_map_t& varidx_map,
- hb_hashmap_t>& layout_variation_idx_delta_map /* IN/OUT */)
- {
- /* varidx_map is empty which means varstore is empty after instantiation,
- * no variations, map all varidx to HB_OT_LAYOUT_NO_VARIATIONS_INDEX.
- * varidx_map doesn't have original varidx, indicating delta row is all
- * zeros, map varidx to HB_OT_LAYOUT_NO_VARIATIONS_INDEX */
- for (auto _ : layout_variation_idx_delta_map.iter_ref ())
+ bool glyph_class_def_ok = glyphClassDef.sanitize (c, this);
+ bool attach_list_ok = attachList.sanitize (c, this);
+ bool lig_caret_list_ok = ligCaretList.sanitize (c, this);
+ bool mark_attach_class_def_ok = markAttachClassDef.sanitize (c, this);
+ bool mark_glyph_sets_def_ok = version.to_int () < 0x00010002u ||
+ markGlyphSetsDef.sanitize (c, this);
+
+#ifndef HB_NO_BEYOND_64K
+ if (version.to_int () >= 0x00010004u)
{
- /* old_varidx->(varidx, delta) mapping generated for subsetting, then this
- * varidx is used as key of varidx_map during instantiation */
- uint32_t varidx = _.second.first;
- uint32_t *new_varidx;
- if (varidx_map.has (varidx, &new_varidx))
- _.second.first = *new_varidx;
- else
- _.second.first = HB_OT_LAYOUT_NO_VARIATIONS_INDEX;
+ if (glyphClassDef2) glyph_class_def_ok = glyphClassDef2.sanitize (c, this);
+ if (attachList2) attach_list_ok = attachList2.sanitize (c, this);
+ if (ligCaretList2) lig_caret_list_ok = ligCaretList2.sanitize (c, this);
+ if (markAttachClassDef2) mark_attach_class_def_ok = markAttachClassDef2.sanitize (c, this);
+ if (markGlyphSetsDef2) mark_glyph_sets_def_ok = markGlyphSetsDef2.sanitize (c, this);
}
+#endif
+
+ return_trace (glyph_class_def_ok &&
+ attach_list_ok &&
+ lig_caret_list_ok &&
+ mark_attach_class_def_ok &&
+ mark_glyph_sets_def_ok &&
+ (version.to_int () < 0x00010003u || varStore.sanitize (c, this)));
}
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
+ if (version.major != 1) return_trace (false);
+
auto *out = c->serializer->start_embed (*this);
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
@@ -667,15 +666,29 @@ struct GDEFVersion1_2
// the end of the GDEF table.
// See: https://github.com/harfbuzz/harfbuzz/issues/4636
auto snapshot_version0 = c->serializer->snapshot ();
- if (unlikely (version.to_int () >= 0x00010002u && hb_barrier () && !c->serializer->embed (markGlyphSetsDef)))
+ if (unlikely (version.to_int () >= 0x00010002u && hb_barrier () &&
+ !c->serializer->embed (markGlyphSetsDef)))
+ return_trace (false);
+
+ auto snapshot_version2 = c->serializer->snapshot ();
+ if (unlikely (version.to_int () >= 0x00010003u && hb_barrier () &&
+ !c->serializer->embed (varStore)))
return_trace (false);
+ bool use_v14 = false;
+#ifndef HB_NO_BEYOND_64K
+ use_v14 = version.to_int () >= 0x00010004u &&
+ (glyphClassDef2 || attachList2 || ligCaretList2 ||
+ markAttachClassDef2 || markGlyphSetsDef2);
+ if (unlikely (version.to_int () >= 0x00010004u && hb_barrier () &&
+ !c->serializer->extend_size (out, get_size ())))
+ return_trace (false);
+#endif
+
bool subset_varstore = false;
unsigned varstore_index = (unsigned) -1;
- auto snapshot_version2 = c->serializer->snapshot ();
if (version.to_int () >= 0x00010003u && hb_barrier ())
{
- if (unlikely (!c->serializer->embed (varStore))) return_trace (false);
if (c->plan->all_axes_pinned)
out->varStore = 0;
else if (c->plan->normalized_coords)
@@ -683,22 +696,26 @@ struct GDEFVersion1_2
if (varStore)
{
item_variations_t item_vars;
- if (item_vars.instantiate (this+varStore, c->plan, true, true,
- c->plan->gdef_varstore_inner_maps.as_array ())) {
- subset_varstore = out->varStore.serialize_serialize (c->serializer,
- item_vars.has_long_word (),
- c->plan->axis_tags,
- item_vars.get_region_list (),
- item_vars.get_vardata_encodings ());
- varstore_index = c->serializer->last_added_child_index();
- }
+ if (unlikely (!c->serializer->check_success (
+ item_vars.instantiate (this+varStore, c->plan, true, true,
+ c->plan->gdef_varstore_inner_maps.as_array (), true))))
+ return_trace (false);
+ subset_varstore = out->varStore.serialize_serialize (c->serializer,
+ item_vars.has_long_word (),
+ c->plan->axis_tags,
+ item_vars.get_region_list (),
+ item_vars.get_vardata_encodings ());
+ varstore_index = c->serializer->last_added_child_index();
remap_varidx_after_instantiation (item_vars.get_varidx_map (),
c->plan->layout_variation_idx_delta_map);
+ remap_varidx_after_instantiation (item_vars.get_varidx_map (),
+ c->plan->layout_condition_idx_value_map);
}
}
else
{
- subset_varstore = out->varStore.serialize_subset (c, varStore, this, c->plan->gdef_varstore_inner_maps.as_array ());
+ subset_varstore = out->varStore.serialize_subset (c, varStore, this,
+ c->plan->gdef_varstore_inner_maps.as_array ());
varstore_index = c->serializer->last_added_child_index();
}
}
@@ -706,20 +723,39 @@ struct GDEFVersion1_2
out->version.major = version.major;
out->version.minor = version.minor;
- if (!subset_varstore && version.to_int () >= 0x00010002u) {
+ if (!subset_varstore && version.to_int () >= 0x00010002u && !use_v14) {
c->serializer->revert (snapshot_version2);
}
+ if (!subset_varstore)
+ out->varStore = 0;
+ else
+ c->plan->has_gdef_varstore = true;
bool subset_markglyphsetsdef = false;
if (version.to_int () >= 0x00010002u && hb_barrier ())
{
- subset_markglyphsetsdef = out->markGlyphSetsDef.serialize_subset (c, markGlyphSetsDef, this);
+#ifndef HB_NO_BEYOND_64K
+ if (use_v14 && markGlyphSetsDef2)
+ {
+ out->markGlyphSetsDef = 0;
+ subset_markglyphsetsdef = serialize_subset_offset (c, out->markGlyphSetsDef2,
+ markGlyphSetsDef2, this);
+ }
+ else
+#endif
+ {
+#ifndef HB_NO_BEYOND_64K
+ if (use_v14) out->markGlyphSetsDef2 = 0;
+#endif
+ subset_markglyphsetsdef = out->markGlyphSetsDef.serialize_subset (c, markGlyphSetsDef, this);
+ }
}
- if (subset_varstore)
+ if (use_v14)
{
+ out->version.minor = 4;
+ } else if (subset_varstore) {
out->version.minor = 3;
- c->plan->has_gdef_varstore = true;
} else if (subset_markglyphsetsdef) {
out->version.minor = 2;
} else {
@@ -727,193 +763,160 @@ struct GDEFVersion1_2
c->serializer->revert (snapshot_version0);
}
- bool subset_glyphclassdef = out->glyphClassDef.serialize_subset (c, glyphClassDef, this, nullptr, false, true);
- bool subset_attachlist = out->attachList.serialize_subset (c, attachList, this);
- bool subset_markattachclassdef = out->markAttachClassDef.serialize_subset (c, markAttachClassDef, this, nullptr, false, true);
- bool subset_ligcaretlist = out->ligCaretList.serialize_subset (c, ligCaretList, this);
+ bool subset_glyphclassdef = false;
+ bool subset_attachlist = false;
+ bool subset_markattachclassdef = false;
+ bool subset_ligcaretlist = false;
- if (subset_varstore && varstore_index != (unsigned) -1) {
- c->serializer->repack_last(varstore_index);
+#ifndef HB_NO_BEYOND_64K
+ if (use_v14 && glyphClassDef2)
+ {
+ out->glyphClassDef = 0;
+ subset_glyphclassdef = serialize_subset_offset (c, out->glyphClassDef2,
+ glyphClassDef2, this, nullptr, false, true);
+ }
+ else
+#endif
+ {
+#ifndef HB_NO_BEYOND_64K
+ if (use_v14) out->glyphClassDef2 = 0;
+#endif
+ subset_glyphclassdef = out->glyphClassDef.serialize_subset (c, glyphClassDef, this, nullptr, false, true);
}
- return_trace (subset_glyphclassdef || subset_attachlist ||
- subset_ligcaretlist || subset_markattachclassdef ||
- (out->version.to_int () >= 0x00010002u && subset_markglyphsetsdef) ||
- (out->version.to_int () >= 0x00010003u && subset_varstore));
- }
-};
-
-struct GDEF
-{
- static constexpr hb_tag_t tableTag = HB_OT_TAG_GDEF;
-
- enum GlyphClasses {
- UnclassifiedGlyph = 0,
- BaseGlyph = 1,
- LigatureGlyph = 2,
- MarkGlyph = 3,
- ComponentGlyph = 4
- };
-
- size_t get_size () const
- {
- switch (u.version.major) {
- case 1: return u.version1.get_size ();
#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.get_size ();
+ if (use_v14 && attachList2)
+ {
+ out->attachList = 0;
+ subset_attachlist = serialize_subset_offset (c, out->attachList2, attachList2, this);
+ }
+ else
#endif
- default: return u.version.static_size;
+ {
+#ifndef HB_NO_BEYOND_64K
+ if (use_v14) out->attachList2 = 0;
+#endif
+ subset_attachlist = out->attachList.serialize_subset (c, attachList, this);
}
- }
- bool sanitize (hb_sanitize_context_t *c) const
- {
- TRACE_SANITIZE (this);
- if (unlikely (!u.version.sanitize (c))) return_trace (false);
- hb_barrier ();
- switch (u.version.major) {
- case 1: return_trace (u.version1.sanitize (c));
#ifndef HB_NO_BEYOND_64K
- case 2: return_trace (u.version2.sanitize (c));
+ if (use_v14 && markAttachClassDef2)
+ {
+ out->markAttachClassDef = 0;
+ subset_markattachclassdef = serialize_subset_offset (c, out->markAttachClassDef2,
+ markAttachClassDef2, this, nullptr, false, true);
+ }
+ else
+#endif
+ {
+#ifndef HB_NO_BEYOND_64K
+ if (use_v14) out->markAttachClassDef2 = 0;
#endif
- default: return_trace (true);
+ subset_markattachclassdef = out->markAttachClassDef.serialize_subset (c, markAttachClassDef,
+ this, nullptr, false, true);
}
- }
- bool subset (hb_subset_context_t *c) const
- {
- switch (u.version.major) {
- case 1: return u.version1.subset (c);
#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.subset (c);
+ if (use_v14 && ligCaretList2)
+ {
+ out->ligCaretList = 0;
+ subset_ligcaretlist = serialize_subset_offset (c, out->ligCaretList2, ligCaretList2, this);
+ }
+ else
+#endif
+ {
+#ifndef HB_NO_BEYOND_64K
+ if (use_v14) out->ligCaretList2 = 0;
#endif
- default: return false;
+ subset_ligcaretlist = out->ligCaretList.serialize_subset (c, ligCaretList, this);
}
+
+ if (subset_varstore && varstore_index != (unsigned) -1) {
+ c->serializer->repack_last(varstore_index);
+ }
+
+ return_trace (subset_glyphclassdef || subset_attachlist ||
+ subset_ligcaretlist || subset_markattachclassdef ||
+ (out->version.to_int () >= 0x00010002u && subset_markglyphsetsdef) ||
+ (out->version.to_int () >= 0x00010003u && subset_varstore));
}
bool has_glyph_classes () const
{
- switch (u.version.major) {
- case 1: return u.version1.glyphClassDef != 0;
#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.glyphClassDef != 0;
+ if (version.to_int () >= 0x00010004u && glyphClassDef2) return true;
#endif
- default: return false;
- }
+ return glyphClassDef != 0;
}
const ClassDef &get_glyph_class_def () const
{
- switch (u.version.major) {
- case 1: return this+u.version1.glyphClassDef;
#ifndef HB_NO_BEYOND_64K
- case 2: return this+u.version2.glyphClassDef;
+ if (version.to_int () >= 0x00010004u && glyphClassDef2) return this+glyphClassDef2;
#endif
- default: return Null(ClassDef);
- }
+ return this+glyphClassDef;
}
bool has_attach_list () const
{
- switch (u.version.major) {
- case 1: return u.version1.attachList != 0;
#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.attachList != 0;
+ if (version.to_int () >= 0x00010004u && attachList2) return true;
#endif
- default: return false;
- }
+ return attachList != 0;
}
const AttachList &get_attach_list () const
{
- switch (u.version.major) {
- case 1: return this+u.version1.attachList;
#ifndef HB_NO_BEYOND_64K
- case 2: return this+u.version2.attachList;
+ if (version.to_int () >= 0x00010004u && attachList2) return this+attachList2;
#endif
- default: return Null(AttachList);
- }
+ return this+attachList;
}
bool has_lig_carets () const
{
- switch (u.version.major) {
- case 1: return u.version1.ligCaretList != 0;
#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.ligCaretList != 0;
+ if (version.to_int () >= 0x00010004u && ligCaretList2) return true;
#endif
- default: return false;
- }
- }
- const LigCaretList &get_lig_caret_list () const
- {
- switch (u.version.major) {
- case 1: return this+u.version1.ligCaretList;
-#ifndef HB_NO_BEYOND_64K
- case 2: return this+u.version2.ligCaretList;
-#endif
- default: return Null(LigCaretList);
- }
+ return ligCaretList != 0;
}
bool has_mark_attachment_types () const
{
- switch (u.version.major) {
- case 1: return u.version1.markAttachClassDef != 0;
#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.markAttachClassDef != 0;
+ if (version.to_int () >= 0x00010004u && markAttachClassDef2) return true;
#endif
- default: return false;
- }
+ return markAttachClassDef != 0;
}
const ClassDef &get_mark_attach_class_def () const
{
- switch (u.version.major) {
- case 1: return this+u.version1.markAttachClassDef;
#ifndef HB_NO_BEYOND_64K
- case 2: return this+u.version2.markAttachClassDef;
+ if (version.to_int () >= 0x00010004u && markAttachClassDef2) return this+markAttachClassDef2;
#endif
- default: return Null(ClassDef);
- }
+ return this+markAttachClassDef;
}
bool has_mark_glyph_sets () const
{
- switch (u.version.major) {
- case 1: return u.version.to_int () >= 0x00010002u && hb_barrier () && u.version1.markGlyphSetsDef != 0;
+ if (version.to_int () < 0x00010002u) return false;
#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.markGlyphSetsDef != 0;
+ if (version.to_int () >= 0x00010004u && markGlyphSetsDef2) return true;
#endif
- default: return false;
- }
+ return markGlyphSetsDef != 0;
}
const MarkGlyphSets &get_mark_glyph_sets () const
{
- switch (u.version.major) {
- case 1: return u.version.to_int () >= 0x00010002u && hb_barrier () ? this+u.version1.markGlyphSetsDef : Null(MarkGlyphSets);
+ if (version.to_int () < 0x00010002u) return Null(MarkGlyphSets);
#ifndef HB_NO_BEYOND_64K
- case 2: return this+u.version2.markGlyphSetsDef;
+ if (version.to_int () >= 0x00010004u && markGlyphSetsDef2) return this+markGlyphSetsDef2;
#endif
- default: return Null(MarkGlyphSets);
- }
+ return this+markGlyphSetsDef;
}
bool has_var_store () const
{
- switch (u.version.major) {
- case 1: return u.version.to_int () >= 0x00010003u && hb_barrier () && u.version1.varStore != 0;
-#ifndef HB_NO_BEYOND_64K
- case 2: return u.version2.varStore != 0;
-#endif
- default: return false;
- }
+ return version.to_int () >= 0x00010003u && hb_barrier () && varStore != 0;
}
const ItemVariationStore &get_var_store () const
{
- switch (u.version.major) {
- case 1: return u.version.to_int () >= 0x00010003u && hb_barrier () ? this+u.version1.varStore : Null(ItemVariationStore);
-#ifndef HB_NO_BEYOND_64K
- case 2: return this+u.version2.varStore;
-#endif
- default: return Null(ItemVariationStore);
- }
+ return version.to_int () >= 0x00010003u && hb_barrier () ? this+varStore : Null(ItemVariationStore);
}
- bool has_data () const { return u.version.to_int (); }
+ bool has_data () const { return version.to_int (); }
unsigned int get_glyph_class (hb_codepoint_t glyph) const
{ return get_glyph_class_def ().get_class (glyph); }
void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const
@@ -934,9 +937,15 @@ struct GDEF
unsigned int start_offset,
unsigned int *caret_count /* IN/OUT */,
hb_position_t *caret_array /* OUT */) const
- { return get_lig_caret_list ().get_lig_carets (font,
- direction, glyph_id, get_var_store(),
- start_offset, caret_count, caret_array); }
+ {
+#ifndef HB_NO_BEYOND_64K
+ if (version.to_int () >= 0x00010004u && ligCaretList2)
+ return (this+ligCaretList2).get_lig_carets (font, direction, glyph_id, get_var_store (),
+ start_offset, caret_count, caret_array);
+#endif
+ return (this+ligCaretList).get_lig_carets (font, direction, glyph_id, get_var_store (),
+ start_offset, caret_count, caret_array);
+ }
bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
{ return get_mark_glyph_sets ().covers (set_index, glyph_id); }
@@ -977,7 +986,39 @@ struct GDEF
}
#ifndef HB_NO_GDEF_CACHE
- table->get_mark_glyph_sets ().collect_coverage (mark_glyph_sets);
+ /* Flatten each mark set whose glyphs span fewer than PAGE_BITS
+ * gids into a single bit-page biased at its first glyph, for
+ * O(1) exact answers. Wider sets, or on allocation failure,
+ * fall back to the table. */
+ {
+ hb_vector_t sets;
+ table->get_mark_glyph_sets ().collect_coverage (sets);
+ if (!sets.in_error () &&
+ mark_glyph_set_bitmaps.resize (sets.length))
+ for (unsigned i = 0; i < sets.length; i++)
+ {
+ auto &bitmap = mark_glyph_set_bitmaps.arrayZ[i];
+ bitmap.bias = HB_SET_VALUE_INVALID;
+ const auto &set = sets.arrayZ[i];
+ if (unlikely (set.in_error ())) continue;
+ hb_codepoint_t min_gid = HB_SET_VALUE_INVALID;
+ hb_codepoint_t max_gid = HB_SET_VALUE_INVALID;
+ hb_set_next (&set, &min_gid);
+ hb_set_previous (&set, &max_gid);
+ if (max_gid == HB_SET_VALUE_INVALID)
+ continue;
+ if (max_gid - min_gid >= hb_bit_page_t::PAGE_BITS)
+ {
+ /* Too wide for one page; a digest pre-filter instead. */
+ for (hb_codepoint_t gid : set)
+ bitmap.u.digest.add (gid);
+ continue;
+ }
+ bitmap.bias = min_gid;
+ for (hb_codepoint_t gid : set)
+ bitmap.u.page.add (gid - min_gid);
+ }
+ }
#endif
}
~accelerator_t () { table.destroy (); }
@@ -1005,20 +1046,37 @@ struct GDEF
HB_ALWAYS_INLINE
bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const
{
- return
#ifndef HB_NO_GDEF_CACHE
- // We can access arrayZ directly because of sanitize_lookup_props() guarantee.
- mark_glyph_sets.arrayZ[set_index].may_have (glyph_id) &&
+ // We can access arrayZ directly because of sanitize_lookup_props() guarantee.
+ const auto &bitmap = mark_glyph_set_bitmaps.arrayZ[set_index];
+ if (likely (bitmap.bias != HB_SET_VALUE_INVALID))
+ {
+ hb_codepoint_t biased = glyph_id - bitmap.bias;
+ return biased < hb_bit_page_t::PAGE_BITS &&
+ bitmap.u.page.get (biased);
+ }
+ return mark_set_covers_slow (set_index, glyph_id);
+#else
+ return table->mark_set_covers (set_index, glyph_id);
#endif
- table->mark_set_covers (set_index, glyph_id)
- ;
}
+#ifndef HB_NO_GDEF_CACHE
+ HB_NEVER_INLINE
+ bool mark_set_covers_slow (unsigned int set_index, hb_codepoint_t glyph_id) const
+ {
+ const auto &bitmap = mark_glyph_set_bitmaps.arrayZ[set_index];
+ if (!bitmap.u.digest.may_have (glyph_id))
+ return false;
+ return table->mark_set_covers (set_index, glyph_id);
+ }
+#endif
+
unsigned sanitize_lookup_props (unsigned lookup_props) const
{
#ifndef HB_NO_GDEF_CACHE
if (lookup_props & LookupFlag::UseMarkFilteringSet &&
- (lookup_props >> 16) >= mark_glyph_sets.length)
+ (lookup_props >> 16) >= mark_glyph_set_bitmaps.length)
{
// Invalid mark filtering set index; unset the flag.
lookup_props &= ~LookupFlag::UseMarkFilteringSet;
@@ -1029,25 +1087,128 @@ struct GDEF
hb_blob_ptr_t table;
#ifndef HB_NO_GDEF_CACHE
- hb_vector_t mark_glyph_sets;
+ struct mark_glyph_set_bitmap_t
+ {
+ /* Gid of the first bit (not page-aligned) for an exact one-page
+ * set, or HB_SET_VALUE_INVALID; then digest is a pre-filter for
+ * the table. The all-zeros state is valid for both members. */
+ hb_codepoint_t bias = HB_SET_VALUE_INVALID;
+ union u_t {
+ u_t () : page () {}
+ hb_bit_page_t page;
+ hb_set_digest_t digest;
+ } u;
+ };
+
+ hb_vector_t mark_glyph_set_bitmaps;
mutable hb_cache_t<21, 3> glyph_props_cache;
static_assert (sizeof (glyph_props_cache) == 512, "");
#endif
};
void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
- { get_lig_caret_list ().collect_variation_indices (c); }
+ {
+#ifndef HB_NO_BEYOND_64K
+ if (version.to_int () >= 0x00010004u && ligCaretList2)
+ {
+ (this+ligCaretList2).collect_variation_indices (c);
+ return;
+ }
+#endif
+ (this+ligCaretList).collect_variation_indices (c);
+ }
protected:
- union {
- FixedVersion<> version; /* Version identifier */
- GDEFVersion1_2 version1;
+ template
+ static void remap_varidx_after_instantiation (const hb_map_t& varidx_map,
+ hb_hashmap_t>& layout_variation_idx_delta_map /* IN/OUT */)
+ {
+ /* varidx_map is empty which means varstore is empty after instantiation,
+ * no variations, map all varidx to HB_OT_LAYOUT_NO_VARIATIONS_INDEX.
+ * varidx_map doesn't have original varidx, indicating delta row is all
+ * zeros, map varidx to HB_OT_LAYOUT_NO_VARIATIONS_INDEX */
+ for (auto _ : layout_variation_idx_delta_map.iter_ref ())
+ {
+ /* old_varidx->(varidx, delta) mapping generated for subsetting, then this
+ * varidx is used as key of varidx_map during instantiation */
+ uint32_t varidx = _.second.first;
+ uint32_t *new_varidx;
+ if (varidx_map.has (varidx, &new_varidx))
+ _.second.first = *new_varidx;
+ else
+ _.second.first = HB_OT_LAYOUT_NO_VARIATIONS_INDEX;
+ }
+ }
+
+ template
+ static bool serialize_subset_offset (hb_subset_context_t *c,
+ OffsetOut& out,
+ const OffsetIn& in,
+ const Base *base,
+ Ts&&... ds)
+ {
+ out = 0;
+ if (in.is_null ()) return false;
+
+ auto *s = c->serializer;
+ s->push ();
+ bool ret = c->dispatch (base+in, std::forward (ds)...);
+ if (ret) s->add_link (out, s->pop_pack ());
+ else s->pop_discard ();
+ return ret;
+ }
+
+ FixedVersion<>version; /* Version of the GDEF table--currently
+ * 0x00010004u */
+ Offset16To
+ glyphClassDef; /* Offset to class definition table
+ * for glyph type--from beginning of
+ * GDEF header (may be Null) */
+ Offset16To
+ attachList; /* Offset to list of glyphs with
+ * attachment points--from beginning
+ * of GDEF header (may be Null) */
+ Offset16To>
+ ligCaretList; /* Offset to list of positioning points
+ * for ligature carets--from beginning
+ * of GDEF header (may be Null) */
+ Offset16To
+ markAttachClassDef; /* Offset to class definition table for
+ * mark attachment type--from beginning
+ * of GDEF header (may be Null) */
+ Offset16To
+ markGlyphSetsDef; /* Offset to the table of mark set
+ * definitions--from beginning of GDEF
+ * header (may be NULL). Introduced
+ * in version 0x00010002. */
+ Offset32To
+ varStore; /* Offset to the table of Item Variation
+ * Store--from beginning of GDEF
+ * header (may be NULL). Introduced
+ * in version 0x00010003. */
#ifndef HB_NO_BEYOND_64K
- GDEFVersion1_2 version2;
+ Offset32To
+ glyphClassDef2; /* 32-bit offset to class definition
+ * table for glyph type. Introduced
+ * in version 0x00010004. */
+ Offset32To
+ attachList2; /* 32-bit offset to list of glyphs
+ * with attachment points. Introduced
+ * in version 0x00010004. */
+ Offset32To>
+ ligCaretList2; /* 32-bit offset to LigCaretList2.
+ * Introduced in version 0x00010004. */
+ Offset32To
+ markAttachClassDef2; /* 32-bit offset to class definition
+ * table for mark attachment type.
+ * Introduced in version 0x00010004. */
+ Offset32To
+ markGlyphSetsDef2; /* 32-bit offset to the table of mark
+ * set definitions. Introduced in
+ * version 0x00010004. */
#endif
- } u;
public:
- DEFINE_SIZE_MIN (4);
+ DEFINE_SIZE_MIN (12);
};
struct GDEF_accelerator_t : GDEF::accelerator_t {
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/Anchor.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/Anchor.hh
index 1938803fa7c4..48c509c25d2a 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/Anchor.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/Anchor.hh
@@ -27,9 +27,9 @@ struct Anchor
if (!u.format.v.sanitize (c)) return_trace (false);
hb_barrier ();
switch (u.format.v) {
- case 1: return_trace (u.format1.sanitize (c));
- case 2: return_trace (u.format2.sanitize (c));
- case 3: return_trace (u.format3.sanitize (c));
+ case 1: hb_barrier (); return_trace (u.format1.sanitize (c));
+ case 2: hb_barrier (); return_trace (u.format2.sanitize (c));
+ case 3: hb_barrier (); return_trace (u.format3.sanitize (c));
default:return_trace (true);
}
}
@@ -39,9 +39,9 @@ struct Anchor
{
*x = *y = 0;
switch (u.format.v) {
- case 1: u.format1.get_anchor (c, glyph_id, x, y); return;
- case 2: u.format2.get_anchor (c, glyph_id, x, y); return;
- case 3: u.format3.get_anchor (c, glyph_id, x, y); return;
+ case 1: hb_barrier (); u.format1.get_anchor (c, glyph_id, x, y); return;
+ case 2: hb_barrier (); u.format2.get_anchor (c, glyph_id, x, y); return;
+ case 3: hb_barrier (); u.format3.get_anchor (c, glyph_id, x, y); return;
default: return;
}
}
@@ -50,8 +50,9 @@ struct Anchor
{
TRACE_SUBSET (this);
switch (u.format.v) {
- case 1: return_trace (bool (reinterpret_cast (u.format1.copy (c->serializer))));
+ case 1: hb_barrier (); return_trace (bool (reinterpret_cast (u.format1.copy (c->serializer))));
case 2:
+ hb_barrier ();
if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
{
// AnchorFormat 2 just containins extra hinting information, so
@@ -59,7 +60,7 @@ struct Anchor
return_trace (bool (reinterpret_cast (u.format1.copy (c->serializer))));
}
return_trace (bool (reinterpret_cast (u.format2.copy (c->serializer))));
- case 3: return_trace (u.format3.subset (c));
+ case 3: hb_barrier (); return_trace (u.format3.subset (c));
default:return_trace (false);
}
}
@@ -70,6 +71,7 @@ struct Anchor
case 1: case 2:
return;
case 3:
+ hb_barrier ();
u.format3.collect_variation_indices (c);
return;
default: return;
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorFormat3.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorFormat3.hh
index c49705bea0eb..1bf4b92b0379 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorFormat3.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorFormat3.hh
@@ -40,12 +40,12 @@ struct AnchorFormat3
if ((font->x_ppem || font->has_nonzero_coords) && xDeviceTable.sanitize (&c->sanitizer, this))
{
hb_barrier ();
- *x += (this+xDeviceTable).get_x_delta (font, c->var_store, c->var_store_cache);
+ *x += (this+xDeviceTable).get_x_delta_f (font, c->var_store, c->var_store_cache);
}
if ((font->y_ppem || font->has_nonzero_coords) && yDeviceTable.sanitize (&c->sanitizer, this))
{
hb_barrier ();
- *y += (this+yDeviceTable).get_y_delta (font, c->var_store, c->var_store_cache);
+ *y += (this+yDeviceTable).get_y_delta_f (font, c->var_store, c->var_store_cache);
}
}
diff --git a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorMatrix.hh b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorMatrix.hh
index 128ced6c176d..6ef66701c254 100644
--- a/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorMatrix.hh
+++ b/src/java.desktop/share/native/libharfbuzz/OT/Layout/GPOS/AnchorMatrix.hh
@@ -5,14 +5,87 @@ namespace OT {
namespace Layout {
namespace GPOS_impl {
+HB_INTERNAL inline
+void collect_ligature_anchor_indexes (unsigned rows,
+ unsigned class_count,
+ const hb_map_t &klass_mapping,
+ hb_sorted_vector_t &indexes)
+{
+ for (unsigned row = 0; row < rows; row++)
+ for (unsigned col = 0; col < class_count; col++)
+ if (klass_mapping.has (col))
+ indexes.push (row * class_count + col);
+}
+
+HB_INTERNAL inline
+void collect_anchor_variation_indices (hb_collect_variation_indices_context_t *c,
+ const void *base,
+ glyph_data_t offsets,
+ hb_array_t indexes)
+{
+ for (unsigned i : indexes)
+ {
+ unsigned offset = offsets[i];
+ if (offset)
+ StructAtOffset (base, offset).collect_variation_indices (c);
+ }
+}
+
+HB_INTERNAL inline
+void collect_anchor_indexes (const Coverage &coverage,
+ unsigned rows,
+ unsigned class_count,
+ const hb_set_t &glyphset,
+ const hb_map_t &klass_mapping,
+ hb_sorted_vector_t