Skip to content

Commit

Permalink
Merge 2f71ef4 into 2266d05
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledhosny committed Jan 3, 2023
2 parents 2266d05 + 2f71ef4 commit e0b581a
Show file tree
Hide file tree
Showing 181 changed files with 1,512 additions and 1,251 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ jobs:
- name: Configure
run: |
./bootstrap.sh
./configure --without-system-luarocks --with-manual
./configure \
--disable-harfbuzz-subset \
--without-system-luarocks \
--with-manual
echo "VERSION=$(./build-aux/git-version-gen .tarball-version)" >> $GITHUB_ENV
echo "MAKEFLAGS=-j$(nproc) -Otarget" >> $GITHUB_ENV
- name: Make
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
./bootstrap.sh
./configure \
--enable-developer LUACHECK=false \
--disable-harfbuzz-subset \
--without-system-luarocks \
--with-luajit \
--without-manual
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
./bootstrap.sh
./configure \
--enable-developer LUACHECK=false \
--disable-harfbuzz-subset \
--without-system-luarocks \
--with${{ startsWith(matrix.luaVersion[0], '5') && 'out' || '' }}-luajit \
--without-manual
Expand Down
44 changes: 15 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,17 @@ if (WIN32)
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DICU_BUILD_IO=ON
INSTALL_DIR "${TMP_INSTALL_DIR}")

ExternalProject_Add(ragel
GIT_REPOSITORY https://github.com/tamaskenez/ragel-cmake
GIT_TAG 651ce281
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
INSTALL_DIR "${TMP_INSTALL_DIR}")

ExternalProject_Add(freetype2_bootstrap
GIT_REPOSITORY https://github.com/aseprite/freetype2
GIT_TAG VER-2-10-0
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DFT_WITH_HARFBUZZ=OFF
INSTALL_DIR "${CMAKE_BINARY_DIR}/bootstrap")

ExternalProject_Add(harfbuzz
DEPENDS ragel icu freetype2_bootstrap
GIT_REPOSITORY https://github.com/harfbuzz/harfbuzz
GIT_TAG 2.3.1
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DHB_HAVE_ICU=ON -DHB_HAVE_FREETYPE=ON -DHB_BUILD_TESTS=OFF "-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/bootstrap"
GIT_TAG 6.0.0
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DHB_BUILD_TESTS=OFF "-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/bootstrap"
INSTALL_DIR "${TMP_INSTALL_DIR}")

ExternalProject_Add(freetype2
DEPENDS harfbuzz libpng zlib
GIT_REPOSITORY https://github.com/aseprite/freetype2
GIT_TAG VER-2-10-0
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DFT_WITH_HARFBUZZ=ON -DFT_WITH_ZLIB=ON -DFT_WITH_PNG=ON
DEPENDS libpng zlib
GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype.git
GIT_TAG VER-2-12-1
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DFT_DISABLE_HARFBUZZ=ON -DFT_REQUIRE_ZLIB=ON -DFT_REQUIRE_PNG=ON
INSTALL_DIR "${TMP_INSTALL_DIR}")

