Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tx] Replace UFO fontinfo.plist parsing with libxml2 #1515

Merged
merged 9 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
env:
CIBW_BUILD: "cp39-*"
CIBW_ARCHS_MACOS: universal2
CIBW_ENVIRONMENT_MACOS: "CFLAGS='-arch arm64 -arch x86_64' CXXFLAGS='-arch arm64 -arch x86_64' LDFLAGS='-arch arm64 -arch x86_64'"
CIBW_ENVIRONMENT_MACOS: "CFLAGS='-arch arm64 -arch x86_64 -I/usr/include/libxml2' CXXFLAGS='-arch arm64 -arch x86_64' LDFLAGS='-arch arm64 -arch x86_64'"

- name: Build wheel (except macosx_universal2)
uses: pypa/cibuildwheel@v2.3.1
Expand All @@ -57,7 +57,10 @@ jobs:
CIBW_ARCHS_LINUX: x86_64
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_SKIP: "*musllinux*"
CIBW_BEFORE_ALL_LINUX: yum install -y libuuid-devel
CIBW_BEFORE_ALL_LINUX: "yum install -y libuuid-devel && yum install -y libxml2-devel"
CIBW_BEFORE_BUILD_WINDOWS: "code --install libxml2"
CIBW_ENVIRONMENT_LINUX: "CFLAGS='-I/usr/include/libxml2'"
CIBW_ENVIRONMENT_WINDOWS: "CFLAGS='-I/usr/include/libxml2'"

- name: Build sdist (Ubuntu only)
if: matrix.os == 'ubuntu-latest'
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/run_cvg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
if: github.event_name == 'workflow_dispatch'
run: |
echo "Reason for triggering: ${{ github.event.inputs.reason }}"

- name: Check out
uses: actions/checkout@v2
with:
Expand All @@ -42,22 +41,18 @@ jobs:

- name: Build AFDKO wheel
env:
CFLAGS: '--coverage'
CFLAGS: '--coverage -I/usr/include/libxml2'
run: |
python -m pip install --upgrade pip
python -m pip install build>=0.7.0
python -m build --wheel


