From 800614382942330bedbbcd4cd694639dca094303 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 20 Sep 2019 09:40:59 +0200 Subject: Handle SVG in OpenType fonts with compressed glyphs. --- src/libnrtype/OpenTypeUtil.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/libnrtype') diff --git a/src/libnrtype/OpenTypeUtil.cpp b/src/libnrtype/OpenTypeUtil.cpp index b5a0760ee..2b60cca9e 100644 --- a/src/libnrtype/OpenTypeUtil.cpp +++ b/src/libnrtype/OpenTypeUtil.cpp @@ -24,6 +24,9 @@ #include #include +// SVG in OpenType +#include "util/ziptool.h" + // Utilities used in this file @@ -378,8 +381,29 @@ void readOpenTypeSVGTable(const FT_Face ft_face, // << " Offset: " << offsetGlyph << " Length: " << lengthGlyph << std::endl; std::string svg; - for (unsigned int c = offsetGlyph; c < offsetGlyph + lengthGlyph; ++c) { - svg += (char) data[offset + c]; + + if (lengthGlyph > 1 && data[offset] & 0x1f && data[offset + 1] & 0x8b) { + // Glyph is gzipped + + std::vector buffer; + for (unsigned int c = offsetGlyph; c < offsetGlyph + lengthGlyph; ++c) { + buffer.push_back(data[offset + c]); + } + + GzipFile zipped; + zipped.readBuffer(buffer); + + std::vector unzipped_data = zipped.getData(); + for (auto i : unzipped_data) { + svg += (char)i; + } + + } else { + // Glyph is not compressed + + for (unsigned int c = offsetGlyph; c < offsetGlyph + lengthGlyph; ++c) { + svg += (unsigned char) data[offset + c]; + } } for (unsigned int i = startGlyphID; i < endGlyphID+1; ++i) { -- cgit v1.2.3