ExternalProject_Add(libiconv
Expand All @@ -67,7 +54,7 @@ if (WIN32)
COMMAND git clean -dfx
COMMAND git apply "${CMAKE_CURRENT_SOURCE_DIR}/cmake/fontconfig.diff"
LIST_SEPARATOR ::
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DCMAKE_C_FLAGS=/DXML_STATIC=1 -DBUILD_SHARED=OFF -DBUILD_STATIC=ON "-DEXPAT_LIBRARIES=<INSTALL_DIR>/lib/expat.lib" "-DFREETYPE_LIBRARIES=<INSTALL_DIR>/lib/freetype.lib" "-DLIBRARIES_TO_LINK=<INSTALL_DIR>/lib/harfbuzz.lib::<INSTALL_DIR>/lib/libpng16_static.lib::<INSTALL_DIR>/lib/zlibstatic.lib"
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>" -DCMAKE_C_FLAGS=/DXML_STATIC=1 -DBUILD_SHARED=OFF -DBUILD_STATIC=ON "-DEXPAT_LIBRARIES=<INSTALL_DIR>/lib/expat.lib" "-DFREETYPE_LIBRARIES=<INSTALL_DIR>/lib/freetype.lib" "-DLIBRARIES_TO_LINK=<INSTALL_DIR>/lib/libpng16_static.lib::<INSTALL_DIR>/lib/zlibstatic.lib"
INSTALL_DIR "${TMP_INSTALL_DIR}")
ExternalProject_Add_Step(fontconfig genconf
COMMAND "${CMAKE_COMMAND}" "-DCMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/fonts_conf.cmake"
Expand Down Expand Up @@ -162,17 +149,17 @@ target_link_libraries(justenoughlibtexpdf PUBLIC libtexpdf lua51.lib)
target_link_options(justenoughlibtexpdf PUBLIC /EXPORT:luaopen_justenoughlibtexpdf)


add_library(justenoughharfbuzz SHARED src/justenoughharfbuzz.c)
add_dependencies(justenoughharfbuzz harfbuzz freetype2 lua)
add_library(justenoughharfbuzz SHARED src/justenoughharfbuzz.c src/hb-utils.c src/hb-utils.h)
add_dependencies(justenoughharfbuzz harfbuzz lua)
target_include_directories(justenoughharfbuzz PUBLIC
"${TMP_INSTALL_DIR}/include"
"${TMP_INSTALL_DIR}/include/harfbuzz"
"${TMP_INSTALL_DIR}/include/freetype2"
"${TMP_LUA_DIR}/include")
target_link_directories(justenoughharfbuzz PUBLIC
"${TMP_INSTALL_DIR}/lib"
"${TMP_LUA_DIR}")
target_link_libraries(justenoughharfbuzz PUBLIC harfbuzz.lib freetype.lib zlibstatic.lib lua51.lib libpng16_static.lib)
target_compile_definitions(justenoughharfbuzz PUBLIC HAVE_HARFBUZZ_SUBSET)
target_link_libraries(justenoughharfbuzz PUBLIC harfbuzz.lib harfbuzz-subset.lib lua51.lib)
target_link_options(justenoughharfbuzz PUBLIC /EXPORT:luaopen_justenoughharfbuzz)

add_library(justenoughicu SHARED src/justenoughicu.c)
Expand All @@ -194,20 +181,19 @@ target_include_directories(justenoughfontconfig PUBLIC
target_link_directories(justenoughfontconfig PUBLIC
"${TMP_INSTALL_DIR}/lib"
"${TMP_LUA_DIR}")
target_link_libraries(justenoughfontconfig PUBLIC fontconfig-static.lib lua51.lib expat.lib freetype.lib harfbuzz.lib libpng16_static.lib zlibstatic.lib)
target_link_libraries(justenoughfontconfig PUBLIC fontconfig-static.lib lua51.lib expat.lib freetype.lib libpng16_static.lib zlibstatic.lib)
target_link_options(justenoughfontconfig PUBLIC /EXPORT:luaopen_justenoughfontconfig)

add_library(fontmetrics SHARED src/fontmetrics.c)
add_dependencies(fontmetrics harfbuzz freetype2 lua)
add_library(fontmetrics SHARED src/fontmetrics.c src/hb-utils.c src/hb-utils.h)
add_dependencies(fontmetrics harfbuzz lua)
target_include_directories(fontmetrics PUBLIC
"${TMP_INSTALL_DIR}/include"
"${TMP_INSTALL_DIR}/include/harfbuzz"
"${TMP_INSTALL_DIR}/include/freetype2"
"${TMP_LUA_DIR}/include")
target_link_directories(fontmetrics PUBLIC
"${TMP_INSTALL_DIR}/lib"
"${TMP_LUA_DIR}")
target_link_libraries(fontmetrics PUBLIC harfbuzz.lib freetype.lib zlibstatic.lib lua51.lib libpng16_static.lib)
target_link_libraries(fontmetrics PUBLIC harfbuzz.lib lua51.lib)
target_link_options(fontmetrics PUBLIC /EXPORT:luaopen_fontmetrics)

add_library(svg SHARED src/svg.c)
Expand Down
7 changes: 7 additions & 0 deletions Makefile-fonts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ TESTFONTFILES += NotoSerifCJK-Regular.ttc
TESTFONTFILES += SBL_Hbrw.ttf
TESTFONTFILES += TwemojiMozilla.ttf

VARIABLEFILES = Tourney[wdth,wght].ttf

comma = ,
varencode = $(subst $(comma),%2C,$(subst [,%5B,$(subst ],%5D,$(1))))
notobase = $(shell echo $(notdir $1) | sed -e 's/-.*//')

# Tell make how to download individual font files directly (when available)
Expand All @@ -60,6 +64,9 @@ notobase = $(shell echo $(notdir $1) | sed -e 's/-.*//')
.fonts/Symbola.otf: | .fonts
$(CURL) -fsSL https://github.com/ChiefMikeK/ttf-symbola/raw/master/Symbola-13.otf -o $@

.fonts/Tourney%: | .fonts
$(CURL) -fsSL https://raw.githubusercontent.com/Etcetera-Type-Co/Tourney/643f1026ad6d41b4527f42cd93c776414fdd6503/fonts/variable/$(call varencode,$(notdir $@)) -o $@

.fonts/TwemojiMozilla.ttf: | .fonts
$(CURL) -fsSL https://github.com/mozilla/twemoji-colr/releases/download/v0.5.1/$(notdir $@) -o $@

Expand Down
7 changes: 7 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ LOCALTESTFONTS := FONTCONFIG_FILE=$(PWD)/fontconfig.conf
SILEFLAGS ?= -m $(DEPDIR)/$(basename $@).d -d versions -f fontconfig
BUSTEDFLAGS ?= $(and $(SILE_COVERAGE),-c)

if !HARFBUZZ_SUBSET
TESTSRC = $(filter-out tests/variable-%,$(TESTSRC))
endif

TESTPDFS = $(addsuffix .pdf,$(basename $(TESTSRCS)))
EXPECTEDS ?= $(filter $(addsuffix .expected,$(basename $(TESTSRCS))),$(TESTEXPECTS))
ACTUALS = $(addsuffix .actual,$(basename $(EXPECTEDS)))
Expand Down Expand Up @@ -165,6 +169,7 @@ endef
_FORCED = $(and $(SILE_COVERAGE)$(CLEAN),force)
_TEST_DEPS = $(and $$(filter tests/%,$@),$(addprefix .fonts/,$(TESTFONTFILES)))
_DOCS_DEPS = $(and $$(filter documentation/%,$@),$(addprefix .fonts/,$(DOCSFONTFILES)))
_VAR_DEPS = $(addprefix .fonts/,$(VARIABLEFILES))

# TODO: remove _BUILT_SUBDIRS hack and replace it with something sensible when
# these subdirs don't do crazy things like copying files outside of their own trees!
Expand Down Expand Up @@ -268,6 +273,8 @@ tests/%.actual: tests/%.nil $$(patterndeps)
-$(if $(CLEAN),rm -f $@,:)
$(LOCALTESTFONTS) ./$(SILE) $(SILEFLAGS) -b debug $< -o $@

tests/variable-%: $(_VAR_DEPS)

DEPFILES = $(addsuffix .d,$(addprefix $(DEPDIR)/,$(basename $(TESTSRCS) $(MANUAL))))
DEPDIRS = $(sort $(dir $(DEPFILES)))

Expand Down
118 changes: 73 additions & 45 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,59 @@ LT_PREREQ([2.2])
LT_INIT([dlopen])

AC_ARG_ENABLE([dependency-checks],
AS_HELP_STRING([--disable-dependency-checks], [Disable dependency checks]))
AS_HELP_STRING([--disable-dependency-checks],
[Disable dependency checks]))
AM_CONDITIONAL([DEPENDENCY_CHECKS], [test "x$enable_dependency_checks" != "xno"])

AC_ARG_ENABLE([developer],
AS_HELP_STRING([--enable-developer], [Check for and enable tooling required only for SILE developers]))
AS_HELP_STRING([--enable-developer],
[Check for and enable tooling required only for SILE developers]))
AM_CONDITIONAL([DEVELOPER], [test "x$enable_developer" = "xyes"])