- name: Install AFDKO wheel
run: |
python -m pip install dist/*.whl -q

- name: Generate Python and C coverage
run: |
python -m pip install pytest-cov -q
python -m pytest tests --cov --cov-report=xml --color=yes

- name: Upload coverage results
run: |
bash <(curl -s https://codecov.io/bash) -y .codecov.yml
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ set(ANTLR4_WITH_STATIC_CRT OFF)
set(ANTLR4_TAG tags/4.9.3)
include(ExternalAntlr4Cpp)

FIND_PACKAGE(LibXml2)
IF (NOT ${LibXml2_FOUND})
MESSAGE(STATUS "Could not locate LibXml2, will install externally.")
set(LIBXML2_TAG tags/v2.9.13)
include(ExternalLibXML2)
ENDIF(NOT ${LibXml2_FOUND})
include_directories(${LIBXML2_INCLUDE_DIR})

# sanitizer support
# work around https://github.com/pypa/setuptools/issues/1928 with environment
# variable
Expand Down
16 changes: 15 additions & 1 deletion c/makeotf/lib/cffread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
add_library(makeotf_cffread STATIC cffread.c)

target_compile_definitions(makeotf_cffread PRIVATE $<$<CONFIG:Debug>:CFF_DEBUG=1> CFF_T13_SUPPORT=0)
target_include_directories(makeotf_cffread PRIVATE AFTER $<$<COMPILE_LANGUAGE:CXX>:${ANTLR4_INCLUDE_DIRS}>)

if (${LibXml2_FOUND})
target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_LIBRARY})
else ()
add_dependencies(makeotf_cffread ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(makeotf_cffread PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

target_link_libraries(makeotf_cffread PUBLIC antlr4_static)

target_compile_definitions(makeotf_cffread PRIVATE $<$<CONFIG:Debug>:CFF_DEBUG=1> CFF_T13_SUPPORT=0)
11 changes: 11 additions & 0 deletions c/makeotf/lib/hotconv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ set_property(TARGET hotconv PROPERTY C_STANDARD 99)
target_include_directories(hotconv PRIVATE AFTER $<$<COMPILE_LANGUAGE:CXX>:${ANTLR4_INCLUDE_DIRS}>)
target_link_libraries(hotconv PUBLIC antlr4_static)

if (${LibXml2_FOUND})
target_link_libraries(hotconv PUBLIC ${LIBXML2_LIBRARY})
else ()
add_dependencies(hotconv ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(hotconv PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(hotconv PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

if ( CMAKE_COMPILER_IS_GNUCC )
target_compile_options(hotconv PRIVATE -Wall -Wno-attributes)
# set_source_files_properties(${GENERATED_SOURCES} PROPERTIES COMPILE_FLAGS -Wno-attributes)
Expand Down
11 changes: 11 additions & 0 deletions c/makeotf/lib/pstoken/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
add_library(makeotf_pstoken STATIC pstoken.c)

if (${LibXml2_FOUND})
target_link_libraries(makeotf_pstoken PUBLIC ${LIBXML2_LIBRARY})
else ()
add_dependencies(makeotf_pstoken ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(makeotf_pstoken PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(makeotf_pstoken PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

target_compile_definitions(makeotf_pstoken PRIVATE PSTOKEN_DEBUG=1 CFF_DEBUG=1 CFF_T13_SUPPORT=0)
11 changes: 11 additions & 0 deletions c/makeotf/lib/typecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ add_library(typecomp STATIC
tc.c
)

if (${LibXml2_FOUND})
target_link_libraries(typecomp PUBLIC ${LIBXML2_LIBRARY})
else ()
add_dependencies(typecomp ${LIBXML2_TARGET})
if (WIN32)
target_link_libraries(typecomp PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(typecomp PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

target_compile_definitions(typecomp PRIVATE
TC_HINT_CHECK=1
TC_T13_SUPPORT=0
Expand Down
12 changes: 11 additions & 1 deletion c/makeotf/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ target_sources(makeotfexe PRIVATE

target_link_libraries(makeotfexe PRIVATE ctutil dynarr hotconv makeotf_pstoken typecomp makeotf_cffread)

if(HAVE_M_LIB)
if (HAVE_M_LIB)
target_link_libraries(makeotfexe PRIVATE m)
endif ()

if (${LibXml2_FOUND})
target_link_libraries(makeotfexe PUBLIC ${LIBXML2_LIBRARY})
else ()
if (WIN32)
target_link_libraries(makeotfexe PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(makeotfexe PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

target_compile_definitions(makeotfexe PRIVATE MAKEOTFLIB_EXPORTS=1)
Expand Down
15 changes: 14 additions & 1 deletion c/mergefonts/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ add_executable(mergefonts
)

target_include_directories(mergefonts PRIVATE ../../shared/include ../../shared/resource ../../shared/source/tx_shared)

target_link_libraries(mergefonts PUBLIC tx_shared)
install(TARGETS mergefonts DESTINATION bin)

if (${LibXml2_FOUND})
target_link_libraries(mergefonts PUBLIC ${LIBXML2_LIBRARY})
else ()
add_dependencies(mergefonts ${LIBXML2_TARGET})
target_compile_definitions(mergefonts PUBLIC -DLIBXML_STATIC)
if (WIN32)
target_link_libraries(mergefonts PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(mergefonts PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

install(TARGETS mergefonts DESTINATION bin)
14 changes: 14 additions & 0 deletions c/rotatefont/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,19 @@ add_executable(rotatefont
)

target_include_directories(rotatefont PRIVATE ../../shared/include ../../shared/resource ../../shared/source/tx_shared)

target_link_libraries(rotatefont PUBLIC tx_shared)

if(${LibXml2_FOUND})
target_link_libraries(rotatefont PUBLIC ${LIBXML2_LIBRARY})
else()
add_dependencies(rotatefont ${LIBXML2_TARGET})
target_compile_definitions(rotatefont PUBLIC -DLIBXML_STATIC)
if (WIN32)
target_link_libraries(rotatefont PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(rotatefont PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

install(TARGETS rotatefont DESTINATION bin)
4 changes: 4 additions & 0 deletions c/shared/include/ctlshare.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#endif
#include <stdint.h>

#include <libxml/tree.h>
#include <libxml/parser.h>

/* CoreType Library Shared Definitions
===================================
This library supplies definitions that are shared between members of the
Expand Down Expand Up @@ -139,6 +142,7 @@ struct ctlStreamCallbacks_ {
int (*seek)(ctlStreamCallbacks *cb, void *stream, long offset);
long (*tell)(ctlStreamCallbacks *cb, void *stream);
size_t (*read)(ctlStreamCallbacks *cb, void *stream, char **ptr);
size_t (*xml_read)(ctlStreamCallbacks *cb, void *stream, xmlDocPtr *doc);
size_t (*write)(ctlStreamCallbacks *cb,
void *stream, size_t count, char *ptr);
int (*status)(ctlStreamCallbacks *cb, void *stream);
Expand Down
3 changes: 3 additions & 0 deletions c/shared/include/tx_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
#include <sys/time.h>
#endif

#include <libxml/tree.h>
#include <libxml/parser.h>

/* ----------------------- Miscellaneous Definitions ----------------------- */

