Bug 1873636 - vendor gfx/ots using mach vendor r=jfkthame

As a consequence, explicitly extract bug 1850314 as a patch.

Differential Revision: https://phabricator.services.mozilla.com/D198006
This commit is contained in:
serge-sans-paille 2024-01-18 13:26:28 +00:00
Родитель e59458d592
Коммит a9dd5d2659
7 изменённых файлов: 231 добавлений и 66 удалений

Просмотреть файл

@ -1,13 +0,0 @@
This is the Sanitiser for OpenType project, from http://code.google.com/p/ots/.
Our reference repository is https://github.com/khaledhosny/ots/.
Current revision: 6ba665aa307ea360283191736814863ca398398d (9.1.0)
Upstream files included: LICENSE, src/, include/, tests/*.cc
Additional files: README.mozilla, src/moz.build
Additional patch: ots-visibility.patch (bug 711079).
Additional patch: ots-lz4.patch
Additional patch: ots-rlbox.patch (bug 1732201).

42
gfx/ots/moz.yaml Normal file
Просмотреть файл

@ -0,0 +1,42 @@
schema: 1
bugzilla:
product: Core
component: "Graphics: Text"
origin:
name: ots
description: Sanitiser for OpenType project
url: https://github.com/khaledhosny/ots
release: 6ba665aa307ea360283191736814863ca398398d (2023-08-16T17:30:00Z).
revision: 6ba665aa307ea360283191736814863ca398398d
license: BSD-3-Clause
license-file: LICENSE
vendoring:
url: https://github.com/khaledhosny/ots
source-hosting: github
tracking: commit
exclude:
- ".*"
- "**"
include:
- include/
- src/
- tests/*.cc
keep:
- LICENSE
- RLBoxWOFF2Host.*
- RLBoxWOFF2Types.*
patches:
- ots-lz4.patch
- ots-rlbox.patch
- ots-visibility.patch
- ots-1850314.patch

177
gfx/ots/ots-1850314.patch Normal file
Просмотреть файл

@ -0,0 +1,177 @@
commit 362a59be47f9e187eec43df0938def661be6c972
Author: Jonathan Kew <jkew@mozilla.com>
Date: Wed Aug 30 12:55:02 2023 +0000
Bug 1850314 - Don't do glyph bounding-box fixup for "tricky" fonts, because it may disrupt glyph rendering on macOS. r=gfx-reviewers,lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D187096
diff --git a/src/glyf.cc b/src/glyf.cc
index 0ed9515ef16d6..31487957bf99b 100644
--- a/src/glyf.cc
+++ b/src/glyf.cc
@@ -10,6 +10,7 @@
#include "head.h"
#include "loca.h"
#include "maxp.h"
+#include "name.h"
// glyf - Glyph Data
// http://www.microsoft.com/typography/otspec/glyf.htm
@@ -97,7 +98,8 @@ bool OpenTypeGLYF::ParseSimpleGlyph(Buffer &glyph,
int16_t& xmin,
int16_t& ymin,
int16_t& xmax,
- int16_t& ymax) {
+ int16_t& ymax,
+ bool is_tricky_font) {
// read the end-points array
uint16_t num_flags = 0;
for (int i = 0; i < num_contours; ++i) {
@@ -219,27 +221,32 @@ bool OpenTypeGLYF::ParseSimpleGlyph(Buffer &glyph,
}
if (adjusted_bbox) {
- Warning("Glyph bbox was incorrect; adjusting (glyph %u)", gid);
- // copy the numberOfContours field
- this->iov.push_back(std::make_pair(glyph.buffer(), 2));
- // output a fixed-up version of the bounding box
- uint8_t* fixed_bbox = new uint8_t[8];
- fixed_bboxes.push_back(fixed_bbox);
- xmin = ots_htons(xmin);
- std::memcpy(fixed_bbox, &xmin, 2);
- ymin = ots_htons(ymin);
- std::memcpy(fixed_bbox + 2, &ymin, 2);
- xmax = ots_htons(xmax);
- std::memcpy(fixed_bbox + 4, &xmax, 2);
- ymax = ots_htons(ymax);
- std::memcpy(fixed_bbox + 6, &ymax, 2);
- this->iov.push_back(std::make_pair(fixed_bbox, 8));
- // copy the remainder of the glyph data
- this->iov.push_back(std::make_pair(glyph.buffer() + 10, glyph.offset() - 10));
- } else {
- this->iov.push_back(std::make_pair(glyph.buffer(), glyph.offset()));
+ if (is_tricky_font) {
+ Warning("Glyph bbox was incorrect; NOT adjusting tricky font (glyph %u)", gid);
+ } else {
+ Warning("Glyph bbox was incorrect; adjusting (glyph %u)", gid);
+ // copy the numberOfContours field
+ this->iov.push_back(std::make_pair(glyph.buffer(), 2));
+ // output a fixed-up version of the bounding box
+ uint8_t* fixed_bbox = new uint8_t[8];
+ fixed_bboxes.push_back(fixed_bbox);
+ xmin = ots_htons(xmin);
+ std::memcpy(fixed_bbox, &xmin, 2);
+ ymin = ots_htons(ymin);
+ std::memcpy(fixed_bbox + 2, &ymin, 2);
+ xmax = ots_htons(xmax);
+ std::memcpy(fixed_bbox + 4, &xmax, 2);
+ ymax = ots_htons(ymax);
+ std::memcpy(fixed_bbox + 6, &ymax, 2);
+ this->iov.push_back(std::make_pair(fixed_bbox, 8));
+ // copy the remainder of the glyph data
+ this->iov.push_back(std::make_pair(glyph.buffer() + 10, glyph.offset() - 10));
+ return true;
+ }
}
+ this->iov.push_back(std::make_pair(glyph.buffer(), glyph.offset()));
+
return true;
}
@@ -342,6 +349,10 @@ bool OpenTypeGLYF::Parse(const uint8_t *data, size_t length) {
return Error("Missing maxp or loca or head table needed by glyf table");
}
+ OpenTypeNAME *name = static_cast<OpenTypeNAME*>(
+ GetFont()->GetTypedTable(OTS_TAG_NAME));
+ bool is_tricky = name->IsTrickyFont();
+
this->maxp = maxp;
const unsigned num_glyphs = maxp->num_glyphs;
@@ -397,7 +408,7 @@ bool OpenTypeGLYF::Parse(const uint8_t *data, size_t length) {
// does we will simply ignore it.
glyph.set_offset(0);
} else if (num_contours > 0) {
- if (!ParseSimpleGlyph(glyph, i, num_contours, xmin, ymin, xmax, ymax)) {
+ if (!ParseSimpleGlyph(glyph, i, num_contours, xmin, ymin, xmax, ymax, is_tricky)) {
return Error("Failed to parse glyph %d", i);
}
} else {
diff --git a/src/glyf.h b/src/glyf.h
index 05e846f1cb6e8..f85fdc4652fcf 100644
--- a/src/glyf.h
+++ b/src/glyf.h
@@ -51,7 +51,8 @@ class OpenTypeGLYF : public Table {
int16_t& xmin,
int16_t& ymin,
int16_t& xmax,
- int16_t& ymax);
+ int16_t& ymax,
+ bool is_tricky_font);
bool ParseCompositeGlyph(
Buffer &glyph,
ComponentPointCount* component_point_count);
diff --git a/src/name.cc b/src/name.cc
index fc5074b0587a3..7526e1f72b9ea 100644
--- a/src/name.cc
+++ b/src/name.cc
@@ -366,4 +366,44 @@ bool OpenTypeNAME::IsValidNameId(uint16_t nameID, bool addIfMissing) {
return this->name_ids.count(nameID);
}
+// List of font names considered "tricky" (dependent on applying original TrueType instructions) by FreeType, see
+// https://gitlab.freedesktop.org/freetype/freetype/-/blob/2d9fce53d4ce89f36075168282fcdd7289e082f9/src/truetype/ttobjs.c#L170-241
+static const char* tricky_font_names[] = {
+ "cpop",
+ "DFGirl-W6-WIN-BF",
+ "DFGothic-EB",
+ "DFGyoSho-Lt",
+ "DFHei",
+ "DFHSGothic-W5",
+ "DFHSMincho-W3",
+ "DFHSMincho-W7",
+ "DFKaiSho-SB",
+ "DFKaiShu",
+ "DFKai-SB",
+ "DFMing",
+ "DLC",
+ "HuaTianKaiTi?",
+ "HuaTianSongTi?",
+ "Ming(for ISO10646)",
+ "MingLiU",
+ "MingMedium",
+ "PMingLiU",
+ "MingLi43"
+};
+
+bool OpenTypeNAME::IsTrickyFont() const {
+ for (const auto& name : this->names) {
+ const uint16_t id = name.name_id;
+ if (id != 1) {
+ continue;
+ }
+ for (const auto* p : tricky_font_names) {
+ if (name.text.find(p) != std::string::npos) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
} // namespace
diff --git a/src/name.h b/src/name.h
index 68c7ac096d3f8..a241e77ee26bb 100644
--- a/src/name.h
+++ b/src/name.h
@@ -52,6 +52,7 @@ class OpenTypeNAME : public Table {
bool Parse(const uint8_t *data, size_t length);
bool Serialize(OTSStream *out);
bool IsValidNameId(uint16_t nameID, bool addIfMissing = false);
+ bool IsTrickyFont() const;
private:
std::vector<NameRecord> names;

Просмотреть файл

@ -1,6 +1,6 @@
diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc
--- a/gfx/ots/src/glat.cc
+++ b/gfx/ots/src/glat.cc
diff --git a/src/glat.cc b/src/glat.cc
--- a/src/glat.cc
+++ b/src/glat.cc
@@ -4,9 +4,9 @@
#include "glat.h"
@ -35,9 +35,9 @@ diff --git a/gfx/ots/src/glat.cc b/gfx/ots/src/glat.cc
return this->Parse(decompressed.get(), decompressed_size, true);
}
default:
diff --git a/gfx/ots/src/silf.cc b/gfx/ots/src/silf.cc
--- a/gfx/ots/src/silf.cc
+++ b/gfx/ots/src/silf.cc
diff --git a/src/silf.cc b/src/silf.cc
--- a/src/silf.cc
+++ b/src/silf.cc
@@ -4,9 +4,9 @@
#include "silf.h"

Просмотреть файл

@ -1,6 +1,6 @@
diff --git a/gfx/ots/src/ots.cc b/gfx/ots/src/ots.cc
--- a/gfx/ots/src/ots.cc
+++ b/gfx/ots/src/ots.cc
diff --git a/src/ots.cc b/src/ots.cc
--- a/src/ots.cc
+++ b/src/ots.cc
@@ -14,7 +14,7 @@
#include <map>
#include <vector>

Просмотреть файл

@ -1,6 +1,6 @@
diff --git a/gfx/ots/include/opentype-sanitiser.h b/gfx/ots/include/opentype-sanitiser.h
--- a/gfx/ots/include/opentype-sanitiser.h
+++ b/gfx/ots/include/opentype-sanitiser.h
diff --git a/include/opentype-sanitiser.h b/include/opentype-sanitiser.h
--- a/include/opentype-sanitiser.h
+++ b/include/opentype-sanitiser.h
@@ -4,8 +4,28 @@
#ifndef OPENTYPE_SANITISER_H_

Просмотреть файл

@ -1,41 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
if [ $# = 0 ] ; then
echo "usage: ./sync.sh ots-git-directory"
exit 1
fi
echo "Updating LICENSE..."
cp $1/LICENSE .
echo "Updating src..."
cd src
ls | fgrep -v moz.build | xargs rm -rf
cp -r $1/src/* .
cd ..
echo "Updating include..."
rm -rf include/
cp -r $1/include .
echo "Updating tests..."
rm -rf tests/*
mkdir -p tests
cp -r $1/tests/*.cc tests
echo "Updating README.mozilla..."
REVISION=`cd $1; git log | head -1 | sed "s/commit //"`
VERSION=`cd $1; git describe | cut -d '-' -f 1 | sed 's/v//'`
sed -e "s/\(Current revision: \).*/\1$REVISION \($VERSION\)/" README.mozilla > README.tmp
mv README.tmp README.mozilla
echo "Applying ots-visibility.patch..."
patch -p3 < ots-visibility.patch
echo "Applying ots-lz4.patch..."
patch -p3 < ots-lz4.patch
echo "Applying ots-rlbox.patch..."
patch -p3 < ots-rlbox.patch