AC_ARG_ENABLE([harfbuzz-subset],
AS_HELP_STRING([--disable-harfbuzz-subset],
[Disable HarfBuzz subsetting used to support variable fonts that requires very recent HarfBuzz]))
AM_CONDITIONAL([HARFBUZZ_SUBSET], [test "x$enable_harfbuzz_subset" != "xno"])

AC_ARG_ENABLE([linklua],
AS_HELP_STRING([--disable-linklua],
[Don’t link lua library with dylibs]))
AM_CONDITIONAL([LINKLUA], [test "x$enable_linklua" != "xno"])

AC_CANONICAL_HOST

# TODO: Refactor fontconfig check to allow Appkit/DirectWrite as alternatives, maybe default to off on Darwin
# AC_ARG_WITH([fontconfig],
# AS_HELP_STRING([--without-fontconfig],
# [Compile without fontconfig font manager support]))
AM_CONDITIONAL([FONTCONFIG], [test "x$with_fontconfig" != "xno"])

AC_ARG_WITH([harfbuzz],
AS_HELP_STRING([--without-harfbuzz],
[Compile without HarfBuzz support used as default shaping backend]))
AM_CONDITIONAL([HARFBUZZ], [test "x$with_harfbuzz" != "xno"])

AC_ARG_WITH([system-libtexpdf],
AS_HELP_STRING([--with-system-libtexpdf], [Don’t bundle libtexpdf, use system provided version]))
AS_HELP_STRING([--with-system-libtexpdf],
[Don’t bundle libtexpdf, use system provided version]))
AM_CONDITIONAL([SYSTEM_LIBTEXPDF], [test "x$with_system_libtexpdf" = "xyes"])