#define ARRAY_LEN(t) (sizeof(t) / sizeof((t)[0]))
Expand Down
7 changes: 7 additions & 0 deletions c/shared/include/uforead.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define UFOREAD_H

#include "ctlshare.h"
#include <stdbool.h>

#define UFO_VERSION CTL_MAKE_VERSION(1, 1, 2)

Expand Down Expand Up @@ -125,6 +126,12 @@ void ufoFree(ufoCtx h);
/* ufoFree() destroys the library context and all the resources allocated to
it. The temporary and debug data streams are closed. */

static char* parseXMLKeyName(ufoCtx h, xmlNodePtr cur);

static char* parseXMLKeyValue(ufoCtx h, xmlNodePtr cur);

static bool setFontDictKey(ufoCtx h, char* keyName, xmlNodePtr cur);

enum {
#undef CTL_DCL_ERR
#define CTL_DCL_ERR(name, string) name,
Expand Down
14 changes: 14 additions & 0 deletions c/shared/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ include_directories(../include ../resource)
MACRO(ADD_AFDKOLIB lm)
file(GLOB sl_sources "${lm}/*")
add_library(${lm} STATIC ${sl_sources})
if(NOT ${LibXml2_FOUND})
add_dependencies(${lm} ${LIBXML2_TARGET})
endif(NOT ${LibXml2_FOUND})
ENDMACRO(ADD_AFDKOLIB)

ADD_AFDKOLIB(absfont)
Expand Down Expand Up @@ -44,6 +47,17 @@ target_compile_definitions(t1write PRIVATE $<$<CONFIG:Debug>:T1W_DEBUG=1>)
target_compile_definitions(ttread PRIVATE $<$<CONFIG:Debug>:TTR_DEBUG=1>)
target_compile_definitions(tx_shared PRIVATE $<$<CONFIG:Debug>:CFW_DEBUG=1>)

if(${LibXml2_FOUND})
target_link_libraries(tx_shared PUBLIC ${LIBXML2_LIBRARY})
else()
target_compile_definitions(tx_shared PUBLIC -DLIBXML_STATIC)
if (WIN32)
target_link_libraries(tx_shared PUBLIC ${LIBXML2_WIN_LIBRARIES})
else ()
target_link_libraries(tx_shared PUBLIC ${LIBXML2_NONWIN_LIBRARIES})
endif()
endif()

# These libraries are partially ordered

target_link_libraries(tx_shared PUBLIC
Expand Down
23 changes: 22 additions & 1 deletion c/shared/source/tx_shared/tx_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static long stm_tell(ctlStreamCallbacks *cb, void *stream) {
}

/* Read from stream. */
static size_t stm_read(ctlStreamCallbacks *cb, void *stream, char **ptr) {
static size_t stm_read(ctlStreamCallbacks *cb, Stream *stream, char **ptr) {
Stream *s = stream;
switch (s->type) {
case stm_Src:
Expand All @@ -405,6 +405,26 @@ static size_t stm_read(ctlStreamCallbacks *cb, void *stream, char **ptr) {
return 0; /* Suppress compiler warning */
}

static size_t stm_xml_read(ctlStreamCallbacks *cb, Stream *stream, xmlDocPtr *doc){
int res;
xmlParserCtxtPtr ctxt;

Stream *s = stream;
txCtx h = cb->direct_ctx;
res = fread(s->buf, 1, 4, s->fp);
if (res > 0) {
ctxt = xmlCreatePushParserCtxt(NULL, NULL,
s->buf, res, s->filename);
while ((res = fread(s->buf, 1, BUFSIZ, s->fp)) > 0) {
xmlParseChunk(ctxt, s->buf, res, 0);
}
xmlParseChunk(ctxt, s->buf, 0, 1);
*doc = ctxt->myDoc;
xmlFreeParserCtxt(ctxt);
}
return 0;
}

/* Write to stream. */
static size_t stm_write(ctlStreamCallbacks *cb, void *stream,
size_t count, char *ptr) {
Expand Down Expand Up @@ -501,6 +521,7 @@ void stmInit(txCtx h) {
h->cb.stm.seek = stm_seek;
h->cb.stm.tell = stm_tell;
h->cb.stm.read = stm_read;
h->cb.stm.xml_read = stm_xml_read;
h->cb.stm.write = stm_write;
h->cb.stm.status = stm_status;
h->cb.stm.close = stm_close;
Expand Down
Loading