[canvaskit] Add support for woff2 fonts

Requested by Flutter. This adds about 80k of code size
due in large part to the brotli decoding logic.

This also updates the check_deps error to point at
a doc on how to create a new GOB mirror.

Brotli version is 1.0.9; the latest as of today.

Change-Id: I1580cb2189ff1205a9bffca3d887ff2b98a4042e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333218
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
Kevin Lubick 2020-11-10 09:13:22 -05:00 committed by Skia Commit-Bot
parent fb5850f410
commit a502878308
7 changed files with 41 additions and 3 deletions

1
DEPS
View File

@ -8,6 +8,7 @@ deps = {
"buildtools" : "https://chromium.googlesource.com/chromium/buildtools.git@505de88083136eefd056e5ee4ca0f01fe9b33de8",
"common" : "https://skia.googlesource.com/common.git@9737551d7a52c3db3262db5856e6bcd62c462b92",
"third_party/externals/angle2" : "https://chromium.googlesource.com/angle/angle.git@72001c7d85ba2be69ccd54768a07e80a7d2756bc",
"third_party/externals/brotli" : "https://skia.googlesource.com/external/github.com/google/brotli.git@e61745a6b7add50d380cfd7d3883dd6c62fc2c71",
"third_party/externals/d3d12allocator" : "https://skia.googlesource.com/external/github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator.git@169895d529dfce00390a20e69c2f516066fe7a3b",
# Dawn requires jinja2 and markupsafe for the code generator, and glslang and shaderc for SPIRV compilation.
# When the Dawn revision is updated these should be updated from the Dawn DEPS as well.

View File

@ -50,7 +50,8 @@ def main():
rev = split[1]
if not 'googlesource.com' in repo:
errs.append(
'DEPS must be hosted on googlesource.com; %s is not allowed.' % repo)
'DEPS must be hosted on googlesource.com; %s is not allowed. '
'See http://go/new-skia-git-mirror' % repo)
if not re.match(r'^[a-z0-9]{40}$', rev):
errs.append('%s: "%s" does not look like a commit hash.' % (repo, rev))
if errs:

View File

@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `getLineMetrics` to Paragraph.
- `Canvas.saveLayerPaint` as an experimental, undocumented "fast path" if one only needs to pass
the paint.
- Support for .woff and .woff2 fonts. Disable .woff2 for reduced code size by supplying
no_woff2 to compile.sh. (This removes the code to do brotli decompression).
### Breaking
- `CanvasKit.MakePathFromSVGString` was renamed to `CanvasKit.Path.MakeFromSVGString`

View File

@ -174,12 +174,14 @@ if [[ $@ == *no_canvas* ]]; then
fi
GN_FONT="skia_enable_fontmgr_custom_directory=false "
WOFF2_FONT="skia_use_freetype_woff2=true"
FONT_CFLAGS=""
BUILTIN_FONT=""
FONT_JS="--pre-js $BASE_DIR/font.js"
if [[ $@ == *no_font* ]]; then
echo "Omitting the built-in font(s), font manager and all code dealing with fonts"
FONT_CFLAGS="-DSK_NO_FONTS"
WOFF2_FONT=""
FONT_JS=""
GN_FONT+="skia_enable_fontmgr_custom_embedded=false skia_enable_fontmgr_custom_empty=false"
elif [[ $@ == *no_embedded_font* ]]; then
@ -196,6 +198,10 @@ else
GN_FONT+="skia_enable_fontmgr_custom_embedded=true skia_enable_fontmgr_custom_empty=false"
fi
if [[ $@ == *no_woff2* ]]; then
WOFF2_FONT="skia_use_freetype_woff2=false"
fi
if [[ $@ == *no_alias_font* ]]; then
EXTRA_CFLAGS+="\"-DCANVASKIT_NO_ALIAS_FONT\","
FONT_CFLAGS+=" -DCANVASKIT_NO_ALIAS_FONT"
@ -306,6 +312,7 @@ echo "Compiling bitcode"
${GN_SHAPER} \
${GN_GPU} \
${GN_FONT} \
${WOFF2_FONT} \
${GN_PARTICLES} \
${GN_VIEWER} \
\

View File

@ -286,12 +286,10 @@ describe('Font Behavior', () => {
buffer: fetchedByteBuffers[0],
y: 90,
},{
// Not currently supported by Skia
type: '.woff font',
buffer: fetchedByteBuffers[1],
y: 120,
},{
// Not currently supported by Skia
type: '.woff2 font',
buffer: fetchedByteBuffers[2],
y: 150,

23
third_party/brotli/BUILD.gn vendored Normal file
View File

@ -0,0 +1,23 @@
# Copyright 2020 Google LLC
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("../third_party.gni")
third_party("brotli") {
public_include_dirs = [ "../externals/brotli/c/include" ]
# The only consumer of brotli is freetype and it only needs to decode brotli.
sources = [
"../externals/brotli/c/common/constants.c",
"../externals/brotli/c/common/context.c",
"../externals/brotli/c/common/dictionary.c",
"../externals/brotli/c/common/platform.c",
"../externals/brotli/c/common/transform.c",
"../externals/brotli/c/dec/bit_reader.c",
"../externals/brotli/c/dec/decode.c",
"../externals/brotli/c/dec/huffman.c",
"../externals/brotli/c/dec/state.c",
]
}

View File

@ -7,6 +7,7 @@ declare_args() {
# TODO: build from source all the time for testing?
skia_use_system_freetype2 =
(is_official_build || !(is_android || sanitize == "MSAN")) && !is_fuchsia
skia_use_freetype_woff2 = false
}
import("../third_party.gni")
@ -37,6 +38,11 @@ if (skia_use_system_freetype2) {
]
}
if (skia_use_freetype_woff2) {
deps += [ "//third_party/brotli" ]
defines += [ "FT_CONFIG_OPTION_USE_BROTLI" ]
}
sources = [
"../externals/freetype/src/autofit/autofit.c",
"../externals/freetype/src/base/ftbase.c",