AC_ARG_WITH([system-luarocks],
AS_HELP_STRING([--with-system-luarocks], [Don’t bundle LuaRocks, use system provided versions]))
AS_HELP_STRING([--with-system-luarocks],
[Don’t bundle LuaRocks, use system provided versions]))
AM_CONDITIONAL([SYSTEM_LUAROCKS], [test "x$with_system_luarocks" = "xyes"])
AC_SUBST([SYSTEM_LUAROCKS])

AC_ARG_WITH([luajit],
AS_HELP_STRING([--with-luajit], [Run under LuaJIT instead of Lua]))
AS_HELP_STRING([--with-luajit],
[Run under LuaJIT instead of Lua]))
AM_CONDITIONAL([LUAJIT], [test "x$with_luajit" = "xyes"])

AC_ARG_WITH([manual],
AS_HELP_STRING([--with-manual], [Rebuild manual and install to system’s PDF documentation directory]))
AS_HELP_STRING([--with-manual],
[Rebuild manual and install to system’s PDF documentation directory]))
AM_CONDITIONAL([MANUAL], [test "x$with_manual" = "xyes"])

AM_COND_IF([SYSTEM_LIBTEXPDF],
[AC_CHECK_LIB([texpdf],[texpdf_doc_set_verbose],
[],
[AC_MSG_FAILURE([--with-system-libtexpdf was given, but test for libtexpdf failed])]) ],
[AC_CONFIG_SUBDIRS([libtexpdf])])

AM_CONDITIONAL([FONT_DOWNLOAD_TOOLS], [test -z ${DEVELOPER_TRUE} || (test -z ${MANUAL_TRUE} && test -z ${IS_SDIST_FALSE})])
AC_SUBST([FONT_DOWNLOAD_TOOLS])

Expand Down Expand Up @@ -90,31 +111,41 @@ AM_COND_IF([DEPENDENCY_CHECKS], [
;;
esac
PKG_CHECK_MODULES(HARFBUZZ, harfbuzz, [
PKG_CHECK_MODULES(FREETYPE, freetype2,[],[AC_MSG_FAILURE([Harfbuzz found but not freetype2])])
PKG_CHECK_MODULES(FONTCONFIG, fontconfig,[],[AC_MSG_FAILURE([Harfbuzz found but not fontconfig])])
with_harfbuzz=yes
backend=harfbuzz
], [
if test "x$with_harfbuzz" != xcheck; then
AC_MSG_FAILURE([--with-harfbuzz was given, but test for harfbuzz failed])
fi
])
AM_COND_IF([FONTCONFIG],
[PKG_CHECK_MODULES(FONTCONFIG, [fontconfig],
[],
[AC_MSG_FAILURE([Fontconfig package not found])])])
AM_COND_IF([HARFBUZZ],
[PKG_CHECK_MODULES(HARFBUZZ, [harfbuzz >= 2.7.4],
[],
[AC_MSG_FAILURE([--with-harfbuzz was given, but harfbuzz not found])]) ])
AM_COND_IF([HARFBUZZ_SUBSET],
[PKG_CHECK_MODULES(HARFBUZZ_SUBSET, [harfbuzz-subset >= 6.0.0],
[AC_DEFINE(HAVE_HARFBUZZ_SUBSET, [1], [Have harfbuzz-subset library])],
[AC_MSG_FAILURE([--enable-harfbuzz-subset was given, but harfbuzz version not new enough to include subsetter])])])
AM_COND_IF([SYSTEM_LIBTEXPDF],
[AC_CHECK_LIB([texpdf],[texpdf_doc_set_verbose],
[],
[AC_MSG_FAILURE([--with-system-libtexpdf was given, but test for libtexpdf failed])]) ],
[AC_CONFIG_SUBDIRS([libtexpdf])])
PKG_CHECK_MODULES(ICU, icu-uc icu-io, [
AC_DEFINE([ICU], [1], [Build using icu4c])
with_icu=yes
],[
AC_CHECK_TOOL(ICU_CONFIG, icu-config, no)
AC_MSG_CHECKING([for ICU by using icu-config fallback])
if test "$ICU_CONFIG" != "no" && "$ICU_CONFIG" --version >/dev/null; then
ICU_LIBS=`icu-config --ldflags-libsonly --ldflags-icuio`
ICU_CFLAGS=`icu-config --cppflags`
AC_DEFINE([ICU], [1], [Build using icu4c])
with_icu=yes
AC_MSG_RESULT([yes])
else
AC_MSG_FAILURE([Required ICU library not found])
fi
],[
AC_CHECK_TOOL(ICU_CONFIG, icu-config, no)
AC_MSG_CHECKING([for ICU by using icu-config fallback])
if test "$ICU_CONFIG" != "no" && "$ICU_CONFIG" --version >/dev/null; then
ICU_LIBS=`icu-config --ldflags-libsonly --ldflags-icuio`
ICU_CFLAGS=`icu-config --cppflags`
with_icu=yes
AC_MSG_RESULT([yes])
else
AC_MSG_FAILURE([Required ICU library not found])
fi
])
case $host_os in
Expand Down Expand Up @@ -175,16 +206,17 @@ AM_COND_IF([DEPENDENCY_CHECKS], [
])
])
AC_SUBST([ICU_CFLAGS])
AC_SUBST([ICU_LIBS])

