summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMoazin Khatti <moazinkhatri@gmail.com>2019-08-10 14:49:59 +0500
committerMoazin Khatti <moazinkhatri@gmail.com>2019-08-10 16:11:07 +0500
commitce64d9cbf11045895118b732a9c8d4ee83cfae83 (patch)
tree2ad9d12c4eeb060d503be8b712b2c2fad894b0dc /include
parent92eeba75c408cb655001648889b93f80379b969e (diff)
downloadfreetype2-ce64d9cbf11045895118b732a9c8d4ee83cfae83.tar.gz
Adds the functionality to load SVG documents.
SVG document corresponding to a glyphID is fetched and stored in an `FT_SVG_Document' structure which is referenced in the glyphslot. * include/freetype/config/ftheader.h: Adds `FT_OTSVG_H'. * include/freetype/ftimage.h: Adds `FT_GLYPH_FORMAT_SVG'. * include/freetype/internal/ftobjs.h: Adds `FT_GLYPH_OWN_GZIP_SVG'. * include/freetype/internal/sfnt.h: Adds `load_svg_doc' and its function type `TT_Load_Svg_Doc_Func'. * include/freetype/otsvg.h: Adds `FT_SVG_Document' and its struct. * src/base/ftobjs.c: Adds code to allocate and free memory for `FT_SVG_Document' in `slot->other'. * src/cff/cffgload.c: Adds code to load SVG glyph if it's present. * src/truetype/ttgload.c: Ditto. * src/sfnt/sfdriver.c: Adds `tt_face_load_svg_doc'. * src/sfnt/ttsvg.h: Ditto. * src/sfnt/ttsvg.c: Adds implementation of `tt_face_load_svg_doc' and its helper functions.
Diffstat (limited to 'include')
-rw-r--r--include/freetype/config/ftheader.h13
-rw-r--r--include/freetype/ftimage.h7
-rw-r--r--include/freetype/internal/ftobjs.h3
-rw-r--r--include/freetype/internal/sfnt.h32
-rw-r--r--include/freetype/otsvg.h91
5 files changed, 142 insertions, 4 deletions
diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h
index 696d6ba90..55716c2e5 100644
--- a/include/freetype/config/ftheader.h
+++ b/include/freetype/config/ftheader.h
@@ -550,6 +550,19 @@
/**************************************************************************
*
* @macro:
+ * FT_OTSVG_H
+ *
+ * @description:
+ * A macro used in `#include` statements to name the file containing the
+ * API of OT-SVG support related things.
+ *
+ */
+#define FT_OTSVG_H <freetype/otsvg.h>
+
+
+ /**************************************************************************
+ *
+ * @macro:
* FT_BBOX_H
*
* @description:
diff --git a/include/freetype/ftimage.h b/include/freetype/ftimage.h
index face34fe4..86fb04065 100644
--- a/include/freetype/ftimage.h
+++ b/include/freetype/ftimage.h
@@ -732,6 +732,9 @@ FT_BEGIN_HEADER
* contours. Some Type~1 fonts, like those in the Hershey family,
* contain glyphs in this format. These are described as @FT_Outline,
* but FreeType isn't currently capable of rendering them correctly.
+ *
+ * FT_GLYPH_FORMAT_SVG ::
+ * The glyph is represented by an SVG document in the SVG table.
*/
typedef enum FT_Glyph_Format_
{
@@ -740,7 +743,8 @@ FT_BEGIN_HEADER
FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ),
FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP, 'b', 'i', 't', 's' ),
FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE, 'o', 'u', 't', 'l' ),
- FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' )
+ FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' ),
+ FT_IMAGE_TAG( FT_GLYPH_FORMAT_SVG, 's', 'v', 'g', ' ' )
} FT_Glyph_Format;
@@ -752,6 +756,7 @@ FT_BEGIN_HEADER
#define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP
#define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE
#define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER
+#define ft_glyph_format_svg FT_GLYPH_FORMAT_SVG
/*************************************************************************/
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index 0c1d3e5bf..2f2050921 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -418,7 +418,8 @@ FT_BEGIN_HEADER
* initializing the glyph slot.
*/
-#define FT_GLYPH_OWN_BITMAP 0x1U
+#define FT_GLYPH_OWN_BITMAP 0x1U
+#define FT_GLYPH_OWN_GZIP_SVG 0x2U
typedef struct FT_Slot_InternalRec_
{
diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index fbc29d3a2..d09b190aa 100644
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -315,6 +315,31 @@ FT_BEGIN_HEADER
/**************************************************************************
*
* @functype:
+ * TT_Load_Svg_Doc_Func
+ *
+ * @description:
+ * Scans the SVG documents list to find the document containing the glyph
+ * that has the id "glyph<glyph_index>".
+ *
+ * @input:
+ * glyph ::
+ * The glyph slot from which pointers to SVG documents list will be
+ * grabbed. The results will be stored back in the slot too.
+ *
+ * glyph_index ::
+ * The index of the glyph that is to be looked up.
+ *
+ * @return:
+ * FreeType error code. 0 means success.
+ */
+ typedef FT_Error
+ (*TT_Load_Svg_Doc_Func)( FT_GlyphSlot glyph,
+ FT_UInt glyph_index );
+
+
+ /**************************************************************************
+ *
+ * @functype:
* TT_Set_SBit_Strike_Func
*
* @description:
@@ -781,6 +806,7 @@ FT_BEGIN_HEADER
/* OpenType SVG support */
TT_Load_Table_Func load_svg;
TT_Free_Table_Func free_svg;
+ TT_Load_Svg_Doc_Func load_svg_doc;
} SFNT_Interface;
@@ -830,7 +856,8 @@ FT_BEGIN_HEADER
get_name_, \
get_name_id_, \
load_svg_, \
- free_svg_ ) \
+ free_svg_, \
+ load_svg_doc_ ) \
static const SFNT_Interface class_ = \
{ \
goto_table_, \
@@ -872,7 +899,8 @@ FT_BEGIN_HEADER
get_name_, \
get_name_id_, \
load_svg_, \
- free_svg_ \
+ free_svg_, \
+ load_svg_doc_ \
};
diff --git a/include/freetype/otsvg.h b/include/freetype/otsvg.h
new file mode 100644
index 000000000..5569ce4d6
--- /dev/null
+++ b/include/freetype/otsvg.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+ *
+ * otsvg.h
+ *
+ * Interface for OT-SVG support related things (specification).
+ *
+ * Copyright (C) 2004-2019 by
+ * David Turner, Robert Wilhelm, Werner Lemberg and Moazin Khatti.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+
+#ifndef FTSVG_RENDERER_H_
+#define FTSVG_RENDERER_H_
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#ifdef FREETYPE_H
+#error "freetype.h of FreeType 1 has been loaded!"
+#error "Please fix the directory search order for header files"
+#error "so that freetype.h of FreeType 2 is found first."
+#endif
+
+FT_BEGIN_HEADER
+
+ /**************************************************************************
+ *
+ * @struct:
+ * FT_SVG_DocumentRec_
+ *
+ * @description:
+ * A structure that models one SVG document.
+ *
+ * @fields:
+ * svg_document ::
+ * A pointer to the SVG document string.
+ *
+ * svg_document_length ::
+ * The length of the SVG document string.
+ *
+ * metrics ::
+ * A metrics object storing the size information.
+ *
+ * units_per_EM ::
+ * The size of the EM square.
+ *
+ * start_glyph_id ::
+ * The starting glyph ID for the glyph range that this document has.
+ *
+ * end_glyph_id ::
+ * The ending glyph ID for the glyph range that this document has.
+ *
+ * @note:
+ * `metrics` and `units_per_EM` might look like repetitions since both
+ * fields are stored in face object, but they are not; When the slot is
+ * passed down to a renderer, the renderer can only access the `metrics`
+ * and `units_per_EM` by `slot->face`. However, when `FT_Glyph_To_Bitmap`
+ * sets up a dummy object, it has no way to set a `face` object. Thus,
+ * metrics information and units_per_EM (which is necessary for OT-SVG)
+ * has to be stored separately.
+ */
+
+ typedef struct FT_SVG_DocumentRec_
+ {
+ FT_Byte* svg_document;
+ FT_ULong svg_document_length;
+ FT_Size_Metrics metrics;
+ FT_UShort units_per_EM;
+ FT_UShort start_glyph_id;
+ FT_UShort end_glyph_id;
+ } FT_SVG_DocumentRec;
+
+ /**************************************************************************
+ *
+ * @type:
+ * FT_SVG_Document
+ *
+ * @description:
+ * A handle to a FT_SVG_DocumentRec object.
+ */
+ typedef struct FT_SVG_DocumentRec_* FT_SVG_Document;
+
+FT_END_HEADER
+#endif