AM_CONDITIONAL([APPKIT], [test "x$have_appkit" = "xyes"])
AC_SUBST([APPKIT])

AM_CONDITIONAL([ICU], [test "x$with_icu" = "xyes"])
AC_ARG_ENABLE([linklua],
AS_HELP_STRING([--disable-linklua], [Don’t link lua library with dylibs]))
AM_CONDITIONAL([LINKLUA], [test "x$enable_linklua" != "xno"])

AC_SUBST([APPKIT])
AC_SUBST([HARFBUZZ_CFLAGS])
AC_SUBST([HARFBUZZ_LIBS])
AC_SUBST([HARFBUZZ_SUBSET_CFLAGS])
AC_SUBST([HARFBUZZ_SUBSET_LIBS])
AC_SUBST([ICU_CFLAGS])
AC_SUBST([ICU_LIBS])

AC_CANONICAL_HOST
case $host_os in
Expand All @@ -202,10 +234,6 @@ esac
AC_SUBST([SHARED_LIB_EXT])
AC_SUBST([LUAROCKSARGS])

AC_SUBST([HARFBUZZ_CFLAGS])
AC_SUBST([HARFBUZZ_LIBS])
AC_SUBST([shared_ext])

AX_SUBST_TRANSFORMED_PACKAGE_NAME

adl_RECURSIVE_EVAL(["${datadir}/${TRANSFORMED_PACKAGE_NAME}"], [SILE_PATH])
Expand Down
13 changes: 13 additions & 0 deletions core/font.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SILE.registerCommand("font", function (options, content)
if options.style then SILE.settings:set("font.style", options.style) end
if options.variant then SILE.settings:set("font.variant", options.variant) end
if options.features then SILE.settings:set("font.features", options.features) end
if options.variations then SILE.settings:set("font.variations", options.variations) end
if options.direction then SILE.settings:set("font.direction", options.direction) end
if options.language then
if options.language ~= "und" and icu and icu.canonicalize_language then
Expand Down Expand Up @@ -68,6 +69,7 @@ SILE.settings:declare({ parameter = "font.style", type = "string", default = ""
SILE.settings:declare({ parameter = "font.direction", type = "string", default = "" })
SILE.settings:declare({ parameter = "font.filename", type = "string or nil", default = "" })
SILE.settings:declare({ parameter = "font.features", type = "string", default = "" })
SILE.settings:declare({ parameter = "font.variations", type = "string", default = "" })
SILE.settings:declare({ parameter = "font.hyphenchar", type = "string", default = "-" })

SILE.fontCache = {}
Expand All @@ -80,6 +82,7 @@ local _key = function (options)
options.style,
options.variant,
options.features,
options.variations,
options.direction,
options.filename,
}, ";")
Expand All @@ -106,6 +109,7 @@ local font = {
end
end
if not options.features then options.features = SILE.settings:get("font.features") end
if not options.variations then options.variations = SILE.settings:get("font.variations") end
if not options.hyphenchar then options.hyphenchar = SILE.settings:get("font.hyphenchar") end
return options
end,
Expand All @@ -122,6 +126,15 @@ local font = {
return cached
end,

finish = function ()
for key, font in pairs(SILE.fontCache) do
if font.tempfilename ~= font.filename then
SU.debug("fonts", "Removing temporary file of", key, ":", font.tempfilename)
os.remove(font.tempfilename)
end
end
end,

postLoadHook = function(face)
local ot = require("core.opentype-parser")
local font = ot.parseFont(face)
Expand Down

0 comments on commit e0b581a

Please sign in to comment.